[llvm-commits] [llvm] r108568 - in /llvm/trunk: lib/CodeGen/AsmPrinter/AsmPrinter.cpp test/CodeGen/PowerPC/2008-01-25-EmptyFunction.ll test/CodeGen/PowerPC/empty-functions.ll test/CodeGen/X86/2008-01-25-EmptyFunction.ll test/CodeGen/X86/empty-functions.ll
Bill Wendling
isanbard at gmail.com
Fri Jul 16 15:51:10 PDT 2010
Author: void
Date: Fri Jul 16 17:51:10 2010
New Revision: 108568
URL: http://llvm.org/viewvc/llvm-project?rev=108568&view=rev
Log:
Consider this function:
void foo() { __builtin_unreachable(); }
It will output the following on Darwin X86:
_func1:
Leh_func_begin0:
pushq %rbp
Ltmp0:
movq %rsp, %rbp
Ltmp1:
Leh_func_end0:
This prolog adds a new Call Frame Information (CFI) row to the FDE with an
address that is not within the address range of the code it describes -- part is
equal to the end of the function -- and therefore results in an invalid EH
frame. If we emit a nop in this situation, then the CFI row is now within the
address range.
Added:
llvm/trunk/test/CodeGen/PowerPC/empty-functions.ll
- copied, changed from r108562, llvm/trunk/test/CodeGen/PowerPC/2008-01-25-EmptyFunction.ll
llvm/trunk/test/CodeGen/X86/empty-functions.ll
Removed:
llvm/trunk/test/CodeGen/PowerPC/2008-01-25-EmptyFunction.ll
llvm/trunk/test/CodeGen/X86/2008-01-25-EmptyFunction.ll
Modified:
llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=108568&r1=108567&r2=108568&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Fri Jul 16 17:51:10 2010
@@ -599,12 +599,15 @@
// Print out code for the function.
bool HasAnyRealCode = false;
+ const MachineInstr *LastMI = 0;
for (MachineFunction::const_iterator I = MF->begin(), E = MF->end();
I != E; ++I) {
// Print a label for the basic block.
EmitBasicBlockStart(I);
for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end();
II != IE; ++II) {
+ LastMI = II;
+
// Print the assembly for the instruction.
if (!II->isLabel() && !II->isImplicitDef() && !II->isKill() &&
!II->isDebugValue()) {
@@ -652,11 +655,18 @@
}
}
}
-
+
+ // If the last instruction was a prolog label, then we have a situation where
+ // we emitted a prolog but no function body. This results in the ending prolog
+ // label equaling the end of function label and an invalid "row" in the
+ // FDE. We need to emit a noop in this situation so that the FDE's rows are
+ // valid.
+ bool RequiresNoop = LastMI && LastMI->getOpcode()==TargetOpcode::PROLOG_LABEL;
+
// If the function is empty and the object file uses .subsections_via_symbols,
// then we need to emit *something* to the function body to prevent the
// labels from collapsing together. Just emit a noop.
- if (MAI->hasSubsectionsViaSymbols() && !HasAnyRealCode) {
+ if ((MAI->hasSubsectionsViaSymbols() && !HasAnyRealCode) || RequiresNoop) {
MCInst Noop;
TM.getInstrInfo()->getNoopForMachoTarget(Noop);
if (Noop.getOpcode()) {
Removed: llvm/trunk/test/CodeGen/PowerPC/2008-01-25-EmptyFunction.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/PowerPC/2008-01-25-EmptyFunction.ll?rev=108567&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/PowerPC/2008-01-25-EmptyFunction.ll (original)
+++ llvm/trunk/test/CodeGen/PowerPC/2008-01-25-EmptyFunction.ll (removed)
@@ -1,8 +0,0 @@
-; RUN: llc < %s -march=ppc32 | grep nop
-target triple = "powerpc-apple-darwin8"
-
-
-define void @bork() noreturn nounwind {
-entry:
- unreachable
-}
Copied: llvm/trunk/test/CodeGen/PowerPC/empty-functions.ll (from r108562, llvm/trunk/test/CodeGen/PowerPC/2008-01-25-EmptyFunction.ll)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/PowerPC/empty-functions.ll?p2=llvm/trunk/test/CodeGen/PowerPC/empty-functions.ll&p1=llvm/trunk/test/CodeGen/PowerPC/2008-01-25-EmptyFunction.ll&r1=108562&r2=108568&rev=108568&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/PowerPC/2008-01-25-EmptyFunction.ll (original)
+++ llvm/trunk/test/CodeGen/PowerPC/empty-functions.ll Fri Jul 16 17:51:10 2010
@@ -1,8 +1,12 @@
-; RUN: llc < %s -march=ppc32 | grep nop
-target triple = "powerpc-apple-darwin8"
+; RUN: llc < %s -mtriple=powerpc-apple-darwin | FileCheck -check-prefix=CHECK-NO-FP %s
+; RUN: llc < %s -mtriple=powerpc-apple-darwin -disable-fp-elim | FileCheck -check-prefix=CHECK-FP %s
-
-define void @bork() noreturn nounwind {
+define void @func() {
entry:
- unreachable
+ unreachable
}
+; CHECK-NO-FP: _func:
+; CHECK-NO-FP: nop
+
+; CHECK-FP: _func:
+; CHECK-FP: nop
Removed: llvm/trunk/test/CodeGen/X86/2008-01-25-EmptyFunction.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/2008-01-25-EmptyFunction.ll?rev=108567&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/2008-01-25-EmptyFunction.ll (original)
+++ llvm/trunk/test/CodeGen/X86/2008-01-25-EmptyFunction.ll (removed)
@@ -1,8 +0,0 @@
-; RUN: llc < %s -march=x86 | grep nop
-target triple = "i686-apple-darwin8"
-
-
-define void @bork() noreturn nounwind {
-entry:
- unreachable
-}
Added: llvm/trunk/test/CodeGen/X86/empty-functions.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/empty-functions.ll?rev=108568&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/empty-functions.ll (added)
+++ llvm/trunk/test/CodeGen/X86/empty-functions.ll Fri Jul 16 17:51:10 2010
@@ -0,0 +1,15 @@
+; RUN: llc < %s -mtriple=x86_64-apple-darwin | FileCheck -check-prefix=CHECK-NO-FP %s
+; RUN: llc < %s -mtriple=x86_64-apple-darwin -disable-fp-elim | FileCheck -check-prefix=CHECK-FP %s
+
+define void @func() {
+entry:
+ unreachable
+}
+; CHECK-NO-FP: _func:
+; CHECK-NO-FP-NOT: movq %rsp, %rbp
+; CHECK-NO-FP: nop
+
+; CHECK-FP: _func:
+; CHECK-FP: movq %rsp, %rbp
+; CHECK-FP-NEXT: Ltmp1:
+; CHECK-FP: nop
More information about the llvm-commits
mailing list