[PATCH] D121100: [clang][DebugInfo] clang should not generate DW_TAG_subprogram entry without DW_AT_name

2022-05-22 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok abandoned this revision.
alok added a comment.

GNU gdb is now modified to accept functions with linkage name.

  commit 6f9b09edaee43ea34d34b1998fe7b844834f251a
  Author: Alok Kumar Sharma 
  Date:   Sun May 22 21:46:06 2022 +0530


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121100

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


[clang] b86440e - [CSKY] Fix the conflict of default fpu features and -mfpu option

2022-05-22 Thread Zi Xuan Wu via cfe-commits

Author: Zi Xuan Wu (Zeson)
Date: 2022-05-23T10:44:55+08:00
New Revision: b86440ecde5c1dec5b898a3f1bc08ab9853d5ed9

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

LOG: [CSKY] Fix the conflict of default fpu features and -mfpu option

The arch or cpu has its default fpu features and versions such as 
fpuv2_sf/fpuv3_sf.
And there is also -mfpu option to specify and override fpu version and features.
For example, C860 has fpuv3_sf/fpuv3_df feature as default, when
-mfpu=fpv2 is given, fpuv3_sf/fpuv3_df is replaced with fpuv2_sf/fpuv2_df.

Added: 
clang/test/Driver/csky-mfpu.c

Modified: 
clang/lib/Basic/Targets/CSKY.cpp
clang/lib/Basic/Targets/CSKY.h
clang/lib/Driver/ToolChains/Arch/CSKY.cpp
llvm/lib/Support/CSKYTargetParser.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/CSKY.cpp 
b/clang/lib/Basic/Targets/CSKY.cpp
index 40004da982594..adcffd90ae780 100644
--- a/clang/lib/Basic/Targets/CSKY.cpp
+++ b/clang/lib/Basic/Targets/CSKY.cpp
@@ -95,17 +95,36 @@ void CSKYTargetInfo::getTargetDefines(const LangOptions 
,
   }
 }
 
+bool CSKYTargetInfo::hasFeature(StringRef Feature) const {
+  return llvm::StringSwitch(Feature)
+  .Case("hard-float", HardFloat)
+  .Case("hard-float-abi", HardFloatABI)
+  .Case("fpuv2_sf", FPUV2_SF)
+  .Case("fpuv2_df", FPUV2_DF)
+  .Case("fpuv3_sf", FPUV3_SF)
+  .Case("fpuv3_df", FPUV3_DF)
+  .Case("vdspv2", VDSPV2)
+  .Case("dspv2", DSPV2)
+  .Case("vdspv1", VDSPV1)
+  .Case("3e3r1", is3E3R1)
+  .Default(false);
+}
+
 bool CSKYTargetInfo::handleTargetFeatures(std::vector ,
   DiagnosticsEngine ) {
-  HardFloat = false;
-  VDSPV2 = false;
-  VDSPV1 = false;
-  DSPV2 = false;
-  is3E3R1 = false;
-
   for (const auto  : Features) {
 if (Feature == "+hard-float")
   HardFloat = true;
+if (Feature == "+hard-float-abi")
+  HardFloatABI = true;
+if (Feature == "+fpuv2_sf")
+  FPUV2_SF = true;
+if (Feature == "+fpuv2_df")
+  FPUV2_DF = true;
+if (Feature == "+fpuv3_sf")
+  FPUV3_SF = true;
+if (Feature == "+fpuv3_df")
+  FPUV3_DF = true;
 if (Feature == "+vdspv2")
   VDSPV2 = true;
 if (Feature == "+dspv2")

diff  --git a/clang/lib/Basic/Targets/CSKY.h b/clang/lib/Basic/Targets/CSKY.h
index 17e5f30d3cd87..7e932e7c86b1c 100644
--- a/clang/lib/Basic/Targets/CSKY.h
+++ b/clang/lib/Basic/Targets/CSKY.h
@@ -26,11 +26,16 @@ class LLVM_LIBRARY_VISIBILITY CSKYTargetInfo : public 
TargetInfo {
   llvm::CSKY::ArchKind Arch = llvm::CSKY::ArchKind::INVALID;
   std::string CPU;
 
-  bool HardFloat;
-  bool VDSPV2;
-  bool VDSPV1;
-  bool DSPV2;
-  bool is3E3R1;
+  bool HardFloat = false;
+  bool HardFloatABI = false;
+  bool FPUV2_SF = false;
+  bool FPUV2_DF = false;
+  bool FPUV3_SF = false;
+  bool FPUV3_DF = false;
+  bool VDSPV2 = false;
+  bool VDSPV1 = false;
+  bool DSPV2 = false;
+  bool is3E3R1 = false;
 
 public:
   CSKYTargetInfo(const llvm::Triple , const TargetOptions )
@@ -81,6 +86,7 @@ class LLVM_LIBRARY_VISIBILITY CSKYTargetInfo : public 
TargetInfo {
 
   void getTargetDefines(const LangOptions ,
 MacroBuilder ) const override;
+  bool hasFeature(StringRef Feature) const override;
   bool handleTargetFeatures(std::vector ,
 DiagnosticsEngine ) override;
 

diff  --git a/clang/lib/Driver/ToolChains/Arch/CSKY.cpp 
b/clang/lib/Driver/ToolChains/Arch/CSKY.cpp
index fb809956afa80..3a8f927856092 100644
--- a/clang/lib/Driver/ToolChains/Arch/CSKY.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/CSKY.cpp
@@ -91,6 +91,22 @@ getCSKYFPUFeatures(const Driver , const Arg *A, const 
ArgList ,
   .Case("fpv3_hsf", llvm::CSKY::FK_FPV3_HSF)
   .Case("fpv3_sdf", llvm::CSKY::FK_FPV3_SDF)
   .Default(llvm::CSKY::FK_INVALID);
+  if (FPUID == llvm::CSKY::FK_INVALID) {
+D.Diag(clang::diag::err_drv_clang_unsupported) << A->getAsString(Args);
+return llvm::CSKY::FK_INVALID;
+  }
+
+  auto RemoveTargetFPUFeature =
+  [](ArrayRef FPUFeatures) {
+for (auto FPUFeature : FPUFeatures) {
+  auto it = std::find(Features.begin(), Features.end(), FPUFeature);
+  if (it != Features.end())
+Features.erase(it);
+}
+  };
+
+  RemoveTargetFPUFeature({"+fpuv2_sf", "+fpuv2_df", "+fdivdu", "+fpuv3_hi",
+  "+fpuv3_hf", "+fpuv3_sf", "+fpuv3_df"});
 
   if (!llvm::CSKY::getFPUFeatures(FPUID, Features)) {
 D.Diag(clang::diag::err_drv_clang_unsupported) << A->getAsString(Args);
@@ -126,6 +142,8 @@ void csky::getCSKYTargetFeatures(const Driver , const 
llvm::Triple ,
   return;
 }
 cpuName = A->getValue();
+if (archName.empty())
+  archName = 

[PATCH] D126138: [clang-tidy] Fix #55134 (regression introduced by 5da7c04)

2022-05-22 Thread Paul Altin via Phabricator via cfe-commits
paulaltin added a comment.

In D126138#3530172 , @salman-javed-nz 
wrote:

> This fix is check-agnostic, so I don't think we need to add even more tests 
> than the two proposed here.

Yes, you're right; the issue itself is check-agnostic too, I just didn't 
realise that when I wrote the above comment (thanks to @nridge for explaining 
what's really going on).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126138

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


[PATCH] D126160: [Concepts] Add an error for unsupported P0848 (destructor overloading) code

2022-05-22 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson abandoned this revision.
royjacobson added a comment.

I continued hacking a bit at this and I think I got a working approach to 
implementing P0848 (down to 6 failing tests, will probably post at least a 
draft tomorrow). So I'll close for now. Maybe it's still useful for backporting 
if someone wants to. Sorry for all the mail spam from today...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126160

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


[PATCH] D126172: [clang] Fix comparison of TemplateArgument when they are of template kind

2022-05-22 Thread Robert Esclapez via Phabricator via cfe-commits
roberteg16 updated this revision to Diff 431264.
roberteg16 edited the summary of this revision.
roberteg16 added a comment.

Make clang-format not complain


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126172

Files:
  clang/lib/AST/TemplateBase.cpp
  clang/test/CXX/dcl/dcl.fct/p17.cpp


Index: clang/test/CXX/dcl/dcl.fct/p17.cpp
===
--- clang/test/CXX/dcl/dcl.fct/p17.cpp
+++ clang/test/CXX/dcl/dcl.fct/p17.cpp
@@ -257,4 +257,23 @@
   static_assert(is_same_v);
   // expected-error@-1{{no matching}}
   static_assert(is_same_v);
-}
+
+  // clang-format off
+  template  struct S3 {};
+  // expected-note@-1 {{'S3' declared here}}
+  // expected-note@-2 {{template is declared here}}
+  void f23(C2<::S3> auto);
+  // expected-error@-1 {{no template named 'S3' in the global namespace; did 
you mean simply 'S3'?}}
+  // expected-error@-2 {{use of class template '::S3' requires template 
arguments}}
+  // clang-format on
+} // namespace constrained
+
+template  struct S4 {};
+// expected-note@-1 {{template is declared here}}
+
+namespace constrained {
+// clang-format off
+void f24(C2<::S4> auto);
+// expected-error@-1 {{use of class template '::S4' requires template 
arguments}}
+// clang-format on
+} // namespace constrained
Index: clang/lib/AST/TemplateBase.cpp
===
--- clang/lib/AST/TemplateBase.cpp
+++ clang/lib/AST/TemplateBase.cpp
@@ -370,8 +370,8 @@
 
   case Template:
   case TemplateExpansion:
-return TemplateArg.Name == Other.TemplateArg.Name &&
-   TemplateArg.NumExpansions == Other.TemplateArg.NumExpansions;
+return getAsTemplateOrTemplatePattern().getAsTemplateDecl() ==
+   Other.getAsTemplateOrTemplatePattern().getAsTemplateDecl();
 
   case Declaration:
 return getAsDecl() == Other.getAsDecl();


Index: clang/test/CXX/dcl/dcl.fct/p17.cpp
===
--- clang/test/CXX/dcl/dcl.fct/p17.cpp
+++ clang/test/CXX/dcl/dcl.fct/p17.cpp
@@ -257,4 +257,23 @@
   static_assert(is_same_v);
   // expected-error@-1{{no matching}}
   static_assert(is_same_v);
-}
+
+  // clang-format off
+  template  struct S3 {};
+  // expected-note@-1 {{'S3' declared here}}
+  // expected-note@-2 {{template is declared here}}
+  void f23(C2<::S3> auto);
+  // expected-error@-1 {{no template named 'S3' in the global namespace; did you mean simply 'S3'?}}
+  // expected-error@-2 {{use of class template '::S3' requires template arguments}}
+  // clang-format on
+} // namespace constrained
+
+template  struct S4 {};
+// expected-note@-1 {{template is declared here}}
+
+namespace constrained {
+// clang-format off
+void f24(C2<::S4> auto);
+// expected-error@-1 {{use of class template '::S4' requires template arguments}}
+// clang-format on
+} // namespace constrained
Index: clang/lib/AST/TemplateBase.cpp
===
--- clang/lib/AST/TemplateBase.cpp
+++ clang/lib/AST/TemplateBase.cpp
@@ -370,8 +370,8 @@
 
   case Template:
   case TemplateExpansion:
-return TemplateArg.Name == Other.TemplateArg.Name &&
-   TemplateArg.NumExpansions == Other.TemplateArg.NumExpansions;
+return getAsTemplateOrTemplatePattern().getAsTemplateDecl() ==
+   Other.getAsTemplateOrTemplatePattern().getAsTemplateDecl();
 
   case Declaration:
 return getAsDecl() == Other.getAsDecl();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126160: [Concepts] Add an error for unsupported P0848 (destructor overloading) code

2022-05-22 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 431263.
royjacobson added a comment.

Fix conventions


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126160

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/over/over.match/over.match.viable/p3.cpp

Index: clang/test/CXX/over/over.match/over.match.viable/p3.cpp
===
--- clang/test/CXX/over/over.match/over.match.viable/p3.cpp
+++ clang/test/CXX/over/over.match/over.match.viable/p3.cpp
@@ -44,24 +44,26 @@
 
 template
 struct S {
+  // expected-error@-1  {{overloading destructors is not supported}}
   void foo(int) requires false;
   void foo(A) requires true;
   S(A) requires false;
   S(double) requires true;
   ~S() requires false;
   // expected-note@-1 2{{because 'false' evaluated to false}}
+  // expected-note@-2 {{destructor declared here}}
   ~S() requires true;
+  // expected-note@-1 {{destructor declared here}}
   operator int() requires true;
   operator int() requires false;
 };
 
 void bar() {
+  // Note - we have a hard error in this case until P0848 is implemented.
   WrapsStatics::foo(A{});
   S{1.}.foo(A{});
   // expected-error@-1{{invalid reference to function '~S': constraints not satisfied}}
-  // Note - this behavior w.r.t. constrained dtors is a consequence of current
-  // wording, which does not invoke overload resolution when a dtor is called.
-  // P0848 is set to address this issue.
+
   S s = 1;
   // expected-error@-1{{invalid reference to function '~S': constraints not satisfied}}
   int a = s;
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -6731,6 +6731,45 @@
   return IssuedDiagnostic;
 }
 
+namespace {
+
+/// We don't support C++20 constrained destructors yet, and we are unlikely to
+/// do so in the near future. Until we do, we check here for multiple
+/// declarations and report an error. We have to handle correctly the case of
+/// merged declarations in modules and the case of invalid templated
+/// destructors so this is a bit involved.
+/// We also don't emit errors on OpenCL code because OpenCL destructors can
+/// overload on address space (https://reviews.llvm.org/D64569).
+void DiagnoseUnsupportedDestructorOverloading(Sema& S, const CXXRecordDecl* Record) {
+  ASTContext  = Record->getASTContext();
+  QualType ClassType = Context.getTypeDeclType(Record);
+
+  DeclarationName Name = Context.DeclarationNames.getCXXDestructorName(
+  Context.getCanonicalType(ClassType));
+
+  DeclContext::lookup_result R = Record->lookup(Name);
+
+  if (!(R.empty() || R.isSingleResult()) && !Context.getLangOpts().OpenCL) {
+bool HasNonTrivialOverloads = false;
+auto FirstDecl = R.front();
+for (const auto  : R) {
+  if (!Decl->isTemplateDecl() && !FirstDecl->isTemplateDecl() &&
+  !Context.isSameEntity(Decl, FirstDecl)) {
+HasNonTrivialOverloads = true;
+  }
+}
+if (HasNonTrivialOverloads) {
+  S.Diag(Record->getLocation(),
+ diag::err_unsupported_destructor_overloading);
+  for (const auto  : R) {
+S.Diag(Decl->getLocation(),
+   diag::note_unsupported_destructor_overloading_declaration);
+  }
+}
+  }
+}
+} // namespace
+
 /// Perform semantic checks on a class definition that has been
 /// completing, introducing implicitly-declared members, checking for
 /// abstract types, etc.
@@ -6955,6 +6994,9 @@
   CheckCompletedMemberFunction(M);
   };
 
+  if (!inTemplateInstantiation())
+DiagnoseUnsupportedDestructorOverloading(*this, Record);
+
   // Check the destructor before any other member function. We need to
   // determine whether it's trivial in order to determine whether the claas
   // type is a literal type, which is a prerequisite for determining whether
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2892,6 +2892,11 @@
 def err_unsupported_placeholder_constraint : Error<
   "constrained placeholder types other than simple 'auto' on non-type template "
   "parameters not supported yet">;
+def err_unsupported_destructor_overloading : Error<
+  "overloading destructors is not supported yet in this version. Consult "
+  "'https://github.com/llvm/llvm-project/issues/45614' for updates">;
+def note_unsupported_destructor_overloading_declaration : Note<
+  "destructor declared here.">;
 
 def err_template_different_requires_clause : Error<
   "requires clause differs in template redeclaration">;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[PATCH] D126160: [Concepts] Add an error for unsupported P0848 (destructor overloading) code

2022-05-22 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 431251.
royjacobson added a comment.

Move diagnostic into Sema, make it fire once for every class template 
definitions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126160

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/over/over.match/over.match.viable/p3.cpp

Index: clang/test/CXX/over/over.match/over.match.viable/p3.cpp
===
--- clang/test/CXX/over/over.match/over.match.viable/p3.cpp
+++ clang/test/CXX/over/over.match/over.match.viable/p3.cpp
@@ -44,24 +44,26 @@
 
 template
 struct S {
+  // expected-error@-1  {{overloading destructors is not supported}}
   void foo(int) requires false;
   void foo(A) requires true;
   S(A) requires false;
   S(double) requires true;
   ~S() requires false;
   // expected-note@-1 2{{because 'false' evaluated to false}}
+  // expected-note@-2 {{destructor declared here}}
   ~S() requires true;
+  // expected-note@-1 {{destructor declared here}}
   operator int() requires true;
   operator int() requires false;
 };
 
 void bar() {
+  // Note - we have a hard error in this case until P0848 is implemented.
   WrapsStatics::foo(A{});
   S{1.}.foo(A{});
   // expected-error@-1{{invalid reference to function '~S': constraints not satisfied}}
-  // Note - this behavior w.r.t. constrained dtors is a consequence of current
-  // wording, which does not invoke overload resolution when a dtor is called.
-  // P0848 is set to address this issue.
+
   S s = 1;
   // expected-error@-1{{invalid reference to function '~S': constraints not satisfied}}
   int a = s;
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -6731,6 +6731,45 @@
   return IssuedDiagnostic;
 }
 
+namespace {
+
+/// We don't support C++20 constrained destructors yet, and we are unlikely to
+/// do so in the near future. Until we do, we check here for multiple
+/// declarations and report an error. We have to handle correctly the case of
+/// merged declarations in modules and the case of invalid templated
+/// destructors so this is a bit involved.
+/// We also don't emit errors on OpenCL code because OpenCL destructors can
+/// overload on address space (https://reviews.llvm.org/D64569).
+void DiagnoseUnsupportedDestructorOverloading(Sema& S, const CXXRecordDecl* Record) {
+  ASTContext  = Record->getASTContext();
+  QualType ClassType = Context.getTypeDeclType(Record);
+
+  DeclarationName Name = Context.DeclarationNames.getCXXDestructorName(
+  Context.getCanonicalType(ClassType));
+
+  DeclContext::lookup_result R = Record->lookup(Name);
+
+  if (!(R.empty() || R.isSingleResult()) && !Context.getLangOpts().OpenCL) {
+bool hasNonTrivialOverloads = false;
+auto firstDecl = R.front();
+for (const auto  : R) {
+  if (!decl->isTemplateDecl() && !firstDecl->isTemplateDecl() &&
+  !Context.isSameEntity(decl, firstDecl)) {
+hasNonTrivialOverloads = true;
+  }
+}
+if (hasNonTrivialOverloads) {
+  S.Diag(Record->getLocation(),
+ diag::err_unsupported_destructor_overloading);
+  for (const auto  : R) {
+S.Diag(decl->getLocation(),
+   diag::note_unsupported_destructor_overloading_declaration);
+  }
+}
+  }
+}
+} // namespace
+
 /// Perform semantic checks on a class definition that has been
 /// completing, introducing implicitly-declared members, checking for
 /// abstract types, etc.
@@ -6955,6 +6994,9 @@
   CheckCompletedMemberFunction(M);
   };
 
+  if (!inTemplateInstantiation())
+DiagnoseUnsupportedDestructorOverloading(*this, Record);
+
   // Check the destructor before any other member function. We need to
   // determine whether it's trivial in order to determine whether the claas
   // type is a literal type, which is a prerequisite for determining whether
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2892,6 +2892,11 @@
 def err_unsupported_placeholder_constraint : Error<
   "constrained placeholder types other than simple 'auto' on non-type template "
   "parameters not supported yet">;
+def err_unsupported_destructor_overloading : Error<
+  "overloading destructors is not supported yet in this version. Consult "
+  "'https://github.com/llvm/llvm-project/issues/45614' for updates">;
+def note_unsupported_destructor_overloading_declaration : Note<
+  "destructor declared here.">;
 
 def err_template_different_requires_clause : Error<
   "requires clause differs in template redeclaration">;
___
cfe-commits 

[PATCH] D126172: [clang] Fix comparison of TemplateArgument when they are of template kind

2022-05-22 Thread Robert Esclapez via Phabricator via cfe-commits
roberteg16 created this revision.
roberteg16 added reviewers: Richard, smith.
Herald added a project: All.
roberteg16 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This diff path takes care of comparing Template{Expansion} by template decl
instead of by comparing the ptr attr Name and the number of expansions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126172

Files:
  clang/lib/AST/TemplateBase.cpp
  clang/test/CXX/dcl/dcl.fct/p17.cpp


Index: clang/test/CXX/dcl/dcl.fct/p17.cpp
===
--- clang/test/CXX/dcl/dcl.fct/p17.cpp
+++ clang/test/CXX/dcl/dcl.fct/p17.cpp
@@ -257,4 +257,21 @@
   static_assert(is_same_v);
   // expected-error@-1{{no matching}}
   static_assert(is_same_v);
+
+  template 
+  struct S3 {};
+  // expected-note@-1 {{'S3' declared here}}
+  // expected-note@-2 {{template is declared here}}
+  void f23(C2<::S3> auto);
+  // expected-error@-1 {{no template named 'S3' in the global namespace; did 
you mean simply 'S3'?}}
+  // expected-error@-2 {{use of class template '::S3' requires template 
arguments}}
+}
+
+template 
+struct S4 {};
+// expected-note@-1 {{template is declared here}}
+
+namespace constrained {
+  void f24(C2<::S4> auto);
+  // expected-error@-1 {{use of class template '::S4' requires template 
arguments}}
 }
Index: clang/lib/AST/TemplateBase.cpp
===
--- clang/lib/AST/TemplateBase.cpp
+++ clang/lib/AST/TemplateBase.cpp
@@ -370,8 +370,8 @@
 
   case Template:
   case TemplateExpansion:
-return TemplateArg.Name == Other.TemplateArg.Name &&
-   TemplateArg.NumExpansions == Other.TemplateArg.NumExpansions;
+return getAsTemplateOrTemplatePattern().getAsTemplateDecl() ==
+   Other.getAsTemplateOrTemplatePattern().getAsTemplateDecl();
 
   case Declaration:
 return getAsDecl() == Other.getAsDecl();


Index: clang/test/CXX/dcl/dcl.fct/p17.cpp
===
--- clang/test/CXX/dcl/dcl.fct/p17.cpp
+++ clang/test/CXX/dcl/dcl.fct/p17.cpp
@@ -257,4 +257,21 @@
   static_assert(is_same_v);
   // expected-error@-1{{no matching}}
   static_assert(is_same_v);
+
+  template 
+  struct S3 {};
+  // expected-note@-1 {{'S3' declared here}}
+  // expected-note@-2 {{template is declared here}}
+  void f23(C2<::S3> auto);
+  // expected-error@-1 {{no template named 'S3' in the global namespace; did you mean simply 'S3'?}}
+  // expected-error@-2 {{use of class template '::S3' requires template arguments}}
+}
+
+template 
+struct S4 {};
+// expected-note@-1 {{template is declared here}}
+
+namespace constrained {
+  void f24(C2<::S4> auto);
+  // expected-error@-1 {{use of class template '::S4' requires template arguments}}
 }
Index: clang/lib/AST/TemplateBase.cpp
===
--- clang/lib/AST/TemplateBase.cpp
+++ clang/lib/AST/TemplateBase.cpp
@@ -370,8 +370,8 @@
 
   case Template:
   case TemplateExpansion:
-return TemplateArg.Name == Other.TemplateArg.Name &&
-   TemplateArg.NumExpansions == Other.TemplateArg.NumExpansions;
+return getAsTemplateOrTemplatePattern().getAsTemplateDecl() ==
+   Other.getAsTemplateOrTemplatePattern().getAsTemplateDecl();
 
   case Declaration:
 return getAsDecl() == Other.getAsDecl();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 202a4fd - Test more C DR conformance (part two of many)

2022-05-22 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-05-22T13:37:30-04:00
New Revision: 202a4fde2ba92d70f1eb8760e1919b6ab19f0ced

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

LOG: Test more C DR conformance (part two of many)

This continues the work started earlier at filling our the C DR status
page based on test coverage.

Added: 
clang/test/C/drs/dr060.c

Modified: 
clang/test/C/drs/dr0xx.c
clang/www/c_dr_status.html

Removed: 




diff  --git a/clang/test/C/drs/dr060.c b/clang/test/C/drs/dr060.c
new file mode 100644
index 0..2650871e5dd6a
--- /dev/null
+++ b/clang/test/C/drs/dr060.c
@@ -0,0 +1,17 @@
+/* RUN: %clang_cc1 -std=c89 -emit-llvm -o - %s | FileCheck %s
+   RUN: %clang_cc1 -std=c99 -emit-llvm -o - %s | FileCheck %s
+   RUN: %clang_cc1 -std=c11 -emit-llvm -o - %s | FileCheck %s
+   RUN: %clang_cc1 -std=c17 -emit-llvm -o - %s | FileCheck %s
+   RUN: %clang_cc1 -std=c2x -emit-llvm -o - %s | FileCheck %s
+ */
+
+/* WG14 DR060:
+ * Array initialization from a string literal
+ */
+
+const char str[5] = "foo";
+const __typeof__(*L"a") wstr[5] = L"foo";
+
+// CHECK: @str = {{.*}}constant [5 x i8] c"foo\00\00"
+// CHECK-NEXT: @wstr = {{.*}}constant [5 x i{{16|32}}] [i{{16|32}} 102, 
i{{16|32}} 111, i{{16|32}} 111,  i{{16|32}} 0, i{{16|32}} 0]
+

diff  --git a/clang/test/C/drs/dr0xx.c b/clang/test/C/drs/dr0xx.c
index 4046765fa97ed..b0b57fa289149 100644
--- a/clang/test/C/drs/dr0xx.c
+++ b/clang/test/C/drs/dr0xx.c
@@ -1,8 +1,9 @@
-/* RUN: %clang_cc1 -std=c89 -verify=expected,c89 -pedantic 
-Wno-declaration-after-statement -Wno-c11-extensions %s
-   RUN: %clang_cc1 -std=c99 -verify -pedantic -Wno-c11-extensions %s
-   RUN: %clang_cc1 -std=c11 -verify -pedantic %s
-   RUN: %clang_cc1 -std=c17 -verify -pedantic %s
-   RUN: %clang_cc1 -std=c2x -verify -pedantic %s
+/* RUN: %clang_cc1 -std=c89 -verify=expected,c89only -pedantic 
-Wno-declaration-after-statement -Wno-c11-extensions %s
+   RUN: %clang_cc1 -std=c89 -verify=expected,c89only -pedantic 
-Wno-declaration-after-statement -Wno-c11-extensions -fno-signed-char %s
+   RUN: %clang_cc1 -std=c99 -verify=expected,c99untilc2x -pedantic 
-Wno-c11-extensions %s
+   RUN: %clang_cc1 -std=c11 -verify=expected,c99untilc2x -pedantic %s
+   RUN: %clang_cc1 -std=c17 -verify=expected,c99untilc2x -pedantic %s
+   RUN: %clang_cc1 -std=c2x -verify=expected,c2xandup -pedantic %s
  */
 
 /* The following are DRs which do not require tests to demonstrate
@@ -28,6 +29,34 @@
  * WG14 DR033: yes
  * Conformance questions around 'shall' violations outside of constraints
  * sections
+ *
+ * WG14 DR036: yes
+ * May floating-point constants be represented with more precision than implied
+ * by its type?
+ *
+ * WG14 DR037: yes
+ * Questions about multibyte characters and Unicode
+ *
+ * WG14 DR051: yes
+ * Question on pointer arithmetic
+ *
+ * WG14 DR052: yes
+ * Editorial corrections
+ *
+ * WG14 DR056: yes
+ * Floating-point representation precision requirements
+ *
+ * WG14 DR057: yes
+ * Is there an integral type for every pointer?
+ *
+ * WG14 DR059: yes
+ * Do types have to be completed?
+ *
+ * WG14 DR063: dup 056
+ * Floating-point representation precision requirements
+ *
+ * WG14 DR067: yes
+ * Integer and integral type confusion
  */
 
 
@@ -49,11 +78,16 @@ struct dr007_a;
 struct dr007_b {int a;};
 struct dr007_b;
 
+
 /* WG14 DR009: no
  * Use of typedef names in parameter declarations
+ *
+ * FIXME: This should be diagnosed as expecting a declaration specifier instead
+ * of treated as declaring a parameter of type 'int (*)(dr009_t);'
  */
 typedef int dr009_t;
-void dr009_f(int dr009_t);
+void dr009_f((dr009_t)); /* c99untilc2x-error {{type specifier missing, 
defaults to 'int'; ISO C99 and later do not support implicit int}}
+c2xandup-error {{a type specifier is required for 
all declarations}} */
 
 /* WG14 DR010:
  * Is a typedef to an incomplete type legal?
@@ -67,6 +101,12 @@ int dr010_c = sizeof(dr010_t); /* expected-error {{invalid 
application of 'sizeo
  * Merging of declarations for linked identifier
  *
  * Note: more of this DR is tested in dr011.c
+ *
+ * WG14 DR034: yes
+ * External declarations in 
diff erent scopes
+ *
+ * Note: DR034 has a question resolved by DR011 and another question where the
+ * result is UB.
  */
 static int dr011_a[]; /* expected-warning {{tentative array definition assumed 
to have one element}} */
 void dr011(void) {
@@ -96,7 +136,7 @@ void dr011(void) {
  */
 void dr012(void *p) {
   /* The behavior changed between C89 and C99. */
-  (void)&*p; /* c89-warning {{ISO C forbids taking the address of an 
expression of type 'void'}} */
+  (void)&*p; /* c89only-warning {{ISO C forbids taking the address of an 
expression of type 'void'}} */
 }
 
 /* WG14 DR013: yes
@@ 

[PATCH] D124446: [clang-tidy] Add the misc-discarded-return-value check

2022-05-22 Thread Whisperity via Phabricator via cfe-commits
whisperity added a comment.

In D124446#3521619 , @whisperity 
wrote:

> @aaron.ballman [...] I think I can put in a measurement job [...]

I've rerun the experiment **on another computer** (compared to the results 
shown in the inline comments) from scratch. The measurement environment had a 
4core/8thread CPU with 16 GiB RAM. There were no OOM situations.
LLVM was self-built by me, in a //Release// build (with 
`-DBUILD_SHARED_LIBS=ON`), linked with `ld.gold`.

The analysis was executed with the //"core checks"// list consisting of **all** 
`bugprone` (excluding bugprone-unchecked-optional-access 
), `misc`, `modernize`, `performance`, `portability`, 
and `readability`; with `-wall -wextra -weverything` and the //Clang Static 
Analyser// turned **off**. (This means that purely guidelines-related checks 
were also not run.)

- //BURV//: `bugprone-unused-return-value`
- //MDRV//: `misc-discarded-return-value`

Below times are the **full** analysis, for the project, at `-j8`, including the 
parsing and whatnot. Times are `h:mm:ss.fff`, real-world elapsed (//"wall"//) 
time.
I've also utilised Tidy's `--export-check-profile` feature. I've run the 
analysis results through CSA-Testbench 
 to generate some graphs, 
attached for each project. I know they look ugly, but I tried to make the 
colours as consistent between projects and executions as possible. (The two 
highlighted checks, //BURV// and //MDRV// are split out of the chart and get 
consistent bright colours. The rest of the colours for every check is 
calculated from the hashing of the check's full name, and as such, the results 
should be comparable even across projects.) The input for each entry in the 
chart is the summed up (for the entire project) `.wall` time, per check, as 
reported by Tidy in the JSONs it emitted.

| **Project**   
  | **Core checks** | Core //+ BURV// | Core //+ MDRV// 
| Core + **//BURV//, //MDRV//** | **only** //BURV// | **only** //MDRV// | 
**only** //BURV//, //MDRV// | **Chart** |
| Bitcoin   
  | 0:13:52.088 | 0:14:16.517 | 0:14:54.725 
| 0:15:18.858   | 0:01:35.215   | 0:02:15.282   | - 
  | F23156342: bitcoin.png 
 |
| CodeChecker ld-logger 

 | 0:00:01.055 | 0:00:01.033 | 0:00:01.098 | 0:00:01.132
   | 0:00:00.334   | 0:00:00.401   | -   | 
F23156348: codechecker.png  |
| Contour Terminal Emulator 
  | 
0:12:54.247 | 0:13:10.559 | 0:13:23.222 | 0:13:49.406   
| 0:01:27.554   | 0:01:57.877   | -   | 
F23156351: contour.png  |
| cURL    
  | 0:01:47.186 | 0:01:50.722 | 0:01:48.436 
| 0:01:51.260   | 0:00:16.982   | 0:00:22.576   | - 
  | F23156353: curl.png 
 |
| FFmpeg   
  | 0:08:45.986 | 0:09:09.407 | 0:09:20.924 
| 0:09:20.310   | 0:01:03.081   | 0:01:28.070   | - 
  | F23156355: ffmpeg.png 
 |
| libWebm  
  | 0:00:12.737 | 0:00:13.759 | 0:00:13.775 
| 0:00:14.609   | 0:00:01.220   | 0:00:01.872   | - 
  | F23156357: libwebm.png 
 |
| LLVM (Clang + CTE)   
  |  DNF   | -   | -   
| - | 0:59:29.017   | 1:21:39.916   | 
1:30:37.199 | F23156359: llvm-project.png 
 |
| MemcacheD   
  | 0:00:07.288 | 0:00:09.124 | 0:00:07.981 
| 0:00:11.056   | 0:00:01.561   | 0:00:01.938   | - 
  | F23156361: memcached.png 
 |
| MongoDB  
 

[PATCH] D126160: [Concepts] Add an error for unsupported P0848 (destructor overloading) code

2022-05-22 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson planned changes to this revision.
royjacobson added a comment.

I've thought about this a bit more and I want to move the diagnostic into 
SemaTemplateInstantiateDecl or somewhere close. It makes more sense because 
it's closer to where P0848 needs to be implemented and it will spam less errors.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126160

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


[PATCH] D126170: C++ DR2394: Const-default-constructible for members.

2022-05-22 Thread James Y Knight via Phabricator via cfe-commits
jyknight created this revision.
jyknight added reviewers: aaron.ballman, rsmith.
Herald added a project: All.
jyknight requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Const class members may be initialized with a defaulted default
constructor under the same conditions it would be allowed for a const
object elsewhere.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126170

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/drs/dr23xx.cpp
  clang/test/CXX/special/class.ctor/p5-0x.cpp
  clang/test/SemaCXX/cxx0x-deleted-default-ctor.cpp
  clang/www/cxx_dr_status.html

Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -14178,7 +14178,7 @@
 https://wg21.link/cwg2394;>2394
 CD5
 Const-default-constructible for members
-Unknown
+Clang 15
   
   
 https://wg21.link/cwg2395;>2395
Index: clang/test/SemaCXX/cxx0x-deleted-default-ctor.cpp
===
--- clang/test/SemaCXX/cxx0x-deleted-default-ctor.cpp
+++ clang/test/SemaCXX/cxx0x-deleted-default-ctor.cpp
@@ -48,8 +48,12 @@
 };
 good g;
 
+struct bad_const_inner {
+  int x;
+};
+
 struct bad_const {
-  const good g; // expected-note {{field 'g' of const-qualified type 'const good' would not be initialized}}
+  const bad_const_inner g; // expected-note {{field 'g' of const-qualified type 'const bad_const_inner' would not be initialized}}
 };
 bad_const bc; // expected-error {{call to implicitly-deleted default constructor}}
 
Index: clang/test/CXX/special/class.ctor/p5-0x.cpp
===
--- clang/test/CXX/special/class.ctor/p5-0x.cpp
+++ clang/test/CXX/special/class.ctor/p5-0x.cpp
@@ -2,6 +2,8 @@
 
 struct DefaultedDefCtor1 {};
 struct DefaultedDefCtor2 { DefaultedDefCtor2() = default; };
+struct DefaultedDefCtorUninitialized1 { int x; };
+struct DefaultedDefCtorUninitialized2 { int x; DefaultedDefCtorUninitialized2() = default; };
 struct DeletedDefCtor { DeletedDefCtor() = delete; DeletedDefCtor(int); }; // expected-note {{explicitly marked deleted here}}
 class PrivateDefCtor { PrivateDefCtor() = default; public: PrivateDefCtor(int); };
 struct DeletedDtor { ~DeletedDtor() = delete; }; // expected-note 4{{explicitly marked deleted here}}
@@ -51,21 +53,20 @@
 NotDeleted2d nd2d; // expected-note {{first required here}}
 
 // - any non-variant non-static data member of const qualified type (or array
-// thereof) with no brace-or-equal-initializer does not have a user-provided
-// default constructor,
+// thereof) with no brace-or-equal-initializer is not const-default-constructible
 class Deleted3a { const int a; }; // expected-note {{because field 'a' of const-qualified type 'const int' would not be initialized}} \
  expected-warning {{does not declare any constructor}} \
  expected-note {{will never be initialized}}
 Deleted3a d3a; // expected-error {{implicitly-deleted default constructor}}
-class Deleted3b { const DefaultedDefCtor1 a[42]; }; // expected-note {{because field 'a' of const-qualified type 'const DefaultedDefCtor1[42]' would not be initialized}}
+class Deleted3b { const DefaultedDefCtorUninitialized1 a[42]; }; // expected-note {{because field 'a' of const-qualified type 'const DefaultedDefCtorUninitialized1[42]' would not be initialized}}
 Deleted3b d3b; // expected-error {{implicitly-deleted default constructor}}
-class Deleted3c { const DefaultedDefCtor2 a; }; // expected-note {{because field 'a' of const-qualified type 'const DefaultedDefCtor2' would not be initialized}}
+class Deleted3c { const DefaultedDefCtorUninitialized2 a; }; // expected-note {{because field 'a' of const-qualified type 'const DefaultedDefCtorUninitialized2' would not be initialized}}
 Deleted3c d3c; // expected-error {{implicitly-deleted default constructor}}
 class NotDeleted3a { const int a = 0; };
 NotDeleted3a nd3a;
-class NotDeleted3b { const DefaultedDefCtor1 a[42] = {}; };
+class NotDeleted3b { const DefaultedDefCtorUninitialized1 a[42] = {}; };
 NotDeleted3b nd3b;
-class NotDeleted3c { const DefaultedDefCtor2 a = DefaultedDefCtor2(); };
+class NotDeleted3c { const DefaultedDefCtorUninitialized2 a = DefaultedDefCtorUninitialized2(); };
 NotDeleted3c nd3c;
 union NotDeleted3d { const int a; int b; };
 NotDeleted3d nd3d;
@@ -75,6 +76,10 @@
 NotDeleted3f nd3f;
 struct NotDeleted3g { union { const int a; int b; }; };
 NotDeleted3g nd3g;
+struct NotDeleted3h { const DefaultedDefCtor1 a[42]; };
+NotDeleted3h nd3h;
+struct NotDeleted3i { const DefaultedDefCtor2 a; };
+NotDeleted3i nd3i;
 
 // - X is a union and all of its variant members are of const-qualified type (or
 // array thereof),
Index: clang/test/CXX/drs/dr23xx.cpp

[clang] 69c0af3 - CWG 1394: Incomplete types as parameters of deleted functions

2022-05-22 Thread James Y Knight via cfe-commits

Author: James Y Knight
Date: 2022-05-22T10:22:13-04:00
New Revision: 69c0af3de224131cca844debd12872d4d1686800

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

LOG: CWG 1394: Incomplete types as parameters of deleted functions

Follow-up to previous commit: Add a DR test-case so the
make_cxx_dr_status automation works.

Bug: #52802
Fixes: 50b1faf5c188956fb59ea7d9f9d470591771aedb

Added: 


Modified: 
clang/test/CXX/drs/dr13xx.cpp

Removed: 




diff  --git a/clang/test/CXX/drs/dr13xx.cpp b/clang/test/CXX/drs/dr13xx.cpp
index 57d0f3cc97cc1..9efbd52ec58f1 100644
--- a/clang/test/CXX/drs/dr13xx.cpp
+++ b/clang/test/CXX/drs/dr13xx.cpp
@@ -450,6 +450,13 @@ namespace dr1391 { // dr1391: partial
   }
 }
 
+namespace dr1394 { // dr1394: 15
+#if __cplusplus >= 201103L
+struct Incomplete;
+Incomplete f(Incomplete) = delete; // well-formed
+#endif
+}
+
 namespace dr1399 { // dr1399: dup 1388
   template void f(T..., int, T...) {} // expected-note 
{{candidate}} expected-error 0-1{{C++11}}
   void g() {



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


[PATCH] D124690: [clangd] add inlay hints for std::forward-ed parameter packs

2022-05-22 Thread Tobias Ribizel via Phabricator via cfe-commits
upsj planned changes to this revision.
upsj marked 15 inline comments as done.
upsj added a comment.

I will update this to split up the control flow into a visitor just collecting 
a single recursion level and the high-level mapping. A general question here 
would be whether we should do the resolution by parameter or by parameter pack. 
Doing it by parameter (like I did it right now) is much easier for inlay hints, 
especially if the pack gets split up into different parts, but that may not 
necessarily be the case for template functions and more fuzzy cases like 
signature help/autocomplete.




Comment at: clang-tools-extra/clangd/InlayHints.cpp:261
+private:
+  void handleParmVarDeclName(const FunctionDecl *Callee, size_t I) {
+const auto *Param = Callee->getParamDecl(I);

sammccall wrote:
> Unless I'm missing something, going looking in the redecls of the function 
> for a parameter name doesn't seem in scope for this patch.
> 
> We don't support it in inlay hints elsewhere, and it's not clear it has 
> anything to do with forwarding functions.
> Maybe the added complexity is justifiable if this logic can be shared with 
> different functions (hover, signature help) but I don't think it belongs in 
> this patch.
This was already functionality previously available in `chooseParameterNames`, 
I thought I would need to do the same thing here, but turns out that I can get 
the `FunctionDecl` from a `ParmVarDecl`, so this can stay in its previous place.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124690

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


[PATCH] D126160: [Concepts] Add an error for unsupported P0848 (destructor overloading) code

2022-05-22 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 431229.
royjacobson added a comment.

A working version.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126160

Files:
  clang/include/clang/Basic/DiagnosticASTKinds.td
  clang/lib/AST/DeclCXX.cpp
  clang/test/CXX/over/over.match/over.match.viable/p3.cpp


Index: clang/test/CXX/over/over.match/over.match.viable/p3.cpp
===
--- clang/test/CXX/over/over.match/over.match.viable/p3.cpp
+++ clang/test/CXX/over/over.match/over.match.viable/p3.cpp
@@ -44,24 +44,26 @@
 
 template
 struct S {
+  // expected-error@-1 7{{overloading destructors is not supported}}
   void foo(int) requires false;
   void foo(A) requires true;
   S(A) requires false;
   S(double) requires true;
   ~S() requires false;
   // expected-note@-1 2{{because 'false' evaluated to false}}
+  // expected-note@-2 7{{destructor declared here}}
   ~S() requires true;
+  // expected-note@-1 7{{destructor declared here}}
   operator int() requires true;
   operator int() requires false;
 };
 
 void bar() {
+  // Note - we have a hard error in this case until P0848 is implemented.
   WrapsStatics::foo(A{});
   S{1.}.foo(A{});
   // expected-error@-1{{invalid reference to function '~S': constraints not 
satisfied}}
-  // Note - this behavior w.r.t. constrained dtors is a consequence of current
-  // wording, which does not invoke overload resolution when a dtor is called.
-  // P0848 is set to address this issue.
+
   S s = 1;
   // expected-error@-1{{invalid reference to function '~S': constraints not 
satisfied}}
   int a = s;
Index: clang/lib/AST/DeclCXX.cpp
===
--- clang/lib/AST/DeclCXX.cpp
+++ clang/lib/AST/DeclCXX.cpp
@@ -29,6 +29,7 @@
 #include "clang/AST/TypeLoc.h"
 #include "clang/AST/UnresolvedSet.h"
 #include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/DiagnosticAST.h"
 #include "clang/Basic/IdentifierTable.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/LangOptions.h"
@@ -1895,6 +1896,33 @@
 
   DeclContext::lookup_result R = lookup(Name);
 
+  // We don't support C++20 constrained destructors yet, and we are unlikely to
+  // do so in the near future. Until we do, we check here for multiple
+  // declarations and report an error. We have to handle correctly the case of
+  // merged declarations in modules and the case of invalid templated
+  // destructors so this is a bit involved.
+  // We also don't emit errors on OpenCL code because OpenCL desturctors can
+  // overload on address space (https://reviews.llvm.org/D64569).
+  if (!(R.empty() || R.isSingleResult()) && !Context.getLangOpts().OpenCL) {
+bool hasNonTrivialOverloads = false;
+auto firstDecl = R.front();
+for (const auto  : R) {
+  if (!decl->isTemplateDecl() && !firstDecl->isTemplateDecl() &&
+  !Context.isSameEntity(decl, firstDecl)) {
+hasNonTrivialOverloads = true;
+  }
+}
+if (hasNonTrivialOverloads) {
+  Context.getDiagnostics().Report(
+  getLocation(), diag::err_unsupported_destructor_overloading);
+  for (const auto  : R) {
+Context.getDiagnostics().Report(
+decl->getLocation(),
+diag::note_unsupported_destructor_overloading_declaration);
+  }
+}
+  }
+
   return R.empty() ? nullptr : dyn_cast(R.front());
 }
 
Index: clang/include/clang/Basic/DiagnosticASTKinds.td
===
--- clang/include/clang/Basic/DiagnosticASTKinds.td
+++ clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -597,4 +597,11 @@
 def warn_unaligned_access : Warning<
   "field %1 within %0 is less aligned than %2 and is usually due to %0 being "
   "packed, which can lead to unaligned accesses">, InGroup, 
DefaultIgnore;
+
+def err_unsupported_destructor_overloading : Error<
+  "overloading destructors is not supported yet in this version. Consult "
+  "'https://github.com/llvm/llvm-project/issues/45614' for updates">;
+def note_unsupported_destructor_overloading_declaration : Note<
+  "destructor declared here.">;
+
 }


Index: clang/test/CXX/over/over.match/over.match.viable/p3.cpp
===
--- clang/test/CXX/over/over.match/over.match.viable/p3.cpp
+++ clang/test/CXX/over/over.match/over.match.viable/p3.cpp
@@ -44,24 +44,26 @@
 
 template
 struct S {
+  // expected-error@-1 7{{overloading destructors is not supported}}
   void foo(int) requires false;
   void foo(A) requires true;
   S(A) requires false;
   S(double) requires true;
   ~S() requires false;
   // expected-note@-1 2{{because 'false' evaluated to false}}
+  // expected-note@-2 7{{destructor declared here}}
   ~S() requires true;
+  // expected-note@-1 7{{destructor declared here}}
   operator int() requires true;
   operator int() requires false;
 };
 
 

[PATCH] D126077: Fix stack crash in classIsDerivedFrom triggered by clang-tidy

2022-05-22 Thread Nathan James via Phabricator via cfe-commits
njames93 edited reviewers, added: aaron.ballman, njames93, alexfh, 
LegalizeAdulthood; removed: bixia, aartbik.
njames93 added a comment.

Do you know of any other instances where this issue could surface?

Please can you add a line to the `Improved Checks` section in 
`clang-tools-extra/docs/ReleaseNotes.rst` about this fix. Make sure it is in 
alphabetical order.




Comment at: 
clang-tools-extra/test/clang-tidy/infrastructure/recursive-templates.cpp:2
+// Regression test: shouldn't crash.
+// RUN: clang-tidy %s -checks='*' -- | FileCheck %s
+template struct t1;

Can you narrow down the check list to just include a check is causing the crash.
Also given we are only ensuring there is no crash, we don't need to invoke 
FileCheck. clang-tidy will return non-zero if it crashes, causing the whole 
test to fail.



Comment at: 
clang-tools-extra/test/clang-tidy/infrastructure/recursive-templates.cpp:8
+int main() {
+  return 0;
+}

This is different to the reproducer in the bug report as it doesn't have an 
instantiation of the struct in this test, unlike the bug report.



Comment at: 
clang-tools-extra/test/clang-tidy/infrastructure/recursive-templates.cpp:11-13
+namespace i {
+}
+// CHECK: warning: namespace 'i' not terminated with a closing comment 
[llvm-namespace-comment]

Definitely unrelated to this check and could safely be removed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126077

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


[PATCH] D54943: [clang-tidy] implement new check 'misc-const-correctness' to add 'const' to unmodified variables

2022-05-22 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

Pretty much good to go, just a few nits with the tests.
Can you add CHECK-FIXES directives for all warnings if there should be a fixit.
If there shouldn't be one could you either add a comment saying there shouldn't 
be one, or put a CHECK-FIXES-NOT directive.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D54943

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


[PATCH] D126162: [clang-tidy] Extend SimplifyBooleanExpr demorgan support.

2022-05-22 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added reviewers: aaron.ballman, alexfh, LegalizeAdulthood.
Herald added subscribers: carlosgalvezp, xazax.hun.
Herald added a project: All.
njames93 requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Adds an option SimplifyDemorganRelaxed which, when enabled, will transform 
negated conjunctions or disjunctions when neither operand is a negation.
Default value is `false`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126162

Files:
  clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
  clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
  clang-tools-extra/docs/clang-tidy/checks/readability-simplify-boolean-expr.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-demorgan.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-demorgan.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-demorgan.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-demorgan.cpp
@@ -1,9 +1,30 @@
 // RUN: %check_clang_tidy %s readability-simplify-boolean-expr %t
 
+// Check when we can convert !(A Op B) -> !A InvOp !B.
+// RUN: %check_clang_tidy -check-suffixes=",RELAXED" %s \
+// RUN: readability-simplify-boolean-expr %t -- -config="{CheckOptions: [{ \
+// RUN: key: "readability-simplify-boolean-expr.SimplifyDeMorganRelaxed", value: true}]}" --
+
+// Verify warning issued when invalid options are specified.
+// RUN: clang-tidy %s -checks=-*,readability-simplify-boolean-expr -config="{CheckOptions: [ \
+// RUN:   {key: readability-simplify-boolean-expr.SimplifyDeMorgan, value: false}, \
+// RUN:   {key: readability-simplify-boolean-expr.SimplifyDeMorganRelaxed, value: true}]}" \
+// RUN: -- 2>&1 | FileCheck %s -check-prefix=CHECK-BAD-CONFIG \
+// RUN:   -implicit-check-not="{{warning|error}}:"
+
+// CHECK-BAD-CONFIG: warning: readability-simplify-boolean-expr: 'SimplifyDeMorganRelaxed' cannot be enabled without 'SimplifyDeMorgan' enabled
 void eat(bool);
 
 void foo(bool A1, bool A2, bool A3, bool A4) {
   bool X;
+
+  X = !(A1 && A2);
+  X = !(A1 || A2);
+  // CHECK-MESSAGES-RELAXED: :[[@LINE-2]]:7: warning: boolean expression can be simplified by DeMorgan's theorem
+  // CHECK-MESSAGES-RELAXED: :[[@LINE-2]]:7: warning: boolean expression can be simplified by DeMorgan's theorem
+  // CHECK-FIXES-RELAXED: X = !A1 || !A2;
+  // CHECK-FIXES-NEXT-RELAXED: X = !A1 && !A2;
+
   X = !(!A1 || A2);
   X = !(A1 || !A2);
   X = !(!A1 || !A2);
Index: clang-tools-extra/docs/clang-tidy/checks/readability-simplify-boolean-expr.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/readability-simplify-boolean-expr.rst
+++ clang-tools-extra/docs/clang-tidy/checks/readability-simplify-boolean-expr.rst
@@ -96,3 +96,23 @@
 
If `true`, DeMorgan's Theorem will be applied to simplify negated
conjunctions and disjunctions.  Default is `true`.
+
+.. option:: SimplifyDeMorganRelaxed
+
+   If `true`, :option:`SimplifyDeMorgan` will also transform negated 
+   conjunctions and disjunctions where there is no negation on either operand. 
+   Default is `false`.
+
+   When Enabled:
+
+   .. code-block::
+
+  bool X = !(A && B)
+  bool Y = !(A || B)
+
+   Would be transformed to:
+
+   .. code-block::
+
+  bool X = !A || !B
+  bool Y = !A && !B
Index: clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
===
--- clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
+++ clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
@@ -69,6 +69,7 @@
   const bool ChainedConditionalReturn;
   const bool ChainedConditionalAssignment;
   const bool SimplifyDeMorgan;
+  const bool SimplifyDeMorganRelaxed;
 };
 
 } // namespace readability
Index: clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
@@ -558,7 +558,8 @@
 if (!BinaryOp || !BinaryOp->isLogicalOp() ||
 !BinaryOp->getType()->isBooleanType())
   return Base::TraverseUnaryOperator(Op);
-if (checkEitherSide(BinaryOp, isUnaryLNot) ||
+if (Check->SimplifyDeMorganRelaxed ||
+checkEitherSide(BinaryOp, isUnaryLNot) ||
 checkEitherSide(BinaryOp,
 [](const Expr *E) { return nestedDemorgan(E, 1); })) {
   if (Check->reportDeMorgan(Context, Op, BinaryOp, !IsProcessing, parent(),
@@ -584,7 +585,13 @@
   ChainedConditionalReturn(Options.get("ChainedConditionalReturn", false)),
   

[PATCH] D126138: [clang-tidy] Fix #55134 (regression introduced by 5da7c04)

2022-05-22 Thread Salman Javed via Phabricator via cfe-commits
salman-javed-nz added a comment.

In D126138#3529820 , @paulaltin wrote:

> Thanks for preparing this revision @salman-javed-nz!
>
> Do you think it could be worth adding a few more test cases to cover this? It 
> turned out that this issue wasn't actually specific to multi-line macros (see 
> this comment 
> ), 
> so if the test case on line 96 was passing then it must not be 
> fully/correctly testing NOLINT for single-line macros. I guess the only way 
> to do this would be to add more checks to the nolint.cpp file, but I realise 
> that's not a trivial change.

I added a second test case to this patch, to cover the specific check mentioned 
in the GitHub ticket.
This fix is check-agnostic, so I don't think we need to add even more tests 
than the two proposed here.

I think I've addressed what everyone has discussed in this review up to this 
point. Let me know what other updates I can make to this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126138

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


[PATCH] D126138: [clang-tidy] Fix #55134 (regression introduced by 5da7c04)

2022-05-22 Thread Salman Javed via Phabricator via cfe-commits
salman-javed-nz updated this revision to Diff 431223.
salman-javed-nz added a comment.

Add another test, to test the specific code sample in the GitHub issue 
(check=cppcoreguidelines-pro-type-member-init).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126138

Files:
  clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/nolint.cpp


Index: clang-tools-extra/test/clang-tidy/infrastructure/nolint.cpp
===
--- clang-tools-extra/test/clang-tidy/infrastructure/nolint.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/nolint.cpp
@@ -1,5 +1,5 @@
 // REQUIRES: static-analyzer
-// RUN: %check_clang_tidy %s 
google-explicit-constructor,clang-diagnostic-unused-variable,clang-analyzer-core.UndefinedBinaryOperatorResult,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays
 %t -- -extra-arg=-Wunused-variable -- -I%S/Inputs/nolint
+// RUN: %check_clang_tidy %s 
google-explicit-constructor,clang-diagnostic-unused-variable,clang-analyzer-core.UndefinedBinaryOperatorResult,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays,cppcoreguidelines-pro-type-member-init
 %t -- -extra-arg=-Wunused-variable -- -I%S/Inputs/nolint
 
 #include "trigger_warning.h"
 void I(int& Out) {
@@ -96,6 +96,23 @@
 #define MACRO_NOLINT class G { G(int i); }; // NOLINT
 MACRO_NOLINT
 
+// Check that we can suppress diagnostics about macro arguments (as opposed to
+// diagnostics about the macro contents itself).
+#define MACRO_SUPPRESS_DIAG_FOR_ARG_1(X)\
+  class X { \
+X(int i); /* NOLINT(google-explicit-constructor) */ \
+  };
+
+MACRO_SUPPRESS_DIAG_FOR_ARG_1(G1)
+
+#define MACRO_SUPPRESS_DIAG_FOR_ARG_2(X)  \
+  struct X { /* NOLINT(cppcoreguidelines-pro-type-member-init) */ \
+int a = 0;\
+int b;\
+  };
+
+MACRO_SUPPRESS_DIAG_FOR_ARG_2(G2)
+
 #define DOUBLE_MACRO MACRO(H) // NOLINT
 DOUBLE_MACRO
 
@@ -116,4 +133,4 @@
 int array3[10];  // 
NOLINT(cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays)
 int array4[10];  // NOLINT(*-avoid-c-arrays)
 
-// CHECK-MESSAGES: Suppressed 34 warnings (34 NOLINT)
+// CHECK-MESSAGES: Suppressed 36 warnings (36 NOLINT)
Index: clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp
===
--- clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp
+++ clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp
@@ -266,7 +266,7 @@
   return true;
 if (!DiagLoc.isMacroID())
   return false;
-DiagLoc = SrcMgr.getImmediateMacroCallerLoc(DiagLoc);
+DiagLoc = SrcMgr.getImmediateExpansionRange(DiagLoc).getBegin();
   }
   return false;
 }


Index: clang-tools-extra/test/clang-tidy/infrastructure/nolint.cpp
===
--- clang-tools-extra/test/clang-tidy/infrastructure/nolint.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/nolint.cpp
@@ -1,5 +1,5 @@
 // REQUIRES: static-analyzer
-// RUN: %check_clang_tidy %s google-explicit-constructor,clang-diagnostic-unused-variable,clang-analyzer-core.UndefinedBinaryOperatorResult,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays %t -- -extra-arg=-Wunused-variable -- -I%S/Inputs/nolint
+// RUN: %check_clang_tidy %s google-explicit-constructor,clang-diagnostic-unused-variable,clang-analyzer-core.UndefinedBinaryOperatorResult,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays,cppcoreguidelines-pro-type-member-init %t -- -extra-arg=-Wunused-variable -- -I%S/Inputs/nolint
 
 #include "trigger_warning.h"
 void I(int& Out) {
@@ -96,6 +96,23 @@
 #define MACRO_NOLINT class G { G(int i); }; // NOLINT
 MACRO_NOLINT
 
+// Check that we can suppress diagnostics about macro arguments (as opposed to
+// diagnostics about the macro contents itself).
+#define MACRO_SUPPRESS_DIAG_FOR_ARG_1(X)\
+  class X { \
+X(int i); /* NOLINT(google-explicit-constructor) */ \
+  };
+
+MACRO_SUPPRESS_DIAG_FOR_ARG_1(G1)
+
+#define MACRO_SUPPRESS_DIAG_FOR_ARG_2(X)  \
+  struct X { /* NOLINT(cppcoreguidelines-pro-type-member-init) */ \
+int a = 0;\
+int b;\
+  };
+
+MACRO_SUPPRESS_DIAG_FOR_ARG_2(G2)
+
 #define DOUBLE_MACRO MACRO(H) // NOLINT
 DOUBLE_MACRO
 
@@ -116,4 +133,4 @@
 int array3[10];  // NOLINT(cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays)
 int array4[10];  // NOLINT(*-avoid-c-arrays)
 
-// CHECK-MESSAGES: Suppressed 34 warnings (34 NOLINT)
+// CHECK-MESSAGES: Suppressed 36 warnings (36 NOLINT)
Index: 

[clang-tools-extra] 9d0d24e - [clang-tidy] Fix not updating storeOptions after af77b1d9901

2022-05-22 Thread Nathan James via cfe-commits

Author: Nathan James
Date: 2022-05-22T10:28:52+01:00
New Revision: 9d0d24eec44787b4a762d01866d0b9b733bee778

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

LOG: [clang-tidy] Fix not updating storeOptions after af77b1d9901

Added: 


Modified: 
clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
index 3502375ea1ba..f35f7839dc25 100644
--- a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
@@ -666,6 +666,7 @@ void 
SimplifyBooleanExprCheck::storeOptions(ClangTidyOptions::OptionMap ) {
   Options.store(Opts, "ChainedConditionalReturn", ChainedConditionalReturn);
   Options.store(Opts, "ChainedConditionalAssignment",
 ChainedConditionalAssignment);
+  Options.store(Opts, "SimplifyDeMorgan", SimplifyDeMorgan);
 }
 
 void SimplifyBooleanExprCheck::registerMatchers(MatchFinder *Finder) {



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


[PATCH] D126123: [analyzer][NFC] MemRegion::getRegion() never returns null

2022-05-22 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

Until this point, the runtime and reports of the Clang Static Analyzer did not 
change on our testset; which confirms that the stack is indeed NFC.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126123

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


[PATCH] D126157: [clang-format][NFC] Insert/remove braces in clang/lib/Format/

2022-05-22 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius accepted this revision.
curdeius added a comment.
This revision is now accepted and ready to land.

Ok. So we mainly missed braces on complex conditionals. LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126157

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


[PATCH] D126160: [Concepts] Add an error for unsupported P0848 (destructor overloading) code

2022-05-22 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson created this revision.
Herald added a project: All.
royjacobson requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

We have received numeroud bug reports over P0848 not being implemented for 
destructors. We currently allow multiple destructor declarations but we will 
always select the first one, which might unintendedly compile with the wrong 
destructor. This patch adds a diagnostic for classes that try to overload 
destructors with constraints so users won't be confused when their (legal) code 
doesn't work.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126160

Files:
  clang/include/clang/Basic/DiagnosticASTKinds.td
  clang/lib/AST/DeclCXX.cpp
  clang/test/CXX/over/over.match/over.match.viable/p3.cpp


Index: clang/test/CXX/over/over.match/over.match.viable/p3.cpp
===
--- clang/test/CXX/over/over.match/over.match.viable/p3.cpp
+++ clang/test/CXX/over/over.match/over.match.viable/p3.cpp
@@ -48,21 +48,20 @@
   void foo(A) requires true;
   S(A) requires false;
   S(double) requires true;
+  // expected-note@-1 7{{destructor declared here}}
   ~S() requires false;
-  // expected-note@-1 2{{because 'false' evaluated to false}}
+  // expected-note@-1 7{{destructor declared here}}
   ~S() requires true;
   operator int() requires true;
   operator int() requires false;
 };
 
 void bar() {
+  // Note - we have a hard error in this case until P0848 is implemented.
+  // expected-error@ 7{{overloading destructors is not supported yet}}
   WrapsStatics::foo(A{});
   S{1.}.foo(A{});
-  // expected-error@-1{{invalid reference to function '~S': constraints not 
satisfied}}
-  // Note - this behavior w.r.t. constrained dtors is a consequence of current
-  // wording, which does not invoke overload resolution when a dtor is called.
-  // P0848 is set to address this issue.
+
   S s = 1;
-  // expected-error@-1{{invalid reference to function '~S': constraints not 
satisfied}}
   int a = s;
 }
Index: clang/lib/AST/DeclCXX.cpp
===
--- clang/lib/AST/DeclCXX.cpp
+++ clang/lib/AST/DeclCXX.cpp
@@ -29,6 +29,7 @@
 #include "clang/AST/TypeLoc.h"
 #include "clang/AST/UnresolvedSet.h"
 #include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/DiagnosticAST.h"
 #include "clang/Basic/IdentifierTable.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/LangOptions.h"
@@ -1895,6 +1896,32 @@
 
   DeclContext::lookup_result R = lookup(Name);
 
+  // We don't support C++20 constrained destructors yet, and we are unlikely to
+  // do so in the near future. Until we do, we check here for multiple
+  // declarations and report an error. We have to handle correctly the case of
+  // merged declarations in modules and the case of invalid templated
+  // destructors so this is a bit involved.
+  if (!(R.empty() || R.isSingleResult())) {
+bool hasNonTrivialOverloads = false;
+auto firstDecl = R.front();
+for (const auto  : R) {
+  if (decl->getFunctionType() && firstDecl->getFunctionType() &&
+  !Context.hasSameType(decl->getFunctionType(),
+   firstDecl->getFunctionType())) {
+hasNonTrivialOverloads = true;
+  }
+}
+if (hasNonTrivialOverloads) {
+  Context.getDiagnostics().Report(
+  diag::err_unsupported_destructor_overloading);
+  for (const auto  : R) {
+Context.getDiagnostics().Report(
+decl->getLocation(),
+diag::note_unsupported_destructor_overloading_declaration);
+  }
+}
+  }
+
   return R.empty() ? nullptr : dyn_cast(R.front());
 }
 
Index: clang/include/clang/Basic/DiagnosticASTKinds.td
===
--- clang/include/clang/Basic/DiagnosticASTKinds.td
+++ clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -597,4 +597,11 @@
 def warn_unaligned_access : Warning<
   "field %1 within %0 is less aligned than %2 and is usually due to %0 being "
   "packed, which can lead to unaligned accesses">, InGroup, 
DefaultIgnore;
+
+def err_unsupported_destructor_overloading : Error<
+  "overloading destructors is not supported yet in this version. Consult "
+  "'https://github.com/llvm/llvm-project/issues/45614' for updates">;
+def note_unsupported_destructor_overloading_declaration : Note<
+  "destructor declared here.">;
+
 }


Index: clang/test/CXX/over/over.match/over.match.viable/p3.cpp
===
--- clang/test/CXX/over/over.match/over.match.viable/p3.cpp
+++ clang/test/CXX/over/over.match/over.match.viable/p3.cpp
@@ -48,21 +48,20 @@
   void foo(A) requires true;
   S(A) requires false;
   S(double) requires true;
+  // expected-note@-1 7{{destructor declared here}}
   ~S() requires false;
-  // expected-note@-1 2{{because 'false' evaluated to false}}
+  // expected-note@-1 7{{destructor 

[PATCH] D124806: [clang-tidy] add support for Demorgan conversions to readability-simplify-bool-expr

2022-05-22 Thread Nathan James via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaf77b1d99016: [clang-tidy] add support for Demorgan 
conversions to readability-simplify-bool… (authored by njames93).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124806

Files:
  clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
  clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/readability-simplify-boolean-expr.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-demorgan.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-demorgan.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-demorgan.cpp
@@ -0,0 +1,87 @@
+// RUN: %check_clang_tidy %s readability-simplify-boolean-expr %t
+
+void eat(bool);
+
+void foo(bool A1, bool A2, bool A3, bool A4) {
+  bool X;
+  X = !(!A1 || A2);
+  X = !(A1 || !A2);
+  X = !(!A1 || !A2);
+  // CHECK-MESSAGES: :[[@LINE-3]]:7: warning: boolean expression can be simplified by DeMorgan's theorem
+  // CHECK-MESSAGES: :[[@LINE-3]]:7: warning: boolean expression can be simplified by DeMorgan's theorem
+  // CHECK-MESSAGES: :[[@LINE-3]]:7: warning: boolean expression can be simplified by DeMorgan's theorem
+  // CHECK-FIXES: X = A1 && !A2;
+  // CHECK-FIXES-NEXT: X = !A1 && A2;
+  // CHECK-FIXES-NEXT: X = A1 && A2;
+
+  X = !(!A1 && A2);
+  X = !(A1 && !A2);
+  X = !(!A1 && !A2);
+  // CHECK-MESSAGES: :[[@LINE-3]]:7: warning: boolean expression can be simplified by DeMorgan's theorem
+  // CHECK-MESSAGES: :[[@LINE-3]]:7: warning: boolean expression can be simplified by DeMorgan's theorem
+  // CHECK-MESSAGES: :[[@LINE-3]]:7: warning: boolean expression can be simplified by DeMorgan's theorem
+  // CHECK-FIXES: X = A1 || !A2;
+  // CHECK-FIXES-NEXT: X = !A1 || A2;
+  // CHECK-FIXES-NEXT: X = A1 || A2;
+
+  X = !(!A1 && !A2 && !A3);
+  X = !(!A1 && (!A2 && !A3));
+  X = !(!A1 && (A2 && A3));
+  // CHECK-MESSAGES: :[[@LINE-3]]:7: warning: boolean expression can be simplified by DeMorgan's theorem
+  // CHECK-MESSAGES: :[[@LINE-3]]:7: warning: boolean expression can be simplified by DeMorgan's theorem
+  // CHECK-MESSAGES: :[[@LINE-3]]:7: warning: boolean expression can be simplified by DeMorgan's theorem
+  // CHECK-FIXES: X = A1 || A2 || A3;
+  // CHECK-FIXES-NEXT: X = A1 || A2 || A3;
+  // CHECK-FIXES-NEXT: X = A1 || !A2 || !A3;
+
+  X = !(A1 && A2 == A3);
+  X = !(!A1 && A2 > A3);
+  // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: boolean expression can be simplified by DeMorgan's theorem
+  // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: boolean expression can be simplified by DeMorgan's theorem
+  // CHECK-FIXES: X = !A1 || A2 != A3;
+  // CHECK-FIXES-NEXT: X = A1 || A2 <= A3;
+
+  // Ensure the check doesn't try to combine fixes for the inner and outer demorgan simplification.
+  X = !(!A1 && !(!A2 && !A3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: boolean expression can be simplified by DeMorgan's theorem
+  // CHECK-MESSAGES: :[[@LINE-2]]:16: warning: boolean expression can be simplified by DeMorgan's theorem
+  // CHECK-FIXES: X = A1 || (!A2 && !A3);
+
+  // Testing to see how it handles parens
+  X = !(A1 && !A2 && !A3);
+  X = !(A1 && !A2 || !A3);
+  X = !(!A1 || A2 && !A3);
+  X = !((A1 || !A2) && !A3);
+  X = !((A1 || !A2) || !A3);
+  // CHECK-MESSAGES: :[[@LINE-5]]:7: warning: boolean expression can be simplified by DeMorgan's theorem
+  // CHECK-MESSAGES: :[[@LINE-5]]:7: warning: boolean expression can be simplified by DeMorgan's theorem
+  // CHECK-MESSAGES: :[[@LINE-5]]:7: warning: boolean expression can be simplified by DeMorgan's theorem
+  // CHECK-MESSAGES: :[[@LINE-5]]:7: warning: boolean expression can be simplified by DeMorgan's theorem
+  // CHECK-MESSAGES: :[[@LINE-5]]:7: warning: boolean expression can be simplified by DeMorgan's theorem
+  // CHECK-FIXES: X = !A1 || A2 || A3;
+  // CHECK-FIXES-NEXT: X = (!A1 || A2) && A3;
+  // CHECK-FIXES-NEXT: X = A1 && (!A2 || A3);
+  // CHECK-FIXES-NEXT: X = (!A1 && A2) || A3;
+  // CHECK-FIXES-NEXT: X = !A1 && A2 && A3;
+  X = !((A1 || A2) && (!A3 || A4));
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: boolean expression can be simplified by DeMorgan's theorem
+  // CHECK-FIXES: X = (!A1 && !A2) || (A3 && !A4);
+
+  eat(!(!A1 && !A2));
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: boolean expression can be simplified by DeMorgan's theorem
+  // CHECK-FIXES: eat(A1 || A2);
+
+  bool Init = !(!A1 || !A2);
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: boolean expression can be simplified by DeMorgan's theorem
+  // CHECK-FIXES: bool Init = A1 && A2;
+
+  X = A1 && !(!A2 || !A3);
+  X = A1 || !(!A2 || !A3);
+  X = A1 && !(!A2 && !A3);
+  // 

[clang-tools-extra] af77b1d - [clang-tidy] add support for Demorgan conversions to readability-simplify-bool-expr

2022-05-22 Thread Nathan James via cfe-commits

Author: Nathan James
Date: 2022-05-22T09:28:43+01:00
New Revision: af77b1d99016fde66edd9e72d907c03fe4511215

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

LOG: [clang-tidy] add support for Demorgan conversions to 
readability-simplify-bool-expr

Adds support for recognising and converting boolean expressions that can be 
simplified using De Morgans Law.

This is a different implementation to D124650.

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

Reviewed By: LegalizeAdulthood

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

Added: 

clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr-demorgan.cpp

Modified: 
clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
clang-tools-extra/docs/ReleaseNotes.rst

clang-tools-extra/docs/clang-tidy/checks/readability-simplify-boolean-expr.rst

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
index 323cf1f2d5ecb..3502375ea1ba6 100644
--- a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
@@ -9,6 +9,7 @@
 #include "SimplifyBooleanExprCheck.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/Lex/Lexer.h"
+#include "llvm/Support/SaveAndRestore.h"
 
 #include 
 #include 
@@ -257,6 +258,8 @@ static bool containsDiscardedTokens(const ASTContext 
,
 }
 
 class SimplifyBooleanExprCheck::Visitor : public RecursiveASTVisitor {
+  using Base = RecursiveASTVisitor;
+
 public:
   Visitor(SimplifyBooleanExprCheck *Check, ASTContext )
   : Check(Check), Context(Context) {}
@@ -503,7 +506,73 @@ class SimplifyBooleanExprCheck::Visitor : public 
RecursiveASTVisitor {
 return true;
   }
 
+  static bool isUnaryLNot(const Expr *E) {
+return isa(E) &&
+   cast(E)->getOpcode() == UO_LNot;
+  }
+
+  template 
+  static bool checkEitherSide(const BinaryOperator *BO, Functor Func) {
+return Func(BO->getLHS()) || Func(BO->getRHS());
+  }
+
+  static bool nestedDemorgan(const Expr *E, unsigned NestingLevel) {
+const auto *BO = 
dyn_cast(E->IgnoreUnlessSpelledInSource());
+if (!BO)
+  return false;
+if (!BO->getType()->isBooleanType())
+  return false;
+switch (BO->getOpcode()) {
+case BO_LT:
+case BO_GT:
+case BO_LE:
+case BO_GE:
+case BO_EQ:
+case BO_NE:
+  return true;
+case BO_LAnd:
+case BO_LOr:
+  if (checkEitherSide(BO, isUnaryLNot))
+return true;
+  if (NestingLevel) {
+if (checkEitherSide(BO, [NestingLevel](const Expr *E) {
+  return nestedDemorgan(E, NestingLevel - 1);
+}))
+  return true;
+  }
+  return false;
+default:
+  return false;
+}
+  }
+
+  bool TraverseUnaryOperator(UnaryOperator *Op) {
+if (!Check->SimplifyDeMorgan || Op->getOpcode() != UO_LNot)
+  return Base::TraverseUnaryOperator(Op);
+Expr *SubImp = Op->getSubExpr()->IgnoreImplicit();
+auto *Parens = dyn_cast(SubImp);
+auto *BinaryOp =
+Parens
+? dyn_cast(Parens->getSubExpr()->IgnoreImplicit())
+: dyn_cast(SubImp);
+if (!BinaryOp || !BinaryOp->isLogicalOp() ||
+!BinaryOp->getType()->isBooleanType())
+  return Base::TraverseUnaryOperator(Op);
+if (checkEitherSide(BinaryOp, isUnaryLNot) ||
+checkEitherSide(BinaryOp,
+[](const Expr *E) { return nestedDemorgan(E, 1); })) {
+  if (Check->reportDeMorgan(Context, Op, BinaryOp, !IsProcessing, parent(),
+Parens) &&
+  !Check->areDiagsSelfContained()) {
+llvm::SaveAndRestore RAII(IsProcessing, true);
+return Base::TraverseUnaryOperator(Op);
+  }
+}
+return Base::TraverseUnaryOperator(Op);
+  }
+
 private:
+  bool IsProcessing = false;
   SimplifyBooleanExprCheck *Check;
   SmallVector StmtStack;
   ASTContext 
@@ -514,7 +583,8 @@ 
SimplifyBooleanExprCheck::SimplifyBooleanExprCheck(StringRef Name,
 : ClangTidyCheck(Name, Context),
   ChainedConditionalReturn(Options.get("ChainedConditionalReturn", false)),
   ChainedConditionalAssignment(
-  Options.get("ChainedConditionalAssignment", false)) {}
+  Options.get("ChainedConditionalAssignment", false)),
+  SimplifyDeMorgan(Options.get("SimplifyDeMorgan", true)) {}
 
 static bool containsBoolLiteral(const Expr *E) {
   if (!E)
@@ -685,6 +755,196 @@ void 
SimplifyBooleanExprCheck::replaceWithAssignment(const ASTContext ,
 Range, Replacement);
 }
 
+/// Swaps a \c 

[PATCH] D125863: [clangd] Dont mark terminating PP-directives as skipped

2022-05-22 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

Potentially related issue: https://github.com/clangd/clangd/issues/773


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125863

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


[PATCH] D126158: [MLIR][GPU] Replace fdiv on fp16 with promoted (fp32) multiplication with reciprocal plus one (conditional) Newton iteration.

2022-05-22 Thread Christian Sigg via Phabricator via cfe-commits
csigg created this revision.
csigg added a reviewer: bkramer.
Herald added subscribers: bzcheeseman, mattd, gchakrabarti, awarzynski, 
sdasgup3, asavonic, wenzhicui, wrengr, Chia-hungDuan, dcaballe, cota, teijeong, 
rdzhabarov, tatianashp, msifontes, jurahul, Kayjukh, grosul1, Joonsoo, 
liufengdb, aartbik, mgester, arpith-jacob, antiagainst, shauheen, rriddle, 
mehdi_amini, sanjoy.google, hiraditya, jholewinski.
Herald added a reviewer: ftynse.
Herald added a reviewer: bondhugula.
Herald added a reviewer: ThomasRaoux.
Herald added a project: All.
csigg requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, stephenneuendorffer, 
nicolasvasilache, jdoerfert.
Herald added a reviewer: herhut.
Herald added projects: clang, MLIR, LLVM.

This is correct for all values, i.e. the same as promoting the division to fp32 
in the NVPTX backend. But it is faster (~10% in average, sometimes more) 
because:

- it performs less Newton iterations
- it avoids the slow path for e.g. denormals
- it allows reuse of the reciprocal for multiple divisions by the same divisor

Test program:

  #include 
  #include "cuda_fp16.h"
  
  // This is a variant of CUDA's own __hdiv which is fast than hdiv_promote 
below
  // and doesn't suffer from the perf cliff of div.rn.fp32 with 'special' 
values.
  __device__ half hdiv_newton(half a, half b) {
float fa = __half2float(a);
float fb = __half2float(b);
  
float rcp;
asm("{rcp.approx.ftz.f32 %0, %1;\n}" : "=f"(rcp) : "f"(fb));
  
float result = fa * rcp;
auto exponent = reinterpret_cast(result) & 0x7f80;
if (exponent != 0 && exponent != 0x7f80) {
  float err = __fmaf_rn(-fb, result, fa);
  result = __fmaf_rn(rcp, err, result);
}
  
return __float2half(result);
  }
  
  // Surprisingly, this is faster than CUDA's own __hdiv.
  __device__ half hdiv_promote(half a, half b) {
return __float2half(__half2float(a) / __half2float(b));
  }
  
  // This is an approximation that is accurate up to 1 ulp.
  __device__ half hdiv_approx(half a, half b) {
float fa = __half2float(a);
float fb = __half2float(b);
  
float result;
asm("{div.approx.ftz.f32 %0, %1, %2;\n}" : "=f"(result) : "f"(fa), "f"(fb));
return __float2half(result);
  }
  
  __global__ void CheckCorrectness() {
int i = threadIdx.x + blockIdx.x * blockDim.x;
half x = reinterpret_cast(i);
for (int j = 0; j < 65536; ++j) {
  half y = reinterpret_cast(j);
  half d1 = hdiv_newton(x, y);
  half d2 = hdiv_promote(x, y);
  auto s1 = reinterpret_cast(d1);
  auto s2 = reinterpret_cast(d2);
  if (s1 != s2) {
printf("%f (%u) / %f (%u), got %f (%hu), expected: %f (%hu)\n",
   __half2float(x), i, __half2float(y), j, __half2float(d1), s1,
   __half2float(d2), s2);
//__trap();
  }
}
  }
  
  __device__ half dst;
  
  __global__ void ProfileBuiltin(half x) {
#pragma unroll 1
for (int i = 0; i < 1000; ++i) {
  x = x / x;
}
dst = x;
  }
  
  __global__ void ProfilePromote(half x) {
#pragma unroll 1
for (int i = 0; i < 1000; ++i) {
  x = hdiv_promote(x, x);
}
dst = x;
  }
  
  __global__ void ProfileNewton(half x) {
#pragma unroll 1
for (int i = 0; i < 1000; ++i) {
  x = hdiv_newton(x, x);
}
dst = x;
  }
  
  __global__ void ProfileApprox(half x) {
#pragma unroll 1
for (int i = 0; i < 1000; ++i) {
  x = hdiv_approx(x, x);
}
dst = x;
  }
  
  int main() {
CheckCorrectness<<<256, 256>>>();
half one = __float2half(1.0f);
ProfileBuiltin<<<1, 1>>>(one);  // 1.001s
ProfilePromote<<<1, 1>>>(one);  // 0.560s
ProfileNewton<<<1, 1>>>(one);   // 0.508s
ProfileApprox<<<1, 1>>>(one);   // 0.304s
auto status = cudaDeviceSynchronize();
printf("%s\n", cudaGetErrorString(status));
  }


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126158

Files:
  clang/include/clang/Basic/BuiltinsNVPTX.def
  llvm/include/llvm/IR/IntrinsicsNVVM.td
  llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
  mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td
  mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
  mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm.mlir
  mlir/test/Dialect/LLVMIR/nvvm.mlir
  mlir/test/Target/LLVMIR/nvvmir.mlir

Index: mlir/test/Target/LLVMIR/nvvmir.mlir
===
--- mlir/test/Target/LLVMIR/nvvmir.mlir
+++ mlir/test/Target/LLVMIR/nvvmir.mlir
@@ -1,5 +1,6 @@
 // RUN: mlir-translate -mlir-to-llvmir %s | FileCheck %s
 
+// CHECK-LABEL: @nvvm_special_regs
 llvm.func @nvvm_special_regs() -> i32 {
   // CHECK: %1 = call i32 @llvm.nvvm.read.ptx.sreg.tid.x()
   %1 = nvvm.read.ptx.sreg.tid.x : i32
@@ -32,12 +33,21 @@
   llvm.return %1 : i32
 }
 
+// CHECK-LABEL: @nvvm_rcp
+llvm.func @nvvm_rcp(%0: f32) -> f32 {
+  // CHECK: call float @llvm.nvvm.rcp.approx.ftz.f
+  %1 = nvvm.rcp.approx.ftz.f %0 : f32
+  

[PATCH] D126132: [clang-format] Fix a crash on lambda trailing return type

2022-05-22 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

In D126132#3530076 , @curdeius wrote:

> LGTM. It seems it has landed already.

Yeah. I pushed it by mistake. :(


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126132

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


[PATCH] D126132: [clang-format] Fix a crash on lambda trailing return type

2022-05-22 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius accepted this revision.
curdeius added a comment.
This revision is now accepted and ready to land.

LGTM. It seems it has landed already.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126132

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