[clang] [Clang] Fix __is_trivially_equality_comparable returning true with ineligebile defaulted overloads (PR #93113)

2024-05-22 Thread Nikolas Klauser via cfe-commits

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


[clang] [Clang] Fix __is_trivially_equality_comparable returning true with ineligebile defaulted overloads (PR #93113)

2024-05-22 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/93113

>From 31e334643e7b4fa4a87c8d15efab4036306d Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Thu, 23 May 2024 01:48:06 +0200
Subject: [PATCH] [Clang] Fix __is_trivially_equality_comparable returning true
 with ineligebile defaulted overloads

---
 clang/docs/ReleaseNotes.rst|  3 ++
 clang/include/clang/AST/Type.h |  3 --
 clang/lib/AST/Type.cpp | 60 -
 clang/lib/Sema/SemaExprCXX.cpp | 71 +-
 clang/test/SemaCXX/type-traits.cpp | 28 
 5 files changed, 101 insertions(+), 64 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0c4a343b70009..cb662f520c4c3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -606,6 +606,9 @@ Bug Fixes in This Version
 - ``__is_array`` and ``__is_bounded_array`` no longer return ``true`` for
   zero-sized arrays. Fixes (#GH54705).
 
+- ``__is_trivially_equality_comparable`` no longer returns true for types which
+  have a constrained defaulted comparison operator (#GH89293).
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 9a5c6e8d562c3..628c7a0d2df83 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -1126,9 +1126,6 @@ class QualType {
   /// Return true if this is a trivially relocatable type.
   bool isTriviallyRelocatableType(const ASTContext ) const;
 
-  /// Return true if this is a trivially equality comparable type.
-  bool isTriviallyEqualityComparableType(const ASTContext ) const;
-
   /// Returns true if it is a class and it might be dynamic.
   bool mayBeDynamicClass() const;
 
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 3b90b8229dd18..62ca402460f94 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2768,66 +2768,6 @@ bool QualType::isTriviallyRelocatableType(const 
ASTContext ) const {
   }
 }
 
-static bool
-HasNonDeletedDefaultedEqualityComparison(const CXXRecordDecl *Decl) {
-  if (Decl->isUnion())
-return false;
-  if (Decl->isLambda())
-return Decl->isCapturelessLambda();
-
-  auto IsDefaultedOperatorEqualEqual = [&](const FunctionDecl *Function) {
-return Function->getOverloadedOperator() ==
-   OverloadedOperatorKind::OO_EqualEqual &&
-   Function->isDefaulted() && Function->getNumParams() > 0 &&
-   (Function->getParamDecl(0)->getType()->isReferenceType() ||
-Decl->isTriviallyCopyable());
-  };
-
-  if (llvm::none_of(Decl->methods(), IsDefaultedOperatorEqualEqual) &&
-  llvm::none_of(Decl->friends(), [&](const FriendDecl *Friend) {
-if (NamedDecl *ND = Friend->getFriendDecl()) {
-  return ND->isFunctionOrFunctionTemplate() &&
- IsDefaultedOperatorEqualEqual(ND->getAsFunction());
-}
-return false;
-  }))
-return false;
-
-  return llvm::all_of(Decl->bases(),
-  [](const CXXBaseSpecifier ) {
-if (const auto *RD = 
BS.getType()->getAsCXXRecordDecl())
-  return HasNonDeletedDefaultedEqualityComparison(RD);
-return true;
-  }) &&
- llvm::all_of(Decl->fields(), [](const FieldDecl *FD) {
-   auto Type = FD->getType();
-   if (Type->isArrayType())
- Type = 
Type->getBaseElementTypeUnsafe()->getCanonicalTypeUnqualified();
-
-   if (Type->isReferenceType() || Type->isEnumeralType())
- return false;
-   if (const auto *RD = Type->getAsCXXRecordDecl())
- return HasNonDeletedDefaultedEqualityComparison(RD);
-   return true;
- });
-}
-
-bool QualType::isTriviallyEqualityComparableType(
-const ASTContext ) const {
-  QualType CanonicalType = getCanonicalType();
-  if (CanonicalType->isIncompleteType() || CanonicalType->isDependentType() ||
-  CanonicalType->isEnumeralType() || CanonicalType->isArrayType())
-return false;
-
-  if (const auto *RD = CanonicalType->getAsCXXRecordDecl()) {
-if (!HasNonDeletedDefaultedEqualityComparison(RD))
-  return false;
-  }
-
-  return Context.hasUniqueObjectRepresentations(
-  CanonicalType, /*CheckIfTriviallyCopyable=*/false);
-}
-
 bool QualType::isNonWeakInMRRWithObjCWeak(const ASTContext ) const {
   return !Context.getLangOpts().ObjCAutoRefCount &&
  Context.getLangOpts().ObjCWeak &&
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index f543e006060d6..ccf678e666ecb 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5199,6 +5199,75 @@ static bool HasNoThrowOperator(const RecordType *RT, 
OverloadedOperatorKind Op,
   return false;
 }
 
+static bool
+HasNonDeletedDefaultedEqualityComparison(Sema& S, const 

[clang] [Clang] Fix __is_trivially_equality_comparable returning true with ineligebile defaulted overloads (PR #93113)

2024-05-22 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 created 
https://github.com/llvm/llvm-project/pull/93113

This changes `__is_trivially_equality_comparable` to do overload resolution 
instead, which fixes a couple of false-positives (and a false-negative as a 
drive-by).

Fixes #89293



>From 53b52a07f8720db4495b93099d3e1874453f6950 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Thu, 23 May 2024 01:48:06 +0200
Subject: [PATCH] [Clang] Fix __is_trivially_equality_comparable returning true
 with ineligebile defaulted overloads

---
 clang/include/clang/AST/Type.h |  3 --
 clang/lib/AST/Type.cpp | 60 -
 clang/lib/Sema/SemaExprCXX.cpp | 71 +-
 clang/test/SemaCXX/type-traits.cpp | 28 
 4 files changed, 98 insertions(+), 64 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 9a5c6e8d562c3..628c7a0d2df83 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -1126,9 +1126,6 @@ class QualType {
   /// Return true if this is a trivially relocatable type.
   bool isTriviallyRelocatableType(const ASTContext ) const;
 
-  /// Return true if this is a trivially equality comparable type.
-  bool isTriviallyEqualityComparableType(const ASTContext ) const;
-
   /// Returns true if it is a class and it might be dynamic.
   bool mayBeDynamicClass() const;
 
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 3b90b8229dd18..62ca402460f94 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2768,66 +2768,6 @@ bool QualType::isTriviallyRelocatableType(const 
ASTContext ) const {
   }
 }
 
-static bool
-HasNonDeletedDefaultedEqualityComparison(const CXXRecordDecl *Decl) {
-  if (Decl->isUnion())
-return false;
-  if (Decl->isLambda())
-return Decl->isCapturelessLambda();
-
-  auto IsDefaultedOperatorEqualEqual = [&](const FunctionDecl *Function) {
-return Function->getOverloadedOperator() ==
-   OverloadedOperatorKind::OO_EqualEqual &&
-   Function->isDefaulted() && Function->getNumParams() > 0 &&
-   (Function->getParamDecl(0)->getType()->isReferenceType() ||
-Decl->isTriviallyCopyable());
-  };
-
-  if (llvm::none_of(Decl->methods(), IsDefaultedOperatorEqualEqual) &&
-  llvm::none_of(Decl->friends(), [&](const FriendDecl *Friend) {
-if (NamedDecl *ND = Friend->getFriendDecl()) {
-  return ND->isFunctionOrFunctionTemplate() &&
- IsDefaultedOperatorEqualEqual(ND->getAsFunction());
-}
-return false;
-  }))
-return false;
-
-  return llvm::all_of(Decl->bases(),
-  [](const CXXBaseSpecifier ) {
-if (const auto *RD = 
BS.getType()->getAsCXXRecordDecl())
-  return HasNonDeletedDefaultedEqualityComparison(RD);
-return true;
-  }) &&
- llvm::all_of(Decl->fields(), [](const FieldDecl *FD) {
-   auto Type = FD->getType();
-   if (Type->isArrayType())
- Type = 
Type->getBaseElementTypeUnsafe()->getCanonicalTypeUnqualified();
-
-   if (Type->isReferenceType() || Type->isEnumeralType())
- return false;
-   if (const auto *RD = Type->getAsCXXRecordDecl())
- return HasNonDeletedDefaultedEqualityComparison(RD);
-   return true;
- });
-}
-
-bool QualType::isTriviallyEqualityComparableType(
-const ASTContext ) const {
-  QualType CanonicalType = getCanonicalType();
-  if (CanonicalType->isIncompleteType() || CanonicalType->isDependentType() ||
-  CanonicalType->isEnumeralType() || CanonicalType->isArrayType())
-return false;
-
-  if (const auto *RD = CanonicalType->getAsCXXRecordDecl()) {
-if (!HasNonDeletedDefaultedEqualityComparison(RD))
-  return false;
-  }
-
-  return Context.hasUniqueObjectRepresentations(
-  CanonicalType, /*CheckIfTriviallyCopyable=*/false);
-}
-
 bool QualType::isNonWeakInMRRWithObjCWeak(const ASTContext ) const {
   return !Context.getLangOpts().ObjCAutoRefCount &&
  Context.getLangOpts().ObjCWeak &&
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index f543e006060d6..ccf678e666ecb 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5199,6 +5199,75 @@ static bool HasNoThrowOperator(const RecordType *RT, 
OverloadedOperatorKind Op,
   return false;
 }
 
+static bool
+HasNonDeletedDefaultedEqualityComparison(Sema& S, const CXXRecordDecl *Decl) {
+  if (Decl->isUnion())
+return false;
+  if (Decl->isLambda())
+return Decl->isCapturelessLambda();
+
+  {
+EnterExpressionEvaluationContext UnevaluatedContext(
+S, Sema::ExpressionEvaluationContext::Unevaluated);
+Sema::SFINAETrap SFINAE(S, /*AccessCheckingSFINAE=*/true);
+Sema::ContextRAII TUContext(S, S.Context.getTranslationUnitDecl());
+
+// const ClassT& obj;
+  

[clang] [Clang] Fix __is_array returning true for zero-sized arrays (PR #86652)

2024-05-20 Thread Nikolas Klauser via cfe-commits

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


[clang] [llvm] [C++23] [CLANG] Adding C++23 constexpr math functions: fmin, fmax and frexp. (PR #88978)

2024-05-19 Thread Nikolas Klauser via cfe-commits


@@ -3452,9 +3452,10 @@ def Fmod : FPMathTemplate, LibBuiltin<"math.h"> {
 
 def Frexp : FPMathTemplate, LibBuiltin<"math.h"> {
   let Spellings = ["frexp"];
-  let Attributes = [NoThrow];
+  let Attributes = [NoThrow, Constexpr];

philnik777 wrote:

This also influences `__has_constexpr_builtin(fmin)`, which would return true 
but then fail to actually evaluate during a constant expression, which doesn't 
seem that great. IMO we'd probably want to introduce the concept of "constexpr 
since C++xy".

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


[clang] [Clang] Fix __is_array returning true for zero-sized arrays (PR #86652)

2024-05-18 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/86652

>From 90f88bdac3dc40635c58f3f67e29354e6a32896e Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Tue, 26 Mar 2024 12:23:24 +0100
Subject: [PATCH] [Clang] Fix __is_array returning true for zero-sized arrays

---
 clang/docs/ReleaseNotes.rst| 2 ++
 clang/lib/Sema/SemaExprCXX.cpp | 4 
 clang/test/SemaCXX/type-traits.cpp | 4 +++-
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7fbe2fec6ca06..e668202853710 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -345,6 +345,8 @@ Bug Fixes in This Version
 - Fixes an assertion failure on invalid code when trying to define member
   functions in lambdas.
 
+- ``__is_array`` no longer returns ``true`` for zero-sized arrays. Fixes 
(#GH54705).
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index c34a40fa7c81a..93d2b4b259fbc 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5143,6 +5143,10 @@ static bool EvaluateUnaryTypeTrait(Sema , TypeTrait 
UTT,
   case UTT_IsFloatingPoint:
 return T->isFloatingType();
   case UTT_IsArray:
+// zero-sized arrays aren't considered arrays in partial specializations,
+// so __is_array shouldn't consider them arrays either.
+if (const auto* CAT = C.getAsConstantArrayType(T))
+  return CAT->getSize() != 0;
 return T->isArrayType();
   case UTT_IsBoundedArray:
 if (!T->isVariableArrayType()) {
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index 14ec17989ec7c..49df4b668513c 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -25,6 +25,7 @@ typedef Empty EmptyArMB[1][2];
 typedef int Int;
 typedef Int IntAr[10];
 typedef Int IntArNB[];
+typedef Int IntArZero[0];
 class Statics { static int priv; static NonPOD np; };
 union EmptyUnion {};
 union IncompleteUnion; // expected-note {{forward declaration of 
'IncompleteUnion'}}
@@ -685,6 +686,7 @@ void is_array()
 {
   static_assert(__is_array(IntAr));
   static_assert(__is_array(IntArNB));
+  static_assert(!__is_array(IntArZero));
   static_assert(__is_array(UnionAr));
 
   static_assert(!__is_array(void));
@@ -1804,7 +1806,7 @@ void is_layout_compatible(int n)
   static_assert(!__is_layout_compatible(EnumForward, int));
   static_assert(!__is_layout_compatible(EnumClassForward, int));
   // FIXME: the following should be rejected (array of unknown bound and void 
are the only allowed incomplete types)
-  static_assert(__is_layout_compatible(CStructIncomplete, CStructIncomplete)); 
+  static_assert(__is_layout_compatible(CStructIncomplete, CStructIncomplete));
   static_assert(!__is_layout_compatible(CStruct, CStructIncomplete));
   static_assert(__is_layout_compatible(CStructIncomplete[2], 
CStructIncomplete[2]));
 }

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


[clang] [Clang] Fix __is_array returning true for zero-sized arrays (PR #86652)

2024-05-18 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/86652

>From 90f88bdac3dc40635c58f3f67e29354e6a32896e Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Tue, 26 Mar 2024 12:23:24 +0100
Subject: [PATCH] [Clang] Fix __is_array returning true for zero-sized arrays

---
 clang/docs/ReleaseNotes.rst| 2 ++
 clang/lib/Sema/SemaExprCXX.cpp | 4 
 clang/test/SemaCXX/type-traits.cpp | 4 +++-
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7fbe2fec6ca06..e668202853710 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -345,6 +345,8 @@ Bug Fixes in This Version
 - Fixes an assertion failure on invalid code when trying to define member
   functions in lambdas.
 
+- ``__is_array`` no longer returns ``true`` for zero-sized arrays. Fixes 
(#GH54705).
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index c34a40fa7c81a..93d2b4b259fbc 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5143,6 +5143,10 @@ static bool EvaluateUnaryTypeTrait(Sema , TypeTrait 
UTT,
   case UTT_IsFloatingPoint:
 return T->isFloatingType();
   case UTT_IsArray:
+// zero-sized arrays aren't considered arrays in partial specializations,
+// so __is_array shouldn't consider them arrays either.
+if (const auto* CAT = C.getAsConstantArrayType(T))
+  return CAT->getSize() != 0;
 return T->isArrayType();
   case UTT_IsBoundedArray:
 if (!T->isVariableArrayType()) {
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index 14ec17989ec7c..49df4b668513c 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -25,6 +25,7 @@ typedef Empty EmptyArMB[1][2];
 typedef int Int;
 typedef Int IntAr[10];
 typedef Int IntArNB[];
+typedef Int IntArZero[0];
 class Statics { static int priv; static NonPOD np; };
 union EmptyUnion {};
 union IncompleteUnion; // expected-note {{forward declaration of 
'IncompleteUnion'}}
@@ -685,6 +686,7 @@ void is_array()
 {
   static_assert(__is_array(IntAr));
   static_assert(__is_array(IntArNB));
+  static_assert(!__is_array(IntArZero));
   static_assert(__is_array(UnionAr));
 
   static_assert(!__is_array(void));
@@ -1804,7 +1806,7 @@ void is_layout_compatible(int n)
   static_assert(!__is_layout_compatible(EnumForward, int));
   static_assert(!__is_layout_compatible(EnumClassForward, int));
   // FIXME: the following should be rejected (array of unknown bound and void 
are the only allowed incomplete types)
-  static_assert(__is_layout_compatible(CStructIncomplete, CStructIncomplete)); 
+  static_assert(__is_layout_compatible(CStructIncomplete, CStructIncomplete));
   static_assert(!__is_layout_compatible(CStruct, CStructIncomplete));
   static_assert(__is_layout_compatible(CStructIncomplete[2], 
CStructIncomplete[2]));
 }

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


[clang] [Clang] Fix __is_array returning true for zero-sized arrays (PR #86652)

2024-05-18 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/86652

>From 90f88bdac3dc40635c58f3f67e29354e6a32896e Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Tue, 26 Mar 2024 12:23:24 +0100
Subject: [PATCH] [Clang] Fix __is_array returning true for zero-sized arrays

---
 clang/docs/ReleaseNotes.rst| 2 ++
 clang/lib/Sema/SemaExprCXX.cpp | 4 
 clang/test/SemaCXX/type-traits.cpp | 4 +++-
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7fbe2fec6ca06..e668202853710 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -345,6 +345,8 @@ Bug Fixes in This Version
 - Fixes an assertion failure on invalid code when trying to define member
   functions in lambdas.
 
+- ``__is_array`` no longer returns ``true`` for zero-sized arrays. Fixes 
(#GH54705).
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index c34a40fa7c81a..93d2b4b259fbc 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5143,6 +5143,10 @@ static bool EvaluateUnaryTypeTrait(Sema , TypeTrait 
UTT,
   case UTT_IsFloatingPoint:
 return T->isFloatingType();
   case UTT_IsArray:
+// zero-sized arrays aren't considered arrays in partial specializations,
+// so __is_array shouldn't consider them arrays either.
+if (const auto* CAT = C.getAsConstantArrayType(T))
+  return CAT->getSize() != 0;
 return T->isArrayType();
   case UTT_IsBoundedArray:
 if (!T->isVariableArrayType()) {
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index 14ec17989ec7c..49df4b668513c 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -25,6 +25,7 @@ typedef Empty EmptyArMB[1][2];
 typedef int Int;
 typedef Int IntAr[10];
 typedef Int IntArNB[];
+typedef Int IntArZero[0];
 class Statics { static int priv; static NonPOD np; };
 union EmptyUnion {};
 union IncompleteUnion; // expected-note {{forward declaration of 
'IncompleteUnion'}}
@@ -685,6 +686,7 @@ void is_array()
 {
   static_assert(__is_array(IntAr));
   static_assert(__is_array(IntArNB));
+  static_assert(!__is_array(IntArZero));
   static_assert(__is_array(UnionAr));
 
   static_assert(!__is_array(void));
@@ -1804,7 +1806,7 @@ void is_layout_compatible(int n)
   static_assert(!__is_layout_compatible(EnumForward, int));
   static_assert(!__is_layout_compatible(EnumClassForward, int));
   // FIXME: the following should be rejected (array of unknown bound and void 
are the only allowed incomplete types)
-  static_assert(__is_layout_compatible(CStructIncomplete, CStructIncomplete)); 
+  static_assert(__is_layout_compatible(CStructIncomplete, CStructIncomplete));
   static_assert(!__is_layout_compatible(CStruct, CStructIncomplete));
   static_assert(__is_layout_compatible(CStructIncomplete[2], 
CStructIncomplete[2]));
 }

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


[clang] [Clang] Add __builtin_selectvector and use it for AVX512 intrinsics (PR #91306)

2024-05-16 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

I don't understand why the order of emitted instructions changes based on how 
exactly Clang is compiled, but other than that this should be ready. Hopefully 
someone spots what the problem could be.

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


[clang] [Clang] Add __builtin_selectvector and use it for AVX512 intrinsics (PR #91306)

2024-05-16 Thread Nikolas Klauser via cfe-commits

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


[clang] [Clang] Add __builtin_selectvector and use it for AVX512 intrinsics (PR #91306)

2024-05-16 Thread Nikolas Klauser via cfe-commits

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


[clang] [clang] Accept lambdas in C++03 as an extensions (PR #73376)

2024-05-16 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

I'm not sure a crash is ever expected, but it's a known issue.

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


[clang] [Clang] Fix __is_array returning true for zero-sized arrays (PR #86652)

2024-05-11 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

@AaronBallman Any thoughts on how we should proceed here?


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


[clang] [Clang] Add __builtin_selectvector and use it for AVX512 intrinsics (PR #91306)

2024-05-07 Thread Nikolas Klauser via cfe-commits

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


[clang] [Clang] Ensure "=default"ed function can be deleted when used as an extension in C++03 (PR #90725)

2024-05-01 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

Note that this is also a problem with an implicit assignment operator: 
https://godbolt.org/z/jrh5novMo. I'm not 100% sure it's not a bug, but it 
definitely looks to me like one. It's definitely a mismatch between C++03 and 
C++11, which I wouldn't expect given that `= delete` a C++11 extension.

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


[clang] [C++23] [CLANG] Adding C++23 constexpr math functions: fmin and frexp. (PR #88978)

2024-04-29 Thread Nikolas Klauser via cfe-commits


@@ -14638,6 +14649,8 @@ bool FloatExprEvaluator::VisitCallExpr(const CallExpr 
*E) {
 return true;
   }
 
+  case Builtin::BIfmin:
+  case Builtin::BIfminf:

philnik777 wrote:

How would that help?

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


[clang] [C++23] [CLANG] Adding C++23 constexpr math functions: fmin and frexp. (PR #88978)

2024-04-28 Thread Nikolas Klauser via cfe-commits


@@ -14638,6 +14649,8 @@ bool FloatExprEvaluator::VisitCallExpr(const CallExpr 
*E) {
 return true;
   }
 
+  case Builtin::BIfmin:
+  case Builtin::BIfminf:

philnik777 wrote:

These have to be made `constexpr`, at least in C++23. C++ stdlibs can't 
override them to make them call the `__builtin_` versions, so Clang has to 
handle that.


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


[clang] [clang] Constexpr for __builtin_shufflevector and __builtin_convertvector (PR #76615)

2024-04-24 Thread Nikolas Klauser via cfe-commits
Pol Marcet =?utf-8?q?Sardà?= ,
Pol Marcet =?utf-8?q?Sardà?= ,
Pol Marcet =?utf-8?q?Sardà?= ,
Pol Marcet =?utf-8?q?Sardà?= 
Message-ID:
In-Reply-To: 


philnik777 wrote:

I just wanted to say thanks for working on this. I'd love to enable the 
vectorization branches in libc++ during constant evaluation. It's always a 
great way to have confidence in the correctness of the code, and this brings us 
a step closer to having fewer `__libcpp_is_constant_evaluated()` in the code 
base.

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


[clang] [C++17] Support __GCC_[CON|DE]STRUCTIVE_SIZE (PR #89446)

2024-04-22 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

@AaronBallman thanks for picking this up! I agree with @cor3ntin and @ldionne 
that we should provide the macros unconditionally. This brings us one step 
closer to finally making libc++ fully conforming in C++17. With the PSTL 
finally making steady progress, we're probably only missing a few audits and 
the math special functions to be fully conforming.

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


[clang] [Clang] Fix __is_trivially_equaltiy_comparable documentation (PR #88528)

2024-04-22 Thread Nikolas Klauser via cfe-commits

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


[clang] [Clang] Fix __is_trivially_equaltiy_comparable documentation (PR #88528)

2024-04-22 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/88528

>From 0c9372749f4b2d52deddea82be4e77524a66a348 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Fri, 12 Apr 2024 17:36:53 +0200
Subject: [PATCH] [Clang] Fix __is_trivially_equaltiy_comparable documentation

---
 clang/docs/LanguageExtensions.rst | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 7b23e4d1c2f30c..40ff2d074e1648 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1640,7 +1640,8 @@ The following type trait primitives are supported by 
Clang. Those traits marked
   were made trivially relocatable via the ``clang::trivial_abi`` attribute.
 * ``__is_trivially_equality_comparable`` (Clang): Returns true if comparing two
   objects of the provided type is known to be equivalent to comparing their
-  value representations.
+  object representations. Note that types containing padding bytes are never
+  trivially equality comparable.
 * ``__is_unbounded_array`` (C++, GNU, Microsoft, Embarcadero)
 * ``__is_union`` (C++, GNU, Microsoft, Embarcadero)
 * ``__is_unsigned`` (C++, Embarcadero):

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


[clang] Revert "[Clang] Reduce the size of Decl and classes derived from it" (PR #88654)

2024-04-14 Thread Nikolas Klauser via cfe-commits

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


[clang] Revert "[Clang] Reduce the size of Decl and classes derived from it" (PR #88654)

2024-04-14 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 created 
https://github.com/llvm/llvm-project/pull/88654

Reverts llvm/llvm-project#87361

On 32 bit platforms there is only a single bit available in the `DeclCtx`, 
resulting in an assertion failure.


>From b243ca1d3616d1dd61b81e3a112707e27cd4c865 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Sun, 14 Apr 2024 12:23:21 +0200
Subject: [PATCH] Revert "[Clang] Reduce the size of Decl and classes derived
 from it (#87361)"

This reverts commit c6f9c84e498ee05a812511ae969773ff166fd25e.
---
 clang/include/clang/AST/DeclBase.h| 72 ---
 clang/lib/AST/DeclBase.cpp| 31 +++---
 clang/lib/Serialization/ASTReaderDecl.cpp |  2 +-
 3 files changed, 35 insertions(+), 70 deletions(-)

diff --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 4bee18767dd11b..858450926455c6 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -268,37 +268,17 @@ class alignas(8) Decl {
   ///   }
   ///   void A::f(); // SemanticDC == namespace 'A'
   ///// LexicalDC == global namespace
+  llvm::PointerUnion DeclCtx;
 
-  // Compress the InvalidDecl and HasAttrs bits into DeclCtx to keep Decl below
-  // 32 bytes in size
-  llvm::PointerIntPair<
-  llvm::PointerIntPair, 1,
-   bool>,
-  1, bool>
-  DeclCtxWithInvalidDeclAndHasAttrs;
-
-  bool isInSemaDC() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
-.getPointer()
-.is();
-  }
-
-  bool isOutOfSemaDC() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
-.getPointer()
-.is();
-  }
+  bool isInSemaDC() const { return DeclCtx.is(); }
+  bool isOutOfSemaDC() const { return DeclCtx.is(); }
 
   MultipleDC *getMultipleDC() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
-.getPointer()
-.get();
+return DeclCtx.get();
   }
 
   DeclContext *getSemanticDC() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
-.getPointer()
-.get();
+return DeclCtx.get();
   }
 
   /// Loc - The location of this decl.
@@ -308,6 +288,14 @@ class alignas(8) Decl {
   LLVM_PREFERRED_TYPE(Kind)
   unsigned DeclKind : 7;
 
+  /// InvalidDecl - This indicates a semantic error occurred.
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned InvalidDecl :  1;
+
+  /// HasAttrs - This indicates whether the decl has attributes or not.
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned HasAttrs : 1;
+
   /// Implicit - Whether this declaration was implicitly generated by
   /// the implementation rather than explicitly written by the user.
   LLVM_PREFERRED_TYPE(bool)
@@ -405,22 +393,21 @@ class alignas(8) Decl {
 protected:
   Decl(Kind DK, DeclContext *DC, SourceLocation L)
   : NextInContextAndBits(nullptr, getModuleOwnershipKindForChildOf(DC)),
-DeclCtxWithInvalidDeclAndHasAttrs({DC, false}, false), Loc(L),
-DeclKind(DK), Implicit(false), Used(false), Referenced(false),
+DeclCtx(DC), Loc(L), DeclKind(DK), InvalidDecl(false), HasAttrs(false),
+Implicit(false), Used(false), Referenced(false),
 TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0),
 IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
 CacheValidAndLinkage(llvm::to_underlying(Linkage::Invalid)) {
-if (StatisticsEnabled)
-  add(DK);
+if (StatisticsEnabled) add(DK);
   }
 
   Decl(Kind DK, EmptyShell Empty)
-  : DeclKind(DK), Implicit(false), Used(false), Referenced(false),
-TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0),
+  : DeclKind(DK), InvalidDecl(false), HasAttrs(false), Implicit(false),
+Used(false), Referenced(false), TopLevelDeclInObjCContainer(false),
+Access(AS_none), FromASTFile(0),
 IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
 CacheValidAndLinkage(llvm::to_underlying(Linkage::Invalid)) {
-if (StatisticsEnabled)
-  add(DK);
+if (StatisticsEnabled) add(DK);
   }
 
   virtual ~Decl();
@@ -533,9 +520,7 @@ class alignas(8) Decl {
 return AccessSpecifier(Access);
   }
 
-  bool hasAttrs() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer().getInt();
-  }
+  bool hasAttrs() const { return HasAttrs; }
 
   void setAttrs(const AttrVec& Attrs) {
 return setAttrsImpl(Attrs, getASTContext());
@@ -564,17 +549,13 @@ class alignas(8) Decl {
   }
 
   template  void dropAttrs() {
-if (!hasAttrs())
-  return;
+if (!HasAttrs) return;
 
 AttrVec  = getAttrs();
 llvm::erase_if(Vec, [](Attr *A) { return isa(A); });
 
-if (Vec.empty()) {
-  auto InnerPtr = DeclCtxWithInvalidDeclAndHasAttrs.getPointer();
-  InnerPtr.setInt(false);
-  DeclCtxWithInvalidDeclAndHasAttrs.setPointer(InnerPtr);
-}
+if (Vec.empty())
+  HasAttrs = false;
   }
 
   template  void dropAttr() { dropAttrs(); }
@@ -609,10 

[clang] [Clang] Reduce the size of Decl and classes derived from it (PR #87361)

2024-04-14 Thread Nikolas Klauser via cfe-commits

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


[clang] [Clang] Reduce the size of Decl and classes derived from it (PR #87361)

2024-04-14 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/87361

>From b8a626116b0719c1acf75e9e7300df8e2bf82f99 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Tue, 2 Apr 2024 18:00:05 +0200
Subject: [PATCH 1/3] [Clang] Reduce the size of Decl and classes derived from
 it

---
 clang/include/clang/AST/DeclBase.h| 66 ++-
 clang/lib/AST/DeclBase.cpp| 29 ++
 clang/lib/Serialization/ASTReaderDecl.cpp |  2 +-
 3 files changed, 62 insertions(+), 35 deletions(-)

diff --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 47ed6d0d1db0df..172bd581b527c8 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -268,17 +268,34 @@ class alignas(8) Decl {
   ///   }
   ///   void A::f(); // SemanticDC == namespace 'A'
   ///// LexicalDC == global namespace
-  llvm::PointerUnion DeclCtx;
+  llvm::PointerIntPair<
+  llvm::PointerIntPair, 1,
+   bool>,
+  1, bool>
+  DeclCtxWithInvalidDeclAndHasAttrs;
 
-  bool isInSemaDC() const { return DeclCtx.is(); }
-  bool isOutOfSemaDC() const { return DeclCtx.is(); }
+  bool isInSemaDC() const {
+return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
+.getPointer()
+.is();
+  }
+
+  bool isOutOfSemaDC() const {
+return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
+.getPointer()
+.is();
+  }
 
   MultipleDC *getMultipleDC() const {
-return DeclCtx.get();
+return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
+.getPointer()
+.get();
   }
 
   DeclContext *getSemanticDC() const {
-return DeclCtx.get();
+return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
+.getPointer()
+.get();
   }
 
   /// Loc - The location of this decl.
@@ -288,14 +305,6 @@ class alignas(8) Decl {
   LLVM_PREFERRED_TYPE(Kind)
   unsigned DeclKind : 7;
 
-  /// InvalidDecl - This indicates a semantic error occurred.
-  LLVM_PREFERRED_TYPE(bool)
-  unsigned InvalidDecl :  1;
-
-  /// HasAttrs - This indicates whether the decl has attributes or not.
-  LLVM_PREFERRED_TYPE(bool)
-  unsigned HasAttrs : 1;
-
   /// Implicit - Whether this declaration was implicitly generated by
   /// the implementation rather than explicitly written by the user.
   LLVM_PREFERRED_TYPE(bool)
@@ -393,21 +402,22 @@ class alignas(8) Decl {
 protected:
   Decl(Kind DK, DeclContext *DC, SourceLocation L)
   : NextInContextAndBits(nullptr, getModuleOwnershipKindForChildOf(DC)),
-DeclCtx(DC), Loc(L), DeclKind(DK), InvalidDecl(false), HasAttrs(false),
-Implicit(false), Used(false), Referenced(false),
+DeclCtxWithInvalidDeclAndHasAttrs({DC, false}, false), Loc(L),
+DeclKind(DK), Implicit(false), Used(false), Referenced(false),
 TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0),
 IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
 CacheValidAndLinkage(llvm::to_underlying(Linkage::Invalid)) {
-if (StatisticsEnabled) add(DK);
+if (StatisticsEnabled)
+  add(DK);
   }
 
   Decl(Kind DK, EmptyShell Empty)
-  : DeclKind(DK), InvalidDecl(false), HasAttrs(false), Implicit(false),
-Used(false), Referenced(false), TopLevelDeclInObjCContainer(false),
-Access(AS_none), FromASTFile(0),
+  : DeclKind(DK), Implicit(false), Used(false), Referenced(false),
+TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0),
 IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
 CacheValidAndLinkage(llvm::to_underlying(Linkage::Invalid)) {
-if (StatisticsEnabled) add(DK);
+if (StatisticsEnabled)
+  add(DK);
   }
 
   virtual ~Decl();
@@ -520,7 +530,7 @@ class alignas(8) Decl {
 return AccessSpecifier(Access);
   }
 
-  bool hasAttrs() const { return HasAttrs; }
+  bool hasAttrs() const { return 
DeclCtxWithInvalidDeclAndHasAttrs.getPointer().getInt(); }
 
   void setAttrs(const AttrVec& Attrs) {
 return setAttrsImpl(Attrs, getASTContext());
@@ -549,13 +559,16 @@ class alignas(8) Decl {
   }
 
   template  void dropAttrs() {
-if (!HasAttrs) return;
+if (!hasAttrs()) return;
 
 AttrVec  = getAttrs();
 llvm::erase_if(Vec, [](Attr *A) { return isa(A); });
 
-if (Vec.empty())
-  HasAttrs = false;
+if (Vec.empty()) {
+  auto InnerPtr = DeclCtxWithInvalidDeclAndHasAttrs.getPointer();
+  InnerPtr.setInt(false);
+  DeclCtxWithInvalidDeclAndHasAttrs.setPointer(InnerPtr);
+}
   }
 
   template  void dropAttr() { dropAttrs(); }
@@ -590,7 +603,10 @@ class alignas(8) Decl {
   /// setInvalidDecl - Indicates the Decl had a semantic error. This
   /// allows for graceful error recovery.
   void setInvalidDecl(bool Invalid = true);
-  bool isInvalidDecl() const { return (bool) InvalidDecl; }
+
+  bool isInvalidDecl() const {
+return DeclCtxWithInvalidDeclAndHasAttrs.getInt();
+  }

[clang] [clang][docs] fix whitespace in AttrDocs.td (PR #88631)

2024-04-14 Thread Nikolas Klauser via cfe-commits

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


[clang] [Clang] Reduce the size of Decl and classes derived from it (PR #87361)

2024-04-13 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/87361

>From b8a626116b0719c1acf75e9e7300df8e2bf82f99 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Tue, 2 Apr 2024 18:00:05 +0200
Subject: [PATCH 1/3] [Clang] Reduce the size of Decl and classes derived from
 it

---
 clang/include/clang/AST/DeclBase.h| 66 ++-
 clang/lib/AST/DeclBase.cpp| 29 ++
 clang/lib/Serialization/ASTReaderDecl.cpp |  2 +-
 3 files changed, 62 insertions(+), 35 deletions(-)

diff --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 47ed6d0d1db0df..172bd581b527c8 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -268,17 +268,34 @@ class alignas(8) Decl {
   ///   }
   ///   void A::f(); // SemanticDC == namespace 'A'
   ///// LexicalDC == global namespace
-  llvm::PointerUnion DeclCtx;
+  llvm::PointerIntPair<
+  llvm::PointerIntPair, 1,
+   bool>,
+  1, bool>
+  DeclCtxWithInvalidDeclAndHasAttrs;
 
-  bool isInSemaDC() const { return DeclCtx.is(); }
-  bool isOutOfSemaDC() const { return DeclCtx.is(); }
+  bool isInSemaDC() const {
+return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
+.getPointer()
+.is();
+  }
+
+  bool isOutOfSemaDC() const {
+return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
+.getPointer()
+.is();
+  }
 
   MultipleDC *getMultipleDC() const {
-return DeclCtx.get();
+return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
+.getPointer()
+.get();
   }
 
   DeclContext *getSemanticDC() const {
-return DeclCtx.get();
+return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
+.getPointer()
+.get();
   }
 
   /// Loc - The location of this decl.
@@ -288,14 +305,6 @@ class alignas(8) Decl {
   LLVM_PREFERRED_TYPE(Kind)
   unsigned DeclKind : 7;
 
-  /// InvalidDecl - This indicates a semantic error occurred.
-  LLVM_PREFERRED_TYPE(bool)
-  unsigned InvalidDecl :  1;
-
-  /// HasAttrs - This indicates whether the decl has attributes or not.
-  LLVM_PREFERRED_TYPE(bool)
-  unsigned HasAttrs : 1;
-
   /// Implicit - Whether this declaration was implicitly generated by
   /// the implementation rather than explicitly written by the user.
   LLVM_PREFERRED_TYPE(bool)
@@ -393,21 +402,22 @@ class alignas(8) Decl {
 protected:
   Decl(Kind DK, DeclContext *DC, SourceLocation L)
   : NextInContextAndBits(nullptr, getModuleOwnershipKindForChildOf(DC)),
-DeclCtx(DC), Loc(L), DeclKind(DK), InvalidDecl(false), HasAttrs(false),
-Implicit(false), Used(false), Referenced(false),
+DeclCtxWithInvalidDeclAndHasAttrs({DC, false}, false), Loc(L),
+DeclKind(DK), Implicit(false), Used(false), Referenced(false),
 TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0),
 IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
 CacheValidAndLinkage(llvm::to_underlying(Linkage::Invalid)) {
-if (StatisticsEnabled) add(DK);
+if (StatisticsEnabled)
+  add(DK);
   }
 
   Decl(Kind DK, EmptyShell Empty)
-  : DeclKind(DK), InvalidDecl(false), HasAttrs(false), Implicit(false),
-Used(false), Referenced(false), TopLevelDeclInObjCContainer(false),
-Access(AS_none), FromASTFile(0),
+  : DeclKind(DK), Implicit(false), Used(false), Referenced(false),
+TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0),
 IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
 CacheValidAndLinkage(llvm::to_underlying(Linkage::Invalid)) {
-if (StatisticsEnabled) add(DK);
+if (StatisticsEnabled)
+  add(DK);
   }
 
   virtual ~Decl();
@@ -520,7 +530,7 @@ class alignas(8) Decl {
 return AccessSpecifier(Access);
   }
 
-  bool hasAttrs() const { return HasAttrs; }
+  bool hasAttrs() const { return 
DeclCtxWithInvalidDeclAndHasAttrs.getPointer().getInt(); }
 
   void setAttrs(const AttrVec& Attrs) {
 return setAttrsImpl(Attrs, getASTContext());
@@ -549,13 +559,16 @@ class alignas(8) Decl {
   }
 
   template  void dropAttrs() {
-if (!HasAttrs) return;
+if (!hasAttrs()) return;
 
 AttrVec  = getAttrs();
 llvm::erase_if(Vec, [](Attr *A) { return isa(A); });
 
-if (Vec.empty())
-  HasAttrs = false;
+if (Vec.empty()) {
+  auto InnerPtr = DeclCtxWithInvalidDeclAndHasAttrs.getPointer();
+  InnerPtr.setInt(false);
+  DeclCtxWithInvalidDeclAndHasAttrs.setPointer(InnerPtr);
+}
   }
 
   template  void dropAttr() { dropAttrs(); }
@@ -590,7 +603,10 @@ class alignas(8) Decl {
   /// setInvalidDecl - Indicates the Decl had a semantic error. This
   /// allows for graceful error recovery.
   void setInvalidDecl(bool Invalid = true);
-  bool isInvalidDecl() const { return (bool) InvalidDecl; }
+
+  bool isInvalidDecl() const {
+return DeclCtxWithInvalidDeclAndHasAttrs.getInt();
+  }

[clang] [Clang] Fix __is_trivially_equaltiy_comparable documentation (PR #88528)

2024-04-12 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 created 
https://github.com/llvm/llvm-project/pull/88528

Currently `__is_trivially_equality_comparable` is documented to return true if 
comparing the value representation is equivalent to calling the comparison 
operator, which is not quite what the trait actually checks. The traits 
actually checks that comparing the object representation is equivalent, which 
means that there cannot be padding bytes in the type.



>From d4cf4c22b40236856d873bf2080060db790a3538 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Fri, 12 Apr 2024 17:36:53 +0200
Subject: [PATCH] [Clang] Fix __is_trivially_equaltiy_comparable documentation

---
 clang/docs/LanguageExtensions.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 7b23e4d1c2f30c..a6942464de5d35 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1640,7 +1640,7 @@ The following type trait primitives are supported by 
Clang. Those traits marked
   were made trivially relocatable via the ``clang::trivial_abi`` attribute.
 * ``__is_trivially_equality_comparable`` (Clang): Returns true if comparing two
   objects of the provided type is known to be equivalent to comparing their
-  value representations.
+  object representations.
 * ``__is_unbounded_array`` (C++, GNU, Microsoft, Embarcadero)
 * ``__is_union`` (C++, GNU, Microsoft, Embarcadero)
 * ``__is_unsigned`` (C++, Embarcadero):

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


[clang] [Clang] Reduce the size of Decl and classes derived from it (PR #87361)

2024-04-12 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/87361

>From b8a626116b0719c1acf75e9e7300df8e2bf82f99 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Tue, 2 Apr 2024 18:00:05 +0200
Subject: [PATCH 1/3] [Clang] Reduce the size of Decl and classes derived from
 it

---
 clang/include/clang/AST/DeclBase.h| 66 ++-
 clang/lib/AST/DeclBase.cpp| 29 ++
 clang/lib/Serialization/ASTReaderDecl.cpp |  2 +-
 3 files changed, 62 insertions(+), 35 deletions(-)

diff --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 47ed6d0d1db0df..172bd581b527c8 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -268,17 +268,34 @@ class alignas(8) Decl {
   ///   }
   ///   void A::f(); // SemanticDC == namespace 'A'
   ///// LexicalDC == global namespace
-  llvm::PointerUnion DeclCtx;
+  llvm::PointerIntPair<
+  llvm::PointerIntPair, 1,
+   bool>,
+  1, bool>
+  DeclCtxWithInvalidDeclAndHasAttrs;
 
-  bool isInSemaDC() const { return DeclCtx.is(); }
-  bool isOutOfSemaDC() const { return DeclCtx.is(); }
+  bool isInSemaDC() const {
+return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
+.getPointer()
+.is();
+  }
+
+  bool isOutOfSemaDC() const {
+return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
+.getPointer()
+.is();
+  }
 
   MultipleDC *getMultipleDC() const {
-return DeclCtx.get();
+return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
+.getPointer()
+.get();
   }
 
   DeclContext *getSemanticDC() const {
-return DeclCtx.get();
+return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
+.getPointer()
+.get();
   }
 
   /// Loc - The location of this decl.
@@ -288,14 +305,6 @@ class alignas(8) Decl {
   LLVM_PREFERRED_TYPE(Kind)
   unsigned DeclKind : 7;
 
-  /// InvalidDecl - This indicates a semantic error occurred.
-  LLVM_PREFERRED_TYPE(bool)
-  unsigned InvalidDecl :  1;
-
-  /// HasAttrs - This indicates whether the decl has attributes or not.
-  LLVM_PREFERRED_TYPE(bool)
-  unsigned HasAttrs : 1;
-
   /// Implicit - Whether this declaration was implicitly generated by
   /// the implementation rather than explicitly written by the user.
   LLVM_PREFERRED_TYPE(bool)
@@ -393,21 +402,22 @@ class alignas(8) Decl {
 protected:
   Decl(Kind DK, DeclContext *DC, SourceLocation L)
   : NextInContextAndBits(nullptr, getModuleOwnershipKindForChildOf(DC)),
-DeclCtx(DC), Loc(L), DeclKind(DK), InvalidDecl(false), HasAttrs(false),
-Implicit(false), Used(false), Referenced(false),
+DeclCtxWithInvalidDeclAndHasAttrs({DC, false}, false), Loc(L),
+DeclKind(DK), Implicit(false), Used(false), Referenced(false),
 TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0),
 IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
 CacheValidAndLinkage(llvm::to_underlying(Linkage::Invalid)) {
-if (StatisticsEnabled) add(DK);
+if (StatisticsEnabled)
+  add(DK);
   }
 
   Decl(Kind DK, EmptyShell Empty)
-  : DeclKind(DK), InvalidDecl(false), HasAttrs(false), Implicit(false),
-Used(false), Referenced(false), TopLevelDeclInObjCContainer(false),
-Access(AS_none), FromASTFile(0),
+  : DeclKind(DK), Implicit(false), Used(false), Referenced(false),
+TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0),
 IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
 CacheValidAndLinkage(llvm::to_underlying(Linkage::Invalid)) {
-if (StatisticsEnabled) add(DK);
+if (StatisticsEnabled)
+  add(DK);
   }
 
   virtual ~Decl();
@@ -520,7 +530,7 @@ class alignas(8) Decl {
 return AccessSpecifier(Access);
   }
 
-  bool hasAttrs() const { return HasAttrs; }
+  bool hasAttrs() const { return 
DeclCtxWithInvalidDeclAndHasAttrs.getPointer().getInt(); }
 
   void setAttrs(const AttrVec& Attrs) {
 return setAttrsImpl(Attrs, getASTContext());
@@ -549,13 +559,16 @@ class alignas(8) Decl {
   }
 
   template  void dropAttrs() {
-if (!HasAttrs) return;
+if (!hasAttrs()) return;
 
 AttrVec  = getAttrs();
 llvm::erase_if(Vec, [](Attr *A) { return isa(A); });
 
-if (Vec.empty())
-  HasAttrs = false;
+if (Vec.empty()) {
+  auto InnerPtr = DeclCtxWithInvalidDeclAndHasAttrs.getPointer();
+  InnerPtr.setInt(false);
+  DeclCtxWithInvalidDeclAndHasAttrs.setPointer(InnerPtr);
+}
   }
 
   template  void dropAttr() { dropAttrs(); }
@@ -590,7 +603,10 @@ class alignas(8) Decl {
   /// setInvalidDecl - Indicates the Decl had a semantic error. This
   /// allows for graceful error recovery.
   void setInvalidDecl(bool Invalid = true);
-  bool isInvalidDecl() const { return (bool) InvalidDecl; }
+
+  bool isInvalidDecl() const {
+return DeclCtxWithInvalidDeclAndHasAttrs.getInt();
+  }

[clang] [C99] Claim conformance for _Complex support (PR #88161)

2024-04-11 Thread Nikolas Klauser via cfe-commits

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

LGTM from my side. I'll leave the conformance test details to the folks who 
know what they're doing.

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


[clang] [C99] Claim conformance for _Complex support (PR #88161)

2024-04-11 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

> > Note that
> > ```c++
> > auto div(_Complex float lhs, _Complex float rhs) {
> >   return lhs / rhs;
> > }
> > 
> > int main() {
> >   return __real div(1.f, 2.f);
> > }
> > ```
> > 
> > 
> > 
> >   
> > 
> > 
> >   
> > 
> > 
> > 
> >   
> > will fail to link on windows due to `__divsc3` not being available. Similar 
> > programs probably also fail due to other compiler-rt functions not being 
> > available.
> 
> I _think_ Clang still gets to claim conformance here because we handle the 
> language side of things correctly and the user is responsible for linking to 
> a runtime library with appropriate support for the platform. However, this 
> sure does straddle the line in some ways, so I could see this being a reason 
> to claim "partial" conformance.

IIRC the problem is that you can't get compiler-rt on windows. If it was just a 
matter of compiling compiler-rt with clang I'd be 100% with you. Partial 
conformance with a note that some operations require compiler-rt functions that 
aren't available on windows seems like a good compromise to me.

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


[clang] [C99] Claim conformance for _Complex support (PR #88161)

2024-04-10 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

Note that
```c++
auto div(_Complex float lhs, _Complex float rhs) {
  return lhs / rhs;
}

int main() {
  return __real div(1.f, 2.f);
}
```
will fail to link on windows due to `__divsc3` not being available. Similar 
programs probably also fail due to other compiler-rt functions not being 
available.

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


[clang] [Clang] Reduce the size of Decl and classes derived from it (PR #87361)

2024-04-08 Thread Nikolas Klauser via cfe-commits


@@ -268,17 +268,34 @@ class alignas(8) Decl {
   ///   }
   ///   void A::f(); // SemanticDC == namespace 'A'
   ///// LexicalDC == global namespace
-  llvm::PointerUnion DeclCtx;
+  llvm::PointerIntPair<

philnik777 wrote:

IDK. I'm personally not a huge fan of manual bit twiddling, since it's way to 
easy to get things wrong. I much rather let the compiler do it.

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


[clang] [Clang] Reduce the size of Decl and classes derived from it (PR #87361)

2024-04-08 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/87361

>From b8a626116b0719c1acf75e9e7300df8e2bf82f99 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Tue, 2 Apr 2024 18:00:05 +0200
Subject: [PATCH 1/2] [Clang] Reduce the size of Decl and classes derived from
 it

---
 clang/include/clang/AST/DeclBase.h| 66 ++-
 clang/lib/AST/DeclBase.cpp| 29 ++
 clang/lib/Serialization/ASTReaderDecl.cpp |  2 +-
 3 files changed, 62 insertions(+), 35 deletions(-)

diff --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 47ed6d0d1db0df..172bd581b527c8 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -268,17 +268,34 @@ class alignas(8) Decl {
   ///   }
   ///   void A::f(); // SemanticDC == namespace 'A'
   ///// LexicalDC == global namespace
-  llvm::PointerUnion DeclCtx;
+  llvm::PointerIntPair<
+  llvm::PointerIntPair, 1,
+   bool>,
+  1, bool>
+  DeclCtxWithInvalidDeclAndHasAttrs;
 
-  bool isInSemaDC() const { return DeclCtx.is(); }
-  bool isOutOfSemaDC() const { return DeclCtx.is(); }
+  bool isInSemaDC() const {
+return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
+.getPointer()
+.is();
+  }
+
+  bool isOutOfSemaDC() const {
+return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
+.getPointer()
+.is();
+  }
 
   MultipleDC *getMultipleDC() const {
-return DeclCtx.get();
+return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
+.getPointer()
+.get();
   }
 
   DeclContext *getSemanticDC() const {
-return DeclCtx.get();
+return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
+.getPointer()
+.get();
   }
 
   /// Loc - The location of this decl.
@@ -288,14 +305,6 @@ class alignas(8) Decl {
   LLVM_PREFERRED_TYPE(Kind)
   unsigned DeclKind : 7;
 
-  /// InvalidDecl - This indicates a semantic error occurred.
-  LLVM_PREFERRED_TYPE(bool)
-  unsigned InvalidDecl :  1;
-
-  /// HasAttrs - This indicates whether the decl has attributes or not.
-  LLVM_PREFERRED_TYPE(bool)
-  unsigned HasAttrs : 1;
-
   /// Implicit - Whether this declaration was implicitly generated by
   /// the implementation rather than explicitly written by the user.
   LLVM_PREFERRED_TYPE(bool)
@@ -393,21 +402,22 @@ class alignas(8) Decl {
 protected:
   Decl(Kind DK, DeclContext *DC, SourceLocation L)
   : NextInContextAndBits(nullptr, getModuleOwnershipKindForChildOf(DC)),
-DeclCtx(DC), Loc(L), DeclKind(DK), InvalidDecl(false), HasAttrs(false),
-Implicit(false), Used(false), Referenced(false),
+DeclCtxWithInvalidDeclAndHasAttrs({DC, false}, false), Loc(L),
+DeclKind(DK), Implicit(false), Used(false), Referenced(false),
 TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0),
 IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
 CacheValidAndLinkage(llvm::to_underlying(Linkage::Invalid)) {
-if (StatisticsEnabled) add(DK);
+if (StatisticsEnabled)
+  add(DK);
   }
 
   Decl(Kind DK, EmptyShell Empty)
-  : DeclKind(DK), InvalidDecl(false), HasAttrs(false), Implicit(false),
-Used(false), Referenced(false), TopLevelDeclInObjCContainer(false),
-Access(AS_none), FromASTFile(0),
+  : DeclKind(DK), Implicit(false), Used(false), Referenced(false),
+TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0),
 IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
 CacheValidAndLinkage(llvm::to_underlying(Linkage::Invalid)) {
-if (StatisticsEnabled) add(DK);
+if (StatisticsEnabled)
+  add(DK);
   }
 
   virtual ~Decl();
@@ -520,7 +530,7 @@ class alignas(8) Decl {
 return AccessSpecifier(Access);
   }
 
-  bool hasAttrs() const { return HasAttrs; }
+  bool hasAttrs() const { return 
DeclCtxWithInvalidDeclAndHasAttrs.getPointer().getInt(); }
 
   void setAttrs(const AttrVec& Attrs) {
 return setAttrsImpl(Attrs, getASTContext());
@@ -549,13 +559,16 @@ class alignas(8) Decl {
   }
 
   template  void dropAttrs() {
-if (!HasAttrs) return;
+if (!hasAttrs()) return;
 
 AttrVec  = getAttrs();
 llvm::erase_if(Vec, [](Attr *A) { return isa(A); });
 
-if (Vec.empty())
-  HasAttrs = false;
+if (Vec.empty()) {
+  auto InnerPtr = DeclCtxWithInvalidDeclAndHasAttrs.getPointer();
+  InnerPtr.setInt(false);
+  DeclCtxWithInvalidDeclAndHasAttrs.setPointer(InnerPtr);
+}
   }
 
   template  void dropAttr() { dropAttrs(); }
@@ -590,7 +603,10 @@ class alignas(8) Decl {
   /// setInvalidDecl - Indicates the Decl had a semantic error. This
   /// allows for graceful error recovery.
   void setInvalidDecl(bool Invalid = true);
-  bool isInvalidDecl() const { return (bool) InvalidDecl; }
+
+  bool isInvalidDecl() const {
+return DeclCtxWithInvalidDeclAndHasAttrs.getInt();
+  }

[clang] [clang] Reject VLAs in `__is_layout_compatible()` (PR #87737)

2024-04-05 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

I think clang should reject incomplete types when the standard says so. It 
doesn't seem particularly useful to accept some special cases but reject 
incomplete types in general. All the traits should probably be audited once. It 
looks like Clang has other problematic cases: https://godbolt.org/z/hajWfq7a6

I don't really care whether Clang should reject VLAs when using the builtin, 
since the trait will be used through some template and that's rejected that 
anyways. FWIW it'd be more consistent, since in my mind `__some_type_trait(T, 
U)` behaves the same as `std::some_type_trait_v`.

Flexible arrays are accepted because they are arrays of unknown bounds in the 
type system, which is part of the standard. The extension is only that they 
aren't rejected at the end of a struct and have some special meaning there. 
They should definitely not be rejected.


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


[clang] [Clang] Reduce the size of Decl and classes derived from it (PR #87361)

2024-04-02 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 created 
https://github.com/llvm/llvm-project/pull/87361

Class | Old size (in bytes) | New size (in bytes)
--|-|
Decl  | 40  | 32
AccessSpecDecl| 40  | 40
BlockDecl | 128 | 120
CapturedDecl  | 88  | 80
EmptyDecl | 40  | 32
ExportDecl| 80  | 72
ExternCContextDecl| 72  | 64
FileScopeAsmDecl  | 56  | 48
FriendDecl| 64  | 56
FriendTemplateDecl| 64  | 64
ImplicitConceptSpecializationDecl | 40  | 40
ImportDecl| 56  | 48
LifetimeExtendedTemporaryDecl | 72  | 64
LinkageSpecDecl   | 80  | 72
NamedDecl | 48  | 40
ObjCPropertyImplDecl  | 96  | 88
PragmaCommentDecl | 40  | 40
PragmaDetectMismatchDecl  | 48  | 40
RequiresExprBodyDecl  | 72  | 64
StaticAssertDecl  | 64  | 56
TopLevelStmtDecl  | 88  | 80
TranslationUnitDecl   | 104 | 96
BaseUsingDecl | 56  | 48
UsingDecl | 88  | 80
UsingEnumDecl | 72  | 64
HLSLBufferDecl| 96  | 88
LabelDecl | 80  | 72
NamespaceAliasDecl| 96  | 88
NamespaceDecl | 112 | 104
ObjCCompatibleAliasDecl   | 56  | 48
ObjCContainerDecl | 88  | 80
ObjCMethodDecl| 136 | 128
ObjCPropertyDecl  | 128 | 120
TemplateDecl  | 64  | 56
BuiltinTemplateDecl   | 72  | 64
TypeDecl  | 64  | 56
UnresolvedUsingIfExistsDecl   | 48  | 40
UsingDirectiveDecl| 88  | 80
UsingPackDecl | 64  | 56
UsingShadowDecl   | 80  | 72
ValueDecl | 56  | 48

When parsing libc++'s `` header the used memory is reduced from 42.8MB 
to 42.5MB.



>From b8a626116b0719c1acf75e9e7300df8e2bf82f99 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Tue, 2 Apr 2024 18:00:05 +0200
Subject: [PATCH] [Clang] Reduce the size of Decl and classes derived from it

---
 clang/include/clang/AST/DeclBase.h| 66 ++-
 clang/lib/AST/DeclBase.cpp| 29 ++
 clang/lib/Serialization/ASTReaderDecl.cpp |  2 +-
 3 files changed, 62 insertions(+), 35 deletions(-)

diff --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 47ed6d0d1db0df..172bd581b527c8 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -268,17 +268,34 @@ class alignas(8) Decl {
   ///   }
   ///   void A::f(); // SemanticDC == namespace 'A'
   ///// LexicalDC == global namespace
-  llvm::PointerUnion DeclCtx;
+  llvm::PointerIntPair<
+  llvm::PointerIntPair, 1,
+   bool>,
+  1, bool>
+  DeclCtxWithInvalidDeclAndHasAttrs;
 
-  bool isInSemaDC() const { return DeclCtx.is(); }
-  bool isOutOfSemaDC() const { return DeclCtx.is(); }
+  bool isInSemaDC() const {
+return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
+.getPointer()
+.is();
+  }
+
+  bool isOutOfSemaDC() const {
+return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
+.getPointer()
+.is();
+  }
 
   MultipleDC *getMultipleDC() const {
-return DeclCtx.get();
+return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
+.getPointer()
+.get();
   }
 
   DeclContext *getSemanticDC() const {
-return DeclCtx.get();
+return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
+.getPointer()
+.get();
   }
 
   /// Loc - The location of this decl.
@@ -288,14 +305,6 @@ class alignas(8) Decl {
   LLVM_PREFERRED_TYPE(Kind)
   unsigned DeclKind : 7;
 
-  /// InvalidDecl - This indicates a semantic error occurred.
-  LLVM_PREFERRED_TYPE(bool)
-  unsigned InvalidDecl :  1;
-
-  /// HasAttrs - This indicates whether the decl has attributes or not.
-  LLVM_PREFERRED_TYPE(bool)
-  unsigned HasAttrs : 1;
-
   /// Implicit - Whether this 

[clang] [Clang] Fix __is_array returning true for zero-sized arrays (PR #86652)

2024-04-01 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

I'd personally be fine with deprecating it. As I said above, we use it in 
libc++ for padding inside `string` like
```c++
struct short_string {
  ;
  char padding[sizeof(value_type) - 1];
  ;
};
```
That could be refactored relatively easily as
```c++
template 
struct padding_t {
  char data[Size];
};

template <>
struct padding_t<0> {};

struct short_string {
  ;
  [[no_unique_address]] padding_t padding;
  ;
};

```
so I don't think that's a use-case worth keeping the extension for.

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


[clang] [Headers] Don't declare unreachable() from stddef.h in C++ (PR #86748)

2024-03-29 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

> Re: there being observable differences between a header in C vs C++ mode, 
> that's already a thing.
> 
> The definition for `isinf` in math.h is specified to be a macro in C, but 
> specified to be a function in C++. We're already doing `#ifdef __cplusplus` 
> for that (see 
> https://github.com/llvm/llvm-project/blob/main/libc/include/llvm-libc-macros/math-macros.h),
>  and other libc's do similar (see `iszero` in glibc).

That's actually really bad. Both libc++ and libstdc++ assume that these are 
either not provided at all by the libc or are macros. This will inevitably lead 
to ambiguous overloads.

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


[clang] [Headers] Don't declare unreachable() from stddef.h in C++ (PR #86748)

2024-03-29 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

I mean that `stddef.h` would be modified to provide it as a function instead of 
a macro. In C++ it would simply never be a macro.

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


[clang] [Headers] Don't declare unreachable() from stddef.h in C++ (PR #86748)

2024-03-29 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

> I can see WG21 solving this either by removing `unreachable` from `cstddef` 
> or by requiring `utility` to guard against the macro via implementation magic 
> (personally, I think `utility` should guard against it because of users 
> including `stddef.h` directly) and it would be nice to know which direction 
> the committee is leaning before we get too far into a solution.

I'm not sure whether you mean it, but I'd expect that it's handled like 
`signbit` and friends - they are functions instead of macros. For libc++ that 
would simply be `#undef unreachable`,  `#include <__utility/unreachable.h>` and 
`using std::unreachable`.


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


[clang] [Headers] Don't declare unreachable() from stddef.h in C++ (PR #86748)

2024-03-29 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

> `unreachable` is morally similar to `offsetof` in that it's a macro interface 
> where the implementation can give better results by expanding to a builtin 
> than a library is likely to be able to give via a naive implementation, but 
> the interfaces _can_ be provided by a CRT.

FWIW I don't think they are morally similar. `unreachable` could be implemented 
in very different ways. Consider a libc which tries to terminate on UB instead 
of letting the compiler optimize things away (e.g. a debug mode). Then the 
Clang implementation is not at all what the libc would do.


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


[clang] [Clang] Fix __is_array returning true for zero-sized arrays (PR #86652)

2024-03-28 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

Another option would be to to not acknowledge zero-sized arrays in the type 
traits at all, just like vector types: https://godbolt.org/z/aP685vz8q. That 
may be the most consistent stance on this. Basically "It's non-standard and 
doesn't fit neatly in any of the standard categories, so it's in no category at 
all."

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


[clang] [Clang] Fix __is_array returning true for zero-sized arrays (PR #86652)

2024-03-28 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

> I wonder if we should be considering making zero-length arrays into a 
> non-conforming extension behind a flag? e.g., `-fzero-sized-arrays` and then 
> it does report true for `__is_array`, `__is_bounded_array`, and handles 
> template specializations, etc as though it were really an array. That solves 
> two problems: 1) we can make the feature regular as opposed to having so many 
> sharp edges, 2) it pushes a surprising and questionable extension behind an 
> opt-in feature flag, and it creates at least one problem: 1) potentially 
> would change behavior of existing code in C++. So maybe this isn't a tenable 
> idea, but do we think it's worth exploring?

I think it may be worth exploring, but I'm not sure it's feasible. We've been 
using them accidentally a lot in the test suite in libc++ simply because it's 
really easy to miss that it's an extension, and we're also using it in our 
`string` implementation for padding.

> > My natural inclination is that it is array-like, but... that just makes me 
> > want `__is_array` to return `true` for it all the more.
> 
> Yes. An array is an array, regardless of its size. The size is just a storage 
> characteristic. It'd almost be like arguing that `NaN` isn't a float.

I don't think the float analogy really works here. The fact is that zero-sized 
arrays aren't acknowledged as being valid by the standard, so they don't behave 
like other arrays. It's _not_ just a storage characteristic. Having 
`-ffast-math` and then passing `NAN` somewhere seems like a better analogy to 
me. Things are mostly treated as if `NAN` didn't exist, and `NAN` also doesn't 
work like other floats.

> > I wonder if we should be considering making zero-length arrays into a 
> > non-conforming extension behind a flag?
> 
> It was never as simple as zero-length arrays. It was also _trailing arrays of 
> any size_ in structures. Those extensions create huge problems with being 
> able to reason about the characteristics of arrays, and we do have a flag for 
> this: `-fstrict-flex-arrays=3`. It is designed to disable all of the "treat 
> it like a flexible array" logic for the old "fake flexible array" objects. 
> But a flexible array is _still an array_. And also note that its size can 
> _change at runtime_ (see the `counted_by` attribute), which even more clearly 
> argues that you can't claim a flexible array isn't an array.

I'm not sure how the array being able to change its size at runtime makes it 
harder to claim it isn't one? non-zero-sized arrays don't do that. It's 
actually another thing that is different from the rest of the arrays.
I'm also not sure that it makes a ton of sense to talk about flexible arrays, 
since they aren't part of the type system, but `T[0]` happen to become flexible 
arrays if it is at the end of a struct (IIUC).

Another option (that I haven't thought deeply about): Make `T[0]` not be a type 
at all, i.e. make it illegal to `decltype`, `sizeof` etc. uses of it. I don't 
know how breaking that would be, and it's probably just as confusing as the 
current state of things, or even more so. Just wanted to throw it out.


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


[clang] [Clang] Fix __is_array returning true for zero-sized arrays (PR #86652)

2024-03-26 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

> This doesn't leave us with good options, does it? :-(

Not really. Zero-sized arrays should probably have been supported by C++ all 
along, but it's too late to change it now.

> I think we need to consider the following things:
> 
> * Should `Ty[0]` and `Ty[]` be handled the same way? (Remember, we 
> support `[0]` in structures as a sort of flexible array member and we support 
> flexible array members in C++ as an extension.)

I'm not sure what you're referring to. AFAICT `T[]` at the end of a struct 
denotes a flexible array member, but `T[0]` doesn't. Or does it?

> * We should probably change the value of `__is_bounded_array` at the same 
> time as `__is_array`.

Yes. I'll update the PR accordingly.

> * What should the behavior of `__is_aggregate` be?

I guess it should be true? I can't think of any case where a zero-sized array 
would be different from a non-zero-sized one at least. I don't have a strong 
opinion either way though.

> * What about other type traits (`__is_compound`, `__is_abstract`, etc)? 
> Basically, what's the principle we're using for this type?

Maybe we could think of it as array-like? i.e. it has the same traits as an 
array except that it's not one. I think the semantics only really break down 
for array-specific features. Just to get a sense, I've gone through a few 
traits:
- `is_compound`: it seems pretty clear to me that it is a compound type, since 
`T[0]` is a distinct type from `T`, but contains a type `T` in its definition.
- `is_class`: It seems pretty clear to me that it's not a class. I don't think 
anybody would disagree here.
- `is_abstract`: You can define a variable of it, so it's not. It's also not a 
class type.
- `is_object`: I think it is, but this could be argued either way. The best 
thing I could come up with is that it's closer to an array than it is to a 
function or reference type.

`is_empty` seems like an interesting case. It's the smallest type there is, 
with `sizeof(int[0]) == 0`, but it's not considered empty by any 
implementation. MSVC rejects the `sizeof` call though. I think it shouldn't be 
considered empty though, since `is_empty` kind-of implies that the type is a 
class type.

> 
> > > > We don't use the trait currently in libc++ because of this bug and GCC 
> > > > only added it in trunk (and have the same bug), so probably not.
> > > 
> > > 
> > > For example, it seems to be used in Unreal Engine: 
> > > https://github.com/windystrife/UnrealEngine_NVIDIAGameWorks/blob/b50e6338a7c5b26374d66306ebc7807541ff815e/Engine/Source/Runtime/Core/Public/Templates/UnrealTemplate.h#L128
> > 
> > 
> > If you think it's a significant enough change that we should add an ABI tag 
> > I can do that.
> 
> I don't have a good feeling one way or the other yet, so let's hold off for 
> the moment and see what the final scope of the changes are before making a 
> decision.

Sounds good.

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


[libcxx] [libunwind] [DRAFT][libc++] Switch FreeBSD to C++26 (PR #86658)

2024-03-26 Thread Nikolas Klauser via cfe-commits

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

LGTM with the libunwind changes removed.

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


[libcxx] [libunwind] [DRAFT][libc++] Switch FreeBSD to C++26 (PR #86658)

2024-03-26 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

Yes, it would be the only buildkite one (AFAIK). I don't think that would make 
much of a difference though.


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


[libcxx] [libunwind] [DRAFT][libc++] Switch FreeBSD to C++26 (PR #86658)

2024-03-26 Thread Nikolas Klauser via cfe-commits


@@ -39,6 +39,9 @@
 # if defined(__HAIKU__)
 #  define _LIBUNWIND_TARGET_HAIKU 1
 # endif
+#if defined(__FreeBSD__)

philnik777 wrote:

Are these changes related?

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


[libcxx] [libunwind] [DRAFT][libc++] Switch FreeBSD to C++26 (PR #86658)

2024-03-26 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

The C++26 job is part of the first jobs that get run. Did you just miss it, or 
do you mean something else?

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


[clang] [Clang] Fix __is_array returning true for zero-sized arrays (PR #86652)

2024-03-26 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

> > According to the spec it's ill-formed, so I'm not sure it falls under any 
> > sensible category.
> 
> It's an extension we support so it's up to us to decide what sensible is.

Sure. If we end up putting it in the array category we should probably 
coordinate with GCC.

> > For T[0] this returns false.
> 
> Understood, but why is this not the bug to be fixed? (It would also fix the 
> `takes_an_array` case as well.)

Because I don't think we can. AFAICT this is valid C++:
```c++
template 
int func() {
  return 1;
}

template 
int func() {
  return 0;
}
```
If clang accepted `int[0]` in this context the observable behaviour would 
change.

> > We don't use the trait currently in libc++ because of this bug and GCC only 
> > added it in trunk (and have the same bug), so probably not.
> 
> For example, it seems to be used in Unreal Engine: 
> https://github.com/windystrife/UnrealEngine_NVIDIAGameWorks/blob/b50e6338a7c5b26374d66306ebc7807541ff815e/Engine/Source/Runtime/Core/Public/Templates/UnrealTemplate.h#L128

If you think it's a significant enough change that we should add an ABI tag I 
can do that.


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


[clang] [Clang] Fix __is_array returning true for zero-sized arrays (PR #86652)

2024-03-26 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

> My primary question is: then what is it?
> 
> We return true for `__is_aggregrate` (https://godbolt.org/z/67zjeo7Mj), and 
> an aggregate is an array or class type 
> (https://eel.is/c++draft/dcl.init.aggr#1). This isn't a class type... but it 
> is an aggregate... so it must be an array? (We also don't claim it's a 
> pointer or a reference currently... so this thing will be basically invisible 
> to type traits.)

According to the spec it's ill-formed, so I'm not sure it falls under any 
sensible category.

> I would think it is an array given that it uses array syntax for declarations 
> and array semantics for accesses, but it's also not an array that's usable so 
> I can see why others say it's not an array. Personally, I think Clang's 
> behavior here makes the most sense -- we claim it's an array, we also claim 
> it's a bounded array, and we claim its extent is zero 
> (https://godbolt.org/z/4GdYTh4GG), and that matches the declaration for the 
> type. So with this change, I'm worried about how type traits can possibly 
> reason about this type -- I'd like to understand better why other 
> implementations decided this isn't an array and what it's classified as with 
> their type traits. Assuming that logic is compelling, there's more work 
> needed here to handle things like claiming it's a bounded array but not an 
> array.

For MSVC it's probably because they don't support `T[0]`. The main reason I 
don't think it should be considered an array for the type traits is that it 
doesn't behave like other arrays. e.g. the implementation that's used without 
the builtin is
```c++
template 
inline constexpr bool is_array_v = false;

template 
inline constexpr bool is_array_v = true;

template 
inline constexpr bool is_array_v = true;
```

For `T[0]` this returns false. 

Another example

> Also, do we need an ABI tag for folks to get the old behavior given that this 
> change almost certainly will impact ABI through type traits?

We don't use the trait currently in libc++ because of this bug and GCC only 
added it in trunk (and have the same bug), so probably not.


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


[clang] [Clang] Fix __is_array returning true for zero-sized arrays (PR #86652)

2024-03-26 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 created 
https://github.com/llvm/llvm-project/pull/86652

Fixes #54705


>From 90f88bdac3dc40635c58f3f67e29354e6a32896e Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Tue, 26 Mar 2024 12:23:24 +0100
Subject: [PATCH] [Clang] Fix __is_array returning true for zero-sized arrays

---
 clang/docs/ReleaseNotes.rst| 2 ++
 clang/lib/Sema/SemaExprCXX.cpp | 4 
 clang/test/SemaCXX/type-traits.cpp | 4 +++-
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7fbe2fec6ca065..e6682028537101 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -345,6 +345,8 @@ Bug Fixes in This Version
 - Fixes an assertion failure on invalid code when trying to define member
   functions in lambdas.
 
+- ``__is_array`` no longer returns ``true`` for zero-sized arrays. Fixes 
(#GH54705).
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index c34a40fa7c81ac..93d2b4b259fbc3 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5143,6 +5143,10 @@ static bool EvaluateUnaryTypeTrait(Sema , TypeTrait 
UTT,
   case UTT_IsFloatingPoint:
 return T->isFloatingType();
   case UTT_IsArray:
+// zero-sized arrays aren't considered arrays in partial specializations,
+// so __is_array shouldn't consider them arrays either.
+if (const auto* CAT = C.getAsConstantArrayType(T))
+  return CAT->getSize() != 0;
 return T->isArrayType();
   case UTT_IsBoundedArray:
 if (!T->isVariableArrayType()) {
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index 14ec17989ec7c7..49df4b668513c0 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -25,6 +25,7 @@ typedef Empty EmptyArMB[1][2];
 typedef int Int;
 typedef Int IntAr[10];
 typedef Int IntArNB[];
+typedef Int IntArZero[0];
 class Statics { static int priv; static NonPOD np; };
 union EmptyUnion {};
 union IncompleteUnion; // expected-note {{forward declaration of 
'IncompleteUnion'}}
@@ -685,6 +686,7 @@ void is_array()
 {
   static_assert(__is_array(IntAr));
   static_assert(__is_array(IntArNB));
+  static_assert(!__is_array(IntArZero));
   static_assert(__is_array(UnionAr));
 
   static_assert(!__is_array(void));
@@ -1804,7 +1806,7 @@ void is_layout_compatible(int n)
   static_assert(!__is_layout_compatible(EnumForward, int));
   static_assert(!__is_layout_compatible(EnumClassForward, int));
   // FIXME: the following should be rejected (array of unknown bound and void 
are the only allowed incomplete types)
-  static_assert(__is_layout_compatible(CStructIncomplete, CStructIncomplete)); 
+  static_assert(__is_layout_compatible(CStructIncomplete, CStructIncomplete));
   static_assert(!__is_layout_compatible(CStruct, CStructIncomplete));
   static_assert(__is_layout_compatible(CStructIncomplete[2], 
CStructIncomplete[2]));
 }

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


[clang] [clang] Accept lambdas in C++03 as an extensions (PR #73376)

2024-03-21 Thread Nikolas Klauser via cfe-commits

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


[clang] [clang] Accept lambdas in C++03 as an extensions (PR #73376)

2024-03-20 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/73376

>From 4d0e485f11fc352ff138268698f776d08c2136b1 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Sat, 25 Nov 2023 04:00:57 +0100
Subject: [PATCH] [clang] Accept lambdas in C++03 as an extensions

This is a fairly simple extension, but makes the life for people who
have to support C++03 a lot easier. As a nice bonus, this also improves
diagnostics, since lambdas are now properly recognized when parsing
C++03 code.
---
 clang/docs/LanguageExtensions.rst |  73 ++-
 clang/docs/ReleaseNotes.rst   |   2 +
 .../clang/Basic/DiagnosticParseKinds.td   |   1 +
 clang/include/clang/Basic/Features.def|   1 +
 clang/lib/Parse/ParseExpr.cpp |   2 +-
 clang/lib/Parse/ParseExprCXX.cpp  |   9 +-
 clang/lib/Parse/ParseInit.cpp |   2 +-
 clang/lib/Sema/SemaDecl.cpp   |   2 +-
 clang/lib/Sema/SemaDeclCXX.cpp|   3 +-
 clang/test/Lexer/has_extension_cxx.cpp|   5 +
 .../OpenMP/declare_reduction_messages.cpp |  14 +--
 clang/test/OpenMP/openmp_check.cpp|   2 +-
 clang/test/Parser/cxx03-lambda-extension.cpp  |   5 +
 .../test/Parser/cxx0x-lambda-expressions.cpp  | 116 +++---
 clang/test/Parser/cxx2b-lambdas.cpp   |  45 +--
 .../Parser/objcxx-lambda-expressions-neg.mm   |   9 +-
 clang/test/ParserHLSL/group_shared.hlsl   |   4 +-
 clang/test/SemaCXX/cxx2a-template-lambdas.cpp |  26 ++--
 clang/test/SemaCXX/lambda-expressions.cpp |  64 ++
 .../SemaCXX/lambda-implicit-this-capture.cpp  |   1 +
 clang/test/SemaCXX/lambda-invalid-capture.cpp |   1 +
 clang/test/SemaCXX/new-delete.cpp |   7 +-
 22 files changed, 213 insertions(+), 181 deletions(-)
 create mode 100644 clang/test/Parser/cxx03-lambda-extension.cpp

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 13d7261d83d7f1..201a4c27f7dd8b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1459,40 +1459,45 @@ More information could be found `here 

 Language Extensions Back-ported to Previous Standards
 =
 
-==  
= =
-FeatureFeature Test Macro   
Introduced In Backported To
-==  
= =
-variadic templates __cpp_variadic_templates C++11  
   C++03
-Alias templates__cpp_alias_templatesC++11  
   C++03
-Non-static data member initializers__cpp_nsdmi  C++11  
   C++03
-Range-based ``for`` loop   __cpp_range_based_forC++11  
   C++03
-RValue references  __cpp_rvalue_references  C++11  
   C++03
-Attributes __cpp_attributes C++11  
   C++03
-variable templates __cpp_variable_templates C++14  
   C++03
-Binary literals__cpp_binary_literalsC++14  
   C++03
-Relaxed constexpr  __cpp_constexpr  C++14  
   C++11
-``if constexpr``   __cpp_if_constexpr   C++17  
   C++11
-fold expressions   __cpp_fold_expressions   C++17  
   C++03
-Lambda capture of \*this by value  __cpp_capture_star_this  C++17  
   C++11
-Attributes on enums__cpp_enumerator_attributes  C++17  
   C++03
-Guaranteed copy elision__cpp_guaranteed_copy_elisionC++17  
   C++03
-Hexadecimal floating literals  __cpp_hex_float  C++17  
   C++03
-``inline`` variables   __cpp_inline_variables   C++17  
   C++03
-Attributes on namespaces   __cpp_namespace_attributes   C++17  
   C++11
-Structured bindings__cpp_structured_bindingsC++17  
   C++03
-template template arguments__cpp_template_template_args C++17  
   C++03
-``static operator[]``  __cpp_multidimensional_subscript C++20  
   C++03
-Designated initializers__cpp_designated_initializersC++20  
   C++03
-Conditional ``explicit``   __cpp_conditional_explicit   C++20  
   C++03
-``using enum`` __cpp_using_enum C++20  
   C++03
-``if consteval``   __cpp_if_consteval   C++23  
   C++20
-``static operator()``  __cpp_static_call_operator   C++23  
   C++03
-Attributes on 

[clang] [clang] Accept lambdas in C++03 as an extensions (PR #73376)

2024-03-17 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/73376

>From 3caa29d68939fec7fcd11bc699c01a74ab1f7d2a Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Sat, 25 Nov 2023 04:00:57 +0100
Subject: [PATCH] [clang] Accept lambdas in C++03 as an extensions

This is a fairly simple extension, but makes the life for people who
have to support C++03 a lot easier. As a nice bonus, this also improves
diagnostics, since lambdas are now properly recognized when parsing
C++03 code.
---
 clang/docs/LanguageExtensions.rst |  73 ++-
 clang/docs/ReleaseNotes.rst   |   2 +
 .../clang/Basic/DiagnosticParseKinds.td   |   1 +
 clang/include/clang/Basic/Features.def|   1 +
 clang/lib/Parse/ParseExpr.cpp |   2 +-
 clang/lib/Parse/ParseExprCXX.cpp  |   9 +-
 clang/lib/Parse/ParseInit.cpp |   2 +-
 clang/lib/Sema/SemaDecl.cpp   |   2 +-
 clang/lib/Sema/SemaDeclCXX.cpp|   3 +-
 clang/test/Lexer/has_extension_cxx.cpp|   5 +
 .../OpenMP/declare_reduction_messages.cpp |  14 +--
 clang/test/OpenMP/openmp_check.cpp|   2 +-
 clang/test/Parser/cxx03-lambda-extension.cpp  |   5 +
 .../test/Parser/cxx0x-lambda-expressions.cpp  | 116 +++---
 clang/test/Parser/cxx2b-lambdas.cpp   |  43 +--
 .../Parser/objcxx-lambda-expressions-neg.mm   |   9 +-
 clang/test/ParserHLSL/group_shared.hlsl   |   4 +-
 clang/test/SemaCXX/cxx2a-template-lambdas.cpp |  26 ++--
 clang/test/SemaCXX/lambda-expressions.cpp |  63 ++
 .../SemaCXX/lambda-implicit-this-capture.cpp  |   1 +
 clang/test/SemaCXX/lambda-invalid-capture.cpp |   1 +
 clang/test/SemaCXX/new-delete.cpp |   7 +-
 22 files changed, 210 insertions(+), 181 deletions(-)
 create mode 100644 clang/test/Parser/cxx03-lambda-extension.cpp

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 13d7261d83d7f1..201a4c27f7dd8b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1459,40 +1459,45 @@ More information could be found `here 

 Language Extensions Back-ported to Previous Standards
 =
 
-==  
= =
-FeatureFeature Test Macro   
Introduced In Backported To
-==  
= =
-variadic templates __cpp_variadic_templates C++11  
   C++03
-Alias templates__cpp_alias_templatesC++11  
   C++03
-Non-static data member initializers__cpp_nsdmi  C++11  
   C++03
-Range-based ``for`` loop   __cpp_range_based_forC++11  
   C++03
-RValue references  __cpp_rvalue_references  C++11  
   C++03
-Attributes __cpp_attributes C++11  
   C++03
-variable templates __cpp_variable_templates C++14  
   C++03
-Binary literals__cpp_binary_literalsC++14  
   C++03
-Relaxed constexpr  __cpp_constexpr  C++14  
   C++11
-``if constexpr``   __cpp_if_constexpr   C++17  
   C++11
-fold expressions   __cpp_fold_expressions   C++17  
   C++03
-Lambda capture of \*this by value  __cpp_capture_star_this  C++17  
   C++11
-Attributes on enums__cpp_enumerator_attributes  C++17  
   C++03
-Guaranteed copy elision__cpp_guaranteed_copy_elisionC++17  
   C++03
-Hexadecimal floating literals  __cpp_hex_float  C++17  
   C++03
-``inline`` variables   __cpp_inline_variables   C++17  
   C++03
-Attributes on namespaces   __cpp_namespace_attributes   C++17  
   C++11
-Structured bindings__cpp_structured_bindingsC++17  
   C++03
-template template arguments__cpp_template_template_args C++17  
   C++03
-``static operator[]``  __cpp_multidimensional_subscript C++20  
   C++03
-Designated initializers__cpp_designated_initializersC++20  
   C++03
-Conditional ``explicit``   __cpp_conditional_explicit   C++20  
   C++03
-``using enum`` __cpp_using_enum C++20  
   C++03
-``if consteval``   __cpp_if_consteval   C++23  
   C++20
-``static operator()``  __cpp_static_call_operator   C++23  
   C++03
-Attributes on 

[clang] [clang] Accept lambdas in C++03 as an extensions (PR #73376)

2024-03-17 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/73376

>From 9bd0146b3f058499b82bdb88fe5bd045c3c07caf Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Sat, 25 Nov 2023 04:00:57 +0100
Subject: [PATCH] [clang] Accept lambdas in C++03 as an extensions

This is a fairly simple extension, but makes the life for people who
have to support C++03 a lot easier. As a nice bonus, this also improves
diagnostics, since lambdas are now properly recognized when parsing
C++03 code.
---
 clang/docs/LanguageExtensions.rst |  73 ++-
 .../clang/Basic/DiagnosticParseKinds.td   |   1 +
 clang/include/clang/Basic/Features.def|   1 +
 clang/lib/Parse/ParseExpr.cpp |   2 +-
 clang/lib/Parse/ParseExprCXX.cpp  |   9 +-
 clang/lib/Parse/ParseInit.cpp |   2 +-
 clang/lib/Sema/SemaDecl.cpp   |   2 +-
 clang/lib/Sema/SemaDeclCXX.cpp|   3 +-
 clang/test/Lexer/has_extension_cxx.cpp|   5 +
 .../OpenMP/declare_reduction_messages.cpp |  14 +--
 clang/test/OpenMP/openmp_check.cpp|   2 +-
 clang/test/Parser/cxx03-lambda-extension.cpp  |   5 +
 .../test/Parser/cxx0x-lambda-expressions.cpp  | 116 +++---
 clang/test/Parser/cxx2b-lambdas.cpp   |  43 +--
 .../Parser/objcxx-lambda-expressions-neg.mm   |   9 +-
 clang/test/ParserHLSL/group_shared.hlsl   |   4 +-
 clang/test/SemaCXX/cxx2a-template-lambdas.cpp |  26 ++--
 clang/test/SemaCXX/lambda-expressions.cpp |  63 ++
 .../SemaCXX/lambda-implicit-this-capture.cpp  |   1 +
 clang/test/SemaCXX/lambda-invalid-capture.cpp |   1 +
 clang/test/SemaCXX/new-delete.cpp |   7 +-
 21 files changed, 208 insertions(+), 181 deletions(-)
 create mode 100644 clang/test/Parser/cxx03-lambda-extension.cpp

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 13d7261d83d7f1..201a4c27f7dd8b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1459,40 +1459,45 @@ More information could be found `here 

 Language Extensions Back-ported to Previous Standards
 =
 
-==  
= =
-FeatureFeature Test Macro   
Introduced In Backported To
-==  
= =
-variadic templates __cpp_variadic_templates C++11  
   C++03
-Alias templates__cpp_alias_templatesC++11  
   C++03
-Non-static data member initializers__cpp_nsdmi  C++11  
   C++03
-Range-based ``for`` loop   __cpp_range_based_forC++11  
   C++03
-RValue references  __cpp_rvalue_references  C++11  
   C++03
-Attributes __cpp_attributes C++11  
   C++03
-variable templates __cpp_variable_templates C++14  
   C++03
-Binary literals__cpp_binary_literalsC++14  
   C++03
-Relaxed constexpr  __cpp_constexpr  C++14  
   C++11
-``if constexpr``   __cpp_if_constexpr   C++17  
   C++11
-fold expressions   __cpp_fold_expressions   C++17  
   C++03
-Lambda capture of \*this by value  __cpp_capture_star_this  C++17  
   C++11
-Attributes on enums__cpp_enumerator_attributes  C++17  
   C++03
-Guaranteed copy elision__cpp_guaranteed_copy_elisionC++17  
   C++03
-Hexadecimal floating literals  __cpp_hex_float  C++17  
   C++03
-``inline`` variables   __cpp_inline_variables   C++17  
   C++03
-Attributes on namespaces   __cpp_namespace_attributes   C++17  
   C++11
-Structured bindings__cpp_structured_bindingsC++17  
   C++03
-template template arguments__cpp_template_template_args C++17  
   C++03
-``static operator[]``  __cpp_multidimensional_subscript C++20  
   C++03
-Designated initializers__cpp_designated_initializersC++20  
   C++03
-Conditional ``explicit``   __cpp_conditional_explicit   C++20  
   C++03
-``using enum`` __cpp_using_enum C++20  
   C++03
-``if consteval``   __cpp_if_consteval   C++23  
   C++20
-``static operator()``  __cpp_static_call_operator   C++23  
   C++03
-Attributes on Lambda-Expressions  

[clang] Reapply "[clang] Fix crash when declaring invalid lambda member" (PR #85427)

2024-03-16 Thread Nikolas Klauser via cfe-commits

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


[clang] Reapply "[clang] Fix crash when declaring invalid lambda member" (PR #85427)

2024-03-15 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/85427

>From bfc6023d76077217fd4c82a91de6e0c08283ddbc Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Fri, 15 Mar 2024 17:28:11 +0100
Subject: [PATCH] Reapply "[clang] Fix crash when declaring invalid lambda
 member"

This re-applies #74110 with the crashing code disabled in C++03. I'll
try to fix the new crash in it's own patch.
---
 clang/docs/ReleaseNotes.rst   |  3 +++
 clang/lib/AST/DeclCXX.cpp |  7 +++
 clang/test/SemaCXX/lambda-expressions.cpp | 21 +
 3 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index dfd88a128941ab..1e7243f62da381 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -300,6 +300,9 @@ Bug Fixes in This Version
   by the C standard. This significantly improves codegen of `*` and `/` 
especially.
   Fixes (`#31205 `_).
 
+- Fixes an assertion failure on invalid code when trying to define member
+  functions in lambdas.
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 1c3dcf63465c68..645ec2f7563bca 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -1567,10 +1567,9 @@ bool CXXRecordDecl::isGenericLambda() const {
 
 #ifndef NDEBUG
 static bool allLookupResultsAreTheSame(const DeclContext::lookup_result ) {
-  for (auto *D : R)
-if (!declaresSameEntity(D, R.front()))
-  return false;
-  return true;
+  return llvm::all_of(R, [&](NamedDecl *D) {
+return D->isInvalidDecl() || declaresSameEntity(D, R.front());
+  });
 }
 #endif
 
diff --git a/clang/test/SemaCXX/lambda-expressions.cpp 
b/clang/test/SemaCXX/lambda-expressions.cpp
index 0516a5da31ae9a..389002ab0e349b 100644
--- a/clang/test/SemaCXX/lambda-expressions.cpp
+++ b/clang/test/SemaCXX/lambda-expressions.cpp
@@ -1,3 +1,4 @@
+// RUN: %clang_cc1 -std=c++11 -Wno-unused-value -fsyntax-only 
-verify=expected,expected-cxx14,cxx11 -fblocks %s
 // RUN: %clang_cc1 -std=c++14 -Wno-unused-value -fsyntax-only -verify 
-verify=expected-cxx14 -fblocks %s
 // RUN: %clang_cc1 -std=c++17 -Wno-unused-value -verify -ast-dump -fblocks %s 
| FileCheck %s
 
@@ -558,8 +559,8 @@ struct B {
   int x;
   A a = [&] { int y = x; };
   A b = [&] { [&] { [&] { int y = x; }; }; };
-  A d = [&](auto param) { int y = x; };
-  A e = [&](auto param) { [&] { [&](auto param2) { int y = x; }; }; };
+  A d = [&](auto param) { int y = x; }; // cxx11-error {{'auto' not allowed in 
lambda parameter}}
+  A e = [&](auto param) { [&] { [&](auto param2) { int y = x; }; }; }; // 
cxx11-error 2 {{'auto' not allowed in lambda parameter}}
 };
 
 B b;
@@ -589,6 +590,7 @@ struct S1 {
 void foo1() {
   auto s0 = S1{[name=]() {}}; // expected-error 2 {{expected expression}}
   auto s1 = S1{[name=name]() {}}; // expected-error {{use of undeclared 
identifier 'name'; did you mean 'name1'?}}
+  // cxx11-warning@-1 {{initialized lambda 
captures are a C++14 extension}}
 }
 }
 
@@ -604,7 +606,7 @@ namespace PR25627_dont_odr_use_local_consts {
 
 namespace ConversionOperatorDoesNotHaveDeducedReturnType {
   auto x = [](int){};
-  auto y = [](auto ) -> void { v.n = 0; };
+  auto y = [](auto ) -> void { v.n = 0; }; // cxx11-error {{'auto' not 
allowed in lambda parameter}} cxx11-note {{candidate function not viable}} 
cxx11-note {{conversion candidate}}
   using T = decltype(x);
   using U = decltype(y);
   using ExpectedTypeT = void (*)(int);
@@ -624,22 +626,22 @@ namespace ConversionOperatorDoesNotHaveDeducedReturnType {
 template
   friend constexpr U::operator ExpectedTypeU() const noexcept;
 #else
-friend auto T::operator()(int) const;
+friend auto T::operator()(int) const; // cxx11-error {{'auto' return 
without trailing return type; deduced return types are a C++14 extension}}
 friend T::operator ExpectedTypeT() const;
 
 template
-  friend void U::operator()(T&) const;
+  friend void U::operator()(T&) const; // cxx11-error {{friend declaration 
of 'operator()' does not match any declaration}}
 // FIXME: This should not match, as above.
 template
-  friend U::operator ExpectedTypeU() const;
+  friend U::operator ExpectedTypeU() const; // cxx11-error {{friend 
declaration of 'operator void (*)(type-parameter-0-0 &)' does not match any 
declaration}}
 #endif
 
   private:
 int n;
   };
 
-  // Should be OK: lambda's call operator is a friend.
-  void use(X ) { y(x); }
+  // Should be OK in C++14 and later: lambda's call operator is a friend.
+  void use(X ) { y(x); } // cxx11-error {{no matching function for call to 
object}}
 
   // This used to crash in return type deduction for the conversion opreator.
   struct A { int n; void f() { +[](decltype(n)) {}; } };
@@ -733,6 +735,8 @@ void 

[clang] [llvm] Reapply "[clang] Fix crash when declaring invalid lambda member" (PR #85427)

2024-03-15 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 created 
https://github.com/llvm/llvm-project/pull/85427

This re-applies #74110 with the crashing code disabled in C++03. I'll
try to fix the new crash in it's own patch.


>From 9deb45f9b175ce41698feb685d74720c2397b63e Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Fri, 15 Mar 2024 17:28:11 +0100
Subject: [PATCH] Reapply "[clang] Fix crash when declaring invalid lambda
 member"

This re-applies #74110 with the crashing code disabled in C++03. I'll
try to fix the new crash in it's own patch.
---
 clang/docs/ReleaseNotes.rst   |  3 +++
 clang/lib/AST/DeclCXX.cpp |  7 +++
 clang/test/SemaCXX/lambda-expressions.cpp | 21 +
 llvm/lib/Support/CodeGenCoverage.cpp  |  3 +++
 4 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index dfd88a128941ab..1e7243f62da381 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -300,6 +300,9 @@ Bug Fixes in This Version
   by the C standard. This significantly improves codegen of `*` and `/` 
especially.
   Fixes (`#31205 `_).
 
+- Fixes an assertion failure on invalid code when trying to define member
+  functions in lambdas.
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 1c3dcf63465c68..645ec2f7563bca 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -1567,10 +1567,9 @@ bool CXXRecordDecl::isGenericLambda() const {
 
 #ifndef NDEBUG
 static bool allLookupResultsAreTheSame(const DeclContext::lookup_result ) {
-  for (auto *D : R)
-if (!declaresSameEntity(D, R.front()))
-  return false;
-  return true;
+  return llvm::all_of(R, [&](NamedDecl *D) {
+return D->isInvalidDecl() || declaresSameEntity(D, R.front());
+  });
 }
 #endif
 
diff --git a/clang/test/SemaCXX/lambda-expressions.cpp 
b/clang/test/SemaCXX/lambda-expressions.cpp
index 0516a5da31ae9a..389002ab0e349b 100644
--- a/clang/test/SemaCXX/lambda-expressions.cpp
+++ b/clang/test/SemaCXX/lambda-expressions.cpp
@@ -1,3 +1,4 @@
+// RUN: %clang_cc1 -std=c++11 -Wno-unused-value -fsyntax-only 
-verify=expected,expected-cxx14,cxx11 -fblocks %s
 // RUN: %clang_cc1 -std=c++14 -Wno-unused-value -fsyntax-only -verify 
-verify=expected-cxx14 -fblocks %s
 // RUN: %clang_cc1 -std=c++17 -Wno-unused-value -verify -ast-dump -fblocks %s 
| FileCheck %s
 
@@ -558,8 +559,8 @@ struct B {
   int x;
   A a = [&] { int y = x; };
   A b = [&] { [&] { [&] { int y = x; }; }; };
-  A d = [&](auto param) { int y = x; };
-  A e = [&](auto param) { [&] { [&](auto param2) { int y = x; }; }; };
+  A d = [&](auto param) { int y = x; }; // cxx11-error {{'auto' not allowed in 
lambda parameter}}
+  A e = [&](auto param) { [&] { [&](auto param2) { int y = x; }; }; }; // 
cxx11-error 2 {{'auto' not allowed in lambda parameter}}
 };
 
 B b;
@@ -589,6 +590,7 @@ struct S1 {
 void foo1() {
   auto s0 = S1{[name=]() {}}; // expected-error 2 {{expected expression}}
   auto s1 = S1{[name=name]() {}}; // expected-error {{use of undeclared 
identifier 'name'; did you mean 'name1'?}}
+  // cxx11-warning@-1 {{initialized lambda 
captures are a C++14 extension}}
 }
 }
 
@@ -604,7 +606,7 @@ namespace PR25627_dont_odr_use_local_consts {
 
 namespace ConversionOperatorDoesNotHaveDeducedReturnType {
   auto x = [](int){};
-  auto y = [](auto ) -> void { v.n = 0; };
+  auto y = [](auto ) -> void { v.n = 0; }; // cxx11-error {{'auto' not 
allowed in lambda parameter}} cxx11-note {{candidate function not viable}} 
cxx11-note {{conversion candidate}}
   using T = decltype(x);
   using U = decltype(y);
   using ExpectedTypeT = void (*)(int);
@@ -624,22 +626,22 @@ namespace ConversionOperatorDoesNotHaveDeducedReturnType {
 template
   friend constexpr U::operator ExpectedTypeU() const noexcept;
 #else
-friend auto T::operator()(int) const;
+friend auto T::operator()(int) const; // cxx11-error {{'auto' return 
without trailing return type; deduced return types are a C++14 extension}}
 friend T::operator ExpectedTypeT() const;
 
 template
-  friend void U::operator()(T&) const;
+  friend void U::operator()(T&) const; // cxx11-error {{friend declaration 
of 'operator()' does not match any declaration}}
 // FIXME: This should not match, as above.
 template
-  friend U::operator ExpectedTypeU() const;
+  friend U::operator ExpectedTypeU() const; // cxx11-error {{friend 
declaration of 'operator void (*)(type-parameter-0-0 &)' does not match any 
declaration}}
 #endif
 
   private:
 int n;
   };
 
-  // Should be OK: lambda's call operator is a friend.
-  void use(X ) { y(x); }
+  // Should be OK in C++14 and later: lambda's call operator is a friend.
+  void use(X ) { y(x); } // cxx11-error {{no matching function for call to 
object}}
 
 

[clang] [Clang][Driver] Merge the different strategies of how libc++ is included (PR #83721)

2024-03-09 Thread Nikolas Klauser via cfe-commits

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


[clang] [Clang] Document some of the implementation-defined keywords (PR #84591)

2024-03-08 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/84591

>From 634b8e8285b23201d7ad852ae35044d9b89c3c63 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Sat, 9 Mar 2024 02:14:36 +0100
Subject: [PATCH] [Clang] Document some of the implementation-defined keywords

---
 clang/docs/LanguageExtensions.rst | 122 +++---
 1 file changed, 111 insertions(+), 11 deletions(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 06af93fd3c15ca..2530d657be5996 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -433,6 +433,117 @@ __datasizeof
 ``__datasizeof`` behaves like ``sizeof``, except that it returns the size of 
the
 type ignoring tail padding.
 
+_BitInt, _ExtInt
+
+
+Clang supports the C23 ``_BitInt(N)`` feature as an extension in older C modes
+and in C++. This type was previously implemented in Clang with the same
+semantics, but spelled ``_ExtInt(N)``. This spelling has been deprecated in
+favor of the standard type.
+
+Note: the ABI for ``_BitInt(N)`` is still in the process of being stabilized,
+so this type should not yet be used in interfaces that require ABI stability.
+
+C keywords supported in all language modes
+--
+
+Clang supports ``_Alignas``, ``_Alignof``, ``_Atomic``, ``_Complex``,
+``_Generic``, ``_Imaginary``, ``_Noreturn``, ``_Static_assert``,
+``_Thread_local``, ``_Float16``, ``_Decimal32``, ``_Decimal64`` and
+``_Decimal128`` in all language modes with the C semantics.
+
+__alignof, __alignof__
+--
+
+``__alignof`` and ``__alignof__`` return, in contrast to ``_Alignof`` and
+``alignof``, the preferred alignment of a type. This may be larger than the
+required alignment for improved performance.
+
+__extension__
+-
+
+``__extension__`` suppressed extension diagnostics in the statement it is
+prepended to.
+
+__auto_type
+---
+
+``__auto_type`` behaves the same as C++11s ``auto`` but is available in all
+language modes.
+
+__imag, __imag__
+
+
+``__imag`` and ``__imag__`` can be used to get the imaginary part of a complex
+value.
+
+__real, __real__
+
+
+``__real`` and ``__real__`` can be used to get the real part of a complex 
value.
+
+__asm, __asm__
+--
+
+``__asm`` and ``__asm__`` are alternate spellings for ``asm``, but available in
+all language modes.
+
+__complex, __complex__
+--
+
+``__complex`` and ``__complex__`` are alternate spellings for ``_Complex``.
+
+__const, __const__
+--
+
+``__const`` and ``__const__`` are alternate spellings for ``const``.
+
+__decltype
+--
+
+``__decltype`` is an alternate spelling for ``decltype``, but is also available
+in C++ modes before C++11.
+
+__inline, __inline__
+
+
+``__inline`` and ``__inline__`` are alternate spellings for ``inline``, but are
+available in all language modes.
+
+__nullptr
+-
+
+``__nullptr`` is an alternate spelling for ``nullptr``, but is also available 
in
+C++ modes before C++11.
+
+__restrict, __restrict__
+
+
+``__restrict`` and ``__restrict__`` are alternate spellings for ``restrict``,
+but are available in all language modes.
+
+__signed, __signed__
+
+
+``__signed`` and ``__signed__`` are alternate spellings for ``signed``.
+
+__typeof, __typeof__
+
+
+``__typeof`` and ``__typeof__`` are alternate spellings for ``typeof``, but are
+available in all langauge modes.
+
+__volatile, __volatile__
+
+
+``__volatile`` and ``__volatile__`` are alternate spellings for ``volatile``.
+
+__char16_t, __char32_t
+--
+
+``__char16_t`` and ``__char32_t`` are alternate spellings for ``char16_t`` and
+``char32_t`` respectively, but are also available in C++ modes before C++11.
+
 ..
   FIXME: This should list all the keyword extensions
 
@@ -5319,17 +5430,6 @@ Examples are:
# 60 "" 2 // return to "main.c"
# 1 "/usr/ancient/header.h" 1 4 // Enter an implicit extern "C" header
 
-Extended Integer Types
-==
-
-Clang supports the C23 ``_BitInt(N)`` feature as an extension in older C modes
-and in C++. This type was previously implemented in Clang with the same
-semantics, but spelled ``_ExtInt(N)``. This spelling has been deprecated in
-favor of the standard type.
-
-Note: the ABI for ``_BitInt(N)`` is still in the process of being stabilized,
-so this type should not yet be used in interfaces that require ABI stability.
-
 Intrinsics Support within Constant Expressions
 ==
 

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


[clang] [Clang] Document some of the implementation-defined keywords (PR #84591)

2024-03-08 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 created 
https://github.com/llvm/llvm-project/pull/84591

None

>From 479b0dec7feb17beaccbdc029799f2333d979ce4 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Sat, 9 Mar 2024 02:14:36 +0100
Subject: [PATCH] [Clang] Document some of the implementation-defined keywords

---
 clang/docs/LanguageExtensions.rst | 123 +++---
 1 file changed, 112 insertions(+), 11 deletions(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 06af93fd3c15ca..9c6c91c1cf4ba3 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -433,6 +433,118 @@ __datasizeof
 ``__datasizeof`` behaves like ``sizeof``, except that it returns the size of 
the
 type ignoring tail padding.
 
+_BitInt, _ExtInt
+
+
+Clang supports the C23 ``_BitInt(N)`` feature as an extension in older C modes
+and in C++. This type was previously implemented in Clang with the same
+semantics, but spelled ``_ExtInt(N)``. This spelling has been deprecated in
+favor of the standard type.
+
+Note: the ABI for ``_BitInt(N)`` is still in the process of being stabilized,
+so this type should not yet be used in interfaces that require ABI stability.
+
+C keywords supported in all language modes
+--
+
+Clang supports ``_Alignas``, ``_Alignof``, ``_Atomic``, ``_Complex``,
+``_Generic``, ``_Imaginary``, ``_Noreturn``, ``_Static_assert``,
+``_Thread_local``, ``_Float16``, ``_Decimal32``, ``_Decimal64`` and
+``_Decimal128`` in all language modes with the C semantics.
+
+__alignof, __alignof__
+-
+
+``__alignof`` and ``__alignof__`` return, in contrast to ``_Alignof`` and
+``alignof``, the preferred alignment of a type. This may be larger than the
+required alignment for improved performance.
+
+__extension__
+-
+
+``__extension__`` suppressed extension diagnostics in the statement it is
+prepended to.
+
+__auto_type
+---
+
+``__auto_type`` behaves the same as C++11s ``auto`` but is available in all
+language modes.
+
+__imag, __imag__
+
+
+``__imag`` and ``__imag__`` can be used to get the imaginary part of a complex
+value.
+
+__real, __real__
+
+
+``__real`` and ``__real__`` can be used to get the real part of a complex 
value.
+
+__asm, __asm__
+--
+
+``__asm`` and ``__asm__`` are alternate spellings for ``asm``, but available in
+all language modes.
+
+__complex, __complex__
+--
+
+``__complex`` and ``__complex__`` are alternate spellings for ``_Complex``.
+These are available for compatibility with old code.
+
+__const, __const__
+--
+
+``__const`` and ``__const__`` are alternate spellings for ``const``.
+
+__decltype
+--
+
+``__decltype`` is an alternate spelling for ``decltype``, but is also available
+in C++ modes before C++11.
+
+__inline, __inline__
+
+
+``__inline`` and ``__inline__`` are alternate spellings for ``inline``, but are
+available in all language modes.
+
+__nullptr
+-
+
+``__nullptr`` is an alternate spelling for ``nullptr``, but is also available 
in
+C++ modes before C++11.
+
+__restrict, __restrict__
+
+
+``__restrict`` and ``__restrict__`` are alternate spellings for ``restrict``,
+but are available in all language modes.
+
+__signed, __signed__
+
+
+``__signed`` and ``__signed__`` are alternate spellings for ``signed``.
+
+__typeof, __typeof__
+
+
+``__typeof`` and ``__typeof__`` are alternate spellings for ``typeof``, but are
+available in all langauge modes.
+
+__volatile, __volatile__
+
+
+``__volatile`` and ``__volatile__`` are alternate spellings for ``volatile``.
+
+__char16_t, __char32_t
+--
+
+``__char16_t`` and ``__char32_t`` are alternate spellings for ``char16_t`` and
+``char32_t`` respectively, but are also available in C++ modes before C++11.
+
 ..
   FIXME: This should list all the keyword extensions
 
@@ -5319,17 +5431,6 @@ Examples are:
# 60 "" 2 // return to "main.c"
# 1 "/usr/ancient/header.h" 1 4 // Enter an implicit extern "C" header
 
-Extended Integer Types
-==
-
-Clang supports the C23 ``_BitInt(N)`` feature as an extension in older C modes
-and in C++. This type was previously implemented in Clang with the same
-semantics, but spelled ``_ExtInt(N)``. This spelling has been deprecated in
-favor of the standard type.
-
-Note: the ABI for ``_BitInt(N)`` is still in the process of being stabilized,
-so this type should not yet be used in interfaces that require ABI stability.
-
 Intrinsics Support within Constant Expressions
 ==
 

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


[clang] [clang] Accept lambdas in C++03 as an extensions (PR #73376)

2024-03-08 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/73376

>From db504f5031b11ff7e28a346db829463fd6883d98 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Sat, 25 Nov 2023 04:00:57 +0100
Subject: [PATCH] [clang] Accept lambdas in C++03 as an extensions

This is a fairly simple extension, but makes the life for people who
have to support C++03 a lot easier. As a nice bonus, this also improves
diagnostics, since lambdas are now properly recognized when parsing
C++03 code.
---
 clang/docs/LanguageExtensions.rst |  73 ++-
 .../clang/Basic/DiagnosticParseKinds.td   |   1 +
 clang/include/clang/Basic/Features.def|   1 +
 clang/lib/Parse/ParseExpr.cpp |   2 +-
 clang/lib/Parse/ParseExprCXX.cpp  |   9 +-
 clang/lib/Parse/ParseInit.cpp |   2 +-
 clang/lib/Sema/SemaDecl.cpp   |   2 +-
 clang/lib/Sema/SemaDeclCXX.cpp|   3 +-
 clang/test/Lexer/has_extension_cxx.cpp|   5 +
 .../OpenMP/declare_reduction_messages.cpp |  14 +--
 clang/test/OpenMP/openmp_check.cpp|   2 +-
 clang/test/Parser/cxx03-lambda-extension.cpp  |   5 +
 .../test/Parser/cxx0x-lambda-expressions.cpp  | 116 +++---
 clang/test/Parser/cxx2b-lambdas.cpp   |  43 +--
 .../Parser/objcxx-lambda-expressions-neg.mm   |   9 +-
 clang/test/ParserHLSL/group_shared.hlsl   |   4 +-
 clang/test/SemaCXX/cxx2a-template-lambdas.cpp |  26 ++--
 clang/test/SemaCXX/lambda-expressions.cpp |  63 ++
 .../SemaCXX/lambda-implicit-this-capture.cpp  |   1 +
 clang/test/SemaCXX/lambda-invalid-capture.cpp |   1 +
 clang/test/SemaCXX/new-delete.cpp |   7 +-
 21 files changed, 208 insertions(+), 181 deletions(-)
 create mode 100644 clang/test/Parser/cxx03-lambda-extension.cpp

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 06af93fd3c15ca8..1d7bbcc161b1844 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1458,40 +1458,45 @@ More information could be found `here 

 Language Extensions Back-ported to Previous Standards
 =
 
-==  
= =
-FeatureFeature Test Macro   
Introduced In Backported To
-==  
= =
-variadic templates __cpp_variadic_templates C++11  
   C++03
-Alias templates__cpp_alias_templatesC++11  
   C++03
-Non-static data member initializers__cpp_nsdmi  C++11  
   C++03
-Range-based ``for`` loop   __cpp_range_based_forC++11  
   C++03
-RValue references  __cpp_rvalue_references  C++11  
   C++03
-Attributes __cpp_attributes C++11  
   C++03
-variable templates __cpp_variable_templates C++14  
   C++03
-Binary literals__cpp_binary_literalsC++14  
   C++03
-Relaxed constexpr  __cpp_constexpr  C++14  
   C++11
-``if constexpr``   __cpp_if_constexpr   C++17  
   C++11
-fold expressions   __cpp_fold_expressions   C++17  
   C++03
-Lambda capture of \*this by value  __cpp_capture_star_this  C++17  
   C++11
-Attributes on enums__cpp_enumerator_attributes  C++17  
   C++03
-Guaranteed copy elision__cpp_guaranteed_copy_elisionC++17  
   C++03
-Hexadecimal floating literals  __cpp_hex_float  C++17  
   C++03
-``inline`` variables   __cpp_inline_variables   C++17  
   C++03
-Attributes on namespaces   __cpp_namespace_attributes   C++17  
   C++11
-Structured bindings__cpp_structured_bindingsC++17  
   C++03
-template template arguments__cpp_template_template_args C++17  
   C++03
-``static operator[]``  __cpp_multidimensional_subscript C++20  
   C++03
-Designated initializers__cpp_designated_initializersC++20  
   C++03
-Conditional ``explicit``   __cpp_conditional_explicit   C++20  
   C++03
-``using enum`` __cpp_using_enum C++20  
   C++03
-``if consteval``   __cpp_if_consteval   C++23  
   C++20
-``static operator()``  __cpp_static_call_operator   C++23  
   C++03
-Attributes on Lambda-Expressions

[clang] [clang] Accept lambdas in C++03 as an extensions (PR #73376)

2024-03-08 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/73376

>From 73135ec6395a6d3a29725e58b30ecb42249695fe Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Sat, 25 Nov 2023 04:00:57 +0100
Subject: [PATCH] [clang] Accept lambdas in C++03 as an extensions

This is a fairly simple extension, but makes the life for people who
have to support C++03 a lot easier. As a nice bonus, this also improves
diagnostics, since lambdas are now properly recognized when parsing
C++03 code.
---
 clang/docs/LanguageExtensions.rst |  74 ++-
 .../clang/Basic/DiagnosticParseKinds.td   |   1 +
 clang/include/clang/Basic/Features.def|   1 +
 clang/lib/Parse/ParseExpr.cpp |   2 +-
 clang/lib/Parse/ParseExprCXX.cpp  |   9 +-
 clang/lib/Parse/ParseInit.cpp |   2 +-
 clang/lib/Sema/SemaDecl.cpp   |   2 +-
 clang/lib/Sema/SemaDeclCXX.cpp|   3 +-
 clang/test/Lexer/has_extension_cxx.cpp|   5 +
 .../OpenMP/declare_reduction_messages.cpp |  14 +--
 clang/test/OpenMP/openmp_check.cpp|   2 +-
 clang/test/Parser/cxx03-lambda-extension.cpp  |   5 +
 .../test/Parser/cxx0x-lambda-expressions.cpp  | 116 +++---
 clang/test/Parser/cxx2b-lambdas.cpp   |  43 +--
 .../Parser/objcxx-lambda-expressions-neg.mm   |   9 +-
 clang/test/ParserHLSL/group_shared.hlsl   |   4 +-
 clang/test/SemaCXX/cxx2a-template-lambdas.cpp |  26 ++--
 clang/test/SemaCXX/lambda-expressions.cpp |  63 ++
 .../SemaCXX/lambda-implicit-this-capture.cpp  |   1 +
 clang/test/SemaCXX/lambda-invalid-capture.cpp |   1 +
 clang/test/SemaCXX/new-delete.cpp |   7 +-
 21 files changed, 209 insertions(+), 181 deletions(-)
 create mode 100644 clang/test/Parser/cxx03-lambda-extension.cpp

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 06af93fd3c15ca8..c9fc01f9b074bd6 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1458,40 +1458,46 @@ More information could be found `here 

 Language Extensions Back-ported to Previous Standards
 =
 
-==  
= =
-FeatureFeature Test Macro   
Introduced In Backported To
-==  
= =
-variadic templates __cpp_variadic_templates C++11  
   C++03
-Alias templates__cpp_alias_templatesC++11  
   C++03
-Non-static data member initializers__cpp_nsdmi  C++11  
   C++03
-Range-based ``for`` loop   __cpp_range_based_forC++11  
   C++03
-RValue references  __cpp_rvalue_references  C++11  
   C++03
-Attributes __cpp_attributes C++11  
   C++03
-variable templates __cpp_variable_templates C++14  
   C++03
-Binary literals__cpp_binary_literalsC++14  
   C++03
-Relaxed constexpr  __cpp_constexpr  C++14  
   C++11
-``if constexpr``   __cpp_if_constexpr   C++17  
   C++11
-fold expressions   __cpp_fold_expressions   C++17  
   C++03
-Lambda capture of \*this by value  __cpp_capture_star_this  C++17  
   C++11
-Attributes on enums__cpp_enumerator_attributes  C++17  
   C++03
-Guaranteed copy elision__cpp_guaranteed_copy_elisionC++17  
   C++03
-Hexadecimal floating literals  __cpp_hex_float  C++17  
   C++03
-``inline`` variables   __cpp_inline_variables   C++17  
   C++03
-Attributes on namespaces   __cpp_namespace_attributes   C++17  
   C++11
-Structured bindings__cpp_structured_bindingsC++17  
   C++03
-template template arguments__cpp_template_template_args C++17  
   C++03
-``static operator[]``  __cpp_multidimensional_subscript C++20  
   C++03
-Designated initializers__cpp_designated_initializersC++20  
   C++03
-Conditional ``explicit``   __cpp_conditional_explicit   C++20  
   C++03
-``using enum`` __cpp_using_enum C++20  
   C++03
-``if consteval``   __cpp_if_consteval   C++23  
   C++20
-``static operator()``  __cpp_static_call_operator   C++23  
   C++03
-Attributes on Lambda-Expressions

[clang] [clang] Accept lambdas in C++03 as an extensions (PR #73376)

2024-03-08 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/73376

>From 305599596dd5914747687af23a105d2968546ca1 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Sat, 25 Nov 2023 04:00:57 +0100
Subject: [PATCH] [clang] Accept lambdas in C++03 as an extensions

This is a fairly simple extension, but makes the life for people who
have to support C++03 a lot easier. As a nice bonus, this also improves
diagnostics, since lambdas are now properly recognized when parsing
C++03 code.
---
 clang/docs/LanguageExtensions.rst |  62 +-
 .../clang/Basic/DiagnosticParseKinds.td   |   1 +
 clang/include/clang/Basic/Features.def|   1 +
 clang/lib/Parse/ParseExpr.cpp |   2 +-
 clang/lib/Parse/ParseExprCXX.cpp  |   9 +-
 clang/lib/Parse/ParseInit.cpp |   2 +-
 clang/lib/Sema/SemaDecl.cpp   |   2 +-
 clang/lib/Sema/SemaDeclCXX.cpp|   3 +-
 clang/test/Lexer/has_extension_cxx.cpp|   5 +
 .../OpenMP/declare_reduction_messages.cpp |  14 +--
 clang/test/OpenMP/openmp_check.cpp|   2 +-
 clang/test/Parser/cxx03-lambda-extension.cpp  |   5 +
 .../test/Parser/cxx0x-lambda-expressions.cpp  | 116 +++---
 clang/test/Parser/cxx2b-lambdas.cpp   |  43 +--
 .../Parser/objcxx-lambda-expressions-neg.mm   |   9 +-
 clang/test/ParserHLSL/group_shared.hlsl   |   4 +-
 clang/test/SemaCXX/cxx2a-template-lambdas.cpp |  26 ++--
 clang/test/SemaCXX/lambda-expressions.cpp |  63 ++
 .../SemaCXX/lambda-implicit-this-capture.cpp  |   1 +
 clang/test/SemaCXX/lambda-invalid-capture.cpp |   1 +
 clang/test/SemaCXX/new-delete.cpp |   7 +-
 21 files changed, 203 insertions(+), 175 deletions(-)
 create mode 100644 clang/test/Parser/cxx03-lambda-extension.cpp

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 06af93fd3c15ca8..b809b544434d540 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1458,34 +1458,39 @@ More information could be found `here 

 Language Extensions Back-ported to Previous Standards
 =
 
-==  
= =
-FeatureFeature Test Macro   
Introduced In Backported To
-==  
= =
-variadic templates __cpp_variadic_templates C++11  
   C++03
-Alias templates__cpp_alias_templatesC++11  
   C++03
-Non-static data member initializers__cpp_nsdmi  C++11  
   C++03
-Range-based ``for`` loop   __cpp_range_based_forC++11  
   C++03
-RValue references  __cpp_rvalue_references  C++11  
   C++03
-Attributes __cpp_attributes C++11  
   C++03
-variable templates __cpp_variable_templates C++14  
   C++03
-Binary literals__cpp_binary_literalsC++14  
   C++03
-Relaxed constexpr  __cpp_constexpr  C++14  
   C++11
-``if constexpr``   __cpp_if_constexpr   C++17  
   C++11
-fold expressions   __cpp_fold_expressions   C++17  
   C++03
-Lambda capture of \*this by value  __cpp_capture_star_this  C++17  
   C++11
-Attributes on enums__cpp_enumerator_attributes  C++17  
   C++03
-Guaranteed copy elision__cpp_guaranteed_copy_elisionC++17  
   C++03
-Hexadecimal floating literals  __cpp_hex_float  C++17  
   C++03
-``inline`` variables   __cpp_inline_variables   C++17  
   C++03
-Attributes on namespaces   __cpp_namespace_attributes   C++17  
   C++11
-Structured bindings__cpp_structured_bindingsC++17  
   C++03
-template template arguments__cpp_template_template_args C++17  
   C++03
-``static operator[]``  __cpp_multidimensional_subscript C++20  
   C++03
-Designated initializers__cpp_designated_initializersC++20  
   C++03
-Conditional ``explicit``   __cpp_conditional_explicit   C++20  
   C++03
-``using enum`` __cpp_using_enum C++20  
   C++03
-``if consteval``   __cpp_if_consteval   C++23  
   C++20
-``static operator()``  __cpp_static_call_operator   C++23  
   C++03
+ 

[clang] [clang] Fix crash when declaring invalid lambda member (PR #74110)

2024-03-08 Thread Nikolas Klauser via cfe-commits

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


[clang] [clang] Fix crash when declaring invalid lambda member (PR #74110)

2024-03-08 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/74110

>From 563f86bddc0ec59b63c6aeffee2342f027c09119 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Fri, 1 Dec 2023 18:16:36 +0100
Subject: [PATCH 1/2] [clang] Fix crash when declaring invalid lambda member

---
 clang/lib/AST/DeclCXX.cpp |  7 +++
 clang/test/SemaCXX/lambda-expressions.cpp | 16 +---
 2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index c944862fcefeee..e9e62fea9fb376 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -1526,10 +1526,9 @@ bool CXXRecordDecl::isGenericLambda() const {
 
 #ifndef NDEBUG
 static bool allLookupResultsAreTheSame(const DeclContext::lookup_result ) {
-  for (auto *D : R)
-if (!declaresSameEntity(D, R.front()))
-  return false;
-  return true;
+  return llvm::all_of(R, [&](NamedDecl *D) {
+return D->isInvalidDecl() || declaresSameEntity(D, R.front());
+  });
 }
 #endif
 
diff --git a/clang/test/SemaCXX/lambda-expressions.cpp 
b/clang/test/SemaCXX/lambda-expressions.cpp
index 1797eef320b865..1921d02b1a9cf8 100644
--- a/clang/test/SemaCXX/lambda-expressions.cpp
+++ b/clang/test/SemaCXX/lambda-expressions.cpp
@@ -1,3 +1,4 @@
+// RUN: %clang_cc1 -std=c++11 -Wno-unused-value -fsyntax-only 
-verify=expected,expected-cxx14,cxx11 -fblocks %s
 // RUN: %clang_cc1 -std=c++14 -Wno-unused-value -fsyntax-only -verify 
-verify=expected-cxx14 -fblocks %s
 // RUN: %clang_cc1 -std=c++17 -Wno-unused-value -verify -ast-dump -fblocks %s 
| FileCheck %s
 
@@ -558,8 +559,8 @@ struct B {
   int x;
   A a = [&] { int y = x; };
   A b = [&] { [&] { [&] { int y = x; }; }; };
-  A d = [&](auto param) { int y = x; };
-  A e = [&](auto param) { [&] { [&](auto param2) { int y = x; }; }; };
+  A d = [&](auto param) { int y = x; }; // cxx11-error {{'auto' not allowed in 
lambda parameter}}
+  A e = [&](auto param) { [&] { [&](auto param2) { int y = x; }; }; }; // 
cxx11-error 2 {{'auto' not allowed in lambda parameter}}
 };
 
 B b;
@@ -589,6 +590,7 @@ struct S1 {
 void foo1() {
   auto s0 = S1{[name=]() {}}; // expected-error 2 {{expected expression}}
   auto s1 = S1{[name=name]() {}}; // expected-error {{use of undeclared 
identifier 'name'; did you mean 'name1'?}}
+  // cxx11-warning@-1 {{initialized lambda 
captures are a C++14 extension}}
 }
 }
 
@@ -604,7 +606,7 @@ namespace PR25627_dont_odr_use_local_consts {
 
 namespace ConversionOperatorDoesNotHaveDeducedReturnType {
   auto x = [](int){};
-  auto y = [](auto ) -> void { v.n = 0; };
+  auto y = [](auto ) -> void { v.n = 0; }; // cxx11-error {{'auto' not 
allowed in lambda parameter}} cxx11-note {{candidate function not viable}} 
cxx11-note {{conversion candidate}}
   using T = decltype(x);
   using U = decltype(y);
   using ExpectedTypeT = void (*)(int);
@@ -624,14 +626,14 @@ namespace ConversionOperatorDoesNotHaveDeducedReturnType {
 template
   friend constexpr U::operator ExpectedTypeU() const noexcept;
 #else
-friend auto T::operator()(int) const;
+friend auto T::operator()(int) const; // cxx11-error {{'auto' return 
without trailing return type; deduced return types are a C++14 extension}}
 friend T::operator ExpectedTypeT() const;
 
 template
-  friend void U::operator()(T&) const;
+  friend void U::operator()(T&) const; // cxx11-error {{friend declaration 
of 'operator()' does not match any declaration}}
 // FIXME: This should not match, as above.
 template
-  friend U::operator ExpectedTypeU() const;
+  friend U::operator ExpectedTypeU() const; // cxx11-error {{friend 
declaration of 'operator void (*)(type-parameter-0-0 &)' does not match any 
declaration}}
 #endif
 
   private:
@@ -639,7 +641,7 @@ namespace ConversionOperatorDoesNotHaveDeducedReturnType {
   };
 
   // Should be OK: lambda's call operator is a friend.
-  void use(X ) { y(x); }
+  void use(X ) { y(x); } // cxx11-error {{no matching function for call to 
object}}
 
   // This used to crash in return type deduction for the conversion opreator.
   struct A { int n; void f() { +[](decltype(n)) {}; } };

>From 5412ff972af6fdc6c83d9f0b835ff989252ff591 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Thu, 7 Mar 2024 12:47:55 +0100
Subject: [PATCH 2/2] Address comments

---
 clang/docs/ReleaseNotes.rst   | 2 ++
 clang/test/SemaCXX/lambda-expressions.cpp | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0ce15169d49bcc..db4dcc3ce029fb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -617,6 +617,8 @@ Bug Fixes in This Version
 - Fix crash during code generation of C++ coroutine initial suspend when the 
return
   type of await_resume is not trivially destructible.
   Fixes (`#63803 `_)
+- Fixes 

[clang] [clang] Fix crash when declaring invalid lambda member (PR #74110)

2024-03-07 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/74110

>From 563f86bddc0ec59b63c6aeffee2342f027c09119 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Fri, 1 Dec 2023 18:16:36 +0100
Subject: [PATCH 1/2] [clang] Fix crash when declaring invalid lambda member

---
 clang/lib/AST/DeclCXX.cpp |  7 +++
 clang/test/SemaCXX/lambda-expressions.cpp | 16 +---
 2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index c944862fcefeee..e9e62fea9fb376 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -1526,10 +1526,9 @@ bool CXXRecordDecl::isGenericLambda() const {
 
 #ifndef NDEBUG
 static bool allLookupResultsAreTheSame(const DeclContext::lookup_result ) {
-  for (auto *D : R)
-if (!declaresSameEntity(D, R.front()))
-  return false;
-  return true;
+  return llvm::all_of(R, [&](NamedDecl *D) {
+return D->isInvalidDecl() || declaresSameEntity(D, R.front());
+  });
 }
 #endif
 
diff --git a/clang/test/SemaCXX/lambda-expressions.cpp 
b/clang/test/SemaCXX/lambda-expressions.cpp
index 1797eef320b865..1921d02b1a9cf8 100644
--- a/clang/test/SemaCXX/lambda-expressions.cpp
+++ b/clang/test/SemaCXX/lambda-expressions.cpp
@@ -1,3 +1,4 @@
+// RUN: %clang_cc1 -std=c++11 -Wno-unused-value -fsyntax-only 
-verify=expected,expected-cxx14,cxx11 -fblocks %s
 // RUN: %clang_cc1 -std=c++14 -Wno-unused-value -fsyntax-only -verify 
-verify=expected-cxx14 -fblocks %s
 // RUN: %clang_cc1 -std=c++17 -Wno-unused-value -verify -ast-dump -fblocks %s 
| FileCheck %s
 
@@ -558,8 +559,8 @@ struct B {
   int x;
   A a = [&] { int y = x; };
   A b = [&] { [&] { [&] { int y = x; }; }; };
-  A d = [&](auto param) { int y = x; };
-  A e = [&](auto param) { [&] { [&](auto param2) { int y = x; }; }; };
+  A d = [&](auto param) { int y = x; }; // cxx11-error {{'auto' not allowed in 
lambda parameter}}
+  A e = [&](auto param) { [&] { [&](auto param2) { int y = x; }; }; }; // 
cxx11-error 2 {{'auto' not allowed in lambda parameter}}
 };
 
 B b;
@@ -589,6 +590,7 @@ struct S1 {
 void foo1() {
   auto s0 = S1{[name=]() {}}; // expected-error 2 {{expected expression}}
   auto s1 = S1{[name=name]() {}}; // expected-error {{use of undeclared 
identifier 'name'; did you mean 'name1'?}}
+  // cxx11-warning@-1 {{initialized lambda 
captures are a C++14 extension}}
 }
 }
 
@@ -604,7 +606,7 @@ namespace PR25627_dont_odr_use_local_consts {
 
 namespace ConversionOperatorDoesNotHaveDeducedReturnType {
   auto x = [](int){};
-  auto y = [](auto ) -> void { v.n = 0; };
+  auto y = [](auto ) -> void { v.n = 0; }; // cxx11-error {{'auto' not 
allowed in lambda parameter}} cxx11-note {{candidate function not viable}} 
cxx11-note {{conversion candidate}}
   using T = decltype(x);
   using U = decltype(y);
   using ExpectedTypeT = void (*)(int);
@@ -624,14 +626,14 @@ namespace ConversionOperatorDoesNotHaveDeducedReturnType {
 template
   friend constexpr U::operator ExpectedTypeU() const noexcept;
 #else
-friend auto T::operator()(int) const;
+friend auto T::operator()(int) const; // cxx11-error {{'auto' return 
without trailing return type; deduced return types are a C++14 extension}}
 friend T::operator ExpectedTypeT() const;
 
 template
-  friend void U::operator()(T&) const;
+  friend void U::operator()(T&) const; // cxx11-error {{friend declaration 
of 'operator()' does not match any declaration}}
 // FIXME: This should not match, as above.
 template
-  friend U::operator ExpectedTypeU() const;
+  friend U::operator ExpectedTypeU() const; // cxx11-error {{friend 
declaration of 'operator void (*)(type-parameter-0-0 &)' does not match any 
declaration}}
 #endif
 
   private:
@@ -639,7 +641,7 @@ namespace ConversionOperatorDoesNotHaveDeducedReturnType {
   };
 
   // Should be OK: lambda's call operator is a friend.
-  void use(X ) { y(x); }
+  void use(X ) { y(x); } // cxx11-error {{no matching function for call to 
object}}
 
   // This used to crash in return type deduction for the conversion opreator.
   struct A { int n; void f() { +[](decltype(n)) {}; } };

>From 5412ff972af6fdc6c83d9f0b835ff989252ff591 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Thu, 7 Mar 2024 12:47:55 +0100
Subject: [PATCH 2/2] Address comments

---
 clang/docs/ReleaseNotes.rst   | 2 ++
 clang/test/SemaCXX/lambda-expressions.cpp | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0ce15169d49bcc..db4dcc3ce029fb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -617,6 +617,8 @@ Bug Fixes in This Version
 - Fix crash during code generation of C++ coroutine initial suspend when the 
return
   type of await_resume is not trivially destructible.
   Fixes (`#63803 `_)
+- Fixes 

[clang] [clang] Refactor Builtins.def to be a tablegen file (PR #68324)

2024-03-05 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

Not right now. I think the first thing to do is moving all the builtins to 
tablegen before we can make better use of it, which is going to take a while.


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


[clang] [clang] Fix crash when declaring invalid lambda member (PR #74110)

2024-03-03 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

@AaronBallman Thanks for the review. Sorry for responding so late - I've missed 
your review.

The tests aren't actually unrelated to the path. This is the file where I 
discovered the crash, so I just used it to demonstrate that it's fixed. I'm not 
sure how to split things, since I can't add the run line without fixing the bug.

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


[clang] [Clang][Driver] Add special-casing for including libc++ in C++03 (PR #83723)

2024-03-03 Thread Nikolas Klauser via cfe-commits

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


[clang] [Clang][Driver] Add special-casing for including libc++ in C++03 (PR #83723)

2024-03-03 Thread Nikolas Klauser via cfe-commits

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


[clang] users/philnik777/add libcxx03 include strategy (PR #83723)

2024-03-03 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 created 
https://github.com/llvm/llvm-project/pull/83723

- [Clang][Driver] Merge the different strategies of how libc++ is included
- [Clang][Driver] Add special-casing for including libc++ in C++03


>From 756f80f22744bb0f2bfb81e6c4010054f1279337 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Fri, 1 Mar 2024 20:49:30 +0100
Subject: [PATCH 1/2] [Clang][Driver] Merge the different strategies of how
 libc++ is included

---
 clang/include/clang/Driver/ToolChain.h   | 41 
 clang/lib/Driver/ToolChain.cpp   | 41 
 clang/lib/Driver/ToolChains/AIX.cpp  | 10 ++---
 clang/lib/Driver/ToolChains/BareMetal.cpp| 13 +++
 clang/lib/Driver/ToolChains/CrossWindows.cpp |  3 +-
 clang/lib/Driver/ToolChains/Darwin.cpp   | 32 ++-
 clang/lib/Driver/ToolChains/FreeBSD.cpp  |  5 ++-
 clang/lib/Driver/ToolChains/Fuchsia.cpp  | 22 ++-
 clang/lib/Driver/ToolChains/Gnu.cpp  |  6 +--
 clang/lib/Driver/ToolChains/Haiku.cpp|  5 ++-
 clang/lib/Driver/ToolChains/Hexagon.cpp  | 27 -
 clang/lib/Driver/ToolChains/MinGW.cpp| 16 +++-
 clang/lib/Driver/ToolChains/MipsLinux.cpp|  7 ++--
 clang/lib/Driver/ToolChains/NaCl.cpp | 16 
 clang/lib/Driver/ToolChains/NetBSD.cpp   | 20 +-
 clang/lib/Driver/ToolChains/OHOS.cpp |  9 ++---
 clang/lib/Driver/ToolChains/OpenBSD.cpp  |  5 ++-
 clang/lib/Driver/ToolChains/WebAssembly.cpp  |  4 +-
 clang/lib/Driver/ToolChains/ZOS.cpp  | 22 ---
 clang/lib/Driver/ToolChains/ZOS.h|  3 --
 20 files changed, 178 insertions(+), 129 deletions(-)

diff --git a/clang/include/clang/Driver/ToolChain.h 
b/clang/include/clang/Driver/ToolChain.h
index fbe2e8fe8e88d8..c61cf2aa064ed5 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -705,6 +705,47 @@ class ToolChain {
   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList ,
llvm::opt::ArgStringList ) const;
 
+  struct IncludeStrategy {
+enum AvailabilityOptions {
+  // Check whether the directory is exists before adding it to the
+  // include path. This is the case if AssumeAvailable isn't set.
+  CheckIfAvailable,
+
+  // Don't check whether the directory exists. Just assume it does and add
+  // the include.
+  AssumeAvailable,
+
+  // Use v that is inside `/c++`. If not set, 
always
+  // uses v1.
+  UseMaxVersionAvailable,
+};
+
+IncludeStrategy(AvailabilityOptions Availability,
+bool AddTargetDirIfAvailable = false,
+bool PrintDebugStatements = false)
+: Availability(Availability),
+  AddTargetDirIfAvailable(AddTargetDirIfAvailable),
+  PrintDebugStatements(PrintDebugStatements) {}
+
+LLVM_PREFERRED_TYPE(AvailabilityOptions)
+unsigned Availability : 2;
+
+// Check whether the directory `//c++/v`
+// exists, and add it to the include path if it does.
+LLVM_PREFERRED_TYPE(bool)
+unsigned AddTargetDirIfAvailable : 1;
+
+// Whether to print a message if a checked directory isn't available.
+LLVM_PREFERRED_TYPE(bool)
+unsigned PrintDebugStatements : 1;
+  };
+
+  /// Helper function to implement AddClangCXXStdlibIncludeArgs for libc++.
+  bool AddLibcxxInclude(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ,
+llvm::Twine IncludeRoot,
+IncludeStrategy Strategy) const;
+
   /// AddClangCXXStdlibIsystemArgs - Add the clang -cc1 level arguments to set
   /// the specified include paths for the C++ standard library.
   void AddClangCXXStdlibIsystemArgs(const llvm::opt::ArgList ,
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 08b1fd01b3c0ac..42c9d6e91d3c35 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -40,6 +40,7 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/WithColor.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/TargetParser/AArch64TargetParser.h"
@@ -1250,6 +1251,46 @@ void ToolChain::AddClangCXXStdlibIncludeArgs(const 
ArgList ,
   DriverArgs.AddAllArgs(CC1Args, options::OPT_stdlib_EQ);
 }
 
+bool ToolChain::AddLibcxxInclude(const llvm::opt::ArgList ,
+ llvm::opt::ArgStringList ,
+ llvm::Twine IncludeRoot,
+ IncludeStrategy Strategy) const {
+  SmallString<128> Path;
+  IncludeRoot.toVector(Path);
+
+  auto VersionDirName =
+  Strategy.Availability == IncludeStrategy::UseMaxVersionAvailable
+  ? detectLibcxxVersion(Path)
+  : "v1";
+
+  if (VersionDirName.empty())
+return false;
+
+  

[clang] [Clang][Driver] Merge the different strategies of how libc++ is included (PR #83721)

2024-03-03 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 created 
https://github.com/llvm/llvm-project/pull/83721

None

>From 756f80f22744bb0f2bfb81e6c4010054f1279337 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Fri, 1 Mar 2024 20:49:30 +0100
Subject: [PATCH] [Clang][Driver] Merge the different strategies of how libc++
 is included

---
 clang/include/clang/Driver/ToolChain.h   | 41 
 clang/lib/Driver/ToolChain.cpp   | 41 
 clang/lib/Driver/ToolChains/AIX.cpp  | 10 ++---
 clang/lib/Driver/ToolChains/BareMetal.cpp| 13 +++
 clang/lib/Driver/ToolChains/CrossWindows.cpp |  3 +-
 clang/lib/Driver/ToolChains/Darwin.cpp   | 32 ++-
 clang/lib/Driver/ToolChains/FreeBSD.cpp  |  5 ++-
 clang/lib/Driver/ToolChains/Fuchsia.cpp  | 22 ++-
 clang/lib/Driver/ToolChains/Gnu.cpp  |  6 +--
 clang/lib/Driver/ToolChains/Haiku.cpp|  5 ++-
 clang/lib/Driver/ToolChains/Hexagon.cpp  | 27 -
 clang/lib/Driver/ToolChains/MinGW.cpp| 16 +++-
 clang/lib/Driver/ToolChains/MipsLinux.cpp|  7 ++--
 clang/lib/Driver/ToolChains/NaCl.cpp | 16 
 clang/lib/Driver/ToolChains/NetBSD.cpp   | 20 +-
 clang/lib/Driver/ToolChains/OHOS.cpp |  9 ++---
 clang/lib/Driver/ToolChains/OpenBSD.cpp  |  5 ++-
 clang/lib/Driver/ToolChains/WebAssembly.cpp  |  4 +-
 clang/lib/Driver/ToolChains/ZOS.cpp  | 22 ---
 clang/lib/Driver/ToolChains/ZOS.h|  3 --
 20 files changed, 178 insertions(+), 129 deletions(-)

diff --git a/clang/include/clang/Driver/ToolChain.h 
b/clang/include/clang/Driver/ToolChain.h
index fbe2e8fe8e88d8..c61cf2aa064ed5 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -705,6 +705,47 @@ class ToolChain {
   AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList ,
llvm::opt::ArgStringList ) const;
 
+  struct IncludeStrategy {
+enum AvailabilityOptions {
+  // Check whether the directory is exists before adding it to the
+  // include path. This is the case if AssumeAvailable isn't set.
+  CheckIfAvailable,
+
+  // Don't check whether the directory exists. Just assume it does and add
+  // the include.
+  AssumeAvailable,
+
+  // Use v that is inside `/c++`. If not set, 
always
+  // uses v1.
+  UseMaxVersionAvailable,
+};
+
+IncludeStrategy(AvailabilityOptions Availability,
+bool AddTargetDirIfAvailable = false,
+bool PrintDebugStatements = false)
+: Availability(Availability),
+  AddTargetDirIfAvailable(AddTargetDirIfAvailable),
+  PrintDebugStatements(PrintDebugStatements) {}
+
+LLVM_PREFERRED_TYPE(AvailabilityOptions)
+unsigned Availability : 2;
+
+// Check whether the directory `//c++/v`
+// exists, and add it to the include path if it does.
+LLVM_PREFERRED_TYPE(bool)
+unsigned AddTargetDirIfAvailable : 1;
+
+// Whether to print a message if a checked directory isn't available.
+LLVM_PREFERRED_TYPE(bool)
+unsigned PrintDebugStatements : 1;
+  };
+
+  /// Helper function to implement AddClangCXXStdlibIncludeArgs for libc++.
+  bool AddLibcxxInclude(const llvm::opt::ArgList ,
+llvm::opt::ArgStringList ,
+llvm::Twine IncludeRoot,
+IncludeStrategy Strategy) const;
+
   /// AddClangCXXStdlibIsystemArgs - Add the clang -cc1 level arguments to set
   /// the specified include paths for the C++ standard library.
   void AddClangCXXStdlibIsystemArgs(const llvm::opt::ArgList ,
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 08b1fd01b3c0ac..42c9d6e91d3c35 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -40,6 +40,7 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/WithColor.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/TargetParser/AArch64TargetParser.h"
@@ -1250,6 +1251,46 @@ void ToolChain::AddClangCXXStdlibIncludeArgs(const 
ArgList ,
   DriverArgs.AddAllArgs(CC1Args, options::OPT_stdlib_EQ);
 }
 
+bool ToolChain::AddLibcxxInclude(const llvm::opt::ArgList ,
+ llvm::opt::ArgStringList ,
+ llvm::Twine IncludeRoot,
+ IncludeStrategy Strategy) const {
+  SmallString<128> Path;
+  IncludeRoot.toVector(Path);
+
+  auto VersionDirName =
+  Strategy.Availability == IncludeStrategy::UseMaxVersionAvailable
+  ? detectLibcxxVersion(Path)
+  : "v1";
+
+  if (VersionDirName.empty())
+return false;
+
+  if (Strategy.AddTargetDirIfAvailable) {
+SmallString<128> TargetDir(Path);
+llvm::sys::path::append(TargetDir, getTripleString(), 

[clang] [clang][Builtins] Parse clang extended vectors types. (PR #83584)

2024-03-01 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

Hm, yeah. I don't think it's worth complicating the parser for a tiny bit of 
syntax sugar. I like your idea with a `:` quite a bit. `_ExtVector(bool:4)` 
would also be an option. I don't have a strong preference either way. I'd like 
to keep it separate from the name though to make it obvious that it's a 
parameter (at least it feels to me like that).

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


[clang] [clang][Builtins] Parse clang extended vectors types. (PR #83584)

2024-03-01 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:


> @philnik777 - thank you for the patch at #68324

You're welcome!

FWIW I'd find a syntax like `_ExtVector` better. The underscore and 
upper case to make it clear that it's non-standard and the angle bracket syntax 
since it's kind-of a template. This unfortunately doesn't map really nicely to 
anything native otherwise. Maybe think of it like
```c++
template 
using _ExtVector __attribute__((ext_vector_type(N))) = T;
```
Then you'd actually use it as `_ExtVector` in source code.
I don't think that would be significantly harder to parse.

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


[clang] [Clang] Fix __has_cpp_attribute and C++11 attributes with arguments in C++03 (PR #83065)

2024-03-01 Thread Nikolas Klauser via cfe-commits

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


[clang] [Clang] Fix __has_cpp_attribute and C++11 attributes with arguments in C++03 (PR #83065)

2024-03-01 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

The CI failure is unrelated.

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


[clang] [Clang] Fix __has_cpp_attribute and C++11 attributes with arguments in C++03 (PR #83065)

2024-02-29 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/83065

>From 84443dfd39a4a1c567a0e301a3d9892955b9a2fe Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Tue, 27 Feb 2024 14:40:42 +0100
Subject: [PATCH] [Clang] Fix __has_cpp_attribute and C++11 attributes with
 arguments in C++03

Address comments
---
 clang/docs/ReleaseNotes.rst  |  3 ++
 clang/test/Preprocessor/has_attribute.cpp|  4 ++-
 clang/test/SemaCXX/attr-declspec-ignored.cpp |  3 +-
 clang/test/SemaCXX/attr-gnu.cpp  | 29 ++--
 clang/test/SemaCXX/cxx03-cxx11-attr.cpp  |  9 ++
 clang/utils/TableGen/ClangAttrEmitter.cpp| 12 +---
 6 files changed, 33 insertions(+), 27 deletions(-)
 create mode 100644 clang/test/SemaCXX/cxx03-cxx11-attr.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f44fef28b9f17f..4e5c870e4177fe 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -298,6 +298,9 @@ Bug Fixes to C++ Support
   Fixes (`#82941 `_),
   (`#42411 `_), and
   (`#18121 `_).
+- Clang now properly reports supported C++11 attributes when using
+  ``__has_cpp_attribute`` and parses attributes with arguments in C++03
+  (`#82995 `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/test/Preprocessor/has_attribute.cpp 
b/clang/test/Preprocessor/has_attribute.cpp
index 33546dbb175f61..00ec57615c84b8 100644
--- a/clang/test/Preprocessor/has_attribute.cpp
+++ b/clang/test/Preprocessor/has_attribute.cpp
@@ -1,4 +1,6 @@
+// RUN: %clang_cc1 -triple i386-unknown-unknown -fms-compatibility -std=c++03 
-E -P %s -o - | FileCheck %s --check-prefixes=CHECK,ITANIUM 
--implicit-check-not=:
 // RUN: %clang_cc1 -triple i386-unknown-unknown -fms-compatibility -std=c++11 
-E -P %s -o - | FileCheck %s --check-prefixes=CHECK,ITANIUM 
--implicit-check-not=:
+// RUN: %clang_cc1 -triple i386-windows -fms-compatibility -std=c++03 -E -P %s 
-o - | FileCheck %s --check-prefixes=CHECK,WINDOWS --implicit-check-not=:
 // RUN: %clang_cc1 -triple i386-windows -fms-compatibility -std=c++11 -E -P %s 
-o - | FileCheck %s --check-prefixes=CHECK,WINDOWS --implicit-check-not=:
 
 #define CXX11(x) x: __has_cpp_attribute(x)
@@ -65,7 +67,7 @@ CXX11(unlikely)
 // CHECK: likely: 201803L
 // CHECK: maybe_unused: 201603L
 // ITANIUM: no_unique_address: 201803L
-// WINDOWS: no_unique_address: 0 
+// WINDOWS: no_unique_address: 0
 // ITANIUM: msvc::no_unique_address: 0
 // WINDOWS: msvc::no_unique_address: 201803L
 // CHECK: nodiscard: 201907L
diff --git a/clang/test/SemaCXX/attr-declspec-ignored.cpp 
b/clang/test/SemaCXX/attr-declspec-ignored.cpp
index dfea8cc4d47c8d..98e0ffd1a1afdc 100644
--- a/clang/test/SemaCXX/attr-declspec-ignored.cpp
+++ b/clang/test/SemaCXX/attr-declspec-ignored.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -verify -fsyntax-only
+// RUN: %clang_cc1 %s -std=c++03 -Wno-c++11-extensions -verify -fsyntax-only
 
 namespace test1 {
   __attribute__((visibility("hidden")))  __attribute__((aligned)) class A; // 
expected-warning{{attribute 'visibility' is ignored, place it after "class" to 
apply attribute to type declaration}} \
@@ -28,7 +29,7 @@ namespace test1 {
 // expected-warning{{attribute 'aligned' is ignored, place it after "enum 
class" to apply attribute to type declaration}}
 __attribute__((visibility("hidden")))  __attribute__((aligned)) enum 
struct ES {}; // expected-warning{{attribute 'visibility' is ignored, place it 
after "enum struct" to apply attribute to type declaration}} \
 // expected-warning{{attribute 'aligned' is ignored, place it after "enum 
struct" to apply attribute to type declaration}}
-  
+
 // Also test [[]] attribute syntax. (On a non-nested declaration, these
 // generate a hard "misplaced attributes" error, which we test for
 // elsewhere.)
diff --git a/clang/test/SemaCXX/attr-gnu.cpp b/clang/test/SemaCXX/attr-gnu.cpp
index c257c2b029127b..941d01a2e611a8 100644
--- a/clang/test/SemaCXX/attr-gnu.cpp
+++ b/clang/test/SemaCXX/attr-gnu.cpp
@@ -1,7 +1,8 @@
-// RUN: %clang_cc1 -std=gnu++17 -fsyntax-only -fms-compatibility -verify %s
-
-void f() {
-  // GNU-style attributes are prohibited in this position.
+// RUN: %clang_cc1 -std=gnu++03 -fsyntax-only -fms-compatibility 
-Wno-c++11-extensions -Wno-c++17-extensions -verify %s
+// RUN: %clang_cc1 -std=gnu++17 -fsyntax-only -fms-compatibility -verify %s
+
+void f() {
+  // GNU-style attributes are prohibited in this position.
   auto P = new int * __attribute__((vector_size(8))); // expected-error {{an 
attribute list cannot appear here}} \
   // expected-error 
{{invalid vector element type 'int *'}}
 
@@ -47,13 +48,13 @@ void tuTest1(Tu u); // expected-note 

[clang] [Clang] Fix __has_cpp_attribute and C++11 attributes with arguments in C++03 (PR #83065)

2024-02-29 Thread Nikolas Klauser via cfe-commits


@@ -1,7 +1,7 @@
-// RUN: %clang_cc1 -std=gnu++17 -fsyntax-only -fms-compatibility -verify %s
-
-void f() {
-  // GNU-style attributes are prohibited in this position.
+// RUN: %clang_cc1 -std=gnu++17 -fsyntax-only -fms-compatibility -verify %s

philnik777 wrote:

I'm pretty sure these are trailing whitespace removals.

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


[clang] [Clang] Fix __has_cpp_attribute and C++11 attributes with arguments in C++03 (PR #83065)

2024-02-29 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/83065

>From 9b0ebc71341dbda73714c6fbd0da4ec7d338f4b7 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Tue, 27 Feb 2024 14:40:42 +0100
Subject: [PATCH 1/2] [Clang] Fix __has_cpp_attribute and C++11 attributes with
 arguments in C++03

---
 clang/docs/ReleaseNotes.rst   |  4 +++
 clang/test/Preprocessor/has_attribute.cpp |  4 ++-
 clang/test/SemaCXX/attr-declspec-ignored.cpp  |  3 +-
 clang/test/SemaCXX/attr-gnu.cpp   | 29 ++-
 .../SemaCXX/constant-expression-cxx11.cpp |  2 +-
 clang/test/SemaCXX/cxx03-cxx11-attr.cpp   |  9 ++
 clang/utils/TableGen/ClangAttrEmitter.cpp | 12 +---
 7 files changed, 35 insertions(+), 28 deletions(-)
 create mode 100644 clang/test/SemaCXX/cxx03-cxx11-attr.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a5c6b80c4e99e1..54baba6b6b100d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -293,6 +293,10 @@ Bug Fixes to C++ Support
   lookup searches the bases of an incomplete class.
 - Fix a crash when an unresolved overload set is encountered on the RHS of a 
``.*`` operator.
   (`#53815 `_)
+  (`#782154 `_`)
+- Clang now properly reports supported C++11 attributes when using
+  ``__has_cpp_attribute`` and parses attributes with arguments in C++03
+  (`#82995 `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/test/Preprocessor/has_attribute.cpp 
b/clang/test/Preprocessor/has_attribute.cpp
index 33546dbb175f61..00ec57615c84b8 100644
--- a/clang/test/Preprocessor/has_attribute.cpp
+++ b/clang/test/Preprocessor/has_attribute.cpp
@@ -1,4 +1,6 @@
+// RUN: %clang_cc1 -triple i386-unknown-unknown -fms-compatibility -std=c++03 
-E -P %s -o - | FileCheck %s --check-prefixes=CHECK,ITANIUM 
--implicit-check-not=:
 // RUN: %clang_cc1 -triple i386-unknown-unknown -fms-compatibility -std=c++11 
-E -P %s -o - | FileCheck %s --check-prefixes=CHECK,ITANIUM 
--implicit-check-not=:
+// RUN: %clang_cc1 -triple i386-windows -fms-compatibility -std=c++03 -E -P %s 
-o - | FileCheck %s --check-prefixes=CHECK,WINDOWS --implicit-check-not=:
 // RUN: %clang_cc1 -triple i386-windows -fms-compatibility -std=c++11 -E -P %s 
-o - | FileCheck %s --check-prefixes=CHECK,WINDOWS --implicit-check-not=:
 
 #define CXX11(x) x: __has_cpp_attribute(x)
@@ -65,7 +67,7 @@ CXX11(unlikely)
 // CHECK: likely: 201803L
 // CHECK: maybe_unused: 201603L
 // ITANIUM: no_unique_address: 201803L
-// WINDOWS: no_unique_address: 0 
+// WINDOWS: no_unique_address: 0
 // ITANIUM: msvc::no_unique_address: 0
 // WINDOWS: msvc::no_unique_address: 201803L
 // CHECK: nodiscard: 201907L
diff --git a/clang/test/SemaCXX/attr-declspec-ignored.cpp 
b/clang/test/SemaCXX/attr-declspec-ignored.cpp
index dfea8cc4d47c8d..98e0ffd1a1afdc 100644
--- a/clang/test/SemaCXX/attr-declspec-ignored.cpp
+++ b/clang/test/SemaCXX/attr-declspec-ignored.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -verify -fsyntax-only
+// RUN: %clang_cc1 %s -std=c++03 -Wno-c++11-extensions -verify -fsyntax-only
 
 namespace test1 {
   __attribute__((visibility("hidden")))  __attribute__((aligned)) class A; // 
expected-warning{{attribute 'visibility' is ignored, place it after "class" to 
apply attribute to type declaration}} \
@@ -28,7 +29,7 @@ namespace test1 {
 // expected-warning{{attribute 'aligned' is ignored, place it after "enum 
class" to apply attribute to type declaration}}
 __attribute__((visibility("hidden")))  __attribute__((aligned)) enum 
struct ES {}; // expected-warning{{attribute 'visibility' is ignored, place it 
after "enum struct" to apply attribute to type declaration}} \
 // expected-warning{{attribute 'aligned' is ignored, place it after "enum 
struct" to apply attribute to type declaration}}
-  
+
 // Also test [[]] attribute syntax. (On a non-nested declaration, these
 // generate a hard "misplaced attributes" error, which we test for
 // elsewhere.)
diff --git a/clang/test/SemaCXX/attr-gnu.cpp b/clang/test/SemaCXX/attr-gnu.cpp
index c257c2b029127b..941d01a2e611a8 100644
--- a/clang/test/SemaCXX/attr-gnu.cpp
+++ b/clang/test/SemaCXX/attr-gnu.cpp
@@ -1,7 +1,8 @@
-// RUN: %clang_cc1 -std=gnu++17 -fsyntax-only -fms-compatibility -verify %s
-
-void f() {
-  // GNU-style attributes are prohibited in this position.
+// RUN: %clang_cc1 -std=gnu++03 -fsyntax-only -fms-compatibility 
-Wno-c++11-extensions -Wno-c++17-extensions -verify %s
+// RUN: %clang_cc1 -std=gnu++17 -fsyntax-only -fms-compatibility -verify %s
+
+void f() {
+  // GNU-style attributes are prohibited in this position.
   auto P = new int * __attribute__((vector_size(8))); // expected-error {{an 
attribute list cannot appear here}} \
   

[clang] [Clang] Fix __has_cpp_attribute and C++11 attributes with arguments in C++03 (PR #83065)

2024-02-27 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/83065

>From f97ef5d3efc94585e531339a233cfb3007734d9a Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Tue, 27 Feb 2024 14:40:42 +0100
Subject: [PATCH 1/2] [Clang] Fix __has_cpp_attribute and C++11 attributes with
 arguments in C++03

---
 clang/docs/ReleaseNotes.rst  |  4 
 clang/test/Preprocessor/has_attribute.cpp|  4 +++-
 clang/test/SemaCXX/constant-expression-cxx11.cpp |  2 +-
 clang/test/SemaCXX/cxx03-cxx11-attr.cpp  |  9 +
 clang/utils/TableGen/ClangAttrEmitter.cpp| 12 +---
 5 files changed, 18 insertions(+), 13 deletions(-)
 create mode 100644 clang/test/SemaCXX/cxx03-cxx11-attr.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 515dffa28df186..1e804dfe69e144 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -285,6 +285,10 @@ Bug Fixes to C++ Support
   templates when determining the primary template of an explicit 
specialization.
 - Fixed a crash in Microsoft compatibility mode where unqualified dependent 
base class
   lookup searches the bases of an incomplete class.
+  (`#782154 `_`)
+- Clang now properly reports supported C++11 attributes when using
+  ``__has_cpp_attribute`` and parses attributes with arguments in C++03
+  (`#82995 `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/test/Preprocessor/has_attribute.cpp 
b/clang/test/Preprocessor/has_attribute.cpp
index 33546dbb175f61..00ec57615c84b8 100644
--- a/clang/test/Preprocessor/has_attribute.cpp
+++ b/clang/test/Preprocessor/has_attribute.cpp
@@ -1,4 +1,6 @@
+// RUN: %clang_cc1 -triple i386-unknown-unknown -fms-compatibility -std=c++03 
-E -P %s -o - | FileCheck %s --check-prefixes=CHECK,ITANIUM 
--implicit-check-not=:
 // RUN: %clang_cc1 -triple i386-unknown-unknown -fms-compatibility -std=c++11 
-E -P %s -o - | FileCheck %s --check-prefixes=CHECK,ITANIUM 
--implicit-check-not=:
+// RUN: %clang_cc1 -triple i386-windows -fms-compatibility -std=c++03 -E -P %s 
-o - | FileCheck %s --check-prefixes=CHECK,WINDOWS --implicit-check-not=:
 // RUN: %clang_cc1 -triple i386-windows -fms-compatibility -std=c++11 -E -P %s 
-o - | FileCheck %s --check-prefixes=CHECK,WINDOWS --implicit-check-not=:
 
 #define CXX11(x) x: __has_cpp_attribute(x)
@@ -65,7 +67,7 @@ CXX11(unlikely)
 // CHECK: likely: 201803L
 // CHECK: maybe_unused: 201603L
 // ITANIUM: no_unique_address: 201803L
-// WINDOWS: no_unique_address: 0 
+// WINDOWS: no_unique_address: 0
 // ITANIUM: msvc::no_unique_address: 0
 // WINDOWS: msvc::no_unique_address: 201803L
 // CHECK: nodiscard: 201907L
diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp 
b/clang/test/SemaCXX/constant-expression-cxx11.cpp
index 9e2ae07cbe4c9c..e71659440aa11d 100644
--- a/clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++23 -isystem %S/Inputs -fsyntax-only 
-verify=expected,cxx20_23,cxx23-triple x86_64-linux -Wno-string-plus-int 
-Wno-pointer-arith -Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions 
-pedantic %s -Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
+// RUN: %clang_cc1 -std=c++23 -isystem %S/Inputs 
-fexperimental-new-constant-interpreter -fsyntax-only 
-verify=expected,cxx20_23,cxx23-triple x86_64-linux -Wno-string-plus-int 
-Wno-pointer-arith -Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions 
-pedantic %s -Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
 // RUN: %clang_cc1 -std=c++20 -isystem %S/Inputs -fsyntax-only 
-verify=expected,cxx11_20,cxx20_23 -triple x86_64-linux -Wno-string-plus-int 
-Wno-pointer-arith -Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions 
-pedantic %s -Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
 // RUN: %clang_cc1 -std=c++11 -isystem %S/Inputs -fsyntax-only 
-verify=expected,cxx11_20,cxx11-triple x86_64-linux -Wno-string-plus-int 
-Wno-pointer-arith -Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions 
-pedantic %s -Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
 
diff --git a/clang/test/SemaCXX/cxx03-cxx11-attr.cpp 
b/clang/test/SemaCXX/cxx03-cxx11-attr.cpp
new file mode 100644
index 00..5a273c8fe2534a
--- /dev/null
+++ b/clang/test/SemaCXX/cxx03-cxx11-attr.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -std=c++03 -fsyntax-only %s
+
+// Ensure that __has_cpp_attribute and argument parsing work in C++03
+
+#if !__has_cpp_attribute(nodiscard)
+#  error
+#endif
+
+[[gnu::assume_aligned(4)]] void* g() { return __nullptr; }
diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 935b9846990ee5..eb5c34d15693d7 100644
--- 

[clang] [Clang] Fix __has_cpp_attribute and C++11 attributes with arguments in C++03 (PR #83065)

2024-02-27 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/83065

>From f97ef5d3efc94585e531339a233cfb3007734d9a Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Tue, 27 Feb 2024 14:40:42 +0100
Subject: [PATCH] [Clang] Fix __has_cpp_attribute and C++11 attributes with
 arguments in C++03

---
 clang/docs/ReleaseNotes.rst  |  4 
 clang/test/Preprocessor/has_attribute.cpp|  4 +++-
 clang/test/SemaCXX/constant-expression-cxx11.cpp |  2 +-
 clang/test/SemaCXX/cxx03-cxx11-attr.cpp  |  9 +
 clang/utils/TableGen/ClangAttrEmitter.cpp| 12 +---
 5 files changed, 18 insertions(+), 13 deletions(-)
 create mode 100644 clang/test/SemaCXX/cxx03-cxx11-attr.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 515dffa28df186..1e804dfe69e144 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -285,6 +285,10 @@ Bug Fixes to C++ Support
   templates when determining the primary template of an explicit 
specialization.
 - Fixed a crash in Microsoft compatibility mode where unqualified dependent 
base class
   lookup searches the bases of an incomplete class.
+  (`#782154 `_`)
+- Clang now properly reports supported C++11 attributes when using
+  ``__has_cpp_attribute`` and parses attributes with arguments in C++03
+  (`#82995 `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/test/Preprocessor/has_attribute.cpp 
b/clang/test/Preprocessor/has_attribute.cpp
index 33546dbb175f61..00ec57615c84b8 100644
--- a/clang/test/Preprocessor/has_attribute.cpp
+++ b/clang/test/Preprocessor/has_attribute.cpp
@@ -1,4 +1,6 @@
+// RUN: %clang_cc1 -triple i386-unknown-unknown -fms-compatibility -std=c++03 
-E -P %s -o - | FileCheck %s --check-prefixes=CHECK,ITANIUM 
--implicit-check-not=:
 // RUN: %clang_cc1 -triple i386-unknown-unknown -fms-compatibility -std=c++11 
-E -P %s -o - | FileCheck %s --check-prefixes=CHECK,ITANIUM 
--implicit-check-not=:
+// RUN: %clang_cc1 -triple i386-windows -fms-compatibility -std=c++03 -E -P %s 
-o - | FileCheck %s --check-prefixes=CHECK,WINDOWS --implicit-check-not=:
 // RUN: %clang_cc1 -triple i386-windows -fms-compatibility -std=c++11 -E -P %s 
-o - | FileCheck %s --check-prefixes=CHECK,WINDOWS --implicit-check-not=:
 
 #define CXX11(x) x: __has_cpp_attribute(x)
@@ -65,7 +67,7 @@ CXX11(unlikely)
 // CHECK: likely: 201803L
 // CHECK: maybe_unused: 201603L
 // ITANIUM: no_unique_address: 201803L
-// WINDOWS: no_unique_address: 0 
+// WINDOWS: no_unique_address: 0
 // ITANIUM: msvc::no_unique_address: 0
 // WINDOWS: msvc::no_unique_address: 201803L
 // CHECK: nodiscard: 201907L
diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp 
b/clang/test/SemaCXX/constant-expression-cxx11.cpp
index 9e2ae07cbe4c9c..e71659440aa11d 100644
--- a/clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++23 -isystem %S/Inputs -fsyntax-only 
-verify=expected,cxx20_23,cxx23-triple x86_64-linux -Wno-string-plus-int 
-Wno-pointer-arith -Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions 
-pedantic %s -Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
+// RUN: %clang_cc1 -std=c++23 -isystem %S/Inputs 
-fexperimental-new-constant-interpreter -fsyntax-only 
-verify=expected,cxx20_23,cxx23-triple x86_64-linux -Wno-string-plus-int 
-Wno-pointer-arith -Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions 
-pedantic %s -Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
 // RUN: %clang_cc1 -std=c++20 -isystem %S/Inputs -fsyntax-only 
-verify=expected,cxx11_20,cxx20_23 -triple x86_64-linux -Wno-string-plus-int 
-Wno-pointer-arith -Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions 
-pedantic %s -Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
 // RUN: %clang_cc1 -std=c++11 -isystem %S/Inputs -fsyntax-only 
-verify=expected,cxx11_20,cxx11-triple x86_64-linux -Wno-string-plus-int 
-Wno-pointer-arith -Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions 
-pedantic %s -Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
 
diff --git a/clang/test/SemaCXX/cxx03-cxx11-attr.cpp 
b/clang/test/SemaCXX/cxx03-cxx11-attr.cpp
new file mode 100644
index 00..5a273c8fe2534a
--- /dev/null
+++ b/clang/test/SemaCXX/cxx03-cxx11-attr.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -std=c++03 -fsyntax-only %s
+
+// Ensure that __has_cpp_attribute and argument parsing work in C++03
+
+#if !__has_cpp_attribute(nodiscard)
+#  error
+#endif
+
+[[gnu::assume_aligned(4)]] void* g() { return __nullptr; }
diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 935b9846990ee5..eb5c34d15693d7 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp

[clang] [Clang] Fix __has_cpp_attribute and C++11 attributes with arguments in C++03 (PR #83065)

2024-02-27 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/83065

>From 497b6639231f9d3141cc3278b3e476edd1d642d2 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Tue, 27 Feb 2024 14:40:42 +0100
Subject: [PATCH] [Clang] Fix __has_cpp_attribute and C++11 attributes with
 arguments in C++03

---
 clang/docs/ReleaseNotes.rst  |  1 +
 clang/test/Preprocessor/has_attribute.cpp|  4 +++-
 clang/test/SemaCXX/constant-expression-cxx11.cpp |  2 +-
 clang/test/SemaCXX/cxx03-cxx11-attr.cpp  |  9 +
 clang/utils/TableGen/ClangAttrEmitter.cpp| 12 +---
 5 files changed, 15 insertions(+), 13 deletions(-)
 create mode 100644 clang/test/SemaCXX/cxx03-cxx11-attr.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 45ace4191592d3..4e0b28cb21ce27 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -267,6 +267,7 @@ Bug Fixes to C++ Support
   was only accepted at namespace scope but not at local function scope.
 - Clang no longer tries to call consteval constructors at runtime when they 
appear in a member initializer.
   (`#782154 `_`)
+- Fixes (`#82995 `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/test/Preprocessor/has_attribute.cpp 
b/clang/test/Preprocessor/has_attribute.cpp
index 33546dbb175f61..00ec57615c84b8 100644
--- a/clang/test/Preprocessor/has_attribute.cpp
+++ b/clang/test/Preprocessor/has_attribute.cpp
@@ -1,4 +1,6 @@
+// RUN: %clang_cc1 -triple i386-unknown-unknown -fms-compatibility -std=c++03 
-E -P %s -o - | FileCheck %s --check-prefixes=CHECK,ITANIUM 
--implicit-check-not=:
 // RUN: %clang_cc1 -triple i386-unknown-unknown -fms-compatibility -std=c++11 
-E -P %s -o - | FileCheck %s --check-prefixes=CHECK,ITANIUM 
--implicit-check-not=:
+// RUN: %clang_cc1 -triple i386-windows -fms-compatibility -std=c++03 -E -P %s 
-o - | FileCheck %s --check-prefixes=CHECK,WINDOWS --implicit-check-not=:
 // RUN: %clang_cc1 -triple i386-windows -fms-compatibility -std=c++11 -E -P %s 
-o - | FileCheck %s --check-prefixes=CHECK,WINDOWS --implicit-check-not=:
 
 #define CXX11(x) x: __has_cpp_attribute(x)
@@ -65,7 +67,7 @@ CXX11(unlikely)
 // CHECK: likely: 201803L
 // CHECK: maybe_unused: 201603L
 // ITANIUM: no_unique_address: 201803L
-// WINDOWS: no_unique_address: 0 
+// WINDOWS: no_unique_address: 0
 // ITANIUM: msvc::no_unique_address: 0
 // WINDOWS: msvc::no_unique_address: 201803L
 // CHECK: nodiscard: 201907L
diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp 
b/clang/test/SemaCXX/constant-expression-cxx11.cpp
index 9e2ae07cbe4c9c..e71659440aa11d 100644
--- a/clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++23 -isystem %S/Inputs -fsyntax-only 
-verify=expected,cxx20_23,cxx23-triple x86_64-linux -Wno-string-plus-int 
-Wno-pointer-arith -Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions 
-pedantic %s -Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
+// RUN: %clang_cc1 -std=c++23 -isystem %S/Inputs 
-fexperimental-new-constant-interpreter -fsyntax-only 
-verify=expected,cxx20_23,cxx23-triple x86_64-linux -Wno-string-plus-int 
-Wno-pointer-arith -Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions 
-pedantic %s -Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
 // RUN: %clang_cc1 -std=c++20 -isystem %S/Inputs -fsyntax-only 
-verify=expected,cxx11_20,cxx20_23 -triple x86_64-linux -Wno-string-plus-int 
-Wno-pointer-arith -Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions 
-pedantic %s -Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
 // RUN: %clang_cc1 -std=c++11 -isystem %S/Inputs -fsyntax-only 
-verify=expected,cxx11_20,cxx11-triple x86_64-linux -Wno-string-plus-int 
-Wno-pointer-arith -Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions 
-pedantic %s -Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
 
diff --git a/clang/test/SemaCXX/cxx03-cxx11-attr.cpp 
b/clang/test/SemaCXX/cxx03-cxx11-attr.cpp
new file mode 100644
index 00..5a273c8fe2534a
--- /dev/null
+++ b/clang/test/SemaCXX/cxx03-cxx11-attr.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -std=c++03 -fsyntax-only %s
+
+// Ensure that __has_cpp_attribute and argument parsing work in C++03
+
+#if !__has_cpp_attribute(nodiscard)
+#  error
+#endif
+
+[[gnu::assume_aligned(4)]] void* g() { return __nullptr; }
diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 935b9846990ee5..eb5c34d15693d7 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -3576,10 +3576,6 @@ static void GenerateHasAttrSpellingStringSwitch(
   const Record *R = Attr->getValueAsDef("Target");
   

[clang] [Clang] Fix __has_cpp_attribute and C++11 attributes with arguments in C++03 (PR #83065)

2024-02-27 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/83065

>From 6a439dd61803e7da91a7791453ca7b9acb90b1b6 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Mon, 26 Feb 2024 22:39:05 +0100
Subject: [PATCH] [Clang] Fix __has_cpp_attribute and C++11 attributes with
 arguments in C++03

---
 clang/test/Preprocessor/has_attribute.cpp |  4 +++-
 clang/test/SemaCXX/attr-gnu.cpp   | 28 +++
 clang/test/SemaCXX/cxx03-cxx11-attr.cpp   |  9 
 clang/utils/TableGen/ClangAttrEmitter.cpp | 12 +-
 4 files changed, 27 insertions(+), 26 deletions(-)
 create mode 100644 clang/test/SemaCXX/cxx03-cxx11-attr.cpp

diff --git a/clang/test/Preprocessor/has_attribute.cpp 
b/clang/test/Preprocessor/has_attribute.cpp
index 33546dbb175f61..00ec57615c84b8 100644
--- a/clang/test/Preprocessor/has_attribute.cpp
+++ b/clang/test/Preprocessor/has_attribute.cpp
@@ -1,4 +1,6 @@
+// RUN: %clang_cc1 -triple i386-unknown-unknown -fms-compatibility -std=c++03 
-E -P %s -o - | FileCheck %s --check-prefixes=CHECK,ITANIUM 
--implicit-check-not=:
 // RUN: %clang_cc1 -triple i386-unknown-unknown -fms-compatibility -std=c++11 
-E -P %s -o - | FileCheck %s --check-prefixes=CHECK,ITANIUM 
--implicit-check-not=:
+// RUN: %clang_cc1 -triple i386-windows -fms-compatibility -std=c++03 -E -P %s 
-o - | FileCheck %s --check-prefixes=CHECK,WINDOWS --implicit-check-not=:
 // RUN: %clang_cc1 -triple i386-windows -fms-compatibility -std=c++11 -E -P %s 
-o - | FileCheck %s --check-prefixes=CHECK,WINDOWS --implicit-check-not=:
 
 #define CXX11(x) x: __has_cpp_attribute(x)
@@ -65,7 +67,7 @@ CXX11(unlikely)
 // CHECK: likely: 201803L
 // CHECK: maybe_unused: 201603L
 // ITANIUM: no_unique_address: 201803L
-// WINDOWS: no_unique_address: 0 
+// WINDOWS: no_unique_address: 0
 // ITANIUM: msvc::no_unique_address: 0
 // WINDOWS: msvc::no_unique_address: 201803L
 // CHECK: nodiscard: 201907L
diff --git a/clang/test/SemaCXX/attr-gnu.cpp b/clang/test/SemaCXX/attr-gnu.cpp
index c257c2b029127b..e7063ce020e2b7 100644
--- a/clang/test/SemaCXX/attr-gnu.cpp
+++ b/clang/test/SemaCXX/attr-gnu.cpp
@@ -1,7 +1,7 @@
-// RUN: %clang_cc1 -std=gnu++17 -fsyntax-only -fms-compatibility -verify %s
-
-void f() {
-  // GNU-style attributes are prohibited in this position.
+// RUN: %clang_cc1 -std=gnu++17 -fsyntax-only -fms-compatibility -verify %s
+
+void f() {
+  // GNU-style attributes are prohibited in this position.
   auto P = new int * __attribute__((vector_size(8))); // expected-error {{an 
attribute list cannot appear here}} \
   // expected-error 
{{invalid vector element type 'int *'}}
 
@@ -47,13 +47,13 @@ void tuTest1(Tu u); // expected-note {{candidate 
function not viable: no kn
 void tuTest2(Tu3 u); // expected-note {{candidate function not viable: no 
known conversion from 'int' to 'Tu3' for 1st argument}}
 void tu() {
   int x = 2;
-  tuTest1(x); // expected-error {{no matching function for call to 'tuTest1'}}
-  tuTest2(x); // expected-error {{no matching function for call to 'tuTest2'}}
-}
-
-[[gnu::__const__]] int f2() { return 12; }
-[[__gnu__::__const__]] int f3() { return 12; }
-[[using __gnu__ : __const__]] int f4() { return 12; }
-
-static_assert(__has_cpp_attribute(gnu::__const__));
-static_assert(__has_cpp_attribute(__gnu__::__const__));
+  tuTest1(x); // expected-error {{no matching function for call to 'tuTest1'}}
+  tuTest2(x); // expected-error {{no matching function for call to 'tuTest2'}}
+}
+
+[[gnu::__const__]] int f2() { return 12; }
+[[__gnu__::__const__]] int f3() { return 12; }
+[[using __gnu__ : __const__]] int f4() { return 12; }
+
+static_assert(__has_cpp_attribute(gnu::__const__));
+static_assert(__has_cpp_attribute(__gnu__::__const__));
diff --git a/clang/test/SemaCXX/cxx03-cxx11-attr.cpp 
b/clang/test/SemaCXX/cxx03-cxx11-attr.cpp
new file mode 100644
index 00..5a273c8fe2534a
--- /dev/null
+++ b/clang/test/SemaCXX/cxx03-cxx11-attr.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -std=c++03 -fsyntax-only %s
+
+// Ensure that __has_cpp_attribute and argument parsing work in C++03
+
+#if !__has_cpp_attribute(nodiscard)
+#  error
+#endif
+
+[[gnu::assume_aligned(4)]] void* g() { return __nullptr; }
diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 935b9846990ee5..eb5c34d15693d7 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -3576,10 +3576,6 @@ static void GenerateHasAttrSpellingStringSwitch(
   const Record *R = Attr->getValueAsDef("Target");
   std::vector Arches = R->getValueAsListOfStrings("Arches");
   GenerateTargetSpecificAttrChecks(R, Arches, Test, nullptr);
-
-  // If this is the C++11 variety, also add in the LangOpts test.
-  if (Variety == "CXX11")
-Test += " && LangOpts.CPlusPlus11";
 } else if (!Attr->getValueAsListOfDefs("TargetSpecificSpellings").empty()) 
{
   

[clang] [Clang] Fix __has_cpp_attribute and C++11 attributes with arguments in C++03 (PR #83065)

2024-02-26 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 created 
https://github.com/llvm/llvm-project/pull/83065


The values for `__has_cpp_attribute` don't have to be guarded behind 
`LangOpts.CPlusPlus` because `__has_cpp_attribute` isn't available if Clang 
isn't in a C++ mode.

Fixes #82995



>From b64d25b222b4c8c4839eb2e77f72c77596f133f2 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Mon, 26 Feb 2024 22:39:05 +0100
Subject: [PATCH] [Clang] Fix __has_cpp_attribute and C++11 attributes with
 arguments in C++03

---
 clang/test/SemaCXX/cxx03-cxx11-attr.cpp   |  9 +
 clang/utils/TableGen/ClangAttrEmitter.cpp | 12 +---
 2 files changed, 10 insertions(+), 11 deletions(-)
 create mode 100644 clang/test/SemaCXX/cxx03-cxx11-attr.cpp

diff --git a/clang/test/SemaCXX/cxx03-cxx11-attr.cpp 
b/clang/test/SemaCXX/cxx03-cxx11-attr.cpp
new file mode 100644
index 00..5a273c8fe2534a
--- /dev/null
+++ b/clang/test/SemaCXX/cxx03-cxx11-attr.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -std=c++03 -fsyntax-only %s
+
+// Ensure that __has_cpp_attribute and argument parsing work in C++03
+
+#if !__has_cpp_attribute(nodiscard)
+#  error
+#endif
+
+[[gnu::assume_aligned(4)]] void* g() { return __nullptr; }
diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 935b9846990ee5..eb5c34d15693d7 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -3576,10 +3576,6 @@ static void GenerateHasAttrSpellingStringSwitch(
   const Record *R = Attr->getValueAsDef("Target");
   std::vector Arches = R->getValueAsListOfStrings("Arches");
   GenerateTargetSpecificAttrChecks(R, Arches, Test, nullptr);
-
-  // If this is the C++11 variety, also add in the LangOpts test.
-  if (Variety == "CXX11")
-Test += " && LangOpts.CPlusPlus11";
 } else if (!Attr->getValueAsListOfDefs("TargetSpecificSpellings").empty()) 
{
   // Add target checks if this spelling is target-specific.
   const std::vector TargetSpellings =
@@ -3597,13 +3593,7 @@ static void GenerateHasAttrSpellingStringSwitch(
   }
 }
   }
-
-  if (Variety == "CXX11")
-Test += " && LangOpts.CPlusPlus11";
-} else if (Variety == "CXX11")
-  // C++11 mode should be checked against LangOpts, which is presumed to be
-  // present in the caller.
-  Test = "LangOpts.CPlusPlus11";
+}
 
 std::string TestStr = !Test.empty()
   ? Test + " ? " + llvm::itostr(Version) + " : 0"

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


[clang] [clang] Fix crash when declaring invalid lambda member (PR #74110)

2024-02-15 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

Ping (@AaronBallman maybe?)

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


[clang] [clang] Fix behavior of `__is_trivially_relocatable(volatile int)` (PR #77092)

2024-02-12 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

This isn't ABI breaking for us currently (at least in a non-benign way). We 
only use it to optimize `vector` growing currently, and just define it to 
`is_trivially_copyable` if `__is_trivially_relocatable` isn't available.

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


[clang] [libcxx] [Clang] Add __is_invocable_r and __is_nothrow_invocable_r (PR #81213)

2024-02-12 Thread Nikolas Klauser via cfe-commits

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


[clang] [libcxx] [Clang] Add __is_invocable_r and __is_nothrow_invocable_r (PR #81213)

2024-02-09 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/81213

>From a6ef9191b3a68e68e7dd225bfb1e802f7542ccd9 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Mon, 11 Sep 2023 04:31:02 +0200
Subject: [PATCH] [Clang] Add __is_invocable_r and __is_nothrow_invocable_r

This patch also uses the new builtins in libc++.
---
 clang/docs/LanguageExtensions.rst|   2 +
 clang/docs/ReleaseNotes.rst  |   4 +
 clang/include/clang/Basic/TokenKinds.def |   2 +
 clang/lib/Sema/SemaExprCXX.cpp   | 395 +--
 clang/test/SemaCXX/type-traits-invocable.cpp | 312 +++
 libcxx/include/__type_traits/invoke.h|  40 +-
 6 files changed, 634 insertions(+), 121 deletions(-)
 create mode 100644 clang/test/SemaCXX/type-traits-invocable.cpp

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index e91156837290f7..bf061590e5ca0b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1582,6 +1582,7 @@ The following type trait primitives are supported by 
Clang. Those traits marked
 * ``__is_integral`` (C++, Embarcadero)
 * ``__is_interface_class`` (Microsoft):
   Returns ``false``, even for types defined with ``__interface``.
+* ``__is_invocable_r`` (Clang)
 * ``__is_literal`` (Clang):
   Synonym for ``__is_literal_type``.
 * ``__is_literal_type`` (C++, GNU, Microsoft):
@@ -1594,6 +1595,7 @@ The following type trait primitives are supported by 
Clang. Those traits marked
 * ``__is_nothrow_assignable`` (C++, MSVC 2013)
 * ``__is_nothrow_constructible`` (C++, MSVC 2013)
 * ``__is_nothrow_destructible`` (C++, MSVC 2013)
+* ``__is_nothrow_invocable_r`` (Clang)
 * ``__is_nullptr`` (C++, GNU, Microsoft, Embarcadero):
   Returns true for ``std::nullptr_t`` and false for everything else. The
   corresponding standard library feature is ``std::is_null_pointer``, but
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index cd8a82f281f52a..8a4ae646c008f6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -78,6 +78,10 @@ here. Generic improvements to Clang as a whole or to its 
underlying
 infrastructure are described first, followed by language-specific
 sections with improvements to Clang's support for those languages.
 
+- The builtins `__is_invocable_r` and `__is_nothrow_invocable_r` have been 
added.
+  These are equivalent to the standard library builtins `std::is_invocable_r`
+  and `std::is_nothrow_invocable_r`.
+
 C++ Language Changes
 
 
diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 23817cde7a9354..6467a52c82cb5b 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -532,6 +532,8 @@ TYPE_TRAIT_1(__is_unbounded_array, IsUnboundedArray, KEYCXX)
 TYPE_TRAIT_1(__is_nullptr, IsNullPointer, KEYCXX)
 TYPE_TRAIT_1(__is_scoped_enum, IsScopedEnum, KEYCXX)
 TYPE_TRAIT_1(__is_referenceable, IsReferenceable, KEYCXX)
+TYPE_TRAIT_N(__is_invocable_r, IsInvocableR, KEYCXX)
+TYPE_TRAIT_N(__is_nothrow_invocable_r, IsNothrowInvocableR, KEYCXX)
 TYPE_TRAIT_1(__can_pass_in_regs, CanPassInRegs, KEYCXX)
 TYPE_TRAIT_2(__reference_binds_to_temporary, ReferenceBindsToTemporary, KEYCXX)
 TYPE_TRAIT_2(__reference_constructs_from_temporary, 
ReferenceConstructsFromTemporary, KEYCXX)
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 246d2313e089f3..6fca4b0edda1e7 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5468,6 +5468,271 @@ static bool EvaluateUnaryTypeTrait(Sema , 
TypeTrait UTT,
 static bool EvaluateBinaryTypeTrait(Sema , TypeTrait BTT, QualType LhsT,
 QualType RhsT, SourceLocation KeyLoc);
 
+static bool IsBaseOf(Sema , QualType LhsT, QualType RhsT,
+ SourceLocation KeyLoc) {
+  // C++0x [meta.rel]p2
+  // Base is a base class of Derived without regard to cv-qualifiers or
+  // Base and Derived are not unions and name the same class type without
+  // regard to cv-qualifiers.
+
+  const RecordType *lhsRecord = LhsT->getAs();
+  const RecordType *rhsRecord = RhsT->getAs();
+  if (!rhsRecord || !lhsRecord) {
+const ObjCObjectType *LHSObjTy = LhsT->getAs();
+const ObjCObjectType *RHSObjTy = RhsT->getAs();
+if (!LHSObjTy || !RHSObjTy)
+  return false;
+
+ObjCInterfaceDecl *BaseInterface = LHSObjTy->getInterface();
+ObjCInterfaceDecl *DerivedInterface = RHSObjTy->getInterface();
+if (!BaseInterface || !DerivedInterface)
+  return false;
+
+if (Self.RequireCompleteType(
+KeyLoc, RhsT, diag::err_incomplete_type_used_in_type_trait_expr))
+  return false;
+
+return BaseInterface->isSuperClassOf(DerivedInterface);
+  }
+
+  assert(Self.Context.hasSameUnqualifiedType(LhsT, RhsT) ==
+ (lhsRecord == rhsRecord));
+
+  // Unions are never base 

[clang] [libcxx] [Clang] Add __is_invocable_r and __is_nothrow_invocable_r (PR #81213)

2024-02-09 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/81213

>From b0b0072067c650e0eb1f4a556301cbc5b873935d Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Mon, 11 Sep 2023 04:31:02 +0200
Subject: [PATCH] [Clang] Add __is_invocable_r and __is_nothrow_invocable_r

This patch also uses the new builtins in libc++.
---
 clang/docs/LanguageExtensions.rst|   2 +
 clang/docs/ReleaseNotes.rst  |   4 +
 clang/include/clang/AST/Type.h   |   4 +
 clang/include/clang/Basic/TokenKinds.def |   2 +
 clang/lib/Sema/SemaExprCXX.cpp   | 395 +--
 clang/test/SemaCXX/type-traits-invocable.cpp | 308 +++
 libcxx/include/__type_traits/invoke.h|  40 +-
 7 files changed, 634 insertions(+), 121 deletions(-)
 create mode 100644 clang/test/SemaCXX/type-traits-invocable.cpp

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index e91156837290f7..bf061590e5ca0b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1582,6 +1582,7 @@ The following type trait primitives are supported by 
Clang. Those traits marked
 * ``__is_integral`` (C++, Embarcadero)
 * ``__is_interface_class`` (Microsoft):
   Returns ``false``, even for types defined with ``__interface``.
+* ``__is_invocable_r`` (Clang)
 * ``__is_literal`` (Clang):
   Synonym for ``__is_literal_type``.
 * ``__is_literal_type`` (C++, GNU, Microsoft):
@@ -1594,6 +1595,7 @@ The following type trait primitives are supported by 
Clang. Those traits marked
 * ``__is_nothrow_assignable`` (C++, MSVC 2013)
 * ``__is_nothrow_constructible`` (C++, MSVC 2013)
 * ``__is_nothrow_destructible`` (C++, MSVC 2013)
+* ``__is_nothrow_invocable_r`` (Clang)
 * ``__is_nullptr`` (C++, GNU, Microsoft, Embarcadero):
   Returns true for ``std::nullptr_t`` and false for everything else. The
   corresponding standard library feature is ``std::is_null_pointer``, but
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index cd8a82f281f52a..8a4ae646c008f6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -78,6 +78,10 @@ here. Generic improvements to Clang as a whole or to its 
underlying
 infrastructure are described first, followed by language-specific
 sections with improvements to Clang's support for those languages.
 
+- The builtins `__is_invocable_r` and `__is_nothrow_invocable_r` have been 
added.
+  These are equivalent to the standard library builtins `std::is_invocable_r`
+  and `std::is_nothrow_invocable_r`.
+
 C++ Language Changes
 
 
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index d6a55f39a4bede..a3ab09db7fad6a 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -4578,6 +4578,10 @@ class FunctionProtoType final
 return static_cast(FunctionTypeBits.RefQualifier);
   }
 
+  bool isAbominable() const {
+return !getMethodQuals().empty() || getRefQualifier() != RQ_None;
+  }
+
   using param_type_iterator = const QualType *;
 
   ArrayRef param_types() const {
diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 23817cde7a9354..6467a52c82cb5b 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -532,6 +532,8 @@ TYPE_TRAIT_1(__is_unbounded_array, IsUnboundedArray, KEYCXX)
 TYPE_TRAIT_1(__is_nullptr, IsNullPointer, KEYCXX)
 TYPE_TRAIT_1(__is_scoped_enum, IsScopedEnum, KEYCXX)
 TYPE_TRAIT_1(__is_referenceable, IsReferenceable, KEYCXX)
+TYPE_TRAIT_N(__is_invocable_r, IsInvocableR, KEYCXX)
+TYPE_TRAIT_N(__is_nothrow_invocable_r, IsNothrowInvocableR, KEYCXX)
 TYPE_TRAIT_1(__can_pass_in_regs, CanPassInRegs, KEYCXX)
 TYPE_TRAIT_2(__reference_binds_to_temporary, ReferenceBindsToTemporary, KEYCXX)
 TYPE_TRAIT_2(__reference_constructs_from_temporary, 
ReferenceConstructsFromTemporary, KEYCXX)
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 246d2313e089f3..e18b6fdc99e919 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5468,6 +5468,271 @@ static bool EvaluateUnaryTypeTrait(Sema , 
TypeTrait UTT,
 static bool EvaluateBinaryTypeTrait(Sema , TypeTrait BTT, QualType LhsT,
 QualType RhsT, SourceLocation KeyLoc);
 
+static bool IsBaseOf(Sema , QualType LhsT, QualType RhsT,
+ SourceLocation KeyLoc) {
+  // C++0x [meta.rel]p2
+  // Base is a base class of Derived without regard to cv-qualifiers or
+  // Base and Derived are not unions and name the same class type without
+  // regard to cv-qualifiers.
+
+  const RecordType *lhsRecord = LhsT->getAs();
+  const RecordType *rhsRecord = RhsT->getAs();
+  if (!rhsRecord || !lhsRecord) {
+const ObjCObjectType *LHSObjTy = LhsT->getAs();
+const ObjCObjectType *RHSObjTy = RhsT->getAs();
+if (!LHSObjTy || !RHSObjTy)
+  

[clang] [libcxx] [clang][Sema] Add checks for validity of default ctor's class (PR #78898)

2024-02-09 Thread Nikolas Klauser via cfe-commits

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

The libc++ changes LGTM.

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


[clang] [libcxx] [Clang] Add __is_invocable_r and __is_nothrow_invocable_r (PR #81213)

2024-02-08 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/81213

>From 8657d0de76373665c55b774b9cdffe9707288efc Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Mon, 11 Sep 2023 04:31:02 +0200
Subject: [PATCH] [Clang] Add __is_invocable_r and __is_nothrow_invocable_r

This patch also uses the new builtins in libc++.
---
 clang/docs/LanguageExtensions.rst|   2 +
 clang/docs/ReleaseNotes.rst  |   4 +
 clang/include/clang/Basic/TokenKinds.def |   2 +
 clang/lib/Sema/SemaExprCXX.cpp   | 390 +--
 clang/test/SemaCXX/type-traits-invocable.cpp | 288 ++
 libcxx/include/__type_traits/invoke.h|  40 +-
 6 files changed, 605 insertions(+), 121 deletions(-)
 create mode 100644 clang/test/SemaCXX/type-traits-invocable.cpp

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index e91156837290f..bf061590e5ca0 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1582,6 +1582,7 @@ The following type trait primitives are supported by 
Clang. Those traits marked
 * ``__is_integral`` (C++, Embarcadero)
 * ``__is_interface_class`` (Microsoft):
   Returns ``false``, even for types defined with ``__interface``.
+* ``__is_invocable_r`` (Clang)
 * ``__is_literal`` (Clang):
   Synonym for ``__is_literal_type``.
 * ``__is_literal_type`` (C++, GNU, Microsoft):
@@ -1594,6 +1595,7 @@ The following type trait primitives are supported by 
Clang. Those traits marked
 * ``__is_nothrow_assignable`` (C++, MSVC 2013)
 * ``__is_nothrow_constructible`` (C++, MSVC 2013)
 * ``__is_nothrow_destructible`` (C++, MSVC 2013)
+* ``__is_nothrow_invocable_r`` (Clang)
 * ``__is_nullptr`` (C++, GNU, Microsoft, Embarcadero):
   Returns true for ``std::nullptr_t`` and false for everything else. The
   corresponding standard library feature is ``std::is_null_pointer``, but
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index cd8a82f281f52..8a4ae646c008f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -78,6 +78,10 @@ here. Generic improvements to Clang as a whole or to its 
underlying
 infrastructure are described first, followed by language-specific
 sections with improvements to Clang's support for those languages.
 
+- The builtins `__is_invocable_r` and `__is_nothrow_invocable_r` have been 
added.
+  These are equivalent to the standard library builtins `std::is_invocable_r`
+  and `std::is_nothrow_invocable_r`.
+
 C++ Language Changes
 
 
diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 23817cde7a935..6467a52c82cb5 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -532,6 +532,8 @@ TYPE_TRAIT_1(__is_unbounded_array, IsUnboundedArray, KEYCXX)
 TYPE_TRAIT_1(__is_nullptr, IsNullPointer, KEYCXX)
 TYPE_TRAIT_1(__is_scoped_enum, IsScopedEnum, KEYCXX)
 TYPE_TRAIT_1(__is_referenceable, IsReferenceable, KEYCXX)
+TYPE_TRAIT_N(__is_invocable_r, IsInvocableR, KEYCXX)
+TYPE_TRAIT_N(__is_nothrow_invocable_r, IsNothrowInvocableR, KEYCXX)
 TYPE_TRAIT_1(__can_pass_in_regs, CanPassInRegs, KEYCXX)
 TYPE_TRAIT_2(__reference_binds_to_temporary, ReferenceBindsToTemporary, KEYCXX)
 TYPE_TRAIT_2(__reference_constructs_from_temporary, 
ReferenceConstructsFromTemporary, KEYCXX)
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 246d2313e089f..5b82de9a51323 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5468,6 +5468,266 @@ static bool EvaluateUnaryTypeTrait(Sema , 
TypeTrait UTT,
 static bool EvaluateBinaryTypeTrait(Sema , TypeTrait BTT, QualType LhsT,
 QualType RhsT, SourceLocation KeyLoc);
 
+static bool IsBaseOf(Sema , QualType LhsT, QualType RhsT,
+ SourceLocation KeyLoc) {
+  // C++0x [meta.rel]p2
+  // Base is a base class of Derived without regard to cv-qualifiers or
+  // Base and Derived are not unions and name the same class type without
+  // regard to cv-qualifiers.
+
+  const RecordType *lhsRecord = LhsT->getAs();
+  const RecordType *rhsRecord = RhsT->getAs();
+  if (!rhsRecord || !lhsRecord) {
+const ObjCObjectType *LHSObjTy = LhsT->getAs();
+const ObjCObjectType *RHSObjTy = RhsT->getAs();
+if (!LHSObjTy || !RHSObjTy)
+  return false;
+
+ObjCInterfaceDecl *BaseInterface = LHSObjTy->getInterface();
+ObjCInterfaceDecl *DerivedInterface = RHSObjTy->getInterface();
+if (!BaseInterface || !DerivedInterface)
+  return false;
+
+if (Self.RequireCompleteType(
+KeyLoc, RhsT, diag::err_incomplete_type_used_in_type_trait_expr))
+  return false;
+
+return BaseInterface->isSuperClassOf(DerivedInterface);
+  }
+
+  assert(Self.Context.hasSameUnqualifiedType(LhsT, RhsT) ==
+ (lhsRecord == rhsRecord));
+
+  // Unions are never base classes, 

[clang] [libcxx] [Clang] Add __is_invocable_r and __is_nothrow_invocable_r (PR #81213)

2024-02-08 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/81213

>From f2394044b0397cbe3bd15f96f43fbf0e50def206 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Mon, 11 Sep 2023 04:31:02 +0200
Subject: [PATCH] [Clang] Add __is_invocable_r and __is_nothrow_invocable_r

This patch also uses the new builtins in libc++.
---
 clang/docs/LanguageExtensions.rst|   2 +
 clang/docs/ReleaseNotes.rst  |   4 +
 clang/include/clang/Basic/TokenKinds.def |   2 +
 clang/lib/Sema/SemaExprCXX.cpp   | 390 +--
 clang/test/SemaCXX/type-traits-invocable.cpp | 288 ++
 libcxx/include/__type_traits/invoke.h|  36 ++
 6 files changed, 603 insertions(+), 119 deletions(-)
 create mode 100644 clang/test/SemaCXX/type-traits-invocable.cpp

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index e91156837290f7..bf061590e5ca0b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1582,6 +1582,7 @@ The following type trait primitives are supported by 
Clang. Those traits marked
 * ``__is_integral`` (C++, Embarcadero)
 * ``__is_interface_class`` (Microsoft):
   Returns ``false``, even for types defined with ``__interface``.
+* ``__is_invocable_r`` (Clang)
 * ``__is_literal`` (Clang):
   Synonym for ``__is_literal_type``.
 * ``__is_literal_type`` (C++, GNU, Microsoft):
@@ -1594,6 +1595,7 @@ The following type trait primitives are supported by 
Clang. Those traits marked
 * ``__is_nothrow_assignable`` (C++, MSVC 2013)
 * ``__is_nothrow_constructible`` (C++, MSVC 2013)
 * ``__is_nothrow_destructible`` (C++, MSVC 2013)
+* ``__is_nothrow_invocable_r`` (Clang)
 * ``__is_nullptr`` (C++, GNU, Microsoft, Embarcadero):
   Returns true for ``std::nullptr_t`` and false for everything else. The
   corresponding standard library feature is ``std::is_null_pointer``, but
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index cd8a82f281f52a..8a4ae646c008f6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -78,6 +78,10 @@ here. Generic improvements to Clang as a whole or to its 
underlying
 infrastructure are described first, followed by language-specific
 sections with improvements to Clang's support for those languages.
 
+- The builtins `__is_invocable_r` and `__is_nothrow_invocable_r` have been 
added.
+  These are equivalent to the standard library builtins `std::is_invocable_r`
+  and `std::is_nothrow_invocable_r`.
+
 C++ Language Changes
 
 
diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 23817cde7a9354..6467a52c82cb5b 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -532,6 +532,8 @@ TYPE_TRAIT_1(__is_unbounded_array, IsUnboundedArray, KEYCXX)
 TYPE_TRAIT_1(__is_nullptr, IsNullPointer, KEYCXX)
 TYPE_TRAIT_1(__is_scoped_enum, IsScopedEnum, KEYCXX)
 TYPE_TRAIT_1(__is_referenceable, IsReferenceable, KEYCXX)
+TYPE_TRAIT_N(__is_invocable_r, IsInvocableR, KEYCXX)
+TYPE_TRAIT_N(__is_nothrow_invocable_r, IsNothrowInvocableR, KEYCXX)
 TYPE_TRAIT_1(__can_pass_in_regs, CanPassInRegs, KEYCXX)
 TYPE_TRAIT_2(__reference_binds_to_temporary, ReferenceBindsToTemporary, KEYCXX)
 TYPE_TRAIT_2(__reference_constructs_from_temporary, 
ReferenceConstructsFromTemporary, KEYCXX)
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 246d2313e089f3..5b82de9a51323f 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5468,6 +5468,266 @@ static bool EvaluateUnaryTypeTrait(Sema , 
TypeTrait UTT,
 static bool EvaluateBinaryTypeTrait(Sema , TypeTrait BTT, QualType LhsT,
 QualType RhsT, SourceLocation KeyLoc);
 
+static bool IsBaseOf(Sema , QualType LhsT, QualType RhsT,
+ SourceLocation KeyLoc) {
+  // C++0x [meta.rel]p2
+  // Base is a base class of Derived without regard to cv-qualifiers or
+  // Base and Derived are not unions and name the same class type without
+  // regard to cv-qualifiers.
+
+  const RecordType *lhsRecord = LhsT->getAs();
+  const RecordType *rhsRecord = RhsT->getAs();
+  if (!rhsRecord || !lhsRecord) {
+const ObjCObjectType *LHSObjTy = LhsT->getAs();
+const ObjCObjectType *RHSObjTy = RhsT->getAs();
+if (!LHSObjTy || !RHSObjTy)
+  return false;
+
+ObjCInterfaceDecl *BaseInterface = LHSObjTy->getInterface();
+ObjCInterfaceDecl *DerivedInterface = RHSObjTy->getInterface();
+if (!BaseInterface || !DerivedInterface)
+  return false;
+
+if (Self.RequireCompleteType(
+KeyLoc, RhsT, diag::err_incomplete_type_used_in_type_trait_expr))
+  return false;
+
+return BaseInterface->isSuperClassOf(DerivedInterface);
+  }
+
+  assert(Self.Context.hasSameUnqualifiedType(LhsT, RhsT) ==
+ (lhsRecord == rhsRecord));
+
+  // Unions are never base 

[clang] [libcxx] [Clang] Add __is_invocable_r and __is_nothrow_invocable_r (PR #81213)

2024-02-08 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 created 
https://github.com/llvm/llvm-project/pull/81213

This patch also uses the new builtins in libc++.


>From 6c74eb263dd889858f3f7be328d85fe354f71835 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Mon, 11 Sep 2023 04:31:02 +0200
Subject: [PATCH] [Clang] Add __is_invocable_r and __is_nothrow_invocable_r

This patch also uses the new builtins in libc++.
---
 clang/docs/LanguageExtensions.rst|   2 +
 clang/docs/ReleaseNotes.rst  |   4 +
 clang/include/clang/AST/Type.h   |   3 +
 clang/include/clang/Basic/TokenKinds.def |   2 +
 clang/lib/Sema/SemaExprCXX.cpp   | 390 +--
 clang/test/SemaCXX/type-traits-invocable.cpp | 288 ++
 libcxx/include/__type_traits/invoke.h|  36 ++
 7 files changed, 606 insertions(+), 119 deletions(-)
 create mode 100644 clang/test/SemaCXX/type-traits-invocable.cpp

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index e91156837290f7..bf061590e5ca0b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1582,6 +1582,7 @@ The following type trait primitives are supported by 
Clang. Those traits marked
 * ``__is_integral`` (C++, Embarcadero)
 * ``__is_interface_class`` (Microsoft):
   Returns ``false``, even for types defined with ``__interface``.
+* ``__is_invocable_r`` (Clang)
 * ``__is_literal`` (Clang):
   Synonym for ``__is_literal_type``.
 * ``__is_literal_type`` (C++, GNU, Microsoft):
@@ -1594,6 +1595,7 @@ The following type trait primitives are supported by 
Clang. Those traits marked
 * ``__is_nothrow_assignable`` (C++, MSVC 2013)
 * ``__is_nothrow_constructible`` (C++, MSVC 2013)
 * ``__is_nothrow_destructible`` (C++, MSVC 2013)
+* ``__is_nothrow_invocable_r`` (Clang)
 * ``__is_nullptr`` (C++, GNU, Microsoft, Embarcadero):
   Returns true for ``std::nullptr_t`` and false for everything else. The
   corresponding standard library feature is ``std::is_null_pointer``, but
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index cd8a82f281f52a..8a4ae646c008f6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -78,6 +78,10 @@ here. Generic improvements to Clang as a whole or to its 
underlying
 infrastructure are described first, followed by language-specific
 sections with improvements to Clang's support for those languages.
 
+- The builtins `__is_invocable_r` and `__is_nothrow_invocable_r` have been 
added.
+  These are equivalent to the standard library builtins `std::is_invocable_r`
+  and `std::is_nothrow_invocable_r`.
+
 C++ Language Changes
 
 
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index d6a55f39a4bede..fe10391ac7057c 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -926,6 +926,9 @@ class QualType {
   /// Return true if this is a trivially equality comparable type.
   bool isTriviallyEqualityComparableType(const ASTContext ) const;
 
+  /// Returns true if this is an invocable type.
+  bool isInvocableType() const;
+
   /// Returns true if it is a class and it might be dynamic.
   bool mayBeDynamicClass() const;
 
diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 23817cde7a9354..6467a52c82cb5b 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -532,6 +532,8 @@ TYPE_TRAIT_1(__is_unbounded_array, IsUnboundedArray, KEYCXX)
 TYPE_TRAIT_1(__is_nullptr, IsNullPointer, KEYCXX)
 TYPE_TRAIT_1(__is_scoped_enum, IsScopedEnum, KEYCXX)
 TYPE_TRAIT_1(__is_referenceable, IsReferenceable, KEYCXX)
+TYPE_TRAIT_N(__is_invocable_r, IsInvocableR, KEYCXX)
+TYPE_TRAIT_N(__is_nothrow_invocable_r, IsNothrowInvocableR, KEYCXX)
 TYPE_TRAIT_1(__can_pass_in_regs, CanPassInRegs, KEYCXX)
 TYPE_TRAIT_2(__reference_binds_to_temporary, ReferenceBindsToTemporary, KEYCXX)
 TYPE_TRAIT_2(__reference_constructs_from_temporary, 
ReferenceConstructsFromTemporary, KEYCXX)
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 246d2313e089f3..4f4b6492e58880 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5468,6 +5468,266 @@ static bool EvaluateUnaryTypeTrait(Sema , 
TypeTrait UTT,
 static bool EvaluateBinaryTypeTrait(Sema , TypeTrait BTT, QualType LhsT,
 QualType RhsT, SourceLocation KeyLoc);
 
+static bool IsBaseOf(Sema , QualType LhsT, QualType RhsT,
+ SourceLocation KeyLoc) {
+  // C++0x [meta.rel]p2
+  // Base is a base class of Derived without regard to cv-qualifiers or
+  // Base and Derived are not unions and name the same class type without
+  // regard to cv-qualifiers.
+
+  const RecordType *lhsRecord = LhsT->getAs();
+  const RecordType *rhsRecord = RhsT->getAs();
+  if (!rhsRecord || !lhsRecord) {
+const ObjCObjectType *LHSObjTy = 

[clang] [Clang] Allow __is_nothrow_convertible to be used as an identifier (PR #80476)

2024-02-02 Thread Nikolas Klauser via cfe-commits

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


[clang] [libcxx] [Clang][libc++] Implement __is_nothrow_convertible and use it in libc++ (PR #80436)

2024-02-02 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

@sdkrystian #80476

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


[clang] [Clang] Allow __is_nothrow_convertible to be used as an identifier (PR #80476)

2024-02-02 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 created 
https://github.com/llvm/llvm-project/pull/80476

`__is_nothrow_convertible` has been used by libstdc++ previously as an 
identifier.


>From fb4160b50535fd16951c5261e6c7d91da0cd92b0 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Fri, 2 Feb 2024 20:06:29 +0100
Subject: [PATCH] [Clang] Allow __is_nothrow_convertible to be used as an
 identifier

---
 clang/lib/Parse/ParseDeclCXX.cpp   |  1 +
 .../libstdcxx_is_nothrow_convertible_hack.cpp  | 14 ++
 2 files changed, 15 insertions(+)
 create mode 100644 clang/test/SemaCXX/libstdcxx_is_nothrow_convertible_hack.cpp

diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index cdbfbb1bc9fff..79928ddb5af59 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -1725,6 +1725,7 @@ void Parser::ParseClassSpecifier(tok::TokenKind 
TagTokKind,
   tok::kw___is_member_pointer,
   tok::kw___is_nothrow_assignable,
   tok::kw___is_nothrow_constructible,
+  tok::kw___is_nothrow_convertible,
   tok::kw___is_nothrow_destructible,
   tok::kw___is_nullptr,
   tok::kw___is_object,
diff --git a/clang/test/SemaCXX/libstdcxx_is_nothrow_convertible_hack.cpp 
b/clang/test/SemaCXX/libstdcxx_is_nothrow_convertible_hack.cpp
new file mode 100644
index 0..9e84f0ab1c081
--- /dev/null
+++ b/clang/test/SemaCXX/libstdcxx_is_nothrow_convertible_hack.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify 
-std=gnu++20 -fms-extensions -Wno-microsoft %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify 
-std=gnu++23 -fms-extensions -Wno-microsoft %s
+
+template 
+struct Same {
+  static constexpr auto value = __is_same(T, U);
+};
+
+template 
+struct __is_nothrow_convertible { // expected-warning{{keyword 
'__is_nothrow_convertible' will be made available as an identifier for the 
remainder of the translation unit}}
+  using type = T;
+};
+
+using A = Same<__is_nothrow_convertible::type, 
__is_nothrow_convertible::type>;

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


[libcxx] [clang] [Clang][libc++] Implement __is_nothrow_convertible and use it in libc++ (PR #80436)

2024-02-02 Thread Nikolas Klauser via cfe-commits

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


[libcxx] [clang] [Clang][libc++] Implement __is_nothrow_convertible and use it in libc++ (PR #80436)

2024-02-02 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/80436

>From d210ffcbc1c60c222bd456851372f4835cc12127 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Fri, 2 Feb 2024 15:12:15 +0100
Subject: [PATCH] [Clang][libc++] Implement __is_nothrow_convertible and use it
 in libc++

---
 clang/docs/LanguageExtensions.rst|  1 +
 clang/include/clang/Basic/TokenKinds.def |  1 +
 clang/lib/Sema/SemaExprCXX.cpp   | 11 +--
 clang/test/SemaCXX/type-traits.cpp   | 16 ++--
 .../__type_traits/is_nothrow_convertible.h   | 12 
 5 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index c1420079f7511..e91156837290f 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1569,6 +1569,7 @@ The following type trait primitives are supported by 
Clang. Those traits marked
 * ``__is_const`` (C++, Embarcadero)
 * ``__is_constructible`` (C++, MSVC 2013)
 * ``__is_convertible`` (C++, Embarcadero)
+* ``__is_nothrow_convertible`` (C++, GNU)
 * ``__is_convertible_to`` (Microsoft):
   Synonym for ``__is_convertible``.
 * ``__is_destructible`` (C++, MSVC 2013)
diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 9117e4376c371..23817cde7a935 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -567,6 +567,7 @@ TYPE_TRAIT_1(__is_unsigned, IsUnsigned, KEYCXX)
 // Embarcadero Binary Type Traits
 TYPE_TRAIT_2(__is_same, IsSame, KEYCXX)
 TYPE_TRAIT_2(__is_convertible, IsConvertible, KEYCXX)
+TYPE_TRAIT_2(__is_nothrow_convertible, IsNothrowConvertible, KEYCXX)
 ARRAY_TYPE_TRAIT(__array_rank, ArrayRank, KEYCXX)
 ARRAY_TYPE_TRAIT(__array_extent, ArrayExtent, KEYCXX)
 // Name for GCC 6 compatibility.
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 3a32754e5376e..246d2313e089f 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5779,7 +5779,8 @@ static bool EvaluateBinaryTypeTrait(Sema , TypeTrait 
BTT, QualType LhsT,
 return Self.Context.typesAreCompatible(Lhs, Rhs);
   }
   case BTT_IsConvertible:
-  case BTT_IsConvertibleTo: {
+  case BTT_IsConvertibleTo:
+  case BTT_IsNothrowConvertible: {
 // C++0x [meta.rel]p4:
 //   Given the following function prototype:
 //
@@ -5840,7 +5841,13 @@ static bool EvaluateBinaryTypeTrait(Sema , 
TypeTrait BTT, QualType LhsT,
   return false;
 
 ExprResult Result = Init.Perform(Self, To, Kind, FromPtr);
-return !Result.isInvalid() && !SFINAE.hasErrorOccurred();
+if (Result.isInvalid() || SFINAE.hasErrorOccurred())
+  return false;
+
+if (BTT != BTT_IsNothrowConvertible)
+  return true;
+
+return Self.canThrow(Result.get()) == CT_Cannot;
   }
 
   case BTT_IsAssignable:
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index c5d196a2590f8..5659594577111 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -2118,7 +2118,7 @@ struct IntWrapper
 {
   int value;
   IntWrapper(int _value) : value(_value) {}
-  operator int() const {
+  operator int() const noexcept {
 return value;
   }
 };
@@ -2126,7 +2126,7 @@ struct IntWrapper
 struct FloatWrapper
 {
   float value;
-  FloatWrapper(float _value) : value(_value) {}
+  FloatWrapper(float _value) noexcept : value(_value) {}
   FloatWrapper(const IntWrapper& obj)
 : value(static_cast(obj.value)) {}
   operator float() const {
@@ -2149,6 +2149,18 @@ void is_convertible()
   int t08[T(__is_convertible(float, FloatWrapper))];
 }
 
+void is_nothrow_convertible()
+{
+  int t01[T(__is_nothrow_convertible(IntWrapper, IntWrapper))];
+  int t02[T(__is_nothrow_convertible(IntWrapper, const IntWrapper))];
+  int t03[T(__is_nothrow_convertible(IntWrapper, int))];
+  int t04[F(__is_nothrow_convertible(int, IntWrapper))];
+  int t05[F(__is_nothrow_convertible(IntWrapper, FloatWrapper))];
+  int t06[F(__is_nothrow_convertible(FloatWrapper, IntWrapper))];
+  int t07[F(__is_nothrow_convertible(FloatWrapper, float))];
+  int t08[T(__is_nothrow_convertible(float, FloatWrapper))];
+}
+
 struct FromInt { FromInt(int); };
 struct ToInt { operator int(); };
 typedef void Function();
diff --git a/libcxx/include/__type_traits/is_nothrow_convertible.h 
b/libcxx/include/__type_traits/is_nothrow_convertible.h
index eda7a49d7224c..bfc5a94cbadec 100644
--- a/libcxx/include/__type_traits/is_nothrow_convertible.h
+++ b/libcxx/include/__type_traits/is_nothrow_convertible.h
@@ -26,6 +26,16 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 #if _LIBCPP_STD_VER >= 20
 
+#  if __has_builtin(__is_nothrow_convertible)
+
+template 
+struct is_nothrow_convertible : bool_constant<__is_nothrow_convertible(_Tp, 
_Up)> {};
+
+template 
+inline constexpr bool is_nothrow_convertible_v = 

[libcxx] [clang] [Clang][libc++] Implement __is_nothrow_convertible and use it in libc++ (PR #80436)

2024-02-02 Thread Nikolas Klauser via cfe-commits


@@ -567,6 +567,7 @@ TYPE_TRAIT_1(__is_unsigned, IsUnsigned, KEYCXX)
 // Embarcadero Binary Type Traits
 TYPE_TRAIT_2(__is_same, IsSame, KEYCXX)
 TYPE_TRAIT_2(__is_convertible, IsConvertible, KEYCXX)
+TYPE_TRAIT_2(__is_nothrow_convertible, IsNothrowConvertible, KEYCXX)

philnik777 wrote:

There are a bunch more type traits that aren't listed correctly anymore, so IMO 
an NFC patch that updates them all would be better.

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


  1   2   3   >