[LLVMdev] c const
Holger Schurig
hs4233 at mail.mn-solutions.de
Wed Aug 8 02:34:45 PDT 2007
> How is c's const keyword translated when compiling c into
> llvm bytecode.
It isn't. You can verify this quite simply with the following
test program:
void a(const void *p)
{
}
void b(void *p)
{
}
$ clang --emit-llvm test.c
; ModuleID = 'foo'
define void @a(i8* %p) {
entry:
%p.addr = alloca i8* ; <i8**> [#uses=1]
%allocapt = bitcast i32 undef to i32 ; <i32> [#uses=0]
store i8* %p, i8** %p.addr
ret void
}
define void @b(i8* %p) {
entry:
%p.addr = alloca i8* ; <i8**> [#uses=1]
%allocapt = bitcast i32 undef to i32 ; <i32> [#uses=0]
store i8* %p, i8** %p.addr
ret void
}
Now, I tried this with the gcc 4.0 frontend as well:
$ gcc -c --emit-llvm test.c -o - | llvm-dis -o -
; ModuleID = '<stdin>'
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
target triple = "i686-pc-linux-gnu"
define void @a(i8* %p) {
entry:
%p_addr = alloca i8* ; <i8**> [#uses=1]
%"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
store i8* %p, i8** %p_addr
br label %return
return: ; preds = %entry
ret void
}
define void @b(i8* %p) {
entry:
%p_addr = alloca i8* ; <i8**> [#uses=1]
%"alloca point" = bitcast i32 0 to i32 ; <i32> [#uses=0]
store i8* %p, i8** %p_addr
br label %return
return: ; preds = %entry
ret void
}
As you can see, with both C compilers the generated intermediate language
is the same for both function a() and b().
More information about the llvm-dev
mailing list