[clang] [clang][dataflow] Use smart pointer caching in unchecked optional accessor (PR #120249)

Jan Voung via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 23 11:27:52 PST 2024


================
@@ -71,10 +73,28 @@ template <typename Base> class CachedConstAccessorsLattice : public Base {
   /// Requirements:
   ///
   ///  - `CE` should return a location (GLValue or a record type).
+  ///
+  /// DEPRECATED: switch users to the below overload which takes Callee and Type
+  /// directly.
   StorageLocation *getOrCreateConstMethodReturnStorageLocation(
       const RecordStorageLocation &RecordLoc, const CallExpr *CE,
       Environment &Env, llvm::function_ref<void(StorageLocation &)> Initialize);
 
+  /// Creates or returns a previously created `StorageLocation` associated with
+  /// a const method call `obj.getFoo()` where `RecordLoc` is the
+  /// `RecordStorageLocation` of `obj`, `Callee` is the decl for `getFoo`,
+  /// and `Type` is the return type of `getFoo`.
+  ///
+  /// The callback `Initialize` runs on the storage location if newly created.
+  ///
+  /// Requirements:
+  ///
+  ///  - `Type` should return a location (GLValue or a record type).
+  StorageLocation &getOrCreateConstMethodReturnStorageLocation(
----------------
jvoung wrote:

Good point! Maybe I was looking at how the old CallExpr version, which used the type from CE->getType() and thought I needed to pass the type in separately (since the CE isn't visible anymore). 

But getting the type from the `FunctionDecl` I think makes sense, especially w.r.t. the `assert(Type->isReferenceType() || Type->isRecordType());`. `CE->getType()` seems to have the reference part excluded (and instead indicated by CE->isGLValue), so wouldn't have been able to determine isReferenceType.

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


More information about the cfe-commits mailing list