[clang] [clang] Fix array types comparison in getCommonSugaredType (PR #131649)
Matheus Izvekov via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 17 13:51:02 PDT 2025
================
@@ -14171,6 +14171,15 @@ static QualType getCommonSugarTypeNode(ASTContext &Ctx, const Type *X,
static auto unwrapSugar(SplitQualType &T, Qualifiers &QTotal) {
SmallVector<SplitQualType, 8> R;
while (true) {
+ if (const auto *ATy = dyn_cast<ArrayType>(T.Ty)) {
+ // C++ 9.3.3.4p3: Any type of the form "cv-qualifier-seq array of N U" is
+ // adjusted to "array of N cv-qualifier-seq U".
+ // C23 6.7.3p10: If the specification of an array type includes any type
+ // qualifiers, both the array and the element type are so-qualified.
+ //
+ // To simplify comparison remove the redundant qualifiers from the array.
+ T.Quals.removeCVRQualifiers(Qualifiers::Const | Qualifiers::Volatile);
----------------
mizvekov wrote:
This is at the wrong level to fix the problem.
We have the logic for dealing with Array qualifiers in `getCommonArrayElementType`.
That's where we adjust the outer qualifiers for Array types accordingly to the qualifiers of the element type.
Looks like there is a bug in the qualifier algebra there:
```C++
QX += EX.getQualifiers() - RQ;
QY += EY.getQualifiers() - RQ;
```
We want to break down those two lines to:
```C++
QX += EX.getQualifiers();
QY += EY.getQualifiers();
QX -= RQ;
QY -= RQ;
```
I believe this should fix your problem.
https://github.com/llvm/llvm-project/pull/131649
More information about the cfe-commits
mailing list