================
@@ -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:
Could you check what happens with `-fblocks` that capture the variable if
they're part of its initializer?
There is some special-case handling for this (when `capturedByInit == true`), I
feel we might not be catching that case here.
See https://gcc.godbolt.org/z/cEexo5n77 for an example.
```cpp
void foo();
void test() {
__block int calls = ^() {
while (++calls < 100) {
foo();
}
return calls;
}();
}
```
https://github.com/llvm/llvm-project/pull/94642
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits