Skip to content

Commit f154048

Browse files
authored
[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().
1 parent 4fb96f2 commit f154048

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

clang/lib/Analysis/FlowSensitive/SmartPointerAccessorCaching.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,17 @@ bool hasSmartPointerClassShape(const CXXRecordDecl &RD, bool &HasGet,
4242
HasStar = true;
4343
StarReturnType = MD->getReturnType()
4444
.getNonReferenceType()
45-
->getCanonicalTypeUnqualified();
45+
->getCanonicalTypeUnqualified()
46+
.getUnqualifiedType();
4647
}
4748
break;
4849
case OO_Arrow:
4950
if (MD->getReturnType()->isPointerType()) {
5051
HasArrow = true;
5152
ArrowReturnType = MD->getReturnType()
5253
->getPointeeType()
53-
->getCanonicalTypeUnqualified();
54+
->getCanonicalTypeUnqualified()
55+
.getUnqualifiedType();
5456
}
5557
break;
5658
case OO_None: {
@@ -62,14 +64,16 @@ bool hasSmartPointerClassShape(const CXXRecordDecl &RD, bool &HasGet,
6264
HasGet = true;
6365
GetReturnType = MD->getReturnType()
6466
->getPointeeType()
65-
->getCanonicalTypeUnqualified();
67+
->getCanonicalTypeUnqualified()
68+
.getUnqualifiedType();
6669
}
6770
} else if (II->isStr("value")) {
6871
if (MD->getReturnType()->isReferenceType()) {
6972
HasValue = true;
7073
ValueReturnType = MD->getReturnType()
7174
.getNonReferenceType()
72-
->getCanonicalTypeUnqualified();
75+
->getCanonicalTypeUnqualified()
76+
.getUnqualifiedType();
7377
}
7478
}
7579
} break;

0 commit comments

Comments
 (0)