[LLVMdev] Can a name in LLVM assembly language hold two types of value at the same time
Zhongxing Xu
xzx at ios.ac.cn
Wed Sep 6 19:58:17 PDT 2006
I am trying to symbolically execute LLVM assembly language. I found a
possible
semantic inconsistancy of the LLVM assembly language, or maybe my
understanding
is wrong.
The C code is:
#include <stdlib.h>
1 int f(void)
2 {
3 int a;
4 int *b = (int *) malloc(3*sizeof(int));
5 a = 3;
6 return 0;
7 }
I compile it with llvm-gcc 4 front end. The generated LLVM assembly code
is:
1 target endian = little
2 target pointersize = 32
3 target triple = "i686-pc-linux-gnu"
4 implementation ; Functions:
5 int %f() {
6 entry:
7 %retval = alloca int, align 4 ; <int*> [#uses=2]
8 %tmp = alloca int, align 4 ; <int*> [#uses=2]
9 %a = alloca int, align 4 ; <int*> [#uses=1]
10 %b = alloca int*, align 4 ; <int**> [#uses=1]
11 "alloca point" = cast int 0 to int ; <int> [#uses=0]
12 %tmp = call sbyte* %malloc( uint 12 ) ; <sbyte*>
[#uses=1]
13 %tmp1 = cast sbyte* %tmp to int* ; <int*>
[#uses=1]
14 store int* %tmp1, int** %b
15 store int 3, int* %a
16 store int 0, int* %tmp
17 %tmp = load int* %tmp ; <int> [#uses=1]
18 store int %tmp, int* %retval
19 br label %return
20 return: ; preds = %entry
21 %retval = load int* %retval ; <int> [#uses=1]
22 ret int %retval
23 }
declare sbyte* %malloc(uint)
After line 8, %tmp holds a pointer to stack, whose type is int*
After line 12, %tmp holds a pointer to heap, whose type is sbyte*
At line 16, value 0 is to be stored to a memory location of type int
pointed to by %tmp. But at this time %tmp is holding a pointer to
heap of type sbyte. And the heap should not be written to. (There is
no assignment to b[0] in the C code.)
So I guess that %;tmp also holds its original value, which is a pointer
to stack of type int. And we can decide which location to store according
to the type.
Could someone explain this for me? Thanks.
-- Zhongxing Xu
More information about the llvm-dev
mailing list