]> granicus.if.org Git - clang/commitdiff
Skip emission of final return block if possible (e.g., functions with
authorDaniel Dunbar <daniel@zuster.org>
Mon, 26 Jan 2009 21:25:20 +0000 (21:25 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Mon, 26 Jan 2009 21:25:20 +0000 (21:25 +0000)
a unified return).

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

lib/CodeGen/CodeGenFunction.cpp

index 2fd8d638d65760e2cfbfc721b0e9a8bc4356273c..b509843daa654ade9fe9064f36d49b649d625d42 100644 (file)
@@ -77,9 +77,13 @@ void CodeGenFunction::FinishFunction(SourceLocation EndLoc) {
   assert(BreakContinueStack.empty() &&
          "mismatched push/pop in break/continue stack!");
 
-  // Emit function epilog (to return). This has the nice side effect
-  // of also automatically handling code that falls off the end.
-  EmitBlock(ReturnBlock);
+  // Emit function epilog (to return). For cleanliness, skip emission
+  // if we know it is safe (when it is unused and the current block is
+  // unterminated).
+  if (!ReturnBlock->use_empty() ||
+      !Builder.GetInsertBlock() ||
+      Builder.GetInsertBlock()->getTerminator())
+    EmitBlock(ReturnBlock);
 
   // Emit debug descriptor for function end.
   if (CGDebugInfo *DI = CGM.getDebugInfo()) {