[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-06-24 Thread Mike Rice via cfe-commits


@@ -1117,6 +1118,31 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   if (isImaginary) break;   // Cannot be repeated.
   isImaginary = true;
   continue;  // Success.
+case '_':
+  if (isFPConstant)
+break; // Invalid for floats
+  if (HasSize)
+break;
+  if (DoubleUnderscore)
+break; // Cannot be repeated.

mikerice1969 wrote:

Thanks for the comments. Submitted 
https://github.com/llvm/llvm-project/pull/96579

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-06-07 Thread via cfe-commits


@@ -1117,6 +1118,31 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   if (isImaginary) break;   // Cannot be repeated.
   isImaginary = true;
   continue;  // Success.
+case '_':
+  if (isFPConstant)
+break; // Invalid for floats
+  if (HasSize)
+break;
+  if (DoubleUnderscore)
+break; // Cannot be repeated.

Sirraide wrote:

> I'd definitely prefer not to have this be forgotten if we add a second double 
> underscore literal suffix

And yeah, agreed.

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-06-07 Thread via cfe-commits


@@ -1117,6 +1118,31 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   if (isImaginary) break;   // Cannot be repeated.
   isImaginary = true;
   continue;  // Success.
+case '_':
+  if (isFPConstant)
+break; // Invalid for floats
+  if (HasSize)
+break;
+  if (DoubleUnderscore)
+break; // Cannot be repeated.

Sirraide wrote:

An assertion would also make sense yeah.

> whoever wants to do the work

(For the record, I’m busy refactoring AST visitors so not me)

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-06-07 Thread Erich Keane via cfe-commits


@@ -1117,6 +1118,31 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   if (isImaginary) break;   // Cannot be repeated.
   isImaginary = true;
   continue;  // Success.
+case '_':
+  if (isFPConstant)
+break; // Invalid for floats
+  if (HasSize)
+break;
+  if (DoubleUnderscore)
+break; // Cannot be repeated.

erichkeane wrote:

Hmm.. I'd definitely prefer not to have this be forgotten if we add a second 
double underscore literal suffix, but presumably there is something we could do 
to make it not active code.  Perhaps we could replace it with a 
`assert(!DoubleUnderscore && "Doubleunderscore should be handled like above if 
we ever get a suffix that could hit this")`

WDYT?  I don't have the ability to do so, but just a suggestion and a 'patches 
welcome' to whoever wants to do the work (@js234 @mikerice1969 @Sirraide ).

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-06-07 Thread via cfe-commits


@@ -1117,6 +1118,31 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   if (isImaginary) break;   // Cannot be repeated.
   isImaginary = true;
   continue;  // Success.
+case '_':
+  if (isFPConstant)
+break; // Invalid for floats
+  if (HasSize)
+break;
+  if (DoubleUnderscore)
+break; // Cannot be repeated.

Sirraide wrote:

This is presumably because there currently is only one suffix that uses the 
`DoubleUnderscore` flag, so the other flags that also get set when `__wb` is 
parsed (e.g. `HasSize`) would be enough to disallow repetition here, from what 
I can tell. I’d still keep `DoubleUnderscore` in case we decide to add more 
literal suffixes that contain double underscores.

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-06-07 Thread Mike Rice via cfe-commits


@@ -1117,6 +1118,31 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   if (isImaginary) break;   // Cannot be repeated.
   isImaginary = true;
   continue;  // Success.
+case '_':
+  if (isFPConstant)
+break; // Invalid for floats
+  if (HasSize)
+break;
+  if (DoubleUnderscore)
+break; // Cannot be repeated.

mikerice1969 wrote:

Hi @js324. our static verifier is reporting this 'break' as dead code saying 
that it will always be false. I removed all references to DoubleUnderscore and 
ran the lit tests and there are no fails. Do you have a test case in mind that 
exercises this condition? If so we should add a test for it. If not we can 
simplify this code and remove DoubleUnderscore. What do you think?

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-04-22 Thread via cfe-commits

github-actions[bot] wrote:



@js324 Congratulations on having your first Pull Request (PR) merged into the 
LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested
by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with 
a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself.
This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-04-22 Thread Aaron Ballman via cfe-commits

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-04-22 Thread via cfe-commits

https://github.com/js324 updated https://github.com/llvm/llvm-project/pull/86586

>From c822eaf87526567825e9c4403ae9f01dd4ff58a3 Mon Sep 17 00:00:00 2001
From: Jin S 
Date: Mon, 25 Mar 2024 17:19:41 -0400
Subject: [PATCH 1/2] [BitInt] Expose a _BitInt literal suffix in C++

---
 clang/docs/ReleaseNotes.rst   |   1 +
 .../clang/Basic/DiagnosticCommonKinds.td  |   3 +
 clang/include/clang/Basic/DiagnosticGroups.td |   2 +
 .../clang/Basic/DiagnosticParseKinds.td   |   2 +-
 clang/include/clang/Lex/LiteralSupport.h  |   5 +-
 clang/lib/Lex/LiteralSupport.cpp  |  36 +++-
 clang/lib/Lex/PPExpressions.cpp   |   8 +-
 clang/lib/Sema/SemaExpr.cpp   |  12 +-
 clang/test/AST/bitint-suffix.cpp  |  32 
 clang/test/Lexer/bitint-constants-compat.c|  11 +-
 clang/test/Lexer/bitint-constants.cpp | 178 ++
 11 files changed, 274 insertions(+), 16 deletions(-)
 create mode 100644 clang/test/AST/bitint-suffix.cpp
 create mode 100644 clang/test/Lexer/bitint-constants.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7fbe2fec6ca065..d40c86a15ac2da 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -88,6 +88,7 @@ sections with improvements to Clang's support for those 
languages.
 
 C++ Language Changes
 
+- Implemented ``_BitInt`` literal suffixes ``__wb`` or ``__WB`` as a Clang 
extension with ``unsigned`` modifiers also allowed. (#GH85223).
 
 C++20 Feature Support
 ^
diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index a52bf62e24202c..0738f43ca555c8 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -234,6 +234,9 @@ def err_cxx23_size_t_suffix: Error<
 def err_size_t_literal_too_large: Error<
   "%select{signed |}0'size_t' literal is out of range of possible "
   "%select{signed |}0'size_t' values">;
+def ext_cxx_bitint_suffix : Extension<
+  "'_BitInt' suffix for literals is a Clang extension">,
+  InGroup;
 def ext_c23_bitint_suffix : ExtWarn<
   "'_BitInt' suffix for literals is a C23 extension">,
   InGroup;
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 44035e2fd16f2e..37f56ed6289d27 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1516,3 +1516,5 @@ def UnsafeBufferUsage : DiagGroup<"unsafe-buffer-usage", 
[UnsafeBufferUsageInCon
 // Warnings and notes InstallAPI verification.
 def InstallAPIViolation : DiagGroup<"installapi-violation">;
 
+// Warnings related to _BitInt extension
+def BitIntExtension : DiagGroup<"bit-int-extension">;
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 46a44418a3153b..6759f923564adf 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1646,7 +1646,7 @@ def warn_ext_int_deprecated : Warning<
   "'_ExtInt' is deprecated; use '_BitInt' instead">, InGroup;
 def ext_bit_int : Extension<
   "'_BitInt' in %select{C17 and earlier|C++}0 is a Clang extension">,
-  InGroup>;
+  InGroup;
 } // end of Parse Issue category.
 
 let CategoryName = "Modules Issue" in {
diff --git a/clang/include/clang/Lex/LiteralSupport.h 
b/clang/include/clang/Lex/LiteralSupport.h
index 643ddbdad8c87d..e7c3aaae9fc35e 100644
--- a/clang/include/clang/Lex/LiteralSupport.h
+++ b/clang/include/clang/Lex/LiteralSupport.h
@@ -80,7 +80,10 @@ class NumericLiteralParser {
   bool isFloat128 : 1;  // 1.0q
   bool isFract : 1; // 1.0hr/r/lr/uhr/ur/ulr
   bool isAccum : 1; // 1.0hk/k/lk/uhk/uk/ulk
-  bool isBitInt : 1;// 1wb, 1uwb (C23)
+  // clang-format off
+  bool isBitInt : 1;// 1wb, 1uwb (C23) or 1__wb, 1__uwb (Clang 
extension in C++
+// mode)
+  // clang-format on
   uint8_t MicrosoftInteger; // Microsoft suffix extension i8, i16, i32, or i64.
 
 
diff --git a/clang/lib/Lex/LiteralSupport.cpp b/clang/lib/Lex/LiteralSupport.cpp
index 438c6d772e6e04..9c0cbea5052cb2 100644
--- a/clang/lib/Lex/LiteralSupport.cpp
+++ b/clang/lib/Lex/LiteralSupport.cpp
@@ -974,6 +974,7 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   bool isFixedPointConstant = isFixedPointLiteral();
   bool isFPConstant = isFloatingLiteral();
   bool HasSize = false;
+  bool DoubleUnderscore = false;
 
   // Loop over all of the characters of the suffix.  If we see something bad,
   // we break out of the loop.
@@ -1117,6 +1118,31 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   if (isImaginary) break;   // Cannot be repeated.
   isImaginary = true;
   continue;  // Success.
+case '_':
+  if (isFPConstant)
+

[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-04-22 Thread Erich Keane via cfe-commits

erichkeane wrote:

At least the windows failure seems completely unrelated, it is a 'flang' build 
failure, likely caused by you getting 'unlucky' and the build being broken at 
the time.  You DO have a conflict to resolve, so perhaps doing that will get 
you back to green.

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-04-22 Thread via cfe-commits

js324 wrote:

Any insight on why the latest commit is failing? Is it just because of the 
clang-format change?

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-04-19 Thread via cfe-commits

https://github.com/js324 updated https://github.com/llvm/llvm-project/pull/86586

>From c822eaf87526567825e9c4403ae9f01dd4ff58a3 Mon Sep 17 00:00:00 2001
From: Jin S 
Date: Mon, 25 Mar 2024 17:19:41 -0400
Subject: [PATCH 1/2] [BitInt] Expose a _BitInt literal suffix in C++

---
 clang/docs/ReleaseNotes.rst   |   1 +
 .../clang/Basic/DiagnosticCommonKinds.td  |   3 +
 clang/include/clang/Basic/DiagnosticGroups.td |   2 +
 .../clang/Basic/DiagnosticParseKinds.td   |   2 +-
 clang/include/clang/Lex/LiteralSupport.h  |   5 +-
 clang/lib/Lex/LiteralSupport.cpp  |  36 +++-
 clang/lib/Lex/PPExpressions.cpp   |   8 +-
 clang/lib/Sema/SemaExpr.cpp   |  12 +-
 clang/test/AST/bitint-suffix.cpp  |  32 
 clang/test/Lexer/bitint-constants-compat.c|  11 +-
 clang/test/Lexer/bitint-constants.cpp | 178 ++
 11 files changed, 274 insertions(+), 16 deletions(-)
 create mode 100644 clang/test/AST/bitint-suffix.cpp
 create mode 100644 clang/test/Lexer/bitint-constants.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7fbe2fec6ca065..d40c86a15ac2da 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -88,6 +88,7 @@ sections with improvements to Clang's support for those 
languages.
 
 C++ Language Changes
 
+- Implemented ``_BitInt`` literal suffixes ``__wb`` or ``__WB`` as a Clang 
extension with ``unsigned`` modifiers also allowed. (#GH85223).
 
 C++20 Feature Support
 ^
diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index a52bf62e24202c..0738f43ca555c8 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -234,6 +234,9 @@ def err_cxx23_size_t_suffix: Error<
 def err_size_t_literal_too_large: Error<
   "%select{signed |}0'size_t' literal is out of range of possible "
   "%select{signed |}0'size_t' values">;
+def ext_cxx_bitint_suffix : Extension<
+  "'_BitInt' suffix for literals is a Clang extension">,
+  InGroup;
 def ext_c23_bitint_suffix : ExtWarn<
   "'_BitInt' suffix for literals is a C23 extension">,
   InGroup;
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 44035e2fd16f2e..37f56ed6289d27 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1516,3 +1516,5 @@ def UnsafeBufferUsage : DiagGroup<"unsafe-buffer-usage", 
[UnsafeBufferUsageInCon
 // Warnings and notes InstallAPI verification.
 def InstallAPIViolation : DiagGroup<"installapi-violation">;
 
+// Warnings related to _BitInt extension
+def BitIntExtension : DiagGroup<"bit-int-extension">;
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 46a44418a3153b..6759f923564adf 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1646,7 +1646,7 @@ def warn_ext_int_deprecated : Warning<
   "'_ExtInt' is deprecated; use '_BitInt' instead">, InGroup;
 def ext_bit_int : Extension<
   "'_BitInt' in %select{C17 and earlier|C++}0 is a Clang extension">,
-  InGroup>;
+  InGroup;
 } // end of Parse Issue category.
 
 let CategoryName = "Modules Issue" in {
diff --git a/clang/include/clang/Lex/LiteralSupport.h 
b/clang/include/clang/Lex/LiteralSupport.h
index 643ddbdad8c87d..e7c3aaae9fc35e 100644
--- a/clang/include/clang/Lex/LiteralSupport.h
+++ b/clang/include/clang/Lex/LiteralSupport.h
@@ -80,7 +80,10 @@ class NumericLiteralParser {
   bool isFloat128 : 1;  // 1.0q
   bool isFract : 1; // 1.0hr/r/lr/uhr/ur/ulr
   bool isAccum : 1; // 1.0hk/k/lk/uhk/uk/ulk
-  bool isBitInt : 1;// 1wb, 1uwb (C23)
+  // clang-format off
+  bool isBitInt : 1;// 1wb, 1uwb (C23) or 1__wb, 1__uwb (Clang 
extension in C++
+// mode)
+  // clang-format on
   uint8_t MicrosoftInteger; // Microsoft suffix extension i8, i16, i32, or i64.
 
 
diff --git a/clang/lib/Lex/LiteralSupport.cpp b/clang/lib/Lex/LiteralSupport.cpp
index 438c6d772e6e04..9c0cbea5052cb2 100644
--- a/clang/lib/Lex/LiteralSupport.cpp
+++ b/clang/lib/Lex/LiteralSupport.cpp
@@ -974,6 +974,7 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   bool isFixedPointConstant = isFixedPointLiteral();
   bool isFPConstant = isFloatingLiteral();
   bool HasSize = false;
+  bool DoubleUnderscore = false;
 
   // Loop over all of the characters of the suffix.  If we see something bad,
   // we break out of the loop.
@@ -1117,6 +1118,31 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   if (isImaginary) break;   // Cannot be repeated.
   isImaginary = true;
   continue;  // Success.
+case '_':
+  if (isFPConstant)
+

[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-04-18 Thread Erich Keane via cfe-commits

https://github.com/erichkeane approved this pull request.

This is fine to me, I have some concerns about the out-of-bounds reads on the 
NumericLIteralParser, but if @cor3ntin and you have done the work to make sure 
it is ok, than I am ok with it.

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-04-18 Thread Aaron Ballman via cfe-commits


@@ -80,7 +80,10 @@ class NumericLiteralParser {
   bool isFloat128 : 1;  // 1.0q
   bool isFract : 1; // 1.0hr/r/lr/uhr/ur/ulr
   bool isAccum : 1; // 1.0hk/k/lk/uhk/uk/ulk
-  bool isBitInt : 1;// 1wb, 1uwb (C23)
+  // clang-format off
+  bool isBitInt : 1;// 1wb, 1uwb (C23) or 1__wb, 1__uwb (Clang 
extension in C++
+// mode)
+  // clang-format on

AaronBallman wrote:

```suggestion
  bool isBitInt : 1;// 1wb, 1uwb (C23) or 1__wb, 1__uwb (Clang 
extension in C++
// mode)
```
It's fine for the patch to not be clang-format clean instead of cluttering 
source with clang format comments.

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-04-18 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman approved this pull request.

Aside from a nit with clang-format commenting, LGTM! @Sirraide are you happy 
with the state of things (you've got a "request changes" for your review). 
@erichkeane are you happy as well?

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-04-18 Thread Aaron Ballman via cfe-commits

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-04-16 Thread via cfe-commits

https://github.com/js324 updated https://github.com/llvm/llvm-project/pull/86586

>From c822eaf87526567825e9c4403ae9f01dd4ff58a3 Mon Sep 17 00:00:00 2001
From: Jin S 
Date: Mon, 25 Mar 2024 17:19:41 -0400
Subject: [PATCH] [BitInt] Expose a _BitInt literal suffix in C++

---
 clang/docs/ReleaseNotes.rst   |   1 +
 .../clang/Basic/DiagnosticCommonKinds.td  |   3 +
 clang/include/clang/Basic/DiagnosticGroups.td |   2 +
 .../clang/Basic/DiagnosticParseKinds.td   |   2 +-
 clang/include/clang/Lex/LiteralSupport.h  |   5 +-
 clang/lib/Lex/LiteralSupport.cpp  |  36 +++-
 clang/lib/Lex/PPExpressions.cpp   |   8 +-
 clang/lib/Sema/SemaExpr.cpp   |  12 +-
 clang/test/AST/bitint-suffix.cpp  |  32 
 clang/test/Lexer/bitint-constants-compat.c|  11 +-
 clang/test/Lexer/bitint-constants.cpp | 178 ++
 11 files changed, 274 insertions(+), 16 deletions(-)
 create mode 100644 clang/test/AST/bitint-suffix.cpp
 create mode 100644 clang/test/Lexer/bitint-constants.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7fbe2fec6ca065..d40c86a15ac2da 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -88,6 +88,7 @@ sections with improvements to Clang's support for those 
languages.
 
 C++ Language Changes
 
+- Implemented ``_BitInt`` literal suffixes ``__wb`` or ``__WB`` as a Clang 
extension with ``unsigned`` modifiers also allowed. (#GH85223).
 
 C++20 Feature Support
 ^
diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index a52bf62e24202c..0738f43ca555c8 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -234,6 +234,9 @@ def err_cxx23_size_t_suffix: Error<
 def err_size_t_literal_too_large: Error<
   "%select{signed |}0'size_t' literal is out of range of possible "
   "%select{signed |}0'size_t' values">;
+def ext_cxx_bitint_suffix : Extension<
+  "'_BitInt' suffix for literals is a Clang extension">,
+  InGroup;
 def ext_c23_bitint_suffix : ExtWarn<
   "'_BitInt' suffix for literals is a C23 extension">,
   InGroup;
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 44035e2fd16f2e..37f56ed6289d27 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1516,3 +1516,5 @@ def UnsafeBufferUsage : DiagGroup<"unsafe-buffer-usage", 
[UnsafeBufferUsageInCon
 // Warnings and notes InstallAPI verification.
 def InstallAPIViolation : DiagGroup<"installapi-violation">;
 
+// Warnings related to _BitInt extension
+def BitIntExtension : DiagGroup<"bit-int-extension">;
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 46a44418a3153b..6759f923564adf 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1646,7 +1646,7 @@ def warn_ext_int_deprecated : Warning<
   "'_ExtInt' is deprecated; use '_BitInt' instead">, InGroup;
 def ext_bit_int : Extension<
   "'_BitInt' in %select{C17 and earlier|C++}0 is a Clang extension">,
-  InGroup>;
+  InGroup;
 } // end of Parse Issue category.
 
 let CategoryName = "Modules Issue" in {
diff --git a/clang/include/clang/Lex/LiteralSupport.h 
b/clang/include/clang/Lex/LiteralSupport.h
index 643ddbdad8c87d..e7c3aaae9fc35e 100644
--- a/clang/include/clang/Lex/LiteralSupport.h
+++ b/clang/include/clang/Lex/LiteralSupport.h
@@ -80,7 +80,10 @@ class NumericLiteralParser {
   bool isFloat128 : 1;  // 1.0q
   bool isFract : 1; // 1.0hr/r/lr/uhr/ur/ulr
   bool isAccum : 1; // 1.0hk/k/lk/uhk/uk/ulk
-  bool isBitInt : 1;// 1wb, 1uwb (C23)
+  // clang-format off
+  bool isBitInt : 1;// 1wb, 1uwb (C23) or 1__wb, 1__uwb (Clang 
extension in C++
+// mode)
+  // clang-format on
   uint8_t MicrosoftInteger; // Microsoft suffix extension i8, i16, i32, or i64.
 
 
diff --git a/clang/lib/Lex/LiteralSupport.cpp b/clang/lib/Lex/LiteralSupport.cpp
index 438c6d772e6e04..9c0cbea5052cb2 100644
--- a/clang/lib/Lex/LiteralSupport.cpp
+++ b/clang/lib/Lex/LiteralSupport.cpp
@@ -974,6 +974,7 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   bool isFixedPointConstant = isFixedPointLiteral();
   bool isFPConstant = isFloatingLiteral();
   bool HasSize = false;
+  bool DoubleUnderscore = false;
 
   // Loop over all of the characters of the suffix.  If we see something bad,
   // we break out of the loop.
@@ -1117,6 +1118,31 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   if (isImaginary) break;   // Cannot be repeated.
   isImaginary = true;
   continue;  // Success.
+case '_':
+  if (isFPConstant)
+

[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-04-16 Thread via cfe-commits

https://github.com/js324 updated https://github.com/llvm/llvm-project/pull/86586

>From 1b0902aa9f8a07771f29fb21d7b4cdea9e966118 Mon Sep 17 00:00:00 2001
From: Jin S 
Date: Mon, 25 Mar 2024 17:19:41 -0400
Subject: [PATCH 1/2] [BitInt] Expose a _BitInt literal suffix in C++

---
 clang/docs/ReleaseNotes.rst   |   1 +
 .../clang/Basic/DiagnosticCommonKinds.td  |   3 +
 clang/include/clang/Basic/DiagnosticGroups.td |   2 +
 .../clang/Basic/DiagnosticParseKinds.td   |   2 +-
 clang/include/clang/Lex/LiteralSupport.h  |   3 +-
 clang/lib/Lex/LiteralSupport.cpp  |  31 ++-
 clang/lib/Lex/PPExpressions.cpp   |   8 +-
 clang/lib/Sema/SemaExpr.cpp   |  12 +-
 clang/test/AST/bitint-suffix.cpp  |  32 
 clang/test/Lexer/bitint-constants-compat.c|  11 +-
 clang/test/Lexer/bitint-constants.cpp | 177 ++
 11 files changed, 266 insertions(+), 16 deletions(-)
 create mode 100644 clang/test/AST/bitint-suffix.cpp
 create mode 100644 clang/test/Lexer/bitint-constants.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7fbe2fec6ca065..d40c86a15ac2da 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -88,6 +88,7 @@ sections with improvements to Clang's support for those 
languages.
 
 C++ Language Changes
 
+- Implemented ``_BitInt`` literal suffixes ``__wb`` or ``__WB`` as a Clang 
extension with ``unsigned`` modifiers also allowed. (#GH85223).
 
 C++20 Feature Support
 ^
diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index a52bf62e24202c..0738f43ca555c8 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -234,6 +234,9 @@ def err_cxx23_size_t_suffix: Error<
 def err_size_t_literal_too_large: Error<
   "%select{signed |}0'size_t' literal is out of range of possible "
   "%select{signed |}0'size_t' values">;
+def ext_cxx_bitint_suffix : Extension<
+  "'_BitInt' suffix for literals is a Clang extension">,
+  InGroup;
 def ext_c23_bitint_suffix : ExtWarn<
   "'_BitInt' suffix for literals is a C23 extension">,
   InGroup;
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 44035e2fd16f2e..37f56ed6289d27 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1516,3 +1516,5 @@ def UnsafeBufferUsage : DiagGroup<"unsafe-buffer-usage", 
[UnsafeBufferUsageInCon
 // Warnings and notes InstallAPI verification.
 def InstallAPIViolation : DiagGroup<"installapi-violation">;
 
+// Warnings related to _BitInt extension
+def BitIntExtension : DiagGroup<"bit-int-extension">;
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 46a44418a3153b..6759f923564adf 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1646,7 +1646,7 @@ def warn_ext_int_deprecated : Warning<
   "'_ExtInt' is deprecated; use '_BitInt' instead">, InGroup;
 def ext_bit_int : Extension<
   "'_BitInt' in %select{C17 and earlier|C++}0 is a Clang extension">,
-  InGroup>;
+  InGroup;
 } // end of Parse Issue category.
 
 let CategoryName = "Modules Issue" in {
diff --git a/clang/include/clang/Lex/LiteralSupport.h 
b/clang/include/clang/Lex/LiteralSupport.h
index 643ddbdad8c87d..e7a2ccc9bb0bb3 100644
--- a/clang/include/clang/Lex/LiteralSupport.h
+++ b/clang/include/clang/Lex/LiteralSupport.h
@@ -80,7 +80,8 @@ class NumericLiteralParser {
   bool isFloat128 : 1;  // 1.0q
   bool isFract : 1; // 1.0hr/r/lr/uhr/ur/ulr
   bool isAccum : 1; // 1.0hk/k/lk/uhk/uk/ulk
-  bool isBitInt : 1;// 1wb, 1uwb (C23)
+  bool isBitInt : 1; // 1wb, 1uwb (C23) or 1__wb, 1__uwb (Clang extension in 
C++
+ // mode)
   uint8_t MicrosoftInteger; // Microsoft suffix extension i8, i16, i32, or i64.
 
 
diff --git a/clang/lib/Lex/LiteralSupport.cpp b/clang/lib/Lex/LiteralSupport.cpp
index 438c6d772e6e04..01ff2e2df8465e 100644
--- a/clang/lib/Lex/LiteralSupport.cpp
+++ b/clang/lib/Lex/LiteralSupport.cpp
@@ -974,6 +974,7 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   bool isFixedPointConstant = isFixedPointLiteral();
   bool isFPConstant = isFloatingLiteral();
   bool HasSize = false;
+  bool PossibleBitInt = false;
 
   // Loop over all of the characters of the suffix.  If we see something bad,
   // we break out of the loop.
@@ -1117,6 +1118,26 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   if (isImaginary) break;   // Cannot be repeated.
   isImaginary = true;
   continue;  // Success.
+case '_':
+  if (isFPConstant)
+break; // Invalid for floats
+  if (HasSize)
+

[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-04-09 Thread Aaron Ballman via cfe-commits


@@ -1117,6 +1118,26 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   if (isImaginary) break;   // Cannot be repeated.
   isImaginary = true;
   continue;  // Success.
+case '_':
+  if (isFPConstant)
+break; // Invalid for floats
+  if (HasSize)
+break;
+  if (PossibleBitInt)
+break; // Cannot be repeated.
+  if (LangOpts.CPlusPlus && s + 1 < ThisTokEnd && s[1] == '_') {
+// Scan ahead to find possible rest of BitInt suffix
+for (const char *c = s; c != ThisTokEnd; ++c) {
+  if (*c == 'w' || *c == 'W') {

AaronBallman wrote:

We definitely should not allow `__iwb` because that puts the `i` suffix in the 
middle of the `__wb` suffix. However, because we accept `iwb` or `wbi` in C, I 
think it's reasonable to support `i__wb` or `__wbi` in C++: 
https://godbolt.org/z/nb9d9qWKK

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-04-09 Thread Aaron Ballman via cfe-commits


@@ -1127,9 +1148,9 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   // wb and WB are allowed, but a mixture of cases like Wb or wB is not. We
   // explicitly do not support the suffix in C++ as an extension because a
   // library-based UDL that resolves to a library type may be more
-  // appropriate there.
-  if (!LangOpts.CPlusPlus && ((s[0] == 'w' && s[1] == 'b') ||
-  (s[0] == 'W' && s[1] == 'B'))) {
+  // appropriate there. The same rules apply for __wb/__WB.
+  if ((!LangOpts.CPlusPlus || PossibleBitInt) &&
+  ((s[0] == 'w' && s[1] == 'b') || (s[0] == 'W' && s[1] == 'B'))) {

AaronBallman wrote:

I think @cor3ntin is asking for a change to ensure `s + 1 < ThisTokEnd`.

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-04-09 Thread via cfe-commits


@@ -1127,9 +1148,9 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   // wb and WB are allowed, but a mixture of cases like Wb or wB is not. We
   // explicitly do not support the suffix in C++ as an extension because a
   // library-based UDL that resolves to a library type may be more
-  // appropriate there.
-  if (!LangOpts.CPlusPlus && ((s[0] == 'w' && s[1] == 'b') ||
-  (s[0] == 'W' && s[1] == 'B'))) {
+  // appropriate there. The same rules apply for __wb/__WB.
+  if ((!LangOpts.CPlusPlus || PossibleBitInt) &&
+  ((s[0] == 'w' && s[1] == 'b') || (s[0] == 'W' && s[1] == 'B'))) {

js324 wrote:

Sorry a little confused here, are we keeping the `s + 1 < ThisTokEnd` checks or 
should we change them to `s < ThisTokEnd` to allow looking into `ThisTokEnd` 
(for example`s < ThisTokEnd && s[1] == '_'`)

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-04-09 Thread via cfe-commits


@@ -1117,6 +1118,26 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   if (isImaginary) break;   // Cannot be repeated.
   isImaginary = true;
   continue;  // Success.
+case '_':
+  if (isFPConstant)
+break; // Invalid for floats
+  if (HasSize)
+break;
+  if (PossibleBitInt)
+break; // Cannot be repeated.
+  if (LangOpts.CPlusPlus && s + 1 < ThisTokEnd && s[1] == '_') {
+// Scan ahead to find possible rest of BitInt suffix
+for (const char *c = s; c != ThisTokEnd; ++c) {
+  if (*c == 'w' || *c == 'W') {

js324 wrote:

Should we allow cases like __iwb or __wbj? Or do we only allow the unsigned 
modifier?

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-04-01 Thread Richard Smith via cfe-commits


@@ -1117,19 +1118,37 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   if (isImaginary) break;   // Cannot be repeated.
   isImaginary = true;
   continue;  // Success.
+case '_':
+  if (isFPConstant)
+break; // Invalid for floats
+  if (HasSize)
+break;
+  if (possibleBitInt)
+break; // Cannot be repeated.
+  if (LangOpts.CPlusPlus && s[1] == '_') {
+// Scan ahead to find possible rest of BitInt suffix
+for (const char *c = s; c != ThisTokEnd; ++c) {
+  if (*c == 'w' || *c == 'W') {
+possibleBitInt = true;
+++s;

zygoloid wrote:

FYI, per CWG1810 / [over.literal]/1, it's now IFNDR rather than UB:

> Some literal suffix identifiers are reserved for future standardization; see 
> [usrlit.suffix]. A declaration whose literal-operator-id uses such a literal 
> suffix identifier is ill-formed, no diagnostic required.

... but that doesn't make a difference here. (The "NDR" part is just to allow 
implementations to permit the standard library to declare these literal 
operators.)

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-04-01 Thread Erich Keane via cfe-commits


@@ -974,6 +974,7 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   bool isFixedPointConstant = isFixedPointLiteral();
   bool isFPConstant = isFloatingLiteral();
   bool HasSize = false;
+  bool PossibleBitInt = false;

erichkeane wrote:

I'd  want this generalized for all 'starts with two `_` cases.

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-04-01 Thread Erich Keane via cfe-commits


@@ -1117,6 +1118,26 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   if (isImaginary) break;   // Cannot be repeated.
   isImaginary = true;
   continue;  // Success.
+case '_':
+  if (isFPConstant)
+break; // Invalid for floats
+  if (HasSize)
+break;
+  if (PossibleBitInt)
+break; // Cannot be repeated.
+  if (LangOpts.CPlusPlus && s + 1 < ThisTokEnd && s[1] == '_') {
+// Scan ahead to find possible rest of BitInt suffix
+for (const char *c = s; c != ThisTokEnd; ++c) {
+  if (*c == 'w' || *c == 'W') {

erichkeane wrote:

I think we're probably better off consuming all of the __wb/__uwb here rather 
than falling through to the code on ~1151.

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-04-01 Thread Erich Keane via cfe-commits


@@ -80,7 +80,8 @@ class NumericLiteralParser {
   bool isFloat128 : 1;  // 1.0q
   bool isFract : 1; // 1.0hr/r/lr/uhr/ur/ulr
   bool isAccum : 1; // 1.0hk/k/lk/uhk/uk/ulk
-  bool isBitInt : 1;// 1wb, 1uwb (C23)
+  bool isBitInt : 1; // 1wb, 1uwb (C23) or 1__wb, 1__uwb (Clang extension in 
C++

erichkeane wrote:

please make the comments line up with the above, I know clang-format disagrees 
(and requires manual modification), but this makes a lot of sense with the way 
it is lined up.

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-03-29 Thread via cfe-commits


@@ -1127,9 +1148,9 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   // wb and WB are allowed, but a mixture of cases like Wb or wB is not. We
   // explicitly do not support the suffix in C++ as an extension because a
   // library-based UDL that resolves to a library type may be more
-  // appropriate there.
-  if (!LangOpts.CPlusPlus && ((s[0] == 'w' && s[1] == 'b') ||
-  (s[0] == 'W' && s[1] == 'B'))) {
+  // appropriate there. The same rules apply for __wb/__WB.
+  if ((!LangOpts.CPlusPlus || PossibleBitInt) &&
+  ((s[0] == 'w' && s[1] == 'b') || (s[0] == 'W' && s[1] == 'B'))) {

Sirraide wrote:

So it seems that the intention here really is that `NumericLiteralParser` 
should always be passed a null-terminated string.

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-03-29 Thread via cfe-commits

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-03-29 Thread via cfe-commits


@@ -1127,9 +1148,9 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   // wb and WB are allowed, but a mixture of cases like Wb or wB is not. We
   // explicitly do not support the suffix in C++ as an extension because a
   // library-based UDL that resolves to a library type may be more
-  // appropriate there.
-  if (!LangOpts.CPlusPlus && ((s[0] == 'w' && s[1] == 'b') ||
-  (s[0] == 'W' && s[1] == 'B'))) {
+  // appropriate there. The same rules apply for __wb/__WB.
+  if ((!LangOpts.CPlusPlus || PossibleBitInt) &&
+  ((s[0] == 'w' && s[1] == 'b') || (s[0] == 'W' && s[1] == 'B'))) {

Sirraide wrote:

In `Sema::ActOnNumericConstant()`:
>   // NumericLiteralParser wants to overread by one character.  Add padding to
  // the buffer in case the token is copied to the buffer.  If getSpelling()
  // returns a StringRef to the memory buffer, it should have a null char at
  // the EOF, so it is also safe.

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-03-29 Thread via cfe-commits


@@ -1127,9 +1148,9 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   // wb and WB are allowed, but a mixture of cases like Wb or wB is not. We
   // explicitly do not support the suffix in C++ as an extension because a
   // library-based UDL that resolves to a library type may be more
-  // appropriate there.
-  if (!LangOpts.CPlusPlus && ((s[0] == 'w' && s[1] == 'b') ||
-  (s[0] == 'W' && s[1] == 'B'))) {
+  // appropriate there. The same rules apply for __wb/__WB.
+  if ((!LangOpts.CPlusPlus || PossibleBitInt) &&
+  ((s[0] == 'w' && s[1] == 'b') || (s[0] == 'W' && s[1] == 'B'))) {

Sirraide wrote:

> But if we lex a string that isn't null terminated for some reason, we'd have 
> the overrun.

Iirc there was another comment somewhere that adressed this too; let me see if 
I can find it.

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-03-29 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman commented:

The changes LGTM but I'd like to give Corentin and Tom a chance to weigh in as 
lexer code owners (you may need to be patient as they were both in WG21 
meetings last week and are currently on vacation, so it may be later next week 
before we hear back).

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-03-29 Thread Aaron Ballman via cfe-commits


@@ -1127,9 +1148,9 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   // wb and WB are allowed, but a mixture of cases like Wb or wB is not. We
   // explicitly do not support the suffix in C++ as an extension because a
   // library-based UDL that resolves to a library type may be more
-  // appropriate there.
-  if (!LangOpts.CPlusPlus && ((s[0] == 'w' && s[1] == 'b') ||
-  (s[0] == 'W' && s[1] == 'B'))) {
+  // appropriate there. The same rules apply for __wb/__WB.
+  if ((!LangOpts.CPlusPlus || PossibleBitInt) &&
+  ((s[0] == 'w' && s[1] == 'b') || (s[0] == 'W' && s[1] == 'B'))) {

AaronBallman wrote:

I looked through the lexer and we might be okay here for normal lexing uses. 
When we lex, we grab all adjacent characters and digits:

https://github.com/llvm/llvm-project/blob/d3bc9cc99b3d45e1fb8d65a57e308e899439fe26/clang/lib/Lex/Lexer.cpp#L2035
https://github.com/llvm/llvm-project/blob/d3bc9cc99b3d45e1fb8d65a57e308e899439fe26/clang/include/clang/Basic/CharInfo.h#L169

So for a complete (ill-formed) TU like `#if 1w`, we get `1w\0` in the numeric 
literal parser. But if we lex a string that isn't null terminated for some 
reason, we'd have the overrun.

CC @cor3ntin @tahonermann for opinions on what we should do here, if anything. 
However, because this is existing behavior, I'd say let's move forward with 
your patch without changing this yet.

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-03-28 Thread via cfe-commits


@@ -1127,9 +1148,9 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   // wb and WB are allowed, but a mixture of cases like Wb or wB is not. We
   // explicitly do not support the suffix in C++ as an extension because a
   // library-based UDL that resolves to a library type may be more
-  // appropriate there.
-  if (!LangOpts.CPlusPlus && ((s[0] == 'w' && s[1] == 'b') ||
-  (s[0] == 'W' && s[1] == 'B'))) {
+  // appropriate there. The same rules apply for __wb/__WB.
+  if ((!LangOpts.CPlusPlus || PossibleBitInt) &&
+  ((s[0] == 'w' && s[1] == 'b') || (s[0] == 'W' && s[1] == 'B'))) {

js324 wrote:

Would the existing test cases of `1__w` and `1.0_` in `bitint-constants.cpp` be 
enough to test this and the similar above comment?

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-03-28 Thread via cfe-commits

https://github.com/js324 updated https://github.com/llvm/llvm-project/pull/86586

>From 1b0902aa9f8a07771f29fb21d7b4cdea9e966118 Mon Sep 17 00:00:00 2001
From: Jin S 
Date: Mon, 25 Mar 2024 17:19:41 -0400
Subject: [PATCH] [BitInt] Expose a _BitInt literal suffix in C++

---
 clang/docs/ReleaseNotes.rst   |   1 +
 .../clang/Basic/DiagnosticCommonKinds.td  |   3 +
 clang/include/clang/Basic/DiagnosticGroups.td |   2 +
 .../clang/Basic/DiagnosticParseKinds.td   |   2 +-
 clang/include/clang/Lex/LiteralSupport.h  |   3 +-
 clang/lib/Lex/LiteralSupport.cpp  |  31 ++-
 clang/lib/Lex/PPExpressions.cpp   |   8 +-
 clang/lib/Sema/SemaExpr.cpp   |  12 +-
 clang/test/AST/bitint-suffix.cpp  |  32 
 clang/test/Lexer/bitint-constants-compat.c|  11 +-
 clang/test/Lexer/bitint-constants.cpp | 177 ++
 11 files changed, 266 insertions(+), 16 deletions(-)
 create mode 100644 clang/test/AST/bitint-suffix.cpp
 create mode 100644 clang/test/Lexer/bitint-constants.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7fbe2fec6ca065..d40c86a15ac2da 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -88,6 +88,7 @@ sections with improvements to Clang's support for those 
languages.
 
 C++ Language Changes
 
+- Implemented ``_BitInt`` literal suffixes ``__wb`` or ``__WB`` as a Clang 
extension with ``unsigned`` modifiers also allowed. (#GH85223).
 
 C++20 Feature Support
 ^
diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index a52bf62e24202c..0738f43ca555c8 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -234,6 +234,9 @@ def err_cxx23_size_t_suffix: Error<
 def err_size_t_literal_too_large: Error<
   "%select{signed |}0'size_t' literal is out of range of possible "
   "%select{signed |}0'size_t' values">;
+def ext_cxx_bitint_suffix : Extension<
+  "'_BitInt' suffix for literals is a Clang extension">,
+  InGroup;
 def ext_c23_bitint_suffix : ExtWarn<
   "'_BitInt' suffix for literals is a C23 extension">,
   InGroup;
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 44035e2fd16f2e..37f56ed6289d27 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1516,3 +1516,5 @@ def UnsafeBufferUsage : DiagGroup<"unsafe-buffer-usage", 
[UnsafeBufferUsageInCon
 // Warnings and notes InstallAPI verification.
 def InstallAPIViolation : DiagGroup<"installapi-violation">;
 
+// Warnings related to _BitInt extension
+def BitIntExtension : DiagGroup<"bit-int-extension">;
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 46a44418a3153b..6759f923564adf 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1646,7 +1646,7 @@ def warn_ext_int_deprecated : Warning<
   "'_ExtInt' is deprecated; use '_BitInt' instead">, InGroup;
 def ext_bit_int : Extension<
   "'_BitInt' in %select{C17 and earlier|C++}0 is a Clang extension">,
-  InGroup>;
+  InGroup;
 } // end of Parse Issue category.
 
 let CategoryName = "Modules Issue" in {
diff --git a/clang/include/clang/Lex/LiteralSupport.h 
b/clang/include/clang/Lex/LiteralSupport.h
index 643ddbdad8c87d..e7a2ccc9bb0bb3 100644
--- a/clang/include/clang/Lex/LiteralSupport.h
+++ b/clang/include/clang/Lex/LiteralSupport.h
@@ -80,7 +80,8 @@ class NumericLiteralParser {
   bool isFloat128 : 1;  // 1.0q
   bool isFract : 1; // 1.0hr/r/lr/uhr/ur/ulr
   bool isAccum : 1; // 1.0hk/k/lk/uhk/uk/ulk
-  bool isBitInt : 1;// 1wb, 1uwb (C23)
+  bool isBitInt : 1; // 1wb, 1uwb (C23) or 1__wb, 1__uwb (Clang extension in 
C++
+ // mode)
   uint8_t MicrosoftInteger; // Microsoft suffix extension i8, i16, i32, or i64.
 
 
diff --git a/clang/lib/Lex/LiteralSupport.cpp b/clang/lib/Lex/LiteralSupport.cpp
index 438c6d772e6e04..01ff2e2df8465e 100644
--- a/clang/lib/Lex/LiteralSupport.cpp
+++ b/clang/lib/Lex/LiteralSupport.cpp
@@ -974,6 +974,7 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   bool isFixedPointConstant = isFixedPointLiteral();
   bool isFPConstant = isFloatingLiteral();
   bool HasSize = false;
+  bool PossibleBitInt = false;
 
   // Loop over all of the characters of the suffix.  If we see something bad,
   // we break out of the loop.
@@ -1117,6 +1118,26 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   if (isImaginary) break;   // Cannot be repeated.
   isImaginary = true;
   continue;  // Success.
+case '_':
+  if (isFPConstant)
+break; // Invalid for floats
+  if (HasSize)
+break;
+ 

[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-03-28 Thread via cfe-commits


@@ -1117,6 +1118,26 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   if (isImaginary) break;   // Cannot be repeated.
   isImaginary = true;
   continue;  // Success.
+case '_':
+  if (isFPConstant)
+break; // Invalid for floats
+  if (HasSize)
+break;
+  if (PossibleBitInt)
+break; // Cannot be repeated.
+  if (LangOpts.CPlusPlus && s[1] == '_') {

Sirraide wrote:

Ah, I see, makes sense.

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-03-28 Thread Aaron Ballman via cfe-commits


@@ -1117,6 +1118,26 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   if (isImaginary) break;   // Cannot be repeated.
   isImaginary = true;
   continue;  // Success.
+case '_':
+  if (isFPConstant)
+break; // Invalid for floats
+  if (HasSize)
+break;
+  if (PossibleBitInt)
+break; // Cannot be repeated.
+  if (LangOpts.CPlusPlus && s[1] == '_') {

AaronBallman wrote:

I think you might be remembering this comment:
```
  // This routine assumes that the range begin/end matches the regex for integer
  // and FP constants (specifically, the 'pp-number' regex), and assumes that
  // the byte at "*end" is both valid and not part of the regex.  Because of
  // this, it doesn't have to check for 'overscan' in various places.
  // Note: For HLSL, the end token is allowed to be '.' which would be in the
  // 'pp-number' regex. This is required to support vector swizzles on numeric
  // constants (i.e. 1.xx or 1.5f.rrr).
```
but I took that to be about pp-number and not the suffix (suffixes are not part 
of pp-number because suffixes are about types and the preprocessor is 
type-agnostic).

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-03-28 Thread via cfe-commits


@@ -1117,6 +1118,26 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   if (isImaginary) break;   // Cannot be repeated.
   isImaginary = true;
   continue;  // Success.
+case '_':
+  if (isFPConstant)
+break; // Invalid for floats
+  if (HasSize)
+break;
+  if (PossibleBitInt)
+break; // Cannot be repeated.
+  if (LangOpts.CPlusPlus && s[1] == '_') {

Sirraide wrote:

I recall reading somewhere that one character of overscan is allowed in 
`NumericLiteralParser`, but I’m not sure if that applies here.

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-03-28 Thread Aaron Ballman via cfe-commits


@@ -1127,9 +1148,9 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   // wb and WB are allowed, but a mixture of cases like Wb or wB is not. We
   // explicitly do not support the suffix in C++ as an extension because a
   // library-based UDL that resolves to a library type may be more
-  // appropriate there.
-  if (!LangOpts.CPlusPlus && ((s[0] == 'w' && s[1] == 'b') ||
-  (s[0] == 'W' && s[1] == 'B'))) {
+  // appropriate there. The same rules apply for __wb/__WB.
+  if ((!LangOpts.CPlusPlus || PossibleBitInt) &&
+  ((s[0] == 'w' && s[1] == 'b') || (s[0] == 'W' && s[1] == 'B'))) {

AaronBallman wrote:

I think there's an existing bug here when `s + 1 >= ThisTokEnd` that should be 
guarded for (and a test case added).

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-03-28 Thread Aaron Ballman via cfe-commits


@@ -1117,6 +1118,26 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   if (isImaginary) break;   // Cannot be repeated.
   isImaginary = true;
   continue;  // Success.
+case '_':
+  if (isFPConstant)
+break; // Invalid for floats
+  if (HasSize)
+break;
+  if (PossibleBitInt)
+break; // Cannot be repeated.
+  if (LangOpts.CPlusPlus && s[1] == '_') {

AaronBallman wrote:

This looks like it will read off the end of the buffer if `s + 1 >= 
ThisTokEnd`, so that should be guarded (and a test case added for that 
situation).

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-03-27 Thread via cfe-commits

https://github.com/js324 updated https://github.com/llvm/llvm-project/pull/86586

>From 3186b97752f6a6a9b065b5b63b78fc3025ed224b Mon Sep 17 00:00:00 2001
From: Jin S 
Date: Mon, 25 Mar 2024 17:19:41 -0400
Subject: [PATCH 1/2] [BitInt] Expose a _BitInt literal suffix in C++

---
 clang/docs/ReleaseNotes.rst   |   1 +
 .../clang/Basic/DiagnosticCommonKinds.td  |   3 +
 clang/include/clang/Basic/DiagnosticGroups.td |   2 +
 .../clang/Basic/DiagnosticParseKinds.td   |   2 +-
 clang/include/clang/Lex/LiteralSupport.h  |   3 +-
 clang/lib/Lex/LiteralSupport.cpp  |  31 ++-
 clang/lib/Lex/PPExpressions.cpp   |   8 +-
 clang/lib/Sema/SemaExpr.cpp   |  12 +-
 clang/test/AST/bitint-suffix.cpp  |  32 
 clang/test/Lexer/bitint-constants-compat.c|  11 +-
 clang/test/Lexer/bitint-constants.cpp | 177 ++
 11 files changed, 266 insertions(+), 16 deletions(-)
 create mode 100644 clang/test/AST/bitint-suffix.cpp
 create mode 100644 clang/test/Lexer/bitint-constants.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7fbe2fec6ca065..d40c86a15ac2da 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -88,6 +88,7 @@ sections with improvements to Clang's support for those 
languages.
 
 C++ Language Changes
 
+- Implemented ``_BitInt`` literal suffixes ``__wb`` or ``__WB`` as a Clang 
extension with ``unsigned`` modifiers also allowed. (#GH85223).
 
 C++20 Feature Support
 ^
diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index a52bf62e24202c..0738f43ca555c8 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -234,6 +234,9 @@ def err_cxx23_size_t_suffix: Error<
 def err_size_t_literal_too_large: Error<
   "%select{signed |}0'size_t' literal is out of range of possible "
   "%select{signed |}0'size_t' values">;
+def ext_cxx_bitint_suffix : Extension<
+  "'_BitInt' suffix for literals is a Clang extension">,
+  InGroup;
 def ext_c23_bitint_suffix : ExtWarn<
   "'_BitInt' suffix for literals is a C23 extension">,
   InGroup;
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 44035e2fd16f2e..38c0c6af949f63 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1516,3 +1516,5 @@ def UnsafeBufferUsage : DiagGroup<"unsafe-buffer-usage", 
[UnsafeBufferUsageInCon
 // Warnings and notes InstallAPI verification.
 def InstallAPIViolation : DiagGroup<"installapi-violation">;
 
+// Warnings related to _BitInt extension 
+def BitIntExtension : DiagGroup<"bit-int-extension">;
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 46a44418a3153b..6759f923564adf 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1646,7 +1646,7 @@ def warn_ext_int_deprecated : Warning<
   "'_ExtInt' is deprecated; use '_BitInt' instead">, InGroup;
 def ext_bit_int : Extension<
   "'_BitInt' in %select{C17 and earlier|C++}0 is a Clang extension">,
-  InGroup>;
+  InGroup;
 } // end of Parse Issue category.
 
 let CategoryName = "Modules Issue" in {
diff --git a/clang/include/clang/Lex/LiteralSupport.h 
b/clang/include/clang/Lex/LiteralSupport.h
index 643ddbdad8c87d..e7a2ccc9bb0bb3 100644
--- a/clang/include/clang/Lex/LiteralSupport.h
+++ b/clang/include/clang/Lex/LiteralSupport.h
@@ -80,7 +80,8 @@ class NumericLiteralParser {
   bool isFloat128 : 1;  // 1.0q
   bool isFract : 1; // 1.0hr/r/lr/uhr/ur/ulr
   bool isAccum : 1; // 1.0hk/k/lk/uhk/uk/ulk
-  bool isBitInt : 1;// 1wb, 1uwb (C23)
+  bool isBitInt : 1; // 1wb, 1uwb (C23) or 1__wb, 1__uwb (Clang extension in 
C++
+ // mode)
   uint8_t MicrosoftInteger; // Microsoft suffix extension i8, i16, i32, or i64.
 
 
diff --git a/clang/lib/Lex/LiteralSupport.cpp b/clang/lib/Lex/LiteralSupport.cpp
index 438c6d772e6e04..050c7ab96b0b32 100644
--- a/clang/lib/Lex/LiteralSupport.cpp
+++ b/clang/lib/Lex/LiteralSupport.cpp
@@ -974,6 +974,7 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   bool isFixedPointConstant = isFixedPointLiteral();
   bool isFPConstant = isFloatingLiteral();
   bool HasSize = false;
+  bool PossibleBitInt = false;
 
   // Loop over all of the characters of the suffix.  If we see something bad,
   // we break out of the loop.
@@ -1117,6 +1118,26 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   if (isImaginary) break;   // Cannot be repeated.
   isImaginary = true;
   continue;  // Success.
+case '_':
+  if (isFPConstant)
+break; // Invalid for floats
+  if (HasSize)
+

[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-03-27 Thread via cfe-commits

https://github.com/js324 updated https://github.com/llvm/llvm-project/pull/86586

>From 3186b97752f6a6a9b065b5b63b78fc3025ed224b Mon Sep 17 00:00:00 2001
From: Jin S 
Date: Mon, 25 Mar 2024 17:19:41 -0400
Subject: [PATCH] [BitInt] Expose a _BitInt literal suffix in C++

---
 clang/docs/ReleaseNotes.rst   |   1 +
 .../clang/Basic/DiagnosticCommonKinds.td  |   3 +
 clang/include/clang/Basic/DiagnosticGroups.td |   2 +
 .../clang/Basic/DiagnosticParseKinds.td   |   2 +-
 clang/include/clang/Lex/LiteralSupport.h  |   3 +-
 clang/lib/Lex/LiteralSupport.cpp  |  31 ++-
 clang/lib/Lex/PPExpressions.cpp   |   8 +-
 clang/lib/Sema/SemaExpr.cpp   |  12 +-
 clang/test/AST/bitint-suffix.cpp  |  32 
 clang/test/Lexer/bitint-constants-compat.c|  11 +-
 clang/test/Lexer/bitint-constants.cpp | 177 ++
 11 files changed, 266 insertions(+), 16 deletions(-)
 create mode 100644 clang/test/AST/bitint-suffix.cpp
 create mode 100644 clang/test/Lexer/bitint-constants.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7fbe2fec6ca065..d40c86a15ac2da 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -88,6 +88,7 @@ sections with improvements to Clang's support for those 
languages.
 
 C++ Language Changes
 
+- Implemented ``_BitInt`` literal suffixes ``__wb`` or ``__WB`` as a Clang 
extension with ``unsigned`` modifiers also allowed. (#GH85223).
 
 C++20 Feature Support
 ^
diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index a52bf62e24202c..0738f43ca555c8 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -234,6 +234,9 @@ def err_cxx23_size_t_suffix: Error<
 def err_size_t_literal_too_large: Error<
   "%select{signed |}0'size_t' literal is out of range of possible "
   "%select{signed |}0'size_t' values">;
+def ext_cxx_bitint_suffix : Extension<
+  "'_BitInt' suffix for literals is a Clang extension">,
+  InGroup;
 def ext_c23_bitint_suffix : ExtWarn<
   "'_BitInt' suffix for literals is a C23 extension">,
   InGroup;
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 44035e2fd16f2e..38c0c6af949f63 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1516,3 +1516,5 @@ def UnsafeBufferUsage : DiagGroup<"unsafe-buffer-usage", 
[UnsafeBufferUsageInCon
 // Warnings and notes InstallAPI verification.
 def InstallAPIViolation : DiagGroup<"installapi-violation">;
 
+// Warnings related to _BitInt extension 
+def BitIntExtension : DiagGroup<"bit-int-extension">;
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 46a44418a3153b..6759f923564adf 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1646,7 +1646,7 @@ def warn_ext_int_deprecated : Warning<
   "'_ExtInt' is deprecated; use '_BitInt' instead">, InGroup;
 def ext_bit_int : Extension<
   "'_BitInt' in %select{C17 and earlier|C++}0 is a Clang extension">,
-  InGroup>;
+  InGroup;
 } // end of Parse Issue category.
 
 let CategoryName = "Modules Issue" in {
diff --git a/clang/include/clang/Lex/LiteralSupport.h 
b/clang/include/clang/Lex/LiteralSupport.h
index 643ddbdad8c87d..e7a2ccc9bb0bb3 100644
--- a/clang/include/clang/Lex/LiteralSupport.h
+++ b/clang/include/clang/Lex/LiteralSupport.h
@@ -80,7 +80,8 @@ class NumericLiteralParser {
   bool isFloat128 : 1;  // 1.0q
   bool isFract : 1; // 1.0hr/r/lr/uhr/ur/ulr
   bool isAccum : 1; // 1.0hk/k/lk/uhk/uk/ulk
-  bool isBitInt : 1;// 1wb, 1uwb (C23)
+  bool isBitInt : 1; // 1wb, 1uwb (C23) or 1__wb, 1__uwb (Clang extension in 
C++
+ // mode)
   uint8_t MicrosoftInteger; // Microsoft suffix extension i8, i16, i32, or i64.
 
 
diff --git a/clang/lib/Lex/LiteralSupport.cpp b/clang/lib/Lex/LiteralSupport.cpp
index 438c6d772e6e04..050c7ab96b0b32 100644
--- a/clang/lib/Lex/LiteralSupport.cpp
+++ b/clang/lib/Lex/LiteralSupport.cpp
@@ -974,6 +974,7 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   bool isFixedPointConstant = isFixedPointLiteral();
   bool isFPConstant = isFloatingLiteral();
   bool HasSize = false;
+  bool PossibleBitInt = false;
 
   // Loop over all of the characters of the suffix.  If we see something bad,
   // we break out of the loop.
@@ -1117,6 +1118,26 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   if (isImaginary) break;   // Cannot be repeated.
   isImaginary = true;
   continue;  // Success.
+case '_':
+  if (isFPConstant)
+break; // Invalid for floats
+  if (HasSize)
+break;

[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-03-27 Thread via cfe-commits

https://github.com/js324 updated https://github.com/llvm/llvm-project/pull/86586

>From 1df201fabc67e252a665338934334490e1849359 Mon Sep 17 00:00:00 2001
From: Jin S 
Date: Mon, 25 Mar 2024 17:19:41 -0400
Subject: [PATCH 1/2] [BitInt] Expose a _BitInt literal suffix in C++

---
 clang/docs/ReleaseNotes.rst   |   1 +
 .../clang/Basic/DiagnosticCommonKinds.td  |   3 +
 clang/include/clang/Basic/DiagnosticGroups.td |   2 +
 .../clang/Basic/DiagnosticParseKinds.td   |   2 +-
 clang/include/clang/Lex/LiteralSupport.h  |   2 +-
 clang/lib/Lex/LiteralSupport.cpp  |  35 +++-
 clang/lib/Lex/PPExpressions.cpp   |  13 +-
 clang/lib/Sema/SemaExpr.cpp   |   8 +-
 clang/test/AST/bitint-suffix.cpp  |  32 
 clang/test/Lexer/bitint-constants-compat.c|  11 +-
 clang/test/Lexer/bitint-constants.cpp | 172 ++
 11 files changed, 261 insertions(+), 20 deletions(-)
 create mode 100644 clang/test/AST/bitint-suffix.cpp
 create mode 100644 clang/test/Lexer/bitint-constants.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7fbe2fec6ca065..15164ef5b68b5e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -88,6 +88,7 @@ sections with improvements to Clang's support for those 
languages.
 
 C++ Language Changes
 
+- Implemented _BitInt literal suffixes as ``__wb`` or ``__WB`` with unsigned 
modifiers also allowed. (#GH85223).
 
 C++20 Feature Support
 ^
diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index a52bf62e24202c..5466e1472fbf5c 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -234,6 +234,9 @@ def err_cxx23_size_t_suffix: Error<
 def err_size_t_literal_too_large: Error<
   "%select{signed |}0'size_t' literal is out of range of possible "
   "%select{signed |}0'size_t' values">;
+def ext_cpp_bitint_suffix : Extension<
+  "'_BitInt' suffix for literals is a Clang extension">,
+  InGroup;
 def ext_c23_bitint_suffix : ExtWarn<
   "'_BitInt' suffix for literals is a C23 extension">,
   InGroup;
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 44035e2fd16f2e..e38c8f009efe79 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1516,3 +1516,5 @@ def UnsafeBufferUsage : DiagGroup<"unsafe-buffer-usage", 
[UnsafeBufferUsageInCon
 // Warnings and notes InstallAPI verification.
 def InstallAPIViolation : DiagGroup<"installapi-violation">;
 
+// Warnings related to _BitInt extension 
+def BitIntExtension : DiagGroup<"bit-int-extension">;
\ No newline at end of file
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 46a44418a3153b..6759f923564adf 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1646,7 +1646,7 @@ def warn_ext_int_deprecated : Warning<
   "'_ExtInt' is deprecated; use '_BitInt' instead">, InGroup;
 def ext_bit_int : Extension<
   "'_BitInt' in %select{C17 and earlier|C++}0 is a Clang extension">,
-  InGroup>;
+  InGroup;
 } // end of Parse Issue category.
 
 let CategoryName = "Modules Issue" in {
diff --git a/clang/include/clang/Lex/LiteralSupport.h 
b/clang/include/clang/Lex/LiteralSupport.h
index 643ddbdad8c87d..4e7e6c77003049 100644
--- a/clang/include/clang/Lex/LiteralSupport.h
+++ b/clang/include/clang/Lex/LiteralSupport.h
@@ -80,7 +80,7 @@ class NumericLiteralParser {
   bool isFloat128 : 1;  // 1.0q
   bool isFract : 1; // 1.0hr/r/lr/uhr/ur/ulr
   bool isAccum : 1; // 1.0hk/k/lk/uhk/uk/ulk
-  bool isBitInt : 1;// 1wb, 1uwb (C23)
+  bool isBitInt : 1;// 1wb, 1uwb (C23) or 1__wb, 1__uwb (C++)
   uint8_t MicrosoftInteger; // Microsoft suffix extension i8, i16, i32, or i64.
 
 
diff --git a/clang/lib/Lex/LiteralSupport.cpp b/clang/lib/Lex/LiteralSupport.cpp
index 438c6d772e6e04..4d605fd88e81db 100644
--- a/clang/lib/Lex/LiteralSupport.cpp
+++ b/clang/lib/Lex/LiteralSupport.cpp
@@ -974,6 +974,7 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   bool isFixedPointConstant = isFixedPointLiteral();
   bool isFPConstant = isFloatingLiteral();
   bool HasSize = false;
+  bool possibleBitInt = false;
 
   // Loop over all of the characters of the suffix.  If we see something bad,
   // we break out of the loop.
@@ -1117,6 +1118,26 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   if (isImaginary) break;   // Cannot be repeated.
   isImaginary = true;
   continue;  // Success.
+case '_':
+  if (isFPConstant)
+break; // Invalid for floats
+  if (HasSize)
+break;
+  if (possibleBitInt)
+

[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-03-26 Thread via cfe-commits


@@ -88,6 +88,7 @@ sections with improvements to Clang's support for those 
languages.
 
 C++ Language Changes
 
+- Implemented _BitInt literal suffixes as ``__wb`` or ``__WB`` with unsigned 
modifiers also allowed. (#GH85223).

Sirraide wrote:

I see, I was misremembering then, my bad.

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-03-26 Thread Aaron Ballman via cfe-commits


@@ -88,6 +88,7 @@ sections with improvements to Clang's support for those 
languages.
 
 C++ Language Changes
 
+- Implemented _BitInt literal suffixes as ``__wb`` or ``__WB`` with unsigned 
modifiers also allowed. (#GH85223).

AaronBallman wrote:

We don't have a separate section in the release notes, so I think where it's at 
is reasonable enough (it's not really a bug fix and it's specific to C++).

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-03-26 Thread Aaron Ballman via cfe-commits


@@ -88,6 +88,7 @@ sections with improvements to Clang's support for those 
languages.
 
 C++ Language Changes
 
+- Implemented _BitInt literal suffixes as ``__wb`` or ``__WB`` with unsigned 
modifiers also allowed. (#GH85223).

AaronBallman wrote:

```suggestion
- Implemented ``_BitInt`` literal suffixes as ``__wb`` or ``__WB`` with 
``unsigned`` modifiers also allowed. (#GH85223).
```

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-03-26 Thread Aaron Ballman via cfe-commits


@@ -1516,3 +1516,5 @@ def UnsafeBufferUsage : DiagGroup<"unsafe-buffer-usage", 
[UnsafeBufferUsageInCon
 // Warnings and notes InstallAPI verification.
 def InstallAPIViolation : DiagGroup<"installapi-violation">;
 
+// Warnings related to _BitInt extension 
+def BitIntExtension : DiagGroup<"bit-int-extension">;

AaronBallman wrote:

```suggestion
def BitIntExtension : DiagGroup<"bit-int-extension">;

```
Adding a newline back to the end of the file.


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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-03-26 Thread Aaron Ballman via cfe-commits


@@ -1241,7 +1260,9 @@ bool NumericLiteralParser::isValidUDSuffix(const 
LangOptions ,
 return false;
 
   // By C++11 [lex.ext]p10, ud-suffixes starting with an '_' are always valid.
-  if (Suffix[0] == '_')
+  // Suffixes starting with '__' (double underscore) are for use by
+  // implementation.
+  if (Suffix[0] == '_' && Suffix[1] != '_')

AaronBallman wrote:

Example code that causes an assertion now:
```
unsigned operator ""_(const char *);

unsigned i = 1_;
```


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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-03-26 Thread Aaron Ballman via cfe-commits


@@ -1117,19 +1118,37 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   if (isImaginary) break;   // Cannot be repeated.
   isImaginary = true;
   continue;  // Success.
+case '_':
+  if (isFPConstant)
+break; // Invalid for floats
+  if (HasSize)
+break;
+  if (possibleBitInt)
+break; // Cannot be repeated.
+  if (LangOpts.CPlusPlus && s[1] == '_') {
+// Scan ahead to find possible rest of BitInt suffix
+for (const char *c = s; c != ThisTokEnd; ++c) {
+  if (*c == 'w' || *c == 'W') {
+possibleBitInt = true;
+++s;

AaronBallman wrote:

Not necessary -- because it's undefined behavior, we're not breaking anything, 
the code was already broken to begin with. Also, users already get a reasonable 
diagnostic on the declaration of the UDL:
```
warning: user-defined literal suffixes containing '__' are reserved; no literal 
will invoke this operator [-Wuser-defined-literals]
1 | unsigned operator ""__w(const char *);
```

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-03-26 Thread via cfe-commits


@@ -1117,19 +1118,37 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   if (isImaginary) break;   // Cannot be repeated.
   isImaginary = true;
   continue;  // Success.
+case '_':
+  if (isFPConstant)
+break; // Invalid for floats
+  if (HasSize)
+break;
+  if (possibleBitInt)
+break; // Cannot be repeated.
+  if (LangOpts.CPlusPlus && s[1] == '_') {
+// Scan ahead to find possible rest of BitInt suffix
+for (const char *c = s; c != ThisTokEnd; ++c) {
+  if (*c == 'w' || *c == 'W') {
+possibleBitInt = true;
+++s;

js324 wrote:

Should I add your remark to the Release Notes as a potentially breaking change 
or is it not necessary? 

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-03-25 Thread via cfe-commits

https://github.com/js324 updated https://github.com/llvm/llvm-project/pull/86586

>From 1df201fabc67e252a665338934334490e1849359 Mon Sep 17 00:00:00 2001
From: Jin S 
Date: Mon, 25 Mar 2024 17:19:41 -0400
Subject: [PATCH] [BitInt] Expose a _BitInt literal suffix in C++

---
 clang/docs/ReleaseNotes.rst   |   1 +
 .../clang/Basic/DiagnosticCommonKinds.td  |   3 +
 clang/include/clang/Basic/DiagnosticGroups.td |   2 +
 .../clang/Basic/DiagnosticParseKinds.td   |   2 +-
 clang/include/clang/Lex/LiteralSupport.h  |   2 +-
 clang/lib/Lex/LiteralSupport.cpp  |  35 +++-
 clang/lib/Lex/PPExpressions.cpp   |  13 +-
 clang/lib/Sema/SemaExpr.cpp   |   8 +-
 clang/test/AST/bitint-suffix.cpp  |  32 
 clang/test/Lexer/bitint-constants-compat.c|  11 +-
 clang/test/Lexer/bitint-constants.cpp | 172 ++
 11 files changed, 261 insertions(+), 20 deletions(-)
 create mode 100644 clang/test/AST/bitint-suffix.cpp
 create mode 100644 clang/test/Lexer/bitint-constants.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7fbe2fec6ca065..15164ef5b68b5e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -88,6 +88,7 @@ sections with improvements to Clang's support for those 
languages.
 
 C++ Language Changes
 
+- Implemented _BitInt literal suffixes as ``__wb`` or ``__WB`` with unsigned 
modifiers also allowed. (#GH85223).
 
 C++20 Feature Support
 ^
diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index a52bf62e24202c..5466e1472fbf5c 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -234,6 +234,9 @@ def err_cxx23_size_t_suffix: Error<
 def err_size_t_literal_too_large: Error<
   "%select{signed |}0'size_t' literal is out of range of possible "
   "%select{signed |}0'size_t' values">;
+def ext_cpp_bitint_suffix : Extension<
+  "'_BitInt' suffix for literals is a Clang extension">,
+  InGroup;
 def ext_c23_bitint_suffix : ExtWarn<
   "'_BitInt' suffix for literals is a C23 extension">,
   InGroup;
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 44035e2fd16f2e..e38c8f009efe79 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1516,3 +1516,5 @@ def UnsafeBufferUsage : DiagGroup<"unsafe-buffer-usage", 
[UnsafeBufferUsageInCon
 // Warnings and notes InstallAPI verification.
 def InstallAPIViolation : DiagGroup<"installapi-violation">;
 
+// Warnings related to _BitInt extension 
+def BitIntExtension : DiagGroup<"bit-int-extension">;
\ No newline at end of file
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 46a44418a3153b..6759f923564adf 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1646,7 +1646,7 @@ def warn_ext_int_deprecated : Warning<
   "'_ExtInt' is deprecated; use '_BitInt' instead">, InGroup;
 def ext_bit_int : Extension<
   "'_BitInt' in %select{C17 and earlier|C++}0 is a Clang extension">,
-  InGroup>;
+  InGroup;
 } // end of Parse Issue category.
 
 let CategoryName = "Modules Issue" in {
diff --git a/clang/include/clang/Lex/LiteralSupport.h 
b/clang/include/clang/Lex/LiteralSupport.h
index 643ddbdad8c87d..4e7e6c77003049 100644
--- a/clang/include/clang/Lex/LiteralSupport.h
+++ b/clang/include/clang/Lex/LiteralSupport.h
@@ -80,7 +80,7 @@ class NumericLiteralParser {
   bool isFloat128 : 1;  // 1.0q
   bool isFract : 1; // 1.0hr/r/lr/uhr/ur/ulr
   bool isAccum : 1; // 1.0hk/k/lk/uhk/uk/ulk
-  bool isBitInt : 1;// 1wb, 1uwb (C23)
+  bool isBitInt : 1;// 1wb, 1uwb (C23) or 1__wb, 1__uwb (C++)
   uint8_t MicrosoftInteger; // Microsoft suffix extension i8, i16, i32, or i64.
 
 
diff --git a/clang/lib/Lex/LiteralSupport.cpp b/clang/lib/Lex/LiteralSupport.cpp
index 438c6d772e6e04..4d605fd88e81db 100644
--- a/clang/lib/Lex/LiteralSupport.cpp
+++ b/clang/lib/Lex/LiteralSupport.cpp
@@ -974,6 +974,7 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   bool isFixedPointConstant = isFixedPointLiteral();
   bool isFPConstant = isFloatingLiteral();
   bool HasSize = false;
+  bool possibleBitInt = false;
 
   // Loop over all of the characters of the suffix.  If we see something bad,
   // we break out of the loop.
@@ -1117,6 +1118,26 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   if (isImaginary) break;   // Cannot be repeated.
   isImaginary = true;
   continue;  // Success.
+case '_':
+  if (isFPConstant)
+break; // Invalid for floats
+  if (HasSize)
+break;
+  if (possibleBitInt)
+

[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-03-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (js324)


Changes

Hi,

This PR is an attempt for #85223 to expose _BitInt literal suffixes as 
an extension in C++ as `__wb`. There is a new Extension warning, and the tests 
are essentially the same as the existing _BitInt literal tests for C but with a 
few additional cases. 


---
Full diff: https://github.com/llvm/llvm-project/pull/86586.diff


11 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+1) 
- (modified) clang/include/clang/Basic/DiagnosticCommonKinds.td (+3) 
- (modified) clang/include/clang/Basic/DiagnosticGroups.td (+2) 
- (modified) clang/include/clang/Basic/DiagnosticParseKinds.td (+1-1) 
- (modified) clang/include/clang/Lex/LiteralSupport.h (+1-1) 
- (modified) clang/lib/Lex/LiteralSupport.cpp (+28-7) 
- (modified) clang/lib/Lex/PPExpressions.cpp (+7-6) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+4-4) 
- (added) clang/test/AST/bitint-suffix.cpp (+32) 
- (modified) clang/test/Lexer/bitint-constants-compat.c (+10-1) 
- (added) clang/test/Lexer/bitint-constants.cpp (+172) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7fbe2fec6ca065..15164ef5b68b5e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -88,6 +88,7 @@ sections with improvements to Clang's support for those 
languages.
 
 C++ Language Changes
 
+- Implemented _BitInt literal suffixes as ``__wb`` or ``__WB`` with unsigned 
modifiers also allowed. (#GH85223).
 
 C++20 Feature Support
 ^
diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index a52bf62e24202c..5466e1472fbf5c 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -234,6 +234,9 @@ def err_cxx23_size_t_suffix: Error<
 def err_size_t_literal_too_large: Error<
   "%select{signed |}0'size_t' literal is out of range of possible "
   "%select{signed |}0'size_t' values">;
+def ext_cpp_bitint_suffix : Extension<
+  "'_BitInt' suffix for literals is a Clang extension">,
+  InGroup;
 def ext_c23_bitint_suffix : ExtWarn<
   "'_BitInt' suffix for literals is a C23 extension">,
   InGroup;
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 44035e2fd16f2e..e38c8f009efe79 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1516,3 +1516,5 @@ def UnsafeBufferUsage : DiagGroup<"unsafe-buffer-usage", 
[UnsafeBufferUsageInCon
 // Warnings and notes InstallAPI verification.
 def InstallAPIViolation : DiagGroup<"installapi-violation">;
 
+// Warnings related to _BitInt extension 
+def BitIntExtension : DiagGroup<"bit-int-extension">;
\ No newline at end of file
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 46a44418a3153b..6759f923564adf 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1646,7 +1646,7 @@ def warn_ext_int_deprecated : Warning<
   "'_ExtInt' is deprecated; use '_BitInt' instead">, InGroup;
 def ext_bit_int : Extension<
   "'_BitInt' in %select{C17 and earlier|C++}0 is a Clang extension">,
-  InGroup>;
+  InGroup;
 } // end of Parse Issue category.
 
 let CategoryName = "Modules Issue" in {
diff --git a/clang/include/clang/Lex/LiteralSupport.h 
b/clang/include/clang/Lex/LiteralSupport.h
index 643ddbdad8c87d..4e7e6c77003049 100644
--- a/clang/include/clang/Lex/LiteralSupport.h
+++ b/clang/include/clang/Lex/LiteralSupport.h
@@ -80,7 +80,7 @@ class NumericLiteralParser {
   bool isFloat128 : 1;  // 1.0q
   bool isFract : 1; // 1.0hr/r/lr/uhr/ur/ulr
   bool isAccum : 1; // 1.0hk/k/lk/uhk/uk/ulk
-  bool isBitInt : 1;// 1wb, 1uwb (C23)
+  bool isBitInt : 1;// 1wb, 1uwb (C23) or 1__wb, 1__uwb (C++)
   uint8_t MicrosoftInteger; // Microsoft suffix extension i8, i16, i32, or i64.
 
 
diff --git a/clang/lib/Lex/LiteralSupport.cpp b/clang/lib/Lex/LiteralSupport.cpp
index 438c6d772e6e04..4d605fd88e81db 100644
--- a/clang/lib/Lex/LiteralSupport.cpp
+++ b/clang/lib/Lex/LiteralSupport.cpp
@@ -974,6 +974,7 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   bool isFixedPointConstant = isFixedPointLiteral();
   bool isFPConstant = isFloatingLiteral();
   bool HasSize = false;
+  bool possibleBitInt = false;
 
   // Loop over all of the characters of the suffix.  If we see something bad,
   // we break out of the loop.
@@ -1117,6 +1118,26 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   if (isImaginary) break;   // Cannot be repeated.
   isImaginary = true;
   continue;  // Success.
+case '_':
+  if (isFPConstant)
+break; // Invalid for floats
+  if (HasSize)
+break;
+  if 

[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-03-25 Thread via cfe-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from 
other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[clang] [BitInt] Expose a _BitInt literal suffix in C++ (PR #86586)

2024-03-25 Thread via cfe-commits

https://github.com/js324 created https://github.com/llvm/llvm-project/pull/86586

Hi,

This PR is an attempt for #85223 to expose _BitInt literal suffixes as an 
extension in C++ as `__wb`. There is a new Extension warning, and the tests are 
essentially the same as the existing _BitInt literal tests for C but with a few 
additional cases. 


>From 7a6d736303cdfe54d01db6371c801545d3d2ae08 Mon Sep 17 00:00:00 2001
From: Jin S 
Date: Mon, 25 Mar 2024 17:19:41 -0400
Subject: [PATCH 1/2] [BitInt] Expose a _BitInt literal suffix in C++

---
 clang/docs/ReleaseNotes.rst   |   1 +
 .../clang/Basic/DiagnosticCommonKinds.td  |   3 +
 clang/include/clang/Basic/DiagnosticGroups.td |   2 +
 .../clang/Basic/DiagnosticParseKinds.td   |   2 +-
 clang/include/clang/Lex/LiteralSupport.h  |   2 +-
 clang/lib/Lex/LiteralSupport.cpp  |  33 +++-
 clang/lib/Lex/PPExpressions.cpp   |  13 +-
 clang/lib/Sema/SemaExpr.cpp   |   8 +-
 clang/test/AST/bitint-suffix.cpp  |  32 
 clang/test/Lexer/bitint-constants-compat.c|  11 +-
 clang/test/Lexer/bitint-constants.cpp | 172 ++
 11 files changed, 258 insertions(+), 21 deletions(-)
 create mode 100644 clang/test/AST/bitint-suffix.cpp
 create mode 100644 clang/test/Lexer/bitint-constants.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7fbe2fec6ca065..15164ef5b68b5e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -88,6 +88,7 @@ sections with improvements to Clang's support for those 
languages.
 
 C++ Language Changes
 
+- Implemented _BitInt literal suffixes as ``__wb`` or ``__WB`` with unsigned 
modifiers also allowed. (#GH85223).
 
 C++20 Feature Support
 ^
diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index a52bf62e24202c..5466e1472fbf5c 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -234,6 +234,9 @@ def err_cxx23_size_t_suffix: Error<
 def err_size_t_literal_too_large: Error<
   "%select{signed |}0'size_t' literal is out of range of possible "
   "%select{signed |}0'size_t' values">;
+def ext_cpp_bitint_suffix : Extension<
+  "'_BitInt' suffix for literals is a Clang extension">,
+  InGroup;
 def ext_c23_bitint_suffix : ExtWarn<
   "'_BitInt' suffix for literals is a C23 extension">,
   InGroup;
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 44035e2fd16f2e..e38c8f009efe79 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1516,3 +1516,5 @@ def UnsafeBufferUsage : DiagGroup<"unsafe-buffer-usage", 
[UnsafeBufferUsageInCon
 // Warnings and notes InstallAPI verification.
 def InstallAPIViolation : DiagGroup<"installapi-violation">;
 
+// Warnings related to _BitInt extension 
+def BitIntExtension : DiagGroup<"bit-int-extension">;
\ No newline at end of file
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 46a44418a3153b..6759f923564adf 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1646,7 +1646,7 @@ def warn_ext_int_deprecated : Warning<
   "'_ExtInt' is deprecated; use '_BitInt' instead">, InGroup;
 def ext_bit_int : Extension<
   "'_BitInt' in %select{C17 and earlier|C++}0 is a Clang extension">,
-  InGroup>;
+  InGroup;
 } // end of Parse Issue category.
 
 let CategoryName = "Modules Issue" in {
diff --git a/clang/include/clang/Lex/LiteralSupport.h 
b/clang/include/clang/Lex/LiteralSupport.h
index 643ddbdad8c87d..4e7e6c77003049 100644
--- a/clang/include/clang/Lex/LiteralSupport.h
+++ b/clang/include/clang/Lex/LiteralSupport.h
@@ -80,7 +80,7 @@ class NumericLiteralParser {
   bool isFloat128 : 1;  // 1.0q
   bool isFract : 1; // 1.0hr/r/lr/uhr/ur/ulr
   bool isAccum : 1; // 1.0hk/k/lk/uhk/uk/ulk
-  bool isBitInt : 1;// 1wb, 1uwb (C23)
+  bool isBitInt : 1;// 1wb, 1uwb (C23) or 1__wb, 1__uwb (C++)
   uint8_t MicrosoftInteger; // Microsoft suffix extension i8, i16, i32, or i64.
 
 
diff --git a/clang/lib/Lex/LiteralSupport.cpp b/clang/lib/Lex/LiteralSupport.cpp
index 438c6d772e6e04..d2c7249c81de26 100644
--- a/clang/lib/Lex/LiteralSupport.cpp
+++ b/clang/lib/Lex/LiteralSupport.cpp
@@ -925,7 +925,7 @@ NumericLiteralParser::NumericLiteralParser(StringRef 
TokSpelling,
   isAccum = false;
   hadError = false;
   isBitInt = false;
-
+  
   // This routine assumes that the range begin/end matches the regex for 
integer
   // and FP constants (specifically, the 'pp-number' regex), and assumes that
   // the byte at "*end" is both valid and not part of the regex.  Because of
@@ -974,6 +974,7 @@