Skip to content

Instantly share code, notes, and snippets.

@mikdusan
Last active February 26, 2021 05:31
Show Gist options
  • Save mikdusan/a6d69a71da51680dd09c4af03ab84e7b to your computer and use it in GitHub Desktop.
Save mikdusan/a6d69a71da51680dd09c4af03ab84e7b to your computer and use it in GitHub Desktop.
const Foo = struct {
a: u32 = 0,
b: u32 = 0,
c: u32 = 0,
d: u32 = 0,
e: u32 = 0,
f: u32 = 0,
g: u32 = 0,
};
export fn entry() void {
_ = doit();
}
fn doit() Foo { return .{}; }
pub fn panic(msg: []const u8, error_return_trace: ?*@import("builtin").StackTrace) noreturn {
while (true) {}
}
@mikdusan
Copy link
Author

mikdusan commented Feb 26, 2021

  • zig0 built against llvmorg-12.0.0-rc2 is used here to build an object file
  • we enable --verbose-llvm-ir and capture to file, feed .ll to llvmorg-12.0.0-rc2 tools such as llc or llvm-as and the following error result:
[llvm12⋅1-0] tiberius▸ /opt/llvm-macos11.1-x86_64-12.0.0-rc2-release/bin/llvm-as z2.ll
/opt/llvm-macos11.1-x86_64-12.0.0-rc2-release/bin/llvm-as: z2.ll:34:37: error: expected '('
  call fastcc void @doit(%Foo* sret %0), !dbg !50
                                    ^

and the IR of our entry() and doit() methods look like this:

; Function Attrs: nobuiltin noredzone nounwind sspstrong
define void @entry() #1 !dbg !2228 {
Entry:
  %0 = alloca %Foo, align 4
  call fastcc void @doit(%Foo* sret %0), !dbg !2232
  ret void, !dbg !2234
}

; Function Attrs: nobuiltin noredzone nounwind sspstrong
define internal fastcc void @doit(%Foo* nonnull sret %0) unnamed_addr #1 !dbg !2235 {
Entry:
  %1 = getelementptr inbounds %Foo, %Foo* %0, i32 0, i32 0, !dbg !2248
  store i32 0, i32* %1, align 4, !dbg !2248
  %2 = getelementptr inbounds %Foo, %Foo* %0, i32 0, i32 1, !dbg !2248
  store i32 0, i32* %2, align 4, !dbg !2248
  %3 = getelementptr inbounds %Foo, %Foo* %0, i32 0, i32 2, !dbg !2248
  store i32 0, i32* %3, align 4, !dbg !2248
  %4 = getelementptr inbounds %Foo, %Foo* %0, i32 0, i32 3, !dbg !2248
  store i32 0, i32* %4, align 4, !dbg !2248
  %5 = getelementptr inbounds %Foo, %Foo* %0, i32 0, i32 4, !dbg !2248
  store i32 0, i32* %5, align 4, !dbg !2248
  %6 = getelementptr inbounds %Foo, %Foo* %0, i32 0, i32 5, !dbg !2248
  store i32 0, i32* %6, align 4, !dbg !2248
  %7 = getelementptr inbounds %Foo, %Foo* %0, i32 0, i32 6, !dbg !2248
  store i32 0, i32* %7, align 4, !dbg !2248
  ret void, !dbg !2250
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment