[PATCH] D65361: [analyzer] Trust global initializers when analyzing main().
Balogh, Ádám via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 29 07:37:15 PDT 2019
baloghadamsoftware added a comment.
Thank you for working on this! I agree, we should trust global initializers in `main()` in C. Can we maybe detect whether GNU global constructors are enabled or better: used?
================
Comment at: clang/lib/StaticAnalyzer/Core/RegionStore.cpp:395
StoreRef getInitialStore(const LocationContext *InitLoc) override {
+ bool IsMainAnalysis = false;
----------------
I think this function deserves now some doc comments since it is not a trivial getter anymore.
================
Comment at: clang/lib/StaticAnalyzer/Core/RegionStore.cpp:630
+ (const RegionBindings::TreeTy *)((uintptr_t)store & ~(uintptr_t)1),
+ RBFactory.getTreeFactory(), (bool)((uintptr_t)store & (uintptr_t)1));
}
----------------
`(uintptr_t)1` look like a bit like some kind of magic number. Could we define it as a constant instead?
================
Comment at: clang/lib/StaticAnalyzer/Core/RegionStore.cpp:1693
const VarDecl *VD = VR->getDecl();
// Either the array or the array element has to be const.
+ if (VD->getType().isConstQualified() ||
----------------
Please, update the comment as well.
================
Comment at: clang/lib/StaticAnalyzer/Core/RegionStore.cpp:1785
unsigned Index = FD->getFieldIndex();
// Either the record variable or the field has to be const qualified.
+ if (RecordVarTy.isConstQualified() || Ty.isConstQualified() ||
----------------
This one as well.
================
Comment at: clang/lib/StaticAnalyzer/Core/RegionStore.cpp:2005
+ if (B.isMainAnalysis())
+ if (const Expr *Init = VD->getAnyInitializer())
----------------
Please add a comment to the block as well.
================
Comment at: clang/test/Analysis/main.c:21
+ return 0;
+}
----------------
Please add a negative test case (i.e. function that is not `main`) as well.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D65361/new/
https://reviews.llvm.org/D65361
More information about the cfe-commits
mailing list