Skip to content

[clang] [dataflow] use unqualified type for smart pointer matching #125958

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

fmayer
Copy link
Contributor

@fmayer fmayer commented Feb 5, 2025

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().

Created using spr 1.3.4
@fmayer fmayer requested a review from jvoung February 5, 2025 23:26
@fmayer fmayer marked this pull request as ready for review February 5, 2025 23:26
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:dataflow Clang Dataflow Analysis framework - https://clang.llvm.org/docs/DataFlowAnalysisIntro.html clang:analysis labels Feb 5, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 5, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-analysis

Author: Florian Mayer (fmayer)

Changes

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().


Full diff: https://github.com/llvm/llvm-project/pull/125958.diff

1 Files Affected:

  • (modified) clang/lib/Analysis/FlowSensitive/SmartPointerAccessorCaching.cpp (+8-4)
diff --git a/clang/lib/Analysis/FlowSensitive/SmartPointerAccessorCaching.cpp b/clang/lib/Analysis/FlowSensitive/SmartPointerAccessorCaching.cpp
index c58bd309545dbf..576a0ca1594154 100644
--- a/clang/lib/Analysis/FlowSensitive/SmartPointerAccessorCaching.cpp
+++ b/clang/lib/Analysis/FlowSensitive/SmartPointerAccessorCaching.cpp
@@ -41,7 +41,8 @@ bool hasSmartPointerClassShape(const CXXRecordDecl &RD, bool &HasGet,
         HasStar = true;
         StarReturnType = MD->getReturnType()
                              .getNonReferenceType()
-                             ->getCanonicalTypeUnqualified();
+                             ->getCanonicalTypeUnqualified()
+                             .getUnqualifiedType();
       }
       break;
     case OO_Arrow:
@@ -49,7 +50,8 @@ bool hasSmartPointerClassShape(const CXXRecordDecl &RD, bool &HasGet,
         HasArrow = true;
         ArrowReturnType = MD->getReturnType()
                               ->getPointeeType()
-                              ->getCanonicalTypeUnqualified();
+                              ->getCanonicalTypeUnqualified()
+                              .getUnqualifiedType();
       }
       break;
     case OO_None: {
@@ -61,14 +63,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;

Copy link
Contributor

@jvoung jvoung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@fmayer fmayer merged commit f154048 into main Feb 6, 2025
12 of 13 checks passed
@fmayer fmayer deleted the users/fmayer/spr/clang-dataflow-use-unqualified-type-for-smart-pointer-matching branch February 6, 2025 02:23
Icohedron pushed a commit to Icohedron/llvm-project that referenced this pull request Feb 11, 2025
…lvm#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().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:analysis clang:dataflow Clang Dataflow Analysis framework - https://clang.llvm.org/docs/DataFlowAnalysisIntro.html clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants