0
我使用标签bar
来标注功能参数,如下所示。如何确定函数参数是否注释?
int foo (char* s __attribute__((annotate("bar")))) {
...
}
接下来,我正在运行函数传递。如何确定给定的函数参数是否使用标签bar
注释?
我使用标签bar
来标注功能参数,如下所示。如何确定函数参数是否注释?
int foo (char* s __attribute__((annotate("bar")))) {
...
}
接下来,我正在运行函数传递。如何确定给定的函数参数是否使用标签bar
注释?
您将不得不阅读llvm.var.annotation和llvm.dbg.declare内部函数。
更具体地说,这里是LLVM-IR通过上面的代码生成:
@.str = private unnamed_addr constant [4 x i8] c"bar\00", section "llvm.metadata"
@.str.1 = private unnamed_addr constant [75 x i8] c"/tmp/compiler-explorer-compiler117030-12962-1rhu4lb.ojfaiz4cxr/example.cpp\00", section "llvm.metadata"
; Function Attrs: nounwind uwtable
define i32 @foo(char*)(i8*) #0 !dbg !6 {
%2 = alloca i8*, align 8
store i8* %0, i8** %2, align 8
call void @llvm.dbg.declare(metadata i8** %2, metadata !12, metadata !13), !dbg !14
%3 = bitcast i8** %2 to i8*
call void @llvm.var.annotation(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.1, i32 0, i32 0), i32 1)
ret i32 0, !dbg !15
}
!6 = distinct !DISubprogram(name: "foo", linkageName: "foo(char*)", scope: !1, file: !1, line: 1, type: !7, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)
!7 = !DISubroutineType(types: !8)
!8 = !{!9, !10}
!9 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
!10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64, align: 64)
!11 = !DIBasicType(name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char)
!12 = !DILocalVariable(name: "s", arg: 1, scope: !6, file: !1, line: 1, type: !10)
的dbg.declare指令告诉你,2%实际上是函数(命名为S)的第一个参数。
%3是%2的bitcast,所以基本上是一个别名。
而且,llvm.var.annotation指令告诉你%2用常量字符串@str注解,该值为“bar”。