Skip to content

Commit fdc1e0d

Browse files
Carl PetoCarl Peto
authored andcommitted
[clang]
- Sema::isSimpleTypeSpecifier return true for _Bool in c99 (currently returns false for _Bool, regardless of C dialect). (Fixes #72203) - replace the logic with a check for simple types and a proper check for a valid keyword in the appropriate dialect
1 parent e278c67 commit fdc1e0d

File tree

5 files changed

+23
-16
lines changed

5 files changed

+23
-16
lines changed

clang/include/clang/Lex/Token.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,13 @@ class Token {
196196
PtrData = (void*) II;
197197
}
198198

199+
bool hasIdentifierInfo() {
200+
if (is(tok::raw_identifier) || isAnnotation() || isLiteral() ||
201+
is(tok::eof))
202+
return false;
203+
return true;
204+
}
205+
199206
const void *getEofData() const {
200207
assert(is(tok::eof));
201208
return reinterpret_cast<const void *>(PtrData);

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(Token &Tok) const;
26402640

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

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 (!Actions.isSimpleTypeSpecifier(Tok))
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 (!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: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,15 @@ 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 {
131+
bool Sema::isSimpleTypeSpecifier(Token &Tok) const {
132+
auto Kind = Tok.getKind();
133+
auto LangOpts = getLangOpts();
134+
132135
switch (Kind) {
133-
// FIXME: Take into account the current language when deciding whether a
134-
// token kind is a valid type specifier
136+
case tok::annot_typename:
137+
case tok::annot_decltype:
138+
return true;
139+
135140
case tok::kw_short:
136141
case tok::kw_long:
137142
case tok::kw___int64:
@@ -156,24 +161,19 @@ bool Sema::isSimpleTypeSpecifier(tok::TokenKind Kind) const {
156161
#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
157162
#include "clang/Basic/TransformTypeTraits.def"
158163
case tok::kw___auto_type:
159-
return true;
160-
161-
case tok::annot_typename:
164+
case tok::kw__Bool:
162165
case tok::kw_char16_t:
163166
case tok::kw_char32_t:
164167
case tok::kw_typeof:
165-
case tok::annot_decltype:
166168
case tok::kw_decltype:
167-
return getLangOpts().CPlusPlus;
168-
169169
case tok::kw_char8_t:
170-
return getLangOpts().Char8;
170+
if (!Tok.hasIdentifierInfo())
171+
return false;
172+
return Tok.getIdentifierInfo()->isKeyword(LangOpts);
171173

172174
default:
173-
break;
175+
return false;
174176
}
175-
176-
return false;
177177
}
178178

179179
namespace {

0 commit comments

Comments
 (0)