banach-space
banach-space

Reputation: 1811

error: expected value token when calling the GEP instruction

I'm playing with LLVM and have started with simple Hello World. Here's the code that I'm trying to run:

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
}

I took it from here : http://llvm.org/docs/LangRef.html#id610. When I run it I get the following error:

$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
                                   ^

It's a bit confusing when code from official LLVM website fails. However, it can be fixed by modifying the problematic line as follows:

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
}

My question is: what is going on here? When I check the documentation for getelementptr: http://llvm.org/docs/LangRef.html#id937, I get the impression that test.s is indeed correct. Yet it doesn't work. Please help.

Some context info:

    $ 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

Upvotes: 1

Views: 1783

Answers (1)

Kun Ling
Kun Ling

Reputation: 2219

This should be a problem about the version mismatch between your lli and the official LLVM docs. The official LLVM docs is for the latest developing version of LLVM, 3.7.

The LLVM IR code in your question was update on Mar 4 2015. according to this link, after getelementptr instruction format was updated.

However, your version of lli is 3.3, which is released on Jun 18 2013.

Please update your llvm toolchain to the latest version, and try it again.

Upvotes: 3

Related Questions