Author: Peter Collingbourne Date: 2026-02-13T14:15:17-08:00 New Revision: 55857e14bc2261305db70dbe1f0e3af93c229aad
URL: https://github.com/llvm/llvm-project/commit/55857e14bc2261305db70dbe1f0e3af93c229aad DIFF: https://github.com/llvm/llvm-project/commit/55857e14bc2261305db70dbe1f0e3af93c229aad.diff LOG: 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 Added: Modified: clang/lib/CodeGen/CGExpr.cpp clang/test/CodeGenCXX/sanitize-trap-loop.cpp Removed: ################################################################################ diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 8de1c53b1b213..a0a1a5675654c 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -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", diff --git a/clang/test/CodeGenCXX/sanitize-trap-loop.cpp b/clang/test/CodeGenCXX/sanitize-trap-loop.cpp index ee083c52f5c30..3c7af1af907c0 100644 --- a/clang/test/CodeGenCXX/sanitize-trap-loop.cpp +++ b/clang/test/CodeGenCXX/sanitize-trap-loop.cpp @@ -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; } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
