Author: Thurston Dang
Date: 2025-05-19T09:39:26-07:00
New Revision: b24c33a9d745bd2a3009f1d52f31247772e954e5

URL: 
https://github.com/llvm/llvm-project/commit/b24c33a9d745bd2a3009f1d52f31247772e954e5
DIFF: 
https://github.com/llvm/llvm-project/commit/b24c33a9d745bd2a3009f1d52f31247772e954e5.diff

LOG: [cfi] Enable -fsanitize-annotate-debug-info functionality for CFI checks 
(#139809)

This connects the -fsanitize-annotate-debug-info plumbing 
(https://github.com/llvm/llvm-project/pull/138577) to CFI check codegen, using 
SanitizerAnnotateDebugInfo() (https://github.com/llvm/llvm-project/pull/139965) 
and SanitizerInfoFromCFIKind (https://github.com/llvm/llvm-project/pull/140117).

Note: SanitizerAnnotateDebugInfo() is updated to a public function because it 
is needed in ItaniumCXXABI.

Updates the tests from https://github.com/llvm/llvm-project/pull/139149.

Added: 
    

Modified: 
    clang/lib/CodeGen/CGClass.cpp
    clang/lib/CodeGen/CGExpr.cpp
    clang/lib/CodeGen/CodeGenFunction.h
    clang/lib/CodeGen/ItaniumCXXABI.cpp
    clang/test/CodeGen/cfi-check-fail-debuginfo.c
    clang/test/CodeGen/cfi-icall-generalize-debuginfo.c
    clang/test/CodeGen/cfi-icall-normalize2-debuginfo.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp
index 7710b1aee6f28..652622a2b878c 100644
--- a/clang/lib/CodeGen/CGClass.cpp
+++ b/clang/lib/CodeGen/CGClass.cpp
@@ -2814,6 +2814,9 @@ void CodeGenFunction::EmitVTablePtrCheckForCall(const 
CXXRecordDecl *RD,
   if (!SanOpts.has(SanitizerKind::CFICastStrict))
     RD = LeastDerivedClassWithSameLayout(RD);
 
+  auto [Ordinal, _] = SanitizerInfoFromCFICheckKind(TCK);
+  ApplyDebugLocation ApplyTrapDI(*this, SanitizerAnnotateDebugInfo(Ordinal));
+
   EmitVTablePtrCheck(RD, VTable, TCK, Loc);
 }
 
@@ -2836,6 +2839,9 @@ void CodeGenFunction::EmitVTablePtrCheckForCast(QualType 
T, Address Derived,
   if (!SanOpts.has(SanitizerKind::CFICastStrict))
     ClassDecl = LeastDerivedClassWithSameLayout(ClassDecl);
 
+  auto [Ordinal, _] = SanitizerInfoFromCFICheckKind(TCK);
+  ApplyDebugLocation ApplyTrapDI(*this, SanitizerAnnotateDebugInfo(Ordinal));
+
   llvm::BasicBlock *ContBlock = nullptr;
 
   if (MayBeNull) {
@@ -2937,6 +2943,8 @@ llvm::Value *CodeGenFunction::EmitVTableTypeCheckedLoad(
   SanitizerScope SanScope(this);
 
   EmitSanitizerStatReport(llvm::SanStat_CFI_VCall);
+  ApplyDebugLocation ApplyTrapDI(
+      *this, SanitizerAnnotateDebugInfo(SanitizerKind::SO_CFIVCall));
 
   llvm::Metadata *MD =
       CGM.CreateMetadataIdentifierForType(QualType(RD->getTypeForDecl(), 0));

diff  --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 37a5678aa61d5..708002a7f9ab3 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3971,6 +3971,8 @@ void CodeGenFunction::EmitCfiCheckFail() {
                          {Addr, AllVtables}),
       IntPtrTy);
 
+  // TODO: the instructions above are not annotated with debug info. It is
+  // inconvenient to do so because we have not determined SanitizerKind yet.
   const std::pair<int, SanitizerKind::SanitizerOrdinal> CheckKinds[] = {
       {CFITCK_VCall, SanitizerKind::SO_CFIVCall},
       {CFITCK_NVCall, SanitizerKind::SO_CFINVCall},
@@ -3981,6 +3983,9 @@ void CodeGenFunction::EmitCfiCheckFail() {
   for (auto CheckKindOrdinalPair : CheckKinds) {
     int Kind = CheckKindOrdinalPair.first;
     SanitizerKind::SanitizerOrdinal Ordinal = CheckKindOrdinalPair.second;
+
+    ApplyDebugLocation ApplyTrapDI(*this, SanitizerAnnotateDebugInfo(Ordinal));
+
     llvm::Value *Cond =
         Builder.CreateICmpNE(CheckKind, llvm::ConstantInt::get(Int8Ty, Kind));
     if (CGM.getLangOpts().Sanitize.has(Ordinal))
@@ -6315,6 +6320,8 @@ RValue CodeGenFunction::EmitCall(QualType CalleeType,
       (!TargetDecl || !isa<FunctionDecl>(TargetDecl))) {
     SanitizerScope SanScope(this);
     EmitSanitizerStatReport(llvm::SanStat_CFI_ICall);
+    ApplyDebugLocation ApplyTrapDI(
+        *this, SanitizerAnnotateDebugInfo(SanitizerKind::SO_CFIICall));
 
     llvm::Metadata *MD;
     if (CGM.getCodeGenOpts().SanitizeCfiICallGeneralizePointers)

diff  --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index 7104303cba50e..603e38d763aa4 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -2816,11 +2816,6 @@ class CodeGenFunction : public CodeGenTypeCache {
   void emitStoresForInitAfterBZero(llvm::Constant *Init, Address Loc,
                                    bool isVolatile, bool IsAutoInit);
 
-  /// Returns debug info, with additional annotation if enabled by
-  /// CGM.getCodeGenOpts().SanitizeAnnotateDebugInfo[CheckKindOrdinal].
-  llvm::DILocation *
-  SanitizerAnnotateDebugInfo(SanitizerKind::SanitizerOrdinal CheckKindOrdinal);
-
 public:
   // Captures all the allocas created during the scope of its RAII object.
   struct AllocaTrackerRAII {
@@ -3367,6 +3362,11 @@ class CodeGenFunction : public CodeGenTypeCache {
                            llvm::Value *Index, QualType IndexType,
                            QualType IndexedType, bool Accessed);
 
+  /// Returns debug info, with additional annotation if enabled by
+  /// CGM.getCodeGenOpts().SanitizeAnnotateDebugInfo[CheckKindOrdinal].
+  llvm::DILocation *
+  SanitizerAnnotateDebugInfo(SanitizerKind::SanitizerOrdinal CheckKindOrdinal);
+
   llvm::Value *GetCountedByFieldExprGEP(const Expr *Base, const FieldDecl *FD,
                                         const FieldDecl *CountDecl);
 

diff  --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp 
b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 8826085c596da..faa07024a6052 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -703,6 +703,9 @@ CGCallee ItaniumCXXABI::EmitLoadOfMemberFunctionPointer(
 
   {
     CodeGenFunction::SanitizerScope SanScope(&CGF);
+    ApplyDebugLocation ApplyTrapDI(
+        CGF, CGF.SanitizerAnnotateDebugInfo(SanitizerKind::SO_CFIMFCall));
+
     llvm::Value *TypeId = nullptr;
     llvm::Value *CheckResult = nullptr;
 
@@ -800,6 +803,8 @@ CGCallee ItaniumCXXABI::EmitLoadOfMemberFunctionPointer(
     CXXRecordDecl *RD = MPT->getMostRecentCXXRecordDecl();
     if (RD->hasDefinition()) {
       CodeGenFunction::SanitizerScope SanScope(&CGF);
+      ApplyDebugLocation ApplyTrapDI(
+          CGF, CGF.SanitizerAnnotateDebugInfo(SanitizerKind::SO_CFIMFCall));
 
       llvm::Constant *StaticData[] = {
           llvm::ConstantInt::get(CGF.Int8Ty, CodeGenFunction::CFITCK_NVMFCall),

diff  --git a/clang/test/CodeGen/cfi-check-fail-debuginfo.c 
b/clang/test/CodeGen/cfi-check-fail-debuginfo.c
index cd5ec567cb01b..74ed5564ec704 100644
--- a/clang/test/CodeGen/cfi-check-fail-debuginfo.c
+++ b/clang/test/CodeGen/cfi-check-fail-debuginfo.c
@@ -10,14 +10,14 @@
 // CHECK-SAME: ptr noundef [[F:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] 
!dbg [[DBG7:![0-9]+]] !type [[META16:![0-9]+]] !type [[META17:![0-9]+]] !type 
[[META18:![0-9]+]] {
 // CHECK-NEXT:  [[ENTRY:.*:]]
 // CHECK-NEXT:      #dbg_value(ptr [[F]], [[META15:![0-9]+]], !DIExpression(), 
[[META19:![0-9]+]])
-// CHECK-NEXT:    [[TMP0:%.*]] = tail call i1 @llvm.type.test(ptr [[F]], 
metadata !"_ZTSFvvE"), !dbg [[DBG20:![0-9]+]], !nosanitize [[META21:![0-9]+]]
-// CHECK-NEXT:    br i1 [[TMP0]], label %[[CFI_CONT:.*]], label 
%[[CFI_SLOWPATH:.*]], !dbg [[DBG20]], !prof [[PROF22:![0-9]+]], !nosanitize 
[[META21]]
+// CHECK-NEXT:    [[TMP0:%.*]] = tail call i1 @llvm.type.test(ptr [[F]], 
metadata !"_ZTSFvvE"), !dbg [[DBG20:![0-9]+]], !nosanitize [[META24:![0-9]+]]
+// CHECK-NEXT:    br i1 [[TMP0]], label %[[CFI_CONT:.*]], label 
%[[CFI_SLOWPATH:.*]], !dbg [[DBG20]], !prof [[PROF25:![0-9]+]], !nosanitize 
[[META24]]
 // CHECK:       [[CFI_SLOWPATH]]:
-// CHECK-NEXT:    tail call void @__cfi_slowpath(i64 9080559750644022485, ptr 
[[F]]) #[[ATTR6:[0-9]+]], !dbg [[DBG20]], !nosanitize [[META21]]
-// CHECK-NEXT:    br label %[[CFI_CONT]], !dbg [[DBG20]], !nosanitize 
[[META21]]
+// CHECK-NEXT:    tail call void @__cfi_slowpath(i64 9080559750644022485, ptr 
[[F]]) #[[ATTR6:[0-9]+]], !dbg [[DBG20]], !nosanitize [[META24]]
+// CHECK-NEXT:    br label %[[CFI_CONT]], !dbg [[DBG20]], !nosanitize 
[[META24]]
 // CHECK:       [[CFI_CONT]]:
-// CHECK-NEXT:    tail call void [[F]]() #[[ATTR6]], !dbg [[DBG20]]
-// CHECK-NEXT:    ret void, !dbg [[DBG23:![0-9]+]]
+// CHECK-NEXT:    tail call void [[F]]() #[[ATTR6]], !dbg [[DBG23:![0-9]+]]
+// CHECK-NEXT:    ret void, !dbg [[DBG26:![0-9]+]]
 //
 void caller(void (*f)(void)) {
   f();
@@ -38,8 +38,11 @@ void caller(void (*f)(void)) {
 // CHECK: [[META17]] = !{i64 0, !"_ZTSFvPvE.generalized"}
 // CHECK: [[META18]] = !{i64 0, i64 2451761621477796417}
 // CHECK: [[META19]] = !DILocation(line: 0, scope: [[DBG7]])
-// CHECK: [[DBG20]] = !DILocation(line: 23, column: 3, scope: [[DBG7]])
-// CHECK: [[META21]] = !{}
-// CHECK: [[PROF22]] = !{!"branch_weights", i32 1048575, i32 1}
-// CHECK: [[DBG23]] = !DILocation(line: 24, column: 1, scope: [[DBG7]])
+// CHECK: [[DBG20]] = !DILocation(line: 0, scope: [[META21:![0-9]+]], 
inlinedAt: [[DBG23]])
+// CHECK: [[META21]] = distinct !DISubprogram(name: "__ubsan_check_cfi_icall", 
scope: [[META8]], file: [[META8]], type: [[META22:![0-9]+]], flags: 
DIFlagArtificial, spFlags: DISPFlagDefinition, unit: [[META0]])
+// CHECK: [[META22]] = !DISubroutineType(types: null)
+// CHECK: [[DBG23]] = !DILocation(line: 23, column: 3, scope: [[DBG7]])
+// CHECK: [[META24]] = !{}
+// CHECK: [[PROF25]] = !{!"branch_weights", i32 1048575, i32 1}
+// CHECK: [[DBG26]] = !DILocation(line: 24, column: 1, scope: [[DBG7]])
 //.

diff  --git a/clang/test/CodeGen/cfi-icall-generalize-debuginfo.c 
b/clang/test/CodeGen/cfi-icall-generalize-debuginfo.c
index 8b184528889a0..304b60539c3d1 100644
--- a/clang/test/CodeGen/cfi-icall-generalize-debuginfo.c
+++ b/clang/test/CodeGen/cfi-icall-generalize-debuginfo.c
@@ -27,27 +27,27 @@ int** f(const char *a, const char **b) {
 // UNGENERALIZED-SAME: ptr noundef [[FP:%.*]]) local_unnamed_addr 
#[[ATTR1:[0-9]+]] !dbg [[DBG25:![0-9]+]] !type [[META31:![0-9]+]] !type 
[[META32:![0-9]+]] {
 // UNGENERALIZED-NEXT:  [[ENTRY:.*:]]
 // UNGENERALIZED-NEXT:      #dbg_value(ptr [[FP]], [[META30:![0-9]+]], 
!DIExpression(), [[META33:![0-9]+]])
-// UNGENERALIZED-NEXT:    [[TMP0:%.*]] = tail call i1 @llvm.type.test(ptr 
[[FP]], metadata !"_ZTSFPPiPKcPS2_E"), !dbg [[DBG34:![0-9]+]], !nosanitize 
[[META35:![0-9]+]]
-// UNGENERALIZED-NEXT:    br i1 [[TMP0]], label %[[CONT:.*]], label 
%[[TRAP:.*]], !dbg [[DBG34]], !prof [[PROF36:![0-9]+]], !nosanitize [[META35]]
+// UNGENERALIZED-NEXT:    [[TMP0:%.*]] = tail call i1 @llvm.type.test(ptr 
[[FP]], metadata !"_ZTSFPPiPKcPS2_E"), !dbg [[DBG34:![0-9]+]], !nosanitize 
[[META38:![0-9]+]]
+// UNGENERALIZED-NEXT:    br i1 [[TMP0]], label %[[CONT:.*]], label 
%[[TRAP:.*]], !dbg [[DBG34]], !prof [[PROF39:![0-9]+]], !nosanitize [[META38]]
 // UNGENERALIZED:       [[TRAP]]:
-// UNGENERALIZED-NEXT:    tail call void @llvm.ubsantrap(i8 2) 
#[[ATTR4:[0-9]+]], !dbg [[DBG34]], !nosanitize [[META35]]
-// UNGENERALIZED-NEXT:    unreachable, !dbg [[DBG34]], !nosanitize [[META35]]
+// UNGENERALIZED-NEXT:    tail call void @llvm.ubsantrap(i8 2) 
#[[ATTR4:[0-9]+]], !dbg [[DBG34]], !nosanitize [[META38]]
+// UNGENERALIZED-NEXT:    unreachable, !dbg [[DBG34]], !nosanitize [[META38]]
 // UNGENERALIZED:       [[CONT]]:
-// UNGENERALIZED-NEXT:    [[CALL:%.*]] = tail call ptr [[FP]](ptr noundef 
null, ptr noundef null) #[[ATTR5:[0-9]+]], !dbg [[DBG34]]
-// UNGENERALIZED-NEXT:    ret void, !dbg [[DBG37:![0-9]+]]
+// UNGENERALIZED-NEXT:    [[CALL:%.*]] = tail call ptr [[FP]](ptr noundef 
null, ptr noundef null) #[[ATTR5:[0-9]+]], !dbg [[DBG37:![0-9]+]]
+// UNGENERALIZED-NEXT:    ret void, !dbg [[DBG40:![0-9]+]]
 //
 // GENERALIZED-LABEL: define dso_local void @g(
 // GENERALIZED-SAME: ptr noundef [[FP:%.*]]) local_unnamed_addr 
#[[ATTR1:[0-9]+]] !dbg [[DBG25:![0-9]+]] !type [[META31:![0-9]+]] !type 
[[META32:![0-9]+]] {
 // GENERALIZED-NEXT:  [[ENTRY:.*:]]
 // GENERALIZED-NEXT:      #dbg_value(ptr [[FP]], [[META30:![0-9]+]], 
!DIExpression(), [[META33:![0-9]+]])
-// GENERALIZED-NEXT:    [[TMP0:%.*]] = tail call i1 @llvm.type.test(ptr 
[[FP]], metadata !"_ZTSFPvPKvS_E.generalized"), !dbg [[DBG34:![0-9]+]], 
!nosanitize [[META35:![0-9]+]]
-// GENERALIZED-NEXT:    br i1 [[TMP0]], label %[[CONT:.*]], label 
%[[TRAP:.*]], !dbg [[DBG34]], !prof [[PROF36:![0-9]+]], !nosanitize [[META35]]
+// GENERALIZED-NEXT:    [[TMP0:%.*]] = tail call i1 @llvm.type.test(ptr 
[[FP]], metadata !"_ZTSFPvPKvS_E.generalized"), !dbg [[DBG34:![0-9]+]], 
!nosanitize [[META38:![0-9]+]]
+// GENERALIZED-NEXT:    br i1 [[TMP0]], label %[[CONT:.*]], label 
%[[TRAP:.*]], !dbg [[DBG34]], !prof [[PROF39:![0-9]+]], !nosanitize [[META38]]
 // GENERALIZED:       [[TRAP]]:
-// GENERALIZED-NEXT:    tail call void @llvm.ubsantrap(i8 2) 
#[[ATTR4:[0-9]+]], !dbg [[DBG34]], !nosanitize [[META35]]
-// GENERALIZED-NEXT:    unreachable, !dbg [[DBG34]], !nosanitize [[META35]]
+// GENERALIZED-NEXT:    tail call void @llvm.ubsantrap(i8 2) 
#[[ATTR4:[0-9]+]], !dbg [[DBG34]], !nosanitize [[META38]]
+// GENERALIZED-NEXT:    unreachable, !dbg [[DBG34]], !nosanitize [[META38]]
 // GENERALIZED:       [[CONT]]:
-// GENERALIZED-NEXT:    [[CALL:%.*]] = tail call ptr [[FP]](ptr noundef null, 
ptr noundef null) #[[ATTR5:[0-9]+]], !dbg [[DBG34]]
-// GENERALIZED-NEXT:    ret void, !dbg [[DBG37:![0-9]+]]
+// GENERALIZED-NEXT:    [[CALL:%.*]] = tail call ptr [[FP]](ptr noundef null, 
ptr noundef null) #[[ATTR5:[0-9]+]], !dbg [[DBG37:![0-9]+]]
+// GENERALIZED-NEXT:    ret void, !dbg [[DBG40:![0-9]+]]
 //
 void g(int** (*fp)(const char *, const char **)) {
   fp(0, 0);
@@ -84,10 +84,13 @@ void g(int** (*fp)(const char *, const char **)) {
 // UNGENERALIZED: [[META31]] = !{i64 0, !"_ZTSFvPFPPiPKcPS2_EE"}
 // UNGENERALIZED: [[META32]] = !{i64 0, !"_ZTSFvPvE.generalized"}
 // UNGENERALIZED: [[META33]] = !DILocation(line: 0, scope: [[DBG25]])
-// UNGENERALIZED: [[DBG34]] = !DILocation(line: 53, column: 3, scope: 
[[DBG25]])
-// UNGENERALIZED: [[META35]] = !{}
-// UNGENERALIZED: [[PROF36]] = !{!"branch_weights", i32 1048575, i32 1}
-// UNGENERALIZED: [[DBG37]] = !DILocation(line: 54, column: 1, scope: 
[[DBG25]])
+// UNGENERALIZED: [[DBG34]] = !DILocation(line: 0, scope: [[META35:![0-9]+]], 
inlinedAt: [[DBG37]])
+// UNGENERALIZED: [[META35]] = distinct !DISubprogram(name: 
"__ubsan_check_cfi_icall", scope: [[META11]], file: [[META11]], type: 
[[META36:![0-9]+]], flags: DIFlagArtificial, spFlags: DISPFlagDefinition, unit: 
[[META0]])
+// UNGENERALIZED: [[META36]] = !DISubroutineType(types: null)
+// UNGENERALIZED: [[DBG37]] = !DILocation(line: 53, column: 3, scope: 
[[DBG25]])
+// UNGENERALIZED: [[META38]] = !{}
+// UNGENERALIZED: [[PROF39]] = !{!"branch_weights", i32 1048575, i32 1}
+// UNGENERALIZED: [[DBG40]] = !DILocation(line: 54, column: 1, scope: 
[[DBG25]])
 //.
 // GENERALIZED: [[META0:![0-9]+]] = distinct !DICompileUnit(language: 
DW_LANG_C11, file: [[META1:![0-9]+]], isOptimized: true, runtimeVersion: 0, 
emissionKind: FullDebug, retainedTypes: [[META2:![0-9]+]], splitDebugInlining: 
false, nameTableKind: None)
 // GENERALIZED: [[META1]] = !DIFile(filename: "{{.*}}<stdin>", directory: 
{{.*}})
@@ -119,8 +122,11 @@ void g(int** (*fp)(const char *, const char **)) {
 // GENERALIZED: [[META31]] = !{i64 0, !"_ZTSFvPFPPiPKcPS2_EE"}
 // GENERALIZED: [[META32]] = !{i64 0, !"_ZTSFvPvE.generalized"}
 // GENERALIZED: [[META33]] = !DILocation(line: 0, scope: [[DBG25]])
-// GENERALIZED: [[DBG34]] = !DILocation(line: 53, column: 3, scope: [[DBG25]])
-// GENERALIZED: [[META35]] = !{}
-// GENERALIZED: [[PROF36]] = !{!"branch_weights", i32 1048575, i32 1}
-// GENERALIZED: [[DBG37]] = !DILocation(line: 54, column: 1, scope: [[DBG25]])
+// GENERALIZED: [[DBG34]] = !DILocation(line: 0, scope: [[META35:![0-9]+]], 
inlinedAt: [[DBG37]])
+// GENERALIZED: [[META35]] = distinct !DISubprogram(name: 
"__ubsan_check_cfi_icall", scope: [[META11]], file: [[META11]], type: 
[[META36:![0-9]+]], flags: DIFlagArtificial, spFlags: DISPFlagDefinition, unit: 
[[META0]])
+// GENERALIZED: [[META36]] = !DISubroutineType(types: null)
+// GENERALIZED: [[DBG37]] = !DILocation(line: 53, column: 3, scope: [[DBG25]])
+// GENERALIZED: [[META38]] = !{}
+// GENERALIZED: [[PROF39]] = !{!"branch_weights", i32 1048575, i32 1}
+// GENERALIZED: [[DBG40]] = !DILocation(line: 54, column: 1, scope: [[DBG25]])
 //.

diff  --git a/clang/test/CodeGen/cfi-icall-normalize2-debuginfo.c 
b/clang/test/CodeGen/cfi-icall-normalize2-debuginfo.c
index 00f416e47dee6..a2f6ee0c6805c 100644
--- a/clang/test/CodeGen/cfi-icall-normalize2-debuginfo.c
+++ b/clang/test/CodeGen/cfi-icall-normalize2-debuginfo.c
@@ -12,53 +12,53 @@
 // CHECK-NEXT:  [[ENTRY:.*:]]
 // CHECK-NEXT:      #dbg_value(ptr [[FN]], [[META16:![0-9]+]], 
!DIExpression(), [[META20:![0-9]+]])
 // CHECK-NEXT:      #dbg_value(i32 [[ARG]], [[META17:![0-9]+]], 
!DIExpression(), [[META20]])
-// CHECK-NEXT:    [[TMP0:%.*]] = tail call i1 @llvm.type.test(ptr [[FN]], 
metadata !"_ZTSFvu3i32E.normalized"), !dbg [[DBG21:![0-9]+]], !nosanitize 
[[META22:![0-9]+]]
-// CHECK-NEXT:    br i1 [[TMP0]], label %[[CONT:.*]], label %[[TRAP:.*]], !dbg 
[[DBG21]], !prof [[PROF23:![0-9]+]], !nosanitize [[META22]]
+// CHECK-NEXT:    [[TMP0:%.*]] = tail call i1 @llvm.type.test(ptr [[FN]], 
metadata !"_ZTSFvu3i32E.normalized"), !dbg [[DBG21:![0-9]+]], !nosanitize 
[[META25:![0-9]+]]
+// CHECK-NEXT:    br i1 [[TMP0]], label %[[CONT:.*]], label %[[TRAP:.*]], !dbg 
[[DBG21]], !prof [[PROF26:![0-9]+]], !nosanitize [[META25]]
 // CHECK:       [[TRAP]]:
-// CHECK-NEXT:    tail call void @llvm.ubsantrap(i8 2) #[[ATTR3:[0-9]+]], !dbg 
[[DBG21]], !nosanitize [[META22]]
-// CHECK-NEXT:    unreachable, !dbg [[DBG21]], !nosanitize [[META22]]
+// CHECK-NEXT:    tail call void @llvm.ubsantrap(i8 2) #[[ATTR3:[0-9]+]], !dbg 
[[DBG21]], !nosanitize [[META25]]
+// CHECK-NEXT:    unreachable, !dbg [[DBG21]], !nosanitize [[META25]]
 // CHECK:       [[CONT]]:
-// CHECK-NEXT:    tail call void [[FN]](i32 noundef [[ARG]]) 
#[[ATTR4:[0-9]+]], !dbg [[DBG21]]
-// CHECK-NEXT:    ret void, !dbg [[DBG24:![0-9]+]]
+// CHECK-NEXT:    tail call void [[FN]](i32 noundef [[ARG]]) 
#[[ATTR4:[0-9]+]], !dbg [[DBG24:![0-9]+]]
+// CHECK-NEXT:    ret void, !dbg [[DBG27:![0-9]+]]
 //
 void foo(void (*fn)(int), int arg) {
     fn(arg);
 }
 
 // CHECK-LABEL: define dso_local void @bar(
-// CHECK-SAME: ptr noundef [[FN:%.*]], i32 noundef [[ARG1:%.*]], i32 noundef 
[[ARG2:%.*]]) local_unnamed_addr #[[ATTR0]] !dbg [[DBG25:![0-9]+]] !type 
[[META35:![0-9]+]] !type [[META36:![0-9]+]] {
+// CHECK-SAME: ptr noundef [[FN:%.*]], i32 noundef [[ARG1:%.*]], i32 noundef 
[[ARG2:%.*]]) local_unnamed_addr #[[ATTR0]] !dbg [[DBG28:![0-9]+]] !type 
[[META38:![0-9]+]] !type [[META39:![0-9]+]] {
 // CHECK-NEXT:  [[ENTRY:.*:]]
-// CHECK-NEXT:      #dbg_value(ptr [[FN]], [[META32:![0-9]+]], 
!DIExpression(), [[META37:![0-9]+]])
-// CHECK-NEXT:      #dbg_value(i32 [[ARG1]], [[META33:![0-9]+]], 
!DIExpression(), [[META37]])
-// CHECK-NEXT:      #dbg_value(i32 [[ARG2]], [[META34:![0-9]+]], 
!DIExpression(), [[META37]])
-// CHECK-NEXT:    [[TMP0:%.*]] = tail call i1 @llvm.type.test(ptr [[FN]], 
metadata !"_ZTSFvu3i32S_E.normalized"), !dbg [[DBG38:![0-9]+]], !nosanitize 
[[META22]]
-// CHECK-NEXT:    br i1 [[TMP0]], label %[[CONT:.*]], label %[[TRAP:.*]], !dbg 
[[DBG38]], !prof [[PROF23]], !nosanitize [[META22]]
+// CHECK-NEXT:      #dbg_value(ptr [[FN]], [[META35:![0-9]+]], 
!DIExpression(), [[META40:![0-9]+]])
+// CHECK-NEXT:      #dbg_value(i32 [[ARG1]], [[META36:![0-9]+]], 
!DIExpression(), [[META40]])
+// CHECK-NEXT:      #dbg_value(i32 [[ARG2]], [[META37:![0-9]+]], 
!DIExpression(), [[META40]])
+// CHECK-NEXT:    [[TMP0:%.*]] = tail call i1 @llvm.type.test(ptr [[FN]], 
metadata !"_ZTSFvu3i32S_E.normalized"), !dbg [[DBG41:![0-9]+]], !nosanitize 
[[META25]]
+// CHECK-NEXT:    br i1 [[TMP0]], label %[[CONT:.*]], label %[[TRAP:.*]], !dbg 
[[DBG41]], !prof [[PROF26]], !nosanitize [[META25]]
 // CHECK:       [[TRAP]]:
-// CHECK-NEXT:    tail call void @llvm.ubsantrap(i8 2) #[[ATTR3]], !dbg 
[[DBG38]], !nosanitize [[META22]]
-// CHECK-NEXT:    unreachable, !dbg [[DBG38]], !nosanitize [[META22]]
+// CHECK-NEXT:    tail call void @llvm.ubsantrap(i8 2) #[[ATTR3]], !dbg 
[[DBG41]], !nosanitize [[META25]]
+// CHECK-NEXT:    unreachable, !dbg [[DBG41]], !nosanitize [[META25]]
 // CHECK:       [[CONT]]:
-// CHECK-NEXT:    tail call void [[FN]](i32 noundef [[ARG1]], i32 noundef 
[[ARG2]]) #[[ATTR4]], !dbg [[DBG38]]
-// CHECK-NEXT:    ret void, !dbg [[DBG39:![0-9]+]]
+// CHECK-NEXT:    tail call void [[FN]](i32 noundef [[ARG1]], i32 noundef 
[[ARG2]]) #[[ATTR4]], !dbg [[DBG42:![0-9]+]]
+// CHECK-NEXT:    ret void, !dbg [[DBG43:![0-9]+]]
 //
 void bar(void (*fn)(int, int), int arg1, int arg2) {
     fn(arg1, arg2);
 }
 
 // CHECK-LABEL: define dso_local void @baz(
-// CHECK-SAME: ptr noundef [[FN:%.*]], i32 noundef [[ARG1:%.*]], i32 noundef 
[[ARG2:%.*]], i32 noundef [[ARG3:%.*]]) local_unnamed_addr #[[ATTR0]] !dbg 
[[DBG40:![0-9]+]] !type [[META51:![0-9]+]] !type [[META52:![0-9]+]] {
+// CHECK-SAME: ptr noundef [[FN:%.*]], i32 noundef [[ARG1:%.*]], i32 noundef 
[[ARG2:%.*]], i32 noundef [[ARG3:%.*]]) local_unnamed_addr #[[ATTR0]] !dbg 
[[DBG44:![0-9]+]] !type [[META55:![0-9]+]] !type [[META56:![0-9]+]] {
 // CHECK-NEXT:  [[ENTRY:.*:]]
-// CHECK-NEXT:      #dbg_value(ptr [[FN]], [[META47:![0-9]+]], 
!DIExpression(), [[META53:![0-9]+]])
-// CHECK-NEXT:      #dbg_value(i32 [[ARG1]], [[META48:![0-9]+]], 
!DIExpression(), [[META53]])
-// CHECK-NEXT:      #dbg_value(i32 [[ARG2]], [[META49:![0-9]+]], 
!DIExpression(), [[META53]])
-// CHECK-NEXT:      #dbg_value(i32 [[ARG3]], [[META50:![0-9]+]], 
!DIExpression(), [[META53]])
-// CHECK-NEXT:    [[TMP0:%.*]] = tail call i1 @llvm.type.test(ptr [[FN]], 
metadata !"_ZTSFvu3i32S_S_E.normalized"), !dbg [[DBG54:![0-9]+]], !nosanitize 
[[META22]]
-// CHECK-NEXT:    br i1 [[TMP0]], label %[[CONT:.*]], label %[[TRAP:.*]], !dbg 
[[DBG54]], !prof [[PROF23]], !nosanitize [[META22]]
+// CHECK-NEXT:      #dbg_value(ptr [[FN]], [[META51:![0-9]+]], 
!DIExpression(), [[META57:![0-9]+]])
+// CHECK-NEXT:      #dbg_value(i32 [[ARG1]], [[META52:![0-9]+]], 
!DIExpression(), [[META57]])
+// CHECK-NEXT:      #dbg_value(i32 [[ARG2]], [[META53:![0-9]+]], 
!DIExpression(), [[META57]])
+// CHECK-NEXT:      #dbg_value(i32 [[ARG3]], [[META54:![0-9]+]], 
!DIExpression(), [[META57]])
+// CHECK-NEXT:    [[TMP0:%.*]] = tail call i1 @llvm.type.test(ptr [[FN]], 
metadata !"_ZTSFvu3i32S_S_E.normalized"), !dbg [[DBG58:![0-9]+]], !nosanitize 
[[META25]]
+// CHECK-NEXT:    br i1 [[TMP0]], label %[[CONT:.*]], label %[[TRAP:.*]], !dbg 
[[DBG58]], !prof [[PROF26]], !nosanitize [[META25]]
 // CHECK:       [[TRAP]]:
-// CHECK-NEXT:    tail call void @llvm.ubsantrap(i8 2) #[[ATTR3]], !dbg 
[[DBG54]], !nosanitize [[META22]]
-// CHECK-NEXT:    unreachable, !dbg [[DBG54]], !nosanitize [[META22]]
+// CHECK-NEXT:    tail call void @llvm.ubsantrap(i8 2) #[[ATTR3]], !dbg 
[[DBG58]], !nosanitize [[META25]]
+// CHECK-NEXT:    unreachable, !dbg [[DBG58]], !nosanitize [[META25]]
 // CHECK:       [[CONT]]:
-// CHECK-NEXT:    tail call void [[FN]](i32 noundef [[ARG1]], i32 noundef 
[[ARG2]], i32 noundef [[ARG3]]) #[[ATTR4]], !dbg [[DBG54]]
-// CHECK-NEXT:    ret void, !dbg [[DBG55:![0-9]+]]
+// CHECK-NEXT:    tail call void [[FN]](i32 noundef [[ARG1]], i32 noundef 
[[ARG2]], i32 noundef [[ARG3]]) #[[ATTR4]], !dbg [[DBG59:![0-9]+]]
+// CHECK-NEXT:    ret void, !dbg [[DBG60:![0-9]+]]
 //
 void baz(void (*fn)(int, int, int), int arg1, int arg2, int arg3) {
     fn(arg1, arg2, arg3);
@@ -81,39 +81,44 @@ void baz(void (*fn)(int, int, int), int arg1, int arg2, int 
arg3) {
 // CHECK: [[META18]] = !{i64 0, !"_ZTSFvPFvu3i32ES_E.normalized"}
 // CHECK: [[META19]] = !{i64 0, !"_ZTSFvPvu3i32E.normalized.generalized"}
 // CHECK: [[META20]] = !DILocation(line: 0, scope: [[DBG7]])
-// CHECK: [[DBG21]] = !DILocation(line: 25, column: 5, scope: [[DBG7]])
-// CHECK: [[META22]] = !{}
-// CHECK: [[PROF23]] = !{!"branch_weights", i32 1048575, i32 1}
-// CHECK: [[DBG24]] = !DILocation(line: 26, column: 1, scope: [[DBG7]])
-// CHECK: [[DBG25]] = distinct !DISubprogram(name: "bar", scope: [[META8]], 
file: [[META8]], line: 43, type: [[META26:![0-9]+]], scopeLine: 43, flags: 
DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: 
[[META0]], retainedNodes: [[META31:![0-9]+]])
-// CHECK: [[META26]] = !DISubroutineType(types: [[META27:![0-9]+]])
-// CHECK: [[META27]] = !{null, [[META28:![0-9]+]], [[META14]], [[META14]]}
-// CHECK: [[META28]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: 
[[META29:![0-9]+]], size: 64)
+// CHECK: [[DBG21]] = !DILocation(line: 0, scope: [[META22:![0-9]+]], 
inlinedAt: [[DBG24]])
+// CHECK: [[META22]] = distinct !DISubprogram(name: "__ubsan_check_cfi_icall", 
scope: [[META8]], file: [[META8]], type: [[META23:![0-9]+]], flags: 
DIFlagArtificial, spFlags: DISPFlagDefinition, unit: [[META0]])
+// CHECK: [[META23]] = !DISubroutineType(types: null)
+// CHECK: [[DBG24]] = !DILocation(line: 25, column: 5, scope: [[DBG7]])
+// CHECK: [[META25]] = !{}
+// CHECK: [[PROF26]] = !{!"branch_weights", i32 1048575, i32 1}
+// CHECK: [[DBG27]] = !DILocation(line: 26, column: 1, scope: [[DBG7]])
+// CHECK: [[DBG28]] = distinct !DISubprogram(name: "bar", scope: [[META8]], 
file: [[META8]], line: 43, type: [[META29:![0-9]+]], scopeLine: 43, flags: 
DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: 
[[META0]], retainedNodes: [[META34:![0-9]+]])
 // CHECK: [[META29]] = !DISubroutineType(types: [[META30:![0-9]+]])
-// CHECK: [[META30]] = !{null, [[META14]], [[META14]]}
-// CHECK: [[META31]] = !{[[META32]], [[META33]], [[META34]]}
-// CHECK: [[META32]] = !DILocalVariable(name: "fn", arg: 1, scope: [[DBG25]], 
file: [[META8]], line: 43, type: [[META28]])
-// CHECK: [[META33]] = !DILocalVariable(name: "arg1", arg: 2, scope: 
[[DBG25]], file: [[META8]], line: 43, type: [[META14]])
-// CHECK: [[META34]] = !DILocalVariable(name: "arg2", arg: 3, scope: 
[[DBG25]], file: [[META8]], line: 43, type: [[META14]])
-// CHECK: [[META35]] = !{i64 0, !"_ZTSFvPFvu3i32S_ES_S_E.normalized"}
-// CHECK: [[META36]] = !{i64 0, !"_ZTSFvPvu3i32S0_E.normalized.generalized"}
-// CHECK: [[META37]] = !DILocation(line: 0, scope: [[DBG25]])
-// CHECK: [[DBG38]] = !DILocation(line: 44, column: 5, scope: [[DBG25]])
-// CHECK: [[DBG39]] = !DILocation(line: 45, column: 1, scope: [[DBG25]])
-// CHECK: [[DBG40]] = distinct !DISubprogram(name: "baz", scope: [[META8]], 
file: [[META8]], line: 63, type: [[META41:![0-9]+]], scopeLine: 63, flags: 
DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: 
[[META0]], retainedNodes: [[META46:![0-9]+]])
-// CHECK: [[META41]] = !DISubroutineType(types: [[META42:![0-9]+]])
-// CHECK: [[META42]] = !{null, [[META43:![0-9]+]], [[META14]], [[META14]], 
[[META14]]}
-// CHECK: [[META43]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: 
[[META44:![0-9]+]], size: 64)
-// CHECK: [[META44]] = !DISubroutineType(types: [[META45:![0-9]+]])
-// CHECK: [[META45]] = !{null, [[META14]], [[META14]], [[META14]]}
-// CHECK: [[META46]] = !{[[META47]], [[META48]], [[META49]], [[META50]]}
-// CHECK: [[META47]] = !DILocalVariable(name: "fn", arg: 1, scope: [[DBG40]], 
file: [[META8]], line: 63, type: [[META43]])
-// CHECK: [[META48]] = !DILocalVariable(name: "arg1", arg: 2, scope: 
[[DBG40]], file: [[META8]], line: 63, type: [[META14]])
-// CHECK: [[META49]] = !DILocalVariable(name: "arg2", arg: 3, scope: 
[[DBG40]], file: [[META8]], line: 63, type: [[META14]])
-// CHECK: [[META50]] = !DILocalVariable(name: "arg3", arg: 4, scope: 
[[DBG40]], file: [[META8]], line: 63, type: [[META14]])
-// CHECK: [[META51]] = !{i64 0, !"_ZTSFvPFvu3i32S_S_ES_S_S_E.normalized"}
-// CHECK: [[META52]] = !{i64 0, !"_ZTSFvPvu3i32S0_S0_E.normalized.generalized"}
-// CHECK: [[META53]] = !DILocation(line: 0, scope: [[DBG40]])
-// CHECK: [[DBG54]] = !DILocation(line: 64, column: 5, scope: [[DBG40]])
-// CHECK: [[DBG55]] = !DILocation(line: 65, column: 1, scope: [[DBG40]])
+// CHECK: [[META30]] = !{null, [[META31:![0-9]+]], [[META14]], [[META14]]}
+// CHECK: [[META31]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: 
[[META32:![0-9]+]], size: 64)
+// CHECK: [[META32]] = !DISubroutineType(types: [[META33:![0-9]+]])
+// CHECK: [[META33]] = !{null, [[META14]], [[META14]]}
+// CHECK: [[META34]] = !{[[META35]], [[META36]], [[META37]]}
+// CHECK: [[META35]] = !DILocalVariable(name: "fn", arg: 1, scope: [[DBG28]], 
file: [[META8]], line: 43, type: [[META31]])
+// CHECK: [[META36]] = !DILocalVariable(name: "arg1", arg: 2, scope: 
[[DBG28]], file: [[META8]], line: 43, type: [[META14]])
+// CHECK: [[META37]] = !DILocalVariable(name: "arg2", arg: 3, scope: 
[[DBG28]], file: [[META8]], line: 43, type: [[META14]])
+// CHECK: [[META38]] = !{i64 0, !"_ZTSFvPFvu3i32S_ES_S_E.normalized"}
+// CHECK: [[META39]] = !{i64 0, !"_ZTSFvPvu3i32S0_E.normalized.generalized"}
+// CHECK: [[META40]] = !DILocation(line: 0, scope: [[DBG28]])
+// CHECK: [[DBG41]] = !DILocation(line: 0, scope: [[META22]], inlinedAt: 
[[DBG42]])
+// CHECK: [[DBG42]] = !DILocation(line: 44, column: 5, scope: [[DBG28]])
+// CHECK: [[DBG43]] = !DILocation(line: 45, column: 1, scope: [[DBG28]])
+// CHECK: [[DBG44]] = distinct !DISubprogram(name: "baz", scope: [[META8]], 
file: [[META8]], line: 63, type: [[META45:![0-9]+]], scopeLine: 63, flags: 
DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: 
[[META0]], retainedNodes: [[META50:![0-9]+]])
+// CHECK: [[META45]] = !DISubroutineType(types: [[META46:![0-9]+]])
+// CHECK: [[META46]] = !{null, [[META47:![0-9]+]], [[META14]], [[META14]], 
[[META14]]}
+// CHECK: [[META47]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: 
[[META48:![0-9]+]], size: 64)
+// CHECK: [[META48]] = !DISubroutineType(types: [[META49:![0-9]+]])
+// CHECK: [[META49]] = !{null, [[META14]], [[META14]], [[META14]]}
+// CHECK: [[META50]] = !{[[META51]], [[META52]], [[META53]], [[META54]]}
+// CHECK: [[META51]] = !DILocalVariable(name: "fn", arg: 1, scope: [[DBG44]], 
file: [[META8]], line: 63, type: [[META47]])
+// CHECK: [[META52]] = !DILocalVariable(name: "arg1", arg: 2, scope: 
[[DBG44]], file: [[META8]], line: 63, type: [[META14]])
+// CHECK: [[META53]] = !DILocalVariable(name: "arg2", arg: 3, scope: 
[[DBG44]], file: [[META8]], line: 63, type: [[META14]])
+// CHECK: [[META54]] = !DILocalVariable(name: "arg3", arg: 4, scope: 
[[DBG44]], file: [[META8]], line: 63, type: [[META14]])
+// CHECK: [[META55]] = !{i64 0, !"_ZTSFvPFvu3i32S_S_ES_S_S_E.normalized"}
+// CHECK: [[META56]] = !{i64 0, !"_ZTSFvPvu3i32S0_S0_E.normalized.generalized"}
+// CHECK: [[META57]] = !DILocation(line: 0, scope: [[DBG44]])
+// CHECK: [[DBG58]] = !DILocation(line: 0, scope: [[META22]], inlinedAt: 
[[DBG59]])
+// CHECK: [[DBG59]] = !DILocation(line: 64, column: 5, scope: [[DBG44]])
+// CHECK: [[DBG60]] = !DILocation(line: 65, column: 1, scope: [[DBG44]])
 //.


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to