Llvm 如何确定是否对函数参数进行了注释?

Llvm 如何确定是否对函数参数进行了注释?,llvm,llvm-ir,Llvm,Llvm Ir,我正在用标签栏注释函数参数,如下所示 int foo (char* s __attribute__((annotate("bar")))) { ... } 接下来,我运行一个函数传递。如何确定给定的函数参数是否用标签bar注释?您必须阅读和内部函数 更具体地说,下面是由上面的代码生成的llvm ir: @.str = private unnamed_addr constant [4 x i8] c"bar\00", section "llvm.metadata" @.str.1 = pri

我正在用标签
注释函数参数,如下所示

int foo (char* s __attribute__((annotate("bar")))) {
  ...
}
接下来,我运行一个函数传递。如何确定给定的函数参数是否用标签
bar
注释?

您必须阅读和内部函数

更具体地说,下面是由上面的代码生成的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的位广播,因此基本上是一个别名

llvm.var.annotation指令告诉您%2是用常量字符串@str注释的,该字符串的值为“bar”