Skip to content

Conversation

@nektro
Copy link
Contributor

@nektro nektro commented Jul 20, 2022

Fixes #11767

test {
    foo();
}

noinline fn foo() void {
    //
}
[meg@nixos:~/dev/zig]$ ./zig-out/bin/zig ast-check -t test.zig 
# Source bytes:       55B
# Tokens:             16 (104B)
# AST Nodes:          9 (237B)
# Total ZIR bytes:    398B
# Instructions:       15 (135B)
# String Table Bytes: 7B
# Extra Data Items:   48 (192B)
%0 = extended(struct_decl(parent, Auto, {
  test line(0) hash(53b4e586ab7c73d53a2fda7c58ad19aa): %1 = block_inline({
    %9 = func_fancy(test, inferror, body={
      %2 = dbg_block_begin())
      %3 = dbg_stmt(2, 5)
      %4 = decl_val("foo") token_offset:2:5 to :2:8
      %5 = dbg_stmt(2, 8)
      %7 = dbg_block_end())
      %6 = call(nodiscard .auto, %4, []) node_offset:2:5 to :2:10
      %8 = ret_tok(@Zir.Inst.Ref.void_value) token_offset:3:1 to :3:2
    }) (lbrace=1:6,rbrace=3:1) node_offset:1:1 to :1:5
    %10 = break_inline(%1, %9)
  }) node_offset:1:1 to :1:5
  [40] foo line(4) hash(f3339e121db838fc9d98c7412345a9c5): %11 = block_inline({
    %13 = func_fancy(noinline, body={
      %12 = ret_tok(@Zir.Inst.Ref.void_value) token_offset:7:1 to :7:2
    }) (lbrace=1:24,rbrace=3:1) node_offset:5:1 to :5:12
    %14 = break_inline(%11, %13)
  }) node_offset:5:1 to :5:23
}, {}, {})
<snip>

; Function Attrs: noinline nounwind
define internal fastcc void @test.foo() unnamed_addr #0 !dbg !4183 {
Entry:
  ret void
}

<snip>

Full .ll log: https://clbin.com/ztvi5

@nektro nektro force-pushed the stage2-noinline branch from 8efb580 to 002f7dd Compare July 21, 2022 00:03
@ghost
Copy link

ghost commented Jul 21, 2022

Can it also handle this?

pub fn main() void {
    x();
}

noinline fn x() callconv(.Inline) void {}

I think it should be an error because it's ambiguous. In stage1 it's

broken LLVM module found: Attributes 'noinline and alwaysinline' are incompatible!
void ()* @x

This is a bug in the Zig compiler.thread 29374 panic:
Unable to dump stack trace: debug info stripped
Aborted (core dumped)

And we might also want to check other possibly problematic calling conventions in std.builtin.CallingConvention but I don't see any other apart from .Inline.

@nektro
Copy link
Contributor Author

nektro commented Jul 21, 2022

good catch, ill fix both notes and re-push

@nektro nektro force-pushed the stage2-noinline branch from 002f7dd to d2f6d96 Compare July 21, 2022 17:58
@nektro nektro force-pushed the stage2-noinline branch from d2f6d96 to dda0f49 Compare July 21, 2022 19:44
@Vexu Vexu force-pushed the stage2-noinline branch from fa88ba4 to 4be0ef8 Compare July 23, 2022 13:13
@Vexu Vexu merged commit dea437e into ziglang:master Jul 24, 2022
@nektro nektro deleted the stage2-noinline branch July 24, 2022 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

implement noinline

2 participants