Skip to content

Commit 5a510a3

Browse files
committed
Use ordinal for label if unique
1 parent 81ecf62 commit 5a510a3

File tree

6 files changed

+52
-20
lines changed

6 files changed

+52
-20
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6421,9 +6421,7 @@ CodeGenFunction::LexicalScope::~LexicalScope() {
64216421
}
64226422
}
64236423

6424-
llvm::DILocation *CodeGenFunction::SanitizerAnnotateDebugInfo(
6425-
ArrayRef<SanitizerKind::SanitizerOrdinal> Ordinals,
6426-
SanitizerHandler Handler) {
6424+
static std::string SanitizerHandlerToCheckLabel(SanitizerHandler Handler) {
64276425
std::string Label;
64286426
switch (Handler) {
64296427
#define SANITIZER_CHECK(Enum, Name, Version) \
@@ -6435,10 +6433,44 @@ llvm::DILocation *CodeGenFunction::SanitizerAnnotateDebugInfo(
64356433
#undef SANITIZER_CHECK
64366434
};
64376435

6436+
// Label doesn't require sanitization
6437+
6438+
return Label;
6439+
}
6440+
6441+
static std::string
6442+
SanitizerOrdinalToCheckLabel(SanitizerKind::SanitizerOrdinal Ordinal) {
6443+
std::string Label;
6444+
switch (Ordinal) {
6445+
#define SANITIZER(NAME, ID) \
6446+
case SanitizerKind::SO_##ID: \
6447+
Label = "__ubsan_check_" NAME; \
6448+
break;
6449+
#include "clang/Basic/Sanitizers.def"
6450+
default:
6451+
llvm_unreachable("unexpected sanitizer kind");
6452+
}
6453+
6454+
// Sanitize label (convert hyphens to underscores; also futureproof against
6455+
// non-alpha)
6456+
for (unsigned int i = 0; i < Label.length(); i++)
6457+
if (!std::isalpha(Label[i]))
6458+
Label[i] = '_';
6459+
6460+
return Label;
6461+
}
6462+
6463+
llvm::DILocation *CodeGenFunction::SanitizerAnnotateDebugInfo(
6464+
ArrayRef<SanitizerKind::SanitizerOrdinal> Ordinals,
6465+
SanitizerHandler Handler) {
6466+
std::string Label;
6467+
if (Ordinals.size() == 1)
6468+
Label = SanitizerOrdinalToCheckLabel(Ordinals[0]);
6469+
else
6470+
Label = SanitizerHandlerToCheckLabel(Handler);
6471+
64386472
llvm::DILocation *CheckDI = Builder.getCurrentDebugLocation();
64396473

6440-
// TODO: the annotation could be more precise e.g.,
6441-
// use the ordinal name if there is only one ordinal
64426474
for (auto Ord : Ordinals) {
64436475
// TODO: deprecate ClArrayBoundsPseudoFn
64446476
if (((ClArrayBoundsPseudoFn && Ord == SanitizerKind::SO_ArrayBounds) ||
@@ -6463,4 +6495,4 @@ SanitizerDebugLocation::SanitizerDebugLocation(
64636495
SanitizerDebugLocation::~SanitizerDebugLocation() {
64646496
assert(CGF->IsSanitizerScope);
64656497
CGF->IsSanitizerScope = false;
6466-
}
6498+
}

clang/test/CodeGen/bounds-checking-debuginfo.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ double f1(int b, int i) {
6868

6969
//.
7070
// CHECK-TRAP: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C11, file: [[META1:![0-9]+]], isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
71-
// CHECK-TRAP: [[META1]] = !DIFile(filename: "<stdin>", directory: {{.*}})
71+
// CHECK-TRAP: [[META1]] = !DIFile(filename: "{{.*}}<stdin>", directory: {{.*}})
7272
// CHECK-TRAP: [[DBG4]] = distinct !DISubprogram(name: "f1", scope: [[META5:![0-9]+]], file: [[META5]], line: 63, type: [[META6:![0-9]+]], scopeLine: 63, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: [[META0]], retainedNodes: [[META10]])
7373
// CHECK-TRAP: [[META5]] = !DIFile(filename: "{{.*}}bounds-checking-debuginfo.c", directory: {{.*}})
7474
// CHECK-TRAP: [[META6]] = !DISubroutineType(types: [[META7:![0-9]+]])
@@ -89,14 +89,14 @@ double f1(int b, int i) {
8989
// CHECK-TRAP: [[DBG21]] = !DILocation(line: 65, column: 3, scope: [[DBG4]])
9090
// CHECK-TRAP: [[DBG22]] = !DILocation(line: 66, column: 12, scope: [[DBG4]])
9191
// CHECK-TRAP: [[DBG23]] = !DILocation(line: 0, scope: [[META24:![0-9]+]], inlinedAt: [[DBG26]])
92-
// CHECK-TRAP: [[META24]] = distinct !DISubprogram(name: "__ubsan_check_out_of_bounds", scope: [[META5]], file: [[META5]], type: [[META25:![0-9]+]], flags: DIFlagArtificial, spFlags: DISPFlagDefinition, unit: [[META0]])
92+
// CHECK-TRAP: [[META24]] = distinct !DISubprogram(name: "__ubsan_check_array_bounds", scope: [[META5]], file: [[META5]], type: [[META25:![0-9]+]], flags: DIFlagArtificial, spFlags: DISPFlagDefinition, unit: [[META0]])
9393
// CHECK-TRAP: [[META25]] = !DISubroutineType(types: null)
9494
// CHECK-TRAP: [[DBG26]] = !DILocation(line: 66, column: 10, scope: [[DBG4]])
9595
// CHECK-TRAP: [[PROF27]] = !{!"branch_weights", i32 1048575, i32 1}
9696
// CHECK-TRAP: [[DBG28]] = !DILocation(line: 66, column: 3, scope: [[DBG4]])
9797
//.
9898
// CHECK-NOTRAP: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C11, file: [[META1:![0-9]+]], isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
99-
// CHECK-NOTRAP: [[META1]] = !DIFile(filename: "<stdin>", directory: {{.*}})
99+
// CHECK-NOTRAP: [[META1]] = !DIFile(filename: "{{.*}}<stdin>", directory: {{.*}})
100100
// CHECK-NOTRAP: [[DBG4]] = distinct !DISubprogram(name: "f1", scope: [[META5:![0-9]+]], file: [[META5]], line: 63, type: [[META6:![0-9]+]], scopeLine: 63, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: [[META0]], retainedNodes: [[META10]])
101101
// CHECK-NOTRAP: [[META5]] = !DIFile(filename: "{{.*}}bounds-checking-debuginfo.c", directory: {{.*}})
102102
// CHECK-NOTRAP: [[META6]] = !DISubroutineType(types: [[META7:![0-9]+]])
@@ -117,7 +117,7 @@ double f1(int b, int i) {
117117
// CHECK-NOTRAP: [[DBG21]] = !DILocation(line: 65, column: 3, scope: [[DBG4]])
118118
// CHECK-NOTRAP: [[DBG22]] = !DILocation(line: 66, column: 12, scope: [[DBG4]])
119119
// CHECK-NOTRAP: [[DBG23]] = !DILocation(line: 0, scope: [[META24:![0-9]+]], inlinedAt: [[DBG26]])
120-
// CHECK-NOTRAP: [[META24]] = distinct !DISubprogram(name: "__ubsan_check_out_of_bounds", scope: [[META5]], file: [[META5]], type: [[META25:![0-9]+]], flags: DIFlagArtificial, spFlags: DISPFlagDefinition, unit: [[META0]])
120+
// CHECK-NOTRAP: [[META24]] = distinct !DISubprogram(name: "__ubsan_check_array_bounds", scope: [[META5]], file: [[META5]], type: [[META25:![0-9]+]], flags: DIFlagArtificial, spFlags: DISPFlagDefinition, unit: [[META0]])
121121
// CHECK-NOTRAP: [[META25]] = !DISubroutineType(types: null)
122122
// CHECK-NOTRAP: [[DBG26]] = !DILocation(line: 66, column: 10, scope: [[DBG4]])
123123
// CHECK-NOTRAP: [[PROF27]] = !{!"branch_weights", i32 1048575, i32 1}

clang/test/CodeGen/cfi-check-fail-debuginfo.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void caller(void (*f)(void)) {
2424
}
2525
//.
2626
// CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C11, file: [[META1:![0-9]+]], isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
27-
// CHECK: [[META1]] = !DIFile(filename: "<stdin>", directory: {{.*}})
27+
// CHECK: [[META1]] = !DIFile(filename: "{{.*}}<stdin>", directory: {{.*}})
2828
// CHECK: [[DBG7]] = distinct !DISubprogram(name: "caller", scope: [[META8:![0-9]+]], file: [[META8]], line: 22, type: [[META9:![0-9]+]], scopeLine: 22, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: [[META0]], retainedNodes: [[META14:![0-9]+]])
2929
// CHECK: [[META8]] = !DIFile(filename: "{{.*}}cfi-check-fail-debuginfo.c", directory: {{.*}})
3030
// CHECK: [[META9]] = !DISubroutineType(types: [[META10:![0-9]+]])
@@ -39,7 +39,7 @@ void caller(void (*f)(void)) {
3939
// CHECK: [[META18]] = !{i64 0, i64 2451761621477796417}
4040
// CHECK: [[META19]] = !DILocation(line: 0, scope: [[DBG7]])
4141
// CHECK: [[DBG20]] = !DILocation(line: 0, scope: [[META21:![0-9]+]], inlinedAt: [[DBG23]])
42-
// CHECK: [[META21]] = distinct !DISubprogram(name: "__ubsan_check_cfi_check_fail", scope: [[META8]], file: [[META8]], type: [[META22:![0-9]+]], flags: DIFlagArtificial, spFlags: DISPFlagDefinition, unit: [[META0]])
42+
// CHECK: [[META21]] = distinct !DISubprogram(name: "__ubsan_check_cfi_icall", scope: [[META8]], file: [[META8]], type: [[META22:![0-9]+]], flags: DIFlagArtificial, spFlags: DISPFlagDefinition, unit: [[META0]])
4343
// CHECK: [[META22]] = !DISubroutineType(types: null)
4444
// CHECK: [[DBG23]] = !DILocation(line: 23, column: 3, scope: [[DBG7]])
4545
// CHECK: [[META24]] = !{}

clang/test/CodeGen/cfi-icall-generalize-debuginfo.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void g(int** (*fp)(const char *, const char **)) {
5555

5656
//.
5757
// UNGENERALIZED: [[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)
58-
// UNGENERALIZED: [[META1]] = !DIFile(filename: "<stdin>", directory: {{.*}})
58+
// UNGENERALIZED: [[META1]] = !DIFile(filename: "{{.*}}<stdin>", directory: {{.*}})
5959
// UNGENERALIZED: [[META2]] = !{[[META3:![0-9]+]]}
6060
// UNGENERALIZED: [[META3]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: [[META4:![0-9]+]], size: 64)
6161
// UNGENERALIZED: [[META4]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: [[META5:![0-9]+]], size: 64)
@@ -85,15 +85,15 @@ void g(int** (*fp)(const char *, const char **)) {
8585
// UNGENERALIZED: [[META32]] = !{i64 0, !"_ZTSFvPvE.generalized"}
8686
// UNGENERALIZED: [[META33]] = !DILocation(line: 0, scope: [[DBG25]])
8787
// UNGENERALIZED: [[DBG34]] = !DILocation(line: 0, scope: [[META35:![0-9]+]], inlinedAt: [[DBG37]])
88-
// UNGENERALIZED: [[META35]] = distinct !DISubprogram(name: "__ubsan_check_cfi_check_fail", scope: [[META11]], file: [[META11]], type: [[META36:![0-9]+]], flags: DIFlagArtificial, spFlags: DISPFlagDefinition, unit: [[META0]])
88+
// UNGENERALIZED: [[META35]] = distinct !DISubprogram(name: "__ubsan_check_cfi_icall", scope: [[META11]], file: [[META11]], type: [[META36:![0-9]+]], flags: DIFlagArtificial, spFlags: DISPFlagDefinition, unit: [[META0]])
8989
// UNGENERALIZED: [[META36]] = !DISubroutineType(types: null)
9090
// UNGENERALIZED: [[DBG37]] = !DILocation(line: 53, column: 3, scope: [[DBG25]])
9191
// UNGENERALIZED: [[META38]] = !{}
9292
// UNGENERALIZED: [[PROF39]] = !{!"branch_weights", i32 1048575, i32 1}
9393
// UNGENERALIZED: [[DBG40]] = !DILocation(line: 54, column: 1, scope: [[DBG25]])
9494
//.
9595
// 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)
96-
// GENERALIZED: [[META1]] = !DIFile(filename: "<stdin>", directory: {{.*}})
96+
// GENERALIZED: [[META1]] = !DIFile(filename: "{{.*}}<stdin>", directory: {{.*}})
9797
// GENERALIZED: [[META2]] = !{[[META3:![0-9]+]]}
9898
// GENERALIZED: [[META3]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: [[META4:![0-9]+]], size: 64)
9999
// GENERALIZED: [[META4]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: [[META5:![0-9]+]], size: 64)
@@ -123,7 +123,7 @@ void g(int** (*fp)(const char *, const char **)) {
123123
// GENERALIZED: [[META32]] = !{i64 0, !"_ZTSFvPvE.generalized"}
124124
// GENERALIZED: [[META33]] = !DILocation(line: 0, scope: [[DBG25]])
125125
// GENERALIZED: [[DBG34]] = !DILocation(line: 0, scope: [[META35:![0-9]+]], inlinedAt: [[DBG37]])
126-
// GENERALIZED: [[META35]] = distinct !DISubprogram(name: "__ubsan_check_cfi_check_fail", scope: [[META11]], file: [[META11]], type: [[META36:![0-9]+]], flags: DIFlagArtificial, spFlags: DISPFlagDefinition, unit: [[META0]])
126+
// GENERALIZED: [[META35]] = distinct !DISubprogram(name: "__ubsan_check_cfi_icall", scope: [[META11]], file: [[META11]], type: [[META36:![0-9]+]], flags: DIFlagArtificial, spFlags: DISPFlagDefinition, unit: [[META0]])
127127
// GENERALIZED: [[META36]] = !DISubroutineType(types: null)
128128
// GENERALIZED: [[DBG37]] = !DILocation(line: 53, column: 3, scope: [[DBG25]])
129129
// GENERALIZED: [[META38]] = !{}

clang/test/CodeGen/cfi-icall-normalize2-debuginfo.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void baz(void (*fn)(int, int, int), int arg1, int arg2, int arg3) {
6666

6767
//.
6868
// CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C11, file: [[META1:![0-9]+]], isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
69-
// CHECK: [[META1]] = !DIFile(filename: "<stdin>", directory: {{.*}})
69+
// CHECK: [[META1]] = !DIFile(filename: "{{.*}}<stdin>", directory: {{.*}})
7070
// CHECK: [[DBG7]] = distinct !DISubprogram(name: "foo", scope: [[META8:![0-9]+]], file: [[META8]], line: 24, type: [[META9:![0-9]+]], scopeLine: 24, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: [[META0]], retainedNodes: [[META15:![0-9]+]])
7171
// CHECK: [[META8]] = !DIFile(filename: "{{.*}}cfi-icall-normalize2-debuginfo.c", directory: {{.*}})
7272
// CHECK: [[META9]] = !DISubroutineType(types: [[META10:![0-9]+]])
@@ -82,7 +82,7 @@ void baz(void (*fn)(int, int, int), int arg1, int arg2, int arg3) {
8282
// CHECK: [[META19]] = !{i64 0, !"_ZTSFvPvu3i32E.normalized.generalized"}
8383
// CHECK: [[META20]] = !DILocation(line: 0, scope: [[DBG7]])
8484
// CHECK: [[DBG21]] = !DILocation(line: 0, scope: [[META22:![0-9]+]], inlinedAt: [[DBG24]])
85-
// CHECK: [[META22]] = distinct !DISubprogram(name: "__ubsan_check_cfi_check_fail", scope: [[META8]], file: [[META8]], type: [[META23:![0-9]+]], flags: DIFlagArtificial, spFlags: DISPFlagDefinition, unit: [[META0]])
85+
// CHECK: [[META22]] = distinct !DISubprogram(name: "__ubsan_check_cfi_icall", scope: [[META8]], file: [[META8]], type: [[META23:![0-9]+]], flags: DIFlagArtificial, spFlags: DISPFlagDefinition, unit: [[META0]])
8686
// CHECK: [[META23]] = !DISubroutineType(types: null)
8787
// CHECK: [[DBG24]] = !DILocation(line: 25, column: 5, scope: [[DBG7]])
8888
// CHECK: [[META25]] = !{}

clang/test/CodeGen/ubsan-function-debuginfo.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void call_no_prototype(void (*f)()) { f(); }
3737
void call_prototype(void (*f)(void)) { f(); }
3838
//.
3939
// CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C11, file: [[META1:![0-9]+]], isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
40-
// CHECK: [[META1]] = !DIFile(filename: "<stdin>", directory: {{.*}})
40+
// CHECK: [[META1]] = !DIFile(filename: "{{.*}}<stdin>", directory: {{.*}})
4141
// CHECK: [[DBG5]] = distinct !DISubprogram(name: "call_no_prototype", scope: [[META6:![0-9]+]], file: [[META6]], line: 14, type: [[META7:![0-9]+]], scopeLine: 14, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: [[META0]], retainedNodes: [[META12:![0-9]+]])
4242
// CHECK: [[META6]] = !DIFile(filename: "{{.*}}ubsan-function-debuginfo.c", directory: {{.*}})
4343
// CHECK: [[META7]] = !DISubroutineType(types: [[META8:![0-9]+]])
@@ -62,7 +62,7 @@ void call_prototype(void (*f)(void)) { f(); }
6262
// CHECK: [[META26]] = !{i32 -1056584962, i32 -747727454}
6363
// CHECK: [[META27]] = !DILocation(line: 0, scope: [[DBG18]])
6464
// CHECK: [[DBG28]] = !DILocation(line: 0, scope: [[META29:![0-9]+]], inlinedAt: [[DBG31]])
65-
// CHECK: [[META29]] = distinct !DISubprogram(name: "__ubsan_check_function_type_mismatch", scope: [[META6]], file: [[META6]], type: [[META30:![0-9]+]], flags: DIFlagArtificial, spFlags: DISPFlagDefinition, unit: [[META0]])
65+
// CHECK: [[META29]] = distinct !DISubprogram(name: "__ubsan_check_function", scope: [[META6]], file: [[META6]], type: [[META30:![0-9]+]], flags: DIFlagArtificial, spFlags: DISPFlagDefinition, unit: [[META0]])
6666
// CHECK: [[META30]] = !DISubroutineType(types: null)
6767
// CHECK: [[DBG31]] = !DILocation(line: 37, column: 40, scope: [[DBG18]])
6868
// CHECK: [[META32]] = !{}

0 commit comments

Comments
 (0)