Skip to content

Commit

Permalink
[𝘀𝗽𝗿] changes introduced through rebase
Browse files Browse the repository at this point in the history
Created using spr 1.3.4

[skip ci]
  • Loading branch information
vitalybuka committed Aug 1, 2024
2 parents a0e255a + ae6dc64 commit df07909
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 7 deletions.
2 changes: 2 additions & 0 deletions clang/lib/CodeGen/CGExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3882,6 +3882,8 @@ llvm::CallInst *CodeGenFunction::EmitTrapCall(llvm::Intrinsic::ID IntrID) {
TrapCall->addFnAttr(A);
}

if (InNoMergeAttributedStmt)
TrapCall->addFnAttr(llvm::Attribute::NoMerge);
return TrapCall;
}

Expand Down
8 changes: 7 additions & 1 deletion clang/test/CodeGen/attr-nomerge.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %clang_cc1 -emit-llvm %s -triple x86_64-unknown-linux-gnu -o - | FileCheck %s
// RUN: %clang_cc1 -emit-llvm %s -fms-extensions -o - | FileCheck %s

class A {
public:
Expand Down Expand Up @@ -42,6 +42,9 @@ void foo(int i, A *ap, B *bp) {

A *newA = new B();
delete newA;
[[clang::nomerge]] __builtin_trap();
[[clang::nomerge]] __debugbreak();
[[clang::nomerge]] __builtin_verbose_trap("check null", "Argument must not be null.");
}

int g(int i);
Expand Down Expand Up @@ -97,6 +100,9 @@ void something_else_again() {
// CHECK: load ptr, ptr
// CHECK: %[[AG:.*]] = load ptr, ptr
// CHECK-NEXT: call void %[[AG]](ptr {{.*}}) #[[ATTR1]]
// CHECK: call void @llvm.trap() #[[ATTR0]]
// CHECK: call void @llvm.debugtrap() #[[ATTR0]]
// CHECK: call void @llvm.trap() #[[ATTR0]]
// CHECK: call void @_ZN1AD1Ev(ptr {{.*}}) #[[ATTR1]]

// CHECK-DAG: attributes #[[ATTR0]] = {{{.*}}nomerge{{.*}}}
Expand Down
4 changes: 3 additions & 1 deletion llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7448,6 +7448,8 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
break;
default: llvm_unreachable("unknown trap intrinsic");
}
DAG.addNoMergeSiteInfo(DAG.getRoot().getNode(),
I.hasFnAttr(Attribute::NoMerge));
return;
}
TargetLowering::ArgListTy Args;
Expand All @@ -7464,7 +7466,7 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
DAG.getExternalSymbol(TrapFuncName.data(),
TLI.getPointerTy(DAG.getDataLayout())),
std::move(Args));

CLI.NoMerge = I.hasFnAttr(Attribute::NoMerge);
std::pair<SDValue, SDValue> Result = TLI.LowerCallTo(CLI);
DAG.setRoot(Result.second);
return;
Expand Down
92 changes: 92 additions & 0 deletions llvm/test/CodeGen/X86/nomerge.ll
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,96 @@ if.end:

declare dso_local void @bar()

define void @nomerge_trap(i32 %i) {
; CHECK-LABEL: nomerge_trap:
; CHECK: # %bb.0: # %entry
; CHECK: # %bb.1: # %entry
; CHECK: # %bb.2: # %if.then
; CHECK-NEXT: ud2
; CHECK-NEXT: LBB{{.*}}: # %if.then2
; CHECK-NEXT: ud2
; CHECK-NEXT: .LBB{{.*}}: # %if.end3
; CHECK-NEXT: ud2
entry:
switch i32 %i, label %if.end3 [
i32 5, label %if.then
i32 7, label %if.then2
]

if.then:
tail call void @llvm.trap() #0
unreachable

if.then2:
tail call void @llvm.trap() #0
unreachable

if.end3:
tail call void @llvm.trap() #0
unreachable
}

declare dso_local void @llvm.trap()

define void @nomerge_debugtrap(i32 %i) {
; CHECK-LABEL: nomerge_debugtrap:
; CHECK: # %bb.0: # %entry
; CHECK: # %bb.1: # %entry
; CHECK: # %bb.2: # %if.then
; CHECK-NEXT: int3
; CHECK-NEXT: LBB{{.*}}: # %if.then2
; CHECK-NEXT: int3
; CHECK-NEXT: .LBB{{.*}}: # %if.end3
; CHECK-NEXT: int3
entry:
switch i32 %i, label %if.end3 [
i32 5, label %if.then
i32 7, label %if.then2
]

if.then:
tail call void @llvm.debugtrap() #0
unreachable

if.then2:
tail call void @llvm.debugtrap() #0
unreachable

if.end3:
tail call void @llvm.debugtrap() #0
unreachable
}

define void @nomerge_named_debugtrap(i32 %i) {
; CHECK-LABEL: nomerge_named_debugtrap:
; CHECK: # %bb.0: # %entry
; CHECK: # %bb.1: # %entry
; CHECK: # %bb.2: # %if.then
; CHECK-NEXT: callq trap_func@PLT
; CHECK-NEXT: LBB{{.*}}: # %if.then2
; CHECK-NEXT: callq trap_func@PLT
; CHECK-NEXT: .LBB{{.*}}: # %if.end3
; CHECK-NEXT: callq trap_func@PLT
entry:
switch i32 %i, label %if.end3 [
i32 5, label %if.then
i32 7, label %if.then2
]

if.then:
tail call void @llvm.debugtrap() #1
unreachable

if.then2:
tail call void @llvm.debugtrap() #1
unreachable

if.end3:
tail call void @llvm.debugtrap() #1
unreachable
}

declare dso_local void @llvm.debugtrap()

attributes #0 = { nomerge }
attributes #1 = { nomerge "trap-func-name"="trap_func" }
12 changes: 7 additions & 5 deletions llvm/test/MC/AArch64/local-bounds-single-trap.ll
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,23 @@ entry:
; CHECK-ASM: add x10, x10, :lo12:B
; CHECK-ASM: strb wzr, [x10, x8]
; CHECK-ASM: cmp x9, #10
; CHECK-ASM: b.hi .LBB0_5
; CHECK-ASM: b.hi .LBB0_6
; CHECK-ASM: // %bb.3:
; CHECK-ASM: mov w8, #10 // =0xa
; CHECK-ASM: sub x8, x8, x9
; CHECK-ASM: cbz x8, .LBB0_5
; CHECK-ASM: cbz x8, .LBB0_6
; CHECK-ASM: // %bb.4:
; CHECK-ASM: adrp x8, B2
; CHECK-ASM: add x8, x8, :lo12:B2
; CHECK-ASM: strb wzr, [x8, x9]
; CHECK-ASM: add sp, sp, #16
; CHECK-ASM: .cfi_def_cfa_offset 0
; CHECK-ASM: ret
; CHECK-ASM: .LBB0_5: // %trap3
; CHECK-ASM: .cfi_restore_state
; CHECK-ASM: brk #0x1
; CHECK-ASM: .LBB0_5: // %trap
; CHECK-ASM: .cfi_restore_state
; CHECK-ASM: brk #0x1
; CHECK-ASM: .LBB0_6: // %trap3
; CHECK-ASM: brk #0x1
%i.addr = alloca i32, align 4
%k.addr = alloca i32, align 4
store i32 %i, ptr %i.addr, align 4
Expand Down

0 comments on commit df07909

Please sign in to comment.