[clang] [llvm] [PowerPC][ISelLowering] Support -mstack-protector-guard=tls (PR #110928)

2024-10-06 Thread Keith Packard via cfe-commits

https://github.com/keith-packard updated 
https://github.com/llvm/llvm-project/pull/110928

>From 34ec006112994e99c27569c8811ee53e4a5c8c63 Mon Sep 17 00:00:00 2001
From: Keith Packard 
Date: Mon, 16 Sep 2024 15:41:38 +0200
Subject: [PATCH 1/4] [PowerPC][ISelLowering] Support
 -mstack-protector-guard=tls

Add support for using a thread-local variable with a specified offset
for holding the stack guard canary value.

To keep Linux targets from also getting another load
due to LOAD_STACK_GUARD, kill that instruction when using
"tls" mode. We can't use LOAD_STACK_GUARD for this new case
as that is gated by useLoadStackGuardNode() and that function
doesn't have a reference to the Module where we could test
for "tls" mode.

Signed-off-by: Keith Packard 
---
 clang/lib/Driver/ToolChains/Clang.cpp   | 18 ++
 llvm/lib/Target/PowerPC/PPCISelLowering.cpp | 20 
 llvm/lib/Target/PowerPC/PPCISelLowering.h   |  1 +
 llvm/lib/Target/PowerPC/PPCInstrInfo.cpp|  6 ++
 4 files changed, 41 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index c9baca00ec6f3b..2b465915054a0c 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3605,7 +3605,7 @@ static void RenderSSPOptions(const Driver &D, const 
ToolChain &TC,
 StringRef Value = A->getValue();
 if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64() &&
 !EffectiveTriple.isARM() && !EffectiveTriple.isThumb() &&
-!EffectiveTriple.isRISCV())
+!EffectiveTriple.isRISCV() && !EffectiveTriple.isPPC())
   D.Diag(diag::err_drv_unsupported_opt_for_target)
   << A->getAsString(Args) << TripleStr;
 if ((EffectiveTriple.isX86() || EffectiveTriple.isARM() ||
@@ -3645,7 +3645,7 @@ static void RenderSSPOptions(const Driver &D, const 
ToolChain &TC,
   << A->getOption().getName() << Value << "sysreg global";
   return;
 }
-if (EffectiveTriple.isRISCV()) {
+if (EffectiveTriple.isRISCV() || EffectiveTriple.isPPC()) {
   if (Value != "tls" && Value != "global") {
 D.Diag(diag::err_drv_invalid_value_with_suggestion)
 << A->getOption().getName() << Value << "tls global";
@@ -3666,7 +3666,7 @@ static void RenderSSPOptions(const Driver &D, const 
ToolChain &TC,
 StringRef Value = A->getValue();
 if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64() &&
 !EffectiveTriple.isARM() && !EffectiveTriple.isThumb() &&
-!EffectiveTriple.isRISCV())
+!EffectiveTriple.isRISCV() && !EffectiveTriple.isPPC())
   D.Diag(diag::err_drv_unsupported_opt_for_target)
   << A->getAsString(Args) << TripleStr;
 int Offset;
@@ -3686,7 +3686,7 @@ static void RenderSSPOptions(const Driver &D, const 
ToolChain &TC,
   if (Arg *A = Args.getLastArg(options::OPT_mstack_protector_guard_reg_EQ)) {
 StringRef Value = A->getValue();
 if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64() &&
-!EffectiveTriple.isRISCV())
+!EffectiveTriple.isRISCV() && !EffectiveTriple.isPPC())
   D.Diag(diag::err_drv_unsupported_opt_for_target)
   << A->getAsString(Args) << TripleStr;
 if (EffectiveTriple.isX86() && (Value != "fs" && Value != "gs")) {
@@ -3703,6 +3703,16 @@ static void RenderSSPOptions(const Driver &D, const 
ToolChain &TC,
   << A->getOption().getName() << Value << "tp";
   return;
 }
+if (EffectiveTriple.isPPC64() && Value != "r13") {
+  D.Diag(diag::err_drv_invalid_value_with_suggestion)
+  << A->getOption().getName() << Value << "r13";
+  return;
+}
+if (EffectiveTriple.isPPC32() && Value != "r2") {
+  D.Diag(diag::err_drv_invalid_value_with_suggestion)
+  << A->getOption().getName() << Value << "r2";
+  return;
+}
 A->render(Args, CmdArgs);
   }
 
diff --git a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp 
b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
index d9847a21489e63..089c866af11b5e 100644
--- a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
+++ b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -17913,6 +17913,26 @@ Value *PPCTargetLowering::getSDagStackGuard(const 
Module &M) const {
   return TargetLowering::getSDagStackGuard(M);
 }
 
+static Value *useTpOffset(IRBuilderBase &IRB, unsigned Offset) {
+  Module *M = IRB.GetInsertBlock()->getModule();
+  Function *ThreadPointerFunc =
+  Intrinsic::getDeclaration(M, Intrinsic::thread_pointer);
+  return IRB.CreateConstGEP1_32(IRB.getInt8Ty(),
+IRB.CreateCall(ThreadPointerFunc), Offset);
+}
+
+Value *PPCTargetLowering::getIRStackGuard(IRBuilderBase &IRB) const {
+  Module *M = IRB.GetInsertBlock()->getModule();
+
+  if (M->getStackProtectorGuard() == "tls") {
+// Specially, some users may customize the base reg and offset.
+int Offset = M->getStackProtectorGuardOffset();
+return useTpOffset(IRB, Offset);
+  }

[clang] [llvm] [PowerPC][ISelLowering] Support -mstack-protector-guard=tls (PR #110928)

2024-10-06 Thread Keith Packard via cfe-commits

https://github.com/keith-packard updated 
https://github.com/llvm/llvm-project/pull/110928

>From 05c0a80977564496094a55ca0ca0b54b8048a30b Mon Sep 17 00:00:00 2001
From: Keith Packard 
Date: Mon, 16 Sep 2024 15:41:38 +0200
Subject: [PATCH 1/4] [PowerPC][ISelLowering] Support
 -mstack-protector-guard=tls

Add support for using a thread-local variable with a specified offset
for holding the stack guard canary value.

To keep Linux targets from also getting another load
due to LOAD_STACK_GUARD, kill that instruction when using
"tls" mode. We can't use LOAD_STACK_GUARD for this new case
as that is gated by useLoadStackGuardNode() and that function
doesn't have a reference to the Module where we could test
for "tls" mode.

Signed-off-by: Keith Packard 
---
 clang/lib/Driver/ToolChains/Clang.cpp   | 18 ++
 llvm/lib/Target/PowerPC/PPCISelLowering.cpp | 20 
 llvm/lib/Target/PowerPC/PPCISelLowering.h   |  1 +
 llvm/lib/Target/PowerPC/PPCInstrInfo.cpp|  6 ++
 4 files changed, 41 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index c9baca00ec6f3b..2b465915054a0c 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3605,7 +3605,7 @@ static void RenderSSPOptions(const Driver &D, const 
ToolChain &TC,
 StringRef Value = A->getValue();
 if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64() &&
 !EffectiveTriple.isARM() && !EffectiveTriple.isThumb() &&
-!EffectiveTriple.isRISCV())
+!EffectiveTriple.isRISCV() && !EffectiveTriple.isPPC())
   D.Diag(diag::err_drv_unsupported_opt_for_target)
   << A->getAsString(Args) << TripleStr;
 if ((EffectiveTriple.isX86() || EffectiveTriple.isARM() ||
@@ -3645,7 +3645,7 @@ static void RenderSSPOptions(const Driver &D, const 
ToolChain &TC,
   << A->getOption().getName() << Value << "sysreg global";
   return;
 }
-if (EffectiveTriple.isRISCV()) {
+if (EffectiveTriple.isRISCV() || EffectiveTriple.isPPC()) {
   if (Value != "tls" && Value != "global") {
 D.Diag(diag::err_drv_invalid_value_with_suggestion)
 << A->getOption().getName() << Value << "tls global";
@@ -3666,7 +3666,7 @@ static void RenderSSPOptions(const Driver &D, const 
ToolChain &TC,
 StringRef Value = A->getValue();
 if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64() &&
 !EffectiveTriple.isARM() && !EffectiveTriple.isThumb() &&
-!EffectiveTriple.isRISCV())
+!EffectiveTriple.isRISCV() && !EffectiveTriple.isPPC())
   D.Diag(diag::err_drv_unsupported_opt_for_target)
   << A->getAsString(Args) << TripleStr;
 int Offset;
@@ -3686,7 +3686,7 @@ static void RenderSSPOptions(const Driver &D, const 
ToolChain &TC,
   if (Arg *A = Args.getLastArg(options::OPT_mstack_protector_guard_reg_EQ)) {
 StringRef Value = A->getValue();
 if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64() &&
-!EffectiveTriple.isRISCV())
+!EffectiveTriple.isRISCV() && !EffectiveTriple.isPPC())
   D.Diag(diag::err_drv_unsupported_opt_for_target)
   << A->getAsString(Args) << TripleStr;
 if (EffectiveTriple.isX86() && (Value != "fs" && Value != "gs")) {
@@ -3703,6 +3703,16 @@ static void RenderSSPOptions(const Driver &D, const 
ToolChain &TC,
   << A->getOption().getName() << Value << "tp";
   return;
 }
+if (EffectiveTriple.isPPC64() && Value != "r13") {
+  D.Diag(diag::err_drv_invalid_value_with_suggestion)
+  << A->getOption().getName() << Value << "r13";
+  return;
+}
+if (EffectiveTriple.isPPC32() && Value != "r2") {
+  D.Diag(diag::err_drv_invalid_value_with_suggestion)
+  << A->getOption().getName() << Value << "r2";
+  return;
+}
 A->render(Args, CmdArgs);
   }
 
diff --git a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp 
b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
index d9847a21489e63..089c866af11b5e 100644
--- a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
+++ b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -17913,6 +17913,26 @@ Value *PPCTargetLowering::getSDagStackGuard(const 
Module &M) const {
   return TargetLowering::getSDagStackGuard(M);
 }
 
+static Value *useTpOffset(IRBuilderBase &IRB, unsigned Offset) {
+  Module *M = IRB.GetInsertBlock()->getModule();
+  Function *ThreadPointerFunc =
+  Intrinsic::getDeclaration(M, Intrinsic::thread_pointer);
+  return IRB.CreateConstGEP1_32(IRB.getInt8Ty(),
+IRB.CreateCall(ThreadPointerFunc), Offset);
+}
+
+Value *PPCTargetLowering::getIRStackGuard(IRBuilderBase &IRB) const {
+  Module *M = IRB.GetInsertBlock()->getModule();
+
+  if (M->getStackProtectorGuard() == "tls") {
+// Specially, some users may customize the base reg and offset.
+int Offset = M->getStackProtectorGuardOffset();
+return useTpOffset(IRB, Offset);
+  }

[clang] [flang] [flang][Driver] Add support for -f[no-]wrapv and -f[no]-strict-overflow in the frontend (PR #110061)

2024-10-06 Thread Yusuke MINATO via cfe-commits


@@ -866,6 +866,17 @@ void Flang::ConstructJob(Compilation &C, const JobAction 
&JA,
 }
   }
 
+  // -fno-strict-overflow implies -fwrapv if it isn't disabled, but
+  // -fstrict-overflow won't turn off an explicitly enabled -fwrapv.
+  if (Arg *A = Args.getLastArg(options::OPT_fwrapv, options::OPT_fno_wrapv)) {
+if (A->getOption().matches(options::OPT_fwrapv))
+  CmdArgs.push_back("-fwrapv");
+  } else if (Arg *A = Args.getLastArg(options::OPT_fstrict_overflow,
+  options::OPT_fno_strict_overflow)) {
+if (A->getOption().matches(options::OPT_fno_strict_overflow))
+  CmdArgs.push_back("-fwrapv");
+  }
+

yus3710-fj wrote:

That sounds good. I fixed it. Thank you.

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


[clang] [llvm] [ARM] Emit an error when the hard-float ABI is enabled but can't be used. (PR #111334)

2024-10-06 Thread David Green via cfe-commits

davemgreen wrote:

It looks like there is already a warning for this in clang, it only triggers 
from -mfloat-abi=hard though: https://godbolt.org/z/dcaz8had4. Could it be made 
to work with any hard-float env? And maybe be made an error down-gradable to a 
warning?

Generally clang-level warnings/errors are more user friendly then the 
llvm-level errors (but both may be useful for other frontends).

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


[clang] [Clang] fix overload resolution for object parameters with top-level cv-qualifiers in member functions (PR #110435)

2024-10-06 Thread Oleksandr T. via cfe-commits

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

>From c52634882631a71fad956a70179b480abf13006a Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sun, 29 Sep 2024 22:01:38 +0300
Subject: [PATCH 1/2] [Clang] fix overload resolution for object parameters
 with top-level cv-qualifiers in member functions

---
 clang/docs/ReleaseNotes.rst| 1 +
 clang/lib/Sema/SemaOverload.cpp| 3 +++
 clang/test/SemaCXX/cxx2b-deducing-this.cpp | 7 +++
 3 files changed, 11 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 28c759538f7df6..1bec2838765dab 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -447,6 +447,7 @@ Bug Fixes to C++ Support
 - Fixed an assertion failure in debug mode, and potential crashes in release 
mode, when
   diagnosing a failed cast caused indirectly by a failed implicit conversion 
to the type of the constructor parameter.
 - Fixed an assertion failure by adjusting integral to boolean vector 
conversions (#GH108326)
+- Fixed overload handling for object parameters with top-level cv-qualifiers 
in explicit member functions (#GH100394)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 0c1e054f7c30a4..7c40bab70bbe9d 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -1511,6 +1511,9 @@ static bool IsOverloadOrOverrideImpl(Sema &SemaRef, 
FunctionDecl *New,
   auto NewObjectType = New->getFunctionObjectParameterReferenceType();
   auto OldObjectType = Old->getFunctionObjectParameterReferenceType();
 
+  if (NewObjectType.isConstQualified() != OldObjectType.isConstQualified())
+return false;
+
   auto IsImplicitWithNoRefQual = [](const CXXMethodDecl *F) {
 return F->getRefQualifier() == RQ_None &&
!F->isExplicitObjectMemberFunction();
diff --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp 
b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
index 63bf92e8d5edd3..5fd02502ce6df4 100644
--- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp
+++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
@@ -1073,3 +1073,10 @@ int main() {
   return foo[]; // expected-error {{no viable overloaded operator[] for type 
'Foo'}}
 }
 }
+
+namespace GH100394 {
+struct C {
+  void f(this const C);
+  void f() const ;  // ok
+};
+}

>From d377c01f46acf28f1dc74103c6a26df6c0c2e376 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sun, 6 Oct 2024 11:52:48 +0300
Subject: [PATCH 2/2] adjust overload resolution for volatile qualifiers

---
 clang/lib/Sema/SemaOverload.cpp|  7 +--
 clang/test/SemaCXX/cxx2b-deducing-this.cpp | 12 +---
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 7c40bab70bbe9d..56705971517cc3 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -1511,8 +1511,11 @@ static bool IsOverloadOrOverrideImpl(Sema &SemaRef, 
FunctionDecl *New,
   auto NewObjectType = New->getFunctionObjectParameterReferenceType();
   auto OldObjectType = Old->getFunctionObjectParameterReferenceType();
 
-  if (NewObjectType.isConstQualified() != OldObjectType.isConstQualified())
-return false;
+  if (Old->isExplicitObjectMemberFunction() &&
+  OldObjectType.getQualifiers() != NewObjectType.getQualifiers())
+return OldObjectType.isConstQualified() &&
+   (NewObjectType.isConstQualified() ||
+NewObjectType.isVolatileQualified());
 
   auto IsImplicitWithNoRefQual = [](const CXXMethodDecl *F) {
 return F->getRefQualifier() == RQ_None &&
diff --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp 
b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
index 5fd02502ce6df4..7dcd63a587c708 100644
--- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp
+++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
@@ -1075,8 +1075,14 @@ int main() {
 }
 
 namespace GH100394 {
-struct C {
-  void f(this const C);
-  void f() const ;  // ok
+struct C1 {
+  void f(this const C1);
+  void f() const;// ok
+};
+
+struct C2 {
+  void f(this const C2);// expected-note {{previous declaration is here}}
+  void f(this volatile C2); // expected-error {{class member cannot be 
redeclared}} \
+// expected-warning {{volatile-qualified parameter 
type 'volatile C2' is deprecated}}
 };
 }

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


[clang] [Clang] omit parentheses in fold expressions with a single expansion (PR #110761)

2024-10-06 Thread via cfe-commits


@@ -15661,12 +15661,16 @@ 
TreeTransform::TransformCXXFoldExpr(CXXFoldExpr *E) {
   return true;
   }
 
+  if (*NumExpansions == 1) {

cor3ntin wrote:

Should we set the flag unconditionally (regardless of the number of expansions)?

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


[clang] [Clang] omit parentheses in fold expressions with a single expansion (PR #110761)

2024-10-06 Thread via cfe-commits


@@ -2171,10 +2171,15 @@ class ParenExpr : public Expr {
   SourceLocation L, R;
   Stmt *Val;
 public:
+  enum TransformConstraint : uint8_t {
+None = 0, // No specific preservation required
+Preserve = 1, // Parentheses have always to be preserved
+  };
+

cor3ntin wrote:

I'm not sure that we need an enum here, i guess me and @erichkeane disagree!
Either way we should try to minimize the memory footprint of this feature.
One way to do that would be to introduce a `ParenExprBitFiled` in Stmt.h

You will also need to modify AstStmtReader / AstStmtWriter to make sure that 
gets serialized

I think the name should probably be something like "ProducedByFoldExpansion".

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


[clang] [clang-tools-extra] RFC: [clang-tidy] [analyzer] Nondeterministic pointer usage improvements (PR #110471)

2024-10-06 Thread via cfe-commits

vabridgers wrote:

As I understand the collective comments so far:

- use `misc`, not `bugprone`. I've heard no affirmations for `bugprone` and one 
suggestion to use `misc`.
- Break up the simulation header files, only include what's actually needed for 
the test
- change the checker name to something like 
`bugprone-nondeterministic-pointer-iteration-order`
- provide testing results, expand upon testing
- I've heard no concrete comments on expanding beyond the few cases this check 
currently addresses. I'll assume that's ok for now.

Next update should address these points. Thanks for the comments!


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


[clang-tools-extra] [clang-tidy] Create bugprone-bitwise-pointer-cast check (PR #108083)

2024-10-06 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


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


[clang-tools-extra] fb0ef6b - [clang-tidy] Create bugprone-bitwise-pointer-cast check (#108083)

2024-10-06 Thread via cfe-commits

Author: Carlos Galvez
Date: 2024-10-06T12:21:09+02:00
New Revision: fb0ef6b66e3c7e91481568c15ed67c047dab84e1

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

LOG: [clang-tidy] Create bugprone-bitwise-pointer-cast check (#108083)

To detect unsafe usages of casting a pointer to another via copying
the bytes from one into the other, either via std::bit_cast or via
memcpy. This is currently not caught by any other means.

Fixes #106987

-

Co-authored-by: Carlos Gálvez 

Added: 
clang-tools-extra/clang-tidy/bugprone/BitwisePointerCastCheck.cpp
clang-tools-extra/clang-tidy/bugprone/BitwisePointerCastCheck.h
clang-tools-extra/docs/clang-tidy/checks/bugprone/bitwise-pointer-cast.rst

clang-tools-extra/test/clang-tidy/checkers/bugprone/bitwise-pointer-cast-cxx20.cpp
clang-tools-extra/test/clang-tidy/checkers/bugprone/bitwise-pointer-cast.cpp

Modified: 
clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/BitwisePointerCastCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BitwisePointerCastCheck.cpp
new file mode 100644
index 00..0992e49b7f372b
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/BitwisePointerCastCheck.cpp
@@ -0,0 +1,46 @@
+//===--- BitwisePointerCastCheck.cpp - clang-tidy 
-===//
+//
+// 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
+//
+//===--===//
+
+#include "BitwisePointerCastCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+void BitwisePointerCastCheck::registerMatchers(MatchFinder *Finder) {
+  if (getLangOpts().CPlusPlus20) {
+auto IsPointerType = refersToType(qualType(isAnyPointer()));
+Finder->addMatcher(callExpr(hasDeclaration(functionDecl(allOf(
+hasName("::std::bit_cast"),
+hasTemplateArgument(0, IsPointerType),
+hasTemplateArgument(1, IsPointerType)
+   .bind("bit_cast"),
+   this);
+  }
+
+  auto IsDoublePointerType =
+  hasType(qualType(pointsTo(qualType(isAnyPointer();
+  Finder->addMatcher(callExpr(hasArgument(0, IsDoublePointerType),
+  hasArgument(1, IsDoublePointerType),
+  
hasDeclaration(functionDecl(hasName("::memcpy"
+ .bind("memcpy"),
+ this);
+}
+
+void BitwisePointerCastCheck::check(const MatchFinder::MatchResult &Result) {
+  if (const auto *Call = Result.Nodes.getNodeAs("bit_cast"))
+diag(Call->getBeginLoc(),
+ "do not use 'std::bit_cast' to cast between pointers")
+<< Call->getSourceRange();
+  else if (const auto *Call = Result.Nodes.getNodeAs("memcpy"))
+diag(Call->getBeginLoc(), "do not use 'memcpy' to cast between pointers")
+<< Call->getSourceRange();
+}
+
+} // namespace clang::tidy::bugprone

diff  --git a/clang-tools-extra/clang-tidy/bugprone/BitwisePointerCastCheck.h 
b/clang-tools-extra/clang-tidy/bugprone/BitwisePointerCastCheck.h
new file mode 100644
index 00..1515519b3c9fda
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/BitwisePointerCastCheck.h
@@ -0,0 +1,34 @@
+//===--- BitwisePointerCastCheck.h - clang-tidy -*- 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
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_BITWISEPOINTERCASTCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_BITWISEPOINTERCASTCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::bugprone {
+
+/// Warns about code that tries to cast between pointers by means of
+/// ``std::bit_cast`` or ``memcpy``.
+///
+/// For the user-facing documentation see:
+/// 
http://clang.llvm.org/extra/clang-tidy/checks/bugprone/bitwise-pointer-cast.html
+class BitwisePointerCastCheck : public ClangTidyCheck {
+public:
+  BitwisePointerCastCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_ma

[clang] [Clang] Remove the special-casing for RequiresExprBodyDecl in BuildResolvedCallExpr() after fd87d765c0 (PR #111277)

2024-10-06 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

That's https://github.com/llvm/llvm-project/pull/85198. Which was merged prior 
to the generic solution fd87d765c0 by @sdkrystian 

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


[clang] [Clang] Extend lifetime of temporaries in mem-default-init for P2718R0 (PR #86960)

2024-10-06 Thread via cfe-commits

https://github.com/yronglin updated 
https://github.com/llvm/llvm-project/pull/86960

>From a8a87484760874d3b36673970e7158f0247df69b Mon Sep 17 00:00:00 2001
From: yronglin 
Date: Thu, 26 Sep 2024 22:28:07 +0800
Subject: [PATCH 1/2] [clang][C++23] Extend lifetime of temporaries in
 mem-default-init for P2718R0

Signed-off-by: yronglin 
---
 clang/lib/Sema/SemaExpr.cpp   |   2 +
 clang/lib/Sema/SemaInit.cpp   |   2 +
 clang/test/CXX/special/class.temporary/p6.cpp | 106 +-
 clang/www/cxx_status.html |   9 +-
 4 files changed, 110 insertions(+), 9 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 66df9c969256a2..bde73670b0b07a 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -5639,6 +5639,8 @@ ExprResult Sema::BuildCXXDefaultInitExpr(SourceLocation 
Loc, FieldDecl *Field) {
   runWithSufficientStackSpace(Loc, [&] {
 MarkDeclarationsReferencedInExpr(E, /*SkipLocalVariables=*/false);
   });
+if (isInLifetimeExtendingContext())
+  DiscardCleanupsInEvaluationContext();
 // C++11 [class.base.init]p7:
 //   The initialization of each base and member constitutes a
 //   full-expression.
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 4d11f2a43fcc6b..a5a716e7499f38 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -763,6 +763,8 @@ void InitListChecker::FillInEmptyInitForField(unsigned 
Init, FieldDecl *Field,
 SemaRef.currentEvaluationContext().DelayedDefaultInitializationContext 
=
 SemaRef.parentEvaluationContext()
 .DelayedDefaultInitializationContext;
+SemaRef.currentEvaluationContext().InLifetimeExtendingContext =
+SemaRef.parentEvaluationContext().InLifetimeExtendingContext;
 DIE = SemaRef.BuildCXXDefaultInitExpr(Loc, Field);
   }
   if (DIE.isInvalid()) {
diff --git a/clang/test/CXX/special/class.temporary/p6.cpp 
b/clang/test/CXX/special/class.temporary/p6.cpp
index a6d2adfd1fd2c5..6c79de5dcbfae3 100644
--- a/clang/test/CXX/special/class.temporary/p6.cpp
+++ b/clang/test/CXX/special/class.temporary/p6.cpp
@@ -304,6 +304,26 @@ void check_dr1815() { // dr1815: yes
 }
 
 namespace P2718R0 {
+extern void block_scope_begin_function();
+extern void block_scope_end_function();
+
+template  using T2 = std::list;
+template  const T2 &f1_temp(const T2 &t)  { return t; }
+template  const T2 &f2_temp(T2 t) { return t; }
+template  T2 g_temp(){ return T2{}; }
+
+// -- Examples from https://wg21.link/p2718r0
+namespace std_examples {
+using T = std::list;
+const T& f1(const T& t) { return t; }
+const T& f2(T t){ return t; }
+T g();
+void foo() {
+  for (auto e : f1(g())) {}  // OK, lifetime of return value of g() extended
+  for (auto e : f2(g())) {}  // undefined behavior
+}
+} // namespace std_examples
+
 namespace basic {
 template  using T2 = std::list;
 template  const T2 &f1_temp(const T2 &t)  { return t; }
@@ -463,6 +483,44 @@ template void default_arg_dependent_context2();
 template void default_arg_dependent_context3();
 } // namespace default_arg
 
+namespace default_init {
+template 
+struct DepA {
+  T arr[1];
+  ~DepA() {}
+};
+
+template 
+struct DepB {
+  int x;
+  const DepA &a = DepA{{0}};
+  ~DepB() {}
+  const int *begin() { return a.arr; }
+  const int *end() { return &a.arr[1]; }
+};
+
+template 
+void default_init1_dependent() {
+  // CHECK-CXX23: void 
@_ZN7P2718R012default_init23default_init1_dependentINS0_4DepBIivv()
+  // CHECK-CXX23-LABEL: for.cond.cleanup:
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R012default_init4DepBIiED1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R012default_init4DepAIiED1Ev(
+  for (auto &&x : T{0}) {}
+}
+
+template 
+void default_init2_dependent() {
+  // CHECK-CXX23: void 
@_ZN7P2718R012default_init23default_init2_dependentINS0_4DepBIivv()
+  // CHECK-CXX23-LABEL: for.cond.cleanup:
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R012default_init4DepBIiED1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R012default_init4DepAIiED1Ev(
+  for (auto &&x : T{0}.a.arr) {}
+}
+
+template void default_init1_dependent>();
+template void default_init2_dependent>();
+} // namespace default_init
+
 namespace basic {
 using T = std::list;
 const T& f1(const T& t) { return t; }
@@ -579,5 +637,51 @@ void default_arg3() {
   for (auto e : C(0, C(0, C(0, C() {}
 }
 } // namespace default_arg
-} // namespace P2718R0
 
+namespace default_init {
+struct X {
+  int x;
+  ~X() {}
+};
+
+struct Y {
+  int y;
+  const X &x = X{1};
+  ~Y() {}
+};
+
+struct A {
+  int arr[1];
+  const Y &y = Y{1};
+  ~A() {}
+};
+
+struct B {
+  int x;
+  const A &a = A{{0}};
+  ~B() {}
+  const int *begin() { return a.arr; }
+  const int *end() { return &a.arr[1]; }
+};
+
+void default_init1() {
+  // CHECK-CXX23: void @_ZN7P2718R012default_init13default_init1Ev()

[clang] [Clang] Extend lifetime of temporaries in mem-default-init for P2718R0 (PR #86960)

2024-10-06 Thread via cfe-commits

https://github.com/yronglin updated 
https://github.com/llvm/llvm-project/pull/86960

>From a8a87484760874d3b36673970e7158f0247df69b Mon Sep 17 00:00:00 2001
From: yronglin 
Date: Thu, 26 Sep 2024 22:28:07 +0800
Subject: [PATCH 1/3] [clang][C++23] Extend lifetime of temporaries in
 mem-default-init for P2718R0

Signed-off-by: yronglin 
---
 clang/lib/Sema/SemaExpr.cpp   |   2 +
 clang/lib/Sema/SemaInit.cpp   |   2 +
 clang/test/CXX/special/class.temporary/p6.cpp | 106 +-
 clang/www/cxx_status.html |   9 +-
 4 files changed, 110 insertions(+), 9 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 66df9c969256a2..bde73670b0b07a 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -5639,6 +5639,8 @@ ExprResult Sema::BuildCXXDefaultInitExpr(SourceLocation 
Loc, FieldDecl *Field) {
   runWithSufficientStackSpace(Loc, [&] {
 MarkDeclarationsReferencedInExpr(E, /*SkipLocalVariables=*/false);
   });
+if (isInLifetimeExtendingContext())
+  DiscardCleanupsInEvaluationContext();
 // C++11 [class.base.init]p7:
 //   The initialization of each base and member constitutes a
 //   full-expression.
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 4d11f2a43fcc6b..a5a716e7499f38 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -763,6 +763,8 @@ void InitListChecker::FillInEmptyInitForField(unsigned 
Init, FieldDecl *Field,
 SemaRef.currentEvaluationContext().DelayedDefaultInitializationContext 
=
 SemaRef.parentEvaluationContext()
 .DelayedDefaultInitializationContext;
+SemaRef.currentEvaluationContext().InLifetimeExtendingContext =
+SemaRef.parentEvaluationContext().InLifetimeExtendingContext;
 DIE = SemaRef.BuildCXXDefaultInitExpr(Loc, Field);
   }
   if (DIE.isInvalid()) {
diff --git a/clang/test/CXX/special/class.temporary/p6.cpp 
b/clang/test/CXX/special/class.temporary/p6.cpp
index a6d2adfd1fd2c5..6c79de5dcbfae3 100644
--- a/clang/test/CXX/special/class.temporary/p6.cpp
+++ b/clang/test/CXX/special/class.temporary/p6.cpp
@@ -304,6 +304,26 @@ void check_dr1815() { // dr1815: yes
 }
 
 namespace P2718R0 {
+extern void block_scope_begin_function();
+extern void block_scope_end_function();
+
+template  using T2 = std::list;
+template  const T2 &f1_temp(const T2 &t)  { return t; }
+template  const T2 &f2_temp(T2 t) { return t; }
+template  T2 g_temp(){ return T2{}; }
+
+// -- Examples from https://wg21.link/p2718r0
+namespace std_examples {
+using T = std::list;
+const T& f1(const T& t) { return t; }
+const T& f2(T t){ return t; }
+T g();
+void foo() {
+  for (auto e : f1(g())) {}  // OK, lifetime of return value of g() extended
+  for (auto e : f2(g())) {}  // undefined behavior
+}
+} // namespace std_examples
+
 namespace basic {
 template  using T2 = std::list;
 template  const T2 &f1_temp(const T2 &t)  { return t; }
@@ -463,6 +483,44 @@ template void default_arg_dependent_context2();
 template void default_arg_dependent_context3();
 } // namespace default_arg
 
+namespace default_init {
+template 
+struct DepA {
+  T arr[1];
+  ~DepA() {}
+};
+
+template 
+struct DepB {
+  int x;
+  const DepA &a = DepA{{0}};
+  ~DepB() {}
+  const int *begin() { return a.arr; }
+  const int *end() { return &a.arr[1]; }
+};
+
+template 
+void default_init1_dependent() {
+  // CHECK-CXX23: void 
@_ZN7P2718R012default_init23default_init1_dependentINS0_4DepBIivv()
+  // CHECK-CXX23-LABEL: for.cond.cleanup:
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R012default_init4DepBIiED1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R012default_init4DepAIiED1Ev(
+  for (auto &&x : T{0}) {}
+}
+
+template 
+void default_init2_dependent() {
+  // CHECK-CXX23: void 
@_ZN7P2718R012default_init23default_init2_dependentINS0_4DepBIivv()
+  // CHECK-CXX23-LABEL: for.cond.cleanup:
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R012default_init4DepBIiED1Ev(
+  // CHECK-CXX23-NEXT: call void @_ZN7P2718R012default_init4DepAIiED1Ev(
+  for (auto &&x : T{0}.a.arr) {}
+}
+
+template void default_init1_dependent>();
+template void default_init2_dependent>();
+} // namespace default_init
+
 namespace basic {
 using T = std::list;
 const T& f1(const T& t) { return t; }
@@ -579,5 +637,51 @@ void default_arg3() {
   for (auto e : C(0, C(0, C(0, C() {}
 }
 } // namespace default_arg
-} // namespace P2718R0
 
+namespace default_init {
+struct X {
+  int x;
+  ~X() {}
+};
+
+struct Y {
+  int y;
+  const X &x = X{1};
+  ~Y() {}
+};
+
+struct A {
+  int arr[1];
+  const Y &y = Y{1};
+  ~A() {}
+};
+
+struct B {
+  int x;
+  const A &a = A{{0}};
+  ~B() {}
+  const int *begin() { return a.arr; }
+  const int *end() { return &a.arr[1]; }
+};
+
+void default_init1() {
+  // CHECK-CXX23: void @_ZN7P2718R012default_init13default_init1Ev()

[clang] [Clang] Extend lifetime of temporaries in mem-default-init for P2718R0 (PR #86960)

2024-10-06 Thread via cfe-commits

yronglin wrote:

> LGTM But you need a release note to say that the implementation of P2718R0 is 
> complete

Thanks for the review, added ReleaseNotes.

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


[clang] [Clang] Remove the special-casing for RequiresExprBodyDecl in BuildResolvedCallExpr() after fd87d765c0 (PR #111277)

2024-10-06 Thread via cfe-commits

cor3ntin wrote:

Do you know why this check was there in the first place?

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


[clang] [clang] CWG2398: improve overload resolution backwards compat (PR #107350)

2024-10-06 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

This implements the wording I presented here: 
https://lists.isocpp.org/core/2024/09/16266.php
This will be part of the next revision of P3310.

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


[clang] [Clang] Remove the special-casing for RequiresExprBodyDecl in BuildResolvedCallExpr() after fd87d765c0 (PR #111277)

2024-10-06 Thread Matheus Izvekov via cfe-commits

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

LGTM

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


[clang] [flang] [flang][Driver] Add support for -f[no-]wrapv and -f[no]-strict-overflow in the frontend (PR #110061)

2024-10-06 Thread Yusuke MINATO via cfe-commits

https://github.com/yus3710-fj updated 
https://github.com/llvm/llvm-project/pull/110061

>From aea2cfa4b1d812dc84cb1609f93cc2ec2bcd33b4 Mon Sep 17 00:00:00 2001
From: Yusuke MINATO 
Date: Wed, 18 Sep 2024 21:12:43 +0900
Subject: [PATCH 1/3] [flang][Driver] Add support for -f[no-]wrapv and
 -f[no]-strict-overflow in the frontend

This patch introduces the options for integer overflow flags into Flang.
---
 clang/include/clang/Driver/Options.td | 11 +++---
 clang/lib/Driver/ToolChains/Flang.cpp | 11 ++
 flang/include/flang/Common/LangOptions.def|  2 ++
 flang/include/flang/Common/LangOptions.h  |  8 +
 flang/include/flang/Lower/LoweringOptions.def |  5 ++-
 flang/lib/Frontend/CompilerInvocation.cpp | 36 +--
 flang/test/Driver/frontend-forwarding.f90 |  2 ++
 flang/test/Driver/integer-overflow.f90| 10 ++
 8 files changed, 75 insertions(+), 10 deletions(-)
 create mode 100644 flang/test/Driver/integer-overflow.f90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 9d183ff2d69b3c..4610cd917f685d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3451,7 +3451,8 @@ def fno_strict_aliasing : Flag<["-"], 
"fno-strict-aliasing">, Group,
 def fstruct_path_tbaa : Flag<["-"], "fstruct-path-tbaa">, Group;
 def fno_struct_path_tbaa : Flag<["-"], "fno-struct-path-tbaa">, Group;
 def fno_strict_enums : Flag<["-"], "fno-strict-enums">, Group;
-def fno_strict_overflow : Flag<["-"], "fno-strict-overflow">, Group;
+def fno_strict_overflow : Flag<["-"], "fno-strict-overflow">, Group,
+  Visibility<[ClangOption, FlangOption]>;
 def fno_pointer_tbaa : Flag<["-"], "fno-pointer-tbaa">, Group;
 def fno_temp_file : Flag<["-"], "fno-temp-file">, Group,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>, HelpText<
@@ -3467,7 +3468,8 @@ def fno_verbose_asm : Flag<["-"], "fno-verbose-asm">, 
Group,
   Visibility<[ClangOption, CC1Option]>,
   MarshallingInfoNegativeFlag>;
 def fno_working_directory : Flag<["-"], "fno-working-directory">, 
Group;
-def fno_wrapv : Flag<["-"], "fno-wrapv">, Group;
+def fno_wrapv : Flag<["-"], "fno-wrapv">, Group,
+  Visibility<[ClangOption, FlangOption]>;
 def fobjc_arc : Flag<["-"], "fobjc-arc">, Group,
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"Synthesize retain and release calls for Objective-C pointers">;
@@ -3963,7 +3965,8 @@ defm strict_vtable_pointers : 
BoolFOption<"strict-vtable-pointers",
   "Enable optimizations based on the strict rules for"
 " overwriting polymorphic C++ objects">,
   NegFlag>;
-def fstrict_overflow : Flag<["-"], "fstrict-overflow">, Group;
+def fstrict_overflow : Flag<["-"], "fstrict-overflow">, Group,
+  Visibility<[ClangOption, FlangOption]>;
 def fpointer_tbaa : Flag<["-"], "fpointer-tbaa">, Group;
 def fdriver_only : Flag<["-"], "fdriver-only">, Flags<[NoXarchOption]>,
   Visibility<[ClangOption, CLOption, DXCOption]>,
@@ -4232,7 +4235,7 @@ defm virtual_function_elimination : 
BoolFOption<"virtual-function-elimination",
   NegFlag, BothFlags<[], [ClangOption, CLOption]>>;
 
 def fwrapv : Flag<["-"], "fwrapv">, Group,
-  Visibility<[ClangOption, CC1Option]>,
+  Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
   HelpText<"Treat signed integer overflow as two's complement">;
 def fwritable_strings : Flag<["-"], "fwritable-strings">, Group,
   Visibility<[ClangOption, CC1Option]>,
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 98350690f8d20e..1865fd57a2d893 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -866,6 +866,17 @@ void Flang::ConstructJob(Compilation &C, const JobAction 
&JA,
 }
   }
 
+  // -fno-strict-overflow implies -fwrapv if it isn't disabled, but
+  // -fstrict-overflow won't turn off an explicitly enabled -fwrapv.
+  if (Arg *A = Args.getLastArg(options::OPT_fwrapv, options::OPT_fno_wrapv)) {
+if (A->getOption().matches(options::OPT_fwrapv))
+  CmdArgs.push_back("-fwrapv");
+  } else if (Arg *A = Args.getLastArg(options::OPT_fstrict_overflow,
+  options::OPT_fno_strict_overflow)) {
+if (A->getOption().matches(options::OPT_fno_strict_overflow))
+  CmdArgs.push_back("-fwrapv");
+  }
+
   assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
 CmdArgs.push_back("-o");
diff --git a/flang/include/flang/Common/LangOptions.def 
b/flang/include/flang/Common/LangOptions.def
index d3e1e972d1519f..1bfdba9cc2c1c7 100644
--- a/flang/include/flang/Common/LangOptions.def
+++ b/flang/include/flang/Common/LangOptions.def
@@ -20,6 +20,8 @@ LANGOPT(Name, Bits, Default)
 #endif
 
 ENUM_LANGOPT(FPContractMode, FPModeKind, 2, FPM_Fast) ///< FP Contract Mode 
(off/fast)
+/// signed integer overflow handling
+ENUM_LANGOPT(SignedOverflowBehavior, SignedOverflowBeha

[clang] [compiler-rt] [lld] [llvm] [Coverage][WebAssembly] Add initial support for WebAssembly/WASI (PR #111332)

2024-10-06 Thread Yuta Saito via cfe-commits

https://github.com/kateinoigakukun created 
https://github.com/llvm/llvm-project/pull/111332

Currently, WebAssembly/WASI target does not provide direct support for code 
coverage.
This patch set fixes several issues to unlock the feature. The main changes are:

1. Port `compiler-rt/lib/profile` to WebAssembly/WASI.
2. Adjust profile metadata sections for Wasm object file format.
- [CodeGen] Emit `__llvm_covmap` and `__llvm_covfun` as custom sections 
instead of data segments.
- [lld] Align the interval space of custom sections at link time.
- [llvm-cov] Copy misaligned custom section data if the start address is 
not aligned.
- [llvm-cov] Read `__llvm_prf_names` from data segments
3. [clang] Link with profile runtime libraries if requested

See each commit message for more details and rationale.


>From 605e1ad180c9f75fd59d8b783ae2041cbaf34e50 Mon Sep 17 00:00:00 2001
From: Yuta Saito 
Date: Sat, 5 Oct 2024 16:54:57 +
Subject: [PATCH 1/7] [compiler-rt][profile] Add initial support for
 WebAssembly/WASI

This patch adds initial support for WebAssembly/WASI to the profile
runtime library on the top of wasi-libc. This is a part of the ongoing
patch series to add coverage support for WebAssembly/WASI.

The patch includes the following changes:
* Add wasm32-wasi to the list of supported architectures/OSes.
* Exclude unsupported features for WASI: flock, madvise, uname.
* Enable some user-space emulation provided by wasi-libc: mmap, getpid
---
 .../cmake/Modules/AllSupportedArchDefs.cmake  |  2 +-
 compiler-rt/cmake/config-ix.cmake |  2 +-
 compiler-rt/lib/profile/CMakeLists.txt| 24 +++
 compiler-rt/lib/profile/GCDAProfiling.c   |  2 +-
 compiler-rt/lib/profile/InstrProfilingPort.h  |  2 +-
 compiler-rt/lib/profile/InstrProfilingUtil.c  | 12 ++
 6 files changed, 36 insertions(+), 8 deletions(-)

diff --git a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake 
b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
index 809e9277156912..d00d39518104bf 100644
--- a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
+++ b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
@@ -77,7 +77,7 @@ set(ALL_HWASAN_SUPPORTED_ARCH ${X86_64} ${ARM64} ${RISCV64})
 set(ALL_MEMPROF_SUPPORTED_ARCH ${X86_64})
 set(ALL_PROFILE_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${PPC32} 
${PPC64}
 ${MIPS32} ${MIPS64} ${S390X} ${SPARC} ${SPARCV9} ${HEXAGON}
-${RISCV32} ${RISCV64} ${LOONGARCH64})
+${RISCV32} ${RISCV64} ${LOONGARCH64} ${WASM32})
 set(ALL_CTX_PROFILE_SUPPORTED_ARCH ${X86_64})
 if (OS_NAME MATCHES "FreeBSD")
   set(ALL_TSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64})
diff --git a/compiler-rt/cmake/config-ix.cmake 
b/compiler-rt/cmake/config-ix.cmake
index a93a88a9205001..a494e0532a50bc 100644
--- a/compiler-rt/cmake/config-ix.cmake
+++ b/compiler-rt/cmake/config-ix.cmake
@@ -822,7 +822,7 @@ else()
 endif()
 
 if (PROFILE_SUPPORTED_ARCH AND NOT LLVM_USE_SANITIZER AND
-OS_NAME MATCHES 
"Darwin|Linux|FreeBSD|Windows|Android|Fuchsia|SunOS|NetBSD|AIX")
+OS_NAME MATCHES 
"Darwin|Linux|FreeBSD|Windows|Android|Fuchsia|SunOS|NetBSD|AIX|WASI")
   set(COMPILER_RT_HAS_PROFILE TRUE)
 else()
   set(COMPILER_RT_HAS_PROFILE FALSE)
diff --git a/compiler-rt/lib/profile/CMakeLists.txt 
b/compiler-rt/lib/profile/CMakeLists.txt
index ef23492514898b..a6402f80b890a2 100644
--- a/compiler-rt/lib/profile/CMakeLists.txt
+++ b/compiler-rt/lib/profile/CMakeLists.txt
@@ -38,6 +38,17 @@ int main() {
 
 " COMPILER_RT_TARGET_HAS_FCNTL_LCK)
 
+CHECK_CXX_SOURCE_COMPILES("
+#include 
+
+int fd;
+int main() {
+  flock(fd, LOCK_EX);
+  return 0;
+}
+
+" COMPILER_RT_TARGET_HAS_FLOCK)
+
 CHECK_CXX_SOURCE_COMPILES("
 #include 
 int main() {
@@ -93,6 +104,13 @@ if(FUCHSIA OR UNIX)
  -Wno-pedantic)
 endif()
 
+if(CMAKE_SYSTEM_NAME STREQUAL "WASI")
+  set(EXTRA_FLAGS
+  ${EXTRA_FLAGS}
+  -D_WASI_EMULATED_MMAN
+  -D_WASI_EMULATED_GETPID)
+endif()
+
 if(COMPILER_RT_TARGET_HAS_ATOMICS)
  set(EXTRA_FLAGS
  ${EXTRA_FLAGS}
@@ -105,6 +123,12 @@ if(COMPILER_RT_TARGET_HAS_FCNTL_LCK)
  -DCOMPILER_RT_HAS_FCNTL_LCK=1)
 endif()
 
+if(COMPILER_RT_TARGET_HAS_FLOCK)
+  set(EXTRA_FLAGS
+  ${EXTRA_FLAGS}
+  -DCOMPILER_RT_HAS_FLOCK=1)
+endif()
+
 if(COMPILER_RT_TARGET_HAS_UNAME)
  set(EXTRA_FLAGS
  ${EXTRA_FLAGS}
diff --git a/compiler-rt/lib/profile/GCDAProfiling.c 
b/compiler-rt/lib/profile/GCDAProfiling.c
index d6e2175169e4a5..a207ddf97c8831 100644
--- a/compiler-rt/lib/profile/GCDAProfiling.c
+++ b/compiler-rt/lib/profile/GCDAProfiling.c
@@ -584,7 +584,7 @@ void llvm_reset_counters(void) {
   }
 }
 
-#if !defined(_WIN32)
+#if !defined(_WIN32) && !defined(__wasi__)
 COMPILER_RT_VISIBILITY
 pid_t __gcov_fork() {
   pid_t parent_pid = getpid();
diff --git a/compiler-rt/lib/profile/InstrProfilingPort.h 
b/compiler-rt/lib/profile/InstrProfilingPort.h
index ed0905cc5f2022..8715a3b0d2a6f0 100644
--- a/compiler-rt/lib/profile/InstrProfilingPort.h
+++ b/compile

[clang] [compiler-rt] [lld] [llvm] [Coverage][WebAssembly] Add initial support for WebAssembly/WASI (PR #111332)

2024-10-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-lld-wasm

Author: Yuta Saito (kateinoigakukun)


Changes

Currently, WebAssembly/WASI target does not provide direct support for code 
coverage.
This patch set fixes several issues to unlock the feature. The main changes are:

1. Port `compiler-rt/lib/profile` to WebAssembly/WASI.
2. Adjust profile metadata sections for Wasm object file format.
- [CodeGen] Emit `__llvm_covmap` and `__llvm_covfun` as custom sections 
instead of data segments.
- [lld] Align the interval space of custom sections at link time.
- [llvm-cov] Copy misaligned custom section data if the start address is 
not aligned.
- [llvm-cov] Read `__llvm_prf_names` from data segments
3. [clang] Link with profile runtime libraries if requested

See each commit message for more details and rationale.


---

Patch is 22.72 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/111332.diff


21 Files Affected:

- (modified) clang/lib/Driver/ToolChains/WebAssembly.cpp (+2) 
- (modified) compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake (+1-1) 
- (modified) compiler-rt/cmake/config-ix.cmake (+1-1) 
- (modified) compiler-rt/lib/profile/CMakeLists.txt (+24) 
- (modified) compiler-rt/lib/profile/GCDAProfiling.c (+1-1) 
- (modified) compiler-rt/lib/profile/InstrProfilingPlatformLinux.c (+2-2) 
- (modified) compiler-rt/lib/profile/InstrProfilingPlatformOther.c (+1-1) 
- (modified) compiler-rt/lib/profile/InstrProfilingPort.h (+1-1) 
- (modified) compiler-rt/lib/profile/InstrProfilingUtil.c (+8-4) 
- (added) lld/test/wasm/custom-section-align.s (+31) 
- (modified) lld/wasm/InputChunks.h (+6-4) 
- (modified) lld/wasm/InputFiles.cpp (+16-2) 
- (modified) lld/wasm/OutputSections.cpp (+1) 
- (modified) llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp (+5-1) 
- (modified) llvm/lib/MC/MCContext.cpp (+5) 
- (modified) llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp (+64-9) 
- (modified) llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp (+2-2) 
- (added) llvm/test/CodeGen/WebAssembly/profile.ll (+47) 
- (added) llvm/test/tools/llvm-cov/Inputs/binary-formats.v6.wasm32 () 
- (added) llvm/test/tools/llvm-cov/Inputs/binary-formats.wasm.proftext (+4) 
- (modified) llvm/test/tools/llvm-cov/binary-formats.c (+6) 


``diff
diff --git a/clang/lib/Driver/ToolChains/WebAssembly.cpp 
b/clang/lib/Driver/ToolChains/WebAssembly.cpp
index 9aec11e69fde1d..44a6894d30fb29 100644
--- a/clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ b/clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -163,6 +163,8 @@ void wasm::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 AddRunTimeLibs(ToolChain, ToolChain.getDriver(), CmdArgs, Args);
   }
 
+  ToolChain.addProfileRTLibs(Args, CmdArgs);
+
   CmdArgs.push_back("-o");
   CmdArgs.push_back(Output.getFilename());
 
diff --git a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake 
b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
index 809e9277156912..d00d39518104bf 100644
--- a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
+++ b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
@@ -77,7 +77,7 @@ set(ALL_HWASAN_SUPPORTED_ARCH ${X86_64} ${ARM64} ${RISCV64})
 set(ALL_MEMPROF_SUPPORTED_ARCH ${X86_64})
 set(ALL_PROFILE_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${PPC32} 
${PPC64}
 ${MIPS32} ${MIPS64} ${S390X} ${SPARC} ${SPARCV9} ${HEXAGON}
-${RISCV32} ${RISCV64} ${LOONGARCH64})
+${RISCV32} ${RISCV64} ${LOONGARCH64} ${WASM32})
 set(ALL_CTX_PROFILE_SUPPORTED_ARCH ${X86_64})
 if (OS_NAME MATCHES "FreeBSD")
   set(ALL_TSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64})
diff --git a/compiler-rt/cmake/config-ix.cmake 
b/compiler-rt/cmake/config-ix.cmake
index a93a88a9205001..a494e0532a50bc 100644
--- a/compiler-rt/cmake/config-ix.cmake
+++ b/compiler-rt/cmake/config-ix.cmake
@@ -822,7 +822,7 @@ else()
 endif()
 
 if (PROFILE_SUPPORTED_ARCH AND NOT LLVM_USE_SANITIZER AND
-OS_NAME MATCHES 
"Darwin|Linux|FreeBSD|Windows|Android|Fuchsia|SunOS|NetBSD|AIX")
+OS_NAME MATCHES 
"Darwin|Linux|FreeBSD|Windows|Android|Fuchsia|SunOS|NetBSD|AIX|WASI")
   set(COMPILER_RT_HAS_PROFILE TRUE)
 else()
   set(COMPILER_RT_HAS_PROFILE FALSE)
diff --git a/compiler-rt/lib/profile/CMakeLists.txt 
b/compiler-rt/lib/profile/CMakeLists.txt
index ef23492514898b..a6402f80b890a2 100644
--- a/compiler-rt/lib/profile/CMakeLists.txt
+++ b/compiler-rt/lib/profile/CMakeLists.txt
@@ -38,6 +38,17 @@ int main() {
 
 " COMPILER_RT_TARGET_HAS_FCNTL_LCK)
 
+CHECK_CXX_SOURCE_COMPILES("
+#include 
+
+int fd;
+int main() {
+  flock(fd, LOCK_EX);
+  return 0;
+}
+
+" COMPILER_RT_TARGET_HAS_FLOCK)
+
 CHECK_CXX_SOURCE_COMPILES("
 #include 
 int main() {
@@ -93,6 +104,13 @@ if(FUCHSIA OR UNIX)
  -Wno-pedantic)
 endif()
 
+if(CMAKE_SYSTEM_NAME STREQUAL "WASI")
+  set(EXTRA_FLAGS
+  ${EXTRA_FLAGS}
+  -D_WASI_EMULATED_MMAN
+  -D_WASI_EMULATED_GETPID)
+endif()
+
 if(COMPILER_RT_TARGET_HAS_ATOMICS)
  set(EXTRA_FLAGS
  ${EXTR

[clang] [compiler-rt] [lld] [llvm] [Coverage][WebAssembly] Add initial support for WebAssembly/WASI (PR #111332)

2024-10-06 Thread Yuta Saito via cfe-commits

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


[clang] [compiler-rt] [lld] [llvm] [Coverage][WebAssembly] Add initial support for WebAssembly/WASI (PR #111332)

2024-10-06 Thread Yuta Saito via cfe-commits

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


[clang] [Clang] Remove the special-casing for RequiresExprBodyDecl in BuildResolvedCallExpr() after fd87d765c0 (PR #111277)

2024-10-06 Thread via cfe-commits

llvmbot wrote:

/pull-request llvm/llvm-project#111324

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


[clang] [clang] Track function template instantiation from definition (PR #110387)

2024-10-06 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/110387

>From 226b1bea7b287f31f4dc8d57466c8af5c6012c4e Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Sat, 28 Sep 2024 14:28:58 -0300
Subject: [PATCH] [clang] Track function template instantiation from definition

This fixes instantiation of definition for friend function templates,
when the declaration found and the one containing the definition
have different template contexts.

In these cases, the the function declaration corresponding to the
definition is not available; it may not even be instantiated at all.

So this patch adds a bit which tracks which function template
declaration was instantiated from the member template.
It's used to find which primary template serves as a context
for the purpose of obtainining the template arguments needed
to instantiate the definition.

Fixes #55509
---
 clang/docs/ReleaseNotes.rst   |   1 +
 clang/include/clang/AST/Decl.h|   7 ++
 clang/include/clang/AST/DeclBase.h|  10 +-
 clang/include/clang/AST/DeclTemplate.h|   9 ++
 clang/lib/AST/Decl.cpp|   1 +
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  17 +--
 clang/lib/Sema/SemaTemplateInstantiate.cpp|   9 +-
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  22 +++-
 clang/lib/Serialization/ASTReaderDecl.cpp |   1 +
 clang/lib/Serialization/ASTWriterDecl.cpp |   3 +-
 clang/test/SemaTemplate/GH55509.cpp   | 101 ++
 11 files changed, 153 insertions(+), 28 deletions(-)
 create mode 100644 clang/test/SemaTemplate/GH55509.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 44d5f348ed2d54..552c9f524a7ae6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -468,6 +468,7 @@ Bug Fixes to C++ Support
 - Fixed an assertion failure in debug mode, and potential crashes in release 
mode, when
   diagnosing a failed cast caused indirectly by a failed implicit conversion 
to the type of the constructor parameter.
 - Fixed an assertion failure by adjusting integral to boolean vector 
conversions (#GH108326)
+- Clang is now better at keeping track of friend function template instance 
contexts. (#GH55509)
 - Fixed an issue deducing non-type template arguments of reference type. 
(#GH73460)
 - Fixed an issue in constraint evaluation, where type constraints on the 
lambda expression
   containing outer unexpanded parameters were not correctly expanded. 
(#GH101754)
diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 7ff35d73df5997..6afc86710a8137 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -2299,6 +2299,13 @@ class FunctionDecl : public DeclaratorDecl,
 FunctionDeclBits.IsLateTemplateParsed = ILT;
   }
 
+  bool isInstantiatedFromMemberTemplate() const {
+return FunctionDeclBits.IsInstantiatedFromMemberTemplate;
+  }
+  void setInstantiatedFromMemberTemplate(bool Val = true) {
+FunctionDeclBits.IsInstantiatedFromMemberTemplate = Val;
+  }
+
   /// Whether this function is "trivial" in some specialized C++ senses.
   /// Can only be true for default constructors, copy constructors,
   /// copy assignment operators, and destructors.  Not meaningful until
diff --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index ee662ed73d7e0e..eb67dc03157e64 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -1763,6 +1763,8 @@ class DeclContext {
 uint64_t HasImplicitReturnZero : 1;
 LLVM_PREFERRED_TYPE(bool)
 uint64_t IsLateTemplateParsed : 1;
+LLVM_PREFERRED_TYPE(bool)
+uint64_t IsInstantiatedFromMemberTemplate : 1;
 
 /// Kind of contexpr specifier as defined by ConstexprSpecKind.
 LLVM_PREFERRED_TYPE(ConstexprSpecKind)
@@ -1813,7 +1815,7 @@ class DeclContext {
   };
 
   /// Number of inherited and non-inherited bits in FunctionDeclBitfields.
-  enum { NumFunctionDeclBits = NumDeclContextBits + 31 };
+  enum { NumFunctionDeclBits = NumDeclContextBits + 32 };
 
   /// Stores the bits used by CXXConstructorDecl. If modified
   /// NumCXXConstructorDeclBits and the accessor
@@ -1824,12 +1826,12 @@ class DeclContext {
 LLVM_PREFERRED_TYPE(FunctionDeclBitfields)
 uint64_t : NumFunctionDeclBits;
 
-/// 20 bits to fit in the remaining available space.
+/// 19 bits to fit in the remaining available space.
 /// Note that this makes CXXConstructorDeclBitfields take
 /// exactly 64 bits and thus the width of NumCtorInitializers
 /// will need to be shrunk if some bit is added to NumDeclContextBitfields,
 /// NumFunctionDeclBitfields or CXXConstructorDeclBitfields.
-uint64_t NumCtorInitializers : 17;
+uint64_t NumCtorInitializers : 16;
 LLVM_PREFERRED_TYPE(bool)
 uint64_t IsInheritingConstructor : 1;
 
@@ -1843,7 +1845,7 @@ class DeclContext {
   };
 
   /// Number of inherited a

[clang] [compiler-rt] [lld] [llvm] [Coverage][WebAssembly] Add initial support for WebAssembly/WASI (PR #111332)

2024-10-06 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 e8f01b0557354a28d17bfe618df5e257ec3e982a 
ed504c7c7ff3b02a08c3d7465df793377934011f --extensions c,h,cpp -- 
clang/lib/Driver/ToolChains/WebAssembly.cpp 
compiler-rt/lib/profile/GCDAProfiling.c 
compiler-rt/lib/profile/InstrProfilingPlatformLinux.c 
compiler-rt/lib/profile/InstrProfilingPlatformOther.c 
compiler-rt/lib/profile/InstrProfilingPort.h 
compiler-rt/lib/profile/InstrProfilingUtil.c lld/wasm/InputChunks.h 
lld/wasm/InputFiles.cpp lld/wasm/OutputSections.cpp 
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp llvm/lib/MC/MCContext.cpp 
llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp 
llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp 
llvm/test/tools/llvm-cov/binary-formats.c
``





View the diff from clang-format here.


``diff
diff --git a/compiler-rt/lib/profile/InstrProfilingPlatformLinux.c 
b/compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
index a9791eebab..02f23379ce 100644
--- a/compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
+++ b/compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
@@ -6,8 +6,8 @@
 |*
 
\*===--===*/
 
-#if defined(__linux__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \
-(defined(__sun__) && defined(__svr4__)) || defined(__NetBSD__) || \
+#if defined(__linux__) || defined(__FreeBSD__) || defined(__Fuchsia__) ||  
\
+(defined(__sun__) && defined(__svr4__)) || defined(__NetBSD__) ||  
\
 defined(_AIX) || defined(__wasm__)
 
 #if !defined(_AIX) && !defined(__wasm__)
diff --git a/compiler-rt/lib/profile/InstrProfilingPlatformOther.c 
b/compiler-rt/lib/profile/InstrProfilingPlatformOther.c
index e873e9ffbf..52e82273f8 100644
--- a/compiler-rt/lib/profile/InstrProfilingPlatformOther.c
+++ b/compiler-rt/lib/profile/InstrProfilingPlatformOther.c
@@ -8,7 +8,8 @@
 
 #if !defined(__APPLE__) && !defined(__linux__) && !defined(__FreeBSD__) && 
\
 !defined(__Fuchsia__) && !(defined(__sun__) && defined(__svr4__)) &&   
\
-!defined(__NetBSD__) && !defined(_WIN32) && !defined(_AIX) && 
!defined(__wasm__)
+!defined(__NetBSD__) && !defined(_WIN32) && !defined(_AIX) &&  
\
+!defined(__wasm__)
 
 #include 
 #include 
diff --git a/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp 
b/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
index 347578ad5f..dcbeb9f22a 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
@@ -1187,7 +1187,8 @@ loadBinaryFormat(std::unique_ptr Bin, StringRef 
Arch,
   // because it doesn't have a good way to insert padding bytes.
   std::unique_ptr CoverageMappingBufferOwner;
   if (!isAddrAligned(Align(8), CoverageMapping.data())) {
-CoverageMappingBufferOwner = 
MemoryBuffer::getMemBufferCopy(CoverageMapping);
+CoverageMappingBufferOwner =
+MemoryBuffer::getMemBufferCopy(CoverageMapping);
 CoverageMapping = CoverageMappingBufferOwner->getBuffer();
   }
 
diff --git a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp 
b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
index b875f851a5..929c787442 100644
--- a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
+++ b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
@@ -1408,7 +1408,8 @@ static bool needsRuntimeRegistrationOfSectionRange(const 
Triple &TT) {
   // compiler-rt uses linker support to get data/counters/name start/end for
   // ELF, COFF, Mach-O, XCOFF, and Wasm.
   if (TT.isOSBinFormatELF() || TT.isOSBinFormatCOFF() ||
-  TT.isOSBinFormatMachO() || TT.isOSBinFormatXCOFF() || 
TT.isOSBinFormatWasm())
+  TT.isOSBinFormatMachO() || TT.isOSBinFormatXCOFF() ||
+  TT.isOSBinFormatWasm())
 return false;
 
   return true;

``




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


[clang] Recommit "[RISCV][FMV] Support target_version" (#111096)" (PR #111333)

2024-10-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Piyou Chen (BeMg)


Changes

Fix the buildbot failure caused by heap use-after-free error.

Origin message:

This patch enable `target_version` attribute for RISC-V target.

The proposal of `target_version` syntax can be found at the
https://github.com/riscv-non-isa/riscv-c-api-doc/pull/48 (which has
landed), as modified by the proposed
https://github.com/riscv-non-isa/riscv-c-api-doc/pull/85 (which adds the
priority syntax).

`target_version` attribute will trigger the function multi-versioning
feature and act like `target_clones` attribute. See
https://github.com/llvm/llvm-project/pull/85786 for the implementation
of `target_clones`.

---

Patch is 57.55 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/111333.diff


8 Files Affected:

- (modified) clang/lib/AST/ASTContext.cpp (+11-3) 
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+6-1) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+16-4) 
- (modified) clang/lib/Sema/SemaDeclAttr.cpp (+48) 
- (added) clang/test/CodeGen/attr-target-version-riscv-invalid.c (+13) 
- (added) clang/test/CodeGen/attr-target-version-riscv.c (+443) 
- (added) clang/test/CodeGenCXX/attr-target-version-riscv.cpp (+432) 
- (added) clang/test/SemaCXX/attr-target-version-riscv.cpp (+113) 


``diff
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index a81429ad6a2380..034fbbe0bc7829 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -14325,9 +14325,17 @@ void 
ASTContext::getFunctionFeatureMap(llvm::StringMap &FeatureMap,
   Target->initFeatureMap(FeatureMap, getDiagnostics(), TargetCPU, 
Features);
 }
   } else if (const auto *TV = FD->getAttr()) {
-llvm::SmallVector Feats;
-TV->getFeatures(Feats);
-std::vector Features = getFMVBackendFeaturesFor(Feats);
+std::vector Features;
+if (Target->getTriple().isRISCV()) {
+  ParsedTargetAttr ParsedAttr = Target->parseTargetAttr(TV->getName());
+  Features.insert(Features.begin(), ParsedAttr.Features.begin(),
+  ParsedAttr.Features.end());
+} else {
+  assert(Target->getTriple().isAArch64());
+  llvm::SmallVector Feats;
+  TV->getFeatures(Feats);
+  Features = getFMVBackendFeaturesFor(Feats);
+}
 Features.insert(Features.begin(),
 Target->getTargetOpts().FeaturesAsWritten.begin(),
 Target->getTargetOpts().FeaturesAsWritten.end());
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 25c1c496a4f27f..5ba098144a74e7 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4287,8 +4287,13 @@ void CodeGenModule::emitMultiVersionFunctions() {
   } else if (const auto *TVA = CurFD->getAttr()) {
 if (TVA->isDefaultVersion() && IsDefined)
   ShouldEmitResolver = true;
-TVA->getFeatures(Feats);
 llvm::Function *Func = createFunction(CurFD);
+if (getTarget().getTriple().isRISCV()) {
+  Feats.push_back(TVA->getName());
+} else {
+  assert(getTarget().getTriple().isAArch64());
+  TVA->getFeatures(Feats);
+}
 Options.emplace_back(Func, /*Architecture*/ "", Feats);
   } else if (const auto *TC = CurFD->getAttr()) {
 if (IsDefined)
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 2bf610746bc317..5c4e0562152c5b 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -10329,7 +10329,8 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, 
DeclContext *DC,
   // Handle attributes.
   ProcessDeclAttributes(S, NewFD, D);
   const auto *NewTVA = NewFD->getAttr();
-  if (NewTVA && !NewTVA->isDefaultVersion() &&
+  if (Context.getTargetInfo().getTriple().isAArch64() && NewTVA &&
+  !NewTVA->isDefaultVersion() &&
   !Context.getTargetInfo().hasFeature("fmv")) {
 // Don't add to scope fmv functions declarations if fmv disabled
 AddToScope = false;
@@ -11038,7 +11039,16 @@ static bool CheckMultiVersionValue(Sema &S, const 
FunctionDecl *FD) {
 
   if (TVA) {
 llvm::SmallVector Feats;
-TVA->getFeatures(Feats);
+ParsedTargetAttr ParseInfo;
+if (S.getASTContext().getTargetInfo().getTriple().isRISCV()) {
+  ParseInfo =
+  S.getASTContext().getTargetInfo().parseTargetAttr(TVA->getName());
+  for (auto &Feat : ParseInfo.Features)
+Feats.push_back(StringRef{Feat}.substr(1));
+} else {
+  assert(S.getASTContext().getTargetInfo().getTriple().isAArch64());
+  TVA->getFeatures(Feats);
+}
 for (const auto &Feat : Feats) {
   if (!TargetInfo.validateCpuSupports(Feat)) {
 S.Diag(FD->getLocation(), diag::err_bad_multiversion_option)
@@ -11324,7 +11334,8 @@ static bool 
PreviousDeclsHa

[clang] Recommit "[RISCV][FMV] Support target_version" (#111096)" (PR #111333)

2024-10-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Piyou Chen (BeMg)


Changes

Fix the buildbot failure caused by heap use-after-free error.

Origin message:

This patch enable `target_version` attribute for RISC-V target.

The proposal of `target_version` syntax can be found at the
https://github.com/riscv-non-isa/riscv-c-api-doc/pull/48 (which has
landed), as modified by the proposed
https://github.com/riscv-non-isa/riscv-c-api-doc/pull/85 (which adds the
priority syntax).

`target_version` attribute will trigger the function multi-versioning
feature and act like `target_clones` attribute. See
https://github.com/llvm/llvm-project/pull/85786 for the implementation
of `target_clones`.

---

Patch is 57.55 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/111333.diff


8 Files Affected:

- (modified) clang/lib/AST/ASTContext.cpp (+11-3) 
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+6-1) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+16-4) 
- (modified) clang/lib/Sema/SemaDeclAttr.cpp (+48) 
- (added) clang/test/CodeGen/attr-target-version-riscv-invalid.c (+13) 
- (added) clang/test/CodeGen/attr-target-version-riscv.c (+443) 
- (added) clang/test/CodeGenCXX/attr-target-version-riscv.cpp (+432) 
- (added) clang/test/SemaCXX/attr-target-version-riscv.cpp (+113) 


``diff
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index a81429ad6a2380..034fbbe0bc7829 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -14325,9 +14325,17 @@ void 
ASTContext::getFunctionFeatureMap(llvm::StringMap &FeatureMap,
   Target->initFeatureMap(FeatureMap, getDiagnostics(), TargetCPU, 
Features);
 }
   } else if (const auto *TV = FD->getAttr()) {
-llvm::SmallVector Feats;
-TV->getFeatures(Feats);
-std::vector Features = getFMVBackendFeaturesFor(Feats);
+std::vector Features;
+if (Target->getTriple().isRISCV()) {
+  ParsedTargetAttr ParsedAttr = Target->parseTargetAttr(TV->getName());
+  Features.insert(Features.begin(), ParsedAttr.Features.begin(),
+  ParsedAttr.Features.end());
+} else {
+  assert(Target->getTriple().isAArch64());
+  llvm::SmallVector Feats;
+  TV->getFeatures(Feats);
+  Features = getFMVBackendFeaturesFor(Feats);
+}
 Features.insert(Features.begin(),
 Target->getTargetOpts().FeaturesAsWritten.begin(),
 Target->getTargetOpts().FeaturesAsWritten.end());
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 25c1c496a4f27f..5ba098144a74e7 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4287,8 +4287,13 @@ void CodeGenModule::emitMultiVersionFunctions() {
   } else if (const auto *TVA = CurFD->getAttr()) {
 if (TVA->isDefaultVersion() && IsDefined)
   ShouldEmitResolver = true;
-TVA->getFeatures(Feats);
 llvm::Function *Func = createFunction(CurFD);
+if (getTarget().getTriple().isRISCV()) {
+  Feats.push_back(TVA->getName());
+} else {
+  assert(getTarget().getTriple().isAArch64());
+  TVA->getFeatures(Feats);
+}
 Options.emplace_back(Func, /*Architecture*/ "", Feats);
   } else if (const auto *TC = CurFD->getAttr()) {
 if (IsDefined)
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 2bf610746bc317..5c4e0562152c5b 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -10329,7 +10329,8 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, 
DeclContext *DC,
   // Handle attributes.
   ProcessDeclAttributes(S, NewFD, D);
   const auto *NewTVA = NewFD->getAttr();
-  if (NewTVA && !NewTVA->isDefaultVersion() &&
+  if (Context.getTargetInfo().getTriple().isAArch64() && NewTVA &&
+  !NewTVA->isDefaultVersion() &&
   !Context.getTargetInfo().hasFeature("fmv")) {
 // Don't add to scope fmv functions declarations if fmv disabled
 AddToScope = false;
@@ -11038,7 +11039,16 @@ static bool CheckMultiVersionValue(Sema &S, const 
FunctionDecl *FD) {
 
   if (TVA) {
 llvm::SmallVector Feats;
-TVA->getFeatures(Feats);
+ParsedTargetAttr ParseInfo;
+if (S.getASTContext().getTargetInfo().getTriple().isRISCV()) {
+  ParseInfo =
+  S.getASTContext().getTargetInfo().parseTargetAttr(TVA->getName());
+  for (auto &Feat : ParseInfo.Features)
+Feats.push_back(StringRef{Feat}.substr(1));
+} else {
+  assert(S.getASTContext().getTargetInfo().getTriple().isAArch64());
+  TVA->getFeatures(Feats);
+}
 for (const auto &Feat : Feats) {
   if (!TargetInfo.validateCpuSupports(Feat)) {
 S.Diag(FD->getLocation(), diag::err_bad_multiversion_option)
@@ -11324,7 +11334,8 @@ static bool 
PreviousDeclsHaveMultiV

[clang] [clang][OpenMP][test] Use x86_64-linux-gnu triple for test referencing avx512f feature (PR #111337)

2024-10-06 Thread Alex Bradbury via cfe-commits

https://github.com/asb created https://github.com/llvm/llvm-project/pull/111337

This test passes as-is on non-X86 hosts only because almost no target 
implements `isValidFeatureName` (the default implementation unconditionally 
returns true). RISC-V does implement it, and like X86 checks that the feature 
name is one supported by the architecture. This means the test creates an 
additional warning on RISC-V due to `_attribute__((target("avx512f")))`.

The simple solution here is to just explicitly target x86_64-linux-gnu.

>From 29be2d206887d7afedf295b8fdde3852eec488ae Mon Sep 17 00:00:00 2001
From: Alex Bradbury 
Date: Mon, 7 Oct 2024 06:02:42 +0100
Subject: [PATCH] [clang][OpenMP][test] Use x86_64-linux-gnu triple for test
 referencing avx512f feature

This test passes as-is on non-X86 hosts only because almost no target
implements `isValidFeatureName` (the default implementation
unconditionally returns true). RISC-V does implement it, and like X86
checks that the feature name is one supported by the architecture. This
means the test creates an additional warning on RISC-V due to
`_attribute__((target("avx512f")))`.

The simple solution here is to just explicitly target x86_64-linux-gnu.
---
 .../declare_variant_device_isa_codegen_1.c| 24 +--
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/clang/test/OpenMP/declare_variant_device_isa_codegen_1.c 
b/clang/test/OpenMP/declare_variant_device_isa_codegen_1.c
index 029270ab848663..47367536550ac1 100644
--- a/clang/test/OpenMP/declare_variant_device_isa_codegen_1.c
+++ b/clang/test/OpenMP/declare_variant_device_isa_codegen_1.c
@@ -1,18 +1,18 @@
-// RUN: %clang_cc1 -verify -fopenmp -x c -triple %itanium_abi_triple 
-emit-llvm %s -o - -fopenmp-version=45 | FileCheck %s --check-prefix=GENERIC
-// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple %itanium_abi_triple 
-fexceptions -fcxx-exceptions -emit-pch -o %t -fopenmp-version=45 %s
-// RUN: %clang_cc1 -fopenmp -x c++ -triple %itanium_abi_triple -fexceptions 
-fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - 
-fopenmp-version=45 | FileCheck %s --check-prefix=GENERIC
+// RUN: %clang_cc1 -verify -fopenmp -x c -triple x86_64-linux-gnu -emit-llvm 
%s -o - -fopenmp-version=45 | FileCheck %s --check-prefix=GENERIC
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-linux-gnu 
-fexceptions -fcxx-exceptions -emit-pch -o %t -fopenmp-version=45 %s
+// RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-linux-gnu -fexceptions 
-fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - 
-fopenmp-version=45 | FileCheck %s --check-prefix=GENERIC
 
-// RUN: %clang_cc1 -target-feature +avx512f -verify -fopenmp -x c -triple 
%itanium_abi_triple -emit-llvm %s -o - -fopenmp-version=45 | FileCheck %s 
--check-prefix=WITHFEATURE
-// RUN: %clang_cc1 -target-feature +avx512f -fopenmp -x c++ -std=c++11 -triple 
%itanium_abi_triple -fexceptions -fcxx-exceptions -emit-pch -o %t 
-fopenmp-version=45 %s
-// RUN: %clang_cc1 -target-feature +avx512f -fopenmp -x c++ -triple 
%itanium_abi_triple -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t 
-verify %s -emit-llvm -o - -fopenmp-version=45 | FileCheck %s 
--check-prefix=WITHFEATURE
+// RUN: %clang_cc1 -target-feature +avx512f -verify -fopenmp -x c -triple 
x86_64-linux-gnu -emit-llvm %s -o - -fopenmp-version=45 | FileCheck %s 
--check-prefix=WITHFEATURE
+// RUN: %clang_cc1 -target-feature +avx512f -fopenmp -x c++ -std=c++11 -triple 
x86_64-linux-gnu -fexceptions -fcxx-exceptions -emit-pch -o %t 
-fopenmp-version=45 %s
+// RUN: %clang_cc1 -target-feature +avx512f -fopenmp -x c++ -triple 
x86_64-linux-gnu -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t 
-verify %s -emit-llvm -o - -fopenmp-version=45 | FileCheck %s 
--check-prefix=WITHFEATURE
 
-// RUN: %clang_cc1 -verify -fopenmp -x c -triple %itanium_abi_triple 
-emit-llvm %s -o - | FileCheck %s --check-prefix=GENERIC
-// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple %itanium_abi_triple 
-fexceptions -fcxx-exceptions -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -x c++ -triple %itanium_abi_triple -fexceptions 
-fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | 
FileCheck %s --check-prefix=GENERIC
+// RUN: %clang_cc1 -verify -fopenmp -x c -triple x86_64-linux-gnu -emit-llvm 
%s -o - | FileCheck %s --check-prefix=GENERIC
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-linux-gnu 
-fexceptions -fcxx-exceptions -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-linux-gnu -fexceptions 
-fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | 
FileCheck %s --check-prefix=GENERIC
 
-// RUN: %clang_cc1 -target-feature +avx512f -verify -fopenmp -x c -triple 
%itanium_abi_triple -emit-llvm %s -o - | FileCheck %s --check-prefix=WITHFEATURE
-// RUN: %clang_cc1 -target-feature +avx512f -fopenmp -x c++ -std=c++11 -triple 
%itanium_abi_triple -fexceptions -fcxx-exceptions -emit-pch -o %t %

[clang] [clang][OpenMP][test] Use x86_64-linux-gnu triple for test referencing avx512f feature (PR #111337)

2024-10-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Alex Bradbury (asb)


Changes

This test passes as-is on non-X86 hosts only because almost no target 
implements `isValidFeatureName` (the default implementation unconditionally 
returns true). RISC-V does implement it, and like X86 checks that the feature 
name is one supported by the architecture. This means the test creates an 
additional warning on RISC-V due to `_attribute__((target("avx512f")))`.

The simple solution here is to just explicitly target x86_64-linux-gnu.

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


1 Files Affected:

- (modified) clang/test/OpenMP/declare_variant_device_isa_codegen_1.c (+12-12) 


``diff
diff --git a/clang/test/OpenMP/declare_variant_device_isa_codegen_1.c 
b/clang/test/OpenMP/declare_variant_device_isa_codegen_1.c
index 029270ab848663..47367536550ac1 100644
--- a/clang/test/OpenMP/declare_variant_device_isa_codegen_1.c
+++ b/clang/test/OpenMP/declare_variant_device_isa_codegen_1.c
@@ -1,18 +1,18 @@
-// RUN: %clang_cc1 -verify -fopenmp -x c -triple %itanium_abi_triple 
-emit-llvm %s -o - -fopenmp-version=45 | FileCheck %s --check-prefix=GENERIC
-// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple %itanium_abi_triple 
-fexceptions -fcxx-exceptions -emit-pch -o %t -fopenmp-version=45 %s
-// RUN: %clang_cc1 -fopenmp -x c++ -triple %itanium_abi_triple -fexceptions 
-fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - 
-fopenmp-version=45 | FileCheck %s --check-prefix=GENERIC
+// RUN: %clang_cc1 -verify -fopenmp -x c -triple x86_64-linux-gnu -emit-llvm 
%s -o - -fopenmp-version=45 | FileCheck %s --check-prefix=GENERIC
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-linux-gnu 
-fexceptions -fcxx-exceptions -emit-pch -o %t -fopenmp-version=45 %s
+// RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-linux-gnu -fexceptions 
-fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - 
-fopenmp-version=45 | FileCheck %s --check-prefix=GENERIC
 
-// RUN: %clang_cc1 -target-feature +avx512f -verify -fopenmp -x c -triple 
%itanium_abi_triple -emit-llvm %s -o - -fopenmp-version=45 | FileCheck %s 
--check-prefix=WITHFEATURE
-// RUN: %clang_cc1 -target-feature +avx512f -fopenmp -x c++ -std=c++11 -triple 
%itanium_abi_triple -fexceptions -fcxx-exceptions -emit-pch -o %t 
-fopenmp-version=45 %s
-// RUN: %clang_cc1 -target-feature +avx512f -fopenmp -x c++ -triple 
%itanium_abi_triple -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t 
-verify %s -emit-llvm -o - -fopenmp-version=45 | FileCheck %s 
--check-prefix=WITHFEATURE
+// RUN: %clang_cc1 -target-feature +avx512f -verify -fopenmp -x c -triple 
x86_64-linux-gnu -emit-llvm %s -o - -fopenmp-version=45 | FileCheck %s 
--check-prefix=WITHFEATURE
+// RUN: %clang_cc1 -target-feature +avx512f -fopenmp -x c++ -std=c++11 -triple 
x86_64-linux-gnu -fexceptions -fcxx-exceptions -emit-pch -o %t 
-fopenmp-version=45 %s
+// RUN: %clang_cc1 -target-feature +avx512f -fopenmp -x c++ -triple 
x86_64-linux-gnu -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t 
-verify %s -emit-llvm -o - -fopenmp-version=45 | FileCheck %s 
--check-prefix=WITHFEATURE
 
-// RUN: %clang_cc1 -verify -fopenmp -x c -triple %itanium_abi_triple 
-emit-llvm %s -o - | FileCheck %s --check-prefix=GENERIC
-// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple %itanium_abi_triple 
-fexceptions -fcxx-exceptions -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -x c++ -triple %itanium_abi_triple -fexceptions 
-fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | 
FileCheck %s --check-prefix=GENERIC
+// RUN: %clang_cc1 -verify -fopenmp -x c -triple x86_64-linux-gnu -emit-llvm 
%s -o - | FileCheck %s --check-prefix=GENERIC
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-linux-gnu 
-fexceptions -fcxx-exceptions -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-linux-gnu -fexceptions 
-fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | 
FileCheck %s --check-prefix=GENERIC
 
-// RUN: %clang_cc1 -target-feature +avx512f -verify -fopenmp -x c -triple 
%itanium_abi_triple -emit-llvm %s -o - | FileCheck %s --check-prefix=WITHFEATURE
-// RUN: %clang_cc1 -target-feature +avx512f -fopenmp -x c++ -std=c++11 -triple 
%itanium_abi_triple -fexceptions -fcxx-exceptions -emit-pch -o %t %s
-// RUN: %clang_cc1 -target-feature +avx512f -fopenmp -x c++ -triple 
%itanium_abi_triple -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t 
-verify %s -emit-llvm -o - | FileCheck %s --check-prefix=WITHFEATURE
+// RUN: %clang_cc1 -target-feature +avx512f -verify -fopenmp -x c -triple 
x86_64-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix=WITHFEATURE
+// RUN: %clang_cc1 -target-feature +avx512f -fopenmp -x c++ -std=c++11 -triple 
x86_64-linux-gnu -fexceptions -fcxx-exceptions -emit-pch -o %t %s
+// RUN: %clang_cc1 -target-feature +avx512f -fopenmp -x c++ -triple 
x86_64-linux-gnu -fexcepti

[clang] [AST] Avoid repeated hash lookups (NFC) (PR #111327)

2024-10-06 Thread Kazu Hirata via cfe-commits

https://github.com/kazutakahirata created 
https://github.com/llvm/llvm-project/pull/111327

Here I'm splitting up the existing "if" statement into two.  Mixing
hasDefinition() and insert() in one "if" condition would be extremely
confusing as hasDefinition() doesn't change anything while insert()
does.


>From f589b84590745c8709f1d9ce0e18c5e13746a27f Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Sun, 6 Oct 2024 09:25:35 -0700
Subject: [PATCH] [AST] Avoid repeated hash lookups (NFC)

Here I'm splitting up the existing "if" statement into two.  Mixing
hasDefinition() and insert() in one "if" condition would be extremely
confusing as hasDefinition() doesn't change anything while insert()
does.
---
 clang/lib/AST/CXXInheritance.cpp | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/clang/lib/AST/CXXInheritance.cpp b/clang/lib/AST/CXXInheritance.cpp
index 25de2a20a7f3b7..eb265a872c1259 100644
--- a/clang/lib/AST/CXXInheritance.cpp
+++ b/clang/lib/AST/CXXInheritance.cpp
@@ -259,12 +259,10 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 BaseRecord = TD->getTemplatedDecl();
 }
 if (BaseRecord) {
-  if (!BaseRecord->hasDefinition() ||
-  VisitedDependentRecords.count(BaseRecord)) {
+  if (!BaseRecord->hasDefinition())
+BaseRecord = nullptr;
+  else if (!VisitedDependentRecords.insert(BaseRecord).second)
 BaseRecord = nullptr;
-  } else {
-VisitedDependentRecords.insert(BaseRecord);
-  }
 }
   } else {
 BaseRecord = cast(

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


[clang] [AST] Avoid repeated hash lookups (NFC) (PR #111327)

2024-10-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)


Changes

Here I'm splitting up the existing "if" statement into two.  Mixing
hasDefinition() and insert() in one "if" condition would be extremely
confusing as hasDefinition() doesn't change anything while insert()
does.


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


1 Files Affected:

- (modified) clang/lib/AST/CXXInheritance.cpp (+3-5) 


``diff
diff --git a/clang/lib/AST/CXXInheritance.cpp b/clang/lib/AST/CXXInheritance.cpp
index 25de2a20a7f3b7..eb265a872c1259 100644
--- a/clang/lib/AST/CXXInheritance.cpp
+++ b/clang/lib/AST/CXXInheritance.cpp
@@ -259,12 +259,10 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 BaseRecord = TD->getTemplatedDecl();
 }
 if (BaseRecord) {
-  if (!BaseRecord->hasDefinition() ||
-  VisitedDependentRecords.count(BaseRecord)) {
+  if (!BaseRecord->hasDefinition())
+BaseRecord = nullptr;
+  else if (!VisitedDependentRecords.insert(BaseRecord).second)
 BaseRecord = nullptr;
-  } else {
-VisitedDependentRecords.insert(BaseRecord);
-  }
 }
   } else {
 BaseRecord = cast(

``




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


[clang] [clang] Track function template instantiation from definition (PR #110387)

2024-10-06 Thread Matheus Izvekov via cfe-commits

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


[clang] Recommit "[RISCV][FMV] Support target_version" (#111096)" (PR #111333)

2024-10-06 Thread Piyou Chen via cfe-commits

https://github.com/BeMg created https://github.com/llvm/llvm-project/pull/111333

Fix the buildbot failure caused by heap use-after-free error.

Origin message:

This patch enable `target_version` attribute for RISC-V target.

The proposal of `target_version` syntax can be found at the
https://github.com/riscv-non-isa/riscv-c-api-doc/pull/48 (which has
landed), as modified by the proposed
https://github.com/riscv-non-isa/riscv-c-api-doc/pull/85 (which adds the
priority syntax).

`target_version` attribute will trigger the function multi-versioning
feature and act like `target_clones` attribute. See
https://github.com/llvm/llvm-project/pull/85786 for the implementation
of `target_clones`.

>From eb3ef519ec78286b76d911304e1c7c2a32c6945f Mon Sep 17 00:00:00 2001
From: Piyou Chen 
Date: Thu, 3 Oct 2024 21:11:40 -0700
Subject: [PATCH 1/2] Recommit "[RISCV][FMV] Support target_version" (#111096)"

---
 clang/lib/AST/ASTContext.cpp  |  14 +-
 clang/lib/CodeGen/CodeGenModule.cpp   |   7 +-
 clang/lib/Sema/SemaDecl.cpp   |  19 +-
 clang/lib/Sema/SemaDeclAttr.cpp   |  48 ++
 .../attr-target-version-riscv-invalid.c   |  13 +
 .../test/CodeGen/attr-target-version-riscv.c  | 443 ++
 .../CodeGenCXX/attr-target-version-riscv.cpp  | 432 +
 .../SemaCXX/attr-target-version-riscv.cpp | 113 +
 8 files changed, 1081 insertions(+), 8 deletions(-)
 create mode 100644 clang/test/CodeGen/attr-target-version-riscv-invalid.c
 create mode 100644 clang/test/CodeGen/attr-target-version-riscv.c
 create mode 100644 clang/test/CodeGenCXX/attr-target-version-riscv.cpp
 create mode 100644 clang/test/SemaCXX/attr-target-version-riscv.cpp

diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index a81429ad6a2380..034fbbe0bc7829 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -14325,9 +14325,17 @@ void 
ASTContext::getFunctionFeatureMap(llvm::StringMap &FeatureMap,
   Target->initFeatureMap(FeatureMap, getDiagnostics(), TargetCPU, 
Features);
 }
   } else if (const auto *TV = FD->getAttr()) {
-llvm::SmallVector Feats;
-TV->getFeatures(Feats);
-std::vector Features = getFMVBackendFeaturesFor(Feats);
+std::vector Features;
+if (Target->getTriple().isRISCV()) {
+  ParsedTargetAttr ParsedAttr = Target->parseTargetAttr(TV->getName());
+  Features.insert(Features.begin(), ParsedAttr.Features.begin(),
+  ParsedAttr.Features.end());
+} else {
+  assert(Target->getTriple().isAArch64());
+  llvm::SmallVector Feats;
+  TV->getFeatures(Feats);
+  Features = getFMVBackendFeaturesFor(Feats);
+}
 Features.insert(Features.begin(),
 Target->getTargetOpts().FeaturesAsWritten.begin(),
 Target->getTargetOpts().FeaturesAsWritten.end());
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 25c1c496a4f27f..5ba098144a74e7 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4287,8 +4287,13 @@ void CodeGenModule::emitMultiVersionFunctions() {
   } else if (const auto *TVA = CurFD->getAttr()) {
 if (TVA->isDefaultVersion() && IsDefined)
   ShouldEmitResolver = true;
-TVA->getFeatures(Feats);
 llvm::Function *Func = createFunction(CurFD);
+if (getTarget().getTriple().isRISCV()) {
+  Feats.push_back(TVA->getName());
+} else {
+  assert(getTarget().getTriple().isAArch64());
+  TVA->getFeatures(Feats);
+}
 Options.emplace_back(Func, /*Architecture*/ "", Feats);
   } else if (const auto *TC = CurFD->getAttr()) {
 if (IsDefined)
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 2bf610746bc317..21f25a2ea09eb0 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -10329,7 +10329,8 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, 
DeclContext *DC,
   // Handle attributes.
   ProcessDeclAttributes(S, NewFD, D);
   const auto *NewTVA = NewFD->getAttr();
-  if (NewTVA && !NewTVA->isDefaultVersion() &&
+  if (Context.getTargetInfo().getTriple().isAArch64() && NewTVA &&
+  !NewTVA->isDefaultVersion() &&
   !Context.getTargetInfo().hasFeature("fmv")) {
 // Don't add to scope fmv functions declarations if fmv disabled
 AddToScope = false;
@@ -11038,7 +11039,15 @@ static bool CheckMultiVersionValue(Sema &S, const 
FunctionDecl *FD) {
 
   if (TVA) {
 llvm::SmallVector Feats;
-TVA->getFeatures(Feats);
+if (S.getASTContext().getTargetInfo().getTriple().isRISCV()) {
+  ParsedTargetAttr ParseInfo =
+  S.getASTContext().getTargetInfo().parseTargetAttr(TVA->getName());
+  for (auto &Feat : ParseInfo.Features)
+Feats.push_back(StringRef{

[clang] [llvm] [ARM] Emit an error when the hard-float ABI is enabled but can't be used. (PR #111334)

2024-10-06 Thread Chris Copeland via cfe-commits

chrisnc wrote:

clang tests are passing now, but some llvm tests are not, e.g., invocations of 
llc in `CodeGen/ARM/arm-eabi.ll` that specify e.g., `--target=arm-none-eabihf` 
don't include enough features to actually use eabihf. Any suggestions on the 
right place to address this would be appreciated.

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


[clang] [compiler-rt] [lld] [llvm] [Coverage][WebAssembly] Add initial support for WebAssembly/WASI (PR #111332)

2024-10-06 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-backend-webassembly

Author: Yuta Saito (kateinoigakukun)


Changes

Currently, WebAssembly/WASI target does not provide direct support for code 
coverage.
This patch set fixes several issues to unlock the feature. The main changes are:

1. Port `compiler-rt/lib/profile` to WebAssembly/WASI.
2. Adjust profile metadata sections for Wasm object file format.
- [CodeGen] Emit `__llvm_covmap` and `__llvm_covfun` as custom sections 
instead of data segments.
- [lld] Align the interval space of custom sections at link time.
- [llvm-cov] Copy misaligned custom section data if the start address is 
not aligned.
- [llvm-cov] Read `__llvm_prf_names` from data segments
3. [clang] Link with profile runtime libraries if requested

See each commit message for more details and rationale.


---

Patch is 22.72 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/111332.diff


21 Files Affected:

- (modified) clang/lib/Driver/ToolChains/WebAssembly.cpp (+2) 
- (modified) compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake (+1-1) 
- (modified) compiler-rt/cmake/config-ix.cmake (+1-1) 
- (modified) compiler-rt/lib/profile/CMakeLists.txt (+24) 
- (modified) compiler-rt/lib/profile/GCDAProfiling.c (+1-1) 
- (modified) compiler-rt/lib/profile/InstrProfilingPlatformLinux.c (+2-2) 
- (modified) compiler-rt/lib/profile/InstrProfilingPlatformOther.c (+1-1) 
- (modified) compiler-rt/lib/profile/InstrProfilingPort.h (+1-1) 
- (modified) compiler-rt/lib/profile/InstrProfilingUtil.c (+8-4) 
- (added) lld/test/wasm/custom-section-align.s (+31) 
- (modified) lld/wasm/InputChunks.h (+6-4) 
- (modified) lld/wasm/InputFiles.cpp (+16-2) 
- (modified) lld/wasm/OutputSections.cpp (+1) 
- (modified) llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp (+5-1) 
- (modified) llvm/lib/MC/MCContext.cpp (+5) 
- (modified) llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp (+64-9) 
- (modified) llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp (+2-2) 
- (added) llvm/test/CodeGen/WebAssembly/profile.ll (+47) 
- (added) llvm/test/tools/llvm-cov/Inputs/binary-formats.v6.wasm32 () 
- (added) llvm/test/tools/llvm-cov/Inputs/binary-formats.wasm.proftext (+4) 
- (modified) llvm/test/tools/llvm-cov/binary-formats.c (+6) 


``diff
diff --git a/clang/lib/Driver/ToolChains/WebAssembly.cpp 
b/clang/lib/Driver/ToolChains/WebAssembly.cpp
index 9aec11e69fde1d..44a6894d30fb29 100644
--- a/clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ b/clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -163,6 +163,8 @@ void wasm::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 AddRunTimeLibs(ToolChain, ToolChain.getDriver(), CmdArgs, Args);
   }
 
+  ToolChain.addProfileRTLibs(Args, CmdArgs);
+
   CmdArgs.push_back("-o");
   CmdArgs.push_back(Output.getFilename());
 
diff --git a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake 
b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
index 809e9277156912..d00d39518104bf 100644
--- a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
+++ b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
@@ -77,7 +77,7 @@ set(ALL_HWASAN_SUPPORTED_ARCH ${X86_64} ${ARM64} ${RISCV64})
 set(ALL_MEMPROF_SUPPORTED_ARCH ${X86_64})
 set(ALL_PROFILE_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${PPC32} 
${PPC64}
 ${MIPS32} ${MIPS64} ${S390X} ${SPARC} ${SPARCV9} ${HEXAGON}
-${RISCV32} ${RISCV64} ${LOONGARCH64})
+${RISCV32} ${RISCV64} ${LOONGARCH64} ${WASM32})
 set(ALL_CTX_PROFILE_SUPPORTED_ARCH ${X86_64})
 if (OS_NAME MATCHES "FreeBSD")
   set(ALL_TSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64})
diff --git a/compiler-rt/cmake/config-ix.cmake 
b/compiler-rt/cmake/config-ix.cmake
index a93a88a9205001..a494e0532a50bc 100644
--- a/compiler-rt/cmake/config-ix.cmake
+++ b/compiler-rt/cmake/config-ix.cmake
@@ -822,7 +822,7 @@ else()
 endif()
 
 if (PROFILE_SUPPORTED_ARCH AND NOT LLVM_USE_SANITIZER AND
-OS_NAME MATCHES 
"Darwin|Linux|FreeBSD|Windows|Android|Fuchsia|SunOS|NetBSD|AIX")
+OS_NAME MATCHES 
"Darwin|Linux|FreeBSD|Windows|Android|Fuchsia|SunOS|NetBSD|AIX|WASI")
   set(COMPILER_RT_HAS_PROFILE TRUE)
 else()
   set(COMPILER_RT_HAS_PROFILE FALSE)
diff --git a/compiler-rt/lib/profile/CMakeLists.txt 
b/compiler-rt/lib/profile/CMakeLists.txt
index ef23492514898b..a6402f80b890a2 100644
--- a/compiler-rt/lib/profile/CMakeLists.txt
+++ b/compiler-rt/lib/profile/CMakeLists.txt
@@ -38,6 +38,17 @@ int main() {
 
 " COMPILER_RT_TARGET_HAS_FCNTL_LCK)
 
+CHECK_CXX_SOURCE_COMPILES("
+#include 
+
+int fd;
+int main() {
+  flock(fd, LOCK_EX);
+  return 0;
+}
+
+" COMPILER_RT_TARGET_HAS_FLOCK)
+
 CHECK_CXX_SOURCE_COMPILES("
 #include 
 int main() {
@@ -93,6 +104,13 @@ if(FUCHSIA OR UNIX)
  -Wno-pedantic)
 endif()
 
+if(CMAKE_SYSTEM_NAME STREQUAL "WASI")
+  set(EXTRA_FLAGS
+  ${EXTRA_FLAGS}
+  -D_WASI_EMULATED_MMAN
+  -D_WASI_EMULATED_GETPID)
+endif()
+
 if(COMPILER_RT_TARGET_HAS_A

[clang] [flang] [flang][Driver] Add support for -f[no-]wrapv and -f[no]-strict-overflow in the frontend (PR #110061)

2024-10-06 Thread Yusuke MINATO via cfe-commits


@@ -6921,16 +6921,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 
   Args.AddLastArg(CmdArgs, options::OPT_ftrap_function_EQ);
 
-  // -fno-strict-overflow implies -fwrapv if it isn't disabled, but
-  // -fstrict-overflow won't turn off an explicitly enabled -fwrapv.
-  if (Arg *A = Args.getLastArg(options::OPT_fwrapv, options::OPT_fno_wrapv)) {
-if (A->getOption().matches(options::OPT_fwrapv))
-  CmdArgs.push_back("-fwrapv");
-  } else if (Arg *A = Args.getLastArg(options::OPT_fstrict_overflow,
-  options::OPT_fno_strict_overflow)) {
-if (A->getOption().matches(options::OPT_fno_strict_overflow))
-  CmdArgs.push_back("-fwrapv");
-  }
+  // handle -f[no-]wrapv and -f[no-]strict-overflow, which are used by both

yus3710-fj wrote:

Thank you for pointing it out. I fixed it.

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


[clang] [flang] [flang][Driver] Add support for -f[no-]wrapv and -f[no]-strict-overflow in the frontend (PR #110061)

2024-10-06 Thread Yusuke MINATO via cfe-commits


@@ -27,6 +27,14 @@ namespace Fortran::common {
 class LangOptionsBase {
 
 public:
+  enum SignedOverflowBehaviorTy {
+// -fno-wrapv (default behavior in Flang)
+SOB_Undefined,

yus3710-fj wrote:

This is used as the default value of a LangOption `SignedOverflowBehavior`. If 
the behavior is not defined, `nsw` could be added to some operations such as 
`add`.
FWIW, this implementation is simliar to [that of 
Clang](https://github.com/llvm/llvm-project/blob/b672071ba51ef6b64651a62bcfaf78bdfdb7d3d4/clang/include/clang/Basic/LangOptions.h#L87-L96).

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


[clang] [Clang] Remove the special-casing for RequiresExprBodyDecl in BuildResolvedCallExpr() after fd87d765c0 (PR #111277)

2024-10-06 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `lldb-arm-ubuntu` running 
on `linaro-lldb-arm-ubuntu` while building `clang` at step 6 "test".

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


Here is the relevant piece of the build log for the reference

```
Step 6 (test) failure: build (failure)
...
PASS: lldb-api :: lang/cpp/global_variables/TestCPPGlobalVariables.py (788 of 
2809)
PASS: lldb-api :: lang/cpp/global_operators/TestCppGlobalOperators.py (789 of 
2809)
UNSUPPORTED: lldb-api :: 
lang/cpp/gmodules/template-with-same-arg/TestTemplateWithSameArg.py (790 of 
2809)
UNSUPPORTED: lldb-api :: lang/cpp/gmodules/templates/TestGModules.py (791 of 
2809)
PASS: lldb-api :: 
lang/cpp/incompatible-class-templates/TestCppIncompatibleClassTemplates.py (792 
of 2809)
PASS: lldb-api :: lang/cpp/incomplete-stl-types/TestStlIncompleteTypes.py (793 
of 2809)
PASS: lldb-api :: 
lang/cpp/incomplete-types/members/TestCppIncompleteTypeMembers.py (794 of 2809)
PASS: lldb-api :: lang/cpp/keywords_enabled/TestCppKeywordsEnabled.py (795 of 
2809)
PASS: lldb-api :: lang/cpp/incomplete-types/TestCppIncompleteTypes.py (796 of 
2809)
PASS: lldb-api :: lang/cpp/inlines/TestInlines.py (797 of 2809)
FAIL: lldb-api :: 
lang/c/shared_lib_stripped_symbols/TestSharedLibStrippedSymbols.py (798 of 2809)
 TEST 'lldb-api :: 
lang/c/shared_lib_stripped_symbols/TestSharedLibStrippedSymbols.py' FAILED 

Script:
--
/usr/bin/python3.10 
/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/test/API/dotest.py 
-u CXXFLAGS -u CFLAGS --env ARCHIVER=/usr/local/bin/llvm-ar --env 
OBJCOPY=/usr/bin/llvm-objcopy --env 
LLVM_LIBS_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./lib --env 
LLVM_INCLUDE_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/include --env 
LLVM_TOOLS_DIR=/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin --arch 
armv8l --build-dir 
/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex 
--lldb-module-cache-dir 
/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api
 --clang-module-cache-dir 
/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/lldb-test-build.noindex/module-cache-clang/lldb-api
 --executable /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/lldb 
--compiler /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/clang 
--dsymutil /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin/dsymutil 
--llvm-tools-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./bin 
--lldb-obj-root /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/tools/lldb 
--lldb-libs-dir /home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/./lib 
/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/test/API/lang/c/shared_lib_stripped_symbols
 -p TestSharedLibStrippedSymbols.py
--
Exit Code: 1

Command Output (stdout):
--
lldb version 20.0.0git (https://github.com/llvm/llvm-project.git revision 
8c1547055eaf65003f3e6fd024195f4926ff2356)
  clang revision 8c1547055eaf65003f3e6fd024195f4926ff2356
  llvm revision 8c1547055eaf65003f3e6fd024195f4926ff2356
Skipping the following test categories: ['libc++', 'dsym', 'gmodules', 
'debugserver', 'objc']

--
Command Output (stderr):
--
UNSUPPORTED: LLDB 
(/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: 
test_expr_dsym (TestSharedLibStrippedSymbols.SharedLibStrippedTestCase) (test 
case does not fall in any category of interest for this run) 
FAIL: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: 
test_expr_dwarf (TestSharedLibStrippedSymbols.SharedLibStrippedTestCase)
PASS: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: 
test_expr_dwo (TestSharedLibStrippedSymbols.SharedLibStrippedTestCase)
UNSUPPORTED: LLDB 
(/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: 
test_frame_variable_dsym 
(TestSharedLibStrippedSymbols.SharedLibStrippedTestCase) (test case does not 
fall in any category of interest for this run) 
XFAIL: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: 
test_frame_variable_dwarf 
(TestSharedLibStrippedSymbols.SharedLibStrippedTestCase)
XFAIL: LLDB (/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang-arm) :: 
test_frame_variable_dwo (TestSharedLibStrippedSymbols.SharedLibStrippedTestCase)
==
FAIL: test_expr_dwarf (TestSharedLibStrippedSymbols.SharedLibStrippedTestCase)
   Test that types work when defined in a shared library and forwa/d-declared 
in the main executable
--
Traceback (most recent call last):
  File 
"/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/packages/Python/lldbsuite/test/lldbtest.py",
 line 1769, in test_method
return attrvalue(self)
  File 
"/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/test/API/lang/c

[clang] [compiler-rt] [lld] [llvm] [Coverage][WebAssembly] Add initial support for WebAssembly/WASI (PR #111332)

2024-10-06 Thread Yuta Saito via cfe-commits

https://github.com/kateinoigakukun updated 
https://github.com/llvm/llvm-project/pull/111332

>From 605e1ad180c9f75fd59d8b783ae2041cbaf34e50 Mon Sep 17 00:00:00 2001
From: Yuta Saito 
Date: Sat, 5 Oct 2024 16:54:57 +
Subject: [PATCH 1/7] [compiler-rt][profile] Add initial support for
 WebAssembly/WASI

This patch adds initial support for WebAssembly/WASI to the profile
runtime library on the top of wasi-libc. This is a part of the ongoing
patch series to add coverage support for WebAssembly/WASI.

The patch includes the following changes:
* Add wasm32-wasi to the list of supported architectures/OSes.
* Exclude unsupported features for WASI: flock, madvise, uname.
* Enable some user-space emulation provided by wasi-libc: mmap, getpid
---
 .../cmake/Modules/AllSupportedArchDefs.cmake  |  2 +-
 compiler-rt/cmake/config-ix.cmake |  2 +-
 compiler-rt/lib/profile/CMakeLists.txt| 24 +++
 compiler-rt/lib/profile/GCDAProfiling.c   |  2 +-
 compiler-rt/lib/profile/InstrProfilingPort.h  |  2 +-
 compiler-rt/lib/profile/InstrProfilingUtil.c  | 12 ++
 6 files changed, 36 insertions(+), 8 deletions(-)

diff --git a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake 
b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
index 809e9277156912..d00d39518104bf 100644
--- a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
+++ b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
@@ -77,7 +77,7 @@ set(ALL_HWASAN_SUPPORTED_ARCH ${X86_64} ${ARM64} ${RISCV64})
 set(ALL_MEMPROF_SUPPORTED_ARCH ${X86_64})
 set(ALL_PROFILE_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${PPC32} 
${PPC64}
 ${MIPS32} ${MIPS64} ${S390X} ${SPARC} ${SPARCV9} ${HEXAGON}
-${RISCV32} ${RISCV64} ${LOONGARCH64})
+${RISCV32} ${RISCV64} ${LOONGARCH64} ${WASM32})
 set(ALL_CTX_PROFILE_SUPPORTED_ARCH ${X86_64})
 if (OS_NAME MATCHES "FreeBSD")
   set(ALL_TSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64})
diff --git a/compiler-rt/cmake/config-ix.cmake 
b/compiler-rt/cmake/config-ix.cmake
index a93a88a9205001..a494e0532a50bc 100644
--- a/compiler-rt/cmake/config-ix.cmake
+++ b/compiler-rt/cmake/config-ix.cmake
@@ -822,7 +822,7 @@ else()
 endif()
 
 if (PROFILE_SUPPORTED_ARCH AND NOT LLVM_USE_SANITIZER AND
-OS_NAME MATCHES 
"Darwin|Linux|FreeBSD|Windows|Android|Fuchsia|SunOS|NetBSD|AIX")
+OS_NAME MATCHES 
"Darwin|Linux|FreeBSD|Windows|Android|Fuchsia|SunOS|NetBSD|AIX|WASI")
   set(COMPILER_RT_HAS_PROFILE TRUE)
 else()
   set(COMPILER_RT_HAS_PROFILE FALSE)
diff --git a/compiler-rt/lib/profile/CMakeLists.txt 
b/compiler-rt/lib/profile/CMakeLists.txt
index ef23492514898b..a6402f80b890a2 100644
--- a/compiler-rt/lib/profile/CMakeLists.txt
+++ b/compiler-rt/lib/profile/CMakeLists.txt
@@ -38,6 +38,17 @@ int main() {
 
 " COMPILER_RT_TARGET_HAS_FCNTL_LCK)
 
+CHECK_CXX_SOURCE_COMPILES("
+#include 
+
+int fd;
+int main() {
+  flock(fd, LOCK_EX);
+  return 0;
+}
+
+" COMPILER_RT_TARGET_HAS_FLOCK)
+
 CHECK_CXX_SOURCE_COMPILES("
 #include 
 int main() {
@@ -93,6 +104,13 @@ if(FUCHSIA OR UNIX)
  -Wno-pedantic)
 endif()
 
+if(CMAKE_SYSTEM_NAME STREQUAL "WASI")
+  set(EXTRA_FLAGS
+  ${EXTRA_FLAGS}
+  -D_WASI_EMULATED_MMAN
+  -D_WASI_EMULATED_GETPID)
+endif()
+
 if(COMPILER_RT_TARGET_HAS_ATOMICS)
  set(EXTRA_FLAGS
  ${EXTRA_FLAGS}
@@ -105,6 +123,12 @@ if(COMPILER_RT_TARGET_HAS_FCNTL_LCK)
  -DCOMPILER_RT_HAS_FCNTL_LCK=1)
 endif()
 
+if(COMPILER_RT_TARGET_HAS_FLOCK)
+  set(EXTRA_FLAGS
+  ${EXTRA_FLAGS}
+  -DCOMPILER_RT_HAS_FLOCK=1)
+endif()
+
 if(COMPILER_RT_TARGET_HAS_UNAME)
  set(EXTRA_FLAGS
  ${EXTRA_FLAGS}
diff --git a/compiler-rt/lib/profile/GCDAProfiling.c 
b/compiler-rt/lib/profile/GCDAProfiling.c
index d6e2175169e4a5..a207ddf97c8831 100644
--- a/compiler-rt/lib/profile/GCDAProfiling.c
+++ b/compiler-rt/lib/profile/GCDAProfiling.c
@@ -584,7 +584,7 @@ void llvm_reset_counters(void) {
   }
 }
 
-#if !defined(_WIN32)
+#if !defined(_WIN32) && !defined(__wasi__)
 COMPILER_RT_VISIBILITY
 pid_t __gcov_fork() {
   pid_t parent_pid = getpid();
diff --git a/compiler-rt/lib/profile/InstrProfilingPort.h 
b/compiler-rt/lib/profile/InstrProfilingPort.h
index ed0905cc5f2022..8715a3b0d2a6f0 100644
--- a/compiler-rt/lib/profile/InstrProfilingPort.h
+++ b/compiler-rt/lib/profile/InstrProfilingPort.h
@@ -54,7 +54,7 @@
 #endif
 
 #define COMPILER_RT_MAX_HOSTLEN 128
-#ifdef __ORBIS__
+#if defined(__ORBIS__) || defined(__wasi__)
 #define COMPILER_RT_GETHOSTNAME(Name, Len) ((void)(Name), (void)(Len), (-1))
 #else
 #define COMPILER_RT_GETHOSTNAME(Name, Len) lprofGetHostName(Name, Len)
diff --git a/compiler-rt/lib/profile/InstrProfilingUtil.c 
b/compiler-rt/lib/profile/InstrProfilingUtil.c
index 642393d432d7ea..95ec4080ba2504 100644
--- a/compiler-rt/lib/profile/InstrProfilingUtil.c
+++ b/compiler-rt/lib/profile/InstrProfilingUtil.c
@@ -152,9 +152,11 @@ COMPILER_RT_VISIBILITY int lprofLockFd(int fd) {
 }
   }
   return 0;
-#else
+#elif defined(COMPILER_RT_HAS_FLOCK)
   flock(fd, LOCK

[clang] [llvm] [ARM] Emit an error when the hard-float ABI is enabled but can't be used. (PR #111334)

2024-10-06 Thread Chris Copeland via cfe-commits

https://github.com/chrisnc updated 
https://github.com/llvm/llvm-project/pull/111334

>From b73e1b342dbbfae004ad0fa62184c106ab00c12a Mon Sep 17 00:00:00 2001
From: Chris Copeland 
Date: Sun, 6 Oct 2024 20:27:48 -0700
Subject: [PATCH] [ARM] Emit an error when the hard-float ABI is enabled but
 can't be used.

Currently, compiling for eabihf with a CPU lacking floating-point
registers will silently use the soft-float ABI instead, even though the
Arm attributes section still has Tag_ABI_VFP_args: VFP registers, which
leads to silent ABI mismatches at link time.

Fixes #110383.
---
 clang/test/Driver/arm-float-abi-lto.c| 4 ++--
 llvm/lib/Target/ARM/ARMTargetMachine.cpp | 6 +-
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/clang/test/Driver/arm-float-abi-lto.c 
b/clang/test/Driver/arm-float-abi-lto.c
index 83c2435d97a4d2..0a5a6cebf97e45 100644
--- a/clang/test/Driver/arm-float-abi-lto.c
+++ b/clang/test/Driver/arm-float-abi-lto.c
@@ -4,7 +4,7 @@
 
 // RUN: %clang --target=arm-none-eabi -mcpu=cortex-m33 -mfloat-abi=hard -O1 %s 
-flto=full -c -o %t.call_full.bc -DCALL_LIB
 // RUN: %clang --target=arm-none-eabi -mcpu=cortex-m33 -mfloat-abi=hard -O1 %s 
-flto=full -c -o %t.define_full.bc -DDEFINE_LIB
-// RUN: llvm-lto2 run -o %t.lto_full -save-temps %t.call_full.bc 
%t.define_full.bc \
+// RUN: llvm-lto2 run --mcpu=cortex-m33 --float-abi=hard -o %t.lto_full 
-save-temps %t.call_full.bc %t.define_full.bc \
 // RUN:  -r %t.call_full.bc,fn,px \
 // RUN:  -r %t.call_full.bc,fwrite,l \
 // RUN:  -r %t.call_full.bc,putchar,l \
@@ -16,7 +16,7 @@
 
 // RUN: %clang --target=arm-none-eabi -mcpu=cortex-m33 -mfloat-abi=hard -O1 %s 
-flto=thin -c -o %t.call_thin.bc -DCALL_LIB
 // RUN: %clang --target=arm-none-eabi -mcpu=cortex-m33 -mfloat-abi=hard -O1 %s 
-flto=thin -c -o %t.define_thin.bc -DDEFINE_LIB
-// RUN: llvm-lto2 run -o %t.lto_thin -save-temps %t.call_thin.bc 
%t.define_thin.bc \
+// RUN: llvm-lto2 run --mcpu=cortex-m33 --float-abi=hard -o %t.lto_thin 
-save-temps %t.call_thin.bc %t.define_thin.bc \
 // RUN:  -r %t.call_thin.bc,fn,px \
 // RUN:  -r %t.call_thin.bc,fwrite,l \
 // RUN:  -r %t.call_thin.bc,putchar,l \
diff --git a/llvm/lib/Target/ARM/ARMTargetMachine.cpp 
b/llvm/lib/Target/ARM/ARMTargetMachine.cpp
index 7553778c574033..3a6d1b9472fe17 100644
--- a/llvm/lib/Target/ARM/ARMTargetMachine.cpp
+++ b/llvm/lib/Target/ARM/ARMTargetMachine.cpp
@@ -309,11 +309,15 @@ ARMBaseTargetMachine::getSubtargetImpl(const Function &F) 
const {
 // function that reside in TargetOptions.
 resetTargetOptions(F);
 I = std::make_unique(TargetTriple, CPU, FS, *this, isLittle,
-F.hasMinSize());
+   F.hasMinSize());
 
 if (!I->isThumb() && !I->hasARMOps())
   F.getContext().emitError("Function '" + F.getName() + "' uses ARM "
   "instructions, but the target does not support ARM mode execution.");
+
+if (I->isTargetHardFloat() && !I->hasFPRegs())
+  F.getContext().emitError("The hard-float ABI is enabled, but the target "
+   "lacks floating-point registers.");
   }
 
   return I.get();

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


[compiler-rt] [libunwind] [AArch64] Fix nofp regressions in compiler-rt and libunwind (PR #111235)

2024-10-06 Thread David Green via cfe-commits


@@ -633,6 +633,13 @@ Lnovec:
 .arch_extension gcs
 #endif
 
+#if defined(__ARM_FP) && __ARM_FP != 0
+#define LDP(a,b,r,o,p) stp a, b, [r, o]
+#else
+/* In reverse order so that the last LDP(x0,x1,x0) works. */
+#define LDP(a,b,r,o,p) ldr b, [r, p] ; ldr a, [r, o]

davemgreen wrote:

Are you sure this is needed for x register ldp/stp? I believe those should be 
fine with nofp. (There are both fpr and gpr variants of ldp/stp, I assume the 
d-reg versions are the ones not available with no-fp).

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


[clang-tools-extra] [clang-tidy] Only expand macros in modernize-use-std-format/print (PR #97911)

2024-10-06 Thread via cfe-commits


@@ -194,10 +194,20 @@ Changes in existing checks
   ` check to support replacing
   member function calls too.
 
+- Improved :doc:`modernize-use-std-format

EugeneZelenko wrote:

Should be merged with previous entry.

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


[clang-tools-extra] [clang-tidy] Only expand macros in modernize-use-std-format/print (PR #97911)

2024-10-06 Thread Mike Crowe via cfe-commits

https://github.com/mikecrowe updated 
https://github.com/llvm/llvm-project/pull/97911

>From 2dd0902d5f79a2b18f53649169bd011ccfbfb46b Mon Sep 17 00:00:00 2001
From: Mike Crowe 
Date: Wed, 12 Jun 2024 21:06:26 +0100
Subject: [PATCH 1/2] [clang-tidy] Only expand  macros in
 modernize-use-std-format/print

Expanding all macros in the printf/absl::StrFormat format string before
conversion could easily break code if those macros are expended to
change their definition between builds. It's important for this check to
expand the  PRI macros though, so let's ensure that the
presence of any other macros in the format string causes the check to
emit a warning and not perform any conversion.
---
 .../modernize/UseStdFormatCheck.cpp   |  7 +-
 .../clang-tidy/modernize/UseStdFormatCheck.h  |  1 +
 .../clang-tidy/modernize/UseStdPrintCheck.cpp |  4 +-
 .../clang-tidy/modernize/UseStdPrintCheck.h   |  1 +
 .../utils/FormatStringConverter.cpp   | 65 +--
 .../clang-tidy/utils/FormatStringConverter.h  |  7 +-
 clang-tools-extra/docs/ReleaseNotes.rst   | 10 +++
 .../checks/modernize/use-std-format.rst   |  3 +-
 .../checks/modernize/use-std-print.rst| 22 +++---
 .../checkers/Inputs/Headers/inttypes.h| 26 +++---
 .../checkers/modernize/use-std-format.cpp | 79 ---
 .../checkers/modernize/use-std-print.cpp  | 73 -
 12 files changed, 257 insertions(+), 41 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp
index cdb34aef1b0e61..f97b844c564961 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp
@@ -44,6 +44,7 @@ void UseStdFormatCheck::registerPPCallbacks(const 
SourceManager &SM,
 Preprocessor *PP,
 Preprocessor *ModuleExpanderPP) {
   IncludeInserter.registerPreprocessor(PP);
+  this->PP = PP;
 }
 
 void UseStdFormatCheck::registerMatchers(MatchFinder *Finder) {
@@ -75,9 +76,9 @@ void UseStdFormatCheck::check(const MatchFinder::MatchResult 
&Result) {
 
   utils::FormatStringConverter::Configuration ConverterConfig;
   ConverterConfig.StrictMode = StrictMode;
-  utils::FormatStringConverter Converter(Result.Context, StrFormat,
- FormatArgOffset, ConverterConfig,
- getLangOpts());
+  utils::FormatStringConverter Converter(
+  Result.Context, StrFormat, FormatArgOffset, ConverterConfig,
+  getLangOpts(), *Result.SourceManager, *PP);
   const Expr *StrFormatCall = StrFormat->getCallee();
   if (!Converter.canApply()) {
 diag(StrFormat->getBeginLoc(),
diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.h 
b/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.h
index b59a4708c6e4bc..9ac2240212ebf6 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.h
@@ -44,6 +44,7 @@ class UseStdFormatCheck : public ClangTidyCheck {
   StringRef ReplacementFormatFunction;
   utils::IncludeInserter IncludeInserter;
   std::optional MaybeHeaderToInclude;
+  Preprocessor *PP = nullptr;
 };
 
 } // namespace clang::tidy::modernize
diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
index 16f2f4b3e7d1af..9161c0e702a28c 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
@@ -68,6 +68,7 @@ void UseStdPrintCheck::registerPPCallbacks(const 
SourceManager &SM,
Preprocessor *PP,
Preprocessor *ModuleExpanderPP) {
   IncludeInserter.registerPreprocessor(PP);
+  this->PP = PP;
 }
 
 static clang::ast_matchers::StatementMatcher
@@ -131,7 +132,8 @@ void UseStdPrintCheck::check(const MatchFinder::MatchResult 
&Result) {
   ConverterConfig.StrictMode = StrictMode;
   ConverterConfig.AllowTrailingNewlineRemoval = true;
   utils::FormatStringConverter Converter(
-  Result.Context, Printf, FormatArgOffset, ConverterConfig, getLangOpts());
+  Result.Context, Printf, FormatArgOffset, ConverterConfig, getLangOpts(),
+  *Result.SourceManager, *PP);
   const Expr *PrintfCall = Printf->getCallee();
   const StringRef ReplacementFunction = Converter.usePrintNewlineFunction()
 ? ReplacementPrintlnFunction
diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.h 
b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.h
index 7a06cf38b4264f..995c740389e73b 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.h
@@ -36,

[clang] [clang-tools-extra] RFC: [clang-tidy] [analyzer] Nondeterministic pointer usage improvements (PR #110471)

2024-10-06 Thread via cfe-commits

https://github.com/vabridgers updated 
https://github.com/llvm/llvm-project/pull/110471

>From 4d8d1057c3f4a423ef0fe15bf58278d9967c8128 Mon Sep 17 00:00:00 2001
From: einvbri 
Date: Thu, 26 Sep 2024 16:24:59 +0200
Subject: [PATCH] [clang-tidy] [analyzer] Move nondeterministic pointer usage
 check to tidy

This change moves the alpha.nondeterministic.PointerSorting and
alpha.nondeterministic.PointerIteration static analyzer checkers to
a single clang-tidy check. Those checkers were implemented as clang-tidy
checks wrapped in the static analyzer framework. The documentation was
updated to describe what the checks can and cannot do, and testing
was completed on a broad set of open source projects.
---
 .../bugprone/BugproneTidyModule.cpp   |   3 +
 .../clang-tidy/bugprone/CMakeLists.txt|   1 +
 .../NondeterministicPointerUsageCheck.cpp |  67 
 .../NondeterministicPointerUsageCheck.h   |  34 
 clang-tools-extra/docs/ReleaseNotes.rst   |   7 +
 ...ndeterministic-pointer-iteration-order.rst |  35 
 .../system-header-simulator/sim_algorithm |  31 
 .../system-header-simulator/sim_c++config.h   |  11 ++
 .../sim_initializer_list  |  39 +
 .../system-header-simulator/sim_iterator_base |  22 +++
 .../Inputs/system-header-simulator/sim_map|  35 
 .../Inputs/system-header-simulator/sim_set|  45 ++
 .../system-header-simulator/sim_stl_pair  |  33 
 .../system-header-simulator/sim_type_traits   |  19 +++
 .../system-header-simulator/sim_unordered_map |  35 
 .../system-header-simulator/sim_unordered_set |  36 +
 .../Inputs/system-header-simulator/sim_vector | 150 ++
 .../nondeterministic-pointer-usage.cpp|  83 ++
 clang/docs/ReleaseNotes.rst   |   6 +
 clang/docs/analyzer/checkers.rst  |  31 
 .../clang/StaticAnalyzer/Checkers/Checkers.td |  18 ---
 .../StaticAnalyzer/Checkers/CMakeLists.txt|   2 -
 .../Checkers/PointerIterationChecker.cpp  | 101 
 .../Checkers/PointerSortingChecker.cpp| 115 --
 clang/test/Analysis/ptr-iter.cpp  |  28 
 clang/test/Analysis/ptr-sort.cpp  |  36 -
 26 files changed, 692 insertions(+), 331 deletions(-)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/NondeterministicPointerUsageCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/NondeterministicPointerUsageCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/nondeterministic-pointer-iteration-order.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/system-header-simulator/sim_algorithm
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/system-header-simulator/sim_c++config.h
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/system-header-simulator/sim_initializer_list
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/system-header-simulator/sim_iterator_base
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/system-header-simulator/sim_map
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/system-header-simulator/sim_set
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/system-header-simulator/sim_stl_pair
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/system-header-simulator/sim_type_traits
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/system-header-simulator/sim_unordered_map
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/system-header-simulator/sim_unordered_set
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/system-header-simulator/sim_vector
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/nondeterministic-pointer-usage.cpp
 delete mode 100644 
clang/lib/StaticAnalyzer/Checkers/PointerIterationChecker.cpp
 delete mode 100644 clang/lib/StaticAnalyzer/Checkers/PointerSortingChecker.cpp
 delete mode 100644 clang/test/Analysis/ptr-iter.cpp
 delete mode 100644 clang/test/Analysis/ptr-sort.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 9120c4b6c0d9ae..48f8ece42ec256 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -48,6 +48,7 @@
 #include "MultipleNewInOneExpressionCheck.h"
 #include "MultipleStatementMacroCheck.h"
 #include "NoEscapeCheck.h"
+#include "NondeterministicPointerUsageCheck.h"
 #include "NonZeroEnumToBoolConversionCheck.h"
 #include "NotNullTerminatedResultCheck.h"
 #include "OptionalValueConversionCheck.h"
@@ -174,6 +175,8 @@ class BugproneModule : public ClangTidyModule {
 "

[clang] [clang-tools-extra] RFC: [clang-tidy] [analyzer] Nondeterministic pointer usage improvements (PR #110471)

2024-10-06 Thread via cfe-commits


@@ -121,6 +121,13 @@ New checks
   Gives warnings for tagged unions, where the number of tags is
   different from the number of data members inside the union.
 
+- New :doc:`bugprone-nondeterministic-pointer-iteration-order
+  `
+  check.
+
+  Detect certain nondeterministic pointer seen with unordered

EugeneZelenko wrote:

Please synchronize with first statement in documentation.

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


[clang] [clang-tools-extra] RFC: [clang-tidy] [analyzer] Nondeterministic pointer usage improvements (PR #110471)

2024-10-06 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 fb0ef6b66e3c7e91481568c15ed67c047dab84e1 
4d8d1057c3f4a423ef0fe15bf58278d9967c8128 --extensions h,cpp -- 
clang-tools-extra/clang-tidy/bugprone/NondeterministicPointerUsageCheck.cpp 
clang-tools-extra/clang-tidy/bugprone/NondeterministicPointerUsageCheck.h 
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/system-header-simulator/sim_c++config.h
 
clang-tools-extra/test/clang-tidy/checkers/bugprone/nondeterministic-pointer-usage.cpp
 clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 48f8ece42e..597ea3e7e9 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -48,8 +48,8 @@
 #include "MultipleNewInOneExpressionCheck.h"
 #include "MultipleStatementMacroCheck.h"
 #include "NoEscapeCheck.h"
-#include "NondeterministicPointerUsageCheck.h"
 #include "NonZeroEnumToBoolConversionCheck.h"
+#include "NondeterministicPointerUsageCheck.h"
 #include "NotNullTerminatedResultCheck.h"
 #include "OptionalValueConversionCheck.h"
 #include "ParentVirtualCallCheck.h"

``




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


[clang] [clang-tools-extra] RFC: [clang-tidy] [analyzer] Nondeterministic pointer usage improvements (PR #110471)

2024-10-06 Thread via cfe-commits


@@ -121,6 +121,13 @@ New checks
   Gives warnings for tagged unions, where the number of tags is
   different from the number of data members inside the union.
 
+- New :doc:`bugprone-nondeterministic-pointer-iteration-order
+  `
+  check.
+
+  Detect certain nondeterministic pointer seen with unordered

vabridgers wrote:

I'll address, thank you

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


[clang] [clang-tools-extra] RFC: [clang-tidy] [analyzer] Nondeterministic pointer usage improvements (PR #110471)

2024-10-06 Thread via cfe-commits

vabridgers wrote:

Hi all, I believe all comments have been addressed. Thanks.

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


[clang] [clang-tools-extra] RFC: [clang-tidy] [analyzer] Nondeterministic pointer usage improvements (PR #110471)

2024-10-06 Thread via cfe-commits

https://github.com/vabridgers updated 
https://github.com/llvm/llvm-project/pull/110471

>From 3ab034755e5876ba9c2d6a0de7450783851140d6 Mon Sep 17 00:00:00 2001
From: einvbri 
Date: Thu, 26 Sep 2024 16:24:59 +0200
Subject: [PATCH] [clang-tidy] [analyzer] Move nondeterministic pointer usage
 check to tidy

This change moves the alpha.nondeterministic.PointerSorting and
alpha.nondeterministic.PointerIteration static analyzer checkers to
a single clang-tidy check. Those checkers were implemented as clang-tidy
checks wrapped in the static analyzer framework. The documentation was
updated to describe what the checks can and cannot do, and testing
was completed on a broad set of open source projects.
---
 .../bugprone/BugproneTidyModule.cpp   |   3 +
 .../clang-tidy/bugprone/CMakeLists.txt|   1 +
 .../NondeterministicPointerUsageCheck.cpp |  67 
 .../NondeterministicPointerUsageCheck.h   |  34 
 clang-tools-extra/docs/ReleaseNotes.rst   |   6 +
 ...ndeterministic-pointer-iteration-order.rst |  35 
 .../system-header-simulator/sim_algorithm |  31 
 .../system-header-simulator/sim_c++config.h   |  11 ++
 .../sim_initializer_list  |  39 +
 .../system-header-simulator/sim_iterator_base |  22 +++
 .../Inputs/system-header-simulator/sim_map|  35 
 .../Inputs/system-header-simulator/sim_set|  45 ++
 .../system-header-simulator/sim_stl_pair  |  33 
 .../system-header-simulator/sim_type_traits   |  19 +++
 .../system-header-simulator/sim_unordered_map |  35 
 .../system-header-simulator/sim_unordered_set |  36 +
 .../Inputs/system-header-simulator/sim_vector | 150 ++
 .../nondeterministic-pointer-usage.cpp|  83 ++
 clang/docs/ReleaseNotes.rst   |   6 +
 clang/docs/analyzer/checkers.rst  |  31 
 .../clang/StaticAnalyzer/Checkers/Checkers.td |  18 ---
 .../StaticAnalyzer/Checkers/CMakeLists.txt|   2 -
 .../Checkers/PointerIterationChecker.cpp  | 101 
 .../Checkers/PointerSortingChecker.cpp| 115 --
 clang/test/Analysis/ptr-iter.cpp  |  28 
 clang/test/Analysis/ptr-sort.cpp  |  36 -
 26 files changed, 691 insertions(+), 331 deletions(-)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/NondeterministicPointerUsageCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/NondeterministicPointerUsageCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/nondeterministic-pointer-iteration-order.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/system-header-simulator/sim_algorithm
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/system-header-simulator/sim_c++config.h
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/system-header-simulator/sim_initializer_list
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/system-header-simulator/sim_iterator_base
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/system-header-simulator/sim_map
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/system-header-simulator/sim_set
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/system-header-simulator/sim_stl_pair
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/system-header-simulator/sim_type_traits
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/system-header-simulator/sim_unordered_map
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/system-header-simulator/sim_unordered_set
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/system-header-simulator/sim_vector
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/nondeterministic-pointer-usage.cpp
 delete mode 100644 
clang/lib/StaticAnalyzer/Checkers/PointerIterationChecker.cpp
 delete mode 100644 clang/lib/StaticAnalyzer/Checkers/PointerSortingChecker.cpp
 delete mode 100644 clang/test/Analysis/ptr-iter.cpp
 delete mode 100644 clang/test/Analysis/ptr-sort.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 9120c4b6c0d9ae..597ea3e7e9c962 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -49,6 +49,7 @@
 #include "MultipleStatementMacroCheck.h"
 #include "NoEscapeCheck.h"
 #include "NonZeroEnumToBoolConversionCheck.h"
+#include "NondeterministicPointerUsageCheck.h"
 #include "NotNullTerminatedResultCheck.h"
 #include "OptionalValueConversionCheck.h"
 #include "ParentVirtualCallCheck.h"
@@ -174,6 +175,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-

[clang] [llvm] [LLVM] [Clang] Support for Gentoo `*t64` triples (64-bit time_t ABIs) (PR #111302)

2024-10-06 Thread Fangrui Song via cfe-commits
=?utf-8?q?Micha=C5=82_G=C3=B3rny?= 
Message-ID:
In-Reply-To: 



@@ -610,7 +610,8 @@ static llvm::Triple computeTargetTriple(const Driver &D,
 if (A->getOption().matches(options::OPT_m64) ||
 A->getOption().matches(options::OPT_maix64)) {
   AT = Target.get64BitArchVariant().getArch();
-  if (Target.getEnvironment() == llvm::Triple::GNUX32)
+  if (Target.getEnvironment() == llvm::Triple::GNUX32 ||

MaskRay wrote:

Optional: you could simplify the pattern  with `llvm::is_contained({...}, X)`

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


[clang] [llvm] [LLVM] [Clang] Support for Gentoo `*t64` triples (64-bit time_t ABIs) (PR #111302)

2024-10-06 Thread Fangrui Song via cfe-commits
=?utf-8?q?Michał_Górny?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -E -dM -triple=i686-pc-linux-gnu < /dev/null | FileCheck 
-match-full-lines -check-prefix TIME32 %s

MaskRay wrote:

You can omit `< `

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


[clang] [llvm] [LLVM] [Clang] Support for Gentoo `*t64` triples (64-bit time_t ABIs) (PR #111302)

2024-10-06 Thread Fangrui Song via cfe-commits
=?utf-8?q?Micha=C5=82_G=C3=B3rny?= 
Message-ID:
In-Reply-To: 


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


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


[clang] [llvm] [LLVM] [Clang] Support for Gentoo `*t64` triples (64-bit time_t ABIs) (PR #111302)

2024-10-06 Thread via cfe-commits
=?utf-8?q?Michał_Górny?= 
Message-ID:
In-Reply-To: 


llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Michał Górny (mgorny)


Changes

Gentoo is planning to introduce a `*t64` suffix for triples that will be used 
by 32-bit platforms that use 64-bit `time_t`. Add support for parsing and 
accepting these triples, and while at it make clang automatically enable the 
necessary glibc feature macros when this suffix is used.

An open question is whether we can backport this to LLVM 19.x. After all, 
adding new triplets to Triple sounds like an ABI change — though I suppose we 
can minimize the risk of breaking something if we move new enum values to the 
very end.

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


16 Files Affected:

- (modified) clang/lib/Basic/Targets/ARM.cpp (+2) 
- (modified) clang/lib/Basic/Targets/OSTargets.h (+4) 
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+1) 
- (modified) clang/lib/CodeGen/Targets/ARM.cpp (+3) 
- (modified) clang/lib/Driver/Driver.cpp (+4-1) 
- (modified) clang/lib/Driver/ToolChains/Arch/ARM.cpp (+7) 
- (modified) clang/lib/Driver/ToolChains/Gnu.cpp (+2) 
- (modified) clang/lib/Driver/ToolChains/Linux.cpp (+1) 
- (added) clang/test/Preprocessor/time64.c (+12) 
- (modified) llvm/include/llvm/TargetParser/Triple.h (+18-5) 
- (modified) llvm/lib/Target/ARM/ARMSubtarget.h (+3-1) 
- (modified) llvm/lib/Target/ARM/ARMTargetMachine.cpp (+2) 
- (modified) llvm/lib/Target/ARM/ARMTargetMachine.h (+1) 
- (modified) llvm/lib/TargetParser/ARMTargetParser.cpp (+3) 
- (modified) llvm/lib/TargetParser/Triple.cpp (+6) 
- (modified) llvm/unittests/TargetParser/TripleTest.cpp (+22) 


``diff
diff --git a/clang/lib/Basic/Targets/ARM.cpp b/clang/lib/Basic/Targets/ARM.cpp
index c56b8d9a448508..c87300bf2d60e0 100644
--- a/clang/lib/Basic/Targets/ARM.cpp
+++ b/clang/lib/Basic/Targets/ARM.cpp
@@ -313,7 +313,9 @@ ARMTargetInfo::ARMTargetInfo(const llvm::Triple &Triple,
 switch (Triple.getEnvironment()) {
 case llvm::Triple::Android:
 case llvm::Triple::GNUEABI:
+case llvm::Triple::GNUEABIT64:
 case llvm::Triple::GNUEABIHF:
+case llvm::Triple::GNUEABIHFT64:
 case llvm::Triple::MuslEABI:
 case llvm::Triple::MuslEABIHF:
 case llvm::Triple::OpenHOS:
diff --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index a83d6464e789d6..75f53e96ce28f6 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -337,6 +337,10 @@ class LLVM_LIBRARY_VISIBILITY LinuxTargetInfo : public 
OSTargetInfo {
   Builder.defineMacro("_GNU_SOURCE");
 if (this->HasFloat128)
   Builder.defineMacro("__FLOAT128__");
+if (Triple.isTime64ABI()) {
+  Builder.defineMacro("_FILE_OFFSET_BITS", "64");
+  Builder.defineMacro("_TIME_BITS", "64");
+}
   }
 
 public:
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 25c1c496a4f27f..9b37e5b07126d8 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -177,6 +177,7 @@ createTargetCodeGenInfo(CodeGenModule &CGM) {
 else if (CodeGenOpts.FloatABI == "hard" ||
  (CodeGenOpts.FloatABI != "soft" &&
   (Triple.getEnvironment() == llvm::Triple::GNUEABIHF ||
+   Triple.getEnvironment() == llvm::Triple::GNUEABIHFT64 ||
Triple.getEnvironment() == llvm::Triple::MuslEABIHF ||
Triple.getEnvironment() == llvm::Triple::EABIHF)))
   Kind = ARMABIKind::AAPCS_VFP;
diff --git a/clang/lib/CodeGen/Targets/ARM.cpp 
b/clang/lib/CodeGen/Targets/ARM.cpp
index f7d7471d386b21..49ac1a76e767aa 100644
--- a/clang/lib/CodeGen/Targets/ARM.cpp
+++ b/clang/lib/CodeGen/Targets/ARM.cpp
@@ -35,7 +35,9 @@ class ARMABIInfo : public ABIInfo {
 case llvm::Triple::EABI:
 case llvm::Triple::EABIHF:
 case llvm::Triple::GNUEABI:
+case llvm::Triple::GNUEABIT64:
 case llvm::Triple::GNUEABIHF:
+case llvm::Triple::GNUEABIHFT64:
 case llvm::Triple::MuslEABI:
 case llvm::Triple::MuslEABIHF:
   return true;
@@ -48,6 +50,7 @@ class ARMABIInfo : public ABIInfo {
 switch (getTarget().getTriple().getEnvironment()) {
 case llvm::Triple::EABIHF:
 case llvm::Triple::GNUEABIHF:
+case llvm::Triple::GNUEABIHFT64:
 case llvm::Triple::MuslEABIHF:
   return true;
 default:
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index e9bf60d5e2ee46..cfcdb5c22e8072 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -610,7 +610,8 @@ static llvm::Triple computeTargetTriple(const Driver &D,
 if (A->getOption().matches(options::OPT_m64) ||
 A->getOption().matches(options::OPT_maix64)) {
   AT = Target.get64BitArchVariant().getArch();
-  if (Target.getEnvironment() == llvm::Triple::GNUX32)
+  if (Target.getEnvironment() == llvm::Triple::GNUX32 ||
+  Target.getEnvironment() == llvm::Triple::G

[clang] [llvm] [LLVM] [Clang] Support for Gentoo `*t64` triples (64-bit time_t ABIs) (PR #111302)

2024-10-06 Thread Michał Górny via cfe-commits

https://github.com/mgorny created 
https://github.com/llvm/llvm-project/pull/111302

Gentoo is planning to introduce a `*t64` suffix for triples that will be used 
by 32-bit platforms that use 64-bit `time_t`. Add support for parsing and 
accepting these triples, and while at it make clang automatically enable the 
necessary glibc feature macros when this suffix is used.

An open question is whether we can backport this to LLVM 19.x. After all, 
adding new triplets to Triple sounds like an ABI change — though I suppose we 
can minimize the risk of breaking something if we move new enum values to the 
very end.

From df75eaa8e0f399a43bde9e60af326f0c91aa7ad4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= 
Date: Sat, 5 Oct 2024 18:31:35 +0200
Subject: [PATCH 1/2] [llvm] [Triple] Support *t64 environments for Gentoo

Add a support for the new `*t64` triples that Gentoo is planning to use
for its 32-bit platforms migrated to use 64-bit time_t.  Given
the supported 32-bit targets, the expected environments are `-gnut64`,
`-gnueabit64` and `-gnueabihft64`.
---
 clang/lib/Basic/Targets/ARM.cpp|  2 ++
 clang/lib/CodeGen/CodeGenModule.cpp|  1 +
 clang/lib/CodeGen/Targets/ARM.cpp  |  3 +++
 clang/lib/Driver/Driver.cpp|  5 -
 clang/lib/Driver/ToolChains/Arch/ARM.cpp   |  7 +++
 clang/lib/Driver/ToolChains/Gnu.cpp|  2 ++
 clang/lib/Driver/ToolChains/Linux.cpp  |  1 +
 llvm/include/llvm/TargetParser/Triple.h| 23 +-
 llvm/lib/Target/ARM/ARMSubtarget.h |  4 +++-
 llvm/lib/Target/ARM/ARMTargetMachine.cpp   |  2 ++
 llvm/lib/Target/ARM/ARMTargetMachine.h |  1 +
 llvm/lib/TargetParser/ARMTargetParser.cpp  |  3 +++
 llvm/lib/TargetParser/Triple.cpp   |  6 ++
 llvm/unittests/TargetParser/TripleTest.cpp | 22 +
 14 files changed, 75 insertions(+), 7 deletions(-)

diff --git a/clang/lib/Basic/Targets/ARM.cpp b/clang/lib/Basic/Targets/ARM.cpp
index c56b8d9a448508..c87300bf2d60e0 100644
--- a/clang/lib/Basic/Targets/ARM.cpp
+++ b/clang/lib/Basic/Targets/ARM.cpp
@@ -313,7 +313,9 @@ ARMTargetInfo::ARMTargetInfo(const llvm::Triple &Triple,
 switch (Triple.getEnvironment()) {
 case llvm::Triple::Android:
 case llvm::Triple::GNUEABI:
+case llvm::Triple::GNUEABIT64:
 case llvm::Triple::GNUEABIHF:
+case llvm::Triple::GNUEABIHFT64:
 case llvm::Triple::MuslEABI:
 case llvm::Triple::MuslEABIHF:
 case llvm::Triple::OpenHOS:
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 25c1c496a4f27f..9b37e5b07126d8 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -177,6 +177,7 @@ createTargetCodeGenInfo(CodeGenModule &CGM) {
 else if (CodeGenOpts.FloatABI == "hard" ||
  (CodeGenOpts.FloatABI != "soft" &&
   (Triple.getEnvironment() == llvm::Triple::GNUEABIHF ||
+   Triple.getEnvironment() == llvm::Triple::GNUEABIHFT64 ||
Triple.getEnvironment() == llvm::Triple::MuslEABIHF ||
Triple.getEnvironment() == llvm::Triple::EABIHF)))
   Kind = ARMABIKind::AAPCS_VFP;
diff --git a/clang/lib/CodeGen/Targets/ARM.cpp 
b/clang/lib/CodeGen/Targets/ARM.cpp
index f7d7471d386b21..49ac1a76e767aa 100644
--- a/clang/lib/CodeGen/Targets/ARM.cpp
+++ b/clang/lib/CodeGen/Targets/ARM.cpp
@@ -35,7 +35,9 @@ class ARMABIInfo : public ABIInfo {
 case llvm::Triple::EABI:
 case llvm::Triple::EABIHF:
 case llvm::Triple::GNUEABI:
+case llvm::Triple::GNUEABIT64:
 case llvm::Triple::GNUEABIHF:
+case llvm::Triple::GNUEABIHFT64:
 case llvm::Triple::MuslEABI:
 case llvm::Triple::MuslEABIHF:
   return true;
@@ -48,6 +50,7 @@ class ARMABIInfo : public ABIInfo {
 switch (getTarget().getTriple().getEnvironment()) {
 case llvm::Triple::EABIHF:
 case llvm::Triple::GNUEABIHF:
+case llvm::Triple::GNUEABIHFT64:
 case llvm::Triple::MuslEABIHF:
   return true;
 default:
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index e9bf60d5e2ee46..cfcdb5c22e8072 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -610,7 +610,8 @@ static llvm::Triple computeTargetTriple(const Driver &D,
 if (A->getOption().matches(options::OPT_m64) ||
 A->getOption().matches(options::OPT_maix64)) {
   AT = Target.get64BitArchVariant().getArch();
-  if (Target.getEnvironment() == llvm::Triple::GNUX32)
+  if (Target.getEnvironment() == llvm::Triple::GNUX32 ||
+  Target.getEnvironment() == llvm::Triple::GNUT64)
 Target.setEnvironment(llvm::Triple::GNU);
   else if (Target.getEnvironment() == llvm::Triple::MuslX32)
 Target.setEnvironment(llvm::Triple::Musl);
@@ -673,6 +674,7 @@ static llvm::Triple computeTargetTriple(const Driver &D,
   } else if (ABIName == "n32") {
 Target = Target.get64BitArchVariant();
  

[clang] [llvm] [LLVM] [Clang] Support for Gentoo `*t64` triples (64-bit time_t ABIs) (PR #111302)

2024-10-06 Thread via cfe-commits
=?utf-8?q?Michał_Górny?= 
Message-ID:
In-Reply-To: 


llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Michał Górny (mgorny)


Changes

Gentoo is planning to introduce a `*t64` suffix for triples that will be used 
by 32-bit platforms that use 64-bit `time_t`. Add support for parsing and 
accepting these triples, and while at it make clang automatically enable the 
necessary glibc feature macros when this suffix is used.

An open question is whether we can backport this to LLVM 19.x. After all, 
adding new triplets to Triple sounds like an ABI change — though I suppose we 
can minimize the risk of breaking something if we move new enum values to the 
very end.

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


16 Files Affected:

- (modified) clang/lib/Basic/Targets/ARM.cpp (+2) 
- (modified) clang/lib/Basic/Targets/OSTargets.h (+4) 
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+1) 
- (modified) clang/lib/CodeGen/Targets/ARM.cpp (+3) 
- (modified) clang/lib/Driver/Driver.cpp (+4-1) 
- (modified) clang/lib/Driver/ToolChains/Arch/ARM.cpp (+7) 
- (modified) clang/lib/Driver/ToolChains/Gnu.cpp (+2) 
- (modified) clang/lib/Driver/ToolChains/Linux.cpp (+1) 
- (added) clang/test/Preprocessor/time64.c (+12) 
- (modified) llvm/include/llvm/TargetParser/Triple.h (+18-5) 
- (modified) llvm/lib/Target/ARM/ARMSubtarget.h (+3-1) 
- (modified) llvm/lib/Target/ARM/ARMTargetMachine.cpp (+2) 
- (modified) llvm/lib/Target/ARM/ARMTargetMachine.h (+1) 
- (modified) llvm/lib/TargetParser/ARMTargetParser.cpp (+3) 
- (modified) llvm/lib/TargetParser/Triple.cpp (+6) 
- (modified) llvm/unittests/TargetParser/TripleTest.cpp (+22) 


``diff
diff --git a/clang/lib/Basic/Targets/ARM.cpp b/clang/lib/Basic/Targets/ARM.cpp
index c56b8d9a448508..c87300bf2d60e0 100644
--- a/clang/lib/Basic/Targets/ARM.cpp
+++ b/clang/lib/Basic/Targets/ARM.cpp
@@ -313,7 +313,9 @@ ARMTargetInfo::ARMTargetInfo(const llvm::Triple &Triple,
 switch (Triple.getEnvironment()) {
 case llvm::Triple::Android:
 case llvm::Triple::GNUEABI:
+case llvm::Triple::GNUEABIT64:
 case llvm::Triple::GNUEABIHF:
+case llvm::Triple::GNUEABIHFT64:
 case llvm::Triple::MuslEABI:
 case llvm::Triple::MuslEABIHF:
 case llvm::Triple::OpenHOS:
diff --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index a83d6464e789d6..75f53e96ce28f6 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -337,6 +337,10 @@ class LLVM_LIBRARY_VISIBILITY LinuxTargetInfo : public 
OSTargetInfo {
   Builder.defineMacro("_GNU_SOURCE");
 if (this->HasFloat128)
   Builder.defineMacro("__FLOAT128__");
+if (Triple.isTime64ABI()) {
+  Builder.defineMacro("_FILE_OFFSET_BITS", "64");
+  Builder.defineMacro("_TIME_BITS", "64");
+}
   }
 
 public:
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 25c1c496a4f27f..9b37e5b07126d8 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -177,6 +177,7 @@ createTargetCodeGenInfo(CodeGenModule &CGM) {
 else if (CodeGenOpts.FloatABI == "hard" ||
  (CodeGenOpts.FloatABI != "soft" &&
   (Triple.getEnvironment() == llvm::Triple::GNUEABIHF ||
+   Triple.getEnvironment() == llvm::Triple::GNUEABIHFT64 ||
Triple.getEnvironment() == llvm::Triple::MuslEABIHF ||
Triple.getEnvironment() == llvm::Triple::EABIHF)))
   Kind = ARMABIKind::AAPCS_VFP;
diff --git a/clang/lib/CodeGen/Targets/ARM.cpp 
b/clang/lib/CodeGen/Targets/ARM.cpp
index f7d7471d386b21..49ac1a76e767aa 100644
--- a/clang/lib/CodeGen/Targets/ARM.cpp
+++ b/clang/lib/CodeGen/Targets/ARM.cpp
@@ -35,7 +35,9 @@ class ARMABIInfo : public ABIInfo {
 case llvm::Triple::EABI:
 case llvm::Triple::EABIHF:
 case llvm::Triple::GNUEABI:
+case llvm::Triple::GNUEABIT64:
 case llvm::Triple::GNUEABIHF:
+case llvm::Triple::GNUEABIHFT64:
 case llvm::Triple::MuslEABI:
 case llvm::Triple::MuslEABIHF:
   return true;
@@ -48,6 +50,7 @@ class ARMABIInfo : public ABIInfo {
 switch (getTarget().getTriple().getEnvironment()) {
 case llvm::Triple::EABIHF:
 case llvm::Triple::GNUEABIHF:
+case llvm::Triple::GNUEABIHFT64:
 case llvm::Triple::MuslEABIHF:
   return true;
 default:
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index e9bf60d5e2ee46..cfcdb5c22e8072 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -610,7 +610,8 @@ static llvm::Triple computeTargetTriple(const Driver &D,
 if (A->getOption().matches(options::OPT_m64) ||
 A->getOption().matches(options::OPT_maix64)) {
   AT = Target.get64BitArchVariant().getArch();
-  if (Target.getEnvironment() == llvm::Triple::GNUX32)
+  if (Target.getEnvironment() == llvm::Triple::GNUX32 ||
+  Target.getEnvironment() == llvm::Triple::GNUT64)

[clang] [llvm] [LLVM] [Clang] Support for Gentoo `*t64` triples (64-bit time_t ABIs) (PR #111302)

2024-10-06 Thread via cfe-commits
=?utf-8?q?Michał_Górny?= 
Message-ID:
In-Reply-To: 


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 b837c9e289dab93c7f8a06876e3f70b6864f40ab 
36ddad47341ac93e3041531c541ee3d9cc051021 --extensions c,cpp,h -- 
clang/test/Preprocessor/time64.c clang/lib/Basic/Targets/ARM.cpp 
clang/lib/Basic/Targets/OSTargets.h clang/lib/CodeGen/CodeGenModule.cpp 
clang/lib/CodeGen/Targets/ARM.cpp clang/lib/Driver/Driver.cpp 
clang/lib/Driver/ToolChains/Arch/ARM.cpp clang/lib/Driver/ToolChains/Gnu.cpp 
clang/lib/Driver/ToolChains/Linux.cpp llvm/include/llvm/TargetParser/Triple.h 
llvm/lib/Target/ARM/ARMSubtarget.h llvm/lib/Target/ARM/ARMTargetMachine.cpp 
llvm/lib/Target/ARM/ARMTargetMachine.h 
llvm/lib/TargetParser/ARMTargetParser.cpp llvm/lib/TargetParser/Triple.cpp 
llvm/unittests/TargetParser/TripleTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index f07eb8fafc..a98250b460 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -312,13 +312,16 @@ StringRef Triple::getEnvironmentTypeName(EnvironmentType 
Kind) {
   case EABI: return "eabi";
   case EABIHF: return "eabihf";
   case GNU: return "gnu";
-  case GNUT64: return "gnut64";
+  case GNUT64:
+return "gnut64";
   case GNUABI64: return "gnuabi64";
   case GNUABIN32: return "gnuabin32";
   case GNUEABI: return "gnueabi";
-  case GNUEABIT64: return "gnueabit64";
+  case GNUEABIT64:
+return "gnueabit64";
   case GNUEABIHF: return "gnueabihf";
-  case GNUEABIHFT64: return "gnueabihft64";
+  case GNUEABIHFT64:
+return "gnueabihft64";
   case GNUF32: return "gnuf32";
   case GNUF64: return "gnuf64";
   case GNUSF: return "gnusf";

``




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


[clang] [compiler-rt] [llvm] [FMV][AArch64] Unify features ssbs and ssbs2. (PR #110297)

2024-10-06 Thread Alexandros Lamprineas via cfe-commits

labrinea wrote:

Thanks for reviewing! Once this lands it will break the llvm test suite. 
[This](https://github.com/llvm/llvm-test-suite/pull/168) fixes it.

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


[clang] [llvm] [LLVM] [Clang] Support for Gentoo `*t64` triples (64-bit time_t ABIs) (PR #111302)

2024-10-06 Thread Michał Górny via cfe-commits


@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -E -dM -triple=i686-pc-linux-gnu < /dev/null | FileCheck 
-match-full-lines -check-prefix TIME32 %s

mgorny wrote:

Yeah, I was wondering if it's in the `init.c` tests for a reason.

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


[clang] [llvm] [LLVM] [Clang] Support for Gentoo `*t64` triples (64-bit time_t ABIs) (PR #111302)

2024-10-06 Thread Michał Górny via cfe-commits

https://github.com/mgorny updated 
https://github.com/llvm/llvm-project/pull/111302

From df75eaa8e0f399a43bde9e60af326f0c91aa7ad4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= 
Date: Sat, 5 Oct 2024 18:31:35 +0200
Subject: [PATCH 1/2] [llvm] [Triple] Support *t64 environments for Gentoo

Add a support for the new `*t64` triples that Gentoo is planning to use
for its 32-bit platforms migrated to use 64-bit time_t.  Given
the supported 32-bit targets, the expected environments are `-gnut64`,
`-gnueabit64` and `-gnueabihft64`.
---
 clang/lib/Basic/Targets/ARM.cpp|  2 ++
 clang/lib/CodeGen/CodeGenModule.cpp|  1 +
 clang/lib/CodeGen/Targets/ARM.cpp  |  3 +++
 clang/lib/Driver/Driver.cpp|  5 -
 clang/lib/Driver/ToolChains/Arch/ARM.cpp   |  7 +++
 clang/lib/Driver/ToolChains/Gnu.cpp|  2 ++
 clang/lib/Driver/ToolChains/Linux.cpp  |  1 +
 llvm/include/llvm/TargetParser/Triple.h| 23 +-
 llvm/lib/Target/ARM/ARMSubtarget.h |  4 +++-
 llvm/lib/Target/ARM/ARMTargetMachine.cpp   |  2 ++
 llvm/lib/Target/ARM/ARMTargetMachine.h |  1 +
 llvm/lib/TargetParser/ARMTargetParser.cpp  |  3 +++
 llvm/lib/TargetParser/Triple.cpp   |  6 ++
 llvm/unittests/TargetParser/TripleTest.cpp | 22 +
 14 files changed, 75 insertions(+), 7 deletions(-)

diff --git a/clang/lib/Basic/Targets/ARM.cpp b/clang/lib/Basic/Targets/ARM.cpp
index c56b8d9a448508..c87300bf2d60e0 100644
--- a/clang/lib/Basic/Targets/ARM.cpp
+++ b/clang/lib/Basic/Targets/ARM.cpp
@@ -313,7 +313,9 @@ ARMTargetInfo::ARMTargetInfo(const llvm::Triple &Triple,
 switch (Triple.getEnvironment()) {
 case llvm::Triple::Android:
 case llvm::Triple::GNUEABI:
+case llvm::Triple::GNUEABIT64:
 case llvm::Triple::GNUEABIHF:
+case llvm::Triple::GNUEABIHFT64:
 case llvm::Triple::MuslEABI:
 case llvm::Triple::MuslEABIHF:
 case llvm::Triple::OpenHOS:
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 25c1c496a4f27f..9b37e5b07126d8 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -177,6 +177,7 @@ createTargetCodeGenInfo(CodeGenModule &CGM) {
 else if (CodeGenOpts.FloatABI == "hard" ||
  (CodeGenOpts.FloatABI != "soft" &&
   (Triple.getEnvironment() == llvm::Triple::GNUEABIHF ||
+   Triple.getEnvironment() == llvm::Triple::GNUEABIHFT64 ||
Triple.getEnvironment() == llvm::Triple::MuslEABIHF ||
Triple.getEnvironment() == llvm::Triple::EABIHF)))
   Kind = ARMABIKind::AAPCS_VFP;
diff --git a/clang/lib/CodeGen/Targets/ARM.cpp 
b/clang/lib/CodeGen/Targets/ARM.cpp
index f7d7471d386b21..49ac1a76e767aa 100644
--- a/clang/lib/CodeGen/Targets/ARM.cpp
+++ b/clang/lib/CodeGen/Targets/ARM.cpp
@@ -35,7 +35,9 @@ class ARMABIInfo : public ABIInfo {
 case llvm::Triple::EABI:
 case llvm::Triple::EABIHF:
 case llvm::Triple::GNUEABI:
+case llvm::Triple::GNUEABIT64:
 case llvm::Triple::GNUEABIHF:
+case llvm::Triple::GNUEABIHFT64:
 case llvm::Triple::MuslEABI:
 case llvm::Triple::MuslEABIHF:
   return true;
@@ -48,6 +50,7 @@ class ARMABIInfo : public ABIInfo {
 switch (getTarget().getTriple().getEnvironment()) {
 case llvm::Triple::EABIHF:
 case llvm::Triple::GNUEABIHF:
+case llvm::Triple::GNUEABIHFT64:
 case llvm::Triple::MuslEABIHF:
   return true;
 default:
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index e9bf60d5e2ee46..cfcdb5c22e8072 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -610,7 +610,8 @@ static llvm::Triple computeTargetTriple(const Driver &D,
 if (A->getOption().matches(options::OPT_m64) ||
 A->getOption().matches(options::OPT_maix64)) {
   AT = Target.get64BitArchVariant().getArch();
-  if (Target.getEnvironment() == llvm::Triple::GNUX32)
+  if (Target.getEnvironment() == llvm::Triple::GNUX32 ||
+  Target.getEnvironment() == llvm::Triple::GNUT64)
 Target.setEnvironment(llvm::Triple::GNU);
   else if (Target.getEnvironment() == llvm::Triple::MuslX32)
 Target.setEnvironment(llvm::Triple::Musl);
@@ -673,6 +674,7 @@ static llvm::Triple computeTargetTriple(const Driver &D,
   } else if (ABIName == "n32") {
 Target = Target.get64BitArchVariant();
 if (Target.getEnvironment() == llvm::Triple::GNU ||
+Target.getEnvironment() == llvm::Triple::GNUT64 ||
 Target.getEnvironment() == llvm::Triple::GNUABI64)
   Target.setEnvironment(llvm::Triple::GNUABIN32);
 else if (Target.getEnvironment() == llvm::Triple::Musl ||
@@ -681,6 +683,7 @@ static llvm::Triple computeTargetTriple(const Driver &D,
   } else if (ABIName == "64") {
 Target = Target.get64BitArchVariant();
 if (Target.getEnvironment() == llvm::Triple::GNU ||
+ 

[clang] [llvm] [LLVM] [Clang] Support for Gentoo `*t64` triples (64-bit time_t ABIs) (PR #111302)

2024-10-06 Thread Fangrui Song via cfe-commits
=?utf-8?q?Micha=C5=82_G=C3=B3rny?= 
Message-ID:
In-Reply-To: 



@@ -1283,6 +1283,28 @@ TEST(TripleTest, ParsedIDs) {
   EXPECT_EQ(Triple::Linux, T.getOS());
   EXPECT_EQ(Triple::PAuthTest, T.getEnvironment());
 
+  // Gentoo time64 triples
+  T = Triple("i686-pc-linux-gnut64");
+  EXPECT_EQ(Triple::x86, T.getArch());
+  EXPECT_EQ(Triple::PC, T.getVendor());
+  EXPECT_EQ(Triple::Linux, T.getOS());
+  EXPECT_EQ(Triple::GNUT64, T.getEnvironment());
+  EXPECT_TRUE(T.isTime64ABI());
+
+  T = Triple("armv5tel-softfloat-linux-gnueabit64");
+  EXPECT_EQ(Triple::arm, T.getArch());
+  EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+  EXPECT_EQ(Triple::Linux, T.getOS());
+  EXPECT_EQ(Triple::GNUEABIT64, T.getEnvironment());
+  EXPECT_TRUE(T.isTime64ABI());
+
+  T = Triple("armv7a-unknown-linux-gnueabihft64");
+  EXPECT_EQ(Triple::arm, T.getArch());
+  EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+  EXPECT_EQ(Triple::Linux, T.getOS());
+  EXPECT_EQ(Triple::GNUEABIHFT64, T.getEnvironment());
+  EXPECT_TRUE(T.isTime64ABI());

MaskRay wrote:

needs a negative test for `isTime64ABI`

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


[clang] [StaticAnalyzer] Avoid repeated hash lookups (NFC) (PR #111272)

2024-10-06 Thread Nikita Popov via cfe-commits

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

LGTM

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


[clang] [ByteCode] Avoid repeated hash lookups (NFC) (PR #111273)

2024-10-06 Thread Nikita Popov via cfe-commits

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

LGTM

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


[clang] [Clang] Remove the special-casing for RequiresExprBodyDecl in BuildResolvedCallExpr() after fd87d765c0 (PR #111277)

2024-10-06 Thread via cfe-commits

cor3ntin wrote:

> That's #85198. Which was merged prior to the generic solution 
> [fd87d76](https://github.com/llvm/llvm-project/commit/fd87d765c0455265aea4595a3741a96b4c078fbc)
>  by @sdkrystian

Thanks!
Can you make the description reflect that more clearly? Thanks!

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


[clang] [Clang] Remove the special-casing for RequiresExprBodyDecl in BuildResolvedCallExpr() after fd87d765c0 (PR #111277)

2024-10-06 Thread via cfe-commits

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

LGTM 

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


[clang-tools-extra] [clang-tidy] Only expand macros in modernize-use-std-format/print (PR #97911)

2024-10-06 Thread Mike Crowe via cfe-commits

mikecrowe wrote:

I've fixed the release notes conflicts and slightly tweaked the documentation a 
little. @5chmidti or @PiotrZSL, please land this if you are happy that it's a 
net improvement on the existing code. I can then try to work out how to improve 
it further. Thanks.

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


[clang] [llvm] [LLVM] [Clang] Support for Gentoo `*t64` triples (64-bit time_t ABIs) (PR #111302)

2024-10-06 Thread Michał Górny via cfe-commits

https://github.com/mgorny updated 
https://github.com/llvm/llvm-project/pull/111302

From 3e057361eee9fa22f1a666857ce98019aba44ea2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= 
Date: Sat, 5 Oct 2024 18:31:35 +0200
Subject: [PATCH 1/2] [llvm] [Triple] Support *t64 environments for Gentoo

Add a support for the new `*t64` triples that Gentoo is planning to use
for its 32-bit platforms migrated to use 64-bit time_t.  Given
the supported 32-bit targets, the expected environments are `-gnut64`,
`-gnueabit64` and `-gnueabihft64`.
---
 clang/lib/Basic/Targets/ARM.cpp|  2 ++
 clang/lib/CodeGen/CodeGenModule.cpp|  1 +
 clang/lib/CodeGen/Targets/ARM.cpp  |  3 +++
 clang/lib/Driver/Driver.cpp|  5 +++-
 clang/lib/Driver/ToolChains/Arch/ARM.cpp   |  7 +
 clang/lib/Driver/ToolChains/Gnu.cpp|  2 ++
 clang/lib/Driver/ToolChains/Linux.cpp  |  1 +
 llvm/include/llvm/TargetParser/Triple.h| 23 
 llvm/lib/Target/ARM/ARMSubtarget.h |  4 ++-
 llvm/lib/Target/ARM/ARMTargetMachine.cpp   |  2 ++
 llvm/lib/Target/ARM/ARMTargetMachine.h |  1 +
 llvm/lib/TargetParser/ARMTargetParser.cpp  |  3 +++
 llvm/lib/TargetParser/Triple.cpp   |  6 +
 llvm/unittests/TargetParser/TripleTest.cpp | 31 ++
 14 files changed, 84 insertions(+), 7 deletions(-)

diff --git a/clang/lib/Basic/Targets/ARM.cpp b/clang/lib/Basic/Targets/ARM.cpp
index c56b8d9a448508..c87300bf2d60e0 100644
--- a/clang/lib/Basic/Targets/ARM.cpp
+++ b/clang/lib/Basic/Targets/ARM.cpp
@@ -313,7 +313,9 @@ ARMTargetInfo::ARMTargetInfo(const llvm::Triple &Triple,
 switch (Triple.getEnvironment()) {
 case llvm::Triple::Android:
 case llvm::Triple::GNUEABI:
+case llvm::Triple::GNUEABIT64:
 case llvm::Triple::GNUEABIHF:
+case llvm::Triple::GNUEABIHFT64:
 case llvm::Triple::MuslEABI:
 case llvm::Triple::MuslEABIHF:
 case llvm::Triple::OpenHOS:
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 25c1c496a4f27f..9b37e5b07126d8 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -177,6 +177,7 @@ createTargetCodeGenInfo(CodeGenModule &CGM) {
 else if (CodeGenOpts.FloatABI == "hard" ||
  (CodeGenOpts.FloatABI != "soft" &&
   (Triple.getEnvironment() == llvm::Triple::GNUEABIHF ||
+   Triple.getEnvironment() == llvm::Triple::GNUEABIHFT64 ||
Triple.getEnvironment() == llvm::Triple::MuslEABIHF ||
Triple.getEnvironment() == llvm::Triple::EABIHF)))
   Kind = ARMABIKind::AAPCS_VFP;
diff --git a/clang/lib/CodeGen/Targets/ARM.cpp 
b/clang/lib/CodeGen/Targets/ARM.cpp
index f7d7471d386b21..49ac1a76e767aa 100644
--- a/clang/lib/CodeGen/Targets/ARM.cpp
+++ b/clang/lib/CodeGen/Targets/ARM.cpp
@@ -35,7 +35,9 @@ class ARMABIInfo : public ABIInfo {
 case llvm::Triple::EABI:
 case llvm::Triple::EABIHF:
 case llvm::Triple::GNUEABI:
+case llvm::Triple::GNUEABIT64:
 case llvm::Triple::GNUEABIHF:
+case llvm::Triple::GNUEABIHFT64:
 case llvm::Triple::MuslEABI:
 case llvm::Triple::MuslEABIHF:
   return true;
@@ -48,6 +50,7 @@ class ARMABIInfo : public ABIInfo {
 switch (getTarget().getTriple().getEnvironment()) {
 case llvm::Triple::EABIHF:
 case llvm::Triple::GNUEABIHF:
+case llvm::Triple::GNUEABIHFT64:
 case llvm::Triple::MuslEABIHF:
   return true;
 default:
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index e9bf60d5e2ee46..cfcdb5c22e8072 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -610,7 +610,8 @@ static llvm::Triple computeTargetTriple(const Driver &D,
 if (A->getOption().matches(options::OPT_m64) ||
 A->getOption().matches(options::OPT_maix64)) {
   AT = Target.get64BitArchVariant().getArch();
-  if (Target.getEnvironment() == llvm::Triple::GNUX32)
+  if (Target.getEnvironment() == llvm::Triple::GNUX32 ||
+  Target.getEnvironment() == llvm::Triple::GNUT64)
 Target.setEnvironment(llvm::Triple::GNU);
   else if (Target.getEnvironment() == llvm::Triple::MuslX32)
 Target.setEnvironment(llvm::Triple::Musl);
@@ -673,6 +674,7 @@ static llvm::Triple computeTargetTriple(const Driver &D,
   } else if (ABIName == "n32") {
 Target = Target.get64BitArchVariant();
 if (Target.getEnvironment() == llvm::Triple::GNU ||
+Target.getEnvironment() == llvm::Triple::GNUT64 ||
 Target.getEnvironment() == llvm::Triple::GNUABI64)
   Target.setEnvironment(llvm::Triple::GNUABIN32);
 else if (Target.getEnvironment() == llvm::Triple::Musl ||
@@ -681,6 +683,7 @@ static llvm::Triple computeTargetTriple(const Driver &D,
   } else if (ABIName == "64") {
 Target = Target.get64BitArchVariant();
 if (Target.getEnvironment() == llvm::Triple::GNU ||
+   

[clang] [llvm] [LLVM] [Clang] Support for Gentoo `*t64` triples (64-bit time_t ABIs) (PR #111302)

2024-10-06 Thread Michał Górny via cfe-commits


@@ -1283,6 +1283,28 @@ TEST(TripleTest, ParsedIDs) {
   EXPECT_EQ(Triple::Linux, T.getOS());
   EXPECT_EQ(Triple::PAuthTest, T.getEnvironment());
 
+  // Gentoo time64 triples
+  T = Triple("i686-pc-linux-gnut64");
+  EXPECT_EQ(Triple::x86, T.getArch());
+  EXPECT_EQ(Triple::PC, T.getVendor());
+  EXPECT_EQ(Triple::Linux, T.getOS());
+  EXPECT_EQ(Triple::GNUT64, T.getEnvironment());
+  EXPECT_TRUE(T.isTime64ABI());
+
+  T = Triple("armv5tel-softfloat-linux-gnueabit64");
+  EXPECT_EQ(Triple::arm, T.getArch());
+  EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+  EXPECT_EQ(Triple::Linux, T.getOS());
+  EXPECT_EQ(Triple::GNUEABIT64, T.getEnvironment());
+  EXPECT_TRUE(T.isTime64ABI());
+
+  T = Triple("armv7a-unknown-linux-gnueabihft64");
+  EXPECT_EQ(Triple::arm, T.getArch());
+  EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+  EXPECT_EQ(Triple::Linux, T.getOS());
+  EXPECT_EQ(Triple::GNUEABIHFT64, T.getEnvironment());
+  EXPECT_TRUE(T.isTime64ABI());

mgorny wrote:

Added.

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


[clang] [llvm] [LLVM] [Clang] Support for Gentoo `*t64` triples (64-bit time_t ABIs) (PR #111302)

2024-10-06 Thread Michał Górny via cfe-commits


@@ -610,7 +610,8 @@ static llvm::Triple computeTargetTriple(const Driver &D,
 if (A->getOption().matches(options::OPT_m64) ||
 A->getOption().matches(options::OPT_maix64)) {
   AT = Target.get64BitArchVariant().getArch();
-  if (Target.getEnvironment() == llvm::Triple::GNUX32)
+  if (Target.getEnvironment() == llvm::Triple::GNUX32 ||

mgorny wrote:

To be honest, I don't have the energy to rewrite it all manually, especially 
that these files don't seem to be clang-formatted consistently.

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


[clang] [llvm] [LLVM] [Clang] Support for Gentoo `*t64` triples (64-bit time_t ABIs) (PR #111302)

2024-10-06 Thread Michał Górny via cfe-commits


@@ -177,6 +177,7 @@ createTargetCodeGenInfo(CodeGenModule &CGM) {
 else if (CodeGenOpts.FloatABI == "hard" ||
  (CodeGenOpts.FloatABI != "soft" &&
   (Triple.getEnvironment() == llvm::Triple::GNUEABIHF ||

mgorny wrote:

I'm wondering if we should add a `isHardFloatABI()` or something like that to 
the `Triple` class.

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


[clang] [Clang][Driver] Improve config file handling on Darwin (PR #111306)

2024-10-06 Thread Carlo Cabrera via cfe-commits

https://github.com/carlocab created 
https://github.com/llvm/llvm-project/pull/111306

On Darwin, the default target triple contains the version of the kernel:

❯ clang --print-target-triple
arm64-apple-darwin24.0.0
❯ uname -r
24.0.0

This makes writing config files for the target triple rather cumbersome,
because they require including the full version of the kernel in the
filename when one generally cares only about the major version if at
all.

Let's improve this by also checking for major-versioned and unversioned
`.cfg` files if we weren't able to find a `.cfg` file for the full
triple when targetting Darwin.


>From 7ab9f9ebb858618f6eb92bb058afca0cb0f56269 Mon Sep 17 00:00:00 2001
From: Carlo Cabrera <30379873+carlo...@users.noreply.github.com>
Date: Mon, 7 Oct 2024 01:53:37 +0800
Subject: [PATCH] [Clang][Driver] Improve config file handling on Darwin
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

On Darwin, the default target triple contains the version of the kernel:

❯ clang --print-target-triple
arm64-apple-darwin24.0.0
❯ uname -r
24.0.0

This makes writing config files for the target triple rather cumbersome,
because they require including the full version of the kernel in the
filename when one generally cares only about the major version if at
all.

Let's improve this by also checking for major-versioned and unversioned
`.cfg` files if we weren't able to find a `.cfg` file for the full
triple when targetting Darwin.
---
 clang/lib/Driver/Driver.cpp| 19 +++
 clang/test/Driver/config-file-darwin.c | 24 
 2 files changed, 43 insertions(+)
 create mode 100644 clang/test/Driver/config-file-darwin.c

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 2aaa52072b03d2..e9f241228d4aab 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -95,6 +95,7 @@
 #include "llvm/TargetParser/Host.h"
 #include "llvm/TargetParser/RISCVISAInfo.h"
 #include  // ::getenv
+#include 
 #include 
 #include 
 #include 
@@ -1222,6 +1223,24 @@ bool 
Driver::loadDefaultConfigFiles(llvm::cl::ExpansionContext &ExpCtx) {
   if (ExpCtx.findConfigFile(CfgFileName, CfgFilePath))
 return readConfigFile(CfgFilePath, ExpCtx);
 
+  // On Darwin, try a major-versioned triple then an unversioned triple.
+  auto pos = Triple.find("-apple-darwin");
+  auto kernelVersionStart = pos + std::strlen("-apple-darwin");
+  if (pos != Triple.npos && Triple.length() > kernelVersionStart) {
+// First, find the major-versioned triple (e.g. arm64-apple-darwin24).
+auto T = Triple.substr(0, Triple.find(".", kernelVersionStart));
+CfgFileName = T + ".cfg";
+if (ExpCtx.findConfigFile(CfgFileName, CfgFilePath))
+  return readConfigFile(CfgFilePath, ExpCtx);
+
+// If that is not available, try an unversioned triple
+// (e.g. arm64-apple-darwin).
+T = Triple.substr(0, kernelVersionStart);
+CfgFileName = T + ".cfg";
+if (ExpCtx.findConfigFile(CfgFileName, CfgFilePath))
+  return readConfigFile(CfgFilePath, ExpCtx);
+  }
+
   // If we were unable to find a config file deduced from executable name,
   // that is not an error.
   return false;
diff --git a/clang/test/Driver/config-file-darwin.c 
b/clang/test/Driver/config-file-darwin.c
new file mode 100644
index 00..c24eb7ad19fe67
--- /dev/null
+++ b/clang/test/Driver/config-file-darwin.c
@@ -0,0 +1,24 @@
+// REQUIRES: shell
+
+// RUN: unset CLANG_NO_DEFAULT_CONFIG
+// RUN: rm -rf %t && mkdir %t
+
+//--- Major-versioned config files are used when targetting *-apple-darwin*
+//
+// RUN: mkdir -p %t/testbin
+// RUN: ln -s %clang %t/testbin/x86_64-apple-darwin24.0.0-clang
+// RUN: echo "-Werror" > %t/testbin/x86_64-apple-darwin24.cfg
+// RUN: %t/testbin/x86_64-apple-darwin24.0.0-clang --config-system-dir= 
--config-user-dir= -c -no-canonical-prefixes -### %s 2>&1 | FileCheck %s 
-check-prefix CHECK-MAJOR-VERSIONED
+//
+// CHECK-MAJOR-VERSIONED: Configuration file: 
{{.*}}/testbin/x86_64-apple-darwin24.cfg
+// CHECK-MAJOR-VERSIONED: -Werror
+
+//--- Unversioned config files are used when targetting *-apple-darwin*
+//
+// RUN: mkdir -p %t/testbin
+// RUN: ln -s %clang %t/testbin/arm64-apple-darwin23.1.2-clang
+// RUN: echo "-Werror" > %t/testbin/arm64-apple-darwin.cfg
+// RUN: %t/testbin/arm64-apple-darwin23.1.2-clang --config-system-dir= 
--config-user-dir= -c -no-canonical-prefixes -### %s 2>&1 | FileCheck %s 
-check-prefix CHECK-UNVERSIONED
+//
+// CHECK-UNVERSIONED: Configuration file: {{.*}}/testbin/arm64-apple-darwin.cfg
+// CHECK-UNVERSIONED: -Werror

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


[clang] [Clang][Driver] Improve config file handling on Darwin (PR #111306)

2024-10-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Carlo Cabrera (carlocab)


Changes

On Darwin, the default target triple contains the version of the kernel:

❯ clang --print-target-triple
arm64-apple-darwin24.0.0
❯ uname -r
24.0.0

This makes writing config files for the target triple rather cumbersome,
because they require including the full version of the kernel in the
filename when one generally cares only about the major version if at
all.

Let's improve this by also checking for major-versioned and unversioned
`.cfg` files if we weren't able to find a `.cfg` file for the full
triple when targetting Darwin.


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


2 Files Affected:

- (modified) clang/lib/Driver/Driver.cpp (+19) 
- (added) clang/test/Driver/config-file-darwin.c (+24) 


``diff
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 2aaa52072b03d2..e9f241228d4aab 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -95,6 +95,7 @@
 #include "llvm/TargetParser/Host.h"
 #include "llvm/TargetParser/RISCVISAInfo.h"
 #include  // ::getenv
+#include 
 #include 
 #include 
 #include 
@@ -1222,6 +1223,24 @@ bool 
Driver::loadDefaultConfigFiles(llvm::cl::ExpansionContext &ExpCtx) {
   if (ExpCtx.findConfigFile(CfgFileName, CfgFilePath))
 return readConfigFile(CfgFilePath, ExpCtx);
 
+  // On Darwin, try a major-versioned triple then an unversioned triple.
+  auto pos = Triple.find("-apple-darwin");
+  auto kernelVersionStart = pos + std::strlen("-apple-darwin");
+  if (pos != Triple.npos && Triple.length() > kernelVersionStart) {
+// First, find the major-versioned triple (e.g. arm64-apple-darwin24).
+auto T = Triple.substr(0, Triple.find(".", kernelVersionStart));
+CfgFileName = T + ".cfg";
+if (ExpCtx.findConfigFile(CfgFileName, CfgFilePath))
+  return readConfigFile(CfgFilePath, ExpCtx);
+
+// If that is not available, try an unversioned triple
+// (e.g. arm64-apple-darwin).
+T = Triple.substr(0, kernelVersionStart);
+CfgFileName = T + ".cfg";
+if (ExpCtx.findConfigFile(CfgFileName, CfgFilePath))
+  return readConfigFile(CfgFilePath, ExpCtx);
+  }
+
   // If we were unable to find a config file deduced from executable name,
   // that is not an error.
   return false;
diff --git a/clang/test/Driver/config-file-darwin.c 
b/clang/test/Driver/config-file-darwin.c
new file mode 100644
index 00..c24eb7ad19fe67
--- /dev/null
+++ b/clang/test/Driver/config-file-darwin.c
@@ -0,0 +1,24 @@
+// REQUIRES: shell
+
+// RUN: unset CLANG_NO_DEFAULT_CONFIG
+// RUN: rm -rf %t && mkdir %t
+
+//--- Major-versioned config files are used when targetting *-apple-darwin*
+//
+// RUN: mkdir -p %t/testbin
+// RUN: ln -s %clang %t/testbin/x86_64-apple-darwin24.0.0-clang
+// RUN: echo "-Werror" > %t/testbin/x86_64-apple-darwin24.cfg
+// RUN: %t/testbin/x86_64-apple-darwin24.0.0-clang --config-system-dir= 
--config-user-dir= -c -no-canonical-prefixes -### %s 2>&1 | FileCheck %s 
-check-prefix CHECK-MAJOR-VERSIONED
+//
+// CHECK-MAJOR-VERSIONED: Configuration file: 
{{.*}}/testbin/x86_64-apple-darwin24.cfg
+// CHECK-MAJOR-VERSIONED: -Werror
+
+//--- Unversioned config files are used when targetting *-apple-darwin*
+//
+// RUN: mkdir -p %t/testbin
+// RUN: ln -s %clang %t/testbin/arm64-apple-darwin23.1.2-clang
+// RUN: echo "-Werror" > %t/testbin/arm64-apple-darwin.cfg
+// RUN: %t/testbin/arm64-apple-darwin23.1.2-clang --config-system-dir= 
--config-user-dir= -c -no-canonical-prefixes -### %s 2>&1 | FileCheck %s 
-check-prefix CHECK-UNVERSIONED
+//
+// CHECK-UNVERSIONED: Configuration file: {{.*}}/testbin/arm64-apple-darwin.cfg
+// CHECK-UNVERSIONED: -Werror

``




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


[clang] [Clang][Driver] Improve config file handling on Darwin (PR #111306)

2024-10-06 Thread via cfe-commits

github-actions[bot] wrote:

⚠️ We detected that you are using a GitHub private e-mail address to contribute 
to the repo. Please turn off [Keep my email addresses 
private](https://github.com/settings/emails) setting in your account. See 
[LLVM 
Discourse](https://discourse.llvm.org/t/hidden-emails-on-github-should-we-do-something-about-it)
 for more information.

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


[clang] [Clang][Driver] Improve config file handling on Darwin (PR #111306)

2024-10-06 Thread Carlo Cabrera via cfe-commits

https://github.com/carlocab updated 
https://github.com/llvm/llvm-project/pull/111306

>From 80b4301ba4a043fe426f206a4ae3a7b46ad8396c Mon Sep 17 00:00:00 2001
From: Carlo Cabrera 
Date: Mon, 7 Oct 2024 01:53:37 +0800
Subject: [PATCH] [Clang][Driver] Improve config file handling on Darwin
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

On Darwin, the default target triple contains the version of the kernel:

❯ clang --print-target-triple
arm64-apple-darwin24.0.0
❯ uname -r
24.0.0

This makes writing config files for the target triple rather cumbersome,
because they require including the full version of the kernel in the
filename when one generally cares only about the major version if at
all.

Let's improve this by also checking for major-versioned and unversioned
`.cfg` files if we weren't able to find a `.cfg` file for the full
triple when targetting Darwin.
---
 clang/lib/Driver/Driver.cpp| 19 +++
 clang/test/Driver/config-file-darwin.c | 24 
 2 files changed, 43 insertions(+)
 create mode 100644 clang/test/Driver/config-file-darwin.c

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 2aaa52072b03d2..e9f241228d4aab 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -95,6 +95,7 @@
 #include "llvm/TargetParser/Host.h"
 #include "llvm/TargetParser/RISCVISAInfo.h"
 #include  // ::getenv
+#include 
 #include 
 #include 
 #include 
@@ -1222,6 +1223,24 @@ bool 
Driver::loadDefaultConfigFiles(llvm::cl::ExpansionContext &ExpCtx) {
   if (ExpCtx.findConfigFile(CfgFileName, CfgFilePath))
 return readConfigFile(CfgFilePath, ExpCtx);
 
+  // On Darwin, try a major-versioned triple then an unversioned triple.
+  auto pos = Triple.find("-apple-darwin");
+  auto kernelVersionStart = pos + std::strlen("-apple-darwin");
+  if (pos != Triple.npos && Triple.length() > kernelVersionStart) {
+// First, find the major-versioned triple (e.g. arm64-apple-darwin24).
+auto T = Triple.substr(0, Triple.find(".", kernelVersionStart));
+CfgFileName = T + ".cfg";
+if (ExpCtx.findConfigFile(CfgFileName, CfgFilePath))
+  return readConfigFile(CfgFilePath, ExpCtx);
+
+// If that is not available, try an unversioned triple
+// (e.g. arm64-apple-darwin).
+T = Triple.substr(0, kernelVersionStart);
+CfgFileName = T + ".cfg";
+if (ExpCtx.findConfigFile(CfgFileName, CfgFilePath))
+  return readConfigFile(CfgFilePath, ExpCtx);
+  }
+
   // If we were unable to find a config file deduced from executable name,
   // that is not an error.
   return false;
diff --git a/clang/test/Driver/config-file-darwin.c 
b/clang/test/Driver/config-file-darwin.c
new file mode 100644
index 00..c24eb7ad19fe67
--- /dev/null
+++ b/clang/test/Driver/config-file-darwin.c
@@ -0,0 +1,24 @@
+// REQUIRES: shell
+
+// RUN: unset CLANG_NO_DEFAULT_CONFIG
+// RUN: rm -rf %t && mkdir %t
+
+//--- Major-versioned config files are used when targetting *-apple-darwin*
+//
+// RUN: mkdir -p %t/testbin
+// RUN: ln -s %clang %t/testbin/x86_64-apple-darwin24.0.0-clang
+// RUN: echo "-Werror" > %t/testbin/x86_64-apple-darwin24.cfg
+// RUN: %t/testbin/x86_64-apple-darwin24.0.0-clang --config-system-dir= 
--config-user-dir= -c -no-canonical-prefixes -### %s 2>&1 | FileCheck %s 
-check-prefix CHECK-MAJOR-VERSIONED
+//
+// CHECK-MAJOR-VERSIONED: Configuration file: 
{{.*}}/testbin/x86_64-apple-darwin24.cfg
+// CHECK-MAJOR-VERSIONED: -Werror
+
+//--- Unversioned config files are used when targetting *-apple-darwin*
+//
+// RUN: mkdir -p %t/testbin
+// RUN: ln -s %clang %t/testbin/arm64-apple-darwin23.1.2-clang
+// RUN: echo "-Werror" > %t/testbin/arm64-apple-darwin.cfg
+// RUN: %t/testbin/arm64-apple-darwin23.1.2-clang --config-system-dir= 
--config-user-dir= -c -no-canonical-prefixes -### %s 2>&1 | FileCheck %s 
-check-prefix CHECK-UNVERSIONED
+//
+// CHECK-UNVERSIONED: Configuration file: {{.*}}/testbin/arm64-apple-darwin.cfg
+// CHECK-UNVERSIONED: -Werror

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


[clang] [Clang][Driver] Improve config file handling on Darwin (PR #111306)

2024-10-06 Thread Carlo Cabrera via cfe-commits

carlocab wrote:

> ⚠️ We detected that you are using a GitHub private e-mail address to 
> contribute to the repo. Please turn off [Keep my email addresses 
> private](https://github.com/settings/emails) setting in your account. See 
> [LLVM 
> Discourse](https://discourse.llvm.org/t/hidden-emails-on-github-should-we-do-something-about-it)
>  for more information.

This seems to be based on the commit author rather than my actual GitHub 
configuration. See also 
https://github.com/llvm/llvm-project/pull/110962#issuecomment-2392834897

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


[clang] [llvm] [LLVM] [Clang] Support for Gentoo `*t64` triples (64-bit time_t ABIs) (PR #111302)

2024-10-06 Thread Fangrui Song via cfe-commits
=?utf-8?q?Micha=C5=82_G=C3=B3rny?= 
Message-ID:
In-Reply-To: 



@@ -177,6 +177,7 @@ createTargetCodeGenInfo(CodeGenModule &CGM) {
 else if (CodeGenOpts.FloatABI == "hard" ||
  (CodeGenOpts.FloatABI != "soft" &&
   (Triple.getEnvironment() == llvm::Triple::GNUEABIHF ||

MaskRay wrote:

This helper sounds good.

will we have `muslt32`?

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


[clang] [clang-format][NFC] Clean up AlignConsecutiveStyle (PR #111285)

2024-10-06 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/111285

None

>From 7745a5d103f73a093bd856d23b3fb1c4ef80d5ac Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sun, 6 Oct 2024 02:27:59 -0700
Subject: [PATCH] [clang-format][NFC] Clean up AlignConsecutiveStyle

---
 clang/lib/Format/Format.cpp  | 18 ++--
 clang/unittests/Format/ConfigParseTest.cpp   | 22 +---
 clang/unittests/Format/FormatTest.cpp|  5 +
 clang/unittests/Format/FormatTestVerilog.cpp |  1 +
 4 files changed, 14 insertions(+), 32 deletions(-)

diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 5350c66ea5132b..d691d198f8025d 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -44,11 +44,7 @@ struct 
ScalarEnumerationTraits {
 
 template <> struct MappingTraits {
   static void enumInput(IO &IO, FormatStyle::AlignConsecutiveStyle &Value) {
-IO.enumCase(Value, "None",
-FormatStyle::AlignConsecutiveStyle(
-{/*Enabled=*/false, /*AcrossEmptyLines=*/false,
- /*AcrossComments=*/false, /*AlignCompound=*/false,
- /*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
+IO.enumCase(Value, "None", FormatStyle::AlignConsecutiveStyle({}));
 IO.enumCase(Value, "Consecutive",
 FormatStyle::AlignConsecutiveStyle(
 {/*Enabled=*/true, /*AcrossEmptyLines=*/false,
@@ -76,11 +72,7 @@ template <> struct 
MappingTraits {
 {/*Enabled=*/true, /*AcrossEmptyLines=*/false,
  /*AcrossComments=*/false, /*AlignCompound=*/false,
  /*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
-IO.enumCase(Value, "false",
-FormatStyle::AlignConsecutiveStyle(
-{/*Enabled=*/false, /*AcrossEmptyLines=*/false,
- /*AcrossComments=*/false, /*AlignCompound=*/false,
- /*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
+IO.enumCase(Value, "false", FormatStyle::AlignConsecutiveStyle({}));
   }
 
   static void mapping(IO &IO, FormatStyle::AlignConsecutiveStyle &Value) {
@@ -1441,12 +1433,6 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   LLVMStyle.AlignAfterOpenBracket = FormatStyle::BAS_Align;
   LLVMStyle.AlignArrayOfStructures = FormatStyle::AIAS_None;
   LLVMStyle.AlignConsecutiveAssignments = {};
-  LLVMStyle.AlignConsecutiveAssignments.AcrossComments = false;
-  LLVMStyle.AlignConsecutiveAssignments.AcrossEmptyLines = false;
-  LLVMStyle.AlignConsecutiveAssignments.AlignCompound = false;
-  LLVMStyle.AlignConsecutiveAssignments.AlignFunctionPointers = false;
-  LLVMStyle.AlignConsecutiveAssignments.Enabled = false;
-  LLVMStyle.AlignConsecutiveAssignments.PadOperators = true;
   LLVMStyle.AlignConsecutiveBitFields = {};
   LLVMStyle.AlignConsecutiveDeclarations = {};
   LLVMStyle.AlignConsecutiveMacros = {};
diff --git a/clang/unittests/Format/ConfigParseTest.cpp 
b/clang/unittests/Format/ConfigParseTest.cpp
index b8bdfaaa74e10e..4d723981d73926 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -300,12 +300,8 @@ TEST(ConfigParseTest, ParsesConfiguration) {
 #define CHECK_ALIGN_CONSECUTIVE(FIELD) 
\
   do { 
\
 Style.FIELD.Enabled = true;
\
-CHECK_PARSE(   
\
-#FIELD ": None", FIELD,
\
-FormatStyle::AlignConsecutiveStyle(
\
-{/*Enabled=*/false, /*AcrossEmptyLines=*/false,
\
- /*AcrossComments=*/false, /*AlignCompound=*/false,
\
- /*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
\
+CHECK_PARSE(#FIELD ": None", FIELD,
\
+FormatStyle::AlignConsecutiveStyle({}));   
\
 CHECK_PARSE(   
\
 #FIELD ": Consecutive", FIELD, 
\
 FormatStyle::AlignConsecutiveStyle(
\
@@ -319,18 +315,20 @@ TEST(ConfigParseTest, ParsesConfiguration) {
  /*AcrossComments=*/false, /*AlignCompound=*/false,
\
  /*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
\
 CHECK_PARSE(   
\
-#FIELD ": AcrossEmptyLinesAndComments", FIELD, 
\
+#FIELD ": AcrossComments", FIELD,  
\
 FormatStyle::AlignConsecuti

[clang] [clang-format][NFC] Clean up AlignConsecutiveStyle (PR #111285)

2024-10-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)


Changes



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


4 Files Affected:

- (modified) clang/lib/Format/Format.cpp (+2-16) 
- (modified) clang/unittests/Format/ConfigParseTest.cpp (+10-12) 
- (modified) clang/unittests/Format/FormatTest.cpp (+1-4) 
- (modified) clang/unittests/Format/FormatTestVerilog.cpp (+1) 


``diff
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 5350c66ea5132b..d691d198f8025d 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -44,11 +44,7 @@ struct 
ScalarEnumerationTraits {
 
 template <> struct MappingTraits {
   static void enumInput(IO &IO, FormatStyle::AlignConsecutiveStyle &Value) {
-IO.enumCase(Value, "None",
-FormatStyle::AlignConsecutiveStyle(
-{/*Enabled=*/false, /*AcrossEmptyLines=*/false,
- /*AcrossComments=*/false, /*AlignCompound=*/false,
- /*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
+IO.enumCase(Value, "None", FormatStyle::AlignConsecutiveStyle({}));
 IO.enumCase(Value, "Consecutive",
 FormatStyle::AlignConsecutiveStyle(
 {/*Enabled=*/true, /*AcrossEmptyLines=*/false,
@@ -76,11 +72,7 @@ template <> struct 
MappingTraits {
 {/*Enabled=*/true, /*AcrossEmptyLines=*/false,
  /*AcrossComments=*/false, /*AlignCompound=*/false,
  /*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
-IO.enumCase(Value, "false",
-FormatStyle::AlignConsecutiveStyle(
-{/*Enabled=*/false, /*AcrossEmptyLines=*/false,
- /*AcrossComments=*/false, /*AlignCompound=*/false,
- /*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
+IO.enumCase(Value, "false", FormatStyle::AlignConsecutiveStyle({}));
   }
 
   static void mapping(IO &IO, FormatStyle::AlignConsecutiveStyle &Value) {
@@ -1441,12 +1433,6 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   LLVMStyle.AlignAfterOpenBracket = FormatStyle::BAS_Align;
   LLVMStyle.AlignArrayOfStructures = FormatStyle::AIAS_None;
   LLVMStyle.AlignConsecutiveAssignments = {};
-  LLVMStyle.AlignConsecutiveAssignments.AcrossComments = false;
-  LLVMStyle.AlignConsecutiveAssignments.AcrossEmptyLines = false;
-  LLVMStyle.AlignConsecutiveAssignments.AlignCompound = false;
-  LLVMStyle.AlignConsecutiveAssignments.AlignFunctionPointers = false;
-  LLVMStyle.AlignConsecutiveAssignments.Enabled = false;
-  LLVMStyle.AlignConsecutiveAssignments.PadOperators = true;
   LLVMStyle.AlignConsecutiveBitFields = {};
   LLVMStyle.AlignConsecutiveDeclarations = {};
   LLVMStyle.AlignConsecutiveMacros = {};
diff --git a/clang/unittests/Format/ConfigParseTest.cpp 
b/clang/unittests/Format/ConfigParseTest.cpp
index b8bdfaaa74e10e..4d723981d73926 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -300,12 +300,8 @@ TEST(ConfigParseTest, ParsesConfiguration) {
 #define CHECK_ALIGN_CONSECUTIVE(FIELD) 
\
   do { 
\
 Style.FIELD.Enabled = true;
\
-CHECK_PARSE(   
\
-#FIELD ": None", FIELD,
\
-FormatStyle::AlignConsecutiveStyle(
\
-{/*Enabled=*/false, /*AcrossEmptyLines=*/false,
\
- /*AcrossComments=*/false, /*AlignCompound=*/false,
\
- /*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
\
+CHECK_PARSE(#FIELD ": None", FIELD,
\
+FormatStyle::AlignConsecutiveStyle({}));   
\
 CHECK_PARSE(   
\
 #FIELD ": Consecutive", FIELD, 
\
 FormatStyle::AlignConsecutiveStyle(
\
@@ -319,18 +315,20 @@ TEST(ConfigParseTest, ParsesConfiguration) {
  /*AcrossComments=*/false, /*AlignCompound=*/false,
\
  /*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
\
 CHECK_PARSE(   
\
-#FIELD ": AcrossEmptyLinesAndComments", FIELD, 
\
+#FIELD ": AcrossComments", FIELD,  
\
 FormatStyle::AlignConsecutiveStyle(
\
-{/*Enabled=*/true, /*AcrossEmptyLines=*/true,  
\
+{/*Enabled

[clang] [clang][AVR] Fix basic type size/alignment values to match avr-gcc. (PR #111290)

2024-10-06 Thread Alex Rønne Petersen via cfe-commits

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


[clang] [clang][AVR] Fix basic type size/alignment values to match avr-gcc. (PR #111290)

2024-10-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Alex Rønne Petersen (alexrp)


Changes

Closes #102172.

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


4 Files Affected:

- (modified) clang/include/clang/Basic/TargetInfo.h (+5-7) 
- (modified) clang/lib/Basic/TargetInfo.cpp (+2) 
- (modified) clang/lib/Basic/Targets/AVR.h (+4) 
- (added) clang/test/Sema/avr-size-align.c (+49) 


``diff
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 57783850606290..e7469e1e989128 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -87,6 +87,7 @@ enum class FloatModeKind {
 struct TransferrableTargetInfo {
   unsigned char PointerWidth, PointerAlign;
   unsigned char BoolWidth, BoolAlign;
+  unsigned char ShortWidth, ShortAlign;
   unsigned char IntWidth, IntAlign;
   unsigned char HalfWidth, HalfAlign;
   unsigned char BFloat16Width, BFloat16Align;
@@ -497,13 +498,10 @@ class TargetInfo : public TransferrableTargetInfo,
   unsigned getCharWidth() const { return 8; } // FIXME
   unsigned getCharAlign() const { return 8; } // FIXME
 
-  /// Return the size of 'signed short' and 'unsigned short' for this
-  /// target, in bits.
-  unsigned getShortWidth() const { return 16; } // FIXME
-
-  /// Return the alignment of 'signed short' and 'unsigned short' for
-  /// this target.
-  unsigned getShortAlign() const { return 16; } // FIXME
+  /// getShortWidth/Align - Return the size of 'signed short' and
+  /// 'unsigned short' for this target, in bits.
+  unsigned getShortWidth() const { return ShortWidth; }
+  unsigned getShortAlign() const { return ShortAlign; }
 
   /// getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' 
for
   /// this target, in bits.
diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index 92195333821097..145ca545854da7 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/lib/Basic/TargetInfo.cpp
@@ -70,6 +70,7 @@ TargetInfo::TargetInfo(const llvm::Triple &T) : Triple(T) {
   HasStrictFP = false;
   PointerWidth = PointerAlign = 32;
   BoolWidth = BoolAlign = 8;
+  ShortWidth = ShortAlign = 16;
   IntWidth = IntAlign = 32;
   LongWidth = LongAlign = 32;
   LongLongWidth = LongLongAlign = 64;
@@ -437,6 +438,7 @@ void TargetInfo::adjust(DiagnosticsEngine &Diags, 
LangOptions &Opts) {
 // what these normally are for the target.
 // We also define long long and long double here, although the
 // OpenCL standard only mentions these as "reserved".
+ShortWidth = ShortAlign = 16;
 IntWidth = IntAlign = 32;
 LongWidth = LongAlign = 64;
 LongLongWidth = LongLongAlign = 128;
diff --git a/clang/lib/Basic/Targets/AVR.h b/clang/lib/Basic/Targets/AVR.h
index feeb04f37eeba7..0a2f51747f8a7f 100644
--- a/clang/lib/Basic/Targets/AVR.h
+++ b/clang/lib/Basic/Targets/AVR.h
@@ -29,6 +29,8 @@ class LLVM_LIBRARY_VISIBILITY AVRTargetInfo : public 
TargetInfo {
 TLSSupported = false;
 PointerWidth = 16;
 PointerAlign = 8;
+ShortWidth = 16;
+ShortAlign = 8;
 IntWidth = 16;
 IntAlign = 8;
 LongWidth = 32;
@@ -65,6 +67,8 @@ class LLVM_LIBRARY_VISIBILITY AVRTargetInfo : public 
TargetInfo {
 return std::nullopt;
   }
 
+  bool allowsLargerPreferedTypeAlignment() const override { return false; }
+
   BuiltinVaListKind getBuiltinVaListKind() const override {
 return TargetInfo::VoidPtrBuiltinVaList;
   }
diff --git a/clang/test/Sema/avr-size-align.c b/clang/test/Sema/avr-size-align.c
new file mode 100644
index 00..9fe94410c91c49
--- /dev/null
+++ b/clang/test/Sema/avr-size-align.c
@@ -0,0 +1,49 @@
+// RUN: %clang_cc1 %s -triple avr -fsyntax-only
+
+_Static_assert(sizeof(char) == 1, "sizeof(char) == 1");
+_Static_assert(_Alignof(char) == 1, "_Alignof(char) == 1");
+_Static_assert(__alignof(char) == 1, "__alignof(char) == 1");
+
+_Static_assert(sizeof(short) == 2, "sizeof(short) == 2");
+_Static_assert(_Alignof(short) == 1, "_Alignof(short) == 1");
+_Static_assert(__alignof(short) == 1, "__alignof(short) == 1");
+
+_Static_assert(sizeof(unsigned short) == 2, "sizeof(unsigned short) == 2");
+_Static_assert(_Alignof(unsigned short) == 1, "_Alignof(unsigned short) == 1");
+_Static_assert(__alignof(unsigned short) == 1, "__alignof(unsigned short) == 
1");
+
+_Static_assert(sizeof(int) == 2, "sizeof(int) == 2");
+_Static_assert(_Alignof(int) == 1, "_Alignof(int) == 1");
+_Static_assert(__alignof(int) == 1, "__alignof(int) == 1");
+
+_Static_assert(sizeof(unsigned int) == 2, "sizeof(unsigned int) == 2");
+_Static_assert(_Alignof(unsigned int) == 1, "_Alignof(unsigned int) == 1");
+_Static_assert(__alignof(unsigned int) == 1, "__alignof(unsigned int) == 1");
+
+_Static_assert(sizeof(long) == 4, "sizeof(long) == 4");
+_Static_assert(_Alignof(long) == 1, "_Alignof(long) == 1");
+_Static_assert(__alignof(long) == 1, "__alignof(long) == 1");
+
+_Static_assert(sizeof(unsigned long) == 4, "s

[clang] [clang][AVR] Fix basic type size/alignment values to match avr-gcc. (PR #111290)

2024-10-06 Thread Alex Rønne Petersen via cfe-commits

alexrp wrote:

cc @aykevl

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


[clang] [clang][AVR] Fix basic type size/alignment values to match avr-gcc. (PR #111290)

2024-10-06 Thread Alex Rønne Petersen via cfe-commits

https://github.com/alexrp created 
https://github.com/llvm/llvm-project/pull/111290

Closes #102172.

From ebf2d154386c83104f229e9638b787bf75286de8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= 
Date: Sun, 6 Oct 2024 14:48:48 +0200
Subject: [PATCH] [clang][AVR] Fix basic type size/alignment values to match
 avr-gcc.

Closes #102172.
---
 clang/include/clang/Basic/TargetInfo.h | 12 +++
 clang/lib/Basic/TargetInfo.cpp |  2 ++
 clang/lib/Basic/Targets/AVR.h  |  4 +++
 clang/test/Sema/avr-size-align.c   | 49 ++
 4 files changed, 60 insertions(+), 7 deletions(-)
 create mode 100644 clang/test/Sema/avr-size-align.c

diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 57783850606290..e7469e1e989128 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -87,6 +87,7 @@ enum class FloatModeKind {
 struct TransferrableTargetInfo {
   unsigned char PointerWidth, PointerAlign;
   unsigned char BoolWidth, BoolAlign;
+  unsigned char ShortWidth, ShortAlign;
   unsigned char IntWidth, IntAlign;
   unsigned char HalfWidth, HalfAlign;
   unsigned char BFloat16Width, BFloat16Align;
@@ -497,13 +498,10 @@ class TargetInfo : public TransferrableTargetInfo,
   unsigned getCharWidth() const { return 8; } // FIXME
   unsigned getCharAlign() const { return 8; } // FIXME
 
-  /// Return the size of 'signed short' and 'unsigned short' for this
-  /// target, in bits.
-  unsigned getShortWidth() const { return 16; } // FIXME
-
-  /// Return the alignment of 'signed short' and 'unsigned short' for
-  /// this target.
-  unsigned getShortAlign() const { return 16; } // FIXME
+  /// getShortWidth/Align - Return the size of 'signed short' and
+  /// 'unsigned short' for this target, in bits.
+  unsigned getShortWidth() const { return ShortWidth; }
+  unsigned getShortAlign() const { return ShortAlign; }
 
   /// getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' 
for
   /// this target, in bits.
diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index 92195333821097..145ca545854da7 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/lib/Basic/TargetInfo.cpp
@@ -70,6 +70,7 @@ TargetInfo::TargetInfo(const llvm::Triple &T) : Triple(T) {
   HasStrictFP = false;
   PointerWidth = PointerAlign = 32;
   BoolWidth = BoolAlign = 8;
+  ShortWidth = ShortAlign = 16;
   IntWidth = IntAlign = 32;
   LongWidth = LongAlign = 32;
   LongLongWidth = LongLongAlign = 64;
@@ -437,6 +438,7 @@ void TargetInfo::adjust(DiagnosticsEngine &Diags, 
LangOptions &Opts) {
 // what these normally are for the target.
 // We also define long long and long double here, although the
 // OpenCL standard only mentions these as "reserved".
+ShortWidth = ShortAlign = 16;
 IntWidth = IntAlign = 32;
 LongWidth = LongAlign = 64;
 LongLongWidth = LongLongAlign = 128;
diff --git a/clang/lib/Basic/Targets/AVR.h b/clang/lib/Basic/Targets/AVR.h
index feeb04f37eeba7..0a2f51747f8a7f 100644
--- a/clang/lib/Basic/Targets/AVR.h
+++ b/clang/lib/Basic/Targets/AVR.h
@@ -29,6 +29,8 @@ class LLVM_LIBRARY_VISIBILITY AVRTargetInfo : public 
TargetInfo {
 TLSSupported = false;
 PointerWidth = 16;
 PointerAlign = 8;
+ShortWidth = 16;
+ShortAlign = 8;
 IntWidth = 16;
 IntAlign = 8;
 LongWidth = 32;
@@ -65,6 +67,8 @@ class LLVM_LIBRARY_VISIBILITY AVRTargetInfo : public 
TargetInfo {
 return std::nullopt;
   }
 
+  bool allowsLargerPreferedTypeAlignment() const override { return false; }
+
   BuiltinVaListKind getBuiltinVaListKind() const override {
 return TargetInfo::VoidPtrBuiltinVaList;
   }
diff --git a/clang/test/Sema/avr-size-align.c b/clang/test/Sema/avr-size-align.c
new file mode 100644
index 00..9fe94410c91c49
--- /dev/null
+++ b/clang/test/Sema/avr-size-align.c
@@ -0,0 +1,49 @@
+// RUN: %clang_cc1 %s -triple avr -fsyntax-only
+
+_Static_assert(sizeof(char) == 1, "sizeof(char) == 1");
+_Static_assert(_Alignof(char) == 1, "_Alignof(char) == 1");
+_Static_assert(__alignof(char) == 1, "__alignof(char) == 1");
+
+_Static_assert(sizeof(short) == 2, "sizeof(short) == 2");
+_Static_assert(_Alignof(short) == 1, "_Alignof(short) == 1");
+_Static_assert(__alignof(short) == 1, "__alignof(short) == 1");
+
+_Static_assert(sizeof(unsigned short) == 2, "sizeof(unsigned short) == 2");
+_Static_assert(_Alignof(unsigned short) == 1, "_Alignof(unsigned short) == 1");
+_Static_assert(__alignof(unsigned short) == 1, "__alignof(unsigned short) == 
1");
+
+_Static_assert(sizeof(int) == 2, "sizeof(int) == 2");
+_Static_assert(_Alignof(int) == 1, "_Alignof(int) == 1");
+_Static_assert(__alignof(int) == 1, "__alignof(int) == 1");
+
+_Static_assert(sizeof(unsigned int) == 2, "sizeof(unsigned int) == 2");
+_Static_assert(_Alignof(unsigned int) == 1, "_Alignof(unsigned int) == 1");
+_Static_assert(__alignof(unsigned int) == 1, 

[clang] [clang-tools-extra] RFC: [clang-tidy] [analyzer] Nondeterministic pointer usage improvements (PR #110471)

2024-10-06 Thread via cfe-commits

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


[clang] [llvm] [LLVM] [Clang] Support for Gentoo `*t64` triples (64-bit time_t ABIs) (PR #111302)

2024-10-06 Thread Michał Górny via cfe-commits


@@ -177,6 +177,7 @@ createTargetCodeGenInfo(CodeGenModule &CGM) {
 else if (CodeGenOpts.FloatABI == "hard" ||
  (CodeGenOpts.FloatABI != "soft" &&
   (Triple.getEnvironment() == llvm::Triple::GNUEABIHF ||

mgorny wrote:

Are you asking if we're going to have musl suffixes on Gentoo? No, musl already 
switched to 64-bit `time_t`.

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


[clang] [Clang] fix overload resolution for object parameters with top-level cv-qualifiers in member functions (PR #110435)

2024-10-06 Thread via cfe-commits


@@ -1511,8 +1511,11 @@ static bool IsOverloadOrOverrideImpl(Sema &SemaRef, 
FunctionDecl *New,
   auto NewObjectType = New->getFunctionObjectParameterReferenceType();
   auto OldObjectType = Old->getFunctionObjectParameterReferenceType();
 
-  if (NewObjectType.isConstQualified() != OldObjectType.isConstQualified())
-return false;
+  if (Old->isExplicitObjectMemberFunction() &&
+  OldObjectType.getQualifiers() != NewObjectType.getQualifiers())

cor3ntin wrote:

do we care about `__restrict` @AaronBallman ?

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


[clang] [clang] CWG2398: improve overload resolution backwards compat (PR #107350)

2024-10-06 Thread via cfe-commits

cor3ntin wrote:

Does that implement 
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3310r0.html#wording-to-2
 exactly?

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


[clang] [llvm] [llvm][opt][Transforms][SPIR-V] Enable `InferAddressSpaces` for SPIR-V (PR #110897)

2024-10-06 Thread Alex Voicu via cfe-commits

https://github.com/AlexVlx updated 
https://github.com/llvm/llvm-project/pull/110897

>From 9f3cac44dde7d0adcf6cd090c0b91f57cb1c4dca Mon Sep 17 00:00:00 2001
From: Alex Voicu 
Date: Wed, 2 Oct 2024 11:18:36 +0100
Subject: [PATCH 1/2] Enable `InferAddressSpaces` for SPIR-V.

---
 .../amdgpu-kernel-arg-pointer-type.cu |  62 ++---
 llvm/lib/Target/SPIRV/CMakeLists.txt  |   2 +
 llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp  |  92 +++
 llvm/lib/Target/SPIRV/SPIRVTargetMachine.h|   7 +
 .../Target/SPIRV/SPIRVTargetTransformInfo.h   |   4 +
 .../SPIRV/assumed-addrspace.ll|  31 +++
 .../InferAddressSpaces/SPIRV/basic.ll | 236 ++
 .../SPIRV/infer-address-space.ll  | 211 
 .../SPIRV/infer-addrspacecast.ll  |  65 +
 .../SPIRV/infer-getelementptr.ll  | 108 
 .../SPIRV/insert-pos-assert.ll| 158 
 .../InferAddressSpaces/SPIRV/is.constant.ll   |  57 +
 .../InferAddressSpaces/SPIRV/lit.local.cfg|   2 +
 .../SPIRV/mem-intrinsics.ll   | 145 +++
 .../SPIRV/multiple-uses-of-val.ll |  70 ++
 .../InferAddressSpaces/SPIRV/prefetch.ll  |  60 +
 .../preserving-debugloc-addrspacecast.ll  |  48 
 .../SPIRV/redundant-addrspacecast.ll  |  28 +++
 .../InferAddressSpaces/SPIRV/self-phi.ll  |  29 +++
 .../InferAddressSpaces/SPIRV/volatile.ll  | 187 ++
 20 files changed, 1567 insertions(+), 35 deletions(-)
 create mode 100644 
llvm/test/Transforms/InferAddressSpaces/SPIRV/assumed-addrspace.ll
 create mode 100644 llvm/test/Transforms/InferAddressSpaces/SPIRV/basic.ll
 create mode 100644 
llvm/test/Transforms/InferAddressSpaces/SPIRV/infer-address-space.ll
 create mode 100644 
llvm/test/Transforms/InferAddressSpaces/SPIRV/infer-addrspacecast.ll
 create mode 100644 
llvm/test/Transforms/InferAddressSpaces/SPIRV/infer-getelementptr.ll
 create mode 100644 
llvm/test/Transforms/InferAddressSpaces/SPIRV/insert-pos-assert.ll
 create mode 100644 llvm/test/Transforms/InferAddressSpaces/SPIRV/is.constant.ll
 create mode 100644 llvm/test/Transforms/InferAddressSpaces/SPIRV/lit.local.cfg
 create mode 100644 
llvm/test/Transforms/InferAddressSpaces/SPIRV/mem-intrinsics.ll
 create mode 100644 
llvm/test/Transforms/InferAddressSpaces/SPIRV/multiple-uses-of-val.ll
 create mode 100644 llvm/test/Transforms/InferAddressSpaces/SPIRV/prefetch.ll
 create mode 100644 
llvm/test/Transforms/InferAddressSpaces/SPIRV/preserving-debugloc-addrspacecast.ll
 create mode 100644 
llvm/test/Transforms/InferAddressSpaces/SPIRV/redundant-addrspacecast.ll
 create mode 100644 llvm/test/Transforms/InferAddressSpaces/SPIRV/self-phi.ll
 create mode 100644 llvm/test/Transforms/InferAddressSpaces/SPIRV/volatile.ll

diff --git a/clang/test/CodeGenCUDA/amdgpu-kernel-arg-pointer-type.cu 
b/clang/test/CodeGenCUDA/amdgpu-kernel-arg-pointer-type.cu
index b295bbbdaaf955..15c8b46d278ea1 100644
--- a/clang/test/CodeGenCUDA/amdgpu-kernel-arg-pointer-type.cu
+++ b/clang/test/CodeGenCUDA/amdgpu-kernel-arg-pointer-type.cu
@@ -58,13 +58,11 @@
 // OPT-NEXT:ret void
 //
 // OPT-SPIRV-LABEL: define spir_kernel void @_Z7kernel1Pi(
-// OPT-SPIRV-SAME: ptr addrspace(1) noundef [[X_COERCE:%.*]]) 
local_unnamed_addr addrspace(4) #[[ATTR0:[0-9]+]] {
+// OPT-SPIRV-SAME: ptr addrspace(1) nocapture noundef [[X_COERCE:%.*]]) 
local_unnamed_addr addrspace(4) #[[ATTR0:[0-9]+]] {
 // OPT-SPIRV-NEXT:  [[ENTRY:.*:]]
-// OPT-SPIRV-NEXT:[[TMP0:%.*]] = ptrtoint ptr addrspace(1) [[X_COERCE]] to 
i64
-// OPT-SPIRV-NEXT:[[TMP1:%.*]] = inttoptr i64 [[TMP0]] to ptr addrspace(4)
-// OPT-SPIRV-NEXT:[[TMP2:%.*]] = load i32, ptr addrspace(4) [[TMP1]], 
align 4
-// OPT-SPIRV-NEXT:[[INC:%.*]] = add nsw i32 [[TMP2]], 1
-// OPT-SPIRV-NEXT:store i32 [[INC]], ptr addrspace(4) [[TMP1]], align 4
+// OPT-SPIRV-NEXT:[[TMP0:%.*]] = load i32, ptr addrspace(1) [[X_COERCE]], 
align 4
+// OPT-SPIRV-NEXT:[[INC:%.*]] = add nsw i32 [[TMP0]], 1
+// OPT-SPIRV-NEXT:store i32 [[INC]], ptr addrspace(1) [[X_COERCE]], align 4
 // OPT-SPIRV-NEXT:ret void
 //
 // HOST-LABEL: define dso_local void @_Z22__device_stub__kernel1Pi(
@@ -126,13 +124,11 @@ __global__ void kernel1(int *x) {
 // OPT-NEXT:ret void
 //
 // OPT-SPIRV-LABEL: define spir_kernel void @_Z7kernel2Ri(
-// OPT-SPIRV-SAME: ptr addrspace(1) noundef align 4 dereferenceable(4) 
[[X_COERCE:%.*]]) local_unnamed_addr addrspace(4) #[[ATTR0]] {
+// OPT-SPIRV-SAME: ptr addrspace(1) nocapture noundef align 4 
dereferenceable(4) [[X_COERCE:%.*]]) local_unnamed_addr addrspace(4) #[[ATTR0]] 
{
 // OPT-SPIRV-NEXT:  [[ENTRY:.*:]]
-// OPT-SPIRV-NEXT:[[TMP0:%.*]] = ptrtoint ptr addrspace(1) [[X_COERCE]] to 
i64
-// OPT-SPIRV-NEXT:[[TMP1:%.*]] = inttoptr i64 [[TMP0]] to ptr addrspace(4)
-// OPT-SPIRV-NEXT:[[TMP2:%.*]] = load i32, ptr addrspace(4) [[TMP1]], 
align 4
-// OPT-SPIRV-NEXT:[[INC:%.*]] = add n

[clang] [llvm] [clang][llvm][SPIR-V] Explicitly encode native integer widths for SPIR-V (PR #110695)

2024-10-06 Thread Alex Voicu via cfe-commits

https://github.com/AlexVlx updated 
https://github.com/llvm/llvm-project/pull/110695

>From 758fb6e28844d89031b5497d651cb2a9b71b6a0e Mon Sep 17 00:00:00 2001
From: Alex Voicu 
Date: Tue, 1 Oct 2024 17:10:50 +0100
Subject: [PATCH 1/2] Explicitly encode native integer widths for SPIR-V.

---
 clang/lib/Basic/Targets/SPIR.h| 16 +++---
 clang/test/CodeGen/target-data.c  |  2 +-
 clang/test/CodeGenOpenCL/builtins-amdgcn.cl   |  2 +-
 llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp  | 12 ++--
 .../SPIRV/optimizations/add-check-overflow.ll | 56 ---
 5 files changed, 16 insertions(+), 72 deletions(-)
 delete mode 100644 llvm/test/CodeGen/SPIRV/optimizations/add-check-overflow.ll

diff --git a/clang/lib/Basic/Targets/SPIR.h b/clang/lib/Basic/Targets/SPIR.h
index cc79562de2871e..09d4ad3c0ac620 100644
--- a/clang/lib/Basic/Targets/SPIR.h
+++ b/clang/lib/Basic/Targets/SPIR.h
@@ -314,8 +314,8 @@ class LLVM_LIBRARY_VISIBILITY SPIRVTargetInfo : public 
BaseSPIRVTargetInfo {
 
 // SPIR-V IDs are represented with a single 32-bit word.
 SizeType = TargetInfo::UnsignedInt;
-resetDataLayout("e-i64:64-v16:16-v24:32-v32:32-v48:64-"
-"v96:128-v192:256-v256:256-v512:512-v1024:1024-G1");
+resetDataLayout("e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-"
+"v256:256-v512:512-v1024:1024-n8:16:32:64-G1");
   }
 
   void getTargetDefines(const LangOptions &Opts,
@@ -338,8 +338,8 @@ class LLVM_LIBRARY_VISIBILITY SPIRV32TargetInfo : public 
BaseSPIRVTargetInfo {
 // SPIR-V has core support for atomic ops, and Int32 is always available;
 // we take the maximum because it's possible the Host supports wider types.
 MaxAtomicInlineWidth = std::max(MaxAtomicInlineWidth, 32);
-resetDataLayout("e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-"
-"v96:128-v192:256-v256:256-v512:512-v1024:1024-G1");
+resetDataLayout("e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-"
+"v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64-G1");
   }
 
   void getTargetDefines(const LangOptions &Opts,
@@ -362,8 +362,8 @@ class LLVM_LIBRARY_VISIBILITY SPIRV64TargetInfo : public 
BaseSPIRVTargetInfo {
 // SPIR-V has core support for atomic ops, and Int64 is always available;
 // we take the maximum because it's possible the Host supports wider types.
 MaxAtomicInlineWidth = std::max(MaxAtomicInlineWidth, 64);
-resetDataLayout("e-i64:64-v16:16-v24:32-v32:32-v48:64-"
-"v96:128-v192:256-v256:256-v512:512-v1024:1024-G1");
+resetDataLayout("e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-"
+"v256:256-v512:512-v1024:1024-n8:16:32:64-G1");
   }
 
   void getTargetDefines(const LangOptions &Opts,
@@ -388,8 +388,8 @@ class LLVM_LIBRARY_VISIBILITY SPIRV64AMDGCNTargetInfo final
 PtrDiffType = IntPtrType = TargetInfo::SignedLong;
 AddrSpaceMap = &SPIRDefIsGenMap;
 
-resetDataLayout("e-i64:64-v16:16-v24:32-v32:32-v48:64-"
-"v96:128-v192:256-v256:256-v512:512-v1024:1024-G1-P4-A0");
+resetDataLayout("e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-"
+"v256:256-v512:512-v1024:1024-n32:64-S32-G1-P4-A0");
 
 BFloat16Width = BFloat16Align = 16;
 BFloat16Format = &llvm::APFloat::BFloat();
diff --git a/clang/test/CodeGen/target-data.c b/clang/test/CodeGen/target-data.c
index 8548aa00cfe877..fa875fe68b0c5b 100644
--- a/clang/test/CodeGen/target-data.c
+++ b/clang/test/CodeGen/target-data.c
@@ -271,4 +271,4 @@
 
 // RUN: %clang_cc1 -triple spirv64-amd-amdhsa -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=AMDGPUSPIRV64
-// AMDGPUSPIRV64: target datalayout = 
"e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-G1-P4-A0"
+// AMDGPUSPIRV64: target datalayout = 
"e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n32:64-S32-G1-P4-A0"
diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn.cl
index bf5f2971cf118c..9132cc8a717e0f 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn.cl
@@ -638,7 +638,7 @@ void test_get_workgroup_size(int d, global int *out)
 
 // CHECK-LABEL: @test_get_grid_size(
 // CHECK: {{.*}}call align 4 dereferenceable(64){{.*}} ptr addrspace(4) 
@llvm.amdgcn.dispatch.ptr()
-// CHECK: getelementptr inbounds i8, ptr addrspace(4) %{{.*}}, i64 %.sink
+// CHECK: getelementptr inbounds i8, ptr addrspace(4) %{{.*}}, i64 %{{.+}}
 // CHECK: load i32, ptr addrspace(4) %{{.*}}, align 4, !invariant.load
 void test_get_grid_size(int d, global int *out)
 {
diff --git a/llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp 
b/llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp
index e5384b2eb2c2c1..50c881a19cf58b 100644
--- a/llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp
@@ -54,14 +54,14 @@ sta

[clang] [clang][HIP] Don't use the OpenCLKernel CC when targeting AMDGCNSPIRV (PR #110447)

2024-10-06 Thread Alex Voicu via cfe-commits

https://github.com/AlexVlx updated 
https://github.com/llvm/llvm-project/pull/110447

>From f65d933740225122d832a340b89fe4da0d80a204 Mon Sep 17 00:00:00 2001
From: Alex Voicu 
Date: Mon, 30 Sep 2024 03:09:58 +0100
Subject: [PATCH] Don't use the OpenCLKernel CC when targeting AMDGCNSPIRV.

---
 clang/lib/CodeGen/CGDeclCXX.cpp   | 10 --
 clang/lib/Sema/SemaType.cpp   |  8 
 clang/test/CodeGenCUDA/device-init-fun.cu |  6 ++
 clang/test/CodeGenCUDA/kernel-amdgcn.cu   |  8 +++-
 4 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index c44f38ef02a3f1..19dea3a55f28c7 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -815,7 +815,10 @@ void CodeGenModule::EmitCXXModuleInitFunc(Module *Primary) 
{
   assert(!getLangOpts().CUDA || !getLangOpts().CUDAIsDevice ||
  getLangOpts().GPUAllowDeviceInit);
   if (getLangOpts().HIP && getLangOpts().CUDAIsDevice) {
-Fn->setCallingConv(llvm::CallingConv::AMDGPU_KERNEL);
+if (getTriple().isSPIRV())
+  Fn->setCallingConv(llvm::CallingConv::SPIR_KERNEL);
+else
+  Fn->setCallingConv(llvm::CallingConv::AMDGPU_KERNEL);
 Fn->addFnAttr("device-init");
   }
 
@@ -973,7 +976,10 @@ CodeGenModule::EmitCXXGlobalInitFunc() {
   assert(!getLangOpts().CUDA || !getLangOpts().CUDAIsDevice ||
  getLangOpts().GPUAllowDeviceInit);
   if (getLangOpts().HIP && getLangOpts().CUDAIsDevice) {
-Fn->setCallingConv(llvm::CallingConv::AMDGPU_KERNEL);
+if (getTriple().isSPIRV())
+  Fn->setCallingConv(llvm::CallingConv::SPIR_KERNEL);
+else
+  Fn->setCallingConv(llvm::CallingConv::AMDGPU_KERNEL);
 Fn->addFnAttr("device-init");
   }
 
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index a7beb9d222c3b5..0024f9d16983ed 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -3734,12 +3734,12 @@ static CallingConv getCCForDeclaratorChunk(
   }
 }
   } else if (S.getLangOpts().CUDA) {
-// If we're compiling CUDA/HIP code and targeting SPIR-V we need to make
+// If we're compiling CUDA/HIP code and targeting HIPSPV we need to make
 // sure the kernels will be marked with the right calling convention so 
that
-// they will be visible by the APIs that ingest SPIR-V.
+// they will be visible by the APIs that ingest SPIR-V. We do not do this
+// when targeting AMDGCNSPIRV, as it does not rely on OpenCL.
 llvm::Triple Triple = S.Context.getTargetInfo().getTriple();
-if (Triple.getArch() == llvm::Triple::spirv32 ||
-Triple.getArch() == llvm::Triple::spirv64) {
+if (Triple.isSPIRV() && Triple.getVendor() != llvm::Triple::AMD) {
   for (const ParsedAttr &AL : D.getDeclSpec().getAttributes()) {
 if (AL.getKind() == ParsedAttr::AT_CUDAGlobal) {
   CC = CC_OpenCLKernel;
diff --git a/clang/test/CodeGenCUDA/device-init-fun.cu 
b/clang/test/CodeGenCUDA/device-init-fun.cu
index 4f3119a2269c61..aaf5b1be72b842 100644
--- a/clang/test/CodeGenCUDA/device-init-fun.cu
+++ b/clang/test/CodeGenCUDA/device-init-fun.cu
@@ -4,11 +4,17 @@
 // RUN: -fgpu-allow-device-init -x hip \
 // RUN: -fno-threadsafe-statics -emit-llvm -o - %s \
 // RUN: | FileCheck %s
+// RUN: %clang_cc1 -triple spirv64-amd-amdhsa -fcuda-is-device -std=c++11 \
+// RUN: -fgpu-allow-device-init -x hip \
+// RUN: -fno-threadsafe-statics -emit-llvm -o - %s \
+// RUN: | FileCheck %s --check-prefix=CHECK-SPIRV
 
 #include "Inputs/cuda.h"
 
 // CHECK: define internal amdgpu_kernel void 
@_GLOBAL__sub_I_device_init_fun.cu() #[[ATTR:[0-9]*]]
 // CHECK: attributes #[[ATTR]] = {{.*}}"device-init"
+// CHECK-SPIRV: define internal spir_kernel void 
@_GLOBAL__sub_I_device_init_fun.cu(){{.*}} #[[ATTR:[0-9]*]]
+// CHECK-SPIRV: attributes #[[ATTR]] = {{.*}}"device-init"
 
 __device__ void f();
 
diff --git a/clang/test/CodeGenCUDA/kernel-amdgcn.cu 
b/clang/test/CodeGenCUDA/kernel-amdgcn.cu
index 48473b92ccff3b..8b971666990992 100644
--- a/clang/test/CodeGenCUDA/kernel-amdgcn.cu
+++ b/clang/test/CodeGenCUDA/kernel-amdgcn.cu
@@ -1,31 +1,37 @@
 // RUN: %clang_cc1 -triple amdgcn -fcuda-is-device -emit-llvm -x hip %s -o - | 
FileCheck %s
+// RUN: %clang_cc1 -triple spirv64-amd-amdhsa -fcuda-is-device -emit-llvm -x 
hip %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
 #include "Inputs/cuda.h"
 
 // CHECK: define{{.*}} amdgpu_kernel void @_ZN1A6kernelEv
+// CHECK-SPIRV: define{{.*}} spir_kernel void @_ZN1A6kernelEv
 class A {
 public:
   static __global__ void kernel(){}
 };
 
 // CHECK: define{{.*}} void @_Z10non_kernelv
+// CHECK-SPIRV: define{{.*}} void @_Z10non_kernelv
 __device__ void non_kernel(){}
 
 // CHECK: define{{.*}} amdgpu_kernel void @_Z6kerneli
+// CHECK-SPIRV: define{{.*}} spir_kernel void @_Z6kerneli
 __global__ void kernel(int x) {
   non_kernel();
 }
 
 // CHECK: define{{.*}} amdgpu_kernel void @_Z11EmptyKernelIvEv

[clang] [libcxx] [Clang] Add __builtin_common_type (PR #99473)

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


@@ -14,16 +14,30 @@
 #include <__type_traits/decay.h>
 #include <__type_traits/is_same.h>
 #include <__type_traits/remove_cvref.h>
+#include <__type_traits/type_identity.h>
 #include <__type_traits/void_t.h>
 #include <__utility/declval.h>
+#include <__utility/empty.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
 #endif
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if _LIBCPP_STD_VER >= 20
+#if __has_builtin(__builtin_common_type)
+
+template 
+struct common_type;
+
+template 
+using __common_type_t = typename common_type<_Args...>::type;
+
+template 
+struct common_type : __builtin_common_type<__common_type_t, __type_identity, 
__empty, _Args...> {};

philnik777 wrote:

@ldionne I think you actually want to export `__type_traits/type_identity.h` 
and `__utility/empty.h`, since the alias resolves to one of these types in the 
end.

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


[compiler-rt] [libcxx] [libcxxabi] [libunwind] [libunwind][libcxx][libcxxabi][compiler-rt-builtins] Fix Exception Handling build for wasm (PR #79667)

2024-10-06 Thread via cfe-commits

https://github.com/trcrsired updated 
https://github.com/llvm/llvm-project/pull/79667

>From 2b526821d4e70f3ea83f95d25f804d9fbcf82612 Mon Sep 17 00:00:00 2001
From: cqwrteur <100043421+trcrsi...@users.noreply.github.com>
Date: Sat, 1 Jun 2024 02:55:50 -0400
Subject: [PATCH] [libunwind][libcxx][libcxxabi] Fix Exception Handling build
 for wasm

The wasm unwind build appears to be dysfunctional, likely because the author 
has only supplied a customized LLVM build on request, rather than a fully 
functional patch.

This patch fixes the build

Apply formatting patch proposed by github bot

use "" to prevent CMAKE_SYSTEM_PROCESSOR not defined

[libunwind] logAPI functions should also be built

[libcxxabi] Fix function signatures for wasm

wasm does not define the function signatures correctly for cxxabi
Fix them

Fix formatting issues for libcxxabi's wasm eh change

Merge remote-tracking branch 'parent/main' into wasmlibunwindfix

remove unwanted changes in unwind-wasm.c

Make Unwind-wasm.c compile correctly without workaround in
CMakeLists.txt

using __wasm__ macro to guard against all wasm eh build

fix UnwindLevel.c's formatting issue

ISO C requires a translation unit to contain at least one declaration 
[-Werror,-Wempty-translation-unit]

compiler-rt does not define CMP_RESULT correct on wasm64
Fixed

Merge code
---
 compiler-rt/lib/builtins/fp_compare_impl.inc |   2 +-
 libcxx/include/__exception/exception_ptr.h   |  21 +-
 libcxxabi/include/cxxabi.h   | 134 ++--
 libcxxabi/src/cxa_exception.cpp  | 710 ---
 libcxxabi/src/cxa_exception.h|   7 +-
 libunwind/include/libunwind.h|   2 +
 libunwind/src/Unwind-wasm.c  |  13 +-
 libunwind/src/UnwindRegistersRestore.S   |   3 +-
 libunwind/src/UnwindRegistersSave.S  |   3 +
 libunwind/src/assembly.h |   2 +
 libunwind/src/cet_unwind.h   |   3 +
 libunwind/src/config.h   |  15 +-
 libunwind/src/libunwind.cpp  |   2 +
 libunwind/src/libunwind_ext.h|   2 +
 14 files changed, 403 insertions(+), 516 deletions(-)

diff --git a/compiler-rt/lib/builtins/fp_compare_impl.inc 
b/compiler-rt/lib/builtins/fp_compare_impl.inc
index a9a4f6fbf5dfe4..83bdea46a45da4 100644
--- a/compiler-rt/lib/builtins/fp_compare_impl.inc
+++ b/compiler-rt/lib/builtins/fp_compare_impl.inc
@@ -12,7 +12,7 @@
 // functions. We need to ensure that the return value is sign-extended in the
 // same way as GCC expects (since otherwise GCC-generated __builtin_isinf
 // returns true for finite 128-bit floating-point numbers).
-#ifdef __aarch64__
+#if defined(__aarch64__) || defined(__wasm__)
 // AArch64 GCC overrides libgcc_cmp_return to use int instead of long.
 typedef int CMP_RESULT;
 #elif __SIZEOF_POINTER__ == 8 && __SIZEOF_LONG__ == 4
diff --git a/libcxx/include/__exception/exception_ptr.h 
b/libcxx/include/__exception/exception_ptr.h
index 9e5351f534a1c1..84a78d378cc19f 100644
--- a/libcxx/include/__exception/exception_ptr.h
+++ b/libcxx/include/__exception/exception_ptr.h
@@ -29,22 +29,21 @@
 
 namespace __cxxabiv1 {
 
+#if defined(__wasm__)
+typedef void* (*__libcpp_exception_destructor_func)(void*);
+#elif defined(_WIN32)
+typedef void(__thiscall* __libcpp_exception_destructor_func)(void*);
+#else
+typedef void (*__libcpp_exception_destructor_func)(void*);
+#endif
+
 extern "C" {
 _LIBCPP_OVERRIDABLE_FUNC_VIS void* __cxa_allocate_exception(size_t) throw();
 _LIBCPP_OVERRIDABLE_FUNC_VIS void __cxa_free_exception(void*) throw();
 
 struct __cxa_exception;
-_LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception* __cxa_init_primary_exception(
-void*,
-std::type_info*,
-#if defined(_WIN32)
-void(__thiscall*)(void*)) throw();
-#elif defined(__wasm__)
-// In Wasm, a destructor returns its argument
-void* (*)(void*)) throw();
-#else
-void (*)(void*)) throw();
-#endif
+_LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception*
+__cxa_init_primary_exception(void*, std::type_info*, 
__libcpp_exception_destructor_func) throw();
 }
 
 } // namespace __cxxabiv1
diff --git a/libcxxabi/include/cxxabi.h b/libcxxabi/include/cxxabi.h
index 9ea93680f62e06..cf0cc40ff42b9e 100644
--- a/libcxxabi/include/cxxabi.h
+++ b/libcxxabi/include/cxxabi.h
@@ -20,49 +20,41 @@
 #include <__cxxabi_config.h>
 
 #define _LIBCPPABI_VERSION 15000
-#define _LIBCXXABI_NORETURN  __attribute__((noreturn))
+#define _LIBCXXABI_NORETURN __attribute__((noreturn))
 #define _LIBCXXABI_ALWAYS_COLD __attribute__((cold))
 
 #ifdef __cplusplus
 
 namespace std {
-#if defined(_WIN32)
+#  if defined(_WIN32)
 class _LIBCXXABI_TYPE_VIS type_info; // forward declaration
-#else
+#  else
 class type_info; // forward declaration
-#endif
-}
-
+#  endif
+} // namespace std
 
 // runtime routines use C calling conventions, but are in __cxxabiv1 namespace
 namespace __cxxabiv1 {
 
 struct __cxa_exception;
+#  if defined(__wasm__)
+typedef 

[clang] [clang] Support --sysroot= for ${arch}-windows-msvc targets (PR #96417)

2024-10-06 Thread via cfe-commits

https://github.com/trcrsired updated 
https://github.com/llvm/llvm-project/pull/96417

>From bb0ba5eb70616ef781eaa6003b756f1bb8dc0c95 Mon Sep 17 00:00:00 2001
From: trcrsired 
Date: Sun, 23 Jun 2024 00:07:19 -0400
Subject: [PATCH] Support --sysroot= for ${arch}-windows-msvc targets

I think it is possible to use the same rule for msvc targets with
--target= and --sysroot=

See Repository:
https://github.com/trcrsired/windows-msvc-sysroot

Add sysroot support for msvc

MSVC.cpp needs getDriver before using D

add stl in parser for -stdlib=

Add Vcruntime to runtime list and unwind list

MSVC add default runtime lib type and default unwind lib type

add a msvc sysroot test

use %S instead of /foo

Fix test for msvc-sysroot

Also add a pesudo implementation for WebAssembly and
maybe Microsoft STL could be ported to more targets in the future

Fix the toggle of wasm that prevents -stdlib=stl passed into

Avoid clang-formatting in MSVC.cpp

Add some comments to ToolChain

avoid indent the if block

Add back space before winsysroot line

use  instead of arch in the comment

remove FIXME for libc++ since we have added the logic here

Remove MSVC.h formatting

Remove default cases in WebAssembly

add back the empty line before the Sysroot line

fix msvc-sysroot typo for libc++ loongarch

Fix : missing in CST_Stl case
---
 clang/include/clang/Driver/ToolChain.h  |  11 +-
 clang/lib/Driver/ToolChain.cpp  |  10 ++
 clang/lib/Driver/ToolChains/MSVC.cpp| 128 +++-
 clang/lib/Driver/ToolChains/MSVC.h  |  15 +++
 clang/lib/Driver/ToolChains/WebAssembly.cpp |  25 
 clang/lib/Driver/ToolChains/WebAssembly.h   |   2 +
 clang/test/Driver/msvc-sysroot.cpp  |  81 +
 clang/test/Driver/wasm-toolchain.cpp|  12 ++
 8 files changed, 279 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/Driver/msvc-sysroot.cpp

diff --git a/clang/include/clang/Driver/ToolChain.h 
b/clang/include/clang/Driver/ToolChain.h
index 5347e29be91439..81e4e46f5806ae 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -94,19 +94,22 @@ class ToolChain {
   using path_list = SmallVector;
 
   enum CXXStdlibType {
-CST_Libcxx,
-CST_Libstdcxx
+CST_Libcxx, // LLVM libc++
+CST_Libstdcxx,  // GNU libstdc++
+CST_Stl,  // MSVC STL
   };
 
   enum RuntimeLibType {
 RLT_CompilerRT,
-RLT_Libgcc
+RLT_Libgcc,
+RLT_Vcruntime
   };
 
   enum UnwindLibType {
 UNW_None,
 UNW_CompilerRT,
-UNW_Libgcc
+UNW_Libgcc,
+UNW_Vcruntime
   };
 
   enum class UnwindTableLevel {
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index de250322b3b34d..c533260e5a7baf 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -1148,6 +1148,8 @@ ToolChain::RuntimeLibType ToolChain::GetRuntimeLibType(
 runtimeLibType = ToolChain::RLT_CompilerRT;
   else if (LibName == "libgcc")
 runtimeLibType = ToolChain::RLT_Libgcc;
+  else if (LibName == "vcruntime")
+runtimeLibType = ToolChain::RLT_Vcruntime;
   else if (LibName == "platform")
 runtimeLibType = GetDefaultRuntimeLibType();
   else {
@@ -1186,6 +1188,8 @@ ToolChain::UnwindLibType ToolChain::GetUnwindLibType(
 unwindLibType = ToolChain::UNW_CompilerRT;
   } else if (LibName == "libgcc")
 unwindLibType = ToolChain::UNW_Libgcc;
+  else if (LibName == "vcruntime")
+unwindLibType = ToolChain::UNW_Vcruntime;
   else {
 if (A)
   getDriver().Diag(diag::err_drv_invalid_unwindlib_name)
@@ -1209,6 +1213,8 @@ ToolChain::CXXStdlibType 
ToolChain::GetCXXStdlibType(const ArgList &Args) const{
 cxxStdlibType = ToolChain::CST_Libcxx;
   else if (LibName == "libstdc++")
 cxxStdlibType = ToolChain::CST_Libstdcxx;
+  else if (LibName == "stl")
+cxxStdlibType = ToolChain::CST_Stl;
   else if (LibName == "platform")
 cxxStdlibType = GetDefaultCXXStdlibType();
   else {
@@ -1347,6 +1353,10 @@ void ToolChain::AddCXXStdlibLibArgs(const ArgList &Args,
   case ToolChain::CST_Libstdcxx:
 CmdArgs.push_back("-lstdc++");
 break;
+
+  case ToolChain::CST_Stl:
+// MSVC STL does not need to add -l
+break;
   }
 }
 
diff --git a/clang/lib/Driver/ToolChains/MSVC.cpp 
b/clang/lib/Driver/ToolChains/MSVC.cpp
index 80799d1e715f07..e5edd6f3abf9f3 100644
--- a/clang/lib/Driver/ToolChains/MSVC.cpp
+++ b/clang/lib/Driver/ToolChains/MSVC.cpp
@@ -90,6 +90,16 @@ void visualstudio::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 CmdArgs.push_back("-defaultlib:oldnames");
   }
 
+  auto SysRoot = TC.getDriver().SysRoot;
+  if (!SysRoot.empty()) {
+// If we have --sysroot, then we ignore all other setings
+// libpath is $SYSROOT/lib and $SYSROOT/lib/${ARCH}-unknown-windows-msvc
+const std::string MultiarchTriple =
+TC.getMultiarchTriple(TC.getDriver(), TC.getTriple(), SysRoot);
+std::string SysRootLib = "-libpath:" + SysRoot + "/lib";
+CmdA

[clang-tools-extra] acf92a4 - [clang-tidy] Avoid capturing a local variable in a static lambda in UseRangesCheck (#111282)

2024-10-06 Thread via cfe-commits

Author: Nathan Ridge
Date: 2024-10-06T18:13:36-04:00
New Revision: acf92a47c0ece8562fd745215c478fe2d4ab5896

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

LOG: [clang-tidy] Avoid capturing a local variable in a static lambda in 
UseRangesCheck (#111282)

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/boost/UseRangesCheck.cpp
clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/boost/UseRangesCheck.cpp 
b/clang-tools-extra/clang-tidy/boost/UseRangesCheck.cpp
index 4022ea0cdaf5ee..e45687fde6d9f6 100644
--- a/clang-tools-extra/clang-tidy/boost/UseRangesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/boost/UseRangesCheck.cpp
@@ -204,7 +204,7 @@ utils::UseRangesCheck::ReplacerMap 
UseRangesCheck::getReplacerMap() const {
   ReplacerMap Results;
   static const Signature SingleSig = {{0}};
   static const Signature TwoSig = {{0}, {2}};
-  static const auto AddFrom =
+  const auto AddFrom =
   [&Results](llvm::IntrusiveRefCntPtr Replacer,
  std::initializer_list Names, StringRef Prefix) {
 llvm::SmallString<64> Buffer;
@@ -214,17 +214,17 @@ utils::UseRangesCheck::ReplacerMap 
UseRangesCheck::getReplacerMap() const {
 }
   };
 
-  static const auto AddFromStd =
-  [](llvm::IntrusiveRefCntPtr Replacer,
- std::initializer_list Names) {
+  const auto AddFromStd =
+  [&](llvm::IntrusiveRefCntPtr Replacer,
+  std::initializer_list Names) {
 AddFrom(Replacer, Names, "std");
   };
 
-  static const auto AddFromBoost =
-  [](llvm::IntrusiveRefCntPtr Replacer,
- std::initializer_list<
- std::pair>>
- NamespaceAndNames) {
+  const auto AddFromBoost =
+  [&](llvm::IntrusiveRefCntPtr Replacer,
+  std::initializer_list<
+  std::pair>>
+  NamespaceAndNames) {
 for (auto [Namespace, Names] : NamespaceAndNames)
   AddFrom(Replacer, Names,
   SmallString<64>{"boost", (Namespace.empty() ? "" : "::"),

diff  --git a/clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp 
b/clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
index 75a140767035b2..49a94045ea4878 100644
--- a/clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
+++ b/clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp
@@ -262,6 +262,22 @@ TEST_F(LSPTest, ClangTidyRename) {
   EXPECT_EQ(Params, std::vector{llvm::json::Value(std::move(ExpectedEdit))});
 }
 
+TEST_F(LSPTest, ClangTidyCrash_Issue109367) {
+  // This test requires clang-tidy checks to be linked in.
+  if (!CLANGD_TIDY_CHECKS)
+return;
+  Opts.ClangTidyProvider = [](tidy::ClangTidyOptions &ClangTidyOpts,
+  llvm::StringRef) {
+ClangTidyOpts.Checks = {"-*,boost-use-ranges"};
+  };
+  // Check that registering the boost-use-ranges checker's matchers
+  // on two 
diff erent threads does not cause a crash.
+  auto &Client = start();
+  Client.didOpen("a.cpp", "");
+  Client.didOpen("b.cpp", "");
+  Client.sync();
+}
+
 TEST_F(LSPTest, IncomingCalls) {
   Annotations Code(R"cpp(
 void calle^e(int);



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


[clang-tools-extra] [clang-tidy] Avoid capturing a local variable in a static lambda in UseRangesCheck (PR #111282)

2024-10-06 Thread Nathan Ridge via cfe-commits

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


[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)

2024-10-06 Thread Owen Pan via cfe-commits


@@ -302,47 +302,46 @@ TEST(ConfigParseTest, ParsesConfiguration) {
 Style.FIELD.Enabled = true;
\
 CHECK_PARSE(   
\
 #FIELD ": None", FIELD,
\
-FormatStyle::AlignConsecutiveStyle(
\
-{/*Enabled=*/false, /*AcrossEmptyLines=*/false,
\
- /*AcrossComments=*/false, /*AlignCompound=*/false,
\
- /*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
\
+FormatStyle::AlignConsecutiveStyle({}));   
\
 CHECK_PARSE(   
\
 #FIELD ": Consecutive", FIELD, 
\
 FormatStyle::AlignConsecutiveStyle(
\
 {/*Enabled=*/true, /*AcrossEmptyLines=*/false, 
\
  /*AcrossComments=*/false, /*AlignCompound=*/false,
\
+ /*AlignFunctionDeclarations=*/true,   
\
  /*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
\
 CHECK_PARSE(   
\
 #FIELD ": AcrossEmptyLines", FIELD,
\
 FormatStyle::AlignConsecutiveStyle(
\
 {/*Enabled=*/true, /*AcrossEmptyLines=*/true,  
\
  /*AcrossComments=*/false, /*AlignCompound=*/false,
\
+ /*AlignFunctionDeclarations=*/true,   
\
  /*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
\
 CHECK_PARSE(   
\
 #FIELD ": AcrossEmptyLinesAndComments", FIELD, 
\
 FormatStyle::AlignConsecutiveStyle(
\
 {/*Enabled=*/true, /*AcrossEmptyLines=*/true,  
\
  /*AcrossComments=*/true, /*AlignCompound=*/false, 
\
+ /*AlignFunctionDeclarations=*/true,   
\
  /*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
\
 /* For backwards compability, false / true should still parse */   
\
 CHECK_PARSE(   
\
 #FIELD ": false", FIELD,   
\
-FormatStyle::AlignConsecutiveStyle(
\
-{/*Enabled=*/false, /*AcrossEmptyLines=*/false,
\
- /*AcrossComments=*/false, /*AlignCompound=*/false,
\
- /*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
\
+FormatStyle::AlignConsecutiveStyle({}));   
\
 CHECK_PARSE(   
\
 #FIELD ": true", FIELD,
\
 FormatStyle::AlignConsecutiveStyle(
\
 {/*Enabled=*/true, /*AcrossEmptyLines=*/false, 
\
  /*AcrossComments=*/false, /*AlignCompound=*/false,
\
+ /*AlignFunctionDeclarations=*/true,   
\
  /*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
\

\
 CHECK_PARSE_NESTED_BOOL(FIELD, Enabled);   
\
 CHECK_PARSE_NESTED_BOOL(FIELD, AcrossEmptyLines);  
\
 CHECK_PARSE_NESTED_BOOL(FIELD, AcrossComments);
\
 CHECK_PARSE_NESTED_BOOL(FIELD, AlignCompound); 
\
 CHECK_PARSE_NESTED_BOOL(FIELD, PadOperators);  
\
+CHECK_PARSE_NESTED_BOOL(FIELD, AlignFunctionDeclarations); 
\

owenca wrote:

```suggestion
CHECK_PARSE_NESTED_BOOL(FIELD, AlignFunctionDeclarations); \
CHECK_PARSE_NESTED_BOOL(FIELD, PadOperators);  \
```

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


[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)

2024-10-06 Thread Owen Pan via cfe-commits

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


[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)

2024-10-06 Thread Owen Pan via cfe-commits

https://github.com/owenca commented:

You can run `ninja clang-format-check-format` and/or `git clang-format HEAD~` 
before `git push`.

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


[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)

2024-10-06 Thread Brad House via cfe-commits

https://github.com/bradh352 updated 
https://github.com/llvm/llvm-project/pull/108241

>From 00cbf31807ca8d8e1c0c86c6a691c47835522fe9 Mon Sep 17 00:00:00 2001
From: Brad House 
Date: Wed, 11 Sep 2024 10:27:50 -0400
Subject: [PATCH 1/6] Add AlignFunctionDeclarations attribute to
 AlignConsecutiveDeclarations

Enabling AlignConsecutiveDeclarations also aligns function prototypes
or declarations.  This is often unexpected as typically function
prototypes, especially in public headers, don't use any padding.

Setting AlignFunctionDeclarations to false will skip this alignment.
It is by default set to true to keep compatibility with prior
versions to not make unexpected changes.

Signed-off-by: Brad House 
---
 clang/docs/ClangFormatStyleOptions.rst | 112 +
 clang/include/clang/Format/Format.h|  16 +++
 clang/lib/Format/Format.cpp|  31 --
 clang/lib/Format/WhitespaceManager.cpp |   2 +-
 clang/unittests/Format/ConfigParseTest.cpp |   6 ++
 clang/unittests/Format/FormatTest.cpp  |  22 +++-
 6 files changed, 179 insertions(+), 10 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index a427d7cd40fcdd..042c5f1b5f15b0 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -392,6 +392,22 @@ the configuration (without a prefix: ``Auto``).
   a &= 2;
   bbb = 2;
 
+  * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20`
+  Only for ``AlignConsecutiveDeclarations``. Whether function declarations
+are aligned.
+
+.. code-block:: c++
+
+  true:
+  unsigned int f1(void);
+  void f2(void);
+  size_t   f3(void);
+
+  false:
+  unsigned int f1(void);
+  void f2(void);
+  size_t f3(void);
+
   * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. 
Whether function pointers are
 aligned.
 
@@ -534,6 +550,22 @@ the configuration (without a prefix: ``Auto``).
   a &= 2;
   bbb = 2;
 
+  * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20`
+  Only for ``AlignConsecutiveDeclarations``. Whether function declarations
+are aligned.
+
+.. code-block:: c++
+
+  true:
+  unsigned int f1(void);
+  void f2(void);
+  size_t   f3(void);
+
+  false:
+  unsigned int f1(void);
+  void f2(void);
+  size_t f3(void);
+
   * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. 
Whether function pointers are
 aligned.
 
@@ -676,6 +708,22 @@ the configuration (without a prefix: ``Auto``).
   a &= 2;
   bbb = 2;
 
+  * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20`
+  Only for ``AlignConsecutiveDeclarations``. Whether function declarations
+are aligned.
+
+.. code-block:: c++
+
+  true:
+  unsigned int f1(void);
+  void f2(void);
+  size_t   f3(void);
+
+  false:
+  unsigned int f1(void);
+  void f2(void);
+  size_t f3(void);
+
   * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. 
Whether function pointers are
 aligned.
 
@@ -819,6 +867,22 @@ the configuration (without a prefix: ``Auto``).
   a &= 2;
   bbb = 2;
 
+  * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20`
+  Only for ``AlignConsecutiveDeclarations``. Whether function declarations
+are aligned.
+
+.. code-block:: c++
+
+  true:
+  unsigned int f1(void);
+  void f2(void);
+  size_t   f3(void);
+
+  false:
+  unsigned int f1(void);
+  void f2(void);
+  size_t f3(void);
+
   * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. 
Whether function pointers are
 aligned.
 
@@ -1081,6 +1145,22 @@ the configuration (without a prefix: ``Auto``).
   a &= 2;
   bbb = 2;
 
+  * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20`
+  Only for ``AlignConsecutiveDeclarations``. Whether function declarations
+are aligned.
+
+.. code-block:: c++
+
+  true:
+  unsigned int f1(void);
+  void f2(void);
+  size_t   f3(void);
+
+  false:
+  unsigned int f1(void);
+  void f2(void);
+  size_t f3(void);
+
   * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. 
Whether function pointers are
 aligned.
 
@@ -1221,6 +1301,22 @@ the configuration (without a prefix: ``Auto``).
   a &= 2;
   bbb = 2;
 
+  * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20`
+  Only for ``AlignConsecutiveDeclarations``. Whether function declarations
+are aligned.
+
+.. code-block:: c++
+
+  true:
+  unsigned int f1(void);
+  void f2(void);
+  size_t   f3(void);
+
+  false:
+  unsigned int f1(void);
+  void f2(void);
+  size_t f3(void);
+
   * ``bool AlignFunctionPointers`` Only for ``AlignConsecu

[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)

2024-10-06 Thread Brad House via cfe-commits


@@ -302,47 +302,46 @@ TEST(ConfigParseTest, ParsesConfiguration) {
 Style.FIELD.Enabled = true;
\
 CHECK_PARSE(   
\
 #FIELD ": None", FIELD,
\
-FormatStyle::AlignConsecutiveStyle(
\
-{/*Enabled=*/false, /*AcrossEmptyLines=*/false,
\
- /*AcrossComments=*/false, /*AlignCompound=*/false,
\
- /*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
\
+FormatStyle::AlignConsecutiveStyle({}));   
\
 CHECK_PARSE(   
\
 #FIELD ": Consecutive", FIELD, 
\
 FormatStyle::AlignConsecutiveStyle(
\
 {/*Enabled=*/true, /*AcrossEmptyLines=*/false, 
\
  /*AcrossComments=*/false, /*AlignCompound=*/false,
\
+ /*AlignFunctionDeclarations=*/true,   
\
  /*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
\
 CHECK_PARSE(   
\
 #FIELD ": AcrossEmptyLines", FIELD,
\
 FormatStyle::AlignConsecutiveStyle(
\
 {/*Enabled=*/true, /*AcrossEmptyLines=*/true,  
\
  /*AcrossComments=*/false, /*AlignCompound=*/false,
\
+ /*AlignFunctionDeclarations=*/true,   
\
  /*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
\
 CHECK_PARSE(   
\
 #FIELD ": AcrossEmptyLinesAndComments", FIELD, 
\
 FormatStyle::AlignConsecutiveStyle(
\
 {/*Enabled=*/true, /*AcrossEmptyLines=*/true,  
\
  /*AcrossComments=*/true, /*AlignCompound=*/false, 
\
+ /*AlignFunctionDeclarations=*/true,   
\
  /*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
\
 /* For backwards compability, false / true should still parse */   
\
 CHECK_PARSE(   
\
 #FIELD ": false", FIELD,   
\
-FormatStyle::AlignConsecutiveStyle(
\
-{/*Enabled=*/false, /*AcrossEmptyLines=*/false,
\
- /*AcrossComments=*/false, /*AlignCompound=*/false,
\
- /*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
\
+FormatStyle::AlignConsecutiveStyle({}));   
\
 CHECK_PARSE(   
\
 #FIELD ": true", FIELD,
\
 FormatStyle::AlignConsecutiveStyle(
\
 {/*Enabled=*/true, /*AcrossEmptyLines=*/false, 
\
  /*AcrossComments=*/false, /*AlignCompound=*/false,
\
+ /*AlignFunctionDeclarations=*/true,   
\
  /*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
\

\
 CHECK_PARSE_NESTED_BOOL(FIELD, Enabled);   
\
 CHECK_PARSE_NESTED_BOOL(FIELD, AcrossEmptyLines);  
\
 CHECK_PARSE_NESTED_BOOL(FIELD, AcrossComments);
\
 CHECK_PARSE_NESTED_BOOL(FIELD, AlignCompound); 
\
 CHECK_PARSE_NESTED_BOOL(FIELD, PadOperators);  
\
+CHECK_PARSE_NESTED_BOOL(FIELD, AlignFunctionDeclarations); 
\

bradh352 wrote:

done

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


[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)

2024-10-06 Thread Brad House via cfe-commits

bradh352 wrote:

> You can run `ninja clang-format-check-format` and/or `git clang-format HEAD~` 
> before `git push`.

whoops, sorry about that

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


[clang-tools-extra] [clangd] Add ArgumentLists config option under Completion (PR #111322)

2024-10-06 Thread Nathan Ridge via cfe-commits

https://github.com/HighCommander4 created 
https://github.com/llvm/llvm-project/pull/111322

The new config option is a more flexible version of 
--function-arg-placeholders, allowing users more detailed control of what is 
inserted in argument list position when clangd completes the name of a function 
in a function call context.

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

>From b0c222e3a67c6ec320ae3582d8034c5562e8fe94 Mon Sep 17 00:00:00 2001
From: MK-Alias 
Date: Sun, 6 Oct 2024 20:19:55 -0400
Subject: [PATCH] [clangd] Add ArgumentLists config option under Completion

The new config option is a more flexible version of
--function-arg-placeholders, allowing users more detailed control
of what is inserted in argument list position when clangd completes
the name of a function in a function call context.

Fixes https://github.com/llvm/llvm-project/issues/63565
---
 clang-tools-extra/clangd/ClangdServer.cpp |  1 +
 clang-tools-extra/clangd/CodeComplete.cpp | 26 +--
 clang-tools-extra/clangd/CodeComplete.h   |  9 ---
 clang-tools-extra/clangd/Config.h | 14 ++
 clang-tools-extra/clangd/ConfigCompile.cpp| 15 +++
 clang-tools-extra/clangd/ConfigFragment.h |  8 ++
 clang-tools-extra/clangd/ConfigYAML.cpp   |  4 +++
 clang-tools-extra/clangd/tool/ClangdMain.cpp  | 18 +
 .../clangd/unittests/CodeCompleteTests.cpp| 25 --
 9 files changed, 101 insertions(+), 19 deletions(-)

diff --git a/clang-tools-extra/clangd/ClangdServer.cpp 
b/clang-tools-extra/clangd/ClangdServer.cpp
index e910a80ba0bae9..9b38be04e7ddd7 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -451,6 +451,7 @@ void ClangdServer::codeComplete(PathRef File, Position Pos,
 
 CodeCompleteOpts.MainFileSignals = IP->Signals;
 CodeCompleteOpts.AllScopes = Config::current().Completion.AllScopes;
+CodeCompleteOpts.ArgumentLists = 
Config::current().Completion.ArgumentLists;
 // FIXME(ibiryukov): even if Preamble is non-null, we may want to check
 // both the old and the new version in case only one of them matches.
 CodeCompleteResult Result = clangd::codeComplete(
diff --git a/clang-tools-extra/clangd/CodeComplete.cpp 
b/clang-tools-extra/clangd/CodeComplete.cpp
index 89eee392837af4..adca462b53f0a0 100644
--- a/clang-tools-extra/clangd/CodeComplete.cpp
+++ b/clang-tools-extra/clangd/CodeComplete.cpp
@@ -21,6 +21,7 @@
 #include "AST.h"
 #include "CodeCompletionStrings.h"
 #include "Compiler.h"
+#include "Config.h"
 #include "ExpectedTypes.h"
 #include "Feature.h"
 #include "FileDistance.h"
@@ -350,8 +351,7 @@ struct CodeCompletionBuilder {
 CodeCompletionContext::Kind ContextKind,
 const CodeCompleteOptions &Opts,
 bool IsUsingDeclaration, tok::TokenKind NextTokenKind)
-  : ASTCtx(ASTCtx),
-EnableFunctionArgSnippets(Opts.EnableFunctionArgSnippets),
+  : ASTCtx(ASTCtx), ArgumentLists(Opts.ArgumentLists),
 IsUsingDeclaration(IsUsingDeclaration), NextTokenKind(NextTokenKind) {
 Completion.Deprecated = true; // cleared by any non-deprecated overload.
 add(C, SemaCCS, ContextKind);
@@ -561,6 +561,15 @@ struct CodeCompletionBuilder {
   }
 
   std::string summarizeSnippet() const {
+/// localize ArgumentLists tests for better readability
+const bool None = ArgumentLists == Config::ArgumentListsPolicy::None;
+const bool Open =
+ArgumentLists == Config::ArgumentListsPolicy::OpenDelimiter;
+const bool Delim = ArgumentLists == 
Config::ArgumentListsPolicy::Delimiters;
+const bool Full =
+ArgumentLists == Config::ArgumentListsPolicy::FullPlaceholders ||
+(!None && !Open && !Delim); // <-- failsafe: Full is default
+
 if (IsUsingDeclaration)
   return "";
 auto *Snippet = onlyValue<&BundledEntry::SnippetSuffix>();
@@ -568,7 +577,7 @@ struct CodeCompletionBuilder {
   // All bundles are function calls.
   // FIXME(ibiryukov): sometimes add template arguments to a snippet, e.g.
   // we need to complete 'forward<$1>($0)'.
-  return "($0)";
+  return None ? "" : (Open ? "(" : "($0)");
 
 if (Snippet->empty())
   return "";
@@ -607,7 +616,7 @@ struct CodeCompletionBuilder {
 return "";
   }
 }
-if (EnableFunctionArgSnippets)
+if (Full)
   return *Snippet;
 
 // Replace argument snippets with a simplified pattern.
@@ -622,9 +631,9 @@ struct CodeCompletionBuilder {
 
   bool EmptyArgs = llvm::StringRef(*Snippet).ends_with("()");
   if (Snippet->front() == '<')
-return EmptyArgs ? "<$1>()$0" : "<$1>($0)";
+return None ? "" : (Open ? "<" : (EmptyArgs ? "<$1>()$0" : 
"<$1>($0)"));
   if (Snippet->front() == '(')
-return EmptyArgs ? "()" : "($0)";
+return None ? "" : (Open ? "(" : (EmptyArgs ? "()" : "($0)"));
   return 

  1   2   >