Skip to content

Commit 58d76a6

Browse files
committed
ApplyTrapDI and stdin cleanup
1 parent 6f82a48 commit 58d76a6

7 files changed

+109
-116
lines changed

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3995,8 +3995,6 @@ void CodeGenFunction::EmitCfiCheckFail() {
39953995
{Addr, AllVtables}),
39963996
IntPtrTy);
39973997

3998-
// TODO: the instructions above are not annotated with debug info. It is
3999-
// inconvenient to do so because we have not determined SanitizerKind yet.
40003998
const std::pair<int, SanitizerKind::SanitizerOrdinal> CheckKinds[] = {
40013999
{CFITCK_VCall, SanitizerKind::SO_CFIVCall},
40024000
{CFITCK_NVCall, SanitizerKind::SO_CFINVCall},
@@ -4008,7 +4006,8 @@ void CodeGenFunction::EmitCfiCheckFail() {
40084006
int Kind = CheckKindOrdinalPair.first;
40094007
SanitizerKind::SanitizerOrdinal Ordinal = CheckKindOrdinalPair.second;
40104008

4011-
ApplyDebugLocation ApplyTrapDI(*this, SanitizerAnnotateDebugInfo(Ordinal));
4009+
// TODO: we could apply SanitizerAnnotateDebugInfo(Ordinal) instead of
4010+
// relying on the SanitizerScope with all CFI ordinals
40124011

40134012
llvm::Value *Cond =
40144013
Builder.CreateICmpNE(CheckKind, llvm::ConstantInt::get(Int8Ty, Kind));

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

Lines changed: 2 additions & 2 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]+]])
@@ -96,7 +96,7 @@ double f1(int b, int i) {
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]+]])

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@
1010
// 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]+]] {
1111
// CHECK-NEXT: [[ENTRY:.*:]]
1212
// CHECK-NEXT: #dbg_value(ptr [[F]], [[META15:![0-9]+]], !DIExpression(), [[META19:![0-9]+]])
13-
// CHECK-NEXT: [[TMP0:%.*]] = tail call i1 @llvm.type.test(ptr [[F]], metadata !"_ZTSFvvE"), !dbg [[DBG20:![0-9]+]], !nosanitize [[META25:![0-9]+]]
14-
// CHECK-NEXT: br i1 [[TMP0]], label %[[CFI_CONT:.*]], label %[[CFI_SLOWPATH:.*]], !dbg [[DBG20]], !prof [[PROF26:![0-9]+]], !nosanitize [[META25]]
13+
// CHECK-NEXT: [[TMP0:%.*]] = tail call i1 @llvm.type.test(ptr [[F]], metadata !"_ZTSFvvE"), !dbg [[DBG20:![0-9]+]], !nosanitize [[META24:![0-9]+]]
14+
// CHECK-NEXT: br i1 [[TMP0]], label %[[CFI_CONT:.*]], label %[[CFI_SLOWPATH:.*]], !dbg [[DBG20]], !prof [[PROF25:![0-9]+]], !nosanitize [[META24]]
1515
// CHECK: [[CFI_SLOWPATH]]:
16-
// CHECK-NEXT: tail call void @__cfi_slowpath(i64 9080559750644022485, ptr [[F]]) #[[ATTR6:[0-9]+]], !dbg [[DBG20]], !nosanitize [[META25]]
17-
// CHECK-NEXT: br label %[[CFI_CONT]], !dbg [[DBG20]], !nosanitize [[META25]]
16+
// CHECK-NEXT: tail call void @__cfi_slowpath(i64 9080559750644022485, ptr [[F]]) #[[ATTR6:[0-9]+]], !dbg [[DBG20]], !nosanitize [[META24]]
17+
// CHECK-NEXT: br label %[[CFI_CONT]], !dbg [[DBG20]], !nosanitize [[META24]]
1818
// CHECK: [[CFI_CONT]]:
19-
// CHECK-NEXT: tail call void [[F]]() #[[ATTR6]], !dbg [[DBG24:![0-9]+]]
20-
// CHECK-NEXT: ret void, !dbg [[DBG27:![0-9]+]]
19+
// CHECK-NEXT: tail call void [[F]]() #[[ATTR6]], !dbg [[DBG23:![0-9]+]]
20+
// CHECK-NEXT: ret void, !dbg [[DBG26:![0-9]+]]
2121
//
2222
void caller(void (*f)(void)) {
2323
f();
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]+]])
@@ -38,12 +38,11 @@ void caller(void (*f)(void)) {
3838
// CHECK: [[META17]] = !{i64 0, !"_ZTSFvPvE.generalized"}
3939
// CHECK: [[META18]] = !{i64 0, i64 2451761621477796417}
4040
// CHECK: [[META19]] = !DILocation(line: 0, scope: [[DBG7]])
41-
// CHECK: [[DBG20]] = !DILocation(line: 0, scope: [[META21:![0-9]+]], inlinedAt: [[META23:![0-9]+]])
41+
// CHECK: [[DBG20]] = !DILocation(line: 0, scope: [[META21:![0-9]+]], inlinedAt: [[DBG23]])
4242
// CHECK: [[META21]] = distinct !DISubprogram(name: "__ubsan_check_singularity", scope: [[META8]], file: [[META8]], type: [[META22:![0-9]+]], flags: DIFlagArtificial, spFlags: DISPFlagDefinition, unit: [[META0]])
4343
// CHECK: [[META22]] = !DISubroutineType(types: null)
44-
// CHECK: [[META23]] = !DILocation(line: 0, scope: [[META21]], inlinedAt: [[DBG24]])
45-
// CHECK: [[DBG24]] = !DILocation(line: 23, column: 3, scope: [[DBG7]])
46-
// CHECK: [[META25]] = !{}
47-
// CHECK: [[PROF26]] = !{!"branch_weights", i32 1048575, i32 1}
48-
// CHECK: [[DBG27]] = !DILocation(line: 24, column: 1, scope: [[DBG7]])
44+
// CHECK: [[DBG23]] = !DILocation(line: 23, column: 3, scope: [[DBG7]])
45+
// CHECK: [[META24]] = !{}
46+
// CHECK: [[PROF25]] = !{!"branch_weights", i32 1048575, i32 1}
47+
// CHECK: [[DBG26]] = !DILocation(line: 24, column: 1, scope: [[DBG7]])
4948
//.

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

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,35 +27,35 @@ int** f(const char *a, const char **b) {
2727
// UNGENERALIZED-SAME: ptr noundef [[FP:%.*]]) local_unnamed_addr #[[ATTR1:[0-9]+]] !dbg [[DBG25:![0-9]+]] !type [[META31:![0-9]+]] !type [[META32:![0-9]+]] {
2828
// UNGENERALIZED-NEXT: [[ENTRY:.*:]]
2929
// UNGENERALIZED-NEXT: #dbg_value(ptr [[FP]], [[META30:![0-9]+]], !DIExpression(), [[META33:![0-9]+]])
30-
// UNGENERALIZED-NEXT: [[TMP0:%.*]] = tail call i1 @llvm.type.test(ptr [[FP]], metadata !"_ZTSFPPiPKcPS2_E"), !dbg [[DBG34:![0-9]+]], !nosanitize [[META39:![0-9]+]]
31-
// UNGENERALIZED-NEXT: br i1 [[TMP0]], label %[[CONT:.*]], label %[[TRAP:.*]], !dbg [[DBG34]], !prof [[PROF40:![0-9]+]], !nosanitize [[META39]]
30+
// UNGENERALIZED-NEXT: [[TMP0:%.*]] = tail call i1 @llvm.type.test(ptr [[FP]], metadata !"_ZTSFPPiPKcPS2_E"), !dbg [[DBG34:![0-9]+]], !nosanitize [[META38:![0-9]+]]
31+
// UNGENERALIZED-NEXT: br i1 [[TMP0]], label %[[CONT:.*]], label %[[TRAP:.*]], !dbg [[DBG34]], !prof [[PROF39:![0-9]+]], !nosanitize [[META38]]
3232
// UNGENERALIZED: [[TRAP]]:
33-
// UNGENERALIZED-NEXT: tail call void @llvm.ubsantrap(i8 2) #[[ATTR4:[0-9]+]], !dbg [[DBG34]], !nosanitize [[META39]]
34-
// UNGENERALIZED-NEXT: unreachable, !dbg [[DBG34]], !nosanitize [[META39]]
33+
// UNGENERALIZED-NEXT: tail call void @llvm.ubsantrap(i8 2) #[[ATTR4:[0-9]+]], !dbg [[DBG34]], !nosanitize [[META38]]
34+
// UNGENERALIZED-NEXT: unreachable, !dbg [[DBG34]], !nosanitize [[META38]]
3535
// UNGENERALIZED: [[CONT]]:
36-
// UNGENERALIZED-NEXT: [[CALL:%.*]] = tail call ptr [[FP]](ptr noundef null, ptr noundef null) #[[ATTR5:[0-9]+]], !dbg [[DBG38:![0-9]+]]
37-
// UNGENERALIZED-NEXT: ret void, !dbg [[DBG41:![0-9]+]]
36+
// UNGENERALIZED-NEXT: [[CALL:%.*]] = tail call ptr [[FP]](ptr noundef null, ptr noundef null) #[[ATTR5:[0-9]+]], !dbg [[DBG37:![0-9]+]]
37+
// UNGENERALIZED-NEXT: ret void, !dbg [[DBG40:![0-9]+]]
3838
//
3939
// GENERALIZED-LABEL: define dso_local void @g(
4040
// GENERALIZED-SAME: ptr noundef [[FP:%.*]]) local_unnamed_addr #[[ATTR1:[0-9]+]] !dbg [[DBG25:![0-9]+]] !type [[META31:![0-9]+]] !type [[META32:![0-9]+]] {
4141
// GENERALIZED-NEXT: [[ENTRY:.*:]]
4242
// GENERALIZED-NEXT: #dbg_value(ptr [[FP]], [[META30:![0-9]+]], !DIExpression(), [[META33:![0-9]+]])
43-
// GENERALIZED-NEXT: [[TMP0:%.*]] = tail call i1 @llvm.type.test(ptr [[FP]], metadata !"_ZTSFPvPKvS_E.generalized"), !dbg [[DBG34:![0-9]+]], !nosanitize [[META39:![0-9]+]]
44-
// GENERALIZED-NEXT: br i1 [[TMP0]], label %[[CONT:.*]], label %[[TRAP:.*]], !dbg [[DBG34]], !prof [[PROF40:![0-9]+]], !nosanitize [[META39]]
43+
// GENERALIZED-NEXT: [[TMP0:%.*]] = tail call i1 @llvm.type.test(ptr [[FP]], metadata !"_ZTSFPvPKvS_E.generalized"), !dbg [[DBG34:![0-9]+]], !nosanitize [[META38:![0-9]+]]
44+
// GENERALIZED-NEXT: br i1 [[TMP0]], label %[[CONT:.*]], label %[[TRAP:.*]], !dbg [[DBG34]], !prof [[PROF39:![0-9]+]], !nosanitize [[META38]]
4545
// GENERALIZED: [[TRAP]]:
46-
// GENERALIZED-NEXT: tail call void @llvm.ubsantrap(i8 2) #[[ATTR4:[0-9]+]], !dbg [[DBG34]], !nosanitize [[META39]]
47-
// GENERALIZED-NEXT: unreachable, !dbg [[DBG34]], !nosanitize [[META39]]
46+
// GENERALIZED-NEXT: tail call void @llvm.ubsantrap(i8 2) #[[ATTR4:[0-9]+]], !dbg [[DBG34]], !nosanitize [[META38]]
47+
// GENERALIZED-NEXT: unreachable, !dbg [[DBG34]], !nosanitize [[META38]]
4848
// GENERALIZED: [[CONT]]:
49-
// GENERALIZED-NEXT: [[CALL:%.*]] = tail call ptr [[FP]](ptr noundef null, ptr noundef null) #[[ATTR5:[0-9]+]], !dbg [[DBG38:![0-9]+]]
50-
// GENERALIZED-NEXT: ret void, !dbg [[DBG41:![0-9]+]]
49+
// GENERALIZED-NEXT: [[CALL:%.*]] = tail call ptr [[FP]](ptr noundef null, ptr noundef null) #[[ATTR5:[0-9]+]], !dbg [[DBG37:![0-9]+]]
50+
// GENERALIZED-NEXT: ret void, !dbg [[DBG40:![0-9]+]]
5151
//
5252
void g(int** (*fp)(const char *, const char **)) {
5353
fp(0, 0);
5454
}
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)
@@ -84,17 +84,16 @@ void g(int** (*fp)(const char *, const char **)) {
8484
// UNGENERALIZED: [[META31]] = !{i64 0, !"_ZTSFvPFPPiPKcPS2_EE"}
8585
// UNGENERALIZED: [[META32]] = !{i64 0, !"_ZTSFvPvE.generalized"}
8686
// UNGENERALIZED: [[META33]] = !DILocation(line: 0, scope: [[DBG25]])
87-
// UNGENERALIZED: [[DBG34]] = !DILocation(line: 0, scope: [[META35:![0-9]+]], inlinedAt: [[META37:![0-9]+]])
87+
// UNGENERALIZED: [[DBG34]] = !DILocation(line: 0, scope: [[META35:![0-9]+]], inlinedAt: [[DBG37]])
8888
// UNGENERALIZED: [[META35]] = distinct !DISubprogram(name: "__ubsan_check_singularity", scope: [[META11]], file: [[META11]], type: [[META36:![0-9]+]], flags: DIFlagArtificial, spFlags: DISPFlagDefinition, unit: [[META0]])
8989
// UNGENERALIZED: [[META36]] = !DISubroutineType(types: null)
90-
// UNGENERALIZED: [[META37]] = !DILocation(line: 0, scope: [[META35]], inlinedAt: [[DBG38]])
91-
// UNGENERALIZED: [[DBG38]] = !DILocation(line: 53, column: 3, scope: [[DBG25]])
92-
// UNGENERALIZED: [[META39]] = !{}
93-
// UNGENERALIZED: [[PROF40]] = !{!"branch_weights", i32 1048575, i32 1}
94-
// UNGENERALIZED: [[DBG41]] = !DILocation(line: 54, column: 1, scope: [[DBG25]])
90+
// UNGENERALIZED: [[DBG37]] = !DILocation(line: 53, column: 3, scope: [[DBG25]])
91+
// UNGENERALIZED: [[META38]] = !{}
92+
// UNGENERALIZED: [[PROF39]] = !{!"branch_weights", i32 1048575, i32 1}
93+
// UNGENERALIZED: [[DBG40]] = !DILocation(line: 54, column: 1, scope: [[DBG25]])
9594
//.
9695
// 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)
97-
// GENERALIZED: [[META1]] = !DIFile(filename: "{{.*}}<stdin>", directory: {{.*}})
96+
// GENERALIZED: [[META1]] = !DIFile(filename: "<stdin>", directory: {{.*}})
9897
// GENERALIZED: [[META2]] = !{[[META3:![0-9]+]]}
9998
// GENERALIZED: [[META3]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: [[META4:![0-9]+]], size: 64)
10099
// GENERALIZED: [[META4]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: [[META5:![0-9]+]], size: 64)
@@ -123,12 +122,11 @@ void g(int** (*fp)(const char *, const char **)) {
123122
// GENERALIZED: [[META31]] = !{i64 0, !"_ZTSFvPFPPiPKcPS2_EE"}
124123
// GENERALIZED: [[META32]] = !{i64 0, !"_ZTSFvPvE.generalized"}
125124
// GENERALIZED: [[META33]] = !DILocation(line: 0, scope: [[DBG25]])
126-
// GENERALIZED: [[DBG34]] = !DILocation(line: 0, scope: [[META35:![0-9]+]], inlinedAt: [[META37:![0-9]+]])
125+
// GENERALIZED: [[DBG34]] = !DILocation(line: 0, scope: [[META35:![0-9]+]], inlinedAt: [[DBG37]])
127126
// GENERALIZED: [[META35]] = distinct !DISubprogram(name: "__ubsan_check_singularity", scope: [[META11]], file: [[META11]], type: [[META36:![0-9]+]], flags: DIFlagArtificial, spFlags: DISPFlagDefinition, unit: [[META0]])
128127
// GENERALIZED: [[META36]] = !DISubroutineType(types: null)
129-
// GENERALIZED: [[META37]] = !DILocation(line: 0, scope: [[META35]], inlinedAt: [[DBG38]])
130-
// GENERALIZED: [[DBG38]] = !DILocation(line: 53, column: 3, scope: [[DBG25]])
131-
// GENERALIZED: [[META39]] = !{}
132-
// GENERALIZED: [[PROF40]] = !{!"branch_weights", i32 1048575, i32 1}
133-
// GENERALIZED: [[DBG41]] = !DILocation(line: 54, column: 1, scope: [[DBG25]])
128+
// GENERALIZED: [[DBG37]] = !DILocation(line: 53, column: 3, scope: [[DBG25]])
129+
// GENERALIZED: [[META38]] = !{}
130+
// GENERALIZED: [[PROF39]] = !{!"branch_weights", i32 1048575, i32 1}
131+
// GENERALIZED: [[DBG40]] = !DILocation(line: 54, column: 1, scope: [[DBG25]])
134132
//.

0 commit comments

Comments
 (0)