mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-02-23 22:15:25 +00:00
In GlobalVariable::setInitializer, assert that the initializer has the
right type. llvm-svn: 89014
This commit is contained in:
parent
382a91041b
commit
135f2adcbb
@ -99,18 +99,10 @@ public:
|
|||||||
assert(hasInitializer() && "GV doesn't have initializer!");
|
assert(hasInitializer() && "GV doesn't have initializer!");
|
||||||
return static_cast<Constant*>(Op<0>().get());
|
return static_cast<Constant*>(Op<0>().get());
|
||||||
}
|
}
|
||||||
inline void setInitializer(Constant *CPV) {
|
/// setInitializer - Sets the initializer for this global variable, removing
|
||||||
if (CPV == 0) {
|
/// any existing initializer if InitVal==NULL. If this GV has type T*, the
|
||||||
if (hasInitializer()) {
|
/// initializer must have type T.
|
||||||
Op<0>().set(0);
|
void setInitializer(Constant *InitVal);
|
||||||
NumOperands = 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!hasInitializer())
|
|
||||||
NumOperands = 1;
|
|
||||||
Op<0>().set(CPV);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// If the value is a global constant, its value is immutable throughout the
|
/// If the value is a global constant, its value is immutable throughout the
|
||||||
/// runtime execution of the program. Assigning a value into the constant
|
/// runtime execution of the program. Assigning a value into the constant
|
||||||
|
@ -171,6 +171,21 @@ void GlobalVariable::replaceUsesOfWithOnConstant(Value *From, Value *To,
|
|||||||
this->setOperand(0, cast<Constant>(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
|
/// copyAttributesFrom - copy all additional attributes (those not needed to
|
||||||
/// create a GlobalVariable) from the GlobalVariable Src to this one.
|
/// create a GlobalVariable) from the GlobalVariable Src to this one.
|
||||||
void GlobalVariable::copyAttributesFrom(const GlobalValue *Src) {
|
void GlobalVariable::copyAttributesFrom(const GlobalValue *Src) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user