diff options
author | Chris Lattner <sabre@nondot.org> | 2008-02-19 04:36:07 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-02-19 04:36:07 +0000 |
commit | 95816b9dee7e8a16722f880239d5b09c653ca5a8 (patch) | |
tree | f52d45895d04a8604501fa0d62374be4c914175d /llvm/lib | |
parent | c0c3cd8e27eb7622078b20601eb8c3b2a104c27f (diff) | |
download | bcm5719-llvm-95816b9dee7e8a16722f880239d5b09c653ca5a8.tar.gz bcm5719-llvm-95816b9dee7e8a16722f880239d5b09c653ca5a8.zip |
Fix PR2060 by rejecting invalid types for integer constants.
llvm-svn: 47311
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/AsmParser/llvmAsmParser.y | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/llvm/lib/AsmParser/llvmAsmParser.y b/llvm/lib/AsmParser/llvmAsmParser.y index 9674bba4d53..ccfe44ab82f 100644 --- a/llvm/lib/AsmParser/llvmAsmParser.y +++ b/llvm/lib/AsmParser/llvmAsmParser.y @@ -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() + "'"); @@ -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; } |