annotations preventing optimizations/cleanup?

I created a plugin to add simple Annotations to VarDecls and
FieldDecls, and write this modified AST out to a file. I notice that
when I use clang to compile this file I get different code then when I
use the source directly. In both cases I'm compiling with -O4. Can
anyone explain this?

Thanks

define i32 @somefunc(i32 (i32)* %ptr) nounwind uwtable {
entry:
  %ptr.addr = alloca i32 (i32)*, align 8
  store i32 (i32)* %ptr, i32 (i32)** %ptr.addr, align 8, !tbaa !0
  %ptr.addr1 = bitcast i32 (i32)** %ptr.addr to i8*
  call void @llvm.var.annotation(i8* %ptr.addr1, i8* getelementptr
inbounds ([11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds
([51 x i8]* @.str1, i64 0, i64 0), i32 13)
  %0 = load i32 (i32)** %ptr.addr, align 8, !tbaa !0
  %cmp = icmp eq i32 (i32)* %0, null
  ...

VS

define i32 @somefunc(i32 (i32)* %ptr) nounwind uwtable ssp {
entry:
  %cmp = icmp eq i32 (i32)* %ptr, null
  ...

I created a plugin to add simple Annotations to VarDecls and
FieldDecls, and write this modified AST out to a file. I notice that
when I use clang to compile this file I get different code then when I
use the source directly. In both cases I'm compiling with -O4. Can
anyone explain this?

This is how clang implements annotations on local variables, that's all.

Ciao, Duncan.

I'm more curious about the stuff before the annotations. In the code I
got from modifying the AST it doesn't look like the function is
getting params like normal, and its not even annotated.

int somefunc(int (*ptr)(int)) {
  if(ptr == NULL)
    return 1;
  
  global = ptr;
  return 0;
}

becomes

%ptr.addr = alloca i32 (i32)*, align 8
store i32 (i32)* %ptr, i32 (i32)** %ptr.addr, align 8, !tbaa !0
%ptr.addr1 = bitcast i32 (i32)** %ptr.addr to i8*

Thanks