Skip to content

Commit c3de969

Browse files
Carl PetoCarl Peto
Carl Peto
authored and
Carl Peto
committed
[clang]
- Sema::isSimpleTypeSpecifier return true for _Bool in c99 (currently returns false for _Bool, regardless of C dialect). (Fixes #72203) - move simple type decision code into shared location (IdentifierInfo) - replace the logic with a check for simple types and a proper check for a valid keyword in the appropriate dialect - change all call sites to match the above new API
1 parent f73bf45 commit c3de969

File tree

6 files changed

+48
-49
lines changed

6 files changed

+48
-49
lines changed

clang/include/clang/Basic/IdentifierTable.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,10 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
427427
/// language.
428428
bool isCPlusPlusKeyword(const LangOptions &LangOpts) const;
429429

430+
/// Return true if this token is a simple type specifier
431+
/// in the specified language.
432+
bool isSimpleTypeSpecifier(const LangOptions &LangOpts) const;
433+
430434
/// Get and set FETokenInfo. The language front-end is allowed to associate
431435
/// arbitrary metadata with this token.
432436
void *getFETokenInfo() const { return FETokenInfo; }

clang/include/clang/Sema/Sema.h

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

26372637
void DiagnoseUseOfUnimplementedSelectors();
26382638

2639-
bool isSimpleTypeSpecifier(tok::TokenKind Kind) const;
2639+
bool isSimpleTypeSpecifier(const IdentifierInfo &II) const;
26402640

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

clang/lib/Basic/IdentifierTable.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,45 @@ StringRef IdentifierInfo::deuglifiedName() const {
419419
return Name;
420420
}
421421

422+
/// Determine whether the token kind starts a simple-type-specifier.
423+
bool IdentifierInfo::isSimpleTypeSpecifier(const LangOptions &LangOpts) const {
424+
auto Kind = getTokenID();
425+
426+
switch (Kind) {
427+
case tok::kw_short:
428+
case tok::kw_long:
429+
case tok::kw___int64:
430+
case tok::kw___int128:
431+
case tok::kw_signed:
432+
case tok::kw_unsigned:
433+
case tok::kw_void:
434+
case tok::kw_char:
435+
case tok::kw_int:
436+
case tok::kw_half:
437+
case tok::kw_float:
438+
case tok::kw_double:
439+
case tok::kw___bf16:
440+
case tok::kw__Float16:
441+
case tok::kw___float128:
442+
case tok::kw_wchar_t:
443+
case tok::kw_bool:
444+
case tok::kw___underlying_type:
445+
case tok::kw___auto_type:
446+
case tok::kw__Bool:
447+
case tok::annot_typename:
448+
case tok::kw_char16_t:
449+
case tok::kw_char32_t:
450+
case tok::kw_typeof:
451+
case tok::annot_decltype:
452+
case tok::kw_decltype:
453+
case tok::kw_char8_t:
454+
return isKeyword(LangOpts);
455+
456+
default:
457+
return false;
458+
}
459+
}
460+
422461
tok::PPKeywordKind IdentifierInfo::getPPKeywordID() const {
423462
// We use a perfect hash function here involving the length of the keyword,
424463
// the first and third character. For preprocessor ID's there are no

clang/lib/Parse/ParseExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1597,7 +1597,7 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
15971597
if (TryAnnotateTypeOrScopeToken())
15981598
return ExprError();
15991599

1600-
if (!Actions.isSimpleTypeSpecifier(Tok.getKind()))
1600+
if (!Tok.getIdentifierInfo() || !Actions.isSimpleTypeSpecifier(*Tok.getIdentifierInfo()))
16011601
// We are trying to parse a simple-type-specifier but might not get such
16021602
// a token after error recovery.
16031603
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 (!Tok.getIdentifierInfo() || !Actions.isSimpleTypeSpecifier(*Tok.getIdentifierInfo())) {
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: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -128,52 +128,8 @@ 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
135-
case tok::kw_short:
136-
case tok::kw_long:
137-
case tok::kw___int64:
138-
case tok::kw___int128:
139-
case tok::kw_signed:
140-
case tok::kw_unsigned:
141-
case tok::kw_void:
142-
case tok::kw_char:
143-
case tok::kw_int:
144-
case tok::kw_half:
145-
case tok::kw_float:
146-
case tok::kw_double:
147-
case tok::kw___bf16:
148-
case tok::kw__Float16:
149-
case tok::kw___float128:
150-
case tok::kw___ibm128:
151-
case tok::kw_wchar_t:
152-
case tok::kw_bool:
153-
case tok::kw__Accum:
154-
case tok::kw__Fract:
155-
case tok::kw__Sat:
156-
#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
157-
#include "clang/Basic/TransformTypeTraits.def"
158-
case tok::kw___auto_type:
159-
return true;
160-
161-
case tok::annot_typename:
162-
case tok::kw_char16_t:
163-
case tok::kw_char32_t:
164-
case tok::kw_typeof:
165-
case tok::annot_decltype:
166-
case tok::kw_decltype:
167-
return getLangOpts().CPlusPlus;
168-
169-
case tok::kw_char8_t:
170-
return getLangOpts().Char8;
171-
172-
default:
173-
break;
174-
}
175-
176-
return false;
131+
bool Sema::isSimpleTypeSpecifier(const IdentifierInfo &II) const {
132+
return II.isSimpleTypeSpecifier(getLangOpts());
177133
}
178134

179135
namespace {

0 commit comments

Comments
 (0)