128 lines · c
1// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 52 3// RUN: %clang_cc1 -emit-llvm -fdebug-prefix-map=%S/= -fno-ident -fdebug-compilation-dir=%S -fsanitize=array-bounds -fsanitize-trap=array-bounds -fsanitize-annotate-debug-info=array-bounds -triple x86_64 -debug-info-kind=limited %s -o - | FileCheck --check-prefix=CHECK-TRAP %s4// RUN: %clang_cc1 -emit-llvm -fdebug-prefix-map=%S/= -fno-ident -fdebug-compilation-dir=%S -fsanitize=array-bounds -fsanitize-annotate-debug-info=array-bounds -triple x86_64 -debug-info-kind=limited %s -o - | FileCheck --check-prefix=CHECK-NOTRAP %s5 6int f();7void d(double*);8 9// CHECK-LABEL: @f110// CHECK-TRAP-LABEL: define dso_local double @f1(11// CHECK-TRAP-SAME: i32 noundef [[B:%.*]], i32 noundef [[I:%.*]]) #[[ATTR0:[0-9]+]] !dbg [[DBG4:![0-9]+]] {12// CHECK-TRAP-NEXT: [[ENTRY:.*:]]13// CHECK-TRAP-NEXT: [[B_ADDR:%.*]] = alloca i32, align 414// CHECK-TRAP-NEXT: [[I_ADDR:%.*]] = alloca i32, align 415// CHECK-TRAP-NEXT: [[A:%.*]] = alloca [10 x double], align 1616// CHECK-TRAP-NEXT: store i32 [[B]], ptr [[B_ADDR]], align 417// CHECK-TRAP-NEXT: #dbg_declare(ptr [[B_ADDR]], [[META11:![0-9]+]], !DIExpression(), [[META12:![0-9]+]])18// CHECK-TRAP-NEXT: store i32 [[I]], ptr [[I_ADDR]], align 419// CHECK-TRAP-NEXT: #dbg_declare(ptr [[I_ADDR]], [[META13:![0-9]+]], !DIExpression(), [[META14:![0-9]+]])20// CHECK-TRAP-NEXT: #dbg_declare(ptr [[A]], [[META15:![0-9]+]], !DIExpression(), [[META19:![0-9]+]])21// CHECK-TRAP-NEXT: [[ARRAYDECAY:%.*]] = getelementptr inbounds [10 x double], ptr [[A]], i64 0, i64 0, !dbg [[DBG20:![0-9]+]]22// CHECK-TRAP-NEXT: call void @d(ptr noundef [[ARRAYDECAY]]), !dbg [[DBG21:![0-9]+]]23// CHECK-TRAP-NEXT: [[CALL:%.*]] = call i32 (...) @f(), !dbg [[DBG22:![0-9]+]]24// CHECK-TRAP-NEXT: [[TMP0:%.*]] = sext i32 [[CALL]] to i64, !dbg [[DBG23:![0-9]+]], !nosanitize [[META10:![0-9]+]]25// CHECK-TRAP-NEXT: [[TMP1:%.*]] = icmp ult i64 [[TMP0]], 10, !dbg [[DBG23]], !nosanitize [[META10]]26// CHECK-TRAP-NEXT: br i1 [[TMP1]], label %[[CONT:.*]], label %[[TRAP:.*]], !dbg [[DBG23]], !prof [[PROF27:![0-9]+]], !nosanitize [[META10]]27// CHECK-TRAP: [[TRAP]]:28// CHECK-TRAP-NEXT: call void @llvm.ubsantrap(i8 18) #[[ATTR3:[0-9]+]], !dbg [[DBGTRAP:![0-9]+]], !nosanitize [[META10]]29// CHECK-TRAP-NEXT: unreachable, !dbg [[DBGTRAP]], !nosanitize [[META10]]30// CHECK-TRAP: [[CONT]]:31// CHECK-TRAP-NEXT: [[IDXPROM:%.*]] = sext i32 [[CALL]] to i64, !dbg [[DBG26:![0-9]+]]32// CHECK-TRAP-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds [10 x double], ptr [[A]], i64 0, i64 [[IDXPROM]], !dbg [[DBG26]]33// CHECK-TRAP-NEXT: [[TMP2:%.*]] = load double, ptr [[ARRAYIDX]], align 8, !dbg [[DBG26]]34// CHECK-TRAP-NEXT: ret double [[TMP2]], !dbg [[DBG30:![0-9]+]]35//36// CHECK-NOTRAP-LABEL: define dso_local double @f1(37// CHECK-NOTRAP-SAME: i32 noundef [[B:%.*]], i32 noundef [[I:%.*]]) #[[ATTR0:[0-9]+]] !dbg [[DBG4:![0-9]+]] {38// CHECK-NOTRAP-NEXT: [[ENTRY:.*:]]39// CHECK-NOTRAP-NEXT: [[B_ADDR:%.*]] = alloca i32, align 440// CHECK-NOTRAP-NEXT: [[I_ADDR:%.*]] = alloca i32, align 441// CHECK-NOTRAP-NEXT: [[A:%.*]] = alloca [10 x double], align 1642// CHECK-NOTRAP-NEXT: store i32 [[B]], ptr [[B_ADDR]], align 443// CHECK-NOTRAP-NEXT: #dbg_declare(ptr [[B_ADDR]], [[META11:![0-9]+]], !DIExpression(), [[META12:![0-9]+]])44// CHECK-NOTRAP-NEXT: store i32 [[I]], ptr [[I_ADDR]], align 445// CHECK-NOTRAP-NEXT: #dbg_declare(ptr [[I_ADDR]], [[META13:![0-9]+]], !DIExpression(), [[META14:![0-9]+]])46// CHECK-NOTRAP-NEXT: #dbg_declare(ptr [[A]], [[META15:![0-9]+]], !DIExpression(), [[META19:![0-9]+]])47// CHECK-NOTRAP-NEXT: [[ARRAYDECAY:%.*]] = getelementptr inbounds [10 x double], ptr [[A]], i64 0, i64 0, !dbg [[DBG20:![0-9]+]]48// CHECK-NOTRAP-NEXT: call void @d(ptr noundef [[ARRAYDECAY]]), !dbg [[DBG21:![0-9]+]]49// CHECK-NOTRAP-NEXT: [[CALL:%.*]] = call i32 (...) @f(), !dbg [[DBG22:![0-9]+]]50// CHECK-NOTRAP-NEXT: [[TMP0:%.*]] = sext i32 [[CALL]] to i64, !dbg [[DBG23:![0-9]+]], !nosanitize [[META10:![0-9]+]]51// CHECK-NOTRAP-NEXT: [[TMP1:%.*]] = icmp ult i64 [[TMP0]], 10, !dbg [[DBG23]], !nosanitize [[META10]]52// CHECK-NOTRAP-NEXT: br i1 [[TMP1]], label %[[CONT:.*]], label %[[HANDLER_OUT_OF_BOUNDS:.*]], !dbg [[DBG23]], !prof [[PROF27:![0-9]+]], !nosanitize [[META10]]53// CHECK-NOTRAP: [[HANDLER_OUT_OF_BOUNDS]]:54// CHECK-NOTRAP-NEXT: [[TMP2:%.*]] = zext i32 [[CALL]] to i64, !dbg [[DBG23]], !nosanitize [[META10]]55// CHECK-NOTRAP-NEXT: call void @__ubsan_handle_out_of_bounds_abort(ptr @[[GLOB2:[0-9]+]], i64 [[TMP2]]) #[[ATTR3:[0-9]+]], !dbg [[DBG23]], !nosanitize [[META10]]56// CHECK-NOTRAP-NEXT: unreachable, !dbg [[DBG23]], !nosanitize [[META10]]57// CHECK-NOTRAP: [[CONT]]:58// CHECK-NOTRAP-NEXT: [[IDXPROM:%.*]] = sext i32 [[CALL]] to i64, !dbg [[DBG26:![0-9]+]]59// CHECK-NOTRAP-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds [10 x double], ptr [[A]], i64 0, i64 [[IDXPROM]], !dbg [[DBG26]]60// CHECK-NOTRAP-NEXT: [[TMP3:%.*]] = load double, ptr [[ARRAYIDX]], align 8, !dbg [[DBG26]]61// CHECK-NOTRAP-NEXT: ret double [[TMP3]], !dbg [[DBG28:![0-9]+]]62//63double f1(int b, int i) {64 double a[10];65 d(a);66 return a[f()];67}68 69//.70// 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: {{.*}})72// 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]])73// CHECK-TRAP: [[META5]] = !DIFile(filename: "bounds-checking-debuginfo.c", directory: {{.*}})74// CHECK-TRAP: [[META6]] = !DISubroutineType(types: [[META7:![0-9]+]])75// CHECK-TRAP: [[META7]] = !{[[META8:![0-9]+]], [[META9:![0-9]+]], [[META9]]}76// CHECK-TRAP: [[META8]] = !DIBasicType(name: "double", size: 64, encoding: DW_ATE_float)77// CHECK-TRAP: [[META9]] = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)78// CHECK-TRAP: [[META10]] = !{}79// CHECK-TRAP: [[META11]] = !DILocalVariable(name: "b", arg: 1, scope: [[DBG4]], file: [[META5]], line: 63, type: [[META9]])80// CHECK-TRAP: [[META12]] = !DILocation(line: 63, column: 15, scope: [[DBG4]])81// CHECK-TRAP: [[META13]] = !DILocalVariable(name: "i", arg: 2, scope: [[DBG4]], file: [[META5]], line: 63, type: [[META9]])82// CHECK-TRAP: [[META14]] = !DILocation(line: 63, column: 22, scope: [[DBG4]])83// CHECK-TRAP: [[META15]] = !DILocalVariable(name: "a", scope: [[DBG4]], file: [[META5]], line: 64, type: [[META16:![0-9]+]])84// CHECK-TRAP: [[META16]] = !DICompositeType(tag: DW_TAG_array_type, baseType: [[META8]], size: 640, elements: [[META17:![0-9]+]])85// CHECK-TRAP: [[META17]] = !{[[META18:![0-9]+]]}86// CHECK-TRAP: [[META18]] = !DISubrange(count: 10)87// CHECK-TRAP: [[META19]] = !DILocation(line: 64, column: 10, scope: [[DBG4]])88// CHECK-TRAP: [[DBG20]] = !DILocation(line: 65, column: 5, scope: [[DBG4]])89// CHECK-TRAP: [[DBG21]] = !DILocation(line: 65, column: 3, scope: [[DBG4]])90// CHECK-TRAP: [[DBG22]] = !DILocation(line: 66, column: 12, scope: [[DBG4]])91// CHECK-TRAP: [[DBG23]] = !DILocation(line: 0, scope: [[META24:![0-9]+]], inlinedAt: [[DBG26]])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]])93// CHECK-TRAP: [[META25]] = !DISubroutineType(types: null)94// CHECK-TRAP: [[DBG26]] = !DILocation(line: 66, column: 10, scope: [[DBG4]])95// CHECK-TRAP: [[PROF27]] = !{!"branch_weights", i32 1048575, i32 1}96// CHECK-TRAP: [[DBGTRAP]] = !DILocation(line: 0, scope: [[TRAPMSG:![0-9]+]], inlinedAt: [[DBG23]])97// CHECK-TRAP: [[TRAPMSG]] = distinct !DISubprogram(name: "__clang_trap_msg$Undefined Behavior Sanitizer$Array index out of bounds", scope: [[META5]], file: [[META5]], type: [[META25]], flags: DIFlagArtificial, spFlags: DISPFlagDefinition, unit: [[META0]])98// CHECK-TRAP: [[DBG30]] = !DILocation(line: 66, column: 3, scope: [[DBG4]])99//.100// 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)101// CHECK-NOTRAP: [[META1]] = !DIFile(filename: "<stdin>", directory: {{.*}})102// 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]])103// CHECK-NOTRAP: [[META5]] = !DIFile(filename: "bounds-checking-debuginfo.c", directory: {{.*}})104// CHECK-NOTRAP: [[META6]] = !DISubroutineType(types: [[META7:![0-9]+]])105// CHECK-NOTRAP: [[META7]] = !{[[META8:![0-9]+]], [[META9:![0-9]+]], [[META9]]}106// CHECK-NOTRAP: [[META8]] = !DIBasicType(name: "double", size: 64, encoding: DW_ATE_float)107// CHECK-NOTRAP: [[META9]] = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)108// CHECK-NOTRAP: [[META10]] = !{}109// CHECK-NOTRAP: [[META11]] = !DILocalVariable(name: "b", arg: 1, scope: [[DBG4]], file: [[META5]], line: 63, type: [[META9]])110// CHECK-NOTRAP: [[META12]] = !DILocation(line: 63, column: 15, scope: [[DBG4]])111// CHECK-NOTRAP: [[META13]] = !DILocalVariable(name: "i", arg: 2, scope: [[DBG4]], file: [[META5]], line: 63, type: [[META9]])112// CHECK-NOTRAP: [[META14]] = !DILocation(line: 63, column: 22, scope: [[DBG4]])113// CHECK-NOTRAP: [[META15]] = !DILocalVariable(name: "a", scope: [[DBG4]], file: [[META5]], line: 64, type: [[META16:![0-9]+]])114// CHECK-NOTRAP: [[META16]] = !DICompositeType(tag: DW_TAG_array_type, baseType: [[META8]], size: 640, elements: [[META17:![0-9]+]])115// CHECK-NOTRAP: [[META17]] = !{[[META18:![0-9]+]]}116// CHECK-NOTRAP: [[META18]] = !DISubrange(count: 10)117// CHECK-NOTRAP: [[META19]] = !DILocation(line: 64, column: 10, scope: [[DBG4]])118// CHECK-NOTRAP: [[DBG20]] = !DILocation(line: 65, column: 5, scope: [[DBG4]])119// CHECK-NOTRAP: [[DBG21]] = !DILocation(line: 65, column: 3, scope: [[DBG4]])120// CHECK-NOTRAP: [[DBG22]] = !DILocation(line: 66, column: 12, scope: [[DBG4]])121// CHECK-NOTRAP: [[DBG23]] = !DILocation(line: 0, scope: [[META24:![0-9]+]], inlinedAt: [[DBG26]])122// CHECK-NOTRAP: [[META24]] = distinct !DISubprogram(name: "__ubsan_check_array_bounds", scope: [[META5]], file: [[META5]], type: [[META25:![0-9]+]], flags: DIFlagArtificial, spFlags: DISPFlagDefinition, unit: [[META0]])123// CHECK-NOTRAP: [[META25]] = !DISubroutineType(types: null)124// CHECK-NOTRAP: [[DBG26]] = !DILocation(line: 66, column: 10, scope: [[DBG4]])125// CHECK-NOTRAP: [[PROF27]] = !{!"branch_weights", i32 1048575, i32 1}126// CHECK-NOTRAP: [[DBG28]] = !DILocation(line: 66, column: 3, scope: [[DBG4]])127//.128