[PATCH] D122805: [analyzer][ctu] Only import const and trivial VarDecls

Balázs Benics via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 31 06:15:00 PDT 2022


steakhal added a comment.

Please add a test case where the class is trivial but the global variable of such is non-const, thus the initialized expression is not imported.



================
Comment at: clang/include/clang/CrossTU/CrossTranslationUnit.h:112
 
-// Returns true if the variable or any field of a record variable is const.
-bool containsConst(const VarDecl *VD, const ASTContext &ACtx);
+/// Returns true if it makes sense to import a foreign variable declaration.
+/// For instance, we don't want to import variables that have non-trivial types
----------------
definition


================
Comment at: clang/lib/CrossTU/CrossTranslationUnit.cpp:195
+bool shouldImport(const VarDecl *VD, const ASTContext &ACtx) {
+
   CanQualType CT = ACtx.getCanonicalType(VD->getType());
----------------
extra blank line


================
Comment at: clang/test/Analysis/Inputs/ctu-other.cpp:128
 SCNest extSCN = {.scn = {.a = 9}};
-SCNest::SCN extSubSCN = {.a = 1};
+extern SCNest::SCN const extSubSCN = {.a = 1};
 struct SCC {
----------------
AFAIK you don't need the `extern` here, since **this is** the definition of that global, not only a declaration.
Similarly applies to the rest of the cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122805



More information about the cfe-commits mailing list