171 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 52; RUN: opt < %s -passes='module(sancov-module)' -sanitizer-coverage-level=2 -S | FileCheck %s3; RUN: opt < %s -passes='module(sancov-module)' -sanitizer-coverage-level=1 -sanitizer-coverage-stack-depth -sanitizer-coverage-stack-depth-callback-min=1 -S | FileCheck %s --check-prefix=CHECK-STACK-CALLBACK4; RUN: opt < %s -passes='module(sancov-module)' -sanitizer-coverage-level=1 -sanitizer-coverage-stack-depth -S | FileCheck %s --check-prefix=CHECK-STACK-DEPTH5 6target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"7 8define i32 @with_dbg(ptr %a, ptr %b) !dbg !3 {9; CHECK-LABEL: define i32 @with_dbg(10; CHECK-SAME: ptr [[A:%.*]], ptr [[B:%.*]]) comdat !dbg [[DBG3:![0-9]+]] {11; CHECK-NEXT: [[ENTRY:.*:]]12; CHECK-NEXT: call void @__sanitizer_cov_trace_pc_guard(ptr @__sancov_gen_) #[[ATTR1:[0-9]+]], !dbg [[DBG6:![0-9]+]]13; CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[A]], align 414; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[TMP1]], 4215; CHECK-NEXT: br i1 [[CMP]], label %[[BB0:.*]], label %[[BB1:.*]]16; CHECK: [[BB0]]:17; CHECK-NEXT: call void @__sanitizer_cov_trace_pc_guard(ptr getelementptr inbounds ([2 x i32], ptr @__sancov_gen_, i64 0, i64 1)) #[[ATTR1]], !dbg [[DBG7:![0-9]+]]18; CHECK-NEXT: store i32 [[TMP1]], ptr [[B]], align 419; CHECK-NEXT: br label %[[BB1]]20; CHECK: [[BB1]]:21; CHECK-NEXT: ret i32 [[TMP1]]22;23entry:24 %t = load i32, ptr %a, align 425 %cmp = icmp eq i32 %t, 4226 br i1 %cmp, label %0, label %1270:28 store i32 %t, ptr %b29 br label %1301:31 ret i32 %t32}33 34define i32 @without_dbg(ptr %a, ptr %b) {35; CHECK-LABEL: define i32 @without_dbg(36; CHECK-SAME: ptr [[A:%.*]], ptr [[B:%.*]]) comdat {37; CHECK-NEXT: [[ENTRY:.*:]]38; CHECK-NEXT: call void @__sanitizer_cov_trace_pc_guard(ptr @__sancov_gen_.1) #[[ATTR1]]39; CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[A]], align 440; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[TMP1]], 4241; CHECK-NEXT: br i1 [[CMP]], label %[[BB0:.*]], label %[[BB1:.*]]42; CHECK: [[BB0]]:43; CHECK-NEXT: call void @__sanitizer_cov_trace_pc_guard(ptr getelementptr inbounds ([2 x i32], ptr @__sancov_gen_.1, i64 0, i64 1)) #[[ATTR1]]44; CHECK-NEXT: store i32 [[TMP1]], ptr [[B]], align 445; CHECK-NEXT: br label %[[BB1]]46; CHECK: [[BB1]]:47; CHECK-NEXT: ret i32 [[TMP1]]48;49entry:50 %t = load i32, ptr %a, align 451 %cmp = icmp eq i32 %t, 4252 br i1 %cmp, label %0, label %1530:54 store i32 %t, ptr %b55 br label %1561:57 ret i32 %t58}59 60define i32 @with_dbg_stack_callback(ptr %a) !dbg !8 {61; CHECK-STACK-CALLBACK-LABEL: define i32 @with_dbg_stack_callback(62; CHECK-STACK-CALLBACK-SAME: ptr [[A:%.*]]) !dbg [[DBG8:![0-9]+]] {63; CHECK-STACK-CALLBACK-NEXT: entry:64; CHECK-STACK-CALLBACK-NEXT: [[BUF:%.*]] = alloca [64 x i8], align 165; CHECK-STACK-CALLBACK-NEXT: call void @__sanitizer_cov_stack_depth() #[[ATTR1:[0-9]+]], !dbg [[DBG9:![0-9]+]]66; CHECK-STACK-CALLBACK-NEXT: %t = load i32, ptr [[A]], align 467; CHECK-STACK-CALLBACK-NEXT: call void @external_func()68; CHECK-STACK-CALLBACK-NEXT: ret i32 %t69;70entry:71 %buf = alloca [64 x i8], align 172 %t = load i32, ptr %a, align 473 call void @external_func()74 ret i32 %t75}76 77define i32 @with_dbg_stack_depth(ptr %a) !dbg !10 {78; CHECK-STACK-DEPTH-LABEL: define i32 @with_dbg_stack_depth(79; CHECK-STACK-DEPTH-SAME: ptr [[A:%.*]]) !dbg [[DBG10:![0-9]+]] {80; CHECK-STACK-DEPTH-NEXT: entry:81; CHECK-STACK-DEPTH-NEXT: [[BUF:%.*]] = alloca [64 x i8], align 182; CHECK-STACK-DEPTH-NEXT: [[TMP1:%.*]] = call ptr @llvm.frameaddress.p0(i32 0)83; CHECK-STACK-DEPTH-NEXT: [[TMP2:%.*]] = ptrtoint ptr [[TMP1]] to i6484; CHECK-STACK-DEPTH-NEXT: [[TMP3:%.*]] = load i64, ptr @__sancov_lowest_stack, align 885; CHECK-STACK-DEPTH-NEXT: [[TMP4:%.*]] = icmp ult i64 [[TMP2]], [[TMP3]]86; CHECK-STACK-DEPTH-NEXT: br i1 [[TMP4]], label {{%.*}}, label {{%.*}}87; CHECK-STACK-DEPTH: store i64 [[TMP2]], ptr @__sancov_lowest_stack, align 8, !dbg [[DBG11:![0-9]+]], {{.*}}!nosanitize88; CHECK-STACK-DEPTH: %t = load i32, ptr [[A]], align 489; CHECK-STACK-DEPTH-NEXT: call void @external_func()90; CHECK-STACK-DEPTH-NEXT: ret i32 %t91;92entry:93 %buf = alloca [64 x i8], align 194 %t = load i32, ptr %a, align 495 call void @external_func()96 ret i32 %t97}98 99define i32 @without_dbg_stack_callback(ptr %a) {100; CHECK-STACK-CALLBACK-LABEL: define i32 @without_dbg_stack_callback(101; CHECK-STACK-CALLBACK-SAME: ptr [[A:%.*]]) {102; CHECK-STACK-CALLBACK-NEXT: entry:103; CHECK-STACK-CALLBACK-NEXT: [[BUF:%.*]] = alloca [64 x i8], align 1104; CHECK-STACK-CALLBACK-NEXT: call void @__sanitizer_cov_stack_depth() #[[ATTR1]]105; CHECK-STACK-CALLBACK-NEXT: %t = load i32, ptr [[A]], align 4106; CHECK-STACK-CALLBACK-NEXT: call void @external_func()107; CHECK-STACK-CALLBACK-NEXT: ret i32 %t108;109entry:110 %buf = alloca [64 x i8], align 1111 %t = load i32, ptr %a, align 4112 call void @external_func()113 ret i32 %t114}115 116define i32 @without_dbg_stack_depth(ptr %a) {117; CHECK-STACK-DEPTH-LABEL: define i32 @without_dbg_stack_depth(118; CHECK-STACK-DEPTH-SAME: ptr [[A:%.*]]) {119; CHECK-STACK-DEPTH-NEXT: entry:120; CHECK-STACK-DEPTH-NEXT: [[BUF:%.*]] = alloca [64 x i8], align 1121; CHECK-STACK-DEPTH-NEXT: [[TMP1:%.*]] = call ptr @llvm.frameaddress.p0(i32 0)122; CHECK-STACK-DEPTH-NEXT: [[TMP2:%.*]] = ptrtoint ptr [[TMP1]] to i64123; CHECK-STACK-DEPTH-NEXT: [[TMP3:%.*]] = load i64, ptr @__sancov_lowest_stack, align 8124; CHECK-STACK-DEPTH-NEXT: [[TMP4:%.*]] = icmp ult i64 [[TMP2]], [[TMP3]]125; CHECK-STACK-DEPTH-NEXT: br i1 [[TMP4]], label {{%.*}}, label {{%.*}}126; CHECK-STACK-DEPTH: store i64 [[TMP2]], ptr @__sancov_lowest_stack, align 8, {{.*}}!nosanitize127; CHECK-STACK-DEPTH: %t = load i32, ptr [[A]], align 4128; CHECK-STACK-DEPTH-NEXT: call void @external_func()129; CHECK-STACK-DEPTH-NEXT: ret i32 %t130;131entry:132 %buf = alloca [64 x i8], align 1133 %t = load i32, ptr %a, align 4134 call void @external_func()135 ret i32 %t136}137 138declare void @external_func()139 140!llvm.dbg.cu = !{!0}141!llvm.module.flags = !{!2}142 143!0 = distinct !DICompileUnit(language: DW_LANG_C89, file: !1, producer: "", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, splitDebugInlining: false, nameTableKind: None)144!1 = !DIFile(filename: "foo.c", directory: "")145!2 = !{i32 2, !"Debug Info Version", i32 3}146!3 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 190, type: !4, scopeLine: 192, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !0)147!4 = !DISubroutineType(types: !5)148!5 = !{}149!6 = !DILocation(line: 192, scope: !3)150!7 = !DILocation(line: 0, scope: !3)151!8 = distinct !DISubprogram(name: "with_dbg_stack_callback", scope: !1, file: !1, line: 200, type: !4, scopeLine: 200, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !0)152!9 = !DILocation(line: 200, scope: !8)153!10 = distinct !DISubprogram(name: "with_dbg_stack_depth", scope: !1, file: !1, line: 210, type: !4, scopeLine: 210, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !0)154!11 = !DILocation(line: 210, scope: !10)155 156;.157; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C89, file: [[META1:![0-9]+]], isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, splitDebugInlining: false, nameTableKind: None)158; CHECK: [[META1]] = !DIFile(filename: "foo.c", directory: "")159; CHECK: [[DBG3]] = distinct !DISubprogram(name: "foo", scope: [[META1]], file: [[META1]], line: 190, type: [[META4:![0-9]+]], scopeLine: 192, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: [[META0]])160; CHECK: [[META4]] = !DISubroutineType(types: [[META5:![0-9]+]])161; CHECK: [[META5]] = !{}162; CHECK: [[DBG6]] = !DILocation(line: 192, scope: [[DBG3]])163; CHECK: [[DBG7]] = !DILocation(line: 0, scope: [[DBG3]])164;.165; CHECK-STACK-CALLBACK: [[DBG8]] = distinct !DISubprogram(name: "with_dbg_stack_callback", scope: {{.*}}, file: {{.*}}, line: 200166; CHECK-STACK-CALLBACK: [[DBG9]] = !DILocation(line: 200, scope: [[DBG8]])167;.168; CHECK-STACK-DEPTH: [[DBG10]] = distinct !DISubprogram(name: "with_dbg_stack_depth", scope: {{.*}}, file: {{.*}}, line: 210169; CHECK-STACK-DEPTH: [[DBG11]] = !DILocation(line: 210, scope: [[DBG10]])170;.171