CodeGen: Switch to generating llvm.looptrap instead of llvm.cond.loop.

Reviewers: fmayer, vitalybuka

Reviewed By: fmayer

Pull Request: https://github.com/llvm/llvm-project/pull/181300
This commit is contained in:
Peter Collingbourne
2026-02-13 14:15:17 -08:00
committed by GitHub
parent b703f63697
commit 55857e14bc
2 changed files with 14 additions and 13 deletions

View File

@@ -4438,12 +4438,6 @@ void CodeGenFunction::EmitUnreachable(SourceLocation Loc) {
void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked,
SanitizerHandler CheckHandlerID,
bool NoMerge, const TrapReason *TR) {
if (CGM.getCodeGenOpts().SanitizeTrapLoop) {
Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::cond_loop),
Builder.CreateNot(Checked));
return;
}
llvm::BasicBlock *Cont = createBasicBlock("cont");
// If we're optimizing, collapse all calls to trap down to just one per
@@ -4495,9 +4489,14 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked,
ApplyDebugLocation applyTrapDI(*this, TrapLocation);
llvm::CallInst *TrapCall =
Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::ubsantrap),
llvm::ConstantInt::get(CGM.Int8Ty, CheckHandlerID));
llvm::CallInst *TrapCall;
if (CGM.getCodeGenOpts().SanitizeTrapLoop)
TrapCall =
Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::looptrap));
else
TrapCall = Builder.CreateCall(
CGM.getIntrinsic(llvm::Intrinsic::ubsantrap),
llvm::ConstantInt::get(CGM.Int8Ty, CheckHandlerID));
if (!CGM.getCodeGenOpts().TrapFuncName.empty()) {
auto A = llvm::Attribute::get(getLLVMContext(), "trap-func-name",

View File

@@ -6,15 +6,17 @@ struct A {
void vcall(A *a) {
// CHECK: [[TEST:%.*]] = call i1 @llvm.type.test
// CHECK-NEXT: [[NOT:%.*]] = xor i1 [[TEST]], true
// CHECK-NEXT: call void @llvm.cond.loop(i1 [[NOT]])
// CHECK-NEXT: br i1 [[TEST]], label %cont, label %trap
// CHECK: trap:
// CHECK-NEXT: call void @llvm.looptrap()
a->f();
}
int overflow(int a, int b) {
// CHECK: [[OVERFLOW:%.*]] = extractvalue { i32, i1 } %2, 1, !nosanitize
// CHECK-NEXT: [[NOTOVERFLOW:%.*]] = xor i1 [[OVERFLOW]], true, !nosanitize
// CHECK-NEXT: [[NOTNOTOVERFLOW:%.*]] = xor i1 [[NOTOVERFLOW]], true, !nosanitize
// CHECK-NEXT: call void @llvm.cond.loop(i1 [[NOTNOTOVERFLOW]])
// CHECK-NEXT: br i1 [[NOTOVERFLOW]], label %cont, label %trap
// CHECK: trap:
// CHECK-NEXT: call void @llvm.looptrap()
return a + b;
}