misc questions on opt and bitcode

Hi,

For the very simple example below, I get Unknown instruction error from lli and llvm-dis, while llc does not print anything. Not sure what is that I am missing here. My llvm-gcc version is i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00)

1-39-155-188:pastebin Babai$ cat example.c
#include <stdio.h>

void hello()
{
printf(“testing\n”);
}

int main()
{
hello();
}
1-39-155-188:pastebin Babai$ llvm-gcc example.c -emit-llvm -c -o example.bc
1-39-155-188:pastebin Babai$ lli example.bc
lli: example.bc: Unknown instruction
1-39-155-188:pastebin Babai$ llvm-dis < example.bc
llvm-dis: Unknown instruction
1-39-155-188:pastebin Babai$ llvm-gcc example.c -emit-llvm -S -o example.s
1-39-155-188:pastebin Babai$ llc example.s
1-39-155-188:pastebin Babai$ llc example.s
1-39-155-188:pastebin Babai$ llvm-gcc example.c
1-39-155-188:pastebin Babai$ ./a.out
testing

Any ideas?

Arpan

On which instruction is illegal? Not offhand, but you can use llvm-gcc -S -emit-llvm example.c -o example.ll to get an llvm bitcode file as text and take a look.

-eric

Hi Eric,

Here’s the C code (example.c):

include <stdio.h>

int main()
{
printf(“testing\n”);
}

Here’s the LLVM IR (from llvm-gcc):

ModuleID = ‘example.c’
target datalayout = “e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64”
target triple = “x86_64-apple-darwin11.0”

@.str = private constant [8 x i8] c"testing\00", align 1 ; <[8 x i8]*> [#uses=1]

define i32 @main() nounwind ssp {
entry:
%retval = alloca i32 ; <i32*> [#uses=1]
%“alloca point” = bitcast i32 0 to i32 ; [#uses=0]
%0 = call i32 @puts(i8* getelementptr inbounds ([8 x i8]* @.str, i64 0, i64 0)) nounwind ; [#uses=0]
br label %return

return: ; preds = %entry
%retval1 = load i32* %retval ; [#uses=1]
ret i32 %retval1
}

declare i32 @puts(i8*)

And when I run llc with this IR I get nothing printed on screen. Not sure if my LLVM revision is corrupted and needs a fresh install. When I ran with the bitcode and lli here’s what I get:

42-105-250-151:pastebin Babai$ llvm-gcc example.c -c -emit-llvm -o example.bc
42-105-250-151:pastebin Babai$ lli example.bc
lli: example.bc: Invalid ALLOCA record

Pretty confusing.

Thanks,
Arpan

Works for me:

[jhereg:~/tmp] echristo% /Volumes/Data/builds/build-llvm/Debug+Asserts/bin/clang -S -emit-llvm foo.cpp
[jhereg:~/tmp] echristo% lli foo.s
testing
[jhereg:~/tmp] echristo% llvm-gcc -S -emit-llvm foo.cpp
[jhereg:~/tmp] echristo% lli foo.s
testing

the first is using top of tree clang. The second is using an llvm-gcc on my OS. What versions are you using?

-eric

And when I run llc with this IR I get nothing printed on screen. Not sure if my
LLVM revision is corrupted and needs a fresh install. When I ran with the
bitcode and lli here's what I get:
42-105-250-151:pastebin Babai$ llvm-gcc example.c -c -emit-llvm -o example.bc
42-105-250-151:pastebin Babai$ lli example.bc
lli: example.bc: Invalid ALLOCA record

Mismatch between the LLVM versions of llvm-gcc and lli?

Ciao, Duncan.