================
@@ -1972,7 +1972,20 @@ void CodeGenFunction::EmitAutoVarInit(const 
AutoVarEmission &emission) {
   }
 
   if (!constant) {
-    initializeWhatIsTechnicallyUninitialized(Loc);
+    if (trivialAutoVarInit !=
+        LangOptions::TrivialAutoVarInitKind::Uninitialized) {
+      // At this point, we know D has an Init expression, but isn't a constant.
+      // - If D is not a scalar, auto-var-init conservatively (members may be
+      // left uninitialized by constructor Init expressions for example).
+      // - If D is a scalar, we only need to auto-var-init if there is a
+      // self-reference. Otherwise, the Init expression should be sufficient.
+      // It may be that the Init expression uses other uninitialized memory,
+      // but auto-var-init here would not help, as auto-init would get
+      // overwritten by Init.
+      if (!D.getType()->isScalarType() || isAccessedBy(D, Init)) {
----------------
ilya-biryukov wrote:
Ah, so `isAccessedBy` also detects all captured block variables. I have missed 
that when skimming through the code for the first time. Thanks for pointing 
that out.

If I'm not mistaken, `capturedByInit || ` does not actually change the 
semantics of the code, so not sure it adds any safety. But it does make sense 
as an optimization and that's also present in the other code for 
`isAccessedBy`, so including it seems like an overall win (performance, 
consistency).

https://github.com/llvm/llvm-project/pull/94642
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to