diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def index 1d79421e952bb..892f66d67b57a 100644 --- a/clang/include/clang/Basic/CodeGenOptions.def +++ b/clang/include/clang/Basic/CodeGenOptions.def @@ -336,10 +336,11 @@ 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. + +CODEGENOPT(BoundsSafetyUniqueTraps, 1, 0, Benign) ///< When true, merging of + /// -fbounds-safety trap + /// instructions will be + /// prevented. /* 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..accdea5b69043 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -2036,6 +2036,18 @@ def fno_bounds_safety_bringup_missing_checks : Flag<["-"], "fno-bounds-safety-br Alias, AliasArgs<["all"]>, HelpText<"Disable new -fbounds-safety run-time checks">; +defm bounds_safety_unique_traps : BoolFOption<"bounds-safety-unique-traps", + CodeGenOpts<"BoundsSafetyUniqueTraps">, DefaultFalse, + PosFlag, + NegFlag>; +// TO_UPSTREAM(BoundsSafety) OFF + defm lifetime_safety : BoolFOption< "experimental-lifetime-safety", LangOpts<"EnableLifetimeSafety">, DefaultFalse, @@ -4445,16 +4457,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..e6db19e454796 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()); @@ -4802,9 +4797,9 @@ void CodeGenFunction::EmitBoundsSafetyTrapCheck(llvm::Value *Checked, // We still need to pass `OptRemark` because not all emitted instructions // can be covered by BoundsSafetyOptRemarkScope. This is because EmitTrapCheck // caches basic blocks that contain instructions that need annotating. - EmitTrapCheck(Checked, SanitizerHandler::BoundsSafety, /*NoMerge=*/false, - /*TR=*/nullptr, - GetBoundsSafetyOptRemarkString(OptRemark), + EmitTrapCheck(Checked, SanitizerHandler::BoundsSafety, + /*NoMerge=*/CGM.getCodeGenOpts().BoundsSafetyUniqueTraps, + /*TR=*/nullptr, GetBoundsSafetyOptRemarkString(OptRemark), GetBoundsSafetyTrapMessageSuffix(kind, TrapCtx)); } 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..6d6e5296a8e7a 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -7042,8 +7042,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &Job, << "-ftrap-function-returns" << "-ftrap-function="; } - Args.addOptInFlag(CmdArgs, options::OPT_funique_traps, - options::OPT_fno_unique_traps); + Args.addOptInFlag(CmdArgs, options::OPT_fbounds_safety_unique_traps, + options::OPT_fno_bounds_safety_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/CodeGen/unique-trap-blocks-O0-O2-opt-disabled.c b/clang/test/BoundsSafety/CodeGen/unique-traps-O0-O2-opt-disabled.c similarity index 85% rename from clang/test/BoundsSafety/CodeGen/unique-trap-blocks-O0-O2-opt-disabled.c rename to clang/test/BoundsSafety/CodeGen/unique-traps-O0-O2-opt-disabled.c index 42da2b8d2dfd0..c52e40f2397c9 100644 --- a/clang/test/BoundsSafety/CodeGen/unique-trap-blocks-O0-O2-opt-disabled.c +++ b/clang/test/BoundsSafety/CodeGen/unique-traps-O0-O2-opt-disabled.c @@ -1,16 +1,13 @@ -// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --include-generated-funcs --version 5 +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-globals all --version 5 // RUN: %clang_cc1 -O0 -triple arm64e-apple-ios -fbounds-safety \ -// RUN: -funique-traps -emit-llvm %s -o - \ +// RUN: -fbounds-safety-unique-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: -fbounds-safety-unique-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:.*:]] @@ -33,28 +30,24 @@ int consume(int* __bidi_indexable ptr, int idx) { // 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:.*:]] @@ -77,32 +70,49 @@ int consume(int* __bidi_indexable ptr, int idx) { // 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]] // +int consume(int* __bidi_indexable ptr, int idx) { + return ptr[idx]; +} +// +// +// +//. +// OPT0: attributes #[[ATTR0]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" } +// OPT0: attributes #[[ATTR1:[0-9]+]] = { nocallback nofree nounwind willreturn memory(argmem: readwrite) } +// OPT0: attributes #[[ATTR2:[0-9]+]] = { cold noreturn nounwind memory(inaccessiblemem: write) } +// OPT0: attributes #[[ATTR3]] = { nomerge noreturn nounwind } +//. +// OPT2: attributes #[[ATTR0]] = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" } +// OPT2: attributes #[[ATTR1:[0-9]+]] = { nocallback nofree nounwind willreturn memory(argmem: readwrite) } +// OPT2: attributes #[[ATTR2:[0-9]+]] = { cold noreturn nounwind memory(inaccessiblemem: write) } +// OPT2: attributes #[[ATTR3]] = { nomerge noreturn nounwind } //. +// OPT0: [[META0:![0-9]+]] = !{i32 1, !"wchar_size", i32 4} +// OPT0: [[META1:![0-9]+]] = !{!"{{.*}}clang version {{.*}}"} // 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: [[META0:![0-9]+]] = !{i32 1, !"wchar_size", i32 4} +// OPT2: [[META1:![0-9]+]] = !{!"{{.*}}clang version {{.*}}"} // 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} diff --git a/clang/test/BoundsSafety/CodeGen/unique-trap-blocks-O2.c b/clang/test/BoundsSafety/CodeGen/unique-traps-O2.c similarity index 77% rename from clang/test/BoundsSafety/CodeGen/unique-trap-blocks-O2.c rename to clang/test/BoundsSafety/CodeGen/unique-traps-O2.c index 75041f46244bd..bc5f7c7d6b7e6 100644 --- a/clang/test/BoundsSafety/CodeGen/unique-trap-blocks-O2.c +++ b/clang/test/BoundsSafety/CodeGen/unique-traps-O2.c @@ -1,36 +1,21 @@ -// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --include-generated-funcs --version 5 +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-globals all --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. +// `-fbounds-safety-unique-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: -fbounds-safety-unique-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: -fbounds-safety-unique-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]; -} +// This should have 3 traps // 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-SAME: ptr dead_on_return 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 @@ -43,30 +28,32 @@ int consume(int* __bidi_indexable ptr, int* __bidi_indexable ptr2, int idx) { // 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: tail call void @llvm.ubsantrap(i8 25) #[[ATTR3:[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: tail call void @llvm.ubsantrap(i8 25) #[[ATTR3]], !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: tail call void @llvm.ubsantrap(i8 25) #[[ATTR3]], !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]] // -// +__attribute__((always_inline)) int i_want_to_be_inlined( + int* __bidi_indexable ptr, int idx) { + return ptr[idx]; +} + +// This should have 6 traps // 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-SAME: ptr dead_on_return noundef readonly captures(none) [[PTR:%.*]], ptr dead_on_return 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 @@ -79,22 +66,19 @@ int consume(int* __bidi_indexable ptr, int* __bidi_indexable ptr2, int idx) { // 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: tail call void @llvm.ubsantrap(i8 25) #[[ATTR3]], !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: tail call void @llvm.ubsantrap(i8 25) #[[ATTR3]], !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: tail call void @llvm.ubsantrap(i8 25) #[[ATTR3]], !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 @@ -107,28 +91,39 @@ int consume(int* __bidi_indexable ptr, int* __bidi_indexable ptr2, int idx) { // 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: tail call void @llvm.ubsantrap(i8 25) #[[ATTR3]], !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: tail call void @llvm.ubsantrap(i8 25) #[[ATTR3]], !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: tail call void @llvm.ubsantrap(i8 25) #[[ATTR3]], !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]] // +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: attributes #[[ATTR0]] = { alwaysinline nounwind memory(read, inaccessiblemem: write) "no-trapping-math"="true" "stack-protector-buffer-size"="8" } +// CHECK: attributes #[[ATTR1:[0-9]+]] = { cold noreturn nounwind memory(inaccessiblemem: write) } +// CHECK: attributes #[[ATTR2]] = { nounwind memory(read, inaccessiblemem: write) "no-trapping-math"="true" "stack-protector-buffer-size"="8" } +// CHECK: attributes #[[ATTR3]] = { nomerge noreturn nounwind } //. +// CHECK: [[META0:![0-9]+]] = !{i32 1, !"wchar_size", i32 4} +// CHECK: [[META1:![0-9]+]] = !{!"{{.*}}clang version {{.*}}"} // 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} diff --git a/clang/test/BoundsSafety-legacy-checks/CodeGen/unique-trap-blocks-O0-O2-opt-disabled.c b/clang/test/BoundsSafety/CodeGen/unique-traps-disabled-O0-O2-opt-disabled.c similarity index 61% rename from clang/test/BoundsSafety-legacy-checks/CodeGen/unique-trap-blocks-O0-O2-opt-disabled.c rename to clang/test/BoundsSafety/CodeGen/unique-traps-disabled-O0-O2-opt-disabled.c index 2486b1208b39e..d2799d9f1406b 100644 --- a/clang/test/BoundsSafety-legacy-checks/CodeGen/unique-trap-blocks-O0-O2-opt-disabled.c +++ b/clang/test/BoundsSafety/CodeGen/unique-traps-disabled-O0-O2-opt-disabled.c @@ -1,17 +1,13 @@ -// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --include-generated-funcs --version 5 - +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-globals all --version 5 // RUN: %clang_cc1 -O0 -triple arm64e-apple-ios -fbounds-safety \ -// RUN: -funique-traps -emit-llvm %s -o - \ +// RUN: -fno-bounds-safety-unique-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: -fno-bounds-safety-unique-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:.*:]] @@ -30,23 +26,27 @@ int consume(int* __bidi_indexable ptr, int idx) { // 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-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: [[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-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 [[META4]] +// 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 @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]] -// +// 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]+]] { @@ -66,28 +66,44 @@ int consume(int* __bidi_indexable ptr, int idx) { // 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-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: [[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: call void @llvm.ubsantrap(i8 25) #[[ATTR3:[0-9]+]], !annotation [[META15:![0-9]+]] // OPT2-NEXT: unreachable, !annotation [[META15]] +// OPT2: [[CONT]]: +// OPT2-NEXT: [[TMP3:%.*]] = icmp ule ptr [[ARRAYIDX]], [[TMP1]], !annotation [[META13]] +// OPT2-NEXT: br i1 [[TMP3]], label %[[CONT1:.*]], label %[[TRAP]], !prof [[PROF14]], !annotation [[META13]] +// OPT2: [[CONT1]]: +// OPT2-NEXT: [[TMP4:%.*]] = icmp uge ptr [[ARRAYIDX]], [[WIDE_PTR_LB]], !annotation [[META16:![0-9]+]] +// OPT2-NEXT: br i1 [[TMP4]], label %[[CONT2:.*]], label %[[TRAP]], !prof [[PROF14]], !annotation [[META16]] // OPT2: [[CONT2]]: -// OPT2-NEXT: [[TMP3:%.*]] = load i32, ptr [[ARRAYIDX]], align 4, !tbaa [[TBAA8]] -// OPT2-NEXT: ret i32 [[TMP3]] +// OPT2-NEXT: [[TMP5:%.*]] = load i32, ptr [[ARRAYIDX]], align 4, !tbaa [[TBAA8]] +// OPT2-NEXT: ret i32 [[TMP5]] // +int consume(int* __bidi_indexable ptr, int idx) { + return ptr[idx]; +} +//. +// OPT0: attributes #[[ATTR0]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" } +// OPT0: attributes #[[ATTR1:[0-9]+]] = { nocallback nofree nounwind willreturn memory(argmem: readwrite) } +// OPT0: attributes #[[ATTR2:[0-9]+]] = { cold noreturn nounwind memory(inaccessiblemem: write) } +// OPT0: attributes #[[ATTR3]] = { nomerge noreturn nounwind } +//. +// OPT2: attributes #[[ATTR0]] = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" } +// OPT2: attributes #[[ATTR1:[0-9]+]] = { nocallback nofree nounwind willreturn memory(argmem: readwrite) } +// OPT2: attributes #[[ATTR2:[0-9]+]] = { cold noreturn nounwind memory(inaccessiblemem: write) } +// OPT2: attributes #[[ATTR3]] = { noreturn nounwind } //. -// OPT0: [[META2]] = !{!"bounds-safety-check-ptr-lt-upper-bound"} +// OPT0: [[META0:![0-9]+]] = !{i32 1, !"wchar_size", i32 4} +// OPT0: [[META1:![0-9]+]] = !{!"{{.*}}clang version {{.*}}"} +// 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: [[META0:![0-9]+]] = !{i32 1, !"wchar_size", i32 4} +// OPT2: [[META1:![0-9]+]] = !{!"{{.*}}clang version {{.*}}"} // 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} @@ -99,7 +115,8 @@ int consume(int* __bidi_indexable ptr, int idx) { // 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: [[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"} +// OPT2: [[META15]] = !{!"bounds-safety-check-ptr-le-upper-bound", !"bounds-safety-check-ptr-ge-lower-bound"} +// OPT2: [[META16]] = !{!"bounds-safety-check-ptr-ge-lower-bound"} //. 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 - -;