aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-07-18 00:14:27 +0000
committerChris Lattner <sabre@nondot.org>2002-07-18 00:14:27 +0000
commitcc4b6ec2b9ee8bcb2fa190ec70946ee172e986b8 (patch)
tree2c544890cf10e1b9d7a235fb028c87c76bde5c70
parent3535c9b38760fc3834101f931c3296b2a5a2d31f (diff)
ConstExpr::getelementptr now takes a vector of Constants not Values
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2948 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/AsmParser/llvmAsmParser.y12
-rw-r--r--lib/Bytecode/Reader/ConstantReader.cpp4
2 files changed, 13 insertions, 3 deletions
diff --git a/lib/AsmParser/llvmAsmParser.y b/lib/AsmParser/llvmAsmParser.y
index a26ea80c81..d865742c85 100644
--- a/lib/AsmParser/llvmAsmParser.y
+++ b/lib/AsmParser/llvmAsmParser.y
@@ -969,13 +969,23 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
};
+// FIXME: ConstExpr::get never return null!
ConstExpr: Types CAST ConstVal {
ConstantExpr* CPE = ConstantExpr::get($2, $3, $1->get());
if (CPE == 0) ThrowException("constant expression builder returned null!");
$$ = CPE;
}
| Types GETELEMENTPTR '(' ConstVal IndexList ')' {
- ConstantExpr* CPE = ConstantExpr::get($2, $4, *$5, $1->get());
+ vector<Constant*> IdxVec;
+ for (unsigned i = 0, e = $5->size(); i != e; ++i)
+ if (Constant *C = dyn_cast<Constant>((*$5)[i]))
+ IdxVec.push_back(C);
+ else
+ ThrowException("Arguments to getelementptr must be constants!");
+
+ delete $5;
+
+ ConstantExpr* CPE = ConstantExpr::get($2, $4, IdxVec, $1->get());
if (CPE == 0) ThrowException("constant expression builder returned null!");
$$ = CPE;
}
diff --git a/lib/Bytecode/Reader/ConstantReader.cpp b/lib/Bytecode/Reader/ConstantReader.cpp
index 68d6a62249..6bbeb8680b 100644
--- a/lib/Bytecode/Reader/ConstantReader.cpp
+++ b/lib/Bytecode/Reader/ConstantReader.cpp
@@ -204,7 +204,7 @@ bool BytecodeParser::parseConstantValue(const uchar *&Buf, const uchar *EndBuf,
// Get the arg value from its slot if it exists, otherwise a placeholder
Value *Val = getValue(argTy, argValSlot, false);
- Constant* C;
+ Constant *C;
if (Val) {
if (!(C = dyn_cast<Constant>(Val))) return failure(true);
BCR_TRACE(5, "Constant Found in ValueTable!\n");
@@ -218,7 +218,7 @@ bool BytecodeParser::parseConstantValue(const uchar *&Buf, const uchar *EndBuf,
if (isExprNumArgs == 1) { // All one-operand expressions
V = ConstantExpr::get(opCode, argVec[0], Ty);
} else if (opCode == Instruction::GetElementPtr) { // GetElementPtr
- std::vector<Value*> IdxList(argVec.begin()+1, argVec.end());
+ std::vector<Constant*> IdxList(argVec.begin()+1, argVec.end());
V = ConstantExpr::get(opCode, argVec[0], IdxList, Ty);
} else { // All other 2-operand expressions
V = ConstantExpr::get(opCode, argVec[0], argVec[1], Ty);