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

Vitaly Buka via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 11 17:30:25 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:

After second thought 
what if we have a large array of structs with a few uninitialized fields.
Initializing the rest will cost us anyway about the same.

Would it be better to check insize of `emitStoresForZeroInit`/`emitStoresForPatternInit`, more precicely in `emitStoresForConstant` before memset if IsAutoInit? 


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


More information about the cfe-commits mailing list