Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit e9322d8

Browse files
committed
AArch64: Don't emit CFI for SCS register in nounwind functions.
All that you can legitimately do with the CFI for a nounwind function is get a backtrace, and adjusting the SCS register is not (currently) required for this purpose. Differential Revision: https://reviews.llvm.org/D54988 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@348035 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 5f1a766 commit e9322d8

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

lib/Target/AArch64/AArch64FrameLowering.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,20 +1733,22 @@ bool AArch64FrameLowering::spillCalleeSavedRegisters(
17331733
BuildMI(MBB, MI, DL, TII.get(AArch64::SEH_Nop))
17341734
.setMIFlag(MachineInstr::FrameSetup);
17351735

1736-
// Emit a CFI instruction that causes 8 to be subtracted from the value of
1737-
// x18 when unwinding past this frame.
1738-
static const char CFIInst[] = {
1739-
dwarf::DW_CFA_val_expression,
1740-
18, // register
1741-
2, // length
1742-
static_cast<char>(unsigned(dwarf::DW_OP_breg18)),
1743-
static_cast<char>(-8) & 0x7f, // addend (sleb128)
1744-
};
1745-
unsigned CFIIndex =
1746-
MF.addFrameInst(MCCFIInstruction::createEscape(nullptr, CFIInst));
1747-
BuildMI(MBB, MI, DL, TII.get(AArch64::CFI_INSTRUCTION))
1748-
.addCFIIndex(CFIIndex)
1749-
.setMIFlag(MachineInstr::FrameSetup);
1736+
if (!MF.getFunction().hasFnAttribute(Attribute::NoUnwind)) {
1737+
// Emit a CFI instruction that causes 8 to be subtracted from the value of
1738+
// x18 when unwinding past this frame.
1739+
static const char CFIInst[] = {
1740+
dwarf::DW_CFA_val_expression,
1741+
18, // register
1742+
2, // length
1743+
static_cast<char>(unsigned(dwarf::DW_OP_breg18)),
1744+
static_cast<char>(-8) & 0x7f, // addend (sleb128)
1745+
};
1746+
unsigned CFIIndex =
1747+
MF.addFrameInst(MCCFIInstruction::createEscape(nullptr, CFIInst));
1748+
BuildMI(MBB, MI, DL, TII.get(AArch64::CFI_INSTRUCTION))
1749+
.addCFIIndex(CFIIndex)
1750+
.setMIFlag(MachineInstr::FrameSetup);
1751+
}
17501752

17511753
// This instruction also makes x18 live-in to the entry block.
17521754
MBB.addLiveIn(AArch64::X18);

test/CodeGen/AArch64/shadow-call-stack.ll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,11 @@ define i32 @f4() shadowcallstack {
4646
; CHECK: ret
4747
ret i32 %res1234
4848
}
49+
50+
define i32 @f5() shadowcallstack nounwind {
51+
; CHECK: f5:
52+
; CHECK-NOT: .cfi_escape
53+
%res = call i32 @bar()
54+
%res1 = add i32 %res, 1
55+
ret i32 %res
56+
}

0 commit comments

Comments
 (0)