If there's no instructions being emitted on X86 for a function, emit a
authorBill Wendling <isanbard@gmail.com>
Sat, 26 Jan 2008 09:03:52 +0000 (09:03 +0000)
committerBill Wendling <isanbard@gmail.com>
Sat, 26 Jan 2008 09:03:52 +0000 (09:03 +0000)
nop. Emit the nop directly for PPC.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@46398 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/PowerPC/PPCAsmPrinter.cpp
lib/Target/X86/X86ATTAsmPrinter.cpp
test/CodeGen/X86/2008-01-25-EmptyFunction.ll [new file with mode: 0644]

index 6a1451d5dcfd1fd61f114d24bd8b48a3210ce034..6f0e41aec5fc798280abf33ac9bc29a415ca2ab4 100644 (file)
@@ -819,12 +819,8 @@ bool DarwinAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
   // be associated with. We emit a noop in this situation.
   MachineFunction::iterator I = MF.begin();
 
-  if (++I == MF.end()) {
-    MachineBasicBlock &MBB = MF.front();
-
-    if (MBB.begin() == MBB.end())
-      BuildMI(MBB, MBB.end(), TM.getInstrInfo()->get(PPC::NOP));
-  }
+  if (++I == MF.end() && MF.front().empty())
+    O << "\tnop\n";
 
   // Print out code for the function.
   for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
index 8198fbe860e62771d63a9c3b43f229cb08fb9ebc..20f2f003722d72e0e73a79164fac270a6128b2ef 100644 (file)
@@ -165,6 +165,16 @@ bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
     DW.BeginFunction(&MF);
   }
 
+  if (Subtarget->isTargetDarwin()) {
+    // If the function is empty, then we need to emit *something*. Otherwise,
+    // the function's label might be associated with something that it wasn't
+    // meant to be associated with. We emit a noop in this situation.
+    MachineFunction::iterator I = MF.begin();
+
+    if (++I == MF.end() && MF.front().empty())
+      O << "\tnop\n";
+  }
+
   // Print out code for the function.
   for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
        I != E; ++I) {
@@ -173,8 +183,8 @@ bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
       printBasicBlockLabel(I, true);
       O << '\n';
     }
-    for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
-         II != E; ++II) {
+    for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end();
+         II != IE; ++II) {
       // Print the assembly for the instruction.
       O << "\t";
       printMachineInstruction(II);
diff --git a/test/CodeGen/X86/2008-01-25-EmptyFunction.ll b/test/CodeGen/X86/2008-01-25-EmptyFunction.ll
new file mode 100644 (file)
index 0000000..7d738bc
--- /dev/null
@@ -0,0 +1,6 @@
+; RUN: llvm-as < %s | llc -march=x86 | grep nop
+
+define void @bork() noreturn nounwind  {
+entry:
+        unreachable
+}