错误:调用GEP指令时的预期值标记

时间:2015-05-22 12:39:52

标签: llvm llvm-ir

我正在玩LLVM并开始使用简单的Hello World。这是我尝试运行的代码:

test.s

; Declare the string constant as a global constant.                  
@.str = private unnamed_addr constant [13 x i8] c"Hello world!\00"   

; External declaration of the puts function                          
declare i32 @puts(i8* nocapture) nounwind                            

; Definition of main function                                        
define i32 @main() {   ; i32()*                                      
  ; Convert [13 x i8]* to i8 *...                                    
  %cast210 = getelementptr [13 x i8], [13 x i8]* @.str, i64 0, i64 0 

  ; Call putr function to write out the string to stdout.
  call i32 @puts(i8* %cast210)
  ret i32 0
}

我从这里开始:http://llvm.org/docs/LangRef.html#id610。当我运行它时,我收到以下错误:

$lli test.s
lli: test.s:10:37: error: expected value token
 %cast210 = getelementptr [13 x i8], [13 x i8]* @.str, i64 0, i64 0
                                   ^

来自官方LLVM网站的代码失败时,这有点令人困惑。但是,可以通过修改有问题的行来修复它,如下所示:

test_fixed.s

; Declare the string constant as a global constant.                  
@.str = private unnamed_addr constant [13 x i8] c"Hello world!\00"   

; External declaration of the puts function                          
declare i32 @puts(i8* nocapture) nounwind                            

; Definition of main function                                        
define i32 @main() {   ; i32()*                                      
  ; Convert [13 x i8]* to i8 *...                                    
  %cast210 = getelementptr [13 x i8]* @.str, i64 0, i64 0 

  ; Call putr function to write out the string to stdout.
  call i32 @puts(i8* %cast210)
  ret i32 0
}

我的问题是:这里发生了什么?当我查看getelementptr:http://llvm.org/docs/LangRef.html#id937的文档时,我得到的印象是 test.s 确实是正确的。然而它并没有奏效。请帮忙。

一些上下文信息:

    $ lli -version
    LLVM (http://llvm.org/):
      LLVM version 3.3
      Optimized build.
      Built Jun 18 2013 (05:58:10).
      Default target: x86_64-pld-linux-gnu
      Host CPU: bdver1

1 个答案:

答案 0 :(得分:3)

这应该是您lli和官方LLVM文档之间版本不匹配的问题。官方LLVM文档适用于LLVM的最新开发版本3.7

您问题中的LLVM IR代码已更新Mar 4 2015。根据{{​​3}},getelementptr指令格式更新后。

但是,您的lli版本为3.3,已在Jun 18 2013上发布。

请将您的llvm工具链更新到最新版本,然后重试。