From 4dfaf9c8da09867bec2bf0008a8c6ba7f22404a7 Mon Sep 17 00:00:00 2001 From: Dan Liew Date: Tue, 9 Sep 2025 17:56:00 -0700 Subject: [PATCH 1/2] [BoundsSafety] Remove `-funique-traps` flag and its implementation The implementation was a bit hacky and interacted badly with the hot-cold splitting pass. So it is going to be removed in favor of a different implementation that's simpler. I also investated why `clang/test/BoundsSafety/CodeGen/unique-trap-blocks-O2.c` broke (rdar://150559639). It turns outthat the "trap blocks" started being unintentionally split by the hot-cold splitting pass because in upstream we started adding branch profiling weights (https://github.com/llvm/llvm-project/pull/134310) which the hot-cold splitting pass used as a signal to split the "trap blocks" into their own function (by-passing the logic I originally added to prevent the splitting). While we could fix this it would be very fragile and given that we are removing the implementation anyway it doesn't matter anymore. rdar://158088410 --- clang/include/clang/Basic/CodeGenOptions.def | 4 - clang/include/clang/Driver/Options.td | 10 -- clang/lib/CodeGen/CGExpr.cpp | 7 +- clang/lib/CodeGen/CodeGenFunction.cpp | 39 ----- clang/lib/CodeGen/CodeGenFunction.h | 7 - clang/lib/CodeGen/CodeGenModule.h | 8 - clang/lib/Driver/ToolChains/Clang.cpp | 3 - .../unique-trap-blocks-O0-O2-opt-disabled.c | 105 ------------- .../unique-trap-blocks-O0-O2-opt-disabled.c | 120 --------------- .../CodeGen/unique-trap-blocks-O2.c | 142 ------------------ llvm/lib/Transforms/IPO/HotColdSplitting.cpp | 29 +--- .../no-outline-bounds-safety-traps.ll | 44 ------ 12 files changed, 2 insertions(+), 516 deletions(-) delete mode 100644 clang/test/BoundsSafety-legacy-checks/CodeGen/unique-trap-blocks-O0-O2-opt-disabled.c delete mode 100644 clang/test/BoundsSafety/CodeGen/unique-trap-blocks-O0-O2-opt-disabled.c delete mode 100644 clang/test/BoundsSafety/CodeGen/unique-trap-blocks-O2.c delete mode 100644 llvm/test/Transforms/HotColdSplit/no-outline-bounds-safety-traps.ll diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def index 1d79421e952bb..fb0ca99bb90b7 100644 --- a/clang/include/clang/Basic/CodeGenOptions.def +++ b/clang/include/clang/Basic/CodeGenOptions.def @@ -336,10 +336,6 @@ CODEGENOPT(ProfileSampleAccurate, 1, 0, Benign) ///< Sample profile is accurate. /* TO_UPSTREAM(BoundsSafety) ON*/ CODEGENOPT(TrapFuncReturns , 1, 0, Benign) ///< When true, the function specified with ///< -ftrap-function may return normally -CODEGENOPT( - UniqueTrapBlocks, 1, - 0, Benign) ///< When true, basic blocks that contain traps they will be prevented - ///< from being merged by optimization passes and the backends. /* TO_UPSTREAM(BoundsSafety) OFF*/ /// Treat loops as finite: language, always, never. diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 7e2b1f56ac6f7..e49281231f675 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -4445,16 +4445,6 @@ defm trap_function_returns : BoolFOption<"trap-function-returns", "The trap function specified by -ftrap-function may return normally">, NegFlag>; -defm unique_traps : BoolFOption<"unique-traps", - CodeGenOpts<"UniqueTrapBlocks">, DefaultFalse, - PosFlag, - NegFlag>; /* TO_UPSTREAM(BoundsSafety) OFF */ def funroll_loops : Flag<["-"], "funroll-loops">, Group, HelpText<"Turn on loop unroller">, Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>; diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 4d7cda2ed21f0..3f6105c8780ce 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -4712,7 +4712,6 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked, /*TO_UPSTREAM(BoundsSafety) ON*/ NoMerge |= CGM.getCodeGenOpts().TrapFuncReturns; - NoMerge |= CGM.getCodeGenOpts().UniqueTrapBlocks; /*TO_UPSTREAM(BoundsSafety) OFF*/ if (TrapBB && !NoMerge) { @@ -4741,11 +4740,7 @@ void CodeGenFunction::EmitTrapCheck(llvm::Value *Checked, /* TO_UPSTREAM(BoundsSafety) OFF*/ } else { /*TO_UPSTREAM(BoundsSafety) ON*/ - if (CGM.getCodeGenOpts().UniqueTrapBlocks && - !CGM.getCodeGenOpts().TrapFuncReturns) - TrapBB = createUnmergeableBasicBlock("trap"); - else - TrapBB = createBasicBlock("trap"); + TrapBB = createBasicBlock("trap"); auto *BrInst = Builder.CreateCondBr(Checked, Cont, TrapBB, MDHelper.createLikelyBranchWeights()); diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 2e70e1d0d4187..c591f75e642e5 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -41,8 +41,6 @@ #include "llvm/IR/DataLayout.h" #include "llvm/IR/Dominators.h" #include "llvm/IR/FPEnv.h" -// TO_UPSTREAM(BoundsSafety) ON -#include "llvm/IR/InlineAsm.h" #include "llvm/IR/Instruction.h" #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/Intrinsics.h" @@ -320,43 +318,6 @@ TypeEvaluationKind CodeGenFunction::getEvaluationKind(QualType type) { } } -/* TO_UPSTREAM(BoundsSafety) ON*/ -llvm::BasicBlock *CodeGenFunction::createUnmergeableBasicBlock( - const Twine &name, llvm::Function *parent, llvm::BasicBlock *before) { - auto *BB = createBasicBlock(name, parent, before); - // This approach is the same approach used by Swift. - // TODO: Find a better way to do this (rdar://137627723). - - // Emit unique side-effecting inline asm calls in order to eliminate - // the possibility that an LLVM optimization or code generation pass - // will merge these blocks back together again. We emit an empty asm - // string with the side-effect flag set, and with a unique integer - // argument. - llvm::IntegerType *asmArgTy = CGM.Int64Ty; - llvm::Type *argTys = {asmArgTy}; - llvm::FunctionType *asmFnTy = - llvm::FunctionType::get(CGM.VoidTy, argTys, /* isVarArg=*/false); - // "n" is an input constraint stating that the first argument to the call - // will be an integer literal. - llvm::InlineAsm *inlineAsm = - llvm::InlineAsm::get(asmFnTy, /*AsmString=*/"", /*Constraints=*/"n", - /*hasSideEffects=*/true); - - // Use the builder so that any opt-remarks and attributes are automatically - // applied by the builder. The current state of the builder is saved so it - // can be used for creating the asm call and then the builder is reset to - // its previous state. - auto OldInsertPoint = Builder.GetInsertPoint(); - auto* OldInsertBB = Builder.GetInsertBlock(); - Builder.SetInsertPoint(BB); - Builder.CreateCall( - inlineAsm, - llvm::ConstantInt::get(asmArgTy, CGM.getAndIncrementUniqueTrapCount())); - Builder.SetInsertPoint(OldInsertBB, OldInsertPoint); - return BB; -} -/* TO_UPSTREAM(BoundsSafety) OFF*/ - llvm::DebugLoc CodeGenFunction::EmitReturnBlock() { // For cleanliness, we try to avoid emitting the return block for // simple cases. diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index 5586c234d9935..6a8c9cedf0284 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -2659,13 +2659,6 @@ class CodeGenFunction : public CodeGenTypeCache { return llvm::BasicBlock::Create(getLLVMContext(), name, parent, before); } - /* TO_UPSTREM(BoundsSafety) ON*/ - llvm::BasicBlock * - createUnmergeableBasicBlock(const Twine &name = "", - llvm::Function *parent = nullptr, - llvm::BasicBlock *before = nullptr); - /* TO_UPSTREM(BoundsSafety) OFF*/ - /// getBasicBlockForLabel - Return the LLVM basicblock that the specified /// label maps to. JumpDest getJumpDestForLabel(const LabelDecl *S); diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h index d46b98caeeb39..6e02edac9a74d 100644 --- a/clang/lib/CodeGen/CodeGenModule.h +++ b/clang/lib/CodeGen/CodeGenModule.h @@ -682,9 +682,6 @@ class CodeGenModule : public CodeGenTypeCache { std::optional computeVTPointerAuthentication(const CXXRecordDecl *ThisClass); - // TO_UPSTREAM(BoundsSafety) - uint64_t UniqueTrapCount = 0; - AtomicOptions AtomicOpts; // A set of functions which should be hot-patched; see @@ -1159,11 +1156,6 @@ class CodeGenModule : public CodeGenTypeCache { /// Fetches the global unique block count. int getUniqueBlockCount() { return ++Block.GlobalUniqueCount; } - /* TO_UPSTREAM(BoundsSafety) ON*/ - /// Fetches and increments unique trap count - uint64_t getAndIncrementUniqueTrapCount() { return UniqueTrapCount++; } - /* TO_UPSTREAM(BoundsSafety) OFF*/ - /// Fetches the type of a generic block descriptor. llvm::Type *getBlockDescriptorType(); diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 87f7ad4e1ede6..935c9318d4737 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -7041,9 +7041,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &Job, D.Diag(diag::err_drv_option_requires_option) << "-ftrap-function-returns" << "-ftrap-function="; } - - Args.addOptInFlag(CmdArgs, options::OPT_funique_traps, - options::OPT_fno_unique_traps); /* TO_UPSTREAM(BoundsSafety) OFF*/ // Handle -f[no-]wrapv and -f[no-]strict-overflow, which are used by both diff --git a/clang/test/BoundsSafety-legacy-checks/CodeGen/unique-trap-blocks-O0-O2-opt-disabled.c b/clang/test/BoundsSafety-legacy-checks/CodeGen/unique-trap-blocks-O0-O2-opt-disabled.c deleted file mode 100644 index 2486b1208b39e..0000000000000 --- a/clang/test/BoundsSafety-legacy-checks/CodeGen/unique-trap-blocks-O0-O2-opt-disabled.c +++ /dev/null @@ -1,105 +0,0 @@ -// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --include-generated-funcs --version 5 - -// RUN: %clang_cc1 -O0 -triple arm64e-apple-ios -fbounds-safety \ -// RUN: -funique-traps -emit-llvm %s -o - \ -// RUN: | FileCheck -check-prefix=OPT0 %s -// RUN: %clang_cc1 -O2 -triple arm64e-apple-ios -fbounds-safety \ -// RUN: -funique-traps -emit-llvm %s -disable-llvm-passes -o - \ -// RUN: | FileCheck -check-prefix=OPT2 %s - -#include - -int consume(int* __bidi_indexable ptr, int idx) { - return ptr[idx]; -} -// OPT0-LABEL: define i32 @consume( -// OPT0-SAME: ptr dead_on_return noundef [[PTR:%.*]], i32 noundef [[IDX:%.*]]) #[[ATTR0:[0-9]+]] { -// OPT0-NEXT: [[ENTRY:.*:]] -// OPT0-NEXT: [[PTR_INDIRECT_ADDR:%.*]] = alloca ptr, align 8 -// OPT0-NEXT: [[IDX_ADDR:%.*]] = alloca i32, align 4 -// OPT0-NEXT: [[AGG_TEMP:%.*]] = alloca %"__bounds_safety::wide_ptr.bidi_indexable", align 8 -// OPT0-NEXT: store ptr [[PTR]], ptr [[PTR_INDIRECT_ADDR]], align 8 -// OPT0-NEXT: store i32 [[IDX]], ptr [[IDX_ADDR]], align 4 -// OPT0-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[AGG_TEMP]], ptr align 8 [[PTR]], i64 24, i1 false) -// OPT0-NEXT: [[WIDE_PTR_PTR_ADDR:%.*]] = getelementptr inbounds nuw %"__bounds_safety::wide_ptr.bidi_indexable", ptr [[AGG_TEMP]], i32 0, i32 0 -// OPT0-NEXT: [[WIDE_PTR_PTR:%.*]] = load ptr, ptr [[WIDE_PTR_PTR_ADDR]], align 8 -// OPT0-NEXT: [[TMP0:%.*]] = load i32, ptr [[IDX_ADDR]], align 4 -// OPT0-NEXT: [[IDXPROM:%.*]] = sext i32 [[TMP0]] to i64 -// OPT0-NEXT: [[ARRAYIDX:%.*]] = getelementptr i32, ptr [[WIDE_PTR_PTR]], i64 [[IDXPROM]] -// OPT0-NEXT: [[WIDE_PTR_UB_ADDR:%.*]] = getelementptr inbounds nuw %"__bounds_safety::wide_ptr.bidi_indexable", ptr [[AGG_TEMP]], i32 0, i32 1 -// OPT0-NEXT: [[WIDE_PTR_UB:%.*]] = load ptr, ptr [[WIDE_PTR_UB_ADDR]], align 8 -// OPT0-NEXT: [[WIDE_PTR_LB_ADDR:%.*]] = getelementptr inbounds nuw %"__bounds_safety::wide_ptr.bidi_indexable", ptr [[AGG_TEMP]], i32 0, i32 2 -// OPT0-NEXT: [[WIDE_PTR_LB:%.*]] = load ptr, ptr [[WIDE_PTR_LB_ADDR]], align 8 -// OPT0-NEXT: [[TMP1:%.*]] = icmp ult ptr [[ARRAYIDX]], [[WIDE_PTR_UB]], !annotation [[META2:![0-9]+]] -// OPT0-NEXT: br i1 [[TMP1]], label %[[CONT:.*]], label %[[TRAP:.*]], !prof [[PROF3:![0-9]+]], !annotation [[META2]] -// OPT0: [[TRAP]]: -// OPT0-NEXT: call void asm sideeffect "", "n"(i64 0), !annotation [[META2]] -// OPT0-NEXT: call void @llvm.ubsantrap(i8 25) #[[ATTR3:[0-9]+]], !annotation [[META2]] -// OPT0-NEXT: unreachable, !annotation [[META2]] -// OPT0: [[CONT]]: -// OPT0-NEXT: [[TMP2:%.*]] = icmp uge ptr [[ARRAYIDX]], [[WIDE_PTR_LB]], !annotation [[META4:![0-9]+]] -// OPT0-NEXT: br i1 [[TMP2]], label %[[CONT2:.*]], label %[[TRAP1:.*]], !prof [[PROF3]], !annotation [[META4]] -// OPT0: [[TRAP1]]: -// OPT0-NEXT: call void asm sideeffect "", "n"(i64 1), !annotation [[META4]] -// OPT0-NEXT: call void @llvm.ubsantrap(i8 25) #[[ATTR3]], !annotation [[META4]] -// OPT0-NEXT: unreachable, !annotation [[META4]] -// OPT0: [[CONT2]]: -// OPT0-NEXT: [[TMP3:%.*]] = load i32, ptr [[ARRAYIDX]], align 4 -// OPT0-NEXT: ret i32 [[TMP3]] -// -// -// OPT2-LABEL: define i32 @consume( -// OPT2-SAME: ptr dead_on_return noundef [[PTR:%.*]], i32 noundef [[IDX:%.*]]) #[[ATTR0:[0-9]+]] { -// OPT2-NEXT: [[ENTRY:.*:]] -// OPT2-NEXT: [[PTR_INDIRECT_ADDR:%.*]] = alloca ptr, align 8 -// OPT2-NEXT: [[IDX_ADDR:%.*]] = alloca i32, align 4 -// OPT2-NEXT: [[AGG_TEMP:%.*]] = alloca %"__bounds_safety::wide_ptr.bidi_indexable", align 8 -// OPT2-NEXT: store ptr [[PTR]], ptr [[PTR_INDIRECT_ADDR]], align 8, !tbaa [[TBAA2:![0-9]+]] -// OPT2-NEXT: store i32 [[IDX]], ptr [[IDX_ADDR]], align 4, !tbaa [[TBAA8:![0-9]+]] -// OPT2-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[AGG_TEMP]], ptr align 8 [[PTR]], i64 24, i1 false), !tbaa.struct [[TBAA_STRUCT10:![0-9]+]] -// OPT2-NEXT: [[WIDE_PTR_PTR_ADDR:%.*]] = getelementptr inbounds nuw %"__bounds_safety::wide_ptr.bidi_indexable", ptr [[AGG_TEMP]], i32 0, i32 0 -// OPT2-NEXT: [[WIDE_PTR_PTR:%.*]] = load ptr, ptr [[WIDE_PTR_PTR_ADDR]], align 8 -// OPT2-NEXT: [[TMP0:%.*]] = load i32, ptr [[IDX_ADDR]], align 4, !tbaa [[TBAA8]] -// OPT2-NEXT: [[IDXPROM:%.*]] = sext i32 [[TMP0]] to i64 -// OPT2-NEXT: [[ARRAYIDX:%.*]] = getelementptr i32, ptr [[WIDE_PTR_PTR]], i64 [[IDXPROM]] -// OPT2-NEXT: [[WIDE_PTR_UB_ADDR:%.*]] = getelementptr inbounds nuw %"__bounds_safety::wide_ptr.bidi_indexable", ptr [[AGG_TEMP]], i32 0, i32 1 -// OPT2-NEXT: [[WIDE_PTR_UB:%.*]] = load ptr, ptr [[WIDE_PTR_UB_ADDR]], align 8 -// OPT2-NEXT: [[WIDE_PTR_LB_ADDR:%.*]] = getelementptr inbounds nuw %"__bounds_safety::wide_ptr.bidi_indexable", ptr [[AGG_TEMP]], i32 0, i32 2 -// OPT2-NEXT: [[WIDE_PTR_LB:%.*]] = load ptr, ptr [[WIDE_PTR_LB_ADDR]], align 8 -// OPT2-NEXT: [[TMP1:%.*]] = icmp ult ptr [[ARRAYIDX]], [[WIDE_PTR_UB]], !annotation [[META13:![0-9]+]] -// OPT2-NEXT: br i1 [[TMP1]], label %[[CONT:.*]], label %[[TRAP:.*]], !prof [[PROF14:![0-9]+]], !annotation [[META13]] -// OPT2: [[TRAP]]: -// OPT2-NEXT: call void asm sideeffect "", "n"(i64 0), !annotation [[META13]] -// OPT2-NEXT: call void @llvm.ubsantrap(i8 25) #[[ATTR3:[0-9]+]], !annotation [[META13]] -// OPT2-NEXT: unreachable, !annotation [[META13]] -// OPT2: [[CONT]]: -// OPT2-NEXT: [[TMP2:%.*]] = icmp uge ptr [[ARRAYIDX]], [[WIDE_PTR_LB]], !annotation [[META15:![0-9]+]] -// OPT2-NEXT: br i1 [[TMP2]], label %[[CONT2:.*]], label %[[TRAP1:.*]], !prof [[PROF14]], !annotation [[META15]] -// OPT2: [[TRAP1]]: -// OPT2-NEXT: call void asm sideeffect "", "n"(i64 1), !annotation [[META15]] -// OPT2-NEXT: call void @llvm.ubsantrap(i8 25) #[[ATTR3]], !annotation [[META15]] -// OPT2-NEXT: unreachable, !annotation [[META15]] -// OPT2: [[CONT2]]: -// OPT2-NEXT: [[TMP3:%.*]] = load i32, ptr [[ARRAYIDX]], align 4, !tbaa [[TBAA8]] -// OPT2-NEXT: ret i32 [[TMP3]] -// -//. -// OPT0: [[META2]] = !{!"bounds-safety-check-ptr-lt-upper-bound"} -// OPT0: [[PROF3]] = !{!"branch_weights", i32 1048575, i32 1} -// OPT0: [[META4]] = !{!"bounds-safety-check-ptr-ge-lower-bound"} -//. -// OPT2: [[TBAA2]] = !{[[META3:![0-9]+]], [[META3]], i64 0} -// OPT2: [[META3]] = !{!"p2 int", [[META4:![0-9]+]], i64 0} -// OPT2: [[META4]] = !{!"any p2 pointer", [[META5:![0-9]+]], i64 0} -// OPT2: [[META5]] = !{!"any pointer", [[META6:![0-9]+]], i64 0} -// OPT2: [[META6]] = !{!"omnipotent char", [[META7:![0-9]+]], i64 0} -// OPT2: [[META7]] = !{!"Simple C/C++ TBAA"} -// OPT2: [[TBAA8]] = !{[[META9:![0-9]+]], [[META9]], i64 0} -// OPT2: [[META9]] = !{!"int", [[META6]], i64 0} -// OPT2: [[TBAA_STRUCT10]] = !{i64 0, i64 24, [[META11:![0-9]+]]} -// OPT2: [[META11]] = !{[[META12:![0-9]+]], [[META12]], i64 0} -// OPT2: [[META12]] = !{!"p1 int", [[META5]], i64 0} -// OPT2: [[META13]] = !{!"bounds-safety-check-ptr-lt-upper-bound"} -// OPT2: [[PROF14]] = !{!"branch_weights", i32 1048575, i32 1} -// OPT2: [[META15]] = !{!"bounds-safety-check-ptr-ge-lower-bound"} -//. diff --git a/clang/test/BoundsSafety/CodeGen/unique-trap-blocks-O0-O2-opt-disabled.c b/clang/test/BoundsSafety/CodeGen/unique-trap-blocks-O0-O2-opt-disabled.c deleted file mode 100644 index 42da2b8d2dfd0..0000000000000 --- a/clang/test/BoundsSafety/CodeGen/unique-trap-blocks-O0-O2-opt-disabled.c +++ /dev/null @@ -1,120 +0,0 @@ -// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --include-generated-funcs --version 5 -// RUN: %clang_cc1 -O0 -triple arm64e-apple-ios -fbounds-safety \ -// RUN: -funique-traps -emit-llvm %s -o - \ -// RUN: | FileCheck -check-prefix=OPT0 %s -// RUN: %clang_cc1 -O2 -triple arm64e-apple-ios -fbounds-safety \ -// RUN: -funique-traps -emit-llvm %s -disable-llvm-passes -o - \ -// RUN: | FileCheck -check-prefix=OPT2 %s - -#include - -int consume(int* __bidi_indexable ptr, int idx) { - return ptr[idx]; -} -// OPT0-LABEL: define i32 @consume( -// OPT0-SAME: ptr dead_on_return noundef [[PTR:%.*]], i32 noundef [[IDX:%.*]]) #[[ATTR0:[0-9]+]] { -// OPT0-NEXT: [[ENTRY:.*:]] -// OPT0-NEXT: [[PTR_INDIRECT_ADDR:%.*]] = alloca ptr, align 8 -// OPT0-NEXT: [[IDX_ADDR:%.*]] = alloca i32, align 4 -// OPT0-NEXT: [[AGG_TEMP:%.*]] = alloca %"__bounds_safety::wide_ptr.bidi_indexable", align 8 -// OPT0-NEXT: store ptr [[PTR]], ptr [[PTR_INDIRECT_ADDR]], align 8 -// OPT0-NEXT: store i32 [[IDX]], ptr [[IDX_ADDR]], align 4 -// OPT0-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[AGG_TEMP]], ptr align 8 [[PTR]], i64 24, i1 false) -// OPT0-NEXT: [[WIDE_PTR_PTR_ADDR:%.*]] = getelementptr inbounds nuw %"__bounds_safety::wide_ptr.bidi_indexable", ptr [[AGG_TEMP]], i32 0, i32 0 -// OPT0-NEXT: [[WIDE_PTR_PTR:%.*]] = load ptr, ptr [[WIDE_PTR_PTR_ADDR]], align 8 -// OPT0-NEXT: [[TMP0:%.*]] = load i32, ptr [[IDX_ADDR]], align 4 -// OPT0-NEXT: [[IDXPROM:%.*]] = sext i32 [[TMP0]] to i64 -// OPT0-NEXT: [[ARRAYIDX:%.*]] = getelementptr i32, ptr [[WIDE_PTR_PTR]], i64 [[IDXPROM]] -// OPT0-NEXT: [[WIDE_PTR_UB_ADDR:%.*]] = getelementptr inbounds nuw %"__bounds_safety::wide_ptr.bidi_indexable", ptr [[AGG_TEMP]], i32 0, i32 1 -// OPT0-NEXT: [[WIDE_PTR_UB:%.*]] = load ptr, ptr [[WIDE_PTR_UB_ADDR]], align 8 -// OPT0-NEXT: [[WIDE_PTR_LB_ADDR:%.*]] = getelementptr inbounds nuw %"__bounds_safety::wide_ptr.bidi_indexable", ptr [[AGG_TEMP]], i32 0, i32 2 -// OPT0-NEXT: [[WIDE_PTR_LB:%.*]] = load ptr, ptr [[WIDE_PTR_LB_ADDR]], align 8 -// OPT0-NEXT: [[TMP1:%.*]] = getelementptr i32, ptr [[ARRAYIDX]], i64 1, !annotation [[META2:![0-9]+]] -// OPT0-NEXT: [[TMP2:%.*]] = icmp ule ptr [[TMP1]], [[WIDE_PTR_UB]], !annotation [[META2]] -// OPT0-NEXT: br i1 [[TMP2]], label %[[CONT:.*]], label %[[TRAP:.*]], !prof [[PROF3:![0-9]+]], !annotation [[META2]] -// OPT0: [[TRAP]]: -// OPT0-NEXT: call void asm sideeffect "", "n"(i64 0), !annotation [[META2]] -// OPT0-NEXT: call void @llvm.ubsantrap(i8 25) #[[ATTR3:[0-9]+]], !annotation [[META2]] -// OPT0-NEXT: unreachable, !annotation [[META2]] -// OPT0: [[CONT]]: -// OPT0-NEXT: [[TMP3:%.*]] = icmp ule ptr [[ARRAYIDX]], [[TMP1]], !annotation [[META2]] -// OPT0-NEXT: br i1 [[TMP3]], label %[[CONT2:.*]], label %[[TRAP1:.*]], !prof [[PROF3]], !annotation [[META2]] -// OPT0: [[TRAP1]]: -// OPT0-NEXT: call void asm sideeffect "", "n"(i64 1), !annotation [[META2]] -// OPT0-NEXT: call void @llvm.ubsantrap(i8 25) #[[ATTR3]], !annotation [[META2]] -// OPT0-NEXT: unreachable, !annotation [[META2]] -// OPT0: [[CONT2]]: -// OPT0-NEXT: [[TMP4:%.*]] = icmp uge ptr [[ARRAYIDX]], [[WIDE_PTR_LB]], !annotation [[META4:![0-9]+]] -// OPT0-NEXT: br i1 [[TMP4]], label %[[CONT4:.*]], label %[[TRAP3:.*]], !prof [[PROF3]], !annotation [[META4]] -// OPT0: [[TRAP3]]: -// OPT0-NEXT: call void asm sideeffect "", "n"(i64 2), !annotation [[META4]] -// OPT0-NEXT: call void @llvm.ubsantrap(i8 25) #[[ATTR3]], !annotation [[META4]] -// OPT0-NEXT: unreachable, !annotation [[META4]] -// OPT0: [[CONT4]]: -// OPT0-NEXT: [[TMP5:%.*]] = load i32, ptr [[ARRAYIDX]], align 4 -// OPT0-NEXT: ret i32 [[TMP5]] -// -// -// OPT2-LABEL: define i32 @consume( -// OPT2-SAME: ptr dead_on_return noundef [[PTR:%.*]], i32 noundef [[IDX:%.*]]) #[[ATTR0:[0-9]+]] { -// OPT2-NEXT: [[ENTRY:.*:]] -// OPT2-NEXT: [[PTR_INDIRECT_ADDR:%.*]] = alloca ptr, align 8 -// OPT2-NEXT: [[IDX_ADDR:%.*]] = alloca i32, align 4 -// OPT2-NEXT: [[AGG_TEMP:%.*]] = alloca %"__bounds_safety::wide_ptr.bidi_indexable", align 8 -// OPT2-NEXT: store ptr [[PTR]], ptr [[PTR_INDIRECT_ADDR]], align 8, !tbaa [[TBAA2:![0-9]+]] -// OPT2-NEXT: store i32 [[IDX]], ptr [[IDX_ADDR]], align 4, !tbaa [[TBAA8:![0-9]+]] -// OPT2-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[AGG_TEMP]], ptr align 8 [[PTR]], i64 24, i1 false), !tbaa.struct [[TBAA_STRUCT10:![0-9]+]] -// OPT2-NEXT: [[WIDE_PTR_PTR_ADDR:%.*]] = getelementptr inbounds nuw %"__bounds_safety::wide_ptr.bidi_indexable", ptr [[AGG_TEMP]], i32 0, i32 0 -// OPT2-NEXT: [[WIDE_PTR_PTR:%.*]] = load ptr, ptr [[WIDE_PTR_PTR_ADDR]], align 8 -// OPT2-NEXT: [[TMP0:%.*]] = load i32, ptr [[IDX_ADDR]], align 4, !tbaa [[TBAA8]] -// OPT2-NEXT: [[IDXPROM:%.*]] = sext i32 [[TMP0]] to i64 -// OPT2-NEXT: [[ARRAYIDX:%.*]] = getelementptr i32, ptr [[WIDE_PTR_PTR]], i64 [[IDXPROM]] -// OPT2-NEXT: [[WIDE_PTR_UB_ADDR:%.*]] = getelementptr inbounds nuw %"__bounds_safety::wide_ptr.bidi_indexable", ptr [[AGG_TEMP]], i32 0, i32 1 -// OPT2-NEXT: [[WIDE_PTR_UB:%.*]] = load ptr, ptr [[WIDE_PTR_UB_ADDR]], align 8 -// OPT2-NEXT: [[WIDE_PTR_LB_ADDR:%.*]] = getelementptr inbounds nuw %"__bounds_safety::wide_ptr.bidi_indexable", ptr [[AGG_TEMP]], i32 0, i32 2 -// OPT2-NEXT: [[WIDE_PTR_LB:%.*]] = load ptr, ptr [[WIDE_PTR_LB_ADDR]], align 8 -// OPT2-NEXT: [[TMP1:%.*]] = getelementptr i32, ptr [[ARRAYIDX]], i64 1, !annotation [[META13:![0-9]+]] -// OPT2-NEXT: [[TMP2:%.*]] = icmp ule ptr [[TMP1]], [[WIDE_PTR_UB]], !annotation [[META13]] -// OPT2-NEXT: br i1 [[TMP2]], label %[[CONT:.*]], label %[[TRAP:.*]], !prof [[PROF14:![0-9]+]], !annotation [[META13]] -// OPT2: [[TRAP]]: -// OPT2-NEXT: call void asm sideeffect "", "n"(i64 0), !annotation [[META13]] -// OPT2-NEXT: call void @llvm.ubsantrap(i8 25) #[[ATTR3:[0-9]+]], !annotation [[META13]] -// OPT2-NEXT: unreachable, !annotation [[META13]] -// OPT2: [[CONT]]: -// OPT2-NEXT: [[TMP3:%.*]] = icmp ule ptr [[ARRAYIDX]], [[TMP1]], !annotation [[META13]] -// OPT2-NEXT: br i1 [[TMP3]], label %[[CONT2:.*]], label %[[TRAP1:.*]], !prof [[PROF14]], !annotation [[META13]] -// OPT2: [[TRAP1]]: -// OPT2-NEXT: call void asm sideeffect "", "n"(i64 1), !annotation [[META13]] -// OPT2-NEXT: call void @llvm.ubsantrap(i8 25) #[[ATTR3]], !annotation [[META13]] -// OPT2-NEXT: unreachable, !annotation [[META13]] -// OPT2: [[CONT2]]: -// OPT2-NEXT: [[TMP4:%.*]] = icmp uge ptr [[ARRAYIDX]], [[WIDE_PTR_LB]], !annotation [[META15:![0-9]+]] -// OPT2-NEXT: br i1 [[TMP4]], label %[[CONT4:.*]], label %[[TRAP3:.*]], !prof [[PROF14]], !annotation [[META15]] -// OPT2: [[TRAP3]]: -// OPT2-NEXT: call void asm sideeffect "", "n"(i64 2), !annotation [[META15]] -// OPT2-NEXT: call void @llvm.ubsantrap(i8 25) #[[ATTR3]], !annotation [[META15]] -// OPT2-NEXT: unreachable, !annotation [[META15]] -// OPT2: [[CONT4]]: -// OPT2-NEXT: [[TMP5:%.*]] = load i32, ptr [[ARRAYIDX]], align 4, !tbaa [[TBAA8]] -// OPT2-NEXT: ret i32 [[TMP5]] -// -//. -// OPT0: [[META2]] = !{!"bounds-safety-check-ptr-le-upper-bound"} -// OPT0: [[PROF3]] = !{!"branch_weights", i32 1048575, i32 1} -// OPT0: [[META4]] = !{!"bounds-safety-check-ptr-ge-lower-bound"} -//. -// OPT2: [[TBAA2]] = !{[[META3:![0-9]+]], [[META3]], i64 0} -// OPT2: [[META3]] = !{!"p2 int", [[META4:![0-9]+]], i64 0} -// OPT2: [[META4]] = !{!"any p2 pointer", [[META5:![0-9]+]], i64 0} -// OPT2: [[META5]] = !{!"any pointer", [[META6:![0-9]+]], i64 0} -// OPT2: [[META6]] = !{!"omnipotent char", [[META7:![0-9]+]], i64 0} -// OPT2: [[META7]] = !{!"Simple C/C++ TBAA"} -// OPT2: [[TBAA8]] = !{[[META9:![0-9]+]], [[META9]], i64 0} -// OPT2: [[META9]] = !{!"int", [[META6]], i64 0} -// OPT2: [[TBAA_STRUCT10]] = !{i64 0, i64 24, [[META11:![0-9]+]]} -// OPT2: [[META11]] = !{[[META12:![0-9]+]], [[META12]], i64 0} -// OPT2: [[META12]] = !{!"p1 int", [[META5]], i64 0} -// OPT2: [[META13]] = !{!"bounds-safety-check-ptr-le-upper-bound"} -// OPT2: [[PROF14]] = !{!"branch_weights", i32 1048575, i32 1} -// OPT2: [[META15]] = !{!"bounds-safety-check-ptr-ge-lower-bound"} -//. diff --git a/clang/test/BoundsSafety/CodeGen/unique-trap-blocks-O2.c b/clang/test/BoundsSafety/CodeGen/unique-trap-blocks-O2.c deleted file mode 100644 index 75041f46244bd..0000000000000 --- a/clang/test/BoundsSafety/CodeGen/unique-trap-blocks-O2.c +++ /dev/null @@ -1,142 +0,0 @@ -// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --include-generated-funcs --version 5 - -// Make sure that with or without `-fsplit-cold-code` that the trap blocks don't -// get outlined into their own function. Outlining trap blocks is unhelpful -// because it makes debugging harder which is the opposite of what -// `-funique-trap` is tries to do. - -// RUN: %clang_cc1 -O2 -triple arm64e-apple-ios -fbounds-safety \ -// RUN: -funique-traps -emit-llvm %s -o - -fno-split-cold-code \ -// RUN: | FileCheck %s -// RUN: %clang_cc1 -O2 -triple arm64e-apple-ios -fbounds-safety \ -// RUN: -funique-traps -emit-llvm %s -o - -fsplit-cold-code \ -// RUN: | FileCheck %s - -// FIXME: When using `-fsplit-cold-code` it looks like traps are getting split -// (rdar://150559639). -// XFAIL: * - -#include - -__attribute__((always_inline)) int i_want_to_be_inlined( - int* __bidi_indexable ptr, int idx) { - return ptr[idx]; -} - -// Note: The trap counter is global to the module so even in the presence of -// inlining the counter will be unique. -int consume(int* __bidi_indexable ptr, int* __bidi_indexable ptr2, int idx) { - int other = i_want_to_be_inlined(ptr2, idx); - return ptr[idx]; -} -// CHECK-LABEL: define i32 @i_want_to_be_inlined( -// CHECK-SAME: ptr noundef readonly captures(none) [[PTR:%.*]], i32 noundef [[IDX:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] { -// CHECK-NEXT: [[ENTRY:.*:]] -// CHECK-NEXT: [[AGG_TEMP_SROA_0_0_COPYLOAD:%.*]] = load ptr, ptr [[PTR]], align 8 -// CHECK-NEXT: [[AGG_TEMP_SROA_2_0_PTR_SROA_IDX:%.*]] = getelementptr inbounds nuw i8, ptr [[PTR]], i64 8 -// CHECK-NEXT: [[AGG_TEMP_SROA_2_0_COPYLOAD:%.*]] = load ptr, ptr [[AGG_TEMP_SROA_2_0_PTR_SROA_IDX]], align 8 -// CHECK-NEXT: [[AGG_TEMP_SROA_3_0_PTR_SROA_IDX:%.*]] = getelementptr inbounds nuw i8, ptr [[PTR]], i64 16 -// CHECK-NEXT: [[AGG_TEMP_SROA_3_0_COPYLOAD:%.*]] = load ptr, ptr [[AGG_TEMP_SROA_3_0_PTR_SROA_IDX]], align 8, !tbaa [[TBAA2:![0-9]+]] -// CHECK-NEXT: [[IDXPROM:%.*]] = sext i32 [[IDX]] to i64 -// CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr i32, ptr [[AGG_TEMP_SROA_0_0_COPYLOAD]], i64 [[IDXPROM]] -// CHECK-NEXT: [[TMP0:%.*]] = getelementptr i8, ptr [[ARRAYIDX]], i64 4, !annotation [[META7:![0-9]+]] -// CHECK-NEXT: [[DOTNOT:%.*]] = icmp ugt ptr [[TMP0]], [[AGG_TEMP_SROA_2_0_COPYLOAD]], !annotation [[META7]] -// CHECK-NEXT: br i1 [[DOTNOT]], label %[[TRAP:.*]], label %[[CONT:.*]], !prof [[PROF8:![0-9]+]], !annotation [[META7]] -// CHECK: [[TRAP]]: -// CHECK-NEXT: tail call void asm sideeffect "", "n"(i64 0) #[[ATTR3:[0-9]+]], !annotation [[META7]] -// CHECK-NEXT: tail call void @llvm.ubsantrap(i8 25) #[[ATTR4:[0-9]+]], !annotation [[META7]] -// CHECK-NEXT: unreachable, !annotation [[META7]] -// CHECK: [[CONT]]: -// CHECK-NEXT: [[DOTNOT5:%.*]] = icmp ugt ptr [[ARRAYIDX]], [[TMP0]], !annotation [[META7]] -// CHECK-NEXT: br i1 [[DOTNOT5]], label %[[TRAP1:.*]], label %[[CONT2:.*]], !prof [[PROF8]], !annotation [[META7]] -// CHECK: [[TRAP1]]: -// CHECK-NEXT: tail call void asm sideeffect "", "n"(i64 1) #[[ATTR3]], !annotation [[META7]] -// CHECK-NEXT: tail call void @llvm.ubsantrap(i8 25) #[[ATTR4]], !annotation [[META7]] -// CHECK-NEXT: unreachable, !annotation [[META7]] -// CHECK: [[CONT2]]: -// CHECK-NEXT: [[DOTNOT6:%.*]] = icmp ult ptr [[ARRAYIDX]], [[AGG_TEMP_SROA_3_0_COPYLOAD]], !annotation [[META9:![0-9]+]] -// CHECK-NEXT: br i1 [[DOTNOT6]], label %[[TRAP3:.*]], label %[[CONT4:.*]], !prof [[PROF8]], !annotation [[META9]] -// CHECK: [[TRAP3]]: -// CHECK-NEXT: tail call void asm sideeffect "", "n"(i64 2) #[[ATTR3]], !annotation [[META9]] -// CHECK-NEXT: tail call void @llvm.ubsantrap(i8 25) #[[ATTR4]], !annotation [[META9]] -// CHECK-NEXT: unreachable, !annotation [[META9]] -// CHECK: [[CONT4]]: -// CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[ARRAYIDX]], align 4, !tbaa [[TBAA10:![0-9]+]] -// CHECK-NEXT: ret i32 [[TMP1]] -// -// -// CHECK-LABEL: define i32 @consume( -// CHECK-SAME: ptr noundef readonly captures(none) [[PTR:%.*]], ptr noundef readonly captures(none) [[PTR2:%.*]], i32 noundef [[IDX:%.*]]) local_unnamed_addr #[[ATTR2:[0-9]+]] { -// CHECK-NEXT: [[ENTRY:.*:]] -// CHECK-NEXT: [[BYVAL_TEMP_SROA_0_0_COPYLOAD:%.*]] = load ptr, ptr [[PTR2]], align 8 -// CHECK-NEXT: [[BYVAL_TEMP_SROA_4_0_PTR2_SROA_IDX:%.*]] = getelementptr inbounds nuw i8, ptr [[PTR2]], i64 8 -// CHECK-NEXT: [[BYVAL_TEMP_SROA_4_0_COPYLOAD:%.*]] = load ptr, ptr [[BYVAL_TEMP_SROA_4_0_PTR2_SROA_IDX]], align 8 -// CHECK-NEXT: [[BYVAL_TEMP_SROA_5_0_PTR2_SROA_IDX:%.*]] = getelementptr inbounds nuw i8, ptr [[PTR2]], i64 16 -// CHECK-NEXT: [[BYVAL_TEMP_SROA_5_0_COPYLOAD:%.*]] = load ptr, ptr [[BYVAL_TEMP_SROA_5_0_PTR2_SROA_IDX]], align 8, !tbaa [[TBAA2]] -// CHECK-NEXT: [[IDXPROM_I:%.*]] = sext i32 [[IDX]] to i64 -// CHECK-NEXT: [[ARRAYIDX_I:%.*]] = getelementptr i32, ptr [[BYVAL_TEMP_SROA_0_0_COPYLOAD]], i64 [[IDXPROM_I]] -// CHECK-NEXT: [[TMP0:%.*]] = getelementptr i8, ptr [[ARRAYIDX_I]], i64 4, !annotation [[META7]] -// CHECK-NEXT: [[DOTNOT_I:%.*]] = icmp ugt ptr [[TMP0]], [[BYVAL_TEMP_SROA_4_0_COPYLOAD]], !annotation [[META7]] -// CHECK-NEXT: br i1 [[DOTNOT_I]], label %[[TRAP_I:.*]], label %[[CONT_I:.*]], !prof [[PROF8]], !annotation [[META7]] -// CHECK: [[TRAP_I]]: -// CHECK-NEXT: tail call void asm sideeffect "", "n"(i64 0) #[[ATTR3]], !annotation [[META7]] -// CHECK-NEXT: tail call void @llvm.ubsantrap(i8 25) #[[ATTR4]], !annotation [[META7]] -// CHECK-NEXT: unreachable, !annotation [[META7]] -// CHECK: [[CONT_I]]: -// CHECK-NEXT: [[DOTNOT5_I:%.*]] = icmp ugt ptr [[ARRAYIDX_I]], [[TMP0]], !annotation [[META7]] -// CHECK-NEXT: br i1 [[DOTNOT5_I]], label %[[TRAP1_I:.*]], label %[[CONT2_I:.*]], !prof [[PROF8]], !annotation [[META7]] -// CHECK: [[TRAP1_I]]: -// CHECK-NEXT: tail call void asm sideeffect "", "n"(i64 1) #[[ATTR3]], !annotation [[META7]] -// CHECK-NEXT: tail call void @llvm.ubsantrap(i8 25) #[[ATTR4]], !annotation [[META7]] -// CHECK-NEXT: unreachable, !annotation [[META7]] -// CHECK: [[CONT2_I]]: -// CHECK-NEXT: [[DOTNOT6_I:%.*]] = icmp ult ptr [[ARRAYIDX_I]], [[BYVAL_TEMP_SROA_5_0_COPYLOAD]], !annotation [[META9]] -// CHECK-NEXT: br i1 [[DOTNOT6_I]], label %[[TRAP3_I:.*]], label %[[I_WANT_TO_BE_INLINED_EXIT:.*]], !prof [[PROF8]], !annotation [[META9]] -// CHECK: [[TRAP3_I]]: -// CHECK-NEXT: tail call void asm sideeffect "", "n"(i64 2) #[[ATTR3]], !annotation [[META9]] -// CHECK-NEXT: tail call void @llvm.ubsantrap(i8 25) #[[ATTR4]], !annotation [[META9]] -// CHECK-NEXT: unreachable, !annotation [[META9]] -// CHECK: [[I_WANT_TO_BE_INLINED_EXIT]]: -// CHECK-NEXT: [[AGG_TEMP_SROA_0_0_COPYLOAD:%.*]] = load ptr, ptr [[PTR]], align 8 -// CHECK-NEXT: [[AGG_TEMP_SROA_2_0_PTR_SROA_IDX:%.*]] = getelementptr inbounds nuw i8, ptr [[PTR]], i64 8 -// CHECK-NEXT: [[AGG_TEMP_SROA_2_0_COPYLOAD:%.*]] = load ptr, ptr [[AGG_TEMP_SROA_2_0_PTR_SROA_IDX]], align 8 -// CHECK-NEXT: [[AGG_TEMP_SROA_3_0_PTR_SROA_IDX:%.*]] = getelementptr inbounds nuw i8, ptr [[PTR]], i64 16 -// CHECK-NEXT: [[AGG_TEMP_SROA_3_0_COPYLOAD:%.*]] = load ptr, ptr [[AGG_TEMP_SROA_3_0_PTR_SROA_IDX]], align 8, !tbaa [[TBAA2]] -// CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr i32, ptr [[AGG_TEMP_SROA_0_0_COPYLOAD]], i64 [[IDXPROM_I]] -// CHECK-NEXT: [[TMP1:%.*]] = getelementptr i8, ptr [[ARRAYIDX]], i64 4, !annotation [[META7]] -// CHECK-NEXT: [[DOTNOT:%.*]] = icmp ugt ptr [[TMP1]], [[AGG_TEMP_SROA_2_0_COPYLOAD]], !annotation [[META7]] -// CHECK-NEXT: br i1 [[DOTNOT]], label %[[TRAP:.*]], label %[[CONT:.*]], !prof [[PROF8]], !annotation [[META7]] -// CHECK: [[TRAP]]: -// CHECK-NEXT: tail call void asm sideeffect "", "n"(i64 3) #[[ATTR3]], !annotation [[META7]] -// CHECK-NEXT: tail call void @llvm.ubsantrap(i8 25) #[[ATTR4]], !annotation [[META7]] -// CHECK-NEXT: unreachable, !annotation [[META7]] -// CHECK: [[CONT]]: -// CHECK-NEXT: [[DOTNOT6:%.*]] = icmp ugt ptr [[ARRAYIDX]], [[TMP1]], !annotation [[META7]] -// CHECK-NEXT: br i1 [[DOTNOT6]], label %[[TRAP1:.*]], label %[[CONT2:.*]], !prof [[PROF8]], !annotation [[META7]] -// CHECK: [[TRAP1]]: -// CHECK-NEXT: tail call void asm sideeffect "", "n"(i64 4) #[[ATTR3]], !annotation [[META7]] -// CHECK-NEXT: tail call void @llvm.ubsantrap(i8 25) #[[ATTR4]], !annotation [[META7]] -// CHECK-NEXT: unreachable, !annotation [[META7]] -// CHECK: [[CONT2]]: -// CHECK-NEXT: [[DOTNOT7:%.*]] = icmp ult ptr [[ARRAYIDX]], [[AGG_TEMP_SROA_3_0_COPYLOAD]], !annotation [[META9]] -// CHECK-NEXT: br i1 [[DOTNOT7]], label %[[TRAP3:.*]], label %[[CONT4:.*]], !prof [[PROF8]], !annotation [[META9]] -// CHECK: [[TRAP3]]: -// CHECK-NEXT: tail call void asm sideeffect "", "n"(i64 5) #[[ATTR3]], !annotation [[META9]] -// CHECK-NEXT: tail call void @llvm.ubsantrap(i8 25) #[[ATTR4]], !annotation [[META9]] -// CHECK-NEXT: unreachable, !annotation [[META9]] -// CHECK: [[CONT4]]: -// CHECK-NEXT: [[TMP2:%.*]] = load i32, ptr [[ARRAYIDX]], align 4, !tbaa [[TBAA10]] -// CHECK-NEXT: ret i32 [[TMP2]] -// -//. -// CHECK: [[TBAA2]] = !{[[META3:![0-9]+]], [[META3]], i64 0} -// CHECK: [[META3]] = !{!"p1 int", [[META4:![0-9]+]], i64 0} -// CHECK: [[META4]] = !{!"any pointer", [[META5:![0-9]+]], i64 0} -// CHECK: [[META5]] = !{!"omnipotent char", [[META6:![0-9]+]], i64 0} -// CHECK: [[META6]] = !{!"Simple C/C++ TBAA"} -// CHECK: [[META7]] = !{!"bounds-safety-check-ptr-le-upper-bound"} -// CHECK: [[PROF8]] = !{!"branch_weights", i32 1, i32 1048575} -// CHECK: [[META9]] = !{!"bounds-safety-check-ptr-ge-lower-bound"} -// CHECK: [[TBAA10]] = !{[[META11:![0-9]+]], [[META11]], i64 0} -// CHECK: [[META11]] = !{!"int", [[META5]], i64 0} -//. diff --git a/llvm/lib/Transforms/IPO/HotColdSplitting.cpp b/llvm/lib/Transforms/IPO/HotColdSplitting.cpp index aa87f2eb2856b..3d8b7cbb59630 100644 --- a/llvm/lib/Transforms/IPO/HotColdSplitting.cpp +++ b/llvm/lib/Transforms/IPO/HotColdSplitting.cpp @@ -37,9 +37,6 @@ #include "llvm/Analysis/TargetTransformInfo.h" #include "llvm/IR/BasicBlock.h" #include "llvm/IR/CFG.h" -/* TO_UPSTREAM(BoundsSafety) ON*/ -#include "llvm/IR/Constants.h" -/* TO_UPSTREAM(BoundsSafety) OFF*/ #include "llvm/IR/DiagnosticInfo.h" #include "llvm/IR/Dominators.h" #include "llvm/IR/EHPersonalities.h" @@ -137,27 +134,6 @@ void analyzeProfMetadata(BasicBlock *BB, AnnotatedColdBlocks.insert(CondBr->getSuccessor(1)); } -/* TO_UPSTREAM(BoundsSafety) ON*/ -bool isBoundsSafetyTrapCall(const CallBase *CB) { - const auto *CF = CB->getCalledFunction(); - if (!CF) - return false; - if (!CF->isIntrinsic()) - return false; - if (CF->getIntrinsicID() != Intrinsic::ubsantrap) - return false; - - assert(CB->arg_size() == 1); - const auto *Arg = CB->getArgOperand(0); - const auto *ConstArg = cast(Arg); - - auto ArgValue = ConstArg->getZExtValue(); - assert(ArgValue <= UINT8_MAX); - // FIXME: Don't hardcode this value - return ArgValue == 0x19; -} -/* TO_UPSTREAM(BoundsSafety) OFF*/ - bool unlikelyExecuted(BasicBlock &BB) { // Exception handling blocks are unlikely executed. if (BB.isEHPad() || isa(BB.getTerminator())) @@ -168,10 +144,7 @@ bool unlikelyExecuted(BasicBlock &BB) { for (Instruction &I : BB) if (auto *CB = dyn_cast(&I)) if (CB->hasFnAttr(Attribute::Cold) && - !CB->getMetadata(LLVMContext::MD_nosanitize) && - /* TO_UPSTREAM(BoundsSafety) ON*/ - !isBoundsSafetyTrapCall(CB) - /* TO_UPSTREAM(BoundsSafety) OFF*/) + !CB->getMetadata(LLVMContext::MD_nosanitize)) return true; // The block is cold if it has an unreachable terminator, unless it's diff --git a/llvm/test/Transforms/HotColdSplit/no-outline-bounds-safety-traps.ll b/llvm/test/Transforms/HotColdSplit/no-outline-bounds-safety-traps.ll deleted file mode 100644 index 148bb042dc384..0000000000000 --- a/llvm/test/Transforms/HotColdSplit/no-outline-bounds-safety-traps.ll +++ /dev/null @@ -1,44 +0,0 @@ -; RUN: opt -passes=hotcoldsplit -hotcoldsplit-threshold=0 -S < %s | FileCheck %s - -target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" -target triple = "x86_64-apple-macosx10.14.0" - -declare void @_Z10sideeffectv() -declare void @llvm.ubsantrap(i8 immarg) cold noreturn nounwind - -; Don't outline -fbounds-safety traps - -; CHECK-LABEL: define {{.*}}@foo( -; CHECK-NOT: foo.cold.1 -define void @foo(i32, ptr) { - %3 = icmp eq i32 %0, 0 - tail call void @_Z10sideeffectv() - br i1 %3, label %5, label %4 - -;