Author: Florian Mayer
Date: 2025-02-05T18:22:59-08:00
New Revision: f1540484ead766b18aeeb2be8b5fc9057ffa8a40

URL: 
https://github.com/llvm/llvm-project/commit/f1540484ead766b18aeeb2be8b5fc9057ffa8a40
DIFF: 
https://github.com/llvm/llvm-project/commit/f1540484ead766b18aeeb2be8b5fc9057ffa8a40.diff

LOG: [clang] [dataflow] use unqualified type for smart pointer matching 
(#125958)

one would assume that `getCanonicalTypeUnqualified` returns an
unqualified type, but sadly one would be wrong. the current logic fails
for std::optional as implemented in libcxx, because Star and Arrow types
mismatch in their const qualification.

there are other places in clang that use
getCanonicalTypeUnqualified().getUnqualifiedType().

Added: 
    

Modified: 
    clang/lib/Analysis/FlowSensitive/SmartPointerAccessorCaching.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Analysis/FlowSensitive/SmartPointerAccessorCaching.cpp 
b/clang/lib/Analysis/FlowSensitive/SmartPointerAccessorCaching.cpp
index b73f9e2751449a2..4f5d18225c4143b 100644
--- a/clang/lib/Analysis/FlowSensitive/SmartPointerAccessorCaching.cpp
+++ b/clang/lib/Analysis/FlowSensitive/SmartPointerAccessorCaching.cpp
@@ -42,7 +42,8 @@ bool hasSmartPointerClassShape(const CXXRecordDecl &RD, bool 
&HasGet,
         HasStar = true;
         StarReturnType = MD->getReturnType()
                              .getNonReferenceType()
-                             ->getCanonicalTypeUnqualified();
+                             ->getCanonicalTypeUnqualified()
+                             .getUnqualifiedType();
       }
       break;
     case OO_Arrow:
@@ -50,7 +51,8 @@ bool hasSmartPointerClassShape(const CXXRecordDecl &RD, bool 
&HasGet,
         HasArrow = true;
         ArrowReturnType = MD->getReturnType()
                               ->getPointeeType()
-                              ->getCanonicalTypeUnqualified();
+                              ->getCanonicalTypeUnqualified()
+                              .getUnqualifiedType();
       }
       break;
     case OO_None: {
@@ -62,14 +64,16 @@ bool hasSmartPointerClassShape(const CXXRecordDecl &RD, 
bool &HasGet,
           HasGet = true;
           GetReturnType = MD->getReturnType()
                               ->getPointeeType()
-                              ->getCanonicalTypeUnqualified();
+                              ->getCanonicalTypeUnqualified()
+                              .getUnqualifiedType();
         }
       } else if (II->isStr("value")) {
         if (MD->getReturnType()->isReferenceType()) {
           HasValue = true;
           ValueReturnType = MD->getReturnType()
                                 .getNonReferenceType()
-                                ->getCanonicalTypeUnqualified();
+                                ->getCanonicalTypeUnqualified()
+                                .getUnqualifiedType();
         }
       }
     } break;


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to