Skip to content
This repository has been archived by the owner on Apr 23, 2020. It is now read-only.

Commit

Permalink
Fix PR2060 by rejecting invalid types for integer constants.
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47311 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
lattner committed Feb 19, 2008
1 parent fa113f8 commit 689e8b2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
26 changes: 15 additions & 11 deletions lib/AsmParser/llvmAsmParser.y
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,8 @@ static Value *getExistingVal(const Type *Ty, const ValID &D) {
// 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() + "'");
Expand All @@ -387,20 +388,23 @@ static Value *getExistingVal(const Type *Ty, const ValID &D) {
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;
}
Expand Down
6 changes: 6 additions & 0 deletions test/Assembler/2008-02-18-IntPointerCrash.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
; RUN: not llvm-as %s |& grep {is invalid or}
; PR2060

define i8* @foo() {
ret i8* 0
}

0 comments on commit 689e8b2

Please sign in to comment.