[PATCH] D60613: Make setInitializer() assert that the entire initializer is usable.
Arnt Gulbrandsen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 12 07:20:36 PDT 2019
arnt updated this revision to Diff 194876.
arnt added a comment.
updated following comments from lebedev.ri; thanks
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D60613/new/
https://reviews.llvm.org/D60613
Files:
llvm/lib/IR/Globals.cpp
Index: llvm/lib/IR/Globals.cpp
===================================================================
--- llvm/lib/IR/Globals.cpp
+++ llvm/lib/IR/Globals.cpp
@@ -359,6 +359,21 @@
getParent()->getGlobalList().erase(getIterator());
}
+static void assertThatAllGlobalsAreIn(Constant *Value, Module *Correct) {
+#ifndef NDEBUG
+ if(ConstantStruct *V = dyn_cast<ConstantStruct>(Value)) {
+ for(int I = 0, N = V->getNumOperands(); I != N; ++I)
+ assertThatAllGlobalsAreIn(V->getOperand(I), Correct);
+ } else if(ConstantArray *V = dyn_cast<ConstantArray>(Value)) {
+ for(int I = 0, N = V->getNumOperands(); I != N; ++I)
+ assertThatAllGlobalsAreIn(V->getAggregateElement(I), Correct);
+ } else if(GlobalValue *V = dyn_cast<GlobalValue>(Value)) {
+ assert((!V->getParent() || V->getParent() == Correct) &&
+ "A Constant and its initializer cannot be in different modules");
+ }
+#endif
+}
+
void GlobalVariable::setInitializer(Constant *InitVal) {
if (!InitVal) {
if (hasInitializer()) {
@@ -377,6 +392,7 @@
if (!hasInitializer())
setGlobalVariableNumOperands(1);
Op<0>().set(InitVal);
+ assertThatAllGlobalsAreIn(InitVal, getParent());
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60613.194876.patch
Type: text/x-patch
Size: 1205 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190412/c7b3266e/attachment-0001.bin>
More information about the llvm-commits
mailing list