Skip to content

Commit 7a0d64a

Browse files
committed
Improved based on reviews
1 parent c0a939b commit 7a0d64a

File tree

7 files changed

+9
-22
lines changed

7 files changed

+9
-22
lines changed

clang/include/clang/AST/ASTContext.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,8 @@ class ASTContext : public RefCountedBase<ASTContext> {
278278
ArrayParameterTypes;
279279

280280
/// Store the unique Type corresponding to each Kind.
281-
mutable std::array<Type *, llvm::to_underlying(
282-
PredefinedSugarType::Kind::NumElements)>
281+
mutable std::array<Type *,
282+
llvm::to_underlying(PredefinedSugarType::Kind::Last) + 1>
283283
PredefinedSugarTypes{};
284284

285285
/// The set of nested name specifiers.

clang/include/clang/AST/Type.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2269,7 +2269,7 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
22692269
PtrdiffT,
22702270

22712271
// Indicates how many items the enum has.
2272-
NumElements
2272+
Last = PtrdiffT
22732273
};
22742274

22752275
class PresefinedSugarTypeBitfields {

clang/lib/AST/ASTContext.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2595,7 +2595,6 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const {
25952595
Align = static_cast<unsigned>(Width);
25962596
}
25972597
}
2598-
25992598
break;
26002599

26012600
case Type::PredefinedSugar:
@@ -5224,8 +5223,6 @@ QualType
52245223
ASTContext::getPredefinedSugarType(PredefinedSugarType::Kind KD) const {
52255224
using Kind = PredefinedSugarType::Kind;
52265225

5227-
assert(KD != Kind::NumElements);
5228-
52295226
if (auto *Target = PredefinedSugarTypes[llvm::to_underlying(KD)];
52305227
Target != nullptr)
52315228
return QualType(Target, 0);
@@ -5243,7 +5240,6 @@ ASTContext::getPredefinedSugarType(PredefinedSugarType::Kind KD) const {
52435240
return Ctx.getFromTargetType(Ctx.Target->getSignedSizeType());
52445241
case Kind::PtrdiffT:
52455242
return Ctx.getFromTargetType(Ctx.Target->getPtrDiffType(LangAS::Default));
5246-
case Kind::NumElements:;
52475243
}
52485244
llvm_unreachable("unexpected kind");
52495245
};

clang/lib/AST/FormatString.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -322,17 +322,12 @@ bool clang::analyze_format_string::ParseUTF8InvalidSpecifier(
322322

323323
static bool namedTypeToLengthModifierKind(ASTContext &Ctx, QualType QT,
324324
LengthModifier::Kind &K) {
325-
for (/**/; const auto *TT = QT->getAs<TypedefType>();
326-
QT = TT->getDecl()->getUnderlyingType()) {
325+
if (!Ctx.getLangOpts().C99 && !Ctx.getLangOpts().CPlusPlus)
326+
return false;
327+
for (/**/; const auto *TT = QT->getAs<TypedefType>(); QT = TT->desugar()) {
327328
const auto *TD = TT->getDecl();
328329
const auto *DC = TT->getDecl()->getDeclContext();
329-
bool RC = false;
330-
if (Ctx.getLangOpts().C99) {
331-
RC = DC->isTranslationUnit();
332-
} else if (Ctx.getLangOpts().CPlusPlus) {
333-
RC = DC->isTranslationUnit() || DC->isStdNamespace();
334-
}
335-
if (RC) {
330+
if (DC->isTranslationUnit() || DC->isStdNamespace()) {
336331
StringRef Name = TD->getIdentifier()->getName();
337332
if (Name == "size_t") {
338333
K = LengthModifier::AsSizeT;
@@ -362,9 +357,8 @@ static bool namedTypeToLengthModifierKind(ASTContext &Ctx, QualType QT,
362357
case Kind::PtrdiffT:
363358
K = LengthModifier::AsPtrDiff;
364359
return true;
365-
case Kind::NumElements:
366-
llvm_unreachable("unexpected kind");
367360
}
361+
llvm_unreachable("unexpected kind");
368362
}
369363
return false;
370364
}

clang/lib/AST/Type.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5622,7 +5622,6 @@ StringRef PredefinedSugarType::getName(Kind KD) {
56225622
return "__signed_size_t";
56235623
case Kind::PtrdiffT:
56245624
return "__ptrdiff_t";
5625-
case Kind::NumElements:;
56265625
}
56275626
llvm_unreachable("unexpected kind");
56285627
}

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -721,8 +721,7 @@ static bool matchesStlAllocatorFn(const Decl *D, const ASTContext &Ctx) {
721721
(MD->getNumParams() != 1 && MD->getNumParams() != 2))
722722
return false;
723723

724-
if (MD->parameters()[0]->getType().getCanonicalType() !=
725-
Ctx.getCanonicalSizeType())
724+
if (!Ctx.hasSameType(MD->parameters()[0]->getType(), Ctx.getSizeType()))
726725
return false;
727726

728727
if (MD->getNumParams() == 2) {

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,6 @@ void TypeLocWriter::VisitAtomicTypeLoc(AtomicTypeLoc TL) {
692692
void TypeLocWriter::VisitPipeTypeLoc(PipeTypeLoc TL) {
693693
addSourceLocation(TL.getKWLoc());
694694
}
695-
696695
void TypeLocWriter::VisitBitIntTypeLoc(clang::BitIntTypeLoc TL) {
697696
addSourceLocation(TL.getNameLoc());
698697
}

0 commit comments

Comments
 (0)