使用clang生成LLVM IR

拉恩
#include <stdio.h>

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

我只是写了一个简单的hello.c

当我输入

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

在终端中运行良好。

但是,当我输入

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

发生错误,表明在第21行发现了一个错误:

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

我删除那些2后,它会起作用metadata为什么?

这是clang或LLVM的问题吗?

有关我的LLVM版本的信息:

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

//我上面使用的所有命令均来自http://llvm.org/docs/CommandGuide/index.html

迈克尔·海德尔

这似乎是Apple lli版本中的错误。我无法使用我的clang / lli版本来重现此行为,该版本是直接从svn(3.5版)编译的。

发出的IR为:

; 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 "}

lli hello.ll打印hello worldhello world如果我将metadata字符串替换为您发布字符串,也会打印

您可能应该提交Apple的错误报告lli

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章