llvm.annotation arguments

Hello all,

According to clang/lib/CodeGen/CodeGenFunction.cpp, a LLVM annotation intrinsic call has 4 arguments:

  • llvm::Value *AnnotatedVal,
  • Builder.CreateBitCast(CGM.EmitAnnotationString(AnnotationStr), Int8PtrTy),
  • Builder.CreateBitCast(CGM.EmitAnnotationUnit(Location), Int8PtrTy),
  • CGM.EmitAnnotationLineNo(Location)

However, this is what an annotation intrinsic char attribute((annotate(“DIFF”))) diff looks like in the IR:

@.str = private unnamed_addr constant [5 x i8] c"DIFF\00", section “llvm.metadata”

@.str.1 = private unnamed_addr constant [6 x i8] c"pin.c\00", section “llvm.metadata”

call void @llvm.var.annotation(i8* %diff,
i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0),
i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i32 0, i32 0),
i32 38)

So my question is, why don’t we find any BitCast here, but a GEP?

Thanks for your help,

Pointer casts are considered less canonical. The GEP is the same as writing &array[0] in C to convert from a pointer to an array to a pointer to an array element, without relying on pointer decay.