[clang] [Modules] Record whether VarDecl initializers contain side effects (PR #143739)

Ben Langmuir via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 16 11:24:22 PDT 2025


================
@@ -2434,6 +2434,22 @@ VarDecl *VarDecl::getInitializingDeclaration() {
   return Def;
 }
 
+bool VarDecl::hasInitWithSideEffects() const {
+  if (!hasInit())
+    return false;
+
+  if (auto *S = dyn_cast<Stmt *>(Init)) {
----------------
benlangmuir wrote:

The original code in `getInit` also handles `EvaluatedStmt`. I would have naively expected we would call `getEvaluatedStmt()` and if present, we would check if it's an offset (in which case fall through to asking the `ASTReader::hasInitializerWithSideEffects`) or a pointer, in which case handle it here.  But I'm not that familiar with `EvaluatedStmt` so maybe I missed something

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


More information about the cfe-commits mailing list