summaryrefslogtreecommitdiffstats
path: root/llvm/lib/AsmParser
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2007-01-17 02:47:33 +0000
committerReid Spencer <rspencer@reidspencer.com>2007-01-17 02:47:33 +0000
commit082a77f1c932d9dbb7237f1b9dea9fd2989e1081 (patch)
tree40f96b734a1151e51f5c04404055c1cb57bc767e /llvm/lib/AsmParser
parent00e5e0ea8f9b5dff15567605d16bcd1ca8d9866d (diff)
downloadbcm5719-llvm-082a77f1c932d9dbb7237f1b9dea9fd2989e1081.tar.gz
bcm5719-llvm-082a77f1c932d9dbb7237f1b9dea9fd2989e1081.zip
For PR1117:
Make the assembler generate a nice error message if a bad cast instruction is attempted instead of asserting out. This is made possible by the recently exposed method CastInst::castIsValid() which checks the validity of any cast instruction. llvm-svn: 33283
Diffstat (limited to 'llvm/lib/AsmParser')
-rw-r--r--llvm/lib/AsmParser/llvmAsmParser.y27
1 files changed, 12 insertions, 15 deletions
diff --git a/llvm/lib/AsmParser/llvmAsmParser.y b/llvm/lib/AsmParser/llvmAsmParser.y
index 59aaf25df31..af1a4ab3825 100644
--- a/llvm/lib/AsmParser/llvmAsmParser.y
+++ b/llvm/lib/AsmParser/llvmAsmParser.y
@@ -1708,14 +1708,12 @@ ConstExpr: CastOps '(' ConstVal TO Types ')' {
if (!UpRefs.empty())
GEN_ERROR("Invalid upreference in type: " + (*$5)->getDescription());
Constant *Val = $3;
- const Type *Ty = $5->get();
- if (!Val->getType()->isFirstClassType())
- GEN_ERROR("cast constant expression from a non-primitive type: '" +
- Val->getType()->getDescription() + "'!");
- if (!Ty->isFirstClassType())
- GEN_ERROR("cast constant expression to a non-primitive type: '" +
- Ty->getDescription() + "'!");
- $$ = ConstantExpr::getCast($1, $3, $5->get());
+ const Type *DestTy = $5->get();
+ if (!CastInst::castIsValid($1, $3, DestTy))
+ GEN_ERROR("invalid cast opcode for cast from '" +
+ Val->getType()->getDescription() + "' to '" +
+ DestTy->getDescription() + "'!");
+ $$ = ConstantExpr::getCast($1, $3, DestTy);
delete $5;
}
| GETELEMENTPTR '(' ConstVal IndexList ')' {
@@ -2647,13 +2645,12 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
if (!UpRefs.empty())
GEN_ERROR("Invalid upreference in type: " + (*$4)->getDescription());
Value* Val = $2;
- const Type* Ty = $4->get();
- if (!Val->getType()->isFirstClassType())
- GEN_ERROR("cast from a non-primitive type: '" +
- Val->getType()->getDescription() + "'!");
- if (!Ty->isFirstClassType())
- GEN_ERROR("cast to a non-primitive type: '" + Ty->getDescription() +"'!");
- $$ = CastInst::create($1, Val, $4->get());
+ const Type* DestTy = $4->get();
+ if (!CastInst::castIsValid($1, Val, DestTy))
+ GEN_ERROR("invalid cast opcode for cast from '" +
+ Val->getType()->getDescription() + "' to '" +
+ DestTy->getDescription() + "'!");
+ $$ = CastInst::create($1, Val, DestTy);
delete $4;
}
| SELECT ResolvedVal ',' ResolvedVal ',' ResolvedVal {
OpenPOWER on IntegriCloud