[PATCH] D150221: Add option -fkeep-static-variables to emit all static variables

Hubert Tong via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 31 21:00:57 PDT 2023


hubert.reinterpretcast added inline comments.


================
Comment at: clang/lib/CodeGen/CodeGenModule.cpp:2201-2210
+  if ((CodeGenOpts.KeepStaticConsts || CodeGenOpts.KeepStaticVariables) && D &&
+      isa<VarDecl>(D)) {
     const auto *VD = cast<VarDecl>(D);
-    if (VD->getType().isConstQualified() &&
-        VD->getStorageDuration() == SD_Static)
-      addUsedOrCompilerUsedGlobal(GV);
+    if (VD->getStorageDuration() == SD_Static) {
+      if (CodeGenOpts.KeepStaticVariables)
+        addUsedOrCompilerUsedGlobal(GV);
+      else if (CodeGenOpts.KeepStaticConsts && VD->getType().isConstQualified())
----------------
aaron.ballman wrote:
> Reformatted with whatever clang-format does for that, as I doubt I have the formatting correct.
@qianzhen, I don't think the suggestion was applied/applied correctly.

There should not be an `isa` followed by `dyn_cast`. That said, I think `dyn_cast_or_null` is perhaps appropriate instead of plain `dyn_cast`. Additionally, `VD` being non-null should be part of the condition.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150221



More information about the cfe-commits mailing list