[PATCH] D99456: [C++2b] Support size_t literals

2021-04-15 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/lib/Frontend/InitPreprocessor.cpp:593-594
+  // C++2b features.
+  if (LangOpts.CPlusPlus2b)
+Builder.defineMacro("__cpp_size_t_suffix", "202011L");
   if (LangOpts.Char8)

Quuxplusone wrote:
> AntonBikineev wrote:
> > AntonBikineev wrote:
> > > Quuxplusone wrote:
> > > > aaron.ballman wrote:
> > > > > AntonBikineev wrote:
> > > > > > aaron.ballman wrote:
> > > > > > > Because we allow this as an extension in all C++ modes, should 
> > > > > > > this be enabled always rather than gated on C++2b?
> > > > > > I was also wondering about this. I've checked that we also do the 
> > > > > > same for other feature macros, such as __cpp_binary_literals, which 
> > > > > > is defined for -std>=c++14 while at the same time is allowed as an 
> > > > > > extension before C++14. Therefore I decided to mimic the behaviour.
> > > > > Thanks for checking on that! I think that seems defensible enough. :-)
> > > > Btw, thus far libc++ has tended to make the opposite choice: for 
> > > > example, libc++ defines `__cpp_lib_variant == 202102` in all modes, 
> > > > because the programmer conceivably might be depending on that macro to 
> > > > make some decision, so we want to make sure it reflects the specific 
> > > > semantics that we implement.  (For `__cpp_binary_literals` 
> > > > specifically, I agree it doesn't really matter because nobody's going 
> > > > to be making decisions based on the value of this macro.)
> > > > 
> > > > See https://reviews.llvm.org/D99290#inline-934563 (D96385, D97394) for 
> > > > previous discussions on the libc++ side.
> > > Thanks for pointing this out, Arthur.
> > > 
> > > I wish there was some consistency, however, I'm not sure if this is 
> > > easily feasible. I guess the strategy of defining `__cpp_size_t_literals` 
> > > on all modes would be problematic, since if the user code depends on 
> > > `__cpp_size_t_literals`, it could suddenly receive the extension warning 
> > > (when compiled with -std<2++2b), which is enabled by default.
> > > Btw, thus far libc++ has tended to make the opposite choice: for example, 
> > > libc++ defines `__cpp_lib_variant == 202102` in all modes, because the 
> > > programmer conceivably might be depending on that macro to make some 
> > > decision, so we want to make sure it reflects the specific semantics that 
> > > we implement.  (For `__cpp_binary_literals` specifically, I agree it 
> > > doesn't really matter because nobody's going to be making decisions based 
> > > on the value of this macro.)
> > > 
> > > See https://reviews.llvm.org/D99290#inline-934563 (D96385, D97394) for 
> > > previous discussions on the libc++ side.
> > 
> > 
> > I guess the strategy of defining `__cpp_size_t_literals` in all modes would 
> > be problematic, since if the [pre-C++2b] user code depends on 
> > `__cpp_size_t_literals`, it could suddenly receive the extension warning...
> 
> Ah, yes. Orthogonally to everything I said above, I think it's fair to say 
> that
> - in modes where `42uz` produces a fatal error, it's definitely "not 
> supported"
> - in modes where it's accepted without complaint, it's definitely "supported" 
> (*)
> - in modes where it produces a non-fatal warning, you can plausibly argue it 
> either way
> (*) - with a bonus exception that if the user passes `-Wno-blah` or `-w`, 
> that doesn't magically make things be supported
> libc++'s situation seems more black-and-white; e.g. `variant` behaves one way 
> or the other. There's no libc++ equivalent of "you get the new behavior but 
> with a warning." :)
We have some prior art to draw on here: our `__has_extension(X)` behavior is 
that under `-pedantic-errors`, we don't advertise any extensions beyond the 
`__has_feature(X)` set, and otherwise we advertise features even if they will 
lead to warnings (or errors via `-Werror` or `-Werror=pedantic` or similar 
warning flags).

I'm not sure that's necessarily the best thing, since it's only loosely 
connected to whether the construct in question would lead to (warnings or) 
errors, but it's consistent with the principle that warning flags shouldn't 
change behavior (beyond which warnings or errors are emitted) and probably more 
useful than never advertising extensions in earlier language modes.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99456/new/

https://reviews.llvm.org/D99456

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


[PATCH] D99456: [C++2b] Support size_t literals

2021-03-31 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added inline comments.



Comment at: clang/lib/Frontend/InitPreprocessor.cpp:593-594
+  // C++2b features.
+  if (LangOpts.CPlusPlus2b)
+Builder.defineMacro("__cpp_size_t_suffix", "202011L");
   if (LangOpts.Char8)

AntonBikineev wrote:
> AntonBikineev wrote:
> > Quuxplusone wrote:
> > > aaron.ballman wrote:
> > > > AntonBikineev wrote:
> > > > > aaron.ballman wrote:
> > > > > > Because we allow this as an extension in all C++ modes, should this 
> > > > > > be enabled always rather than gated on C++2b?
> > > > > I was also wondering about this. I've checked that we also do the 
> > > > > same for other feature macros, such as __cpp_binary_literals, which 
> > > > > is defined for -std>=c++14 while at the same time is allowed as an 
> > > > > extension before C++14. Therefore I decided to mimic the behaviour.
> > > > Thanks for checking on that! I think that seems defensible enough. :-)
> > > Btw, thus far libc++ has tended to make the opposite choice: for example, 
> > > libc++ defines `__cpp_lib_variant == 202102` in all modes, because the 
> > > programmer conceivably might be depending on that macro to make some 
> > > decision, so we want to make sure it reflects the specific semantics that 
> > > we implement.  (For `__cpp_binary_literals` specifically, I agree it 
> > > doesn't really matter because nobody's going to be making decisions based 
> > > on the value of this macro.)
> > > 
> > > See https://reviews.llvm.org/D99290#inline-934563 (D96385, D97394) for 
> > > previous discussions on the libc++ side.
> > Thanks for pointing this out, Arthur.
> > 
> > I wish there was some consistency, however, I'm not sure if this is easily 
> > feasible. I guess the strategy of defining `__cpp_size_t_literals` on all 
> > modes would be problematic, since if the user code depends on 
> > `__cpp_size_t_literals`, it could suddenly receive the extension warning 
> > (when compiled with -std<2++2b), which is enabled by default.
> > Btw, thus far libc++ has tended to make the opposite choice: for example, 
> > libc++ defines `__cpp_lib_variant == 202102` in all modes, because the 
> > programmer conceivably might be depending on that macro to make some 
> > decision, so we want to make sure it reflects the specific semantics that 
> > we implement.  (For `__cpp_binary_literals` specifically, I agree it 
> > doesn't really matter because nobody's going to be making decisions based 
> > on the value of this macro.)
> > 
> > See https://reviews.llvm.org/D99290#inline-934563 (D96385, D97394) for 
> > previous discussions on the libc++ side.
> 
> 
> I guess the strategy of defining `__cpp_size_t_literals` in all modes would 
> be problematic, since if the [pre-C++2b] user code depends on 
> `__cpp_size_t_literals`, it could suddenly receive the extension warning...

Ah, yes. Orthogonally to everything I said above, I think it's fair to say that
- in modes where `42uz` produces a fatal error, it's definitely "not supported"
- in modes where it's accepted without complaint, it's definitely "supported" 
(*)
- in modes where it produces a non-fatal warning, you can plausibly argue it 
either way
(*) - with a bonus exception that if the user passes `-Wno-blah` or `-w`, that 
doesn't magically make things be supported
libc++'s situation seems more black-and-white; e.g. `variant` behaves one way 
or the other. There's no libc++ equivalent of "you get the new behavior but 
with a warning." :)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99456/new/

https://reviews.llvm.org/D99456

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


[PATCH] D99456: [C++2b] Support size_t literals

2021-03-31 Thread Anton Bikineev via Phabricator via cfe-commits
AntonBikineev added inline comments.



Comment at: clang/lib/Frontend/InitPreprocessor.cpp:593-594
+  // C++2b features.
+  if (LangOpts.CPlusPlus2b)
+Builder.defineMacro("__cpp_size_t_suffix", "202011L");
   if (LangOpts.Char8)

Quuxplusone wrote:
> aaron.ballman wrote:
> > AntonBikineev wrote:
> > > aaron.ballman wrote:
> > > > Because we allow this as an extension in all C++ modes, should this be 
> > > > enabled always rather than gated on C++2b?
> > > I was also wondering about this. I've checked that we also do the same 
> > > for other feature macros, such as __cpp_binary_literals, which is defined 
> > > for -std>=c++14 while at the same time is allowed as an extension before 
> > > C++14. Therefore I decided to mimic the behaviour.
> > Thanks for checking on that! I think that seems defensible enough. :-)
> Btw, thus far libc++ has tended to make the opposite choice: for example, 
> libc++ defines `__cpp_lib_variant == 202102` in all modes, because the 
> programmer conceivably might be depending on that macro to make some 
> decision, so we want to make sure it reflects the specific semantics that we 
> implement.  (For `__cpp_binary_literals` specifically, I agree it doesn't 
> really matter because nobody's going to be making decisions based on the 
> value of this macro.)
> 
> See https://reviews.llvm.org/D99290#inline-934563 (D96385, D97394) for 
> previous discussions on the libc++ side.
Thanks for pointing this out, Arthur.

I wish there was some consistency, however, I'm not sure if this is easily 
feasible. I guess the strategy of defining `__cpp_size_t_literals` on all modes 
would be problematic, since if the user code depends on 
`__cpp_size_t_literals`, it could suddenly receive the extension warning (when 
compiled with -std<2++2b), which is enabled by default.



Comment at: clang/lib/Frontend/InitPreprocessor.cpp:593-594
+  // C++2b features.
+  if (LangOpts.CPlusPlus2b)
+Builder.defineMacro("__cpp_size_t_suffix", "202011L");
   if (LangOpts.Char8)

AntonBikineev wrote:
> Quuxplusone wrote:
> > aaron.ballman wrote:
> > > AntonBikineev wrote:
> > > > aaron.ballman wrote:
> > > > > Because we allow this as an extension in all C++ modes, should this 
> > > > > be enabled always rather than gated on C++2b?
> > > > I was also wondering about this. I've checked that we also do the same 
> > > > for other feature macros, such as __cpp_binary_literals, which is 
> > > > defined for -std>=c++14 while at the same time is allowed as an 
> > > > extension before C++14. Therefore I decided to mimic the behaviour.
> > > Thanks for checking on that! I think that seems defensible enough. :-)
> > Btw, thus far libc++ has tended to make the opposite choice: for example, 
> > libc++ defines `__cpp_lib_variant == 202102` in all modes, because the 
> > programmer conceivably might be depending on that macro to make some 
> > decision, so we want to make sure it reflects the specific semantics that 
> > we implement.  (For `__cpp_binary_literals` specifically, I agree it 
> > doesn't really matter because nobody's going to be making decisions based 
> > on the value of this macro.)
> > 
> > See https://reviews.llvm.org/D99290#inline-934563 (D96385, D97394) for 
> > previous discussions on the libc++ side.
> Thanks for pointing this out, Arthur.
> 
> I wish there was some consistency, however, I'm not sure if this is easily 
> feasible. I guess the strategy of defining `__cpp_size_t_literals` on all 
> modes would be problematic, since if the user code depends on 
> `__cpp_size_t_literals`, it could suddenly receive the extension warning 
> (when compiled with -std<2++2b), which is enabled by default.
> Btw, thus far libc++ has tended to make the opposite choice: for example, 
> libc++ defines `__cpp_lib_variant == 202102` in all modes, because the 
> programmer conceivably might be depending on that macro to make some 
> decision, so we want to make sure it reflects the specific semantics that we 
> implement.  (For `__cpp_binary_literals` specifically, I agree it doesn't 
> really matter because nobody's going to be making decisions based on the 
> value of this macro.)
> 
> See https://reviews.llvm.org/D99290#inline-934563 (D96385, D97394) for 
> previous discussions on the libc++ side.




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99456/new/

https://reviews.llvm.org/D99456

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


[PATCH] D99456: [C++2b] Support size_t literals

2021-03-31 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added inline comments.



Comment at: clang/lib/Frontend/InitPreprocessor.cpp:593-594
+  // C++2b features.
+  if (LangOpts.CPlusPlus2b)
+Builder.defineMacro("__cpp_size_t_suffix", "202011L");
   if (LangOpts.Char8)

aaron.ballman wrote:
> AntonBikineev wrote:
> > aaron.ballman wrote:
> > > Because we allow this as an extension in all C++ modes, should this be 
> > > enabled always rather than gated on C++2b?
> > I was also wondering about this. I've checked that we also do the same for 
> > other feature macros, such as __cpp_binary_literals, which is defined for 
> > -std>=c++14 while at the same time is allowed as an extension before C++14. 
> > Therefore I decided to mimic the behaviour.
> Thanks for checking on that! I think that seems defensible enough. :-)
Btw, thus far libc++ has tended to make the opposite choice: for example, 
libc++ defines `__cpp_lib_variant == 202102` in all modes, because the 
programmer conceivably might be depending on that macro to make some decision, 
so we want to make sure it reflects the specific semantics that we implement.  
(For `__cpp_binary_literals` specifically, I agree it doesn't really matter 
because nobody's going to be making decisions based on the value of this macro.)

See https://reviews.llvm.org/D99290#inline-934563 (D96385, D97394) for previous 
discussions on the libc++ side.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99456/new/

https://reviews.llvm.org/D99456

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


[PATCH] D99456: [C++2b] Support size_t literals

2021-03-31 Thread Anton Bikineev via Phabricator via cfe-commits
AntonBikineev closed this revision.
AntonBikineev added a comment.

Aaron, Richard, thanks a lot for reviewing this!

Sorry, forgot to add amend the commit with 'Differential revision', closing 
this manually..


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99456/new/

https://reviews.llvm.org/D99456

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


[PATCH] D99456: [C++2b] Support size_t literals

2021-03-31 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM, thank you for the patch!




Comment at: clang/lib/Frontend/InitPreprocessor.cpp:593-594
+  // C++2b features.
+  if (LangOpts.CPlusPlus2b)
+Builder.defineMacro("__cpp_size_t_suffix", "202011L");
   if (LangOpts.Char8)

AntonBikineev wrote:
> aaron.ballman wrote:
> > Because we allow this as an extension in all C++ modes, should this be 
> > enabled always rather than gated on C++2b?
> I was also wondering about this. I've checked that we also do the same for 
> other feature macros, such as __cpp_binary_literals, which is defined for 
> -std>=c++14 while at the same time is allowed as an extension before C++14. 
> Therefore I decided to mimic the behaviour.
Thanks for checking on that! I think that seems defensible enough. :-)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99456/new/

https://reviews.llvm.org/D99456

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


[PATCH] D99456: [C++2b] Support size_t literals

2021-03-31 Thread Anton Bikineev via Phabricator via cfe-commits
AntonBikineev updated this revision to Diff 334422.
AntonBikineev added a comment.

Fix comment


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99456/new/

https://reviews.llvm.org/D99456

Files:
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Lex/LiteralSupport.h
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Lex/LiteralSupport.cpp
  clang/lib/Lex/PPExpressions.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Lexer/cxx-features.cpp
  clang/test/Lexer/size_t-literal.cpp
  clang/test/SemaCXX/cxx1y-user-defined-literals.cpp
  clang/test/SemaCXX/size_t-literal.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1270,7 +1270,7 @@
 
   Literal suffix uz, z for size_t, ssize_t
   https://wg21.link/p0330r8;>P0330R8
-  No
+  Clang 13
 
 
 
Index: clang/test/SemaCXX/size_t-literal.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/size_t-literal.cpp
@@ -0,0 +1,99 @@
+// RUN: %clang_cc1 -std=c++2b -triple x86_64-linux -Wpre-c++2b-compat -fsyntax-only -verify=cxx2b %s
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-linux -fsyntax-only -verify=cxx20 %s
+// RUN: %clang_cc1 -std=c++2b -triple i686-linux -fsyntax-only -verify=cxx2b-32 %s
+// RUN: %clang_cc1 -x c -std=c11 -fsyntax-only -verify=c11 %s
+
+#ifdef __cplusplus
+
+typedef __SIZE_TYPE__ size_t;
+// Assume ptrdiff_t is the signed integer type corresponding to size_t.
+typedef __PTRDIFF_TYPE__ ssize_t;
+
+template 
+struct is_same { static constexpr bool value = false; };
+
+template 
+struct is_same { static constexpr bool value = true; };
+
+void SSizeT() {
+  auto a1 = 1z;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a2 = 1Z;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+}
+
+void SizeT() {
+  auto a1 = 1uz;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a2 = 1uZ;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a3 = 1Uz;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a4 = 1UZ;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a5 = 1zu;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a6 = 1Zu;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a7 = 1zU;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a8 = 1ZU;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+}
+
+void oor() {
+#if __i386__
+  (void)3'000'000'000z; // cxx2b-32-error {{signed 'size_t' literal is out of range of possible signed 'size_t' values}}
+  (void)3'000'000'000uz;
+  (void)5'000'000'000uz; // cxx2b-32-error {{'size_t' literal is out of range of possible 'size_t' values}}
+
+  (void)0x8000z;
+  (void)0x8000uz;
+  (void)0x18000uz; //cxx2b-32-error {{'size_t' literal is out of range of possible 'size_t' values}}
+#endif
+}
+
+#else
+
+void f() {
+  (void)1z;  // c11-error {{'size_t' suffix for literals is a C++2b feature}}
+  (void)1Z;  // c11-error {{'size_t' suffix for literals is a C++2b feature}}
+  (void)1uz; // c11-error {{'size_t' suffix for literals is a C++2b feature}}
+  (void)1uZ; // c11-error {{'size_t' suffix for literals is a C++2b feature}}

[PATCH] D99456: [C++2b] Support size_t literals

2021-03-31 Thread Anton Bikineev via Phabricator via cfe-commits
AntonBikineev marked an inline comment as done.
AntonBikineev added inline comments.



Comment at: clang/lib/Frontend/InitPreprocessor.cpp:593-594
+  // C++2b features.
+  if (LangOpts.CPlusPlus2b)
+Builder.defineMacro("__cpp_size_t_suffix", "202011L");
   if (LangOpts.Char8)

aaron.ballman wrote:
> Because we allow this as an extension in all C++ modes, should this be 
> enabled always rather than gated on C++2b?
I was also wondering about this. I've checked that we also do the same for 
other feature macros, such as __cpp_binary_literals, which is defined for 
-std>=c++14 while at the same time is allowed as an extension before C++14. 
Therefore I decided to mimic the behaviour.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99456/new/

https://reviews.llvm.org/D99456

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


[PATCH] D99456: [C++2b] Support size_t literals

2021-03-31 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Generally LGTM but I did have a question about the feature testing macro.




Comment at: clang/lib/Frontend/InitPreprocessor.cpp:593-594
+  // C++2b features.
+  if (LangOpts.CPlusPlus2b)
+Builder.defineMacro("__cpp_size_t_suffix", "202011L");
   if (LangOpts.Char8)

Because we allow this as an extension in all C++ modes, should this be enabled 
always rather than gated on C++2b?



Comment at: clang/lib/Lex/LiteralSupport.cpp:678
+  if (isFPConstant)
+break; // invalid for floats.
+  if (HasSize)




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99456/new/

https://reviews.llvm.org/D99456

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


[PATCH] D99456: [C++2b] Support size_t literals

2021-03-30 Thread Anton Bikineev via Phabricator via cfe-commits
AntonBikineev updated this revision to Diff 334288.
AntonBikineev marked 2 inline comments as done.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99456/new/

https://reviews.llvm.org/D99456

Files:
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Lex/LiteralSupport.h
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Lex/LiteralSupport.cpp
  clang/lib/Lex/PPExpressions.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Lexer/cxx-features.cpp
  clang/test/Lexer/size_t-literal.cpp
  clang/test/SemaCXX/cxx1y-user-defined-literals.cpp
  clang/test/SemaCXX/size_t-literal.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1270,7 +1270,7 @@
 
   Literal suffix uz, z for size_t, ssize_t
   https://wg21.link/p0330r8;>P0330R8
-  No
+  Clang 13
 
 
 
Index: clang/test/SemaCXX/size_t-literal.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/size_t-literal.cpp
@@ -0,0 +1,99 @@
+// RUN: %clang_cc1 -std=c++2b -triple x86_64-linux -Wpre-c++2b-compat -fsyntax-only -verify=cxx2b %s
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-linux -fsyntax-only -verify=cxx20 %s
+// RUN: %clang_cc1 -std=c++2b -triple i686-linux -fsyntax-only -verify=cxx2b-32 %s
+// RUN: %clang_cc1 -x c -std=c11 -fsyntax-only -verify=c11 %s
+
+#ifdef __cplusplus
+
+typedef __SIZE_TYPE__ size_t;
+// Assume ptrdiff_t is the signed integer type corresponding to size_t.
+typedef __PTRDIFF_TYPE__ ssize_t;
+
+template 
+struct is_same { static constexpr bool value = false; };
+
+template 
+struct is_same { static constexpr bool value = true; };
+
+void SSizeT() {
+  auto a1 = 1z;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a2 = 1Z;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+}
+
+void SizeT() {
+  auto a1 = 1uz;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a2 = 1uZ;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a3 = 1Uz;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a4 = 1UZ;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a5 = 1zu;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a6 = 1Zu;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a7 = 1zU;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a8 = 1ZU;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+}
+
+void oor() {
+#if __i386__
+  (void)3'000'000'000z; // cxx2b-32-error {{signed 'size_t' literal is out of range of possible signed 'size_t' values}}
+  (void)3'000'000'000uz;
+  (void)5'000'000'000uz; // cxx2b-32-error {{'size_t' literal is out of range of possible 'size_t' values}}
+
+  (void)0x8000z;
+  (void)0x8000uz;
+  (void)0x18000uz; //cxx2b-32-error {{'size_t' literal is out of range of possible 'size_t' values}}
+#endif
+}
+
+#else
+
+void f() {
+  (void)1z;  // c11-error {{'size_t' suffix for literals is a C++2b feature}}
+  (void)1Z;  // c11-error {{'size_t' suffix for literals is a C++2b feature}}
+  (void)1uz; // c11-error {{'size_t' suffix for literals is a C++2b feature}}
+  (void)1uZ; // c11-error {{'size_t' suffix for literals is a C++2b 

[PATCH] D99456: [C++2b] Support size_t literals

2021-03-30 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added a comment.

Thanks! Looks good to me. Please wait a day or so in case Aaron has more 
comments before going ahead.




Comment at: clang/include/clang/Basic/DiagnosticCommonKinds.td:198-200
+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">;

AntonBikineev wrote:
> rsmith wrote:
> > I wonder if it'd be better to say `'ssize_t'` instead of `signed 'size_t'` 
> > here? The latter sounds self-contradictory since `size_t` is an unsigned 
> > type.
> I thought about it (and actually had it first as ssize_t). The problem with 
> ssize_t is that it's not defined by C or C++ Standards, AFAIK, but by POSIX. 
> The proposal calls it "the signed integer type corresponding to std::size_t", 
> so I decided to shorten it to "signed 'size_t'". However, I don't have strong 
> opinion on this.
That makes sense. OK, I don't have a strong opinion either, so let's go with 
what you have.



Comment at: clang/lib/Sema/SemaExpr.cpp:3996-3997
+  // If we still couldn't decide a type, we either have 'size_t' literal
+  // that is out of range or a literal that does not fit in a signed long
+  // long, but has no U suffix.
   if (Ty.isNull()) {

(Mostly to make it clear that this can happen for `size_t` regardless of the 
`u` suffix.)



Comment at: clang/www/cxx_status.html:1273
   https://wg21.link/p0330r8;>P0330R8
-  No
+  Clang 13
 




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99456/new/

https://reviews.llvm.org/D99456

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


[PATCH] D99456: [C++2b] Support size_t literals

2021-03-30 Thread Anton Bikineev via Phabricator via cfe-commits
AntonBikineev updated this revision to Diff 334263.
AntonBikineev added a comment.

Address comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99456/new/

https://reviews.llvm.org/D99456

Files:
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Lex/LiteralSupport.h
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Lex/LiteralSupport.cpp
  clang/lib/Lex/PPExpressions.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Lexer/cxx-features.cpp
  clang/test/Lexer/size_t-literal.cpp
  clang/test/SemaCXX/cxx1y-user-defined-literals.cpp
  clang/test/SemaCXX/size_t-literal.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1270,7 +1270,7 @@
 
   Literal suffix uz, z for size_t, ssize_t
   https://wg21.link/p0330r8;>P0330R8
-  No
+  Clang 13
 
 
 
Index: clang/test/SemaCXX/size_t-literal.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/size_t-literal.cpp
@@ -0,0 +1,99 @@
+// RUN: %clang_cc1 -std=c++2b -triple x86_64-linux -Wpre-c++2b-compat -fsyntax-only -verify=cxx2b %s
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-linux -fsyntax-only -verify=cxx20 %s
+// RUN: %clang_cc1 -std=c++2b -triple i686-linux -fsyntax-only -verify=cxx2b-32 %s
+// RUN: %clang_cc1 -x c -std=c11 -fsyntax-only -verify=c11 %s
+
+#ifdef __cplusplus
+
+typedef __SIZE_TYPE__ size_t;
+// Assume ptrdiff_t is the signed integer type corresponding to size_t.
+typedef __PTRDIFF_TYPE__ ssize_t;
+
+template 
+struct is_same { static constexpr bool value = false; };
+
+template 
+struct is_same { static constexpr bool value = true; };
+
+void SSizeT() {
+  auto a1 = 1z;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a2 = 1Z;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+}
+
+void SizeT() {
+  auto a1 = 1uz;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a2 = 1uZ;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a3 = 1Uz;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a4 = 1UZ;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a5 = 1zu;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a6 = 1Zu;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a7 = 1zU;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a8 = 1ZU;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+}
+
+void oor() {
+#if __i386__
+  (void)3'000'000'000z; // cxx2b-32-error {{signed 'size_t' literal is out of range of possible signed 'size_t' values}}
+  (void)3'000'000'000uz;
+  (void)5'000'000'000uz; // cxx2b-32-error {{'size_t' literal is out of range of possible 'size_t' values}}
+
+  (void)0x8000z;
+  (void)0x8000uz;
+  (void)0x18000uz; //cxx2b-32-error {{'size_t' literal is out of range of possible 'size_t' values}}
+#endif
+}
+
+#else
+
+void f() {
+  (void)1z;  // c11-error {{'size_t' suffix for literals is a C++2b feature}}
+  (void)1Z;  // c11-error {{'size_t' suffix for literals is a C++2b feature}}
+  (void)1uz; // c11-error {{'size_t' suffix for literals is a C++2b feature}}
+  (void)1uZ; // c11-error {{'size_t' suffix for literals is a C++2b 

[PATCH] D99456: [C++2b] Support size_t literals

2021-03-30 Thread Anton Bikineev via Phabricator via cfe-commits
AntonBikineev marked an inline comment as done.
AntonBikineev added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticCommonKinds.td:198-200
+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">;

rsmith wrote:
> I wonder if it'd be better to say `'ssize_t'` instead of `signed 'size_t'` 
> here? The latter sounds self-contradictory since `size_t` is an unsigned type.
I thought about it (and actually had it first as ssize_t). The problem with 
ssize_t is that it's not defined by C or C++ Standards, AFAIK, but by POSIX. 
The proposal calls it "the signed integer type corresponding to std::size_t", 
so I decided to shorten it to "signed 'size_t'". However, I don't have strong 
opinion on this.



Comment at: clang/lib/Sema/SemaExpr.cpp:3895
   // be an unsigned int.
   bool AllowUnsigned = Literal.isUnsigned || Literal.getRadix() != 10;
 

rsmith wrote:
> AntonBikineev wrote:
> > I now begin to think that we should probably also prohibit things like 
> > 0x1234z to be implicitly interpreted as unsigned. Wdyt?
> Table 8 says that a `z`-suffixed literal has type `ssize_t` (if the value 
> fits) or `size_t` (otherwise), so I think taking `AllowUnsigned` into account 
> is correct (although perhaps surprising).
Thanks for pointing this out! Changed it back and fixed the tests.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99456/new/

https://reviews.llvm.org/D99456

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


[PATCH] D99456: [C++2b] Support size_t literals

2021-03-30 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticCommonKinds.td:198-200
+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">;

I wonder if it'd be better to say `'ssize_t'` instead of `signed 'size_t'` 
here? The latter sounds self-contradictory since `size_t` is an unsigned type.



Comment at: clang/lib/Sema/SemaExpr.cpp:3895
   // be an unsigned int.
   bool AllowUnsigned = Literal.isUnsigned || Literal.getRadix() != 10;
 

AntonBikineev wrote:
> I now begin to think that we should probably also prohibit things like 
> 0x1234z to be implicitly interpreted as unsigned. Wdyt?
Table 8 says that a `z`-suffixed literal has type `ssize_t` (if the value fits) 
or `size_t` (otherwise), so I think taking `AllowUnsigned` into account is 
correct (although perhaps surprising).



Comment at: clang/lib/Sema/SemaExpr.cpp:3997
   // does not fit in a signed long long, but has no U suffix.
   if (Ty.isNull()) {
 Diag(Tok.getLocation(), 
diag::ext_integer_literal_too_large_for_signed);

AntonBikineev wrote:
> I think this branch should also be covered, since we probably don't want 
> promotion from size_t to ULL but instead have a separate diagnostic that 
> size_t is out-of-range. I've added another diagnostic and branch here.
Thanks, that makes sense to me. I agree that a `z`-suffixed literal should 
never have any type other than `size_t` or `ssize_t`; we don't want to fall 
back to `unsigned long long` as an extension.



Comment at: clang/test/SemaCXX/size_t-literal.cpp:78
+
+  (void)0x8000z; //cxx2b-32-error {{signed 'size_t' literal is out of 
range of possible signed 'size_t' values}}
+  (void)0x8000uz;

This case looks valid to me.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99456/new/

https://reviews.llvm.org/D99456

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


[PATCH] D99456: [C++2b] Support size_t literals

2021-03-30 Thread Anton Bikineev via Phabricator via cfe-commits
AntonBikineev updated this revision to Diff 334102.
AntonBikineev marked an inline comment as done.
AntonBikineev added a comment.

Address comments. Also:

- always issue a new diagnostic if size_t/ssize_t is out of range;
- prohibit numbers with 'z' suffix and non-10-radix to be interpreted as 
unsigned.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99456/new/

https://reviews.llvm.org/D99456

Files:
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Lex/LiteralSupport.h
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Lex/LiteralSupport.cpp
  clang/lib/Lex/PPExpressions.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Lexer/cxx-features.cpp
  clang/test/Lexer/size_t-literal.cpp
  clang/test/SemaCXX/cxx1y-user-defined-literals.cpp
  clang/test/SemaCXX/size_t-literal.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1270,7 +1270,7 @@
 
   Literal suffix uz, z for size_t, ssize_t
   https://wg21.link/p0330r8;>P0330R8
-  No
+  Clang 13
 
 
 
Index: clang/test/SemaCXX/size_t-literal.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/size_t-literal.cpp
@@ -0,0 +1,99 @@
+// RUN: %clang_cc1 -std=c++2b -triple x86_64-linux -Wpre-c++2b-compat -fsyntax-only -verify=cxx2b %s
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-linux -fsyntax-only -verify=cxx20 %s
+// RUN: %clang_cc1 -std=c++2b -triple i686-linux -fsyntax-only -verify=cxx2b-32 %s
+// RUN: %clang_cc1 -x c -std=c11 -fsyntax-only -verify=c11 %s
+
+#ifdef __cplusplus
+
+typedef __SIZE_TYPE__ size_t;
+// Assume ptrdiff_t is the signed integer type corresponding to size_t.
+typedef __PTRDIFF_TYPE__ ssize_t;
+
+template 
+struct is_same { static constexpr bool value = false; };
+
+template 
+struct is_same { static constexpr bool value = true; };
+
+void SSizeT() {
+  auto a1 = 1z;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a2 = 1Z;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+}
+
+void SizeT() {
+  auto a1 = 1uz;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a2 = 1uZ;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a3 = 1Uz;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a4 = 1UZ;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a5 = 1zu;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a6 = 1Zu;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a7 = 1zU;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a8 = 1ZU;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+}
+
+void oor() {
+#if __i386__
+  (void)3'000'000'000z; // cxx2b-32-error {{signed 'size_t' literal is out of range of possible signed 'size_t' values}}
+  (void)3'000'000'000uz;
+  (void)5'000'000'000uz; // cxx2b-32-error {{'size_t' literal is out of range of possible 'size_t' values}}
+
+  (void)0x8000z; //cxx2b-32-error {{signed 'size_t' literal is out of range of possible signed 'size_t' values}}
+  (void)0x8000uz;
+  (void)0x18000uz; //cxx2b-32-error {{'size_t' literal is out of range of possible 'size_t' values}}
+#endif
+}
+
+#else
+
+void f() {
+  

[PATCH] D99456: [C++2b] Support size_t literals

2021-03-30 Thread Anton Bikineev via Phabricator via cfe-commits
AntonBikineev marked 3 inline comments as done.
AntonBikineev added inline comments.



Comment at: clang/lib/Lex/LiteralSupport.cpp:640
 isFloat16 = true;
 continue;
   }

rsmith wrote:
> Looks like this might fix [[ https://godbolt.org/z/9Pe4qr1c7 | incorrect 
> acceptance ]] of `1.0f16f` and `1.0f16L` in CUDA mode too :)
Nice!



Comment at: clang/lib/Sema/SemaExpr.cpp:3895
   // be an unsigned int.
   bool AllowUnsigned = Literal.isUnsigned || Literal.getRadix() != 10;
 

I now begin to think that we should probably also prohibit things like 0x1234z 
to be implicitly interpreted as unsigned. Wdyt?



Comment at: clang/lib/Sema/SemaExpr.cpp:3997
   // does not fit in a signed long long, but has no U suffix.
   if (Ty.isNull()) {
 Diag(Tok.getLocation(), 
diag::ext_integer_literal_too_large_for_signed);

I think this branch should also be covered, since we probably don't want 
promotion from size_t to ULL but instead have a separate diagnostic that size_t 
is out-of-range. I've added another diagnostic and branch here.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99456/new/

https://reviews.llvm.org/D99456

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


[PATCH] D99456: [C++2b] Support size_t literals

2021-03-29 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/lib/Lex/LiteralSupport.cpp:640
 isFloat16 = true;
 continue;
   }

Looks like this might fix [[ https://godbolt.org/z/9Pe4qr1c7 | incorrect 
acceptance ]] of `1.0f16f` and `1.0f16L` in CUDA mode too :)



Comment at: clang/lib/Sema/SemaExpr.cpp:3920-3927
+if (ResultVal.isIntN(SizeTSize)) {
+  // Does it fit in a ssize_t?
+  if (!Literal.isUnsigned && ResultVal[SizeTSize - 1] == 0)
+Ty = Context.getSignedSizeType();
+  else if (AllowUnsigned)
+Ty = Context.getSizeType();
+  Width = SizeTSize;

I'd like to see some test coverage for this, particularly the testing of the 
high bit to determine if we're forming a signed or unsigned literal.



Comment at: clang/lib/Sema/SemaExpr.cpp:3975
   // Check long long if needed.
   if (Ty.isNull()) {
 unsigned LongLongSize = Context.getTargetInfo().getLongLongWidth();

rsmith wrote:
> Likewise here -- and this one actually does matter, because we have targets 
> with a 32-bit `size_t` but a 64-bit `long long`.
Can we get a test for this case? (Eg, `5'000'000'000z` with `-triple 
i686-linux`.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99456/new/

https://reviews.llvm.org/D99456

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


[PATCH] D99456: [C++2b] Support size_t literals

2021-03-29 Thread Anton Bikineev via Phabricator via cfe-commits
AntonBikineev updated this revision to Diff 334037.
AntonBikineev marked 2 inline comments as done.
AntonBikineev added a comment.

Address comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99456/new/

https://reviews.llvm.org/D99456

Files:
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Lex/LiteralSupport.h
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Lex/LiteralSupport.cpp
  clang/lib/Lex/PPExpressions.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Lexer/cxx-features.cpp
  clang/test/Lexer/size_t-literal.cpp
  clang/test/SemaCXX/cxx1y-user-defined-literals.cpp
  clang/test/SemaCXX/size_t-literal.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1270,7 +1270,7 @@
 
   Literal suffix uz, z for size_t, ssize_t
   https://wg21.link/p0330r8;>P0330R8
-  No
+  Clang 13
 
 
 
Index: clang/test/SemaCXX/size_t-literal.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/size_t-literal.cpp
@@ -0,0 +1,86 @@
+// RUN: %clang_cc1 -std=c++2b -Wpre-c++2b-compat -fsyntax-only -verify=cxx2b %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=cxx20 %s
+// RUN: %clang_cc1 -x c -std=c11 -fsyntax-only -verify=c11 %s
+
+#ifdef __cplusplus
+
+typedef __SIZE_TYPE__ size_t;
+// Assume ptrdiff_t is the signed integer type corresponding to size_t.
+typedef __PTRDIFF_TYPE__ ssize_t;
+
+template 
+struct is_same { static constexpr bool value = false; };
+
+template 
+struct is_same { static constexpr bool value = true; };
+
+void SSizeT() {
+  auto a1 = 1z;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a2 = 1Z;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+}
+
+void SizeT() {
+  auto a1 = 1uz;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a2 = 1uZ;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a3 = 1Uz;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a4 = 1UZ;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a5 = 1zu;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a6 = 1Zu;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a7 = 1zU;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a8 = 1ZU;
+  // cxx2b-warning@-1 {{'size_t' suffix for literals is incompatible with C++ standards before C++2b}}
+  // cxx20-warning@-2 {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+}
+
+#else
+
+void f() {
+  (void)1z;  // c11-error {{'size_t' suffix for literals is a C++2b feature}}
+  (void)1Z;  // c11-error {{'size_t' suffix for literals is a C++2b feature}}
+  (void)1uz; // c11-error {{'size_t' suffix for literals is a C++2b feature}}
+  (void)1uZ; // c11-error {{'size_t' suffix for literals is a C++2b feature}}
+  (void)1Uz; // c11-error {{'size_t' suffix for literals is a C++2b feature}}
+  (void)1UZ; // c11-error {{'size_t' suffix for literals is a C++2b feature}}
+  (void)1zu; // c11-error {{'size_t' suffix for literals is a C++2b feature}}
+  (void)1Zu; // c11-error {{'size_t' suffix for literals is a C++2b feature}}
+  (void)1zU; // c11-error {{'size_t' suffix for literals is a C++2b feature}}
+  (void)1ZU; // c11-error {{'size_t' suffix for literals is a C++2b feature}}
+}
+
+#endif
Index: 

[PATCH] D99456: [C++2b] Support size_t literals

2021-03-29 Thread Anton Bikineev via Phabricator via cfe-commits
AntonBikineev marked 7 inline comments as done.
AntonBikineev added a comment.

Thanks Richard for taking a look!




Comment at: clang/include/clang/Basic/DiagnosticCommonKinds.td:190
   InGroup, DefaultIgnore;
+def ext_cxx2b_size_t_suffix : Extension<
+  "'size_t' suffix for literals is a C++2b extension">,

rsmith wrote:
> Should this be an `ExtWarn`? I think we should warn on this by default.
I tried to follow the strategy used for 'long long' (only warn with 
-Wlong-long), but I agree that warn-by-default would probably be better.



Comment at: clang/lib/Lex/LiteralSupport.cpp:594-595
 
   // Loop over all of the characters of the suffix.  If we see something bad,
   // we break out of the loop.
   for (; s != ThisTokEnd; ++s) {

rsmith wrote:
> General comment: I think the checks here have become too complex and 
> error-prone. I suggest we add another flag, `hasSize`, that's set when we 
> parse any size modifier (`F`, `L`, `LL`, `H`, `F128`, `I64`, and now `Z`), 
> and when parsing any size modifier, replace the existing ad-hoc set of checks 
> with a check for `hasSize`.
Good idea! It actually helped to flush out the issue when Q and H are mixed 
together: https://godbolt.org/z/8hj39P93a


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99456/new/

https://reviews.llvm.org/D99456

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


[PATCH] D99456: [C++2b] Support size_t literals

2021-03-29 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticCommonKinds.td:190
   InGroup, DefaultIgnore;
+def ext_cxx2b_size_t_suffix : Extension<
+  "'size_t' suffix for literals is a C++2b extension">,

Should this be an `ExtWarn`? I think we should warn on this by default.



Comment at: clang/lib/Lex/LiteralSupport.cpp:594-595
 
   // Loop over all of the characters of the suffix.  If we see something bad,
   // we break out of the loop.
   for (; s != ThisTokEnd; ++s) {

General comment: I think the checks here have become too complex and 
error-prone. I suggest we add another flag, `hasSize`, that's set when we parse 
any size modifier (`F`, `L`, `LL`, `H`, `F128`, `I64`, and now `Z`), and when 
parsing any size modifier, replace the existing ad-hoc set of checks with a 
check for `hasSize`.



Comment at: clang/lib/Lex/PPExpressions.cpp:325
+// 'z/uz' literals are a C++2b feature.
+if (!PP.getLangOpts().CPlusPlus2b && Literal.isSizeT)
+  PP.Diag(PeekTok, PP.getLangOpts().CPlusPlus

We should issue a compat warning when these literals are used in C++2b or 
later. (That is, always issue a diagnostic for a `size_t` literal: in C, it's 
an error, in C++20 and before, it's an extension warning, and in C++2b and 
later, it's a backwards-compatibility warning.) There are a bunch of examples 
of this elsewhere in the codebase -- look for the emission of 
`warn_cxx.*_compat`.



Comment at: clang/lib/Sema/SemaExpr.cpp:3871
+// 'z/uz' literals are a C++2b feature.
+if (!getLangOpts().CPlusPlus2b && Literal.isSizeT)
+  Diag(Tok.getLocation(), getLangOpts().CPlusPlus

Also need the C++20-and-before compat warning here for C++2b-onwards mode.



Comment at: clang/lib/Sema/SemaExpr.cpp:3928
+
   if (Ty.isNull() && !Literal.isLong && !Literal.isLongLong) {
 // Are int/unsigned possibilities?

This should exclude the `isSizeT` case in addition to `isLong` and 
`isLongLong`. (It probably doesn't matter, because `int` is not larger than 
`size_t` on any platform we support, but nonetheless we should check.)



Comment at: clang/lib/Sema/SemaExpr.cpp:3944
   // Are long/unsigned long possibilities?
   if (Ty.isNull() && !Literal.isLongLong) {
 unsigned LongSize = Context.getTargetInfo().getLongWidth();

Likewise here.



Comment at: clang/lib/Sema/SemaExpr.cpp:3975
   // Check long long if needed.
   if (Ty.isNull()) {
 unsigned LongLongSize = Context.getTargetInfo().getLongLongWidth();

Likewise here -- and this one actually does matter, because we have targets 
with a 32-bit `size_t` but a 64-bit `long long`.



Comment at: clang/test/Lexer/size_t-literal.cpp:6-8
+#if 1uz != 1
+#error "size_t suffix must be recognized by preprocessor"
+#endif

Please also check `-1z < 0` and `-1zu < 0` to ensure that the preprocessor gets 
the signedness correct.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99456/new/

https://reviews.llvm.org/D99456

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


[PATCH] D99456: [C++2b] Support size_t literals

2021-03-29 Thread Anton Bikineev via Phabricator via cfe-commits
AntonBikineev updated this revision to Diff 333972.
AntonBikineev marked an inline comment as done.
AntonBikineev added a comment.

Address comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99456/new/

https://reviews.llvm.org/D99456

Files:
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Lex/LiteralSupport.h
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Lex/LiteralSupport.cpp
  clang/lib/Lex/PPExpressions.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Lexer/cxx-features.cpp
  clang/test/Lexer/size_t-literal.cpp
  clang/test/SemaCXX/cxx1y-user-defined-literals.cpp
  clang/test/SemaCXX/size_t-literal.cpp

Index: clang/test/SemaCXX/size_t-literal.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/size_t-literal.cpp
@@ -0,0 +1,68 @@
+// RUN: %clang_cc1 -std=c++2b -Wc++2b-extensions -fsyntax-only -verify=cxx2b %s
+// RUN: %clang_cc1 -std=c++20 -Wc++2b-extensions -fsyntax-only -verify=cxx20 %s
+// RUN: %clang_cc1 -x c -std=c11 -fsyntax-only -verify=c11 %s
+
+#ifdef __cplusplus
+
+typedef __SIZE_TYPE__ size_t;
+// Assume ptrdiff_t is the signed integer type corresponding to size_t.
+typedef __PTRDIFF_TYPE__ ssize_t;
+
+template 
+struct is_same { static constexpr bool value = false; };
+
+template 
+struct is_same { static constexpr bool value = true; };
+
+// cxx2b-no-diagnostics
+
+void SSizeT() {
+  auto a1 = 1z; // cxx20-warning {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a2 = 1Z; // cxx20-warning {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+}
+
+void SizeT() {
+  auto a1 = 1uz; // cxx20-warning {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a2 = 1uZ; // cxx20-warning {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a3 = 1Uz; // cxx20-warning {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a4 = 1UZ; // cxx20-warning {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a5 = 1zu; // cxx20-warning {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a6 = 1Zu; // cxx20-warning {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a7 = 1zU; // cxx20-warning {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+
+  auto a8 = 1ZU; // cxx20-warning {{'size_t' suffix for literals is a C++2b extension}}
+  static_assert(is_same::value);
+}
+
+#else
+
+void f() {
+  (void)1z;  // c11-error {{'size_t' suffix for literals is a C++2b feature}}
+  (void)1Z;  // c11-error {{'size_t' suffix for literals is a C++2b feature}}
+  (void)1uz; // c11-error {{'size_t' suffix for literals is a C++2b feature}}
+  (void)1uZ; // c11-error {{'size_t' suffix for literals is a C++2b feature}}
+  (void)1Uz; // c11-error {{'size_t' suffix for literals is a C++2b feature}}
+  (void)1UZ; // c11-error {{'size_t' suffix for literals is a C++2b feature}}
+  (void)1zu; // c11-error {{'size_t' suffix for literals is a C++2b feature}}
+  (void)1Zu; // c11-error {{'size_t' suffix for literals is a C++2b feature}}
+  (void)1zU; // c11-error {{'size_t' suffix for literals is a C++2b feature}}
+  (void)1ZU; // c11-error {{'size_t' suffix for literals is a C++2b feature}}
+}
+
+#endif
Index: clang/test/SemaCXX/cxx1y-user-defined-literals.cpp
===
--- clang/test/SemaCXX/cxx1y-user-defined-literals.cpp
+++ clang/test/SemaCXX/cxx1y-user-defined-literals.cpp
@@ -34,7 +34,7 @@
 string s = "foo"s;
 char error = 'x's; // expected-error {{invalid suffix}} expected-error {{expected ';'}}
 
-int _1z = 1z; // expected-error {{invalid suffix}}
+int _1y = 1y; // expected-error {{invalid suffix}}
 int _1b = 1b; // expected-error {{invalid digit}}
 
 complex cf1 = 1if, cf2 = 2.if, cf3 = 0x3if;
Index: clang/test/Lexer/size_t-literal.cpp
===
--- /dev/null
+++ clang/test/Lexer/size_t-literal.cpp
@@ -0,0 +1,161 @@
+// RUN: %clang_cc1 -std=c++2b -fsyntax-only -verify %s
+
+#if 1z != 1
+#error "size_t suffix must be recognized by preprocessor"
+#endif
+#if 1uz != 1
+#error "size_t suffix must be recognized by preprocessor"
+#endif
+
+void ValidSuffix() {
+  // Decimal literals.
+  {
+auto a1 = 1z;
+auto a2 = 1Z;
+
+auto a3 = 1uz;
+auto a4 = 1uZ;
+auto a5 = 1Uz;
+auto a6 = 1UZ;
+
+auto a7 = 1zu;
+auto a8 = 1Zu;
+auto a9 = 1zU;
+auto a10 = 1ZU;
+
+auto a11 = 1'2z;
+auto a12 = 1'2Z;
+  }
+  // Hexadecimal literals.
+  {
+auto a1 = 0x1z;
+auto a2 = 0x1Z;
+
+auto a3 = 0x1uz;
+auto a4 = 0x1uZ;
+auto a5 = 0x1Uz;
+auto a6 = 0x1UZ;
+

[PATCH] D99456: [C++2b] Support size_t literals

2021-03-29 Thread Anton Bikineev via Phabricator via cfe-commits
AntonBikineev marked 9 inline comments as done.
AntonBikineev added a comment.

Thanks Aaron for taking a look! Addressed the comments. I also hope it's okay 
to test preprocessor in the same test (test/Lexer/size_t-literal.cpp).




Comment at: clang/lib/Sema/SemaExpr.cpp:3911
+  if (Literal.isSizeT) {
+assert(Ty.isNull() && "size_t literals can't be Microsoft literals");
+unsigned SizeTSize = Context.getTargetInfo().getTypeWidth(

aaron.ballman wrote:
> The assert message doesn't seem to match the predicate -- why does a null 
> qualtype imply it's a microsoft literal?
Hm, agree, that's probably misleading. I've tried to check that the previous 
branch couldn't be taken if this one has been. I think 
"assert(!Literal.MicrosoftInteger && ...);" would make more sense.



Comment at: clang/test/SemaCXX/size_t-literal.cpp:14-16
+#if __cplusplus >= 202101L
+//  expected-no-diagnostics
+#endif

aaron.ballman wrote:
> Rather than check `__cplusplus` like this, I think the RUN lines should 
> specify a verify prefix. e.g., `-verify=cxx2b` and then use 
> `cxx2b-no-diagnostics` and `-verify=cxx20` and then use `cxx20-warning {{}}`.
Good idea, thanks! That has made the test much cleaner.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99456/new/

https://reviews.llvm.org/D99456

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


[PATCH] D99456: [C++2b] Support size_t literals

2021-03-29 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman requested changes to this revision.
aaron.ballman added a comment.
This revision now requires changes to proceed.

Thanks for working on this! I think the direction is good in general, but I 
think we should also add tests for use in the preprocessor (`#if 1z == 1`, etc) 
as well as tests for the behavior in C.




Comment at: clang/include/clang/Basic/DiagnosticCommonKinds.td:191
+def ext_cxx2b_size_t_suffix : Extension<
+  "size_t suffix for literals is a C++2b extension">,
+  InGroup;





Comment at: clang/include/clang/Lex/LiteralSupport.h:66
   bool isLongLong : 1;
+  bool isSizeT : 1; // C++2b's z/uz size_t literals
   bool isHalf : 1;  // 1.0h





Comment at: clang/lib/Frontend/InitPreprocessor.cpp:593-595
+  if (LangOpts.CPlusPlus2b) {
+Builder.defineMacro("__cpp_size_t_suffix", "202011L");
+  }





Comment at: clang/lib/Lex/LiteralSupport.cpp:682
+break; // invalid for floats.
+  if (isMicrosoftInteger)
+break; // invalid for Microsoft integers.





Comment at: clang/lib/Lex/PPExpressions.cpp:325-327
+if (!PP.getLangOpts().CPlusPlus2b && Literal.isSizeT) {
+  PP.Diag(PeekTok, diag::ext_cxx2b_size_t_suffix);
+}





Comment at: clang/lib/Lex/PPExpressions.cpp:326
+if (!PP.getLangOpts().CPlusPlus2b && Literal.isSizeT) {
+  PP.Diag(PeekTok, diag::ext_cxx2b_size_t_suffix);
+}

This feature is specific to C++ and needs some sort of diagnostic in C. There 
is not currently a WG14 proposal for this literal suffix, so I think this 
should be an error in that case rather than a warning.



Comment at: clang/lib/Sema/SemaExpr.cpp:3871-3873
+if (!getLangOpts().CPlusPlus2b && Literal.isSizeT) {
+  Diag(Tok.getLocation(), diag::ext_cxx2b_size_t_suffix);
+}





Comment at: clang/lib/Sema/SemaExpr.cpp:3872
+if (!getLangOpts().CPlusPlus2b && Literal.isSizeT) {
+  Diag(Tok.getLocation(), diag::ext_cxx2b_size_t_suffix);
+}

Same diagnostic needs for C here as above.



Comment at: clang/lib/Sema/SemaExpr.cpp:3911
+  if (Literal.isSizeT) {
+assert(Ty.isNull() && "size_t literals can't be Microsoft literals");
+unsigned SizeTSize = Context.getTargetInfo().getTypeWidth(

The assert message doesn't seem to match the predicate -- why does a null 
qualtype imply it's a microsoft literal?



Comment at: clang/test/SemaCXX/size_t-literal.cpp:14-16
+#if __cplusplus >= 202101L
+//  expected-no-diagnostics
+#endif

Rather than check `__cplusplus` like this, I think the RUN lines should specify 
a verify prefix. e.g., `-verify=cxx2b` and then use `cxx2b-no-diagnostics` and 
`-verify=cxx20` and then use `cxx20-warning {{}}`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99456/new/

https://reviews.llvm.org/D99456

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


[PATCH] D99456: [C++2b] Support size_t literals

2021-03-29 Thread Anton Bikineev via Phabricator via cfe-commits
AntonBikineev updated this revision to Diff 333811.
AntonBikineev added a comment.

Fix formatting


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99456/new/

https://reviews.llvm.org/D99456

Files:
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Lex/LiteralSupport.h
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Lex/LiteralSupport.cpp
  clang/lib/Lex/PPExpressions.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Lexer/cxx-features.cpp
  clang/test/Lexer/size_t-literal.cpp
  clang/test/SemaCXX/cxx1y-user-defined-literals.cpp
  clang/test/SemaCXX/size_t-literal.cpp

Index: clang/test/SemaCXX/size_t-literal.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/size_t-literal.cpp
@@ -0,0 +1,80 @@
+// RUN: %clang_cc1 -std=c++2b -Werror=c++2b-extensions -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++20 -Werror=c++2b-extensions -fsyntax-only -verify %s
+
+typedef __SIZE_TYPE__ size_t;
+// Assume ptrdiff_t is the signed integer type corresponding to size_t.
+typedef __PTRDIFF_TYPE__ ssize_t;
+
+template 
+struct is_same { static constexpr bool value = false; };
+
+template 
+struct is_same { static constexpr bool value = true; };
+
+#if __cplusplus >= 202101L
+//  expected-no-diagnostics
+#endif
+
+void SSizeT() {
+  auto a1 = 1z;
+#if __cplusplus < 202101L
+  // expected-error@-2 {{size_t suffix for literals is a C++2b extension}}
+#endif
+  static_assert(is_same::value);
+
+  auto a2 = 1Z;
+#if __cplusplus < 202101L
+  // expected-error@-2 {{size_t suffix for literals is a C++2b extension}}
+#endif
+  static_assert(is_same::value);
+}
+
+void SizeT() {
+  auto a1 = 1uz;
+#if __cplusplus < 202101L
+  // expected-error@-2 {{size_t suffix for literals is a C++2b extension}}
+#endif
+  static_assert(is_same::value);
+
+  auto a2 = 1uZ;
+#if __cplusplus < 202101L
+  // expected-error@-2 {{size_t suffix for literals is a C++2b extension}}
+#endif
+  static_assert(is_same::value);
+
+  auto a3 = 1Uz;
+#if __cplusplus < 202101L
+  // expected-error@-2 {{size_t suffix for literals is a C++2b extension}}
+#endif
+  static_assert(is_same::value);
+
+  auto a4 = 1UZ;
+#if __cplusplus < 202101L
+  // expected-error@-2 {{size_t suffix for literals is a C++2b extension}}
+#endif
+  static_assert(is_same::value);
+
+  auto a5 = 1zu;
+#if __cplusplus < 202101L
+  // expected-error@-2 {{size_t suffix for literals is a C++2b extension}}
+#endif
+  static_assert(is_same::value);
+
+  auto a6 = 1Zu;
+#if __cplusplus < 202101L
+  // expected-error@-2 {{size_t suffix for literals is a C++2b extension}}
+#endif
+  static_assert(is_same::value);
+
+  auto a7 = 1zU;
+#if __cplusplus < 202101L
+  // expected-error@-2 {{size_t suffix for literals is a C++2b extension}}
+#endif
+  static_assert(is_same::value);
+
+  auto a8 = 1ZU;
+#if __cplusplus < 202101L
+  // expected-error@-2 {{size_t suffix for literals is a C++2b extension}}
+#endif
+  static_assert(is_same::value);
+}
Index: clang/test/SemaCXX/cxx1y-user-defined-literals.cpp
===
--- clang/test/SemaCXX/cxx1y-user-defined-literals.cpp
+++ clang/test/SemaCXX/cxx1y-user-defined-literals.cpp
@@ -34,7 +34,7 @@
 string s = "foo"s;
 char error = 'x's; // expected-error {{invalid suffix}} expected-error {{expected ';'}}
 
-int _1z = 1z; // expected-error {{invalid suffix}}
+int _1y = 1y; // expected-error {{invalid suffix}}
 int _1b = 1b; // expected-error {{invalid digit}}
 
 complex cf1 = 1if, cf2 = 2.if, cf3 = 0x3if;
Index: clang/test/Lexer/size_t-literal.cpp
===
--- /dev/null
+++ clang/test/Lexer/size_t-literal.cpp
@@ -0,0 +1,154 @@
+// RUN: %clang_cc1 -std=c++2b -fsyntax-only -verify %s
+
+void ValidSuffix() {
+  // Decimal literals.
+  {
+auto a1 = 1z;
+auto a2 = 1Z;
+
+auto a3 = 1uz;
+auto a4 = 1uZ;
+auto a5 = 1Uz;
+auto a6 = 1UZ;
+
+auto a7 = 1zu;
+auto a8 = 1Zu;
+auto a9 = 1zU;
+auto a10 = 1ZU;
+
+auto a11 = 1'2z;
+auto a12 = 1'2Z;
+  }
+  // Hexadecimal literals.
+  {
+auto a1 = 0x1z;
+auto a2 = 0x1Z;
+
+auto a3 = 0x1uz;
+auto a4 = 0x1uZ;
+auto a5 = 0x1Uz;
+auto a6 = 0x1UZ;
+
+auto a7 = 0x1zu;
+auto a8 = 0x1Zu;
+auto a9 = 0x1zU;
+auto a10 = 0x1ZU;
+
+auto a11 = 0x1'2z;
+auto a12 = 0x1'2Z;
+  }
+  // Binary literals.
+  {
+auto a1 = 0b1z;
+auto a2 = 0b1Z;
+
+auto a3 = 0b1uz;
+auto a4 = 0b1uZ;
+auto a5 = 0b1Uz;
+auto a6 = 0b1UZ;
+
+auto a7 = 0b1zu;
+auto a8 = 0b1Zu;
+auto a9 = 0b1zU;
+auto a10 = 0b1ZU;
+
+auto a11 = 0b1'1z;
+auto a12 = 0b1'1Z;
+  }
+  // Octal literals.
+  {
+auto a1 = 01z;
+auto a2 = 01Z;
+
+auto a3 = 01uz;
+auto a4 = 01uZ;
+auto a5 = 01Uz;
+auto a6 = 01UZ;
+
+auto a7 = 01zu;
+auto a8 = 01Zu;
+auto a9 = 01zU;
+auto a10 = 

[PATCH] D99456: [C++2b] Support size_t literals

2021-03-27 Thread Anton Bikineev via Phabricator via cfe-commits
AntonBikineev updated this revision to Diff 333681.
AntonBikineev added a comment.

Fix failing tests


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99456/new/

https://reviews.llvm.org/D99456

Files:
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Lex/LiteralSupport.h
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Lex/LiteralSupport.cpp
  clang/lib/Lex/PPExpressions.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Lexer/cxx-features.cpp
  clang/test/Lexer/size_t-literal.cpp
  clang/test/SemaCXX/cxx1y-user-defined-literals.cpp
  clang/test/SemaCXX/size_t-literal.cpp

Index: clang/test/SemaCXX/size_t-literal.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/size_t-literal.cpp
@@ -0,0 +1,80 @@
+// RUN: %clang_cc1 -std=c++2b -Werror=c++2b-extensions -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++20 -Werror=c++2b-extensions -fsyntax-only -verify %s
+
+typedef __SIZE_TYPE__ size_t;
+// Assume ptrdiff_t is the signed integer type corresponding to size_t.
+typedef __PTRDIFF_TYPE__ ssize_t;
+
+template 
+struct is_same { static constexpr bool value = false; };
+
+template 
+struct is_same { static constexpr bool value = true; };
+
+#if __cplusplus >= 202101L
+//  expected-no-diagnostics
+#endif
+
+void SSizeT() {
+  auto a1 = 1z;
+#if __cplusplus < 202101L
+  // expected-error@-2 {{size_t suffix for literals is a C++2b extension}}
+#endif
+  static_assert(is_same::value);
+
+  auto a2 = 1Z;
+#if __cplusplus < 202101L
+  // expected-error@-2 {{size_t suffix for literals is a C++2b extension}}
+#endif
+  static_assert(is_same::value);
+}
+
+void SizeT() {
+  auto a1 = 1uz;
+#if __cplusplus < 202101L
+  // expected-error@-2 {{size_t suffix for literals is a C++2b extension}}
+#endif
+  static_assert(is_same::value);
+
+  auto a2 = 1uZ;
+#if __cplusplus < 202101L
+  // expected-error@-2 {{size_t suffix for literals is a C++2b extension}}
+#endif
+  static_assert(is_same::value);
+
+  auto a3 = 1Uz;
+#if __cplusplus < 202101L
+  // expected-error@-2 {{size_t suffix for literals is a C++2b extension}}
+#endif
+  static_assert(is_same::value);
+
+  auto a4 = 1UZ;
+#if __cplusplus < 202101L
+  // expected-error@-2 {{size_t suffix for literals is a C++2b extension}}
+#endif
+  static_assert(is_same::value);
+
+  auto a5 = 1zu;
+#if __cplusplus < 202101L
+  // expected-error@-2 {{size_t suffix for literals is a C++2b extension}}
+#endif
+  static_assert(is_same::value);
+
+  auto a6 = 1Zu;
+#if __cplusplus < 202101L
+  // expected-error@-2 {{size_t suffix for literals is a C++2b extension}}
+#endif
+  static_assert(is_same::value);
+
+  auto a7 = 1zU;
+#if __cplusplus < 202101L
+  // expected-error@-2 {{size_t suffix for literals is a C++2b extension}}
+#endif
+  static_assert(is_same::value);
+
+  auto a8 = 1ZU;
+#if __cplusplus < 202101L
+  // expected-error@-2 {{size_t suffix for literals is a C++2b extension}}
+#endif
+  static_assert(is_same::value);
+}
Index: clang/test/SemaCXX/cxx1y-user-defined-literals.cpp
===
--- clang/test/SemaCXX/cxx1y-user-defined-literals.cpp
+++ clang/test/SemaCXX/cxx1y-user-defined-literals.cpp
@@ -34,7 +34,7 @@
 string s = "foo"s;
 char error = 'x's; // expected-error {{invalid suffix}} expected-error {{expected ';'}}
 
-int _1z = 1z; // expected-error {{invalid suffix}}
+int _1y = 1y; // expected-error {{invalid suffix}}
 int _1b = 1b; // expected-error {{invalid digit}}
 
 complex cf1 = 1if, cf2 = 2.if, cf3 = 0x3if;
Index: clang/test/Lexer/size_t-literal.cpp
===
--- /dev/null
+++ clang/test/Lexer/size_t-literal.cpp
@@ -0,0 +1,154 @@
+// RUN: %clang_cc1 -std=c++2b -fsyntax-only -verify %s
+
+void ValidSuffix() {
+  // Decimal literals.
+  {
+auto a1 = 1z;
+auto a2 = 1Z;
+
+auto a3 = 1uz;
+auto a4 = 1uZ;
+auto a5 = 1Uz;
+auto a6 = 1UZ;
+
+auto a7 = 1zu;
+auto a8 = 1Zu;
+auto a9 = 1zU;
+auto a10 = 1ZU;
+
+auto a11 = 1'2z;
+auto a12 = 1'2Z;
+  }
+  // Hexadecimal literals.
+  {
+auto a1 = 0x1z;
+auto a2 = 0x1Z;
+
+auto a3 = 0x1uz;
+auto a4 = 0x1uZ;
+auto a5 = 0x1Uz;
+auto a6 = 0x1UZ;
+
+auto a7 = 0x1zu;
+auto a8 = 0x1Zu;
+auto a9 = 0x1zU;
+auto a10 = 0x1ZU;
+
+auto a11 = 0x1'2z;
+auto a12 = 0x1'2Z;
+  }
+  // Binary literals.
+  {
+auto a1 = 0b1z;
+auto a2 = 0b1Z;
+
+auto a3 = 0b1uz;
+auto a4 = 0b1uZ;
+auto a5 = 0b1Uz;
+auto a6 = 0b1UZ;
+
+auto a7 = 0b1zu;
+auto a8 = 0b1Zu;
+auto a9 = 0b1zU;
+auto a10 = 0b1ZU;
+
+auto a11 = 0b1'1z;
+auto a12 = 0b1'1Z;
+  }
+  // Octal literals.
+  {
+auto a1 = 01z;
+auto a2 = 01Z;
+
+auto a3 = 01uz;
+auto a4 = 01uZ;
+auto a5 = 01Uz;
+auto a6 = 01UZ;
+
+auto a7 = 01zu;
+auto a8 = 01Zu;
+auto a9 = 01zU;
+auto 

[PATCH] D99456: [C++2b] Support size_t literals

2021-03-27 Thread Anton Bikineev via Phabricator via cfe-commits
AntonBikineev created this revision.
AntonBikineev added a reviewer: rsmith.
AntonBikineev requested review of this revision.
Herald added a project: clang.

This adds support for C++2b z/uz suffixes for size_t literals (P0330).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99456

Files:
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Lex/LiteralSupport.h
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Lex/LiteralSupport.cpp
  clang/lib/Lex/PPExpressions.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Lexer/cxx-features.cpp
  clang/test/Lexer/size_t-literal.cpp
  clang/test/SemaCXX/size_t-literal.cpp

Index: clang/test/SemaCXX/size_t-literal.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/size_t-literal.cpp
@@ -0,0 +1,80 @@
+// RUN: %clang_cc1 -std=c++2b -Werror=c++2b-extensions -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++20 -Werror=c++2b-extensions -fsyntax-only -verify %s
+
+typedef __SIZE_TYPE__ size_t;
+// Assume ptrdiff_t is the signed integer type corresponding to size_t.
+typedef __PTRDIFF_TYPE__ ssize_t;
+
+template 
+struct is_same { static constexpr bool value = false; };
+
+template 
+struct is_same { static constexpr bool value = true; };
+
+#if __cplusplus >= 202101L
+//  expected-no-diagnostics
+#endif
+
+void SSizeT() {
+  auto a1 = 1z;
+#if __cplusplus < 202101L
+  // expected-error@-2 {{size_t suffix for literals is a C++2b extension}}
+#endif
+  static_assert(is_same::value);
+
+  auto a2 = 1Z;
+#if __cplusplus < 202101L
+  // expected-error@-2 {{size_t suffix for literals is a C++2b extension}}
+#endif
+  static_assert(is_same::value);
+}
+
+void SizeT() {
+  auto a1 = 1uz;
+#if __cplusplus < 202101L
+  // expected-error@-2 {{size_t suffix for literals is a C++2b extension}}
+#endif
+  static_assert(is_same::value);
+
+  auto a2 = 1uZ;
+#if __cplusplus < 202101L
+  // expected-error@-2 {{size_t suffix for literals is a C++2b extension}}
+#endif
+  static_assert(is_same::value);
+
+  auto a3 = 1Uz;
+#if __cplusplus < 202101L
+  // expected-error@-2 {{size_t suffix for literals is a C++2b extension}}
+#endif
+  static_assert(is_same::value);
+
+  auto a4 = 1UZ;
+#if __cplusplus < 202101L
+  // expected-error@-2 {{size_t suffix for literals is a C++2b extension}}
+#endif
+  static_assert(is_same::value);
+
+  auto a5 = 1zu;
+#if __cplusplus < 202101L
+  // expected-error@-2 {{size_t suffix for literals is a C++2b extension}}
+#endif
+  static_assert(is_same::value);
+
+  auto a6 = 1Zu;
+#if __cplusplus < 202101L
+  // expected-error@-2 {{size_t suffix for literals is a C++2b extension}}
+#endif
+  static_assert(is_same::value);
+
+  auto a7 = 1zU;
+#if __cplusplus < 202101L
+  // expected-error@-2 {{size_t suffix for literals is a C++2b extension}}
+#endif
+  static_assert(is_same::value);
+
+  auto a8 = 1ZU;
+#if __cplusplus < 202101L
+  // expected-error@-2 {{size_t suffix for literals is a C++2b extension}}
+#endif
+  static_assert(is_same::value);
+}
Index: clang/test/Lexer/size_t-literal.cpp
===
--- /dev/null
+++ clang/test/Lexer/size_t-literal.cpp
@@ -0,0 +1,154 @@
+// RUN: %clang_cc1 -std=c++2b -fsyntax-only -verify -ferror-limit=0 %s
+
+void ValidSuffix() {
+  // Decimal literals.
+  {
+auto a1 = 1z;
+auto a2 = 1Z;
+
+auto a3 = 1uz;
+auto a4 = 1uZ;
+auto a5 = 1Uz;
+auto a6 = 1UZ;
+
+auto a7 = 1zu;
+auto a8 = 1Zu;
+auto a9 = 1zU;
+auto a10 = 1ZU;
+
+auto a11 = 1'2z;
+auto a12 = 1'2Z;
+  }
+  // Hexadecimal literals.
+  {
+auto a1 = 0x1z;
+auto a2 = 0x1Z;
+
+auto a3 = 0x1uz;
+auto a4 = 0x1uZ;
+auto a5 = 0x1Uz;
+auto a6 = 0x1UZ;
+
+auto a7 = 0x1zu;
+auto a8 = 0x1Zu;
+auto a9 = 0x1zU;
+auto a10 = 0x1ZU;
+
+auto a11 = 0x1'2z;
+auto a12 = 0x1'2Z;
+  }
+  // Binary literals.
+  {
+auto a1 = 0b1z;
+auto a2 = 0b1Z;
+
+auto a3 = 0b1uz;
+auto a4 = 0b1uZ;
+auto a5 = 0b1Uz;
+auto a6 = 0b1UZ;
+
+auto a7 = 0b1zu;
+auto a8 = 0b1Zu;
+auto a9 = 0b1zU;
+auto a10 = 0b1ZU;
+
+auto a11 = 0b1'1z;
+auto a12 = 0b1'1Z;
+  }
+  // Octal literals.
+  {
+auto a1 = 01z;
+auto a2 = 01Z;
+
+auto a3 = 01uz;
+auto a4 = 01uZ;
+auto a5 = 01Uz;
+auto a6 = 01UZ;
+
+auto a7 = 01zu;
+auto a8 = 01Zu;
+auto a9 = 01zU;
+auto a10 = 01ZU;
+
+auto a11 = 0'1z;
+auto a12 = 0'1Z;
+  }
+}
+
+void InvalidSuffix() {
+  // Long.
+  {
+auto a1 = 1lz; // expected-error {{invalid suffix}}
+auto a2 = 1lZ; // expected-error {{invalid suffix}}
+auto a3 = 1Lz; // expected-error {{invalid suffix}}
+auto a4 = 1LZ; // expected-error {{invalid suffix}}
+
+auto a5 = 1zl; // expected-error {{invalid suffix}}
+auto a6 = 1Zl; // expected-error {{invalid suffix}}
+auto a7 = 1zL; // expected-error {{invalid suffix}}
+auto a8 = 1ZL; //