[clang] [clang] Sema::isSimpleTypeSpecifier return true for _Bool in c99 (PR #72204)

2023-11-13 Thread Carl Peto via cfe-commits

https://github.com/carlos4242 created 
https://github.com/llvm/llvm-project/pull/72204

Currently returns false for _Bool, regardless of C dialect.

Fixes #72203.

I'm unsure how to add a unit test for this?

I am open to suggestions!

@AaronBallman

>From 26d40ec42af065fdeda6bdf679cc87928c81c97a Mon Sep 17 00:00:00 2001
From: Carl Peto 
Date: Tue, 14 Nov 2023 03:50:14 +
Subject: [PATCH] [clang] Sema::isSimpleTypeSpecifier return true for _Bool in
 c99 Currently returns false for _Bool, regardless of C dialect.

Fixes #72203.
---
 clang/lib/Sema/SemaDecl.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 3876eb501083acb..da40b9a1a1b21b9 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -153,6 +153,9 @@ bool Sema::isSimpleTypeSpecifier(tok::TokenKind Kind) const 
{
   case tok::kw___auto_type:
 return true;
 
+  case tok::kw__Bool:
+return getLangOpts().C99;
+
   case tok::annot_typename:
   case tok::kw_char16_t:
   case tok::kw_char32_t:

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Sema::isSimpleTypeSpecifier return true for _Bool in c99 (PR #72204)

2023-11-14 Thread Carl Peto via cfe-commits

https://github.com/carlos4242 updated 
https://github.com/llvm/llvm-project/pull/72204

>From 26d40ec42af065fdeda6bdf679cc87928c81c97a Mon Sep 17 00:00:00 2001
From: Carl Peto 
Date: Tue, 14 Nov 2023 03:50:14 +
Subject: [PATCH 1/2] [clang] Sema::isSimpleTypeSpecifier return true for _Bool
 in c99 Currently returns false for _Bool, regardless of C dialect.

Fixes #72203.
---
 clang/lib/Sema/SemaDecl.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 3876eb501083acb..da40b9a1a1b21b9 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -153,6 +153,9 @@ bool Sema::isSimpleTypeSpecifier(tok::TokenKind Kind) const 
{
   case tok::kw___auto_type:
 return true;
 
+  case tok::kw__Bool:
+return getLangOpts().C99;
+
   case tok::annot_typename:
   case tok::kw_char16_t:
   case tok::kw_char32_t:

>From a3c5a71f93190204b17bfe01633ef0fa96c5f0ec Mon Sep 17 00:00:00 2001
From: Carl Peto 
Date: Tue, 14 Nov 2023 17:27:37 +
Subject: [PATCH 2/2] [AVR] make the AVR ABI Swift compatible

This patch is needed to add support to clang's AVR ABI for the Swift
language. It is a pre-requisite for upstreaming AVR patches to the Swift
compiler itself.

@benshi001 @rjmccall
---
 clang/lib/CodeGen/Targets/AVR.cpp | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/Targets/AVR.cpp 
b/clang/lib/CodeGen/Targets/AVR.cpp
index 50547dd6dec5e7d..bc6418c1e224eb4 100644
--- a/clang/lib/CodeGen/Targets/AVR.cpp
+++ b/clang/lib/CodeGen/Targets/AVR.cpp
@@ -112,7 +112,10 @@ class AVRABIInfo : public DefaultABIInfo {
 class AVRTargetCodeGenInfo : public TargetCodeGenInfo {
 public:
   AVRTargetCodeGenInfo(CodeGenTypes &CGT, unsigned NPR, unsigned NRR)
-  : TargetCodeGenInfo(std::make_unique(CGT, NPR, NRR)) {}
+  : TargetCodeGenInfo(std::make_unique(CGT, NPR, NRR)) {
+SwiftInfo =
+  std::make_unique(CGT, /*SwiftErrorInRegister=*/true);
+  }
 
   LangAS getGlobalVarAddressSpace(CodeGenModule &CGM,
   const VarDecl *D) const override {

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Sema::isSimpleTypeSpecifier return true for _Bool in c99 (PR #72204)

2023-11-14 Thread Carl Peto via cfe-commits

https://github.com/carlos4242 updated 
https://github.com/llvm/llvm-project/pull/72204

>From 26d40ec42af065fdeda6bdf679cc87928c81c97a Mon Sep 17 00:00:00 2001
From: Carl Peto 
Date: Tue, 14 Nov 2023 03:50:14 +
Subject: [PATCH] [clang] Sema::isSimpleTypeSpecifier return true for _Bool in
 c99 Currently returns false for _Bool, regardless of C dialect.

Fixes #72203.
---
 clang/lib/Sema/SemaDecl.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 3876eb501083acb..da40b9a1a1b21b9 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -153,6 +153,9 @@ bool Sema::isSimpleTypeSpecifier(tok::TokenKind Kind) const 
{
   case tok::kw___auto_type:
 return true;
 
+  case tok::kw__Bool:
+return getLangOpts().C99;
+
   case tok::annot_typename:
   case tok::kw_char16_t:
   case tok::kw_char32_t:

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [AVR] make the AVR ABI Swift compatible (PR #72298)

2023-11-14 Thread Carl Peto via cfe-commits

https://github.com/carlos4242 created 
https://github.com/llvm/llvm-project/pull/72298

This patch is needed to add support to clang's AVR ABI for the Swift language. 
It is a pre-requisite for adding AVR support to the public Swift compiler 
itself.

I'm open to any suggestions how I might create suitable unit tests for this?

@benshi001 @rjmccall

>From ed8b63c31f8b9a496bc5c51ab83a132c224594f0 Mon Sep 17 00:00:00 2001
From: Carl Peto 
Date: Tue, 14 Nov 2023 17:27:37 +
Subject: [PATCH] [AVR] make the AVR ABI Swift compatible

This patch is needed to add support to clang's AVR ABI for the Swift
language. It is a pre-requisite for upstreaming AVR patches to the Swift
compiler itself.

@benshi001 @rjmccall
---
 clang/lib/CodeGen/Targets/AVR.cpp | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/Targets/AVR.cpp 
b/clang/lib/CodeGen/Targets/AVR.cpp
index 50547dd6dec5e7d..bc6418c1e224eb4 100644
--- a/clang/lib/CodeGen/Targets/AVR.cpp
+++ b/clang/lib/CodeGen/Targets/AVR.cpp
@@ -112,7 +112,10 @@ class AVRABIInfo : public DefaultABIInfo {
 class AVRTargetCodeGenInfo : public TargetCodeGenInfo {
 public:
   AVRTargetCodeGenInfo(CodeGenTypes &CGT, unsigned NPR, unsigned NRR)
-  : TargetCodeGenInfo(std::make_unique(CGT, NPR, NRR)) {}
+  : TargetCodeGenInfo(std::make_unique(CGT, NPR, NRR)) {
+SwiftInfo =
+  std::make_unique(CGT, /*SwiftErrorInRegister=*/true);
+  }
 
   LangAS getGlobalVarAddressSpace(CodeGenModule &CGM,
   const VarDecl *D) const override {

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [AVR] make the AVR ABI Swift compatible (PR #72298)

2023-11-14 Thread Carl Peto via cfe-commits

https://github.com/carlos4242 updated 
https://github.com/llvm/llvm-project/pull/72298

>From fe214850572ba740c0027e8f2908cde0bae75517 Mon Sep 17 00:00:00 2001
From: Carl Peto 
Date: Tue, 14 Nov 2023 17:27:37 +
Subject: [PATCH] [AVR] make the AVR ABI Swift compatible

This patch is needed to add support to clang's AVR ABI for the Swift
language. It is a pre-requisite for upstreaming AVR patches to the Swift
compiler itself.

@benshi001 @rjmccall
---
 clang/lib/CodeGen/Targets/AVR.cpp | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/Targets/AVR.cpp 
b/clang/lib/CodeGen/Targets/AVR.cpp
index 50547dd6dec5e7d..bc6418c1e224eb4 100644
--- a/clang/lib/CodeGen/Targets/AVR.cpp
+++ b/clang/lib/CodeGen/Targets/AVR.cpp
@@ -112,7 +112,10 @@ class AVRABIInfo : public DefaultABIInfo {
 class AVRTargetCodeGenInfo : public TargetCodeGenInfo {
 public:
   AVRTargetCodeGenInfo(CodeGenTypes &CGT, unsigned NPR, unsigned NRR)
-  : TargetCodeGenInfo(std::make_unique(CGT, NPR, NRR)) {}
+  : TargetCodeGenInfo(std::make_unique(CGT, NPR, NRR)) {
+SwiftInfo =
+  std::make_unique(CGT, /*SwiftErrorInRegister=*/true);
+  }
 
   LangAS getGlobalVarAddressSpace(CodeGenModule &CGM,
   const VarDecl *D) const override {

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [AVR] make the AVR ABI Swift compatible (PR #72298)

2023-11-14 Thread Carl Peto via cfe-commits

https://github.com/carlos4242 updated 
https://github.com/llvm/llvm-project/pull/72298

>From 333916a07e90955564d03f14e004695802d9f618 Mon Sep 17 00:00:00 2001
From: Carl Peto 
Date: Tue, 14 Nov 2023 17:27:37 +
Subject: [PATCH] [AVR] make the AVR ABI Swift compatible

This patch is needed to add support to clang's AVR ABI for the Swift
language. It is a pre-requisite for upstreaming AVR patches to the Swift
compiler itself.

@benshi001 @rjmccall
---
 clang/lib/CodeGen/Targets/AVR.cpp | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/Targets/AVR.cpp 
b/clang/lib/CodeGen/Targets/AVR.cpp
index 50547dd6dec5e7d..ae141d3f485139c 100644
--- a/clang/lib/CodeGen/Targets/AVR.cpp
+++ b/clang/lib/CodeGen/Targets/AVR.cpp
@@ -112,7 +112,10 @@ class AVRABIInfo : public DefaultABIInfo {
 class AVRTargetCodeGenInfo : public TargetCodeGenInfo {
 public:
   AVRTargetCodeGenInfo(CodeGenTypes &CGT, unsigned NPR, unsigned NRR)
-  : TargetCodeGenInfo(std::make_unique(CGT, NPR, NRR)) {}
+  : TargetCodeGenInfo(std::make_unique(CGT, NPR, NRR)) {
+SwiftInfo =
+std::make_unique(CGT, /*SwiftErrorInRegister=*/true);
+  }
 
   LangAS getGlobalVarAddressSpace(CodeGenModule &CGM,
   const VarDecl *D) const override {

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [AVR] make the AVR ABI Swift compatible (PR #72298)

2023-11-17 Thread Carl Peto via cfe-commits

carlos4242 wrote:

@efriedma-quic  Cool. So it sounds like it's worth parking this for now, until 
Kuba's work #71986 is merged?

@rjmccall I'm not 100% sure I understand? The existing code in AVR.cpp handles 
the standard AVR ABI, which has a few simple rules based on GCC behaviour. Here 
we are effectively just passing on the handling for that to `AVRABIInfo`. The 
error in register thing, I just copied what ARM is doing. I figure that's OK 
for now. If we need to do some bugfixes later to get AVR working with errors 
then we'll take a look then probably. Is that reasonable?

https://github.com/llvm/llvm-project/pull/72298
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [AVR] make the AVR ABI Swift compatible (PR #72298)

2023-11-17 Thread Carl Peto via cfe-commits

carlos4242 wrote:

Thanks, that sounds like it's worth looking into and might avoid issues with 
AVR.

I'm still nowhere near enough of an LLVM expert to follow all the aspects of 
the discussion. Although from our perspective, I've never seen an issue that I 
know, using the above patch for the last few years in our LLVM back end for the 
swift compile (not in our build of clang). The code produced by the back end 
has always followed the AVR GCC ABI calling convention 
(https://gcc.gnu.org/wiki/avr-gcc ...roughly... registers assigned to 
parameters starting at r24 and working backward r22, r20, etc. to r8 then the 
rest on stack) when I have examined the generated assembly. But maybe that is 
because, until now, only our swift code has been emitted with the swift calling 
convention, until #71986 is merged, clang can't emit code with that calling 
convention and that's the issue?

Stupid question... Is it possible that our AVR LLVM back end is basically 
ignoring the swift calling convention when it actually emits our code? Doesn't 
usually the front end (clang/swift) just specify parameter types and the back 
end decides whether to put something in registers or on the stack? Sorry if I'm 
being dumb!

---

It might be that I just don't understand enough about LLVM and clang to really 
understand what all the surrounding code is doing properly, and maybe the right 
answer is for me to close this PR and wait for someone more experienced to come 
along when the time is right. We can always maintain this as a local patch in 
our builds instead, as we have for the past few years? I don't want to lay down 
issues for anyone using this in the future.

Or as an alternative, we can merge this PR as-is and deal with AVR problems 
later as an optimisation. I am neutral about what is the best approach and 
happy to take the advice of all the experts on here. (At the very least, the 
discussion has been enlightening for me!)

https://github.com/llvm/llvm-project/pull/72298
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Sema::isSimpleTypeSpecifier return true for _Bool in c99 (PR #72204)

2023-11-17 Thread Carl Peto via cfe-commits

carlos4242 wrote:

The dup  in Format seems to have already drifted from the one in Sema so 
putting them together might be a significant change, a bit more than I'm 
comfortable taking on... I don't want to break or alter behaviour for someone's 
formatter just to fix a tiny issue I found in a backwater part of Sema. :)

I'm thinking this probably isn't a testable patch TBH. I came across this issue 
due to the swift compiler linking into libClang and calling this function. 
Within clang itself, it looks like it's only used for some obscure objective C 
case and an equally obscure error case. The only "test" I can envisage is 
building some kind of artificial stand-alone command line tool that links into 
libClang and tests it, doesn't seem like a sensible use of anyone's CPU for 
such a straight bufix?

---

But it's a decision for the maintainer?

https://github.com/llvm/llvm-project/pull/72204
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [AVR] make the AVR ABI Swift compatible (PR #72298)

2023-11-21 Thread Carl Peto via cfe-commits

carlos4242 wrote:

> This is less about the implementation weeds of LLVM and more about the actual 
> details of your calling convention — the decisions about how arguments and 
> results are passed that are ultimately downstream of the choices made here. 
> Mostly, I'm encouraging you as a platform maintainer who's adding Swift CC 
> support for your platform to take a few moments to make sure you're happy 
> with the CC. It's likely that everything will _work_ regardless — Swift will 
> generate both declarations and calls according to the rules of the CC you 
> specify here, which should be enough to make things functional — but you 
> might find yourself looking at generated code in two years and realize you've 
> been doing something ridiculous for that entire time, and maybe it'll be too 
> awkward to change.

That makes a lot of sense. Thank you John. I guess here are my thoughts. As I 
understand it, the `SwiftABIInfo` by default does something like "if something 
can be passed in 4 registers or fewer then pass by register, otherwise pass 
indirectly"? I think that sweet spot (also sort of reflected in Existential 
Containers I believe?) makes sense for 32 bit or 64 bit registers (and 
presumably the sorts of caching you'd expect in modern intel/arm larger machine 
architectures). We have 8 bit registers, which is quite different...

Thinking aloud...

In our case, one complication is stack manipulation is fairly painful, we may 
be able to improve the AVR back end a bit but at the moment, just moving the 
stack pointer down for something like an alloca is 8 instructions (and then 
again 8 bytes in the function epilog).

But, equally, the default C ABI (avr gcc abi) allows a struct to be split over 
as many as 18 registers, and we are often producing pretty inefficient code 
like this when we have large structs, moving registers around a lot either side 
of a call site. Which is something I really wanted to find a way to solve "one 
day" with Swift for Arduino/Microswift/Swift for AVR.

Probably it's reasonable to say that ideally, when lowering to AVR assembly 
from Swift, any struct larger than 8 bytes should be passed on the stack in our 
case. Do you think we can implement that?

I'm happy to do some AVR back end work to change the ABI when the swift calling 
convention is in place on a function. (Although it might have to wait until 
I've had time to get the new Embedded mode working on our Swift compiler first, 
as that's taking up most of my time for the moment.)

https://github.com/llvm/llvm-project/pull/72298
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [AVR] make the AVR ABI Swift compatible (PR #72298)

2023-12-29 Thread Carl Peto via cfe-commits

carlos4242 wrote:

@benshi001 Have you got any thoughts on this as the AVR maintainer? I've been 
using various versions of this patch in my own branches for years. Should we 
merge?

I think ultimately it's your call as you're the AVR backend owner?

https://github.com/llvm/llvm-project/pull/72298
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Sema::isSimpleTypeSpecifier return true for _Bool in c99 (PR #72204)

2023-12-29 Thread Carl Peto via cfe-commits

carlos4242 wrote:

Hi @AaronBallman what do you think about this PR? Is it good to merge or is 
there something else I can add?

https://github.com/llvm/llvm-project/pull/72204
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [AVR] make the AVR ABI Swift compatible (PR #72298)

2024-01-10 Thread Carl Peto via cfe-commits

carlos4242 wrote:

Sure thing @benshi001 ... I'll create tests. The Swift ABI is documented here: 
https://github.com/apple/swift/blob/main/docs/ABI/CallingConvention.rst

I don't think this change will actually change any ABI. All my code uses the 
normal avr-gcc ABI you referenced.

I'll work out the details with the Apple engineers on a PR in their LLVM fork. 
Once we've got it in a state everyone is happy with, I'll bring it back here. 
That way nothing is blocked and we can take the time we need. Thank you.

https://github.com/llvm/llvm-project/pull/72298
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [AVR] make the AVR ABI Swift compatible (PR #72298)

2024-01-10 Thread Carl Peto via cfe-commits

carlos4242 wrote:

That makes sense. I think I’ll close this PR for now and work on the apple fork 
to get these issues resolved with them. Then I’ll come back once we have 
squared off the edges. Cheers Ben.

https://github.com/llvm/llvm-project/pull/72298
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [AVR] make the AVR ABI Swift compatible (PR #72298)

2024-01-10 Thread Carl Peto via cfe-commits

https://github.com/carlos4242 closed 
https://github.com/llvm/llvm-project/pull/72298
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libc] [compiler-rt] [libcxx] [clang] [llvm] [flang] [clang] Improved isSimpleTypeSpecifier (PR #79037)

2024-01-30 Thread Carl Peto via cfe-commits

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 
Date: Fri, 26 Jan 2024 14:20:48 +
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 {

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Improved isSimpleTypeSpecifier (PR #79037)

2024-01-25 Thread Carl Peto via cfe-commits

https://github.com/carlos4242 updated 
https://github.com/llvm/llvm-project/pull/79037

>From 61a06b77e8e6f2b5c5a9a2aa0b7f46260545f5b4 Mon Sep 17 00:00:00 2001
From: Carl Peto 
Date: Mon, 22 Jan 2024 18:52:46 +
Subject: [PATCH 1/2] [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

---
 clang/include/clang/Basic/IdentifierTable.h |  4 ++
 clang/include/clang/Sema/Sema.h |  2 +-
 clang/lib/Basic/IdentifierTable.cpp | 39 +
 clang/lib/Parse/ParseExpr.cpp   |  3 +-
 clang/lib/Parse/ParseObjc.cpp   |  3 +-
 clang/lib/Sema/SemaDecl.cpp | 48 +
 6 files changed, 50 insertions(+), 49 deletions(-)

diff --git a/clang/include/clang/Basic/IdentifierTable.h 
b/clang/include/clang/Basic/IdentifierTable.h
index 1ac182d4fce26f6..2c979e438e81bb3 100644
--- a/clang/include/clang/Basic/IdentifierTable.h
+++ b/clang/include/clang/Basic/IdentifierTable.h
@@ -427,6 +427,10 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
   /// language.
   bool isCPlusPlusKeyword(const LangOptions &LangOpts) const;
 
+  /// Return true if this token is a simple type specifier
+  /// in the specified language.
+  bool isSimpleTypeSpecifier(const LangOptions &LangOpts) const;
+
   /// Get and set FETokenInfo. The language front-end is allowed to associate
   /// arbitrary metadata with this token.
   void *getFETokenInfo() const { return FETokenInfo; }
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 0db39333b0ee347..bc1fd19b5c6de7b 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2636,7 +2636,7 @@ class Sema final {
 
   void DiagnoseUseOfUnimplementedSelectors();
 
-  bool isSimpleTypeSpecifier(tok::TokenKind Kind) const;
+  bool isSimpleTypeSpecifier(const IdentifierInfo &II) const;
 
   ParsedType getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
  Scope *S, CXXScopeSpec *SS = nullptr,
diff --git a/clang/lib/Basic/IdentifierTable.cpp 
b/clang/lib/Basic/IdentifierTable.cpp
index d0d8316385b452f..78c783cdff6b5ea 100644
--- a/clang/lib/Basic/IdentifierTable.cpp
+++ b/clang/lib/Basic/IdentifierTable.cpp
@@ -419,6 +419,45 @@ StringRef IdentifierInfo::deuglifiedName() const {
   return Name;
 }
 
+/// Determine whether the token kind starts a simple-type-specifier.
+bool IdentifierInfo::isSimpleTypeSpecifier(const LangOptions &LangOpts) const {
+  auto Kind = getTokenID();
+
+  switch (Kind) {
+  case tok::kw_short:
+  case tok::kw_long:
+  case tok::kw___int64:
+  case tok::kw___int128:
+  case tok::kw_signed:
+  case tok::kw_unsigned:
+  case tok::kw_void:
+  case tok::kw_char:
+  case tok::kw_int:
+  case tok::kw_half:
+  case tok::kw_float:
+  case tok::kw_double:
+  case tok::kw___bf16:
+  case tok::kw__Float16:
+  case tok::kw___float128:
+  case tok::kw_wchar_t:
+  case tok::kw_bool:
+  case tok::kw___underlying_type:
+  case tok::kw___auto_type:
+  case tok::kw__Bool:
+  case tok::annot_typename:
+  case tok::kw_char16_t:
+  case tok::kw_char32_t:
+  case tok::kw_typeof:
+  case tok::annot_decltype:
+  case tok::kw_decltype:
+  case tok::kw_char8_t:
+return isKeyword(LangOpts);
+
+  default:
+return false;
+  }
+}
+
 tok::PPKeywordKind IdentifierInfo::getPPKeywordID() const {
   // We use a perfect hash function here involving the length of the keyword,
   // the first and third character.  For preprocessor ID's there are no
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index e862856a08ca117..8f9f918bf544fd8 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -1597,7 +1597,8 @@ ExprResult Parser::ParseCastExpression(CastParseKind 
ParseKind,
   if (TryAnnotateTypeOrScopeToken())
 return ExprError();
 
-  if (!Actions.isSimpleTypeSpecifier(Tok.getKind()))
+  if (!Tok.getIdentifierInfo() ||
+  !Actions.isSimpleTypeSpecifier(*Tok.getIdentifierInfo()))
 // 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 849fd1ac95a442e..5565770610c491b 100644
--- a/clang/lib/Parse/ParseObjc.cpp
+++ b/clang/lib/Parse/ParseObjc.cpp
@@ -2971,7 +2971,8 @@ bool Parser::ParseObjCXXMessageReceiver(bool &IsExpr, 
void *&TypeOrExpr) {
   tok::annot_cxxscope))
 TryAnnotateTypeOrScopeToken();
 
-  if (!Actions.isSimpleTypeSpecifier(Tok.getKind())) {
+  if (!Tok.getIdentifierInfo() ||
+  !Actions.isSimpleTypeSpecifier(*Tok.getId

[clang] [clang] Improved isSimpleTypeSpecifier (PR #79037)

2024-01-26 Thread Carl Peto via cfe-commits

https://github.com/carlos4242 updated 
https://github.com/llvm/llvm-project/pull/79037

>From fdc1e0dbec6821e292ba3da7770dbae22923db20 Mon Sep 17 00:00:00 2001
From: Carl Peto 
Date: Fri, 26 Jan 2024 14:20:48 +
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

---
 clang/include/clang/Lex/Token.h |  7 +++
 clang/include/clang/Sema/Sema.h |  2 +-
 clang/lib/Parse/ParseExpr.cpp   |  2 +-
 clang/lib/Parse/ParseObjc.cpp   |  2 +-
 clang/lib/Sema/SemaDecl.cpp | 26 +-
 5 files changed, 23 insertions(+), 16 deletions(-)

diff --git a/clang/include/clang/Lex/Token.h b/clang/include/clang/Lex/Token.h
index 1409e2c58b550d..3c707d46932213 100644
--- a/clang/include/clang/Lex/Token.h
+++ b/clang/include/clang/Lex/Token.h
@@ -196,6 +196,13 @@ class Token {
 PtrData = (void*) II;
   }
 
+  bool hasIdentifierInfo() {
+if (is(tok::raw_identifier) || isAnnotation() || isLiteral() ||
+is(tok::eof))
+  return false;
+return true;
+  }
+
   const void *getEofData() const {
 assert(is(tok::eof));
 return reinterpret_cast(PtrData);
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 1f1cbd11ff7358..dc8797b2f12106 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2636,7 +2636,7 @@ class Sema final {
 
   void DiagnoseUseOfUnimplementedSelectors();
 
-  bool isSimpleTypeSpecifier(tok::TokenKind Kind) const;
+  bool isSimpleTypeSpecifier(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 e862856a08ca11..034d56c6b0e300 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -1597,7 +1597,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 849fd1ac95a442..4771b69eadb34b 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 f9bf1d14bdc4f6..4c7b12a53768c0 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -128,10 +128,15 @@ 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 {
+bool Sema::isSimpleTypeSpecifier(Token &Tok) const {
+  auto Kind = Tok.getKind();
+  auto LangOpts = getLangOpts();
+
   switch (Kind) {
-  // FIXME: Take into account the current language when deciding whether a
-  // token kind is a valid type specifier
+  case tok::annot_typename:
+  case tok::annot_decltype:
+return true;
+
   case tok::kw_short:
   case tok::kw_long:
   case tok::kw___int64:
@@ -156,24 +161,19 @@ bool Sema::isSimpleTypeSpecifier(tok::TokenKind Kind) 
const {
 #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__Bool:
   case tok::kw_char16_t:
   case tok::kw_char32_t:
   case tok::kw_typeof:
-  case tok::annot_decltype:
   case tok::kw_decltype:
-return getLangOpts().CPlusPlus;
-
   case tok::kw_char8_t:
-return getLangOpts().Char8;
+if (!Tok.hasIdentifierInfo())
+  return false;
+return Tok.getIdentifierInfo()->isKeyword(LangOpts);
 
   default:
-break;
+return false;
   }
-
-  return false;
 }
 
 namespace {

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Improved is simple type specifier (PR #78903)

2024-01-26 Thread Carl Peto via cfe-commits

carlos4242 wrote:

closed in favour of https://github.com/llvm/llvm-project/pull/79037

https://github.com/llvm/llvm-project/pull/78903
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Improved is simple type specifier (PR #78903)

2024-01-26 Thread Carl Peto via cfe-commits

https://github.com/carlos4242 closed 
https://github.com/llvm/llvm-project/pull/78903
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Improved isSimpleTypeSpecifier (PR #79037)

2024-01-26 Thread Carl Peto via cfe-commits

https://github.com/carlos4242 ready_for_review 
https://github.com/llvm/llvm-project/pull/79037
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Improved isSimpleTypeSpecifier (PR #79037)

2024-01-26 Thread Carl Peto via cfe-commits

https://github.com/carlos4242 edited 
https://github.com/llvm/llvm-project/pull/79037
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Improved isSimpleTypeSpecifier (PR #79037)

2024-01-28 Thread Carl Peto via cfe-commits

carlos4242 wrote:

I think unit testing the bug fix to this function (the copy that is in Sema) is 
going to be nearly impossible.

To prove the point, I tried hard coding the wrong return value for many types 
just now...

```
  switch (Kind) {
  case tok::kw_bool:
  case tok::kw_short:
  case tok::kw_long:
  case tok::kw___int64:
  case tok::kw___int128:
  case tok::kw_signed:
  case tok::kw_unsigned:
  case tok::kw_char:
  case tok::kw_int:
  case tok::kw_half:
  case tok::kw_float:
  case tok::kw_double:
  case tok::kw___bf16:
  case tok::kw__Float16:
  case tok::kw___float128:
  case tok::kw___ibm128:
  case tok::kw_wchar_t:
return false;
```

...Then re-ran the full clang/tests suite (18,000+ tests) and all passed as 
normal. So there's basically very little unit test coverage on this function as 
it stands. It's not just a question of improving or adding to existing tests. 
Whoever first wrote this function seems to have not added really enough unit 
test coverage at the time, and it's only called in two obscure places in Sema. 
The duplicate copy function in Format is more widely used and would probably be 
easier to test. But for this PR I think I'll make the changes you suggest, then 
leave it as is... either it gets approved without new tests or it'll get culled 
one day as an abandoned PR. I'll leave that up to the maintainers.

https://github.com/llvm/llvm-project/pull/79037
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Improved isSimpleTypeSpecifier (PR #79037)

2024-01-28 Thread Carl Peto via cfe-commits

https://github.com/carlos4242 updated 
https://github.com/llvm/llvm-project/pull/79037

>From fdc1e0dbec6821e292ba3da7770dbae22923db20 Mon Sep 17 00:00:00 2001
From: Carl Peto 
Date: Fri, 26 Jan 2024 14:20:48 +
Subject: [PATCH 1/2] [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

---
 clang/include/clang/Lex/Token.h |  7 +++
 clang/include/clang/Sema/Sema.h |  2 +-
 clang/lib/Parse/ParseExpr.cpp   |  2 +-
 clang/lib/Parse/ParseObjc.cpp   |  2 +-
 clang/lib/Sema/SemaDecl.cpp | 26 +-
 5 files changed, 23 insertions(+), 16 deletions(-)

diff --git a/clang/include/clang/Lex/Token.h b/clang/include/clang/Lex/Token.h
index 1409e2c58b550df..3c707d469322139 100644
--- a/clang/include/clang/Lex/Token.h
+++ b/clang/include/clang/Lex/Token.h
@@ -196,6 +196,13 @@ class Token {
 PtrData = (void*) II;
   }
 
+  bool hasIdentifierInfo() {
+if (is(tok::raw_identifier) || isAnnotation() || isLiteral() ||
+is(tok::eof))
+  return false;
+return true;
+  }
+
   const void *getEofData() const {
 assert(is(tok::eof));
 return reinterpret_cast(PtrData);
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 1f1cbd11ff73581..dc8797b2f12106f 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2636,7 +2636,7 @@ class Sema final {
 
   void DiagnoseUseOfUnimplementedSelectors();
 
-  bool isSimpleTypeSpecifier(tok::TokenKind Kind) const;
+  bool isSimpleTypeSpecifier(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 e862856a08ca117..034d56c6b0e300a 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -1597,7 +1597,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 849fd1ac95a442e..4771b69eadb34b9 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 f9bf1d14bdc4f68..4c7b12a53768c01 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -128,10 +128,15 @@ 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 {
+bool Sema::isSimpleTypeSpecifier(Token &Tok) const {
+  auto Kind = Tok.getKind();
+  auto LangOpts = getLangOpts();
+
   switch (Kind) {
-  // FIXME: Take into account the current language when deciding whether a
-  // token kind is a valid type specifier
+  case tok::annot_typename:
+  case tok::annot_decltype:
+return true;
+
   case tok::kw_short:
   case tok::kw_long:
   case tok::kw___int64:
@@ -156,24 +161,19 @@ bool Sema::isSimpleTypeSpecifier(tok::TokenKind Kind) 
const {
 #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__Bool:
   case tok::kw_char16_t:
   case tok::kw_char32_t:
   case tok::kw_typeof:
-  case tok::annot_decltype:
   case tok::kw_decltype:
-return getLangOpts().CPlusPlus;
-
   case tok::kw_char8_t:
-return getLangOpts().Char8;
+if (!Tok.hasIdentifierInfo())
+  return false;
+return Tok.getIdentifierInfo()->isKeyword(LangOpts);
 
   default:
-break;
+return false;
   }
-
-  return false;
 }
 
 namespace {

>From 986324450006ad6dc761e85e7611a6e93a4ee2fb Mon Sep 17 00:00:00 2001
From: Carl Peto 
Date: Sun, 28 Jan 2024 20:32:17 +
Subject: [PATCH 2/2] PR feedback fixes for owenca

---
 clang/include/clang/Lex/Token.h |  7 ---
 clang/include/clang/Sema/Sema.h |  2 +-
 clang/lib/Sema/SemaDecl.cpp | 13 --

[clang] [clang] Improved isSimpleTypeSpecifier (PR #79037)

2024-01-29 Thread Carl Peto via cfe-commits

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 
Date: Fri, 26 Jan 2024 14:20:48 +
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 b5946e3f3178ff2..31ee05ec99a43c8 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 68dc1bc4a40a074..e5d4285b991831e 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 849fd1ac95a442e..4771b69eadb34b9 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 e725e187fc9ea08..c31b07d46cf5301 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 {

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Improved isSimpleTypeSpecifier (PR #79037)

2024-01-29 Thread Carl Peto via cfe-commits

carlos4242 wrote:

> LGTM, but please rebase and resolve conflicts.

done, rebased, tests pass locally

https://github.com/llvm/llvm-project/pull/79037
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Improved isSimpleTypeSpecifier (PR #79037)

2024-01-29 Thread Carl Peto via cfe-commits

carlos4242 wrote:

note: build kite is passing on linux but failing windows tests with an error 
like "mt.exe : general error c101008d: Failed to write the updated manifest to 
the resource of file "bin\llvm-symbolizer.exe". Operation did not complete 
successfully because the file contains a virus or potentially unwanted 
software" ... I'm a bit unsure how to proceed with that. Does it look like a 
genuine failure I should address or a spurious build quirk?

https://github.com/llvm/llvm-project/pull/79037
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Improved is simple type specifier (PR #78903)

2024-01-21 Thread Carl Peto via cfe-commits

https://github.com/carlos4242 created 
https://github.com/llvm/llvm-project/pull/78903

Here's the sort of approach I"m looking at @owenca 

>From 95eb591df3727dfefae5336f80e92046bff96f42 Mon Sep 17 00:00:00 2001
From: Carl Peto 
Date: Tue, 14 Nov 2023 03:50:14 +
Subject: [PATCH 1/2] [clang] Sema::isSimpleTypeSpecifier return true for _Bool
 in c99 Currently returns false for _Bool, regardless of C dialect.

Fixes #72203.
---
 clang/lib/Sema/SemaDecl.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 8dff2cdc063df3..aca7d6f343f96d 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -158,6 +158,9 @@ bool Sema::isSimpleTypeSpecifier(tok::TokenKind Kind) const 
{
   case tok::kw___auto_type:
 return true;
 
+  case tok::kw__Bool:
+return getLangOpts().C99;
+
   case tok::annot_typename:
   case tok::kw_char16_t:
   case tok::kw_char32_t:

>From d46a0f8fde1a7d6b57fa52b0d2b6db96d3e4e260 Mon Sep 17 00:00:00 2001
From: Carl Peto 
Date: Sun, 21 Jan 2024 01:13:24 +
Subject: [PATCH 2/2] - 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 the
 duplicate functions from Sema and Format to stub functions that both invoke
 this - attempt to reverse engineer language options in Format from the Style
 - change all call sites to match the above new API

---
 clang/include/clang/Basic/IdentifierTable.h |  4 ++
 clang/include/clang/Sema/Sema.h |  2 +-
 clang/lib/Basic/IdentifierTable.cpp | 39 
 clang/lib/Format/FormatToken.cpp| 38 ++-
 clang/lib/Format/TokenAnnotator.cpp | 16 +++
 clang/lib/Format/UnwrappedLineParser.cpp|  6 +--
 clang/lib/Parse/ParseExpr.cpp   |  2 +-
 clang/lib/Parse/ParseObjc.cpp   |  2 +-
 clang/lib/Sema/SemaDecl.cpp | 51 +
 9 files changed, 62 insertions(+), 98 deletions(-)

diff --git a/clang/include/clang/Basic/IdentifierTable.h 
b/clang/include/clang/Basic/IdentifierTable.h
index 1ac182d4fce26f..2c979e438e81bb 100644
--- a/clang/include/clang/Basic/IdentifierTable.h
+++ b/clang/include/clang/Basic/IdentifierTable.h
@@ -427,6 +427,10 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
   /// language.
   bool isCPlusPlusKeyword(const LangOptions &LangOpts) const;
 
+  /// Return true if this token is a simple type specifier
+  /// in the specified language.
+  bool isSimpleTypeSpecifier(const LangOptions &LangOpts) const;
+
   /// Get and set FETokenInfo. The language front-end is allowed to associate
   /// arbitrary metadata with this token.
   void *getFETokenInfo() const { return FETokenInfo; }
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 0db39333b0ee34..bc1fd19b5c6de7 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2636,7 +2636,7 @@ class Sema final {
 
   void DiagnoseUseOfUnimplementedSelectors();
 
-  bool isSimpleTypeSpecifier(tok::TokenKind Kind) const;
+  bool isSimpleTypeSpecifier(const IdentifierInfo &II) const;
 
   ParsedType getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
  Scope *S, CXXScopeSpec *SS = nullptr,
diff --git a/clang/lib/Basic/IdentifierTable.cpp 
b/clang/lib/Basic/IdentifierTable.cpp
index d0d8316385b452..78c783cdff6b5e 100644
--- a/clang/lib/Basic/IdentifierTable.cpp
+++ b/clang/lib/Basic/IdentifierTable.cpp
@@ -419,6 +419,45 @@ StringRef IdentifierInfo::deuglifiedName() const {
   return Name;
 }
 
+/// Determine whether the token kind starts a simple-type-specifier.
+bool IdentifierInfo::isSimpleTypeSpecifier(const LangOptions &LangOpts) const {
+  auto Kind = getTokenID();
+
+  switch (Kind) {
+  case tok::kw_short:
+  case tok::kw_long:
+  case tok::kw___int64:
+  case tok::kw___int128:
+  case tok::kw_signed:
+  case tok::kw_unsigned:
+  case tok::kw_void:
+  case tok::kw_char:
+  case tok::kw_int:
+  case tok::kw_half:
+  case tok::kw_float:
+  case tok::kw_double:
+  case tok::kw___bf16:
+  case tok::kw__Float16:
+  case tok::kw___float128:
+  case tok::kw_wchar_t:
+  case tok::kw_bool:
+  case tok::kw___underlying_type:
+  case tok::kw___auto_type:
+  case tok::kw__Bool:
+  case tok::annot_typename:
+  case tok::kw_char16_t:
+  case tok::kw_char32_t:
+  case tok::kw_typeof:
+  case tok::annot_decltype:
+  case tok::kw_decltype:
+  case tok::kw_char8_t:
+return isKeyword(LangOpts);
+
+  default:
+return false;
+  }
+}
+
 tok::PPKeywordKind IdentifierInfo::getPPKeywordID() const {
   // We use a perfect hash function here involving the length of the keyword,
   // the first and third character.  For preprocessor ID's there are no
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index b791c5a26bbe3a..70e997e179a8cc 1

[clang] Improved is simple type specifier (PR #78903)

2024-01-22 Thread Carl Peto via cfe-commits

https://github.com/carlos4242 updated 
https://github.com/llvm/llvm-project/pull/78903

>From 2622ca430d7edb1c49cda9bbbf6145b60e2e37c4 Mon Sep 17 00:00:00 2001
From: Carl Peto 
Date: Tue, 14 Nov 2023 03:50:14 +
Subject: [PATCH] [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 the duplicate functions from Sema and Format to stub functions that 
both invoke this
- attempt to reverse engineer language options in Format from the Style
- change all call sites to match the above new API
---
 clang/include/clang/Basic/IdentifierTable.h |  4 ++
 clang/include/clang/Sema/Sema.h |  2 +-
 clang/lib/Basic/IdentifierTable.cpp | 39 +
 clang/lib/Format/FormatToken.cpp| 38 ++--
 clang/lib/Format/TokenAnnotator.cpp | 16 +++
 clang/lib/Format/UnwrappedLineParser.cpp|  6 +--
 clang/lib/Parse/ParseExpr.cpp   |  2 +-
 clang/lib/Parse/ParseObjc.cpp   |  2 +-
 clang/lib/Sema/SemaDecl.cpp | 48 +
 9 files changed, 62 insertions(+), 95 deletions(-)

diff --git a/clang/include/clang/Basic/IdentifierTable.h 
b/clang/include/clang/Basic/IdentifierTable.h
index 1ac182d4fce26f6..2c979e438e81bb3 100644
--- a/clang/include/clang/Basic/IdentifierTable.h
+++ b/clang/include/clang/Basic/IdentifierTable.h
@@ -427,6 +427,10 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
   /// language.
   bool isCPlusPlusKeyword(const LangOptions &LangOpts) const;
 
+  /// Return true if this token is a simple type specifier
+  /// in the specified language.
+  bool isSimpleTypeSpecifier(const LangOptions &LangOpts) const;
+
   /// Get and set FETokenInfo. The language front-end is allowed to associate
   /// arbitrary metadata with this token.
   void *getFETokenInfo() const { return FETokenInfo; }
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 0db39333b0ee347..bc1fd19b5c6de7b 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2636,7 +2636,7 @@ class Sema final {
 
   void DiagnoseUseOfUnimplementedSelectors();
 
-  bool isSimpleTypeSpecifier(tok::TokenKind Kind) const;
+  bool isSimpleTypeSpecifier(const IdentifierInfo &II) const;
 
   ParsedType getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
  Scope *S, CXXScopeSpec *SS = nullptr,
diff --git a/clang/lib/Basic/IdentifierTable.cpp 
b/clang/lib/Basic/IdentifierTable.cpp
index d0d8316385b452f..78c783cdff6b5ea 100644
--- a/clang/lib/Basic/IdentifierTable.cpp
+++ b/clang/lib/Basic/IdentifierTable.cpp
@@ -419,6 +419,45 @@ StringRef IdentifierInfo::deuglifiedName() const {
   return Name;
 }
 
+/// Determine whether the token kind starts a simple-type-specifier.
+bool IdentifierInfo::isSimpleTypeSpecifier(const LangOptions &LangOpts) const {
+  auto Kind = getTokenID();
+
+  switch (Kind) {
+  case tok::kw_short:
+  case tok::kw_long:
+  case tok::kw___int64:
+  case tok::kw___int128:
+  case tok::kw_signed:
+  case tok::kw_unsigned:
+  case tok::kw_void:
+  case tok::kw_char:
+  case tok::kw_int:
+  case tok::kw_half:
+  case tok::kw_float:
+  case tok::kw_double:
+  case tok::kw___bf16:
+  case tok::kw__Float16:
+  case tok::kw___float128:
+  case tok::kw_wchar_t:
+  case tok::kw_bool:
+  case tok::kw___underlying_type:
+  case tok::kw___auto_type:
+  case tok::kw__Bool:
+  case tok::annot_typename:
+  case tok::kw_char16_t:
+  case tok::kw_char32_t:
+  case tok::kw_typeof:
+  case tok::annot_decltype:
+  case tok::kw_decltype:
+  case tok::kw_char8_t:
+return isKeyword(LangOpts);
+
+  default:
+return false;
+  }
+}
+
 tok::PPKeywordKind IdentifierInfo::getPPKeywordID() const {
   // We use a perfect hash function here involving the length of the keyword,
   // the first and third character.  For preprocessor ID's there are no
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index b791c5a26bbe3ab..70e997e179a8ccd 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -34,41 +34,9 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
-// FIXME: This is copy&pasted from Sema. Put it in a common place and remove
-// duplication.
-bool FormatToken::isSimpleTypeSpecifier() const {
-  switch (Tok.getKind()) {
-  case tok::kw_short:
-  case tok::kw_long:
-  case tok::kw___int64:
-  case tok::kw___int128:
-  case tok::kw_signed:
-  case tok::kw_unsigned:
-  case tok::kw_void:
-  case tok::kw_char:
-  case tok::kw_int:
-  case tok::kw_half:
-  case tok::kw_float:
-  case tok::kw_double:
-  case tok::kw___bf16:
-  case tok::kw__Float16:
-  case tok::kw___float128:
-  case tok::kw___ib

[clang] [clang] Improved isSimpleTypeSpecifier (PR #79037)

2024-01-22 Thread Carl Peto via cfe-commits

https://github.com/carlos4242 created 
https://github.com/llvm/llvm-project/pull/79037

- 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

>From c3de96925ea288fa50e72b597428d3e47c2e4595 Mon Sep 17 00:00:00 2001
From: Carl Peto 
Date: Mon, 22 Jan 2024 18:52:46 +
Subject: [PATCH] [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

---
 clang/include/clang/Basic/IdentifierTable.h |  4 ++
 clang/include/clang/Sema/Sema.h |  2 +-
 clang/lib/Basic/IdentifierTable.cpp | 39 +
 clang/lib/Parse/ParseExpr.cpp   |  2 +-
 clang/lib/Parse/ParseObjc.cpp   |  2 +-
 clang/lib/Sema/SemaDecl.cpp | 48 +
 6 files changed, 48 insertions(+), 49 deletions(-)

diff --git a/clang/include/clang/Basic/IdentifierTable.h 
b/clang/include/clang/Basic/IdentifierTable.h
index 1ac182d4fce26f6..2c979e438e81bb3 100644
--- a/clang/include/clang/Basic/IdentifierTable.h
+++ b/clang/include/clang/Basic/IdentifierTable.h
@@ -427,6 +427,10 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
   /// language.
   bool isCPlusPlusKeyword(const LangOptions &LangOpts) const;
 
+  /// Return true if this token is a simple type specifier
+  /// in the specified language.
+  bool isSimpleTypeSpecifier(const LangOptions &LangOpts) const;
+
   /// Get and set FETokenInfo. The language front-end is allowed to associate
   /// arbitrary metadata with this token.
   void *getFETokenInfo() const { return FETokenInfo; }
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 0db39333b0ee347..bc1fd19b5c6de7b 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2636,7 +2636,7 @@ class Sema final {
 
   void DiagnoseUseOfUnimplementedSelectors();
 
-  bool isSimpleTypeSpecifier(tok::TokenKind Kind) const;
+  bool isSimpleTypeSpecifier(const IdentifierInfo &II) const;
 
   ParsedType getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
  Scope *S, CXXScopeSpec *SS = nullptr,
diff --git a/clang/lib/Basic/IdentifierTable.cpp 
b/clang/lib/Basic/IdentifierTable.cpp
index d0d8316385b452f..78c783cdff6b5ea 100644
--- a/clang/lib/Basic/IdentifierTable.cpp
+++ b/clang/lib/Basic/IdentifierTable.cpp
@@ -419,6 +419,45 @@ StringRef IdentifierInfo::deuglifiedName() const {
   return Name;
 }
 
+/// Determine whether the token kind starts a simple-type-specifier.
+bool IdentifierInfo::isSimpleTypeSpecifier(const LangOptions &LangOpts) const {
+  auto Kind = getTokenID();
+
+  switch (Kind) {
+  case tok::kw_short:
+  case tok::kw_long:
+  case tok::kw___int64:
+  case tok::kw___int128:
+  case tok::kw_signed:
+  case tok::kw_unsigned:
+  case tok::kw_void:
+  case tok::kw_char:
+  case tok::kw_int:
+  case tok::kw_half:
+  case tok::kw_float:
+  case tok::kw_double:
+  case tok::kw___bf16:
+  case tok::kw__Float16:
+  case tok::kw___float128:
+  case tok::kw_wchar_t:
+  case tok::kw_bool:
+  case tok::kw___underlying_type:
+  case tok::kw___auto_type:
+  case tok::kw__Bool:
+  case tok::annot_typename:
+  case tok::kw_char16_t:
+  case tok::kw_char32_t:
+  case tok::kw_typeof:
+  case tok::annot_decltype:
+  case tok::kw_decltype:
+  case tok::kw_char8_t:
+return isKeyword(LangOpts);
+
+  default:
+return false;
+  }
+}
+
 tok::PPKeywordKind IdentifierInfo::getPPKeywordID() const {
   // We use a perfect hash function here involving the length of the keyword,
   // the first and third character.  For preprocessor ID's there are no
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index e862856a08ca117..7e6f59c2f66b151 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -1597,7 +1597,7 @@ ExprResult Parser::ParseCastExpression(CastParseKind 
ParseKind,
   if (TryAnnotateTypeOrScopeToken())
 return ExprError();
 
-  if (!Actions.isSimpleTypeSpecifier(Tok.getKind()))
+  if (!Tok.getIdentifierInfo() || 
!Actions.isSimpleTypeSpecifier(*Tok.getIdentifierInfo()))
 // 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 849fd1ac95a442e..58e5bc4a42b5f17 100644
--- a/clang/lib/Parse/Par

[clang] [clang] Improved isSimpleTypeSpecifier (PR #79037)

2024-01-22 Thread Carl Peto via cfe-commits

https://github.com/carlos4242 updated 
https://github.com/llvm/llvm-project/pull/79037

>From 61a06b77e8e6f2b5c5a9a2aa0b7f46260545f5b4 Mon Sep 17 00:00:00 2001
From: Carl Peto 
Date: Mon, 22 Jan 2024 18:52:46 +
Subject: [PATCH] [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

---
 clang/include/clang/Basic/IdentifierTable.h |  4 ++
 clang/include/clang/Sema/Sema.h |  2 +-
 clang/lib/Basic/IdentifierTable.cpp | 39 +
 clang/lib/Parse/ParseExpr.cpp   |  3 +-
 clang/lib/Parse/ParseObjc.cpp   |  3 +-
 clang/lib/Sema/SemaDecl.cpp | 48 +
 6 files changed, 50 insertions(+), 49 deletions(-)

diff --git a/clang/include/clang/Basic/IdentifierTable.h 
b/clang/include/clang/Basic/IdentifierTable.h
index 1ac182d4fce26f..2c979e438e81bb 100644
--- a/clang/include/clang/Basic/IdentifierTable.h
+++ b/clang/include/clang/Basic/IdentifierTable.h
@@ -427,6 +427,10 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
   /// language.
   bool isCPlusPlusKeyword(const LangOptions &LangOpts) const;
 
+  /// Return true if this token is a simple type specifier
+  /// in the specified language.
+  bool isSimpleTypeSpecifier(const LangOptions &LangOpts) const;
+
   /// Get and set FETokenInfo. The language front-end is allowed to associate
   /// arbitrary metadata with this token.
   void *getFETokenInfo() const { return FETokenInfo; }
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 0db39333b0ee34..bc1fd19b5c6de7 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2636,7 +2636,7 @@ class Sema final {
 
   void DiagnoseUseOfUnimplementedSelectors();
 
-  bool isSimpleTypeSpecifier(tok::TokenKind Kind) const;
+  bool isSimpleTypeSpecifier(const IdentifierInfo &II) const;
 
   ParsedType getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
  Scope *S, CXXScopeSpec *SS = nullptr,
diff --git a/clang/lib/Basic/IdentifierTable.cpp 
b/clang/lib/Basic/IdentifierTable.cpp
index d0d8316385b452..78c783cdff6b5e 100644
--- a/clang/lib/Basic/IdentifierTable.cpp
+++ b/clang/lib/Basic/IdentifierTable.cpp
@@ -419,6 +419,45 @@ StringRef IdentifierInfo::deuglifiedName() const {
   return Name;
 }
 
+/// Determine whether the token kind starts a simple-type-specifier.
+bool IdentifierInfo::isSimpleTypeSpecifier(const LangOptions &LangOpts) const {
+  auto Kind = getTokenID();
+
+  switch (Kind) {
+  case tok::kw_short:
+  case tok::kw_long:
+  case tok::kw___int64:
+  case tok::kw___int128:
+  case tok::kw_signed:
+  case tok::kw_unsigned:
+  case tok::kw_void:
+  case tok::kw_char:
+  case tok::kw_int:
+  case tok::kw_half:
+  case tok::kw_float:
+  case tok::kw_double:
+  case tok::kw___bf16:
+  case tok::kw__Float16:
+  case tok::kw___float128:
+  case tok::kw_wchar_t:
+  case tok::kw_bool:
+  case tok::kw___underlying_type:
+  case tok::kw___auto_type:
+  case tok::kw__Bool:
+  case tok::annot_typename:
+  case tok::kw_char16_t:
+  case tok::kw_char32_t:
+  case tok::kw_typeof:
+  case tok::annot_decltype:
+  case tok::kw_decltype:
+  case tok::kw_char8_t:
+return isKeyword(LangOpts);
+
+  default:
+return false;
+  }
+}
+
 tok::PPKeywordKind IdentifierInfo::getPPKeywordID() const {
   // We use a perfect hash function here involving the length of the keyword,
   // the first and third character.  For preprocessor ID's there are no
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index e862856a08ca11..8f9f918bf544fd 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -1597,7 +1597,8 @@ ExprResult Parser::ParseCastExpression(CastParseKind 
ParseKind,
   if (TryAnnotateTypeOrScopeToken())
 return ExprError();
 
-  if (!Actions.isSimpleTypeSpecifier(Tok.getKind()))
+  if (!Tok.getIdentifierInfo() ||
+  !Actions.isSimpleTypeSpecifier(*Tok.getIdentifierInfo()))
 // 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 849fd1ac95a442..5565770610c491 100644
--- a/clang/lib/Parse/ParseObjc.cpp
+++ b/clang/lib/Parse/ParseObjc.cpp
@@ -2971,7 +2971,8 @@ bool Parser::ParseObjCXXMessageReceiver(bool &IsExpr, 
void *&TypeOrExpr) {
   tok::annot_cxxscope))
 TryAnnotateTypeOrScopeToken();
 
-  if (!Actions.isSimpleTypeSpecifier(Tok.getKind())) {
+  if (!Tok.getIdentifierInfo() ||
+  !Actions.isSimpleTypeSpecifier(*Tok.getIdentifierInfo()

[clang] [clang] Improved isSimpleTypeSpecifier (PR #79037)

2024-01-22 Thread Carl Peto via cfe-commits

carlos4242 wrote:

@owenca ... is this better for you?

https://github.com/llvm/llvm-project/pull/79037
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits