@@ -218,6 +218,12 @@ static bool valueDominatesPHI(Value *V, PHINode *P, const DominatorTree *DT) {
218
218
// Arguments and constants dominate all instructions.
219
219
return true ;
220
220
221
+ // If we are processing instructions (and/or basic blocks) that have not been
222
+ // fully added to a function, the parent nodes may still be null. Simply
223
+ // return the conservative answer in these cases.
224
+ if (!I->getParent () || !P->getParent () || !I->getFunction ())
225
+ return false ;
226
+
221
227
// If we have a DominatorTree then do a precise test.
222
228
if (DT)
223
229
return DT->dominates (I, P);
@@ -2632,7 +2638,7 @@ static bool isAllocDisjoint(const Value *V) {
2632
2638
// that might be resolve lazily to symbols in another dynamically-loaded
2633
2639
// library (and, thus, could be malloc'ed by the implementation).
2634
2640
if (const AllocaInst *AI = dyn_cast<AllocaInst>(V))
2635
- return AI->isStaticAlloca ();
2641
+ return AI->getParent () && AI-> getFunction () && AI-> isStaticAlloca ();
2636
2642
if (const GlobalValue *GV = dyn_cast<GlobalValue>(V))
2637
2643
return (GV->hasLocalLinkage () || GV->hasHiddenVisibility () ||
2638
2644
GV->hasProtectedVisibility () || GV->hasGlobalUnnamedAddr ()) &&
@@ -3663,7 +3669,7 @@ static Value *simplifyICmpWithDominatingAssume(CmpInst::Predicate Predicate,
3663
3669
Value *LHS, Value *RHS,
3664
3670
const SimplifyQuery &Q) {
3665
3671
// Gracefully handle instructions that have not been inserted yet.
3666
- if (!Q.AC || !Q.CxtI )
3672
+ if (!Q.AC || !Q.CxtI || !Q. CxtI -> getParent () )
3667
3673
return nullptr ;
3668
3674
3669
3675
for (Value *AssumeBaseOp : {LHS, RHS}) {
@@ -6469,6 +6475,9 @@ static Value *simplifyIntrinsic(CallBase *Call, Value *Callee,
6469
6475
if (!NumOperands) {
6470
6476
switch (IID) {
6471
6477
case Intrinsic::vscale: {
6478
+ // Call may not be inserted into the IR yet at point of calling simplify.
6479
+ if (!Call->getParent () || !Call->getParent ()->getParent ())
6480
+ return nullptr ;
6472
6481
auto Attr = Call->getFunction ()->getFnAttribute (Attribute::VScaleRange);
6473
6482
if (!Attr.isValid ())
6474
6483
return nullptr ;
@@ -6916,7 +6925,10 @@ static bool replaceAndRecursivelySimplifyImpl(
6916
6925
// Replace the instruction with its simplified value.
6917
6926
I->replaceAllUsesWith (SimpleV);
6918
6927
6919
- if (!I->isEHPad () && !I->isTerminator () && !I->mayHaveSideEffects ())
6928
+ // Gracefully handle edge cases where the instruction is not wired into any
6929
+ // parent block.
6930
+ if (I->getParent () && !I->isEHPad () && !I->isTerminator () &&
6931
+ !I->mayHaveSideEffects ())
6920
6932
I->eraseFromParent ();
6921
6933
} else {
6922
6934
Worklist.insert (I);
@@ -6945,7 +6957,10 @@ static bool replaceAndRecursivelySimplifyImpl(
6945
6957
// Replace the instruction with its simplified value.
6946
6958
I->replaceAllUsesWith (SimpleV);
6947
6959
6948
- if (!I->isEHPad () && !I->isTerminator () && !I->mayHaveSideEffects ())
6960
+ // Gracefully handle edge cases where the instruction is not wired into any
6961
+ // parent block.
6962
+ if (I->getParent () && !I->isEHPad () && !I->isTerminator () &&
6963
+ !I->mayHaveSideEffects ())
6949
6964
I->eraseFromParent ();
6950
6965
}
6951
6966
return Simplified;
0 commit comments