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 | 7c57c41d5f8e700151c5eeb2b7e0e65f4d3149a1 (patch) | |
| tree | 781ea9f90b19ec33698c81adfcd8b4a0386e8dc1 /llvm/lib | |
| parent | c40943224d632c08d04ae22d8cc07696f7596b24 (diff) | |
| download | bcm5719-llvm-7c57c41d5f8e700151c5eeb2b7e0e65f4d3149a1.tar.gz bcm5719-llvm-7c57c41d5f8e700151c5eeb2b7e0e65f4d3149a1.zip | |
In GlobalVariable::setInitializer, assert that the initializer has the
right type.
llvm-svn: 89014
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/VMCore/Globals.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/llvm/lib/VMCore/Globals.cpp b/llvm/lib/VMCore/Globals.cpp index 2d7d1b960b6..94bf3dea9ab 100644 --- a/llvm/lib/VMCore/Globals.cpp +++ b/llvm/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) { |

