[PATCH] D77168: Add a flag to debug automatic variable initialization

JF Bastien via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 29 18:56:42 PDT 2020


jfb added a comment.

I think you want to emit a diagnostic any time auto-init doesn't happen because of this new flag. With the code simplification I propose, it would be pretty hard to introduce a regression... and it someone does it wouldn't be a silent one :)



================
Comment at: clang/lib/CodeGen/CGBuiltin.cpp:84
+    CGF.CGM.countAutoVarInit();
+  }
   CGF.Builder.CreateMemSet(AI, Byte, Size, AlignmentInBytes);
----------------
I think this logic is about right, but it seems like something you'd want to use as a two-liner instead. Maybe something like:

```
if (autoInitStopCounter())
  return;
```

This would check the value is set, check its value against the counter, and increment the counter.


================
Comment at: clang/lib/CodeGen/CGDecl.cpp:1817
+      CGM.countAutoVarInit();
+    }
+
----------------
This isn't the right place to stop auto-init: we can get past this point even without auto-init. As-is you're introducing a change in the regular language.

I hope that some tests for whatever happens below would break if you hack your flag to always stop auto-init for any value. i.e. just on your machine, run the entire test suite with this forcibly on. Only auto-init tests should fail, the others should all still pass.


================
Comment at: clang/lib/CodeGen/CodeGenModule.h:305
   const CodeGenOptions &CodeGenOpts;
+  mutable unsigned NumAutoVarInit = 0;
   llvm::Module &TheModule;
----------------
This is reachable from a context where `CodeGenModule` is `const` ? :( 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77168/new/

https://reviews.llvm.org/D77168





More information about the cfe-commits mailing list