[clang] [clang] Add size filter for stack auto init (PR #74777)

Vitaly Buka via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 12 23:28:14 PST 2023


================
@@ -1759,20 +1759,29 @@ void CodeGenFunction::emitZeroOrPatternForAutoVarInit(QualType type,
                                                       const VarDecl &D,
                                                       Address Loc) {
   auto trivialAutoVarInit = getContext().getLangOpts().getTrivialAutoVarInit();
+  auto trivialAutoVarInitSizeBound =
+      getContext().getLangOpts().TrivialAutoVarInitSizeBound;
   CharUnits Size = getContext().getTypeSizeInChars(type);
   bool isVolatile = type.isVolatileQualified();
   if (!Size.isZero()) {
+    auto allocSize = CGM.getDataLayout().getTypeAllocSize(Loc.getElementType());
----------------
vitalybuka wrote:

I'd expect that it's kind of `bail out` measure which should not be consider as a contract by a end-user. So confusing should not be a concern.

Also how 
```
struct S {
  long a;
  long b;
  char c;
} var;
```

is better  then:
```
long a;
long b;
char c;
```

My impression was that your concern is buffers of hundreds of bytes, then maybe better to target just them?
If it 's `24 vs 16` maybe it should not use auto init at all?

https://github.com/llvm/llvm-project/pull/74777


More information about the cfe-commits mailing list