Skip to content

Commit b4d832c

Browse files
carlos4242Carl Peto
and
Carl Peto
authored
[clang] Improved isSimpleTypeSpecifier (llvm#79037)
- Sema::isSimpleTypeSpecifier return true for _Bool in c99 (currently returns false for _Bool, regardless of C dialect). (Fixes llvm#72203) - replace the logic with a check for simple types and a proper check for a valid keyword in the appropriate dialect Co-authored-by: Carl Peto <[email protected]>
1 parent 2abcbbd commit b4d832c

File tree

4 files changed

+13
-18
lines changed

4 files changed

+13
-18
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2683,7 +2683,7 @@ class Sema final {
26832683

26842684
void DiagnoseUseOfUnimplementedSelectors();
26852685

2686-
bool isSimpleTypeSpecifier(tok::TokenKind Kind) const;
2686+
bool isSimpleTypeSpecifier(const Token &Tok) const;
26872687

26882688
ParsedType getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
26892689
Scope *S, CXXScopeSpec *SS = nullptr,

clang/lib/Parse/ParseExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1609,7 +1609,7 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
16091609
if (TryAnnotateTypeOrScopeToken())
16101610
return ExprError();
16111611

1612-
if (!Actions.isSimpleTypeSpecifier(Tok.getKind()))
1612+
if (!Actions.isSimpleTypeSpecifier(Tok))
16131613
// We are trying to parse a simple-type-specifier but might not get such
16141614
// a token after error recovery.
16151615
return ExprError();

clang/lib/Parse/ParseObjc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2971,7 +2971,7 @@ bool Parser::ParseObjCXXMessageReceiver(bool &IsExpr, void *&TypeOrExpr) {
29712971
tok::annot_cxxscope))
29722972
TryAnnotateTypeOrScopeToken();
29732973

2974-
if (!Actions.isSimpleTypeSpecifier(Tok.getKind())) {
2974+
if (!Actions.isSimpleTypeSpecifier(Tok)) {
29752975
// objc-receiver:
29762976
// expression
29772977
// Make sure any typos in the receiver are corrected or diagnosed, so that

clang/lib/Sema/SemaDecl.cpp

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,13 @@ class TypeNameValidatorCCC final : public CorrectionCandidateCallback {
128128
} // end anonymous namespace
129129

130130
/// Determine whether the token kind starts a simple-type-specifier.
131-
bool Sema::isSimpleTypeSpecifier(tok::TokenKind Kind) const {
132-
switch (Kind) {
133-
// FIXME: Take into account the current language when deciding whether a
134-
// token kind is a valid type specifier
131+
bool Sema::isSimpleTypeSpecifier(const Token &Tok) const {
132+
switch (Tok.getKind()) {
133+
case tok::annot_typename:
134+
case tok::annot_decltype:
135+
case tok::annot_pack_indexing_type:
136+
return true;
137+
135138
case tok::kw_short:
136139
case tok::kw_long:
137140
case tok::kw___int64:
@@ -150,31 +153,23 @@ bool Sema::isSimpleTypeSpecifier(tok::TokenKind Kind) const {
150153
case tok::kw___ibm128:
151154
case tok::kw_wchar_t:
152155
case tok::kw_bool:
156+
case tok::kw__Bool:
153157
case tok::kw__Accum:
154158
case tok::kw__Fract:
155159
case tok::kw__Sat:
156160
#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
157161
#include "clang/Basic/TransformTypeTraits.def"
158162
case tok::kw___auto_type:
159-
return true;
160-
161-
case tok::annot_typename:
162163
case tok::kw_char16_t:
163164
case tok::kw_char32_t:
164165
case tok::kw_typeof:
165-
case tok::annot_decltype:
166-
case tok::annot_pack_indexing_type:
167166
case tok::kw_decltype:
168-
return getLangOpts().CPlusPlus;
169-
170167
case tok::kw_char8_t:
171-
return getLangOpts().Char8;
168+
return Tok.getIdentifierInfo()->isKeyword(getLangOpts());
172169

173170
default:
174-
break;
171+
return false;
175172
}
176-
177-
return false;
178173
}
179174

180175
namespace {

0 commit comments

Comments
 (0)