summaryrefslogtreecommitdiff
path: root/lib/VMCore/Globals.cpp
diff options
context:
space:
mode:
authorJeffrey Yasskin <jyasskin@google.com>2009-11-17 00:43:13 +0000
committerJeffrey Yasskin <jyasskin@google.com>2009-11-17 00:43:13 +0000
commitdc1472b6d9281893771a64eb95b4599dff9aadfd (patch)
tree9002b058274c71da4b779c48a648151a23065be8 /lib/VMCore/Globals.cpp
parent574186f8adce4064b206dad5e139211e06688308 (diff)
downloadllvm-dc1472b6d9281893771a64eb95b4599dff9aadfd.tar.gz
llvm-dc1472b6d9281893771a64eb95b4599dff9aadfd.tar.bz2
llvm-dc1472b6d9281893771a64eb95b4599dff9aadfd.tar.xz
In GlobalVariable::setInitializer, assert that the initializer has the
right type. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@89014 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Globals.cpp')
-rw-r--r--lib/VMCore/Globals.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/VMCore/Globals.cpp b/lib/VMCore/Globals.cpp
index 2d7d1b960b..94bf3dea9a 100644
--- a/lib/VMCore/Globals.cpp
+++ b/lib/VMCore/Globals.cpp
@@ -171,6 +171,21 @@ void GlobalVariable::replaceUsesOfWithOnConstant(Value *From, Value *To,
this->setOperand(0, cast<Constant>(To));
}
+void GlobalVariable::setInitializer(Constant *InitVal) {
+ if (InitVal == 0) {
+ if (hasInitializer()) {
+ Op<0>().set(0);
+ NumOperands = 0;
+ }
+ } else {
+ assert(InitVal->getType() == getType()->getElementType() &&
+ "Initializer type must match GlobalVariable type");
+ if (!hasInitializer())
+ NumOperands = 1;
+ Op<0>().set(InitVal);
+ }
+}
+
/// copyAttributesFrom - copy all additional attributes (those not needed to
/// create a GlobalVariable) from the GlobalVariable Src to this one.
void GlobalVariable::copyAttributesFrom(const GlobalValue *Src) {