Rahn
Rahn

Reputation: 5425

Generating LLVM IR using clang

#include <stdio.h>

int main() {
    printf("hello world\n");
    return 0;
}

I just wrote a simple hello.c.

When I type in

$ clang -O3 -emit-llvm hello.c -c -o hello.bc and $ lli hello.bc

in a terminal it runs well.

BUT, when I type in

$ clang -O3 -emit-llvm hello.c -S -o hello.ll and lli hello.ll.

An error occur showing that a bug is found at line 21:

!0 = metadata !{metadata !"Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)"}

It WORKS after I DELETE those 2 metadata. WHY?

Is this a problem of clang or LLVM?

Information about my LLVM version:

Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.0.0
Thread model: posix

//all the commands I use above come from http://llvm.org/docs/CommandGuide/index.html

Upvotes: 1

Views: 537

Answers (1)

Michael Haidl
Michael Haidl

Reputation: 5482

This seams to be a bug in the Apple lli version. I cannot reproduce this behavior with my clang/lli version, which is compiled from svn (release 3.5) directly.

The emitted IR is:

; ModuleID = 'hello.cpp'
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@.str = private unnamed_addr constant [13 x i8] c"hello world\0A\00", align 1

; Function Attrs: nounwind uwtable
define i32 @main() #0 {
  %1 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([13 x i8]* @.str, i64 0, i64 0))
  ret i32 0
}

; Function Attrs: nounwind
declare i32 @printf(i8* nocapture readonly, ...) #1

attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #1 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }

!llvm.ident = !{!0}

!0 = metadata !{metadata !"clang version 3.5.0 "}

and lli hello.ll prints hello world. It also prints hello world if I replace the metadata string with the one you posted.

You should probably file a bug report for Apple's lli.

Upvotes: 2

Related Questions