[llvm-commits] [dragonegg] r128772 - in /dragonegg/trunk: Backend.cpp Constants.cpp Convert.cpp DefaultABI.cpp Internals.h Types.cpp x86/Target.cpp

Duncan Sands baldrick at free.fr
Sat Apr 2 10:08:23 PDT 2011


Author: baldrick
Date: Sat Apr  2 12:08:23 2011
New Revision: 128772

URL: http://llvm.org/viewvc/llvm-project?rev=128772&view=rev
Log:
See if the alignment assertion in ConvertInitializer now survives
the buildbots.  While there, factor fatal error handling code.

Modified:
    dragonegg/trunk/Backend.cpp
    dragonegg/trunk/Constants.cpp
    dragonegg/trunk/Convert.cpp
    dragonegg/trunk/DefaultABI.cpp
    dragonegg/trunk/Internals.h
    dragonegg/trunk/Types.cpp
    dragonegg/trunk/x86/Target.cpp

Modified: dragonegg/trunk/Backend.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/Backend.cpp?rev=128772&r1=128771&r2=128772&view=diff
==============================================================================
--- dragonegg/trunk/Backend.cpp (original)
+++ dragonegg/trunk/Backend.cpp Sat Apr  2 12:08:23 2011
@@ -38,8 +38,6 @@
 #include "llvm/Assembly/PrintModulePass.h"
 #include "llvm/Bitcode/ReaderWriter.h"
 #include "llvm/CodeGen/RegAllocRegistry.h"
-#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/FormattedStream.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/StandardPasses.h"
 #include "llvm/Target/SubtargetFeature.h"
@@ -738,10 +736,8 @@
     InitializeOutputStreams(false);
     if (TheTarget->addPassesToEmitFile(*PM, FormattedOutStream,
                                        TargetMachine::CGFT_AssemblyFile,
-                                       OptLevel, DisableVerify)) {
-      errs() << "Error interfacing to target machine!\n";
-      exit(1);
-    }
+                                       OptLevel, DisableVerify))
+      DieAbjectly("Error interfacing to target machine!");
   }
 
   if (HasPerFunctionPasses) {
@@ -841,10 +837,8 @@
       InitializeOutputStreams(false);
       if (TheTarget->addPassesToEmitFile(*PM, FormattedOutStream,
                                          TargetMachine::CGFT_AssemblyFile,
-                                         OptLevel, DisableVerify)) {
-        errs() << "Error interfacing to target machine!\n";
-        exit(1);
-      }
+                                         OptLevel, DisableVerify))
+        DieAbjectly("Error interfacing to target machine!");
     }
   }
 
@@ -1210,15 +1204,13 @@
     return V;
 
 #ifdef ENABLE_CHECKING
-  // Check that we are not being given an automatic variable.
+  // Check that we are not being given an automatic variable or a type or label.
   // A weak alias has TREE_PUBLIC set but not the other bits.
-  if (TREE_CODE(decl) == PARM_DECL || TREE_CODE(decl) == RESULT_DECL
-      || (TREE_CODE(decl) == VAR_DECL && !TREE_STATIC(decl) &&
-          !TREE_PUBLIC(decl) && !DECL_EXTERNAL(decl) && !DECL_REGISTER(decl)))
-    abort();
-  // And that we were not given a type or a label.  */
-  else if (TREE_CODE(decl) == TYPE_DECL || TREE_CODE(decl) == LABEL_DECL)
-    abort ();
+  if (TREE_CODE(decl) == PARM_DECL || TREE_CODE(decl) == RESULT_DECL ||
+      TREE_CODE(decl) == TYPE_DECL || TREE_CODE(decl) == LABEL_DECL ||
+      (TREE_CODE(decl) == VAR_DECL && !TREE_STATIC(decl) &&
+       !TREE_PUBLIC(decl) && !DECL_EXTERNAL(decl) && !DECL_REGISTER(decl)))
+    DieAbjectly("Cannot make a global for this kind of declaration!", decl);
 #endif
 
   if (errorcount || sorrycount)

Modified: dragonegg/trunk/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/Constants.cpp?rev=128772&r1=128771&r2=128772&view=diff
==============================================================================
--- dragonegg/trunk/Constants.cpp (original)
+++ dragonegg/trunk/Constants.cpp Sat Apr  2 12:08:23 2011
@@ -30,7 +30,6 @@
 // LLVM headers
 #include "llvm/GlobalVariable.h"
 #include "llvm/LLVMContext.h"
-#include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/Host.h"
 #include "llvm/Target/TargetData.h"
 
@@ -288,7 +287,7 @@
 
   switch (Ty->getTypeID()) {
   default:
-    llvm_unreachable("Unsupported type!");
+    DieAbjectly("Unsupported type!");
   case Type::PointerTyID: {
     // Cast to an integer with the same number of bits and return that.
     const IntegerType *IntTy = getTargetData().getIntPtrType(Context);
@@ -400,7 +399,7 @@
 
   switch (Ty->getTypeID()) {
   default:
-    llvm_unreachable("Unsupported type!");
+    DieAbjectly("Unsupported type!");
   case Type::IntegerTyID: {
     unsigned BitWidth = Ty->getPrimitiveSizeInBits();
     unsigned StoreSize = getTargetData().getTypeStoreSizeInBits(Ty);
@@ -1090,9 +1089,7 @@
   Constant *Init;
   switch (TREE_CODE(exp)) {
   default:
-    debug_tree(exp);
-    assert(0 && "Unknown constant to convert!");
-    abort();
+    DieAbjectly("Unknown constant to convert!", exp);
   case COMPLEX_CST:
   case INTEGER_CST:
   case REAL_CST:
@@ -1135,18 +1132,14 @@
   if (Ty->isSized()) {
     uint64_t InitSize = getTargetData().getTypeAllocSizeInBits(Init->getType());
     uint64_t TypeSize = getTargetData().getTypeAllocSizeInBits(Ty);
-    if (InitSize < TypeSize) {
-      debug_tree(exp);
-      llvm_unreachable("Constant too small for type!");
-    }
-    if (isInt64(TREE_TYPE(exp), true) && InitSize != TypeSize) {
-      debug_tree(exp);
-      llvm_unreachable("Constant too big for type!");
-    }
-  }
-// FIXME: This check fails when building libdecnumber (self-host build).
-//  assert(getTargetData().getABITypeAlignment(Init->getType()) * 8 <=
-//         TYPE_ALIGN(TREE_TYPE(exp)) && "Constant over aligned!");
+    if (InitSize < TypeSize)
+      DieAbjectly("Constant too small for type!", exp);
+    if (isInt64(TREE_TYPE(exp), true) && InitSize != TypeSize)
+      DieAbjectly("Constant too big for type!", exp);
+  }
+  if (getTargetData().getABITypeAlignment(Init->getType()) * 8 >
+      TYPE_ALIGN(TREE_TYPE(exp)))
+    DieAbjectly("Constant over aligned!", exp);
 #endif
 
   return Init;
@@ -1306,9 +1299,7 @@
 
   switch (TREE_CODE(exp)) {
   default:
-    debug_tree(exp);
-    assert(false && "Unknown constant to take the address of!");
-    abort();
+    DieAbjectly("Unknown constant to take the address of!", exp);
   case COMPLEX_CST:
   case FIXED_CST:
   case INTEGER_CST:

Modified: dragonegg/trunk/Convert.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/Convert.cpp?rev=128772&r1=128771&r2=128772&view=diff
==============================================================================
--- dragonegg/trunk/Convert.cpp (original)
+++ dragonegg/trunk/Convert.cpp Sat Apr  2 12:08:23 2011
@@ -31,7 +31,6 @@
 #include "llvm/Module.h"
 #include "llvm/Support/CFG.h"
 #include "llvm/Support/Debug.h"
-#include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/Host.h"
 #include "llvm/Target/TargetLowering.h"
 #include "llvm/ADT/Statistic.h"
@@ -70,11 +69,6 @@
 STATISTIC(NumBasicBlocks, "Number of basic blocks converted");
 STATISTIC(NumStatements,  "Number of gimple statements converted");
 
-/// dump - Print a gimple statement to standard error.
-void dump(gimple stmt) {
-  print_gimple_stmt(stderr, stmt, 0, TDF_RAW);
-}
-
 /// getINTEGER_CSTVal - Return the specified INTEGER_CST value as a uint64_t.
 ///
 uint64_t getINTEGER_CSTVal(tree exp) {
@@ -267,7 +261,7 @@
 
   switch (TREE_CODE(decl)) {
   default:
-    llvm_unreachable("Unhandled local declaration!");
+    DieAbjectly("Unhandled local declaration!", decl);
 
   case RESULT_DECL:
   case VAR_DECL:
@@ -1018,8 +1012,7 @@
         NameDef->replaceAllUsesWith(UndefValue::get(NameDef->getType()));
         delete NameDef;
       } else {
-        debug_tree(I->first);
-        llvm_unreachable("SSA name never defined!");
+        DieAbjectly("SSA name never defined!", I->first);
       }
     }
 
@@ -1133,6 +1126,9 @@
     }
 
     switch (gimple_code(stmt)) {
+    default:
+      DieAbjectly("Unhandled GIMPLE statement during LLVM emission!", stmt);
+
     case GIMPLE_ASM:
       RenderGIMPLE_ASM(stmt);
       break;
@@ -1177,10 +1173,6 @@
     case GIMPLE_SWITCH:
       RenderGIMPLE_SWITCH(stmt);
       break;
-
-    default:
-      dump(stmt);
-      llvm_unreachable("Unhandled GIMPLE statement during LLVM emission!");
     }
   }
 
@@ -1246,8 +1238,7 @@
 
   switch (TREE_CODE(exp)) {
   default:
-    debug_tree(exp);
-    llvm_unreachable("Unhandled lvalue expression!");
+    DieAbjectly("Unhandled lvalue expression!", exp);
 
   case PARM_DECL:
   case VAR_DECL:
@@ -1321,11 +1312,6 @@
 //                         ... Utility Functions ...
 //===----------------------------------------------------------------------===//
 
-void TreeToLLVM::TODO(tree exp) {
-  if (exp) debug_tree(exp);
-  llvm_unreachable("Unhandled tree node");
-}
-
 /// CastToAnyType - Cast the specified value to the specified type making no
 /// assumptions about the types of the arguments. This creates an inferred cast.
 Value *TreeToLLVM::CastToAnyType(Value *V, bool VisSigned,
@@ -1781,11 +1767,8 @@
   if (DECL_SIZE(decl) == 0) {    // Variable with incomplete type.
     if (DECL_INITIAL(decl) == 0)
       return; // Error message was already done; now avoid a crash.
-    else {
-      // "An initializer is going to decide the size of this array."??
-      TODO(decl);
-      abort();
-    }
+    else
+      DieAbjectly("Initializer will decide the size of this array?", decl);
   } else if (TREE_CODE(DECL_SIZE_UNIT(decl)) == INTEGER_CST) {
     // Variable of fixed size that goes on the stack.
     Ty = ConvertType(type);
@@ -2451,11 +2434,8 @@
   case ARRAY_TYPE:
   case RECORD_TYPE:
   default:
-    if (elt && VEC_length(constructor_elt, elt)) {
-      // We don't handle elements yet.
-
-      TODO(exp);
-    }
+    if (elt && VEC_length(constructor_elt, elt))
+      DieAbjectly("We don't handle elements yet!", exp);
     return 0;
   case QUAL_UNION_TYPE:
   case UNION_TYPE:
@@ -4560,7 +4540,7 @@
     switch(DECL_FUNCTION_CODE(fndecl)) {
       case BUILT_IN_LOCK_RELEASE_16:    // not handled; should use SSE on x86
       default:
-        abort();
+        DieAbjectly("Not handled; should use SSE on x86!");
       case BUILT_IN_LOCK_RELEASE_1:
         Ty = Type::getInt8Ty(Context); break;
       case BUILT_IN_LOCK_RELEASE_2:
@@ -5717,7 +5697,7 @@
       LValue LV(ConstantPointerNull::get(PTy), 1);
       return LV;
     }
-    llvm_unreachable("Referencing decl that hasn't been laid out");
+    DieAbjectly("Referencing decl that hasn't been laid out!", exp);
   }
 
   const Type *Ty = ConvertType(TREE_TYPE(exp));
@@ -5891,17 +5871,14 @@
 /// an LLVM constant.  Creates no code, only constants.
 Constant *TreeToLLVM::EmitRegisterConstant(tree reg) {
 #ifndef NDEBUG
-  if (!is_gimple_constant(reg)) {
-    debug_tree(reg);
-    llvm_unreachable("Not a gimple constant!");
-  }
+  if (!is_gimple_constant(reg))
+    DieAbjectly("Not a gimple constant!", reg);
 #endif
   assert(is_gimple_reg_type(TREE_TYPE(reg)) && "Not of register type!");
 
   switch (TREE_CODE(reg)) {
   default:
-    debug_tree(reg);
-    llvm_unreachable("Unhandled GIMPLE constant!");
+    DieAbjectly("Unhandled GIMPLE constant!", reg);
 
   case INTEGER_CST:
     return EmitIntegerRegisterConstant(reg);
@@ -7491,7 +7468,7 @@
 
   switch (region->type) {
   default:
-    llvm_unreachable("Unexpected region type!");
+    DieAbjectly("Unexpected region type!");
   case ERT_ALLOWED_EXCEPTIONS: {
     // Filter.
     BasicBlock *Dest = getLabelDeclBlock(region->u.allowed.label);
@@ -7751,8 +7728,7 @@
   Value *RHS = 0;
   switch (code) {
   default:
-    dump(stmt);
-    llvm_unreachable("Unhandled GIMPLE assignment!");
+    DieAbjectly("Unhandled GIMPLE assignment!", stmt);
 
   // Unary expressions.
   case ABS_EXPR:

Modified: dragonegg/trunk/DefaultABI.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/DefaultABI.cpp?rev=128772&r1=128771&r2=128772&view=diff
==============================================================================
--- dragonegg/trunk/DefaultABI.cpp (original)
+++ dragonegg/trunk/DefaultABI.cpp Sat Apr  2 12:08:23 2011
@@ -160,10 +160,8 @@
       else if (const Type* ScalarTy =
                LLVM_SCALAR_TYPE_FOR_STRUCT_RETURN(type, &Offset))
         C.HandleAggregateResultAsScalar(ScalarTy, Offset);
-      else {
-        assert(0 && "Unable to determine how to return this aggregate!");
-        abort();
-      }
+      else
+        DieAbjectly("Unable to determine how to return this aggregate!");
     }
   } else {
     // If the function is returning a struct or union, we pass the pointer to
@@ -291,8 +289,7 @@
       C.ExitField();
     }
   } else {
-    assert(0 && "unknown aggregate type!");
-    abort();
+    DieAbjectly("Unknown aggregate type!");
   }
 }
 

Modified: dragonegg/trunk/Internals.h
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/Internals.h?rev=128772&r1=128771&r2=128772&view=diff
==============================================================================
--- dragonegg/trunk/Internals.h (original)
+++ dragonegg/trunk/Internals.h Sat Apr  2 12:08:23 2011
@@ -28,6 +28,8 @@
 #include "llvm/Intrinsics.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SetVector.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/FormattedStream.h"
 #include "llvm/Support/IRBuilder.h"
 #include "llvm/Support/TargetFolder.h"
 
@@ -35,6 +37,11 @@
 union gimple_statement_d;
 union tree_node;
 
+extern "C" {
+extern void debug_gimple_stmt(union gimple_statement_d *);
+extern void debug_tree(union tree_node *);
+}
+
 namespace llvm {
   class Module;
   class GlobalVariable;
@@ -103,6 +110,20 @@
 
 extern Constant* ConvertMetadataStringToGV(const char *str);
 
+inline void DieAbjectly(const char *Message) {
+  llvm_unreachable(Message);
+}
+
+inline void DieAbjectly(const char *Message, union gimple_statement_d *stmt) {
+  if (stmt) debug_gimple_stmt(stmt);
+  DieAbjectly(Message);
+}
+
+inline void DieAbjectly(const char *Message, union tree_node *exp) {
+  if (exp) debug_tree(exp);
+  DieAbjectly(Message);
+}
+
 /// AddAnnotateAttrsToGlobal - Adds decls that have a
 /// annotate attribute to a vector to be emitted later.
 extern void AddAnnotateAttrsToGlobal(GlobalValue *GV, tree_node *decl);
@@ -460,8 +481,6 @@
   /// the address of the result.
   LValue EmitLV(tree_node *exp);
 
-  void TODO(tree_node *exp = 0);
-
   /// CastToAnyType - Cast the specified value to the specified type regardless
   /// of the types involved. This is an inferred cast.
   Value *CastToAnyType (Value *V, bool VSigned, const Type *Ty, bool TySigned);

Modified: dragonegg/trunk/Types.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/Types.cpp?rev=128772&r1=128771&r2=128772&view=diff
==============================================================================
--- dragonegg/trunk/Types.cpp (original)
+++ dragonegg/trunk/Types.cpp Sat Apr  2 12:08:23 2011
@@ -78,7 +78,7 @@
       errs() << "LLVM: ";
       Ty->print(errs());
       errs() << " (" << LLVMSize << " bits)\n";
-      llvm_unreachable("LLVM type size doesn't match GCC type size!");
+      DieAbjectly("LLVM type size doesn't match GCC type size!");
     }
   }
 #endif
@@ -561,9 +561,7 @@
 
   switch (TREE_CODE(type)) {
   default:
-    fprintf(stderr, "Unknown type to compare:\n");
-    debug_tree(type);
-    abort();
+    DieAbjectly("Unknown type to compare!", type);
   case VOID_TYPE:
   case BOOLEAN_TYPE:
   case ENUMERAL_TYPE:
@@ -672,8 +670,7 @@
 
   switch (TREE_CODE(type)) {
   default:
-    debug_tree(type);
-    llvm_unreachable("Unknown type to convert!");
+    DieAbjectly("Unknown type to convert!", type);
 
   case VOID_TYPE:
     Ty = SET_TYPE_LLVM(type, Type::getVoidTy(Context));
@@ -709,8 +706,7 @@
     if ((Ty = GET_TYPE_LLVM(type))) return Ty;
     switch (TYPE_PRECISION(type)) {
     default:
-      debug_tree(type);
-      llvm_unreachable("Unknown FP type!");
+      DieAbjectly("Unknown FP type!", type);
     case 32: Ty = SET_TYPE_LLVM(type, Type::getFloatTy(Context)); break;
     case 64: Ty = SET_TYPE_LLVM(type, Type::getDoubleTy(Context)); break;
     case 80: Ty = SET_TYPE_LLVM(type, Type::getX86_FP80Ty(Context)); break;

Modified: dragonegg/trunk/x86/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/x86/Target.cpp?rev=128772&r1=128771&r2=128772&view=diff
==============================================================================
--- dragonegg/trunk/x86/Target.cpp (original)
+++ dragonegg/trunk/x86/Target.cpp Sat Apr  2 12:08:23 2011
@@ -27,7 +27,6 @@
 
 // LLVM headers
 #include "llvm/Module.h"
-#include "llvm/Support/ErrorHandling.h"
 
 // System headers
 #include <gmp.h>
@@ -755,7 +754,8 @@
     }
   }
   }
-  llvm_unreachable("Builtin not implemented!");
+  DieAbjectly("Builtin not implemented!", stmt);
+  return false;
 }
 
 /* These are defined in i386.c */





More information about the llvm-commits mailing list