Skip to content

Commit

Permalink
[clang] Improved isSimpleTypeSpecifier (llvm#79037)
Browse files Browse the repository at this point in the history
- 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 <CPeto@becrypt.com>
  • Loading branch information
carlos4242 and Carl Peto authored Jan 31, 2024
1 parent 2abcbbd commit b4d832c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 18 deletions.
2 changes: 1 addition & 1 deletion clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -2683,7 +2683,7 @@ class Sema final {

void DiagnoseUseOfUnimplementedSelectors();

bool isSimpleTypeSpecifier(tok::TokenKind Kind) const;
bool isSimpleTypeSpecifier(const Token &Tok) const;

ParsedType getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
Scope *S, CXXScopeSpec *SS = nullptr,
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Parse/ParseExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,7 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
if (TryAnnotateTypeOrScopeToken())
return ExprError();

if (!Actions.isSimpleTypeSpecifier(Tok.getKind()))
if (!Actions.isSimpleTypeSpecifier(Tok))
// We are trying to parse a simple-type-specifier but might not get such
// a token after error recovery.
return ExprError();
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Parse/ParseObjc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2971,7 +2971,7 @@ bool Parser::ParseObjCXXMessageReceiver(bool &IsExpr, void *&TypeOrExpr) {
tok::annot_cxxscope))
TryAnnotateTypeOrScopeToken();

if (!Actions.isSimpleTypeSpecifier(Tok.getKind())) {
if (!Actions.isSimpleTypeSpecifier(Tok)) {
// objc-receiver:
// expression
// Make sure any typos in the receiver are corrected or diagnosed, so that
Expand Down
25 changes: 10 additions & 15 deletions clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,13 @@ class TypeNameValidatorCCC final : public CorrectionCandidateCallback {
} // end anonymous namespace

/// Determine whether the token kind starts a simple-type-specifier.
bool Sema::isSimpleTypeSpecifier(tok::TokenKind Kind) const {
switch (Kind) {
// FIXME: Take into account the current language when deciding whether a
// token kind is a valid type specifier
bool Sema::isSimpleTypeSpecifier(const Token &Tok) const {
switch (Tok.getKind()) {
case tok::annot_typename:
case tok::annot_decltype:
case tok::annot_pack_indexing_type:
return true;

case tok::kw_short:
case tok::kw_long:
case tok::kw___int64:
Expand All @@ -150,31 +153,23 @@ bool Sema::isSimpleTypeSpecifier(tok::TokenKind Kind) const {
case tok::kw___ibm128:
case tok::kw_wchar_t:
case tok::kw_bool:
case tok::kw__Bool:
case tok::kw__Accum:
case tok::kw__Fract:
case tok::kw__Sat:
#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
#include "clang/Basic/TransformTypeTraits.def"
case tok::kw___auto_type:
return true;

case tok::annot_typename:
case tok::kw_char16_t:
case tok::kw_char32_t:
case tok::kw_typeof:
case tok::annot_decltype:
case tok::annot_pack_indexing_type:
case tok::kw_decltype:
return getLangOpts().CPlusPlus;

case tok::kw_char8_t:
return getLangOpts().Char8;
return Tok.getIdentifierInfo()->isKeyword(getLangOpts());

default:
break;
return false;
}

return false;
}

namespace {
Expand Down

0 comments on commit b4d832c

Please sign in to comment.