Skip to content

Commit 9bc13ae

Browse files
committed
Address review comments
- Now only qualifiers that are found in array element are cleared, - Test are moved into a new location.
1 parent cdf9f1a commit 9bc13ae

File tree

3 files changed

+40
-19
lines changed

3 files changed

+40
-19
lines changed

clang/lib/AST/ASTContext.cpp

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14168,18 +14168,39 @@ static QualType getCommonSugarTypeNode(ASTContext &Ctx, const Type *X,
1416814168
llvm_unreachable("Unhandled Type Class");
1416914169
}
1417014170

14171+
/// Returns element type of the array, probably multidimensional, specified by
14172+
/// the given ArrayType.
14173+
/// \returns Canonical type of the array element.
14174+
static QualType getNonArrayElementType(const ArrayType* ATy) {
14175+
QualType ElTy = ATy->getElementType().getCanonicalType();
14176+
while (auto *SubArr = dyn_cast<ArrayType>(ElTy.getTypePtr()))
14177+
ElTy = SubArr->getElementType();
14178+
return ElTy;
14179+
}
14180+
14181+
/// Given a qualified type, returns an equivalent type, which has cv-qualifiers
14182+
/// only at array element type.
14183+
static SplitQualType normalizeArrayQualifiers(const SplitQualType &T) {
14184+
if (const auto *ATy = dyn_cast<ArrayType>(T.Ty)) {
14185+
// C++ 9.3.3.4p3: Any type of the form "cv-qualifier-seq array of N U" is
14186+
// adjusted to "array of N cv-qualifier-seq U".
14187+
// C23 6.7.3p10: If the specification of an array type includes any type
14188+
// qualifiers, both the array and the element type are so-qualified.
14189+
//
14190+
// If cv-qualifier is present in both array and element type, remove the
14191+
// redundant qualifiers from the array.
14192+
QualType ElTy = getNonArrayElementType(ATy);
14193+
unsigned Quals =
14194+
ElTy.getCVRQualifiers() & (Qualifiers::Const | Qualifiers::Volatile);
14195+
return SplitQualType(ATy, Qualifiers::fromCVRMask(Quals));
14196+
}
14197+
return T;
14198+
}
14199+
1417114200
static auto unwrapSugar(SplitQualType &T, Qualifiers &QTotal) {
1417214201
SmallVector<SplitQualType, 8> R;
1417314202
while (true) {
14174-
if (const auto *ATy = dyn_cast<ArrayType>(T.Ty)) {
14175-
// C++ 9.3.3.4p3: Any type of the form "cv-qualifier-seq array of N U" is
14176-
// adjusted to "array of N cv-qualifier-seq U".
14177-
// C23 6.7.3p10: If the specification of an array type includes any type
14178-
// qualifiers, both the array and the element type are so-qualified.
14179-
//
14180-
// To simplify comparison remove the redundant qualifiers from the array.
14181-
T.Quals.removeCVRQualifiers(Qualifiers::Const | Qualifiers::Volatile);
14182-
}
14203+
T = normalizeArrayQualifiers(T);
1418314204
QTotal.addConsistentQualifiers(T.Quals);
1418414205
QualType NT = T.Ty->getLocallyUnqualifiedSingleStepDesugaredType();
1418514206
if (NT == QualType(T.Ty, 0))

clang/test/SemaCXX/constexpr-implicit-const-97005.cpp

Lines changed: 0 additions & 10 deletions
This file was deleted.

clang/test/SemaCXX/sugar-common-types.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,13 @@ namespace GH67603 {
146146
}
147147
template void h<int>();
148148
} // namespace GH67603
149+
150+
namespace PR97005 {
151+
bool a;
152+
constexpr const unsigned char c[] = { 5 };
153+
constexpr const unsigned char d[1] = { 0 };
154+
auto b = (a ? d : c);
155+
constexpr const unsigned char c1[][1] = {{ 5 }};
156+
constexpr const unsigned char d1[1][1] = {{ 0 }};
157+
auto b1 = (a ? d1 : c1);
158+
} // namespace PR97005

0 commit comments

Comments
 (0)