@@ -69,6 +69,8 @@ namespace {
69
69
70
70
private:
71
71
bool setupEntryBlockAndCallSites (Function &F);
72
+ void substituteLPadValues (LandingPadInst *LPI, Value *ExnVal,
73
+ Value *SelVal, IRBuilder<> &Builder);
72
74
Value *setupFunctionContext (Function &F, ArrayRef<LandingPadInst*> LPads);
73
75
void lowerIncomingArguments (Function &F);
74
76
void lowerAcrossUnwindEdges (Function &F, ArrayRef<InvokeInst*> Invokes);
@@ -138,6 +140,36 @@ static void MarkBlocksLiveIn(BasicBlock *BB,
138
140
MarkBlocksLiveIn (*PI, LiveBBs);
139
141
}
140
142
143
+ // / substituteLPadValues - Substitute the values returned by the landingpad
144
+ // / instruction with those returned by the personality function.
145
+ void SjLjEHPass::substituteLPadValues (LandingPadInst *LPI, Value *ExnVal,
146
+ Value *SelVal, IRBuilder<> &Builder) {
147
+ SmallVector<Value*, 8 > UseWorkList (LPI->use_begin (), LPI->use_end ());
148
+ while (!UseWorkList.empty ()) {
149
+ Value *Val = UseWorkList.pop_back_val ();
150
+ ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(Val);
151
+ if (!EVI) continue ;
152
+ if (EVI->getNumIndices () != 1 ) continue ;
153
+ if (*EVI->idx_begin () == 0 )
154
+ EVI->replaceAllUsesWith (ExnVal);
155
+ else if (*EVI->idx_begin () == 1 )
156
+ EVI->replaceAllUsesWith (SelVal);
157
+ if (EVI->getNumUses () == 0 )
158
+ EVI->eraseFromParent ();
159
+ }
160
+
161
+ if (LPI->getNumUses () == 0 ) return ;
162
+
163
+ // There are still some uses of LPI. Construct an aggregate with the exception
164
+ // values and replace the LPI with that aggregate.
165
+ Type *LPadType = LPI->getType ();
166
+ Value *LPadVal = UndefValue::get (LPadType);
167
+ LPadVal = Builder.CreateInsertValue (LPadVal, ExnVal, 0 , " lpad.val" );
168
+ LPadVal = Builder.CreateInsertValue (LPadVal, SelVal, 1 , " lpad.val" );
169
+
170
+ LPI->replaceAllUsesWith (LPadVal);
171
+ }
172
+
141
173
// / setupFunctionContext - Allocate the function context on the stack and fill
142
174
// / it with all of the data that we know at this point.
143
175
Value *SjLjEHPass::
@@ -189,12 +221,7 @@ setupFunctionContext(Function &F, ArrayRef<LandingPadInst*> LPads) {
189
221
ExnVal = Builder.CreateIntToPtr (ExnVal, Type::getInt8PtrTy (F.getContext ()));
190
222
Value *SelVal = Builder.CreateLoad (SelectorAddr, true , " exn_selector_val" );
191
223
192
- Type *LPadType = LPI->getType ();
193
- Value *LPadVal = UndefValue::get (LPadType);
194
- LPadVal = Builder.CreateInsertValue (LPadVal, ExnVal, 0 , " lpad.val" );
195
- LPadVal = Builder.CreateInsertValue (LPadVal, SelVal, 1 , " lpad.val" );
196
-
197
- LPI->replaceAllUsesWith (LPadVal);
224
+ substituteLPadValues (LPI, ExnVal, SelVal, Builder);
198
225
}
199
226
200
227
// Personality function
0 commit comments