[llvm-commits] [dragonegg] r164895 - in /dragonegg/trunk: src/Convert.cpp test/validator/c/EmptyBlock.c

Duncan Sands baldrick at free.fr
Sat Sep 29 08:25:42 PDT 2012


Author: baldrick
Date: Sat Sep 29 10:25:42 2012
New Revision: 164895

URL: http://llvm.org/viewvc/llvm-project?rev=164895&view=rev
Log:
In some situations (eg unsupported builtin) we may produce no code whatsoever
for a block, which in gcc land wouldn't return, and get confused about whether
the block should be deleted or not.  In this case terminate the block with an
unreachable instruction.

Added:
    dragonegg/trunk/test/validator/c/EmptyBlock.c
Modified:
    dragonegg/trunk/src/Convert.cpp

Modified: dragonegg/trunk/src/Convert.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Convert.cpp?rev=164895&r1=164894&r2=164895&view=diff
==============================================================================
--- dragonegg/trunk/src/Convert.cpp (original)
+++ dragonegg/trunk/src/Convert.cpp Sat Sep 29 10:25:42 2012
@@ -1401,11 +1401,15 @@
     }
   } else { // !ReturnBB
     BasicBlock *CurBB = Builder.GetInsertBlock();
-    // If the previous block has no terminator then it must be empty, remove it.
+    // If the previous block has no terminator then it must be empty.
     if (CurBB->getTerminator() == 0) {
-      assert(CurBB->getName().empty() && CurBB->begin() == CurBB->end() &&
-             "Falling through to a block that doesn't exist!");
-      CurBB->eraseFromParent();
+      assert(CurBB->begin() == CurBB->end() && "Falls through to nowhere!");
+      // If it has a name then it may be branched to or have its address taken.
+      // If it doesn't even have a name then delete it.
+      if (!CurBB->getName().empty())
+        Builder.CreateUnreachable();
+      else
+        CurBB->eraseFromParent();
     }
   }
 

Added: dragonegg/trunk/test/validator/c/EmptyBlock.c
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/test/validator/c/EmptyBlock.c?rev=164895&view=auto
==============================================================================
--- dragonegg/trunk/test/validator/c/EmptyBlock.c (added)
+++ dragonegg/trunk/test/validator/c/EmptyBlock.c Sat Sep 29 10:25:42 2012
@@ -0,0 +1,8 @@
+// RUN: %dragonegg -S %s
+
+void *buf[20];
+
+sub2 (void)
+{
+  __builtin_longjmp (buf, 1);
+}





More information about the llvm-commits mailing list