[llvm-commits] [llvm] r47311 - in /llvm/trunk: lib/AsmParser/llvmAsmParser.y test/Assembler/2008-02-18-IntPointerCrash.ll

Chris Lattner sabre at nondot.org
Mon Feb 18 20:36:08 PST 2008


Author: lattner
Date: Mon Feb 18 22:36:07 2008
New Revision: 47311

URL: http://llvm.org/viewvc/llvm-project?rev=47311&view=rev
Log:
Fix PR2060 by rejecting invalid types for integer constants.

Added:
    llvm/trunk/test/Assembler/2008-02-18-IntPointerCrash.ll
Modified:
    llvm/trunk/lib/AsmParser/llvmAsmParser.y

Modified: llvm/trunk/lib/AsmParser/llvmAsmParser.y
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/llvmAsmParser.y?rev=47311&r1=47310&r2=47311&view=diff

==============================================================================
--- llvm/trunk/lib/AsmParser/llvmAsmParser.y (original)
+++ llvm/trunk/lib/AsmParser/llvmAsmParser.y Mon Feb 18 22:36:07 2008
@@ -378,7 +378,8 @@
   // Check to make sure that "Ty" is an integral type, and that our
   // value will fit into the specified type...
   case ValID::ConstSIntVal:    // Is it a constant pool reference??
-    if (!ConstantInt::isValueValidForType(Ty, D.ConstPool64)) {
+    if (!isa<IntegerType>(Ty) ||
+        !ConstantInt::isValueValidForType(Ty, D.ConstPool64)) {
       GenerateError("Signed integral constant '" +
                      itostr(D.ConstPool64) + "' is invalid for type '" +
                      Ty->getDescription() + "'");
@@ -387,20 +388,23 @@
     return ConstantInt::get(Ty, D.ConstPool64, true);
 
   case ValID::ConstUIntVal:     // Is it an unsigned const pool reference?
-    if (!ConstantInt::isValueValidForType(Ty, D.UConstPool64)) {
-      if (!ConstantInt::isValueValidForType(Ty, D.ConstPool64)) {
-        GenerateError("Integral constant '" + utostr(D.UConstPool64) +
-                       "' is invalid or out of range");
-        return 0;
-      } else {     // This is really a signed reference.  Transmogrify.
-        return ConstantInt::get(Ty, D.ConstPool64, true);
-      }
-    } else {
+    if (isa<IntegerType>(Ty) &&
+        ConstantInt::isValueValidForType(Ty, D.UConstPool64))
       return ConstantInt::get(Ty, D.UConstPool64);
+
+    if (!isa<IntegerType>(Ty) ||
+        !ConstantInt::isValueValidForType(Ty, D.ConstPool64)) {
+      GenerateError("Integral constant '" + utostr(D.UConstPool64) +
+                    "' is invalid or out of range for type '" +
+                    Ty->getDescription() + "'");
+      return 0;
     }
+    // This is really a signed reference.  Transmogrify.
+    return ConstantInt::get(Ty, D.ConstPool64, true);
 
   case ValID::ConstFPVal:        // Is it a floating point const pool reference?
-    if (!ConstantFP::isValueValidForType(Ty, *D.ConstPoolFP)) {
+    if (!Ty->isFloatingPoint() ||
+        !ConstantFP::isValueValidForType(Ty, *D.ConstPoolFP)) {
       GenerateError("FP constant invalid for type");
       return 0;
     }

Added: llvm/trunk/test/Assembler/2008-02-18-IntPointerCrash.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/2008-02-18-IntPointerCrash.ll?rev=47311&view=auto

==============================================================================
--- llvm/trunk/test/Assembler/2008-02-18-IntPointerCrash.ll (added)
+++ llvm/trunk/test/Assembler/2008-02-18-IntPointerCrash.ll Mon Feb 18 22:36:07 2008
@@ -0,0 +1,6 @@
+; RUN: not llvm-as %s |& grep {is invalid or}
+; PR2060
+
+define i8* @foo() {
+       ret i8* 0
+}





More information about the llvm-commits mailing list