[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 14:03:17 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:

The problem of `emitStoresForConstant` is that it may split struct/array variables to a handful of stores, which would mess up the size filtering (e.g., difficult to debug). What do you think?

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

(Correct me if I'm wrong) While emitting the auto-init, clang has no idea how each filed/element is initialized. It's difficult to distinguish these two cases in `CGDecl.cpp`:
- A large array of structs with all fields uninitialized.
- A large array of structs with a few field uninitialized.



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


More information about the cfe-commits mailing list