[clang] 0e8afdd - [Clang] NFC: Remove duplicated variable def in CheckLValueConstantExpression

2022-09-10 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-09-10T19:10:23+02:00
New Revision: 0e8afddaa15fda1d50888b44695eecb89c0b1c0b

URL: 
https://github.com/llvm/llvm-project/commit/0e8afddaa15fda1d50888b44695eecb89c0b1c0b
DIFF: 
https://github.com/llvm/llvm-project/commit/0e8afddaa15fda1d50888b44695eecb89c0b1c0b.diff

LOG: [Clang] NFC: Remove duplicated variable def in 
CheckLValueConstantExpression

Added: 


Modified: 
clang/lib/AST/ExprConstant.cpp

Removed: 




diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index a5568e0158e33..26822a64b14c6 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -2174,12 +2174,10 @@ static bool CheckLValueConstantExpression(EvalInfo 
&Info, SourceLocation Loc,
   // assumed to be global here.
   if (!IsGlobalLValue(Base)) {
 if (Info.getLangOpts().CPlusPlus11) {
-  const ValueDecl *VD = Base.dyn_cast();
   Info.FFDiag(Loc, diag::note_constexpr_non_global, 1)
-<< IsReferenceType << !Designator.Entries.empty()
-<< !!VD << VD;
-
-  auto *VarD = dyn_cast_or_null(VD);
+  << IsReferenceType << !Designator.Entries.empty() << !!BaseVD
+  << BaseVD;
+  auto *VarD = dyn_cast_or_null(BaseVD);
   if (VarD && VarD->isConstexpr()) {
 // Non-static local constexpr variables have unintuitive semantics:
 //   constexpr int a = 1;



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


[clang] 7eead18 - [Clang] NFC: Make UnqualifiedId::Kind private for consistency.

2022-09-12 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-09-12T19:14:06+02:00
New Revision: 7eead180b92dcff7eaf9d71df14e33936ec4dbe5

URL: 
https://github.com/llvm/llvm-project/commit/7eead180b92dcff7eaf9d71df14e33936ec4dbe5
DIFF: 
https://github.com/llvm/llvm-project/commit/7eead180b92dcff7eaf9d71df14e33936ec4dbe5.diff

LOG: [Clang] NFC: Make UnqualifiedId::Kind private for consistency.

Differential Revision: https://reviews.llvm.org/D133703

Added: 


Modified: 
clang/include/clang/Sema/DeclSpec.h
clang/lib/Sema/DeclSpec.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclCXX.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/DeclSpec.h 
b/clang/include/clang/Sema/DeclSpec.h
index bb49151c77248..1aa335b8b9b7a 100644
--- a/clang/include/clang/Sema/DeclSpec.h
+++ b/clang/include/clang/Sema/DeclSpec.h
@@ -964,10 +964,10 @@ class UnqualifiedId {
   UnqualifiedId(const UnqualifiedId &Other) = delete;
   const UnqualifiedId &operator=(const UnqualifiedId &) = delete;
 
-public:
   /// Describes the kind of unqualified-id parsed.
   UnqualifiedIdKind Kind;
 
+public:
   struct OFI {
 /// The kind of overloaded operator.
 OverloadedOperatorKind Operator;

diff  --git a/clang/lib/Sema/DeclSpec.cpp b/clang/lib/Sema/DeclSpec.cpp
index 6875d3d97c282..0c4b79d8b9642 100644
--- a/clang/lib/Sema/DeclSpec.cpp
+++ b/clang/lib/Sema/DeclSpec.cpp
@@ -413,7 +413,7 @@ bool Declarator::isDeclarationOfFunction() const {
 bool Declarator::isStaticMember() {
   assert(getContext() == DeclaratorContext::Member);
   return getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static ||
- (getName().Kind == UnqualifiedIdKind::IK_OperatorFunctionId &&
+ (getName().getKind() == UnqualifiedIdKind::IK_OperatorFunctionId &&
   CXXMethodDecl::isStaticOverloadedOperator(
   getName().OperatorFunctionId.Operator));
 }

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 6e94da4a115eb..9d0e6769f0875 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -6586,8 +6586,8 @@ Sema::ActOnTypedefDeclarator(Scope* S, Declarator& D, 
DeclContext* DC,
 Diag(D.getDeclSpec().getConstexprSpecLoc(), diag::err_invalid_constexpr)
 << 1 << static_cast(D.getDeclSpec().getConstexprSpecifier());
 
-  if (D.getName().Kind != UnqualifiedIdKind::IK_Identifier) {
-if (D.getName().Kind == UnqualifiedIdKind::IK_DeductionGuideName)
+  if (D.getName().getKind() != UnqualifiedIdKind::IK_Identifier) {
+if (D.getName().getKind() == UnqualifiedIdKind::IK_DeductionGuideName)
   Diag(D.getName().StartLocation,
diag::err_deduction_guide_invalid_specifier)
   << "typedef";

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 9a2ee556fc2e0..6463d0678007d 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -13009,7 +13009,7 @@ Decl *Sema::ActOnAliasDeclaration(Scope *S, 
AccessSpecifier AS,
 Previous.clear();
   }
 
-  assert(Name.Kind == UnqualifiedIdKind::IK_Identifier &&
+  assert(Name.getKind() == UnqualifiedIdKind::IK_Identifier &&
  "name in alias declaration must be an identifier");
   TypeAliasDecl *NewTD = TypeAliasDecl::Create(Context, CurContext, UsingLoc,
Name.StartLocation,



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


[clang] e70d2a4 - [Clang] Add the list of papers approved in Kona

2023-11-11 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-11-11T09:03:49-10:00
New Revision: e70d2a45ea00241035143394be28604390341f0e

URL: 
https://github.com/llvm/llvm-project/commit/e70d2a45ea00241035143394be28604390341f0e
DIFF: 
https://github.com/llvm/llvm-project/commit/e70d2a45ea00241035143394be28604390341f0e.diff

LOG: [Clang] Add the list of papers approved in Kona

This is a rather short list that does not include the list
of resolvded CWG issues, which is rather long (P3046).

Some of the links are currently invalid as they have yet to be
publicly published.

Added: 


Modified: 
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index e2cf9ab25465214..621439d0bae9666 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -147,6 +147,23 @@ C++2c implementation status
   https://wg21.link/P2169R4";>P2169R4
   Clang 18
  
+ 
+ 
+  Template parameter initialization
+  https://wg21.link/P2308R1";>P2308R1 (DR)
+  No
+ 
+ 
+  Pack Indexing
+  https://wg21.link/P2662R3";>P2662R3
+  No
+ 
+ 
+  Remove Deprecated Arithmetic Conversion on Enumerations
+  https://wg21.link/P2864R2";>P2864R2
+  No
+ 
+
 
 
 



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


[clang] 4142a64 - [Clang] Fix compilation with GCC 7.5

2023-11-28 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-11-28T12:05:34+01:00
New Revision: 4142a64ae3ca4856e6a5ffae9e40014ef5cf9db5

URL: 
https://github.com/llvm/llvm-project/commit/4142a64ae3ca4856e6a5ffae9e40014ef5cf9db5
DIFF: 
https://github.com/llvm/llvm-project/commit/4142a64ae3ca4856e6a5ffae9e40014ef5cf9db5.diff

LOG: [Clang] Fix compilation with GCC 7.5

Fixes #73628

Added: 


Modified: 
clang/lib/Sema/SemaDeclCXX.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 213e1f0a728c204..7385eac48d8c895 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -17299,7 +17299,7 @@ bool Sema::EvaluateStaticAssertMessageAsString(Expr 
*Message,
 OverloadCandidateSet::CSK_Normal);
 if (MemberLookup.empty())
   return std::nullopt;
-return MemberLookup;
+return std::move(MemberLookup);
   };
 
   bool SizeNotFound, DataNotFound;



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


[clang] 19e2174 - Revert "[Clang] Eagerly instantiate used constexpr function upon definition. (#73463)"

2023-12-02 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-12-02T13:35:27+01:00
New Revision: 19e2174d54356e1654583a65ff9cd38eccf797ee

URL: 
https://github.com/llvm/llvm-project/commit/19e2174d54356e1654583a65ff9cd38eccf797ee
DIFF: 
https://github.com/llvm/llvm-project/commit/19e2174d54356e1654583a65ff9cd38eccf797ee.diff

LOG: Revert "[Clang] Eagerly instantiate used constexpr function upon 
definition. (#73463)"

This reverts commit 030047c432cac133738be68fa0974f70e69dd58d.

Breaks Qt and is inconsistent with GCC.

See the following issue for details:

Fixes #74069

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/ExternalSemaSource.h
clang/include/clang/Sema/MultiplexExternalSemaSource.h
clang/include/clang/Sema/Sema.h
clang/include/clang/Serialization/ASTBitCodes.h
clang/include/clang/Serialization/ASTReader.h
clang/lib/Sema/MultiplexExternalSemaSource.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp

Removed: 
clang/test/PCH/instantiate-used-constexpr-function.cpp
clang/test/SemaTemplate/instantiate-used-constexpr-function.cpp



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 06796780f322..c7a948fd3fae 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -802,11 +802,6 @@ Bug Fixes to C++ Support
 - Fix crash when parsing nested requirement. Fixes:
   (`#73112 `_)
 
-- Clang now immediately instantiates function template specializations
-  at the end of the definition of the corresponding function template
-  when the definition appears after the first point of instantiation.
-  (`#73232 `_)
-
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.

diff  --git a/clang/include/clang/Sema/ExternalSemaSource.h 
b/clang/include/clang/Sema/ExternalSemaSource.h
index 8b41c5483458..22d1ee2df115 100644
--- a/clang/include/clang/Sema/ExternalSemaSource.h
+++ b/clang/include/clang/Sema/ExternalSemaSource.h
@@ -181,9 +181,6 @@ class ExternalSemaSource : public ExternalASTSource {
  SmallVectorImpl > &Pending) {}
 
-  virtual void ReadPendingInstantiationsOfConstexprEntity(
-  const NamedDecl *D, llvm::SmallSetVector &Decls){};
-
   /// Read the set of late parsed template functions for this source.
   ///
   /// The external source should insert its own late parsed template functions

diff  --git a/clang/include/clang/Sema/MultiplexExternalSemaSource.h 
b/clang/include/clang/Sema/MultiplexExternalSemaSource.h
index 6054ef39e54f..2bf91cb5212c 100644
--- a/clang/include/clang/Sema/MultiplexExternalSemaSource.h
+++ b/clang/include/clang/Sema/MultiplexExternalSemaSource.h
@@ -319,9 +319,6 @@ class MultiplexExternalSemaSource : public 
ExternalSemaSource {
   void ReadPendingInstantiations(
  SmallVectorImpl >& Pending) 
override;
 
-  virtual void ReadPendingInstantiationsOfConstexprEntity(
-  const NamedDecl *D, llvm::SmallSetVector &Decls) 
override;
-
   /// Read the set of late parsed template functions for this source.
   ///
   /// The external source should insert its own late parsed template functions

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 8b2ed6f7cd8c..e745c01ae0ae 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -59,7 +59,6 @@
 #include "clang/Sema/TypoCorrection.h"
 #include "clang/Sema/Weak.h"
 #include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/SmallBitVector.h"
 #include "llvm/ADT/SmallPtrSet.h"
@@ -10093,12 +10092,6 @@ class Sema final {
   /// but have not yet been performed.
   std::deque PendingInstantiations;
 
-  /// Track constexpr functions referenced before they are (lexically) defined.
-  /// The key is the pattern, associated with a list of specialisations that
-  /// need to be instantiated when the pattern is defined.
-  llvm::DenseMap>
-  PendingInstantiationsOfConstexprEntities;
-
   /// Queue of implicit template instantiations that cannot be performed
   /// eagerly.
   SmallVector LateParsedInstantiations;
@@ -10417,9 +10410,6 @@ class Sema final {
  bool Recursive = false,
  bool DefinitionRequired = false,
  bool AtEndOfTU = false);
-
-  void PerformPendingInstantiationsOfConstexprFunctions(FunctionDecl 
*Template);
-
   VarTemplateSpecializationDecl *BuildVarTemplateInstantiation(
   VarTemplateDecl *VarTemplate, VarDecl *FromVar,
   const TemplateArgumentList &TemplateArgList,

diff  --git a/clang/includ

[clang] 9d97247 - [clang] Fix color consistency in C paper tracking web page

2024-01-11 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2024-01-11T10:23:37+01:00
New Revision: 9d97247e26eaca29bf27c842e08bd983a34fab93

URL: 
https://github.com/llvm/llvm-project/commit/9d97247e26eaca29bf27c842e08bd983a34fab93
DIFF: 
https://github.com/llvm/llvm-project/commit/9d97247e26eaca29bf27c842e08bd983a34fab93.diff

LOG: [clang] Fix color consistency in C paper tracking web page

Added: 


Modified: 
clang/www/c_status.html

Removed: 




diff  --git a/clang/www/c_status.html b/clang/www/c_status.html
index fe56bc791ccbe1..b9e0650ddca242 100644
--- a/clang/www/c_status.html
+++ b/clang/www/c_status.html
@@ -9,7 +9,7 @@
 .none { background-color: #FF }
 .partial { background-color: #FFE0B0 }
 .unreleased { background-color: #99 }
-.unknown { background-color: #DDAEF7 }
+.unknown { background-color: #EBCAFE }
 .full { background-color: #CCFF99 }
 .na { background-color: #DD }
 :target { background-color: #BB; outline: #55 solid thin; }



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


[clang] 870b6d2 - Improve handling of static assert messages.

2022-06-28 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-06-28T22:26:00+02:00
New Revision: 870b6d21839707a3e4c40a29b526995f065a220f

URL: 
https://github.com/llvm/llvm-project/commit/870b6d21839707a3e4c40a29b526995f065a220f
DIFF: 
https://github.com/llvm/llvm-project/commit/870b6d21839707a3e4c40a29b526995f065a220f.diff

LOG: Improve handling of static assert messages.

Instead of dumping the string literal (which
quotes it and escape every non-ascii symbol),
we can use the content of the string when it is a
8 byte string.

Wide, UTF-8/UTF-16/32 strings are still completely
escaped, until we clarify how these entities should
behave (cf https://wg21.link/p2361).

`FormatDiagnostic` is modified to escape
non printable characters and invalid UTF-8.

This ensures that unicode characters, spaces and new
lines are properly rendered in static messages.
This make clang more consistent with other implementation
and fixes this tweet
https://twitter.com/jfbastien/status/1298307325443231744 :)

Of note, `PaddingChecker` did print out new lines that were
later removed by the diagnostic printing code.
To be consistent with its tests, the new lines are removed
from the diagnostic.

Unicode tables updated to both use the Unicode definitions
and the Unicode 14.0 data.

U+00AD SOFT HYPHEN is still considered a print character
to match existing practices in terminals, in addition of
being considered a formatting character as per Unicode.

Reviewed By: aaron.ballman, #clang-language-wg

Differential Revision: https://reviews.llvm.org/D108469

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Basic/Diagnostic.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/StaticAnalyzer/Checkers/PaddingChecker.cpp
clang/test/C/drs/dr0xx.c
clang/test/CXX/dcl.dcl/p4-0x.cpp
clang/test/CXX/expr/expr.prim/expr.prim.id/p3.cpp
clang/test/Lexer/null-character-in-literal.c
clang/test/Misc/diag-special-chars.c
clang/test/Misc/wrong-encoding.c
clang/test/PCH/cxx-static_assert.cpp
clang/test/Sema/static-assert.c
clang/test/SemaCXX/int-ptr-cast-SFINAE.cpp
clang/test/SemaCXX/static-assert.cpp
llvm/include/llvm/Support/Unicode.h
llvm/lib/Support/Unicode.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3e29987ad2631..815430839489d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -273,6 +273,8 @@ Improvements to Clang's diagnostics
 - When using class templates without arguments, clang now tells developers
   that template arguments are missing in certain contexts.
   This fixes `Issue 55962 
`_.
+- Printable Unicode characters within ``static_assert`` messages are no longer
+  escaped.
 
 Non-comprehensive list of changes in this release
 -

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 442088d078d98..843024c988ef6 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1527,9 +1527,9 @@ def err_static_assert_expression_is_not_constant : Error<
   "static_assert expression is not an integral constant expression">;
 def err_constexpr_if_condition_expression_is_not_constant : Error<
   "constexpr if condition is not a constant expression">;
-def err_static_assert_failed : Error<"static_assert failed%select{ %1|}0">;
+def err_static_assert_failed : Error<"static_assert failed%select{: %1|}0">;
 def err_static_assert_requirement_failed : Error<
-  "static_assert failed due to requirement '%0'%select{ %2|}1">;
+  "static_assert failed due to requirement '%0'%select{: %2 |}1">;
 
 def warn_consteval_if_always_true : Warning<
   "consteval if is always true in an %select{unevaluated|immediate}0 context">,

diff  --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp
index deb398756e373..dbe62ecb50d33 100644
--- a/clang/lib/Basic/Diagnostic.cpp
+++ b/clang/lib/Basic/Diagnostic.cpp
@@ -25,8 +25,9 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/CrashRecoveryContext.h"
-#include "llvm/Support/Locale.h"
+#include "llvm/Support/Unicode.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
@@ -803,6 +804,50 @@ FormatDiagnostic(SmallVectorImpl &OutStr) const {
   FormatDiagnostic(Diag.begin(), Diag.end(), OutStr);
 }
 
+/// pushEscapedString - Append Str to the diagnostic buffer,
+/// escaping non-printable characters and ill-formed code unit sequences.
+static void pushEscapedString(StringRef Str, SmallVectorImpl &OutStr) {
+  OutStr.reserve(OutStr.size() + Str.size());
+  auto *Begin = reinterpret_cast(Str.data());
+  llvm::raw_sv

[clang] a774ba7 - Revert "Improve handling of static assert messages."

2022-06-28 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-06-29T00:03:23+02:00
New Revision: a774ba7f60d1fef403b5507b1b1a7475d3684d71

URL: 
https://github.com/llvm/llvm-project/commit/a774ba7f60d1fef403b5507b1b1a7475d3684d71
DIFF: 
https://github.com/llvm/llvm-project/commit/a774ba7f60d1fef403b5507b1b1a7475d3684d71.diff

LOG: Revert "Improve handling of static assert messages."

This reverts commit 870b6d21839707a3e4c40a29b526995f065a220f.

This seems to break some libc++ tests, reverting while investigating

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Basic/Diagnostic.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/StaticAnalyzer/Checkers/PaddingChecker.cpp
clang/test/C/drs/dr0xx.c
clang/test/CXX/dcl.dcl/p4-0x.cpp
clang/test/CXX/expr/expr.prim/expr.prim.id/p3.cpp
clang/test/Lexer/null-character-in-literal.c
clang/test/Misc/diag-special-chars.c
clang/test/Misc/wrong-encoding.c
clang/test/PCH/cxx-static_assert.cpp
clang/test/Sema/static-assert.c
clang/test/SemaCXX/int-ptr-cast-SFINAE.cpp
clang/test/SemaCXX/static-assert.cpp
llvm/include/llvm/Support/Unicode.h
llvm/lib/Support/Unicode.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 815430839489d..3e29987ad2631 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -273,8 +273,6 @@ Improvements to Clang's diagnostics
 - When using class templates without arguments, clang now tells developers
   that template arguments are missing in certain contexts.
   This fixes `Issue 55962 
`_.
-- Printable Unicode characters within ``static_assert`` messages are no longer
-  escaped.
 
 Non-comprehensive list of changes in this release
 -

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 843024c988ef6..442088d078d98 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1527,9 +1527,9 @@ def err_static_assert_expression_is_not_constant : Error<
   "static_assert expression is not an integral constant expression">;
 def err_constexpr_if_condition_expression_is_not_constant : Error<
   "constexpr if condition is not a constant expression">;
-def err_static_assert_failed : Error<"static_assert failed%select{: %1|}0">;
+def err_static_assert_failed : Error<"static_assert failed%select{ %1|}0">;
 def err_static_assert_requirement_failed : Error<
-  "static_assert failed due to requirement '%0'%select{: %2 |}1">;
+  "static_assert failed due to requirement '%0'%select{ %2|}1">;
 
 def warn_consteval_if_always_true : Warning<
   "consteval if is always true in an %select{unevaluated|immediate}0 context">,

diff  --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp
index dbe62ecb50d33..deb398756e373 100644
--- a/clang/lib/Basic/Diagnostic.cpp
+++ b/clang/lib/Basic/Diagnostic.cpp
@@ -25,9 +25,8 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
-#include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/CrashRecoveryContext.h"
-#include "llvm/Support/Unicode.h"
+#include "llvm/Support/Locale.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
@@ -804,50 +803,6 @@ FormatDiagnostic(SmallVectorImpl &OutStr) const {
   FormatDiagnostic(Diag.begin(), Diag.end(), OutStr);
 }
 
-/// pushEscapedString - Append Str to the diagnostic buffer,
-/// escaping non-printable characters and ill-formed code unit sequences.
-static void pushEscapedString(StringRef Str, SmallVectorImpl &OutStr) {
-  OutStr.reserve(OutStr.size() + Str.size());
-  auto *Begin = reinterpret_cast(Str.data());
-  llvm::raw_svector_ostream OutStream(OutStr);
-  const unsigned char *End = Begin + Str.size();
-  while (Begin != End) {
-// ASCII case
-if (isPrintable(*Begin) || isWhitespace(*Begin)) {
-  OutStream << *Begin;
-  ++Begin;
-  continue;
-}
-if (llvm::isLegalUTF8Sequence(Begin, End)) {
-  llvm::UTF32 CodepointValue;
-  llvm::UTF32 *CpPtr = &CodepointValue;
-  const unsigned char *CodepointBegin = Begin;
-  const unsigned char *CodepointEnd =
-  Begin + llvm::getNumBytesForUTF8(*Begin);
-  llvm::ConversionResult Res = llvm::ConvertUTF8toUTF32(
-  &Begin, CodepointEnd, &CpPtr, CpPtr + 1, llvm::strictConversion);
-  (void)Res;
-  assert(
-  llvm::conversionOK == Res &&
-  "the sequence is legal UTF-8 but we couldn't convert it to UTF-32");
-  assert(Begin == CodepointEnd &&
- "we must be further along in the string now");
-  if (llvm::sys::unicode::isPrintable(CodepointValue) ||
-  llvm::sys::unicode::isFormatting(Codepo

[clang] 64ab2b1 - Improve handling of static assert messages.

2022-06-29 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-06-29T14:57:35+02:00
New Revision: 64ab2b1dcc5136a744fcac21d3d2c59e9cce040a

URL: 
https://github.com/llvm/llvm-project/commit/64ab2b1dcc5136a744fcac21d3d2c59e9cce040a
DIFF: 
https://github.com/llvm/llvm-project/commit/64ab2b1dcc5136a744fcac21d3d2c59e9cce040a.diff

LOG: Improve handling of static assert messages.

Instead of dumping the string literal (which
quotes it and escape every non-ascii symbol),
we can use the content of the string when it is a
8 byte string.

Wide, UTF-8/UTF-16/32 strings are still completely
escaped, until we clarify how these entities should
behave (cf https://wg21.link/p2361).

`FormatDiagnostic` is modified to escape
non printable characters and invalid UTF-8.

This ensures that unicode characters, spaces and new
lines are properly rendered in static messages.
This make clang more consistent with other implementation
and fixes this tweet
https://twitter.com/jfbastien/status/1298307325443231744 :)

Of note, `PaddingChecker` did print out new lines that were
later removed by the diagnostic printing code.
To be consistent with its tests, the new lines are removed
from the diagnostic.

Unicode tables updated to both use the Unicode definitions
and the Unicode 14.0 data.

U+00AD SOFT HYPHEN is still considered a print character
to match existing practices in terminals, in addition of
being considered a formatting character as per Unicode.

Reviewed By: aaron.ballman, #clang-language-wg

Differential Revision: https://reviews.llvm.org/D108469

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Basic/Diagnostic.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/StaticAnalyzer/Checkers/PaddingChecker.cpp
clang/test/Lexer/null-character-in-literal.c
clang/test/Misc/diag-special-chars.c
clang/test/Misc/wrong-encoding.c
clang/test/SemaCXX/static-assert.cpp
llvm/include/llvm/Support/Unicode.h
llvm/lib/Support/Unicode.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3e29987ad2631..99288d0ffac4e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -273,6 +273,8 @@ Improvements to Clang's diagnostics
 - When using class templates without arguments, clang now tells developers
   that template arguments are missing in certain contexts.
   This fixes `Issue 55962 
`_.
+- Printable Unicode characters within `static_assert` messages are no longer
+  escaped.
 
 Non-comprehensive list of changes in this release
 -

diff  --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp
index deb398756e373..dbe62ecb50d33 100644
--- a/clang/lib/Basic/Diagnostic.cpp
+++ b/clang/lib/Basic/Diagnostic.cpp
@@ -25,8 +25,9 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/CrashRecoveryContext.h"
-#include "llvm/Support/Locale.h"
+#include "llvm/Support/Unicode.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
@@ -803,6 +804,50 @@ FormatDiagnostic(SmallVectorImpl &OutStr) const {
   FormatDiagnostic(Diag.begin(), Diag.end(), OutStr);
 }
 
+/// pushEscapedString - Append Str to the diagnostic buffer,
+/// escaping non-printable characters and ill-formed code unit sequences.
+static void pushEscapedString(StringRef Str, SmallVectorImpl &OutStr) {
+  OutStr.reserve(OutStr.size() + Str.size());
+  auto *Begin = reinterpret_cast(Str.data());
+  llvm::raw_svector_ostream OutStream(OutStr);
+  const unsigned char *End = Begin + Str.size();
+  while (Begin != End) {
+// ASCII case
+if (isPrintable(*Begin) || isWhitespace(*Begin)) {
+  OutStream << *Begin;
+  ++Begin;
+  continue;
+}
+if (llvm::isLegalUTF8Sequence(Begin, End)) {
+  llvm::UTF32 CodepointValue;
+  llvm::UTF32 *CpPtr = &CodepointValue;
+  const unsigned char *CodepointBegin = Begin;
+  const unsigned char *CodepointEnd =
+  Begin + llvm::getNumBytesForUTF8(*Begin);
+  llvm::ConversionResult Res = llvm::ConvertUTF8toUTF32(
+  &Begin, CodepointEnd, &CpPtr, CpPtr + 1, llvm::strictConversion);
+  (void)Res;
+  assert(
+  llvm::conversionOK == Res &&
+  "the sequence is legal UTF-8 but we couldn't convert it to UTF-32");
+  assert(Begin == CodepointEnd &&
+ "we must be further along in the string now");
+  if (llvm::sys::unicode::isPrintable(CodepointValue) ||
+  llvm::sys::unicode::isFormatting(CodepointValue)) {
+OutStr.append(CodepointBegin, CodepointEnd);
+continue;
+  }
+  // Unprintable code point.
+  OutStream << "";
+  continue;
+}
+// Invalid code unit.
+OutStream << "<" << llvm::format_hex_no_prefix(*Begin, 2, true) << ">";

[clang] a9a60f2 - [Clang] Rename StringLiteral::isAscii() => isOrdinary() [NFC]

2022-06-29 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-06-29T18:28:51+02:00
New Revision: a9a60f20e6cc80855864b8f559073bc31f34554b

URL: 
https://github.com/llvm/llvm-project/commit/a9a60f20e6cc80855864b8f559073bc31f34554b
DIFF: 
https://github.com/llvm/llvm-project/commit/a9a60f20e6cc80855864b8f559073bc31f34554b.diff

LOG: [Clang] Rename StringLiteral::isAscii() => isOrdinary() [NFC]

"Ascii" StringLiteral instances are actually narrow strings
that are UTF-8 encoded and do not have an encoding prefix.
(UTF8 StringLiteral are also UTF-8 encoded strings, but with
the u8 prefix.

To avoid possible confusion both with actuall ASCII strings,
and with future works extending the set of literal encodings
supported by clang, this rename StringLiteral::isAscii() to
isOrdinary(), matching C++ standard terminology.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D128762

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp
clang-tools-extra/clangd/refactor/tweaks/RawStringLiteral.cpp
clang/include/clang/AST/Expr.h
clang/include/clang/Lex/LiteralSupport.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/Expr.cpp
clang/lib/AST/ExprConstant.cpp
clang/lib/AST/OSLog.cpp
clang/lib/Frontend/Rewrite/RewriteModernObjC.cpp
clang/lib/Frontend/Rewrite/RewriteObjC.cpp
clang/lib/Lex/LiteralSupport.cpp
clang/lib/Lex/PPDirectives.cpp
clang/lib/Lex/Preprocessor.cpp
clang/lib/Parse/ParseDecl.cpp
clang/lib/Parse/Parser.cpp
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaExprObjC.cpp
clang/lib/Sema/SemaInit.cpp
clang/lib/Sema/SemaStmtAsm.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp
index 40dda98b1e49b..d4b8fc8407153 100644
--- a/clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp
@@ -44,7 +44,7 @@ bool containsEscapedCharacters(const MatchFinder::MatchResult 
&Result,
const StringLiteral *Literal,
const CharsBitSet &DisallowedChars) {
   // FIXME: Handle L"", u8"", u"" and U"" literals.
-  if (!Literal->isAscii())
+  if (!Literal->isOrdinary())
 return false;
 
   for (const unsigned char C : Literal->getBytes())

diff  --git a/clang-tools-extra/clangd/refactor/tweaks/RawStringLiteral.cpp 
b/clang-tools-extra/clangd/refactor/tweaks/RawStringLiteral.cpp
index 77fefe87e3580..4185127d1f017 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/RawStringLiteral.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/RawStringLiteral.cpp
@@ -46,7 +46,7 @@ REGISTER_TWEAK(RawStringLiteral)
 static bool isNormalString(const StringLiteral &Str, SourceLocation Cursor,
   SourceManager &SM) {
   // All chunks must be normal ASCII strings, not u8"..." etc.
-  if (!Str.isAscii())
+  if (!Str.isOrdinary())
 return false;
   SourceLocation LastTokenBeforeCursor;
   for (auto I = Str.tokloc_begin(), E = Str.tokloc_end(); I != E; ++I) {

diff  --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 574d2fad216ea..1f3d524691ed6 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -1786,7 +1786,7 @@ class StringLiteral final
   /// * An array of getByteLength() char used to store the string data.
 
 public:
-  enum StringKind { Ascii, Wide, UTF8, UTF16, UTF32 };
+  enum StringKind { Ordinary, Wide, UTF8, UTF16, UTF32 };
 
 private:
   unsigned numTrailingObjects(OverloadToken) const { return 1; }
@@ -1883,7 +1883,7 @@ class StringLiteral final
 return static_cast(StringLiteralBits.Kind);
   }
 
-  bool isAscii() const { return getKind() == Ascii; }
+  bool isOrdinary() const { return getKind() == Ordinary; }
   bool isWide() const { return getKind() == Wide; }
   bool isUTF8() const { return getKind() == UTF8; }
   bool isUTF16() const { return getKind() == UTF16; }

diff  --git a/clang/include/clang/Lex/LiteralSupport.h 
b/clang/include/clang/Lex/LiteralSupport.h
index 977963dcbbba0..fd237c2c9cd87 100644
--- a/clang/include/clang/Lex/LiteralSupport.h
+++ b/clang/include/clang/Lex/LiteralSupport.h
@@ -198,7 +198,7 @@ class CharLiteralParser {
 tok::TokenKind kind);
 
   bool hadError() const { return HadError; }
-  bool isAscii() const { return Kind == tok::char_constant; }
+  bool isOrdinary() const { return Kind == tok::char_constant; }
   bool isWide() const { return Kind == tok::wide_char_constant; }
   bool isUTF8() const { return Kind == tok::utf8_char_constant; }
   bool isUTF16() const { return Kind == tok::utf16_char_constant; }
@@ -263,7 +263,7 @

[clang] 3d2629d - [Clang] Mark consteval as supported in Clang 15 [NFC]

2022-06-29 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-06-29T22:23:17+02:00
New Revision: 3d2629dd3aab17098813c68b5b76bb864bc5e285

URL: 
https://github.com/llvm/llvm-project/commit/3d2629dd3aab17098813c68b5b76bb864bc5e285
DIFF: 
https://github.com/llvm/llvm-project/commit/3d2629dd3aab17098813c68b5b76bb864bc5e285.diff

LOG: [Clang] Mark consteval as supported in Clang 15 [NFC]

Support was completed by D119646.

Added: 


Modified: 
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index 5501d07f0e1ba..c891d7ef9baa1 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -1120,11 +1120,7 @@ C++20 implementation status
 
   Immediate functions (consteval)
   https://wg21.link/p1073r3";>P1073R3
-  
-Partial
-  Using consteval functions as default parameters is not yet supported.
-
-  
+  Clang 15
 

 https://wg21.link/p1937r2";>P1937R2



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


[clang] da1609a - Improve the formatting of static_assert messages

2022-06-30 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-06-30T23:59:21+02:00
New Revision: da1609ad73540978f66111e96ea500b97ca9b39a

URL: 
https://github.com/llvm/llvm-project/commit/da1609ad73540978f66111e96ea500b97ca9b39a
DIFF: 
https://github.com/llvm/llvm-project/commit/da1609ad73540978f66111e96ea500b97ca9b39a.diff

LOG: Improve the formatting of static_assert messages

Display 'static_assert failed: message' instead of
'static_assert failed "message"' to be consistent
with other implementations and be slightly more
readable.

Reviewed By: #libc, aaron.ballman, philnik, Mordante

Differential Revision: https://reviews.llvm.org/D128844

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/C/drs/dr0xx.c
clang/test/CXX/dcl.dcl/p4-0x.cpp
clang/test/CXX/expr/expr.prim/expr.prim.id/p3.cpp
clang/test/PCH/cxx-static_assert.cpp
clang/test/Sema/static-assert.c
clang/test/SemaCXX/int-ptr-cast-SFINAE.cpp
clang/test/SemaCXX/static-assert.cpp

libcxx/test/libcxx/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add.verify.cpp

libcxx/test/libcxx/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_add_explicit.verify.cpp

libcxx/test/libcxx/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub.verify.cpp

libcxx/test/libcxx/atomics/atomics.types.operations/atomics.types.operations.req/atomic_fetch_sub_explicit.verify.cpp

libcxx/test/libcxx/input.output/file.streams/fstreams/filebuf/traits_mismatch.fail.cpp

libcxx/test/libcxx/input.output/file.streams/fstreams/traits_mismatch.fail.cpp

libcxx/test/libcxx/input.output/iostream.format/input.streams/traits_mismatch.fail.cpp

libcxx/test/libcxx/input.output/iostream.format/output.streams/traits_mismatch.fail.cpp
libcxx/test/libcxx/input.output/string.streams/traits_mismatch.fail.cpp

libcxx/test/libcxx/iterators/predef.iterators/reverse.iterators/bad_template_argument.verify.cpp

libcxx/test/libcxx/utilities/memory/util.smartptr/util.smartptr.shared/function_type_default_deleter.fail.cpp

libcxx/test/libcxx/utilities/tuple/tuple.tuple/tuple.cnstr/PR20855_tuple_ref_binding_diagnostics.fail.cpp

libcxx/test/libcxx/utilities/utility/pairs/pairs.pair/pair.tuple_element.fail.cpp

libcxx/test/libcxx/utilities/variant/variant.variant/variant.helper/variant_alternative.fail.cpp

libcxx/test/std/algorithms/alg.modifying.operations/alg.random.sample/sample.fail.cpp

libcxx/test/std/algorithms/alg.sorting/alg.min.max/requires_forward_iterator.fail.cpp
libcxx/test/std/containers/associative/map/map.cons/deduct.fail.cpp

libcxx/test/std/containers/associative/multimap/multimap.cons/deduct.fail.cpp
libcxx/test/std/containers/sequences/array/array.fill/fill.fail.cpp
libcxx/test/std/containers/sequences/array/array.swap/swap.fail.cpp
libcxx/test/std/containers/sequences/array/array.tuple/get.fail.cpp

libcxx/test/std/containers/sequences/array/array.tuple/tuple_element.fail.cpp

libcxx/test/std/containers/sequences/vector/vector.modifiers/resize_not_move_insertable.fail.cpp
libcxx/test/std/containers/views/views.span/span.sub/subspan.verify.cpp

libcxx/test/std/experimental/language.support/support.coroutines/coroutine.handle/coroutine.handle.export/from_address.fail.cpp

libcxx/test/std/language.support/support.dynamic/ptr.launder/launder.types.fail.cpp
libcxx/test/std/numerics/numbers/illformed.verify.cpp
libcxx/test/std/numerics/rand/rand.eng/rand.eng.lcong/params.fail.cpp
libcxx/test/std/strings/basic.string/char.bad.verify.cpp
libcxx/test/std/strings/string.view/char.bad.fail.cpp
libcxx/test/std/time/time.hms/hhmmss.fail.cpp

libcxx/test/std/utilities/any/any.nonmembers/any.cast/any_cast_request_invalid_value_category.fail.cpp

libcxx/test/std/utilities/any/any.nonmembers/any.cast/const_correctness.verify.cpp

libcxx/test/std/utilities/any/any.nonmembers/any.cast/not_copy_constructible.verify.cpp

libcxx/test/std/utilities/any/any.nonmembers/any.cast/reference_types.fail.cpp
libcxx/test/std/utilities/intseq/intseq.make/make_integer_seq.fail.cpp

libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/ctor.fail.cpp

libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/deduct.fail.cpp

libcxx/test/std/utilities/optional/optional.object/optional_requires_destructible_object.fail.cpp
libcxx/test/std/utilities/optional/optional.syn/optional_in_place_t.fail.cpp
libcxx/test/std/utilities/utility/forward/forward.fail.cpp
libcxx/test/std/utilities/variant/variant.relops/relops_bool_conv.fail.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 880fe0d18a02e..bc7aec3803e82 10

[clang] e3dc568 - [Clang] Add a warning on invalid UTF-8 in comments.

2022-07-06 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-07-06T17:59:44+02:00
New Revision: e3dc56805f1029dd5959e4c69196a287961afb8d

URL: 
https://github.com/llvm/llvm-project/commit/e3dc56805f1029dd5959e4c69196a287961afb8d
DIFF: 
https://github.com/llvm/llvm-project/commit/e3dc56805f1029dd5959e4c69196a287961afb8d.diff

LOG: [Clang] Add a warning on invalid UTF-8 in comments.

Introduce an off-by default `-Winvalid-utf8` warning
that detects invalid UTF-8 code units sequences in comments.

Invalid UTF-8 in other places is already diagnosed,
as that cannot appear in identifiers and other grammar constructs.

The warning is off by default as its likely to be somewhat disruptive
otherwise.

This warning allows clang to conform to the yet-to be approved WG21
"P2295R5 Support for UTF-8 as a portable source file encoding"
paper.

Reviewed By: aaron.ballman, #clang-language-wg

Differential Revision: https://reviews.llvm.org/D128059

Added: 
clang/test/Lexer/comment-invalid-utf8.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/lib/Lex/Lexer.cpp
llvm/include/llvm/Support/ConvertUTF.h
llvm/lib/Support/ConvertUTF.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0f542e08b841c..c50e1b89649cf 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -279,6 +279,8 @@ Improvements to Clang's diagnostics
   unevaluated operands of a ``typeid`` expression, as they are now
   modeled correctly in the CFG. This fixes
   `Issue 21668 `_.
+- Added ``-Winvalid-utf8`` which diagnoses invalid UTF-8 code unit sequences in
+  comments.
 
 Non-comprehensive list of changes in this release
 -
@@ -576,7 +578,7 @@ AST Matchers
 
 - Added ``forEachTemplateArgument`` matcher which creates a match every
   time a ``templateArgument`` matches the matcher supplied to it.
-  
+
 - Added ``objcStringLiteral`` matcher which matches ObjectiveC String
   literal expressions.
 

diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index ac86076140c58..38ee022e5f04c 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -113,6 +113,8 @@ def warn_four_char_character_literal : Warning<
 // Unicode and UCNs
 def err_invalid_utf8 : Error<
   "source file is not valid UTF-8">;
+def warn_invalid_utf8_in_comment : Extension<
+  "invalid UTF-8 in comment">, InGroup>;
 def err_character_not_allowed : Error<
   "unexpected character ">;
 def err_character_not_allowed_identifier : Error<

diff  --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index 6820057642bea..351e518c7ed37 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -2392,13 +2392,37 @@ bool Lexer::SkipLineComment(Token &Result, const char 
*CurPtr,
   //
   // This loop terminates with CurPtr pointing at the newline (or end of 
buffer)
   // character that ends the line comment.
+
+  // C++23 [lex.phases] p1
+  // Diagnose invalid UTF-8 if the corresponding warning is enabled, emitting a
+  // diagnostic only once per entire ill-formed subsequence to avoid
+  // emiting to many diagnostics (see http://unicode.org/review/pr-121.html).
+  bool UnicodeDecodingAlreadyDiagnosed = false;
+
   char C;
   while (true) {
 C = *CurPtr;
 // Skip over characters in the fast loop.
-while (C != 0 &&// Potentially EOF.
-   C != '\n' && C != '\r')  // Newline or DOS-style newline.
+while (isASCII(C) && C != 0 &&   // Potentially EOF.
+   C != '\n' && C != '\r') { // Newline or DOS-style newline.
   C = *++CurPtr;
+  UnicodeDecodingAlreadyDiagnosed = false;
+}
+
+if (!isASCII(C)) {
+  unsigned Length = llvm::getUTF8SequenceSize(
+  (const llvm::UTF8 *)CurPtr, (const llvm::UTF8 *)BufferEnd);
+  if (Length == 0) {
+if (!UnicodeDecodingAlreadyDiagnosed && !isLexingRawMode())
+  Diag(CurPtr, diag::warn_invalid_utf8_in_comment);
+UnicodeDecodingAlreadyDiagnosed = true;
+++CurPtr;
+  } else {
+UnicodeDecodingAlreadyDiagnosed = false;
+CurPtr += Length;
+  }
+  continue;
+}
 
 const char *NextLine = CurPtr;
 if (C != 0) {
@@ -2665,6 +2689,12 @@ bool Lexer::SkipBlockComment(Token &Result, const char 
*CurPtr,
   if (C == '/')
 C = *CurPtr++;
 
+  // C++23 [lex.phases] p1
+  // Diagnose invalid UTF-8 if the corresponding warning is enabled, emitting a
+  // diagnostic only once per entire ill-formed subsequence to avoid
+  // emiting to many diagnostics (see http://unicode.org/review/pr-121.html).
+  bool UnicodeDecodingAlreadyDiagnosed = false;
+
   while (true) {
 // Skip over all non-interesting characters until we fin

[clang] fb06dd3 - Revert "[Clang] Add a warning on invalid UTF-8 in comments."

2022-07-06 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-07-06T19:45:12+02:00
New Revision: fb06dd3e8ca1b89579055a74f2217e7665c3f150

URL: 
https://github.com/llvm/llvm-project/commit/fb06dd3e8ca1b89579055a74f2217e7665c3f150
DIFF: 
https://github.com/llvm/llvm-project/commit/fb06dd3e8ca1b89579055a74f2217e7665c3f150.diff

LOG: Revert "[Clang] Add a warning on invalid UTF-8 in comments."

Reverting while I investigate build failures

This reverts commit e3dc56805f1029dd5959e4c69196a287961afb8d.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/lib/Lex/Lexer.cpp
llvm/include/llvm/Support/ConvertUTF.h
llvm/lib/Support/ConvertUTF.cpp

Removed: 
clang/test/Lexer/comment-invalid-utf8.c



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c50e1b89649cf..0f542e08b841c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -279,8 +279,6 @@ Improvements to Clang's diagnostics
   unevaluated operands of a ``typeid`` expression, as they are now
   modeled correctly in the CFG. This fixes
   `Issue 21668 `_.
-- Added ``-Winvalid-utf8`` which diagnoses invalid UTF-8 code unit sequences in
-  comments.
 
 Non-comprehensive list of changes in this release
 -
@@ -578,7 +576,7 @@ AST Matchers
 
 - Added ``forEachTemplateArgument`` matcher which creates a match every
   time a ``templateArgument`` matches the matcher supplied to it.
-
+  
 - Added ``objcStringLiteral`` matcher which matches ObjectiveC String
   literal expressions.
 

diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index 38ee022e5f04c..ac86076140c58 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -113,8 +113,6 @@ def warn_four_char_character_literal : Warning<
 // Unicode and UCNs
 def err_invalid_utf8 : Error<
   "source file is not valid UTF-8">;
-def warn_invalid_utf8_in_comment : Extension<
-  "invalid UTF-8 in comment">, InGroup>;
 def err_character_not_allowed : Error<
   "unexpected character ">;
 def err_character_not_allowed_identifier : Error<

diff  --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index 351e518c7ed37..6820057642bea 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -2392,37 +2392,13 @@ bool Lexer::SkipLineComment(Token &Result, const char 
*CurPtr,
   //
   // This loop terminates with CurPtr pointing at the newline (or end of 
buffer)
   // character that ends the line comment.
-
-  // C++23 [lex.phases] p1
-  // Diagnose invalid UTF-8 if the corresponding warning is enabled, emitting a
-  // diagnostic only once per entire ill-formed subsequence to avoid
-  // emiting to many diagnostics (see http://unicode.org/review/pr-121.html).
-  bool UnicodeDecodingAlreadyDiagnosed = false;
-
   char C;
   while (true) {
 C = *CurPtr;
 // Skip over characters in the fast loop.
-while (isASCII(C) && C != 0 &&   // Potentially EOF.
-   C != '\n' && C != '\r') { // Newline or DOS-style newline.
+while (C != 0 &&// Potentially EOF.
+   C != '\n' && C != '\r')  // Newline or DOS-style newline.
   C = *++CurPtr;
-  UnicodeDecodingAlreadyDiagnosed = false;
-}
-
-if (!isASCII(C)) {
-  unsigned Length = llvm::getUTF8SequenceSize(
-  (const llvm::UTF8 *)CurPtr, (const llvm::UTF8 *)BufferEnd);
-  if (Length == 0) {
-if (!UnicodeDecodingAlreadyDiagnosed && !isLexingRawMode())
-  Diag(CurPtr, diag::warn_invalid_utf8_in_comment);
-UnicodeDecodingAlreadyDiagnosed = true;
-++CurPtr;
-  } else {
-UnicodeDecodingAlreadyDiagnosed = false;
-CurPtr += Length;
-  }
-  continue;
-}
 
 const char *NextLine = CurPtr;
 if (C != 0) {
@@ -2689,12 +2665,6 @@ bool Lexer::SkipBlockComment(Token &Result, const char 
*CurPtr,
   if (C == '/')
 C = *CurPtr++;
 
-  // C++23 [lex.phases] p1
-  // Diagnose invalid UTF-8 if the corresponding warning is enabled, emitting a
-  // diagnostic only once per entire ill-formed subsequence to avoid
-  // emiting to many diagnostics (see http://unicode.org/review/pr-121.html).
-  bool UnicodeDecodingAlreadyDiagnosed = false;
-
   while (true) {
 // Skip over all non-interesting characters until we find end of buffer or 
a
 // (probably ending) '/' character.
@@ -2703,24 +2673,14 @@ bool Lexer::SkipBlockComment(Token &Result, const char 
*CurPtr,
 // doesn't check for '\0'.
 !(PP && PP->getCodeCompletionFileLoc() == FileLoc)) {
   // While not aligned to a 16-byte boundary.
-  while (C != '/' && (intptr_t)CurPtr % 16 != 0) {
-if (!isASCII(C)) {
-  CurPtr--;
-  goto MultiByteUTF8;
-

[clang] 4174f0c - [Clang] Add a warning on invalid UTF-8 in comments.

2022-07-06 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-07-06T21:18:29+02:00
New Revision: 4174f0ca618b467571b43cff12cbe4c4239670f8

URL: 
https://github.com/llvm/llvm-project/commit/4174f0ca618b467571b43cff12cbe4c4239670f8
DIFF: 
https://github.com/llvm/llvm-project/commit/4174f0ca618b467571b43cff12cbe4c4239670f8.diff

LOG: [Clang] Add a warning on invalid UTF-8 in comments.

Introduce an off-by default `-Winvalid-utf8` warning
that detects invalid UTF-8 code units sequences in comments.

Invalid UTF-8 in other places is already diagnosed,
as that cannot appear in identifiers and other grammar constructs.

The warning is off by default as its likely to be somewhat disruptive
otherwise.

This warning allows clang to conform to the yet-to be approved WG21
"P2295R5 Support for UTF-8 as a portable source file encoding"
paper.

Reviewed By: aaron.ballman, #clang-language-wg

Differential Revision: https://reviews.llvm.org/D128059

Added: 
clang/test/Lexer/comment-invalid-utf8.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/lib/Lex/Lexer.cpp
clang/test/SemaCXX/static-assert.cpp
llvm/include/llvm/Support/ConvertUTF.h
llvm/lib/Support/ConvertUTF.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0f542e08b841..c50e1b89649c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -279,6 +279,8 @@ Improvements to Clang's diagnostics
   unevaluated operands of a ``typeid`` expression, as they are now
   modeled correctly in the CFG. This fixes
   `Issue 21668 `_.
+- Added ``-Winvalid-utf8`` which diagnoses invalid UTF-8 code unit sequences in
+  comments.
 
 Non-comprehensive list of changes in this release
 -
@@ -576,7 +578,7 @@ AST Matchers
 
 - Added ``forEachTemplateArgument`` matcher which creates a match every
   time a ``templateArgument`` matches the matcher supplied to it.
-  
+
 - Added ``objcStringLiteral`` matcher which matches ObjectiveC String
   literal expressions.
 

diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index ac86076140c5..38ee022e5f04 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -113,6 +113,8 @@ def warn_four_char_character_literal : Warning<
 // Unicode and UCNs
 def err_invalid_utf8 : Error<
   "source file is not valid UTF-8">;
+def warn_invalid_utf8_in_comment : Extension<
+  "invalid UTF-8 in comment">, InGroup>;
 def err_character_not_allowed : Error<
   "unexpected character ">;
 def err_character_not_allowed_identifier : Error<

diff  --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index 6820057642be..351e518c7ed3 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -2392,13 +2392,37 @@ bool Lexer::SkipLineComment(Token &Result, const char 
*CurPtr,
   //
   // This loop terminates with CurPtr pointing at the newline (or end of 
buffer)
   // character that ends the line comment.
+
+  // C++23 [lex.phases] p1
+  // Diagnose invalid UTF-8 if the corresponding warning is enabled, emitting a
+  // diagnostic only once per entire ill-formed subsequence to avoid
+  // emiting to many diagnostics (see http://unicode.org/review/pr-121.html).
+  bool UnicodeDecodingAlreadyDiagnosed = false;
+
   char C;
   while (true) {
 C = *CurPtr;
 // Skip over characters in the fast loop.
-while (C != 0 &&// Potentially EOF.
-   C != '\n' && C != '\r')  // Newline or DOS-style newline.
+while (isASCII(C) && C != 0 &&   // Potentially EOF.
+   C != '\n' && C != '\r') { // Newline or DOS-style newline.
   C = *++CurPtr;
+  UnicodeDecodingAlreadyDiagnosed = false;
+}
+
+if (!isASCII(C)) {
+  unsigned Length = llvm::getUTF8SequenceSize(
+  (const llvm::UTF8 *)CurPtr, (const llvm::UTF8 *)BufferEnd);
+  if (Length == 0) {
+if (!UnicodeDecodingAlreadyDiagnosed && !isLexingRawMode())
+  Diag(CurPtr, diag::warn_invalid_utf8_in_comment);
+UnicodeDecodingAlreadyDiagnosed = true;
+++CurPtr;
+  } else {
+UnicodeDecodingAlreadyDiagnosed = false;
+CurPtr += Length;
+  }
+  continue;
+}
 
 const char *NextLine = CurPtr;
 if (C != 0) {
@@ -2665,6 +2689,12 @@ bool Lexer::SkipBlockComment(Token &Result, const char 
*CurPtr,
   if (C == '/')
 C = *CurPtr++;
 
+  // C++23 [lex.phases] p1
+  // Diagnose invalid UTF-8 if the corresponding warning is enabled, emitting a
+  // diagnostic only once per entire ill-formed subsequence to avoid
+  // emiting to many diagnostics (see http://unicode.org/review/pr-121.html).
+  bool UnicodeDecodingAlreadyDiagnosed = false;
+
   while (true) {
 // Skip over all non-

[clang] bf45e27 - [Clang] Fix invalid utf-8 detection

2022-07-06 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-07-06T22:20:04+02:00
New Revision: bf45e27a676d87944f1f13d5f0d0f39935fc4010

URL: 
https://github.com/llvm/llvm-project/commit/bf45e27a676d87944f1f13d5f0d0f39935fc4010
DIFF: 
https://github.com/llvm/llvm-project/commit/bf45e27a676d87944f1f13d5f0d0f39935fc4010.diff

LOG: [Clang] Fix invalid utf-8 detection

The length of valid codepoints was incorrectly
calculated which was not caught before because the
absence of tests for the valid codepoints scenario.

Differential Revision: https://reviews.llvm.org/D129223

Added: 


Modified: 
clang/test/Lexer/comment-invalid-utf8.c
llvm/lib/Support/ConvertUTF.cpp

Removed: 




diff  --git a/clang/test/Lexer/comment-invalid-utf8.c 
b/clang/test/Lexer/comment-invalid-utf8.c
index b8bf551dd8564..ed7405a3c079e 100644
--- a/clang/test/Lexer/comment-invalid-utf8.c
+++ b/clang/test/Lexer/comment-invalid-utf8.c
@@ -25,3 +25,14 @@
 // abcd
 // €abcd
 // expected-warning@-1 {{invalid UTF-8 in comment}}
+
+
+//§ § § 😀 你好 ©
+
+/*§ § § 😀 你好 ©*/
+
+/*
+§ § § 😀 你好 ©
+*/
+
+/* § § § 😀 你好 © */

diff  --git a/llvm/lib/Support/ConvertUTF.cpp b/llvm/lib/Support/ConvertUTF.cpp
index c494110cdcee1..25875d4c3184b 100644
--- a/llvm/lib/Support/ConvertUTF.cpp
+++ b/llvm/lib/Support/ConvertUTF.cpp
@@ -423,7 +423,7 @@ Boolean isLegalUTF8Sequence(const UTF8 *source, const UTF8 
*sourceEnd) {
  */
 unsigned getUTF8SequenceSize(const UTF8 *source, const UTF8 *sourceEnd) {
   int length = trailingBytesForUTF8[*source] + 1;
-  return (length > sourceEnd - source && isLegalUTF8(source, length)) ? length
+  return (length < sourceEnd - source && isLegalUTF8(source, length)) ? length
   : 0;
 }
 



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


[clang] 355532a - [Clang] Add a warning on invalid UTF-8 in comments.

2022-07-09 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-07-09T11:26:45+02:00
New Revision: 355532a1499aa9b13a89fb5b5caaba2344d57cd7

URL: 
https://github.com/llvm/llvm-project/commit/355532a1499aa9b13a89fb5b5caaba2344d57cd7
DIFF: 
https://github.com/llvm/llvm-project/commit/355532a1499aa9b13a89fb5b5caaba2344d57cd7.diff

LOG: [Clang] Add a warning on invalid UTF-8 in comments.

Introduce an off-by default `-Winvalid-utf8` warning
that detects invalid UTF-8 code units sequences in comments.

Invalid UTF-8 in other places is already diagnosed,
as that cannot appear in identifiers and other grammar constructs.

The warning is off by default as its likely to be somewhat disruptive
otherwise.

This warning allows clang to conform to the yet-to be approved WG21
"P2295R5 Support for UTF-8 as a portable source file encoding"
paper.

Reviewed By: aaron.ballman, #clang-language-wg

Differential Revision: https://reviews.llvm.org/D128059

Added: 
clang/test/Lexer/comment-invalid-utf8.c
clang/test/Lexer/comment-utf8.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/lib/Lex/Lexer.cpp
clang/test/SemaCXX/static-assert.cpp
llvm/include/llvm/Support/ConvertUTF.h
llvm/lib/Support/ConvertUTF.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5dae6205efa05..da14489f6f2cd 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -279,9 +279,11 @@ Improvements to Clang's diagnostics
   unevaluated operands of a ``typeid`` expression, as they are now
   modeled correctly in the CFG. This fixes
   `Issue 21668 `_.
-- ``-Wself-assign``, ``-Wself-assign-overloaded`` and ``-Wself-move`` will 
+- ``-Wself-assign``, ``-Wself-assign-overloaded`` and ``-Wself-move`` will
   suggest a fix if the decl being assigned is a parameter that shadows a data
   member of the contained class.
+- Added ``-Winvalid-utf8`` which diagnoses invalid UTF-8 code unit sequences in
+  comments.
 
 Non-comprehensive list of changes in this release
 -
@@ -592,7 +594,7 @@ AST Matchers
 
 - Added ``forEachTemplateArgument`` matcher which creates a match every
   time a ``templateArgument`` matches the matcher supplied to it.
-  
+
 - Added ``objcStringLiteral`` matcher which matches ObjectiveC String
   literal expressions.
 

diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index ac86076140c58..38ee022e5f04c 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -113,6 +113,8 @@ def warn_four_char_character_literal : Warning<
 // Unicode and UCNs
 def err_invalid_utf8 : Error<
   "source file is not valid UTF-8">;
+def warn_invalid_utf8_in_comment : Extension<
+  "invalid UTF-8 in comment">, InGroup>;
 def err_character_not_allowed : Error<
   "unexpected character ">;
 def err_character_not_allowed_identifier : Error<

diff  --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index 6820057642bea..799f3017daa82 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -2392,13 +2392,37 @@ bool Lexer::SkipLineComment(Token &Result, const char 
*CurPtr,
   //
   // This loop terminates with CurPtr pointing at the newline (or end of 
buffer)
   // character that ends the line comment.
+
+  // C++23 [lex.phases] p1
+  // Diagnose invalid UTF-8 if the corresponding warning is enabled, emitting a
+  // diagnostic only once per entire ill-formed subsequence to avoid
+  // emiting to many diagnostics (see http://unicode.org/review/pr-121.html).
+  bool UnicodeDecodingAlreadyDiagnosed = false;
+
   char C;
   while (true) {
 C = *CurPtr;
 // Skip over characters in the fast loop.
-while (C != 0 &&// Potentially EOF.
-   C != '\n' && C != '\r')  // Newline or DOS-style newline.
+while (isASCII(C) && C != 0 &&   // Potentially EOF.
+   C != '\n' && C != '\r') { // Newline or DOS-style newline.
   C = *++CurPtr;
+  UnicodeDecodingAlreadyDiagnosed = false;
+}
+
+if (!isASCII(C)) {
+  unsigned Length = llvm::getUTF8SequenceSize(
+  (const llvm::UTF8 *)CurPtr, (const llvm::UTF8 *)BufferEnd);
+  if (Length == 0) {
+if (!UnicodeDecodingAlreadyDiagnosed && !isLexingRawMode())
+  Diag(CurPtr, diag::warn_invalid_utf8_in_comment);
+UnicodeDecodingAlreadyDiagnosed = true;
+++CurPtr;
+  } else {
+UnicodeDecodingAlreadyDiagnosed = false;
+CurPtr += Length;
+  }
+  continue;
+}
 
 const char *NextLine = CurPtr;
 if (C != 0) {
@@ -2665,6 +2689,12 @@ bool Lexer::SkipBlockComment(Token &Result, const char 
*CurPtr,
   if (C == '/')
 C = *CurPtr++;
 
+  // C++23 [lex.phases] p1
+  // Diagnose i

[clang] 50416e5 - Revert "[Clang] Add a warning on invalid UTF-8 in comments."

2022-07-09 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-07-09T17:18:35+02:00
New Revision: 50416e5454d802a3ef71bb799e5bfd38e8ec9089

URL: 
https://github.com/llvm/llvm-project/commit/50416e5454d802a3ef71bb799e5bfd38e8ec9089
DIFF: 
https://github.com/llvm/llvm-project/commit/50416e5454d802a3ef71bb799e5bfd38e8ec9089.diff

LOG: Revert "[Clang] Add a warning on invalid UTF-8 in comments."

It is probable thart this change crashes on the powerpc bots.

This reverts commit 355532a1499aa9b13a89fb5b5caaba2344d57cd7.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/lib/Lex/Lexer.cpp
clang/test/SemaCXX/static-assert.cpp
llvm/include/llvm/Support/ConvertUTF.h
llvm/lib/Support/ConvertUTF.cpp

Removed: 
clang/test/Lexer/comment-invalid-utf8.c
clang/test/Lexer/comment-utf8.c



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index da14489f6f2cd..5dae6205efa05 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -279,11 +279,9 @@ Improvements to Clang's diagnostics
   unevaluated operands of a ``typeid`` expression, as they are now
   modeled correctly in the CFG. This fixes
   `Issue 21668 `_.
-- ``-Wself-assign``, ``-Wself-assign-overloaded`` and ``-Wself-move`` will
+- ``-Wself-assign``, ``-Wself-assign-overloaded`` and ``-Wself-move`` will 
   suggest a fix if the decl being assigned is a parameter that shadows a data
   member of the contained class.
-- Added ``-Winvalid-utf8`` which diagnoses invalid UTF-8 code unit sequences in
-  comments.
 
 Non-comprehensive list of changes in this release
 -
@@ -594,7 +592,7 @@ AST Matchers
 
 - Added ``forEachTemplateArgument`` matcher which creates a match every
   time a ``templateArgument`` matches the matcher supplied to it.
-
+  
 - Added ``objcStringLiteral`` matcher which matches ObjectiveC String
   literal expressions.
 

diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index 38ee022e5f04c..ac86076140c58 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -113,8 +113,6 @@ def warn_four_char_character_literal : Warning<
 // Unicode and UCNs
 def err_invalid_utf8 : Error<
   "source file is not valid UTF-8">;
-def warn_invalid_utf8_in_comment : Extension<
-  "invalid UTF-8 in comment">, InGroup>;
 def err_character_not_allowed : Error<
   "unexpected character ">;
 def err_character_not_allowed_identifier : Error<

diff  --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index 799f3017daa82..6820057642bea 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -2392,37 +2392,13 @@ bool Lexer::SkipLineComment(Token &Result, const char 
*CurPtr,
   //
   // This loop terminates with CurPtr pointing at the newline (or end of 
buffer)
   // character that ends the line comment.
-
-  // C++23 [lex.phases] p1
-  // Diagnose invalid UTF-8 if the corresponding warning is enabled, emitting a
-  // diagnostic only once per entire ill-formed subsequence to avoid
-  // emiting to many diagnostics (see http://unicode.org/review/pr-121.html).
-  bool UnicodeDecodingAlreadyDiagnosed = false;
-
   char C;
   while (true) {
 C = *CurPtr;
 // Skip over characters in the fast loop.
-while (isASCII(C) && C != 0 &&   // Potentially EOF.
-   C != '\n' && C != '\r') { // Newline or DOS-style newline.
+while (C != 0 &&// Potentially EOF.
+   C != '\n' && C != '\r')  // Newline or DOS-style newline.
   C = *++CurPtr;
-  UnicodeDecodingAlreadyDiagnosed = false;
-}
-
-if (!isASCII(C)) {
-  unsigned Length = llvm::getUTF8SequenceSize(
-  (const llvm::UTF8 *)CurPtr, (const llvm::UTF8 *)BufferEnd);
-  if (Length == 0) {
-if (!UnicodeDecodingAlreadyDiagnosed && !isLexingRawMode())
-  Diag(CurPtr, diag::warn_invalid_utf8_in_comment);
-UnicodeDecodingAlreadyDiagnosed = true;
-++CurPtr;
-  } else {
-UnicodeDecodingAlreadyDiagnosed = false;
-CurPtr += Length;
-  }
-  continue;
-}
 
 const char *NextLine = CurPtr;
 if (C != 0) {
@@ -2689,12 +2665,6 @@ bool Lexer::SkipBlockComment(Token &Result, const char 
*CurPtr,
   if (C == '/')
 C = *CurPtr++;
 
-  // C++23 [lex.phases] p1
-  // Diagnose invalid UTF-8 if the corresponding warning is enabled, emitting a
-  // diagnostic only once per entire ill-formed subsequence to avoid
-  // emiting to many diagnostics (see http://unicode.org/review/pr-121.html).
-  bool UnicodeDecodingAlreadyDiagnosed = false;
-
   while (true) {
 // Skip over all non-interesting characters until we find end of buffer or 
a
 // (probably ending) '/' character.
@@ -2703,22 +2673,1

[clang] 3784e8c - [Clang] Fix Unevaluated Lambdas

2022-03-25 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-03-25T19:16:45+01:00
New Revision: 3784e8ccfbdaaab31f9e9c221daa59a21827

URL: 
https://github.com/llvm/llvm-project/commit/3784e8ccfbdaaab31f9e9c221daa59a21827
DIFF: 
https://github.com/llvm/llvm-project/commit/3784e8ccfbdaaab31f9e9c221daa59a21827.diff

LOG: [Clang] Fix Unevaluated Lambdas

Unlike other types, when lambdas are instanciated,
they are recreated from scratch.
When an unevaluated lambdas appear in the type of a function,
parameter it is instanciated in the wrong declaration context,
as parameters are transformed before the function.

To support lambda in function parameters, we try to
compute whether they are dependant without looking at the
declaration context.

This is a short term stopgap solution to avoid clang
iceing. A better fix might be to inject some kind of
transparent declaration with correctly computed dependency
for function parameters, variable templates, etc.

Fixes https://github.com/llvm/llvm-project/issues/50376
Fixes https://github.com/llvm/llvm-project/issues/51414
Fixes https://github.com/llvm/llvm-project/issues/51416
Fixes https://github.com/llvm/llvm-project/issues/51641
Fixes https://github.com/llvm/llvm-project/issues/54296

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D121532

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/DeclCXX.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/DeclBase.cpp
clang/lib/AST/DeclCXX.cpp
clang/lib/Sema/SemaLambda.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/SemaCXX/lambda-unevaluated.cpp
clang/unittests/AST/ASTImporterTest.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 58523c2569283..39499b79e34d4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -83,6 +83,14 @@ Bug Fixes
   per identifier.
   Fixes `Issue 28985 `_.
 
+- Unevaluated lambdas in dependant contexts no longer result in clang crashing.
+  This fixes Issues `50376 < 
https://github.com/llvm/llvm-project/issues/50376>`_,
+  `54296 < https://github.com/llvm/llvm-project/issues/54296>`_,
+  `51414 < https://github.com/llvm/llvm-project/issues/51414>`_,
+  `51416 < https://github.com/llvm/llvm-project/issues/51416>`_,
+  and `51641 < https://github.com/llvm/llvm-project/issues/51641>`_.
+
+
 Improvements to Clang's diagnostics
 ^^^
 - ``-Wliteral-range`` will warn on floating-point equality comparisons with

diff  --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 2833df0505dac..545f29975fd89 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -275,6 +275,14 @@ class CXXRecordDecl : public RecordDecl {
 SMF_All = 0x3f
   };
 
+public:
+  enum LambdaDependencyKind {
+LDK_Unknown = 0,
+LDK_AlwaysDependent,
+LDK_NeverDependent,
+  };
+
+private:
   struct DefinitionData {
 #define FIELD(Name, Width, Merge) \
 unsigned Name : Width;
@@ -374,7 +382,7 @@ class CXXRecordDecl : public RecordDecl {
 /// lambda will have been created with the enclosing context as its
 /// declaration context, rather than function. This is an unfortunate
 /// artifact of having to parse the default arguments before.
-unsigned Dependent : 1;
+unsigned DependencyKind : 2;
 
 /// Whether this lambda is a generic lambda.
 unsigned IsGenericLambda : 1;
@@ -408,9 +416,9 @@ class CXXRecordDecl : public RecordDecl {
 /// The type of the call method.
 TypeSourceInfo *MethodTyInfo;
 
-LambdaDefinitionData(CXXRecordDecl *D, TypeSourceInfo *Info, bool 
Dependent,
+LambdaDefinitionData(CXXRecordDecl *D, TypeSourceInfo *Info, unsigned DK,
  bool IsGeneric, LambdaCaptureDefault CaptureDefault)
-: DefinitionData(D), Dependent(Dependent), IsGenericLambda(IsGeneric),
+: DefinitionData(D), DependencyKind(DK), IsGenericLambda(IsGeneric),
   CaptureDefault(CaptureDefault), NumCaptures(0),
   NumExplicitCaptures(0), HasKnownInternalLinkage(0), 
ManglingNumber(0),
   MethodTyInfo(Info) {
@@ -547,7 +555,7 @@ class CXXRecordDecl : public RecordDecl {
bool DelayTypeCreation = false);
   static CXXRecordDecl *CreateLambda(const ASTContext &C, DeclContext *DC,
  TypeSourceInfo *Info, SourceLocation Loc,
- bool DependentLambda, bool IsGeneric,
+ unsigned DependencyKind, bool IsGeneric,
 

[clang] 26e201b - [Clang] Fix error in Documentation introduced by 3784e8cc [nfc].

2022-03-25 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-03-25T19:38:36+01:00
New Revision: 26e201b7968cf12e603ef648d1be660bb23f3a08

URL: 
https://github.com/llvm/llvm-project/commit/26e201b7968cf12e603ef648d1be660bb23f3a08
DIFF: 
https://github.com/llvm/llvm-project/commit/26e201b7968cf12e603ef648d1be660bb23f3a08.diff

LOG: [Clang] Fix error in Documentation introduced by 3784e8cc [nfc].

The documentation contained extra space.
Also remove https://github.com/llvm/llvm-project/issues/54296
from the list of issues by 3784e8cc as this commit did not
fix it (nor was it supposed to).

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 39499b79e34d4..9e7958918b2dc 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -84,11 +84,10 @@ Bug Fixes
   Fixes `Issue 28985 `_.
 
 - Unevaluated lambdas in dependant contexts no longer result in clang crashing.
-  This fixes Issues `50376 < 
https://github.com/llvm/llvm-project/issues/50376>`_,
-  `54296 < https://github.com/llvm/llvm-project/issues/54296>`_,
-  `51414 < https://github.com/llvm/llvm-project/issues/51414>`_,
-  `51416 < https://github.com/llvm/llvm-project/issues/51416>`_,
-  and `51641 < https://github.com/llvm/llvm-project/issues/51641>`_.
+  This fixes Issues `50376 
`_,
+  `51414 `_,
+  `51416 `_,
+  and `51641 `_.
 
 
 Improvements to Clang's diagnostics



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


[clang] 0550601 - [Clang] Add a compatibiliy warning for non-literals in constexpr.

2022-03-30 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-03-30T19:18:53+02:00
New Revision: 0550601d180111a1c48baf170c2e7e9c7fac28c2

URL: 
https://github.com/llvm/llvm-project/commit/0550601d180111a1c48baf170c2e7e9c7fac28c2
DIFF: 
https://github.com/llvm/llvm-project/commit/0550601d180111a1c48baf170c2e7e9c7fac28c2.diff

LOG: [Clang] Add a compatibiliy warning for non-literals in constexpr.

Reviewed By: aaron.ballman, hubert.reinterpretcast

Differential Revision: https://reviews.llvm.org/D122249

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3-2b.cpp
clang/test/SemaCXX/constant-expression-cxx2b.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index d3055fed20828..a272cb741270f 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2721,9 +2721,9 @@ def ext_constexpr_static_var : ExtWarn<
   "definition of a %select{static|thread_local}1 variable "
   "in a constexpr %select{function|constructor}0 "
   "is a C++2b extension">, InGroup;
-def warn_cxx20_compat_constexpr_static_var : Warning<
-  "definition of a %select{static|thread_local}1 variable "
-  "in a constexpr %select{function|constructor}0 "
+def warn_cxx20_compat_constexpr_var : Warning<
+  "definition of a %select{static variable|thread_local variable|variable "
+  "of non-literal type}1 in a constexpr %select{function|constructor}0 "
   "is incompatible with C++ standards before C++2b">,
   InGroup, DefaultIgnore;
 def err_constexpr_local_var_non_literal_type : Error<

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 48fb642ad15e1..0f56e6024f332 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -1893,7 +1893,7 @@ static bool CheckConstexprDeclStmt(Sema &SemaRef, const 
FunctionDecl *Dcl,
   if (Kind == Sema::CheckConstexprKind::Diagnose) {
 SemaRef.Diag(VD->getLocation(),
  SemaRef.getLangOpts().CPlusPlus2b
- ? diag::warn_cxx20_compat_constexpr_static_var
+ ? diag::warn_cxx20_compat_constexpr_var
  : diag::ext_constexpr_static_var)
 << isa(Dcl)
 << (VD->getTLSKind() == VarDecl::TLS_Dynamic);
@@ -1901,11 +1901,17 @@ static bool CheckConstexprDeclStmt(Sema &SemaRef, const 
FunctionDecl *Dcl,
 return false;
   }
 }
-if (!SemaRef.LangOpts.CPlusPlus2b &&
-CheckLiteralType(SemaRef, Kind, VD->getLocation(), VD->getType(),
- diag::err_constexpr_local_var_non_literal_type,
- isa(Dcl)))
+if (SemaRef.LangOpts.CPlusPlus2b) {
+  CheckLiteralType(SemaRef, Kind, VD->getLocation(), VD->getType(),
+   diag::warn_cxx20_compat_constexpr_var,
+   isa(Dcl),
+   /*variable of non-literal type*/ 2);
+} else if (CheckLiteralType(
+   SemaRef, Kind, VD->getLocation(), VD->getType(),
+   diag::err_constexpr_local_var_non_literal_type,
+   isa(Dcl))) {
   return false;
+}
 if (!VD->getType()->isDependentType() &&
 !VD->hasInit() && !VD->isCXXForRangeDecl()) {
   if (Kind == Sema::CheckConstexprKind::Diagnose) {

diff  --git a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3-2b.cpp 
b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3-2b.cpp
index 671895b278bdf..3ba5cbba79ce2 100644
--- a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3-2b.cpp
+++ b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3-2b.cpp
@@ -25,17 +25,18 @@ constexpr void h() {
 label:; // expected-warning {{use of this statement in a constexpr function is 
incompatible with C++ standards before C++2b}}
 }
 
-struct NonLiteral {
+struct NonLiteral { // expected-note 2 {{'NonLiteral' is not literal}}
   NonLiteral() {}
 };
 
 constexpr void non_literal() { // expected-error {{constexpr function never 
produces a constant expression}}
-  NonLiteral n;// expected-note {{non-literal type 
'NonLiteral' cannot be used in a constant expression}}
+  NonLiteral n;// expected-note {{non-literal type 
'NonLiteral' cannot be used in a constant expression}} \
+   // expected-warning {{definition of a variable 
of non-literal type in a constexpr function is incompatible with C++ standards 
before C++2b}}
 }
 
 constexpr void non_literal2(bool b) {
   if (!b)
-NonLiteral n;
+NonLiteral n; // expected-warning {{definition of a variable of 
non-literal type in a constexpr function is incompatible with C++

[clang] 84f0a36 - [Clang] Do not warn on unused lifetime-extending vars with side effects...

2022-04-05 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-04-05T21:03:02+02:00
New Revision: 84f0a36b14bbd464d65cb1a6135134072b828447

URL: 
https://github.com/llvm/llvm-project/commit/84f0a36b14bbd464d65cb1a6135134072b828447
DIFF: 
https://github.com/llvm/llvm-project/commit/84f0a36b14bbd464d65cb1a6135134072b828447.diff

LOG: [Clang] Do not warn on unused lifetime-extending vars with side effects...

const auto & var = ObjectWithSideEffects();

Fixes https://github.com/llvm/llvm-project/issues/54489

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D122661

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDecl.cpp
clang/test/SemaCXX/warn-unused-variables.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index acc433f2bc86b..86d0a3e7303f1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -110,6 +110,9 @@ Improvements to Clang's diagnostics
   `_.
 - ``-Wunused-but-set-variable`` now also warns if the variable is only used
   by unary operators.
+- ``-Wunused-variable`` no longer warn for references extending the lifetime
+  of temporaries with side effects. This fixes `Issue 54489
+  `_.
 
 Non-comprehensive list of changes in this release
 -

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 0b5b530bc756c..a2d3722f2efb8 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -1889,15 +1889,28 @@ static bool ShouldDiagnoseUnusedDecl(const NamedDecl 
*D) {
   // Types of valid local variables should be complete, so this should succeed.
   if (const VarDecl *VD = dyn_cast(D)) {
 
-// White-list anything with an __attribute__((unused)) type.
+const Expr *Init = VD->getInit();
+if (const auto *Cleanups = dyn_cast_or_null(Init))
+  Init = Cleanups->getSubExpr();
+
 const auto *Ty = VD->getType().getTypePtr();
 
 // Only look at the outermost level of typedef.
 if (const TypedefType *TT = Ty->getAs()) {
+  // Allow anything marked with __attribute__((unused)).
   if (TT->getDecl()->hasAttr())
 return false;
 }
 
+// Warn for reference variables whose initializtion performs lifetime
+// extension.
+if (const auto *MTE = dyn_cast_or_null(Init)) {
+  if (MTE->getExtendingDecl()) {
+Ty = VD->getType().getNonReferenceType().getTypePtr();
+Init = MTE->getSubExpr()->IgnoreImplicitAsWritten();
+  }
+}
+
 // If we failed to complete the type for some reason, or if the type is
 // dependent, don't diagnose the variable.
 if (Ty->isIncompleteType() || Ty->isDependentType())
@@ -1916,10 +1929,7 @@ static bool ShouldDiagnoseUnusedDecl(const NamedDecl *D) 
{
 if (!RD->hasTrivialDestructor() && !RD->hasAttr())
   return false;
 
-if (const Expr *Init = VD->getInit()) {
-  if (const ExprWithCleanups *Cleanups =
-  dyn_cast(Init))
-Init = Cleanups->getSubExpr();
+if (Init) {
   const CXXConstructExpr *Construct =
 dyn_cast(Init);
   if (Construct && !Construct->isElidable()) {
@@ -1931,10 +1941,16 @@ static bool ShouldDiagnoseUnusedDecl(const NamedDecl 
*D) {
 
   // Suppress the warning if we don't know how this is constructed, and
   // it could possibly be non-trivial constructor.
-  if (Init->isTypeDependent())
+  if (Init->isTypeDependent()) {
 for (const CXXConstructorDecl *Ctor : RD->ctors())
   if (!Ctor->isTrivial())
 return false;
+  }
+
+  // Suppress the warning if the constructor is unresolved because
+  // its arguments are dependent.
+  if (isa(Init))
+return false;
 }
   }
 }

diff  --git a/clang/test/SemaCXX/warn-unused-variables.cpp 
b/clang/test/SemaCXX/warn-unused-variables.cpp
index 2634fb1ec0f7f..4db8bdf12e5de 100644
--- a/clang/test/SemaCXX/warn-unused-variables.cpp
+++ b/clang/test/SemaCXX/warn-unused-variables.cpp
@@ -154,13 +154,13 @@ namespace ctor_with_cleanups {
 
 #include "Inputs/warn-unused-variables.h"
 
-namespace arrayRecords {
-
 class NonTriviallyDestructible {
 public:
   ~NonTriviallyDestructible() {}
 };
 
+namespace arrayRecords {
+
 struct Foo {
   int x;
   Foo(int x) : x(x) {}
@@ -196,7 +196,7 @@ void test() {
   bar<2>();
 }
 
-}
+} // namespace arrayRecords
 
 #if __cplusplus >= 201103L
 namespace with_constexpr {
@@ -253,3 +253,44 @@ void foo(T &t) {
 }
 }
 #endif
+
+// Ensure we do not warn on lifetime extension
+namespace gh54489 {
+
+void f() {
+  const auto &a = NonTriviallyDestructible();
+  const auto &b = a; // expected-warning {{unused variable 'b'}}
+#if __cplusplus >

[clang] ad16268 - [Clang] Do not check for underscores in isAllowedInitiallyIDChar

2022-07-29 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-07-29T17:46:38+02:00
New Revision: ad16268f135001bd21a805ae8acf8d8243793984

URL: 
https://github.com/llvm/llvm-project/commit/ad16268f135001bd21a805ae8acf8d8243793984
DIFF: 
https://github.com/llvm/llvm-project/commit/ad16268f135001bd21a805ae8acf8d8243793984.diff

LOG: [Clang] Do not check for underscores in isAllowedInitiallyIDChar

isAllowedInitiallyIDChar is only used with non-ASCII codepoints,
which are handled by isAsciiIdentifierStart.
To make that clearer, remove the check for _ from
isAllowedInitiallyIDChar, and assert on ASCII - to ensure neither
_ or $ are passed to this function.

Reviewed By: tahonermann, aaron.ballman

Differential Revision: https://reviews.llvm.org/D130750

Added: 


Modified: 
clang/lib/Lex/Lexer.cpp

Removed: 




diff  --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index a4cff403e739c..6c1c55fc703fc 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -1483,13 +1483,13 @@ static bool isAllowedIDChar(uint32_t C, const 
LangOptions &LangOpts) {
 }
 
 static bool isAllowedInitiallyIDChar(uint32_t C, const LangOptions &LangOpts) {
+  assert(C > 0x7F && "isAllowedInitiallyIDChar called with an ASCII 
codepoint");
   if (LangOpts.AsmPreprocessor) {
 return false;
   }
   if (LangOpts.CPlusPlus || LangOpts.C2x) {
 static const llvm::sys::UnicodeCharSet XIDStartChars(XIDStartRanges);
-// '_' doesn't have the XID_Start property but is allowed in C++.
-return C == '_' || XIDStartChars.contains(C);
+return XIDStartChars.contains(C);
   }
   if (!isAllowedIDChar(C, LangOpts))
 return false;



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


[clang-tools-extra] 44f2baa - [Clang][C++20] Support capturing structured bindings in lambdas

2022-08-03 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-08-03T20:00:01+02:00
New Revision: 44f2baa3804a62ca793f0ff3e43aa71cea91a795

URL: 
https://github.com/llvm/llvm-project/commit/44f2baa3804a62ca793f0ff3e43aa71cea91a795
DIFF: 
https://github.com/llvm/llvm-project/commit/44f2baa3804a62ca793f0ff3e43aa71cea91a795.diff

LOG: [Clang][C++20] Support capturing structured bindings in lambdas

This completes the implementation of P1091R3 and P1381R1.

This patch allow the capture of structured bindings
both for C++20+ and C++17, with extension/compat warning.

In addition, capturing an anonymous union member,
a bitfield, or a structured binding thereof now has a
better diagnostic.

We only support structured bindings - as opposed to other kinds
of structured statements/blocks. We still emit an error for those.

In addition, support for structured bindings capture is entirely disabled in
OpenMP mode as this needs more investigation - a specific diagnostic indicate 
the feature is not yet supported there.

Note that the rest of P1091R3 (static/thread_local structured bindings) was 
already implemented.

at the request of @shafik, i can confirm the correct behavior of lldb wit this 
change.

Fixes https://github.com/llvm/llvm-project/issues/54300
Fixes https://github.com/llvm/llvm-project/issues/54300
Fixes https://github.com/llvm/llvm-project/issues/52720

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D122768

Added: 
clang/test/CodeGenCXX/cxx20-decomposition.cpp
clang/test/SemaCXX/cxx20-decomposition.cpp
clang/test/SemaCXX/decomposition-blocks.cpp
clang/test/SemaCXX/decomposition-openmp.cpp

Modified: 
clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/Decl.h
clang/include/clang/AST/DeclCXX.h
clang/include/clang/AST/LambdaCapture.h
clang/include/clang/AST/Stmt.h
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/ScopeInfo.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/Decl.cpp
clang/lib/AST/DeclCXX.cpp
clang/lib/AST/ExprCXX.cpp
clang/lib/AST/ExprConstant.cpp
clang/lib/AST/StmtPrinter.cpp
clang/lib/Analysis/AnalysisDeclContext.cpp
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaInit.cpp
clang/lib/Sema/SemaLambda.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/SemaStmt.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTWriter.cpp
clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
clang/test/SemaCXX/cxx1z-decomposition.cpp
clang/tools/libclang/CIndex.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp 
b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
index 5d4f3b8249249..fc3dfbdeac785 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
@@ -785,8 +785,8 @@ bool 
ForLoopIndexUseVisitor::TraverseLambdaCapture(LambdaExpr *LE,
const LambdaCapture *C,
Expr *Init) {
   if (C->capturesVariable()) {
-const VarDecl *VDecl = C->getCapturedVar();
-if (areSameVariable(IndexVar, cast(VDecl))) {
+const ValueDecl *VDecl = C->getCapturedVar();
+if (areSameVariable(IndexVar, VDecl)) {
   // FIXME: if the index is captured, it will count as an usage and the
   // alias (if any) won't work, because it is only used in case of having
   // exactly one usage.

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8e35bd567b658..4af8ebec3a971 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -105,6 +105,16 @@ C++ Language Changes in Clang
 C++20 Feature Support
 ^
 
+- Support capturing structured bindings in lambdas
+  (`P1091R3 `_ and `P1381R1 
`).
+  This fixes issues `GH52720 
`_,
+  `GH54300 `_,
+  `GH54301 `_,
+  and `GH49430 `_.
+
+
+
+
 C++2b Feature Support
 ^
 

diff  --git a/clang/include/clang/AST

[clang-tools-extra] a274219 - Revert "[Clang][C++20] Support capturing structured bindings in lambdas"

2022-08-03 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-08-03T21:00:29+02:00
New Revision: a274219600ea00c4406248acfbea113e29a8ead2

URL: 
https://github.com/llvm/llvm-project/commit/a274219600ea00c4406248acfbea113e29a8ead2
DIFF: 
https://github.com/llvm/llvm-project/commit/a274219600ea00c4406248acfbea113e29a8ead2.diff

LOG: Revert "[Clang][C++20] Support capturing structured bindings in lambdas"

This reverts commit 44f2baa3804a62ca793f0ff3e43aa71cea91a795.

Breaks self builds and seems to have conformance issues.

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/Decl.h
clang/include/clang/AST/DeclCXX.h
clang/include/clang/AST/LambdaCapture.h
clang/include/clang/AST/Stmt.h
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/ScopeInfo.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/Decl.cpp
clang/lib/AST/DeclCXX.cpp
clang/lib/AST/ExprCXX.cpp
clang/lib/AST/ExprConstant.cpp
clang/lib/AST/StmtPrinter.cpp
clang/lib/Analysis/AnalysisDeclContext.cpp
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaInit.cpp
clang/lib/Sema/SemaLambda.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/SemaStmt.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTWriter.cpp
clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
clang/test/SemaCXX/cxx1z-decomposition.cpp
clang/tools/libclang/CIndex.cpp
clang/www/cxx_status.html

Removed: 
clang/test/CodeGenCXX/cxx20-decomposition.cpp
clang/test/SemaCXX/cxx20-decomposition.cpp
clang/test/SemaCXX/decomposition-blocks.cpp
clang/test/SemaCXX/decomposition-openmp.cpp



diff  --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp 
b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
index fc3dfbdeac785..5d4f3b8249249 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
@@ -785,8 +785,8 @@ bool 
ForLoopIndexUseVisitor::TraverseLambdaCapture(LambdaExpr *LE,
const LambdaCapture *C,
Expr *Init) {
   if (C->capturesVariable()) {
-const ValueDecl *VDecl = C->getCapturedVar();
-if (areSameVariable(IndexVar, VDecl)) {
+const VarDecl *VDecl = C->getCapturedVar();
+if (areSameVariable(IndexVar, cast(VDecl))) {
   // FIXME: if the index is captured, it will count as an usage and the
   // alias (if any) won't work, because it is only used in case of having
   // exactly one usage.

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e42ed9dd025bd..dd0d802ff2c10 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -108,16 +108,6 @@ C++ Language Changes in Clang
 C++20 Feature Support
 ^
 
-- Support capturing structured bindings in lambdas
-  (`P1091R3 `_ and `P1381R1 
`).
-  This fixes issues `GH52720 
`_,
-  `GH54300 `_,
-  `GH54301 `_,
-  and `GH49430 `_.
-
-
-
-
 C++2b Feature Support
 ^
 

diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 1b414b5c0c194..6441cd339d917 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -689,11 +689,6 @@ class ValueDecl : public NamedDecl {
   ///or declared with the weak or weak-ref attr.
   bool isWeak() const;
 
-  /// Whether this variable is the implicit variable for a lambda init-capture.
-  /// Only VarDecl can be init captures, but both VarDecl and BindingDecl
-  /// can be captured.
-  bool isInitCapture() const;
-
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classofKind(Kind K) { return K >= firstValue && K <= lastValue; }

diff  --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index c97301957cb60..9e4fc3fc1254f 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1057,9 +1057,8 @

[clang] 127bf44 - [Clang][C++20] Support capturing structured bindings in lambdas

2022-08-04 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-08-04T10:12:53+02:00
New Revision: 127bf44385424891eb04cff8e52d3f157fc2cb7c

URL: 
https://github.com/llvm/llvm-project/commit/127bf44385424891eb04cff8e52d3f157fc2cb7c
DIFF: 
https://github.com/llvm/llvm-project/commit/127bf44385424891eb04cff8e52d3f157fc2cb7c.diff

LOG: [Clang][C++20] Support capturing structured bindings in lambdas

This completes the implementation of P1091R3 and P1381R1.

This patch allow the capture of structured bindings
both for C++20+ and C++17, with extension/compat warning.

In addition, capturing an anonymous union member,
a bitfield, or a structured binding thereof now has a
better diagnostic.

We only support structured bindings - as opposed to other kinds
of structured statements/blocks. We still emit an error for those.

In addition, support for structured bindings capture is entirely disabled in
OpenMP mode as this needs more investigation - a specific diagnostic indicate 
the feature is not yet supported there.

Note that the rest of P1091R3 (static/thread_local structured bindings) was 
already implemented.

at the request of @shafik, i can confirm the correct behavior of lldb wit this 
change.

Fixes https://github.com/llvm/llvm-project/issues/54300
Fixes https://github.com/llvm/llvm-project/issues/54300
Fixes https://github.com/llvm/llvm-project/issues/52720

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D122768

Added: 
clang/test/CodeGenCXX/cxx20-decomposition.cpp
clang/test/SemaCXX/cxx20-decomposition.cpp
clang/test/SemaCXX/decomposition-blocks.cpp
clang/test/SemaCXX/decomposition-openmp.cpp

Modified: 
clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/Decl.h
clang/include/clang/AST/DeclCXX.h
clang/include/clang/AST/LambdaCapture.h
clang/include/clang/AST/Stmt.h
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/ScopeInfo.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/Decl.cpp
clang/lib/AST/DeclCXX.cpp
clang/lib/AST/ExprCXX.cpp
clang/lib/AST/ExprConstant.cpp
clang/lib/AST/StmtPrinter.cpp
clang/lib/Analysis/AnalysisDeclContext.cpp
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaInit.cpp
clang/lib/Sema/SemaLambda.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/SemaStmt.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTWriter.cpp
clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
clang/test/SemaCXX/cxx1z-decomposition.cpp
clang/tools/libclang/CIndex.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp 
b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
index 5d4f3b8249249..fc3dfbdeac785 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
@@ -785,8 +785,8 @@ bool 
ForLoopIndexUseVisitor::TraverseLambdaCapture(LambdaExpr *LE,
const LambdaCapture *C,
Expr *Init) {
   if (C->capturesVariable()) {
-const VarDecl *VDecl = C->getCapturedVar();
-if (areSameVariable(IndexVar, cast(VDecl))) {
+const ValueDecl *VDecl = C->getCapturedVar();
+if (areSameVariable(IndexVar, VDecl)) {
   // FIXME: if the index is captured, it will count as an usage and the
   // alias (if any) won't work, because it is only used in case of having
   // exactly one usage.

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7d90b08814baa..878effe08294c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -108,6 +108,16 @@ C++ Language Changes in Clang
 C++20 Feature Support
 ^
 
+- Support capturing structured bindings in lambdas
+  (`P1091R3 `_ and `P1381R1 
`).
+  This fixes issues `GH52720 
`_,
+  `GH54300 `_,
+  `GH54301 `_,
+  and `GH49430 `_.
+
+
+
+
 C++2b Feature Support
 ^
 

diff  --git a/clang/include/clang/AST

[clang] a1a71b7 - [Clang] Fix capture of values initialized by bitfields

2022-08-04 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-08-04T23:58:47+02:00
New Revision: a1a71b7dc97b35133425a31ede90c40529f1be9e

URL: 
https://github.com/llvm/llvm-project/commit/a1a71b7dc97b35133425a31ede90c40529f1be9e
DIFF: 
https://github.com/llvm/llvm-project/commit/a1a71b7dc97b35133425a31ede90c40529f1be9e.diff

LOG: [Clang] Fix capture of values initialized by bitfields

This fixes a regression introduced in 127bf44

Differential Revision: https://reviews.llvm.org/D131202

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/cxx1z-decomposition.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 550ad5ab73c64..13209d3bff24f 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9013,8 +9013,6 @@ def ext_ms_anonymous_record : ExtWarn<
 def err_reference_to_local_in_enclosing_context : Error<
   "reference to local %select{variable|binding}1 %0 declared in enclosing "
   "%select{%3|block literal|lambda expression|context}2">;
-def err_bitfield_capture_by_ref : Error<
-  "cannot capture a bit-field by reference">;
 def err_capture_binding_openmp : Error<
   "capturing a structured binding is not yet supported in OpenMP">;
 def ext_capture_binding : ExtWarn<

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 9497c4b5d5300..152f15159fa1f 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -18533,32 +18533,8 @@ static bool captureInLambda(LambdaScopeInfo *LSI, 
ValueDecl *Var,
   } else {
 ByRef = (LSI->ImpCaptureStyle == LambdaScopeInfo::ImpCap_LambdaByref);
   }
-  // C++20 : [expr.prim.lambda.capture]p12
-  // A bit-field or a member of an anonymous union shall
-  // not be captured by reference.
-  MemberExpr *ME = nullptr;
-  BindingDecl *BD = nullptr;
-  if (auto *V = dyn_cast(Var)) {
-if (V->getInit())
-  ME = dyn_cast(V->getInit()->IgnoreImplicit());
-  } else if ((BD = dyn_cast(Var))) {
-ME = dyn_cast_or_null(BD->getBinding());
-  }
-
-  // Capturing a bitfield by reference is not allowed except in OpenMP.
-  if (ByRef && ME &&
-  (isa(Var) || !S.LangOpts.OpenMP ||
-   !S.isOpenMPCapturedDecl(Var))) {
-const auto *FD = dyn_cast_or_null(ME->getMemberDecl());
-if (FD && FD->isBitField()) {
-  if (BuildAndDiagnose) {
-S.Diag(Loc, diag::err_bitfield_capture_by_ref) << Var;
-S.Diag(Var->getLocation(), diag::note_entity_declared_at) << Var;
-S.Diag(FD->getLocation(), diag::note_bitfield_decl) << FD;
-  }
-  Invalid = true;
-}
-  }
+
+  BindingDecl *BD = dyn_cast(Var);
   // FIXME: We should support capturing structured bindings in OpenMP.
   if (!Invalid && BD && S.LangOpts.OpenMP) {
 if (BuildAndDiagnose) {

diff  --git a/clang/test/SemaCXX/cxx1z-decomposition.cpp 
b/clang/test/SemaCXX/cxx1z-decomposition.cpp
index 7165f30dc0703..13fe826759a34 100644
--- a/clang/test/SemaCXX/cxx1z-decomposition.cpp
+++ b/clang/test/SemaCXX/cxx1z-decomposition.cpp
@@ -84,9 +84,9 @@ void enclosing() {
 
   (void)[outerbit1]{}; // expected-error {{'outerbit1' cannot be captured 
because it does not have automatic storage duration}}
 
-  auto [bit, var] = S2{1, 1}; // expected-note 4{{'bit' declared here}}
+  auto [bit, var] = S2{1, 1}; // expected-note 2{{'bit' declared here}}
 
-  (void)[&bit] { // expected-error {{cannot capture a bit-field by reference}} 
\
+  (void)[&bit] { // expected-error {{non-const reference cannot bind to 
bit-field 'a'}} \
 // expected-warning {{C++20}}
 return bit;
   };
@@ -96,7 +96,7 @@ void enclosing() {
   };
 
   (void)[&] { return bit + u; } // expected-error {{unnamed variable cannot be 
implicitly captured in a lambda expression}} \
-// expected-error {{cannot capture a bit-field 
by reference}} \
+// expected-error {{non-const reference cannot 
bind to bit-field 'a'}} \
 // expected-warning {{C++20}}
   ();
 }



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


[clang] 683e83c - [Clang][C++2b] P2242R3: Non-literal variables [...] in constexpr

2022-03-22 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-03-22T19:51:19+01:00
New Revision: 683e83c56f98df6fe42d506a04dda44309ca758f

URL: 
https://github.com/llvm/llvm-project/commit/683e83c56f98df6fe42d506a04dda44309ca758f
DIFF: 
https://github.com/llvm/llvm-project/commit/683e83c56f98df6fe42d506a04dda44309ca758f.diff

LOG: [Clang][C++2b] P2242R3: Non-literal variables [...] in constexpr

Allow goto, labelled statements as well as `static`, `thread_local`, and
non-literal variables in `constexpr` functions.

As specified. for all of the above (except labelled statements) constant
evaluation of the construct still fails.

For `constexpr` bodies, the proposal is implemented with diagnostics as
a language extension in older language modes. For determination of
whether a lambda body satisfies the requirements for a constexpr
function, the proposal is implemented only in C++2b mode to retain the
semantics of older modes for programs conforming to them.

Reviewed By: aaron.ballman, hubert.reinterpretcast, erichkeane

Differential Revision: https://reviews.llvm.org/D111400

Added: 
clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3-2b.cpp
clang/test/SemaCXX/constant-expression-cxx2b.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticASTKinds.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/AST/ExprConstant.cpp
clang/lib/Frontend/InitPreprocessor.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/dtor.cpp
clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp
clang/test/Lexer/cxx-features.cpp
clang/test/SemaCXX/constant-expression-cxx14.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9864019fda09b..c30512c80e0b7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -147,6 +147,7 @@ C++2b Feature Support
 
 - Implemented `P2128R6: Multidimensional subscript operator 
`_.
 - Implemented `P0849R8: auto(x): decay-copy in the language 
`_.
+- Implemented `P2242R3: Non-literal variables (and labels and gotos) in 
constexpr functions`_.
 
 CUDA Language Changes in Clang
 --

diff  --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index 56662bcd0cc25..930264a495495 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -65,6 +65,8 @@ def note_consteval_address_accessible : Note<
   "is not a constant expression">;
 def note_constexpr_uninitialized : Note<
   "%select{|sub}0object of type %1 is not initialized">;
+def note_constexpr_static_local : Note<
+  "control flows through the definition of a %select{static|thread_local}0 
variable">;
 def note_constexpr_subobject_declared_here : Note<
   "subobject declared here">;
 def note_constexpr_array_index : Note<"cannot refer to element %0 of "

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index fea7461e2dc99..dbde2af216d97 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2693,6 +2693,13 @@ def warn_cxx17_compat_constexpr_body_invalid_stmt : 
Warning<
   "use of this statement in a constexpr %select{function|constructor}0 "
   "is incompatible with C++ standards before C++20">,
   InGroup, DefaultIgnore;
+def ext_constexpr_body_invalid_stmt_cxx2b : ExtWarn<
+  "use of this statement in a constexpr %select{function|constructor}0 "
+  "is a C++2b extension">, InGroup;
+def warn_cxx20_compat_constexpr_body_invalid_stmt : Warning<
+  "use of this statement in a constexpr %select{function|constructor}0 "
+  "is incompatible with C++ standards before C++2b">,
+  InGroup, DefaultIgnore;
 def ext_constexpr_type_definition : ExtWarn<
   "type definition in a constexpr %select{function|constructor}0 "
   "is a C++14 extension">, InGroup;
@@ -2710,12 +2717,18 @@ def warn_cxx11_compat_constexpr_local_var : Warning<
   "variable declaration in a constexpr %select{function|constructor}0 "
   "is incompatible with C++ standards before C++14">,
   InGroup, DefaultIgnore;
-def err_constexpr_local_var_static : Error<
-  "%select{static|thread_local}1 variable not permitted in a constexpr "
-  "%select{function|constructor}0">;
+def ext_constexpr_static_var : ExtWarn<
+  "definition of a %select{static|thread_local}1 variable "
+  "in a constexpr %select{function|constructor}0 "
+  "is a C++2b extension">, InGroup;
+def warn_cxx20_compat_constexpr_static_var : Warning<
+  "definition of a %select{static|thread_local}1 variable "
+  "in a constexpr %select{function|constructor}0 "
+  "is incompatible with C++ standards before C++2b">,
+  InGroup, De

[clang] 8f05736 - [Clang][NFC] Add braces to help readability

2022-03-22 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-03-22T20:12:20+01:00
New Revision: 8f057362a87f1b3c6072c1d0c4d66867ded99669

URL: 
https://github.com/llvm/llvm-project/commit/8f057362a87f1b3c6072c1d0c4d66867ded99669
DIFF: 
https://github.com/llvm/llvm-project/commit/8f057362a87f1b3c6072c1d0c4d66867ded99669.diff

LOG: [Clang][NFC] Add braces to help readability

In CheckConstexprFunctionStmt, as discussed in
D111400.

Added: 


Modified: 
clang/lib/Sema/SemaDeclCXX.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 6ae88ce3d86a4..008c65673ed26 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -2103,11 +2103,12 @@ CheckConstexprFunctionStmt(Sema &SemaRef, const 
FunctionDecl *Dcl, Stmt *S,
   break;
 if (!Cxx1yLoc.isValid())
   Cxx1yLoc = S->getBeginLoc();
-for (Stmt *SubStmt : S->children())
+for (Stmt *SubStmt : S->children()) {
   if (SubStmt &&
   !CheckConstexprFunctionStmt(SemaRef, Dcl, SubStmt, ReturnStmts,
   Cxx1yLoc, Cxx2aLoc, Cxx2bLoc, Kind))
 return false;
+}
 return true;
 
   case Stmt::SwitchStmtClass:
@@ -2118,22 +2119,24 @@ CheckConstexprFunctionStmt(Sema &SemaRef, const 
FunctionDecl *Dcl, Stmt *S,
 // mutation, we can reasonably allow them in C++11 as an extension.
 if (!Cxx1yLoc.isValid())
   Cxx1yLoc = S->getBeginLoc();
-for (Stmt *SubStmt : S->children())
+for (Stmt *SubStmt : S->children()) {
   if (SubStmt &&
   !CheckConstexprFunctionStmt(SemaRef, Dcl, SubStmt, ReturnStmts,
   Cxx1yLoc, Cxx2aLoc, Cxx2bLoc, Kind))
 return false;
+}
 return true;
 
   case Stmt::LabelStmtClass:
   case Stmt::GotoStmtClass:
 if (Cxx2bLoc.isInvalid())
   Cxx2bLoc = S->getBeginLoc();
-for (Stmt *SubStmt : S->children())
+for (Stmt *SubStmt : S->children()) {
   if (SubStmt &&
   !CheckConstexprFunctionStmt(SemaRef, Dcl, SubStmt, ReturnStmts,
   Cxx1yLoc, Cxx2aLoc, Cxx2bLoc, Kind))
 return false;
+}
 return true;
 
   case Stmt::GCCAsmStmtClass:



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


[clang] 9f63cd7 - [Clang][NFC] Cleanup dcl.constexpr/p3 tests

2022-03-23 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-03-23T15:37:48+01:00
New Revision: 9f63cd763ec85e89212e071d5d50ae5a3d5f384d

URL: 
https://github.com/llvm/llvm-project/commit/9f63cd763ec85e89212e071d5d50ae5a3d5f384d
DIFF: 
https://github.com/llvm/llvm-project/commit/9f63cd763ec85e89212e071d5d50ae5a3d5f384d.diff

LOG: [Clang][NFC] Cleanup dcl.constexpr/p3 tests

* Check for warnings instead of using -Werror, to avoid masking the
type of diagnostic emitted

* use different -verify labels instead of using conditional
compilation of diagnostic checks

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D122265

Added: 


Modified: 
clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp

Removed: 




diff  --git a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp 
b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp
index 3dbe3e9a7212b..2db0995127506 100644
--- a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp
+++ b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp
@@ -1,7 +1,7 @@
-// RUN: %clang_cc1 -verify -fcxx-exceptions -triple=x86_64-linux-gnu 
-std=c++11 -Werror=c++14-extensions -Werror=c++20-extensions 
-Werror=c++2b-extensions %s
-// RUN: %clang_cc1 -verify -fcxx-exceptions -triple=x86_64-linux-gnu 
-std=c++14 -DCXX14 -Werror=c++20-extensions -Werror=c++2b-extensions %s
-// RUN: %clang_cc1 -verify -fcxx-exceptions -triple=x86_64-linux-gnu 
-std=c++20 -DCXX14 -DCXX20 -Werror=c++2b-extensions %s
-// RUN: %clang_cc1 -verify -fcxx-exceptions -triple=x86_64-linux-gnu 
-std=c++2b -DCXX14 -DCXX20 -DCXX2b %s
+// RUN: %clang_cc1 -fcxx-exceptions 
-verify=expected,beforecxx14,beforecxx20,beforecxx2b -std=c++11 %s
+// RUN: %clang_cc1 -fcxx-exceptions 
-verify=expected,aftercxx14,beforecxx20,beforecxx2b -std=c++14 %s
+// RUN: %clang_cc1 -fcxx-exceptions 
-verify=expected,aftercxx14,aftercxx20,beforecxx2b -std=c++20  %s
+// RUN: %clang_cc1 -fcxx-exceptions -verify=expected,aftercxx14,aftercxx20 
-std=c++2b %s
 
 namespace N {
   typedef char C;
@@ -21,10 +21,7 @@ struct Literal {
 };
 
 struct S {
-  virtual int ImplicitlyVirtual() const = 0;
-#if __cplusplus <= 201703L
-  // expected-note@-2 {{overridden virtual function}}
-#endif
+  virtual int ImplicitlyVirtual() const = 0; // beforecxx20-note {{overridden 
virtual function}}
 };
 struct SS : S {
   int ImplicitlyVirtual() const;
@@ -37,31 +34,17 @@ struct T : SS, NonLiteral {
   constexpr int f() const;
 
   //  - it shall not be virtual; [until C++20]
-  virtual constexpr int ExplicitlyVirtual() const { return 0; }
-#if __cplusplus <= 201703L
-  // expected-error@-2 {{virtual function cannot be constexpr}}
-#endif
+  virtual constexpr int ExplicitlyVirtual() const { return 0; } // 
beforecxx20-error {{virtual function cannot be constexpr}}
 
-  constexpr int ImplicitlyVirtual() const { return 0; }
-#if __cplusplus <= 201703L
-  // expected-error@-2 {{virtual function cannot be constexpr}}
-#endif
+  constexpr int ImplicitlyVirtual() const { return 0; } // beforecxx20-error 
{{virtual function cannot be constexpr}}
 
-  virtual constexpr int OutOfLineVirtual() const;
-#if __cplusplus <= 201703L
-  // expected-error@-2 {{virtual function cannot be constexpr}}
-#endif
+  virtual constexpr int OutOfLineVirtual() const; // beforecxx20-error 
{{virtual function cannot be constexpr}}
 
   //  - its return type shall be a literal type;
   constexpr NonLiteral NonLiteralReturn() const { return {}; } // 
expected-error {{constexpr function's return type 'NonLiteral' is not a literal 
type}}
-  constexpr void VoidReturn() const { return; }
-#ifndef CXX14
-  // expected-error@-2 {{constexpr function's return type 'void' is not a 
literal type}}
-#endif
-  constexpr ~T();
-#ifndef CXX20
-  // expected-error@-2 {{destructor cannot be declared constexpr}}
-#endif
+  constexpr void VoidReturn() const { return; }// 
beforecxx14-error {{constexpr function's return type 'void' is not a literal 
type}}
+  constexpr ~T();  // 
beforecxx20-error {{destructor cannot be declared constexpr}}
+
   typedef NonLiteral F() const;
   constexpr F NonLiteralReturn2; // ok until definition
 
@@ -78,29 +61,21 @@ struct T : SS, NonLiteral {
   // destructor can be defaulted. Destructors can't be constexpr since they
   // don't have a literal return type. Defaulted assignment operators can't be
   // constexpr since they can't be const.
-  constexpr T &operator=(const T&) = default;
-#ifndef CXX14
-  // expected-error@-2 {{an explicitly-defaulted copy assignment operator may 
not have 'const', 'constexpr' or 'volatile' qualifiers}}
-  // expected-warning@-3 {{C++14}}
-#else
-  // expected-error@-5 {{defaulted definition of copy assignment operator is 
not constexpr}}
-#endif
+  constexpr T &operator=(const T &) = default; // beforecxx14-error {{an 
explicitly-defaulted copy assignment operator may not have 'const', 'conste

[clang] adff142 - [clang] Implement Change scope of lambda trailing-return-type

2022-04-13 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-04-13T20:00:03+02:00
New Revision: adff142dc253d65b6560e420bba6b858d88d4a98

URL: 
https://github.com/llvm/llvm-project/commit/adff142dc253d65b6560e420bba6b858d88d4a98
DIFF: 
https://github.com/llvm/llvm-project/commit/adff142dc253d65b6560e420bba6b858d88d4a98.diff

LOG: [clang] Implement Change scope of lambda trailing-return-type

Implement P2036R3.

Captured variables by copy (explicitely or not), are deduced
correctly at the point we know whether the lambda is mutable,
and ill-formed before that.

Up until now, the entire lambda declaration up to the start of the body would 
be parsed in the parent scope, such that capture would not be available to look 
up.

The scoping is changed to have an outer lambda scope, followed by the lambda 
prototype and body.

The lambda scope is necessary because there may be a template scope between the 
start of the lambda (to which we want to attach the captured variable) and the 
prototype scope.

We also need to introduce a declaration context to attach the captured variable 
to (and several parts of clang assume captures are handled from the call 
operator context), before we know the type of the call operator.

The order of operations is as follow:

* Parse the init capture in the lambda's parent scope

* Introduce a lambda scope

* Create the lambda class and call operator

* Add the init captures to the call operator context and the lambda scope. But 
the variables are not capured yet (because we don't know their type).
Instead, explicit  captures are stored in a temporary map that conserves the 
order of capture (for the purpose of having a stable order in the ast dumps).

* A flag is set on LambdaScopeInfo to indicate that we have not yet injected 
the captures.

* The parameters are parsed (in the parent context, as lambda mangling recurses 
in the parent context, we couldn't mangle a lambda that is attached to the 
context of a lambda whose type is not yet known).

* The lambda qualifiers are parsed, at this point We can switch (for the second 
time) inside the lambda context, unset the flag indicating that we have not 
parsed the lambda qualifiers,
record the lambda is mutable and capture the explicit variables.

* We can parse the rest of the lambda type, transform the lambda and call 
operator's types and also transform the call operator to a template function 
decl where necessary.

At this point, both captures and parameters can be injected in the body's 
scope. When trying to capture an implicit variable, if we are before the 
qualifiers of a lambda, we need to remember that the variables are still in the 
parent's context (rather than in the call operator's).

Reviewed By: aaron.ballman, #clang-language-wg, ChuanqiXu

Differential Revision: https://reviews.llvm.org/D119136

Added: 
clang/test/SemaCXX/lambda-capture-type-deduction.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/DeclCXX.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Scope.h
clang/include/clang/Sema/ScopeInfo.h
clang/include/clang/Sema/Sema.h
clang/lib/Parse/ParseExprCXX.cpp
clang/lib/Sema/Scope.cpp
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaCXXScopeSpec.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaLambda.cpp
clang/lib/Sema/TreeTransform.h
clang/test/CXX/expr/expr.prim/expr.prim.lambda/p11-1y.cpp
clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 91fc57dfac595..016aafee016c2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -247,6 +247,9 @@ C++2b Feature Support
 - Implemented `P2128R6: Multidimensional subscript operator 
`_.
 - Implemented `P0849R8: auto(x): decay-copy in the language 
`_.
 - Implemented `P2242R3: Non-literal variables (and labels and gotos) in 
constexpr functions`_.
+- Implemented `P2036R3: Change scope of lambda trailing-return-type 
`_.
+  This proposal modifies how variables captured in lambdas can appear in 
trailing return type
+  expressions and how their types are deduced therein, in all C++ language 
versions.
 
 CUDA Language Changes in Clang
 --

diff  --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 04a9daa14e05e..c640f7f7ba63f 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1799,6 +1799,20 @@ class CXXRecordDecl : public RecordDecl {
 return getLambdaData().MethodTyInfo;
   }
 
+  void setLambdaTypeInfo(TypeSourceInfo *TS) {
+auto *DD = DefinitionData;
+assert(DD && DD->IsLambda && "setting lambda property of non-lambda

[clang] 925acfe - [Clang] Fix html error in cxx_status.html [NFC]

2022-04-13 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-04-13T20:27:34+02:00
New Revision: 925acfea8836ffe97a1c1d76d31df3229e978a11

URL: 
https://github.com/llvm/llvm-project/commit/925acfea8836ffe97a1c1d76d31df3229e978a11
DIFF: 
https://github.com/llvm/llvm-project/commit/925acfea8836ffe97a1c1d76d31df3229e978a11.diff

LOG: [Clang] Fix html error in cxx_status.html [NFC]

Added: 


Modified: 
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index 97634b1b0cd8b..44dfcbe98e2c1 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -1405,7 +1405,7 @@ C++2b implementation status
   Clang 13
 
 
-  constexpr for  and cstdlib
+  constexpr for  and 

   https://wg21.link/P0533R9";>P0533R9
   No
 



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


[clang] c729d5b - [clang] Implement Change scope of lambda trailing-return-type

2022-04-13 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-04-13T23:07:39+02:00
New Revision: c729d5be781a8e80137c11ab28aa14d9ace148db

URL: 
https://github.com/llvm/llvm-project/commit/c729d5be781a8e80137c11ab28aa14d9ace148db
DIFF: 
https://github.com/llvm/llvm-project/commit/c729d5be781a8e80137c11ab28aa14d9ace148db.diff

LOG: [clang] Implement Change scope of lambda trailing-return-type

Implement P2036R3.

Captured variables by copy (explicitely or not), are deduced
correctly at the point we know whether the lambda is mutable,
and ill-formed before that.

Up until now, the entire lambda declaration up to the start
of the body would  be parsed in the parent scope, such that
captures would not be available to look up.

The scoping is changed to have an outer lambda scope,
followed by the lambda prototype and body.

The lambda scope is necessary because there may be a template scope
between the start of the lambda (to which we want to attach
the captured variable) and the prototype scope.

We also need to introduce a declaration context to attach the captured
variable to (and several parts of clang assume captures are handled from
the call operator context), before we know the type of the call operator.

The order of operations is as follow:

* Parse the init capture in the lambda's parent scope
* Introduce a lambda scope
* Create the lambda class and call operator
* Add the init captures to the call operator context and the lambda scope.
  But the variables are not capured yet (because we don't know their type).
  Instead, explicit  captures are stored in a temporary map that
  conserves the order of capture (for the purpose of having a stable order in 
the ast dumps).

* A flag is set on LambdaScopeInfo to indicate that we have not yet injected 
the captures.

* The parameters are parsed (in the parent context, as lambda mangling recurses 
in the parent context,
  we couldn't mangle a lambda that is attached to the context of a lambda whose 
type is not yet known).

* The lambda qualifiers are parsed, at this point,
  we can switch (for the second time) inside the lambda context,
  unset the flag indicating that we have not parsed the lambda qualifiers,
  record the lambda is mutable and capture the explicit variables.

* We can parse the rest of the lambda type, transform the lambda and call 
operator's types and also
  transform the call operator to a template function decl where necessary.

At this point, both captures and parameters can be injected in the body's scope.
When trying to capture an implicit variable, if we are before the qualifiers of 
a lambda,
we need to remember that the variables are still in the parent's context 
(rather than in the call operator's).

This is a recommit of adff142dc2 after a fix in d8d793f29b4

Reviewed By: aaron.ballman, #clang-language-wg, ChuanqiXu

Differential Revision: https://reviews.llvm.org/D119136

Added: 
clang/test/SemaCXX/lambda-capture-type-deduction.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/DeclCXX.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Scope.h
clang/include/clang/Sema/ScopeInfo.h
clang/include/clang/Sema/Sema.h
clang/lib/Parse/ParseExprCXX.cpp
clang/lib/Sema/Scope.cpp
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaCXXScopeSpec.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaLambda.cpp
clang/lib/Sema/TreeTransform.h
clang/test/CXX/expr/expr.prim/expr.prim.lambda/p11-1y.cpp
clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 91fc57dfac595..016aafee016c2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -247,6 +247,9 @@ C++2b Feature Support
 - Implemented `P2128R6: Multidimensional subscript operator 
`_.
 - Implemented `P0849R8: auto(x): decay-copy in the language 
`_.
 - Implemented `P2242R3: Non-literal variables (and labels and gotos) in 
constexpr functions`_.
+- Implemented `P2036R3: Change scope of lambda trailing-return-type 
`_.
+  This proposal modifies how variables captured in lambdas can appear in 
trailing return type
+  expressions and how their types are deduced therein, in all C++ language 
versions.
 
 CUDA Language Changes in Clang
 --

diff  --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 04a9daa14e05e..c640f7f7ba63f 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1799,6 +1799,20 @@ class CXXRecordDecl : public RecordDecl {
 return getLambdaData().MethodTyInfo;
   }
 
+  void setLambdaTypeInfo(TypeSourceInfo *TS) {
+auto *DD = DefinitionData;
+as

[clang] 04000c2 - [clang] Implement Change scope of lambda trailing-return-type

2022-04-15 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-04-15T16:50:52+02:00
New Revision: 04000c2f928a7adc32138a664d167f01b642bef3

URL: 
https://github.com/llvm/llvm-project/commit/04000c2f928a7adc32138a664d167f01b642bef3
DIFF: 
https://github.com/llvm/llvm-project/commit/04000c2f928a7adc32138a664d167f01b642bef3.diff

LOG: [clang] Implement Change scope of lambda trailing-return-type

Implement P2036R3.

Captured variables by copy (explicitely or not), are deduced
correctly at the point we know whether the lambda is mutable,
and ill-formed before that.

Up until now, the entire lambda declaration up to the start of the body would 
be parsed in the parent scope, such that capture would not be available to look 
up.

The scoping is changed to have an outer lambda scope, followed by the lambda 
prototype and body.

The lambda scope is necessary because there may be a template scope between the 
start of the lambda (to which we want to attach the captured variable) and the 
prototype scope.

We also need to introduce a declaration context to attach the captured variable 
to (and several parts of clang assume captures are handled from the call 
operator context), before we know the type of the call operator.

The order of operations is as follow:

* Parse the init capture in the lambda's parent scope

* Introduce a lambda scope

* Create the lambda class and call operator

* Add the init captures to the call operator context and the lambda scope. But 
the variables are not capured yet (because we don't know their type).
Instead, explicit  captures are stored in a temporary map that conserves the 
order of capture (for the purpose of having a stable order in the ast dumps).

* A flag is set on LambdaScopeInfo to indicate that we have not yet injected 
the captures.

* The parameters are parsed (in the parent context, as lambda mangling recurses 
in the parent context, we couldn't mangle a lambda that is attached to the 
context of a lambda whose type is not yet known).

* The lambda qualifiers are parsed, at this point We can switch (for the second 
time) inside the lambda context, unset the flag indicating that we have not 
parsed the lambda qualifiers,
record the lambda is mutable and capture the explicit variables.

* We can parse the rest of the lambda type, transform the lambda and call 
operator's types and also transform the call operator to a template function 
decl where necessary.

At this point, both captures and parameters can be injected in the body's 
scope. When trying to capture an implicit variable, if we are before the 
qualifiers of a lambda, we need to remember that the variables are still in the 
parent's context (rather than in the call operator's).

Reviewed By: aaron.ballman, #clang-language-wg, ChuanqiXu

Differential Revision: https://reviews.llvm.org/D119136

Added: 
clang/test/SemaCXX/lambda-capture-type-deduction.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/DeclCXX.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Parse/Parser.h
clang/include/clang/Sema/Scope.h
clang/include/clang/Sema/ScopeInfo.h
clang/include/clang/Sema/Sema.h
clang/lib/Parse/ParseExprCXX.cpp
clang/lib/Sema/Scope.cpp
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaCXXScopeSpec.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaLambda.cpp
clang/lib/Sema/TreeTransform.h
clang/test/CXX/expr/expr.prim/expr.prim.lambda/p11-1y.cpp
clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2497280dfdd6d..c72028c718586 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -255,6 +255,9 @@ C++2b Feature Support
 - Implemented `P2128R6: Multidimensional subscript operator 
`_.
 - Implemented `P0849R8: auto(x): decay-copy in the language 
`_.
 - Implemented `P2242R3: Non-literal variables (and labels and gotos) in 
constexpr functions`_.
+- Implemented `P2036R3: Change scope of lambda trailing-return-type 
`_.
+  This proposal modifies how variables captured in lambdas can appear in 
trailing return type
+  expressions and how their types are deduced therein, in all C++ language 
versions.
 
 CUDA Language Changes in Clang
 --

diff  --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 04a9daa14e05e..c640f7f7ba63f 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1799,6 +1799,20 @@ class CXXRecordDecl : public RecordDecl {
 return getLambdaData().MethodTyInfo;
   }
 
+  void setLambdaTypeInfo(TypeSourceInfo *TS) {
+auto *DD = DefinitionData;
+assert(DD && DD->IsLambda &&

[clang] daa6d7b - [Clang] Use of decltype(capture) in parameter-declaration-clause

2022-04-18 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-04-18T15:58:25+02:00
New Revision: daa6d7b250edb81ffef7770a71049d7af211698b

URL: 
https://github.com/llvm/llvm-project/commit/daa6d7b250edb81ffef7770a71049d7af211698b
DIFF: 
https://github.com/llvm/llvm-project/commit/daa6d7b250edb81ffef7770a71049d7af211698b.diff

LOG: [Clang] Use of decltype(capture) in parameter-declaration-clause

Partially implement the proposed resolution to CWG2569.

D119136 broke some libstdc++ code, as P2036R3, implemented as a DR to
C++11 made ill-formed some previously valid and innocuous code.

We resolve this issue to allow decltype(x) - but not decltype((x)
to appear in the parameter list of a lambda that capture x by copy.

Unlike CWG2569, we do not extend that special treatment to
sizeof/noexcept yet, as the resolution has not been approved yet
and keeping the review small allows a quicker fix of impacted code.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D123909

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Parse/Parser.h
clang/include/clang/Sema/Sema.h
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Parse/ParseExprCXX.cpp
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/lambda-capture-type-deduction.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2aabeaf6d679f..fd4eac5458c0a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -261,6 +261,8 @@ C++2b Feature Support
 - Implemented `P2036R3: Change scope of lambda trailing-return-type 
`_.
   This proposal modifies how variables captured in lambdas can appear in 
trailing return type
   expressions and how their types are deduced therein, in all C++ language 
versions.
+  `CWG2569 `_ is also 
partially implemented so that
+  `[x](decltype(x)){}` doesn't become ill-formed with the adoption of P2036R3.
 
 CUDA Language Changes in Clang
 --

diff  --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 3046962dddec4..e9b1fa0f27451 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -1861,6 +1861,8 @@ class Parser : public CodeCompletionHandler {
  Token &Replacement);
   ExprResult ParseCXXIdExpression(bool isAddressOfOperand = false);
 
+  ExprResult ParseCXXMaybeMutableAgnosticExpression();
+
   bool areTokensAdjacent(const Token &A, const Token &B);
 
   void CheckForTemplateAndDigraph(Token &Next, ParsedType ObjectTypePtr,

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 95ce074fdccd3..e2ae02ea9f76f 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -787,6 +787,23 @@ class Sema final {
   /// context.
   unsigned FunctionScopesStart = 0;
 
+  /// Whether we are currently in the context of a mutable agnostic identifier
+  /// as described by CWG2569.
+  /// We are handling the unqualified-id of a decltype or noexcept expression.
+  bool InMutableAgnosticContext = false;
+
+  /// RAII object used to change the value of \c InMutableAgnosticContext
+  /// within a \c Sema object.
+  class MutableAgnosticContextRAII {
+Sema &SemaRef;
+
+  public:
+MutableAgnosticContextRAII(Sema &S) : SemaRef(S) {
+  SemaRef.InMutableAgnosticContext = true;
+}
+~MutableAgnosticContextRAII() { SemaRef.InMutableAgnosticContext = false; }
+  };
+
   ArrayRef getFunctionScopes() const {
 return llvm::makeArrayRef(FunctionScopes.begin() + FunctionScopesStart,
   FunctionScopes.end());
@@ -5270,6 +5287,9 @@ class Sema final {
   CorrectionCandidateCallback *CCC = nullptr,
   bool IsInlineAsmIdentifier = false, Token *KeywordReplacement = nullptr);
 
+  ExprResult ActOnMutableAgnosticIdExpression(Scope *S, CXXScopeSpec &SS,
+  UnqualifiedId &Id);
+
   void DecomposeUnqualifiedId(const UnqualifiedId &Id,
   TemplateArgumentListInfo &Buffer,
   DeclarationNameInfo &NameInfo,

diff  --git a/clang/lib/Parse/ParseDeclCXX.cpp 
b/clang/lib/Parse/ParseDeclCXX.cpp
index 9cf9f7cc4c371..e367417410c86 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -1054,7 +1054,7 @@ SourceLocation Parser::ParseDecltypeSpecifier(DeclSpec 
&DS) {
   Actions, Sema::ExpressionEvaluationContext::Unevaluated, nullptr,
   Sema::ExpressionEvaluationContextRecord::EK_Decltype);
   Result = Actions.CorrectDelayedTyposInExpr(
-  ParseExpression(), /*InitDecl=*/nullptr,
+  ParseCXXMaybeMutableAgnosticExpression(), /*InitDecl=*/nullptr,
   /*RecoverUncorrectedTypos=*/false,
   [](Expr *E) { retur

[clang] 69dd89f - [Clang] Fix references to captured variables in dependant context.

2022-04-20 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-04-20T15:35:20+02:00
New Revision: 69dd89fdcbd846375a45e2fe3a88710887236d7a

URL: 
https://github.com/llvm/llvm-project/commit/69dd89fdcbd846375a45e2fe3a88710887236d7a
DIFF: 
https://github.com/llvm/llvm-project/commit/69dd89fdcbd846375a45e2fe3a88710887236d7a.diff

LOG: [Clang] Fix references to captured variables in dependant context.

D119136 changed how captures are handled in a lambda call operator
declaration, but did not properly handled dependant context,
which led to crash when refering to init-captures in
a trailing return type.

We fix that bug by making transformations more symetric with parsing,
ie. we first create the call operator, then transform the capture,
then compute the type of the lambda call operaror.

This ensures captures exist and have the right type when
we parse a trailing requires-clause / return type.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D124012

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaLambda.cpp
clang/lib/Sema/TreeTransform.h
clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4.cpp
clang/test/SemaCXX/lambda-capture-type-deduction.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index d5b73686e84a7..6298838d60855 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -6828,15 +6828,6 @@ class Sema final {
  unsigned LambdaDependencyKind,
  LambdaCaptureDefault CaptureDefault);
 
-  /// Start the definition of a lambda expression.
-  CXXMethodDecl *startLambdaDefinition(CXXRecordDecl *Class,
-   SourceRange IntroducerRange,
-   TypeSourceInfo *MethodType,
-   SourceLocation EndLoc,
-   ArrayRef Params,
-   ConstexprSpecKind ConstexprKind,
-   Expr *TrailingRequiresClause);
-
   /// Number lambda for linkage purposes if necessary.
   void handleLambdaNumbering(
   CXXRecordDecl *Class, CXXMethodDecl *Method,
@@ -6849,9 +6840,16 @@ class Sema final {
 LambdaCaptureDefault CaptureDefault,
 SourceLocation CaptureDefaultLoc,
 bool ExplicitParams,
-bool ExplicitResultType,
 bool Mutable);
 
+  CXXMethodDecl *CreateLambdaCallOperator(SourceRange IntroducerRange,
+  CXXRecordDecl *Class);
+  void CompleteLambdaCallOperator(
+  CXXMethodDecl *Method, SourceLocation LambdaLoc,
+  SourceLocation CallOperatorLoc, Expr *TrailingRequiresClause,
+  TypeSourceInfo *MethodTyInfo, ConstexprSpecKind ConstexprKind,
+  ArrayRef Params, bool HasExplicitResultType);
+
   /// Perform initialization analysis of the init-capture and perform
   /// any implicit conversions such as an lvalue-to-rvalue conversion if
   /// not being used to initialize a reference.

diff  --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index d5918a28d9f06..e1086adcdb73b 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -377,76 +377,6 @@ buildTypeForLambdaCallOperator(Sema &S, 
clang::CXXRecordDecl *Class,
   return MethodType;
 }
 
-/// Start the definition of a lambda expression.
-/// In this overload, we do not know the type yet
-CXXMethodDecl *Sema::startLambdaDefinition(CXXRecordDecl *Class,
-   SourceRange IntroducerRange,
-   TypeSourceInfo *MethodTypeInfo,
-   SourceLocation EndLoc,
-   ArrayRef Params,
-   ConstexprSpecKind ConstexprKind,
-   Expr *TrailingRequiresClause) {
-
-  LambdaScopeInfo *LSI = getCurLambda();
-
-  TemplateParameterList *TemplateParams =
-  getGenericLambdaTemplateParameterList(LSI, *this);
-
-  // At this point, we may not know the type of the lambda, if we have not
-  // parsed a trailing return type yet
-  QualType MethodType = MethodTypeInfo
-? buildTypeForLambdaCallOperator(
-  *this, Class, TemplateParams, MethodTypeInfo)
-: QualType();
-
-  // C++11 [expr.prim.lambda]p5:
-  //   The closure type for a lambda-expression has a public inline function
-  //   call operator (13.5.4) whose parameters and return type are described
-  //   by the lambda-expression's parameter-declaration-clause and
-  //   trailing-return-type respectively.
-  DeclarationName Me

[clang] cc30972 - [Clang] Add a warning on invalid UTF-8 in comments.

2022-07-12 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-07-12T14:34:30+02:00
New Revision: cc309721d20c8e544ae7a10a66735ccf4981a11c

URL: 
https://github.com/llvm/llvm-project/commit/cc309721d20c8e544ae7a10a66735ccf4981a11c
DIFF: 
https://github.com/llvm/llvm-project/commit/cc309721d20c8e544ae7a10a66735ccf4981a11c.diff

LOG: [Clang] Add a warning on invalid UTF-8 in comments.

Introduce an off-by default `-Winvalid-utf8` warning
that detects invalid UTF-8 code units sequences in comments.

Invalid UTF-8 in other places is already diagnosed,
as that cannot appear in identifiers and other grammar constructs.

The warning is off by default as its likely to be somewhat disruptive
otherwise.

This warning allows clang to conform to the yet-to be approved WG21
"P2295R5 Support for UTF-8 as a portable source file encoding"
paper.

Reviewed By: aaron.ballman, #clang-language-wg

Differential Revision: https://reviews.llvm.org/D128059

Added: 
clang/test/Lexer/comment-invalid-utf8.c
clang/test/Lexer/comment-utf8.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/lib/Lex/Lexer.cpp
clang/test/SemaCXX/static-assert.cpp
llvm/include/llvm/Support/ConvertUTF.h
llvm/lib/Support/ConvertUTF.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ce76de44e2f0f..f5aecff0d2647 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -281,9 +281,11 @@ Improvements to Clang's diagnostics
   unevaluated operands of a ``typeid`` expression, as they are now
   modeled correctly in the CFG. This fixes
   `Issue 21668 `_.
-- ``-Wself-assign``, ``-Wself-assign-overloaded`` and ``-Wself-move`` will 
+- ``-Wself-assign``, ``-Wself-assign-overloaded`` and ``-Wself-move`` will
   suggest a fix if the decl being assigned is a parameter that shadows a data
   member of the contained class.
+- Added ``-Winvalid-utf8`` which diagnoses invalid UTF-8 code unit sequences in
+  comments.
 
 Non-comprehensive list of changes in this release
 -
@@ -597,7 +599,7 @@ AST Matchers
 
 - Added ``forEachTemplateArgument`` matcher which creates a match every
   time a ``templateArgument`` matches the matcher supplied to it.
-  
+
 - Added ``objcStringLiteral`` matcher which matches ObjectiveC String
   literal expressions.
 

diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index ac86076140c58..38ee022e5f04c 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -113,6 +113,8 @@ def warn_four_char_character_literal : Warning<
 // Unicode and UCNs
 def err_invalid_utf8 : Error<
   "source file is not valid UTF-8">;
+def warn_invalid_utf8_in_comment : Extension<
+  "invalid UTF-8 in comment">, InGroup>;
 def err_character_not_allowed : Error<
   "unexpected character ">;
 def err_character_not_allowed_identifier : Error<

diff  --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index 6820057642bea..221ec2721fe00 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -2392,13 +2392,37 @@ bool Lexer::SkipLineComment(Token &Result, const char 
*CurPtr,
   //
   // This loop terminates with CurPtr pointing at the newline (or end of 
buffer)
   // character that ends the line comment.
+
+  // C++23 [lex.phases] p1
+  // Diagnose invalid UTF-8 if the corresponding warning is enabled, emitting a
+  // diagnostic only once per entire ill-formed subsequence to avoid
+  // emiting to many diagnostics (see http://unicode.org/review/pr-121.html).
+  bool UnicodeDecodingAlreadyDiagnosed = false;
+
   char C;
   while (true) {
 C = *CurPtr;
 // Skip over characters in the fast loop.
-while (C != 0 &&// Potentially EOF.
-   C != '\n' && C != '\r')  // Newline or DOS-style newline.
+while (isASCII(C) && C != 0 &&   // Potentially EOF.
+   C != '\n' && C != '\r') { // Newline or DOS-style newline.
   C = *++CurPtr;
+  UnicodeDecodingAlreadyDiagnosed = false;
+}
+
+if (!isASCII(C)) {
+  unsigned Length = llvm::getUTF8SequenceSize(
+  (const llvm::UTF8 *)CurPtr, (const llvm::UTF8 *)BufferEnd);
+  if (Length == 0) {
+if (!UnicodeDecodingAlreadyDiagnosed && !isLexingRawMode())
+  Diag(CurPtr, diag::warn_invalid_utf8_in_comment);
+UnicodeDecodingAlreadyDiagnosed = true;
+++CurPtr;
+  } else {
+UnicodeDecodingAlreadyDiagnosed = false;
+CurPtr += Length;
+  }
+  continue;
+}
 
 const char *NextLine = CurPtr;
 if (C != 0) {
@@ -2665,6 +2689,12 @@ bool Lexer::SkipBlockComment(Token &Result, const char 
*CurPtr,
   if (C == '/')
 C = *CurPtr++;
 
+  // C++23 [lex.phases] p1
+  // Diagnose i

[clang] d4892a1 - [Clang] Add a warning on invalid UTF-8 in comments.

2022-07-13 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-07-13T10:19:26+02:00
New Revision: d4892a168f51dabdba255af3a8d23049fcb66960

URL: 
https://github.com/llvm/llvm-project/commit/d4892a168f51dabdba255af3a8d23049fcb66960
DIFF: 
https://github.com/llvm/llvm-project/commit/d4892a168f51dabdba255af3a8d23049fcb66960.diff

LOG: [Clang] Add a warning on invalid UTF-8 in comments.

Introduce an off-by default `-Winvalid-utf8` warning
that detects invalid UTF-8 code units sequences in comments.

Invalid UTF-8 in other places is already diagnosed,
as that cannot appear in identifiers and other grammar constructs.

The warning is off by default as its likely to be somewhat disruptive
otherwise.

This warning allows clang to conform to the yet-to be approved WG21
"P2295R5 Support for UTF-8 as a portable source file encoding"
paper.

Reviewed By: aaron.ballman, #clang-language-wg

Differential Revision: https://reviews.llvm.org/D128059

Added: 
clang/test/Lexer/comment-invalid-utf8.c
clang/test/Lexer/comment-utf8.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/lib/Lex/Lexer.cpp
clang/test/SemaCXX/static-assert.cpp
llvm/include/llvm/Support/ConvertUTF.h
llvm/lib/Support/ConvertUTF.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e09a4a7c91b78..f8977d5ac720b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -284,9 +284,11 @@ Improvements to Clang's diagnostics
   unevaluated operands of a ``typeid`` expression, as they are now
   modeled correctly in the CFG. This fixes
   `Issue 21668 `_.
-- ``-Wself-assign``, ``-Wself-assign-overloaded`` and ``-Wself-move`` will 
+- ``-Wself-assign``, ``-Wself-assign-overloaded`` and ``-Wself-move`` will
   suggest a fix if the decl being assigned is a parameter that shadows a data
   member of the contained class.
+- Added ``-Winvalid-utf8`` which diagnoses invalid UTF-8 code unit sequences in
+  comments.
 
 Non-comprehensive list of changes in this release
 -
@@ -613,7 +615,7 @@ AST Matchers
 
 - Added ``forEachTemplateArgument`` matcher which creates a match every
   time a ``templateArgument`` matches the matcher supplied to it.
-  
+
 - Added ``objcStringLiteral`` matcher which matches ObjectiveC String
   literal expressions.
 

diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index ac86076140c58..38ee022e5f04c 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -113,6 +113,8 @@ def warn_four_char_character_literal : Warning<
 // Unicode and UCNs
 def err_invalid_utf8 : Error<
   "source file is not valid UTF-8">;
+def warn_invalid_utf8_in_comment : Extension<
+  "invalid UTF-8 in comment">, InGroup>;
 def err_character_not_allowed : Error<
   "unexpected character ">;
 def err_character_not_allowed_identifier : Error<

diff  --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index 6820057642bea..6b2767dcee3d5 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -2392,13 +2392,37 @@ bool Lexer::SkipLineComment(Token &Result, const char 
*CurPtr,
   //
   // This loop terminates with CurPtr pointing at the newline (or end of 
buffer)
   // character that ends the line comment.
+
+  // C++23 [lex.phases] p1
+  // Diagnose invalid UTF-8 if the corresponding warning is enabled, emitting a
+  // diagnostic only once per entire ill-formed subsequence to avoid
+  // emiting to many diagnostics (see http://unicode.org/review/pr-121.html).
+  bool UnicodeDecodingAlreadyDiagnosed = false;
+
   char C;
   while (true) {
 C = *CurPtr;
 // Skip over characters in the fast loop.
-while (C != 0 &&// Potentially EOF.
-   C != '\n' && C != '\r')  // Newline or DOS-style newline.
+while (isASCII(C) && C != 0 &&   // Potentially EOF.
+   C != '\n' && C != '\r') { // Newline or DOS-style newline.
   C = *++CurPtr;
+  UnicodeDecodingAlreadyDiagnosed = false;
+}
+
+if (!isASCII(C)) {
+  unsigned Length = llvm::getUTF8SequenceSize(
+  (const llvm::UTF8 *)CurPtr, (const llvm::UTF8 *)BufferEnd);
+  if (Length == 0) {
+if (!UnicodeDecodingAlreadyDiagnosed && !isLexingRawMode())
+  Diag(CurPtr, diag::warn_invalid_utf8_in_comment);
+UnicodeDecodingAlreadyDiagnosed = true;
+++CurPtr;
+  } else {
+UnicodeDecodingAlreadyDiagnosed = false;
+CurPtr += Length;
+  }
+  continue;
+}
 
 const char *NextLine = CurPtr;
 if (C != 0) {
@@ -2665,6 +2689,12 @@ bool Lexer::SkipBlockComment(Token &Result, const char 
*CurPtr,
   if (C == '/')
 C = *CurPtr++;
 
+  // C++23 [lex.phases] p1
+  // Diagnose i

[clang] 6882ca9 - [Clang] Adjust extension warnings for delimited sequences

2022-07-13 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-07-14T07:50:58+02:00
New Revision: 6882ca9aff076738bbffd68f73892187519554f8

URL: 
https://github.com/llvm/llvm-project/commit/6882ca9aff076738bbffd68f73892187519554f8
DIFF: 
https://github.com/llvm/llvm-project/commit/6882ca9aff076738bbffd68f73892187519554f8.diff

LOG: [Clang] Adjust extension warnings for delimited sequences

WG21 approved delimited escape sequences and named escape
sequences.
Adjust the extension warnings accordingly, and update
the release notes.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D129664

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/lib/Lex/Lexer.cpp
clang/lib/Lex/LiteralSupport.cpp
clang/test/Lexer/char-escapes-delimited.c
clang/test/Preprocessor/ucn-pp-identifier.c
clang/test/Sema/ucn-identifiers.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f8977d5ac720b..a02bc0a2f6914 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -502,6 +502,10 @@ C++2b Feature Support
 - Implemented `P0849R8: auto(x): decay-copy in the language 
`_.
 - Implemented `P2242R3: Non-literal variables (and labels and gotos) in 
constexpr functions`_.
 - Implemented `LWG3659: Consider ATOMIC_FLAG_INIT undeprecation 
`_.
+- Implemented `P2290 Delimited escape sequences `_.
+  This feature is available as an extension in all C and C++ language modes.
+- Implemented `P2071 Named universal character escapes 
`_.
+  This feature is available as an extension in all C and C++ language modes.
 
 CUDA/HIP Language Changes in Clang
 --

diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index 38ee022e5f04c..dd09097044926 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -130,8 +130,15 @@ def warn_utf8_symbol_zero_width : Warning<
   "some environments">, InGroup>;
 
 def ext_delimited_escape_sequence : Extension<
-  "%select{delimited|named}0 escape sequences are a Clang extension">,
+  "%select{delimited|named}0 escape sequences are a "
+  "%select{Clang|C++2b}1 extension">,
   InGroup>;
+
+def warn_cxx2b_delimited_escape_sequence : Warning<
+  "%select{delimited|named}0 escape sequences are "
+  "incompatible with C++ standards before C++2b">,
+  InGroup, DefaultIgnore;
+
 def err_delimited_escape_empty : Error<
   "delimited escape sequence cannot be empty">;
 def err_delimited_escape_missing_brace: Error<

diff  --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index 6b2767dcee3d5..b3aac9df65465 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -3287,7 +3287,10 @@ llvm::Optional Lexer::tryReadNumericUCN(const 
char *&StartPtr,
   }
 
   if (Delimited && PP) {
-Diag(BufferPtr, diag::ext_delimited_escape_sequence) << /*delimited*/ 0;
+Diag(BufferPtr, PP->getLangOpts().CPlusPlus2b
+? diag::warn_cxx2b_delimited_escape_sequence
+: diag::ext_delimited_escape_sequence)
+<< /*delimited*/ 0 << (PP->getLangOpts().CPlusPlus ? 1 : 0);
   }
 
   if (Result) {
@@ -3371,7 +3374,10 @@ llvm::Optional Lexer::tryReadNamedUCN(const 
char *&StartPtr,
   }
 
   if (Diagnose && PP && !LooseMatch)
-Diag(BufferPtr, diag::ext_delimited_escape_sequence) << /*named*/ 1;
+Diag(BufferPtr, PP->getLangOpts().CPlusPlus2b
+? diag::warn_cxx2b_delimited_escape_sequence
+: diag::ext_delimited_escape_sequence)
+<< /*named*/ 1 << (PP->getLangOpts().CPlusPlus ? 1 : 0);
 
   if (LooseMatch)
 Res = LooseMatch->CodePoint;

diff  --git a/clang/lib/Lex/LiteralSupport.cpp 
b/clang/lib/Lex/LiteralSupport.cpp
index ebf30c9f01a9e..53635a7385ec6 100644
--- a/clang/lib/Lex/LiteralSupport.cpp
+++ b/clang/lib/Lex/LiteralSupport.cpp
@@ -311,8 +311,9 @@ static unsigned ProcessCharEscape(const char *ThisTokBegin,
   << tok::r_brace;
 else if (!HadError) {
   Diag(Diags, Features, Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
-   diag::ext_delimited_escape_sequence)
-  << /*delimited*/ 0;
+   Features.CPlusPlus2b ? diag::warn_cxx2b_delimited_escape_sequence
+: diag::ext_delimited_escape_sequence)
+  << /*delimited*/ 0 << (Features.CPlusPlus ? 1 : 0);
 }
   }
 
@@ -641,8 +642,9 @@ static bool ProcessUCNEscape(const char *ThisTokBegin, 
const char *&ThisTokBuf,
 
   if ((IsDelimitedEscapeSequence || IsNamedEscapeSequence) && Diags)
 Diag(Diags, Features, Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
- diag::ext_delimit

[clang] aee76cb - [Clang] Add support for Unicode identifiers (UAX31) in C2x mode.

2022-07-23 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-07-23T14:08:08+02:00
New Revision: aee76cb59ca273d46db20cd7d23a252a2683ed6a

URL: 
https://github.com/llvm/llvm-project/commit/aee76cb59ca273d46db20cd7d23a252a2683ed6a
DIFF: 
https://github.com/llvm/llvm-project/commit/aee76cb59ca273d46db20cd7d23a252a2683ed6a.diff

LOG: [Clang] Add support for Unicode identifiers (UAX31) in C2x mode.

This implements
N2836 Identifier Syntax using Unicode Standard Annex 31.

The feature was already implemented for C++,
and the semantics are the same.

Unlike C++ there was, afaict, no decision to
backport the feature in older languages mode,
so C17 and earlier are not modified and the
code point tables for these language modes are conserved.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D130416

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Lex/Lexer.cpp
clang/test/Lexer/unicode.c
clang/www/c_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9bedbf7a1e76..7fb21dbadea0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -469,6 +469,7 @@ C2x Feature Support
   support for functions without prototypes, which no longer exist in C2x.
 - Implemented `WG14 N2841 No function declarators without prototypes 
`_
   and `WG14 N2432 Remove support for function definitions with identifier 
lists `_.
+- Implemented `WG14 N2836 Identifier Syntax using Unicode Standard Annex 31 
`_.
 
 C++ Language Changes in Clang
 -

diff  --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index b3aac9df6546..a4cff403e739 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -1462,11 +1462,11 @@ static bool isAllowedIDChar(uint32_t C, const 
LangOptions &LangOpts) {
 return false;
   } else if (LangOpts.DollarIdents && '$' == C) {
 return true;
-  } else if (LangOpts.CPlusPlus) {
+  } else if (LangOpts.CPlusPlus || LangOpts.C2x) {
 // A non-leading codepoint must have the XID_Continue property.
 // XIDContinueRanges doesn't contains characters also in XIDStartRanges,
 // so we need to check both tables.
-// '_' doesn't have the XID_Continue property but is allowed in C++.
+// '_' doesn't have the XID_Continue property but is allowed in C and C++.
 static const llvm::sys::UnicodeCharSet XIDStartChars(XIDStartRanges);
 static const llvm::sys::UnicodeCharSet XIDContinueChars(XIDContinueRanges);
 return C == '_' || XIDStartChars.contains(C) ||
@@ -1486,7 +1486,7 @@ static bool isAllowedInitiallyIDChar(uint32_t C, const 
LangOptions &LangOpts) {
   if (LangOpts.AsmPreprocessor) {
 return false;
   }
-  if (LangOpts.CPlusPlus) {
+  if (LangOpts.CPlusPlus || LangOpts.C2x) {
 static const llvm::sys::UnicodeCharSet XIDStartChars(XIDStartRanges);
 // '_' doesn't have the XID_Start property but is allowed in C++.
 return C == '_' || XIDStartChars.contains(C);

diff  --git a/clang/test/Lexer/unicode.c b/clang/test/Lexer/unicode.c
index efbd63fb0063..8d5295ef338b 100644
--- a/clang/test/Lexer/unicode.c
+++ b/clang/test/Lexer/unicode.c
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -x c -std=c11 %s
-// RUN: %clang_cc1 -fsyntax-only -verify -x c++ -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,c2x -x c -std=c2x %s
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx -x c++ -std=c++11 %s
 // RUN: %clang_cc1 -std=c99 -E -DPP_ONLY=1 %s | FileCheck %s 
--strict-whitespace
 // RUN: %clang_cc1 -E -DPP_ONLY=1 %s | FileCheck %s --strict-whitespace
 
@@ -31,7 +32,7 @@ CHECK : The preprocessor should not complain about Unicode 
characters like ©.
 extern int X\U; // expected-error {{not allowed in an identifier}}
 int Y = '\U'; // expected-error {{invalid universal character}}
 
-#ifdef __cplusplus
+#if defined(__cplusplus) || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 
202000L)
 
 extern int ༀ;
 extern int 𑩐;
@@ -46,7 +47,8 @@ extern int _\N{TANGSALETTERGA}; // expected-error 
{{'TANGSALETTERGA' is not a va
 
 
 // This character doesn't have the XID_Start property
-extern int  \U00016AC0; // TANGSA DIGIT ZERO  // expected-error {{expected 
unqualified-id}}
+extern int  \U00016AC0; // TANGSA DIGIT ZERO  // cxx-error {{expected 
unqualified-id}} \
+  // c2x-error {{expected 
identifier or '('}}
 
 extern int 🌹; // expected-error {{unexpected character }} \
   expected-warning {{declaration does not declare anything}}

diff  --git a/clang/www/c_status.html b/clang/www/c_status.html
index 17d18d8724f8..f3076d345237 100644
--- a/clang/www/c_status.html
+++ b/clang/www/c_status.ht

[clang] 559f07b - [Clang] Adjust extension warnings for #warning

2022-07-23 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-07-23T14:10:11+02:00
New Revision: 559f07b872116fb85ea7d493768a6eb450329fa0

URL: 
https://github.com/llvm/llvm-project/commit/559f07b872116fb85ea7d493768a6eb450329fa0
DIFF: 
https://github.com/llvm/llvm-project/commit/559f07b872116fb85ea7d493768a6eb450329fa0.diff

LOG: [Clang] Adjust extension warnings for #warning

The #warning directive is standard in C++2b and C2x,
this adjusts the pedantic and extensions warning accordingly.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D130415

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/lib/Lex/PPDirectives.cpp
clang/test/Preprocessor/ext-pp-directive.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7fb21dbadea0..6d6faa32e458 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -262,7 +262,7 @@ Improvements to Clang's diagnostics
 - Added the ``-Wgnu-line-marker`` diagnostic flag (grouped under the ``-Wgnu``
   flag) which is a portability warning about use of GNU linemarker preprocessor
   directives. Fixes `Issue 55067 
`_.
-- Using ``#elifdef`` and ``#elifndef`` that are incompatible with C/C++
+- Using ``#warning``, ``#elifdef`` and ``#elifndef`` that are incompatible 
with C/C++
   standards before C2x/C++2b are now warned via ``-pedantic``. Additionally,
   on such language mode, ``-Wpre-c2x-compat`` and ``-Wpre-c++2b-compat``
   diagnostic flags report a compatibility issue.

diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index 5d3abb1f9b70..6032fbd18d56 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -387,7 +387,15 @@ def ext_pp_include_search_ms : ExtWarn<
 def ext_pp_ident_directive : Extension<"#ident is a language extension">;
 def ext_pp_include_next_directive : Extension<
   "#include_next is a language extension">, InGroup;
-def ext_pp_warning_directive : Extension<"#warning is a language extension">;
+
+def ext_pp_warning_directive : Extension<
+  "#warning is a %select{C2x|C++2b}0 extension">;
+def warn_cxx2b_compat_warning_directive : Warning<
+  "#warning is incompatible with C++ standards before C++2b">,
+  InGroup, DefaultIgnore;
+def warn_c2x_compat_warning_directive : Warning<
+  "#warning is incompatible with C standards before C2x">,
+  InGroup, DefaultIgnore;
 
 def ext_pp_extra_tokens_at_eol : ExtWarn<
   "extra tokens at end of #%0 directive">, InGroup;

diff  --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 4679cb4e7a34..9a8fd4391b41 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -1261,7 +1261,16 @@ void Preprocessor::HandleDirective(Token &Result) {
   return HandleIncludeNextDirective(SavedHash.getLocation(), Result);
 
 case tok::pp_warning:
-  Diag(Result, diag::ext_pp_warning_directive);
+  if (LangOpts.CPlusPlus)
+Diag(Result, LangOpts.CPlusPlus2b
+ ? diag::warn_cxx2b_compat_warning_directive
+ : diag::ext_pp_warning_directive)
+<< /*C++2b*/ 1;
+  else
+Diag(Result, LangOpts.C2x ? diag::warn_c2x_compat_warning_directive
+  : diag::ext_pp_warning_directive)
+<< /*C2x*/ 0;
+
   return HandleUserDiagnosticDirective(Result, true);
 case tok::pp_ident:
   return HandleIdentSCCSDirective(Result);

diff  --git a/clang/test/Preprocessor/ext-pp-directive.c 
b/clang/test/Preprocessor/ext-pp-directive.c
index 45f7ecba3022..97454b4d9002 100644
--- a/clang/test/Preprocessor/ext-pp-directive.c
+++ b/clang/test/Preprocessor/ext-pp-directive.c
@@ -57,3 +57,16 @@ int x;
 // For C++
 // pre-cpp2b-pedantic-warning@-7 {{use of a '#elifndef' directive is a C++2b 
extension}}
 // pre-cpp2b-compat-warning@-8 {{use of a '#elifndef' directive is 
incompatible with C++ standards before C++2b}}
+
+#warning foo
+// For C
+// pre-c2x-pedantic-warning@-2 {{#warning is a C2x extension}}
+// pre-c2x-pedantic-warning@-3 {{foo}}
+// pre-c2x-compat-warning@-4 {{#warning is incompatible with C standards 
before C2x}}
+// pre-c2x-compat-warning@-5 {{foo}}
+
+// For C++
+// pre-cpp2b-pedantic-warning@-8 {{#warning is a C++2b extension}}
+// pre-cpp2b-pedantic-warning@-9 {{foo}}
+// pre-cpp2b-compat-warning@-10 {{#warning is incompatible with C++ standards 
before C++2b}}
+// pre-cpp2b-compat-warning@-11 {{foo}}



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


[clang] e82880e - [Clang] Update the status of N2393 in c_status.html

2022-07-23 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-07-23T15:15:12+02:00
New Revision: e82880e6b8cd2f01ee18e99c4c7b6ec71b764e13

URL: 
https://github.com/llvm/llvm-project/commit/e82880e6b8cd2f01ee18e99c4c7b6ec71b764e13
DIFF: 
https://github.com/llvm/llvm-project/commit/e82880e6b8cd2f01ee18e99c4c7b6ec71b764e13.diff

LOG: [Clang] Update the status of N2393 in c_status.html

Added: 


Modified: 
clang/www/c_status.html

Removed: 




diff  --git a/clang/www/c_status.html b/clang/www/c_status.html
index f3076d345237..4bb8d3408d00 100644
--- a/clang/www/c_status.html
+++ b/clang/www/c_status.html
@@ -746,7 +746,7 @@ C2x implementation status
 
   _Bool definitions for true and false
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2393.pdf";>N2393
-  No
+  Subsumed by N2935
 
 
 



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


[clang] 0ba128f - [Clang] De-deprecate volatile compound operations

2022-07-24 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-07-24T16:16:52+02:00
New Revision: 0ba128f7c8c2b6c0842cdfebcc1db0d11ce57dd9

URL: 
https://github.com/llvm/llvm-project/commit/0ba128f7c8c2b6c0842cdfebcc1db0d11ce57dd9
DIFF: 
https://github.com/llvm/llvm-project/commit/0ba128f7c8c2b6c0842cdfebcc1db0d11ce57dd9.diff

LOG: [Clang] De-deprecate volatile compound operations

As per P2327R1,

|=, &= and ^= are no longer deprecated in all languages mode.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D130421

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/deprecated.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6d6faa32e458e..ac6c5bb543121 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -520,6 +520,7 @@ C++2b Feature Support
   This feature is available as an extension in all C and C++ language modes.
 - Implemented `P2071 Named universal character escapes 
`_.
   This feature is available as an extension in all C and C++ language modes.
+- Implemented `P2327R1 De-deprecating volatile compound operations 
`_
 
 CUDA/HIP Language Changes in Clang
 --

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index a33d85cc954d0..de9bde6841f7d 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -12170,7 +12170,8 @@ class Sema final {
   // For simple assignment, pass both expressions and a null converted type.
   // For compound assignment, pass both expressions and the converted type.
   QualType CheckAssignmentOperands( // C99 6.5.16.[1,2]
-Expr *LHSExpr, ExprResult &RHS, SourceLocation Loc, QualType CompoundType);
+  Expr *LHSExpr, ExprResult &RHS, SourceLocation Loc, QualType 
CompoundType,
+  BinaryOperatorKind Opc);
 
   ExprResult checkPseudoObjectIncDec(Scope *S, SourceLocation OpLoc,
  UnaryOperatorKind Opcode, Expr *Op);

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index cd5cdbde7f3f0..0f79978b0911c 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -13824,7 +13824,8 @@ static void CheckIdentityFieldAssignment(Expr *LHSExpr, 
Expr *RHSExpr,
 // C99 6.5.16.1
 QualType Sema::CheckAssignmentOperands(Expr *LHSExpr, ExprResult &RHS,
SourceLocation Loc,
-   QualType CompoundType) {
+   QualType CompoundType,
+   BinaryOperatorKind Opc) {
   assert(!LHSExpr->hasPlaceholderType(BuiltinType::PseudoObject));
 
   // Verify that LHS is a modifiable lvalue, and emit error if not.
@@ -13937,10 +13938,18 @@ QualType Sema::CheckAssignmentOperands(Expr *LHSExpr, 
ExprResult &RHS,
   //   expression or an unevaluated operand
   ExprEvalContexts.back().VolatileAssignmentLHSs.push_back(LHSExpr);
 } else {
-  // C++2a [expr.ass]p6:
+  // C++20 [expr.ass]p6:
   //   [Compound-assignment] expressions are deprecated if E1 has
-  //   volatile-qualified type
-  Diag(Loc, diag::warn_deprecated_compound_assign_volatile) << LHSType;
+  //   volatile-qualified type and op is not one of the bitwise
+  //   operators |, &, ˆ.
+  switch (Opc) {
+  case BO_OrAssign:
+  case BO_AndAssign:
+  case BO_XorAssign:
+break;
+  default:
+Diag(Loc, diag::warn_deprecated_compound_assign_volatile) << LHSType;
+  }
 }
   }
 
@@ -14879,7 +14888,7 @@ ExprResult Sema::CreateBuiltinBinOp(SourceLocation 
OpLoc,
 
   switch (Opc) {
   case BO_Assign:
-ResultTy = CheckAssignmentOperands(LHS.get(), RHS, OpLoc, QualType());
+ResultTy = CheckAssignmentOperands(LHS.get(), RHS, OpLoc, QualType(), Opc);
 if (getLangOpts().CPlusPlus &&
 LHS.get()->getObjectKind() != OK_ObjCProperty) {
   VK = LHS.get()->getValueKind();
@@ -14976,32 +14985,37 @@ ExprResult Sema::CreateBuiltinBinOp(SourceLocation 
OpLoc,
Opc == BO_DivAssign);
 CompLHSTy = CompResultTy;
 if (!CompResultTy.isNull() && !LHS.isInvalid() && !RHS.isInvalid())
-  ResultTy = CheckAssignmentOperands(LHS.get(), RHS, OpLoc, CompResultTy);
+  ResultTy =
+  CheckAssignmentOperands(LHS.get(), RHS, OpLoc, CompResultTy, Opc);
 break;
   case BO_RemAssign:
 CompResultTy = CheckRemainderOperands(LHS, RHS, OpLoc, true);
 CompLHSTy = CompResultTy;
 if (!CompResultTy.isNull() && !LHS.isInvalid() && !RHS.isInvalid())
-  ResultTy = CheckAssignmentOperands(LHS.get(), RHS, OpLoc, CompResultTy);
+  ResultTy =
+  CheckAssignmentOperands(LHS.get(), RHS, OpL

[clang] c68baa7 - [clang] Fix incorrect constant folding of `if consteval`

2022-07-24 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-07-24T16:18:12+02:00
New Revision: c68baa73eb437556cd8abe40902182a6034930ac

URL: 
https://github.com/llvm/llvm-project/commit/c68baa73eb437556cd8abe40902182a6034930ac
DIFF: 
https://github.com/llvm/llvm-project/commit/c68baa73eb437556cd8abe40902182a6034930ac.diff

LOG: [clang] Fix incorrect constant folding of `if consteval`

Fixes https://github.com/llvm/llvm-project/issues/55638.

`if consteval` was evaluated incorrectly when in a
non-constant context that could be constant-folded.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D130437

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/AST/ExprConstant.cpp
clang/test/CodeGenCXX/cxx2b-consteval-if.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ac6c5bb543121..af64152666757 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -194,6 +194,8 @@ Bug Fixes
   move assignment operator. Fixes `Issue 56456 
`_.
 - Fixed a crash when a variable with a bool enum type that has no definition
   used in comparison operators. Fixes `Issue 56560 
`_.
+- Fix that ``if consteval`` could evaluate to ``true`` at runtime because it 
was incorrectly
+  constant folded. Fixes `Issue 55638 
`_.
 
 Improvements to Clang's diagnostics
 ^^^

diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 6ffb65d8e71d3..9d92c848ccb84 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -5266,10 +5266,14 @@ static EvalStmtResult EvaluateStmt(StmtResult &Result, 
EvalInfo &Info,
   }
 }
 bool Cond;
-if (IS->isConsteval())
+if (IS->isConsteval()) {
   Cond = IS->isNonNegatedConsteval();
-else if (!EvaluateCond(Info, IS->getConditionVariable(), IS->getCond(),
-   Cond))
+  // If we are not in a constant context, if consteval should not evaluate
+  // to true.
+  if (!Info.InConstantContext)
+Cond = !Cond;
+} else if (!EvaluateCond(Info, IS->getConditionVariable(), IS->getCond(),
+ Cond))
   return ESR_Failed;
 
 if (const Stmt *SubStmt = Cond ? IS->getThen() : IS->getElse()) {

diff  --git a/clang/test/CodeGenCXX/cxx2b-consteval-if.cpp 
b/clang/test/CodeGenCXX/cxx2b-consteval-if.cpp
index 2e38ce0e63639..a69a2271f661b 100644
--- a/clang/test/CodeGenCXX/cxx2b-consteval-if.cpp
+++ b/clang/test/CodeGenCXX/cxx2b-consteval-if.cpp
@@ -26,3 +26,30 @@ constexpr void f() {
 void g() {
   f();
 }
+
+namespace GH55638 {
+
+constexpr bool is_constant_evaluated() noexcept {
+  if consteval { return true; } else { return false; }
+}
+
+constexpr int compiletime(int) {
+   return 2;
+}
+
+constexpr int runtime(int) {
+   return 1;
+}
+
+constexpr int test(int x) {
+  if(is_constant_evaluated())
+return compiletime(x);  // CHECK-NOT: call {{.*}}compiletime
+   return runtime(x);  // CHECK: call {{.*}}runtime
+}
+
+int f(int x) {
+  x = test(x);
+  return x;
+}
+
+}



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


[clang] fa8a189 - [Clang] Add missing paper revisions in the release notes [NFC]

2022-07-24 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-07-24T16:24:11+02:00
New Revision: fa8a1896a784a771153d60cdf05da0fdff86d23c

URL: 
https://github.com/llvm/llvm-project/commit/fa8a1896a784a771153d60cdf05da0fdff86d23c
DIFF: 
https://github.com/llvm/llvm-project/commit/fa8a1896a784a771153d60cdf05da0fdff86d23c.diff

LOG: [Clang] Add missing paper revisions in the release notes [NFC]

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index af6415266675..317fd250b193 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -518,9 +518,9 @@ C++2b Feature Support
 - Implemented `P0849R8: auto(x): decay-copy in the language 
`_.
 - Implemented `P2242R3: Non-literal variables (and labels and gotos) in 
constexpr functions`_.
 - Implemented `LWG3659: Consider ATOMIC_FLAG_INIT undeprecation 
`_.
-- Implemented `P2290 Delimited escape sequences `_.
+- Implemented `P2290R3 Delimited escape sequences 
`_.
   This feature is available as an extension in all C and C++ language modes.
-- Implemented `P2071 Named universal character escapes 
`_.
+- Implemented `P2071R2 Named universal character escapes 
`_.
   This feature is available as an extension in all C and C++ language modes.
 - Implemented `P2327R1 De-deprecating volatile compound operations 
`_
 



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


[clang] 2e80d2d - [Clang] Status of the C++23 papers approved by WG21 at the July plenary

2022-07-25 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-07-25T19:43:06+02:00
New Revision: 2e80d2d7c3f4ed4433f747a5644817d095250df9

URL: 
https://github.com/llvm/llvm-project/commit/2e80d2d7c3f4ed4433f747a5644817d095250df9
DIFF: 
https://github.com/llvm/llvm-project/commit/2e80d2d7c3f4ed4433f747a5644817d095250df9.diff

LOG: [Clang] Status of the C++23 papers approved by WG21 at the July plenary

Added: 


Modified: 
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index c891d7ef9baa1..0fd33524596ad 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -1350,9 +1350,12 @@ C++2b implementation status
   No
 
 
-  Change scope of lambda trailing-return-type
+  Change scope of lambda trailing-return-type
   https://wg21.link/P2036R3";>P2036R3
-  No
+  No
+
+
+  https://wg21.link/P2579R0";>P2579R0
 
 
   Multidimensional subscript operator
@@ -1419,6 +1422,92 @@ C++2b implementation status
 
   
 
+
+
+  The Equality Operator You Are Looking For
+  https://wg21.link/P2468R2";>P2468R2
+  No
+
+
+  De-deprecating volatile compound operations
+  https://wg21.link/P2327R1";>P2327R1
+  Clang 15
+
+
+  Support for #warning
+  https://wg21.link/P2437R1";>P2437R1
+  Yes
+
+
+  Remove non-encodable wide character literals and multicharacter wide 
character literals
+  https://wg21.link/P2362R3";>P2362R3
+  Clang 14
+
+
+  Labels at the end of compound statements
+  https://wg21.link/P2324R2";>P2324R2
+  No
+
+
+  Delimited escape sequences
+  https://wg21.link/P2290R3";>P2290R3
+  Clang 15
+
+
+  Named universal character escapes
+  https://wg21.link/P2071R2";>P2071R2
+  Clang 15
+
+
+  Relaxing some constexpr restrictions
+  https://wg21.link/P2448R2";>P2448R2
+  No
+
+
+  Using unknown pointers and references in constant expressions
+  https://wg21.link/P2280R4";>P2280R4
+  No
+
+
+  static operator()
+  https://wg21.link/P1169R4";>P1169R4
+  No
+
+
+  Extended floating-point types and standard names
+  https://wg21.link/P1467R9";>P1467R9
+  No
+
+
+  Class template argument deduction from inherited constructors
+  https://wg21.link/P2582R1";>P2582R1
+  No
+
+
+  Portable assumptions
+  https://wg21.link/P1774R8";>P1774R8
+  No
+
+
+  Support for UTF-8 as a portable source file encoding
+  https://wg21.link/P2295R6";>P2295R6
+  Clang 15
+
+
+  char8_t Compatibility and Portability Fix
+  https://wg21.link/P2513R3";>P2513R3
+  No
+
+
+  Relax requirements on wchar_t to match existing 
practices
+  https://wg21.link/P2460R2";>P2460R2
+  Yes
+
+
+  Explicit lifetime management
+  https://wg21.link/P2590R2";>P2590R2
+  No
+
 
 
 



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


[clang] b723c57 - [Clang] Update the C++ page with papers approved in Tokyo

2024-03-22 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2024-03-23T10:04:45+09:00
New Revision: b723c57f8fdb12ca8eaa6c5ee2afb820aaeb56c5

URL: 
https://github.com/llvm/llvm-project/commit/b723c57f8fdb12ca8eaa6c5ee2afb820aaeb56c5
DIFF: 
https://github.com/llvm/llvm-project/commit/b723c57f8fdb12ca8eaa6c5ee2afb820aaeb56c5.diff

LOG: [Clang] Update the C++ page with papers approved in Tokyo

Added: 


Modified: 
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index 1e36b90356c3e1..c1d95dadbb27e2 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -163,7 +163,47 @@ C++2c implementation status
   https://wg21.link/P2864R2";>P2864R2
   Clang 18
  
-
+ 
+ 
+  Disallow Binding a Returned Glvalue to a Temporary
+  https://wg21.link/P2748R5";>P2748R5
+  No
+ 
+ 
+  Clarifying rules for brace elision in aggregate initialization
+  https://wg21.link/P3106R1";>P3106R1 (DR)
+  No
+ 
+ 
+  Attributes for Structured Bindings
+  https://wg21.link/P0609R3";>P0609R3
+  No
+ 
+ 
+  Module Declarations Shouldn’t be Macros
+  https://wg21.link/P3034R1";>P3034R1 (DR)
+  No
+ 
+ 
+  Trivial infinite loops are not Undefined Behavior
+  https://wg21.link/P2809R3";>P2809R3 (DR)
+  No
+ 
+ 
+  Erroneous behaviour for uninitialized reads
+  https://wg21.link/P2795R5";>P2795R5
+  No
+ 
+ 
+  = delete("should have a reason");
+  https://wg21.link/P2573R2";>P2573R2
+  No
+ 
+ 
+  Variadic friends
+  https://wg21.link/P2893R3";>P2893R3
+  No
+ 
 
 
 



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


[clang] 33e3121 - [Clang] Mark papers & core issues implemented in clang 18 as released

2024-03-06 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2024-03-06T14:47:53+01:00
New Revision: 33e312137b065ba330b187f56ddd60df70927241

URL: 
https://github.com/llvm/llvm-project/commit/33e312137b065ba330b187f56ddd60df70927241
DIFF: 
https://github.com/llvm/llvm-project/commit/33e312137b065ba330b187f56ddd60df70927241.diff

LOG: [Clang] Mark papers & core issues implemented in clang 18 as released

Added: 


Modified: 
clang/www/cxx_dr_status.html
clang/www/cxx_status.html
clang/www/make_cxx_dr_status

Removed: 




diff  --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index b13401625a6fb5..0b810b50c529c2 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -11076,7 +11076,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/1878.html";>1878
 CD4
 operator auto template
-Clang 18
+Clang 18
   
   
 https://cplusplus.github.io/CWG/issues/1879.html";>1879
@@ -12384,7 +12384,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/2096.html";>2096
 CD4
 Constraints on literal unions
-Duplicate of 2598
+Duplicate of 2598
   
   
 https://cplusplus.github.io/CWG/issues/2097.html";>2097
@@ -15396,7 +15396,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/2598.html";>2598
 C++23
 Unions should not require a non-static data member of literal type
-Clang 18
+Clang 18
   
   
 https://cplusplus.github.io/CWG/issues/2599.html";>2599
@@ -15726,7 +15726,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/2653.html";>2653
 C++23
 Can an explicit object parameter have a default argument?
-Clang 18
+Clang 18
   
   
 https://cplusplus.github.io/CWG/issues/2654.html";>2654
@@ -15840,7 +15840,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/2672.html";>2672
 DR
 Lambda body SFINAE is still required, contrary to intent and note
-Clang 18
+Clang 18
   
   
 https://cplusplus.github.io/CWG/issues/2673.html";>2673
@@ -15930,7 +15930,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/2687.html";>2687
 C++23
 Calling an explicit object member function via an 
address-of-overload-set
-Clang 18
+Clang 18
   
   
 https://cplusplus.github.io/CWG/issues/2688.html";>2688
@@ -16542,7 +16542,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/2789.html";>2789
 DR
 Overload resolution with implicit and explicit object member 
functions
-Clang 18
+Clang 18
   
   
 https://cplusplus.github.io/CWG/issues/2790.html";>2790

diff  --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index 301f141b2f2b60..421b3426b006f9 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -115,7 +115,7 @@ C++2c implementation status
  
   Unevaluated strings
   https://wg21.link/P2361R6";>P2361R6
-  Clang 18
+  Clang 18
  
  
   Add @, $, and ` to the basic character set
@@ -145,13 +145,13 @@ C++2c implementation status
  
   Placeholder variables with no name
   https://wg21.link/P2169R4";>P2169R4
-  Clang 18
+  Clang 18
  
  
  
   Template parameter initialization
   https://wg21.link/P2308R1";>P2308R1 (DR)
-  Clang 18
+  Clang 18
  
  
   Pack Indexing
@@ -161,7 +161,7 @@ C++2c implementation status
  
   Remove Deprecated Arithmetic Conversion on Enumerations
   https://wg21.link/P2864R2";>P2864R2
-  Clang 18
+  Clang 18
  
 
 
@@ -239,7 +239,7 @@ C++23 implementation status
 
   Deducing this
   https://wg21.link/P0847R7";>P0847R7
-  Clang 18
+  Clang 18
 
 
   https://wg21.link/P2797R0";>P2797R0

diff  --git a/clang/www/make_cxx_dr_status b/clang/www/make_cxx_dr_status
index 38f847cdc1b7f9..7183e1a6d2be1a 100755
--- a/clang/www/make_cxx_dr_status
+++ b/clang/www/make_cxx_dr_status
@@ -1,6 +1,7 @@
 #! /usr/bin/env python3
 import sys, os, re, urllib.request
 
+latest_release = 18
 
 clang_www_dir = os.path.dirname(__file__)
 default_issue_list_path = os.path.join(clang_www_dir, 'cwg_index.html')
@@ -127,8 +128,6 @@ out_file.write('''\
 Available in Clang?
   ''')
 
-latest_release = 17
-
 class AvailabilityError(RuntimeError):
   pass
 



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


[clang] 143b510 - [Clang] Fix asan error after ad1a65fca

2024-01-27 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2024-01-27T14:35:18+01:00
New Revision: 143b510a8fefb0d203c9ac7e036aa9967dd8a2ef

URL: 
https://github.com/llvm/llvm-project/commit/143b510a8fefb0d203c9ac7e036aa9967dd8a2ef
DIFF: 
https://github.com/llvm/llvm-project/commit/143b510a8fefb0d203c9ac7e036aa9967dd8a2ef.diff

LOG: [Clang] Fix asan error after ad1a65fca

Annotating tokens can invalid the stack of Peaked tokens.

Added: 


Modified: 
clang/lib/Parse/ParseExpr.cpp

Removed: 




diff  --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 6e83b7aa3441b5c..68dc1bc4a40a074 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -1065,7 +1065,7 @@ ExprResult Parser::ParseCastExpression(CastParseKind 
ParseKind,
 if (getLangOpts().CPlusPlus) {
   // Avoid the unnecessary parse-time lookup in the common case
   // where the syntax forbids a type.
-  const Token &Next = NextToken();
+  Token Next = NextToken();
 
   if (Next.is(tok::ellipsis) && Tok.is(tok::identifier) &&
   GetLookAheadToken(2).is(tok::l_square)) {
@@ -1081,9 +1081,8 @@ ExprResult Parser::ParseCastExpression(CastParseKind 
ParseKind,
   // If this identifier was reverted from a token ID, and the next token
   // is a parenthesis, this is likely to be a use of a type trait. Check
   // those tokens.
-  if (Next.is(tok::l_paren) &&
-  Tok.is(tok::identifier) &&
-  Tok.getIdentifierInfo()->hasRevertedTokenIDToIdentifier()) {
+  else if (Next.is(tok::l_paren) && Tok.is(tok::identifier) &&
+   Tok.getIdentifierInfo()->hasRevertedTokenIDToIdentifier()) {
 IdentifierInfo *II = Tok.getIdentifierInfo();
 // Build up the mapping of revertible type traits, for future use.
 if (RevertibleTypeTraits.empty()) {
@@ -1170,9 +1169,9 @@ ExprResult Parser::ParseCastExpression(CastParseKind 
ParseKind,
 }
   }
 
-  if ((!ColonIsSacred && Next.is(tok::colon)) ||
-  Next.isOneOf(tok::coloncolon, tok::less, tok::l_paren,
-   tok::l_brace)) {
+  else if ((!ColonIsSacred && Next.is(tok::colon)) ||
+   Next.isOneOf(tok::coloncolon, tok::less, tok::l_paren,
+tok::l_brace)) {
 // If TryAnnotateTypeOrScopeToken annotates the token, tail recurse.
 if (TryAnnotateTypeOrScopeToken())
   return ExprError();



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


[clang] 4d46721 - [Clang] Revert inintentional changes to cmake committed in 33e5db6e0

2024-01-12 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2024-01-12T10:59:46+01:00
New Revision: 4d467215f162b487381e17b8cb59283af75ca50e

URL: 
https://github.com/llvm/llvm-project/commit/4d467215f162b487381e17b8cb59283af75ca50e
DIFF: 
https://github.com/llvm/llvm-project/commit/4d467215f162b487381e17b8cb59283af75ca50e.diff

LOG: [Clang] Revert inintentional changes to cmake committed in 33e5db6e0

Added: 


Modified: 
clang/.clang-tidy
llvm/cmake/modules/HandleLLVMOptions.cmake

Removed: 




diff  --git a/clang/.clang-tidy b/clang/.clang-tidy
index 7eef110c3cf7e2..ba55beb095f54f 100644
--- a/clang/.clang-tidy
+++ b/clang/.clang-tidy
@@ -1,5 +1,5 @@
 # Note that the readability-identifier-naming check is disabled, there are too
 # many violations in the codebase and they create too much noise in clang-tidy
 # results.
-Checks: '-readability-identifier-naming, -misc-include*'
+Checks: '-readability-identifier-naming'
 InheritParentConfig: true

diff  --git a/llvm/cmake/modules/HandleLLVMOptions.cmake 
b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 52babeda1fef03..0699a8586fcc7e 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -647,7 +647,7 @@ if ( LLVM_COMPILER_IS_GCC_COMPATIBLE )
   # crash if LLVM is built with GCC and LTO enabled (#57740).  Until
   # these bugs are fixed, we need to disable dead store eliminations
   # based on object lifetime.
-  # add_flag_if_supported("-fno-lifetime-dse" CMAKE_CXX_FLAGS)
+  add_flag_if_supported("-fno-lifetime-dse" CMAKE_CXX_FLAGS)
 endif ( LLVM_COMPILER_IS_GCC_COMPATIBLE )
 
 # Modules enablement for GCC-compatible compilers:



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


[clang] 8658d15 - Revert "[Clang][Sema] Diagnose function/variable templates that shadow their own template parameters (#78274)"

2024-01-22 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2024-01-22T09:29:01+01:00
New Revision: 8658d157654832fe24b4f3d2a9a62784a4d6a162

URL: 
https://github.com/llvm/llvm-project/commit/8658d157654832fe24b4f3d2a9a62784a4d6a162
DIFF: 
https://github.com/llvm/llvm-project/commit/8658d157654832fe24b4f3d2a9a62784a4d6a162.diff

LOG: Revert "[Clang][Sema] Diagnose function/variable templates that shadow 
their own template parameters (#78274)"

This reverts commit fc0253264445be7f88d4cf0f9129dcb10c2fb84b.

This errors is disruptive to downstream projects
and should be reintroduced as a separate on-by-default
warning.

https://github.com/llvm/llvm-project/pull/78274

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDecl.cpp
clang/test/CXX/temp/temp.res/temp.local/p6.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2c7c7b8a21b8e74..7c9f9ecca727a48 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -590,7 +590,6 @@ Improvements to Clang's diagnostics
 - Clang now diagnoses the requirement that non-template friend declarations 
with requires clauses
   and template friend declarations with a constraint that depends on a 
template parameter from an
   enclosing template must be a definition.
-- Clang now diagnoses function/variable templates that shadow their own 
template parameters, e.g. ``template void T();``.
 - Clang now diagnoses incorrect usage of ``const`` and ``pure`` attributes, so 
``-Wignored-attributes`` diagnoses more cases.
 - Clang now emits more descriptive diagnostics for 'unusual' expressions (e.g. 
incomplete index
   expressions on matrix types or builtin functions without an argument list) 
as placement-args

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 8dff2cdc063df32..13ca438e6a487fe 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -6377,6 +6377,12 @@ NamedDecl *Sema::HandleDeclarator(Scope *S, Declarator 
&D,
   } else if (DiagnoseUnexpandedParameterPack(NameInfo, UPPC_DeclarationType))
 return nullptr;
 
+  // The scope passed in may not be a decl scope.  Zip up the scope tree until
+  // we find one that is.
+  while ((S->getFlags() & Scope::DeclScope) == 0 ||
+ (S->getFlags() & Scope::TemplateParamScope) != 0)
+S = S->getParent();
+
   DeclContext *DC = CurContext;
   if (D.getCXXScopeSpec().isInvalid())
 D.setInvalidType();
@@ -6529,12 +6535,6 @@ NamedDecl *Sema::HandleDeclarator(Scope *S, Declarator 
&D,
   if (getLangOpts().CPlusPlus)
 CheckExtraCXXDefaultArguments(D);
 
-  // The scope passed in may not be a decl scope.  Zip up the scope tree until
-  // we find one that is.
-  while ((S->getFlags() & Scope::DeclScope) == 0 ||
- (S->getFlags() & Scope::TemplateParamScope) != 0)
-S = S->getParent();
-
   NamedDecl *New;
 
   bool AddToScope = true;

diff  --git a/clang/test/CXX/temp/temp.res/temp.local/p6.cpp 
b/clang/test/CXX/temp/temp.res/temp.local/p6.cpp
index 0702966e5685480..e2aa0ff344291d2 100644
--- a/clang/test/CXX/temp/temp.res/temp.local/p6.cpp
+++ b/clang/test/CXX/temp/temp.res/temp.local/p6.cpp
@@ -127,30 +127,16 @@ template struct Z { // expected-note 16{{declared 
here}}
 template // expected-note {{declared here}}
 void f(int T) {} // expected-error {{declaration of 'T' shadows template 
parameter}}
 
+// FIXME: These are ill-formed: a template-parameter shall not have the same 
name as the template name.
 namespace A {
   template struct T {};  // expected-error{{declaration of 'T' 
shadows template parameter}}
  // expected-note@-1{{template parameter 
is declared here}}
-  template struct U {
-template struct V {}; // expected-error{{declaration of 'V' 
shadows template parameter}}
-  // expected-note@-1{{template parameter 
is declared here}}
-  };
 }
 namespace B {
-  template void T() {} // expected-error{{declaration of 'T' 
shadows template parameter}}
-   // expected-note@-1{{template parameter is 
declared here}}
-
-  template struct U {
-template void V(); // expected-error{{declaration of 'V' 
shadows template parameter}}
-   // expected-note@-1{{template parameter is 
declared here}}
-  };
+  template void T() {}
 }
 namespace C {
-  template int T; // expected-error{{declaration of 'T' shadows 
template parameter}}
-  // expected-note@-1{{template parameter is 
declared here}}
-  template struct U {
-template static int V; // expected-error{{declaration of 'V' 
shadows template parameter}}
-   // expected-note@-1{{template parameter 
is declared here}}
-  };
+  template int T;
 }
 
 namespace PR28023 {



___
cfe-commits mailing list
c

[clang] d0d2772 - [Clang] Implement P2513

2022-10-24 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-10-24T18:10:43+02:00
New Revision: d0d2772379bd89f1dce3c456520272678cf4b966

URL: 
https://github.com/llvm/llvm-project/commit/d0d2772379bd89f1dce3c456520272678cf4b966
DIFF: 
https://github.com/llvm/llvm-project/commit/d0d2772379bd89f1dce3c456520272678cf4b966.diff

LOG: [Clang] Implement P2513

Implement P2513

This change allows initializing an array of unsigned char,
or char from u8 string literals.
This was done both to support legacy code and for compatibility
with C where char8_t will be typedef to unsigned char.

This is backported to C++20 as per WG21 guidance.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D136449

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Frontend/InitPreprocessor.cpp
clang/lib/Sema/SemaInit.cpp
clang/test/Lexer/cxx-features.cpp
clang/test/SemaCXX/char8_t.cpp
clang/test/SemaCXX/cxx2a-compat.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 68cee534513a..49ef53f33877 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -557,6 +557,8 @@ C++2b Feature Support
 
 - Support label at end of compound statement (`P2324 
`_).
 - Implemented `P1169R4: static operator() `_.
+- Implemented "char8_t Compatibility and Portability Fix" (`P2513R3 
`_).
+  This Change was applied to C++20 as a Defect Report.
 
 CUDA/HIP Language Changes in Clang
 --
@@ -654,8 +656,8 @@ libclang
   the behavior of ``QualType::getNonReferenceType`` for ``CXType``.
 - Introduced the new function ``clang_CXXMethod_isDeleted``, which queries
   whether the method is declared ``= delete``.
-- ``clang_Cursor_getNumTemplateArguments``, 
``clang_Cursor_getTemplateArgumentKind``, 
-  ``clang_Cursor_getTemplateArgumentType``, 
``clang_Cursor_getTemplateArgumentValue`` and 
+- ``clang_Cursor_getNumTemplateArguments``, 
``clang_Cursor_getTemplateArgumentKind``,
+  ``clang_Cursor_getTemplateArgumentType``, 
``clang_Cursor_getTemplateArgumentValue`` and
   ``clang_Cursor_getTemplateArgumentUnsignedValue`` now work on struct, class,
   and partial template specialization cursors in addition to function cursors.
 

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index b1d475772502..8cf73784d97b 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6868,8 +6868,8 @@ def err_array_init_plain_string_into_char8_t : Error<
 def note_array_init_plain_string_into_char8_t : Note<
   "add 'u8' prefix to form a 'char8_t' string literal">;
 def err_array_init_utf8_string_into_char : Error<
-  "%select{|ISO C++20 does not permit }0initialization of char array with "
-  "UTF-8 string literal%select{ is not permitted by '-fchar8_t'|}0">;
+  "initialization of %select{|signed }0char array with "
+  "UTF-8 string literal is not permitted by %select{'-fchar8_t'|C++20}1">;
 def warn_cxx20_compat_utf8_string : Warning<
   "type of UTF-8 string literal will change from array of const char to "
   "array of const char8_t in C++20">, InGroup, DefaultIgnore;

diff  --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index 2273fb113fb2..96b93dcdf044 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -705,7 +705,7 @@ static void InitializeCPlusPlusFeatureTestMacros(const 
LangOptions &LangOpts,
   Builder.defineMacro("__cpp_named_character_escapes", "202207L");
 
   if (LangOpts.Char8)
-Builder.defineMacro("__cpp_char8_t", "201811L");
+Builder.defineMacro("__cpp_char8_t", "202207L");
   Builder.defineMacro("__cpp_impl_destroying_delete", "201806L");
 
   // TS features.

diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index db5580c9e55c..7ebf6997e27e 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -81,10 +81,20 @@ static StringInitFailureKind IsStringInit(Expr *Init, const 
ArrayType *AT,
   const QualType ElemTy =
   Context.getCanonicalType(AT->getElementType()).getUnqualifiedType();
 
+  auto IsCharOrUnsignedChar = [](const QualType &T) {
+const BuiltinType *BT = dyn_cast(T.getTypePtr());
+return BT && BT->isCharType() && BT->getKind() != BuiltinType::SChar;
+  };
+
   switch (SL->getKind()) {
   case StringLiteral::UTF8:
 // char8_t array can be initialized with a UTF-8 string.
-if (ElemTy->isChar8Type())
+// - C++20 [dcl.init.string] (DR)
+//   Additionally, an array of char or unsigned char may be initialized
+//   by a UTF-8 string literal.
+if (ElemTy->isChar8Type() ||
+

[clang] bcc90f6 - [Clang] Update cxx_dr_status [NFC]

2022-08-10 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-08-11T08:24:31+02:00
New Revision: bcc90f6268182a42205bd546be996fac6d05a071

URL: 
https://github.com/llvm/llvm-project/commit/bcc90f6268182a42205bd546be996fac6d05a071
DIFF: 
https://github.com/llvm/llvm-project/commit/bcc90f6268182a42205bd546be996fac6d05a071.diff

LOG: [Clang] Update cxx_dr_status [NFC]

Update the DR status page with the C++ Standard Core
Issues List revision 109.

Added: 


Modified: 
clang/www/cxx_dr_status.html
clang/www/make_cxx_dr_status

Removed: 




diff  --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index f3cfe9faea150..9db2d890f62a6 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -1056,7 +1056,7 @@ C++ defect report implementation 
status
   
   
 https://wg21.link/cwg170";>170
-drafting
+open
 Pointer-to-member conversions
 Not resolved
   
@@ -2768,7 +2768,7 @@ C++ defect report implementation 
status
   
   
 https://wg21.link/cwg455";>455
-drafting
+open
 Partial ordering and non-deduced arguments
 Not resolved
   
@@ -2892,11 +2892,11 @@ C++ defect report implementation 
status
 When is std::uncaught_exception() true? (take 2)
 Unknown
   
-  
+  
 https://wg21.link/cwg476";>476
-extension
+CD5
 Determining the buffer size for placement new
-Extension
+Unknown
   
   
 https://wg21.link/cwg477";>477
@@ -3508,7 +3508,7 @@ C++ defect report implementation 
status
   
   
 https://wg21.link/cwg578";>578
-open
+review
 Phase 1 replacement of characters with 
universal-character-names
 Not resolved
   
@@ -4160,11 +4160,11 @@ C++ defect report implementation 
status
 Type declarations/definitions in type-specifier-seqs and 
type-ids
 Yes
   
-  
+  
 https://wg21.link/cwg687";>687
-extension
+NAD
 template keyword with unqualified-ids
-Extension
+Unknown
   
   
 https://wg21.link/cwg688";>688
@@ -4172,11 +4172,11 @@ C++ defect report implementation 
status
 Constexpr constructors and static initialization
 Unknown
   
-  
+  
 https://wg21.link/cwg689";>689
-open
+CD5
 Maximum values of signed and unsigned integers
-Not resolved
+Unknown
   
   
 https://wg21.link/cwg690";>690
@@ -4388,11 +4388,11 @@ C++ defect report implementation 
status
 In-class explicit specializations
 Partial
   
-  
+  
 https://wg21.link/cwg728";>728
-extension
+NAD
 Restrictions on local classes
-Extension
+Unknown
   
   
 https://wg21.link/cwg729";>729
@@ -5318,12 +5318,6 @@ C++ defect report implementation 
status
 Deleted specializations of member function templates
 Unknown
   
-  
-https://wg21.link/cwg916";>916
-open
-Does a reference type have a destructor?
-Not resolved
-  
   
 https://wg21.link/cwg919";>919
 CD2
@@ -5474,11 +5468,11 @@ C++ defect report implementation 
status
 Is T() a temporary?
 Unknown
   
-  
+  
 https://wg21.link/cwg944";>944
-extension
+NAD
 reinterpret_cast for all types with the same size and 
alignment
-Extension
+Unknown
   
   
 https://wg21.link/cwg945";>945
@@ -7330,7 +7324,7 @@ C++ defect report implementation 
status
   
   
 https://wg21.link/cwg1253";>1253
-drafting
+open
 Generic non-template members
 Not resolved
   
@@ -7342,7 +7336,7 @@ C++ defect report implementation 
status
   
   
 https://wg21.link/cwg1255";>1255
-drafting
+open
 Definition problems with constexpr functions
 Not resolved
   
@@ -7358,11 +7352,11 @@ C++ defect report implementation 
status
 Instantiation via non-dependent references in uninstantiated 
templates
 Not resolved
   
-  
+  
 https://wg21.link/cwg1258";>1258
-drafting
+CD5
 “Instantiation context” 
diff ers from dependent lookup rules
-Not resolved
+Unknown
   
   
 https://wg21.link/cwg1259";>1259
@@ -7576,7 +7570,7 @@ C++ defect report implementation 
status
   
   
 https://wg21.link/cwg1294";>1294
-drafting
+open
 Side effects in dynamic/static initialization
 Not resolved
   
@@ -7766,11 +7760,11 @@ C++ defect report implementation 
status
 Omitted declarator in friend declarations
 Unknown
   
-  
+  
 https://wg21.link/cwg1326";>1326
-extension
+dup
 Deducing an array bound from an initializer-list
-Extension
+Unknown
   
   
 https://wg21.link/cwg1327";>1327
@@ -7822,7 +7816,7 @@ C++ defect report implementation 
status
   
   
 https://wg21.link/cwg1335";>1335
-drafting
+open
 Stringizing, extended characters, and universal-character-names
 Not resolved
   
@@ -7862,11 +7856,11 @@ C++ defect report implementation 
status
 Bit-field initializers
 Unknown
   
-  
+  
 https://wg21.link/cwg1342";>1342
-

[clang] 463e30f - [Clang] Fix crash in coverage of if consteval.

2022-08-26 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-08-26T17:46:53+02:00
New Revision: 463e30f51fd07921f32c6630afb3f8dd18d6d2f5

URL: 
https://github.com/llvm/llvm-project/commit/463e30f51fd07921f32c6630afb3f8dd18d6d2f5
DIFF: 
https://github.com/llvm/llvm-project/commit/463e30f51fd07921f32c6630afb3f8dd18d6d2f5.diff

LOG: [Clang] Fix crash in coverage of if consteval.

Clang crashes when encountering an `if consteval` statement.
This is the minimum fix not to crash.
The fix is consistent with the current behavior of if constexpr,
which does generate coverage data for the discarded branches.
This is of course not correct and a better solution is
needed for both if constexpr and if consteval.
See https://github.com/llvm/llvm-project/issues/54419.

Fixes #57377

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D132723

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/CodeGen/CoverageMappingGen.cpp
clang/test/CoverageMapping/if.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3f7eec1effd46..b6d1dbedb2c59 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -78,6 +78,10 @@ Bug Fixes
 - ``-Wtautological-compare`` missed warnings for tautological comparisons
   involving a negative integer literal. This fixes
   `Issue 42918 `_.
+- Fix a crash when generating code coverage information for an
+  ``if consteval`` statement. This fixes
+  `Issue 57377 `_.
+
 
 Improvements to Clang's diagnostics
 ^^^

diff  --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 0fe084b628dab..836aabf80179d 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -1377,19 +1377,23 @@ struct CounterCoverageMappingBuilder
 
 // Extend into the condition before we propagate through it below - this is
 // needed to handle macros that generate the "if" but not the condition.
-extendRegion(S->getCond());
+if (!S->isConsteval())
+  extendRegion(S->getCond());
 
 Counter ParentCount = getRegion().getCounter();
 Counter ThenCount = getRegionCounter(S);
 
-// Emitting a counter for the condition makes it easier to interpret the
-// counter for the body when looking at the coverage.
-propagateCounts(ParentCount, S->getCond());
+if (!S->isConsteval()) {
+  // Emitting a counter for the condition makes it easier to interpret the
+  // counter for the body when looking at the coverage.
+  propagateCounts(ParentCount, S->getCond());
 
-// The 'then' count applies to the area immediately after the condition.
-auto Gap = findGapAreaBetween(S->getRParenLoc(), getStart(S->getThen()));
-if (Gap)
-  fillGapAreaWithCount(Gap->getBegin(), Gap->getEnd(), ThenCount);
+  // The 'then' count applies to the area immediately after the condition.
+  Optional Gap =
+  findGapAreaBetween(S->getRParenLoc(), getStart(S->getThen()));
+  if (Gap)
+fillGapAreaWithCount(Gap->getBegin(), Gap->getEnd(), ThenCount);
+}
 
 extendRegion(S->getThen());
 Counter OutCount = propagateCounts(ThenCount, S->getThen());
@@ -1398,9 +1402,9 @@ struct CounterCoverageMappingBuilder
 if (const Stmt *Else = S->getElse()) {
   bool ThenHasTerminateStmt = HasTerminateStmt;
   HasTerminateStmt = false;
-
   // The 'else' count applies to the area immediately after the 'then'.
-  Gap = findGapAreaBetween(getEnd(S->getThen()), getStart(Else));
+  Optional Gap =
+  findGapAreaBetween(getEnd(S->getThen()), getStart(Else));
   if (Gap)
 fillGapAreaWithCount(Gap->getBegin(), Gap->getEnd(), ElseCount);
   extendRegion(Else);
@@ -1416,9 +1420,11 @@ struct CounterCoverageMappingBuilder
   GapRegionCounter = OutCount;
 }
 
-// Create Branch Region around condition.
-createBranchRegion(S->getCond(), ThenCount,
-   subtractCounters(ParentCount, ThenCount));
+if (!S->isConsteval()) {
+  // Create Branch Region around condition.
+  createBranchRegion(S->getCond(), ThenCount,
+ subtractCounters(ParentCount, ThenCount));
+}
   }
 
   void VisitCXXTryStmt(const CXXTryStmt *S) {

diff  --git a/clang/test/CoverageMapping/if.cpp 
b/clang/test/CoverageMapping/if.cpp
index 5b705cd46ab72..de3554c100b96 100644
--- a/clang/test/CoverageMapping/if.cpp
+++ b/clang/test/CoverageMapping/if.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false 
-fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping 
-emit-llvm-only -std=c++1z -triple %itanium_abi_triple -main-file-name if.cpp 
%s | FileCheck %s
+// RUN: %clang_cc1 -mllvm -emptyline-comment-c

[clang] 0d6b26b - [Clang] Fix a crash when encountering an ill-formed delimited UCN.

2023-01-03 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-01-03T20:57:52+01:00
New Revision: 0d6b26b4d3e3991da16f5b7f53e397b0051e8598

URL: 
https://github.com/llvm/llvm-project/commit/0d6b26b4d3e3991da16f5b7f53e397b0051e8598
DIFF: 
https://github.com/llvm/llvm-project/commit/0d6b26b4d3e3991da16f5b7f53e397b0051e8598.diff

LOG: [Clang] Fix a crash when encountering an ill-formed delimited UCN.

\u{...} was incorrectly parsed as a valid UCN instead
of emitting a diagnostic, causing an assertion failure.

Reviewed By: tahonermann

Differential Revision: https://reviews.llvm.org/D139889

Added: 


Modified: 
clang/lib/Lex/Lexer.cpp
clang/test/Preprocessor/ucn-pp-identifier.c

Removed: 




diff  --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index 2f21f7b069cfe..ce48e7da21bb3 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -3286,7 +3286,7 @@ llvm::Optional Lexer::tryReadNumericUCN(const 
char *&StartPtr,
   uint32_t CodePoint = 0;
   while (Count != NumHexDigits || Delimited) {
 char C = getCharAndSize(CurPtr, CharSize);
-if (!Delimited && C == '{') {
+if (!Delimited && Count == 0 && C == '{') {
   Delimited = true;
   CurPtr += CharSize;
   continue;

diff  --git a/clang/test/Preprocessor/ucn-pp-identifier.c 
b/clang/test/Preprocessor/ucn-pp-identifier.c
index 8d30a6a2bb239..c47ed21ff3158 100644
--- a/clang/test/Preprocessor/ucn-pp-identifier.c
+++ b/clang/test/Preprocessor/ucn-pp-identifier.c
@@ -117,6 +117,7 @@ C 1
 // CHECK-NEXT: {{^   u}}
 
 #define \u{}   // expected-warning {{empty delimited universal 
character name; treating as '\' 'u' '{' '}'}} expected-error {{macro name must 
be an identifier}}
+#define \u1{123}   // expected-warning {{incomplete universal character 
name; treating as '\' followed by identifier}} expected-error {{macro name must 
be an identifier}}
 #define \u{123456789}  // expected-error {{hex escape sequence out of range}} 
expected-error {{macro name must be an identifier}}
 #define \u{// expected-warning {{incomplete delimited universal 
character name; treating as '\' 'u' '{' identifier}} expected-error {{macro 
name must be an identifier}}
 #define \u{fgh}// expected-warning {{incomplete delimited universal 
character name; treating as '\' 'u' '{' identifier}} expected-error {{macro 
name must be an identifier}}



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


[clang] ca61961 - Implement CWG2631

2023-01-08 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-01-08T10:35:26+01:00
New Revision: ca619613801233ef2def8c3cc7d311d5ed0033cb

URL: 
https://github.com/llvm/llvm-project/commit/ca619613801233ef2def8c3cc7d311d5ed0033cb
DIFF: 
https://github.com/llvm/llvm-project/commit/ca619613801233ef2def8c3cc7d311d5ed0033cb.diff

LOG: Implement CWG2631

Implement https://cplusplus.github.io/CWG/issues/2631.html.

Immediate calls in default arguments and defaults members
are not evaluated.

Instead, we evaluate them when constructing a
`CXXDefaultArgExpr`/`BuildCXXDefaultInitExpr`.

The immediate calls are executed by doing a
transform on the initializing expression.

Note that lambdas are not considering subexpressions so
we do not need to transform them.

As a result of this patch, unused default member
initializers are not considered odr-used, and
errors about members binding to local variables
in an outer scope only surface at the point
where a constructor is defined.

Reviewed By: aaron.ballman, #clang-language-wg, rupprecht

Differential Revision: https://reviews.llvm.org/D136554

Added: 
clang/test/CodeGenCXX/default-arguments-with-immediate.cpp
clang/test/CodeGenCXX/meminit-initializers-odr.cpp
clang/test/PCH/default-argument-with-immediate-calls.cpp
clang/test/SemaCXX/cxx2a-consteval-default-params.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/ExprCXX.h
clang/include/clang/AST/Stmt.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/Decl.cpp
clang/lib/AST/ExprCXX.cpp
clang/lib/Parse/ParseCXXInlineMethods.cpp
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Sema/UsedDeclVisitor.h
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriterStmt.cpp
clang/test/AST/ast-dump-records.cpp
clang/test/CXX/class/class.local/p1-0x.cpp
clang/test/CXX/drs/dr26xx.cpp
clang/test/CodeGenCXX/builtin-source-location.cpp
clang/test/SemaCXX/cxx11-default-member-initializers.cpp
clang/test/SemaCXX/source_location.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f2cfac238613c..91cb9049bcb4b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -671,6 +671,11 @@ C++ Language Changes in Clang
 - Implemented DR2358 allowing init captures in lambdas in default arguments.
 - implemented `DR2654 `_ which undeprecates
   all compound assignements operations on volatile qualified variables.
+- Implemented DR2631. Invalid ``consteval`` calls in default arguments and 
default
+  member initializers are diagnosed when and if the default is used.
+  This Fixes `Issue 56379 `_
+  and changes the value of ``std::source_location::current()``
+  used in default parameters calls compared to previous versions of Clang.
 
 C++20 Feature Support
 ^

diff  --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index c2f6751d62ede..a0bdf50f57ac0 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -1244,8 +1244,12 @@ class CXXThrowExpr : public Expr {
 /// This wraps up a function call argument that was created from the
 /// corresponding parameter's default argument, when the call did not
 /// explicitly supply arguments for all of the parameters.
-class CXXDefaultArgExpr final : public Expr {
+class CXXDefaultArgExpr final
+: public Expr,
+  private llvm::TrailingObjects {
   friend class ASTStmtReader;
+  friend class ASTReader;
+  friend TrailingObjects;
 
   /// The parameter whose default is being used.
   ParmVarDecl *Param;
@@ -1254,7 +1258,7 @@ class CXXDefaultArgExpr final : public Expr {
   DeclContext *UsedContext;
 
   CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *Param,
-DeclContext *UsedContext)
+Expr *RewrittenExpr, DeclContext *UsedContext)
   : Expr(SC,
  Param->hasUnparsedDefaultArg()
  ? Param->getType().getNonReferenceType()
@@ -1263,28 +1267,54 @@ class CXXDefaultArgExpr final : public Expr {
  Param->getDefaultArg()->getObjectKind()),
 Param(Param), UsedContext(UsedContext) {
 CXXDefaultArgExprBits.Loc = Loc;
+CXXDefaultArgExprBits.HasRewrittenInit = RewrittenExpr != nullptr;
+if (RewrittenExpr)
+  *getTrailingObjects() = RewrittenExpr;
 setDependence(computeDependence(this));
   }
 
+  CXXDefaultArgExpr(EmptyShell Empty, bool HasRewrittenInit)
+  : Expr(CXXDefaultArgExprClass, Empty) {
+CXXDefaultArgExprBits.HasRewrittenIn

[clang] e1111e2 - [Clang] Correctly capture bindings in dependent lambdas.

2023-01-09 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-01-09T21:20:57+01:00
New Revision: ee2056e7245b21e24816f6f7ef5ac016ed6f

URL: 
https://github.com/llvm/llvm-project/commit/ee2056e7245b21e24816f6f7ef5ac016ed6f
DIFF: 
https://github.com/llvm/llvm-project/commit/ee2056e7245b21e24816f6f7ef5ac016ed6f.diff

LOG: [Clang] Correctly capture bindings in dependent lambdas.

Structured bindings were not properly marked odr-used
and therefore captured in generic lambddas.

Fixes #57826

It is unclear to me if further simplification can be gained
through the allowance described in
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0588r1.html.

Either way, I think this makes support for P0588 completes,
but we probably want to add test for that in a separate PR.
(and I lack confidence I understand P0588 sufficiently to assert
the completeness of our cnformance).

Reviewed By: aaron.ballman, #clang-language-wg

Differential Revision: https://reviews.llvm.org/D137244

Added: 


Modified: 
clang/include/clang/AST/Decl.h
clang/include/clang/Sema/ScopeInfo.h
clang/include/clang/Sema/Sema.h
clang/include/clang/Sema/SemaLambda.h
clang/lib/AST/DeclCXX.cpp
clang/lib/Sema/ScopeInfo.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaLambda.cpp
clang/lib/Sema/TreeTransform.h
clang/test/SemaCXX/cxx20-decomposition.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 3ae2703a406ee..7a710b36c91f2 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -695,6 +695,8 @@ class NamespaceDecl : public NamedDecl, public DeclContext,
   }
 };
 
+class VarDecl;
+
 /// Represent the declaration of a variable (in which case it is
 /// an lvalue) a function (in which case it is a function designator) or
 /// an enum constant.
@@ -721,6 +723,13 @@ class ValueDecl : public NamedDecl {
   /// can be captured.
   bool isInitCapture() const;
 
+  // If this is a VarDecl, or a BindindDecl with an
+  // associated decomposed VarDecl, return that VarDecl.
+  VarDecl *getPotentiallyDecomposedVarDecl();
+  const VarDecl *getPotentiallyDecomposedVarDecl() const {
+return const_cast(this)->getPotentiallyDecomposedVarDecl();
+  }
+
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classofKind(Kind K) { return K >= firstValue && K <= lastValue; }

diff  --git a/clang/include/clang/Sema/ScopeInfo.h 
b/clang/include/clang/Sema/ScopeInfo.h
index 613749f2da3ff..363fbf454879d 100644
--- a/clang/include/clang/Sema/ScopeInfo.h
+++ b/clang/include/clang/Sema/ScopeInfo.h
@@ -1028,7 +1028,7 @@ class LambdaScopeInfo final :
   }
 
   void visitPotentialCaptures(
-  llvm::function_ref Callback) const;
+  llvm::function_ref Callback) const;
 };
 
 FunctionScopeInfo::WeakObjectProfileTy::WeakObjectProfileTy()

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6c0d950eb929c..fd60a1f9ac43e 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -5409,7 +5409,7 @@ class Sema final {
   void MarkDeclRefReferenced(DeclRefExpr *E, const Expr *Base = nullptr);
   void MarkMemberReferenced(MemberExpr *E);
   void MarkFunctionParmPackReferenced(FunctionParmPackExpr *E);
-  void MarkCaptureUsedInEnclosingContext(VarDecl *Capture, SourceLocation Loc,
+  void MarkCaptureUsedInEnclosingContext(ValueDecl *Capture, SourceLocation 
Loc,
  unsigned CapturingScopeIndex);
 
   ExprResult CheckLValueToRValueConversionOperand(Expr *E);

diff  --git a/clang/include/clang/Sema/SemaLambda.h 
b/clang/include/clang/Sema/SemaLambda.h
index e8eaa46b88a20..494568722d9f7 100644
--- a/clang/include/clang/Sema/SemaLambda.h
+++ b/clang/include/clang/Sema/SemaLambda.h
@@ -32,7 +32,7 @@ class Sema;
 
 Optional getStackIndexOfNearestEnclosingCaptureCapableLambda(
 ArrayRef FunctionScopes,
-VarDecl *VarToCapture, Sema &S);
+ValueDecl *VarToCapture, Sema &S);
 
 } // clang
 

diff  --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 1576c27a463fe..3cf355714107c 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -3249,6 +3249,16 @@ StaticAssertDecl 
*StaticAssertDecl::CreateDeserialized(ASTContext &C,
   nullptr, SourceLocation(), false);
 }
 
+VarDecl *ValueDecl::getPotentiallyDecomposedVarDecl() {
+  assert((isa(this)) &&
+ "expected a VarDecl or a BindingDecl");
+  if (auto *Var = llvm::dyn_cast(this))
+return Var;
+  if (auto *BD = llvm::dyn_cast(this))
+return llvm::dyn_cast(BD->getDecomposedDecl());
+  return nullptr;
+}
+
 void BindingDecl::anchor() {}
 
 BindingDecl *BindingDecl::Create(ASTContext &C, DeclContext *DC,

diff  --git a/

[clang] 7429709 - [Clang] Implement CWG2358 Explicit capture of value

2022-11-03 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-11-03T13:27:11+01:00
New Revision: 742970920b7a7fc2fe1cb6bca6fb04f03ab7d5d9

URL: 
https://github.com/llvm/llvm-project/commit/742970920b7a7fc2fe1cb6bca6fb04f03ab7d5d9
DIFF: 
https://github.com/llvm/llvm-project/commit/742970920b7a7fc2fe1cb6bca6fb04f03ab7d5d9.diff

LOG: [Clang] Implement CWG2358 Explicit capture of value

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D137172

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp
clang/test/CXX/drs/dr23xx.cpp
clang/test/CXX/expr/expr.prim/expr.prim.lambda/p13.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 763f4cece4634..ebf280f4da4a8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -574,6 +574,7 @@ C++ Language Changes in Clang
   This means Clang will by default accept code using features from C++17 and
   conforming GNU extensions. Projects incompatible with C++17 can add
   ``-std=gnu++14`` to their build settings to restore the previous behaviour.
+- Implemented DR2358 allowing init captures in lambdas in default arguments.
 
 C++20 Feature Support
 ^

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 80b748cbb3744..ea7997b347959 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -102,24 +102,31 @@ bool CheckDefaultArgumentVisitor::VisitDeclRefExpr(const 
DeclRefExpr *DRE) {
   return S.Diag(DRE->getBeginLoc(),
 diag::err_param_default_argument_references_param)
  << Param->getDeclName() << DefaultArg->getSourceRange();
-  } else if (const auto *VDecl = dyn_cast(Decl)) {
-// C++ [dcl.fct.default]p7:
-//   Local variables shall not be used in default argument
-//   expressions.
-//
-// C++17 [dcl.fct.default]p7 (by CWG 2082):
-//   A local variable shall not appear as a potentially-evaluated
-//   expression in a default argument.
-//
-// C++20 [dcl.fct.default]p7 (DR as part of P0588R1, see also CWG 2346):
-//   Note: A local variable cannot be odr-used (6.3) in a default argument.
-//
-if (VDecl->isLocalVarDecl() && !DRE->isNonOdrUse())
-  return S.Diag(DRE->getBeginLoc(),
-diag::err_param_default_argument_references_local)
- << VDecl->getDeclName() << DefaultArg->getSourceRange();
+  } else {
+const VarDecl *VD = nullptr;
+if (const auto *BD = dyn_cast(Decl))
+  VD = dyn_cast_if_present(BD->getDecomposedDecl());
+else
+  VD = dyn_cast(Decl);
+if (VD) {
+  // C++ [dcl.fct.default]p7:
+  //   Local variables shall not be used in default argument
+  //   expressions.
+  //
+  // C++17 [dcl.fct.default]p7 (by CWG 2082):
+  //   A local variable shall not appear as a potentially-evaluated
+  //   expression in a default argument.
+  //
+  // C++20 [dcl.fct.default]p7 (DR as part of P0588R1, see also CWG 2346):
+  //   Note: A local variable cannot be odr-used (6.3) in a default
+  //   argument.
+  //
+  if (VD->isLocalVarDecl() && !DRE->isNonOdrUse())
+return S.Diag(DRE->getBeginLoc(),
+  diag::err_param_default_argument_references_local)
+   << Decl->getDeclName() << DefaultArg->getSourceRange();
+}
   }
-
   return false;
 }
 
@@ -149,13 +156,20 @@ bool CheckDefaultArgumentVisitor::VisitPseudoObjectExpr(
 }
 
 bool CheckDefaultArgumentVisitor::VisitLambdaExpr(const LambdaExpr *Lambda) {
-  // C++11 [expr.lambda.prim]p13:
-  //   A lambda-expression appearing in a default argument shall not
-  //   implicitly or explicitly capture any entity.
-  if (Lambda->capture_begin() == Lambda->capture_end())
-return false;
-
-  return S.Diag(Lambda->getBeginLoc(), diag::err_lambda_capture_default_arg);
+  // [expr.prim.lambda.capture]p9
+  // a lambda-expression appearing in a default argument cannot implicitly or
+  // explicitly capture any local entity. Such a lambda-expression can still
+  // have an init-capture if any full-expression in its initializer satisfies
+  // the constraints of an expression appearing in a default argument.
+  bool Invalid = false;
+  for (const LambdaCapture &LC : Lambda->captures()) {
+if (!Lambda->isInitCapture(&LC))
+  return S.Diag(LC.getLocation(), diag::err_lambda_capture_default_arg);
+// Init captures are always VarDecl.
+auto *D = cast(LC.getCapturedVar());
+Invalid |= Visit(D->getInit());
+  }
+  return Invalid;
 }
 } // namespace
 

diff  --git a/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp 
b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp
index 52986faa4e859..97b227222eb09 100644
--- a/c

[clang] bf1e235 - Implement CWG2631

2022-11-03 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-11-04T07:58:57+01:00
New Revision: bf1e235695a7acdc3e868217e69d5b31ada06cb3

URL: 
https://github.com/llvm/llvm-project/commit/bf1e235695a7acdc3e868217e69d5b31ada06cb3
DIFF: 
https://github.com/llvm/llvm-project/commit/bf1e235695a7acdc3e868217e69d5b31ada06cb3.diff

LOG: Implement CWG2631

Implement https://cplusplus.github.io/CWG/issues/2631.html.

Immediate calls in default arguments and defaults members
are not evaluated.

Instead, we evaluate them when constructing a
`CXXDefaultArgExpr`/`BuildCXXDefaultInitExpr`.

The immediate calls are executed by doing a
transform on the initializing expression.

Note that lambdas are not considering subexpressions so
we do not need to transform them.

As a result of this patch, unused default member
initializers are not considered odr-used, and
errors about members binding to local variables
in an outer scope only surface at the point
where a constructor is defined.

Reviewed By: aaron.ballman, #clang-language-wg

Differential Revision: https://reviews.llvm.org/D136554

Added: 
clang/test/CodeGenCXX/default-arguments-with-immediate.cpp
clang/test/PCH/default-argument-with-immediate-calls.cpp
clang/test/SemaCXX/cxx2a-consteval-default-params.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/ExprCXX.h
clang/include/clang/AST/Stmt.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/ExprCXX.cpp
clang/lib/Parse/ParseCXXInlineMethods.cpp
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriterStmt.cpp
clang/test/CXX/class/class.local/p1-0x.cpp
clang/test/SemaCXX/source_location.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ad1a00b4bbcc4..bd2d811b30668 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -578,6 +578,11 @@ C++ Language Changes in Clang
   conforming GNU extensions. Projects incompatible with C++17 can add
   ``-std=gnu++14`` to their build settings to restore the previous behaviour.
 - Implemented DR2358 allowing init captures in lambdas in default arguments.
+- Implemented DR2631. Invalid ``consteval`` calls in default arguments and 
default
+  member initializers are diagnosed when and if the default is used.
+  This Fixes `Issue 56379 `_
+  and changes the value of ``std::source_location::current()``
+  used in default parameters calls compared to previous versions of Clang.
 
 C++20 Feature Support
 ^

diff  --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 0b927c0294752..098720d9469f0 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -1245,8 +1245,12 @@ class CXXThrowExpr : public Expr {
 /// This wraps up a function call argument that was created from the
 /// corresponding parameter's default argument, when the call did not
 /// explicitly supply arguments for all of the parameters.
-class CXXDefaultArgExpr final : public Expr {
+class CXXDefaultArgExpr final
+: public Expr,
+  private llvm::TrailingObjects {
   friend class ASTStmtReader;
+  friend class ASTReader;
+  friend TrailingObjects;
 
   /// The parameter whose default is being used.
   ParmVarDecl *Param;
@@ -1255,7 +1259,7 @@ class CXXDefaultArgExpr final : public Expr {
   DeclContext *UsedContext;
 
   CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *Param,
-DeclContext *UsedContext)
+Expr *RewrittenExpr, DeclContext *UsedContext)
   : Expr(SC,
  Param->hasUnparsedDefaultArg()
  ? Param->getType().getNonReferenceType()
@@ -1264,28 +1268,58 @@ class CXXDefaultArgExpr final : public Expr {
  Param->getDefaultArg()->getObjectKind()),
 Param(Param), UsedContext(UsedContext) {
 CXXDefaultArgExprBits.Loc = Loc;
+CXXDefaultArgExprBits.HasRewrittenInit = RewrittenExpr != nullptr;
+if (RewrittenExpr)
+  *getTrailingObjects() = RewrittenExpr;
 setDependence(computeDependence(this));
   }
 
+  CXXDefaultArgExpr(EmptyShell Empty, bool HasRewrittenInit)
+  : Expr(CXXDefaultArgExprClass, Empty) {
+CXXDefaultArgExprBits.HasRewrittenInit = HasRewrittenInit;
+  }
+
+  size_t numTrailingObjects() const {
+return CXXDefaultArgExprBits.HasRewrittenInit;
+  }
+
 public:
-  CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {}
+  static CXXDefaultArgExpr *CreateEmpty(const ASTContext &C,
+bool HasRewrittenInit);
 
 

[clang] 722a0ef - Revert "Implement CWG2631"

2022-11-04 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-11-04T08:24:52+01:00
New Revision: 722a0efe31e16e6a98dc3742cf6101d930ba3479

URL: 
https://github.com/llvm/llvm-project/commit/722a0efe31e16e6a98dc3742cf6101d930ba3479
DIFF: 
https://github.com/llvm/llvm-project/commit/722a0efe31e16e6a98dc3742cf6101d930ba3479.diff

LOG: Revert "Implement CWG2631"

Breaks the build on some platforms.

This reverts commit bf1e235695a7acdc3e868217e69d5b31ada06cb3.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/ExprCXX.h
clang/include/clang/AST/Stmt.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/ExprCXX.cpp
clang/lib/Parse/ParseCXXInlineMethods.cpp
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriterStmt.cpp
clang/test/CXX/class/class.local/p1-0x.cpp
clang/test/SemaCXX/source_location.cpp

Removed: 
clang/test/CodeGenCXX/default-arguments-with-immediate.cpp
clang/test/PCH/default-argument-with-immediate-calls.cpp
clang/test/SemaCXX/cxx2a-consteval-default-params.cpp



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index bd2d811b30668..ad1a00b4bbcc4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -578,11 +578,6 @@ C++ Language Changes in Clang
   conforming GNU extensions. Projects incompatible with C++17 can add
   ``-std=gnu++14`` to their build settings to restore the previous behaviour.
 - Implemented DR2358 allowing init captures in lambdas in default arguments.
-- Implemented DR2631. Invalid ``consteval`` calls in default arguments and 
default
-  member initializers are diagnosed when and if the default is used.
-  This Fixes `Issue 56379 `_
-  and changes the value of ``std::source_location::current()``
-  used in default parameters calls compared to previous versions of Clang.
 
 C++20 Feature Support
 ^

diff  --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 098720d9469f0..0b927c0294752 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -1245,12 +1245,8 @@ class CXXThrowExpr : public Expr {
 /// This wraps up a function call argument that was created from the
 /// corresponding parameter's default argument, when the call did not
 /// explicitly supply arguments for all of the parameters.
-class CXXDefaultArgExpr final
-: public Expr,
-  private llvm::TrailingObjects {
+class CXXDefaultArgExpr final : public Expr {
   friend class ASTStmtReader;
-  friend class ASTReader;
-  friend TrailingObjects;
 
   /// The parameter whose default is being used.
   ParmVarDecl *Param;
@@ -1259,7 +1255,7 @@ class CXXDefaultArgExpr final
   DeclContext *UsedContext;
 
   CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *Param,
-Expr *RewrittenExpr, DeclContext *UsedContext)
+DeclContext *UsedContext)
   : Expr(SC,
  Param->hasUnparsedDefaultArg()
  ? Param->getType().getNonReferenceType()
@@ -1268,58 +1264,28 @@ class CXXDefaultArgExpr final
  Param->getDefaultArg()->getObjectKind()),
 Param(Param), UsedContext(UsedContext) {
 CXXDefaultArgExprBits.Loc = Loc;
-CXXDefaultArgExprBits.HasRewrittenInit = RewrittenExpr != nullptr;
-if (RewrittenExpr)
-  *getTrailingObjects() = RewrittenExpr;
 setDependence(computeDependence(this));
   }
 
-  CXXDefaultArgExpr(EmptyShell Empty, bool HasRewrittenInit)
-  : Expr(CXXDefaultArgExprClass, Empty) {
-CXXDefaultArgExprBits.HasRewrittenInit = HasRewrittenInit;
-  }
-
-  size_t numTrailingObjects() const {
-return CXXDefaultArgExprBits.HasRewrittenInit;
-  }
-
 public:
-  static CXXDefaultArgExpr *CreateEmpty(const ASTContext &C,
-bool HasRewrittenInit);
+  CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {}
 
   // \p Param is the parameter whose default argument is used by this
   // expression.
   static CXXDefaultArgExpr *Create(const ASTContext &C, SourceLocation Loc,
-   ParmVarDecl *Param, Expr *RewrittenExpr,
-   DeclContext *UsedContext);
+   ParmVarDecl *Param,
+   DeclContext *UsedContext) {
+return new (C)
+CXXDefaultArgExpr(CXXDefaultArgExprClass, Loc, Param, UsedContext);
+  }
+
   // Retrieve the parameter that the argument was created from.
   const ParmVarDecl *getParam() const { return Param; }
   ParmV

[clang] 7acfe36 - Implement CWG2631

2022-11-04 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-11-04T14:46:38+01:00
New Revision: 7acfe3629479c8489fc2d7f629994dc200be990c

URL: 
https://github.com/llvm/llvm-project/commit/7acfe3629479c8489fc2d7f629994dc200be990c
DIFF: 
https://github.com/llvm/llvm-project/commit/7acfe3629479c8489fc2d7f629994dc200be990c.diff

LOG: Implement CWG2631

Implement https://cplusplus.github.io/CWG/issues/2631.html.

Immediate calls in default arguments and defaults members
are not evaluated.

Instead, we evaluate them when constructing a
`CXXDefaultArgExpr`/`BuildCXXDefaultInitExpr`.

The immediate calls are executed by doing a
transform on the initializing expression.

Note that lambdas are not considering subexpressions so
we do not need to transform them.

As a result of this patch, unused default member
initializers are not considered odr-used, and
errors about members binding to local variables
in an outer scope only surface at the point
where a constructor is defined.

Reviewed By: aaron.ballman, #clang-language-wg

Differential Revision: https://reviews.llvm.org/D136554

Added: 
clang/test/CodeGenCXX/default-arguments-with-immediate.cpp
clang/test/PCH/default-argument-with-immediate-calls.cpp
clang/test/SemaCXX/cxx2a-consteval-default-params.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/ExprCXX.h
clang/include/clang/AST/Stmt.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/Decl.cpp
clang/lib/AST/ExprCXX.cpp
clang/lib/Parse/ParseCXXInlineMethods.cpp
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriterStmt.cpp
clang/test/CXX/class/class.local/p1-0x.cpp
clang/test/CodeGenCXX/builtin-source-location.cpp
clang/test/SemaCXX/source_location.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7bb1405c131ab..e16191e06e337 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -578,6 +578,11 @@ C++ Language Changes in Clang
   conforming GNU extensions. Projects incompatible with C++17 can add
   ``-std=gnu++14`` to their build settings to restore the previous behaviour.
 - Implemented DR2358 allowing init captures in lambdas in default arguments.
+- Implemented DR2631. Invalid ``consteval`` calls in default arguments and 
default
+  member initializers are diagnosed when and if the default is used.
+  This Fixes `Issue 56379 `_
+  and changes the value of ``std::source_location::current()``
+  used in default parameters calls compared to previous versions of Clang.
 
 C++20 Feature Support
 ^

diff  --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 0b927c0294752..098720d9469f0 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -1245,8 +1245,12 @@ class CXXThrowExpr : public Expr {
 /// This wraps up a function call argument that was created from the
 /// corresponding parameter's default argument, when the call did not
 /// explicitly supply arguments for all of the parameters.
-class CXXDefaultArgExpr final : public Expr {
+class CXXDefaultArgExpr final
+: public Expr,
+  private llvm::TrailingObjects {
   friend class ASTStmtReader;
+  friend class ASTReader;
+  friend TrailingObjects;
 
   /// The parameter whose default is being used.
   ParmVarDecl *Param;
@@ -1255,7 +1259,7 @@ class CXXDefaultArgExpr final : public Expr {
   DeclContext *UsedContext;
 
   CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *Param,
-DeclContext *UsedContext)
+Expr *RewrittenExpr, DeclContext *UsedContext)
   : Expr(SC,
  Param->hasUnparsedDefaultArg()
  ? Param->getType().getNonReferenceType()
@@ -1264,28 +1268,58 @@ class CXXDefaultArgExpr final : public Expr {
  Param->getDefaultArg()->getObjectKind()),
 Param(Param), UsedContext(UsedContext) {
 CXXDefaultArgExprBits.Loc = Loc;
+CXXDefaultArgExprBits.HasRewrittenInit = RewrittenExpr != nullptr;
+if (RewrittenExpr)
+  *getTrailingObjects() = RewrittenExpr;
 setDependence(computeDependence(this));
   }
 
+  CXXDefaultArgExpr(EmptyShell Empty, bool HasRewrittenInit)
+  : Expr(CXXDefaultArgExprClass, Empty) {
+CXXDefaultArgExprBits.HasRewrittenInit = HasRewrittenInit;
+  }
+
+  size_t numTrailingObjects() const {
+return CXXDefaultArgExprBits.HasRewrittenInit;
+  }
+
 public:
-  CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {}
+  static CXXDefaultArgExpr *CreateEmpty(const AS

[clang] 5f87a89 - [clang] Fix assert in SemaEXpr.cpp

2022-11-04 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-11-04T15:37:37+01:00
New Revision: 5f87a892a7bed9cb0599573b9aaf387bc1df9c14

URL: 
https://github.com/llvm/llvm-project/commit/5f87a892a7bed9cb0599573b9aaf387bc1df9c14
DIFF: 
https://github.com/llvm/llvm-project/commit/5f87a892a7bed9cb0599573b9aaf387bc1df9c14.diff

LOG: [clang] Fix assert in SemaEXpr.cpp

Added: 


Modified: 
clang/lib/Sema/SemaExpr.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 51bd0004a389..40f6af8d8e8c 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -5943,7 +5943,7 @@ struct ImmediateCallVisitor : public 
RecursiveASTVisitor {
   bool VisitBlockDecl(BlockDecl *B) { return false; }
 
   bool VisitCompoundStmt(CompoundStmt *B) {
-assert("Unexpected Compound statement in default parameter or 
initializer");
+assert(false && "Unexpected Compound statement in default parameter or 
initializer");
 return false;
   }
 



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


[clang] 6875ac6 - [clang] Remove an incorrect assert

2022-11-04 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-11-04T15:46:22+01:00
New Revision: 6875ac69279a3a02fab382a2c8d121558ecbfa91

URL: 
https://github.com/llvm/llvm-project/commit/6875ac69279a3a02fab382a2c8d121558ecbfa91
DIFF: 
https://github.com/llvm/llvm-project/commit/6875ac69279a3a02fab382a2c8d121558ecbfa91.diff

LOG: [clang]  Remove an incorrect assert

Compound statements can appear in default arguments
but should not be visited in ImmediateCallVisitor as they are
not subexpressions

Added: 


Modified: 
clang/lib/Sema/SemaExpr.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 40f6af8d8e8c..ec67a6b6f28e 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -5943,7 +5943,6 @@ struct ImmediateCallVisitor : public 
RecursiveASTVisitor {
   bool VisitBlockDecl(BlockDecl *B) { return false; }
 
   bool VisitCompoundStmt(CompoundStmt *B) {
-assert(false && "Unexpected Compound statement in default parameter or 
initializer");
 return false;
   }
 



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


[clang] 35a870c - Revert "Implement CWG2631"

2022-11-04 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2022-11-04T22:10:50+01:00
New Revision: 35a870c30aaa9b16ccb45a9222471433b43ae66c

URL: 
https://github.com/llvm/llvm-project/commit/35a870c30aaa9b16ccb45a9222471433b43ae66c
DIFF: 
https://github.com/llvm/llvm-project/commit/35a870c30aaa9b16ccb45a9222471433b43ae66c.diff

LOG: Revert "Implement CWG2631"

This reverts commit 7acfe3629479c8489fc2d7f629994dc200be990c.
This reverts commit 5f87a892a7bed9cb0599573b9aaf387bc1df9c14.
This reverts commit 6875ac69279a3a02fab382a2c8d121558ecbfa91.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/ExprCXX.h
clang/include/clang/AST/Stmt.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/Decl.cpp
clang/lib/AST/ExprCXX.cpp
clang/lib/Parse/ParseCXXInlineMethods.cpp
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriterStmt.cpp
clang/test/CXX/class/class.local/p1-0x.cpp
clang/test/CodeGenCXX/builtin-source-location.cpp
clang/test/SemaCXX/source_location.cpp

Removed: 
clang/test/CodeGenCXX/default-arguments-with-immediate.cpp
clang/test/PCH/default-argument-with-immediate-calls.cpp
clang/test/SemaCXX/cxx2a-consteval-default-params.cpp



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e16191e06e337..7bb1405c131ab 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -578,11 +578,6 @@ C++ Language Changes in Clang
   conforming GNU extensions. Projects incompatible with C++17 can add
   ``-std=gnu++14`` to their build settings to restore the previous behaviour.
 - Implemented DR2358 allowing init captures in lambdas in default arguments.
-- Implemented DR2631. Invalid ``consteval`` calls in default arguments and 
default
-  member initializers are diagnosed when and if the default is used.
-  This Fixes `Issue 56379 `_
-  and changes the value of ``std::source_location::current()``
-  used in default parameters calls compared to previous versions of Clang.
 
 C++20 Feature Support
 ^

diff  --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 098720d9469f0..0b927c0294752 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -1245,12 +1245,8 @@ class CXXThrowExpr : public Expr {
 /// This wraps up a function call argument that was created from the
 /// corresponding parameter's default argument, when the call did not
 /// explicitly supply arguments for all of the parameters.
-class CXXDefaultArgExpr final
-: public Expr,
-  private llvm::TrailingObjects {
+class CXXDefaultArgExpr final : public Expr {
   friend class ASTStmtReader;
-  friend class ASTReader;
-  friend TrailingObjects;
 
   /// The parameter whose default is being used.
   ParmVarDecl *Param;
@@ -1259,7 +1255,7 @@ class CXXDefaultArgExpr final
   DeclContext *UsedContext;
 
   CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *Param,
-Expr *RewrittenExpr, DeclContext *UsedContext)
+DeclContext *UsedContext)
   : Expr(SC,
  Param->hasUnparsedDefaultArg()
  ? Param->getType().getNonReferenceType()
@@ -1268,58 +1264,28 @@ class CXXDefaultArgExpr final
  Param->getDefaultArg()->getObjectKind()),
 Param(Param), UsedContext(UsedContext) {
 CXXDefaultArgExprBits.Loc = Loc;
-CXXDefaultArgExprBits.HasRewrittenInit = RewrittenExpr != nullptr;
-if (RewrittenExpr)
-  *getTrailingObjects() = RewrittenExpr;
 setDependence(computeDependence(this));
   }
 
-  CXXDefaultArgExpr(EmptyShell Empty, bool HasRewrittenInit)
-  : Expr(CXXDefaultArgExprClass, Empty) {
-CXXDefaultArgExprBits.HasRewrittenInit = HasRewrittenInit;
-  }
-
-  size_t numTrailingObjects() const {
-return CXXDefaultArgExprBits.HasRewrittenInit;
-  }
-
 public:
-  static CXXDefaultArgExpr *CreateEmpty(const ASTContext &C,
-bool HasRewrittenInit);
+  CXXDefaultArgExpr(EmptyShell Empty) : Expr(CXXDefaultArgExprClass, Empty) {}
 
   // \p Param is the parameter whose default argument is used by this
   // expression.
   static CXXDefaultArgExpr *Create(const ASTContext &C, SourceLocation Loc,
-   ParmVarDecl *Param, Expr *RewrittenExpr,
-   DeclContext *UsedContext);
+   ParmVarDecl *Param,
+   DeclContext *UsedContext) {
+return new (C)
+CXXDefaultArgExpr(CXXDefaultArgExprCl

[clang] d708a18 - [Clang] Implement Change scope of lambda trailing-return-type

2023-01-31 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-01-31T11:06:14+01:00
New Revision: d708a186b6a9b050d09558163dd353d9f738c82d

URL: 
https://github.com/llvm/llvm-project/commit/d708a186b6a9b050d09558163dd353d9f738c82d
DIFF: 
https://github.com/llvm/llvm-project/commit/d708a186b6a9b050d09558163dd353d9f738c82d.diff

LOG: [Clang] Implement Change scope of lambda trailing-return-type

This implements P2036R3 and P2579R0.
That is, explicit, int, and implicit capture become visible
at the start of the parameter head.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D124351

Added: 
clang/test/SemaCXX/lambda-capture-type-deduction.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/DeclCXX.h
clang/include/clang/Sema/Scope.h
clang/include/clang/Sema/ScopeInfo.h
clang/include/clang/Sema/Sema.h
clang/lib/Parse/ParseExprCXX.cpp
clang/lib/Sema/Scope.cpp
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaCXXScopeSpec.cpp
clang/lib/Sema/SemaConcept.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaLambda.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/TreeTransform.h
clang/test/CXX/expr/expr.prim/expr.prim.lambda/p11-1y.cpp
clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4.cpp
clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 94b466122a348..fe418d938650a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -110,6 +110,11 @@ C++20 Feature Support
 C++2b Feature Support
 ^
 
+- Implemented `P2036R3: Change scope of lambda trailing-return-type 
`_
+  and `P2579R0 Mitigation strategies for P2036 `_.
+  This proposals modify how variables captured in lambdas can appear in 
trailing return type
+  expressions and how their types are deduced therein, in all C++ language 
versions.
+
 CUDA/HIP Language Changes in Clang
 --
 

diff  --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 11276c77490ce..ff8f8a1bb12d6 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1092,6 +1092,11 @@ class CXXRecordDecl : public RecordDecl {
 
   unsigned capture_size() const { return getLambdaData().NumCaptures; }
 
+  const LambdaCapture *getCapture(unsigned I) const {
+assert(isLambda() && I < capture_size() && "invalid index for capture");
+return captures_begin() + I;
+  }
+
   using conversion_iterator = UnresolvedSetIterator;
 
   conversion_iterator conversion_begin() const {
@@ -1826,6 +1831,20 @@ class CXXRecordDecl : public RecordDecl {
 return getLambdaData().MethodTyInfo;
   }
 
+  void setLambdaTypeInfo(TypeSourceInfo *TS) {
+assert(DefinitionData && DefinitionData->IsLambda &&
+   "setting lambda property of non-lambda class");
+auto &DL = static_cast(*DefinitionData);
+DL.MethodTyInfo = TS;
+  }
+
+  void setLambdaIsGeneric(bool IsGeneric) {
+assert(DefinitionData && DefinitionData->IsLambda &&
+   "setting lambda property of non-lambda class");
+auto &DL = static_cast(*DefinitionData);
+DL.IsGenericLambda = IsGeneric;
+  }
+
   // Determine whether this type is an Interface Like type for
   // __interface inheritance purposes.
   bool isInterfaceLike() const;

diff  --git a/clang/include/clang/Sema/Scope.h 
b/clang/include/clang/Sema/Scope.h
index be5cdb62045b1..9e81706cd2aa1 100644
--- a/clang/include/clang/Sema/Scope.h
+++ b/clang/include/clang/Sema/Scope.h
@@ -145,6 +145,11 @@ class Scope {
 /// This is a scope of some OpenMP directive with
 /// order clause which specifies concurrent
 OpenMPOrderClauseScope = 0x400,
+/// This is the scope for a lambda, after the lambda introducer.
+/// Lambdas need two FunctionPrototypeScope scopes (because there is a
+/// template scope in between), the outer scope does not increase the
+/// depth of recursion.
+LambdaScope = 0x800,
   };
 
 private:

diff  --git a/clang/include/clang/Sema/ScopeInfo.h 
b/clang/include/clang/Sema/ScopeInfo.h
index 65fa18fbb2903..5888dee0a883d 100644
--- a/clang/include/clang/Sema/ScopeInfo.h
+++ b/clang/include/clang/Sema/ScopeInfo.h
@@ -838,6 +838,11 @@ class LambdaScopeInfo final :
   /// The lambda's compiler-generated \c operator().
   CXXMethodDecl *CallOperator = nullptr;
 
+  /// Indicate that we parsed the parameter list
+  /// at which point the mutability of the lambda
+  /// is known.
+  bool AfterParameterList = true;
+
   /// Source range covering the lambda introducer [...].
   SourceRange IntroducerRange;
 
@@ -849,8 +854,9 @@ class LambdaScopeInfo final :
   /// explicit captures.
   unsigned NumExplicitCaptures = 0

[clang] e4bc989 - [Clang] Fix typo in ReleaseNotes.rst

2023-01-31 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-01-31T11:19:44+01:00
New Revision: e4bc9898ddbeb70bc49d713bbf863f050f21e03f

URL: 
https://github.com/llvm/llvm-project/commit/e4bc9898ddbeb70bc49d713bbf863f050f21e03f
DIFF: 
https://github.com/llvm/llvm-project/commit/e4bc9898ddbeb70bc49d713bbf863f050f21e03f.diff

LOG: [Clang] Fix typo in ReleaseNotes.rst

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index fe418d938650..efa9fe076b41 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -112,7 +112,7 @@ C++2b Feature Support
 
 - Implemented `P2036R3: Change scope of lambda trailing-return-type 
`_
   and `P2579R0 Mitigation strategies for P2036 `_.
-  This proposals modify how variables captured in lambdas can appear in 
trailing return type
+  These proposals modify how variables captured in lambdas can appear in 
trailing return type
   expressions and how their types are deduced therein, in all C++ language 
versions.
 
 CUDA/HIP Language Changes in Clang



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


[clang] a041572 - Let the c(xx)_status pages reflect that clang 17 is released

2023-09-19 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-09-19T20:28:45+02:00
New Revision: a041572353fbb9745c92f8dc1f9f184dbcaacfd9

URL: 
https://github.com/llvm/llvm-project/commit/a041572353fbb9745c92f8dc1f9f184dbcaacfd9
DIFF: 
https://github.com/llvm/llvm-project/commit/a041572353fbb9745c92f8dc1f9f184dbcaacfd9.diff

LOG: Let the c(xx)_status pages reflect that clang 17 is released

Added: 


Modified: 
clang/www/c_status.html
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/www/c_status.html b/clang/www/c_status.html
index 1c45bf3a65a0d36..99e5c0109d4ffca 100644
--- a/clang/www/c_status.html
+++ b/clang/www/c_status.html
@@ -1032,7 +1032,7 @@ C23 implementation status
 
   Add annotations for unreachable control flow v2
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2826.pdf";>N2826
-  Clang 17
+  Clang 17
 
 
   Unicode Sequences More Than 21 Bits are a Constraint Violation 
r0
@@ -1079,11 +1079,11 @@ C23 implementation status
 

 https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2900.htm";>N2900
-Clang 17
+Clang 17
   

 https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3011.htm";>N3011
-Clang 17
+Clang 17
   
 
   Not-so-magic: typeof
@@ -1104,7 +1104,7 @@ C23 implementation status
 
   Revise spelling of keywords v7
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2934.pdf";>N2934
-  Clang 17
+  Clang 17
 
 
   Make false and true first-class language features v8
@@ -1130,7 +1130,7 @@ C23 implementation status
 
   Remove ATOMIC_VAR_INIT v2
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2886.htm";>N2886
-  Clang 17
+  Clang 17
 
 
   Require exact-width integer type interfaces v2
@@ -1211,7 +1211,7 @@ C23 implementation status
 
   Introduce the nullptr constant
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3042.htm";>N3042
-  Clang 17
+  Clang 17
 
 
   Memory layout of unions

diff  --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index d888c8487abe819..41acb47b40d878f 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -125,7 +125,7 @@ C++2c implementation status
  
   constexpr cast from void*
   https://wg21.link/P2738R1";>P2738R1
-  Clang 17
+  Clang 17
  
  
   On the ignorability of standard attributes
@@ -140,7 +140,7 @@ C++2c implementation status
  
   User-generated static_assert messages
   https://wg21.link/P2741R3";>P2741R3
-  Clang 17
+  Clang 17
  
  
   Placeholder variables with no name
@@ -231,7 +231,7 @@ C++23 implementation status
 
   Change scope of lambda trailing-return-type
   https://wg21.link/P2036R3";>P2036R3
-  Clang 17
+  Clang 17
 
 
   https://wg21.link/P2579R0";>P2579R0
@@ -407,7 +407,7 @@ C++23 implementation status
 
   consteval needs to propagate up
   https://wg21.link/P2564R3";>P2564R3 (DR)
-  Clang 17
+  Clang 17
 
 
   Lifetime extension in range-based for loops
@@ -576,7 +576,7 @@ C++20 implementation status
   

 https://wg21.link/p2002r1";>P2002R1
-Clang 17
+Clang 17
   
   
 https://wg21.link/p2085r0";>P2085R0
@@ -595,7 +595,7 @@ C++20 implementation status
 
   Lambdas in unevaluated contexts
   https://wg21.link/p0315r4";>P0315R4
-  Clang 17
+  Clang 17
 
 
 
@@ -687,7 +687,7 @@ C++20 implementation status
 
   Immediate functions (consteval)
   https://wg21.link/p1073r3";>P1073R3
-  Clang 17
+  Clang 17
 

 https://wg21.link/p1937r2";>P1937R2
@@ -810,7 +810,7 @@ C++20 implementation status
 
   Class template argument deduction for aggregates
   https://wg21.link/p1816r0";>P1816R0
-  Clang 17
+  Clang 17
 

 https://wg21.link/p2082r1";>P2082R1



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


[clang] 624c130 - [Clang][C] Fixed a bug where we reject an _Atomic qualified integer in a switch statment

2023-09-20 Thread Corentin Jabot via cfe-commits

Author: Guillot Tony
Date: 2023-09-20T19:19:02+02:00
New Revision: 624c130578744da4bb07b13e056e619f8ce260fa

URL: 
https://github.com/llvm/llvm-project/commit/624c130578744da4bb07b13e056e619f8ce260fa
DIFF: 
https://github.com/llvm/llvm-project/commit/624c130578744da4bb07b13e056e619f8ce260fa.diff

LOG: [Clang][C] Fixed a bug where we reject an _Atomic qualified integer in a 
switch statment

We are currently rejecting an _Atomic qualified integer in a switch statment.
This fixes the issue by doing an Lvalue conversion before trying to match on 
the type.
Fixes #65557

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D159522

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaOverload.cpp
clang/test/Sema/atomic-expr.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 44a5d5740dabef1..43b113d00a50956 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -226,6 +226,8 @@ Bug Fixes in This Version
   an invalid conversion during method function overload resolution.
 - Fix parser crash when dealing with ill-formed objective C++ header code. 
Fixes
   (`#64836 `_)
+- Clang now allows an ``_Atomic`` qualified integer in a switch statement. 
Fixes
+  (`#65557 `_)
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 3ba7266122e4c0c..0ac2ac258c0c7d1 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -6302,10 +6302,12 @@ ExprResult Sema::PerformContextualImplicitConversion(
 From = result.get();
   }
 
+  // Try converting the expression to an Lvalue first, to get rid of 
qualifiers.
+  ExprResult Converted = DefaultLvalueConversion(From);
+  QualType T = Converted.isUsable() ? Converted.get()->getType() : QualType();
   // If the expression already has a matching type, we're golden.
-  QualType T = From->getType();
   if (Converter.match(T))
-return DefaultLvalueConversion(From);
+return Converted;
 
   // FIXME: Check for missing '()' if T is a function type?
 

diff  --git a/clang/test/Sema/atomic-expr.c b/clang/test/Sema/atomic-expr.c
index b34c15e4fca8b49..8eefbf92152b817 100644
--- a/clang/test/Sema/atomic-expr.c
+++ b/clang/test/Sema/atomic-expr.c
@@ -216,3 +216,9 @@ void func_18(void) {
   struct T { int a; };
   (void)(_Atomic struct T)s; // expected-error {{used type 'struct T' where 
arithmetic or pointer type is required}}
 }
+
+// Test if we can handle an _Atomic qualified integer in a switch statement.
+void func_19(void) {
+  _Atomic int a = 0;
+  switch (a) { }
+}



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


[clang] 33dfd90 - Fix sphinx bot build

2023-09-20 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-09-20T22:27:29+02:00
New Revision: 33dfd90700a11fb39802d0b1ab500f3a8efd7e78

URL: 
https://github.com/llvm/llvm-project/commit/33dfd90700a11fb39802d0b1ab500f3a8efd7e78
DIFF: 
https://github.com/llvm/llvm-project/commit/33dfd90700a11fb39802d0b1ab500f3a8efd7e78.diff

LOG: Fix sphinx bot build

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3cf2d4f6cfb30cc..3c661b8a08fe36d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -50,13 +50,15 @@ C++ Specific Potentially Breaking Changes
   account the possibility that functions could be overloaded on their template
   parameter lists or requires-clauses. This causes mangled names to change for
   function templates in the following cases:
-- When the function has any constraints, whether from constrained template
+
+  - When the function has any constraints, whether from constrained template
   parameters or requires-clauses.
-- When the template parameter list includes a deduced type -- either
+  - When the template parameter list includes a deduced type -- either
   ``auto``, ``decltype(auto)``, or a deduced class template specialization
   type.
-- When a template template parameter is given a template template argument
+  - When a template template parameter is given a template template argument
   that has a 
diff erent template parameter list.
+
   This fixes a number of issues where valid programs would be rejected due to
   mangling collisions, or would in some cases be silently miscompiled. Clang
   will use the old manglings if ``-fclang-abi-compat=17`` or lower is



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


[clang] d6ae4bd - [Clang][NFC] Add tests for #56071

2023-09-28 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-09-28T17:57:56+02:00
New Revision: d6ae4bd686714d34969012fa273140e547606d81

URL: 
https://github.com/llvm/llvm-project/commit/d6ae4bd686714d34969012fa273140e547606d81
DIFF: 
https://github.com/llvm/llvm-project/commit/d6ae4bd686714d34969012fa273140e547606d81.diff

LOG: [Clang][NFC] Add tests for #56071

Theses tests were part of https://reviews.llvm.org/D140184,
which is no longer necessary but preserving the tests seems useful.

Thanks to Richard Trieu for providing these tests and the work
on this PR.

Added: 
clang/test/SemaCXX/lambda-expressions-gh56071.cpp

Modified: 


Removed: 




diff  --git a/clang/test/SemaCXX/lambda-expressions-gh56071.cpp 
b/clang/test/SemaCXX/lambda-expressions-gh56071.cpp
new file mode 100644
index 000..d45d2d9b2e40976
--- /dev/null
+++ b/clang/test/SemaCXX/lambda-expressions-gh56071.cpp
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -Wno-unused-value -std=c++17
+// expected-no-diagnostics
+namespace test1 {
+
+template  int return_num() { return num; }
+
+template  struct lambda_wrapper {
+  lambda &outer_lambda;
+  lambda_wrapper(lambda& outer_lambda) : outer_lambda(outer_lambda) {}
+  template  auto operator+(T t) { outer_lambda(t); return 1; }
+};
+
+template 
+void bw(lambda& outer_lambda) {
+  (lambda_wrapper(outer_lambda) + ... + return_num());
+}
+
+template  auto check_return_type(lambda inner_lambda) {
+  using inner_lambda_return_type = decltype(inner_lambda(5));
+}
+
+void cs() {
+  auto outer_lambda = [](auto param) {
+auto inner_lambda = [](auto o) -> decltype(param) {};
+check_return_type(inner_lambda);
+  };
+  bw<1,2>(outer_lambda);
+}
+
+}  // namespace test1
+
+namespace test2 {
+
+template 
+auto run_lambda_with_zero(lambda l) {
+  l(0);
+}
+template 
+void run_lambda_once_per_type(lambda l) {
+  ((Ts{}, run_lambda_with_zero(l)), ...);
+}
+template  void inner_function() {
+  char c;
+  [](auto param) -> decltype(c) { return param; }(0);
+}
+void run() {
+  auto x = [](auto) -> void { inner_function(); };
+  run_lambda_once_per_type(x);
+}
+
+}  // namespace test2



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


[clang] f756061 - [Clang] Add missing words to ReleaseNotes.rst

2023-10-02 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-10-02T15:14:32+02:00
New Revision: f756061387c801e86d2a0f7ec6e162bb5b5bbfdf

URL: 
https://github.com/llvm/llvm-project/commit/f756061387c801e86d2a0f7ec6e162bb5b5bbfdf
DIFF: 
https://github.com/llvm/llvm-project/commit/f756061387c801e86d2a0f7ec6e162bb5b5bbfdf.diff

LOG: [Clang] Add missing words to ReleaseNotes.rst

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index df4299d2502eab7..53be34961fd15a5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -95,6 +95,7 @@ C++23 Feature Support
   implemented (`CWG2553 `_, `CWG2554 
`_,
   `CWG2653 `_, `CWG2687 
`_). Because the
   support for this feature is still experimental, the feature test macro 
``__cpp_explicit_this_parameter``
+  was not set in this version.
 
 C++2c Feature Support
 ^



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


[clang] 64cfcde - [Clang] Fix the location of default init expressions

2023-07-18 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-07-19T08:54:01+02:00
New Revision: 64cfcde31a48962c3bbc703753a4ea41200da7a8

URL: 
https://github.com/llvm/llvm-project/commit/64cfcde31a48962c3bbc703753a4ea41200da7a8
DIFF: 
https://github.com/llvm/llvm-project/commit/64cfcde31a48962c3bbc703753a4ea41200da7a8.diff

LOG: [Clang] Fix the location of default init expressions

Default member initializations constructed from
a parenthesized aggregate initialization should be constructed
at the location of the left paren, to be consistent with
brace initialization.
Otherwise we get diagmostics and source_location in the wrong places.

Fixes #63903

Reviewed By: aaron.ballman, #clang-language-wg

Differential Revision: https://reviews.llvm.org/D155573

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaInit.cpp
clang/test/SemaCXX/paren-list-agg-init.cpp
clang/test/SemaCXX/source_location.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index eb888282bf6676..805b0f5697f759 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -766,6 +766,9 @@ Bug Fixes to C++ Support
 - Merge lambdas in require expressions in standard C++ modules.
   (`#63544 `_)
 
+- Fix location of default member initialization in parenthesized aggregate
+  initialization.
+  (`#63903 `_)
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 8e2177bce4fd79..32c9215184eba5 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -5593,7 +5593,8 @@ static void TryOrBuildParenListInitialization(
 // C++ [dcl.init]p16.6.2.2
 //   The remaining elements are initialized with their default
 //   member initializers, if any
-ExprResult DIE = S.BuildCXXDefaultInitExpr(FD->getLocation(), FD);
+ExprResult DIE = S.BuildCXXDefaultInitExpr(
+Kind.getParenOrBraceRange().getEnd(), FD);
 if (DIE.isInvalid())
   return;
 S.checkInitializerLifetime(SubEntity, DIE.get());

diff  --git a/clang/test/SemaCXX/paren-list-agg-init.cpp 
b/clang/test/SemaCXX/paren-list-agg-init.cpp
index e2eec1779699ac..944ea76b81d24d 100644
--- a/clang/test/SemaCXX/paren-list-agg-init.cpp
+++ b/clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -299,3 +299,14 @@ namespace gh63758 {
   struct S {} s;
   auto words = (char[])s; // expected-error {{C-style cast from 'struct S' to 
'char[]' is not allowed}}
 };
+
+namespace GH63903 {
+  constexpr int f(); // expected-note {{declared here}}
+  struct S {
+int a = 0, b = f(); // expected-note {{undefined function 'f' cannot be 
used in a constant expression}}
+  };
+
+  // Test that errors produced by default members are produced at the location 
of the initialization
+  constexpr S s(0); // beforecxx20-warning {{aggregate initialization of type 
'const S' from a parenthesized list of values is a C++20 extension}} \
+// expected-error {{constexpr variable 's' must be 
initialized by a constant expression}}
+}

diff  --git a/clang/test/SemaCXX/source_location.cpp 
b/clang/test/SemaCXX/source_location.cpp
index 6ff58d4ee8ca11..2732700bf4bee3 100644
--- a/clang/test/SemaCXX/source_location.cpp
+++ b/clang/test/SemaCXX/source_location.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fexceptions -verify %s
 // RUN: %clang_cc1 -std=c++2a -fcxx-exceptions -DUSE_CONSTEVAL -fexceptions 
-verify %s
+// RUN: %clang_cc1 -std=c++2b -fcxx-exceptions -DUSE_CONSTEVAL -DPAREN_INIT 
-fexceptions -verify %s
 // RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fms-extensions -DMS 
-fexceptions -verify %s
 // RUN: %clang_cc1 -std=c++2a -fcxx-exceptions -fms-extensions -DMS 
-DUSE_CONSTEVAL -fexceptions -verify %s
 // expected-no-diagnostics
@@ -781,3 +782,20 @@ constexpr int f(int i = G{}.line) {
 static_assert(f() != // intentional new line
   f());
 }
+
+#ifdef PAREN_INIT
+namespace GH63903 {
+struct S {
+int _;
+int i = SL::current().line();
+int j = __builtin_LINE();
+};
+// Ensure parent aggregate initialization is consistent with brace
+// aggregate initialization.
+// Note: consteval functions are evaluated where they are used.
+static_assert(S(0).i == __builtin_LINE());
+static_assert(S(0).i == S{0}.i);
+static_assert(S(0).j == S{0}.j);
+static_assert(S(0).j == S{0}.i);
+}
+#endif



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


[clang] 47ccfd7 - [Clang] Implement P2741R3 - user-generated static_assert messages

2023-07-19 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-07-20T08:33:19+02:00
New Revision: 47ccfd7a89e2a9a747a7114db18db1376324799c

URL: 
https://github.com/llvm/llvm-project/commit/47ccfd7a89e2a9a747a7114db18db1376324799c
DIFF: 
https://github.com/llvm/llvm-project/commit/47ccfd7a89e2a9a747a7114db18db1376324799c.diff

LOG: [Clang] Implement P2741R3 - user-generated static_assert messages

Reviewed By: #clang-language-wg, aaron.ballman

Differential Revision: https://reviews.llvm.org/D154290

Added: 
clang/test/SemaCXX/static-assert-cxx26.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/DeclCXX.h
clang/include/clang/AST/Expr.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/AST/DeclCXX.cpp
clang/lib/AST/DeclPrinter.cpp
clang/lib/AST/ExprConstant.cpp
clang/lib/AST/ODRDiagsEmitter.cpp
clang/lib/Frontend/InitPreprocessor.cpp
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/Lexer/cxx-features.cpp
clang/tools/libclang/CIndex.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 55fa4cb27d0b61..ef1cc898c21f6d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -137,6 +137,7 @@ C++2c Feature Support
 - Implemented `P2738R1: constexpr cast from void* 
`_.
 - Partially implemented `P2361R6: Unevaluated strings 
`_.
   The changes to attributes declarations are not part of this release.
+- Implemented `P2741R3: user-generated static_assert messages  
`_.
 
 Resolutions to C++ Defect Reports
 ^

diff  --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index f4322e1e00f0c6..afec8150c2c9c6 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -4010,12 +4010,12 @@ class UnresolvedUsingIfExistsDecl final : public 
NamedDecl {
 /// Represents a C++11 static_assert declaration.
 class StaticAssertDecl : public Decl {
   llvm::PointerIntPair AssertExprAndFailed;
-  StringLiteral *Message;
+  Expr *Message;
   SourceLocation RParenLoc;
 
   StaticAssertDecl(DeclContext *DC, SourceLocation StaticAssertLoc,
-   Expr *AssertExpr, StringLiteral *Message,
-   SourceLocation RParenLoc, bool Failed)
+   Expr *AssertExpr, Expr *Message, SourceLocation RParenLoc,
+   bool Failed)
   : Decl(StaticAssert, DC, StaticAssertLoc),
 AssertExprAndFailed(AssertExpr, Failed), Message(Message),
 RParenLoc(RParenLoc) {}
@@ -4027,15 +4027,15 @@ class StaticAssertDecl : public Decl {
 
   static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC,
   SourceLocation StaticAssertLoc,
-  Expr *AssertExpr, StringLiteral *Message,
+  Expr *AssertExpr, Expr *Message,
   SourceLocation RParenLoc, bool Failed);
   static StaticAssertDecl *CreateDeserialized(ASTContext &C, unsigned ID);
 
   Expr *getAssertExpr() { return AssertExprAndFailed.getPointer(); }
   const Expr *getAssertExpr() const { return AssertExprAndFailed.getPointer(); 
}
 
-  StringLiteral *getMessage() { return Message; }
-  const StringLiteral *getMessage() const { return Message; }
+  Expr *getMessage() { return Message; }
+  const Expr *getMessage() const { return Message; }
 
   bool isFailed() const { return AssertExprAndFailed.getInt(); }
 

diff  --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 7a886f546ed937..f9795b6386c46f 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -762,6 +762,11 @@ class Expr : public ValueStmt {
   /// strlen, false otherwise.
   bool tryEvaluateStrLen(uint64_t &Result, ASTContext &Ctx) const;
 
+  bool EvaluateCharRangeAsString(std::string &Result,
+ const Expr *SizeExpression,
+ const Expr *PtrExpression, ASTContext &Ctx,
+ EvalResult &Status) const;
+
   /// Enumeration used to describe the kind of Null pointer constant
   /// returned from \c isNullPointerConstant().
   enum NullPointerConstantKind {

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 52cca5acfd9245..7faefab0a4187a 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -83,8 +83,8 @@ def err_typecheck_converted_constant_expression_indirect : 
Error<
   "bind reference to a temporary">;
 def err_expr_not_cce : Error<
  

[clang-tools-extra] 528447f - [clang-tools-extra] the message in a static_assert is not always a string literal

2023-07-20 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-07-20T09:23:08+02:00
New Revision: 528447ff265a6c58b43af6cff2a3ee0ce5784331

URL: 
https://github.com/llvm/llvm-project/commit/528447ff265a6c58b43af6cff2a3ee0ce5784331
DIFF: 
https://github.com/llvm/llvm-project/commit/528447ff265a6c58b43af6cff2a3ee0ce5784331.diff

LOG: [clang-tools-extra] the message in a static_assert is not always a string 
literal

Fixes build failure introduce by 47ccfd7.

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/UnaryStaticAssertCheck.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/UnaryStaticAssertCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UnaryStaticAssertCheck.cpp
index 81b21565667e8a..c90d2e4f764b89 100644
--- a/clang-tools-extra/clang-tidy/modernize/UnaryStaticAssertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UnaryStaticAssertCheck.cpp
@@ -21,7 +21,8 @@ void UnaryStaticAssertCheck::registerMatchers(MatchFinder 
*Finder) {
 void UnaryStaticAssertCheck::check(const MatchFinder::MatchResult &Result) {
   const auto *MatchedDecl =
   Result.Nodes.getNodeAs("static_assert");
-  const StringLiteral *AssertMessage = MatchedDecl->getMessage();
+  const auto *AssertMessage =
+  dyn_cast_if_present(MatchedDecl->getMessage());
 
   SourceLocation Loc = MatchedDecl->getLocation();
 



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


[clang] 9265f7c - [Clang] Fix failing test caused by non-portable diag message

2023-07-20 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-07-20T17:55:28+02:00
New Revision: 9265f7c40a0aedb79ba1c8c4728d109c47946fbe

URL: 
https://github.com/llvm/llvm-project/commit/9265f7c40a0aedb79ba1c8c4728d109c47946fbe
DIFF: 
https://github.com/llvm/llvm-project/commit/9265f7c40a0aedb79ba1c8c4728d109c47946fbe.diff

LOG: [Clang] Fix failing test caused by non-portable diag message

Added: 


Modified: 
clang/test/SemaCXX/static-assert-cxx26.cpp

Removed: 




diff  --git a/clang/test/SemaCXX/static-assert-cxx26.cpp 
b/clang/test/SemaCXX/static-assert-cxx26.cpp
index 9eddc4830e080e..4c28fba1ca5fc3 100644
--- a/clang/test/SemaCXX/static-assert-cxx26.cpp
+++ b/clang/test/SemaCXX/static-assert-cxx26.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++2c -fsyntax-only %s -verify
+// RUN: %clang_cc1 -std=c++2c -triple=x86_64-linux -fsyntax-only %s -verify
 
 static_assert(true, "");
 static_assert(true, 0); // expected-error {{the message in a static assertion 
must be a string literal or an object with 'data()' and 'size()' member 
functions}}



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


[clang] f9caa12 - [Clang] Fix constraint checking of non-generic lambdas.

2023-07-21 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-07-21T10:59:36+02:00
New Revision: f9caa12328b265b77221fe7a310d4504673d814a

URL: 
https://github.com/llvm/llvm-project/commit/f9caa12328b265b77221fe7a310d4504673d814a
DIFF: 
https://github.com/llvm/llvm-project/commit/f9caa12328b265b77221fe7a310d4504673d814a.diff

LOG: [Clang] Fix constraint checking of non-generic lambdas.

A lambda call operator can be a templated entity -
and therefore have constraints while not being a function template

   template void f() {
 []() requires false { }();
   }

In that case, we would check the constraints of the call operator
which is non-viable. However, we would find a viable candidate:
the conversion operator to function pointer, and use it to
perform a surrogate call.
These constraints were not checked because:
 * We never check the constraints of surrogate functions
 * The lambda conversion operator has non constraints.

>From the wording, it is not clear what the intent is but
it seems reasonable to expect the constraints of the lambda conversion
operator to be checked and it is consistent with GCC and MSVC.

This patch also improve the diagnostics for constraint failure
on surrogate calls.

Fixes #63181

Reviewed By: #clang-language-wg, aaron.ballman

Differential Revision: https://reviews.llvm.org/D154368

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaConcept.cpp
clang/lib/Sema/SemaLambda.cpp
clang/lib/Sema/SemaOverload.cpp
clang/test/SemaTemplate/concepts.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 05a7ec04d60c31..45381e7aad4ffc 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -777,6 +777,8 @@ Bug Fixes to C++ Support
 - Fix location of default member initialization in parenthesized aggregate
   initialization.
   (`#63903 `_)
+- Fix constraint checking of non-generic lambdas.
+  (`#63181 `_)
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 569c6a054e7102..99917f190d82a1 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4732,6 +4732,8 @@ def note_ovl_candidate_bad_target : Note<
 def note_ovl_candidate_constraints_not_satisfied : Note<
 "candidate %sub{select_ovl_candidate_kind}0,1,2 not viable: constraints "
 "not satisfied">;
+def note_ovl_surrogate_constraints_not_satisfied : Note<
+"conversion candidate %0 not viable: constraints not satisfied">;
 def note_implicit_member_target_infer_collision : Note<
 "implicit %sub{select_special_member_kind}0 inferred target collision: 
call to both "
 "%select{__device__|__global__|__host__|__host__ __device__}1 and "

diff  --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index f562e85009282a..f24b549dd2ef7a 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -679,6 +679,15 @@ bool Sema::CheckFunctionConstraints(const FunctionDecl *FD,
 return false;
   }
 
+  // A lambda conversion operator has the same constraints as the call operator
+  // and constraints checking relies on whether we are in a lambda call 
operator
+  // (and may refer to its parameters), so check the call operator instead.
+  if (const auto *MD = dyn_cast(FD);
+  MD && isLambdaConversionOperator(const_cast(MD)))
+return CheckFunctionConstraints(MD->getParent()->getLambdaCallOperator(),
+Satisfaction, UsageLoc,
+ForOverloadResolution);
+
   DeclContext *CtxToSave = const_cast(FD);
 
   while (isLambdaCallOperator(CtxToSave) || FD->isTransparentContext()) {

diff  --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index 339d16b080ee22..06fc53591a7643 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -1633,6 +1633,11 @@ static void addFunctionPointerConversion(Sema &S, 
SourceRange IntroducerRange,
   Conversion->setAccess(AS_public);
   Conversion->setImplicit(true);
 
+  // A non-generic lambda may still be a templated entity. We need to preserve
+  // constraints when converting the lambda to a function pointer. See GH63181.
+  if (Expr *Requires = CallOperator->getTrailingRequiresClause())
+Conversion->setTrailingRequiresClause(Requires);
+
   if (Class->isGenericLambda()) {
 // Create a template version of the conversion operator, using the template
 // parameter list of the function call operator.

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index c70d37de0a0130..42a367dca531d5 100644
--- a/clang

[clang] 33c2e4e - [Clang] Fix access to an unitinialized variable

2023-07-21 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-07-21T12:34:35+02:00
New Revision: 33c2e4ec7c3efb7d77df0d9f5c3f1c423aac6b0f

URL: 
https://github.com/llvm/llvm-project/commit/33c2e4ec7c3efb7d77df0d9f5c3f1c423aac6b0f
DIFF: 
https://github.com/llvm/llvm-project/commit/33c2e4ec7c3efb7d77df0d9f5c3f1c423aac6b0f.diff

LOG: [Clang] Fix access to an unitinialized variable

This fixes the spurious test failure introduced in f9caa12328b2

Added: 


Modified: 
clang/lib/Sema/SemaOverload.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 42a367dca531d5..a3d9abb1537789 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -11658,7 +11658,8 @@ static void NoteSurrogateCandidate(Sema &S, 
OverloadCandidate *Cand) {
   if (isRValueReference) FnType = S.Context.getRValueReferenceType(FnType);
   if (isLValueReference) FnType = S.Context.getLValueReferenceType(FnType);
 
-  if (Cand->FailureKind == ovl_fail_constraints_not_satisfied) {
+  if (!Cand->Viable &&
+  Cand->FailureKind == ovl_fail_constraints_not_satisfied) {
 S.Diag(Cand->Surrogate->getLocation(),
diag::note_ovl_surrogate_constraints_not_satisfied)
 << Cand->Surrogate;



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


[clang] 2021910 - [Clang] Diagnose jumps into statement expressions

2023-07-21 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-07-21T15:08:51+02:00
New Revision: 20219106060208f0c2f5d096eb3aed7b712f5067

URL: 
https://github.com/llvm/llvm-project/commit/20219106060208f0c2f5d096eb3aed7b712f5067
DIFF: 
https://github.com/llvm/llvm-project/commit/20219106060208f0c2f5d096eb3aed7b712f5067.diff

LOG: [Clang] Diagnose jumps into statement expressions

Such jumps are not allowed by GCC and allowing them
can lead to situations where we jumps into unevaluated
statements.

Fixes #63682

Reviewed By: aaron.ballman, #clang-language-wg

Differential Revision: https://reviews.llvm.org/D154696

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/JumpDiagnostics.cpp
clang/lib/Sema/SemaExpr.cpp
clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
clang/test/Sema/asm-goto.cpp
clang/test/Sema/scope-check.c
clang/test/SemaCXX/constant-expression-cxx14.cpp
clang/test/SemaObjC/scope-check.m

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 45381e7aad4ffc..f412e790d88b8a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -660,6 +660,9 @@ Bug Fixes in This Version
 - Fixed false positive error diagnostic observed from mixing ``asm goto`` with
   ``__attribute__((cleanup()))`` variables falsely warning that jumps to
   non-targets would skip cleanup.
+- Correcly diagnose jumps into statement expressions.
+  This ensures the behavior of Clang is consistent with GCC.
+  (`#63682 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
@@ -949,7 +952,7 @@ AST Matchers
 
 - The ``hasBody`` matcher now matches coroutine body nodes in
   ``CoroutineBodyStmts``.
-  
+
 - Add ``arrayInitIndexExpr`` and ``arrayInitLoopExpr`` matchers.
 
 clang-format

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 99917f190d82a1..b87414d91c238f 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6219,6 +6219,8 @@ def note_enters_block_captures_non_trivial_c_struct : 
Note<
   "to destroy">;
 def note_enters_compound_literal_scope : Note<
   "jump enters lifetime of a compound literal that is non-trivial to 
destruct">;
+def note_enters_statement_expression : Note<
+  "jump enters a statement expression">;
 
 def note_exits_cleanup : Note<
   "jump exits scope of variable with __attribute__((cleanup))">;

diff  --git a/clang/lib/Sema/JumpDiagnostics.cpp 
b/clang/lib/Sema/JumpDiagnostics.cpp
index 5a6df56323a98b..45ff36d5fe237b 100644
--- a/clang/lib/Sema/JumpDiagnostics.cpp
+++ b/clang/lib/Sema/JumpDiagnostics.cpp
@@ -466,6 +466,21 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S,
 return;
   }
 
+  case Stmt::StmtExprClass: {
+// [GNU]
+// Jumping into a statement expression with goto or using
+// a switch statement outside the statement expression with
+// a case or default label inside the statement expression is not 
permitted.
+// Jumping out of a statement expression is permitted.
+StmtExpr *SE = cast(S);
+unsigned NewParentScope = Scopes.size();
+Scopes.push_back(GotoScope(ParentScope,
+   diag::note_enters_statement_expression,
+   /*OutDiag=*/0, SE->getBeginLoc()));
+BuildScopeInformation(SE->getSubStmt(), NewParentScope);
+return;
+  }
+
   case Stmt::ObjCAtTryStmtClass: {
 // Disallow jumps into any part of an @try statement by pushing a scope and
 // walking all sub-stmts in that scope.

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 2a7ae730a9084f..240f1520efad2b 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -16509,6 +16509,8 @@ ExprResult Sema::ActOnAddrLabel(SourceLocation OpLoc, 
SourceLocation LabLoc,
 
 void Sema::ActOnStartStmtExpr() {
   PushExpressionEvaluationContext(ExprEvalContexts.back().Context);
+  // Make sure we diagnose jumping into a statement expression.
+  setFunctionHasBranchProtectedScope();
 }
 
 void Sema::ActOnStmtExprError() {

diff  --git a/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp 
b/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
index 0c357db764a92a..55af13bfc0ef3a 100644
--- a/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
+++ b/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
@@ -153,7 +153,8 @@ a:  if constexpr(sizeof(n) == 4) // expected-error 
{{redefinition}} expected-not
 
   void evil_things() {
 goto evil_label; // expected-error {{cannot jump}}
-if constexpr (true || ({evil_label: false;})) {} // expected-note 
{{constexpr if}}
+if constexpr (true || ({evil_label: false;})) {} // expected-note 
{{constexpr if}} \
+  

[clang] 02bb2be - [clang] Fix diagnostics for defaulted, implicitly deleted 'operator=='.

2023-07-23 Thread Corentin Jabot via cfe-commits

Author: Amirreza Ashouri
Date: 2023-07-23T10:58:17+02:00
New Revision: 02bb2beeef3d93360694de29573430f584caafe9

URL: 
https://github.com/llvm/llvm-project/commit/02bb2beeef3d93360694de29573430f584caafe9
DIFF: 
https://github.com/llvm/llvm-project/commit/02bb2beeef3d93360694de29573430f584caafe9.diff

LOG: [clang] Fix diagnostics for defaulted, implicitly deleted 'operator=='.

https://godbolt.org/z/cMKE3o1aG

According to the issue https://github.com/llvm/llvm-project/issues/63960 , 
compiler falsely complains that no viable `operator<=>` was found while we are 
actually looking for a `operator==`.
This bug has been fixed through adding a check of the `OverloadedOperatorKind` 
type's object, `OO`, to see if it is `OO_EqualEqual` in addition to 
`OO_ExclaimEqual`.

Reviewed By: #clang-language-wg, cor3ntin

Differential Revision: https://reviews.llvm.org/D155714

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
clang/test/CXX/class/class.compare/class.compare.default/p4.cpp
clang/test/CXX/class/class.compare/class.compare.secondary/p2.cpp
clang/test/CXX/class/class.compare/class.eq/p2.cpp
clang/test/CXX/class/class.compare/class.spaceship/p1.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1944605f09a25f..9298f24d62970c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -407,8 +407,10 @@ Improvements to Clang's diagnostics
   by making use of the syntactical structure of function calls. This avoids 
display
   of syntactically invalid codes in diagnostics.
   (`#57081: `_)
-- Clang no longer emits inappropriate notes about the loss of ``__unaligned`` 
qualifier
-  on overload resolution, when the actual reason for the failure is loss of 
other qualifiers.
+- The note emitted when an ``operator==`` was defaulted as deleted used to 
refer to
+  the lack of a data member's "three-way comparison operator". It now refers 
correctly
+  to the data member's ``operator==``.
+  (`#63960: `_)
 - Clang's notes about unconvertible types in overload resolution failure now 
covers
   the source range of parameter declaration of the candidate function 
declaration.
 

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 30e8e380e6596b..40fbaa043c1bfb 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -8209,7 +8209,8 @@ class DefaultedComparisonAnalyzer
 
   if (Diagnose == ExplainDeleted) {
 S.Diag(Subobj.Loc, diag::note_defaulted_comparison_no_viable_function)
-<< FD << (OO == OO_ExclaimEqual) << Subobj.Kind << Subobj.Decl;
+<< FD << (OO == OO_EqualEqual || OO == OO_ExclaimEqual)
+<< Subobj.Kind << Subobj.Decl;
 
 // For a three-way comparison, list both the candidates for the
 // original operator and the candidates for the synthesized operator.

diff  --git a/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp 
b/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
index 9094d400fd5467..b595825e1750ad 100644
--- a/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
+++ b/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
@@ -153,7 +153,7 @@ namespace P1946 {
 friend bool operator==(A &, A &); // expected-note {{would lose const 
qualifier}}
   };
   struct B {
-A a; // expected-note {{no viable three-way comparison}}
+A a; // expected-note {{no viable 'operator=='}}
 friend bool operator==(B, B) = default; // ok
 friend bool operator==(const B&, const B&) = default; // expected-warning 
{{deleted}} expected-note{{replace 'default'}}
   };

diff  --git a/clang/test/CXX/class/class.compare/class.compare.default/p4.cpp 
b/clang/test/CXX/class/class.compare/class.compare.default/p4.cpp
index fab2abb7dee004..02cdd7f85aebfa 100644
--- a/clang/test/CXX/class/class.compare/class.compare.default/p4.cpp
+++ b/clang/test/CXX/class/class.compare/class.compare.default/p4.cpp
@@ -100,7 +100,7 @@ namespace DeleteAfterFirstDecl {
   struct Q {
 struct X {
   friend std::strong_ordering operator<=>(const X&, const X&);
-} x; // expected-note {{no viable three-way comparison}}
+} x; // expected-note {{no viable 'operator=='}}
 // expected-error@+1 {{defaulting the corresponding implicit 'operator==' 
for this defaulted 'operator<=>' would delete it after its first declaration}}
 friend std::strong_ordering operator<=>(const Q&, const Q&) = default;
   };

diff  --git a/clang/test/CXX/class/class.compare/class.compare.secondary/p2.cpp 
b/clang/test/CXX/class/class.compare/class.compare.secondary/p2.cpp
index 07d43f15aac14c..e53738632e805e 1

[clang] ca3ad82 - [Clang][NFC] Restore changelog entry incorrectly removed by 02bb2beeef

2023-07-23 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-07-23T11:11:04+02:00
New Revision: ca3ad82cb50c79d8e43445bf93311ff39ec52c52

URL: 
https://github.com/llvm/llvm-project/commit/ca3ad82cb50c79d8e43445bf93311ff39ec52c52
DIFF: 
https://github.com/llvm/llvm-project/commit/ca3ad82cb50c79d8e43445bf93311ff39ec52c52.diff

LOG: [Clang][NFC] Restore changelog entry incorrectly removed by 02bb2beeef

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9298f24d62970c..84f0eae81589ce 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -407,6 +407,8 @@ Improvements to Clang's diagnostics
   by making use of the syntactical structure of function calls. This avoids 
display
   of syntactically invalid codes in diagnostics.
   (`#57081: `_)
+- Clang no longer emits inappropriate notes about the loss of ``__unaligned`` 
qualifier
+  on overload resolution, when the actual reason for the failure is loss of 
other qualifiers.
 - The note emitted when an ``operator==`` was defaulted as deleted used to 
refer to
   the lack of a data member's "three-way comparison operator". It now refers 
correctly
   to the data member's ``operator==``.



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


[clang] 8698262 - [Clang] Fix consteval propagation for aggregates and defaulted constructors

2023-07-24 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-07-24T18:15:38+02:00
New Revision: 8698262a4365bf22b5b0c96e77bfecd3dcf084a7

URL: 
https://github.com/llvm/llvm-project/commit/8698262a4365bf22b5b0c96e77bfecd3dcf084a7
DIFF: 
https://github.com/llvm/llvm-project/commit/8698262a4365bf22b5b0c96e77bfecd3dcf084a7.diff

LOG: [Clang] Fix consteval propagation for aggregates and defaulted constructors

This patch does a few things:

* Fix aggregate initialization.
  When an aggregate has an initializer that is immediate-escalating,
  the context in which it is used automatically becomes an immediate function.
  The wording does that by rpretending an aggregate initialization is itself
  an invocation which is not really how clang works, so my previous attempt
  was... wrong.

* Fix initialization of defaulted constructors with immediate escalating
  default member initializers.
  The wording was silent about that case and I did not handled it fully
  https://cplusplus.github.io/CWG/issues/2760.html

* Fix diagnostics
  In some cases clang would produce additional and unhelpful
  diagnostics by listing the invalid references to consteval
  function that appear in immediate escalating functions

Fixes https://github.com/llvm/llvm-project/issues/63742

Reviewed By: aaron.ballman, #clang-language-wg, Fznamznon

Differential Revision: https://reviews.llvm.org/D155175

Added: 
clang/test/CodeGenCXX/cxx2c-consteval-propagate.cpp

Modified: 
clang/include/clang/AST/RecursiveASTVisitor.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
clang/test/SemaCXX/cxx2b-consteval-propagate.cpp

Removed: 




diff  --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index 95b04fe3dd59b6..604875cd6337a4 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -2727,7 +2727,11 @@ DEF_TRAVERSE_STMT(CXXDefaultArgExpr, {
 TRY_TO(TraverseStmt(S->getExpr()));
 })
 
-DEF_TRAVERSE_STMT(CXXDefaultInitExpr, {})
+DEF_TRAVERSE_STMT(CXXDefaultInitExpr, {
+  if (getDerived().shouldVisitImplicitCode())
+TRY_TO(TraverseStmt(S->getExpr()));
+})
+
 DEF_TRAVERSE_STMT(CXXDeleteExpr, {})
 DEF_TRAVERSE_STMT(ExprWithCleanups, {})
 DEF_TRAVERSE_STMT(CXXInheritedCtorInitExpr, {})

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index b87414d91c238f..fe4c3005c0ba3f 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2685,7 +2685,8 @@ def err_immediate_function_used_before_definition : Error<
   "immediate function %0 used before it is defined">;
 
 def note_immediate_function_reason : Note<
-  "%0 is an immediate function because its body "
+  "%0 is an immediate %select{function|constructor}5 because "
+  "%select{its body|the%select{| default}7 initializer of %8}6 "
   "%select{evaluates the address of %select{an immediate|a consteval}2 "
   "function %1|contains a call to %select{an immediate|a consteval}2 "
   "%select{function|constructor}4 %1 and that call is not a constant "

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 082fa252feabac..3418a37b307785 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -1078,10 +1078,13 @@ class Sema final {
   public:
 SynthesizedFunctionScope(Sema &S, DeclContext *DC)
 : S(S), SavedContext(S, DC) {
+  auto *FD = dyn_cast(DC);
   S.PushFunctionScope();
   S.PushExpressionEvaluationContext(
-  Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
-  if (auto *FD = dyn_cast(DC)) {
+  (FD && FD->isConsteval())
+  ? ExpressionEvaluationContext::ImmediateFunctionContext
+  : ExpressionEvaluationContext::PotentiallyEvaluated);
+  if (FD) {
 FD->setWillHaveBody(true);
 S.ExprEvalContexts.back().InImmediateFunctionContext =
 FD->isImmediateFunction();
@@ -1106,8 +1109,10 @@ class Sema final {
 ~SynthesizedFunctionScope() {
   if (PushedCodeSynthesisContext)
 S.popCodeSynthesisContext();
-  if (auto *FD = dyn_cast(S.CurContext))
+  if (auto *FD = dyn_cast(S.CurContext)) {
 FD->setWillHaveBody(false);
+S.CheckImmediateEscalatingFunctionDefinition(FD, S.getCurFunction());
+  }
   S.PopExpressionEvaluationContext();
   S.PopFunctionScopeInfo();
 }
@@ -6578,11 +6583,11 @@ class Sema final {
   ExprResult CheckForImmediateInvocation(ExprResult E, FunctionDecl *Decl);
 
   bool CheckImmediateEscalatingFunctionDef

[clang] 86da763 - [Clang] Fix crash in CIndex, when visiting a static_assert without message

2023-07-25 Thread Corentin Jabot via cfe-commits

Author: Kai Stierand
Date: 2023-07-25T10:53:14+02:00
New Revision: 86da763ab6ed19c58349d3f6f62d4bb52becab2c

URL: 
https://github.com/llvm/llvm-project/commit/86da763ab6ed19c58349d3f6f62d4bb52becab2c
DIFF: 
https://github.com/llvm/llvm-project/commit/86da763ab6ed19c58349d3f6f62d4bb52becab2c.diff

LOG: [Clang] Fix crash in CIndex, when visiting a static_assert without message

After implementation of "[Clang] Implement P2741R3 - user-generated 
static_assert messages"  (47ccfd7a89e2a9a747a7114db18db1376324799c) the c 
indexer crashes when handling a `static_assert` w/o any message.
This is caused by using `dyn_cast` to get the literal string, which isn't 
working on `nullptr`.

Reviewed By: cor3ntin

Differential Revision: https://reviews.llvm.org/D156053

Added: 


Modified: 
clang/tools/libclang/CIndex.cpp
clang/unittests/libclang/LibclangTest.cpp
clang/unittests/libclang/TestUtils.h

Removed: 




diff  --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index 120ad4ea39e1a9..1bdc0bf742a8ce 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/tools/libclang/CIndex.cpp
@@ -1294,7 +1294,7 @@ bool CursorVisitor::VisitUnresolvedUsingTypenameDecl(
 bool CursorVisitor::VisitStaticAssertDecl(StaticAssertDecl *D) {
   if (Visit(MakeCXCursor(D->getAssertExpr(), StmtParent, TU, 
RegionOfInterest)))
 return true;
-  if (auto *Message = dyn_cast(D->getMessage()))
+  if (auto *Message = D->getMessage())
 if (Visit(MakeCXCursor(Message, StmtParent, TU, RegionOfInterest)))
   return true;
   return false;

diff  --git a/clang/unittests/libclang/LibclangTest.cpp 
b/clang/unittests/libclang/LibclangTest.cpp
index f85a72b1c2f702..b1f653441d0efe 100644
--- a/clang/unittests/libclang/LibclangTest.cpp
+++ b/clang/unittests/libclang/LibclangTest.cpp
@@ -1172,6 +1172,80 @@ TEST_F(LibclangParseTest, UnaryOperator) {
   });
 }
 
+TEST_F(LibclangParseTest, VisitStaticAssertDecl_noMessage) {
+  const char testSource[] = R"cpp(static_assert(true))cpp";
+  std::string fileName = "main.cpp";
+  WriteFile(fileName, testSource);
+  const char *Args[] = {"-xc++"};
+  ClangTU = clang_parseTranslationUnit(Index, fileName.c_str(), Args, 1,
+   nullptr, 0, TUFlags);
+
+  std::optional staticAssertCsr;
+  Traverse([&](CXCursor cursor, CXCursor parent) -> CXChildVisitResult {
+if (cursor.kind == CXCursor_StaticAssert) {
+  staticAssertCsr.emplace(cursor);
+  return CXChildVisit_Break;
+}
+return CXChildVisit_Recurse;
+  });
+  ASSERT_TRUE(staticAssertCsr.has_value());
+  Traverse(*staticAssertCsr, [](CXCursor cursor, CXCursor parent) {
+EXPECT_EQ(cursor.kind, CXCursor_CXXBoolLiteralExpr);
+return CXChildVisit_Break;
+  });
+  EXPECT_EQ(fromCXString(clang_getCursorSpelling(*staticAssertCsr)), "");
+}
+
+TEST_F(LibclangParseTest, VisitStaticAssertDecl_exprMessage) {
+  const char testSource[] = R"cpp(
+template 
+constexpr unsigned size(const char (&)[s])
+{
+return s - 1;
+}
+
+struct Message {
+static constexpr char message[] = "Hello World!";
+constexpr const char* data() const { return message;}
+constexpr unsigned size() const
+{
+return ::size(message);
+}
+};
+Message message;
+static_assert(true, message);
+)cpp";
+  std::string fileName = "main.cpp";
+  WriteFile(fileName, testSource);
+  const char *Args[] = {"-xc++", "-std=c++26"};
+  ClangTU = clang_parseTranslationUnit(Index, fileName.c_str(), Args,
+   std::size(Args), nullptr, 0, TUFlags);
+  ASSERT_EQ(clang_getNumDiagnostics(ClangTU), 0);
+  std::optional staticAssertCsr;
+  Traverse([&](CXCursor cursor, CXCursor parent) -> CXChildVisitResult {
+if (cursor.kind == CXCursor_StaticAssert) {
+  staticAssertCsr.emplace(cursor);
+}
+return CXChildVisit_Continue;
+  });
+  ASSERT_TRUE(staticAssertCsr.has_value());
+  size_t argCnt = 0;
+  Traverse(*staticAssertCsr, [&argCnt](CXCursor cursor, CXCursor parent) {
+switch (argCnt) {
+case 0:
+  EXPECT_EQ(cursor.kind, CXCursor_CXXBoolLiteralExpr);
+  break;
+case 1:
+  EXPECT_EQ(cursor.kind, CXCursor_DeclRefExpr);
+  break;
+}
+++argCnt;
+return CXChildVisit_Continue;
+  });
+  ASSERT_EQ(argCnt, 2);
+  EXPECT_EQ(fromCXString(clang_getCursorSpelling(*staticAssertCsr)), "");
+}
+
 class LibclangRewriteTest : public LibclangParseTest {
 public:
   CXRewriter Rew = nullptr;

diff  --git a/clang/unittests/libclang/TestUtils.h 
b/clang/unittests/libclang/TestUtils.h
index c78351d4afd200..013aad17358211 100644
--- a/clang/unittests/libclang/TestUtils.h
+++ b/clang/unittests/libclang/TestUtils.h
@@ -87,14 +87,18 @@ class LibclangParseTest : public ::testing::Test {
 it.first->second->size()// length
 });
   }
-  template
-  void Traverse(const F &TraversalFunctor) {
-CXCursor TuCursor = clang_getTranslation

[clang] d0b54bb - [Clang] use unsigned integer constants in unit-test | fixes build error on ppc64le-lld-multistage-test

2023-07-25 Thread Corentin Jabot via cfe-commits

Author: Kai Stierand
Date: 2023-07-25T13:58:30+02:00
New Revision: d0b54bb50e5110a004b41fc06dadf3fee70834b7

URL: 
https://github.com/llvm/llvm-project/commit/d0b54bb50e5110a004b41fc06dadf3fee70834b7
DIFF: 
https://github.com/llvm/llvm-project/commit/d0b54bb50e5110a004b41fc06dadf3fee70834b7.diff

LOG: [Clang] use unsigned integer constants in unit-test | fixes build error on 
ppc64le-lld-multistage-test

Fixes:

/home/buildbots/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/third-party/unittest/googletest/include/gtest/gtest.h:1526:11:
 warning: comparison of integer expressions of different signedness: ‘const 
unsigned int’ and ‘const int’ [-Wsign-compare]

/home/buildbots/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/third-party/unittest/googletest/include/gtest/gtest.h:1526:11:
 warning: comparison of integer expressions of different signedness: ‘const 
long unsigned int’ and ‘const int’ [-Wsign-compare]

Reviewed By: cor3ntin

Differential Revision: https://reviews.llvm.org/D156224

Added: 


Modified: 
clang/unittests/libclang/LibclangTest.cpp

Removed: 




diff  --git a/clang/unittests/libclang/LibclangTest.cpp 
b/clang/unittests/libclang/LibclangTest.cpp
index b1f653441d0efe..295706c9e6ff8b 100644
--- a/clang/unittests/libclang/LibclangTest.cpp
+++ b/clang/unittests/libclang/LibclangTest.cpp
@@ -1220,7 +1220,7 @@ static_assert(true, message);
   const char *Args[] = {"-xc++", "-std=c++26"};
   ClangTU = clang_parseTranslationUnit(Index, fileName.c_str(), Args,
std::size(Args), nullptr, 0, TUFlags);
-  ASSERT_EQ(clang_getNumDiagnostics(ClangTU), 0);
+  ASSERT_EQ(clang_getNumDiagnostics(ClangTU), 0u);
   std::optional staticAssertCsr;
   Traverse([&](CXCursor cursor, CXCursor parent) -> CXChildVisitResult {
 if (cursor.kind == CXCursor_StaticAssert) {
@@ -1229,7 +1229,7 @@ static_assert(true, message);
 return CXChildVisit_Continue;
   });
   ASSERT_TRUE(staticAssertCsr.has_value());
-  size_t argCnt = 0;
+  int argCnt = 0;
   Traverse(*staticAssertCsr, [&argCnt](CXCursor cursor, CXCursor parent) {
 switch (argCnt) {
 case 0:



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


[clang] 98322d3 - Complete the implementation of P2361 Unevaluated string literals

2023-08-15 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-08-15T14:13:13+02:00
New Revision: 98322d3eb43168a6a64c1a15a1e754e15c04aa2f

URL: 
https://github.com/llvm/llvm-project/commit/98322d3eb43168a6a64c1a15a1e754e15c04aa2f
DIFF: 
https://github.com/llvm/llvm-project/commit/98322d3eb43168a6a64c1a15a1e754e15c04aa2f.diff

LOG: Complete the implementation of P2361 Unevaluated string literals

The attributes changes were left out of Clang 17.
Attributes that used to take a string literal now accept an unevaluated
string literal instead, which means they reject numeric escape sequences
and strings literal with an encoding prefix - but the later was already
ill-formed in most cases.

We need to know that we are going to parse an unevaluated string literal
before we do - so we can reject numeric escape sequence,
so we derive from Attrs.td which attributes parameters are expected
to be string literals.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D156237

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticCommonKinds.td
clang/include/clang/Parse/Parser.h
clang/include/clang/Sema/ParsedAttr.h
clang/lib/Parse/ParseDecl.cpp
clang/lib/Parse/ParseExpr.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/Parser/MicrosoftExtensions.cpp
clang/test/Parser/c2x-attributes.c
clang/test/Parser/cxx-attributes.cpp
clang/test/Parser/cxx0x-attributes.cpp
clang/test/Sema/MicrosoftExtensions.c
clang/test/Sema/annotate-type.c
clang/test/Sema/annotate.c
clang/test/Sema/attr-assume.c
clang/test/Sema/attr-btf_tag.c
clang/test/Sema/attr-btf_type_tag.c
clang/test/Sema/attr-capabilities.c
clang/test/Sema/attr-enforce-tcb-errors.cpp
clang/test/Sema/attr-enforce-tcb-errors.m
clang/test/Sema/attr-error.c
clang/test/Sema/attr-handles.cpp
clang/test/Sema/attr-section.c
clang/test/Sema/attr-tls_model.c
clang/test/Sema/attr-unavailable-message.c
clang/test/Sema/attr-warning.c
clang/test/Sema/diagnose_if.c
clang/test/Sema/enable_if.c
clang/test/SemaCXX/attr-deprecated-replacement-error.cpp
clang/test/SemaCXX/attr-no-sanitize.cpp
clang/test/SemaCXX/attr-section.cpp
clang/test/SemaCXX/attr-weakref.cpp
clang/test/SemaCXX/suppress.cpp
clang/test/SemaObjC/attr-swift_bridge.m
clang/test/SemaObjC/objc-asm-attribute-neg-test.m
clang/test/SemaObjC/validate-attr-swift_attr.m
clang/test/SemaTemplate/attributes.cpp
clang/utils/TableGen/ClangAttrEmitter.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index cd7beff546c932..56eef72c8a2835 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -85,6 +85,9 @@ C++2c Feature Support
   int _; // Previously diagnosed under -Wunused, no longer diagnosed
 }
 
+- Attributes now expect unevaluated strings in attributes parameters that are 
string literals.
+  This is applied to both C++ standard attributes, and other attributes 
supported by Clang.
+  This completes the implementation of `P2361R6 Unevaluated Strings 
_`
 
 
 Resolutions to C++ Defect Reports

diff  --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index 46a21d5da54026..195a61127c2a67 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -56,7 +56,9 @@ def err_expected_string_literal : Error<"expected string 
literal "
   "%select{in %1|for diagnostic message in static_assert|"
   "for optional message in 'availability' attribute|"
   "for %select{language name|source container name|USR}1 in "
-  "'external_source_symbol' attribute}0">;
+  "'external_source_symbol' attribute|"
+  "as argument of '%1' attribute}0">;
+
 def err_invalid_string_udl : Error<
   "string literal with user-defined suffix cannot be used here">;
 def err_invalid_character_udl : Error<

diff  --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 6312318d0ba983..c4dff165a13041 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -2790,6 +2790,13 @@ class Parser : public CodeCompletionHandler {
   /// clang accepts as an extension.
   void DiagnoseCXX11AttributeExtension(ParsedAttributes &Attrs);
 
+  ExprResult ParseUnevaluatedStringInAttribute(const IdentifierInfo &AttrName);
+
+  bool
+  ParseAttributeArgumentList(const clang::IdentifierInfo &AttrName,
+ SmallVectorImpl &Exprs,
+ ParsedAttributeArgumentsProperties 
ArgsProperties);
+
   /// Parses syntax-generic attribute arguments for attributes which are
   /// known to the implementation, and adds them to the given ParsedAttributes

[clang] 45ab2b4 - [Clang] Improve the handling of large arrays evaluation.

2023-07-28 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-07-28T14:38:22+02:00
New Revision: 45ab2b48bd55e50a86f6026ed31d2b60a118bdce

URL: 
https://github.com/llvm/llvm-project/commit/45ab2b48bd55e50a86f6026ed31d2b60a118bdce
DIFF: 
https://github.com/llvm/llvm-project/commit/45ab2b48bd55e50a86f6026ed31d2b60a118bdce.diff

LOG: [Clang] Improve the handling of large arrays evaluation.

This is a temporary fix (for clang 17) that caps the size of
any array we try to constant evaluate:

There are 2 limits:
  * We cap to UINT_MAX the size of ant constant evaluated array,
because the constant evaluator does not support size_t.
  * We cap to `-fconstexpr-steps` elements the size of each individual
array and dynamic array allocations.
This works out because the number of constexpr steps already limits
how many array elements can be initialized, which makes this new
limit conservatively generous.
This ensure that the compiler does not crash when attempting to
constant-fold valid programs.

If the limit is reached by a given array, constant evaluation will fail,
and the program will be ill-formed, until a bigger limit is given.
Or, constant folding will fail and the array will be evaluated at runtime.

Fixes #63562

Reviewed By: efriedma

Differential Revision: https://reviews.llvm.org/D155955

Added: 
clang/test/SemaCXX/cxx2a-constexpr-dynalloc-limits.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/docs/UsersManual.rst
clang/include/clang/AST/Type.h
clang/include/clang/Basic/DiagnosticASTKinds.td
clang/lib/AST/ExprConstant.cpp
clang/lib/AST/Type.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 98f50b428c2dc3..8ba3d22253a62b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -112,6 +112,11 @@ Bug Fixes to Attribute Support
 Bug Fixes to C++ Support
 
 
+- Clang limits the size of arrays it will try to evaluate at compile time
+  to avoid memory exhaustion.
+  This limit can be modified by `-fconstexpr-steps`.
+  (`#63562 `_)
+
 Bug Fixes to AST Handling
 ^
 

diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 14af07d35f5e1d..a774fd91aa277f 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -3348,7 +3348,9 @@ Controlling implementation limits
 .. option:: -fconstexpr-steps=N
 
   Sets the limit for the number of full-expressions evaluated in a single
-  constant expression evaluation.  The default is 1048576.
+  constant expression evaluation. This also controls the maximum size
+  of array and dynamic array allocation that can be constant evaluated.
+  The default is 1048576.
 
 .. option:: -ftemplate-depth=N
 

diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 8d20d088bb63c4..7526ec8906a32c 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -3144,6 +3144,8 @@ class ConstantArrayType final
QualType ElementType,
const llvm::APInt &NumElements);
 
+  unsigned getNumAddressingBits(const ASTContext &Context) const;
+
   /// Determine the maximum number of active bits that an array's size
   /// can require, which limits the maximum size of the array.
   static unsigned getMaxSizeBits(const ASTContext &Context);

diff  --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index 566cdc3406058f..f73a289f80ca95 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -351,6 +351,9 @@ def note_constexpr_new_negative : Note<
   "cannot allocate array; evaluated array bound %0 is negative">;
 def note_constexpr_new_too_large : Note<
   "cannot allocate array; evaluated array bound %0 is too large">;
+def note_constexpr_new_exceeds_limits : Note<
+  "cannot allocate array; evaluated array bound %0 exceeds the limit (%1); "
+  "use '-fconstexpr-steps' to increase this limit">;
 def note_constexpr_new_too_small : Note<
   "cannot allocate array; evaluated array bound %0 is too small to hold "
   "%1 explicitly initialized elements">;

diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index d9208b53e44994..c06ca3c405370e 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -1019,6 +1019,34 @@ namespace {
   return false;
 }
 
+bool CheckArraySize(SourceLocation Loc, unsigned BitWidth,
+uint64_t ElemCount, bool Diag) {
+  // FIXME: GH63562
+  // APValue stores array extents as unsigned,
+  // so anything that is greater that unsigned would overflow when
+  // constructing the

[clang] cdfb3d9 - [Clang] Fix constexpr alloc tests on 32 bits platforms

2023-07-28 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-07-28T16:22:26+02:00
New Revision: cdfb3d93e394a6f03082558e3c6abbe71bb1df6f

URL: 
https://github.com/llvm/llvm-project/commit/cdfb3d93e394a6f03082558e3c6abbe71bb1df6f
DIFF: 
https://github.com/llvm/llvm-project/commit/cdfb3d93e394a6f03082558e3c6abbe71bb1df6f.diff

LOG: [Clang] Fix constexpr alloc tests on 32 bits platforms

Some bots were broken by 45ab2b48bd55

Differential Revision: https://reviews.llvm.org/D156542

Added: 


Modified: 
clang/test/SemaCXX/cxx2a-constexpr-dynalloc-limits.cpp

Removed: 




diff  --git a/clang/test/SemaCXX/cxx2a-constexpr-dynalloc-limits.cpp 
b/clang/test/SemaCXX/cxx2a-constexpr-dynalloc-limits.cpp
index 0d26eca38ddcc5..a85d44f40926fb 100644
--- a/clang/test/SemaCXX/cxx2a-constexpr-dynalloc-limits.cpp
+++ b/clang/test/SemaCXX/cxx2a-constexpr-dynalloc-limits.cpp
@@ -42,12 +42,15 @@ struct S {
 T* data;
 };
 
-constexpr std::size_t s = S(109951162)[42]; // expected-error 
{{constexpr variable 's' must be initialized by a constant expression}} \
-   // expected-note@#call {{in call to 
'this->alloc.allocate(109951162)'}} \
-   // expected-note@#alloc {{cannot 
allocate array; evaluated array bound 109951162 is too large}} \
-   // expected-note {{in call to 
'S(109951162)'}}
+// Only run these tests on 64 bits platforms
+#if __LP64__
+constexpr std::size_t s = S(~0UL)[42]; // expected-error 
{{constexpr variable 's' must be initialized by a constant expression}} \
+   // expected-note-re@#call {{in call 
to 'this->alloc.allocate({{.*}})'}} \
+   // expected-note-re@#alloc {{cannot 
allocate array; evaluated array bound {{.*}} is too large}} \
+   // expected-note-re {{in call to 
'S({{.*}})'}}
+#endif
 // Check that we do not try to fold very large arrays
-std::size_t s2 = S(109951162)[42];
+std::size_t s2 = S(~0UL)[42];
 std::size_t s3 = S(~0ULL)[42];
 
 // We can allocate and initialize a small array



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


[clang] 4d494e7 - [Clang] Handle static_assert messages with an expression started by a literal

2023-08-01 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-08-01T10:16:02+02:00
New Revision: 4d494e76d098fde0a3399f792f360c111e546ae8

URL: 
https://github.com/llvm/llvm-project/commit/4d494e76d098fde0a3399f792f360c111e546ae8
DIFF: 
https://github.com/llvm/llvm-project/commit/4d494e76d098fde0a3399f792f360c111e546ae8.diff

LOG: [Clang] Handle static_assert messages with an expression started by a 
literal

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D156597

Added: 


Modified: 
clang/lib/Parse/ParseDeclCXX.cpp
clang/test/SemaCXX/static-assert-cxx26.cpp

Removed: 




diff  --git a/clang/lib/Parse/ParseDeclCXX.cpp 
b/clang/lib/Parse/ParseDeclCXX.cpp
index c1e09db2b3eeff..e4a10f2e5c98d0 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -1016,10 +1016,23 @@ Decl 
*Parser::ParseStaticAssertDeclaration(SourceLocation &DeclEnd) {
   return nullptr;
 }
 
-if (isTokenStringLiteral())
-  AssertMessage = ParseUnevaluatedStringLiteralExpression();
-else if (getLangOpts().CPlusPlus26)
+bool ParseAsExpression = false;
+if (getLangOpts().CPlusPlus26) {
+  for (unsigned I = 0;; ++I) {
+const Token &T = GetLookAheadToken(I);
+if (T.is(tok::r_paren))
+  break;
+if (T.isNot(tok::string_literal)) {
+  ParseAsExpression = true;
+  break;
+}
+  }
+}
+
+if (ParseAsExpression)
   AssertMessage = ParseConstantExpressionInExprEvalContext();
+else if (isTokenStringLiteral())
+  AssertMessage = ParseUnevaluatedStringLiteralExpression();
 else {
   Diag(Tok, diag::err_expected_string_literal)
   << /*Source='static_assert'*/ 1;

diff  --git a/clang/test/SemaCXX/static-assert-cxx26.cpp 
b/clang/test/SemaCXX/static-assert-cxx26.cpp
index 4c28fba1ca5fc3..c2bb2d2ebc6ffb 100644
--- a/clang/test/SemaCXX/static-assert-cxx26.cpp
+++ b/clang/test/SemaCXX/static-assert-cxx26.cpp
@@ -65,6 +65,10 @@ struct string_view {
 }
 };
 
+constexpr string_view operator+(auto, string_view S) {
+return S;
+}
+
 constexpr const char g_[] = "long string";
 
 template 
@@ -79,6 +83,11 @@ struct array {
 };
 
 static_assert(false, string_view("test")); // expected-error {{static 
assertion failed: test}}
+static_assert(false, "Literal" + string_view("test")); // expected-error 
{{static assertion failed: test}}
+static_assert(false, L"Wide Literal" + string_view("test")); // expected-error 
{{static assertion failed: test}}
+static_assert(false, "Wild" "Literal" "Concatenation" + string_view("test")); 
// expected-error {{static assertion failed: test}}
+static_assert(false, "Wild" "Literal" L"Concatenation" + string_view("test")); 
// expected-error {{static assertion failed: test}}
+static_assert(false, "Wild" u"Literal" L"Concatenation" + 
string_view("test")); // expected-error {{unsupported non-standard 
concatenation of string literals}}
 static_assert(false, string_view("😀")); // expected-error {{static assertion 
failed: 😀}}
 static_assert(false, string_view(0, nullptr)); // expected-error {{static 
assertion failed:}}
 static_assert(false, string_view(1, "ABC")); // expected-error {{static 
assertion failed: A}}



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


[clang] a8bef88 - [Clang] Implement P2169 A nice placeholder with no name

2023-08-04 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-08-04T16:51:15+02:00
New Revision: a8bef8865e4a4226ee608df327fddd380870c620

URL: 
https://github.com/llvm/llvm-project/commit/a8bef8865e4a4226ee608df327fddd380870c620
DIFF: 
https://github.com/llvm/llvm-project/commit/a8bef8865e4a4226ee608df327fddd380870c620.diff

LOG: [Clang] Implement P2169 A nice placeholder with no name

This is a C++ feature that allows the use of `_` to
declare multiple variable of that name in the same scope;
these variables can then not be referred to.

In addition, while P2169 does not extend to parameter
declarations, we stop warning on unused parameters of that name,
for consistency.

The feature is backported to all C++ language modes.

Reviewed By: #clang-language-wg, aaron.ballman

Differential Revision: https://reviews.llvm.org/D153536

Added: 
clang/test/SemaCXX/cxx2c-placeholder-vars.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/Decl.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/IdentifierTable.h
clang/include/clang/Sema/Lookup.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/Decl.cpp
clang/lib/Frontend/InitPreprocessor.cpp
clang/lib/Parse/ParseDecl.cpp
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Parse/ParseTemplate.cpp
clang/lib/Parse/Parser.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaInit.cpp
clang/lib/Sema/SemaLambda.cpp
clang/lib/Sema/SemaLookup.cpp
clang/test/Lexer/cxx-features.cpp
clang/test/Lexer/unicode.c
clang/test/SemaCXX/anonymous-union-export.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a98ad496d22498..46a7aff15da9dc 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -66,6 +66,26 @@ C++23 Feature Support
 C++2c Feature Support
 ^
 
+- Implemented `P2169R4: A nice placeholder with no name 
`_. This allows using ``_``
+  as a variable name multiple times in the same scope and is supported in all 
C++ language modes as an extension.
+  An extension warning is produced when multiple variables are introduced by 
``_`` in the same scope.
+  Unused warnings are no longer produced for variables named ``_``.
+  Currently, inspecting placeholders variables in a debugger when more than 
one are declared in the same scope
+  is not supported.
+
+  .. code-block:: cpp
+struct S {
+  int _, _; // Was invalid, now OK
+};
+void func() {
+  int _, _; // Was invalid, now OK
+}
+void other() {
+  int _; // Previously diagnosed under -Wunused, no longer diagnosed
+}
+
+
+
 Resolutions to C++ Defect Reports
 ^
 

diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 788f6ab97b1bbf..f6e38e5c57440d 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -452,6 +452,8 @@ class NamedDecl : public Decl {
 return hasCachedLinkage();
   }
 
+  bool isPlaceholderVar(const LangOptions &LangOpts) const;
+
   /// Looks through UsingDecls and ObjCCompatibleAliasDecls for
   /// the underlying named decl.
   NamedDecl *getUnderlyingDecl() {

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index b531babf0449c4..4979f9f86d236d 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6611,6 +6611,16 @@ def warn_atomic_member_access : Warning<
   InGroup>, DefaultError;
 
 // Expressions.
+def err_using_placeholder_variable : Error<
+  "ambiguous reference to placeholder '_', which is defined multiple times">;
+def note_reference_placeholder : Note<
+  "placeholder declared here">;
+def ext_placeholder_var_definition : ExtWarn<
+  "placeholder variables are a C++2c extension">, InGroup;
+def warn_cxx23_placeholder_var_definition : Warning<
+  "placeholder variables are incompatible with C++ standards before C++2c">,
+  DefaultIgnore, InGroup;
+
 def ext_sizeof_alignof_function_type : Extension<
   "invalid application of '%0' to a function type">, InGroup;
 def ext_sizeof_alignof_void_type : Extension<

diff  --git a/clang/include/clang/Basic/IdentifierTable.h 
b/clang/include/clang/Basic/IdentifierTable.h
index f87f7671481579..1a1ffddf2b1c60 100644
--- a/clang/include/clang/Basic/IdentifierTable.h
+++ b/clang/include/clang/Basic/IdentifierTable.h
@@ -504,6 +504,9 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
   /// If the identifier is an "uglified" reserved name, return a cleaned form.
   /// e.g. _Foo => Foo. Otherwise, just returns the name.
   StringRef deuglifiedName() const;
+  bool isPlaceholder() const {
+return getLength() == 1 && getNameStart(

[clang] 20e0116 - [Clang] Produce a warning instead of an error in unevaluated strings before C++26

2023-08-09 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-08-10T08:32:42+02:00
New Revision: 20e01167b15aa17dac09e4742909a7138eca7afc

URL: 
https://github.com/llvm/llvm-project/commit/20e01167b15aa17dac09e4742909a7138eca7afc
DIFF: 
https://github.com/llvm/llvm-project/commit/20e01167b15aa17dac09e4742909a7138eca7afc.diff

LOG: [Clang] Produce a warning instead of an error in unevaluated strings 
before C++26

Reviewed By: aaron.ballman, hubert.reinterpretcast

Differential Revision: https://reviews.llvm.org/D156596

Added: 
clang/test/FixIt/unevaluated-strings.cpp

Modified: 
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/lib/Lex/LiteralSupport.cpp
clang/test/CXX/dcl.dcl/dcl.link/p2.cpp
clang/test/CXX/dcl.dcl/p4-0x.cpp
clang/test/Sema/static-assert.c
clang/test/SemaCXX/static-assert.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index 0eb270aeea0e5d..6ad691975bd587 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -285,6 +285,10 @@ def ext_ms_reserved_user_defined_literal : ExtWarn<
 def err_unsupported_string_concat : Error<
   "unsupported non-standard concatenation of string literals">;
 
+def warn_unevaluated_string_prefix : Warning<
+  "encoding prefix '%0' on an unevaluated string literal has no effect"
+  "%select{| and is incompatible with c++2c}1">,
+  InGroup>;
 def err_unevaluated_string_prefix : Error<
   "an unevaluated string literal cannot have an encoding prefix">;
 def err_unevaluated_string_udl : Error<

diff  --git a/clang/lib/Lex/LiteralSupport.cpp 
b/clang/lib/Lex/LiteralSupport.cpp
index 21711fcfb5d08a..888ea772ee6011 100644
--- a/clang/lib/Lex/LiteralSupport.cpp
+++ b/clang/lib/Lex/LiteralSupport.cpp
@@ -57,6 +57,26 @@ static unsigned getCharWidth(tok::TokenKind kind, const 
TargetInfo &Target) {
   }
 }
 
+static unsigned getEncodingPrefixLen(tok::TokenKind kind) {
+  switch (kind) {
+  default:
+llvm_unreachable("Unknown token type!");
+  case tok::char_constant:
+  case tok::string_literal:
+return 0;
+  case tok::utf8_char_constant:
+  case tok::utf8_string_literal:
+return 2;
+  case tok::wide_char_constant:
+  case tok::wide_string_literal:
+  case tok::utf16_char_constant:
+  case tok::utf16_string_literal:
+  case tok::utf32_char_constant:
+  case tok::utf32_string_literal:
+return 1;
+  }
+}
+
 static CharSourceRange MakeCharSourceRange(const LangOptions &Features,
FullSourceLoc TokLoc,
const char *TokBegin,
@@ -343,7 +363,9 @@ static unsigned ProcessCharEscape(const char *ThisTokBegin,
 Diag(Diags, Features, Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
  diag::err_unevaluated_string_invalid_escape_sequence)
 << StringRef(EscapeBegin, ThisTokBuf - EscapeBegin);
+HadError = true;
   }
+
   return ResultChar;
 }
 
@@ -1930,9 +1952,22 @@ void StringLiteralParser::init(ArrayRef 
StringToks){
 // Remember if we see any wide or utf-8/16/32 strings.
 // Also check for illegal concatenations.
 if (isUnevaluated() && Tok.getKind() != tok::string_literal) {
-  if (Diags)
-Diags->Report(Tok.getLocation(), diag::err_unevaluated_string_prefix);
-  hadError = true;
+  if (Diags) {
+SourceLocation PrefixEndLoc = Lexer::AdvanceToTokenCharacter(
+Tok.getLocation(), getEncodingPrefixLen(Tok.getKind()), SM,
+Features);
+CharSourceRange Range =
+CharSourceRange::getCharRange({Tok.getLocation(), PrefixEndLoc});
+StringRef Prefix(SM.getCharacterData(Tok.getLocation()),
+ getEncodingPrefixLen(Tok.getKind()));
+Diags->Report(Tok.getLocation(),
+  Features.CPlusPlus26
+  ? diag::err_unevaluated_string_prefix
+  : diag::warn_unevaluated_string_prefix)
+<< Prefix << Features.CPlusPlus << FixItHint::CreateRemoval(Range);
+  }
+  if (Features.CPlusPlus26)
+hadError = true;
 } else if (Tok.isNot(Kind) && Tok.isNot(tok::string_literal)) {
   if (isOrdinary()) {
 Kind = Tok.getKind();

diff  --git a/clang/test/CXX/dcl.dcl/dcl.link/p2.cpp 
b/clang/test/CXX/dcl.dcl/dcl.link/p2.cpp
index 206c46f34f05b2..234db01a001fbf 100644
--- a/clang/test/CXX/dcl.dcl/dcl.link/p2.cpp
+++ b/clang/test/CXX/dcl.dcl/dcl.link/p2.cpp
@@ -8,7 +8,7 @@ extern "C" {
 extern "C" plusplus {
 }
 
-extern u8"C" {}  // expected-error {{an unevaluated string literal cannot have 
an encoding prefix}}
-extern L"C" {}   // expected-error {{an unevaluated string literal cannot have 
an encoding prefix}}
-extern u"C++" {} // expected-error {{an unevaluated string literal cannot have 
an encoding prefix}}
-extern U"C" {}   // expected-error {{an

[clang] ab4e4a6 - Revert "[Clang] Produce a warning instead of an error in unevaluated strings before C++26"

2023-08-09 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-08-10T08:47:57+02:00
New Revision: ab4e4a69854dd348014495921a6b3648f1ee1895

URL: 
https://github.com/llvm/llvm-project/commit/ab4e4a69854dd348014495921a6b3648f1ee1895
DIFF: 
https://github.com/llvm/llvm-project/commit/ab4e4a69854dd348014495921a6b3648f1ee1895.diff

LOG: Revert "[Clang] Produce a warning instead of an error in unevaluated 
strings before C++26"

Causes build failure on bots after rebase.

This reverts commit 20e01167b15aa17dac09e4742909a7138eca7afc.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/lib/Lex/LiteralSupport.cpp
clang/test/CXX/dcl.dcl/dcl.link/p2.cpp
clang/test/CXX/dcl.dcl/p4-0x.cpp
clang/test/Sema/static-assert.c
clang/test/SemaCXX/static-assert.cpp

Removed: 
clang/test/FixIt/unevaluated-strings.cpp



diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index 6ad691975bd587..0eb270aeea0e5d 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -285,10 +285,6 @@ def ext_ms_reserved_user_defined_literal : ExtWarn<
 def err_unsupported_string_concat : Error<
   "unsupported non-standard concatenation of string literals">;
 
-def warn_unevaluated_string_prefix : Warning<
-  "encoding prefix '%0' on an unevaluated string literal has no effect"
-  "%select{| and is incompatible with c++2c}1">,
-  InGroup>;
 def err_unevaluated_string_prefix : Error<
   "an unevaluated string literal cannot have an encoding prefix">;
 def err_unevaluated_string_udl : Error<

diff  --git a/clang/lib/Lex/LiteralSupport.cpp 
b/clang/lib/Lex/LiteralSupport.cpp
index 888ea772ee6011..21711fcfb5d08a 100644
--- a/clang/lib/Lex/LiteralSupport.cpp
+++ b/clang/lib/Lex/LiteralSupport.cpp
@@ -57,26 +57,6 @@ static unsigned getCharWidth(tok::TokenKind kind, const 
TargetInfo &Target) {
   }
 }
 
-static unsigned getEncodingPrefixLen(tok::TokenKind kind) {
-  switch (kind) {
-  default:
-llvm_unreachable("Unknown token type!");
-  case tok::char_constant:
-  case tok::string_literal:
-return 0;
-  case tok::utf8_char_constant:
-  case tok::utf8_string_literal:
-return 2;
-  case tok::wide_char_constant:
-  case tok::wide_string_literal:
-  case tok::utf16_char_constant:
-  case tok::utf16_string_literal:
-  case tok::utf32_char_constant:
-  case tok::utf32_string_literal:
-return 1;
-  }
-}
-
 static CharSourceRange MakeCharSourceRange(const LangOptions &Features,
FullSourceLoc TokLoc,
const char *TokBegin,
@@ -363,9 +343,7 @@ static unsigned ProcessCharEscape(const char *ThisTokBegin,
 Diag(Diags, Features, Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
  diag::err_unevaluated_string_invalid_escape_sequence)
 << StringRef(EscapeBegin, ThisTokBuf - EscapeBegin);
-HadError = true;
   }
-
   return ResultChar;
 }
 
@@ -1952,22 +1930,9 @@ void StringLiteralParser::init(ArrayRef 
StringToks){
 // Remember if we see any wide or utf-8/16/32 strings.
 // Also check for illegal concatenations.
 if (isUnevaluated() && Tok.getKind() != tok::string_literal) {
-  if (Diags) {
-SourceLocation PrefixEndLoc = Lexer::AdvanceToTokenCharacter(
-Tok.getLocation(), getEncodingPrefixLen(Tok.getKind()), SM,
-Features);
-CharSourceRange Range =
-CharSourceRange::getCharRange({Tok.getLocation(), PrefixEndLoc});
-StringRef Prefix(SM.getCharacterData(Tok.getLocation()),
- getEncodingPrefixLen(Tok.getKind()));
-Diags->Report(Tok.getLocation(),
-  Features.CPlusPlus26
-  ? diag::err_unevaluated_string_prefix
-  : diag::warn_unevaluated_string_prefix)
-<< Prefix << Features.CPlusPlus << FixItHint::CreateRemoval(Range);
-  }
-  if (Features.CPlusPlus26)
-hadError = true;
+  if (Diags)
+Diags->Report(Tok.getLocation(), diag::err_unevaluated_string_prefix);
+  hadError = true;
 } else if (Tok.isNot(Kind) && Tok.isNot(tok::string_literal)) {
   if (isOrdinary()) {
 Kind = Tok.getKind();

diff  --git a/clang/test/CXX/dcl.dcl/dcl.link/p2.cpp 
b/clang/test/CXX/dcl.dcl/dcl.link/p2.cpp
index 234db01a001fbf..206c46f34f05b2 100644
--- a/clang/test/CXX/dcl.dcl/dcl.link/p2.cpp
+++ b/clang/test/CXX/dcl.dcl/dcl.link/p2.cpp
@@ -8,7 +8,7 @@ extern "C" {
 extern "C" plusplus {
 }
 
-extern u8"C" {}  // expected-warning {{encoding prefix 'u8' on an unevaluated 
string literal has no effect and is incompatible with c++2c}}
-extern L"C" {}   // expected-warning {{encoding prefix 'L' on an unevaluated 
string literal has no effect and is incompatible with c++2c}}
-extern u"C++" {} // expected-warning {{encoding prefix 

[clang] 49e0495 - [Clang] Produce a warning instead of an error in unevaluated strings before C++26

2023-08-10 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-08-10T09:43:20+02:00
New Revision: 49e0495febec5b88dcbc3c0a8814441e207bd608

URL: 
https://github.com/llvm/llvm-project/commit/49e0495febec5b88dcbc3c0a8814441e207bd608
DIFF: 
https://github.com/llvm/llvm-project/commit/49e0495febec5b88dcbc3c0a8814441e207bd608.diff

LOG: [Clang] Produce a warning instead of an error in unevaluated strings 
before C++26

Emiting an error on unexpected encoding prefix - which was allowed before C++26 
-
caused build errors for a few users.
This downgrade the error to a warning on older language modes and C.

Reviewed By: aaron.ballman, hubert.reinterpretcast

Differential Revision: https://reviews.llvm.org/D156596

Added: 
clang/test/FixIt/unevaluated-strings.cpp

Modified: 
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/lib/Lex/LiteralSupport.cpp
clang/lib/Parse/ParseDeclCXX.cpp
clang/test/CXX/dcl.dcl/dcl.link/p2.cpp
clang/test/CXX/dcl.dcl/p4-0x.cpp
clang/test/Sema/static-assert.c
clang/test/SemaCXX/static-assert.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index 0eb270aeea0e5d..6ad691975bd587 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -285,6 +285,10 @@ def ext_ms_reserved_user_defined_literal : ExtWarn<
 def err_unsupported_string_concat : Error<
   "unsupported non-standard concatenation of string literals">;
 
+def warn_unevaluated_string_prefix : Warning<
+  "encoding prefix '%0' on an unevaluated string literal has no effect"
+  "%select{| and is incompatible with c++2c}1">,
+  InGroup>;
 def err_unevaluated_string_prefix : Error<
   "an unevaluated string literal cannot have an encoding prefix">;
 def err_unevaluated_string_udl : Error<

diff  --git a/clang/lib/Lex/LiteralSupport.cpp 
b/clang/lib/Lex/LiteralSupport.cpp
index 21711fcfb5d08a..888ea772ee6011 100644
--- a/clang/lib/Lex/LiteralSupport.cpp
+++ b/clang/lib/Lex/LiteralSupport.cpp
@@ -57,6 +57,26 @@ static unsigned getCharWidth(tok::TokenKind kind, const 
TargetInfo &Target) {
   }
 }
 
+static unsigned getEncodingPrefixLen(tok::TokenKind kind) {
+  switch (kind) {
+  default:
+llvm_unreachable("Unknown token type!");
+  case tok::char_constant:
+  case tok::string_literal:
+return 0;
+  case tok::utf8_char_constant:
+  case tok::utf8_string_literal:
+return 2;
+  case tok::wide_char_constant:
+  case tok::wide_string_literal:
+  case tok::utf16_char_constant:
+  case tok::utf16_string_literal:
+  case tok::utf32_char_constant:
+  case tok::utf32_string_literal:
+return 1;
+  }
+}
+
 static CharSourceRange MakeCharSourceRange(const LangOptions &Features,
FullSourceLoc TokLoc,
const char *TokBegin,
@@ -343,7 +363,9 @@ static unsigned ProcessCharEscape(const char *ThisTokBegin,
 Diag(Diags, Features, Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
  diag::err_unevaluated_string_invalid_escape_sequence)
 << StringRef(EscapeBegin, ThisTokBuf - EscapeBegin);
+HadError = true;
   }
+
   return ResultChar;
 }
 
@@ -1930,9 +1952,22 @@ void StringLiteralParser::init(ArrayRef 
StringToks){
 // Remember if we see any wide or utf-8/16/32 strings.
 // Also check for illegal concatenations.
 if (isUnevaluated() && Tok.getKind() != tok::string_literal) {
-  if (Diags)
-Diags->Report(Tok.getLocation(), diag::err_unevaluated_string_prefix);
-  hadError = true;
+  if (Diags) {
+SourceLocation PrefixEndLoc = Lexer::AdvanceToTokenCharacter(
+Tok.getLocation(), getEncodingPrefixLen(Tok.getKind()), SM,
+Features);
+CharSourceRange Range =
+CharSourceRange::getCharRange({Tok.getLocation(), PrefixEndLoc});
+StringRef Prefix(SM.getCharacterData(Tok.getLocation()),
+ getEncodingPrefixLen(Tok.getKind()));
+Diags->Report(Tok.getLocation(),
+  Features.CPlusPlus26
+  ? diag::err_unevaluated_string_prefix
+  : diag::warn_unevaluated_string_prefix)
+<< Prefix << Features.CPlusPlus << FixItHint::CreateRemoval(Range);
+  }
+  if (Features.CPlusPlus26)
+hadError = true;
 } else if (Tok.isNot(Kind) && Tok.isNot(tok::string_literal)) {
   if (isOrdinary()) {
 Kind = Tok.getKind();

diff  --git a/clang/lib/Parse/ParseDeclCXX.cpp 
b/clang/lib/Parse/ParseDeclCXX.cpp
index f1f091fddc13c6..39873bf8bd6b7b 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -1023,7 +1023,7 @@ Decl *Parser::ParseStaticAssertDeclaration(SourceLocation 
&DeclEnd) {
 const Token &T = GetLookAheadToken(I);
 if (T.is(tok::r_paren))
   break;
-   

[clang] 3ed9e9e - [Clang] Add captures to the instantiation scope of lambda call operators

2023-09-08 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-09-08T17:50:27+02:00
New Revision: 3ed9e9e3ace6f9ce320cf4e75cffa04a7c7241b5

URL: 
https://github.com/llvm/llvm-project/commit/3ed9e9e3ace6f9ce320cf4e75cffa04a7c7241b5
DIFF: 
https://github.com/llvm/llvm-project/commit/3ed9e9e3ace6f9ce320cf4e75cffa04a7c7241b5.diff

LOG: [Clang] Add captures to the instantiation scope of lambda call operators

Like concepts checking, a trailing return type of a lambda
in a dependent context may refer to captures in which case
they may need to be rebuilt, so the map of local decl
should include captures.

This patch reveal a pre-existing issue.
`this` is always recomputed by TreeTransform.

`*this` (like all captures) only become `const`
after the parameter list.

However, if try to recompute the value of `this` (in a parameter)
during template instantiation while determining the type of the call operator,
we will determine  it to be const (unless the lambda is mutable).

There is no good way to know at that point that we are in a parameter
or not, the easiest/best solution is to transform the type of this.

Note that doing so break a handful of HLSL tests.
So this is a prototype at this point.

Fixes #65067
Fixes #63675

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D159126

Added: 
clang/test/SemaCXX/this-type-deduction-concept.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaConcept.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaLambda.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/lib/Sema/TreeTransform.h
clang/test/SemaCXX/lambda-capture-type-deduction.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2d0302c399fb6f3..6a3a6bb8ad425b0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -270,6 +270,11 @@ Bug Fixes to C++ Support
 - Fix crash when parsing the requires clause of some generic lambdas.
   (`#64689 `_)
 
+- Fix crash when the trailing return type of a generic and dependent
+  lambda refers to an init-capture.
+  (`#65067 `_` and
+   `#63675 `_`)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 1bb096c667e39c3..566655818a85baf 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -7365,6 +7365,14 @@ class Sema final {
 
   sema::LambdaScopeInfo *RebuildLambdaScopeInfo(CXXMethodDecl *CallOperator);
 
+  class LambdaScopeForCallOperatorInstantiationRAII
+  : private FunctionScopeRAII {
+  public:
+LambdaScopeForCallOperatorInstantiationRAII(
+Sema &SemasRef, FunctionDecl *FD, MultiLevelTemplateArgumentList MLTAL,
+LocalInstantiationScope &Scope);
+  };
+
   /// Check whether the given expression is a valid constraint expression.
   /// A diagnostic is emitted if it is not, false is returned, and
   /// PossibleNonPrimary will be set to true if the failure might be due to a

diff  --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index fa3dadf68229ee8..d1fa8e7831225b7 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -600,11 +600,6 @@ bool Sema::SetupConstraintScope(
   if (addInstantiatedParametersToScope(FD, 
FromMemTempl->getTemplatedDecl(),
Scope, MLTAL))
 return true;
-  // Make sure the captures are also added to the instantiation scope.
-  if (isLambdaCallOperator(FD) &&
-  addInstantiatedCapturesToScope(FD, FromMemTempl->getTemplatedDecl(),
- Scope, MLTAL))
-return true;
 }
 
 return false;
@@ -629,11 +624,6 @@ bool Sema::SetupConstraintScope(
 // child-function.
 if (addInstantiatedParametersToScope(FD, InstantiatedFrom, Scope, MLTAL))
   return true;
-
-// Make sure the captures are also added to the instantiation scope.
-if (isLambdaCallOperator(FD) &&
-addInstantiatedCapturesToScope(FD, InstantiatedFrom, Scope, MLTAL))
-  return true;
   }
 
   return false;
@@ -712,20 +702,8 @@ bool Sema::CheckFunctionConstraints(const FunctionDecl *FD,
   }
   CXXThisScopeRAII ThisScope(*this, Record, ThisQuals, Record != nullptr);
 
-  // When checking the constraints of a lambda, we need to restore a
-  // LambdaScopeInfo populated with correct capture information so that the 
type
-  // of a variable referring to a capture is correctly const-adjusted.
-  FunctionScopeRAII FuncScope(*this);
-  if (isLambdaCallOperator(FD)) {
-LambdaScopeInfo *LSI = RebuildLambdaScopeInfo(
-

[clang] 1bc7f3f - [Clang] Fix a crash when trying to initialize an invalid aggregate.

2023-07-05 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-07-05T15:45:46+02:00
New Revision: 1bc7f3fb936724dd7a2d0b5ac91f773d3168a5f0

URL: 
https://github.com/llvm/llvm-project/commit/1bc7f3fb936724dd7a2d0b5ac91f773d3168a5f0
DIFF: 
https://github.com/llvm/llvm-project/commit/1bc7f3fb936724dd7a2d0b5ac91f773d3168a5f0.diff

LOG: [Clang] Fix a crash when trying to initialize an invalid aggregate.

We did not return an error when failing to producing
a valid expression when performing the initialization of
an aggregate initialized with a parenthesized list of expressions.

This is a regression introduced in Clang 17.

Fixes #63278

Reviewed By: aaron.ballman, #clang-language-wg

Differential Revision: https://reviews.llvm.org/D154486

Added: 


Modified: 
clang/lib/Sema/SemaInit.cpp
clang/test/SemaCXX/paren-list-agg-init.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index b893d358dfe790..6db211a20e311f 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -9387,10 +9387,13 @@ ExprResult InitializationSequence::Perform(Sema &S,
 }
   }
 
+  Expr *Init = CurInit.get();
+  if (!Init)
+return ExprError();
+
   // Check whether the initializer has a shorter lifetime than the initialized
   // entity, and if not, either lifetime-extend or warn as appropriate.
-  if (auto *Init = CurInit.get())
-S.checkInitializerLifetime(Entity, Init);
+  S.checkInitializerLifetime(Entity, Init);
 
   // Diagnose non-fatal problems with the completed initialization.
   if (InitializedEntity::EntityKind EK = Entity.getKind();
@@ -9398,16 +9401,13 @@ ExprResult InitializationSequence::Perform(Sema &S,
EK == InitializedEntity::EK_ParenAggInitMember) &&
   cast(Entity.getDecl())->isBitField())
 S.CheckBitFieldInitialization(Kind.getLocation(),
-  cast(Entity.getDecl()),
-  CurInit.get());
+  cast(Entity.getDecl()), Init);
 
   // Check for std::move on construction.
-  if (const Expr *E = CurInit.get()) {
-CheckMoveOnConstruction(S, E,
-Entity.getKind() == InitializedEntity::EK_Result);
-  }
+  CheckMoveOnConstruction(S, Init,
+  Entity.getKind() == InitializedEntity::EK_Result);
 
-  return CurInit;
+  return Init;
 }
 
 /// Somewhere within T there is an uninitialized reference subobject.

diff  --git a/clang/test/SemaCXX/paren-list-agg-init.cpp 
b/clang/test/SemaCXX/paren-list-agg-init.cpp
index 042ce3b3ddce2c..88d9b95c0e4be4 100644
--- a/clang/test/SemaCXX/paren-list-agg-init.cpp
+++ b/clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -272,3 +272,25 @@ auto a = new A('a', {1.1});
 // expected-warning@-1 {{braces around scalar init}}
 // beforecxx20-warning@-2 {{aggregate initialization of type 'A' from a 
parenthesized list of values is a C++20 extension}}
 }
+
+
+namespace GH63278 {
+struct S {
+  int a = 0;
+  int b {0};
+  auto x = 1; // expected-error {{'auto' not allowed in non-static struct 
member}}
+  static const auto y = 1;
+};
+
+int test() {
+  // used to crash
+  S a(0, 1);
+  S b(0);
+  S c(0, 0, 1); // beforecxx20-warning {{aggregate initialization of type 'S' 
from a parenthesized list of values is a C++20 extension}}
+
+  S d {0, 1};
+  S e {0};
+  S f {0, 0, 1};
+}
+
+}



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


[clang] 1077a34 - [Clang] Fix handling of using declarations in for loop init statements.

2023-07-05 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-07-05T16:20:53+02:00
New Revision: 1077a343911127452615c6f5441c121de06be6d5

URL: 
https://github.com/llvm/llvm-project/commit/1077a343911127452615c6f5441c121de06be6d5
DIFF: 
https://github.com/llvm/llvm-project/commit/1077a343911127452615c6f5441c121de06be6d5.diff

LOG: [Clang] Fix handling of using declarations in for loop init statements.

The type was never saved, and therefore never transformed
in dependent contexts.

Reviewed By: aaron.ballman, #clang-language-wg

Differential Revision: https://reviews.llvm.org/D154492

Added: 
clang/test/SemaCXX/cxx23-init-statement.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Parse/ParseStmt.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 022d51b525c04c..79550f79cc36b5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -635,6 +635,9 @@ Bug Fixes to C++ Support
 - Allow abstract parameter and return types in functions that are
   either deleted or not defined.
   (`#63012 `_)
+- Fix handling of using-declarations in the init statements of for
+  loop declarations.
+  (`#63627 `_)
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp
index 43ff808e296b54..2346470dbdb73d 100644
--- a/clang/lib/Parse/ParseStmt.cpp
+++ b/clang/lib/Parse/ParseStmt.cpp
@@ -2054,15 +2054,15 @@ StmtResult Parser::ParseForStatement(SourceLocation 
*TrailingElseLoc) {
   Diag(Tok, diag::warn_gcc_variable_decl_in_for_loop);
 }
 DeclGroupPtrTy DG;
+SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
 if (Tok.is(tok::kw_using)) {
   DG = ParseAliasDeclarationInInitStatement(DeclaratorContext::ForInit,
 attrs);
+  FirstPart = Actions.ActOnDeclStmt(DG, DeclStart, Tok.getLocation());
 } else {
   // In C++0x, "for (T NS:a" might not be a typo for ::
   bool MightBeForRangeStmt = getLangOpts().CPlusPlus;
   ColonProtectionRAIIObject ColonProtection(*this, MightBeForRangeStmt);
-
-  SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
   ParsedAttributes DeclSpecAttrs(AttrFactory);
   DG = ParseSimpleDeclaration(
   DeclaratorContext::ForInit, DeclEnd, attrs, DeclSpecAttrs, false,

diff  --git a/clang/test/SemaCXX/cxx23-init-statement.cpp 
b/clang/test/SemaCXX/cxx23-init-statement.cpp
new file mode 100644
index 00..bf99a53df15e14
--- /dev/null
+++ b/clang/test/SemaCXX/cxx23-init-statement.cpp
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++23 %s
+
+namespace GH63627 {
+template
+void ok() {
+  if  (using U = decltype([]{ return 42;}); true) {
+  static_assert(U{}() == 42);
+  }
+  for (using U = decltype([]{ return 42;}); [[maybe_unused]] auto x : "abc") {
+  static_assert(U{}() == 42);
+  }
+  for (using U = decltype([]{ return 42;}); false; ) {
+  static_assert(U{}() == 42);
+  }
+}
+
+template
+void err() {
+  if  (using U = decltype([]{}.foo); true) {}  // expected-error {{no member 
named 'foo'}}
+
+  for (using U = decltype([]{}.foo);  // expected-error {{no member 
named 'foo'}}
+   [[maybe_unused]] auto x : "abc") { }
+
+  for (using U = decltype([]{}.foo);  // expected-error {{no member 
named 'foo'}}
+   false ; ) { }
+};
+
+void test() {
+  ok();
+  err(); // expected-note {{in instantiation of function template 
specialization 'GH63627::err'}}
+}
+
+}



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


[clang-tools-extra] 95f5096 - Implement P2361 Unevaluated string literals

2023-07-07 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-07-07T13:30:27+02:00
New Revision: 95f50964fbf59dc6394898c0719ce8772cc24d25

URL: 
https://github.com/llvm/llvm-project/commit/95f50964fbf59dc6394898c0719ce8772cc24d25
DIFF: 
https://github.com/llvm/llvm-project/commit/95f50964fbf59dc6394898c0719ce8772cc24d25.diff

LOG: Implement P2361 Unevaluated string literals

This patch proposes to handle in an uniform fashion
the parsing of strings that are never evaluated,
in asm statement, static assert, attrributes, extern,
etc.

Unevaluated strings are UTF-8 internally and so currently
behave as narrow strings, but these things will diverge with
D93031.

The big question both for this patch and the P2361 paper
is whether we risk breaking code by disallowing
encoding prefixes in this context.
I hope this patch may allow to gather some data on that.

Future work:
Improve the rendering of unicode characters, line break
and so forth in static-assert messages

Reviewed By: aaron.ballman, shafik

Differential Revision: https://reviews.llvm.org/D105759

Added: 


Modified: 
clang-tools-extra/test/clang-tidy/checkers/modernize/unary-static-assert.cpp
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/Expr.h
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Lex/LiteralSupport.h
clang/include/clang/Parse/Parser.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/Expr.cpp
clang/lib/Lex/LiteralSupport.cpp
clang/lib/Lex/PPMacroExpansion.cpp
clang/lib/Lex/Pragma.cpp
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Parse/ParseExpr.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaInit.cpp
clang/test/CXX/dcl.dcl/dcl.link/p2.cpp
clang/test/CXX/dcl.dcl/p4-0x.cpp
clang/test/FixIt/fixit-static-assert.cpp
clang/test/SemaCXX/static-assert.cpp
clang/www/cxx_status.html

Removed: 




diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/unary-static-assert.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/unary-static-assert.cpp
index 97ad94834cd0e6..74b4209505f97a 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/unary-static-assert.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/unary-static-assert.cpp
@@ -7,9 +7,6 @@ void f_textless(int a) {
   static_assert(sizeof(a) <= 10, "");
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use unary 'static_assert' when 
the string literal is an empty string [modernize-unary-static-assert]
   // CHECK-FIXES: {{^}}  static_assert(sizeof(a) <= 10 );{{$}}
-  static_assert(sizeof(a) <= 12, L"");
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use unary 'static_assert' when
-  // CHECK-FIXES: {{^}}  static_assert(sizeof(a) <= 12 );{{$}}
   FOO
   // CHECK-FIXES: {{^}}  FOO{{$}}
   static_assert(sizeof(a) <= 17, MSG);

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 79550f79cc36b5..8672b483cf836b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -135,6 +135,8 @@ C++2c Feature Support
 ^
 - Compiler flags ``-std=c++2c`` and ``-std=gnu++2c`` have been added for 
experimental C++2c implementation work.
 - Implemented `P2738R1: constexpr cast from void* 
`_.
+- Partially implemented `P2361R6: constexpr cast from void* 
`_.
+  The changes to attributes declarations are not part of this release.
 
 Resolutions to C++ Defect Reports
 ^

diff  --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 34aa63658d5017..661a8a7175ca88 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -1804,7 +1804,7 @@ class StringLiteral final
   /// * An array of getByteLength() char used to store the string data.
 
 public:
-  enum StringKind { Ordinary, Wide, UTF8, UTF16, UTF32 };
+  enum StringKind { Ordinary, Wide, UTF8, UTF16, UTF32, Unevaluated };
 
 private:
   unsigned numTrailingObjects(OverloadToken) const { return 1; }
@@ -1866,7 +1866,7 @@ class StringLiteral final
 unsigned CharByteWidth);
 
   StringRef getString() const {
-assert(getCharByteWidth() == 1 &&
+assert((isUnevaluated() || getCharByteWidth() == 1) &&
"This function is used in places that assume strings use char");
 return StringRef(getStrDataAsChar(), getByteLength());
   }
@@ -1906,6 +1906,7 @@ class StringLiteral final
   bool isUTF8() const { return getKind() == UTF8; }
   bool isUTF16() const { return getKind() == UTF16; }
   bool isUTF32() const { return getKind() == UTF32; }
+  bool isUnevaluated() const { return getKind() == Unevaluated; }
   bool isPascal() const { return StringLiteralBits.IsPascal; }
 
   bool containsNonAscii() const {

[clang] c5301cc - [Clang][NFC] Fix the title of P2361 in the release notes

2023-07-07 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-07-07T16:41:17+02:00
New Revision: c5301cc5ce5edc56ba5ec27bb79ec2b2957d1974

URL: 
https://github.com/llvm/llvm-project/commit/c5301cc5ce5edc56ba5ec27bb79ec2b2957d1974
DIFF: 
https://github.com/llvm/llvm-project/commit/c5301cc5ce5edc56ba5ec27bb79ec2b2957d1974.diff

LOG: [Clang][NFC] Fix the title of P2361 in the release notes

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 35caf85725c140..1ae7b8377e3e4e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -135,7 +135,7 @@ C++2c Feature Support
 ^
 - Compiler flags ``-std=c++2c`` and ``-std=gnu++2c`` have been added for 
experimental C++2c implementation work.
 - Implemented `P2738R1: constexpr cast from void* 
`_.
-- Partially implemented `P2361R6: constexpr cast from void* 
`_.
+- Partially implemented `P2361R6: Unevaluated strings 
`_.
   The changes to attributes declarations are not part of this release.
 
 Resolutions to C++ Defect Reports



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


[clang] 5f038e0 - [Clang][NFC] Fix "initalizer" typo

2023-07-10 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-07-10T09:06:19+02:00
New Revision: 5f038e0e20641515fe412e1df298a62eb657f554

URL: 
https://github.com/llvm/llvm-project/commit/5f038e0e20641515fe412e1df298a62eb657f554
DIFF: 
https://github.com/llvm/llvm-project/commit/5f038e0e20641515fe412e1df298a62eb657f554.diff

LOG: [Clang][NFC] Fix "initalizer" typo

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticASTKinds.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/CodeGen/CGDeclCXX.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaInit.cpp
clang/test/Modules/odr_hash.cpp
clang/test/SemaCXX/cxx2a-consteval-default-params.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index 856293dd45d089..566cdc3406058f 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -781,7 +781,7 @@ def err_module_odr_violation_field : Error<
   "%select{non-|}5bitfield %4|"
   "bitfield %4 with one width expression|"
   "%select{non-|}5mutable field %4|"
-  "field %4 with %select{no|an}5 initalizer|"
+  "field %4 with %select{no|an}5 initializer|"
   "field %4 with an initializer"
   "}3">;
 def note_module_odr_violation_field : Note<

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 7ca91020181845..eea4d4961c077a 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2671,7 +2671,7 @@ def note_immediate_function_reason : Note<
   "expression}3">;
 
 def note_invalid_consteval_initializer : Note<
-  "in the default initalizer of %0">;
+  "in the default initializer of %0">;
 def note_invalid_consteval_initializer_here : Note<
   "initialized here %0">;
 def err_invalid_consteval_decl_kind : Error<
@@ -9660,7 +9660,7 @@ def note_lambda_capture_initializer : Note<
   "%select{implicitly |}2captured%select{| by reference}3"
   "%select{%select{ due to use|}2 here|"
   " via initialization of lambda capture %0}1">;
-def note_init_with_default_member_initalizer : Note<
+def note_init_with_default_member_initializer : Note<
   "initializing field %0 with default member initializer">;
 
 // Check for initializing a member variable with the address or a reference to

diff  --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index 8a77ffeed52f7c..be8fb6c274db10 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -643,7 +643,7 @@ void CodeGenModule::EmitCXXThreadLocalInitFunc() {
This is arranged to be run only once regardless of how many times the module
might be included transitively.  This arranged by using a guard variable.
 
-   If there are no initalizers at all (and also no imported modules) we reduce
+   If there are no initializers at all (and also no imported modules) we reduce
this to an empty function (since the Itanium ABI requires that this function
be available to a caller, which might be produced by a 
diff erent
implementation).

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index e3cbcd6795ea66..7a4e154cb26110 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -19601,7 +19601,7 @@ static void CheckForDuplicateEnumValues(Sema &S, 
ArrayRef Elements,
   return;
 }
 
-// Constants with initalizers are handled in the next loop.
+// Constants with initializers are handled in the next loop.
 if (ECD->getInitExpr())
   continue;
 

diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 71d59a64fb5767..89fd56fb660b8b 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -8282,7 +8282,7 @@ void Sema::checkInitializerLifetime(const 
InitializedEntity &Entity,
 
   case IndirectLocalPathEntry::DefaultInit: {
 auto *FD = cast(Elem.D);
-Diag(FD->getLocation(), diag::note_init_with_default_member_initalizer)
+Diag(FD->getLocation(), 
diag::note_init_with_default_member_initializer)
 << FD << nextPathEntryRange(Path, I + 1, L);
 break;
   }

diff  --git a/clang/test/Modules/odr_hash.cpp b/clang/test/Modules/odr_hash.cpp
index fffac5e318f5d5..c5bf6e873e52ec 100644
--- a/clang/test/Modules/odr_hash.cpp
+++ b/clang/test/Modules/odr_hash.cpp
@@ -334,7 +334,7 @@ struct S10 {
 };
 #else
 S10 s10;
-// expected-error@second.h:* {{'Field::S10' has 
diff erent definitions in 
diff erent modules; first 
diff erence is definition in module 'SecondModule' found field 'x' with no 
initalizer}}
+// expected-error@second.h:* {{'Field::S10' has 
diff erent definitions in 
diff erent modules; first 
diff erence is definition in module 'SecondModule' found field 'x' with no 
initializer}}
 // expected-note@first.h

[clang] b0cc947 - [Clang] Diagnose jumps into statement expressions

2023-07-11 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-07-11T21:41:14+02:00
New Revision: b0cc947b5d0a74f4ffe63c53b32978b21498e72e

URL: 
https://github.com/llvm/llvm-project/commit/b0cc947b5d0a74f4ffe63c53b32978b21498e72e
DIFF: 
https://github.com/llvm/llvm-project/commit/b0cc947b5d0a74f4ffe63c53b32978b21498e72e.diff

LOG: [Clang] Diagnose jumps into statement expressions

Such jumps are not allowed by GCC and allowing them
can lead to situations where we jumps into unevaluated
statements.

Fixes #63682

Reviewed By: aaron.ballman, #clang-language-wg

Differential Revision: https://reviews.llvm.org/D154696

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/JumpDiagnostics.cpp
clang/lib/Sema/SemaExpr.cpp
clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
clang/test/Sema/asm-goto.cpp
clang/test/Sema/scope-check.c
clang/test/SemaCXX/constant-expression-cxx14.cpp
clang/test/SemaObjC/scope-check.m

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6a1e2fc3ea0e64..1f025097babc95 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -582,6 +582,9 @@ Bug Fixes in This Version
   (`#50243 `_),
   (`#48636 `_),
   (`#50320 `_).
+- Correcly diagnose jumps into statement expressions.
+  This ensures the behavior of Clang is consistent with GCC.
+  (`#63682 `_)
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index eea4d4961c077a..695cf9bce93e87 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6196,6 +6196,8 @@ def note_enters_block_captures_non_trivial_c_struct : 
Note<
   "to destroy">;
 def note_enters_compound_literal_scope : Note<
   "jump enters lifetime of a compound literal that is non-trivial to 
destruct">;
+def note_enters_statement_expression : Note<
+  "jump enters a statement expression">;
 
 def note_exits_cleanup : Note<
   "jump exits scope of variable with __attribute__((cleanup))">;

diff  --git a/clang/lib/Sema/JumpDiagnostics.cpp 
b/clang/lib/Sema/JumpDiagnostics.cpp
index bd2ce9a93e7e03..45e3cc2b00f0e8 100644
--- a/clang/lib/Sema/JumpDiagnostics.cpp
+++ b/clang/lib/Sema/JumpDiagnostics.cpp
@@ -477,6 +477,21 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S,
 return;
   }
 
+  case Stmt::StmtExprClass: {
+// [GNU]
+// Jumping into a statement expression with goto or using
+// a switch statement outside the statement expression with
+// a case or default label inside the statement expression is not 
permitted.
+// Jumping out of a statement expression is permitted.
+StmtExpr *SE = cast(S);
+unsigned NewParentScope = Scopes.size();
+Scopes.push_back(GotoScope(ParentScope,
+   diag::note_enters_statement_expression,
+   /*OutDiag=*/0, SE->getBeginLoc()));
+BuildScopeInformation(SE->getSubStmt(), NewParentScope);
+return;
+  }
+
   case Stmt::ObjCAtTryStmtClass: {
 // Disallow jumps into any part of an @try statement by pushing a scope and
 // walking all sub-stmts in that scope.

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 56e9c4ca133278..6cebb7e2dd540d 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -16490,6 +16490,8 @@ ExprResult Sema::ActOnAddrLabel(SourceLocation OpLoc, 
SourceLocation LabLoc,
 
 void Sema::ActOnStartStmtExpr() {
   PushExpressionEvaluationContext(ExprEvalContexts.back().Context);
+  // Make sure we diagnose jumping into a statement expression.
+  setFunctionHasBranchProtectedScope();
 }
 
 void Sema::ActOnStmtExprError() {

diff  --git a/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp 
b/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
index 0c357db764a92a..55af13bfc0ef3a 100644
--- a/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
+++ b/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
@@ -153,7 +153,8 @@ a:  if constexpr(sizeof(n) == 4) // expected-error 
{{redefinition}} expected-not
 
   void evil_things() {
 goto evil_label; // expected-error {{cannot jump}}
-if constexpr (true || ({evil_label: false;})) {} // expected-note 
{{constexpr if}}
+if constexpr (true || ({evil_label: false;})) {} // expected-note 
{{constexpr if}} \
+ // expected-note {{jump 
enters a statement expression}}
 
 if constexpr (true) // expected-note {{constexpr if}}
   goto surprise; // expected-error {{cannot 

[clang] 304e974 - [Clang] Correctly handle $, @, and ` when represented as UCN

2023-07-11 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-07-12T08:03:23+02:00
New Revision: 304e97469455b57f6496f68fef569eeaed3a2cd8

URL: 
https://github.com/llvm/llvm-project/commit/304e97469455b57f6496f68fef569eeaed3a2cd8
DIFF: 
https://github.com/llvm/llvm-project/commit/304e97469455b57f6496f68fef569eeaed3a2cd8.diff

LOG: [Clang] Correctly handle $, @, and ` when represented as UCN

This covers
 * P2558R2 (C++, wg21.link/P2558)
 * N2701 (C, https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2701.htm)
 * N3124 (C, https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3124.pdf)

This patch
 * Disallow representing $ as a UCN in all language mode, which did not
   properly work (see GH62133), and which in made ill-formed in
   C++ and C by P2558 and N3124 respectively
 * Allow a UCN for any character in C2X, in string and character
   literals

Fixes #62133

Reviewed By: #clang-language-wg, tahonermann

Differential Revision: https://reviews.llvm.org/D153621

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/lib/Lex/Lexer.cpp
clang/lib/Lex/LiteralSupport.cpp
clang/test/Lexer/char-literal.cpp
clang/test/Lexer/utf8-char-literal.cpp
clang/test/Preprocessor/ucn-allowed-chars.c
clang/test/Preprocessor/ucn-pp-identifier.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b7babe3ddc3f41..f86dc00fa8bcfb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -205,6 +205,9 @@ C2x Feature Support
 
 bool b = nullptr; // Was incorrectly rejected by Clang, is now accepted.
 
+- Implemented `WG14 N3124 
_`,
+  which allows any universal character name to appear in character and string 
literals.
+
 
 Non-comprehensive list of changes in this release
 -
@@ -585,6 +588,9 @@ Bug Fixes in This Version
 - Correcly diagnose jumps into statement expressions.
   This ensures the behavior of Clang is consistent with GCC.
   (`#63682 `_)
+  (`#38717 _`).
+- Fix an assertion when using ``\u0024`` (``$``) as an identifier, by 
disallowing
+  that construct (`#62133 
_`).
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index b9dfb76cca4a1a..0eb270aeea0e5d 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -197,6 +197,14 @@ def warn_cxx98_compat_literal_ucn_escape_basic_scs : 
Warning<
 def warn_cxx98_compat_literal_ucn_control_character : Warning<
   "universal character name referring to a control character "
   "is incompatible with C++98">, InGroup, DefaultIgnore;
+def warn_c2x_compat_literal_ucn_escape_basic_scs : Warning<
+  "specifying character '%0' with a universal character name is "
+  "incompatible with C standards before C2x">,
+  InGroup, DefaultIgnore;
+def warn_c2x_compat_literal_ucn_control_character : Warning<
+  "universal character name referring to a control character "
+  "is incompatible with C standards before C2x">,
+  InGroup, DefaultIgnore;
 def warn_ucn_not_valid_in_c89 : Warning<
   "universal character names are only valid in C99 or C++; "
   "treating as '\\' followed by identifier">, InGroup;

diff  --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index 82f65ef3aaf8ca..3070407997b2c5 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -3484,9 +3484,14 @@ uint32_t Lexer::tryReadUCN(const char *&StartPtr, const 
char *SlashLoc,
   if (LangOpts.AsmPreprocessor)
 return CodePoint;
 
-  // C99 6.4.3p2: A universal character name shall not specify a character 
whose
-  //   short identifier is less than 00A0 other than 0024 ($), 0040 (@), or
-  //   0060 (`), nor one in the range D800 through DFFF inclusive.)
+  // C2x 6.4.3p2: A universal character name shall not designate a code point
+  // where the hexadecimal value is:
+  // - in the range D800 through DFFF inclusive; or
+  // - greater than 10.
+  // A universal-character-name outside the c-char-sequence of a character
+  // constant, or the s-char-sequence of a string-literal shall not designate
+  // a control character or a character in the basic character set.
+
   // C++11 [lex.charset]p2: If the hexadecimal value for a
   //   universal-character-name corresponds to a surrogate code point (in the
   //   range 0xD800-0xDFFF, inclusive), the program is ill-formed. 
Additionally,
@@ -3496,9 +3501,6 @@ uint32_t Lexer::tryReadUCN(const char *&StartPtr, const 
char *SlashLoc,
   //   ranges 0x00-0x1F or 0x7F-0x9F, both inclusive) or to a character in th

[clang] 7d54aae - Revert "[Clang] Diagnose jumps into statement expressions"

2023-07-12 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-07-12T17:54:16+02:00
New Revision: 7d54aae2f122cac8989af0b978938152c6b08454

URL: 
https://github.com/llvm/llvm-project/commit/7d54aae2f122cac8989af0b978938152c6b08454
DIFF: 
https://github.com/llvm/llvm-project/commit/7d54aae2f122cac8989af0b978938152c6b08454.diff

LOG: Revert "[Clang] Diagnose jumps into statement expressions"

This reverts commit b0cc947b5d0a74f4ffe63c53b32978b21498e72e.

Breaks in presence of asm goto
https://reviews.llvm.org/D154696#4493805

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/JumpDiagnostics.cpp
clang/lib/Sema/SemaExpr.cpp
clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
clang/test/Sema/asm-goto.cpp
clang/test/Sema/scope-check.c
clang/test/SemaCXX/constant-expression-cxx14.cpp
clang/test/SemaObjC/scope-check.m

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f86dc00fa8bcfb..42e92576808218 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -585,10 +585,6 @@ Bug Fixes in This Version
   (`#50243 `_),
   (`#48636 `_),
   (`#50320 `_).
-- Correcly diagnose jumps into statement expressions.
-  This ensures the behavior of Clang is consistent with GCC.
-  (`#63682 `_)
-  (`#38717 _`).
 - Fix an assertion when using ``\u0024`` (``$``) as an identifier, by 
disallowing
   that construct (`#62133 
_`).
 

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 695cf9bce93e87..eea4d4961c077a 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6196,8 +6196,6 @@ def note_enters_block_captures_non_trivial_c_struct : 
Note<
   "to destroy">;
 def note_enters_compound_literal_scope : Note<
   "jump enters lifetime of a compound literal that is non-trivial to 
destruct">;
-def note_enters_statement_expression : Note<
-  "jump enters a statement expression">;
 
 def note_exits_cleanup : Note<
   "jump exits scope of variable with __attribute__((cleanup))">;

diff  --git a/clang/lib/Sema/JumpDiagnostics.cpp 
b/clang/lib/Sema/JumpDiagnostics.cpp
index 45e3cc2b00f0e8..bd2ce9a93e7e03 100644
--- a/clang/lib/Sema/JumpDiagnostics.cpp
+++ b/clang/lib/Sema/JumpDiagnostics.cpp
@@ -477,21 +477,6 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S,
 return;
   }
 
-  case Stmt::StmtExprClass: {
-// [GNU]
-// Jumping into a statement expression with goto or using
-// a switch statement outside the statement expression with
-// a case or default label inside the statement expression is not 
permitted.
-// Jumping out of a statement expression is permitted.
-StmtExpr *SE = cast(S);
-unsigned NewParentScope = Scopes.size();
-Scopes.push_back(GotoScope(ParentScope,
-   diag::note_enters_statement_expression,
-   /*OutDiag=*/0, SE->getBeginLoc()));
-BuildScopeInformation(SE->getSubStmt(), NewParentScope);
-return;
-  }
-
   case Stmt::ObjCAtTryStmtClass: {
 // Disallow jumps into any part of an @try statement by pushing a scope and
 // walking all sub-stmts in that scope.

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 6cebb7e2dd540d..56e9c4ca133278 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -16490,8 +16490,6 @@ ExprResult Sema::ActOnAddrLabel(SourceLocation OpLoc, 
SourceLocation LabLoc,
 
 void Sema::ActOnStartStmtExpr() {
   PushExpressionEvaluationContext(ExprEvalContexts.back().Context);
-  // Make sure we diagnose jumping into a statement expression.
-  setFunctionHasBranchProtectedScope();
 }
 
 void Sema::ActOnStmtExprError() {

diff  --git a/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp 
b/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
index 55af13bfc0ef3a..0c357db764a92a 100644
--- a/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
+++ b/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
@@ -153,8 +153,7 @@ a:  if constexpr(sizeof(n) == 4) // expected-error 
{{redefinition}} expected-not
 
   void evil_things() {
 goto evil_label; // expected-error {{cannot jump}}
-if constexpr (true || ({evil_label: false;})) {} // expected-note 
{{constexpr if}} \
- // expected-note {{jump 
enters a statement expression}}
+if constexpr (true || ({evil_label: false;})) {} // expected-note 
{{constexpr if}}
 
 if constexpr (true) // e

  1   2   >