Fix http://llvm.org/PR6028, an assertion failure when an UndefValue of
authorJay Foad <jay.foad@gmail.com>
Fri, 15 Jan 2010 08:32:58 +0000 (08:32 +0000)
committerJay Foad <jay.foad@gmail.com>
Fri, 15 Jan 2010 08:32:58 +0000 (08:32 +0000)
integer type is used.

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

lib/ExecutionEngine/ExecutionEngine.cpp

index c466400393e8add23fbda2bcbd2862eb6b24c801..89c4290f2346c23642a8a1192f9dbfe30d995e5e 100644 (file)
@@ -491,8 +491,22 @@ void *ExecutionEngine::getPointerToGlobal(const GlobalValue *GV) {
 /// @brief Get a GenericValue for a Constant*
 GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
   // If its undefined, return the garbage.
-  if (isa<UndefValue>(C)) 
-    return GenericValue();
+  if (isa<UndefValue>(C)) {
+    GenericValue Result;
+    switch (C->getType()->getTypeID()) {
+    case Type::IntegerTyID:
+    case Type::X86_FP80TyID:
+    case Type::FP128TyID:
+    case Type::PPC_FP128TyID:
+      // Although the value is undefined, we still have to construct an APInt
+      // with the correct bit width.
+      Result.IntVal = APInt(C->getType()->getPrimitiveSizeInBits(), 0);
+      break;
+    default:
+      break;
+    }
+    return Result;
+  }
 
   // If the value is a ConstantExpr
   if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {