|
| 1 | +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5 |
| 2 | +// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-icall -fsanitize-trap=cfi-icall -emit-llvm -o - %s \ |
| 3 | +// RUN: -fsanitize-annotate-debug-info=cfi-icall,cfi-nvcall,cfi-vcall,cfi-unrelated-cast,cfi-derived-cast \ |
| 4 | +// RUN: -fdebug-prefix-map=%S/= -fno-ident -fdebug-compilation-dir=%S -debug-info-kind=limited \ |
| 5 | +// RUN: | FileCheck --check-prefix=CHECK --check-prefix=UNGENERALIZED %s |
| 6 | +// |
| 7 | +// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-icall -fsanitize-trap=cfi-icall -fsanitize-cfi-icall-generalize-pointers -emit-llvm -o - %s \ |
| 8 | +// RUN: -fsanitize-annotate-debug-info=cfi-icall,cfi-nvcall,cfi-vcall,cfi-unrelated-cast,cfi-derived-cast \ |
| 9 | +// RUN: -fdebug-prefix-map=%S/= -fno-ident -fdebug-compilation-dir=%S -debug-info-kind=limited \ |
| 10 | +// RUN: | FileCheck --check-prefix=CHECK --check-prefix=GENERALIZED %s |
| 11 | + |
| 12 | +// Test that const char* is generalized to const ptr and that const char** is |
| 13 | +// generalized to ptr |
| 14 | + |
| 15 | +// CHECK-LABEL: define dso_local ptr @f( |
| 16 | +// CHECK-SAME: ptr noundef [[A:%.*]], ptr noundef [[B:%.*]]) #[[ATTR0:[0-9]+]] !dbg [[DBG9:![0-9]+]] !type [[META18:![0-9]+]] !type [[META19:![0-9]+]] { |
| 17 | +// CHECK-NEXT: [[ENTRY:.*:]] |
| 18 | +// CHECK-NEXT: [[A_ADDR:%.*]] = alloca ptr, align 8 |
| 19 | +// CHECK-NEXT: [[B_ADDR:%.*]] = alloca ptr, align 8 |
| 20 | +// CHECK-NEXT: store ptr [[A]], ptr [[A_ADDR]], align 8 |
| 21 | +// CHECK-NEXT: #dbg_declare(ptr [[A_ADDR]], [[META20:![0-9]+]], !DIExpression(), [[META21:![0-9]+]]) |
| 22 | +// CHECK-NEXT: store ptr [[B]], ptr [[B_ADDR]], align 8 |
| 23 | +// CHECK-NEXT: #dbg_declare(ptr [[B_ADDR]], [[META22:![0-9]+]], !DIExpression(), [[META23:![0-9]+]]) |
| 24 | +// CHECK-NEXT: ret ptr null, !dbg [[DBG24:![0-9]+]] |
| 25 | +// |
| 26 | +int** f(const char *a, const char **b) { |
| 27 | + return (int**)0; |
| 28 | +} |
| 29 | + |
| 30 | +// UNGENERALIZED-LABEL: define dso_local void @g( |
| 31 | +// UNGENERALIZED-SAME: ptr noundef [[FP:%.*]]) #[[ATTR0]] !dbg [[DBG25:![0-9]+]] !type [[META29:![0-9]+]] !type [[META30:![0-9]+]] { |
| 32 | +// UNGENERALIZED-NEXT: [[ENTRY:.*:]] |
| 33 | +// UNGENERALIZED-NEXT: [[FP_ADDR:%.*]] = alloca ptr, align 8 |
| 34 | +// UNGENERALIZED-NEXT: store ptr [[FP]], ptr [[FP_ADDR]], align 8 |
| 35 | +// UNGENERALIZED-NEXT: #dbg_declare(ptr [[FP_ADDR]], [[META31:![0-9]+]], !DIExpression(), [[META32:![0-9]+]]) |
| 36 | +// UNGENERALIZED-NEXT: [[TMP0:%.*]] = load ptr, ptr [[FP_ADDR]], align 8, !dbg [[DBG33:![0-9]+]] |
| 37 | +// UNGENERALIZED-NEXT: [[TMP1:%.*]] = call i1 @llvm.type.test(ptr [[TMP0]], metadata !"_ZTSFPPiPKcPS2_E"), !dbg [[DBG33]], !nosanitize [[META17:![0-9]+]] |
| 38 | +// UNGENERALIZED-NEXT: br i1 [[TMP1]], label %[[CONT:.*]], label %[[TRAP:.*]], !dbg [[DBG33]], !prof [[PROF34:![0-9]+]], !nosanitize [[META17]] |
| 39 | +// UNGENERALIZED: [[TRAP]]: |
| 40 | +// UNGENERALIZED-NEXT: call void @llvm.ubsantrap(i8 2) #[[ATTR3:[0-9]+]], !dbg [[DBG33]], !nosanitize [[META17]] |
| 41 | +// UNGENERALIZED-NEXT: unreachable, !dbg [[DBG33]], !nosanitize [[META17]] |
| 42 | +// UNGENERALIZED: [[CONT]]: |
| 43 | +// UNGENERALIZED-NEXT: [[CALL:%.*]] = call ptr [[TMP0]](ptr noundef null, ptr noundef null), !dbg [[DBG33]] |
| 44 | +// UNGENERALIZED-NEXT: ret void, !dbg [[DBG35:![0-9]+]] |
| 45 | +// |
| 46 | +// GENERALIZED-LABEL: define dso_local void @g( |
| 47 | +// GENERALIZED-SAME: ptr noundef [[FP:%.*]]) #[[ATTR0]] !dbg [[DBG25:![0-9]+]] !type [[META29:![0-9]+]] !type [[META30:![0-9]+]] { |
| 48 | +// GENERALIZED-NEXT: [[ENTRY:.*:]] |
| 49 | +// GENERALIZED-NEXT: [[FP_ADDR:%.*]] = alloca ptr, align 8 |
| 50 | +// GENERALIZED-NEXT: store ptr [[FP]], ptr [[FP_ADDR]], align 8 |
| 51 | +// GENERALIZED-NEXT: #dbg_declare(ptr [[FP_ADDR]], [[META31:![0-9]+]], !DIExpression(), [[META32:![0-9]+]]) |
| 52 | +// GENERALIZED-NEXT: [[TMP0:%.*]] = load ptr, ptr [[FP_ADDR]], align 8, !dbg [[DBG33:![0-9]+]] |
| 53 | +// GENERALIZED-NEXT: [[TMP1:%.*]] = call i1 @llvm.type.test(ptr [[TMP0]], metadata !"_ZTSFPvPKvS_E.generalized"), !dbg [[DBG33]], !nosanitize [[META17:![0-9]+]] |
| 54 | +// GENERALIZED-NEXT: br i1 [[TMP1]], label %[[CONT:.*]], label %[[TRAP:.*]], !dbg [[DBG33]], !prof [[PROF34:![0-9]+]], !nosanitize [[META17]] |
| 55 | +// GENERALIZED: [[TRAP]]: |
| 56 | +// GENERALIZED-NEXT: call void @llvm.ubsantrap(i8 2) #[[ATTR3:[0-9]+]], !dbg [[DBG33]], !nosanitize [[META17]] |
| 57 | +// GENERALIZED-NEXT: unreachable, !dbg [[DBG33]], !nosanitize [[META17]] |
| 58 | +// GENERALIZED: [[CONT]]: |
| 59 | +// GENERALIZED-NEXT: [[CALL:%.*]] = call ptr [[TMP0]](ptr noundef null, ptr noundef null), !dbg [[DBG33]] |
| 60 | +// GENERALIZED-NEXT: ret void, !dbg [[DBG35:![0-9]+]] |
| 61 | +// |
| 62 | +void g(int** (*fp)(const char *, const char **)) { |
| 63 | + fp(0, 0); |
| 64 | +} |
| 65 | + |
| 66 | +//. |
| 67 | +// UNGENERALIZED: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C11, file: [[META1:![0-9]+]], isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, retainedTypes: [[META2:![0-9]+]], splitDebugInlining: false, nameTableKind: None) |
| 68 | +// UNGENERALIZED: [[META1]] = !DIFile(filename: "{{.*}}<stdin>", directory: {{.*}}) |
| 69 | +// UNGENERALIZED: [[META2]] = !{[[META3:![0-9]+]]} |
| 70 | +// UNGENERALIZED: [[META3]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: [[META4:![0-9]+]], size: 64) |
| 71 | +// UNGENERALIZED: [[META4]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: [[META5:![0-9]+]], size: 64) |
| 72 | +// UNGENERALIZED: [[META5]] = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) |
| 73 | +// UNGENERALIZED: [[DBG9]] = distinct !DISubprogram(name: "f", scope: [[META10:![0-9]+]], file: [[META10]], line: 15, type: [[META11:![0-9]+]], scopeLine: 15, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: [[META0]], retainedNodes: [[META17]]) |
| 74 | +// UNGENERALIZED: [[META10]] = !DIFile(filename: "{{.*}}cfi-icall-generalize-debuginfo.c", directory: {{.*}}) |
| 75 | +// UNGENERALIZED: [[META11]] = !DISubroutineType(types: [[META12:![0-9]+]]) |
| 76 | +// UNGENERALIZED: [[META12]] = !{[[META3]], [[META13:![0-9]+]], [[META16:![0-9]+]]} |
| 77 | +// UNGENERALIZED: [[META13]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: [[META14:![0-9]+]], size: 64) |
| 78 | +// UNGENERALIZED: [[META14]] = !DIDerivedType(tag: DW_TAG_const_type, baseType: [[META15:![0-9]+]]) |
| 79 | +// UNGENERALIZED: [[META15]] = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char) |
| 80 | +// UNGENERALIZED: [[META16]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: [[META13]], size: 64) |
| 81 | +// UNGENERALIZED: [[META17]] = !{} |
| 82 | +// UNGENERALIZED: [[META18]] = !{i64 0, !"_ZTSFPPiPKcPS2_E"} |
| 83 | +// UNGENERALIZED: [[META19]] = !{i64 0, !"_ZTSFPvPKvS_E.generalized"} |
| 84 | +// UNGENERALIZED: [[META20]] = !DILocalVariable(name: "a", arg: 1, scope: [[DBG9]], file: [[META10]], line: 15, type: [[META13]]) |
| 85 | +// UNGENERALIZED: [[META21]] = !DILocation(line: 15, column: 21, scope: [[DBG9]]) |
| 86 | +// UNGENERALIZED: [[META22]] = !DILocalVariable(name: "b", arg: 2, scope: [[DBG9]], file: [[META10]], line: 15, type: [[META16]]) |
| 87 | +// UNGENERALIZED: [[META23]] = !DILocation(line: 15, column: 37, scope: [[DBG9]]) |
| 88 | +// UNGENERALIZED: [[DBG24]] = !DILocation(line: 16, column: 3, scope: [[DBG9]]) |
| 89 | +// UNGENERALIZED: [[DBG25]] = distinct !DISubprogram(name: "g", scope: [[META10]], file: [[META10]], line: 19, type: [[META26:![0-9]+]], scopeLine: 19, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: [[META0]], retainedNodes: [[META17]]) |
| 90 | +// UNGENERALIZED: [[META26]] = !DISubroutineType(types: [[META27:![0-9]+]]) |
| 91 | +// UNGENERALIZED: [[META27]] = !{null, [[META28:![0-9]+]]} |
| 92 | +// UNGENERALIZED: [[META28]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: [[META11]], size: 64) |
| 93 | +// UNGENERALIZED: [[META29]] = !{i64 0, !"_ZTSFvPFPPiPKcPS2_EE"} |
| 94 | +// UNGENERALIZED: [[META30]] = !{i64 0, !"_ZTSFvPvE.generalized"} |
| 95 | +// UNGENERALIZED: [[META31]] = !DILocalVariable(name: "fp", arg: 1, scope: [[DBG25]], file: [[META10]], line: 19, type: [[META28]]) |
| 96 | +// UNGENERALIZED: [[META32]] = !DILocation(line: 19, column: 16, scope: [[DBG25]]) |
| 97 | +// UNGENERALIZED: [[DBG33]] = !DILocation(line: 22, column: 3, scope: [[DBG25]]) |
| 98 | +// UNGENERALIZED: [[PROF34]] = !{!"branch_weights", i32 1048575, i32 1} |
| 99 | +// UNGENERALIZED: [[DBG35]] = !DILocation(line: 23, column: 1, scope: [[DBG25]]) |
| 100 | +//. |
| 101 | +// GENERALIZED: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C11, file: [[META1:![0-9]+]], isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, retainedTypes: [[META2:![0-9]+]], splitDebugInlining: false, nameTableKind: None) |
| 102 | +// GENERALIZED: [[META1]] = !DIFile(filename: "{{.*}}<stdin>", directory: {{.*}}) |
| 103 | +// GENERALIZED: [[META2]] = !{[[META3:![0-9]+]]} |
| 104 | +// GENERALIZED: [[META3]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: [[META4:![0-9]+]], size: 64) |
| 105 | +// GENERALIZED: [[META4]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: [[META5:![0-9]+]], size: 64) |
| 106 | +// GENERALIZED: [[META5]] = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) |
| 107 | +// GENERALIZED: [[DBG9]] = distinct !DISubprogram(name: "f", scope: [[META10:![0-9]+]], file: [[META10]], line: 15, type: [[META11:![0-9]+]], scopeLine: 15, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: [[META0]], retainedNodes: [[META17]]) |
| 108 | +// GENERALIZED: [[META10]] = !DIFile(filename: "{{.*}}cfi-icall-generalize-debuginfo.c", directory: {{.*}}) |
| 109 | +// GENERALIZED: [[META11]] = !DISubroutineType(types: [[META12:![0-9]+]]) |
| 110 | +// GENERALIZED: [[META12]] = !{[[META3]], [[META13:![0-9]+]], [[META16:![0-9]+]]} |
| 111 | +// GENERALIZED: [[META13]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: [[META14:![0-9]+]], size: 64) |
| 112 | +// GENERALIZED: [[META14]] = !DIDerivedType(tag: DW_TAG_const_type, baseType: [[META15:![0-9]+]]) |
| 113 | +// GENERALIZED: [[META15]] = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char) |
| 114 | +// GENERALIZED: [[META16]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: [[META13]], size: 64) |
| 115 | +// GENERALIZED: [[META17]] = !{} |
| 116 | +// GENERALIZED: [[META18]] = !{i64 0, !"_ZTSFPPiPKcPS2_E"} |
| 117 | +// GENERALIZED: [[META19]] = !{i64 0, !"_ZTSFPvPKvS_E.generalized"} |
| 118 | +// GENERALIZED: [[META20]] = !DILocalVariable(name: "a", arg: 1, scope: [[DBG9]], file: [[META10]], line: 15, type: [[META13]]) |
| 119 | +// GENERALIZED: [[META21]] = !DILocation(line: 15, column: 21, scope: [[DBG9]]) |
| 120 | +// GENERALIZED: [[META22]] = !DILocalVariable(name: "b", arg: 2, scope: [[DBG9]], file: [[META10]], line: 15, type: [[META16]]) |
| 121 | +// GENERALIZED: [[META23]] = !DILocation(line: 15, column: 37, scope: [[DBG9]]) |
| 122 | +// GENERALIZED: [[DBG24]] = !DILocation(line: 16, column: 3, scope: [[DBG9]]) |
| 123 | +// GENERALIZED: [[DBG25]] = distinct !DISubprogram(name: "g", scope: [[META10]], file: [[META10]], line: 19, type: [[META26:![0-9]+]], scopeLine: 19, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: [[META0]], retainedNodes: [[META17]]) |
| 124 | +// GENERALIZED: [[META26]] = !DISubroutineType(types: [[META27:![0-9]+]]) |
| 125 | +// GENERALIZED: [[META27]] = !{null, [[META28:![0-9]+]]} |
| 126 | +// GENERALIZED: [[META28]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: [[META11]], size: 64) |
| 127 | +// GENERALIZED: [[META29]] = !{i64 0, !"_ZTSFvPFPPiPKcPS2_EE"} |
| 128 | +// GENERALIZED: [[META30]] = !{i64 0, !"_ZTSFvPvE.generalized"} |
| 129 | +// GENERALIZED: [[META31]] = !DILocalVariable(name: "fp", arg: 1, scope: [[DBG25]], file: [[META10]], line: 19, type: [[META28]]) |
| 130 | +// GENERALIZED: [[META32]] = !DILocation(line: 19, column: 16, scope: [[DBG25]]) |
| 131 | +// GENERALIZED: [[DBG33]] = !DILocation(line: 22, column: 3, scope: [[DBG25]]) |
| 132 | +// GENERALIZED: [[PROF34]] = !{!"branch_weights", i32 1048575, i32 1} |
| 133 | +// GENERALIZED: [[DBG35]] = !DILocation(line: 23, column: 1, scope: [[DBG25]]) |
| 134 | +//. |
0 commit comments