diff options
author | Jeffrey Yasskin <jyasskin@google.com> | 2009-11-17 00:43:13 +0000 |
---|---|---|
committer | Jeffrey Yasskin <jyasskin@google.com> | 2009-11-17 00:43:13 +0000 |
commit | e4e00b81b5a07e01722211f03b31a5941d4d731e (patch) | |
tree | 9002b058274c71da4b779c48a648151a23065be8 /lib/VMCore | |
parent | 1fb3d35636d3bf4700533a22ab2a13f2b98fc9d2 (diff) | |
download | external_llvm-e4e00b81b5a07e01722211f03b31a5941d4d731e.zip external_llvm-e4e00b81b5a07e01722211f03b31a5941d4d731e.tar.gz external_llvm-e4e00b81b5a07e01722211f03b31a5941d4d731e.tar.bz2 |
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')
-rw-r--r-- | lib/VMCore/Globals.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/VMCore/Globals.cpp b/lib/VMCore/Globals.cpp index 2d7d1b9..94bf3de 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) { |