[PATCH] D131707: [analyzer]{NFC} Cache the result of getLocationType in TypedValueRegion
Denys Petrov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 11 11:41:25 PDT 2022
ASDenysPetrov created this revision.
ASDenysPetrov added reviewers: steakhal, martong, NoQ, xazax.hun, isuckatcs.
ASDenysPetrov added a project: clang.
Herald added subscribers: manas, dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware.
Herald added a project: All.
ASDenysPetrov requested review of this revision.
Herald added a subscriber: cfe-commits.
Fix FIXME. Produce `QualType` once in `getLocationType` at the first call. Then cache the result and return it for the next calls.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D131707
Files:
clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
===================================================================
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
@@ -529,6 +529,8 @@
/// TypedValueRegion - An abstract class representing regions having a typed value.
class TypedValueRegion : public TypedRegion {
+ mutable QualType CachedLocationType;
+
void anchor() override;
protected:
@@ -540,12 +542,13 @@
virtual QualType getValueType() const = 0;
QualType getLocationType() const override {
- // FIXME: We can possibly optimize this later to cache this value.
- QualType T = getValueType();
- ASTContext &ctx = getContext();
- if (T->getAs<ObjCObjectType>())
- return ctx.getObjCObjectPointerType(T);
- return ctx.getPointerType(getValueType());
+ if (CachedLocationType.isNull()) {
+ QualType T = getValueType();
+ ASTContext &C = getContext();
+ CachedLocationType = T->isObjCObjectType() ? C.getObjCObjectPointerType(T)
+ : C.getPointerType(T);
+ }
+ return CachedLocationType;
}
QualType getDesugaredValueType(ASTContext &Context) const {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131707.451935.patch
Type: text/x-patch
Size: 1287 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220811/6863a55c/attachment-0001.bin>
More information about the cfe-commits
mailing list