[clang] b4d832c - [clang] Improved isSimpleTypeSpecifier (#79037)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 30 18:18:54 PST 2024
Author: Carl Peto
Date: 2024-01-30T18:18:49-08:00
New Revision: b4d832c77dcba4136132559a5183883cf064389d
URL: https://github.com/llvm/llvm-project/commit/b4d832c77dcba4136132559a5183883cf064389d
DIFF: https://github.com/llvm/llvm-project/commit/b4d832c77dcba4136132559a5183883cf064389d.diff
LOG: [clang] Improved isSimpleTypeSpecifier (#79037)
- 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
Co-authored-by: Carl Peto <CPeto at becrypt.com>
Added:
Modified:
clang/include/clang/Sema/Sema.h
clang/lib/Parse/ParseExpr.cpp
clang/lib/Parse/ParseObjc.cpp
clang/lib/Sema/SemaDecl.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 59eab0185ae63..490df817ddfa2 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -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,
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 68dc1bc4a40a0..e5d4285b99183 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -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();
diff --git a/clang/lib/Parse/ParseObjc.cpp b/clang/lib/Parse/ParseObjc.cpp
index 849fd1ac95a44..4771b69eadb34 100644
--- a/clang/lib/Parse/ParseObjc.cpp
+++ b/clang/lib/Parse/ParseObjc.cpp
@@ -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
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index c89c3c487272d..00c750e42285c 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -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:
@@ -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 {
More information about the cfe-commits
mailing list