[clang] [Clang] Remove __is_nullptr (PR #99038)

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

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


[clang] [Clang] Remove __is_nullptr (PR #99038)

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

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

>From fbc9ebb3900e69f2485111cfdc6b7a7dfd3e6ebe Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Tue, 16 Jul 2024 14:53:30 +0200
Subject: [PATCH 1/2] [Clang] Remove __is_nullptr

---
 clang/docs/LanguageExtensions.rst  |  4 
 clang/lib/Parse/ParseDeclCXX.cpp   |  5 ++---
 clang/lib/Parse/ParseExpr.cpp  |  1 -
 clang/lib/Sema/SemaExprCXX.cpp |  3 ---
 clang/test/SemaCXX/type-traits.cpp | 36 --
 5 files changed, 2 insertions(+), 47 deletions(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 81784c75081ba..cfd7d29fb9eac 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1614,10 +1614,6 @@ 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_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
-  ``__is_null_pointer`` is already in use by some implementations.
 * ``__is_object`` (C++, Embarcadero)
 * ``__is_pod`` (C++, GNU, Microsoft, Embarcadero):
   Note, the corresponding standard trait was deprecated in C++20.
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index ce827c689beb7..2c201d346328b 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -447,9 +447,9 @@ Decl *Parser::ParseLinkage(ParsingDeclSpec , 
DeclaratorContext Context) {
 ///
 /// HLSL: Parse export function declaration.
 ///
-///  export-function-declaration: 
+///  export-function-declaration:
 /// 'export' function-declaration
-/// 
+///
 ///  export-declaration-group:
 /// 'export' '{' function-declaration-seq[opt] '}'
 ///
@@ -1799,7 +1799,6 @@ void Parser::ParseClassSpecifier(tok::TokenKind 
TagTokKind,
   tok::kw___is_nothrow_constructible,
   tok::kw___is_nothrow_convertible,
   tok::kw___is_nothrow_destructible,
-  tok::kw___is_nullptr,
   tok::kw___is_object,
   tok::kw___is_pod,
   tok::kw___is_pointer,
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 3d7c58e5b3c3c..b3df9cfbc8b9a 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -800,7 +800,6 @@ bool Parser::isRevertibleTypeTrait(const IdentifierInfo *II,
 REVERTIBLE_TYPE_TRAIT(__is_nothrow_assignable);
 REVERTIBLE_TYPE_TRAIT(__is_nothrow_constructible);
 REVERTIBLE_TYPE_TRAIT(__is_nothrow_destructible);
-REVERTIBLE_TYPE_TRAIT(__is_nullptr);
 REVERTIBLE_TYPE_TRAIT(__is_object);
 REVERTIBLE_TYPE_TRAIT(__is_pod);
 REVERTIBLE_TYPE_TRAIT(__is_pointer);
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index bef7da239e6e5..a41b938531cab 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -4979,7 +4979,6 @@ static bool CheckUnaryTypeTraitTypeCompleteness(Sema , 
TypeTrait UTT,
   case UTT_IsArray:
   case UTT_IsBoundedArray:
   case UTT_IsPointer:
-  case UTT_IsNullPointer:
   case UTT_IsReferenceable:
   case UTT_IsLvalueReference:
   case UTT_IsRvalueReference:
@@ -5235,8 +5234,6 @@ static bool EvaluateUnaryTypeTrait(Sema , TypeTrait 
UTT,
 return T->isIncompleteArrayType();
   case UTT_IsPointer:
 return T->isAnyPointerType();
-  case UTT_IsNullPointer:
-return T->isNullPtrType();
   case UTT_IsLvalueReference:
 return T->isLValueReferenceType();
   case UTT_IsRvalueReference:
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index 7adbf4aad7afe..b38e8989cb559 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -1041,42 +1041,6 @@ void is_pointer()
   static_assert(!__is_pointer(void (StructWithMembers::*) ()));
 }
 
-void is_null_pointer() {
-  StructWithMembers x;
-
-  static_assert(__is_nullptr(decltype(nullptr)));
-  static_assert(!__is_nullptr(void *));
-  static_assert(!__is_nullptr(cvoid *));
-  static_assert(!__is_nullptr(cvoid *));
-  static_assert(!__is_nullptr(char *));
-  static_assert(!__is_nullptr(int *));
-  static_assert(!__is_nullptr(int **));
-  static_assert(!__is_nullptr(ClassType *));
-  static_assert(!__is_nullptr(Derives *));
-  static_assert(!__is_nullptr(Enum *));
-  static_assert(!__is_nullptr(IntArNB *));
-  static_assert(!__is_nullptr(Union *));
-  static_assert(!__is_nullptr(UnionAr *));
-  static_assert(!__is_nullptr(StructWithMembers *));
-  static_assert(!__is_nullptr(void (*)()));
-
-  static_assert(!__is_nullptr(void));
-  static_assert(!__is_nullptr(cvoid));
-  static_assert(!__is_nullptr(cvoid));
-  

[clang] [Clang] Add [[clang::diagnose_specializations]] (PR #101469)

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

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

>From 82ab798fc72c6de64ae527d96393f0dc67307e98 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Thu, 1 Aug 2024 12:30:22 +0200
Subject: [PATCH 1/3] [Clang] Add [[clang::diagnose_specializations]]

---
 clang/include/clang/Basic/Attr.td | 13 ++-
 clang/include/clang/Basic/AttrDocs.td | 14 ++--
 clang/include/clang/Basic/DiagnosticGroups.td |  1 +
 .../clang/Basic/DiagnosticSemaKinds.td|  3 ++
 clang/lib/Sema/SemaDeclAttr.cpp   |  9 +
 clang/lib/Sema/SemaTemplate.cpp   |  6 
 .../SemaCXX/attr-diagnose-specializations.cpp | 34 +++
 7 files changed, 76 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/SemaCXX/attr-diagnose-specializations.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 8ac2079099c85..e074cc8b285a9 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -103,6 +103,9 @@ def NonParmVar : SubsetSubjecthasLocalStorage()}],
 "variables with non-local storage">;
+def VarTmpl : SubsetSubjectgetDescribedVarTemplate()}],
+"variable template">;
+
 def NonBitField : SubsetSubjectisBitField()}],
 "non-bit-field non-static data members">;
@@ -3327,6 +3330,14 @@ def DiagnoseIf : InheritableAttr {
   let Documentation = [DiagnoseIfDocs];
 }
 
+def DiagnoseSpecializations : InheritableAttr {
+  let Spellings = [Clang<"diagnose_specializations", /*AllowInC*/0>];
+  let Subjects = SubjectList<[ClassTmpl, VarTmpl]>;
+  let Documentation = [DiagnoseSpecializationsDocs];
+  let MeaningfulToClassTemplateDefinition = 1;
+  let TemplateDependent = 1;
+}
+
 def ArcWeakrefUnavailable : InheritableAttr {
   let Spellings = [Clang<"objc_arc_weak_reference_unavailable">];
   let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
@@ -4581,7 +4592,7 @@ def HLSLResource : InheritableAttr {
   let Spellings = [];
   let Subjects = SubjectList<[Struct]>;
   let LangOpts = [HLSL];
-  let Args = [
+  let Args = [
 EnumArgument<
 "ResourceKind", "llvm::hlsl::ResourceKind",
 /*is_string=*/0,
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 94c284fc73158..4ca67a63714d4 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -975,6 +975,15 @@ Query for this feature with 
``__has_attribute(diagnose_if)``.
   }];
 }
 
+def DiagnoseSpecializationsDocs : Documentation {
+  let Category = DocCatDecl;
+  let Content = [{
+``clang::diagnose_specializations`` can be appied to class templates which
+should not be specialized by users. This is primarily used to diagnose user
+specializations of standard library type traits.
+  }];
+}
+
 def PassObjectSizeDocs : Documentation {
   let Category = DocCatVariable; // Technically it's a parameter doc, but eh.
   let Heading = "pass_object_size, pass_dynamic_object_size";
@@ -7388,10 +7397,10 @@ def HLSLLoopHintDocs : Documentation {
   let Content = [{
 The ``[loop]`` directive allows loop optimization hints to be
 specified for the subsequent loop. The directive allows unrolling to
-be disabled and is not compatible with [unroll(x)]. 
+be disabled and is not compatible with [unroll(x)].
 
 Specifying the parameter, ``[loop]``, directs the
-unroller to not unroll the loop. 
+unroller to not unroll the loop.
 
 .. code-block:: hlsl
 
@@ -8306,4 +8315,3 @@ Declares that a function potentially allocates heap 
memory, and prevents any pot
 of ``nonallocating`` by the compiler.
   }];
 }
-
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 19c3f1e043349..d6f6111f70868 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -472,6 +472,7 @@ def ExpansionToDefined : DiagGroup<"expansion-to-defined">;
 def FlagEnum : DiagGroup<"flag-enum">;
 def IncrementBool : DiagGroup<"increment-bool", [DeprecatedIncrementBool]>;
 def InfiniteRecursion : DiagGroup<"infinite-recursion">;
+def InvalidSpecialization : DiagGroup<"invalid-specialization">;
 def PureVirtualCallFromCtorDtor: 
DiagGroup<"call-to-pure-virtual-from-ctor-dtor">;
 def GNUImaginaryConstant : DiagGroup<"gnu-imaginary-constant">;
 def IgnoredGCH : DiagGroup<"ignored-gch">;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 581434d33c5c9..5972d630347ec 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5407,6 +5407,9 @@ def note_dependent_function_template_spec_discard_reason 
: Note<
   "candidate ignored: %select{not a function template|"
   "not a member of the enclosing %select{class template|"
   "namespace; did you mean 

[clang] [Clang] Add [[clang::diagnose_specializations]] (PR #101469)

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

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

>From 82ab798fc72c6de64ae527d96393f0dc67307e98 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Thu, 1 Aug 2024 12:30:22 +0200
Subject: [PATCH 1/2] [Clang] Add [[clang::diagnose_specializations]]

---
 clang/include/clang/Basic/Attr.td | 13 ++-
 clang/include/clang/Basic/AttrDocs.td | 14 ++--
 clang/include/clang/Basic/DiagnosticGroups.td |  1 +
 .../clang/Basic/DiagnosticSemaKinds.td|  3 ++
 clang/lib/Sema/SemaDeclAttr.cpp   |  9 +
 clang/lib/Sema/SemaTemplate.cpp   |  6 
 .../SemaCXX/attr-diagnose-specializations.cpp | 34 +++
 7 files changed, 76 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/SemaCXX/attr-diagnose-specializations.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 8ac2079099c85..e074cc8b285a9 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -103,6 +103,9 @@ def NonParmVar : SubsetSubjecthasLocalStorage()}],
 "variables with non-local storage">;
+def VarTmpl : SubsetSubjectgetDescribedVarTemplate()}],
+"variable template">;
+
 def NonBitField : SubsetSubjectisBitField()}],
 "non-bit-field non-static data members">;
@@ -3327,6 +3330,14 @@ def DiagnoseIf : InheritableAttr {
   let Documentation = [DiagnoseIfDocs];
 }
 
+def DiagnoseSpecializations : InheritableAttr {
+  let Spellings = [Clang<"diagnose_specializations", /*AllowInC*/0>];
+  let Subjects = SubjectList<[ClassTmpl, VarTmpl]>;
+  let Documentation = [DiagnoseSpecializationsDocs];
+  let MeaningfulToClassTemplateDefinition = 1;
+  let TemplateDependent = 1;
+}
+
 def ArcWeakrefUnavailable : InheritableAttr {
   let Spellings = [Clang<"objc_arc_weak_reference_unavailable">];
   let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
@@ -4581,7 +4592,7 @@ def HLSLResource : InheritableAttr {
   let Spellings = [];
   let Subjects = SubjectList<[Struct]>;
   let LangOpts = [HLSL];
-  let Args = [
+  let Args = [
 EnumArgument<
 "ResourceKind", "llvm::hlsl::ResourceKind",
 /*is_string=*/0,
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 94c284fc73158..4ca67a63714d4 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -975,6 +975,15 @@ Query for this feature with 
``__has_attribute(diagnose_if)``.
   }];
 }
 
+def DiagnoseSpecializationsDocs : Documentation {
+  let Category = DocCatDecl;
+  let Content = [{
+``clang::diagnose_specializations`` can be appied to class templates which
+should not be specialized by users. This is primarily used to diagnose user
+specializations of standard library type traits.
+  }];
+}
+
 def PassObjectSizeDocs : Documentation {
   let Category = DocCatVariable; // Technically it's a parameter doc, but eh.
   let Heading = "pass_object_size, pass_dynamic_object_size";
@@ -7388,10 +7397,10 @@ def HLSLLoopHintDocs : Documentation {
   let Content = [{
 The ``[loop]`` directive allows loop optimization hints to be
 specified for the subsequent loop. The directive allows unrolling to
-be disabled and is not compatible with [unroll(x)]. 
+be disabled and is not compatible with [unroll(x)].
 
 Specifying the parameter, ``[loop]``, directs the
-unroller to not unroll the loop. 
+unroller to not unroll the loop.
 
 .. code-block:: hlsl
 
@@ -8306,4 +8315,3 @@ Declares that a function potentially allocates heap 
memory, and prevents any pot
 of ``nonallocating`` by the compiler.
   }];
 }
-
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 19c3f1e043349..d6f6111f70868 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -472,6 +472,7 @@ def ExpansionToDefined : DiagGroup<"expansion-to-defined">;
 def FlagEnum : DiagGroup<"flag-enum">;
 def IncrementBool : DiagGroup<"increment-bool", [DeprecatedIncrementBool]>;
 def InfiniteRecursion : DiagGroup<"infinite-recursion">;
+def InvalidSpecialization : DiagGroup<"invalid-specialization">;
 def PureVirtualCallFromCtorDtor: 
DiagGroup<"call-to-pure-virtual-from-ctor-dtor">;
 def GNUImaginaryConstant : DiagGroup<"gnu-imaginary-constant">;
 def IgnoredGCH : DiagGroup<"ignored-gch">;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 581434d33c5c9..5972d630347ec 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5407,6 +5407,9 @@ def note_dependent_function_template_spec_discard_reason 
: Note<
   "candidate ignored: %select{not a function template|"
   "not a member of the enclosing %select{class template|"
   "namespace; did you mean 

[clang] [Clang] Add [[clang::diagnose_specializations]] (PR #101469)

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

philnik777 wrote:

> Also consider adding an argument that lets you diagnose 
> https://eel.is/c++draft/namespace.std#2.1
> 
> > * the added declaration depends on at least one program-defined type,
> 
> To diagnose specializations for `std::pair`, but allow 
> `std::pair`.

Given that this seems like a very standard-library-specific feature I'm not 
sure it makes a ton of sense to add it to this attribute. I think adding an 
ad-hoc diagnostic for this would be better.

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


[clang] [Clang] Add [[clang::diagnose_specializations]] (PR #101469)

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


@@ -975,6 +975,15 @@ Query for this feature with 
``__has_attribute(diagnose_if)``.
   }];
 }
 
+def DiagnoseSpecializationsDocs : Documentation {
+  let Category = DocCatDecl;
+  let Content = [{
+``clang::diagnose_specializations`` can be appied to class templates which
+should not be specialized by users. This is primarily used to diagnose user
+specializations of standard library type traits.

philnik777 wrote:

Are users of a non-standard-library not users?

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


[clang] [Clang] Add [[clang::diagnose_specializations]] (PR #101469)

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

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

This can be used to inform users when a template should not be specialized. For 
example, this is the case for the standard type traits (except for 
`common_type` and `common_reference`, which have more complicated rules).


>From 82ab798fc72c6de64ae527d96393f0dc67307e98 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Thu, 1 Aug 2024 12:30:22 +0200
Subject: [PATCH] [Clang] Add [[clang::diagnose_specializations]]

---
 clang/include/clang/Basic/Attr.td | 13 ++-
 clang/include/clang/Basic/AttrDocs.td | 14 ++--
 clang/include/clang/Basic/DiagnosticGroups.td |  1 +
 .../clang/Basic/DiagnosticSemaKinds.td|  3 ++
 clang/lib/Sema/SemaDeclAttr.cpp   |  9 +
 clang/lib/Sema/SemaTemplate.cpp   |  6 
 .../SemaCXX/attr-diagnose-specializations.cpp | 34 +++
 7 files changed, 76 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/SemaCXX/attr-diagnose-specializations.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 8ac2079099c85..e074cc8b285a9 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -103,6 +103,9 @@ def NonParmVar : SubsetSubjecthasLocalStorage()}],
 "variables with non-local storage">;
+def VarTmpl : SubsetSubjectgetDescribedVarTemplate()}],
+"variable template">;
+
 def NonBitField : SubsetSubjectisBitField()}],
 "non-bit-field non-static data members">;
@@ -3327,6 +3330,14 @@ def DiagnoseIf : InheritableAttr {
   let Documentation = [DiagnoseIfDocs];
 }
 
+def DiagnoseSpecializations : InheritableAttr {
+  let Spellings = [Clang<"diagnose_specializations", /*AllowInC*/0>];
+  let Subjects = SubjectList<[ClassTmpl, VarTmpl]>;
+  let Documentation = [DiagnoseSpecializationsDocs];
+  let MeaningfulToClassTemplateDefinition = 1;
+  let TemplateDependent = 1;
+}
+
 def ArcWeakrefUnavailable : InheritableAttr {
   let Spellings = [Clang<"objc_arc_weak_reference_unavailable">];
   let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
@@ -4581,7 +4592,7 @@ def HLSLResource : InheritableAttr {
   let Spellings = [];
   let Subjects = SubjectList<[Struct]>;
   let LangOpts = [HLSL];
-  let Args = [
+  let Args = [
 EnumArgument<
 "ResourceKind", "llvm::hlsl::ResourceKind",
 /*is_string=*/0,
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 94c284fc73158..4ca67a63714d4 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -975,6 +975,15 @@ Query for this feature with 
``__has_attribute(diagnose_if)``.
   }];
 }
 
+def DiagnoseSpecializationsDocs : Documentation {
+  let Category = DocCatDecl;
+  let Content = [{
+``clang::diagnose_specializations`` can be appied to class templates which
+should not be specialized by users. This is primarily used to diagnose user
+specializations of standard library type traits.
+  }];
+}
+
 def PassObjectSizeDocs : Documentation {
   let Category = DocCatVariable; // Technically it's a parameter doc, but eh.
   let Heading = "pass_object_size, pass_dynamic_object_size";
@@ -7388,10 +7397,10 @@ def HLSLLoopHintDocs : Documentation {
   let Content = [{
 The ``[loop]`` directive allows loop optimization hints to be
 specified for the subsequent loop. The directive allows unrolling to
-be disabled and is not compatible with [unroll(x)]. 
+be disabled and is not compatible with [unroll(x)].
 
 Specifying the parameter, ``[loop]``, directs the
-unroller to not unroll the loop. 
+unroller to not unroll the loop.
 
 .. code-block:: hlsl
 
@@ -8306,4 +8315,3 @@ Declares that a function potentially allocates heap 
memory, and prevents any pot
 of ``nonallocating`` by the compiler.
   }];
 }
-
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 19c3f1e043349..d6f6111f70868 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -472,6 +472,7 @@ def ExpansionToDefined : DiagGroup<"expansion-to-defined">;
 def FlagEnum : DiagGroup<"flag-enum">;
 def IncrementBool : DiagGroup<"increment-bool", [DeprecatedIncrementBool]>;
 def InfiniteRecursion : DiagGroup<"infinite-recursion">;
+def InvalidSpecialization : DiagGroup<"invalid-specialization">;
 def PureVirtualCallFromCtorDtor: 
DiagGroup<"call-to-pure-virtual-from-ctor-dtor">;
 def GNUImaginaryConstant : DiagGroup<"gnu-imaginary-constant">;
 def IgnoredGCH : DiagGroup<"ignored-gch">;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 581434d33c5c9..5972d630347ec 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5407,6 

[clang] [libcxx] [Clang] Add __common_type builtin (PR #99473)

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


@@ -3058,6 +3058,133 @@ void Sema::NoteAllFoundTemplates(TemplateName Name) {
   }
 }
 
+static QualType commonTypeImpl(Sema , TemplateName BaseTemplate,
+   SourceLocation TemplateLoc,
+   ArrayRef Ts) {
+  auto lookUpCommonType = [&](TemplateArgument T1,
+  TemplateArgument T2) -> QualType {
+// Don't bother looking for other specializations if both types are
+// builtins - users aren't allowed to specialize for them
+if (T1.getAsType()->isBuiltinType() && T2.getAsType()->isBuiltinType())
+  return commonTypeImpl(S, BaseTemplate, TemplateLoc, {T1, T2});
+
+TemplateArgumentListInfo Args;
+Args.addArgument(TemplateArgumentLoc(
+T1, S.Context.getTrivialTypeSourceInfo(T1.getAsType(;
+Args.addArgument(TemplateArgumentLoc(
+T2, S.Context.getTrivialTypeSourceInfo(T2.getAsType(;
+QualType BaseTemplateInst =
+S.CheckTemplateIdType(BaseTemplate, TemplateLoc, Args);
+if (S.RequireCompleteType(TemplateLoc, BaseTemplateInst,
+  diag::err_incomplete_type))
+  return QualType();
+return S.getTypeMember(BaseTemplateInst, "type");

philnik777 wrote:

Nice idea! Looks like it works just fine and doesn't have any impact on the 
performance. The only downside is that we don't diagnose incomplete 
`common_type`s anymore, since they SFINAE away now. OTOH 
http://eel.is/c++draft/type.traits#meta.trans.other-4.2 could be read as 
requiring that behaviour so who knows.

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


[clang] [libcxx] [Clang] Add __common_type builtin (PR #99473)

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

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


[clang] [libcxx] [Clang] Add __common_type builtin (PR #99473)

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

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

>From d6903daf0da6979822b8981ea3641455ff6d06f8 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Tue, 16 Jul 2024 14:48:10 +0200
Subject: [PATCH 1/5] [Clang] Add __common_type builtin

---
 clang/include/clang/AST/ASTContext.h  |  11 ++
 clang/include/clang/AST/DeclID.h  |   5 +-
 clang/include/clang/Basic/Builtins.h  |   5 +-
 clang/include/clang/Sema/Sema.h   |   4 +
 clang/lib/AST/ASTContext.cpp  |   7 +
 clang/lib/AST/ASTImporter.cpp |   3 +
 clang/lib/AST/DeclTemplate.cpp|  53 ++
 clang/lib/Lex/PPMacroExpansion.cpp|   1 +
 clang/lib/Sema/SemaChecking.cpp   |   8 +
 clang/lib/Sema/SemaLookup.cpp |   4 +
 clang/lib/Sema/SemaTemplate.cpp   | 160 +-
 clang/lib/Serialization/ASTReader.cpp |   3 +
 clang/lib/Serialization/ASTWriter.cpp |   2 +
 clang/test/SemaCXX/type-trait-common-type.cpp | 126 ++
 libcxx/include/__type_traits/common_type.h|  16 +-
 libcxx/include/module.modulemap   |   2 +
 16 files changed, 404 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/SemaCXX/type-trait-common-type.cpp

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 608bd90fcc3ff..d02e742297898 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -399,6 +399,9 @@ class ASTContext : public RefCountedBase {
   /// The identifier '__type_pack_element'.
   mutable IdentifierInfo *TypePackElementName = nullptr;
 
+  /// The identifier '__common_type'.
+  mutable IdentifierInfo *CommonTypeName = nullptr;
+
   QualType ObjCConstantStringType;
   mutable RecordDecl *CFConstantStringTagDecl = nullptr;
   mutable TypedefDecl *CFConstantStringTypeDecl = nullptr;
@@ -606,6 +609,7 @@ class ASTContext : public RefCountedBase {
   mutable ExternCContextDecl *ExternCContext = nullptr;
   mutable BuiltinTemplateDecl *MakeIntegerSeqDecl = nullptr;
   mutable BuiltinTemplateDecl *TypePackElementDecl = nullptr;
+  mutable BuiltinTemplateDecl *CommonTypeDecl = nullptr;
 
   /// The associated SourceManager object.
   SourceManager 
@@ -1107,6 +,7 @@ class ASTContext : public RefCountedBase {
   ExternCContextDecl *getExternCContextDecl() const;
   BuiltinTemplateDecl *getMakeIntegerSeqDecl() const;
   BuiltinTemplateDecl *getTypePackElementDecl() const;
+  BuiltinTemplateDecl *getCommonTypeDecl() const;
 
   // Builtin Types.
   CanQualType VoidTy;
@@ -1984,6 +1989,12 @@ class ASTContext : public RefCountedBase {
 return TypePackElementName;
   }
 
+  IdentifierInfo *getCommonTypeName() const {
+if (!CommonTypeName)
+  CommonTypeName = ("__common_type");
+return CommonTypeName;
+  }
+
   /// Retrieve the Objective-C "instancetype" type, if already known;
   /// otherwise, returns a NULL type;
   QualType getObjCInstanceType() {
diff --git a/clang/include/clang/AST/DeclID.h b/clang/include/clang/AST/DeclID.h
index e5e27389fac60..875e9a72b3951 100644
--- a/clang/include/clang/AST/DeclID.h
+++ b/clang/include/clang/AST/DeclID.h
@@ -84,13 +84,16 @@ enum PredefinedDeclIDs {
 
   /// The internal '__type_pack_element' template.
   PREDEF_DECL_TYPE_PACK_ELEMENT_ID = 17,
+
+  /// The internal '__common_type' template.
+  PREDEF_DECL_COMMON_TYPE_ID = 18,
 };
 
 /// The number of declaration IDs that are predefined.
 ///
 /// For more information about predefined declarations, see the
 /// \c PredefinedDeclIDs type and the PREDEF_DECL_*_ID constants.
-const unsigned int NUM_PREDEF_DECL_IDS = 18;
+const unsigned int NUM_PREDEF_DECL_IDS = 19;
 
 /// GlobalDeclID means DeclID in the current ASTContext and LocalDeclID means
 /// DeclID specific to a certain ModuleFile. Specially, in ASTWriter, the
diff --git a/clang/include/clang/Basic/Builtins.h 
b/clang/include/clang/Basic/Builtins.h
index e85ec5b2dca14..4353b72f71383 100644
--- a/clang/include/clang/Basic/Builtins.h
+++ b/clang/include/clang/Basic/Builtins.h
@@ -309,7 +309,10 @@ enum BuiltinTemplateKind : int {
   BTK__make_integer_seq,
 
   /// This names the __type_pack_element BuiltinTemplateDecl.
-  BTK__type_pack_element
+  BTK__type_pack_element,
+
+  /// This names the __common_type BuiltinTemplateDecl.
+  BTK__common_type,
 };
 
 } // end namespace clang
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 3cb1aa935fe46..5c7945c4c5c58 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2282,6 +2282,10 @@ class Sema final : public SemaBase {
   /// Check to see if a given expression could have '.c_str()' called on it.
   bool hasCStrMethod(const Expr *E);
 
+  // Check whether a type member 'Type::Name' exists, and if yes, return the
+  // type. If there is no type, the QualType is null
+  QualType getTypeMember(StringRef 

[clang] [libcxx] [Clang] Add __common_type builtin (PR #99473)

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


@@ -3058,6 +3058,133 @@ void Sema::NoteAllFoundTemplates(TemplateName Name) {
   }
 }
 
+static QualType commonTypeImpl(Sema , TemplateName BaseTemplate,
+   SourceLocation TemplateLoc,
+   ArrayRef Ts) {
+  auto lookUpCommonType = [&](TemplateArgument T1,
+  TemplateArgument T2) -> QualType {
+// Don't bother looking for other specializations if both types are
+// builtins - users aren't allowed to specialize for them

philnik777 wrote:

Given the precedent I don't think it's reasonable to block this patch on 
diagnosing some edge cases.

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


[clang] [libcxx] [Clang] Add __common_type builtin (PR #99473)

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


@@ -3058,6 +3058,133 @@ void Sema::NoteAllFoundTemplates(TemplateName Name) {
   }
 }
 
+static QualType commonTypeImpl(Sema , TemplateName BaseTemplate,
+   SourceLocation TemplateLoc,
+   ArrayRef Ts) {
+  auto lookUpCommonType = [&](TemplateArgument T1,
+  TemplateArgument T2) -> QualType {
+// Don't bother looking for other specializations if both types are
+// builtins - users aren't allowed to specialize for them
+if (T1.getAsType()->isBuiltinType() && T2.getAsType()->isBuiltinType())
+  return commonTypeImpl(S, BaseTemplate, TemplateLoc, {T1, T2});
+
+TemplateArgumentListInfo Args;
+Args.addArgument(TemplateArgumentLoc(
+T1, S.Context.getTrivialTypeSourceInfo(T1.getAsType(;
+Args.addArgument(TemplateArgumentLoc(
+T2, S.Context.getTrivialTypeSourceInfo(T2.getAsType(;
+QualType BaseTemplateInst =
+S.CheckTemplateIdType(BaseTemplate, TemplateLoc, Args);
+if (S.RequireCompleteType(TemplateLoc, BaseTemplateInst,
+  diag::err_incomplete_type))
+  return QualType();
+return S.getTypeMember(BaseTemplateInst, "type");
+  };
+
+  // Note A: For the common_type trait applied to a template parameter pack T 
of
+  // types, the member type shall be either defined or not present as follows:
+  switch (Ts.size()) {
+
+  // If sizeof...(T) is zero, there shall be no member type.
+  case 0:
+return QualType();
+
+  // If sizeof...(T) is one, let T0 denote the sole type constituting the
+  // pack T. The member typedef-name type shall denote the same type, if any, 
as
+  // common_type_t; otherwise there shall be no member type.
+  case 1:
+return lookUpCommonType(Ts[0], Ts[0]);
+
+  // If sizeof...(T) is two, let the first and second types constituting T be
+  // denoted by T1 and T2, respectively, and let D1 and D2 denote the same 
types
+  // as decay_t and decay_t, respectively.
+  case 2: {
+QualType T1 = Ts[0].getAsType();
+QualType T2 = Ts[1].getAsType();
+QualType D1 = S.BuiltinDecay(T1, {});
+QualType D2 = S.BuiltinDecay(T2, {});
+
+// If is_same_v is false or is_same_v is false, let C 
denote
+// the same type, if any, as common_type_t.
+if (!S.Context.hasSameType(T1, D1) || !S.Context.hasSameType(T2, D2))
+  return lookUpCommonType(D1, D2);
+
+// Otherwise, if decay_t() : declval())>
+// denotes a valid type, let C denote that type.
+{
+  auto CheckConditionalOperands = [&](bool ConstRefQual) -> QualType {
+EnterExpressionEvaluationContext UnevaluatedContext(
+S, Sema::ExpressionEvaluationContext::Unevaluated);
+Sema::SFINAETrap SFINAE(S, /*AccessCheckingSFINAE=*/true);
+Sema::ContextRAII TUContext(S, S.Context.getTranslationUnitDecl());
+
+// false
+OpaqueValueExpr CondExpr(SourceLocation(), S.Context.BoolTy,
+ VK_PRValue);
+ExprResult Cond = 
+
+auto EVK = ConstRefQual ? VK_LValue : VK_PRValue;
+if (ConstRefQual) {
+  D1.addConst();
+  D2.addConst();
+}
+
+// declval()
+OpaqueValueExpr LHSExpr(TemplateLoc, D1, EVK);
+ExprResult LHS = 
+
+// declval()
+OpaqueValueExpr RHSExpr(TemplateLoc, D2, EVK);
+ExprResult RHS = 
+
+ExprValueKind VK = VK_PRValue;
+ExprObjectKind OK = OK_Ordinary;
+
+// decltype(false ? declval() : declval())
+QualType Result =
+S.CheckConditionalOperands(Cond, LHS, RHS, VK, OK, TemplateLoc);

philnik777 wrote:

AFAICT we'd have to do that for all the extensions as well, which seems like 
it'd be a lot of work. We'd also only save the SFINAE context and the opaque 
values, which seems to me like not that much code. It'd probably be a bit 
faster, but I'm not sure it's that significant.

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


[clang] [libcxx] [Clang] Add __common_type builtin (PR #99473)

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

https://github.com/philnik777 commented:

> How much of a performance difference are you measuring with this change?

That depends heavily on what you're looking at. For `common_type`s with a lot 
of builtin types, I've seen a 10x improvement. When it's basically just 
combining specializations I've seen as low as a 1.25x improvement. When having 
classes that are convertible to another there is about a 2x improvement.

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


[clang] [Clang] Remove __is_nullptr (PR #99038)

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

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

>From fbc9ebb3900e69f2485111cfdc6b7a7dfd3e6ebe Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Tue, 16 Jul 2024 14:53:30 +0200
Subject: [PATCH 1/2] [Clang] Remove __is_nullptr

---
 clang/docs/LanguageExtensions.rst  |  4 
 clang/lib/Parse/ParseDeclCXX.cpp   |  5 ++---
 clang/lib/Parse/ParseExpr.cpp  |  1 -
 clang/lib/Sema/SemaExprCXX.cpp |  3 ---
 clang/test/SemaCXX/type-traits.cpp | 36 --
 5 files changed, 2 insertions(+), 47 deletions(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 81784c75081ba..cfd7d29fb9eac 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1614,10 +1614,6 @@ 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_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
-  ``__is_null_pointer`` is already in use by some implementations.
 * ``__is_object`` (C++, Embarcadero)
 * ``__is_pod`` (C++, GNU, Microsoft, Embarcadero):
   Note, the corresponding standard trait was deprecated in C++20.
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index ce827c689beb7..2c201d346328b 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -447,9 +447,9 @@ Decl *Parser::ParseLinkage(ParsingDeclSpec , 
DeclaratorContext Context) {
 ///
 /// HLSL: Parse export function declaration.
 ///
-///  export-function-declaration: 
+///  export-function-declaration:
 /// 'export' function-declaration
-/// 
+///
 ///  export-declaration-group:
 /// 'export' '{' function-declaration-seq[opt] '}'
 ///
@@ -1799,7 +1799,6 @@ void Parser::ParseClassSpecifier(tok::TokenKind 
TagTokKind,
   tok::kw___is_nothrow_constructible,
   tok::kw___is_nothrow_convertible,
   tok::kw___is_nothrow_destructible,
-  tok::kw___is_nullptr,
   tok::kw___is_object,
   tok::kw___is_pod,
   tok::kw___is_pointer,
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 3d7c58e5b3c3c..b3df9cfbc8b9a 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -800,7 +800,6 @@ bool Parser::isRevertibleTypeTrait(const IdentifierInfo *II,
 REVERTIBLE_TYPE_TRAIT(__is_nothrow_assignable);
 REVERTIBLE_TYPE_TRAIT(__is_nothrow_constructible);
 REVERTIBLE_TYPE_TRAIT(__is_nothrow_destructible);
-REVERTIBLE_TYPE_TRAIT(__is_nullptr);
 REVERTIBLE_TYPE_TRAIT(__is_object);
 REVERTIBLE_TYPE_TRAIT(__is_pod);
 REVERTIBLE_TYPE_TRAIT(__is_pointer);
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index bef7da239e6e5..a41b938531cab 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -4979,7 +4979,6 @@ static bool CheckUnaryTypeTraitTypeCompleteness(Sema , 
TypeTrait UTT,
   case UTT_IsArray:
   case UTT_IsBoundedArray:
   case UTT_IsPointer:
-  case UTT_IsNullPointer:
   case UTT_IsReferenceable:
   case UTT_IsLvalueReference:
   case UTT_IsRvalueReference:
@@ -5235,8 +5234,6 @@ static bool EvaluateUnaryTypeTrait(Sema , TypeTrait 
UTT,
 return T->isIncompleteArrayType();
   case UTT_IsPointer:
 return T->isAnyPointerType();
-  case UTT_IsNullPointer:
-return T->isNullPtrType();
   case UTT_IsLvalueReference:
 return T->isLValueReferenceType();
   case UTT_IsRvalueReference:
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index 7adbf4aad7afe..b38e8989cb559 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -1041,42 +1041,6 @@ void is_pointer()
   static_assert(!__is_pointer(void (StructWithMembers::*) ()));
 }
 
-void is_null_pointer() {
-  StructWithMembers x;
-
-  static_assert(__is_nullptr(decltype(nullptr)));
-  static_assert(!__is_nullptr(void *));
-  static_assert(!__is_nullptr(cvoid *));
-  static_assert(!__is_nullptr(cvoid *));
-  static_assert(!__is_nullptr(char *));
-  static_assert(!__is_nullptr(int *));
-  static_assert(!__is_nullptr(int **));
-  static_assert(!__is_nullptr(ClassType *));
-  static_assert(!__is_nullptr(Derives *));
-  static_assert(!__is_nullptr(Enum *));
-  static_assert(!__is_nullptr(IntArNB *));
-  static_assert(!__is_nullptr(Union *));
-  static_assert(!__is_nullptr(UnionAr *));
-  static_assert(!__is_nullptr(StructWithMembers *));
-  static_assert(!__is_nullptr(void (*)()));
-
-  static_assert(!__is_nullptr(void));
-  static_assert(!__is_nullptr(cvoid));
-  static_assert(!__is_nullptr(cvoid));
-  

[clang] [libcxx] [Clang] Add __common_type builtin (PR #99473)

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


@@ -3058,6 +3058,133 @@ void Sema::NoteAllFoundTemplates(TemplateName Name) {
   }
 }
 
+static QualType commonTypeImpl(Sema , TemplateName BaseTemplate,
+   SourceLocation TemplateLoc,
+   ArrayRef Ts) {
+  auto lookUpCommonType = [&](TemplateArgument T1,
+  TemplateArgument T2) -> QualType {
+// Don't bother looking for other specializations if both types are
+// builtins - users aren't allowed to specialize for them

philnik777 wrote:

How is this any different from all the other cases where we switched to 
builtins, which results in potential breaks?

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


[clang] [libcxx] [Clang] Add __common_type builtin (PR #99473)

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


@@ -3058,6 +3058,133 @@ void Sema::NoteAllFoundTemplates(TemplateName Name) {
   }
 }
 
+static QualType commonTypeImpl(Sema , TemplateName BaseTemplate,
+   SourceLocation TemplateLoc,
+   ArrayRef Ts) {
+  auto lookUpCommonType = [&](TemplateArgument T1,
+  TemplateArgument T2) -> QualType {
+// Don't bother looking for other specializations if both types are
+// builtins - users aren't allowed to specialize for them

philnik777 wrote:

We can do that, but I don't think that's part of this project. AFAICT this 
requires tinkering with the template specialization code and check whether a 
specialization is allowed to exist. To me that seems like an entire project on 
its own.

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


[clang] [clang] Remove `__is_layout_compatible` from revertible type traits list (PR #100572)

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

philnik777 wrote:

Should we also rename to `__builtin_is_layout_compatible`?

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


[clang] [libcxx] [Clang] Add __common_type builtin (PR #99473)

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

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

>From d6903daf0da6979822b8981ea3641455ff6d06f8 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Tue, 16 Jul 2024 14:48:10 +0200
Subject: [PATCH 1/4] [Clang] Add __common_type builtin

---
 clang/include/clang/AST/ASTContext.h  |  11 ++
 clang/include/clang/AST/DeclID.h  |   5 +-
 clang/include/clang/Basic/Builtins.h  |   5 +-
 clang/include/clang/Sema/Sema.h   |   4 +
 clang/lib/AST/ASTContext.cpp  |   7 +
 clang/lib/AST/ASTImporter.cpp |   3 +
 clang/lib/AST/DeclTemplate.cpp|  53 ++
 clang/lib/Lex/PPMacroExpansion.cpp|   1 +
 clang/lib/Sema/SemaChecking.cpp   |   8 +
 clang/lib/Sema/SemaLookup.cpp |   4 +
 clang/lib/Sema/SemaTemplate.cpp   | 160 +-
 clang/lib/Serialization/ASTReader.cpp |   3 +
 clang/lib/Serialization/ASTWriter.cpp |   2 +
 clang/test/SemaCXX/type-trait-common-type.cpp | 126 ++
 libcxx/include/__type_traits/common_type.h|  16 +-
 libcxx/include/module.modulemap   |   2 +
 16 files changed, 404 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/SemaCXX/type-trait-common-type.cpp

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 608bd90fcc3ff..d02e742297898 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -399,6 +399,9 @@ class ASTContext : public RefCountedBase {
   /// The identifier '__type_pack_element'.
   mutable IdentifierInfo *TypePackElementName = nullptr;
 
+  /// The identifier '__common_type'.
+  mutable IdentifierInfo *CommonTypeName = nullptr;
+
   QualType ObjCConstantStringType;
   mutable RecordDecl *CFConstantStringTagDecl = nullptr;
   mutable TypedefDecl *CFConstantStringTypeDecl = nullptr;
@@ -606,6 +609,7 @@ class ASTContext : public RefCountedBase {
   mutable ExternCContextDecl *ExternCContext = nullptr;
   mutable BuiltinTemplateDecl *MakeIntegerSeqDecl = nullptr;
   mutable BuiltinTemplateDecl *TypePackElementDecl = nullptr;
+  mutable BuiltinTemplateDecl *CommonTypeDecl = nullptr;
 
   /// The associated SourceManager object.
   SourceManager 
@@ -1107,6 +,7 @@ class ASTContext : public RefCountedBase {
   ExternCContextDecl *getExternCContextDecl() const;
   BuiltinTemplateDecl *getMakeIntegerSeqDecl() const;
   BuiltinTemplateDecl *getTypePackElementDecl() const;
+  BuiltinTemplateDecl *getCommonTypeDecl() const;
 
   // Builtin Types.
   CanQualType VoidTy;
@@ -1984,6 +1989,12 @@ class ASTContext : public RefCountedBase {
 return TypePackElementName;
   }
 
+  IdentifierInfo *getCommonTypeName() const {
+if (!CommonTypeName)
+  CommonTypeName = ("__common_type");
+return CommonTypeName;
+  }
+
   /// Retrieve the Objective-C "instancetype" type, if already known;
   /// otherwise, returns a NULL type;
   QualType getObjCInstanceType() {
diff --git a/clang/include/clang/AST/DeclID.h b/clang/include/clang/AST/DeclID.h
index e5e27389fac60..875e9a72b3951 100644
--- a/clang/include/clang/AST/DeclID.h
+++ b/clang/include/clang/AST/DeclID.h
@@ -84,13 +84,16 @@ enum PredefinedDeclIDs {
 
   /// The internal '__type_pack_element' template.
   PREDEF_DECL_TYPE_PACK_ELEMENT_ID = 17,
+
+  /// The internal '__common_type' template.
+  PREDEF_DECL_COMMON_TYPE_ID = 18,
 };
 
 /// The number of declaration IDs that are predefined.
 ///
 /// For more information about predefined declarations, see the
 /// \c PredefinedDeclIDs type and the PREDEF_DECL_*_ID constants.
-const unsigned int NUM_PREDEF_DECL_IDS = 18;
+const unsigned int NUM_PREDEF_DECL_IDS = 19;
 
 /// GlobalDeclID means DeclID in the current ASTContext and LocalDeclID means
 /// DeclID specific to a certain ModuleFile. Specially, in ASTWriter, the
diff --git a/clang/include/clang/Basic/Builtins.h 
b/clang/include/clang/Basic/Builtins.h
index e85ec5b2dca14..4353b72f71383 100644
--- a/clang/include/clang/Basic/Builtins.h
+++ b/clang/include/clang/Basic/Builtins.h
@@ -309,7 +309,10 @@ enum BuiltinTemplateKind : int {
   BTK__make_integer_seq,
 
   /// This names the __type_pack_element BuiltinTemplateDecl.
-  BTK__type_pack_element
+  BTK__type_pack_element,
+
+  /// This names the __common_type BuiltinTemplateDecl.
+  BTK__common_type,
 };
 
 } // end namespace clang
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 3cb1aa935fe46..5c7945c4c5c58 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2282,6 +2282,10 @@ class Sema final : public SemaBase {
   /// Check to see if a given expression could have '.c_str()' called on it.
   bool hasCStrMethod(const Expr *E);
 
+  // Check whether a type member 'Type::Name' exists, and if yes, return the
+  // type. If there is no type, the QualType is null
+  QualType getTypeMember(StringRef 

[clang] [libcxx] [Clang] Add __common_type builtin (PR #99473)

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

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

>From d6903daf0da6979822b8981ea3641455ff6d06f8 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Tue, 16 Jul 2024 14:48:10 +0200
Subject: [PATCH 1/2] [Clang] Add __common_type builtin

---
 clang/include/clang/AST/ASTContext.h  |  11 ++
 clang/include/clang/AST/DeclID.h  |   5 +-
 clang/include/clang/Basic/Builtins.h  |   5 +-
 clang/include/clang/Sema/Sema.h   |   4 +
 clang/lib/AST/ASTContext.cpp  |   7 +
 clang/lib/AST/ASTImporter.cpp |   3 +
 clang/lib/AST/DeclTemplate.cpp|  53 ++
 clang/lib/Lex/PPMacroExpansion.cpp|   1 +
 clang/lib/Sema/SemaChecking.cpp   |   8 +
 clang/lib/Sema/SemaLookup.cpp |   4 +
 clang/lib/Sema/SemaTemplate.cpp   | 160 +-
 clang/lib/Serialization/ASTReader.cpp |   3 +
 clang/lib/Serialization/ASTWriter.cpp |   2 +
 clang/test/SemaCXX/type-trait-common-type.cpp | 126 ++
 libcxx/include/__type_traits/common_type.h|  16 +-
 libcxx/include/module.modulemap   |   2 +
 16 files changed, 404 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/SemaCXX/type-trait-common-type.cpp

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 608bd90fcc3ff..d02e742297898 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -399,6 +399,9 @@ class ASTContext : public RefCountedBase {
   /// The identifier '__type_pack_element'.
   mutable IdentifierInfo *TypePackElementName = nullptr;
 
+  /// The identifier '__common_type'.
+  mutable IdentifierInfo *CommonTypeName = nullptr;
+
   QualType ObjCConstantStringType;
   mutable RecordDecl *CFConstantStringTagDecl = nullptr;
   mutable TypedefDecl *CFConstantStringTypeDecl = nullptr;
@@ -606,6 +609,7 @@ class ASTContext : public RefCountedBase {
   mutable ExternCContextDecl *ExternCContext = nullptr;
   mutable BuiltinTemplateDecl *MakeIntegerSeqDecl = nullptr;
   mutable BuiltinTemplateDecl *TypePackElementDecl = nullptr;
+  mutable BuiltinTemplateDecl *CommonTypeDecl = nullptr;
 
   /// The associated SourceManager object.
   SourceManager 
@@ -1107,6 +,7 @@ class ASTContext : public RefCountedBase {
   ExternCContextDecl *getExternCContextDecl() const;
   BuiltinTemplateDecl *getMakeIntegerSeqDecl() const;
   BuiltinTemplateDecl *getTypePackElementDecl() const;
+  BuiltinTemplateDecl *getCommonTypeDecl() const;
 
   // Builtin Types.
   CanQualType VoidTy;
@@ -1984,6 +1989,12 @@ class ASTContext : public RefCountedBase {
 return TypePackElementName;
   }
 
+  IdentifierInfo *getCommonTypeName() const {
+if (!CommonTypeName)
+  CommonTypeName = ("__common_type");
+return CommonTypeName;
+  }
+
   /// Retrieve the Objective-C "instancetype" type, if already known;
   /// otherwise, returns a NULL type;
   QualType getObjCInstanceType() {
diff --git a/clang/include/clang/AST/DeclID.h b/clang/include/clang/AST/DeclID.h
index e5e27389fac60..875e9a72b3951 100644
--- a/clang/include/clang/AST/DeclID.h
+++ b/clang/include/clang/AST/DeclID.h
@@ -84,13 +84,16 @@ enum PredefinedDeclIDs {
 
   /// The internal '__type_pack_element' template.
   PREDEF_DECL_TYPE_PACK_ELEMENT_ID = 17,
+
+  /// The internal '__common_type' template.
+  PREDEF_DECL_COMMON_TYPE_ID = 18,
 };
 
 /// The number of declaration IDs that are predefined.
 ///
 /// For more information about predefined declarations, see the
 /// \c PredefinedDeclIDs type and the PREDEF_DECL_*_ID constants.
-const unsigned int NUM_PREDEF_DECL_IDS = 18;
+const unsigned int NUM_PREDEF_DECL_IDS = 19;
 
 /// GlobalDeclID means DeclID in the current ASTContext and LocalDeclID means
 /// DeclID specific to a certain ModuleFile. Specially, in ASTWriter, the
diff --git a/clang/include/clang/Basic/Builtins.h 
b/clang/include/clang/Basic/Builtins.h
index e85ec5b2dca14..4353b72f71383 100644
--- a/clang/include/clang/Basic/Builtins.h
+++ b/clang/include/clang/Basic/Builtins.h
@@ -309,7 +309,10 @@ enum BuiltinTemplateKind : int {
   BTK__make_integer_seq,
 
   /// This names the __type_pack_element BuiltinTemplateDecl.
-  BTK__type_pack_element
+  BTK__type_pack_element,
+
+  /// This names the __common_type BuiltinTemplateDecl.
+  BTK__common_type,
 };
 
 } // end namespace clang
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 3cb1aa935fe46..5c7945c4c5c58 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2282,6 +2282,10 @@ class Sema final : public SemaBase {
   /// Check to see if a given expression could have '.c_str()' called on it.
   bool hasCStrMethod(const Expr *E);
 
+  // Check whether a type member 'Type::Name' exists, and if yes, return the
+  // type. If there is no type, the QualType is null
+  QualType getTypeMember(StringRef 

[clang] [libcxx] [Clang] Add __common_type builtin (PR #99473)

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


@@ -1599,13 +1599,66 @@ createTypePackElementParameterList(const ASTContext , 
DeclContext *DC) {
nullptr);
 }
 
+static TemplateParameterList *createCommonTypeList(const ASTContext ,
+   DeclContext *DC) {
+  // class... Args
+  auto *Args = TemplateTypeParmDecl::Create(
+  C, DC, {}, {}, /*Depth=*/1, /*Position=*/0, /*Id=*/nullptr,
+  /*Typename=*/false, /*ParameterPack=*/true);
+  Args->setImplicit();

philnik777 wrote:

Turns out this actually hides the arguments from the diagnostic message, so I 
think none of them should be implicit.

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


[clang] [libcxx] [Clang] Add __common_type builtin (PR #99473)

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


@@ -6844,6 +6844,14 @@ CXXRecordMembersNamed(StringRef Name, Sema , QualType 
Ty) {
   return Results;
 }
 
+QualType Sema::getTypeMember(StringRef Name, QualType Type) {

philnik777 wrote:

`CXXRecordMembersNamed` is used in `hasCStrMethod` below as well. Should I move 
all of this to `SemaType.cpp`?

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


[clang] [libcxx] [Clang] Add __common_type builtin (PR #99473)

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


@@ -3058,6 +3058,141 @@ void Sema::NoteAllFoundTemplates(TemplateName Name) {
   }
 }
 
+static std::optional commonTypeImpl(Sema ,
+  TemplateName BaseTemplate,
+  SourceLocation TemplateLoc,
+  ArrayRef Ts) {
+  auto lookUpCommonType = [&](TemplateArgument T1,
+  TemplateArgument T2) -> std::optional {
+// Don't bother looking for other specializations if both types are
+// builtins - users aren't allowed to specialize for them
+if (T1.getAsType()->isBuiltinType() && T2.getAsType()->isBuiltinType())
+  return commonTypeImpl(S, BaseTemplate, TemplateLoc, {T1, T2});

philnik777 wrote:

There are two cases where `lookUpCommonType` is called:
- `sizeof...(Ts)` is 1 - in that case we now call `commonTypeImpl` with two 
types
- `sizeof...(Ts)` is 2 and `decay_t` is a different type that `T1/T2` - 
we now call `commonTypeImpl` with the decayed types instead, which won't go 
into the same branch, since a decayed type doesn't decay any further.

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


[clang] [libcxx] [Clang] Add __common_type builtin (PR #99473)

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


@@ -3058,6 +3058,141 @@ void Sema::NoteAllFoundTemplates(TemplateName Name) {
   }
 }
 
+static std::optional commonTypeImpl(Sema ,
+  TemplateName BaseTemplate,
+  SourceLocation TemplateLoc,
+  ArrayRef Ts) {
+  auto lookUpCommonType = [&](TemplateArgument T1,
+  TemplateArgument T2) -> std::optional {
+// Don't bother looking for other specializations if both types are
+// builtins - users aren't allowed to specialize for them
+if (T1.getAsType()->isBuiltinType() && T2.getAsType()->isBuiltinType())
+  return commonTypeImpl(S, BaseTemplate, TemplateLoc, {T1, T2});
+
+TemplateArgumentListInfo Args;
+Args.addArgument(TemplateArgumentLoc(
+T1, S.Context.getTrivialTypeSourceInfo(T1.getAsType(;
+Args.addArgument(TemplateArgumentLoc(
+T2, S.Context.getTrivialTypeSourceInfo(T2.getAsType(;
+QualType BaseTemplateInst =
+S.CheckTemplateIdType(BaseTemplate, TemplateLoc, Args);
+if (S.RequireCompleteType(TemplateLoc, BaseTemplateInst,
+  diag::err_incomplete_type))
+  return std::nullopt;
+if (QualType Type = S.getTypeMember("type", BaseTemplateInst);
+!Type.isNull()) {
+  return Type;
+}
+return std::nullopt;
+  };
+
+  // Note A: For the common_type trait applied to a template parameter pack T 
of
+  // types, the member type shall be either defined or not present as follows:
+  switch (Ts.size()) {
+
+  // If sizeof...(T) is zero, there shall be no member type.
+  case 0:
+return std::nullopt;
+
+  // If sizeof...(T) is one, let T0 denote the sole type constituting the
+  // pack T. The member typedef-name type shall denote the same type, if any, 
as
+  // common_type_t; otherwise there shall be no member type.
+  case 1:
+return lookUpCommonType(Ts[0], Ts[0]);
+
+  // If sizeof...(T) is two, let the first and second types constituting T be
+  // denoted by T1 and T2, respectively, and let D1 and D2 denote the same 
types
+  // as decay_t and decay_t, respectively.
+  case 2: {
+QualType T1 = Ts[0].getAsType();
+QualType T2 = Ts[1].getAsType();
+QualType D1 = S.BuiltinDecay(T1, {});
+QualType D2 = S.BuiltinDecay(T2, {});
+
+// If is_same_v is false or is_same_v is false, let C 
denote
+// the same type, if any, as common_type_t.
+if (!S.Context.hasSameType(T1, D1) || !S.Context.hasSameType(T2, D2)) {
+  return lookUpCommonType(D1, D2);
+}
+
+// Otherwise, if decay_t() : declval())>
+// denotes a valid type, let C denote that type.
+{
+  auto CheckConditionalOperands =
+  [&](bool ConstRefQual) -> std::optional {
+EnterExpressionEvaluationContext UnevaluatedContext(
+S, Sema::ExpressionEvaluationContext::Unevaluated);
+Sema::SFINAETrap SFINAE(S, /*AccessCheckingSFINAE=*/true);
+Sema::ContextRAII TUContext(S, S.Context.getTranslationUnitDecl());
+
+// false
+OpaqueValueExpr CondExpr({}, S.Context.BoolTy,
+ ExprValueKind::VK_PRValue);
+ExprResult Cond = 
+
+auto EVK =
+ConstRefQual ? ExprValueKind::VK_LValue : 
ExprValueKind::VK_PRValue;
+if (ConstRefQual) {
+  D1.addConst();
+  D2.addConst();
+}
+
+// declval()
+OpaqueValueExpr LHSExpr(TemplateLoc, D1, EVK);
+ExprResult LHS = 
+
+// declval()
+OpaqueValueExpr RHSExpr(TemplateLoc, D2, EVK);
+ExprResult RHS = 
+
+ExprValueKind VK = VK_PRValue;
+ExprObjectKind OK = OK_Ordinary;
+
+// decltype(false ? declval() : declval())
+QualType Result =
+S.CheckConditionalOperands(Cond, LHS, RHS, VK, OK, TemplateLoc);
+
+if (Result.isNull() || SFINAE.hasErrorOccurred())
+  return std::nullopt;
+
+// decay_t() : declval())>
+return S.BuiltinDecay(Result, TemplateLoc);
+  };
+
+  if (auto Res = CheckConditionalOperands(false))
+return Res;
+
+  // Let:
+  // CREF(A) be add_lvalue_reference_t>,
+  // COND-RES(X, Y) be
+  //   decltype(false ? declval()() : declval()()).
+
+  // C++20 only
+  // Otherwise, if COND-RES(CREF(D1), CREF(D2)) denotes a type, let C 
denote
+  // the type decay_t.
+  if (!S.Context.getLangOpts().CPlusPlus20)
+return std::nullopt;
+  return CheckConditionalOperands(true);
+}
+  }
+
+  // If sizeof...(T) is greater than two, let T1, T2, and R, respectively,
+  // denote the first, second, and (pack of) remaining types constituting T. 
Let
+  // C denote the same type, if any, as common_type_t. If there is such
+  // a type C, the member typedef-name type shall denote the same type, if any,
+  // as common_type_t. Otherwise, there shall be no member type.
+  default: {
+ 

[clang] [libcxx] [Clang] Add __common_type builtin (PR #99473)

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

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


[clang] [libcxx] [Clang] Add __common_type builtin (PR #99473)

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

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

>From d6903daf0da6979822b8981ea3641455ff6d06f8 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Tue, 16 Jul 2024 14:48:10 +0200
Subject: [PATCH] [Clang] Add __common_type builtin

---
 clang/include/clang/AST/ASTContext.h  |  11 ++
 clang/include/clang/AST/DeclID.h  |   5 +-
 clang/include/clang/Basic/Builtins.h  |   5 +-
 clang/include/clang/Sema/Sema.h   |   4 +
 clang/lib/AST/ASTContext.cpp  |   7 +
 clang/lib/AST/ASTImporter.cpp |   3 +
 clang/lib/AST/DeclTemplate.cpp|  53 ++
 clang/lib/Lex/PPMacroExpansion.cpp|   1 +
 clang/lib/Sema/SemaChecking.cpp   |   8 +
 clang/lib/Sema/SemaLookup.cpp |   4 +
 clang/lib/Sema/SemaTemplate.cpp   | 160 +-
 clang/lib/Serialization/ASTReader.cpp |   3 +
 clang/lib/Serialization/ASTWriter.cpp |   2 +
 clang/test/SemaCXX/type-trait-common-type.cpp | 126 ++
 libcxx/include/__type_traits/common_type.h|  16 +-
 libcxx/include/module.modulemap   |   2 +
 16 files changed, 404 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/SemaCXX/type-trait-common-type.cpp

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 608bd90fcc3ff..d02e742297898 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -399,6 +399,9 @@ class ASTContext : public RefCountedBase {
   /// The identifier '__type_pack_element'.
   mutable IdentifierInfo *TypePackElementName = nullptr;
 
+  /// The identifier '__common_type'.
+  mutable IdentifierInfo *CommonTypeName = nullptr;
+
   QualType ObjCConstantStringType;
   mutable RecordDecl *CFConstantStringTagDecl = nullptr;
   mutable TypedefDecl *CFConstantStringTypeDecl = nullptr;
@@ -606,6 +609,7 @@ class ASTContext : public RefCountedBase {
   mutable ExternCContextDecl *ExternCContext = nullptr;
   mutable BuiltinTemplateDecl *MakeIntegerSeqDecl = nullptr;
   mutable BuiltinTemplateDecl *TypePackElementDecl = nullptr;
+  mutable BuiltinTemplateDecl *CommonTypeDecl = nullptr;
 
   /// The associated SourceManager object.
   SourceManager 
@@ -1107,6 +,7 @@ class ASTContext : public RefCountedBase {
   ExternCContextDecl *getExternCContextDecl() const;
   BuiltinTemplateDecl *getMakeIntegerSeqDecl() const;
   BuiltinTemplateDecl *getTypePackElementDecl() const;
+  BuiltinTemplateDecl *getCommonTypeDecl() const;
 
   // Builtin Types.
   CanQualType VoidTy;
@@ -1984,6 +1989,12 @@ class ASTContext : public RefCountedBase {
 return TypePackElementName;
   }
 
+  IdentifierInfo *getCommonTypeName() const {
+if (!CommonTypeName)
+  CommonTypeName = ("__common_type");
+return CommonTypeName;
+  }
+
   /// Retrieve the Objective-C "instancetype" type, if already known;
   /// otherwise, returns a NULL type;
   QualType getObjCInstanceType() {
diff --git a/clang/include/clang/AST/DeclID.h b/clang/include/clang/AST/DeclID.h
index e5e27389fac60..875e9a72b3951 100644
--- a/clang/include/clang/AST/DeclID.h
+++ b/clang/include/clang/AST/DeclID.h
@@ -84,13 +84,16 @@ enum PredefinedDeclIDs {
 
   /// The internal '__type_pack_element' template.
   PREDEF_DECL_TYPE_PACK_ELEMENT_ID = 17,
+
+  /// The internal '__common_type' template.
+  PREDEF_DECL_COMMON_TYPE_ID = 18,
 };
 
 /// The number of declaration IDs that are predefined.
 ///
 /// For more information about predefined declarations, see the
 /// \c PredefinedDeclIDs type and the PREDEF_DECL_*_ID constants.
-const unsigned int NUM_PREDEF_DECL_IDS = 18;
+const unsigned int NUM_PREDEF_DECL_IDS = 19;
 
 /// GlobalDeclID means DeclID in the current ASTContext and LocalDeclID means
 /// DeclID specific to a certain ModuleFile. Specially, in ASTWriter, the
diff --git a/clang/include/clang/Basic/Builtins.h 
b/clang/include/clang/Basic/Builtins.h
index e85ec5b2dca14..4353b72f71383 100644
--- a/clang/include/clang/Basic/Builtins.h
+++ b/clang/include/clang/Basic/Builtins.h
@@ -309,7 +309,10 @@ enum BuiltinTemplateKind : int {
   BTK__make_integer_seq,
 
   /// This names the __type_pack_element BuiltinTemplateDecl.
-  BTK__type_pack_element
+  BTK__type_pack_element,
+
+  /// This names the __common_type BuiltinTemplateDecl.
+  BTK__common_type,
 };
 
 } // end namespace clang
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 3cb1aa935fe46..5c7945c4c5c58 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2282,6 +2282,10 @@ class Sema final : public SemaBase {
   /// Check to see if a given expression could have '.c_str()' called on it.
   bool hasCStrMethod(const Expr *E);
 
+  // Check whether a type member 'Type::Name' exists, and if yes, return the
+  // type. If there is no type, the QualType is null
+  QualType getTypeMember(StringRef Name, 

[clang] [libcxx] [Clang] Add __common_type builtin (PR #99473)

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

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

>From f034248ddb55ff2184662e0558c078f8109c0e00 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Tue, 16 Jul 2024 14:48:10 +0200
Subject: [PATCH] [Clang] Add __common_type builtin

---
 clang/include/clang/AST/ASTContext.h  |  11 ++
 clang/include/clang/AST/DeclID.h  |   5 +-
 clang/include/clang/Basic/Builtins.h  |   5 +-
 clang/include/clang/Sema/Sema.h   |   4 +
 clang/lib/AST/ASTContext.cpp  |   7 +
 clang/lib/AST/ASTImporter.cpp |   3 +
 clang/lib/AST/DeclTemplate.cpp|  53 ++
 clang/lib/Lex/PPMacroExpansion.cpp|   1 +
 clang/lib/Sema/SemaChecking.cpp   |   8 +
 clang/lib/Sema/SemaLookup.cpp |   4 +
 clang/lib/Sema/SemaTemplate.cpp   | 160 +-
 clang/lib/Serialization/ASTReader.cpp |   3 +
 clang/lib/Serialization/ASTWriter.cpp |   2 +
 clang/test/SemaCXX/type-trait-common-type.cpp | 126 ++
 libcxx/include/__type_traits/common_type.h|  16 +-
 libcxx/include/module.modulemap   |   2 +
 16 files changed, 404 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/SemaCXX/type-trait-common-type.cpp

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 608bd90fcc3ff..d02e742297898 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -399,6 +399,9 @@ class ASTContext : public RefCountedBase {
   /// The identifier '__type_pack_element'.
   mutable IdentifierInfo *TypePackElementName = nullptr;
 
+  /// The identifier '__common_type'.
+  mutable IdentifierInfo *CommonTypeName = nullptr;
+
   QualType ObjCConstantStringType;
   mutable RecordDecl *CFConstantStringTagDecl = nullptr;
   mutable TypedefDecl *CFConstantStringTypeDecl = nullptr;
@@ -606,6 +609,7 @@ class ASTContext : public RefCountedBase {
   mutable ExternCContextDecl *ExternCContext = nullptr;
   mutable BuiltinTemplateDecl *MakeIntegerSeqDecl = nullptr;
   mutable BuiltinTemplateDecl *TypePackElementDecl = nullptr;
+  mutable BuiltinTemplateDecl *CommonTypeDecl = nullptr;
 
   /// The associated SourceManager object.
   SourceManager 
@@ -1107,6 +,7 @@ class ASTContext : public RefCountedBase {
   ExternCContextDecl *getExternCContextDecl() const;
   BuiltinTemplateDecl *getMakeIntegerSeqDecl() const;
   BuiltinTemplateDecl *getTypePackElementDecl() const;
+  BuiltinTemplateDecl *getCommonTypeDecl() const;
 
   // Builtin Types.
   CanQualType VoidTy;
@@ -1984,6 +1989,12 @@ class ASTContext : public RefCountedBase {
 return TypePackElementName;
   }
 
+  IdentifierInfo *getCommonTypeName() const {
+if (!CommonTypeName)
+  CommonTypeName = ("__common_type");
+return CommonTypeName;
+  }
+
   /// Retrieve the Objective-C "instancetype" type, if already known;
   /// otherwise, returns a NULL type;
   QualType getObjCInstanceType() {
diff --git a/clang/include/clang/AST/DeclID.h b/clang/include/clang/AST/DeclID.h
index e5e27389fac60..875e9a72b3951 100644
--- a/clang/include/clang/AST/DeclID.h
+++ b/clang/include/clang/AST/DeclID.h
@@ -84,13 +84,16 @@ enum PredefinedDeclIDs {
 
   /// The internal '__type_pack_element' template.
   PREDEF_DECL_TYPE_PACK_ELEMENT_ID = 17,
+
+  /// The internal '__common_type' template.
+  PREDEF_DECL_COMMON_TYPE_ID = 18,
 };
 
 /// The number of declaration IDs that are predefined.
 ///
 /// For more information about predefined declarations, see the
 /// \c PredefinedDeclIDs type and the PREDEF_DECL_*_ID constants.
-const unsigned int NUM_PREDEF_DECL_IDS = 18;
+const unsigned int NUM_PREDEF_DECL_IDS = 19;
 
 /// GlobalDeclID means DeclID in the current ASTContext and LocalDeclID means
 /// DeclID specific to a certain ModuleFile. Specially, in ASTWriter, the
diff --git a/clang/include/clang/Basic/Builtins.h 
b/clang/include/clang/Basic/Builtins.h
index e85ec5b2dca14..4353b72f71383 100644
--- a/clang/include/clang/Basic/Builtins.h
+++ b/clang/include/clang/Basic/Builtins.h
@@ -309,7 +309,10 @@ enum BuiltinTemplateKind : int {
   BTK__make_integer_seq,
 
   /// This names the __type_pack_element BuiltinTemplateDecl.
-  BTK__type_pack_element
+  BTK__type_pack_element,
+
+  /// This names the __common_type BuiltinTemplateDecl.
+  BTK__common_type,
 };
 
 } // end namespace clang
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 3cb1aa935fe46..5c7945c4c5c58 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2282,6 +2282,10 @@ class Sema final : public SemaBase {
   /// Check to see if a given expression could have '.c_str()' called on it.
   bool hasCStrMethod(const Expr *E);
 
+  // Check whether a type member 'Type::Name' exists, and if yes, return the
+  // type. If there is no type, the QualType is null
+  QualType getTypeMember(StringRef Name, 

[clang] [libcxx] [Clang] Add __common_type builtin (PR #99473)

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

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

>From d11417d4addd7a5da5436e9fb406748a3059e17c Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Tue, 16 Jul 2024 14:48:10 +0200
Subject: [PATCH] [Clang] Add __common_type builtin

---
 clang/include/clang/AST/ASTContext.h  |  11 ++
 clang/include/clang/AST/DeclID.h  |   5 +-
 clang/include/clang/Basic/Builtins.h  |   5 +-
 clang/include/clang/Sema/Sema.h   |   4 +
 clang/lib/AST/ASTContext.cpp  |   7 +
 clang/lib/AST/ASTImporter.cpp |   3 +
 clang/lib/AST/DeclTemplate.cpp|  53 ++
 clang/lib/Lex/PPMacroExpansion.cpp|   1 +
 clang/lib/Sema/SemaChecking.cpp   |   8 +
 clang/lib/Sema/SemaLookup.cpp |   4 +
 clang/lib/Sema/SemaTemplate.cpp   | 160 +-
 clang/lib/Serialization/ASTReader.cpp |   3 +
 clang/lib/Serialization/ASTWriter.cpp |   2 +
 clang/test/SemaCXX/type-trait-common-type.cpp | 125 ++
 libcxx/include/__type_traits/common_type.h|  16 +-
 15 files changed, 401 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/SemaCXX/type-trait-common-type.cpp

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 608bd90fcc3ff..d02e742297898 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -399,6 +399,9 @@ class ASTContext : public RefCountedBase {
   /// The identifier '__type_pack_element'.
   mutable IdentifierInfo *TypePackElementName = nullptr;
 
+  /// The identifier '__common_type'.
+  mutable IdentifierInfo *CommonTypeName = nullptr;
+
   QualType ObjCConstantStringType;
   mutable RecordDecl *CFConstantStringTagDecl = nullptr;
   mutable TypedefDecl *CFConstantStringTypeDecl = nullptr;
@@ -606,6 +609,7 @@ class ASTContext : public RefCountedBase {
   mutable ExternCContextDecl *ExternCContext = nullptr;
   mutable BuiltinTemplateDecl *MakeIntegerSeqDecl = nullptr;
   mutable BuiltinTemplateDecl *TypePackElementDecl = nullptr;
+  mutable BuiltinTemplateDecl *CommonTypeDecl = nullptr;
 
   /// The associated SourceManager object.
   SourceManager 
@@ -1107,6 +,7 @@ class ASTContext : public RefCountedBase {
   ExternCContextDecl *getExternCContextDecl() const;
   BuiltinTemplateDecl *getMakeIntegerSeqDecl() const;
   BuiltinTemplateDecl *getTypePackElementDecl() const;
+  BuiltinTemplateDecl *getCommonTypeDecl() const;
 
   // Builtin Types.
   CanQualType VoidTy;
@@ -1984,6 +1989,12 @@ class ASTContext : public RefCountedBase {
 return TypePackElementName;
   }
 
+  IdentifierInfo *getCommonTypeName() const {
+if (!CommonTypeName)
+  CommonTypeName = ("__common_type");
+return CommonTypeName;
+  }
+
   /// Retrieve the Objective-C "instancetype" type, if already known;
   /// otherwise, returns a NULL type;
   QualType getObjCInstanceType() {
diff --git a/clang/include/clang/AST/DeclID.h b/clang/include/clang/AST/DeclID.h
index e5e27389fac60..875e9a72b3951 100644
--- a/clang/include/clang/AST/DeclID.h
+++ b/clang/include/clang/AST/DeclID.h
@@ -84,13 +84,16 @@ enum PredefinedDeclIDs {
 
   /// The internal '__type_pack_element' template.
   PREDEF_DECL_TYPE_PACK_ELEMENT_ID = 17,
+
+  /// The internal '__common_type' template.
+  PREDEF_DECL_COMMON_TYPE_ID = 18,
 };
 
 /// The number of declaration IDs that are predefined.
 ///
 /// For more information about predefined declarations, see the
 /// \c PredefinedDeclIDs type and the PREDEF_DECL_*_ID constants.
-const unsigned int NUM_PREDEF_DECL_IDS = 18;
+const unsigned int NUM_PREDEF_DECL_IDS = 19;
 
 /// GlobalDeclID means DeclID in the current ASTContext and LocalDeclID means
 /// DeclID specific to a certain ModuleFile. Specially, in ASTWriter, the
diff --git a/clang/include/clang/Basic/Builtins.h 
b/clang/include/clang/Basic/Builtins.h
index e85ec5b2dca14..4353b72f71383 100644
--- a/clang/include/clang/Basic/Builtins.h
+++ b/clang/include/clang/Basic/Builtins.h
@@ -309,7 +309,10 @@ enum BuiltinTemplateKind : int {
   BTK__make_integer_seq,
 
   /// This names the __type_pack_element BuiltinTemplateDecl.
-  BTK__type_pack_element
+  BTK__type_pack_element,
+
+  /// This names the __common_type BuiltinTemplateDecl.
+  BTK__common_type,
 };
 
 } // end namespace clang
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 3cb1aa935fe46..5c7945c4c5c58 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2282,6 +2282,10 @@ class Sema final : public SemaBase {
   /// Check to see if a given expression could have '.c_str()' called on it.
   bool hasCStrMethod(const Expr *E);
 
+  // Check whether a type member 'Type::Name' exists, and if yes, return the
+  // type. If there is no type, the QualType is null
+  QualType getTypeMember(StringRef Name, QualType Type);
+
   /// Diagnose pointers that are 

[clang] [libcxx] [Clang] Add __common_type builtin (PR #99473)

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

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

>From 22513d53967ac32ae4112499c33c7c481b52b2fd Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Tue, 16 Jul 2024 14:48:10 +0200
Subject: [PATCH] [Clang] Add __common_type builtin

---
 clang/include/clang/AST/ASTContext.h  |  11 ++
 clang/include/clang/AST/DeclID.h  |   5 +-
 clang/include/clang/Basic/Builtins.h  |   5 +-
 clang/include/clang/Sema/Sema.h   |   4 +
 clang/lib/AST/ASTContext.cpp  |   8 +
 clang/lib/AST/ASTImporter.cpp |   3 +
 clang/lib/AST/DeclTemplate.cpp|  53 ++
 clang/lib/Lex/PPMacroExpansion.cpp|   1 +
 clang/lib/Sema/SemaChecking.cpp   |   8 +
 clang/lib/Sema/SemaLookup.cpp |   4 +
 clang/lib/Sema/SemaTemplate.cpp   | 159 +-
 clang/lib/Serialization/ASTReader.cpp |   3 +
 clang/test/SemaCXX/type-trait-common-type.cpp | 125 ++
 libcxx/include/__type_traits/common_type.h|  10 ++
 14 files changed, 396 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/SemaCXX/type-trait-common-type.cpp

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 608bd90fcc3ff..d02e742297898 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -399,6 +399,9 @@ class ASTContext : public RefCountedBase {
   /// The identifier '__type_pack_element'.
   mutable IdentifierInfo *TypePackElementName = nullptr;
 
+  /// The identifier '__common_type'.
+  mutable IdentifierInfo *CommonTypeName = nullptr;
+
   QualType ObjCConstantStringType;
   mutable RecordDecl *CFConstantStringTagDecl = nullptr;
   mutable TypedefDecl *CFConstantStringTypeDecl = nullptr;
@@ -606,6 +609,7 @@ class ASTContext : public RefCountedBase {
   mutable ExternCContextDecl *ExternCContext = nullptr;
   mutable BuiltinTemplateDecl *MakeIntegerSeqDecl = nullptr;
   mutable BuiltinTemplateDecl *TypePackElementDecl = nullptr;
+  mutable BuiltinTemplateDecl *CommonTypeDecl = nullptr;
 
   /// The associated SourceManager object.
   SourceManager 
@@ -1107,6 +,7 @@ class ASTContext : public RefCountedBase {
   ExternCContextDecl *getExternCContextDecl() const;
   BuiltinTemplateDecl *getMakeIntegerSeqDecl() const;
   BuiltinTemplateDecl *getTypePackElementDecl() const;
+  BuiltinTemplateDecl *getCommonTypeDecl() const;
 
   // Builtin Types.
   CanQualType VoidTy;
@@ -1984,6 +1989,12 @@ class ASTContext : public RefCountedBase {
 return TypePackElementName;
   }
 
+  IdentifierInfo *getCommonTypeName() const {
+if (!CommonTypeName)
+  CommonTypeName = ("__common_type");
+return CommonTypeName;
+  }
+
   /// Retrieve the Objective-C "instancetype" type, if already known;
   /// otherwise, returns a NULL type;
   QualType getObjCInstanceType() {
diff --git a/clang/include/clang/AST/DeclID.h b/clang/include/clang/AST/DeclID.h
index e5e27389fac60..875e9a72b3951 100644
--- a/clang/include/clang/AST/DeclID.h
+++ b/clang/include/clang/AST/DeclID.h
@@ -84,13 +84,16 @@ enum PredefinedDeclIDs {
 
   /// The internal '__type_pack_element' template.
   PREDEF_DECL_TYPE_PACK_ELEMENT_ID = 17,
+
+  /// The internal '__common_type' template.
+  PREDEF_DECL_COMMON_TYPE_ID = 18,
 };
 
 /// The number of declaration IDs that are predefined.
 ///
 /// For more information about predefined declarations, see the
 /// \c PredefinedDeclIDs type and the PREDEF_DECL_*_ID constants.
-const unsigned int NUM_PREDEF_DECL_IDS = 18;
+const unsigned int NUM_PREDEF_DECL_IDS = 19;
 
 /// GlobalDeclID means DeclID in the current ASTContext and LocalDeclID means
 /// DeclID specific to a certain ModuleFile. Specially, in ASTWriter, the
diff --git a/clang/include/clang/Basic/Builtins.h 
b/clang/include/clang/Basic/Builtins.h
index e85ec5b2dca14..4353b72f71383 100644
--- a/clang/include/clang/Basic/Builtins.h
+++ b/clang/include/clang/Basic/Builtins.h
@@ -309,7 +309,10 @@ enum BuiltinTemplateKind : int {
   BTK__make_integer_seq,
 
   /// This names the __type_pack_element BuiltinTemplateDecl.
-  BTK__type_pack_element
+  BTK__type_pack_element,
+
+  /// This names the __common_type BuiltinTemplateDecl.
+  BTK__common_type,
 };
 
 } // end namespace clang
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 3cb1aa935fe46..5c7945c4c5c58 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2282,6 +2282,10 @@ class Sema final : public SemaBase {
   /// Check to see if a given expression could have '.c_str()' called on it.
   bool hasCStrMethod(const Expr *E);
 
+  // Check whether a type member 'Type::Name' exists, and if yes, return the
+  // type. If there is no type, the QualType is null
+  QualType getTypeMember(StringRef Name, QualType Type);
+
   /// Diagnose pointers that are always non-null.
   /// \param E the expression containing 

[clang] [libcxx] [Clang] Add __common_type builtin (PR #99473)

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

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

>From f9b9431a97952909190c69e1dee188ef234addb2 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Tue, 16 Jul 2024 14:48:10 +0200
Subject: [PATCH] [Clang] Add __common_type builtin

---
 clang/include/clang/AST/ASTContext.h  |  11 +
 clang/include/clang/AST/DeclID.h  |   3 +
 clang/include/clang/Basic/Builtins.h  |   5 +-
 clang/include/clang/Sema/Sema.h   |   4 +
 clang/lib/AST/ASTContext.cpp  |   8 +
 clang/lib/AST/ASTImporter.cpp |   3 +
 clang/lib/AST/DeclTemplate.cpp|  53 
 clang/lib/Lex/PPMacroExpansion.cpp|   1 +
 clang/lib/Sema/SemaChecking.cpp   |   8 +
 clang/lib/Sema/SemaLookup.cpp |   4 +
 clang/lib/Sema/SemaTemplate.cpp   | 154 ++-
 clang/test/AST/Interp/crash-GH49103-2.cpp |   4 +-
 clang/test/SemaCXX/crash-GH49103-2.cpp|   4 +-
 clang/test/SemaCXX/type-trait-common-type.cpp | 125 +
 clang/test/SemaCXX/type-traits.cpp| 240 +-
 libcxx/include/__type_traits/common_type.h|  10 +
 16 files changed, 511 insertions(+), 126 deletions(-)
 create mode 100644 clang/test/SemaCXX/type-trait-common-type.cpp

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 57022e75073fe..867467d01f4d1 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -399,6 +399,9 @@ class ASTContext : public RefCountedBase {
   /// The identifier '__type_pack_element'.
   mutable IdentifierInfo *TypePackElementName = nullptr;
 
+  /// The identifier '__common_type'.
+  mutable IdentifierInfo *CommonTypeName = nullptr;
+
   QualType ObjCConstantStringType;
   mutable RecordDecl *CFConstantStringTagDecl = nullptr;
   mutable TypedefDecl *CFConstantStringTypeDecl = nullptr;
@@ -606,6 +609,7 @@ class ASTContext : public RefCountedBase {
   mutable ExternCContextDecl *ExternCContext = nullptr;
   mutable BuiltinTemplateDecl *MakeIntegerSeqDecl = nullptr;
   mutable BuiltinTemplateDecl *TypePackElementDecl = nullptr;
+  mutable BuiltinTemplateDecl *CommonTypeDecl = nullptr;
 
   /// The associated SourceManager object.
   SourceManager 
@@ -1104,6 +1108,7 @@ class ASTContext : public RefCountedBase {
   ExternCContextDecl *getExternCContextDecl() const;
   BuiltinTemplateDecl *getMakeIntegerSeqDecl() const;
   BuiltinTemplateDecl *getTypePackElementDecl() const;
+  BuiltinTemplateDecl *getCommonTypeDecl() const;
 
   // Builtin Types.
   CanQualType VoidTy;
@@ -1981,6 +1986,12 @@ class ASTContext : public RefCountedBase {
 return TypePackElementName;
   }
 
+  IdentifierInfo *getCommonTypeName() const {
+if (!CommonTypeName)
+  CommonTypeName = ("__common_type");
+return CommonTypeName;
+  }
+
   /// Retrieve the Objective-C "instancetype" type, if already known;
   /// otherwise, returns a NULL type;
   QualType getObjCInstanceType() {
diff --git a/clang/include/clang/AST/DeclID.h b/clang/include/clang/AST/DeclID.h
index e5e27389fac60..d8243773d8d98 100644
--- a/clang/include/clang/AST/DeclID.h
+++ b/clang/include/clang/AST/DeclID.h
@@ -84,6 +84,9 @@ enum PredefinedDeclIDs {
 
   /// The internal '__type_pack_element' template.
   PREDEF_DECL_TYPE_PACK_ELEMENT_ID = 17,
+
+  /// The internal '__common_type' template.
+  PREDEF_DECL_COMMON_TYPE_ID = 17,
 };
 
 /// The number of declaration IDs that are predefined.
diff --git a/clang/include/clang/Basic/Builtins.h 
b/clang/include/clang/Basic/Builtins.h
index f955d21169556..defffb334d480 100644
--- a/clang/include/clang/Basic/Builtins.h
+++ b/clang/include/clang/Basic/Builtins.h
@@ -304,7 +304,10 @@ enum BuiltinTemplateKind : int {
   BTK__make_integer_seq,
 
   /// This names the __type_pack_element BuiltinTemplateDecl.
-  BTK__type_pack_element
+  BTK__type_pack_element,
+
+  /// This names the __common_type BuiltinTemplateDecl.
+  BTK__common_type,
 };
 
 } // end namespace clang
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 48dff1b76cc57..1f9480418238a 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2282,6 +2282,10 @@ class Sema final : public SemaBase {
   /// Check to see if a given expression could have '.c_str()' called on it.
   bool hasCStrMethod(const Expr *E);
 
+  // Check whether a type member 'Type::Name' exists, and if yes, return the
+  // type. If there is no type, the QualType is null
+  QualType getTypeMember(StringRef Name, QualType Type);
+
   /// Diagnose pointers that are always non-null.
   /// \param E the expression containing the pointer
   /// \param NullKind NPCK_NotNull if E is a cast to bool, otherwise, E is
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 6c89e3890ae3e..4000c2c2d6836 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp

[clang] [Clang] Add __common_type builtin (PR #99473)

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

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

This implements the logic of the `common_type` base template as a builtin 
alias. If there should be no `type` member, an empty class is returned. 
Otherwise a specialization of a `type_identity`-like class is returned. The 
base template (i.e. `std::common_type`) as well as the empty class and 
`type_identity`-like struct are given as arguments to the builtin.


>From c893eb9db0b25eef0b1c9df8e711358c14bc8a63 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Tue, 16 Jul 2024 14:48:10 +0200
Subject: [PATCH] [Clang] Add __common_type builtin

---
 clang/include/clang/AST/ASTContext.h  |  11 +
 clang/include/clang/AST/DeclID.h  |   3 +
 clang/include/clang/Basic/Builtins.h  |   5 +-
 clang/include/clang/Sema/Sema.h   |   4 +
 clang/lib/AST/ASTContext.cpp  |   8 +
 clang/lib/AST/ASTImporter.cpp |   3 +
 clang/lib/AST/DeclTemplate.cpp|  53 
 clang/lib/Lex/PPMacroExpansion.cpp|   1 +
 clang/lib/Sema/SemaChecking.cpp   |   8 +
 clang/lib/Sema/SemaLookup.cpp |   4 +
 clang/lib/Sema/SemaTemplate.cpp   | 154 ++-
 clang/test/AST/Interp/crash-GH49103-2.cpp |   4 +-
 clang/test/SemaCXX/crash-GH49103-2.cpp|   4 +-
 clang/test/SemaCXX/type-trait-common-type.cpp | 125 +
 clang/test/SemaCXX/type-traits.cpp| 240 +-
 15 files changed, 501 insertions(+), 126 deletions(-)
 create mode 100644 clang/test/SemaCXX/type-trait-common-type.cpp

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 57022e75073fe..867467d01f4d1 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -399,6 +399,9 @@ class ASTContext : public RefCountedBase {
   /// The identifier '__type_pack_element'.
   mutable IdentifierInfo *TypePackElementName = nullptr;
 
+  /// The identifier '__common_type'.
+  mutable IdentifierInfo *CommonTypeName = nullptr;
+
   QualType ObjCConstantStringType;
   mutable RecordDecl *CFConstantStringTagDecl = nullptr;
   mutable TypedefDecl *CFConstantStringTypeDecl = nullptr;
@@ -606,6 +609,7 @@ class ASTContext : public RefCountedBase {
   mutable ExternCContextDecl *ExternCContext = nullptr;
   mutable BuiltinTemplateDecl *MakeIntegerSeqDecl = nullptr;
   mutable BuiltinTemplateDecl *TypePackElementDecl = nullptr;
+  mutable BuiltinTemplateDecl *CommonTypeDecl = nullptr;
 
   /// The associated SourceManager object.
   SourceManager 
@@ -1104,6 +1108,7 @@ class ASTContext : public RefCountedBase {
   ExternCContextDecl *getExternCContextDecl() const;
   BuiltinTemplateDecl *getMakeIntegerSeqDecl() const;
   BuiltinTemplateDecl *getTypePackElementDecl() const;
+  BuiltinTemplateDecl *getCommonTypeDecl() const;
 
   // Builtin Types.
   CanQualType VoidTy;
@@ -1981,6 +1986,12 @@ class ASTContext : public RefCountedBase {
 return TypePackElementName;
   }
 
+  IdentifierInfo *getCommonTypeName() const {
+if (!CommonTypeName)
+  CommonTypeName = ("__common_type");
+return CommonTypeName;
+  }
+
   /// Retrieve the Objective-C "instancetype" type, if already known;
   /// otherwise, returns a NULL type;
   QualType getObjCInstanceType() {
diff --git a/clang/include/clang/AST/DeclID.h b/clang/include/clang/AST/DeclID.h
index e5e27389fac60..d8243773d8d98 100644
--- a/clang/include/clang/AST/DeclID.h
+++ b/clang/include/clang/AST/DeclID.h
@@ -84,6 +84,9 @@ enum PredefinedDeclIDs {
 
   /// The internal '__type_pack_element' template.
   PREDEF_DECL_TYPE_PACK_ELEMENT_ID = 17,
+
+  /// The internal '__common_type' template.
+  PREDEF_DECL_COMMON_TYPE_ID = 17,
 };
 
 /// The number of declaration IDs that are predefined.
diff --git a/clang/include/clang/Basic/Builtins.h 
b/clang/include/clang/Basic/Builtins.h
index f955d21169556..defffb334d480 100644
--- a/clang/include/clang/Basic/Builtins.h
+++ b/clang/include/clang/Basic/Builtins.h
@@ -304,7 +304,10 @@ enum BuiltinTemplateKind : int {
   BTK__make_integer_seq,
 
   /// This names the __type_pack_element BuiltinTemplateDecl.
-  BTK__type_pack_element
+  BTK__type_pack_element,
+
+  /// This names the __common_type BuiltinTemplateDecl.
+  BTK__common_type,
 };
 
 } // end namespace clang
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 48dff1b76cc57..1f9480418238a 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2282,6 +2282,10 @@ class Sema final : public SemaBase {
   /// Check to see if a given expression could have '.c_str()' called on it.
   bool hasCStrMethod(const Expr *E);
 
+  // Check whether a type member 'Type::Name' exists, and if yes, return the
+  // type. If there is no type, the QualType is null
+  QualType getTypeMember(StringRef Name, QualType Type);
+
   /// Diagnose pointers that are always non-null.
   

[clang] [Clang] Remove __is_nullptr (PR #99038)

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

philnik777 wrote:

> I mostly support the removal but I'd feel more comfortable documenting the 
> extension as deprecated in Clang 19, adding a release note warning users 
> about it going away and what the replacement code would look like, and then 
> remove `__is_nullptr()` in Clang 20. (edited to remove the need for a time 
> machine as a prerequisite.)
> 
> That said, has anyone checked with Embarcadero and Microsoft as to whether 
> they still need it supported for their STL implementations for historical 
> reasons? That might delay the timeline or change opinions on the direction.

AFAICT MSVC never had such a trait. I don't know why it's documented that way, 
but the documentation is almost certainly wrong.


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


[clang] [Clang] Remove __is_nullptr (PR #99038)

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

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

`is_null_pointer` can be implemented very efficiently as 
`__is_same(__remove_cv(T), decltype(nullptr))`. Since GCC supports both of 
these builtins as well, libc++ has no interest in using `__is_nullptr` instead. 
Furthermore, I could find only a single use in the wild 
(https://sourcegraph.com/search?q=context:global+__is_nullptr%28+-file:clang=keyword=0).
 Because of these reasons I don't think it's worth keeping this builtin around.


>From fbc9ebb3900e69f2485111cfdc6b7a7dfd3e6ebe Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Tue, 16 Jul 2024 14:53:30 +0200
Subject: [PATCH] [Clang] Remove __is_nullptr

---
 clang/docs/LanguageExtensions.rst  |  4 
 clang/lib/Parse/ParseDeclCXX.cpp   |  5 ++---
 clang/lib/Parse/ParseExpr.cpp  |  1 -
 clang/lib/Sema/SemaExprCXX.cpp |  3 ---
 clang/test/SemaCXX/type-traits.cpp | 36 --
 5 files changed, 2 insertions(+), 47 deletions(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 81784c75081ba..cfd7d29fb9eac 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1614,10 +1614,6 @@ 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_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
-  ``__is_null_pointer`` is already in use by some implementations.
 * ``__is_object`` (C++, Embarcadero)
 * ``__is_pod`` (C++, GNU, Microsoft, Embarcadero):
   Note, the corresponding standard trait was deprecated in C++20.
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index ce827c689beb7..2c201d346328b 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -447,9 +447,9 @@ Decl *Parser::ParseLinkage(ParsingDeclSpec , 
DeclaratorContext Context) {
 ///
 /// HLSL: Parse export function declaration.
 ///
-///  export-function-declaration: 
+///  export-function-declaration:
 /// 'export' function-declaration
-/// 
+///
 ///  export-declaration-group:
 /// 'export' '{' function-declaration-seq[opt] '}'
 ///
@@ -1799,7 +1799,6 @@ void Parser::ParseClassSpecifier(tok::TokenKind 
TagTokKind,
   tok::kw___is_nothrow_constructible,
   tok::kw___is_nothrow_convertible,
   tok::kw___is_nothrow_destructible,
-  tok::kw___is_nullptr,
   tok::kw___is_object,
   tok::kw___is_pod,
   tok::kw___is_pointer,
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 3d7c58e5b3c3c..b3df9cfbc8b9a 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -800,7 +800,6 @@ bool Parser::isRevertibleTypeTrait(const IdentifierInfo *II,
 REVERTIBLE_TYPE_TRAIT(__is_nothrow_assignable);
 REVERTIBLE_TYPE_TRAIT(__is_nothrow_constructible);
 REVERTIBLE_TYPE_TRAIT(__is_nothrow_destructible);
-REVERTIBLE_TYPE_TRAIT(__is_nullptr);
 REVERTIBLE_TYPE_TRAIT(__is_object);
 REVERTIBLE_TYPE_TRAIT(__is_pod);
 REVERTIBLE_TYPE_TRAIT(__is_pointer);
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index bef7da239e6e5..a41b938531cab 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -4979,7 +4979,6 @@ static bool CheckUnaryTypeTraitTypeCompleteness(Sema , 
TypeTrait UTT,
   case UTT_IsArray:
   case UTT_IsBoundedArray:
   case UTT_IsPointer:
-  case UTT_IsNullPointer:
   case UTT_IsReferenceable:
   case UTT_IsLvalueReference:
   case UTT_IsRvalueReference:
@@ -5235,8 +5234,6 @@ static bool EvaluateUnaryTypeTrait(Sema , TypeTrait 
UTT,
 return T->isIncompleteArrayType();
   case UTT_IsPointer:
 return T->isAnyPointerType();
-  case UTT_IsNullPointer:
-return T->isNullPtrType();
   case UTT_IsLvalueReference:
 return T->isLValueReferenceType();
   case UTT_IsRvalueReference:
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index 7adbf4aad7afe..b38e8989cb559 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -1041,42 +1041,6 @@ void is_pointer()
   static_assert(!__is_pointer(void (StructWithMembers::*) ()));
 }
 
-void is_null_pointer() {
-  StructWithMembers x;
-
-  static_assert(__is_nullptr(decltype(nullptr)));
-  static_assert(!__is_nullptr(void *));
-  static_assert(!__is_nullptr(cvoid *));
-  static_assert(!__is_nullptr(cvoid *));
-  static_assert(!__is_nullptr(char *));
-  static_assert(!__is_nullptr(int *));
-  static_assert(!__is_nullptr(int **));
-  static_assert(!__is_nullptr(ClassType *));
-  

[clang] [clang-tools-extra] [clang] Extend diagnose_if to accept more detailed warning information (PR #70976)

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

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

>From a91f499900d4cea4804833d004b6c4e54a7d8b15 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Sun, 3 Sep 2023 17:26:28 -0700
Subject: [PATCH 1/7] [clang] Extend diagnose_if to accept more detailed
 warning information

---
 .../clang-tidy/ClangTidyDiagnosticConsumer.h  |   4 +
 clang-tools-extra/clangd/Diagnostics.cpp  |   6 +-
 clang-tools-extra/clangd/ParsedAST.cpp|   2 +-
 clang/include/clang/Basic/Attr.td |  13 +-
 clang/include/clang/Basic/Diagnostic.h|   9 +-
 .../clang/Basic/DiagnosticCategories.h|   1 +
 clang/include/clang/Basic/DiagnosticIDs.h | 106 ++--
 .../clang/Basic/DiagnosticSemaKinds.td|   6 +
 clang/lib/Basic/Diagnostic.cpp|  15 +-
 clang/lib/Basic/DiagnosticIDs.cpp | 232 ++
 clang/lib/Frontend/LogDiagnosticPrinter.cpp   |   4 +-
 .../Frontend/SerializedDiagnosticPrinter.cpp  |   3 +-
 clang/lib/Frontend/TextDiagnosticPrinter.cpp  |   8 +-
 clang/lib/Sema/Sema.cpp   |   4 +-
 clang/lib/Sema/SemaCUDA.cpp   |   4 +-
 clang/lib/Sema/SemaDeclAttr.cpp   |  22 +-
 clang/lib/Sema/SemaOverload.cpp   |  24 +-
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |   3 +-
 clang/lib/Serialization/ASTReader.cpp |   2 +-
 clang/lib/Serialization/ASTWriter.cpp |   2 +-
 .../SemaCXX/diagnose_if-warning-group.cpp |  35 +++
 clang/tools/diagtool/ListWarnings.cpp |   7 +-
 clang/tools/diagtool/ShowEnabledWarnings.cpp  |   6 +-
 clang/tools/libclang/CXStoredDiagnostic.cpp   |  15 +-
 24 files changed, 353 insertions(+), 180 deletions(-)
 create mode 100644 clang/test/SemaCXX/diagnose_if-warning-group.cpp

diff --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h 
b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
index 9280eb1e1f218..c7694ad05f03e 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
@@ -79,6 +79,10 @@ class ClangTidyContext {
 this->DiagEngine = DiagEngine;
   }
 
+  const DiagnosticsEngine* getDiagnosticsEngine() const {
+return DiagEngine;
+  }
+
   ~ClangTidyContext();
 
   /// Report any errors detected using this method.
diff --git a/clang-tools-extra/clangd/Diagnostics.cpp 
b/clang-tools-extra/clangd/Diagnostics.cpp
index 704e61b1e4dd7..0962fd971342f 100644
--- a/clang-tools-extra/clangd/Diagnostics.cpp
+++ b/clang-tools-extra/clangd/Diagnostics.cpp
@@ -579,7 +579,9 @@ std::vector StoreDiags::take(const 
clang::tidy::ClangTidyContext *Tidy) {
   for (auto  : Output) {
 if (const char *ClangDiag = getDiagnosticCode(Diag.ID)) {
   // Warnings controlled by -Wfoo are better recognized by that name.
-  StringRef Warning = DiagnosticIDs::getWarningOptionForDiag(Diag.ID);
+  StringRef Warning = Tidy->getDiagnosticsEngine()
+  ->getDiagnosticIDs()
+  ->getWarningOptionForDiag(Diag.ID);
   if (!Warning.empty()) {
 Diag.Name = ("-W" + Warning).str();
   } else {
@@ -909,7 +911,7 @@ bool isBuiltinDiagnosticSuppressed(unsigned ID,
 if (Suppress.contains(normalizeSuppressedCode(CodePtr)))
   return true;
   }
-  StringRef Warning = DiagnosticIDs::getWarningOptionForDiag(ID);
+  StringRef Warning = DiagnosticIDs{}.getWarningOptionForDiag(ID);
   if (!Warning.empty() && Suppress.contains(Warning))
 return true;
   return false;
diff --git a/clang-tools-extra/clangd/ParsedAST.cpp 
b/clang-tools-extra/clangd/ParsedAST.cpp
index edd0f77b1031e..57d21fa271179 100644
--- a/clang-tools-extra/clangd/ParsedAST.cpp
+++ b/clang-tools-extra/clangd/ParsedAST.cpp
@@ -340,7 +340,7 @@ void applyWarningOptions(llvm::ArrayRef 
ExtraArgs,
   if (Enable) {
 if (Diags.getDiagnosticLevel(ID, SourceLocation()) <
 DiagnosticsEngine::Warning) {
-  auto Group = DiagnosticIDs::getGroupForDiag(ID);
+  auto Group = Diags.getDiagnosticIDs()->getGroupForDiag(ID);
   if (!Group || !EnabledGroups(*Group))
 continue;
   Diags.setSeverity(ID, diag::Severity::Warning, SourceLocation());
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 25231c5b82b90..e08b7720508d4 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2959,18 +2959,15 @@ def DiagnoseIf : InheritableAttr {
   let Spellings = [GNU<"diagnose_if">];
   let Subjects = SubjectList<[Function, ObjCMethod, ObjCProperty]>;
   let Args = [ExprArgument<"Cond">, StringArgument<"Message">,
-  EnumArgument<"DiagnosticType",
-   "DiagnosticType",
-   ["error", "warning"],
-   ["DT_Error", "DT_Warning"]>,
+  EnumArgument<"DefaultSeverity",
+   

[clang] [clang-tools-extra] [clang] Extend diagnose_if to accept more detailed warning information (PR #70976)

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


@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 %s -verify -fno-builtin -Werror=comment -Wno-error=abi 
-Wfatal-errors=assume -Wno-fatal-errors=assume
+
+#define diagnose_if(...) __attribute__((diagnose_if(__VA_ARGS__)))
+
+template 
+void diagnose_if_wcomma() diagnose_if(b, "oh no", "warning", "comma") {}
+
+template 
+void diagnose_if_wcomment() diagnose_if(b, "oh no", "warning", "comment") {}
+
+void bougus_warning() diagnose_if(true, "oh no", "warning", "bougus warning") 
{} // expected-error {{unknown warning group}}
+
+void show_in_system_header() diagnose_if(true, "oh no", "warning", "assume", 
"Banane") {} // expected-error {{'diagnose_if' attribute takes no more than 4 
arguments}}
+
+
+void diagnose_if_wabi_default_error() diagnose_if(true, "ABI stuff", "error", 
"abi") {}
+void diagnose_assume() diagnose_if(true, "Assume diagnostic", "warning", 
"assume") {}
+
+void call() {
+  diagnose_if_wcomma(); // expected-warning {{oh no}}
+  diagnose_if_wcomma();
+  diagnose_if_wcomment(); // expected-error {{oh no}}
+  diagnose_if_wcomment();
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wcomma"
+  diagnose_if_wcomma();
+  diagnose_if_wcomment(); // expected-error {{oh no}}
+#pragma clang diagnostic pop
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wcomment"
+  diagnose_if_wcomma(); // expected-warning {{oh no}}
+  diagnose_if_wcomment();
+#pragma clang diagnostic pop
+
+  diagnose_if_wcomma(); // expected-warning {{oh no}}
+  diagnose_if_wcomment(); // expected-error {{oh no}}
+
+  diagnose_if_wabi_default_error(); // expected-warning {{ABI stuff}}
+  diagnose_assume(); // expected-error {{Assume diagnostic}}
+
+  // Make sure that the -Wassume diagnostic isn't fatal
+  diagnose_if_wabi_default_error(); // expected-warning {{ABI stuff}}
+}

philnik777 wrote:

I don't think `-Wpedantic` and `-pedantic` should be in any way different. It 
also feels very weird to say that we enable a `diagnose_if` that's in 
`-Wpedantic` only if we're passing `-Wpedantic`, but not if we're passing 
`-pedantic`, since `-pedantic` is just enabling all the warnings is 
`-Wpedantic` AFAICT. Because of https://godbolt.org/z/sK11rjxsa it's also kinda 
hard to add a test right now, since we don't have default ignore as an option 
currently.

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


[clang] [libcxx] [clang] [libc++] P3309 constexpr atomic and atomic ref [WIP] (PR #98738)

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

philnik777 wrote:

> @philnik777 I would rather not, at least for the review, manipulating two 
> branches will be cumbersome. I can split it before merging, but as I don't 
> expect this to happen soon, it should be fine.

This is less about having two separate commits than having mostly unrelated 
changes in separate PRs. It's "the llvm project", but it's really not a single 
project. The people reviewing the clang part don't know what to look for in 
libc++ and vice versa. You can use tools like 
https://github.com/spacedentist/spr to make it easier to manage a stacked PR if 
you want.

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


[clang] [libcxx] [clang] [libc++] P3309 constexpr atomic and atomic ref [WIP] (PR #98738)

2024-07-13 Thread Nikolas Klauser via cfe-commits
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= 
Message-ID:
In-Reply-To: 


philnik777 wrote:

Could you split this up into separate patches for the Clang and libc++ changes? 
The Clang changes can probably be landed independently of LWG, but for the 
libc++ changes we almost always wait until plenary approval (I'd be happy to 
give early feedback though).

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


[clang] Reapply "[Clang] Fix __is_trivially_equality_comparable returning true with ineligebile defaulted overloads" (#97002) (PR #97894)

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

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


[clang] [clang-tools-extra] [clang] Extend diagnose_if to accept more detailed warning information (PR #70976)

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


@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 %s -verify -fno-builtin -Werror=comment -Wno-error=abi 
-Wfatal-errors=assume -Wno-fatal-errors=assume
+
+#define diagnose_if(...) __attribute__((diagnose_if(__VA_ARGS__)))
+
+template 
+void diagnose_if_wcomma() diagnose_if(b, "oh no", "warning", "comma") {}
+
+template 
+void diagnose_if_wcomment() diagnose_if(b, "oh no", "warning", "comment") {}
+
+void bougus_warning() diagnose_if(true, "oh no", "warning", "bougus warning") 
{} // expected-error {{unknown warning group}}
+
+void show_in_system_header() diagnose_if(true, "oh no", "warning", "assume", 
"Banane") {} // expected-error {{'diagnose_if' attribute takes no more than 4 
arguments}}
+
+
+void diagnose_if_wabi_default_error() diagnose_if(true, "ABI stuff", "error", 
"abi") {}
+void diagnose_assume() diagnose_if(true, "Assume diagnostic", "warning", 
"assume") {}
+
+void call() {
+  diagnose_if_wcomma(); // expected-warning {{oh no}}
+  diagnose_if_wcomma();
+  diagnose_if_wcomment(); // expected-error {{oh no}}
+  diagnose_if_wcomment();
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wcomma"
+  diagnose_if_wcomma();
+  diagnose_if_wcomment(); // expected-error {{oh no}}
+#pragma clang diagnostic pop
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wcomment"
+  diagnose_if_wcomma(); // expected-warning {{oh no}}
+  diagnose_if_wcomment();
+#pragma clang diagnostic pop
+
+  diagnose_if_wcomma(); // expected-warning {{oh no}}
+  diagnose_if_wcomment(); // expected-error {{oh no}}
+
+  diagnose_if_wabi_default_error(); // expected-warning {{ABI stuff}}

philnik777 wrote:

If you don't give the attribute a warning group, it should still produce an 
error. With a warning group it's currently implemented as a warning that 
defaults to an error, since it doesn't seem to make a ton of sense to add a 
warning group but then ask for it to never be a warning.

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


[clang] [clang-tools-extra] [clang] Extend diagnose_if to accept more detailed warning information (PR #70976)

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

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


[clang] [clang-tools-extra] [clang] Extend diagnose_if to accept more detailed warning information (PR #70976)

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

https://github.com/philnik777 commented:

> Sorry for the delay in review!

No worries! I dropped this for a few months myself. I can't expect to get a 
review within days when doing that :D

> This seems like the right direction to go, in general. As @erichkeane, it's a 
> bit hard to review due to the whitespace-only changes and changes to 
> `__is_trivially_equality_comparable`, you should remove those changes or 
> split them into a separate PR.

Oops, looks like a commit got in here that was supposed to be part of another 
PR.

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


[clang] Reapply "[Clang] Fix __is_trivially_equality_comparable returning true with ineligebile defaulted overloads" (#97002) (PR #97894)

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

philnik777 wrote:

@cor3ntin The `S.CreateOverloadedBinOp` (line 5226) now gets a real location 
(the keyword location - seemed the most appropriate to me). The problem was 
that during overload resolution something got instantiated and that requires a 
real location. Although I'm not sure why that's the case. I've also added the 
test case
```c++
template 
class Template {};

// Make sure we don't crash when instantiating a type
static_assert(!__is_trivially_equality_comparable(Template>));
```
for that.


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


[clang] [clang-tools-extra] [clang] Extend diagnose_if to accept more detailed warning information (PR #70976)

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

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

>From a91f499900d4cea4804833d004b6c4e54a7d8b15 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Sun, 3 Sep 2023 17:26:28 -0700
Subject: [PATCH 1/5] [clang] Extend diagnose_if to accept more detailed
 warning information

---
 .../clang-tidy/ClangTidyDiagnosticConsumer.h  |   4 +
 clang-tools-extra/clangd/Diagnostics.cpp  |   6 +-
 clang-tools-extra/clangd/ParsedAST.cpp|   2 +-
 clang/include/clang/Basic/Attr.td |  13 +-
 clang/include/clang/Basic/Diagnostic.h|   9 +-
 .../clang/Basic/DiagnosticCategories.h|   1 +
 clang/include/clang/Basic/DiagnosticIDs.h | 106 ++--
 .../clang/Basic/DiagnosticSemaKinds.td|   6 +
 clang/lib/Basic/Diagnostic.cpp|  15 +-
 clang/lib/Basic/DiagnosticIDs.cpp | 232 ++
 clang/lib/Frontend/LogDiagnosticPrinter.cpp   |   4 +-
 .../Frontend/SerializedDiagnosticPrinter.cpp  |   3 +-
 clang/lib/Frontend/TextDiagnosticPrinter.cpp  |   8 +-
 clang/lib/Sema/Sema.cpp   |   4 +-
 clang/lib/Sema/SemaCUDA.cpp   |   4 +-
 clang/lib/Sema/SemaDeclAttr.cpp   |  22 +-
 clang/lib/Sema/SemaOverload.cpp   |  24 +-
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |   3 +-
 clang/lib/Serialization/ASTReader.cpp |   2 +-
 clang/lib/Serialization/ASTWriter.cpp |   2 +-
 .../SemaCXX/diagnose_if-warning-group.cpp |  35 +++
 clang/tools/diagtool/ListWarnings.cpp |   7 +-
 clang/tools/diagtool/ShowEnabledWarnings.cpp  |   6 +-
 clang/tools/libclang/CXStoredDiagnostic.cpp   |  15 +-
 24 files changed, 353 insertions(+), 180 deletions(-)
 create mode 100644 clang/test/SemaCXX/diagnose_if-warning-group.cpp

diff --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h 
b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
index 9280eb1e1f218d..c7694ad05f03e5 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
@@ -79,6 +79,10 @@ class ClangTidyContext {
 this->DiagEngine = DiagEngine;
   }
 
+  const DiagnosticsEngine* getDiagnosticsEngine() const {
+return DiagEngine;
+  }
+
   ~ClangTidyContext();
 
   /// Report any errors detected using this method.
diff --git a/clang-tools-extra/clangd/Diagnostics.cpp 
b/clang-tools-extra/clangd/Diagnostics.cpp
index 704e61b1e4dd79..0962fd971342fd 100644
--- a/clang-tools-extra/clangd/Diagnostics.cpp
+++ b/clang-tools-extra/clangd/Diagnostics.cpp
@@ -579,7 +579,9 @@ std::vector StoreDiags::take(const 
clang::tidy::ClangTidyContext *Tidy) {
   for (auto  : Output) {
 if (const char *ClangDiag = getDiagnosticCode(Diag.ID)) {
   // Warnings controlled by -Wfoo are better recognized by that name.
-  StringRef Warning = DiagnosticIDs::getWarningOptionForDiag(Diag.ID);
+  StringRef Warning = Tidy->getDiagnosticsEngine()
+  ->getDiagnosticIDs()
+  ->getWarningOptionForDiag(Diag.ID);
   if (!Warning.empty()) {
 Diag.Name = ("-W" + Warning).str();
   } else {
@@ -909,7 +911,7 @@ bool isBuiltinDiagnosticSuppressed(unsigned ID,
 if (Suppress.contains(normalizeSuppressedCode(CodePtr)))
   return true;
   }
-  StringRef Warning = DiagnosticIDs::getWarningOptionForDiag(ID);
+  StringRef Warning = DiagnosticIDs{}.getWarningOptionForDiag(ID);
   if (!Warning.empty() && Suppress.contains(Warning))
 return true;
   return false;
diff --git a/clang-tools-extra/clangd/ParsedAST.cpp 
b/clang-tools-extra/clangd/ParsedAST.cpp
index edd0f77b1031ef..57d21fa2711793 100644
--- a/clang-tools-extra/clangd/ParsedAST.cpp
+++ b/clang-tools-extra/clangd/ParsedAST.cpp
@@ -340,7 +340,7 @@ void applyWarningOptions(llvm::ArrayRef 
ExtraArgs,
   if (Enable) {
 if (Diags.getDiagnosticLevel(ID, SourceLocation()) <
 DiagnosticsEngine::Warning) {
-  auto Group = DiagnosticIDs::getGroupForDiag(ID);
+  auto Group = Diags.getDiagnosticIDs()->getGroupForDiag(ID);
   if (!Group || !EnabledGroups(*Group))
 continue;
   Diags.setSeverity(ID, diag::Severity::Warning, SourceLocation());
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 25231c5b82b907..e08b7720508d40 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2959,18 +2959,15 @@ def DiagnoseIf : InheritableAttr {
   let Spellings = [GNU<"diagnose_if">];
   let Subjects = SubjectList<[Function, ObjCMethod, ObjCProperty]>;
   let Args = [ExprArgument<"Cond">, StringArgument<"Message">,
-  EnumArgument<"DiagnosticType",
-   "DiagnosticType",
-   ["error", "warning"],
-   ["DT_Error", "DT_Warning"]>,
+  EnumArgument<"DefaultSeverity",
+   

[clang] Reapply "[Clang] Fix __is_trivially_equality_comparable returning true with ineligebile defaulted overloads" (#97002) (PR #97894)

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

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

This reverts commit 567b2c608c307c097315dd5ec4d6a5bbcddf898d.


>From 43b1972a867bf9fa16fdf0d93dcbca4deae9fd13 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Sat, 29 Jun 2024 21:51:02 +0200
Subject: [PATCH] Reapply "[Clang] Fix __is_trivially_equality_comparable
 returning true with ineligebile defaulted overloads" (#97002)

This reverts commit 567b2c608c307c097315dd5ec4d6a5bbcddf898d.
---
 clang/docs/ReleaseNotes.rst|  5 +-
 clang/include/clang/AST/Type.h |  3 --
 clang/lib/AST/Type.cpp | 60 ---
 clang/lib/Sema/SemaExprCXX.cpp | 79 +-
 clang/test/SemaCXX/type-traits.cpp | 49 ++
 5 files changed, 131 insertions(+), 65 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index feba3c7ba8d779..5117b678b22210 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -104,7 +104,7 @@ ABI Changes in This Version
   ifuncs. Its purpose was to preserve backwards compatibility when the ".ifunc"
   suffix got removed from the name mangling. The alias interacts badly with
   GlobalOpt (see the issue #96197).
-  
+
 - Fixed Microsoft name mangling for auto non-type template arguments of pointer
   type for MSVC 1920+. This change resolves incompatibilities with code 
compiled
   by MSVC 1920+ but will introduce incompatibilities with code compiled by
@@ -740,6 +740,9 @@ Bug Fixes in This Version
   negatives where the analysis failed to detect unchecked access to guarded
   data.
 
+- ``__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 62836ec5c63125..a98899f7f4222c 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -1142,9 +1142,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 d8b885870de3ac..cc535aba4936e3 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2815,66 +2815,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(
-  

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

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

philnik777 wrote:

> > > > @ZequanWu I can't successfully build your reproducer with clang trunk. 
> > > > Would it be possible to provide the full test case or a fully reduced 
> > > > one?
> > > 
> > > 
> > > Because I reverted this change at 
> > > [567b2c6](https://github.com/llvm/llvm-project/commit/567b2c608c307c097315dd5ec4d6a5bbcddf898d),
> > >  so it no longer crashes. If you recommit this or checkout to 
> > > [5b36348](https://github.com/llvm/llvm-project/commit/5b363483cf2461617fbb2449491c9914811c8d53),
> > >  you can repro the crash.
> > 
> > 
> > No, I mean it isn't a well-formed program. There are semicolons missing 
> > after class definitions.
> 
> That's caused by creduce but it shouldn't matter (clang shouldn't crash due 
> to syntax errors). I attached the original crash source here as creduce is 
> still running. The command to repro is same as above. 
> [rtp_transmission_manager-8cce12.txt](https://github.com/user-attachments/files/16041931/rtp_transmission_manager-8cce12.txt)

Yes, but it's a lot easier to reduce a file without errors, at least for me. 
(And FWIW I'd also question reverting a bug fix that could result into bad code 
gen because of a crash-on-invalid it introduced)

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-06-29 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

> > @ZequanWu I can't successfully build your reproducer with clang trunk. 
> > Would it be possible to provide the full test case or a fully reduced one?
> 
> Because I reverted this change at 
> [567b2c6](https://github.com/llvm/llvm-project/commit/567b2c608c307c097315dd5ec4d6a5bbcddf898d),
>  so it no longer crashes. If you recommit this or checkout to 
> [5b36348](https://github.com/llvm/llvm-project/commit/5b363483cf2461617fbb2449491c9914811c8d53),
>  you can repro the crash.

No, I mean it isn't a well-formed program. There are semicolons missing after 
class definitions.

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-tools-extra] [clang] Extend diagnose_if to accept more detailed warning information (PR #70976)

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

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

>From a91f499900d4cea4804833d004b6c4e54a7d8b15 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Sun, 3 Sep 2023 17:26:28 -0700
Subject: [PATCH 1/3] [clang] Extend diagnose_if to accept more detailed
 warning information

---
 .../clang-tidy/ClangTidyDiagnosticConsumer.h  |   4 +
 clang-tools-extra/clangd/Diagnostics.cpp  |   6 +-
 clang-tools-extra/clangd/ParsedAST.cpp|   2 +-
 clang/include/clang/Basic/Attr.td |  13 +-
 clang/include/clang/Basic/Diagnostic.h|   9 +-
 .../clang/Basic/DiagnosticCategories.h|   1 +
 clang/include/clang/Basic/DiagnosticIDs.h | 106 ++--
 .../clang/Basic/DiagnosticSemaKinds.td|   6 +
 clang/lib/Basic/Diagnostic.cpp|  15 +-
 clang/lib/Basic/DiagnosticIDs.cpp | 232 ++
 clang/lib/Frontend/LogDiagnosticPrinter.cpp   |   4 +-
 .../Frontend/SerializedDiagnosticPrinter.cpp  |   3 +-
 clang/lib/Frontend/TextDiagnosticPrinter.cpp  |   8 +-
 clang/lib/Sema/Sema.cpp   |   4 +-
 clang/lib/Sema/SemaCUDA.cpp   |   4 +-
 clang/lib/Sema/SemaDeclAttr.cpp   |  22 +-
 clang/lib/Sema/SemaOverload.cpp   |  24 +-
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |   3 +-
 clang/lib/Serialization/ASTReader.cpp |   2 +-
 clang/lib/Serialization/ASTWriter.cpp |   2 +-
 .../SemaCXX/diagnose_if-warning-group.cpp |  35 +++
 clang/tools/diagtool/ListWarnings.cpp |   7 +-
 clang/tools/diagtool/ShowEnabledWarnings.cpp  |   6 +-
 clang/tools/libclang/CXStoredDiagnostic.cpp   |  15 +-
 24 files changed, 353 insertions(+), 180 deletions(-)
 create mode 100644 clang/test/SemaCXX/diagnose_if-warning-group.cpp

diff --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h 
b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
index 9280eb1e1f218..c7694ad05f03e 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
@@ -79,6 +79,10 @@ class ClangTidyContext {
 this->DiagEngine = DiagEngine;
   }
 
+  const DiagnosticsEngine* getDiagnosticsEngine() const {
+return DiagEngine;
+  }
+
   ~ClangTidyContext();
 
   /// Report any errors detected using this method.
diff --git a/clang-tools-extra/clangd/Diagnostics.cpp 
b/clang-tools-extra/clangd/Diagnostics.cpp
index 704e61b1e4dd7..0962fd971342f 100644
--- a/clang-tools-extra/clangd/Diagnostics.cpp
+++ b/clang-tools-extra/clangd/Diagnostics.cpp
@@ -579,7 +579,9 @@ std::vector StoreDiags::take(const 
clang::tidy::ClangTidyContext *Tidy) {
   for (auto  : Output) {
 if (const char *ClangDiag = getDiagnosticCode(Diag.ID)) {
   // Warnings controlled by -Wfoo are better recognized by that name.
-  StringRef Warning = DiagnosticIDs::getWarningOptionForDiag(Diag.ID);
+  StringRef Warning = Tidy->getDiagnosticsEngine()
+  ->getDiagnosticIDs()
+  ->getWarningOptionForDiag(Diag.ID);
   if (!Warning.empty()) {
 Diag.Name = ("-W" + Warning).str();
   } else {
@@ -909,7 +911,7 @@ bool isBuiltinDiagnosticSuppressed(unsigned ID,
 if (Suppress.contains(normalizeSuppressedCode(CodePtr)))
   return true;
   }
-  StringRef Warning = DiagnosticIDs::getWarningOptionForDiag(ID);
+  StringRef Warning = DiagnosticIDs{}.getWarningOptionForDiag(ID);
   if (!Warning.empty() && Suppress.contains(Warning))
 return true;
   return false;
diff --git a/clang-tools-extra/clangd/ParsedAST.cpp 
b/clang-tools-extra/clangd/ParsedAST.cpp
index edd0f77b1031e..57d21fa271179 100644
--- a/clang-tools-extra/clangd/ParsedAST.cpp
+++ b/clang-tools-extra/clangd/ParsedAST.cpp
@@ -340,7 +340,7 @@ void applyWarningOptions(llvm::ArrayRef 
ExtraArgs,
   if (Enable) {
 if (Diags.getDiagnosticLevel(ID, SourceLocation()) <
 DiagnosticsEngine::Warning) {
-  auto Group = DiagnosticIDs::getGroupForDiag(ID);
+  auto Group = Diags.getDiagnosticIDs()->getGroupForDiag(ID);
   if (!Group || !EnabledGroups(*Group))
 continue;
   Diags.setSeverity(ID, diag::Severity::Warning, SourceLocation());
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 25231c5b82b90..e08b7720508d4 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2959,18 +2959,15 @@ def DiagnoseIf : InheritableAttr {
   let Spellings = [GNU<"diagnose_if">];
   let Subjects = SubjectList<[Function, ObjCMethod, ObjCProperty]>;
   let Args = [ExprArgument<"Cond">, StringArgument<"Message">,
-  EnumArgument<"DiagnosticType",
-   "DiagnosticType",
-   ["error", "warning"],
-   ["DT_Error", "DT_Warning"]>,
+  EnumArgument<"DefaultSeverity",
+   

[clang] [clang-tools-extra] [clang] Extend diagnose_if to accept more detailed warning information (PR #70976)

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

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

>From a91f499900d4cea4804833d004b6c4e54a7d8b15 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Sun, 3 Sep 2023 17:26:28 -0700
Subject: [PATCH 1/2] [clang] Extend diagnose_if to accept more detailed
 warning information

---
 .../clang-tidy/ClangTidyDiagnosticConsumer.h  |   4 +
 clang-tools-extra/clangd/Diagnostics.cpp  |   6 +-
 clang-tools-extra/clangd/ParsedAST.cpp|   2 +-
 clang/include/clang/Basic/Attr.td |  13 +-
 clang/include/clang/Basic/Diagnostic.h|   9 +-
 .../clang/Basic/DiagnosticCategories.h|   1 +
 clang/include/clang/Basic/DiagnosticIDs.h | 106 ++--
 .../clang/Basic/DiagnosticSemaKinds.td|   6 +
 clang/lib/Basic/Diagnostic.cpp|  15 +-
 clang/lib/Basic/DiagnosticIDs.cpp | 232 ++
 clang/lib/Frontend/LogDiagnosticPrinter.cpp   |   4 +-
 .../Frontend/SerializedDiagnosticPrinter.cpp  |   3 +-
 clang/lib/Frontend/TextDiagnosticPrinter.cpp  |   8 +-
 clang/lib/Sema/Sema.cpp   |   4 +-
 clang/lib/Sema/SemaCUDA.cpp   |   4 +-
 clang/lib/Sema/SemaDeclAttr.cpp   |  22 +-
 clang/lib/Sema/SemaOverload.cpp   |  24 +-
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |   3 +-
 clang/lib/Serialization/ASTReader.cpp |   2 +-
 clang/lib/Serialization/ASTWriter.cpp |   2 +-
 .../SemaCXX/diagnose_if-warning-group.cpp |  35 +++
 clang/tools/diagtool/ListWarnings.cpp |   7 +-
 clang/tools/diagtool/ShowEnabledWarnings.cpp  |   6 +-
 clang/tools/libclang/CXStoredDiagnostic.cpp   |  15 +-
 24 files changed, 353 insertions(+), 180 deletions(-)
 create mode 100644 clang/test/SemaCXX/diagnose_if-warning-group.cpp

diff --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h 
b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
index 9280eb1e1f218..c7694ad05f03e 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
@@ -79,6 +79,10 @@ class ClangTidyContext {
 this->DiagEngine = DiagEngine;
   }
 
+  const DiagnosticsEngine* getDiagnosticsEngine() const {
+return DiagEngine;
+  }
+
   ~ClangTidyContext();
 
   /// Report any errors detected using this method.
diff --git a/clang-tools-extra/clangd/Diagnostics.cpp 
b/clang-tools-extra/clangd/Diagnostics.cpp
index 704e61b1e4dd7..0962fd971342f 100644
--- a/clang-tools-extra/clangd/Diagnostics.cpp
+++ b/clang-tools-extra/clangd/Diagnostics.cpp
@@ -579,7 +579,9 @@ std::vector StoreDiags::take(const 
clang::tidy::ClangTidyContext *Tidy) {
   for (auto  : Output) {
 if (const char *ClangDiag = getDiagnosticCode(Diag.ID)) {
   // Warnings controlled by -Wfoo are better recognized by that name.
-  StringRef Warning = DiagnosticIDs::getWarningOptionForDiag(Diag.ID);
+  StringRef Warning = Tidy->getDiagnosticsEngine()
+  ->getDiagnosticIDs()
+  ->getWarningOptionForDiag(Diag.ID);
   if (!Warning.empty()) {
 Diag.Name = ("-W" + Warning).str();
   } else {
@@ -909,7 +911,7 @@ bool isBuiltinDiagnosticSuppressed(unsigned ID,
 if (Suppress.contains(normalizeSuppressedCode(CodePtr)))
   return true;
   }
-  StringRef Warning = DiagnosticIDs::getWarningOptionForDiag(ID);
+  StringRef Warning = DiagnosticIDs{}.getWarningOptionForDiag(ID);
   if (!Warning.empty() && Suppress.contains(Warning))
 return true;
   return false;
diff --git a/clang-tools-extra/clangd/ParsedAST.cpp 
b/clang-tools-extra/clangd/ParsedAST.cpp
index edd0f77b1031e..57d21fa271179 100644
--- a/clang-tools-extra/clangd/ParsedAST.cpp
+++ b/clang-tools-extra/clangd/ParsedAST.cpp
@@ -340,7 +340,7 @@ void applyWarningOptions(llvm::ArrayRef 
ExtraArgs,
   if (Enable) {
 if (Diags.getDiagnosticLevel(ID, SourceLocation()) <
 DiagnosticsEngine::Warning) {
-  auto Group = DiagnosticIDs::getGroupForDiag(ID);
+  auto Group = Diags.getDiagnosticIDs()->getGroupForDiag(ID);
   if (!Group || !EnabledGroups(*Group))
 continue;
   Diags.setSeverity(ID, diag::Severity::Warning, SourceLocation());
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 25231c5b82b90..e08b7720508d4 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2959,18 +2959,15 @@ def DiagnoseIf : InheritableAttr {
   let Spellings = [GNU<"diagnose_if">];
   let Subjects = SubjectList<[Function, ObjCMethod, ObjCProperty]>;
   let Args = [ExprArgument<"Cond">, StringArgument<"Message">,
-  EnumArgument<"DiagnosticType",
-   "DiagnosticType",
-   ["error", "warning"],
-   ["DT_Error", "DT_Warning"]>,
+  EnumArgument<"DefaultSeverity",
+   

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

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

philnik777 wrote:

@ZequanWu I can't successfully build your reproducer with clang trunk. Would it 
be possible to provide the full test case or a fully reduced one?

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-06-28 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

@ZequanWu Could you give me a reproducer? Ther CI failure looks pretty 
unrelated to me, since it complains about LeakSanitizer. The next build was 
also green.

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-06-27 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 closed 
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-06-27 Thread Nikolas Klauser via cfe-commits

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

>From 3998e9a8e130677f5932b744c0f4487861a54710 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|  5 +-
 clang/include/clang/AST/Type.h |  3 --
 clang/lib/AST/Type.cpp | 60 ---
 clang/lib/Sema/SemaExprCXX.cpp | 78 +-
 clang/test/SemaCXX/type-traits.cpp | 43 
 5 files changed, 124 insertions(+), 65 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index da967fcdda808..7ebfc87144269 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -104,7 +104,7 @@ ABI Changes in This Version
   ifuncs. Its purpose was to preserve backwards compatibility when the ".ifunc"
   suffix got removed from the name mangling. The alias interacts badly with
   GlobalOpt (see the issue #96197).
-  
+
 - Fixed Microsoft name mangling for auto non-type template arguments of pointer
   type for MSVC 1920+. This change resolves incompatibilities with code 
compiled
   by MSVC 1920+ but will introduce incompatibilities with code compiled by
@@ -740,6 +740,9 @@ Bug Fixes in This Version
   negatives where the analysis failed to detect unchecked access to guarded
   data.
 
+- ``__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 62836ec5c6312..a98899f7f4222 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -1142,9 +1142,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 d8b885870de3a..cc535aba4936e 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2815,66 +2815,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 

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

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


@@ -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;

philnik777 wrote:

Always happy to do that!

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] [TBAA] Emit distinct TBAA tags for pointers with different depths,types. (PR #76612)

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


@@ -392,6 +392,10 @@ Non-comprehensive list of changes in this release
 - ``#pragma GCC diagnostic warning "-Wfoo"`` can now downgrade ``-Werror=foo``
   errors and certain default-to-error ``-W`` diagnostics to warnings.
 
+- Clang now emits distinct type-based alias analysis tags for incompatible
+  pointers, enabling more powerful alias analysis when accessing pointer types.
+  The new behavior can be disabledusing ``-fno-pointer-tbaa``.

philnik777 wrote:

```suggestion
  The new behavior can be disabled using ``-fno-pointer-tbaa``.
```

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


[clang] [TBAA] Emit distinct TBAA tags for pointers with different depths,types. (PR #76612)

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

https://github.com/philnik777 commented:

First of all I want to say that this is a really cool project, especially the 
type sanitizer part. Thanks for working on this!

> Just updated the tysan branches again. Unfortunately we aren't yet at a point 
> where LLVM is `tysan` clean, there is a large number of reported violations 
> when running the tblgen built with `tysan` even without this patch. I'd 
> expect that a substantial amount of work is still needed to get to a state 
> where we can build LLVM successfully with tysan.

Given that not even LLVM itself is clean (which has probably some of the 
densest population of compiler engineers), and you say that this will require a 
significant amount of work, would it maybe make sense to have this 
off-by-default for now and only enable it in a year or so by default? 
Especially if there are problems in any system libraries, like libc++, it would 
be rather unfortunate, since users can't do much about it. 

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


[clang] [TBAA] Emit distinct TBAA tags for pointers with different depths,types. (PR #76612)

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

https://github.com/philnik777 edited 
https://github.com/llvm/llvm-project/pull/76612
___
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-06-27 Thread Nikolas Klauser via cfe-commits


@@ -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;

philnik777 wrote:

Hmm. I'm not sure the is much use to "this is definitely not trivially equality 
comparable". Right now I think I'd rather just keep it in `SemaExprCXX`. If 
there comes up a use-case or we want to save some of the information we can 
still move some info into `Type`.

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-06-27 Thread Nikolas Klauser via cfe-commits


@@ -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;

philnik777 wrote:

We're not actually storing any infomation for 
`__is_trivially_equaltiy_comparable`, so I'm not sure what the benefit would 
be? If we ever do that we can of course split things up to say "this definitely 
isn't trivially equaility comparable".


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-06-27 Thread Nikolas Klauser via cfe-commits


@@ -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;

philnik777 wrote:

The main problem with this is that you don't have to have a member. Take this 
test case for example:
```c++
struct NotTriviallyEqualityComparableMoreConstrainedExternalOp {
  int i;
  bool operator==(const 
NotTriviallyEqualityComparableMoreConstrainedExternalOp&) const = default;
};

bool operator==(const NotTriviallyEqualityComparableMoreConstrainedExternalOp&,
const NotTriviallyEqualityComparableMoreConstrainedExternalOp&) 
__attribute__((enable_if(true, ""))) {}

static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableMoreConstrainedExternalOp));
```
I'm sure this can also be written with some `requires` clause. Without the 
builtin telling the library there is no way to figure out that a free function 
instead of the member is called.


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: Support minimumnum and maximumnum intrinsics (PR #96281)

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


@@ -3636,6 +3648,22 @@ def Fmin : FPMathTemplate, LibBuiltin<"math.h"> {
   let OnlyBuiltinPrefixedAliasIsConstexpr = 1;
 }
 
+def FmaximumNum : FPMathTemplate, LibBuiltin<"math.h"> {

philnik777 wrote:

In that case this should probably be a `GNULibBuiltin`. Or is it actually 
standardized?

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


[clang] Clang: Support minimumnum and maximumnum intrinsics (PR #96281)

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


@@ -3636,6 +3648,22 @@ def Fmin : FPMathTemplate, LibBuiltin<"math.h"> {
   let OnlyBuiltinPrefixedAliasIsConstexpr = 1;
 }
 
+def FmaximumNum : FPMathTemplate, LibBuiltin<"math.h"> {

philnik777 wrote:

Why is this a libbuiltin? IIUC this is only supposed to be an intrinsic, never 
alibrary function.

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


[clang] [Clang][NFC] Avoid opening namespace std (PR #95470)

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

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


[clang] [Clang][NFC] Avoid opening namespace std (PR #95470)

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

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

>From ee78c1e22b81ef3beb4e28e4ea778ab3a80b1f2d Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Thu, 13 Jun 2024 22:24:17 +0200
Subject: [PATCH] [Clang] Avoid opening namespace std

---
 clang/include/clang/Format/Format.h| 4 +---
 clang/include/clang/Frontend/PrecompiledPreamble.h | 4 +---
 clang/include/clang/Frontend/SerializedDiagnosticReader.h  | 7 ++-
 .../Checkers/BlockInCriticalSectionChecker.cpp | 4 +---
 4 files changed, 5 insertions(+), 14 deletions(-)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index eb6647038403d..3900f6496f06a 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -5430,9 +5430,7 @@ bool isClangFormatOff(StringRef Comment);
 } // end namespace format
 } // end namespace clang
 
-namespace std {
 template <>
-struct is_error_code_enum : std::true_type {};
-} // namespace std
+struct std::is_error_code_enum : std::true_type {};
 
 #endif // LLVM_CLANG_FORMAT_FORMAT_H
diff --git a/clang/include/clang/Frontend/PrecompiledPreamble.h 
b/clang/include/clang/Frontend/PrecompiledPreamble.h
index 798870bf24fe1..624df004bf89e 100644
--- a/clang/include/clang/Frontend/PrecompiledPreamble.h
+++ b/clang/include/clang/Frontend/PrecompiledPreamble.h
@@ -256,9 +256,7 @@ class BuildPreambleErrorCategory final : public 
std::error_category {
 std::error_code make_error_code(BuildPreambleError Error);
 } // namespace clang
 
-namespace std {
 template <>
-struct is_error_code_enum : std::true_type {};
-} // namespace std
+struct std::is_error_code_enum : std::true_type {};
 
 #endif
diff --git a/clang/include/clang/Frontend/SerializedDiagnosticReader.h 
b/clang/include/clang/Frontend/SerializedDiagnosticReader.h
index 309e0abb14613..f7c2012a7662a 100644
--- a/clang/include/clang/Frontend/SerializedDiagnosticReader.h
+++ b/clang/include/clang/Frontend/SerializedDiagnosticReader.h
@@ -128,11 +128,8 @@ class SerializedDiagnosticReader {
 } // namespace serialized_diags
 } // namespace clang
 
-namespace std {
-
 template <>
-struct is_error_code_enum : std::true_type 
{};
-
-} // namespace std
+struct std::is_error_code_enum
+: std::true_type {};
 
 #endif // LLVM_CLANG_FRONTEND_SERIALIZEDDIAGNOSTICREADER_H
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp
index 92347f8fafc00..40f7e9cede1f1 100644
--- a/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp
@@ -202,13 +202,12 @@ class BlockInCriticalSectionChecker : public 
Checker {
 
 REGISTER_LIST_WITH_PROGRAMSTATE(ActiveCritSections, CritSectionMarker)
 
-namespace std {
 // Iterator traits for ImmutableList data structure
 // that enable the use of STL algorithms.
 // TODO: Move these to llvm::ImmutableList when overhauling immutable data
 // structures for proper iterator concept support.
 template <>
-struct iterator_traits<
+struct std::iterator_traits<
 typename llvm::ImmutableList::iterator> {
   using iterator_category = std::forward_iterator_tag;
   using value_type = CritSectionMarker;
@@ -216,7 +215,6 @@ struct iterator_traits<
   using reference = CritSectionMarker &;
   using pointer = CritSectionMarker *;
 };
-} // namespace std
 
 std::optional
 BlockInCriticalSectionChecker::checkDescriptorMatch(const CallEvent ,

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


[clang] [Clang][NFC] Avoid opening namespace std (PR #95470)

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

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

Never opening `namespace std` avoids even the possibility of introducing new 
symbols as well as making the code a bit shorter by removing unnecessary boiler 
plate.



>From f5fc162cd1a6fdef3dcdc3e4c73aedcf67b603df Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Thu, 13 Jun 2024 22:24:17 +0200
Subject: [PATCH] [Clang] Avoid opening namespace std

---
 clang/include/clang/Format/Format.h | 4 +---
 clang/include/clang/Frontend/PrecompiledPreamble.h  | 4 +---
 clang/include/clang/Frontend/SerializedDiagnosticReader.h   | 6 +-
 .../Checkers/BlockInCriticalSectionChecker.cpp  | 4 +---
 4 files changed, 4 insertions(+), 14 deletions(-)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index eb6647038403d..3900f6496f06a 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -5430,9 +5430,7 @@ bool isClangFormatOff(StringRef Comment);
 } // end namespace format
 } // end namespace clang
 
-namespace std {
 template <>
-struct is_error_code_enum : std::true_type {};
-} // namespace std
+struct std::is_error_code_enum : std::true_type {};
 
 #endif // LLVM_CLANG_FORMAT_FORMAT_H
diff --git a/clang/include/clang/Frontend/PrecompiledPreamble.h 
b/clang/include/clang/Frontend/PrecompiledPreamble.h
index 798870bf24fe1..624df004bf89e 100644
--- a/clang/include/clang/Frontend/PrecompiledPreamble.h
+++ b/clang/include/clang/Frontend/PrecompiledPreamble.h
@@ -256,9 +256,7 @@ class BuildPreambleErrorCategory final : public 
std::error_category {
 std::error_code make_error_code(BuildPreambleError Error);
 } // namespace clang
 
-namespace std {
 template <>
-struct is_error_code_enum : std::true_type {};
-} // namespace std
+struct std::is_error_code_enum : std::true_type {};
 
 #endif
diff --git a/clang/include/clang/Frontend/SerializedDiagnosticReader.h 
b/clang/include/clang/Frontend/SerializedDiagnosticReader.h
index 309e0abb14613..96d576a63b9f2 100644
--- a/clang/include/clang/Frontend/SerializedDiagnosticReader.h
+++ b/clang/include/clang/Frontend/SerializedDiagnosticReader.h
@@ -128,11 +128,7 @@ class SerializedDiagnosticReader {
 } // namespace serialized_diags
 } // namespace clang
 
-namespace std {
-
 template <>
-struct is_error_code_enum : std::true_type 
{};
-
-} // namespace std
+struct std::is_error_code_enum : 
std::true_type {};
 
 #endif // LLVM_CLANG_FRONTEND_SERIALIZEDDIAGNOSTICREADER_H
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp
index 92347f8fafc00..40f7e9cede1f1 100644
--- a/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp
@@ -202,13 +202,12 @@ class BlockInCriticalSectionChecker : public 
Checker {
 
 REGISTER_LIST_WITH_PROGRAMSTATE(ActiveCritSections, CritSectionMarker)
 
-namespace std {
 // Iterator traits for ImmutableList data structure
 // that enable the use of STL algorithms.
 // TODO: Move these to llvm::ImmutableList when overhauling immutable data
 // structures for proper iterator concept support.
 template <>
-struct iterator_traits<
+struct std::iterator_traits<
 typename llvm::ImmutableList::iterator> {
   using iterator_category = std::forward_iterator_tag;
   using value_type = CritSectionMarker;
@@ -216,7 +215,6 @@ struct iterator_traits<
   using reference = CritSectionMarker &;
   using pointer = CritSectionMarker *;
 };
-} // namespace std
 
 std::optional
 BlockInCriticalSectionChecker::checkDescriptorMatch(const CallEvent ,

___
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-06-13 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

gentle ping

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] Add value_type attr, use it to add noalias when pass-by-value. (PR #95004)

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

philnik777 wrote:

This is really sweet. However, I feel like this is a property that needs to 
propagate through types. We can't guarantee that a `std::vector>` doesn't escape the pointer. Similarly, I think we'd 
like
```c++
struct my_pair {
  int i;
  std::string str;
};
```
to have this property.

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


[clang] [llvm] Enable LLDB tests in Linux pre-merge CI (PR #94208)

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

philnik777 wrote:

FYI in the libc++ CI we've been running the LLDB tests for a few months now and 
I haven't seen a single unrelated failure.

https://github.com/llvm/llvm-project/pull/94208
___
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-06-02 Thread Nikolas Klauser via cfe-commits

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

>From d1507bf2be71940c795925cdc8159cbc90b17f0d 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 | 78 +-
 clang/test/SemaCXX/type-traits.cpp | 43 
 5 files changed, 123 insertions(+), 64 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 22b4dc172c840..fabc0fdbcc551 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -640,6 +640,9 @@ Bug Fixes in This Version
 - Correctly reject declarations where a statement is required in C.
   Fixes #GH92775
 
+- ``__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 263b632df23ce..53d2ae2905a56 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 2097b29b7e0b6..6121612687f55 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2778,66 +2778,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 4487c618862c5..f4461ecf44a37 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5197,6 +5197,82 @@ static bool HasNoThrowOperator(const RecordType *RT, 
OverloadedOperatorKind Op,
   return false;
 }
 
+static bool
+HasNonDeletedDefaultedEqualityComparison(Sema , const CXXRecordDecl *Decl) {
+  if 

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

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

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

>From cabff5972424393e9d76bce4f8015ceed331a5f9 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 | 74 +-
 clang/test/SemaCXX/type-traits.cpp | 37 +++
 5 files changed, 113 insertions(+), 64 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 22b4dc172c840..fabc0fdbcc551 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -640,6 +640,9 @@ Bug Fixes in This Version
 - Correctly reject declarations where a statement is required in C.
   Fixes #GH92775
 
+- ``__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 263b632df23ce..53d2ae2905a56 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 2097b29b7e0b6..6121612687f55 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2778,66 +2778,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 4487c618862c5..d6be724d1cc2a 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5197,6 +5197,78 @@ static bool HasNoThrowOperator(const RecordType *RT, 
OverloadedOperatorKind Op,
   return false;
 }
 
+static bool
+HasNonDeletedDefaultedEqualityComparison(Sema , const CXXRecordDecl *Decl) {
+  if 

[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


  1   2   3   >