diff --git a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp index 22acf59c78a38..ac033d92e30d8 100644 --- a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp +++ b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp @@ -1045,10 +1045,8 @@ void ModuleSanitizerCoverage::InjectCoverageAtBlock(Function &F, BasicBlock &BB, ->setCannotMerge(); // gets the PC using GET_CALLER_PC. } if (Options.TracePCGuard) { - auto GuardPtr = IRB.CreateIntToPtr( - IRB.CreateAdd(IRB.CreatePointerCast(FunctionGuardArray, IntptrTy), - ConstantInt::get(IntptrTy, Idx * 4)), - PtrTy); + auto GuardPtr = IRB.CreateConstInBoundsGEP2_64( + FunctionGuardArray->getValueType(), FunctionGuardArray, 0, Idx); if (Options.GatedCallbacks) { Instruction *I = &*IP; auto GateBranch = CreateGateBranch(F, FunctionGateCmp, I); diff --git a/llvm/test/Instrumentation/SanitizerCoverage/cmp-tracing-api-x86_32.ll b/llvm/test/Instrumentation/SanitizerCoverage/cmp-tracing-api-x86_32.ll index 6ade3e32bd279..e57ff078a5274 100644 --- a/llvm/test/Instrumentation/SanitizerCoverage/cmp-tracing-api-x86_32.ll +++ b/llvm/test/Instrumentation/SanitizerCoverage/cmp-tracing-api-x86_32.ll @@ -7,13 +7,14 @@ target triple = "i386-unknown-linux-gnu" define i32 @foo() #0 { ; CHECK-LABEL: define i32 @foo() comdat { ; CHECK-NEXT: entry: -; CHECK-NEXT: call void @__sanitizer_cov_trace_pc_guard(ptr inttoptr (i32 ptrtoint (ptr @__sancov_gen_ to i32) to ptr)) #[[ATTR1:[0-9]+]] +; CHECK-NEXT: call void @__sanitizer_cov_trace_pc_guard(ptr @__sancov_gen_) #[[ATTR1:[0-9]+]] ; CHECK-NEXT: ret i32 0 ; entry: ret i32 0 } +; UTC_ARGS: --disable ; CHECK-DAG: declare void @__sanitizer_cov_trace_pc_indir(i32) ; CHECK-DAG: declare void @__sanitizer_cov_trace_cmp1(i8 zeroext, i8 zeroext) ; CHECK-DAG: declare void @__sanitizer_cov_trace_cmp2(i16 zeroext, i16 zeroext) diff --git a/llvm/test/Instrumentation/SanitizerCoverage/missing_dbg.ll b/llvm/test/Instrumentation/SanitizerCoverage/missing_dbg.ll index fdd6b7e7d24ca..35684346c4d5a 100644 --- a/llvm/test/Instrumentation/SanitizerCoverage/missing_dbg.ll +++ b/llvm/test/Instrumentation/SanitizerCoverage/missing_dbg.ll @@ -12,7 +12,7 @@ define i32 @with_dbg(ptr %a, ptr %b) !dbg !3 { ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[TMP1]], 42 ; CHECK-NEXT: br i1 [[CMP]], label %[[BB0:.*]], label %[[BB1:.*]] ; CHECK: [[BB0]]: -; CHECK-NEXT: call void @__sanitizer_cov_trace_pc_guard(ptr inttoptr (i64 add (i64 ptrtoint (ptr @__sancov_gen_ to i64), i64 4) to ptr)) #[[ATTR1]], !dbg [[DBG7:![0-9]+]] +; 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]+]] ; CHECK-NEXT: store i32 [[TMP1]], ptr [[B]], align 4 ; CHECK-NEXT: br label %[[BB1]] ; CHECK: [[BB1]]: @@ -38,7 +38,7 @@ define i32 @without_dbg(ptr %a, ptr %b) { ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[TMP1]], 42 ; CHECK-NEXT: br i1 [[CMP]], label %[[BB0:.*]], label %[[BB1:.*]] ; CHECK: [[BB0]]: -; CHECK-NEXT: call void @__sanitizer_cov_trace_pc_guard(ptr inttoptr (i64 add (i64 ptrtoint (ptr @__sancov_gen_.1 to i64), i64 4) to ptr)) #[[ATTR1]] +; CHECK-NEXT: call void @__sanitizer_cov_trace_pc_guard(ptr getelementptr inbounds ([2 x i32], ptr @__sancov_gen_.1, i64 0, i64 1)) #[[ATTR1]] ; CHECK-NEXT: store i32 [[TMP1]], ptr [[B]], align 4 ; CHECK-NEXT: br label %[[BB1]] ; CHECK: [[BB1]]: