[clang] [clang][bytecode] Fix shifting negative values (PR #104663)

2024-08-18 Thread Timm Baeder via cfe-commits

tbaederr wrote:

This code is unused unless you're passing 
`-fexperimental-new-constant-interpreter`, is anyone using that in production 
code?

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


[clang] [libcxx] [Clang] Implement CWG2369 "Ordering between constraints and substitution" (PR #102857)

2024-08-18 Thread via cfe-commits


@@ -1122,6 +1122,154 @@ bool Sema::CheckInstantiatedFunctionTemplateConstraints(
  PointOfInstantiation, Satisfaction);
 }
 
+namespace {
+
+// We employ a TreeTransform because RAV couldn't recurse into a bunch of
+// Exprs e.g. SizeOfPackExpr, CXXFoldExpr, etc.
+// FIXME: Could we do the Decl instantiation as we substitute into
+// the constraint expressions?
+class InstantiateReferencedParameter
+: public TreeTransform {
+  const MultiLevelTemplateArgumentList &TemplateArgs;
+
+  llvm::SmallPtrSet InstantiatedDecls;
+
+  FunctionDecl *PrimaryTemplatedFunction;
+
+  using inherited = TreeTransform;
+
+  bool instantiateParameterToScope(ParmVarDecl *OldParm,
+   LocalInstantiationScope &Scope) {
+// The current context might have been changed by lambda expressions. So
+// resume it before we substitute into parameters.
+Sema::ContextRAII Context(SemaRef, PrimaryTemplatedFunction);
+std::optional NumExpansions;
+ParmVarDecl *NewParm = nullptr;
+unsigned IndexAdjustment = 0;
+if (OldParm->isParameterPack()) {
+  SmallVector Unexpanded;
+  TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
+  PackExpansionTypeLoc ExpansionTL = TL.castAs();
+  TypeLoc Pattern = ExpansionTL.getPatternLoc();
+  SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
+
+  assert(!Unexpanded.empty() &&
+ "A pack Decl doesn't contain anything unexpanded?");
+
+  bool ShouldExpand = false;
+  bool RetainExpansion = false;
+  std::optional OrigNumExpansions =
+  ExpansionTL.getTypePtr()->getNumExpansions();
+  NumExpansions = OrigNumExpansions;
+  if (SemaRef.CheckParameterPacksForExpansion(
+  ExpansionTL.getEllipsisLoc(), Pattern.getSourceRange(),
+  Unexpanded, TemplateArgs, ShouldExpand, RetainExpansion,
+  NumExpansions))
+return true;
+
+  assert(ShouldExpand && !RetainExpansion &&
+ "Shouldn't retain an expansion here!");
+  Scope.MakeInstantiatedLocalArgPack(OldParm);
+
+  for (unsigned I = 0; I != *NumExpansions; ++I) {
+Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
+ParmVarDecl *NewParm = SemaRef.SubstParmVarDecl(
+OldParm, TemplateArgs, /*indexAdjustment=*/IndexAdjustment++,
+NumExpansions, /*ExpectParameterPack=*/false,
+/*EvaluateConstraints=*/false);
+if (!NewParm)
+  return true;
+  }
+
+  return false;
+}
+NewParm = SemaRef.SubstParmVarDecl(OldParm, TemplateArgs,
+   /*indexAdjustment=*/IndexAdjustment,
+   std::nullopt,
+   /*ExpectParameterPack=*/false);
+if (!NewParm)
+  return true;
+Scope.InstantiatedLocal(OldParm, NewParm);
+return false;
+  }
+
+public:
+  InstantiateReferencedParameter(
+  Sema &SemaRef, const MultiLevelTemplateArgumentList &TemplateArgs,
+  FunctionDecl *PrimaryTemplatedFunction)
+  : inherited(SemaRef), TemplateArgs(TemplateArgs),
+PrimaryTemplatedFunction(PrimaryTemplatedFunction) {}
+
+  Decl *TransformDecl(SourceLocation Loc, Decl *D) {
+if (auto *PVD = dyn_cast_if_present(D);
+PVD && PVD->getDeclContext() == PrimaryTemplatedFunction &&
+!InstantiatedDecls.contains(PVD)) {
+  instantiateParameterToScope(PVD, *SemaRef.CurrentInstantiationScope);

cor3ntin wrote:

I did some research, this is 
https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#2770

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


[clang] [libcxx] [Clang] Implement CWG2369 "Ordering between constraints and substitution" (PR #102857)

2024-08-18 Thread via cfe-commits


@@ -1122,6 +1122,154 @@ bool Sema::CheckInstantiatedFunctionTemplateConstraints(
  PointOfInstantiation, Satisfaction);
 }
 
+namespace {
+
+// We employ a TreeTransform because RAV couldn't recurse into a bunch of
+// Exprs e.g. SizeOfPackExpr, CXXFoldExpr, etc.
+// FIXME: Could we do the Decl instantiation as we substitute into
+// the constraint expressions?
+class InstantiateReferencedParameter
+: public TreeTransform {
+  const MultiLevelTemplateArgumentList &TemplateArgs;
+
+  llvm::SmallPtrSet InstantiatedDecls;
+
+  FunctionDecl *PrimaryTemplatedFunction;
+
+  using inherited = TreeTransform;
+
+  bool instantiateParameterToScope(ParmVarDecl *OldParm,
+   LocalInstantiationScope &Scope) {
+// The current context might have been changed by lambda expressions. So
+// resume it before we substitute into parameters.
+Sema::ContextRAII Context(SemaRef, PrimaryTemplatedFunction);
+std::optional NumExpansions;
+ParmVarDecl *NewParm = nullptr;
+unsigned IndexAdjustment = 0;
+if (OldParm->isParameterPack()) {
+  SmallVector Unexpanded;
+  TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
+  PackExpansionTypeLoc ExpansionTL = TL.castAs();
+  TypeLoc Pattern = ExpansionTL.getPatternLoc();
+  SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
+
+  assert(!Unexpanded.empty() &&
+ "A pack Decl doesn't contain anything unexpanded?");
+
+  bool ShouldExpand = false;
+  bool RetainExpansion = false;
+  std::optional OrigNumExpansions =
+  ExpansionTL.getTypePtr()->getNumExpansions();
+  NumExpansions = OrigNumExpansions;
+  if (SemaRef.CheckParameterPacksForExpansion(
+  ExpansionTL.getEllipsisLoc(), Pattern.getSourceRange(),
+  Unexpanded, TemplateArgs, ShouldExpand, RetainExpansion,
+  NumExpansions))
+return true;
+
+  assert(ShouldExpand && !RetainExpansion &&
+ "Shouldn't retain an expansion here!");
+  Scope.MakeInstantiatedLocalArgPack(OldParm);
+
+  for (unsigned I = 0; I != *NumExpansions; ++I) {
+Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
+ParmVarDecl *NewParm = SemaRef.SubstParmVarDecl(
+OldParm, TemplateArgs, /*indexAdjustment=*/IndexAdjustment++,
+NumExpansions, /*ExpectParameterPack=*/false,
+/*EvaluateConstraints=*/false);
+if (!NewParm)
+  return true;
+  }
+
+  return false;
+}
+NewParm = SemaRef.SubstParmVarDecl(OldParm, TemplateArgs,
+   /*indexAdjustment=*/IndexAdjustment,
+   std::nullopt,
+   /*ExpectParameterPack=*/false);
+if (!NewParm)
+  return true;
+Scope.InstantiatedLocal(OldParm, NewParm);
+return false;
+  }
+
+public:
+  InstantiateReferencedParameter(
+  Sema &SemaRef, const MultiLevelTemplateArgumentList &TemplateArgs,
+  FunctionDecl *PrimaryTemplatedFunction)
+  : inherited(SemaRef), TemplateArgs(TemplateArgs),
+PrimaryTemplatedFunction(PrimaryTemplatedFunction) {}
+
+  Decl *TransformDecl(SourceLocation Loc, Decl *D) {
+if (auto *PVD = dyn_cast_if_present(D);
+PVD && PVD->getDeclContext() == PrimaryTemplatedFunction &&
+!InstantiatedDecls.contains(PVD)) {
+  instantiateParameterToScope(PVD, *SemaRef.CurrentInstantiationScope);

cor3ntin wrote:

See also https://github.com/cplusplus/CWG/issues/364 
https://cplusplus.github.io/CWG/issues/2769.html

https://gcc.godbolt.org/z/WrfG5Gxaj

I think instead of doing the substitution there, we want to do it where we 
check atomic constraints

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


[clang] [libcxx] [Clang] Implement CWG2369 "Ordering between constraints and substitution" (PR #102857)

2024-08-18 Thread via cfe-commits


@@ -1122,6 +1122,154 @@ bool Sema::CheckInstantiatedFunctionTemplateConstraints(
  PointOfInstantiation, Satisfaction);
 }
 
+namespace {
+
+// We employ a TreeTransform because RAV couldn't recurse into a bunch of
+// Exprs e.g. SizeOfPackExpr, CXXFoldExpr, etc.
+// FIXME: Could we do the Decl instantiation as we substitute into
+// the constraint expressions?
+class InstantiateReferencedParameter
+: public TreeTransform {
+  const MultiLevelTemplateArgumentList &TemplateArgs;
+
+  llvm::SmallPtrSet InstantiatedDecls;
+
+  FunctionDecl *PrimaryTemplatedFunction;
+
+  using inherited = TreeTransform;
+
+  bool instantiateParameterToScope(ParmVarDecl *OldParm,
+   LocalInstantiationScope &Scope) {
+// The current context might have been changed by lambda expressions. So
+// resume it before we substitute into parameters.
+Sema::ContextRAII Context(SemaRef, PrimaryTemplatedFunction);
+std::optional NumExpansions;
+ParmVarDecl *NewParm = nullptr;
+unsigned IndexAdjustment = 0;
+if (OldParm->isParameterPack()) {
+  SmallVector Unexpanded;
+  TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
+  PackExpansionTypeLoc ExpansionTL = TL.castAs();
+  TypeLoc Pattern = ExpansionTL.getPatternLoc();
+  SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
+
+  assert(!Unexpanded.empty() &&
+ "A pack Decl doesn't contain anything unexpanded?");
+
+  bool ShouldExpand = false;
+  bool RetainExpansion = false;
+  std::optional OrigNumExpansions =
+  ExpansionTL.getTypePtr()->getNumExpansions();
+  NumExpansions = OrigNumExpansions;
+  if (SemaRef.CheckParameterPacksForExpansion(
+  ExpansionTL.getEllipsisLoc(), Pattern.getSourceRange(),
+  Unexpanded, TemplateArgs, ShouldExpand, RetainExpansion,
+  NumExpansions))
+return true;
+
+  assert(ShouldExpand && !RetainExpansion &&
+ "Shouldn't retain an expansion here!");
+  Scope.MakeInstantiatedLocalArgPack(OldParm);
+
+  for (unsigned I = 0; I != *NumExpansions; ++I) {
+Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
+ParmVarDecl *NewParm = SemaRef.SubstParmVarDecl(
+OldParm, TemplateArgs, /*indexAdjustment=*/IndexAdjustment++,
+NumExpansions, /*ExpectParameterPack=*/false,
+/*EvaluateConstraints=*/false);
+if (!NewParm)
+  return true;
+  }
+
+  return false;
+}
+NewParm = SemaRef.SubstParmVarDecl(OldParm, TemplateArgs,
+   /*indexAdjustment=*/IndexAdjustment,
+   std::nullopt,
+   /*ExpectParameterPack=*/false);
+if (!NewParm)
+  return true;
+Scope.InstantiatedLocal(OldParm, NewParm);
+return false;
+  }
+
+public:
+  InstantiateReferencedParameter(
+  Sema &SemaRef, const MultiLevelTemplateArgumentList &TemplateArgs,
+  FunctionDecl *PrimaryTemplatedFunction)
+  : inherited(SemaRef), TemplateArgs(TemplateArgs),
+PrimaryTemplatedFunction(PrimaryTemplatedFunction) {}
+
+  Decl *TransformDecl(SourceLocation Loc, Decl *D) {
+if (auto *PVD = dyn_cast_if_present(D);
+PVD && PVD->getDeclContext() == PrimaryTemplatedFunction &&
+!InstantiatedDecls.contains(PVD)) {
+  instantiateParameterToScope(PVD, *SemaRef.CurrentInstantiationScope);

cor3ntin wrote:

@zygoloid

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


[clang] [Clang] warn on discarded [[nodiscard]] function results after casting in C (PR #104677)

2024-08-18 Thread Oleksandr T. via cfe-commits

a-tarasyuk wrote:

@cor3ntin Do you mean casting to `void` or declaring a `void` function?



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


[clang] [Clang] warn on discarded [[nodiscard]] function results after casting in C (PR #104677)

2024-08-18 Thread via cfe-commits

cor3ntin wrote:

Casting to void

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


[clang] [Clang] warn on discarded [[nodiscard]] function results after casting in C (PR #104677)

2024-08-18 Thread via cfe-commits


@@ -54,3 +54,9 @@ void test_missiles(void) {
   launch_missiles();
 }
 
+[[nodiscard]] int f3();
+
+void f4() {

cor3ntin wrote:

```suggestion
void GH104391(void) {
```

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


[clang] [clang][bytecode] Support ObjC blocks (PR #104551)

2024-08-18 Thread Timm Baeder via cfe-commits

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


[clang] [Clang] warn on discarded [[nodiscard]] function results after casting in C (PR #104677)

2024-08-18 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/104677

>From cd7ce740464c9c46ab231cf773fd1cf28e3495eb Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sat, 17 Aug 2024 19:43:45 +0300
Subject: [PATCH 1/2] [Clang] warn on discarded [[nodiscard]] function results
 after casting in C

---
 clang/docs/ReleaseNotes.rst | 2 ++
 clang/lib/Sema/SemaStmt.cpp | 3 ++-
 clang/test/Sema/c2x-nodiscard.c | 6 ++
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ffdd063ec99037..c8c6a98264b3a2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -214,6 +214,8 @@ Improvements to Clang's diagnostics
 
 - Clang now diagnoses the use of ``main`` in an ``extern`` context as invalid 
according to [basic.start.main] p3. Fixes #GH101512.
 
+- Clang now diagnoses when the result of a [[nodiscard]] function is discarded 
after being cast in C. Fixes #GH104391.
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index d283eaa511011b..ba681671eb3290 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -281,7 +281,8 @@ void Sema::DiagnoseUnusedExprResult(const Stmt *S, unsigned 
DiagID) {
   E = WarnExpr;
   if (const auto *Cast = dyn_cast(E))
 if (Cast->getCastKind() == CK_NoOp ||
-Cast->getCastKind() == CK_ConstructorConversion)
+Cast->getCastKind() == CK_ConstructorConversion ||
+Cast->getCastKind() == CK_IntegralCast)
   E = Cast->getSubExpr()->IgnoreImpCasts();
 
   if (const CallExpr *CE = dyn_cast(E)) {
diff --git a/clang/test/Sema/c2x-nodiscard.c b/clang/test/Sema/c2x-nodiscard.c
index cb33c0c242e7db..8b48fe8118dfe7 100644
--- a/clang/test/Sema/c2x-nodiscard.c
+++ b/clang/test/Sema/c2x-nodiscard.c
@@ -54,3 +54,9 @@ void test_missiles(void) {
   launch_missiles();
 }
 
+[[nodiscard]] int f3();
+
+void f4() {
+#define M (unsigned int) f3()
+  M; // expected-warning {{ignoring return value of function declared with 
'nodiscard' attribute}}
+}

>From d1b3369f0e7dab62710a79a611a920aee5d2c0d8 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sun, 18 Aug 2024 10:50:53 +0300
Subject: [PATCH 2/2] rename test

---
 clang/test/Sema/c2x-nodiscard.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Sema/c2x-nodiscard.c b/clang/test/Sema/c2x-nodiscard.c
index 8b48fe8118dfe7..f8b0567366465d 100644
--- a/clang/test/Sema/c2x-nodiscard.c
+++ b/clang/test/Sema/c2x-nodiscard.c
@@ -56,7 +56,7 @@ void test_missiles(void) {
 
 [[nodiscard]] int f3();
 
-void f4() {
+void GH104391() {
 #define M (unsigned int) f3()
   M; // expected-warning {{ignoring return value of function declared with 
'nodiscard' attribute}}
 }

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


[clang] [Clang] warn on discarded [[nodiscard]] function results after casting in C (PR #104677)

2024-08-18 Thread Oleksandr T. via cfe-commits


@@ -54,3 +54,9 @@ void test_missiles(void) {
   launch_missiles();
 }
 
+[[nodiscard]] int f3();
+
+void f4() {

a-tarasyuk wrote:

@cor3ntin I've updated the test. Thanks for the review.

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


[clang] [Clang] warn on discarded [[nodiscard]] function results after casting in C (PR #104677)

2024-08-18 Thread via cfe-commits

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


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


[clang] [Clang] Check constraints for an explicit instantiation of a member function (PR #104438)

2024-08-18 Thread Mital Ashok via cfe-commits


@@ -5663,6 +5663,8 @@ def err_explicit_instantiation_internal_linkage : Error<
 def err_explicit_instantiation_not_known : Error<
   "explicit instantiation of %0 does not refer to a function template, "
   "variable template, member function, member class, or static data member">;
+def err_explicit_instantiation_no_candidate : Error<
+"no candidate for explicit instantiation of %0">;

MitalAshok wrote:

There's notes in the example above, but yeah no reason to change everything in 
this PR when it seems unrelated.  
This message should say "no *viable* candidate" (or "no matching function").

Also you should be able to restructure stuff so that template/non template 
member functions can use the same overload set, so would naturally use the same 
diagnostic. For example, this:

```c++
template
struct A {
  template
  void f() requires(false);
  void f() requires(false);
};
template void A::f();
```

Should note both candidates, when I think your change means it only notes the 
non-template candidate (and removing the non-template function means it notes 
the template one, which seems strange)

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


[clang] [Clang] Do not allow `[[clang::lifetimebound]]` on explicit object member functions (PR #96113)

2024-08-18 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok updated 
https://github.com/llvm/llvm-project/pull/96113

>From 453fea9fee85aef61c449761f24b0accecf03d29 Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Wed, 19 Jun 2024 21:03:34 +0100
Subject: [PATCH 1/2] [Clang] Do not allow `[[clang::lifetimebound]]` on
 explicit object member functions

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td |  5 +++--
 clang/lib/Sema/SemaDecl.cpp  | 11 +--
 clang/test/SemaCXX/attr-lifetimebound.cpp|  3 ++-
 3 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8a92973236ddbd..94be9c874afe97 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10066,8 +10066,9 @@ def warn_null_ret : Warning<
   InGroup;
 
 def err_lifetimebound_no_object_param : Error<
-  "'lifetimebound' attribute cannot be applied; %select{static |non-}0member "
-  "function has no implicit object parameter">;
+  "'lifetimebound' attribute cannot be applied; "
+  "%select{non-|static |explicit object }0"
+  "member function has no implicit object parameter">;
 def err_lifetimebound_ctor_dtor : Error<
   "'lifetimebound' attribute cannot be applied to a "
   "%select{constructor|destructor}0">;
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index d19a16cf2ba150..61a465ca55c5c7 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -6938,9 +6938,16 @@ static void checkAttributesAfterMerging(Sema &S, 
NamedDecl &ND) {
   // by applying it to the function type.
   if (const auto *A = ATL.getAttrAs()) {
 const auto *MD = dyn_cast(FD);
-if (!MD || MD->isStatic()) {
+int NoImplicitObjectError = -1;
+if (!MD)
+  NoImplicitObjectError = 0;
+else if (MD->isStatic())
+  NoImplicitObjectError = 1;
+else if (MD->isExplicitObjectMemberFunction())
+  NoImplicitObjectError = 2;
+if (NoImplicitObjectError != -1) {
   S.Diag(A->getLocation(), diag::err_lifetimebound_no_object_param)
-  << !MD << A->getRange();
+  << NoImplicitObjectError << A->getRange();
 } else if (isa(MD) || isa(MD)) {
   S.Diag(A->getLocation(), diag::err_lifetimebound_ctor_dtor)
   << isa(MD) << A->getRange();
diff --git a/clang/test/SemaCXX/attr-lifetimebound.cpp 
b/clang/test/SemaCXX/attr-lifetimebound.cpp
index 7db0a4d64d2596..f4ca840cb276f9 100644
--- a/clang/test/SemaCXX/attr-lifetimebound.cpp
+++ b/clang/test/SemaCXX/attr-lifetimebound.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++2a -verify %s
+// RUN: %clang_cc1 -std=c++23 -verify %s
 
 namespace usage_invalid {
   // FIXME: Should we diagnose a void return type?
@@ -9,6 +9,7 @@ namespace usage_invalid {
 A() [[clang::lifetimebound]]; // expected-error {{cannot be applied to a 
constructor}}
 ~A() [[clang::lifetimebound]]; // expected-error {{cannot be applied to a 
destructor}}
 static int *static_class_member() [[clang::lifetimebound]]; // 
expected-error {{static member function has no implicit object parameter}}
+int *explicit_object(this A&) [[clang::lifetimebound]]; // expected-error 
{{explicit object member function has no implicit object parameter}}
 int not_function [[clang::lifetimebound]]; // expected-error {{only 
applies to parameters and implicit object parameters}}
 int [[clang::lifetimebound]] also_not_function; // expected-error {{cannot 
be applied to types}}
   };

>From a8295b7e294fbf13006d182a0f8ee02a7921370e Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Sun, 18 Aug 2024 09:29:10 +0100
Subject: [PATCH 2/2] Add release note

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

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ffdd063ec99037..556d1ceae7a4e9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -189,6 +189,9 @@ Attribute Changes in Clang
 - The ``hybrid_patchable`` attribute is now supported on ARM64EC targets. It 
can be used to specify
   that a function requires an additional x86-64 thunk, which may be patched at 
runtime.
 
+- ``[[clang::lifetimebound]]`` is now explicitly disallowed on explicit object 
member functions
+  where they were previously silently ignored.
+
 Improvements to Clang's diagnostics
 ---
 

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


[clang] [Clang] `constexpr` builtin floating point classification / comparison functions (PR #94118)

2024-08-18 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok updated 
https://github.com/llvm/llvm-project/pull/94118

>From ed1c00ee4474a626965290f2d16aaaf0f4519ec9 Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Sat, 1 Jun 2024 17:45:21 +0100
Subject: [PATCH 1/5] constexpr __builtin_signbit

---
 clang/include/clang/Basic/Builtins.td  |  8 +---
 clang/lib/AST/ExprConstant.cpp |  8 
 clang/lib/AST/Interp/InterpBuiltin.cpp | 15 +++
 clang/test/Sema/constant-builtins-2.c  | 13 +
 4 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 11982af3fa609b..f784711bc04dc1 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -646,19 +646,21 @@ def IsFPClass : Builtin {
 def Signbit : Builtin {
   let Spellings = ["__builtin_signbit"];
   let Attributes = [FunctionWithBuiltinPrefix, NoThrow, Const,
-CustomTypeChecking];
+CustomTypeChecking, Constexpr];
   let Prototype = "int(...)";
 }
 
 def SignbitF : Builtin {
   let Spellings = ["__builtin_signbitf"];
-  let Attributes = [FunctionWithBuiltinPrefix, NoThrow, Const];
+  let Attributes = [FunctionWithBuiltinPrefix, NoThrow, Const,
+Constexpr];
   let Prototype = "int(float)";
 }
 
 def SignbitL : Builtin {
   let Spellings = ["__builtin_signbitl"];
-  let Attributes = [FunctionWithBuiltinPrefix, NoThrow, Const];
+  let Attributes = [FunctionWithBuiltinPrefix, NoThrow, Const,
+Constexpr];
   let Prototype = "int(long double)";
 }
 
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index f1aa19e4409e15..b4de743c4d95bf 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -12650,6 +12650,14 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
Success(Val.isZero() ? 1 : 0, E);
   }
 
+  case Builtin::BI__builtin_signbit:
+  case Builtin::BI__builtin_signbitf:
+  case Builtin::BI__builtin_signbitl: {
+APFloat Val(0.0);
+return EvaluateFloat(E->getArg(0), Val, Info) &&
+   Success(Val.isNegative() ? 1 : 0, E);
+  }
+
   case Builtin::BI__builtin_issignaling: {
 APFloat Val(0.0);
 return EvaluateFloat(E->getArg(0), Val, Info) &&
diff --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index 00206d09c113d9..4ca92e66b29129 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -430,6 +430,15 @@ static bool interp__builtin_iszero(InterpState &S, CodePtr 
OpPC,
   return true;
 }
 
+static bool interp__builtin_signbit(InterpState &S, CodePtr OpPC,
+const InterpFrame *Frame, const Function 
*F,
+const CallExpr *Call) {
+  const Floating &Arg = S.Stk.peek();
+
+  pushInteger(S, Arg.isNegative(), Call->getType());
+  return true;
+}
+
 /// First parameter to __builtin_isfpclass is the floating value, the
 /// second one is an integral value.
 static bool interp__builtin_isfpclass(InterpState &S, CodePtr OpPC,
@@ -1214,6 +1223,12 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, 
const Function *F,
 if (!interp__builtin_iszero(S, OpPC, Frame, F, Call))
   return false;
 break;
+  case Builtin::BI__builtin_signbit:
+  case Builtin::BI__builtin_signbitf:
+  case Builtin::BI__builtin_signbitl:
+if (!interp__builtin_signbit(S, OpPC, Frame, F, Call))
+  return false;
+break;
   case Builtin::BI__builtin_isfpclass:
 if (!interp__builtin_isfpclass(S, OpPC, Frame, F, Call))
   return false;
diff --git a/clang/test/Sema/constant-builtins-2.c 
b/clang/test/Sema/constant-builtins-2.c
index a60a1f16a45874..fca4ac2a26898f 100644
--- a/clang/test/Sema/constant-builtins-2.c
+++ b/clang/test/Sema/constant-builtins-2.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -fexperimental-new-constant-interpreter 
-verify %s
 
 // Math stuff
 
@@ -204,6 +205,18 @@ char isfpclass_snan_1   
[!__builtin_isfpclass(__builtin_nans(""), 0x0002) ? 1 :
 char isfpclass_snan_2   [__builtin_isfpclass(__builtin_nansl(""), 0x0207) ? 1 
: -1]; // ~fcFinite
 char isfpclass_snan_3   [!__builtin_isfpclass(__builtin_nans(""), 0x01F8) ? 1 
: -1]; // fcFinite
 
+__extension__ _Static_assert(
+  !__builtin_signbit(1.0) && __builtin_signbit(-1.0) && 
!__builtin_signbit(0.0) && __builtin_signbit(-0.0) &&
+  !__builtin_signbitf(1.0f) && __builtin_signbitf(-1.0f) && 
!__builtin_signbitf(0.0f) && __builtin_signbitf(-0.0f) &&
+  !__builtin_signbitl(1.0L) && __builtin_signbitf(-1.0L) && 
!__builtin_signbitf(0.0L) && __builtin_signbitf(-0.0L) &&
+  !__builtin_signbit(1.0f) && __builtin_signbit(-1.0f) && 
!__builtin_signbit(0.0f) && __builtin_signbit(-0.0f) &&
+  !__builtin_signbit(1.0L) && __builtin_signbit(-1.0L) && 
!__builtin_signbit(0.0L) && __builtin_signbit(-0

[clang-tools-extra] [clang-tidy] Consider `readability-uppercase-literal-suffix` when dealing with `readability-implicit-bool-conversion`. (PR #104694)

2024-08-18 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp requested changes to this pull request.

We have explicitly said in the other PR that we do *not* want checks to depend 
on each other. Checks must remain independent of each other.

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


[clang-tools-extra] [clang-tidy] Consider `readability-uppercase-literal-suffix` when dealing with `readability-implicit-bool-conversion`. (PR #104694)

2024-08-18 Thread Carlos Galvez via cfe-commits

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


[clang-tools-extra] [clang-tidy] Consider `readability-uppercase-literal-suffix` when dealing with `readability-implicit-bool-conversion`. (PR #104694)

2024-08-18 Thread Carlos Galvez via cfe-commits

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


[clang-tools-extra] [clang-tidy] Consider `readability-uppercase-literal-suffix` when dealing with `readability-implicit-bool-conversion`. (PR #104694)

2024-08-18 Thread via cfe-commits

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


[clang-tools-extra] [clang-tidy] Consider `readability-uppercase-literal-suffix` when dealing with `readability-implicit-bool-conversion`. (PR #104694)

2024-08-18 Thread via cfe-commits

c8ef wrote:

I apologize for not noticing this earlier.

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


[clang] [Clang] `constexpr` builtin floating point classification / comparison functions (PR #94118)

2024-08-18 Thread Mital Ashok via cfe-commits

MitalAshok wrote:

@Endilll This should be done, just needs to be merged

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


[clang-tools-extra] [clang-tidy] Consider `readability-uppercase-literal-suffix` when dealing with `readability-implicit-bool-conversion`. (PR #104694)

2024-08-18 Thread Carlos Galvez via cfe-commits

carlosgalvezp wrote:

No problem, thanks for the initiative! We should probably clarify this in the 
developer documentation.

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


[clang] 1125934 - [Clang] `constexpr` builtin floating point classification / comparison functions (#94118)

2024-08-18 Thread via cfe-commits

Author: Mital Ashok
Date: 2024-08-18T13:50:42+04:00
New Revision: 11259343593043c77678b59d420159fcd147a858

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

LOG: [Clang] `constexpr` builtin floating point classification / comparison 
functions (#94118)

As per [P0533R9](https://wg21.link/P0533R9), the corresponding C++
`[c.math.fpclass]` standard library functions for the C macros are now
`constexpr`.

The only classification function that wasn't already `constexpr` was
`__builtin_signbit`.
The floating point comparison functions `__builtin_isgreater`,
`__builtin_isgreaterequal`, `__builtin_isless`, `__builtin_islessequal`,
`__builtin_islessgreater` and `__builtin_isunordered` are now
`constexpr`.
The C23 macro `iseqsig` is not currently supported because
`__bulitin_iseqsig` doesn't exist yet (and C++26 is still currently
based on C18).

This also allows them to be constant folded in C, matching the behaviour
of GCC.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/Builtins.td
clang/lib/AST/ByteCode/InterpBuiltin.cpp
clang/lib/AST/ExprConstant.cpp
clang/test/Analysis/builtin_signbit.cpp
clang/test/Sema/constant-builtins-2.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ffdd063ec99037..12a3707db8a39f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -161,6 +161,10 @@ C23 Feature Support
 Non-comprehensive list of changes in this release
 -
 
+- The floating point comparison builtins (``__builtin_isgreater``,
+  ``__builtin_isgreaterequal``, ``__builtin_isless``, etc.) and
+  ``__builtin_signbit`` can now be used in constant expressions.
+
 New Compiler Flags
 --
 

diff  --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 0a874d8638df43..036366cdadf4aa 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -533,42 +533,42 @@ def BuiltinComplex : Builtin {
 def IsGreater : Builtin {
   let Spellings = ["__builtin_isgreater"];
   let Attributes = [FunctionWithBuiltinPrefix, NoThrow, Const,
-CustomTypeChecking];
+CustomTypeChecking, Constexpr];
   let Prototype = "int(...)";
 }
 
 def IsGreaterEqual : Builtin {
   let Spellings = ["__builtin_isgreaterequal"];
   let Attributes = [FunctionWithBuiltinPrefix, NoThrow, Const,
-CustomTypeChecking];
+CustomTypeChecking, Constexpr];
   let Prototype = "int(...)";
 }
 
 def IsLess : Builtin {
   let Spellings = ["__builtin_isless"];
   let Attributes = [FunctionWithBuiltinPrefix, NoThrow, Const,
-CustomTypeChecking];
+CustomTypeChecking, Constexpr];
   let Prototype = "int(...)";
 }
 
 def IsLessEqual : Builtin {
   let Spellings = ["__builtin_islessequal"];
   let Attributes = [FunctionWithBuiltinPrefix, NoThrow, Const,
-CustomTypeChecking];
+CustomTypeChecking, Constexpr];
   let Prototype = "int(...)";
 }
 
 def IsLessGreater : Builtin {
   let Spellings = ["__builtin_islessgreater"];
   let Attributes = [FunctionWithBuiltinPrefix, NoThrow, Const,
-CustomTypeChecking];
+CustomTypeChecking, Constexpr];
   let Prototype = "int(...)";
 }
 
 def IsUnordered : Builtin {
   let Spellings = ["__builtin_isunordered"];
   let Attributes = [FunctionWithBuiltinPrefix, NoThrow, Const,
-CustomTypeChecking];
+CustomTypeChecking, Constexpr];
   let Prototype = "int(...)";
 }
 
@@ -646,19 +646,21 @@ def IsFPClass : Builtin {
 def Signbit : Builtin {
   let Spellings = ["__builtin_signbit"];
   let Attributes = [FunctionWithBuiltinPrefix, NoThrow, Const,
-CustomTypeChecking];
+CustomTypeChecking, Constexpr];
   let Prototype = "int(...)";
 }
 
 def SignbitF : Builtin {
   let Spellings = ["__builtin_signbitf"];
-  let Attributes = [FunctionWithBuiltinPrefix, NoThrow, Const];
+  let Attributes = [FunctionWithBuiltinPrefix, NoThrow, Const,
+Constexpr];
   let Prototype = "int(float)";
 }
 
 def SignbitL : Builtin {
   let Spellings = ["__builtin_signbitl"];
-  let Attributes = [FunctionWithBuiltinPrefix, NoThrow, Const];
+  let Attributes = [FunctionWithBuiltinPrefix, NoThrow, Const,
+Constexpr];
   let Prototype = "int(long double)";
 }
 

diff  --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index c3370e2e5286e0..26abf582051067 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ 

[clang] [Clang] `constexpr` builtin floating point classification / comparison functions (PR #94118)

2024-08-18 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [Clang] warn on discarded [[nodiscard]] function results after casting in C (PR #104677)

2024-08-18 Thread Oleksandr T. via cfe-commits


@@ -54,3 +54,9 @@ void test_missiles(void) {
   launch_missiles();
 }
 
+[[nodiscard]] int f3();
+
+void f4() {

a-tarasyuk wrote:

@cor3ntin could you merge it once the CI passes? Thanks

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


[clang] [clang] Be const-correct with all uses of `Module *`. (PR #93493)

2024-08-18 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

@davidstone Do you plan to get back to this PR?

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


[clang] [clang][NFC] Un-constify `MultiLevelTemplateArgumentList` (PR #104687)

2024-08-18 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [Clang] Check constraints for an explicit instantiation of a member function (PR #104438)

2024-08-18 Thread via cfe-commits

https://github.com/cor3ntin updated 
https://github.com/llvm/llvm-project/pull/104438

>From e3f210f4105d9eef5f34af893b5af81ac94e250b Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Thu, 15 Aug 2024 15:46:43 +0200
Subject: [PATCH 1/2] [Clang] Check constraints for an explicit instantiation
 of a member function

Fixes #46029

Because there may be multiple constrained function of the same type,
we need to perform overload resolution to find the best viable function
to specialize.
---
 clang/docs/ReleaseNotes.rst   |  3 +-
 .../clang/Basic/DiagnosticSemaKinds.td|  2 +
 clang/lib/Sema/SemaTemplate.cpp   | 64 +++
 .../explicit-instantiation-cxx20.cpp  | 40 
 4 files changed, 95 insertions(+), 14 deletions(-)
 create mode 100644 clang/test/SemaTemplate/explicit-instantiation-cxx20.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f5696d6ce15dc7..a7d49460b4bb5d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -73,7 +73,7 @@ C++ Specific Potentially Breaking Changes
 template <> // error: extraneous template head
 template 
 void f();
-
+
 ABI Changes in This Version
 ---
 
@@ -254,6 +254,7 @@ Bug Fixes to C++ Support
   specialization of a conversion function template.
 - Correctly diagnose attempts to use a concept name in its own definition;
   A concept name is introduced to its scope sooner to match the C++ standard. 
(#GH55875)
+- Correctly check constraints of explicit instantiations of member functions. 
(#GH46029)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index da2f939067bfab..d5225783115892 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5663,6 +5663,8 @@ def err_explicit_instantiation_internal_linkage : Error<
 def err_explicit_instantiation_not_known : Error<
   "explicit instantiation of %0 does not refer to a function template, "
   "variable template, member function, member class, or static data member">;
+def err_explicit_instantiation_no_candidate : Error<
+"no candidate for explicit instantiation of %0">;
 def note_explicit_instantiation_here : Note<
   "explicit instantiation refers here">;
 def err_explicit_instantiation_data_member_not_instantiated : Error<
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 25585f683752ac..0afe6064bab185 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -10124,8 +10124,9 @@ DeclResult Sema::ActOnExplicitInstantiation(Scope *S,
   //  instantiated from the member definition associated with its class
   //  template.
   UnresolvedSet<8> TemplateMatches;
-  FunctionDecl *NonTemplateMatch = nullptr;
-  TemplateSpecCandidateSet FailedCandidates(D.getIdentifierLoc());
+  OverloadCandidateSet NonTemplateMatches(D.getBeginLoc(),
+  OverloadCandidateSet::CSK_Normal);
+  TemplateSpecCandidateSet FailedTemplateCandidates(D.getIdentifierLoc());
   for (LookupResult::iterator P = Previous.begin(), PEnd = Previous.end();
P != PEnd; ++P) {
 NamedDecl *Prev = *P;
@@ -10137,9 +10138,18 @@ DeclResult Sema::ActOnExplicitInstantiation(Scope *S,
   if (Method->getPrimaryTemplate()) {
 TemplateMatches.addDecl(Method, P.getAccess());
   } else {
-// FIXME: Can this assert ever happen?  Needs a test.
-assert(!NonTemplateMatch && "Multiple NonTemplateMatches");
-NonTemplateMatch = Method;
+OverloadCandidate &C = NonTemplateMatches.addCandidate();
+C.FoundDecl = P.getPair();
+C.Function = Method;
+C.Viable = true;
+ConstraintSatisfaction S;
+if (Method->getTrailingRequiresClause() &&
+(CheckFunctionConstraints(Method, S, D.getIdentifierLoc(),
+  /*ForOverloadResolution=*/true) ||
+ !S.IsSatisfied)) {
+  C.Viable = false;
+  C.FailureKind = ovl_fail_constraints_not_satisfied;
+}
   }
 }
   }
@@ -10149,16 +10159,16 @@ DeclResult Sema::ActOnExplicitInstantiation(Scope *S,
 if (!FunTmpl)
   continue;
 
-TemplateDeductionInfo Info(FailedCandidates.getLocation());
+TemplateDeductionInfo Info(FailedTemplateCandidates.getLocation());
 FunctionDecl *Specialization = nullptr;
 if (TemplateDeductionResult TDK = DeduceTemplateArguments(
 FunTmpl, (HasExplicitTemplateArgs ? &TemplateArgs : nullptr), R,
 Specialization, Info);
 TDK != TemplateDeductionResult::Success) {
   // Keep track of almost-matches.
-  FailedCandidates.addCandidate()
-  .set(P.getPair(), FunTmpl->ge

[clang] [Clang] Check constraints for an explicit instantiation of a member function (PR #104438)

2024-08-18 Thread via cfe-commits


@@ -5663,6 +5663,8 @@ def err_explicit_instantiation_internal_linkage : Error<
 def err_explicit_instantiation_not_known : Error<
   "explicit instantiation of %0 does not refer to a function template, "
   "variable template, member function, member class, or static data member">;
+def err_explicit_instantiation_no_candidate : Error<
+"no candidate for explicit instantiation of %0">;

cor3ntin wrote:

Agreed, but that's a bigger refactor

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


[clang] [libcxx] [Clang] Implement CWG2369 "Ordering between constraints and substitution" (PR #102857)

2024-08-18 Thread Younan Zhang via cfe-commits


@@ -1122,6 +1122,154 @@ bool Sema::CheckInstantiatedFunctionTemplateConstraints(
  PointOfInstantiation, Satisfaction);
 }
 
+namespace {
+
+// We employ a TreeTransform because RAV couldn't recurse into a bunch of
+// Exprs e.g. SizeOfPackExpr, CXXFoldExpr, etc.
+// FIXME: Could we do the Decl instantiation as we substitute into
+// the constraint expressions?
+class InstantiateReferencedParameter
+: public TreeTransform {
+  const MultiLevelTemplateArgumentList &TemplateArgs;
+
+  llvm::SmallPtrSet InstantiatedDecls;
+
+  FunctionDecl *PrimaryTemplatedFunction;
+
+  using inherited = TreeTransform;
+
+  bool instantiateParameterToScope(ParmVarDecl *OldParm,
+   LocalInstantiationScope &Scope) {
+// The current context might have been changed by lambda expressions. So
+// resume it before we substitute into parameters.
+Sema::ContextRAII Context(SemaRef, PrimaryTemplatedFunction);
+std::optional NumExpansions;
+ParmVarDecl *NewParm = nullptr;
+unsigned IndexAdjustment = 0;
+if (OldParm->isParameterPack()) {
+  SmallVector Unexpanded;
+  TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
+  PackExpansionTypeLoc ExpansionTL = TL.castAs();
+  TypeLoc Pattern = ExpansionTL.getPatternLoc();
+  SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
+
+  assert(!Unexpanded.empty() &&
+ "A pack Decl doesn't contain anything unexpanded?");
+
+  bool ShouldExpand = false;
+  bool RetainExpansion = false;
+  std::optional OrigNumExpansions =
+  ExpansionTL.getTypePtr()->getNumExpansions();
+  NumExpansions = OrigNumExpansions;
+  if (SemaRef.CheckParameterPacksForExpansion(
+  ExpansionTL.getEllipsisLoc(), Pattern.getSourceRange(),
+  Unexpanded, TemplateArgs, ShouldExpand, RetainExpansion,
+  NumExpansions))
+return true;
+
+  assert(ShouldExpand && !RetainExpansion &&
+ "Shouldn't retain an expansion here!");
+  Scope.MakeInstantiatedLocalArgPack(OldParm);
+
+  for (unsigned I = 0; I != *NumExpansions; ++I) {
+Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
+ParmVarDecl *NewParm = SemaRef.SubstParmVarDecl(
+OldParm, TemplateArgs, /*indexAdjustment=*/IndexAdjustment++,
+NumExpansions, /*ExpectParameterPack=*/false,
+/*EvaluateConstraints=*/false);
+if (!NewParm)
+  return true;
+  }
+
+  return false;
+}
+NewParm = SemaRef.SubstParmVarDecl(OldParm, TemplateArgs,
+   /*indexAdjustment=*/IndexAdjustment,
+   std::nullopt,
+   /*ExpectParameterPack=*/false);
+if (!NewParm)
+  return true;
+Scope.InstantiatedLocal(OldParm, NewParm);
+return false;
+  }
+
+public:
+  InstantiateReferencedParameter(
+  Sema &SemaRef, const MultiLevelTemplateArgumentList &TemplateArgs,
+  FunctionDecl *PrimaryTemplatedFunction)
+  : inherited(SemaRef), TemplateArgs(TemplateArgs),
+PrimaryTemplatedFunction(PrimaryTemplatedFunction) {}
+
+  Decl *TransformDecl(SourceLocation Loc, Decl *D) {
+if (auto *PVD = dyn_cast_if_present(D);
+PVD && PVD->getDeclContext() == PrimaryTemplatedFunction &&
+!InstantiatedDecls.contains(PVD)) {
+  instantiateParameterToScope(PVD, *SemaRef.CurrentInstantiationScope);

zyn0217 wrote:

> I think instead of doing the substitution there, we want to do it where we 
> check atomic constraints

Err.. I just tried and I realized there will be much more complexity then:
IIUC we need to move the substitution to `TemplateInstantiator` which just 
delegates `TryExpandParameterPacks` to `Sema.CheckParameterPacksForExpansion`, 
so for a pack expansion, e.g.

```cpp
void f18(auto... x)
  requires(sizeof...(x) == 2);

void foo() {
  f18('c');
}
```

We would end up calling `CurrentInstantiationScope->findInstantiationOf` inside 
`CheckParameterPacksForExpansion` when trying to transform the `sizeof...` 
expression. Unfortunately we don't have a chance to instantiate `x` between the 
transform of the expression starts and the `findInstantiation` call, therefore 
we would crash.

One alternative is to duplicate much of the `CheckParameterPacksForExpansion` 
to `TryExpandParameterPacks`, and we instantiate the Decls there. But I feel 
that would clutter up everything and we probably couldn't accept the 
maintenance cost.

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


[clang] [libcxx] [Clang] Implement CWG2369 "Ordering between constraints and substitution" (PR #102857)

2024-08-18 Thread Younan Zhang via cfe-commits


@@ -1122,6 +1122,154 @@ bool Sema::CheckInstantiatedFunctionTemplateConstraints(
  PointOfInstantiation, Satisfaction);
 }
 
+namespace {
+
+// We employ a TreeTransform because RAV couldn't recurse into a bunch of
+// Exprs e.g. SizeOfPackExpr, CXXFoldExpr, etc.
+// FIXME: Could we do the Decl instantiation as we substitute into
+// the constraint expressions?
+class InstantiateReferencedParameter
+: public TreeTransform {
+  const MultiLevelTemplateArgumentList &TemplateArgs;
+
+  llvm::SmallPtrSet InstantiatedDecls;
+
+  FunctionDecl *PrimaryTemplatedFunction;
+
+  using inherited = TreeTransform;
+
+  bool instantiateParameterToScope(ParmVarDecl *OldParm,
+   LocalInstantiationScope &Scope) {
+// The current context might have been changed by lambda expressions. So
+// resume it before we substitute into parameters.
+Sema::ContextRAII Context(SemaRef, PrimaryTemplatedFunction);
+std::optional NumExpansions;
+ParmVarDecl *NewParm = nullptr;
+unsigned IndexAdjustment = 0;
+if (OldParm->isParameterPack()) {
+  SmallVector Unexpanded;
+  TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
+  PackExpansionTypeLoc ExpansionTL = TL.castAs();
+  TypeLoc Pattern = ExpansionTL.getPatternLoc();
+  SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
+
+  assert(!Unexpanded.empty() &&
+ "A pack Decl doesn't contain anything unexpanded?");
+
+  bool ShouldExpand = false;
+  bool RetainExpansion = false;
+  std::optional OrigNumExpansions =
+  ExpansionTL.getTypePtr()->getNumExpansions();
+  NumExpansions = OrigNumExpansions;
+  if (SemaRef.CheckParameterPacksForExpansion(
+  ExpansionTL.getEllipsisLoc(), Pattern.getSourceRange(),
+  Unexpanded, TemplateArgs, ShouldExpand, RetainExpansion,
+  NumExpansions))
+return true;
+
+  assert(ShouldExpand && !RetainExpansion &&
+ "Shouldn't retain an expansion here!");
+  Scope.MakeInstantiatedLocalArgPack(OldParm);
+
+  for (unsigned I = 0; I != *NumExpansions; ++I) {
+Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
+ParmVarDecl *NewParm = SemaRef.SubstParmVarDecl(
+OldParm, TemplateArgs, /*indexAdjustment=*/IndexAdjustment++,
+NumExpansions, /*ExpectParameterPack=*/false,
+/*EvaluateConstraints=*/false);
+if (!NewParm)
+  return true;
+  }
+
+  return false;
+}
+NewParm = SemaRef.SubstParmVarDecl(OldParm, TemplateArgs,
+   /*indexAdjustment=*/IndexAdjustment,
+   std::nullopt,
+   /*ExpectParameterPack=*/false);
+if (!NewParm)
+  return true;
+Scope.InstantiatedLocal(OldParm, NewParm);
+return false;
+  }
+
+public:
+  InstantiateReferencedParameter(
+  Sema &SemaRef, const MultiLevelTemplateArgumentList &TemplateArgs,
+  FunctionDecl *PrimaryTemplatedFunction)
+  : inherited(SemaRef), TemplateArgs(TemplateArgs),
+PrimaryTemplatedFunction(PrimaryTemplatedFunction) {}
+
+  Decl *TransformDecl(SourceLocation Loc, Decl *D) {
+if (auto *PVD = dyn_cast_if_present(D);
+PVD && PVD->getDeclContext() == PrimaryTemplatedFunction &&
+!InstantiatedDecls.contains(PVD)) {
+  instantiateParameterToScope(PVD, *SemaRef.CurrentInstantiationScope);

zyn0217 wrote:

Hmmm, never mind. Probably things are not so dreadful than I thought.

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


[clang] [Clang] `constexpr` builtin floating point classification / comparison functions (PR #94118)

2024-08-18 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`sanitizer-x86_64-linux-fast` running on `sanitizer-buildbot4` while building 
`clang` at step 2 "annotate".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/169/builds/2272

Here is the relevant piece of the build log for the reference:
```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:508:
 note: using lld-link: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:508:
 note: using ld64.lld: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:508:
 note: using wasm-ld: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:508:
 note: using ld.lld: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:508:
 note: using lld-link: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:508:
 note: using ld64.lld: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:508:
 note: using wasm-ld: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/main.py:72:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 900 seconds was requested on the command line. Forcing 
timeout to be 900 seconds.
-- Testing: 85066 of 85067 tests, 88 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70..
FAIL: Clang :: Sema/constant-builtins-2.c (38188 of 85066)
 TEST 'Clang :: Sema/constant-builtins-2.c' FAILED 

Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/clang -cc1 
-internal-isystem 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/lib/clang/20/include
 -nostdsysteminc -fsyntax-only -verify 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Sema/constant-builtins-2.c
+ /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/clang 
-cc1 -internal-isystem 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/lib/clang/20/include
 -nostdsysteminc -fsyntax-only -verify 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Sema/constant-builtins-2.c
RUN: at line 2: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/clang -cc1 
-internal-isystem 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/lib/clang/20/include
 -nostdsysteminc -fsyntax-only -fexperimental-new-constant-interpreter -verify 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Sema/constant-builtins-2.c
+ /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/clang 
-cc1 -internal-isystem 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/lib/clang/20/include
 -nostdsysteminc -fsyntax-only -fexperimental-new-constant-interpreter -verify 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Sema/constant-builtins-2.c

=
==865709==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 64 byte(s) in 4 object(s) allocated from:
#0 0x5ca09b5c803d in operator new[](unsigned long) 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/compiler-rt/lib/asan/asan_new_delete.cpp:89:3
#1 0x5ca0a1eee2da in getMemory 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/Support/APInt.cpp:45:10
#2 0x5ca0a1eee2da in llvm::APInt::initSlowCase(llvm::APInt const&) 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/Support/APInt.cpp:86:12
#3 0x5ca0abac7934 in APInt 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/ADT/APInt.h:158:7
#4 0x5ca0abac7934 in IntegralAP 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/AST/ByteCode/IntegralAP.h:62:25
#5 0x5ca0abac7934 in clang::interp::IntegralAP 
clang::interp::IntegralAP::from<32u, true>(clang::interp::Integral<32u, 
true>, unsigned int) 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/AST/ByteCode/IntegralAP.h:117:12
#

[clang] [libcxx] [Clang] Implement CWG2369 "Ordering between constraints and substitution" (PR #102857)

2024-08-18 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/102857

>From 1119f0a8d180e482bff45c999d488827ac5ae49e Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Mon, 12 Aug 2024 23:32:34 +0800
Subject: [PATCH 01/10] [Clang][NFCI] Slightly refactor
 getTemplateInstantiationArgs()

---
 clang/include/clang/Sema/Sema.h| 12 +---
 clang/lib/Sema/SemaConcept.cpp |  2 +-
 clang/lib/Sema/SemaTemplate.cpp|  2 +-
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 15 +++
 4 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 2ec6367eccea01..352b26b0739ffb 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -13033,11 +13033,14 @@ class Sema final : public SemaBase {
   /// instantiation arguments.
   ///
   /// \param DC In the event we don't HAVE a declaration yet, we instead 
provide
-  ///  the decl context where it will be created.  In this case, the 
`Innermost`
-  ///  should likely be provided.  If ND is non-null, this is ignored.
+  ///  the decl context where it will be created.  In this case, the \p
+  ///  Innermost should likely be provided.  If \p ND is non-null and \p
+  ///  Innermost is NULL, this is ignored.
   ///
   /// \param Innermost if non-NULL, specifies a template argument list for the
-  /// template declaration passed as ND.
+  /// template declaration passed as \p ND. The next declaration context would
+  /// be switched to \p DC if present; otherwise, it would be the semantic
+  /// declaration context of \p ND.
   ///
   /// \param RelativeToPrimary true if we should get the template
   /// arguments relative to the primary template, even when we're
@@ -13053,6 +13056,9 @@ class Sema final : public SemaBase {
   /// ForConstraintInstantiation indicates we should continue looking when
   /// encountering a lambda generic call operator, and continue looking for
   /// arguments on an enclosing class template.
+  ///
+  /// \param SkipForSpecialization when specified, any template specializations
+  /// in a traversal would be ignored.
   MultiLevelTemplateArgumentList getTemplateInstantiationArgs(
   const NamedDecl *D, const DeclContext *DC = nullptr, bool Final = false,
   std::optional> Innermost = std::nullopt,
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index d4c9d044985e34..929555e94dc35d 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -1482,7 +1482,7 @@ substituteParameterMappings(Sema &S, NormalizedConstraint 
&N,
 static bool substituteParameterMappings(Sema &S, NormalizedConstraint &N,
 const ConceptSpecializationExpr *CSE) {
   MultiLevelTemplateArgumentList MLTAL = S.getTemplateInstantiationArgs(
-  CSE->getNamedConcept(), CSE->getNamedConcept()->getLexicalDeclContext(),
+  CSE->getNamedConcept(), CSE->getNamedConcept()->getDeclContext(),
   /*Final=*/true, CSE->getTemplateArguments(),
   /*RelativeToPrimary=*/true,
   /*Pattern=*/nullptr,
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 1346a4a3f0012a..e6191c8c1397bd 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -5582,7 +5582,7 @@ bool Sema::CheckTemplateArgumentList(
 CXXThisScopeRAII(*this, RD, ThisQuals, RD != nullptr);
 
 MultiLevelTemplateArgumentList MLTAL = getTemplateInstantiationArgs(
-Template, NewContext, /*Final=*/true, SugaredConverted,
+Template, Template->getDeclContext(), /*Final=*/true, SugaredConverted,
 /*RelativeToPrimary=*/true,
 /*Pattern=*/nullptr,
 /*ForConceptInstantiation=*/true);
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index de470739ab78e7..6cc9fb0ef04b65 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -491,7 +491,8 @@ MultiLevelTemplateArgumentList 
Sema::getTemplateInstantiationArgs(
 // has a depth of 0.
 if (const auto *TTP = dyn_cast(CurDecl))
   HandleDefaultTempArgIntoTempTempParam(TTP, Result);
-CurDecl = Response::UseNextDecl(CurDecl).NextDecl;
+CurDecl = DC ? Decl::castFromDeclContext(DC)
+ : Response::UseNextDecl(CurDecl).NextDecl;
   }
 
   while (!CurDecl->isFileContextDecl()) {
@@ -3242,15 +3243,13 @@ bool Sema::SubstDefaultArgument(
   /*ForDefinition*/ false);
   if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs))
 return true;
-  const FunctionTemplateDecl *PrimaryTemplate = FD->getPrimaryTemplate();
-  if (PrimaryTemplate && PrimaryTemplate->isOutOfLine()) {
-TemplateArgumentList *CurrentTemplateArgumentList =
-TemplateArgumentList::CreateCopy(getASTContext(),
- TemplateArg

[clang] [clang-tools-extra] [clang][NFC] Un-constify `MultiLevelTemplateArgumentList` (PR #104687)

2024-08-18 Thread via cfe-commits

cor3ntin wrote:

While I agree with you that we should be careful with you that `const_cast` is 
usually a bad thing,
I am not sure removing const everywhere for one usage is a net-positive. There 
are no reason for template arguments to ever be modified. 
The forgot/remember exception is somewhat of a hack, and we might want to 
explore if we can improve _that_

A clean change would be to copy the whole MTAL and replace the "forgotten" 
argument. That might be worth benchmarking (references to `TemplateArgs` in 
`TemplateInstantiator` would have to be replaced by a function that return that 
copy, if any) 

But, I think I am content with the status quo, if we don't find a better option 
we should probably add comments.







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


[clang] c4092d3 - [Clang] warn on discarded [[nodiscard]] function results after casting in C (#104677)

2024-08-18 Thread via cfe-commits

Author: Oleksandr T.
Date: 2024-08-18T12:45:20+02:00
New Revision: c4092d326ae4989f54c5f01d3a077841fd76bc2f

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

LOG: [Clang] warn on discarded [[nodiscard]] function results after casting in 
C (#104677)

Fixes #104391

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaStmt.cpp
clang/test/Sema/c2x-nodiscard.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 12a3707db8a39f..11301e4c7dc4a2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -218,6 +218,8 @@ Improvements to Clang's diagnostics
 
 - Clang now diagnoses the use of ``main`` in an ``extern`` context as invalid 
according to [basic.start.main] p3. Fixes #GH101512.
 
+- Clang now diagnoses when the result of a [[nodiscard]] function is discarded 
after being cast in C. Fixes #GH104391.
+
 Improvements to Clang's time-trace
 --
 

diff  --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index d283eaa511011b..ba681671eb3290 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -281,7 +281,8 @@ void Sema::DiagnoseUnusedExprResult(const Stmt *S, unsigned 
DiagID) {
   E = WarnExpr;
   if (const auto *Cast = dyn_cast(E))
 if (Cast->getCastKind() == CK_NoOp ||
-Cast->getCastKind() == CK_ConstructorConversion)
+Cast->getCastKind() == CK_ConstructorConversion ||
+Cast->getCastKind() == CK_IntegralCast)
   E = Cast->getSubExpr()->IgnoreImpCasts();
 
   if (const CallExpr *CE = dyn_cast(E)) {

diff  --git a/clang/test/Sema/c2x-nodiscard.c b/clang/test/Sema/c2x-nodiscard.c
index cb33c0c242e7db..f8b0567366465d 100644
--- a/clang/test/Sema/c2x-nodiscard.c
+++ b/clang/test/Sema/c2x-nodiscard.c
@@ -54,3 +54,9 @@ void test_missiles(void) {
   launch_missiles();
 }
 
+[[nodiscard]] int f3();
+
+void GH104391() {
+#define M (unsigned int) f3()
+  M; // expected-warning {{ignoring return value of function declared with 
'nodiscard' attribute}}
+}



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


[clang] [Clang] warn on discarded [[nodiscard]] function results after casting in C (PR #104677)

2024-08-18 Thread via cfe-commits

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


[clang] [libcxx] [Clang] Implement CWG2369 "Ordering between constraints and substitution" (PR #102857)

2024-08-18 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff d990cc4568f45c28d1d5ac86125935628c76efc8 
cebe7063174a12dfedbe28185b7173b8826093ab --extensions cpp,h -- 
clang/include/clang/Sema/Sema.h clang/include/clang/Sema/Template.h 
clang/lib/Sema/SemaConcept.cpp clang/lib/Sema/SemaTemplate.cpp 
clang/lib/Sema/SemaTemplateDeduction.cpp 
clang/lib/Sema/SemaTemplateDeductionGuide.cpp 
clang/lib/Sema/SemaTemplateInstantiate.cpp 
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp clang/lib/Sema/TreeTransform.h 
clang/test/CXX/drs/cwg23xx.cpp clang/test/CXX/drs/cwg26xx.cpp 
clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp 
clang/test/CXX/temp/temp.constr/temp.constr.atomic/constrant-satisfaction-conversions.cpp
 clang/test/SemaCXX/concept-crash-on-diagnostic.cpp 
clang/test/SemaCXX/cxx20-ctad-type-alias.cpp 
clang/test/SemaCXX/cxx23-assume.cpp clang/test/SemaCXX/cxx2c-fold-exprs.cpp 
clang/test/SemaCXX/lambda-unevaluated.cpp 
clang/test/SemaTemplate/concepts-recursive-inst.cpp 
clang/test/SemaTemplate/cxx2a-constraint-exprs.cpp 
clang/test/SemaTemplate/deduction-guide.cpp 
clang/test/SemaTemplate/nested-implicit-deduction-guides.cpp 
libcxx/include/__chrono/leap_second.h
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 99c1b4a699..f89dd6878b 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -1168,7 +1168,6 @@ bool Sema::CheckFunctionConstraintsWithoutInstantiation(
/*Pattern=*/nullptr,
/*ForConstraintInstantiation=*/true);
 
-
   Qualifiers ThisQuals;
   CXXRecordDecl *Record = nullptr;
   if (auto *Method = dyn_cast(FD)) {
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 4f590fc1af..971dc65eb1 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1351,6 +1351,7 @@ namespace {
 DeclContext *FunctionDCForParameterDeclInstantiation;
 
 LocalInstantiationScope *ParameterInstantiationScope;
+
   private:
 bool instantiateParameterToScope(ParmVarDecl *OldParm,
  LocalInstantiationScope &Scope);
@@ -1367,9 +1368,7 @@ namespace {
 void setEvaluateConstraints(bool B) {
   EvaluateConstraints = B;
 }
-bool getEvaluateConstraints() const {
-  return EvaluateConstraints;
-}
+bool getEvaluateConstraints() const { return EvaluateConstraints; }
 
 void setInstantiatingFunctionDC(DeclContext *FunctionDC) {
   FunctionDCForParameterDeclInstantiation = FunctionDC;
@@ -4441,7 +4440,6 @@ static const Decl *getCanonicalParmVarDecl(const Decl *D) 
{
   return D;
 }
 
-
 llvm::PointerUnion *
 LocalInstantiationScope::findInstantiationUnsafe(const Decl *D) {
   D = getCanonicalParmVarDecl(D);

``




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


[clang] 7180170 - [clang][test] Remove bytecode interpreter RUN line from test

2024-08-18 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-08-18T13:02:37+02:00
New Revision: 71801707e33c235656b172fa7dfb8662473a95c2

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

LOG: [clang][test] Remove bytecode interpreter RUN line from test

Specifically, from constant-builtins2. This breaks runners using
sanitizers.

See https://github.com/llvm/llvm-project/pull/94118

Added: 


Modified: 
clang/test/Sema/constant-builtins-2.c

Removed: 




diff  --git a/clang/test/Sema/constant-builtins-2.c 
b/clang/test/Sema/constant-builtins-2.c
index c359eba4e3d16..da2264500d768 100644
--- a/clang/test/Sema/constant-builtins-2.c
+++ b/clang/test/Sema/constant-builtins-2.c
@@ -1,5 +1,4 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
-// RUN: %clang_cc1 -fsyntax-only -fexperimental-new-constant-interpreter 
-verify %s
 
 // Math stuff
 



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


[clang] [llvm] [NVPTX] Support __usAtomicCAS builtin (PR #99646)

2024-08-18 Thread via cfe-commits

https://github.com/DenisGZM updated 
https://github.com/llvm/llvm-project/pull/99646

>From 6312ad5d7fa63bda97d534fe76967a69e019cded Mon Sep 17 00:00:00 2001
From: Denis Gerasimov 
Date: Fri, 19 Jul 2024 15:47:57 +0300
Subject: [PATCH 1/7] [NVPTX] Support __usAtomicCAS builtin

---
 clang/include/clang/Basic/BuiltinsNVPTX.def   |  3 +++
 clang/lib/CodeGen/CGBuiltin.cpp   |  3 +++
 clang/lib/Headers/__clang_cuda_device_functions.h | 12 
 clang/test/CodeGen/builtins-nvptx.c   |  3 +++
 llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp   |  2 +-
 llvm/lib/Target/NVPTX/NVPTXIntrinsics.td  | 15 +++
 6 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/BuiltinsNVPTX.def 
b/clang/include/clang/Basic/BuiltinsNVPTX.def
index 504314d8d96e91..3cf683a2f21298 100644
--- a/clang/include/clang/Basic/BuiltinsNVPTX.def
+++ b/clang/include/clang/Basic/BuiltinsNVPTX.def
@@ -829,6 +829,9 @@ BUILTIN(__nvvm_atom_xor_gen_ll, "LLiLLiD*LLi", "n")
 TARGET_BUILTIN(__nvvm_atom_cta_xor_gen_ll, "LLiLLiD*LLi", "n", SM_60)
 TARGET_BUILTIN(__nvvm_atom_sys_xor_gen_ll, "LLiLLiD*LLi", "n", SM_60)
 
+TARGET_BUILTIN(__nvvm_atom_cas_gen_us, "UsUsD*UsUs", "n", SM_70)
+TARGET_BUILTIN(__nvvm_atom_cta_cas_gen_us, "UsUsD*UsUs", "n", SM_70)
+TARGET_BUILTIN(__nvvm_atom_sys_cas_gen_us, "UsUsD*UsUs", "n", SM_70)
 BUILTIN(__nvvm_atom_cas_gen_i, "iiD*ii", "n")
 TARGET_BUILTIN(__nvvm_atom_cta_cas_gen_i, "iiD*ii", "n", SM_60)
 TARGET_BUILTIN(__nvvm_atom_sys_cas_gen_i, "iiD*ii", "n", SM_60)
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 3221989e14351f..7dcfc2564aa6b8 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -20199,6 +20199,7 @@ Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned 
BuiltinID,
   case NVPTX::BI__nvvm_atom_min_gen_ull:
 return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::UMin, E);
 
+  case NVPTX::BI__nvvm_atom_cas_gen_us:
   case NVPTX::BI__nvvm_atom_cas_gen_i:
   case NVPTX::BI__nvvm_atom_cas_gen_l:
   case NVPTX::BI__nvvm_atom_cas_gen_ll:
@@ -20390,6 +20391,7 @@ Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned 
BuiltinID,
   case NVPTX::BI__nvvm_atom_sys_xor_gen_l:
   case NVPTX::BI__nvvm_atom_sys_xor_gen_ll:
 return MakeScopedAtomic(Intrinsic::nvvm_atomic_xor_gen_i_sys, *this, E);
+  case NVPTX::BI__nvvm_atom_cta_cas_gen_us:
   case NVPTX::BI__nvvm_atom_cta_cas_gen_i:
   case NVPTX::BI__nvvm_atom_cta_cas_gen_l:
   case NVPTX::BI__nvvm_atom_cta_cas_gen_ll: {
@@ -20401,6 +20403,7 @@ Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned 
BuiltinID,
 Intrinsic::nvvm_atomic_cas_gen_i_cta, {ElemTy, Ptr->getType()}),
 {Ptr, EmitScalarExpr(E->getArg(1)), EmitScalarExpr(E->getArg(2))});
   }
+  case NVPTX::BI__nvvm_atom_sys_cas_gen_us:
   case NVPTX::BI__nvvm_atom_sys_cas_gen_i:
   case NVPTX::BI__nvvm_atom_sys_cas_gen_l:
   case NVPTX::BI__nvvm_atom_sys_cas_gen_ll: {
diff --git a/clang/lib/Headers/__clang_cuda_device_functions.h 
b/clang/lib/Headers/__clang_cuda_device_functions.h
index f8a12cefdb81b4..f66fe625a39676 100644
--- a/clang/lib/Headers/__clang_cuda_device_functions.h
+++ b/clang/lib/Headers/__clang_cuda_device_functions.h
@@ -529,6 +529,18 @@ __DEVICE__ void __threadfence(void) { __nvvm_membar_gl(); }
 __DEVICE__ void __threadfence_block(void) { __nvvm_membar_cta(); };
 __DEVICE__ void __threadfence_system(void) { __nvvm_membar_sys(); };
 __DEVICE__ void __trap(void) { __asm__ __volatile__("trap;"); }
+__DEVICE__ unsigned short __usAtomicCAS(unsigned short *__p, unsigned short 
__cmp,
+unsigned short __v) {
+  return __nvvm_atom_cas_gen_us(__p, __cmp, __v);
+}
+__DEVICE__ unsigned short __usAtomicCAS_block(unsigned short *__p, unsigned 
short __cmp,
+  unsigned short __v) {
+  return __nvvm_atom_cta_cas_gen_us(__p, __cmp, __v);
+}
+__DEVICE__ unsigned short __usAtomicCAS_system(unsigned short *__p, unsigned 
short __cmp,
+   unsigned short __v) {
+  return __nvvm_atom_sys_cas_gen_us(__p, __cmp, __v);
+}
 __DEVICE__ unsigned int __uAtomicAdd(unsigned int *__p, unsigned int __v) {
   return __nvvm_atom_add_gen_i((int *)__p, __v);
 }
diff --git a/clang/test/CodeGen/builtins-nvptx.c 
b/clang/test/CodeGen/builtins-nvptx.c
index 75b9d6d1fe1902..3ba1fabd05335e 100644
--- a/clang/test/CodeGen/builtins-nvptx.c
+++ b/clang/test/CodeGen/builtins-nvptx.c
@@ -306,6 +306,9 @@ __device__ void nvvm_atom(float *fp, float f, double *dfp, 
double df, int *ip,
   // CHECK: atomicrmw umin ptr {{.*}} seq_cst, align 8
   __nvvm_atom_min_gen_ull((unsigned long long *)&sll, ll);
 
+  // CHECK: cmpxchg ptr {{.*}} seq_cst seq_cst, align 2
+  // CHECK-NEXT: extractvalue { i16, i1 } {{%[0-9]+}}, 0
+  __nvvm_atom_cas_gen_us(ip, 0, i);
   // CHECK: cmpxchg ptr {{.*}} seq_cst seq_cst, align 4
   // CHECK-NEXT: extractvalue { 

[clang] [llvm] [NVPTX] Support __usAtomicCAS builtin (PR #99646)

2024-08-18 Thread via cfe-commits

https://github.com/DenisGZM updated 
https://github.com/llvm/llvm-project/pull/99646

>From accdc9bee5a6f2ee2add330dd8d06d280cd13b64 Mon Sep 17 00:00:00 2001
From: Denis Gerasimov 
Date: Fri, 19 Jul 2024 15:47:57 +0300
Subject: [PATCH 1/7] [NVPTX] Support __usAtomicCAS builtin

---
 clang/include/clang/Basic/BuiltinsNVPTX.def   |  3 +++
 clang/lib/CodeGen/CGBuiltin.cpp   |  3 +++
 clang/lib/Headers/__clang_cuda_device_functions.h | 12 
 clang/test/CodeGen/builtins-nvptx.c   |  3 +++
 llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp   |  2 +-
 llvm/lib/Target/NVPTX/NVPTXIntrinsics.td  | 15 +++
 6 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/BuiltinsNVPTX.def 
b/clang/include/clang/Basic/BuiltinsNVPTX.def
index 504314d8d96e91..3cf683a2f21298 100644
--- a/clang/include/clang/Basic/BuiltinsNVPTX.def
+++ b/clang/include/clang/Basic/BuiltinsNVPTX.def
@@ -829,6 +829,9 @@ BUILTIN(__nvvm_atom_xor_gen_ll, "LLiLLiD*LLi", "n")
 TARGET_BUILTIN(__nvvm_atom_cta_xor_gen_ll, "LLiLLiD*LLi", "n", SM_60)
 TARGET_BUILTIN(__nvvm_atom_sys_xor_gen_ll, "LLiLLiD*LLi", "n", SM_60)
 
+TARGET_BUILTIN(__nvvm_atom_cas_gen_us, "UsUsD*UsUs", "n", SM_70)
+TARGET_BUILTIN(__nvvm_atom_cta_cas_gen_us, "UsUsD*UsUs", "n", SM_70)
+TARGET_BUILTIN(__nvvm_atom_sys_cas_gen_us, "UsUsD*UsUs", "n", SM_70)
 BUILTIN(__nvvm_atom_cas_gen_i, "iiD*ii", "n")
 TARGET_BUILTIN(__nvvm_atom_cta_cas_gen_i, "iiD*ii", "n", SM_60)
 TARGET_BUILTIN(__nvvm_atom_sys_cas_gen_i, "iiD*ii", "n", SM_60)
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f424ddaa175400..769b3ce1886baf 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -20357,6 +20357,7 @@ Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned 
BuiltinID,
   case NVPTX::BI__nvvm_atom_min_gen_ull:
 return MakeBinaryAtomicValue(*this, llvm::AtomicRMWInst::UMin, E);
 
+  case NVPTX::BI__nvvm_atom_cas_gen_us:
   case NVPTX::BI__nvvm_atom_cas_gen_i:
   case NVPTX::BI__nvvm_atom_cas_gen_l:
   case NVPTX::BI__nvvm_atom_cas_gen_ll:
@@ -20548,6 +20549,7 @@ Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned 
BuiltinID,
   case NVPTX::BI__nvvm_atom_sys_xor_gen_l:
   case NVPTX::BI__nvvm_atom_sys_xor_gen_ll:
 return MakeScopedAtomic(Intrinsic::nvvm_atomic_xor_gen_i_sys, *this, E);
+  case NVPTX::BI__nvvm_atom_cta_cas_gen_us:
   case NVPTX::BI__nvvm_atom_cta_cas_gen_i:
   case NVPTX::BI__nvvm_atom_cta_cas_gen_l:
   case NVPTX::BI__nvvm_atom_cta_cas_gen_ll: {
@@ -20559,6 +20561,7 @@ Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned 
BuiltinID,
 Intrinsic::nvvm_atomic_cas_gen_i_cta, {ElemTy, Ptr->getType()}),
 {Ptr, EmitScalarExpr(E->getArg(1)), EmitScalarExpr(E->getArg(2))});
   }
+  case NVPTX::BI__nvvm_atom_sys_cas_gen_us:
   case NVPTX::BI__nvvm_atom_sys_cas_gen_i:
   case NVPTX::BI__nvvm_atom_sys_cas_gen_l:
   case NVPTX::BI__nvvm_atom_sys_cas_gen_ll: {
diff --git a/clang/lib/Headers/__clang_cuda_device_functions.h 
b/clang/lib/Headers/__clang_cuda_device_functions.h
index f8a12cefdb81b4..f66fe625a39676 100644
--- a/clang/lib/Headers/__clang_cuda_device_functions.h
+++ b/clang/lib/Headers/__clang_cuda_device_functions.h
@@ -529,6 +529,18 @@ __DEVICE__ void __threadfence(void) { __nvvm_membar_gl(); }
 __DEVICE__ void __threadfence_block(void) { __nvvm_membar_cta(); };
 __DEVICE__ void __threadfence_system(void) { __nvvm_membar_sys(); };
 __DEVICE__ void __trap(void) { __asm__ __volatile__("trap;"); }
+__DEVICE__ unsigned short __usAtomicCAS(unsigned short *__p, unsigned short 
__cmp,
+unsigned short __v) {
+  return __nvvm_atom_cas_gen_us(__p, __cmp, __v);
+}
+__DEVICE__ unsigned short __usAtomicCAS_block(unsigned short *__p, unsigned 
short __cmp,
+  unsigned short __v) {
+  return __nvvm_atom_cta_cas_gen_us(__p, __cmp, __v);
+}
+__DEVICE__ unsigned short __usAtomicCAS_system(unsigned short *__p, unsigned 
short __cmp,
+   unsigned short __v) {
+  return __nvvm_atom_sys_cas_gen_us(__p, __cmp, __v);
+}
 __DEVICE__ unsigned int __uAtomicAdd(unsigned int *__p, unsigned int __v) {
   return __nvvm_atom_add_gen_i((int *)__p, __v);
 }
diff --git a/clang/test/CodeGen/builtins-nvptx.c 
b/clang/test/CodeGen/builtins-nvptx.c
index 75b9d6d1fe1902..3ba1fabd05335e 100644
--- a/clang/test/CodeGen/builtins-nvptx.c
+++ b/clang/test/CodeGen/builtins-nvptx.c
@@ -306,6 +306,9 @@ __device__ void nvvm_atom(float *fp, float f, double *dfp, 
double df, int *ip,
   // CHECK: atomicrmw umin ptr {{.*}} seq_cst, align 8
   __nvvm_atom_min_gen_ull((unsigned long long *)&sll, ll);
 
+  // CHECK: cmpxchg ptr {{.*}} seq_cst seq_cst, align 2
+  // CHECK-NEXT: extractvalue { i16, i1 } {{%[0-9]+}}, 0
+  __nvvm_atom_cas_gen_us(ip, 0, i);
   // CHECK: cmpxchg ptr {{.*}} seq_cst seq_cst, align 4
   // CHECK-NEXT: extractvalue { 

[clang] [clang-tools-extra] [clang][NFC] Un-constify `MultiLevelTemplateArgumentList` (PR #104687)

2024-08-18 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [clang] fix divide by zero in ComplexExprEvaluator (PR #104666)

2024-08-18 Thread via cfe-commits

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


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


[clang] [clang] fix divide by zero in ComplexExprEvaluator (PR #104666)

2024-08-18 Thread via cfe-commits

cor3ntin wrote:

@c8ef you need me to merge that for you?

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


[clang] [clang-tools-extra] [clang][NFC] Un-constify `MultiLevelTemplateArgumentList` (PR #104687)

2024-08-18 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

I think the main contribution of this patch is showing the extent of the 
propagation. I personally was surprised this got to `ASTMatchers` and 
`APValue`. Now that we understand the scope, we can try to draw a line where 
changes here stop making sense, and do some else where we'd like propagation to 
stop, e.g. start copying things.

> A clean change would be to copy the whole MTAL and replace the "forgotten" 
> argument.

I'm not sure I understand, because MLTAL doesn't seem to own the arguments in 
the first place, so copying it doesn't seem of any help.

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


[clang] [llvm] [NVPTX] Support __usAtomicCAS builtin (PR #99646)

2024-08-18 Thread via cfe-commits


@@ -0,0 +1,37 @@
+; RUN: llc < %s -march=nvptx64 -mcpu=sm_32 | FileCheck %s 
--check-prefixes=SM30,CHECK

DenisGZM wrote:

Seems, that noone autogenerated tests for ptx before, because there wasn't 
nvptx march

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


[clang] [clang] fix divide by zero in ComplexExprEvaluator (PR #104666)

2024-08-18 Thread via cfe-commits

c8ef wrote:

Yes, please. That would be great.

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


[clang] [clang-tools-extra] [clang][NFC] Un-constify `MultiLevelTemplateArgumentList` (PR #104687)

2024-08-18 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

I'll deal with the formatting later, because I don't want to burden reviewers 
with more changes than necessary.
I also updated the description after fixing clang-tidy build. We've got two 
more bad `const_cast`s.

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


[clang] [llvm] [NVPTX] Support __usAtomicCAS builtin (PR #99646)

2024-08-18 Thread via cfe-commits

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


[clang] [Clang] `constexpr` builtin floating point classification / comparison functions (PR #94118)

2024-08-18 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`sanitizer-x86_64-linux-bootstrap-asan` running on `sanitizer-buildbot2` while 
building `clang` at step 2 "annotate".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/52/builds/1612

Here is the relevant piece of the build log for the reference:
```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:508:
 note: using lld-link: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:508:
 note: using ld64.lld: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:508:
 note: using wasm-ld: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:508:
 note: using ld.lld: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:508:
 note: using lld-link: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:508:
 note: using ld64.lld: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:508:
 note: using wasm-ld: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/main.py:72:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 900 seconds was requested on the command line. Forcing 
timeout to be 900 seconds.
-- Testing: 85066 of 85067 tests, 88 workers --
Testing:  0.. 10..
FAIL: Clang :: Sema/constant-builtins-2.c (16887 of 85066)
 TEST 'Clang :: Sema/constant-builtins-2.c' FAILED 

Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/clang 
-cc1 -internal-isystem 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/lib/clang/20/include
 -nostdsysteminc -fsyntax-only -verify 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/clang/test/Sema/constant-builtins-2.c
+ /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/clang 
-cc1 -internal-isystem 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/lib/clang/20/include
 -nostdsysteminc -fsyntax-only -verify 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/clang/test/Sema/constant-builtins-2.c
RUN: at line 2: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/clang 
-cc1 -internal-isystem 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/lib/clang/20/include
 -nostdsysteminc -fsyntax-only -fexperimental-new-constant-interpreter -verify 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/clang/test/Sema/constant-builtins-2.c
+ /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/clang 
-cc1 -internal-isystem 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/lib/clang/20/include
 -nostdsysteminc -fsyntax-only -fexperimental-new-constant-interpreter -verify 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/clang/test/Sema/constant-builtins-2.c

=
==2615403==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 64 byte(s) in 4 object(s) allocated from:
#0 0x5d8e422f07bd in operator new[](unsigned long) 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/compiler-rt/lib/asan/asan_new_delete.cpp:89:3
#1 0x5d8e48b9265c in getMemory 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/lib/Support/APInt.cpp:45:10
#2 0x5d8e48b9265c in llvm::APInt::initSlowCase(llvm::APInt const&) 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/lib/Support/APInt.cpp:86:12
#3 0x5d8e5181aef3 in APInt 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/include/llvm/ADT/APInt.h:158:7
#4 0x5d8e5181aef3 in IntegralAP 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/clang/lib/AST/ByteCode/IntegralAP.h:62:25
#5 0x5d8e5181aef3 in clang::interp::

[clang] [Clang] `constexpr` builtin floating point classification / comparison functions (PR #94118)

2024-08-18 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`sanitizer-aarch64-linux-bootstrap-hwasan` running on `sanitizer-buildbot12` 
while building `clang` at step 2 "annotate".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/55/builds/1360

Here is the relevant piece of the build log for the reference:
```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:508:
 note: using lld-link: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:508:
 note: using ld64.lld: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:508:
 note: using wasm-ld: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:508:
 note: using ld.lld: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/ld.lld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:508:
 note: using lld-link: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:508:
 note: using ld64.lld: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:508:
 note: using wasm-ld: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/main.py:72:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 900 seconds was requested on the command line. Forcing 
timeout to be 900 seconds.
-- Testing: 81685 tests, 48 workers --
Testing:  0.. 10.. 
FAIL: Clang :: Sema/constant-builtins-2.c (16882 of 81685)
 TEST 'Clang :: Sema/constant-builtins-2.c' FAILED 

Exit Code: 134

Command Output (stderr):
--
RUN: at line 1: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/clang
 -cc1 -internal-isystem 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/lib/clang/20/include
 -nostdsysteminc -fsyntax-only -verify 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/test/Sema/constant-builtins-2.c
+ 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/clang
 -cc1 -internal-isystem 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/lib/clang/20/include
 -nostdsysteminc -fsyntax-only -verify 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/test/Sema/constant-builtins-2.c
RUN: at line 2: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/clang
 -cc1 -internal-isystem 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/lib/clang/20/include
 -nostdsysteminc -fsyntax-only -fexperimental-new-constant-interpreter -verify 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/test/Sema/constant-builtins-2.c
+ 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/clang
 -cc1 -internal-isystem 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/lib/clang/20/include
 -nostdsysteminc -fsyntax-only -fexperimental-new-constant-interpreter -verify 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/clang/test/Sema/constant-builtins-2.c

=
==2926763==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 64 byte(s) in 4 object(s) allocated from:
#0 0xbc948bc579e8 in operator new[](unsigned long) 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/compiler-rt/lib/hwasan/hwasan_new_delete.cpp:68:3
#1 0xbc9491eb1028 in getMemory 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/lib/Support/APInt.cpp:45:10
#2 0xbc9491eb1028 in llvm::APInt::initSlowCase(llvm::APInt const&) 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/lib/Support/APInt.cpp:86:12
#3 0xbc949a0feec0 in APInt 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/include/llvm/ADT/APInt.h:158:7
#4 0xbc949a0feec0 in IntegralAP 
/home/b/sanitizer-aa

[clang] [clang] fix divide by zero in ComplexExprEvaluator (PR #104666)

2024-08-18 Thread Sergei Barannikov via cfe-commits


@@ -15567,12 +15567,13 @@ bool ComplexExprEvaluator::VisitBinaryOperator(const 
BinaryOperator *E) {
 HandleComplexComplexDiv(A, B, C, D, ResR, ResI);
   }
 } else {
-  if (RHS.getComplexIntReal() == 0 && RHS.getComplexIntImag() == 0)
-return Error(E, diag::note_expr_divide_by_zero);
-
   ComplexValue LHS = Result;
   APSInt Den = RHS.getComplexIntReal() * RHS.getComplexIntReal() +
 RHS.getComplexIntImag() * RHS.getComplexIntImag();
+  if ((RHS.getComplexIntReal() == 0 && RHS.getComplexIntImag() == 0) ||
+  Den.isZero())

s-barannikov wrote:

(nit) The first part of the check implies the second, why not just
```suggestion
  if (Den.isZero())
```


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


[clang] [Clang][Sema] Expose static inline functions from GMF (PR #104701)

2024-08-18 Thread Jan Kokemüller via cfe-commits

https://github.com/jiixyj created 
https://github.com/llvm/llvm-project/pull/104701

In C, it is a common pattern to have `static inline` functions in headers to 
avoid ODR issues. Currently, when those headers are included in a GMF, the 
names are not found when two-phase name lookup and ADL is involved. Those names 
are removed by `Sema::AddOverloadCandidate`.

Similarly, in C++, sometimes people use templates with internal linkage in 
headers.

As the GMF was designed to be a transitional mechanism for headers, special 
case those functions in `Sema::AddOverloadCandidate`.

This fixes .

From feaf6512fc6323ad0c3d5082c06e610504f0a527 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20Kokem=C3=BCller?= 
Date: Sun, 18 Aug 2024 13:45:43 +0200
Subject: [PATCH] Expose static inline function from GMF

They should be exposed even when two-phase name lookup and ADL are
involved.
---
 clang/lib/Sema/SemaOverload.cpp   | 23 +--
 .../expose-static-inline-from-gmf-1.cppm  | 37 +
 .../expose-static-inline-from-gmf-2.cppm  | 22 ++
 .../expose-static-inline-from-gmf-3.cppm  | 24 +++
 .../expose-static-inline-from-gmf-4.cppm  | 40 +++
 .../expose-static-inline-from-gmf-5.cppm  | 26 
 6 files changed, 168 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/Modules/expose-static-inline-from-gmf-1.cppm
 create mode 100644 clang/test/Modules/expose-static-inline-from-gmf-2.cppm
 create mode 100644 clang/test/Modules/expose-static-inline-from-gmf-3.cppm
 create mode 100644 clang/test/Modules/expose-static-inline-from-gmf-4.cppm
 create mode 100644 clang/test/Modules/expose-static-inline-from-gmf-5.cppm

diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 52f640eb96b73b..ca070d0e22d472 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -6926,11 +6926,26 @@ void Sema::AddOverloadCandidate(
 /// have linkage. So that all entities of the same should share one
 /// linkage. But in clang, different entities of the same could have
 /// different linkage.
-NamedDecl *ND = Function;
-if (auto *SpecInfo = Function->getTemplateSpecializationInfo())
+const NamedDecl *ND = Function;
+bool IsImplicitlyInstantiated = false;
+if (auto *SpecInfo = Function->getTemplateSpecializationInfo()) {
   ND = SpecInfo->getTemplate();
-
-if (ND->getFormalLinkage() == Linkage::Internal) {
+  IsImplicitlyInstantiated = SpecInfo->getTemplateSpecializationKind() ==
+ TSK_ImplicitInstantiation;
+}
+
+/// Don't remove inline functions with internal linkage from the overload
+/// set if they are declared in a GMF.
+/// The global module is meant to be a transition mechanism for C and C++
+/// headers.
+/// Inline functions with internal linkage are a common pattern in headers
+/// to avoid ODR issues.
+const bool IsInlineFunctionInGMF =
+  Function->getOwningModule() &&
+  Function->getOwningModule()->isGlobalModule() &&
+  (IsImplicitlyInstantiated || Function->isInlined());
+
+if (ND->getFormalLinkage() == Linkage::Internal && !IsInlineFunctionInGMF) 
{
   Candidate.Viable = false;
   Candidate.FailureKind = ovl_fail_module_mismatched;
   return;
diff --git a/clang/test/Modules/expose-static-inline-from-gmf-1.cppm 
b/clang/test/Modules/expose-static-inline-from-gmf-1.cppm
new file mode 100644
index 00..4de9b583dac8da
--- /dev/null
+++ b/clang/test/Modules/expose-static-inline-from-gmf-1.cppm
@@ -0,0 +1,37 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang -std=c++20 %t/a.cppm --precompile -o %t/a.pcm \
+// RUN:   -DTEST_INLINE
+// RUN: %clang -std=c++20 %t/test.cc -fprebuilt-module-path=%t -fsyntax-only 
-Xclang -verify \
+// RUN:   -DTEST_INLINE
+//
+// RUN: %clang -std=c++20 %t/a.cppm --precompile -o %t/a.pcm
+// RUN: %clang -std=c++20 %t/test.cc -fprebuilt-module-path=%t -fsyntax-only 
-Xclang -verify
+
+//--- a.h
+#ifdef TEST_INLINE
+#define INLINE inline
+#else
+#define INLINE
+#endif
+static INLINE void func(long) {}
+template  void a() { func(T{}); }
+
+//--- a.cppm
+module;
+#include "a.h"
+export module a;
+export using ::a;
+
+//--- test.cc
+import a;
+auto m = (a(), 0);
+
+#ifdef TEST_INLINE
+// expected-no-diagnostics
+#else
+// expected-error@a.h:7 {{no matching function for call to 'func'}}
+// expected-n...@test.cc:2 {{in instantiation of function template 
specialization 'a' requested here}}
+#endif
diff --git a/clang/test/Modules/expose-static-inline-from-gmf-2.cppm 
b/clang/test/Modules/expose-static-inline-from-gmf-2.cppm
new file mode 100644
index 00..c89b613f5074b1
--- /dev/null
+++ b/clang/test/Modules/expose-static-inline-from-gmf-2.cppm
@@ -0,0 +1,22 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split

[clang] [Clang][Sema] Expose static inline functions from GMF (PR #104701)

2024-08-18 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-modules

Author: Jan Kokemüller (jiixyj)


Changes

In C, it is a common pattern to have `static inline` functions in headers to 
avoid ODR issues. Currently, when those headers are included in a GMF, the 
names are not found when two-phase name lookup and ADL is involved. Those names 
are removed by `Sema::AddOverloadCandidate`.

Similarly, in C++, sometimes people use templates with internal linkage in 
headers.

As the GMF was designed to be a transitional mechanism for headers, special 
case those functions in `Sema::AddOverloadCandidate`.

This fixes ;.

---
Full diff: https://github.com/llvm/llvm-project/pull/104701.diff


6 Files Affected:

- (modified) clang/lib/Sema/SemaOverload.cpp (+19-4) 
- (added) clang/test/Modules/expose-static-inline-from-gmf-1.cppm (+37) 
- (added) clang/test/Modules/expose-static-inline-from-gmf-2.cppm (+22) 
- (added) clang/test/Modules/expose-static-inline-from-gmf-3.cppm (+24) 
- (added) clang/test/Modules/expose-static-inline-from-gmf-4.cppm (+40) 
- (added) clang/test/Modules/expose-static-inline-from-gmf-5.cppm (+26) 


``diff
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 52f640eb96b73b..ca070d0e22d472 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -6926,11 +6926,26 @@ void Sema::AddOverloadCandidate(
 /// have linkage. So that all entities of the same should share one
 /// linkage. But in clang, different entities of the same could have
 /// different linkage.
-NamedDecl *ND = Function;
-if (auto *SpecInfo = Function->getTemplateSpecializationInfo())
+const NamedDecl *ND = Function;
+bool IsImplicitlyInstantiated = false;
+if (auto *SpecInfo = Function->getTemplateSpecializationInfo()) {
   ND = SpecInfo->getTemplate();
-
-if (ND->getFormalLinkage() == Linkage::Internal) {
+  IsImplicitlyInstantiated = SpecInfo->getTemplateSpecializationKind() ==
+ TSK_ImplicitInstantiation;
+}
+
+/// Don't remove inline functions with internal linkage from the overload
+/// set if they are declared in a GMF.
+/// The global module is meant to be a transition mechanism for C and C++
+/// headers.
+/// Inline functions with internal linkage are a common pattern in headers
+/// to avoid ODR issues.
+const bool IsInlineFunctionInGMF =
+  Function->getOwningModule() &&
+  Function->getOwningModule()->isGlobalModule() &&
+  (IsImplicitlyInstantiated || Function->isInlined());
+
+if (ND->getFormalLinkage() == Linkage::Internal && !IsInlineFunctionInGMF) 
{
   Candidate.Viable = false;
   Candidate.FailureKind = ovl_fail_module_mismatched;
   return;
diff --git a/clang/test/Modules/expose-static-inline-from-gmf-1.cppm 
b/clang/test/Modules/expose-static-inline-from-gmf-1.cppm
new file mode 100644
index 00..4de9b583dac8da
--- /dev/null
+++ b/clang/test/Modules/expose-static-inline-from-gmf-1.cppm
@@ -0,0 +1,37 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang -std=c++20 %t/a.cppm --precompile -o %t/a.pcm \
+// RUN:   -DTEST_INLINE
+// RUN: %clang -std=c++20 %t/test.cc -fprebuilt-module-path=%t -fsyntax-only 
-Xclang -verify \
+// RUN:   -DTEST_INLINE
+//
+// RUN: %clang -std=c++20 %t/a.cppm --precompile -o %t/a.pcm
+// RUN: %clang -std=c++20 %t/test.cc -fprebuilt-module-path=%t -fsyntax-only 
-Xclang -verify
+
+//--- a.h
+#ifdef TEST_INLINE
+#define INLINE inline
+#else
+#define INLINE
+#endif
+static INLINE void func(long) {}
+template  void a() { func(T{}); }
+
+//--- a.cppm
+module;
+#include "a.h"
+export module a;
+export using ::a;
+
+//--- test.cc
+import a;
+auto m = (a(), 0);
+
+#ifdef TEST_INLINE
+// expected-no-diagnostics
+#else
+// expected-error@a.h:7 {{no matching function for call to 'func'}}
+// expected-n...@test.cc:2 {{in instantiation of function template 
specialization 'a' requested here}}
+#endif
diff --git a/clang/test/Modules/expose-static-inline-from-gmf-2.cppm 
b/clang/test/Modules/expose-static-inline-from-gmf-2.cppm
new file mode 100644
index 00..c89b613f5074b1
--- /dev/null
+++ b/clang/test/Modules/expose-static-inline-from-gmf-2.cppm
@@ -0,0 +1,22 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang -std=c++20 %t/a.cppm --precompile -o %t/a.pcm
+// RUN: %clang -std=c++20 %t/test.cc -fprebuilt-module-path=%t -fsyntax-only 
-Xclang -verify
+
+//--- a.h
+template  static inline void func() {}
+template  void a() { func(); }
+
+//--- a.cppm
+module;
+#include "a.h"
+export module a;
+export using ::a;
+
+//--- test.cc
+import a;
+auto m = (a(), 0);
+
+// expected-no-diagnostics
diff --git a/clang/test/Modules/expose-static-inline-from-gmf-3.cppm 
b/clang/test/Modules/expose-static-inline-from-gmf-3.cppm
new file m

[clang] [Clang][Sema] Expose static inline functions from GMF (PR #104701)

2024-08-18 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff dac182990dabe8d15cfb8079aba68df2ded015aa 
feaf6512fc6323ad0c3d5082c06e610504f0a527 --extensions cppm,cpp -- 
clang/test/Modules/expose-static-inline-from-gmf-1.cppm 
clang/test/Modules/expose-static-inline-from-gmf-2.cppm 
clang/test/Modules/expose-static-inline-from-gmf-3.cppm 
clang/test/Modules/expose-static-inline-from-gmf-4.cppm 
clang/test/Modules/expose-static-inline-from-gmf-5.cppm 
clang/lib/Sema/SemaOverload.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index ca070d0e22..594b607149 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -6941,9 +6941,9 @@ void Sema::AddOverloadCandidate(
 /// Inline functions with internal linkage are a common pattern in headers
 /// to avoid ODR issues.
 const bool IsInlineFunctionInGMF =
-  Function->getOwningModule() &&
-  Function->getOwningModule()->isGlobalModule() &&
-  (IsImplicitlyInstantiated || Function->isInlined());
+Function->getOwningModule() &&
+Function->getOwningModule()->isGlobalModule() &&
+(IsImplicitlyInstantiated || Function->isInlined());
 
 if (ND->getFormalLinkage() == Linkage::Internal && !IsInlineFunctionInGMF) 
{
   Candidate.Viable = false;

``




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


[clang] [Clang] `constexpr` builtin floating point classification / comparison functions (PR #94118)

2024-08-18 Thread Mital Ashok via cfe-commits

MitalAshok wrote:

@tbaederr Thanks for fixing the build bots. The leak appears to be unrelated to 
these changes and happen on this line:

https://github.com/llvm/llvm-project/blob/71801707e33c235656b172fa7dfb8662473a95c2/clang/test/Sema/constant-builtins-2.c#L309

It even happens with:

```c
int x = ((unsigned __int128)0) + __builtin_clzg(0u); // expected-error {{not a 
compile-time constant}}
```

Is there a different file that these tests should be added for? Like 
AST/ByteCode/builtin-functions.cpp?

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


[clang] [Clang][Sema] Expose static inline functions from GMF (PR #104701)

2024-08-18 Thread Jan Kokemüller via cfe-commits

https://github.com/jiixyj updated 
https://github.com/llvm/llvm-project/pull/104701

From feaf6512fc6323ad0c3d5082c06e610504f0a527 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20Kokem=C3=BCller?= 
Date: Sun, 18 Aug 2024 13:45:43 +0200
Subject: [PATCH 1/2] Expose static inline function from GMF

They should be exposed even when two-phase name lookup and ADL are
involved.
---
 clang/lib/Sema/SemaOverload.cpp   | 23 +--
 .../expose-static-inline-from-gmf-1.cppm  | 37 +
 .../expose-static-inline-from-gmf-2.cppm  | 22 ++
 .../expose-static-inline-from-gmf-3.cppm  | 24 +++
 .../expose-static-inline-from-gmf-4.cppm  | 40 +++
 .../expose-static-inline-from-gmf-5.cppm  | 26 
 6 files changed, 168 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/Modules/expose-static-inline-from-gmf-1.cppm
 create mode 100644 clang/test/Modules/expose-static-inline-from-gmf-2.cppm
 create mode 100644 clang/test/Modules/expose-static-inline-from-gmf-3.cppm
 create mode 100644 clang/test/Modules/expose-static-inline-from-gmf-4.cppm
 create mode 100644 clang/test/Modules/expose-static-inline-from-gmf-5.cppm

diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 52f640eb96b73b..ca070d0e22d472 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -6926,11 +6926,26 @@ void Sema::AddOverloadCandidate(
 /// have linkage. So that all entities of the same should share one
 /// linkage. But in clang, different entities of the same could have
 /// different linkage.
-NamedDecl *ND = Function;
-if (auto *SpecInfo = Function->getTemplateSpecializationInfo())
+const NamedDecl *ND = Function;
+bool IsImplicitlyInstantiated = false;
+if (auto *SpecInfo = Function->getTemplateSpecializationInfo()) {
   ND = SpecInfo->getTemplate();
-
-if (ND->getFormalLinkage() == Linkage::Internal) {
+  IsImplicitlyInstantiated = SpecInfo->getTemplateSpecializationKind() ==
+ TSK_ImplicitInstantiation;
+}
+
+/// Don't remove inline functions with internal linkage from the overload
+/// set if they are declared in a GMF.
+/// The global module is meant to be a transition mechanism for C and C++
+/// headers.
+/// Inline functions with internal linkage are a common pattern in headers
+/// to avoid ODR issues.
+const bool IsInlineFunctionInGMF =
+  Function->getOwningModule() &&
+  Function->getOwningModule()->isGlobalModule() &&
+  (IsImplicitlyInstantiated || Function->isInlined());
+
+if (ND->getFormalLinkage() == Linkage::Internal && !IsInlineFunctionInGMF) 
{
   Candidate.Viable = false;
   Candidate.FailureKind = ovl_fail_module_mismatched;
   return;
diff --git a/clang/test/Modules/expose-static-inline-from-gmf-1.cppm 
b/clang/test/Modules/expose-static-inline-from-gmf-1.cppm
new file mode 100644
index 00..4de9b583dac8da
--- /dev/null
+++ b/clang/test/Modules/expose-static-inline-from-gmf-1.cppm
@@ -0,0 +1,37 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang -std=c++20 %t/a.cppm --precompile -o %t/a.pcm \
+// RUN:   -DTEST_INLINE
+// RUN: %clang -std=c++20 %t/test.cc -fprebuilt-module-path=%t -fsyntax-only 
-Xclang -verify \
+// RUN:   -DTEST_INLINE
+//
+// RUN: %clang -std=c++20 %t/a.cppm --precompile -o %t/a.pcm
+// RUN: %clang -std=c++20 %t/test.cc -fprebuilt-module-path=%t -fsyntax-only 
-Xclang -verify
+
+//--- a.h
+#ifdef TEST_INLINE
+#define INLINE inline
+#else
+#define INLINE
+#endif
+static INLINE void func(long) {}
+template  void a() { func(T{}); }
+
+//--- a.cppm
+module;
+#include "a.h"
+export module a;
+export using ::a;
+
+//--- test.cc
+import a;
+auto m = (a(), 0);
+
+#ifdef TEST_INLINE
+// expected-no-diagnostics
+#else
+// expected-error@a.h:7 {{no matching function for call to 'func'}}
+// expected-n...@test.cc:2 {{in instantiation of function template 
specialization 'a' requested here}}
+#endif
diff --git a/clang/test/Modules/expose-static-inline-from-gmf-2.cppm 
b/clang/test/Modules/expose-static-inline-from-gmf-2.cppm
new file mode 100644
index 00..c89b613f5074b1
--- /dev/null
+++ b/clang/test/Modules/expose-static-inline-from-gmf-2.cppm
@@ -0,0 +1,22 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang -std=c++20 %t/a.cppm --precompile -o %t/a.pcm
+// RUN: %clang -std=c++20 %t/test.cc -fprebuilt-module-path=%t -fsyntax-only 
-Xclang -verify
+
+//--- a.h
+template  static inline void func() {}
+template  void a() { func(); }
+
+//--- a.cppm
+module;
+#include "a.h"
+export module a;
+export using ::a;
+
+//--- test.cc
+import a;
+auto m = (a(), 0);
+
+// expected-no-diagnostics
diff --git a/clang/test/Modules/expose-static-inline-from-gmf-3.cppm 
b/clang/test/Modules/expose-static-inline-from-gmf-3.cppm
new file mode 1006

[clang] [clang] fix divide by zero in ComplexExprEvaluator (PR #104666)

2024-08-18 Thread via cfe-commits

https://github.com/c8ef updated https://github.com/llvm/llvm-project/pull/104666

>From b58b9c3ad5fb2b37715ba9f52c905b6961159f0c Mon Sep 17 00:00:00 2001
From: c8ef 
Date: Sat, 17 Aug 2024 05:42:39 +
Subject: [PATCH 1/4] [clang] fix divide by zero in ComplexExprEvaluator

---
 clang/lib/AST/ExprConstant.cpp | 7 ---
 clang/test/SemaCXX/complex-div.cpp | 3 +++
 2 files changed, 7 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/SemaCXX/complex-div.cpp

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 7bfc63ffd81e28..aa902280f1861e 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -15567,12 +15567,13 @@ bool ComplexExprEvaluator::VisitBinaryOperator(const 
BinaryOperator *E) {
 HandleComplexComplexDiv(A, B, C, D, ResR, ResI);
   }
 } else {
-  if (RHS.getComplexIntReal() == 0 && RHS.getComplexIntImag() == 0)
-return Error(E, diag::note_expr_divide_by_zero);
-
   ComplexValue LHS = Result;
   APSInt Den = RHS.getComplexIntReal() * RHS.getComplexIntReal() +
 RHS.getComplexIntImag() * RHS.getComplexIntImag();
+  if ((RHS.getComplexIntReal() == 0 && RHS.getComplexIntImag() == 0) ||
+  Den.isZero())
+return Error(E, diag::note_expr_divide_by_zero);
+
   Result.getComplexIntReal() =
 (LHS.getComplexIntReal() * RHS.getComplexIntReal() +
  LHS.getComplexIntImag() * RHS.getComplexIntImag()) / Den;
diff --git a/clang/test/SemaCXX/complex-div.cpp 
b/clang/test/SemaCXX/complex-div.cpp
new file mode 100644
index 00..a5f9a79b8ebde0
--- /dev/null
+++ b/clang/test/SemaCXX/complex-div.cpp
@@ -0,0 +1,3 @@
+// RUN: %clang_cc1 -fsyntax-only %s
+
+auto f() { return 43273096 / 65536j; }

>From 8a0be6659ac649e45b7a04458c3266f9ba5d6315 Mon Sep 17 00:00:00 2001
From: c8ef 
Date: Sat, 17 Aug 2024 09:37:18 +
Subject: [PATCH 2/4] address CR comment

---
 clang/docs/ReleaseNotes.rst  | 1 +
 clang/test/SemaCXX/complex-div.cpp   | 3 ---
 clang/test/SemaCXX/constant-expression-cxx11.cpp | 3 +++
 3 files changed, 4 insertions(+), 3 deletions(-)
 delete mode 100644 clang/test/SemaCXX/complex-div.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ffdd063ec99037..71a7abc8db166a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -264,6 +264,7 @@ Bug Fixes to C++ Support
 - Properly reject defaulted copy/move assignment operators that have a 
non-reference explicit object parameter.
 - Clang now properly handles the order of attributes in `extern` blocks. 
(#GH101990).
 - Fixed an assertion failure by preventing null explicit object arguments from 
being deduced. (#GH102025).
+- Fixed a crash that occurred when dividing by zero in complex integer 
division. (#GH55390).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/test/SemaCXX/complex-div.cpp 
b/clang/test/SemaCXX/complex-div.cpp
deleted file mode 100644
index a5f9a79b8ebde0..00
--- a/clang/test/SemaCXX/complex-div.cpp
+++ /dev/null
@@ -1,3 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only %s
-
-auto f() { return 43273096 / 65536j; }
diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp 
b/clang/test/SemaCXX/constant-expression-cxx11.cpp
index d87bd8c6f3..44ef540f41fa8c 100644
--- a/clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -1268,6 +1268,9 @@ constexpr complex_wrap makeComplexWrap(int re, int im) {
 static_assert(makeComplexWrap(1,0) == complex(1), "");
 static_assert(makeComplexWrap(1,0) != complex(0, 1), "");
 
+constexpr auto GH55390 = 1 / 65536j; // expected-note {{division by zero}} \
+ // expected-error {{constexpr variable 
'GH55390' must be initialized by a constant expression}} \
+ // expected-warning {{imaginary constants 
are a GNU extension}}
 }
 
 namespace PR11595 {

>From 73a9f7bb42d10ec2df2f2f1f2d5fc9ae939d266b Mon Sep 17 00:00:00 2001
From: c8ef 
Date: Sat, 17 Aug 2024 09:43:40 +
Subject: [PATCH 3/4] relocate note

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

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 71a7abc8db166a..c28fbd881eda86 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -264,11 +264,12 @@ Bug Fixes to C++ Support
 - Properly reject defaulted copy/move assignment operators that have a 
non-reference explicit object parameter.
 - Clang now properly handles the order of attributes in `extern` blocks. 
(#GH101990).
 - Fixed an assertion failure by preventing null explicit object arguments from 
being deduced. (#GH102025).
-- Fixed a crash that occurred when dividing by zero in complex integer 
division. (#GH55390).
 
 Bug Fixes to AST Handling
 ^
 
+- Fixed a crash that occurred when 

[clang] [clang] fix divide by zero in ComplexExprEvaluator (PR #104666)

2024-08-18 Thread via cfe-commits


@@ -15567,12 +15567,13 @@ bool ComplexExprEvaluator::VisitBinaryOperator(const 
BinaryOperator *E) {
 HandleComplexComplexDiv(A, B, C, D, ResR, ResI);
   }
 } else {
-  if (RHS.getComplexIntReal() == 0 && RHS.getComplexIntImag() == 0)
-return Error(E, diag::note_expr_divide_by_zero);
-
   ComplexValue LHS = Result;
   APSInt Den = RHS.getComplexIntReal() * RHS.getComplexIntReal() +
 RHS.getComplexIntImag() * RHS.getComplexIntImag();
+  if ((RHS.getComplexIntReal() == 0 && RHS.getComplexIntImag() == 0) ||
+  Den.isZero())

c8ef wrote:

done

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


[clang] [clang] fix divide by zero in ComplexExprEvaluator (PR #104666)

2024-08-18 Thread Sergei Barannikov via cfe-commits

https://github.com/s-barannikov approved this pull request.


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


[clang] [Clang] warn on discarded [[nodiscard]] function results after casting in C (PR #104677)

2024-08-18 Thread Oleksandr T. via cfe-commits

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


[clang] [Clang] `constexpr` builtin floating point classification / comparison functions (PR #94118)

2024-08-18 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Yeah it's a well known problem.

> Is there a different file that these tests should be added for? Like 
> AST/ByteCode/builtin-functions.cpp?

That should work. I have sanitizers enabled locally so I can test the changes 
if you want.

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


[clang] [Clang][test] Add bytecode interpreter tests for floating comparison functions (PR #104703)

2024-08-18 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok created 
https://github.com/llvm/llvm-project/pull/104703

See also: #94118, 71801707e33c235656b172fa7dfb8662473a95c2


>From 76735bd57b948dcbd366a80b846be38f0bf8c41e Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Sun, 18 Aug 2024 14:12:51 +0100
Subject: [PATCH] [Clang][test] Add bytecode interpreter tests for floating
 comparison functions

---
 clang/test/AST/ByteCode/builtin-functions.cpp | 45 +++
 1 file changed, 45 insertions(+)

diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp 
b/clang/test/AST/ByteCode/builtin-functions.cpp
index b179298fee9bde..1cff2228cd7a97 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -193,6 +193,51 @@ namespace isfpclass {
   char isfpclass_snan_3   [!__builtin_isfpclass(__builtin_nans(""), 0x01F8) ? 
1 : -1]; // fcFinite
 }
 
+namespace signbit {
+  static_assert(
+!__builtin_signbit(1.0) && __builtin_signbit(-1.0) && 
!__builtin_signbit(0.0) && __builtin_signbit(-0.0) &&
+!__builtin_signbitf(1.0f) && __builtin_signbitf(-1.0f) && 
!__builtin_signbitf(0.0f) && __builtin_signbitf(-0.0f) &&
+!__builtin_signbitl(1.0L) && __builtin_signbitf(-1.0L) && 
!__builtin_signbitf(0.0L) && __builtin_signbitf(-0.0L) &&
+!__builtin_signbit(1.0f) && __builtin_signbit(-1.0f) && 
!__builtin_signbit(0.0f) && __builtin_signbit(-0.0f) &&
+!__builtin_signbit(1.0L) && __builtin_signbit(-1.0L) && 
!__builtin_signbit(0.0L) && __builtin_signbit(-0.0L) &&
+true, ""
+  );
+}
+
+namespace floating_comparison {
+#define LESS(X, Y) \
+  !__builtin_isgreater(X, Y) && __builtin_isgreater(Y, X) && \
+  !__builtin_isgreaterequal(X, Y) && __builtin_isgreaterequal(Y, X) &&   \
+  __builtin_isless(X, Y) && !__builtin_isless(Y, X) &&   \
+  __builtin_islessequal(X, Y) && !__builtin_islessequal(Y, X) && \
+  __builtin_islessgreater(X, Y) && __builtin_islessgreater(Y, X) &&  \
+  !__builtin_isunordered(X, Y) && !__builtin_isunordered(Y, X)
+#define EQUAL(X, Y) \
+  !__builtin_isgreater(X, Y) && !__builtin_isgreater(Y, X) &&\
+  __builtin_isgreaterequal(X, Y) && __builtin_isgreaterequal(Y, X) &&\
+  !__builtin_isless(X, Y) && !__builtin_isless(Y, X) &&  \
+  __builtin_islessequal(X, Y) && __builtin_islessequal(Y, X) &&  \
+  !__builtin_islessgreater(X, Y) && !__builtin_islessgreater(Y, X) &&\
+  !__builtin_isunordered(X, Y) && !__builtin_isunordered(Y, X)
+#define UNORDERED(X, Y) \
+  !__builtin_isgreater(X, Y) && !__builtin_isgreater(Y, X) &&\
+  !__builtin_isgreaterequal(X, Y) && !__builtin_isgreaterequal(Y, X) &&  \
+  !__builtin_isless(X, Y) && !__builtin_isless(Y, X) &&  \
+  !__builtin_islessequal(X, Y) && !__builtin_islessequal(Y, X) &&\
+  !__builtin_islessgreater(X, Y) && !__builtin_islessgreater(Y, X) &&\
+  __builtin_isunordered(X, Y) && __builtin_isunordered(Y, X)
+
+  static_assert(
+LESS(0.0, 1.0) && EQUAL(1.0, 1.0) && EQUAL(0.0, -0.0) &&
+UNORDERED(__builtin_nan(""), 1.0) && UNORDERED(__builtin_nan(""), 
__builtin_inf()) && LESS(0.0, __builtin_inf()) &&
+LESS(0.0f, 1.0f) && EQUAL(1.0f, 1.0f) && EQUAL(0.0f, -0.0f) &&
+UNORDERED(__builtin_nanf(""), 1.0f) && UNORDERED(__builtin_nanf(""), 
__builtin_inff()) && LESS(0.0f, __builtin_inff()) &&
+LESS(0.0L, 1.0L) && EQUAL(1.0L, 1.0L) && EQUAL(0.0L, -0.0L) &&
+UNORDERED(__builtin_nanl(""), 1.0L) && UNORDERED(__builtin_nanl(""), 
__builtin_infl()) && LESS(0.0L, __builtin_infl()) &&
+true, ""
+  );
+}
+
 namespace fpclassify {
   char classify_nan [__builtin_fpclassify(+1, -1, -1, -1, -1, 
__builtin_nan(""))];
   char classify_snan[__builtin_fpclassify(+1, -1, -1, -1, -1, 
__builtin_nans(""))];

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


[clang] [Clang][test] Add bytecode interpreter tests for floating comparison functions (PR #104703)

2024-08-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Mital Ashok (MitalAshok)


Changes

See also: #94118, 71801707e33c235656b172fa7dfb8662473a95c2


---
Full diff: https://github.com/llvm/llvm-project/pull/104703.diff


1 Files Affected:

- (modified) clang/test/AST/ByteCode/builtin-functions.cpp (+45) 


``diff
diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp 
b/clang/test/AST/ByteCode/builtin-functions.cpp
index b179298fee9bd..1cff2228cd7a9 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -193,6 +193,51 @@ namespace isfpclass {
   char isfpclass_snan_3   [!__builtin_isfpclass(__builtin_nans(""), 0x01F8) ? 
1 : -1]; // fcFinite
 }
 
+namespace signbit {
+  static_assert(
+!__builtin_signbit(1.0) && __builtin_signbit(-1.0) && 
!__builtin_signbit(0.0) && __builtin_signbit(-0.0) &&
+!__builtin_signbitf(1.0f) && __builtin_signbitf(-1.0f) && 
!__builtin_signbitf(0.0f) && __builtin_signbitf(-0.0f) &&
+!__builtin_signbitl(1.0L) && __builtin_signbitf(-1.0L) && 
!__builtin_signbitf(0.0L) && __builtin_signbitf(-0.0L) &&
+!__builtin_signbit(1.0f) && __builtin_signbit(-1.0f) && 
!__builtin_signbit(0.0f) && __builtin_signbit(-0.0f) &&
+!__builtin_signbit(1.0L) && __builtin_signbit(-1.0L) && 
!__builtin_signbit(0.0L) && __builtin_signbit(-0.0L) &&
+true, ""
+  );
+}
+
+namespace floating_comparison {
+#define LESS(X, Y) \
+  !__builtin_isgreater(X, Y) && __builtin_isgreater(Y, X) && \
+  !__builtin_isgreaterequal(X, Y) && __builtin_isgreaterequal(Y, X) &&   \
+  __builtin_isless(X, Y) && !__builtin_isless(Y, X) &&   \
+  __builtin_islessequal(X, Y) && !__builtin_islessequal(Y, X) && \
+  __builtin_islessgreater(X, Y) && __builtin_islessgreater(Y, X) &&  \
+  !__builtin_isunordered(X, Y) && !__builtin_isunordered(Y, X)
+#define EQUAL(X, Y) \
+  !__builtin_isgreater(X, Y) && !__builtin_isgreater(Y, X) &&\
+  __builtin_isgreaterequal(X, Y) && __builtin_isgreaterequal(Y, X) &&\
+  !__builtin_isless(X, Y) && !__builtin_isless(Y, X) &&  \
+  __builtin_islessequal(X, Y) && __builtin_islessequal(Y, X) &&  \
+  !__builtin_islessgreater(X, Y) && !__builtin_islessgreater(Y, X) &&\
+  !__builtin_isunordered(X, Y) && !__builtin_isunordered(Y, X)
+#define UNORDERED(X, Y) \
+  !__builtin_isgreater(X, Y) && !__builtin_isgreater(Y, X) &&\
+  !__builtin_isgreaterequal(X, Y) && !__builtin_isgreaterequal(Y, X) &&  \
+  !__builtin_isless(X, Y) && !__builtin_isless(Y, X) &&  \
+  !__builtin_islessequal(X, Y) && !__builtin_islessequal(Y, X) &&\
+  !__builtin_islessgreater(X, Y) && !__builtin_islessgreater(Y, X) &&\
+  __builtin_isunordered(X, Y) && __builtin_isunordered(Y, X)
+
+  static_assert(
+LESS(0.0, 1.0) && EQUAL(1.0, 1.0) && EQUAL(0.0, -0.0) &&
+UNORDERED(__builtin_nan(""), 1.0) && UNORDERED(__builtin_nan(""), 
__builtin_inf()) && LESS(0.0, __builtin_inf()) &&
+LESS(0.0f, 1.0f) && EQUAL(1.0f, 1.0f) && EQUAL(0.0f, -0.0f) &&
+UNORDERED(__builtin_nanf(""), 1.0f) && UNORDERED(__builtin_nanf(""), 
__builtin_inff()) && LESS(0.0f, __builtin_inff()) &&
+LESS(0.0L, 1.0L) && EQUAL(1.0L, 1.0L) && EQUAL(0.0L, -0.0L) &&
+UNORDERED(__builtin_nanl(""), 1.0L) && UNORDERED(__builtin_nanl(""), 
__builtin_infl()) && LESS(0.0L, __builtin_infl()) &&
+true, ""
+  );
+}
+
 namespace fpclassify {
   char classify_nan [__builtin_fpclassify(+1, -1, -1, -1, -1, 
__builtin_nan(""))];
   char classify_snan[__builtin_fpclassify(+1, -1, -1, -1, -1, 
__builtin_nans(""))];

``




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


[clang] [Clang][test] Add bytecode interpreter tests for floating comparison functions (PR #104703)

2024-08-18 Thread Mital Ashok via cfe-commits

MitalAshok wrote:

@tbaederr I've basically just copied over the tests from the other file.  
There's no other quad-precision (`__float128`) tests so they were removed.  
Do these need to be rewritten in a C++ style? (i.e., replace the macros with 
template functions)


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


[clang] [Clang] CWG722: nullptr to ellipses (PR #104704)

2024-08-18 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok created 
https://github.com/llvm/llvm-project/pull/104704

https://cplusplus.github.io/CWG/issues/722.html

nullptr passed to a variadic function now converted to void* in C++. This does 
not affect C23 nullptr.

Also fixes -Wformat-pedantic so that it no longer warns for nullptr passed to 
%p (because it is converted to void* in C++ and it is allowed for va_arg(ap, 
void*) in C23)


>From 1ecb1a5ddcd6256d46bc4293d0adbeb18ca590c1 Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Sun, 23 Jul 2023 15:33:01 +0100
Subject: [PATCH] [Clang] CWG722: nullptr to ellipses

https://cplusplus.github.io/CWG/issues/722.html

nullptr passed to a variadic function now converted to void* in C++.
This does not affect C23 nullptr.

Also fixes -Wformat-pedantic so that it no longer warns for nullptr
passed to %p (because it is converted to void* in C++ and it is
allowed for va_arg(ap, void*) in C23)
---
 clang/docs/ReleaseNotes.rst   |  3 ++
 clang/lib/AST/FormatString.cpp| 57 +++
 clang/lib/Sema/SemaExpr.cpp   | 13 --
 clang/test/CXX/drs/cwg722.cpp | 56 ++
 clang/test/CXX/drs/cwg7xx.cpp |  2 +
 clang/test/Sema/format-pointer.c  | 53 +
 clang/test/Sema/format-strings-pedantic.c |  5 +-
 clang/www/cxx_dr_status.html  |  2 +-
 8 files changed, 154 insertions(+), 37 deletions(-)
 create mode 100644 clang/test/CXX/drs/cwg722.cpp
 create mode 100644 clang/test/Sema/format-pointer.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 11301e4c7dc4a2..6993c219dfcb79 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -149,6 +149,9 @@ Resolutions to C++ Defect Reports
   of the target type, even if the type of the bit-field is larger.
   (`CWG2627: Bit-fields and narrowing conversions 
`_)
 
+- ``nullptr`` is now promoted to ``void*`` when passed to a C-style variadic 
function.
+  (`CWG722: Can nullptr be passed to an ellipsis? 
`_)
+
 C Language Changes
 --
 
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index da8164bad518ec..e892c1592df986 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -520,33 +520,18 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const 
{
   return NoMatch;
 }
 
-case CStrTy: {
-  const PointerType *PT = argTy->getAs();
-  if (!PT)
-return NoMatch;
-  QualType pointeeTy = PT->getPointeeType();
-  if (const BuiltinType *BT = pointeeTy->getAs())
-switch (BT->getKind()) {
-  case BuiltinType::Char_U:
-  case BuiltinType::UChar:
-  case BuiltinType::Char_S:
-  case BuiltinType::SChar:
-return Match;
-  default:
-break;
-}
-
+case CStrTy:
+  if (const auto *PT = argTy->getAs();
+  PT && PT->getPointeeType()->isCharType())
+return Match;
   return NoMatch;
-}
 
-case WCStrTy: {
-  const PointerType *PT = argTy->getAs();
-  if (!PT)
-return NoMatch;
-  QualType pointeeTy =
-C.getCanonicalType(PT->getPointeeType()).getUnqualifiedType();
-  return pointeeTy == C.getWideCharType() ? Match : NoMatch;
-}
+case WCStrTy:
+  if (const auto *PT = argTy->getAs();
+  PT &&
+  C.hasSameUnqualifiedType(PT->getPointeeType(), C.getWideCharType()))
+return Match;
+  return NoMatch;
 
 case WIntTy: {
   QualType WInt = C.getCanonicalType(C.getWIntType()).getUnqualifiedType();
@@ -569,15 +554,25 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const 
{
 }
 
 case CPointerTy:
-  if (argTy->isVoidPointerType()) {
-return Match;
-  } if (argTy->isPointerType() || argTy->isObjCObjectPointerType() ||
-argTy->isBlockPointerType() || argTy->isNullPtrType()) {
+  if (const auto *PT = argTy->getAs()) {
+QualType PointeeTy = PT->getPointeeType();
+if (PointeeTy->isVoidType() || (!Ptr && PointeeTy->isCharType()))
+  return Match;
 return NoMatchPedantic;
-  } else {
-return NoMatch;
   }
 
+  // nullptr_t* is not a double pointer, so reject when something like
+  // void** is expected.
+  // In C++, nullptr is promoted to void*. In C23, va_arg(ap, void*) is not
+  // undefined when the next argument is of type nullptr_t.
+  if (!Ptr && argTy->isNullPtrType())
+return C.getLangOpts().CPlusPlus ? MatchPromotion : Match;
+
+  if (argTy->isObjCObjectPointerType() || argTy->isBlockPointerType())
+return NoMatchPedantic;
+
+  return NoMatch;
+
 case ObjCPointerTy: {
   if (argTy->getAs() ||
   argTy->getAs())
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/

[clang] [Clang] CWG722: nullptr to ellipses (PR #104704)

2024-08-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Mital Ashok (MitalAshok)


Changes

https://cplusplus.github.io/CWG/issues/722.html

nullptr passed to a variadic function now converted to void* in C++. This does 
not affect C23 nullptr.

Also fixes -Wformat-pedantic so that it no longer warns for nullptr passed to 
%p (because it is converted to void* in C++ and it is allowed for va_arg(ap, 
void*) in C23)


---
Full diff: https://github.com/llvm/llvm-project/pull/104704.diff


8 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+3) 
- (modified) clang/lib/AST/FormatString.cpp (+26-31) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+10-3) 
- (added) clang/test/CXX/drs/cwg722.cpp (+56) 
- (modified) clang/test/CXX/drs/cwg7xx.cpp (+2) 
- (added) clang/test/Sema/format-pointer.c (+53) 
- (modified) clang/test/Sema/format-strings-pedantic.c (+3-2) 
- (modified) clang/www/cxx_dr_status.html (+1-1) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 11301e4c7dc4a2..6993c219dfcb79 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -149,6 +149,9 @@ Resolutions to C++ Defect Reports
   of the target type, even if the type of the bit-field is larger.
   (`CWG2627: Bit-fields and narrowing conversions 
`_)
 
+- ``nullptr`` is now promoted to ``void*`` when passed to a C-style variadic 
function.
+  (`CWG722: Can nullptr be passed to an ellipsis? 
`_)
+
 C Language Changes
 --
 
diff --git a/clang/lib/AST/FormatString.cpp b/clang/lib/AST/FormatString.cpp
index da8164bad518ec..e892c1592df986 100644
--- a/clang/lib/AST/FormatString.cpp
+++ b/clang/lib/AST/FormatString.cpp
@@ -520,33 +520,18 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const 
{
   return NoMatch;
 }
 
-case CStrTy: {
-  const PointerType *PT = argTy->getAs();
-  if (!PT)
-return NoMatch;
-  QualType pointeeTy = PT->getPointeeType();
-  if (const BuiltinType *BT = pointeeTy->getAs())
-switch (BT->getKind()) {
-  case BuiltinType::Char_U:
-  case BuiltinType::UChar:
-  case BuiltinType::Char_S:
-  case BuiltinType::SChar:
-return Match;
-  default:
-break;
-}
-
+case CStrTy:
+  if (const auto *PT = argTy->getAs();
+  PT && PT->getPointeeType()->isCharType())
+return Match;
   return NoMatch;
-}
 
-case WCStrTy: {
-  const PointerType *PT = argTy->getAs();
-  if (!PT)
-return NoMatch;
-  QualType pointeeTy =
-C.getCanonicalType(PT->getPointeeType()).getUnqualifiedType();
-  return pointeeTy == C.getWideCharType() ? Match : NoMatch;
-}
+case WCStrTy:
+  if (const auto *PT = argTy->getAs();
+  PT &&
+  C.hasSameUnqualifiedType(PT->getPointeeType(), C.getWideCharType()))
+return Match;
+  return NoMatch;
 
 case WIntTy: {
   QualType WInt = C.getCanonicalType(C.getWIntType()).getUnqualifiedType();
@@ -569,15 +554,25 @@ ArgType::matchesType(ASTContext &C, QualType argTy) const 
{
 }
 
 case CPointerTy:
-  if (argTy->isVoidPointerType()) {
-return Match;
-  } if (argTy->isPointerType() || argTy->isObjCObjectPointerType() ||
-argTy->isBlockPointerType() || argTy->isNullPtrType()) {
+  if (const auto *PT = argTy->getAs()) {
+QualType PointeeTy = PT->getPointeeType();
+if (PointeeTy->isVoidType() || (!Ptr && PointeeTy->isCharType()))
+  return Match;
 return NoMatchPedantic;
-  } else {
-return NoMatch;
   }
 
+  // nullptr_t* is not a double pointer, so reject when something like
+  // void** is expected.
+  // In C++, nullptr is promoted to void*. In C23, va_arg(ap, void*) is not
+  // undefined when the next argument is of type nullptr_t.
+  if (!Ptr && argTy->isNullPtrType())
+return C.getLangOpts().CPlusPlus ? MatchPromotion : Match;
+
+  if (argTy->isObjCObjectPointerType() || argTy->isBlockPointerType())
+return NoMatchPedantic;
+
+  return NoMatch;
+
 case ObjCPointerTy: {
   if (argTy->getAs() ||
   argTy->getAs())
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index f495658fe58641..c67183df335dd5 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -923,6 +923,13 @@ ExprResult Sema::DefaultArgumentPromotion(Expr *E) {
 E = Temp.get();
   }
 
+  // C++ [expr.call]p7, per CWG722:
+  //   An argument that has (possibly cv-qualified) type std::nullptr_t is
+  //   converted to void* ([conv.ptr]).
+  // (This does not apply to C23 nullptr)
+  if (getLangOpts().CPlusPlus && E->getType()->isNullPtrType())
+E = ImpCastExprToType(E, Context.VoidPtrTy, CK_NullToPointer).get();
+
   return E;
 }
 
@@ -933,9 +940,9 @@ Sema::VarArgKind

[clang] [Clang] CWG722: nullptr to ellipses (PR #104704)

2024-08-18 Thread Mital Ashok via cfe-commits

MitalAshok wrote:

This was originally part of https://reviews.llvm.org/D156054 (Previously 
reviewed by @AaronBallman), but there have been a lot of changes.


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


[clang] [HIP] search fatbin symbols for libs passed by -l (PR #104638)

2024-08-18 Thread Yaxun Liu via cfe-commits


@@ -76,8 +79,75 @@ class HIPUndefinedFatBinSymbols {
 return GPUBinHandleSymbols;
   }
 
+  // Collect symbols from static libraries specified by -l options.
+  void processStaticLibraries() {
+llvm::SmallVector LibNames;
+llvm::SmallVector LibPaths;
+llvm::SmallVector ExactLibNames;
+llvm::Triple Triple(C.getDriver().getTargetTriple());
+bool IsMSVC = Triple.isWindowsMSVCEnvironment();
+llvm::StringRef Ext = IsMSVC ? ".lib" : ".a";
+
+for (const auto *Arg : Args.filtered(options::OPT_l)) {
+  llvm::StringRef Value = Arg->getValue();
+  if (Value.starts_with(":"))
+ExactLibNames.push_back(Value.drop_front());
+  else
+LibNames.push_back(Value);
+}
+for (const auto *Arg : Args.filtered(options::OPT_L)) {
+  auto Path = Arg->getValue();
+  LibPaths.push_back(Path);
+  if (Verbose)
+llvm::errs() << "HIP fatbin symbol search uses library path:  " << Path
+ << "\n";
+}
+
+auto ProcessLib = [&](llvm::StringRef LibName, bool IsExact) {
+  llvm::SmallString<256> FullLibName;
+  if (IsExact)
+FullLibName = LibName;
+  else {
+if (IsMSVC)
+  (llvm::Twine(LibName) + Ext).toVector(FullLibName);
+else
+  (llvm::Twine("lib") + LibName + Ext).toVector(FullLibName);
+  }

yxsamliu wrote:

will use the first suggestion. with minor change Twine("lib") for it to work

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


[clang] [HIP] search fatbin symbols for libs passed by -l (PR #104638)

2024-08-18 Thread Yaxun Liu via cfe-commits


@@ -76,8 +79,75 @@ class HIPUndefinedFatBinSymbols {
 return GPUBinHandleSymbols;
   }
 
+  // Collect symbols from static libraries specified by -l options.
+  void processStaticLibraries() {
+llvm::SmallVector LibNames;
+llvm::SmallVector LibPaths;
+llvm::SmallVector ExactLibNames;
+llvm::Triple Triple(C.getDriver().getTargetTriple());
+bool IsMSVC = Triple.isWindowsMSVCEnvironment();
+llvm::StringRef Ext = IsMSVC ? ".lib" : ".a";
+
+for (const auto *Arg : Args.filtered(options::OPT_l)) {
+  llvm::StringRef Value = Arg->getValue();
+  if (Value.starts_with(":"))
+ExactLibNames.push_back(Value.drop_front());
+  else
+LibNames.push_back(Value);
+}
+for (const auto *Arg : Args.filtered(options::OPT_L)) {
+  auto Path = Arg->getValue();
+  LibPaths.push_back(Path);
+  if (Verbose)
+llvm::errs() << "HIP fatbin symbol search uses library path:  " << Path
+ << "\n";
+}
+
+auto ProcessLib = [&](llvm::StringRef LibName, bool IsExact) {
+  llvm::SmallString<256> FullLibName;
+  if (IsExact)
+FullLibName = LibName;
+  else {
+if (IsMSVC)
+  (llvm::Twine(LibName) + Ext).toVector(FullLibName);
+else
+  (llvm::Twine("lib") + LibName + Ext).toVector(FullLibName);
+  }
+
+  bool Found = false;
+  for (const auto &Path : LibPaths) {
+llvm::SmallString<256> FullPath = Path;
+llvm::sys::path::append(FullPath, FullLibName);
+
+if (llvm::sys::fs::exists(FullPath)) {
+  if (Verbose)
+llvm::errs() << "HIP fatbin symbol search found library: "
+ << FullPath << "\n";
+  auto BufferOrErr = llvm::MemoryBuffer::getFile(FullPath);
+  if (!BufferOrErr) {
+errorHandler(llvm::errorCodeToError(BufferOrErr.getError()));
+continue;
+  }
+  processInput(BufferOrErr.get()->getMemBufferRef());
+  Found = true;
+  break;
+}
+  }
+  if (!Found && Verbose)
+llvm::errs() << "HIP fatbin symbol search could not find library: "
+ << FullLibName << "\n";
+};
+
+for (const auto &LibName : ExactLibNames)

yxsamliu wrote:

will do

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


[clang] [HIP] search fatbin symbols for libs passed by -l (PR #104638)

2024-08-18 Thread Yaxun Liu via cfe-commits

https://github.com/yxsamliu updated 
https://github.com/llvm/llvm-project/pull/104638

>From 3c281d8cfc99674f2a4de0dfe5e1f02e35e68d6d Mon Sep 17 00:00:00 2001
From: "Yaxun (Sam) Liu" 
Date: Fri, 16 Aug 2024 14:24:08 -0400
Subject: [PATCH] [HIP] search fatbin symbols for libs passed by -l

For -fgpu-rdc linking, clang needs to collect undefined fatbin
symbols and resolve them to the embedded fatbin.

This has been done for object files and archive files passed
as input files to clang.

However, the same action is not performed for archive files passed
through -l options, which causes missing fatbin symbols.
---
 clang/lib/Driver/ToolChains/HIPUtility.cpp | 75 --
 clang/test/Driver/hip-toolchain-rdc.hip| 23 +++
 2 files changed, 93 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/HIPUtility.cpp 
b/clang/lib/Driver/ToolChains/HIPUtility.cpp
index f32a23f111e4bf..f3adb8bbc72aea 100644
--- a/clang/lib/Driver/ToolChains/HIPUtility.cpp
+++ b/clang/lib/Driver/ToolChains/HIPUtility.cpp
@@ -52,13 +52,16 @@ static std::string normalizeForBundler(const llvm::Triple 
&T,
 // input object or archive files.
 class HIPUndefinedFatBinSymbols {
 public:
-  HIPUndefinedFatBinSymbols(const Compilation &C)
-  : C(C), DiagID(C.getDriver().getDiags().getCustomDiagID(
-  DiagnosticsEngine::Error,
-  "Error collecting HIP undefined fatbin symbols: %0")),
+  HIPUndefinedFatBinSymbols(const Compilation &C,
+const llvm::opt::ArgList &Args_)
+  : C(C), Args(Args_),
+DiagID(C.getDriver().getDiags().getCustomDiagID(
+DiagnosticsEngine::Error,
+"Error collecting HIP undefined fatbin symbols: %0")),
 Quiet(C.getArgs().hasArg(options::OPT__HASH_HASH_HASH)),
 Verbose(C.getArgs().hasArg(options::OPT_v)) {
 populateSymbols();
+processStaticLibraries();
 if (Verbose) {
   for (const auto &Name : FatBinSymbols)
 llvm::errs() << "Found undefined HIP fatbin symbol: " << Name << "\n";
@@ -76,8 +79,70 @@ class HIPUndefinedFatBinSymbols {
 return GPUBinHandleSymbols;
   }
 
+  // Collect symbols from static libraries specified by -l options.
+  void processStaticLibraries() {
+llvm::SmallVector LibNames;
+llvm::SmallVector LibPaths;
+llvm::SmallVector ExactLibNames;
+llvm::Triple Triple(C.getDriver().getTargetTriple());
+bool IsMSVC = Triple.isWindowsMSVCEnvironment();
+llvm::StringRef Ext = IsMSVC ? ".lib" : ".a";
+
+for (const auto *Arg : Args.filtered(options::OPT_l)) {
+  llvm::StringRef Value = Arg->getValue();
+  if (Value.starts_with(":"))
+ExactLibNames.push_back(Value.drop_front());
+  else
+LibNames.push_back(Value);
+}
+for (const auto *Arg : Args.filtered(options::OPT_L)) {
+  auto Path = Arg->getValue();
+  LibPaths.push_back(Path);
+  if (Verbose)
+llvm::errs() << "HIP fatbin symbol search uses library path:  " << Path
+ << "\n";
+}
+
+auto ProcessLib = [&](llvm::StringRef LibName, bool IsExact) {
+  Twine LibNameTwine = IsExact  ? LibName
+   : IsMSVC ? LibName + Ext
+: Twine("lib") + LibName + Ext;
+  llvm::SmallString<256> FullLibName(LibNameTwine.str());
+
+  bool Found = false;
+  for (const auto Path : LibPaths) {
+llvm::SmallString<256> FullPath = Path;
+llvm::sys::path::append(FullPath, FullLibName);
+
+if (llvm::sys::fs::exists(FullPath)) {
+  if (Verbose)
+llvm::errs() << "HIP fatbin symbol search found library: "
+ << FullPath << "\n";
+  auto BufferOrErr = llvm::MemoryBuffer::getFile(FullPath);
+  if (!BufferOrErr) {
+errorHandler(llvm::errorCodeToError(BufferOrErr.getError()));
+continue;
+  }
+  processInput(BufferOrErr.get()->getMemBufferRef());
+  Found = true;
+  break;
+}
+  }
+  if (!Found && Verbose)
+llvm::errs() << "HIP fatbin symbol search could not find library: "
+ << FullLibName << "\n";
+};
+
+for (const auto LibName : ExactLibNames)
+  ProcessLib(LibName, true);
+
+for (const auto LibName : LibNames)
+  ProcessLib(LibName, false);
+  }
+
 private:
   const Compilation &C;
+  const llvm::opt::ArgList &Args;
   unsigned DiagID;
   bool Quiet;
   bool Verbose;
@@ -301,7 +366,7 @@ void HIP::constructGenerateObjFileFromHIPFatBinary(
   auto HostTriple =
   C.getSingleOffloadToolChain()->getTriple();
 
-  HIPUndefinedFatBinSymbols Symbols(C);
+  HIPUndefinedFatBinSymbols Symbols(C, Args);
 
   std::string PrimaryHipFatbinSymbol;
   std::string PrimaryGpuBinHandleSymbol;
diff --git a/clang/test/Driver/hip-toolchain-rdc.hip 
b/clang/test/Driver/hip-toolchain-rdc.hip
index 7e6697a0e254f6..ec79bf06afb92c 100644
--- a/clang/test/Driver/hi

[clang] [flang] [flang][driver] Add pre-processing type to `.i` files (PR #104664)

2024-08-18 Thread Kareem Ergawy via cfe-commits

https://github.com/ergawy updated 
https://github.com/llvm/llvm-project/pull/104664

>From 88baab5e4f1f37e7238d11aa416b3bc57cf961fe Mon Sep 17 00:00:00 2001
From: ergawy 
Date: Sat, 17 Aug 2024 00:20:11 -0500
Subject: [PATCH] [flang][driver] Add pre-processing type to `.i` files

This diff allows `.i` files emitted by flang-new to be treated as valid
files in the pre-processing phase. This, in turn, allows flang-new to
add pre-processing options (e.g. `-I`) when launching compilation jobs
for these files.

This solves a bug when using `--save-temps` with source files that
include modules from non-standard directories, for example:
```
flang-new -c --save-temps -I/tmp/module_dir -fno-integrated-as \
  /tmp/ModuleUser.f90
```
The problem was that `.i` files were treated as "binary" files and
therefore the return value for `types::getPreprocessedType(InputType)`
in `Flang::ConstructJob(...)` was `types::TY_INVALID`.
---
 clang/include/clang/Driver/Types.def|  2 +-
 flang/test/Driver/save-temps-use-module.f90 | 26 +
 2 files changed, 27 insertions(+), 1 deletion(-)
 create mode 100644 flang/test/Driver/save-temps-use-module.f90

diff --git a/clang/include/clang/Driver/Types.def 
b/clang/include/clang/Driver/Types.def
index 0e0cae5fb7068d..b4e9e1f9f3f8b6 100644
--- a/clang/include/clang/Driver/Types.def
+++ b/clang/include/clang/Driver/Types.def
@@ -79,7 +79,7 @@ TYPE("c++-module-cpp-output",PP_CXXModule, INVALID,   
  "iim",phases
 TYPE("ada",  Ada,  INVALID, nullptr,  
phases::Compile, phases::Backend, phases::Assemble, phases::Link)
 TYPE("assembler",PP_Asm,   INVALID, "s",  
phases::Assemble, phases::Link)
 TYPE("assembler-with-cpp",   Asm,  PP_Asm,  "S",  
phases::Preprocess, phases::Assemble, phases::Link)
-TYPE("f95",  PP_Fortran,   INVALID, "i",  
phases::Compile, phases::Backend, phases::Assemble, phases::Link)
+TYPE("f95",  PP_Fortran,   PP_Fortran,  "i",  
phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, 
phases::Link)
 TYPE("f95-cpp-input",Fortran,  PP_Fortran,  nullptr,  
phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, 
phases::Link)
 TYPE("java", Java, INVALID, nullptr,  
phases::Compile, phases::Backend, phases::Assemble, phases::Link)
 
diff --git a/flang/test/Driver/save-temps-use-module.f90 
b/flang/test/Driver/save-temps-use-module.f90
new file mode 100644
index 00..d77dd56a870911
--- /dev/null
+++ b/flang/test/Driver/save-temps-use-module.f90
@@ -0,0 +1,26 @@
+! Tests that `--save-temps` works properly when a module from a non standard 
dir
+! is included with `-I/...`.
+
+! RUN: rm -rf %t && split-file %s %t
+! RUN: mkdir %t/mod_inc_dir
+! RUN: mv %t/somemodule.mod %t/mod_inc_dir
+! RUN: %flang --save-temps=obj -I%t/mod_inc_dir -fno-integrated-as \
+! RUN:   %t/ModuleUser.f90 -o %t/ModuleUser.o
+! RUN: ls %t | FileCheck %s
+
+! Verify that the temp file(s) were written to disk.
+! CHECK: ModuleUser.i
+
+!--- somemodule.mod
+!mod$ v1 sum:e9e8fd2bd49e8daa
+module SomeModule
+
+end module SomeModule
+!--- ModuleUser.f90
+
+module User
+  use SomeModule
+end module User
+
+program dummy
+end program

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


[clang] [Clang][test] Add bytecode interpreter tests for floating comparison functions (PR #104703)

2024-08-18 Thread Timm Baeder via cfe-commits

tbaederr wrote:

> @tbaederr I've basically just copied over the tests from the other file. 
> There's no other quad-precision (`__float128`) tests so they were removed. 

Unfortunately that problem also exists with regular floating-point values 
(provided they heap-allocate memory).

> Do these need to be rewritten in a C++ style? (i.e., replace the macros with 
> template functions)

No, I think this is fine.


The changes work for me locally.

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


[clang] [Clang][test] Add bytecode interpreter tests for floating comparison functions (PR #104703)

2024-08-18 Thread Timm Baeder via cfe-commits

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


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


[clang] [clang][bytecode] Fix 'if consteval' in non-constant contexts (PR #104707)

2024-08-18 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/104707

The previous code made this a compile-time decision but it's not.

>From ba9edf8e883d9ac976a79c4f8883d71625b6cbaa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sun, 18 Aug 2024 15:40:05 +0200
Subject: [PATCH] [clang][bytecode] Fix 'if consteval' in non-constant contexts

The previous code made this a compile-time decision but it's not.
---
 clang/lib/AST/ByteCode/Compiler.cpp  | 20 +---
 clang/lib/AST/ByteCode/Interp.h  |  5 +
 clang/lib/AST/ByteCode/Opcodes.td|  2 ++
 clang/test/CodeGenCXX/cxx2b-consteval-if.cpp |  1 +
 4 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index c3ecaa40b86f2a..06e66f8d9ef2fa 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -4355,11 +4355,6 @@ bool Compiler::visitReturnStmt(const ReturnStmt 
*RS) {
 }
 
 template  bool Compiler::visitIfStmt(const IfStmt *IS) 
{
-  if (IS->isNonNegatedConsteval())
-return visitStmt(IS->getThen());
-  if (IS->isNegatedConsteval())
-return IS->getElse() ? visitStmt(IS->getElse()) : true;
-
   if (auto *CondInit = IS->getInit())
 if (!visitStmt(CondInit))
   return false;
@@ -4368,8 +4363,19 @@ template  bool 
Compiler::visitIfStmt(const IfStmt *IS) {
 if (!visitDeclStmt(CondDecl))
   return false;
 
-  if (!this->visitBool(IS->getCond()))
-return false;
+  // Compile condition.
+  if (IS->isNonNegatedConsteval()) {
+if (!this->emitIsConstantContext(IS))
+  return false;
+  } else if (IS->isNegatedConsteval()) {
+if (!this->emitIsConstantContext(IS))
+  return false;
+if (!this->emitInvBool(IS))
+  return false;
+  } else {
+if (!this->visitBool(IS->getCond()))
+  return false;
+  }
 
   if (const Stmt *Else = IS->getElse()) {
 LabelTy LabelElse = this->getLabel();
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 6cb7a42482ab25..02dff753062dc8 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -3054,6 +3054,11 @@ static inline bool Free(InterpState &S, CodePtr OpPC, 
bool DeleteIsArrayForm) {
  BlockDesc, Source);
 }
 
+static inline bool IsConstantContext(InterpState &S, CodePtr OpPC) {
+  S.Stk.push(Boolean::from(S.inConstantContext()));
+  return true;
+}
+
 inline bool CheckLiteralType(InterpState &S, CodePtr OpPC, const Type *T) {
   assert(T);
   assert(!S.getLangOpts().CPlusPlus23);
diff --git a/clang/lib/AST/ByteCode/Opcodes.td 
b/clang/lib/AST/ByteCode/Opcodes.td
index 3478eb174e518e..21bc31bfc5706e 100644
--- a/clang/lib/AST/ByteCode/Opcodes.td
+++ b/clang/lib/AST/ByteCode/Opcodes.td
@@ -787,3 +787,5 @@ def AllocCN : Opcode {
 def Free : Opcode {
   let Args = [ArgBool];
 }
+
+def IsConstantContext: Opcode;
diff --git a/clang/test/CodeGenCXX/cxx2b-consteval-if.cpp 
b/clang/test/CodeGenCXX/cxx2b-consteval-if.cpp
index 343b6a0bbd8a6b..a6aa862b975ebe 100644
--- a/clang/test/CodeGenCXX/cxx2b-consteval-if.cpp
+++ b/clang/test/CodeGenCXX/cxx2b-consteval-if.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++23 %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -std=c++23 %s -emit-llvm -o - 
-fexperimental-new-constant-interpreter | FileCheck %s
 
 void should_be_used_1();
 void should_be_used_2();

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


[clang] [clang][bytecode] Fix 'if consteval' in non-constant contexts (PR #104707)

2024-08-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

The previous code made this a compile-time decision but it's not.

---
Full diff: https://github.com/llvm/llvm-project/pull/104707.diff


4 Files Affected:

- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+13-7) 
- (modified) clang/lib/AST/ByteCode/Interp.h (+5) 
- (modified) clang/lib/AST/ByteCode/Opcodes.td (+2) 
- (modified) clang/test/CodeGenCXX/cxx2b-consteval-if.cpp (+1) 


``diff
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index c3ecaa40b86f2a..06e66f8d9ef2fa 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -4355,11 +4355,6 @@ bool Compiler::visitReturnStmt(const ReturnStmt 
*RS) {
 }
 
 template  bool Compiler::visitIfStmt(const IfStmt *IS) 
{
-  if (IS->isNonNegatedConsteval())
-return visitStmt(IS->getThen());
-  if (IS->isNegatedConsteval())
-return IS->getElse() ? visitStmt(IS->getElse()) : true;
-
   if (auto *CondInit = IS->getInit())
 if (!visitStmt(CondInit))
   return false;
@@ -4368,8 +4363,19 @@ template  bool 
Compiler::visitIfStmt(const IfStmt *IS) {
 if (!visitDeclStmt(CondDecl))
   return false;
 
-  if (!this->visitBool(IS->getCond()))
-return false;
+  // Compile condition.
+  if (IS->isNonNegatedConsteval()) {
+if (!this->emitIsConstantContext(IS))
+  return false;
+  } else if (IS->isNegatedConsteval()) {
+if (!this->emitIsConstantContext(IS))
+  return false;
+if (!this->emitInvBool(IS))
+  return false;
+  } else {
+if (!this->visitBool(IS->getCond()))
+  return false;
+  }
 
   if (const Stmt *Else = IS->getElse()) {
 LabelTy LabelElse = this->getLabel();
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 6cb7a42482ab25..02dff753062dc8 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -3054,6 +3054,11 @@ static inline bool Free(InterpState &S, CodePtr OpPC, 
bool DeleteIsArrayForm) {
  BlockDesc, Source);
 }
 
+static inline bool IsConstantContext(InterpState &S, CodePtr OpPC) {
+  S.Stk.push(Boolean::from(S.inConstantContext()));
+  return true;
+}
+
 inline bool CheckLiteralType(InterpState &S, CodePtr OpPC, const Type *T) {
   assert(T);
   assert(!S.getLangOpts().CPlusPlus23);
diff --git a/clang/lib/AST/ByteCode/Opcodes.td 
b/clang/lib/AST/ByteCode/Opcodes.td
index 3478eb174e518e..21bc31bfc5706e 100644
--- a/clang/lib/AST/ByteCode/Opcodes.td
+++ b/clang/lib/AST/ByteCode/Opcodes.td
@@ -787,3 +787,5 @@ def AllocCN : Opcode {
 def Free : Opcode {
   let Args = [ArgBool];
 }
+
+def IsConstantContext: Opcode;
diff --git a/clang/test/CodeGenCXX/cxx2b-consteval-if.cpp 
b/clang/test/CodeGenCXX/cxx2b-consteval-if.cpp
index 343b6a0bbd8a6b..a6aa862b975ebe 100644
--- a/clang/test/CodeGenCXX/cxx2b-consteval-if.cpp
+++ b/clang/test/CodeGenCXX/cxx2b-consteval-if.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++23 %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -std=c++23 %s -emit-llvm -o - 
-fexperimental-new-constant-interpreter | FileCheck %s
 
 void should_be_used_1();
 void should_be_used_2();

``




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


[clang] d082f1f - [clang][bytecode] Only booleans can be inverted

2024-08-18 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-08-18T16:02:32+02:00
New Revision: d082f1f37d8cb7a0c6875537ba873a631b154d53

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

LOG: [clang][bytecode] Only booleans can be inverted

No need to have the Inv() function be templated.

Added: 


Modified: 
clang/lib/AST/ByteCode/Boolean.h
clang/lib/AST/ByteCode/Compiler.cpp
clang/lib/AST/ByteCode/Interp.h
clang/lib/AST/ByteCode/Opcodes.td

Removed: 




diff  --git a/clang/lib/AST/ByteCode/Boolean.h 
b/clang/lib/AST/ByteCode/Boolean.h
index 0a2e0fe332110e..f1914ddb9970dc 100644
--- a/clang/lib/AST/ByteCode/Boolean.h
+++ b/clang/lib/AST/ByteCode/Boolean.h
@@ -44,6 +44,7 @@ class Boolean final {
   Boolean operator-() const { return Boolean(V); }
   Boolean operator-(const Boolean &Other) const { return Boolean(V - Other.V); 
}
   Boolean operator~() const { return Boolean(true); }
+  Boolean operator!() const { return Boolean(!V); }
 
   template >>
   explicit operator Ty() const {

diff  --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index c3ecaa40b86f2a..53144a50ccf4a9 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -5112,7 +5112,7 @@ bool Compiler::VisitUnaryOperator(const 
UnaryOperator *E) {
 if (!this->visitBool(SubExpr))
   return false;
 
-if (!this->emitInvBool(E))
+if (!this->emitInv(E))
   return false;
 
 if (PrimType ET = classifyPrim(E->getType()); ET != PT_Bool)
@@ -5231,7 +5231,7 @@ bool Compiler::VisitComplexUnaryOperator(const 
UnaryOperator *E) {
   return false;
 if (!this->emitComplexBoolCast(SubExpr))
   return false;
-if (!this->emitInvBool(E))
+if (!this->emitInv(E))
   return false;
 if (PrimType ET = classifyPrim(E->getType()); ET != PT_Bool)
   return this->emitCast(PT_Bool, ET, E);

diff  --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 6cb7a42482ab25..5aa3d24ebc7582 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -656,15 +656,9 @@ inline bool Divf(InterpState &S, CodePtr OpPC, 
llvm::RoundingMode RM) {
 // Inv
 
//===--===//
 
-template ::T>
-bool Inv(InterpState &S, CodePtr OpPC) {
-  using BoolT = PrimConv::T;
-  const T &Val = S.Stk.pop();
-  const unsigned Bits = Val.bitWidth();
-  Boolean R;
-  Boolean::inv(BoolT::from(Val, Bits), &R);
-
-  S.Stk.push(R);
+inline bool Inv(InterpState &S, CodePtr OpPC) {
+  const auto &Val = S.Stk.pop();
+  S.Stk.push(!Val);
   return true;
 }
 

diff  --git a/clang/lib/AST/ByteCode/Opcodes.td 
b/clang/lib/AST/ByteCode/Opcodes.td
index 3478eb174e518e..61319e1633d9ad 100644
--- a/clang/lib/AST/ByteCode/Opcodes.td
+++ b/clang/lib/AST/ByteCode/Opcodes.td
@@ -103,10 +103,6 @@ def PtrTypeClass : TypeClass {
   let Types = [Ptr, FnPtr, MemberPtr];
 }
 
-def BoolTypeClass : TypeClass {
-  let Types = [Bool];
-}
-
 def NonPtrTypeClass : TypeClass {
   let Types = !listconcat(IntegerTypeClass.Types, [Bool], [Float]);
 }
@@ -574,11 +570,8 @@ def Shr : Opcode {
 // Unary operators.
 
//===--===//
 
-// [Real] -> [Real]
-def Inv: Opcode {
-  let Types = [BoolTypeClass];
-  let HasGroup = 1;
-}
+// [Bool] -> [Bool]
+def Inv: Opcode;
 
 // Increment and decrement.
 def Inc: AluOpcode;



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


[clang] [Clang] CWG722: nullptr to ellipses (PR #104704)

2024-08-18 Thread Vlad Serebrennikov via cfe-commits


@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 -std=c++98 %s -verify -pedantic-errors
+// RUN: %clang_cc1 -std=c++11 %s -verify -pedantic-errors -ast-dump | 
FileCheck %s
+// RUN: %clang_cc1 -std=c++14 %s -verify -pedantic-errors -ast-dump | 
FileCheck %s
+// RUN: %clang_cc1 -std=c++17 %s -verify -pedantic-errors -ast-dump | 
FileCheck %s
+// RUN: %clang_cc1 -std=c++20 %s -verify -pedantic-errors -ast-dump | 
FileCheck %s
+// RUN: %clang_cc1 -std=c++23 %s -verify -pedantic-errors -ast-dump | 
FileCheck %s
+// RUN: %clang_cc1 -std=c++26 %s -verify -pedantic-errors -ast-dump | 
FileCheck %s
+
+// expected-no-diagnostics
+// cwg722: 20

Endilll wrote:

We've been accepting this since Clang 9. Either the status is wrong and should 
be `9`, or the test has insufficient coverage.
https://godbolt.org/z/Ysv3WP4Kv

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


[clang] [clang][bytecode] Fix 'if consteval' in non-constant contexts (PR #104707)

2024-08-18 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/104707

>From 30ea12f3a0841a532471c750204f13e5850d714c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sun, 18 Aug 2024 15:40:05 +0200
Subject: [PATCH] [clang][bytecode] Fix 'if consteval' in non-constant contexts

The previous code made this a compile-time decision but it's not.
---
 clang/lib/AST/ByteCode/Compiler.cpp  | 20 +---
 clang/lib/AST/ByteCode/Interp.h  |  5 +
 clang/lib/AST/ByteCode/Opcodes.td|  2 ++
 clang/test/CodeGenCXX/cxx2b-consteval-if.cpp |  1 +
 4 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 53144a50ccf4a9..6c76a88b85d8c8 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -4355,11 +4355,6 @@ bool Compiler::visitReturnStmt(const ReturnStmt 
*RS) {
 }
 
 template  bool Compiler::visitIfStmt(const IfStmt *IS) 
{
-  if (IS->isNonNegatedConsteval())
-return visitStmt(IS->getThen());
-  if (IS->isNegatedConsteval())
-return IS->getElse() ? visitStmt(IS->getElse()) : true;
-
   if (auto *CondInit = IS->getInit())
 if (!visitStmt(CondInit))
   return false;
@@ -4368,8 +4363,19 @@ template  bool 
Compiler::visitIfStmt(const IfStmt *IS) {
 if (!visitDeclStmt(CondDecl))
   return false;
 
-  if (!this->visitBool(IS->getCond()))
-return false;
+  // Compile condition.
+  if (IS->isNonNegatedConsteval()) {
+if (!this->emitIsConstantContext(IS))
+  return false;
+  } else if (IS->isNegatedConsteval()) {
+if (!this->emitIsConstantContext(IS))
+  return false;
+if (!this->emitInv(IS))
+  return false;
+  } else {
+if (!this->visitBool(IS->getCond()))
+  return false;
+  }
 
   if (const Stmt *Else = IS->getElse()) {
 LabelTy LabelElse = this->getLabel();
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 5aa3d24ebc7582..527e4e9e4129c7 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -3048,6 +3048,11 @@ static inline bool Free(InterpState &S, CodePtr OpPC, 
bool DeleteIsArrayForm) {
  BlockDesc, Source);
 }
 
+static inline bool IsConstantContext(InterpState &S, CodePtr OpPC) {
+  S.Stk.push(Boolean::from(S.inConstantContext()));
+  return true;
+}
+
 inline bool CheckLiteralType(InterpState &S, CodePtr OpPC, const Type *T) {
   assert(T);
   assert(!S.getLangOpts().CPlusPlus23);
diff --git a/clang/lib/AST/ByteCode/Opcodes.td 
b/clang/lib/AST/ByteCode/Opcodes.td
index 61319e1633d9ad..7374a441c8bb19 100644
--- a/clang/lib/AST/ByteCode/Opcodes.td
+++ b/clang/lib/AST/ByteCode/Opcodes.td
@@ -780,3 +780,5 @@ def AllocCN : Opcode {
 def Free : Opcode {
   let Args = [ArgBool];
 }
+
+def IsConstantContext: Opcode;
diff --git a/clang/test/CodeGenCXX/cxx2b-consteval-if.cpp 
b/clang/test/CodeGenCXX/cxx2b-consteval-if.cpp
index 343b6a0bbd8a6b..a6aa862b975ebe 100644
--- a/clang/test/CodeGenCXX/cxx2b-consteval-if.cpp
+++ b/clang/test/CodeGenCXX/cxx2b-consteval-if.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++23 %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -std=c++23 %s -emit-llvm -o - 
-fexperimental-new-constant-interpreter | FileCheck %s
 
 void should_be_used_1();
 void should_be_used_2();

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


[clang] [clang][bytecode] Fix 'if consteval' in non-constant contexts (PR #104707)

2024-08-18 Thread via cfe-commits


@@ -4368,8 +4363,19 @@ template  bool 
Compiler::visitIfStmt(const IfStmt *IS) {
 if (!visitDeclStmt(CondDecl))
   return false;
 
-  if (!this->visitBool(IS->getCond()))
-return false;
+  // Compile condition.
+  if (IS->isNonNegatedConsteval()) {
+if (!this->emitIsConstantContext(IS))
+  return false;
+  } else if (IS->isNegatedConsteval()) {
+if (!this->emitIsConstantContext(IS))
+  return false;
+if (!this->emitInv(IS))
+  return false;
+  } else {
+if (!this->visitBool(IS->getCond()))
+  return false;
+  }

cor3ntin wrote:

We really should not evaluate the condition, just the underlying statement 
directly
(getThen or getElse depending on both `S.inConstantContext()` and whether it's 
negated)

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


[clang] [clang][bytecode] Fix 'if consteval' in non-constant contexts (PR #104707)

2024-08-18 Thread Timm Baeder via cfe-commits


@@ -4368,8 +4363,19 @@ template  bool 
Compiler::visitIfStmt(const IfStmt *IS) {
 if (!visitDeclStmt(CondDecl))
   return false;
 
-  if (!this->visitBool(IS->getCond()))
-return false;
+  // Compile condition.
+  if (IS->isNonNegatedConsteval()) {
+if (!this->emitIsConstantContext(IS))
+  return false;
+  } else if (IS->isNegatedConsteval()) {
+if (!this->emitIsConstantContext(IS))
+  return false;
+if (!this->emitInv(IS))
+  return false;
+  } else {
+if (!this->visitBool(IS->getCond()))
+  return false;
+  }

tbaederr wrote:

The condition is only evaluated if the ifstmt is not a consteval stmt at all

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


[clang] [Clang] CWG722: nullptr to ellipses (PR #104704)

2024-08-18 Thread Mital Ashok via cfe-commits


@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 -std=c++98 %s -verify -pedantic-errors
+// RUN: %clang_cc1 -std=c++11 %s -verify -pedantic-errors -ast-dump | 
FileCheck %s
+// RUN: %clang_cc1 -std=c++14 %s -verify -pedantic-errors -ast-dump | 
FileCheck %s
+// RUN: %clang_cc1 -std=c++17 %s -verify -pedantic-errors -ast-dump | 
FileCheck %s
+// RUN: %clang_cc1 -std=c++20 %s -verify -pedantic-errors -ast-dump | 
FileCheck %s
+// RUN: %clang_cc1 -std=c++23 %s -verify -pedantic-errors -ast-dump | 
FileCheck %s
+// RUN: %clang_cc1 -std=c++26 %s -verify -pedantic-errors -ast-dump | 
FileCheck %s
+
+// expected-no-diagnostics
+// cwg722: 20

MitalAshok wrote:

The difference is there is no `ImplicitCastExpr` to `void*` in the AST: 
https://godbolt.org/z/9dcT8Tzs4

This does not change the behaviour for the first few arguments, but the last 
two arguments can no longer pass `nullptr` with non-zero bit patterns.

This has differences at runtime if `nullptr` prvalues are passed to a variadic 
function: https://godbolt.org/z/19vovz8o6

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


[clang-tools-extra] [clang-tidy] Support member functions with modernize-use-std-print/format (PR #104675)

2024-08-18 Thread via cfe-commits


@@ -104,6 +104,14 @@ New check aliases
 Changes in existing checks
 ^^
 
+- Improved :doc:`modernize-use-std-format
+  ` check to support replacing
+  member function calls too.
+
+- Improved :doc:`modernize-use-std-print

EugeneZelenko wrote:

Duplicate entry.

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


[clang-tools-extra] [clang-tidy] Support member functions with modernize-use-std-print/format (PR #104675)

2024-08-18 Thread via cfe-commits

https://github.com/EugeneZelenko requested changes to this pull request.


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


[clang] [clang][bytecode] Fix 'if consteval' in non-constant contexts (PR #104707)

2024-08-18 Thread via cfe-commits


@@ -4368,8 +4363,19 @@ template  bool 
Compiler::visitIfStmt(const IfStmt *IS) {
 if (!visitDeclStmt(CondDecl))
   return false;
 
-  if (!this->visitBool(IS->getCond()))
-return false;
+  // Compile condition.
+  if (IS->isNonNegatedConsteval()) {
+if (!this->emitIsConstantContext(IS))
+  return false;
+  } else if (IS->isNegatedConsteval()) {
+if (!this->emitIsConstantContext(IS))
+  return false;
+if (!this->emitInv(IS))
+  return false;
+  } else {
+if (!this->visitBool(IS->getCond()))
+  return false;
+  }

cor3ntin wrote:

I mean, we should not have a `emitIsConstantContext(IS)` - just emit the 
underlying statement 

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


[clang-tools-extra] [clang-tidy] Support member functions with modernize-use-std-print/format (PR #104675)

2024-08-18 Thread via cfe-commits

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


[clang] [Clang] CWG722: nullptr to ellipses (PR #104704)

2024-08-18 Thread Vlad Serebrennikov via cfe-commits


@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 -std=c++98 %s -verify -pedantic-errors
+// RUN: %clang_cc1 -std=c++11 %s -verify -pedantic-errors -ast-dump | 
FileCheck %s
+// RUN: %clang_cc1 -std=c++14 %s -verify -pedantic-errors -ast-dump | 
FileCheck %s
+// RUN: %clang_cc1 -std=c++17 %s -verify -pedantic-errors -ast-dump | 
FileCheck %s
+// RUN: %clang_cc1 -std=c++20 %s -verify -pedantic-errors -ast-dump | 
FileCheck %s
+// RUN: %clang_cc1 -std=c++23 %s -verify -pedantic-errors -ast-dump | 
FileCheck %s
+// RUN: %clang_cc1 -std=c++26 %s -verify -pedantic-errors -ast-dump | 
FileCheck %s
+
+// expected-no-diagnostics
+// cwg722: 20

Endilll wrote:

I see. Thank you for the explanation.

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


[clang] [clang][bytecode] Fix 'if consteval' in non-constant contexts (PR #104707)

2024-08-18 Thread Timm Baeder via cfe-commits


@@ -4368,8 +4363,19 @@ template  bool 
Compiler::visitIfStmt(const IfStmt *IS) {
 if (!visitDeclStmt(CondDecl))
   return false;
 
-  if (!this->visitBool(IS->getCond()))
-return false;
+  // Compile condition.
+  if (IS->isNonNegatedConsteval()) {
+if (!this->emitIsConstantContext(IS))
+  return false;
+  } else if (IS->isNegatedConsteval()) {
+if (!this->emitIsConstantContext(IS))
+  return false;
+if (!this->emitInv(IS))
+  return false;
+  } else {
+if (!this->visitBool(IS->getCond()))
+  return false;
+  }

tbaederr wrote:

That's what the previous code did, though. That doesn't work if we compile to 
bytecode and later interpret the same bytecode in a non-constant context.

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


[clang] [HIP] search fatbin symbols for libs passed by -l (PR #104638)

2024-08-18 Thread Yaxun Liu via cfe-commits

https://github.com/yxsamliu updated 
https://github.com/llvm/llvm-project/pull/104638

>From 6e6bb355f2cf79f30d01c97b580d4354cbb7e727 Mon Sep 17 00:00:00 2001
From: "Yaxun (Sam) Liu" 
Date: Fri, 16 Aug 2024 14:24:08 -0400
Subject: [PATCH] [HIP] search fatbin symbols for libs passed by -l

For -fgpu-rdc linking, clang needs to collect undefined fatbin
symbols and resolve them to the embedded fatbin.

This has been done for object files and archive files passed
as input files to clang.

However, the same action is not performed for archive files passed
through -l options, which causes missing fatbin symbols.
---
 clang/lib/Driver/ToolChains/HIPUtility.cpp | 75 --
 clang/test/Driver/hip-toolchain-rdc.hip| 23 +++
 2 files changed, 93 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/HIPUtility.cpp 
b/clang/lib/Driver/ToolChains/HIPUtility.cpp
index f32a23f111e4bf..1b707376dea819 100644
--- a/clang/lib/Driver/ToolChains/HIPUtility.cpp
+++ b/clang/lib/Driver/ToolChains/HIPUtility.cpp
@@ -52,13 +52,16 @@ static std::string normalizeForBundler(const llvm::Triple 
&T,
 // input object or archive files.
 class HIPUndefinedFatBinSymbols {
 public:
-  HIPUndefinedFatBinSymbols(const Compilation &C)
-  : C(C), DiagID(C.getDriver().getDiags().getCustomDiagID(
-  DiagnosticsEngine::Error,
-  "Error collecting HIP undefined fatbin symbols: %0")),
+  HIPUndefinedFatBinSymbols(const Compilation &C,
+const llvm::opt::ArgList &Args_)
+  : C(C), Args(Args_),
+DiagID(C.getDriver().getDiags().getCustomDiagID(
+DiagnosticsEngine::Error,
+"Error collecting HIP undefined fatbin symbols: %0")),
 Quiet(C.getArgs().hasArg(options::OPT__HASH_HASH_HASH)),
 Verbose(C.getArgs().hasArg(options::OPT_v)) {
 populateSymbols();
+processStaticLibraries();
 if (Verbose) {
   for (const auto &Name : FatBinSymbols)
 llvm::errs() << "Found undefined HIP fatbin symbol: " << Name << "\n";
@@ -76,8 +79,70 @@ class HIPUndefinedFatBinSymbols {
 return GPUBinHandleSymbols;
   }
 
+  // Collect symbols from static libraries specified by -l options.
+  void processStaticLibraries() {
+llvm::SmallVector LibNames;
+llvm::SmallVector LibPaths;
+llvm::SmallVector ExactLibNames;
+llvm::Triple Triple(C.getDriver().getTargetTriple());
+bool IsMSVC = Triple.isWindowsMSVCEnvironment();
+llvm::StringRef Ext = IsMSVC ? ".lib" : ".a";
+
+for (const auto *Arg : Args.filtered(options::OPT_l)) {
+  llvm::StringRef Value = Arg->getValue();
+  if (Value.starts_with(":"))
+ExactLibNames.push_back(Value.drop_front());
+  else
+LibNames.push_back(Value);
+}
+for (const auto *Arg : Args.filtered(options::OPT_L)) {
+  auto Path = Arg->getValue();
+  LibPaths.push_back(Path);
+  if (Verbose)
+llvm::errs() << "HIP fatbin symbol search uses library path:  " << Path
+ << "\n";
+}
+
+auto ProcessLib = [&](llvm::StringRef LibName, bool IsExact) {
+  llvm::SmallString<256> FullLibName(
+  IsExact  ? Twine(LibName).str()
+  : IsMSVC ? (Twine(LibName) + Ext).str()
+   : (Twine("lib") + LibName + Ext).str());
+
+  bool Found = false;
+  for (const auto Path : LibPaths) {
+llvm::SmallString<256> FullPath = Path;
+llvm::sys::path::append(FullPath, FullLibName);
+
+if (llvm::sys::fs::exists(FullPath)) {
+  if (Verbose)
+llvm::errs() << "HIP fatbin symbol search found library: "
+ << FullPath << "\n";
+  auto BufferOrErr = llvm::MemoryBuffer::getFile(FullPath);
+  if (!BufferOrErr) {
+errorHandler(llvm::errorCodeToError(BufferOrErr.getError()));
+continue;
+  }
+  processInput(BufferOrErr.get()->getMemBufferRef());
+  Found = true;
+  break;
+}
+  }
+  if (!Found && Verbose)
+llvm::errs() << "HIP fatbin symbol search could not find library: "
+ << FullLibName << "\n";
+};
+
+for (const auto LibName : ExactLibNames)
+  ProcessLib(LibName, true);
+
+for (const auto LibName : LibNames)
+  ProcessLib(LibName, false);
+  }
+
 private:
   const Compilation &C;
+  const llvm::opt::ArgList &Args;
   unsigned DiagID;
   bool Quiet;
   bool Verbose;
@@ -301,7 +366,7 @@ void HIP::constructGenerateObjFileFromHIPFatBinary(
   auto HostTriple =
   C.getSingleOffloadToolChain()->getTriple();
 
-  HIPUndefinedFatBinSymbols Symbols(C);
+  HIPUndefinedFatBinSymbols Symbols(C, Args);
 
   std::string PrimaryHipFatbinSymbol;
   std::string PrimaryGpuBinHandleSymbol;
diff --git a/clang/test/Driver/hip-toolchain-rdc.hip 
b/clang/test/Driver/hip-toolchain-rdc.hip
index 7e6697a0e254f6..ec79bf06afb92c 100644
--- a/clang/test/Driver/hip-toolchain-rdc.hip
+++ b/clang/te

[clang] [clang][bytecode] Fix 'if consteval' in non-constant contexts (PR #104707)

2024-08-18 Thread via cfe-commits


@@ -4368,8 +4363,19 @@ template  bool 
Compiler::visitIfStmt(const IfStmt *IS) {
 if (!visitDeclStmt(CondDecl))
   return false;
 
-  if (!this->visitBool(IS->getCond()))
-return false;
+  // Compile condition.
+  if (IS->isNonNegatedConsteval()) {
+if (!this->emitIsConstantContext(IS))
+  return false;
+  } else if (IS->isNegatedConsteval()) {
+if (!this->emitIsConstantContext(IS))
+  return false;
+if (!this->emitInv(IS))
+  return false;
+  } else {
+if (!this->visitBool(IS->getCond()))
+  return false;
+  }

cor3ntin wrote:

How would you deal with code like

```cpp
constexpr void f() {
if !consteval {
goto a;
a:;  
}
}```

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


[clang] e05307f - [clang][OpenMP] Avoid multiple calls to getCurrentDirective in DSAChecker, NFC

2024-08-18 Thread Krzysztof Parzyszek via cfe-commits

Author: Krzysztof Parzyszek
Date: 2024-08-18T10:25:52-05:00
New Revision: e05307f6633ca405834a4fd24d858ffb676c9170

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

LOG: [clang][OpenMP] Avoid multiple calls to getCurrentDirective in DSAChecker, 
NFC

Added: 


Modified: 
clang/lib/Sema/SemaOpenMP.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 87d81dfaad601b..ac51bee29bc5b0 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -3717,6 +3717,7 @@ namespace {
 class DSAAttrChecker final : public StmtVisitor {
   DSAStackTy *Stack;
   Sema &SemaRef;
+  OpenMPDirectiveKind DKind = OMPD_unknown;
   bool ErrorFound = false;
   bool TryCaptureCXXThisMembers = false;
   CapturedStmt *CS = nullptr;
@@ -3748,7 +3749,7 @@ class DSAAttrChecker final : public 
StmtVisitor {
 // Try to capture inner this->member references to generate correct 
mappings
 // and diagnostics.
 if (TryCaptureCXXThisMembers ||
-(isOpenMPTargetExecutionDirective(Stack->getCurrentDirective()) &&
+(isOpenMPTargetExecutionDirective(DKind) &&
  llvm::any_of(S->getInnermostCapturedStmt()->captures(),
   [](const CapturedStmt::Capture &C) {
 return C.capturesThis();
@@ -3818,7 +3819,6 @@ class DSAAttrChecker final : public 
StmtVisitor {
 return;
 
   SourceLocation ELoc = E->getExprLoc();
-  OpenMPDirectiveKind DKind = Stack->getCurrentDirective();
   // The default(none) clause requires that each variable that is 
referenced
   // in the construct, and does not have a predetermined data-sharing
   // attribute, must have its data-sharing attribute explicitly determined
@@ -3983,7 +3983,6 @@ class DSAAttrChecker final : public 
StmtVisitor {
 E->containsUnexpandedParameterPack() || E->isInstantiationDependent())
   return;
 auto *FD = dyn_cast(E->getMemberDecl());
-OpenMPDirectiveKind DKind = Stack->getCurrentDirective();
 if (auto *TE = dyn_cast(E->getBase()->IgnoreParenCasts())) {
   if (!FD)
 return;
@@ -4065,8 +4064,7 @@ class DSAAttrChecker final : public 
StmtVisitor {
 if (isOpenMPTargetExecutionDirective(DKind)) {
   OMPClauseMappableExprCommon::MappableExprComponentList CurComponents;
   if (!checkMapClauseExpressionBase(SemaRef, E, CurComponents, OMPC_map,
-Stack->getCurrentDirective(),
-/*NoDiagnose=*/true))
+DKind, /*NoDiagnose=*/true))
 return;
   const auto *VD = cast(
   CurComponents.back().getAssociatedDeclaration()->getCanonicalDecl());
@@ -4119,8 +4117,7 @@ class DSAAttrChecker final : public 
StmtVisitor {
   // Skip analysis of arguments of implicitly defined map clause for target
   // directives.
   if (C && !((isa(C) || isa(C)) &&
- C->isImplicit() &&
- !isOpenMPTaskingDirective(Stack->getCurrentDirective( {
+ C->isImplicit() && !isOpenMPTaskingDirective(DKind))) {
 for (Stmt *CC : C->children()) {
   if (CC)
 Visit(CC);
@@ -4169,7 +4166,7 @@ class DSAAttrChecker final : public 
StmtVisitor {
   VarDecl *VD = Cap.getCapturedVar();
   // Do not try to map the variable if it or its sub-component was mapped
   // already.
-  if (isOpenMPTargetExecutionDirective(Stack->getCurrentDirective()) &&
+  if (isOpenMPTargetExecutionDirective(DKind) &&
   Stack->checkMappableExprComponentListsForDecl(
   VD, /*CurrentRegionOnly=*/true,
   [](OMPClauseMappableExprCommon::MappableExprComponentListRef,
@@ -4200,8 +4197,9 @@ class DSAAttrChecker final : public 
StmtVisitor {
 
   DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS)
   : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) {
+DKind = S->getCurrentDirective();
 // Process declare target link variables for the target directives.
-if (isOpenMPTargetExecutionDirective(S->getCurrentDirective())) {
+if (isOpenMPTargetExecutionDirective(DKind)) {
   for (DeclRefExpr *E : Stack->getLinkGlobals())
 Visit(E);
 }



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


[clang] dd40632 - [clang] fix divide by zero in ComplexExprEvaluator (#104666)

2024-08-18 Thread via cfe-commits

Author: c8ef
Date: 2024-08-18T17:32:44+02:00
New Revision: dd40632b52d8da2146a12254afc900315ac3c2e4

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

LOG: [clang] fix divide by zero in ComplexExprEvaluator (#104666)

fix: #55390.

-

Co-authored-by: Sergei Barannikov 

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/AST/ExprConstant.cpp
clang/test/SemaCXX/constant-expression-cxx11.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 11301e4c7dc4a2..a4257ea1f48c11 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -274,6 +274,8 @@ Bug Fixes to C++ Support
 Bug Fixes to AST Handling
 ^
 
+- Fixed a crash that occurred when dividing by zero in complex integer 
division. (#GH55390).
+
 Miscellaneous Bug Fixes
 ^^^
 

diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 31b65ff4bcc135..5540f58b526705 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -15615,12 +15615,12 @@ bool ComplexExprEvaluator::VisitBinaryOperator(const 
BinaryOperator *E) {
 HandleComplexComplexDiv(A, B, C, D, ResR, ResI);
   }
 } else {
-  if (RHS.getComplexIntReal() == 0 && RHS.getComplexIntImag() == 0)
-return Error(E, diag::note_expr_divide_by_zero);
-
   ComplexValue LHS = Result;
   APSInt Den = RHS.getComplexIntReal() * RHS.getComplexIntReal() +
 RHS.getComplexIntImag() * RHS.getComplexIntImag();
+  if (Den.isZero())
+return Error(E, diag::note_expr_divide_by_zero);
+
   Result.getComplexIntReal() =
 (LHS.getComplexIntReal() * RHS.getComplexIntReal() +
  LHS.getComplexIntImag() * RHS.getComplexIntImag()) / Den;

diff  --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp 
b/clang/test/SemaCXX/constant-expression-cxx11.cpp
index d87bd8c6f3..44ef540f41fa8c 100644
--- a/clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -1268,6 +1268,9 @@ constexpr complex_wrap makeComplexWrap(int re, int im) {
 static_assert(makeComplexWrap(1,0) == complex(1), "");
 static_assert(makeComplexWrap(1,0) != complex(0, 1), "");
 
+constexpr auto GH55390 = 1 / 65536j; // expected-note {{division by zero}} \
+ // expected-error {{constexpr variable 
'GH55390' must be initialized by a constant expression}} \
+ // expected-warning {{imaginary constants 
are a GNU extension}}
 }
 
 namespace PR11595 {



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


[clang] [clang] fix divide by zero in ComplexExprEvaluator (PR #104666)

2024-08-18 Thread via cfe-commits

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


[clang] [Clang] Do not allow `[[clang::lifetimebound]]` on explicit object member functions (PR #96113)

2024-08-18 Thread via cfe-commits

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


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


[clang] [Clang] Do not allow `[[clang::lifetimebound]]` on explicit object member functions (PR #96113)

2024-08-18 Thread via cfe-commits

cor3ntin wrote:

@MitalAshok should i merge?

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


[clang] [clang][bytecode] Fix 'if consteval' in non-constant contexts (PR #104707)

2024-08-18 Thread Timm Baeder via cfe-commits


@@ -4368,8 +4363,19 @@ template  bool 
Compiler::visitIfStmt(const IfStmt *IS) {
 if (!visitDeclStmt(CondDecl))
   return false;
 
-  if (!this->visitBool(IS->getCond()))
-return false;
+  // Compile condition.
+  if (IS->isNonNegatedConsteval()) {
+if (!this->emitIsConstantContext(IS))
+  return false;
+  } else if (IS->isNegatedConsteval()) {
+if (!this->emitIsConstantContext(IS))
+  return false;
+if (!this->emitInv(IS))
+  return false;
+  } else {
+if (!this->visitBool(IS->getCond()))
+  return false;
+  }

tbaederr wrote:

Just emitting ops for invalid code won't produce diagnostics, so that's not a 
problem. It would only be problematic if the thenstmt in this case caused the 
compilation to be aborted.

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


[clang-tools-extra] bbcb625 - [clang-tidy] Support member functions with modernize-use-std-print/format (#104675)

2024-08-18 Thread via cfe-commits

Author: Mike Crowe
Date: 2024-08-18T17:46:19+02:00
New Revision: bbcb625798514f1cd6ef04818381d38ea26b23e5

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

LOG: [clang-tidy] Support member functions with modernize-use-std-print/format 
(#104675)

These checks can be made to work on member functions quite easily and
it's not unknown to have at least printf-style functions as members.
Let's remove the restriction.

Added: 

clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-member.cpp

clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-member.cpp

Modified: 
clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-format.rst
clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp
index 6cef21f1318a2a..cdb34aef1b0e61 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp
@@ -50,8 +50,7 @@ void UseStdFormatCheck::registerMatchers(MatchFinder *Finder) 
{
   Finder->addMatcher(
   callExpr(argumentCountAtLeast(1),
hasArgument(0, stringLiteral(isOrdinary())),
-   callee(functionDecl(unless(cxxMethodDecl()),
-   matchers::matchesAnyListedName(
+   callee(functionDecl(matchers::matchesAnyListedName(
StrFormatLikeFunctions))
   .bind("func_decl")))
   .bind("strformat"),
@@ -93,7 +92,8 @@ void UseStdFormatCheck::check(const MatchFinder::MatchResult 
&Result) {
   diag(StrFormatCall->getBeginLoc(), "use '%0' instead of %1")
   << ReplacementFormatFunction << OldFunction->getIdentifier();
   Diag << FixItHint::CreateReplacement(
-  CharSourceRange::getTokenRange(StrFormatCall->getSourceRange()),
+  CharSourceRange::getTokenRange(StrFormatCall->getExprLoc(),
+ StrFormatCall->getEndLoc()),
   ReplacementFormatFunction);
   Converter.applyFixes(Diag, *Result.SourceManager);
 

diff  --git a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
index ff990feadc0c1d..16f2f4b3e7d1af 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
@@ -100,8 +100,7 @@ void UseStdPrintCheck::registerMatchers(MatchFinder 
*Finder) {
 unusedReturnValue(
 callExpr(argumentCountAtLeast(1),
  hasArgument(0, stringLiteral(isOrdinary())),
- callee(functionDecl(unless(cxxMethodDecl()),
- matchers::matchesAnyListedName(
+ callee(functionDecl(matchers::matchesAnyListedName(
  PrintfLikeFunctions))
 .bind("func_decl")))
 .bind("printf")),
@@ -112,8 +111,7 @@ void UseStdPrintCheck::registerMatchers(MatchFinder 
*Finder) {
 unusedReturnValue(
 callExpr(argumentCountAtLeast(2),
  hasArgument(1, stringLiteral(isOrdinary())),
- callee(functionDecl(unless(cxxMethodDecl()),
- matchers::matchesAnyListedName(
+ callee(functionDecl(matchers::matchesAnyListedName(
  FprintfLikeFunctions))
 .bind("func_decl")))
 .bind("fprintf")),
@@ -152,7 +150,7 @@ void UseStdPrintCheck::check(const MatchFinder::MatchResult 
&Result) {
   << ReplacementFunction << OldFunction->getIdentifier();
 
   Diag << FixItHint::CreateReplacement(
-  CharSourceRange::getTokenRange(PrintfCall->getBeginLoc(),
+  CharSourceRange::getTokenRange(PrintfCall->getExprLoc(),
  PrintfCall->getEndLoc()),
   ReplacementFunction);
   Converter.applyFixes(Diag, *Result.SourceManager);

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 0f6b34cf400521..1b025e8f90f7ba 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -104,6 +104,14 @@ New check aliases
 Changes in existing checks
 ^^
 
+- Improved :doc:`modernize-use-std-format
+  ` check to support replacing
+  member f

[clang-tools-extra] [clang-tidy] Support member functions with modernize-use-std-print/format (PR #104675)

2024-08-18 Thread Piotr Zegar via cfe-commits

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


[clang] de5ea2d - [clang][OpenMP] Change /* ParamName */ to /*ParamName=*/, NFC

2024-08-18 Thread Krzysztof Parzyszek via cfe-commits

Author: Krzysztof Parzyszek
Date: 2024-08-18T10:48:49-05:00
New Revision: de5ea2d122c31e1551654ff506c33df299f351b8

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

LOG: [clang][OpenMP] Change /* ParamName */ to /*ParamName=*/, NFC

Change
  foo(/* Index */ 0);
to
  foo(/*Index=*/0);

There was a mix of these two formats in the source. Clang-format treats
the latter one a bit better, so use that one consistently.

Added: 


Modified: 
clang/lib/Sema/SemaOpenMP.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index ac51bee29bc5b0..5950bc272fae3c 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -4021,7 +4021,7 @@ class DSAAttrChecker final : public 
StmtVisitor {
 OpenMPDefaultmapClauseKind ClauseKind =
 getVariableCategoryFromDecl(SemaRef.getLangOpts(), FD);
 OpenMPMapClauseKind Kind = getMapClauseKindFromModifier(
-Modifier, /*IsAggregateOrDeclareTarget*/ true);
+Modifier, /*IsAggregateOrDeclareTarget=*/true);
 ImplicitMap[ClauseKind][Kind].emplace_back(E);
 return;
   }
@@ -4586,7 +4586,7 @@ static bool checkOrderedOrderSpecified(Sema &S,
 StmtResult SemaOpenMP::ActOnOpenMPRegionEnd(StmtResult S,
 ArrayRef Clauses) {
   handleDeclareVariantConstructTrait(DSAStack, DSAStack->getCurrentDirective(),
- /* ScopeEntry */ false);
+ /*ScopeEntry=*/false);
   if (!isOpenMPCapturingDirective(DSAStack->getCurrentDirective()))
 return S;
 
@@ -7057,8 +7057,8 @@ void 
SemaOpenMP::ActOnStartOfFunctionDefinitionInOpenMPDeclareVariantScope(
 QualType UDeclTy = UDecl->getType();
 if (!UDeclTy->isDependentType()) {
   QualType NewType = getASTContext().mergeFunctionTypes(
-  FType, UDeclTy, /* OfBlockPointer */ false,
-  /* Unqualified */ false, /* AllowCXX */ true);
+  FType, UDeclTy, /*OfBlockPointer=*/false,
+  /*Unqualified=*/false, /*AllowCXX=*/true);
   if (NewType.isNull())
 continue;
 }
@@ -7104,9 +7104,8 @@ void 
SemaOpenMP::ActOnFinishedFunctionDefinitionInOpenMPDeclareVariantScope(
 FD = cast(D);
   auto *VariantFuncRef = DeclRefExpr::Create(
   getASTContext(), NestedNameSpecifierLoc(), SourceLocation(), FD,
-  /* RefersToEnclosingVariableOrCapture */ false,
-  /* NameLoc */ FD->getLocation(), FD->getType(),
-  ExprValueKind::VK_PRValue);
+  /*RefersToEnclosingVariableOrCapture=*/false,
+  /*NameLoc=*/FD->getLocation(), FD->getType(), ExprValueKind::VK_PRValue);
 
   OMPDeclareVariantScope &DVScope = OMPDeclareVariantScopes.back();
   auto *OMPDeclareVariantA = OMPDeclareVariantAttr::CreateImplicit(
@@ -7168,7 +7167,7 @@ ExprResult SemaOpenMP::ActOnOpenMPCall(ExprResult Call, 
Scope *Scope,
   OMPTraitInfo &TI = A->getTraitInfo();
   TI.getAsVariantMatchInfo(Context, VMI);
   if (!isVariantApplicableInContext(VMI, OMPCtx,
-/* DeviceSetOnly */ false))
+/*DeviceSetOnly=*/false))
 continue;
 
   VMIs.push_back(VMI);
@@ -7204,7 +7203,7 @@ ExprResult SemaOpenMP::ActOnOpenMPCall(ExprResult Call, 
Scope *Scope,
 auto *MemberCall = dyn_cast(CE);
 BestExpr = MemberExpr::CreateImplicit(
 Context, MemberCall->getImplicitObjectArgument(),
-/* IsArrow */ false, SpecializedMethod, Context.BoundMemberTy,
+/*IsArrow=*/false, SpecializedMethod, Context.BoundMemberTy,
 MemberCall->getValueKind(), MemberCall->getObjectKind());
   }
   NewCall = SemaRef.BuildCallExpr(Scope, BestExpr, LParenLoc, ArgExprs,
@@ -7214,8 +7213,8 @@ ExprResult SemaOpenMP::ActOnOpenMPCall(ExprResult Call, 
Scope *Scope,
   FunctionDecl *NewCalleeFnDecl = NCE->getDirectCallee();
   QualType NewType = getASTContext().mergeFunctionTypes(
   CalleeFnType, NewCalleeFnDecl->getType(),
-  /* OfBlockPointer */ false,
-  /* Unqualified */ false, /* AllowCXX */ true);
+  /*OfBlockPointer=*/false,
+  /*Unqualified=*/false, /*AllowCXX=*/true);
   if (!NewType.isNull())
 break;
   // Don't use the call if the function type was not compatible.
@@ -9413,7 +9412,7 @@ static ExprResult widenIterationCount(unsigned Bits, Expr 
*E, Sema &SemaRef) {
   if (HasBits >= Bits)
 return ExprResult(E);
   // OK to convert to signed, because new type has more bits than old.
-  QualType NewType = C.getIntTypeForBitwidth(Bits, /* Signed */ true);
+  QualType NewType = C.getIntTypeForBitwidth(Bits, /*Signed=*/true);
   return 

[clang] [llvm] [llvm][clang] Move RewriterBuffer to ADT. (PR #99770)

2024-08-18 Thread Jacques Pienaar via cfe-commits

https://github.com/jpienaar updated 
https://github.com/llvm/llvm-project/pull/99770

>From ee91900dd42321ce1344a70df5f1baddf36bde9f Mon Sep 17 00:00:00 2001
From: Jacques Pienaar 
Date: Sat, 20 Jul 2024 16:25:14 +
Subject: [PATCH] [llvm][clang] Move RewriterBuffer to ADT.

These classes are not specific to clang and useful for other rewriter tools.
---
 clang/include/clang/Rewrite/Core/DeltaTree.h  |  50 --
 .../include/clang/Rewrite/Core/HTMLRewrite.h  |  11 +-
 .../include/clang/Rewrite/Core/RewriteRope.h  | 223 
 clang/include/clang/Rewrite/Core/Rewriter.h   |  19 +-
 clang/lib/ARCMigrate/ARCMT.cpp|   2 +-
 clang/lib/ARCMigrate/ObjCMT.cpp   |   1 +
 clang/lib/Frontend/Rewrite/FixItRewriter.cpp  |   3 +-
 clang/lib/Frontend/Rewrite/HTMLPrint.cpp  |   2 +
 clang/lib/Frontend/Rewrite/RewriteMacros.cpp  |   4 +-
 .../Frontend/Rewrite/RewriteModernObjC.cpp|   3 +-
 clang/lib/Frontend/Rewrite/RewriteObjC.cpp|   1 +
 clang/lib/Rewrite/CMakeLists.txt  |   2 -
 clang/lib/Rewrite/HTMLRewrite.cpp |   1 +
 clang/lib/Rewrite/Rewriter.cpp| 109 +---
 .../StaticAnalyzer/Core/HTMLDiagnostics.cpp   |   2 +
 clang/lib/Tooling/Core/Replacement.cpp|   2 +-
 clang/unittests/Rewrite/CMakeLists.txt|   1 -
 llvm/include/llvm/ADT/DeltaTree.h |  50 ++
 .../include/llvm/ADT}/RewriteBuffer.h |  40 +-
 llvm/include/llvm/ADT/RewriteRope.h   | 223 
 llvm/lib/Support/CMakeLists.txt   |   3 +
 .../lib/Support}/DeltaTree.cpp| 265 +
 llvm/lib/Support/RewriteBuffer.cpp| 107 
 .../lib/Support}/RewriteRope.cpp  | 507 +-
 llvm/unittests/ADT/CMakeLists.txt |   1 +
 .../unittests/ADT}/RewriteBufferTest.cpp  |   5 +-
 26 files changed, 825 insertions(+), 812 deletions(-)
 delete mode 100644 clang/include/clang/Rewrite/Core/DeltaTree.h
 delete mode 100644 clang/include/clang/Rewrite/Core/RewriteRope.h
 create mode 100644 llvm/include/llvm/ADT/DeltaTree.h
 rename {clang/include/clang/Rewrite/Core => 
llvm/include/llvm/ADT}/RewriteBuffer.h (82%)
 create mode 100644 llvm/include/llvm/ADT/RewriteRope.h
 rename {clang/lib/Rewrite => llvm/lib/Support}/DeltaTree.cpp (68%)
 create mode 100644 llvm/lib/Support/RewriteBuffer.cpp
 rename {clang/lib/Rewrite => llvm/lib/Support}/RewriteRope.cpp (63%)
 rename {clang/unittests/Rewrite => llvm/unittests/ADT}/RewriteBufferTest.cpp 
(96%)

diff --git a/clang/include/clang/Rewrite/Core/DeltaTree.h 
b/clang/include/clang/Rewrite/Core/DeltaTree.h
deleted file mode 100644
index e566c92aaff91a..00
--- a/clang/include/clang/Rewrite/Core/DeltaTree.h
+++ /dev/null
@@ -1,50 +0,0 @@
-//===- DeltaTree.h - B-Tree for Rewrite Delta tracking --*- C++ 
-*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-//
-// This file defines the DeltaTree class.
-//
-//===--===//
-
-#ifndef LLVM_CLANG_REWRITE_CORE_DELTATREE_H
-#define LLVM_CLANG_REWRITE_CORE_DELTATREE_H
-
-namespace clang {
-
-  /// DeltaTree - a multiway search tree (BTree) structure with some fancy
-  /// features.  B-Trees are generally more memory and cache efficient than
-  /// binary trees, because they store multiple keys/values in each node.  This
-  /// implements a key/value mapping from index to delta, and allows fast 
lookup
-  /// on index.  However, an added (important) bonus is that it can also
-  /// efficiently tell us the full accumulated delta for a specific file offset
-  /// as well, without traversing the whole tree.
-  class DeltaTree {
-void *Root;// "DeltaTreeNode *"
-
-  public:
-DeltaTree();
-
-// Note: Currently we only support copying when the RHS is empty.
-DeltaTree(const DeltaTree &RHS);
-
-DeltaTree &operator=(const DeltaTree &) = delete;
-~DeltaTree();
-
-/// getDeltaAt - Return the accumulated delta at the specified file offset.
-/// This includes all insertions or delections that occurred *before* the
-/// specified file index.
-int getDeltaAt(unsigned FileIndex) const;
-
-/// AddDelta - When a change is made that shifts around the text buffer,
-/// this method is used to record that info.  It inserts a delta of 'Delta'
-/// into the current DeltaTree at offset FileIndex.
-void AddDelta(unsigned FileIndex, int Delta);
-  };
-
-} // namespace clang
-
-#endif // LLVM_CLANG_REWRITE_CORE_DELTATREE_H
diff --git a/clang/include/clang/Rewrite/Core/HTMLRewrite.h 
b/clang/include/clang/Rewrite/Core/HTMLRewrite.h
index eecf589632746c..9edb514d566b9c 100644
--- a/clang/include/clang/Rewrite/Core/HTMLRewrite.h
+++ b/clang

[clang] [Clang] Do not allow `[[clang::lifetimebound]]` on explicit object member functions (PR #96113)

2024-08-18 Thread Mital Ashok via cfe-commits

MitalAshok wrote:

@cor3ntin Yes, thanks

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


[clang] Fix typo in SanitizerCoverage.rst (PR #104715)

2024-08-18 Thread Marco Vanotti via cfe-commits

https://github.com/mvanotti created 
https://github.com/llvm/llvm-project/pull/104715

The callback for indirect calls is `__sanitizer_cov_trace_pc_indir`, not 
`__sanitizer_cov_trace_pc_indirect`.

See: 
https://github.com/llvm/llvm-project/blob/de5ea2d122c31e1551654ff506c33df299f351b8/compiler-rt/lib/sanitizer_common/sanitizer_interface_internal.h#L120

>From 43acabf1cbdd21d008c905f5842681fcdfd2cabd Mon Sep 17 00:00:00 2001
From: Marco Vanotti 
Date: Sun, 18 Aug 2024 11:59:07 -0400
Subject: [PATCH] Fix typo in SanitizerCoverage.rst

The callback for indirect calls is `__sanitizer_cov_trace_pc_indir`, not 
`__sanitizer_cov_trace_pc_indirect`.

See: 
https://github.com/llvm/llvm-project/blob/de5ea2d122c31e1551654ff506c33df299f351b8/compiler-rt/lib/sanitizer_common/sanitizer_interface_internal.h#L120
---
 clang/docs/SanitizerCoverage.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/SanitizerCoverage.rst b/clang/docs/SanitizerCoverage.rst
index 45ad03cb43774c..e5bfcb554e6b2b 100644
--- a/clang/docs/SanitizerCoverage.rst
+++ b/clang/docs/SanitizerCoverage.rst
@@ -37,7 +37,7 @@ The compiler will also insert calls to a module constructor:
__sanitizer_cov_trace_pc_guard_init(uint32_t *start, uint32_t *stop);
 
 With an additional ``...=trace-pc,indirect-calls`` flag
-``__sanitizer_cov_trace_pc_indirect(void *callee)`` will be inserted on every 
indirect call.
+``__sanitizer_cov_trace_pc_indir(void *callee)`` will be inserted on every 
indirect call.
 
 The functions `__sanitizer_cov_trace_pc_*` should be defined by the user.
 

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


  1   2   >