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

Gábor Horváth via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 23 02:36:19 PST 2024


================
@@ -555,24 +557,26 @@ void handleConstMemberCall(const CallExpr *CE,
                            LatticeTransferState &State) {
   // If the const method returns an optional or reference to an optional.
   if (RecordLoc != nullptr && isSupportedOptionalType(CE->getType())) {
-    StorageLocation *Loc =
+    const FunctionDecl *DirectCallee = CE->getDirectCallee();
+    if (DirectCallee == nullptr)
+      return;
+    StorageLocation &Loc =
         State.Lattice.getOrCreateConstMethodReturnStorageLocation(
-            *RecordLoc, CE, State.Env, [&](StorageLocation &Loc) {
+            *RecordLoc, DirectCallee, CE->getType(), State.Env,
----------------
Xazax-hun wrote:

Here, we do not actually pass the return type of `DirectCallee`. The return type of the callee, and the type of the call expression might differ (I think one of differences is when the function returns a reference type). Thus, this use contradicts the documentation of this function. Update the documentation or the call site. 

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


More information about the cfe-commits mailing list