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

Haopeng Liu via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 12 22:59:44 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());
----------------
haopliu wrote:

`struct S {
  long a;
  long b;
  char c;
}; S var;` The `var` size is 24 bytes. `emitStoresForConstant` splits the constant store and emits several stores instead. Assume we set the max-size flag to 16. If filter the size in `emitStoresForConstant`, this var will be auto-initialized (each split store is less than 16) even though its size > 16. Would it be confusing? 

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


More information about the cfe-commits mailing list