[libcxx-commits] [libc] [compiler-rt] [libcxx] [clang] [llvm] [flang] [clang] Improved isSimpleTypeSpecifier (PR #79037)
Carl Peto via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jan 30 09:15:09 PST 2024
https://github.com/carlos4242 updated https://github.com/llvm/llvm-project/pull/79037
>From a78545315baf3d920f7101f44c6dba05238dbcf7 Mon Sep 17 00:00:00 2001
From: Carl Peto <CPeto at becrypt.com>
Date: Fri, 26 Jan 2024 14:20:48 +0000
Subject: [PATCH] [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 - PR feedback
fixes for owenca
---
clang/include/clang/Sema/Sema.h | 2 +-
clang/lib/Parse/ParseExpr.cpp | 2 +-
clang/lib/Parse/ParseObjc.cpp | 2 +-
clang/lib/Sema/SemaDecl.cpp | 25 ++++++++++---------------
4 files changed, 13 insertions(+), 18 deletions(-)
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index b5946e3f3178f..31ee05ec99a43 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2644,7 +2644,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 e725e187fc9ea..c31b07d46cf53 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 libcxx-commits
mailing list