@@ -199,15 +199,23 @@ AllocStackInst::AllocStackInst(SILDebugLocation Loc, SILType elementType,
199
199
Var ? Var->Type.hasValue() : false,
200
200
Var ? Var->Loc.hasValue() : false,
201
201
Var ? Var->Scope != nullptr : false),
202
- VarInfo(Var, getTrailingObjects<char >(),
203
- getTrailingObjects<SILType>(),
204
- getTrailingObjects<SILLocation>(),
205
- getTrailingObjects<const SILDebugScope *>(),
206
- getTrailingObjects<SILDIExprElement>()) {
202
+ // Initialize VarInfo with a temporary raw value of 0. The real
203
+ // initialization can only be done after `numOperands` is set (see below).
204
+ VarInfo(0 ) {
207
205
sharedUInt8 ().AllocStackInst .dynamicLifetime = hasDynamicLifetime;
208
206
sharedUInt8 ().AllocStackInst .lexical = isLexical;
209
207
sharedUInt8 ().AllocStackInst .wasMoved = wasMoved;
210
208
sharedUInt32 ().AllocStackInst .numOperands = TypeDependentOperands.size ();
209
+
210
+ // VarInfo must be initialized after `sharedUInt32().AllocStackInst.numOperands`!
211
+ // Otherwise the trailing object addresses are wrong.
212
+ VarInfo = TailAllocatedDebugVariable (Var,
213
+ getTrailingObjects<char >(),
214
+ getTrailingObjects<SILType>(),
215
+ getTrailingObjects<SILLocation>(),
216
+ getTrailingObjects<const SILDebugScope *>(),
217
+ getTrailingObjects<SILDIExprElement>());
218
+
211
219
assert (sharedUInt32 ().AllocStackInst .numOperands ==
212
220
TypeDependentOperands.size () && " Truncation" );
213
221
auto *VD = Loc.getLocation ().getAsASTNode <VarDecl>();
0 commit comments