[llvm-commits] [dragonegg] r126545 - /dragonegg/trunk/llvm-convert.cpp

Duncan Sands baldrick at free.fr
Sat Feb 26 05:39:45 PST 2011


Author: baldrick
Date: Sat Feb 26 07:39:44 2011
New Revision: 126545

URL: http://llvm.org/viewvc/llvm-project?rev=126545&view=rev
Log:
If an error occurred then be cool and don't require every SSA name to
have a proper definition.  This prevents the compiler from crashing if
we bailed out on an error condition without taking care to define some
SSA name.

Modified:
    dragonegg/trunk/llvm-convert.cpp

Modified: dragonegg/trunk/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/llvm-convert.cpp?rev=126545&r1=126544&r2=126545&view=diff
==============================================================================
--- dragonegg/trunk/llvm-convert.cpp (original)
+++ dragonegg/trunk/llvm-convert.cpp Sat Feb 26 07:39:44 2011
@@ -1008,15 +1008,33 @@
     TheDebugInfo->EmitFunctionEnd(true);
   }
 
-#ifndef NDEBUG
-  if (!errorcount && !sorrycount)
+#ifdef NDEBUG
+  // When processing broken code it can be awkward to ensure that every SSA name
+  // that was used has a definition.  So in this case we play it cool and create
+  // an artificial definition for such SSA names.  The choice of definition does
+  // not matter because the compiler is going to exit with an error anyway.
+  if (errorcount || sorrycount)
+#else
+  // When checks are enabled, complain if an SSA name was used but not defined.
+#endif
     for (DenseMap<tree,TrackingVH<Value> >::const_iterator I = SSANames.begin(),
-         E = SSANames.end(); I != E; ++I)
-      if (isSSAPlaceholder(I->second)) {
+         E = SSANames.end(); I != E; ++I) {
+      Value *NameDef = I->second;
+      // If this is not a placeholder then the SSA name was defined.
+      if (!isSSAPlaceholder(NameDef))
+        continue;
+
+      // If an error occurred then replace the placeholder with undef.  Thanks
+      // to this we can just bail out on errors, without having to worry about
+      // whether we defined every SSA name.
+      if (errorcount || sorrycount) {
+        NameDef->replaceAllUsesWith(UndefValue::get(NameDef->getType()));
+        delete NameDef;
+      } else {
         debug_tree(I->first);
         llvm_unreachable("SSA name never defined!");
       }
-#endif
+    }
 
   return Fn;
 }





More information about the llvm-commits mailing list