================
@@ -1644,6 +1644,39 @@ CodeGenFunction::EmitAutoVarAlloca(const VarDecl &D) {
}
}
+ // A variable whose declaration is bypassed by a goto or switch is not
+ // initialized by EmitAutoVarInit, which runs at the declaration. Emit the
+ // trivial-auto-var-init separately.
+ if (Bypasses.IsBypassed(&D) && !emission.IsEscapingByRef &&
+ !Ty->isVariablyModifiedType() &&
+ getAutoVarInitKind(Ty, D) !=
+ LangOptions::TrivialAutoVarInitKind::Uninitialized) {
+ if (!Bypasses.isAlwaysBypassed()) {
+ // The variable's lifetime restarts on each re-entry into its scope, so
+ // reinitialize at every bypassing jump. Backward gotos are emitted at
+ // the jump source, which comes after this alloca; forward gotos and
the
+ // switch dispatch have already been emitted, so patch their init in
+ // before the jump.
+ BypassedVarInits.insert({&D, address});
+ for (const BypassingForwardJump &FG : BypassingForwardJumps) {
+ const auto *Vars = Bypasses.getBypassedVarsForSource(FG.Source);
+ if (Vars && Vars->contains(&D))
+ if (llvm::Instruction *Term = FG.Block->getTerminator()) {
+ llvm::IRBuilderBase::InsertPointGuard IPG(Builder);
+ Builder.SetInsertPoint(Term);
+ emitZeroOrPatternForAutoVarInit(Ty, D, address);
+ }
+ }
----------------
nickdesaulniers wrote:
An early-`continue` would help you reduce indentation here.
```suggestion
if (!Vars || !Vars->contains(&D))
continue;
if (llvm::Instruction *Term = FG.Block->getTerminator()) {
llvm::IRBuilderBase::InsertPointGuard IPG(Builder);
Builder.SetInsertPoint(Term);
emitZeroOrPatternForAutoVarInit(Ty, D, address);
}
}
```
https://github.com/llvm/llvm-project/pull/181937
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits