[clang] [RISCV][clang] Optimize memory usage of intrinsic lookup table (PR #77487)

2024-01-15 Thread Craig Topper via cfe-commits


@@ -463,7 +464,7 @@ void 
RISCVIntrinsicManagerImpl::CreateRVVIntrinsicDecl(LookupResult &LR,
 bool RISCVIntrinsicManagerImpl::CreateIntrinsicIfFound(LookupResult &LR,
IdentifierInfo *II,
Preprocessor &PP) {
-  StringRef Name = II->getName();
+  StringRef Name = II->getName().substr(8);

topperc wrote:

Will this cause something like `XXX_vadd_vv` to be recognized as a valid 
RISC-V intrinsic name?

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


[clang] [RISCV][clang] Optimize memory usage of intrinsic lookup table (PR #77487)

2024-01-15 Thread Brandon Wu via cfe-commits


@@ -416,8 +416,10 @@ class RVVIntrinsic {
   RVVTypePtr getOutputType() const { return OutputType; }
   const RVVTypes &getInputTypes() const { return InputTypes; }
   llvm::StringRef getBuiltinName() const { return BuiltinName; }
-  llvm::StringRef getName() const { return Name; }
-  llvm::StringRef getOverloadedName() const { return OverloadedName; }
+  llvm::StringRef getName() const { return "__riscv_" + Name; }

4vtomat wrote:

Do you think converting them to string literal is a good idea?

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


[clang] [RISCV][clang] Optimize memory usage of intrinsic lookup table (PR #77487)

2024-01-15 Thread Brandon Wu via cfe-commits


@@ -416,8 +416,10 @@ class RVVIntrinsic {
   RVVTypePtr getOutputType() const { return OutputType; }
   const RVVTypes &getInputTypes() const { return InputTypes; }
   llvm::StringRef getBuiltinName() const { return BuiltinName; }
-  llvm::StringRef getName() const { return Name; }
-  llvm::StringRef getOverloadedName() const { return OverloadedName; }
+  llvm::StringRef getName() const { return "__riscv_" + Name; }

4vtomat wrote:

I mean, return the temporary string's raw data pointer(const char*).

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


[clang] [RISCV][clang] Optimize memory usage of intrinsic lookup table (PR #77487)

2024-01-15 Thread Craig Topper via cfe-commits


@@ -416,8 +416,10 @@ class RVVIntrinsic {
   RVVTypePtr getOutputType() const { return OutputType; }
   const RVVTypes &getInputTypes() const { return InputTypes; }
   llvm::StringRef getBuiltinName() const { return BuiltinName; }
-  llvm::StringRef getName() const { return Name; }
-  llvm::StringRef getOverloadedName() const { return OverloadedName; }
+  llvm::StringRef getName() const { return "__riscv_" + Name; }

topperc wrote:

You can make the function return a std::string.

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


[clang] [RISCV][clang] Optimize memory usage of intrinsic lookup table (PR #77487)

2024-01-15 Thread Craig Topper via cfe-commits

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


[clang] [RISCV][clang] Optimize memory usage of intrinsic lookup table (PR #77487)

2024-01-15 Thread Craig Topper via cfe-commits


@@ -416,8 +416,10 @@ class RVVIntrinsic {
   RVVTypePtr getOutputType() const { return OutputType; }
   const RVVTypes &getInputTypes() const { return InputTypes; }
   llvm::StringRef getBuiltinName() const { return BuiltinName; }
-  llvm::StringRef getName() const { return Name; }
-  llvm::StringRef getOverloadedName() const { return OverloadedName; }
+  llvm::StringRef getName() const { return "__riscv_" + Name; }

topperc wrote:

That raw pointer is allocated on the heap. It has the same lifetime as the 
std::string temporary.

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


[clang] [RISCV][clang] Optimize memory usage of intrinsic lookup table (PR #77487)

2024-01-15 Thread Brandon Wu via cfe-commits


@@ -463,7 +464,7 @@ void 
RISCVIntrinsicManagerImpl::CreateRVVIntrinsicDecl(LookupResult &LR,
 bool RISCVIntrinsicManagerImpl::CreateIntrinsicIfFound(LookupResult &LR,
IdentifierInfo *II,
Preprocessor &PP) {
-  StringRef Name = II->getName();
+  StringRef Name = II->getName().substr(8);

4vtomat wrote:

Yes, I think we should early return if `consume_front` return `false`.

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


[clang] [RISCV][clang] Optimize memory usage of intrinsic lookup table (PR #77487)

2024-01-15 Thread Brandon Wu via cfe-commits

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


[llvm] [clang-tools-extra] [clang] [LoopVectorize] Refine runtime memory check costs when there is an outer loop (PR #76034)

2024-01-15 Thread David Sherwood via cfe-commits

david-arm wrote:

Gentle ping!

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


[llvm] [clang] [RISCV] Bump Zfbfmin, Zvfbfmin, and Zvfbfwma to 1.0. (PR #78021)

2024-01-15 Thread via cfe-commits

https://github.com/joshua-arch1 commented:

LGTM.

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


[llvm] [clang] Hurd: Add x86_64 support (PR #78065)

2024-01-15 Thread Samuel Thibault via cfe-commits


@@ -78,3 +78,82 @@
 // CHECK-CROSS: 
"{{.*}}/Inputs/basic_cross_hurd_tree/usr/lib/gcc/i686-gnu/10/../../../../i686-gnu/bin/ld"
 {{.*}} "-m" "elf_i386"
 // CHECK-CROSS: 
"{{.*}}/Inputs/basic_cross_hurd_tree/usr/lib/gcc/i686-gnu/10/crtbegin.o"
 // CHECK-CROSS: 
"-L{{.*}}/Inputs/basic_cross_hurd_tree/usr/lib/gcc/i686-gnu/10/../../../../i686-gnu/lib"
+

sthibaul wrote:

it passes fine indeed

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


[clang] [clang][dataflow] Process terminator condition within `transferCFGBlock()`. (PR #78127)

2024-01-15 Thread via cfe-commits

https://github.com/martinboehme created 
https://github.com/llvm/llvm-project/pull/78127

In particular, it's important that we create the "fallback" atomic at this point
(which we produce if the transfer function didn't produce a value for the
expression) so that it is placed in the correct environment.

Previously, we processed the terminator condition in the `TerminatorVisitor`,
which put the fallback atomic in a copy of the environment that is produced as
input for the _successor_ block, rather than the environment for the block
containing the expression for which we produce the fallback atomic.

As a result, we produce different fallback atomics every time we process the
successor block, and hence we don't have a consistent representation of the
terminator condition in the flow condition.

This patch includes a test (authored by ymand@) that fails without the fix.


>From 2e104ab8d306b9f0375391263662426c1b24f55a Mon Sep 17 00:00:00 2001
From: Martin Braenne 
Date: Mon, 15 Jan 2024 08:27:21 +
Subject: [PATCH] [clang][dataflow] Process terminator condition within
 `transferCFGBlock()`.

In particular, it's important that we create the "fallback" atomic at this point
(which we produce if the transfer function didn't produce a value for the
expression) so that it is placed in the correct environment.

Previously, we processed the terminator condition in the `TerminatorVisitor`,
which put the fallback atomic in a copy of the environment that is produced as
input for the _successor_ block, rather than the environment for the block
containing the expression for which we produce the fallback atomic.

As a result, we produce different fallback atomics every time we process the
successor block, and hence we don't have a consistent representation of the
terminator condition in the flow condition.

This patch includes a test (authored by ymand@) that fails without the fix.
---
 .../TypeErasedDataflowAnalysis.cpp| 52 ---
 .../Analysis/FlowSensitive/LoggerTest.cpp |  1 +
 .../Analysis/FlowSensitive/TransferTest.cpp   | 31 +++
 3 files changed, 65 insertions(+), 19 deletions(-)

diff --git a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp 
b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
index faf83a8920d4ead..0b5371f1c601a43 100644
--- a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -75,9 +75,8 @@ using TerminatorVisitorRetTy = std::pair;
 class TerminatorVisitor
 : public ConstStmtVisitor {
 public:
-  TerminatorVisitor(const StmtToEnvMap &StmtToEnv, Environment &Env,
-int BlockSuccIdx)
-  : StmtToEnv(StmtToEnv), Env(Env), BlockSuccIdx(BlockSuccIdx) {}
+  TerminatorVisitor(Environment &Env, int BlockSuccIdx)
+  : Env(Env), BlockSuccIdx(BlockSuccIdx) {}
 
   TerminatorVisitorRetTy VisitIfStmt(const IfStmt *S) {
 auto *Cond = S->getCond();
@@ -126,19 +125,12 @@ class TerminatorVisitor
 
 private:
   TerminatorVisitorRetTy extendFlowCondition(const Expr &Cond) {
-// The terminator sub-expression might not be evaluated.
-if (Env.getValue(Cond) == nullptr)
-  transfer(StmtToEnv, Cond, Env);
-
 auto *Val = Env.get(Cond);
-// Value merging depends on flow conditions from different environments
-// being mutually exclusive -- that is, they cannot both be true in their
-// entirety (even if they may share some clauses). So, we need *some* value
-// for the condition expression, even if just an atom.
-if (Val == nullptr) {
-  Val = &Env.makeAtomicBoolValue();
-  Env.setValue(Cond, *Val);
-}
+// In transferCFGBlock(), we ensure that we always have a `Value` for the
+// terminator condition, so assert this.
+// We consciously assert ourselves instead of asserting via `cast()` so
+// that we get a more meaningful line number if the assertion fails.
+assert(Val != nullptr);
 
 bool ConditionValue = true;
 // The condition must be inverted for the successor that encompasses the
@@ -152,7 +144,6 @@ class TerminatorVisitor
 return {&Cond, ConditionValue};
   }
 
-  const StmtToEnvMap &StmtToEnv;
   Environment &Env;
   int BlockSuccIdx;
 };
@@ -335,10 +326,8 @@ computeBlockInputState(const CFGBlock &Block, 
AnalysisContext &AC) {
 // when the terminator is taken. Copy now.
 TypeErasedDataflowAnalysisState Copy = MaybePredState->fork();
 
-const StmtToEnvMap StmtToEnv(AC.CFCtx, AC.BlockStates);
 auto [Cond, CondValue] =
-TerminatorVisitor(StmtToEnv, Copy.Env,
-  blockIndexInPredecessor(*Pred, Block))
+TerminatorVisitor(Copy.Env, blockIndexInPredecessor(*Pred, Block))
 .Visit(PredTerminatorStmt);
 if (Cond != nullptr)
   // FIXME: Call transferBranchTypeErased even if BuiltinTransferOpts
@@ -489,6 +478,31 @@ transferCFGBlock(const CFGBlock

[clang] [clang][dataflow] Process terminator condition within `transferCFGBlock()`. (PR #78127)

2024-01-15 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-analysis

@llvm/pr-subscribers-clang

Author: None (martinboehme)


Changes

In particular, it's important that we create the "fallback" atomic at this point
(which we produce if the transfer function didn't produce a value for the
expression) so that it is placed in the correct environment.

Previously, we processed the terminator condition in the `TerminatorVisitor`,
which put the fallback atomic in a copy of the environment that is produced as
input for the _successor_ block, rather than the environment for the block
containing the expression for which we produce the fallback atomic.

As a result, we produce different fallback atomics every time we process the
successor block, and hence we don't have a consistent representation of the
terminator condition in the flow condition.

This patch includes a test (authored by ymand@) that fails without the fix.


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


3 Files Affected:

- (modified) clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp 
(+33-19) 
- (modified) clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp (+1) 
- (modified) clang/unittests/Analysis/FlowSensitive/TransferTest.cpp (+31) 


``diff
diff --git a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp 
b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
index faf83a8920d4ead..0b5371f1c601a43 100644
--- a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -75,9 +75,8 @@ using TerminatorVisitorRetTy = std::pair;
 class TerminatorVisitor
 : public ConstStmtVisitor {
 public:
-  TerminatorVisitor(const StmtToEnvMap &StmtToEnv, Environment &Env,
-int BlockSuccIdx)
-  : StmtToEnv(StmtToEnv), Env(Env), BlockSuccIdx(BlockSuccIdx) {}
+  TerminatorVisitor(Environment &Env, int BlockSuccIdx)
+  : Env(Env), BlockSuccIdx(BlockSuccIdx) {}
 
   TerminatorVisitorRetTy VisitIfStmt(const IfStmt *S) {
 auto *Cond = S->getCond();
@@ -126,19 +125,12 @@ class TerminatorVisitor
 
 private:
   TerminatorVisitorRetTy extendFlowCondition(const Expr &Cond) {
-// The terminator sub-expression might not be evaluated.
-if (Env.getValue(Cond) == nullptr)
-  transfer(StmtToEnv, Cond, Env);
-
 auto *Val = Env.get(Cond);
-// Value merging depends on flow conditions from different environments
-// being mutually exclusive -- that is, they cannot both be true in their
-// entirety (even if they may share some clauses). So, we need *some* value
-// for the condition expression, even if just an atom.
-if (Val == nullptr) {
-  Val = &Env.makeAtomicBoolValue();
-  Env.setValue(Cond, *Val);
-}
+// In transferCFGBlock(), we ensure that we always have a `Value` for the
+// terminator condition, so assert this.
+// We consciously assert ourselves instead of asserting via `cast()` so
+// that we get a more meaningful line number if the assertion fails.
+assert(Val != nullptr);
 
 bool ConditionValue = true;
 // The condition must be inverted for the successor that encompasses the
@@ -152,7 +144,6 @@ class TerminatorVisitor
 return {&Cond, ConditionValue};
   }
 
-  const StmtToEnvMap &StmtToEnv;
   Environment &Env;
   int BlockSuccIdx;
 };
@@ -335,10 +326,8 @@ computeBlockInputState(const CFGBlock &Block, 
AnalysisContext &AC) {
 // when the terminator is taken. Copy now.
 TypeErasedDataflowAnalysisState Copy = MaybePredState->fork();
 
-const StmtToEnvMap StmtToEnv(AC.CFCtx, AC.BlockStates);
 auto [Cond, CondValue] =
-TerminatorVisitor(StmtToEnv, Copy.Env,
-  blockIndexInPredecessor(*Pred, Block))
+TerminatorVisitor(Copy.Env, blockIndexInPredecessor(*Pred, Block))
 .Visit(PredTerminatorStmt);
 if (Cond != nullptr)
   // FIXME: Call transferBranchTypeErased even if BuiltinTransferOpts
@@ -489,6 +478,31 @@ transferCFGBlock(const CFGBlock &Block, AnalysisContext 
&AC,
 }
 AC.Log.recordState(State);
   }
+
+  // If we have a terminator, evaluate its condition.
+  // This `Expr` may not appear as a `CFGElement` anywhere else, and it's
+  // important that we evaluate it here (rather than while processing the
+  // terminator) so that we put the corresponding value in the right
+  // environment.
+  if (const Expr *TerminatorCond =
+  dyn_cast_or_null(Block.getTerminatorCondition())) {
+if (State.Env.getValue(*TerminatorCond) == nullptr)
+  // FIXME: This only runs the builtin transfer, not the analysis-specific
+  // transfer. Fixing this isn't trivial, as the analysis-specific transfer
+  // takes a `CFGElement` as input, but some expressions only show up as a
+  // terminator condition, but not as a `CFGElement`. The condition of an 
if
+  // statement is one such example.

[clang] [clang][dataflow] Process terminator condition within `transferCFGBlock()`. (PR #78127)

2024-01-15 Thread via cfe-commits

martinboehme wrote:

This is a re-land of https://github.com/llvm/llvm-project/pull/77750, which I 
reverted; it caused build bots to fail because `TerminatorVisitor::StmtToEnv` 
became unused.

This version removes `TerminatorVisitor::StmtToEnv` entirely.

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


[clang] [clang][Interp] Handle std::move etc. builtins (PR #70772)

2024-01-15 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


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

>From e850b96306ab5d9e6aac4171150195ea013f6ec2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Tue, 31 Oct 2023 07:17:16 +0100
Subject: [PATCH 1/5] [clang][Interp] Handle std::move etc. builtins

---
 clang/lib/AST/Interp/InterpBuiltin.cpp | 17 +
 clang/test/AST/Interp/functions.cpp| 15 +++
 2 files changed, 32 insertions(+)

diff --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index 754ca96b0c645e..142f92ffc337c3 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -634,6 +634,15 @@ static bool interp__builtin_addressof(InterpState &S, 
CodePtr OpPC,
   return true;
 }
 
+static bool interp__builtin_move(InterpState &S, CodePtr OpPC,
+ const InterpFrame *Frame, const Function 
*Func,
+ const CallExpr *Call) {
+
+  const Pointer &Arg = S.Stk.peek();
+  S.Stk.push(Arg);
+  return Func->getDecl()->isConstexpr();
+}
+
 bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
   const CallExpr *Call) {
   InterpFrame *Frame = S.Current;
@@ -848,6 +857,14 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const 
Function *F,
   return false;
 break;
 
+  case Builtin::BIas_const:
+  case Builtin::BIforward:
+  case Builtin::BIforward_like:
+  case Builtin::BImove:
+if (!interp__builtin_move(S, OpPC, Frame, F, Call))
+  return false;
+break;
+
   default:
 return false;
   }
diff --git a/clang/test/AST/Interp/functions.cpp 
b/clang/test/AST/Interp/functions.cpp
index 75f3c5d192b2cf..019af555c347a6 100644
--- a/clang/test/AST/Interp/functions.cpp
+++ b/clang/test/AST/Interp/functions.cpp
@@ -413,3 +413,18 @@ namespace AddressOf {
   constexpr _Complex float F = {3, 4};
   static_assert(__builtin_addressof(F) == &F, "");
 }
+
+namespace std {
+template  struct remove_reference { using type = T; };
+template  struct remove_reference { using type = T; };
+template  struct remove_reference { using type = T; };
+template 
+constexpr typename std::remove_reference::type&& move(T &&t) noexcept {
+  return static_cast::type &&>(t);
+}
+}
+/// The std::move declaration above gets translated to a builtin function.
+namespace Move {
+  constexpr int A = std::move(5);
+  static_assert(A == 5, "");
+}

>From d90032c82863ea20e7896b78c1d9b78590603a15 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Thu, 2 Nov 2023 09:17:41 +0100
Subject: [PATCH 2/5] Add more tests

---
 clang/test/AST/Interp/functions.cpp | 74 +
 1 file changed, 74 insertions(+)

diff --git a/clang/test/AST/Interp/functions.cpp 
b/clang/test/AST/Interp/functions.cpp
index 019af555c347a6..6e995ce704e394 100644
--- a/clang/test/AST/Interp/functions.cpp
+++ b/clang/test/AST/Interp/functions.cpp
@@ -425,6 +425,80 @@ constexpr typename std::remove_reference::type&& move(T 
&&t) noexcept {
 }
 /// The std::move declaration above gets translated to a builtin function.
 namespace Move {
+#if __cplusplus >= 202002L
+  consteval int f_eval() { // expected-note 12{{declared here}} \
+   // ref-note 12{{declared here}}
+return 0;
+  }
+
+  /// From test/SemaCXX/cxx2a-consteval.
+  struct Copy {
+int(*ptr)();
+constexpr Copy(int(*p)() = nullptr) : ptr(p) {}
+consteval Copy(const Copy&) = default;
+  };
+
+  constexpr const Copy &to_lvalue_ref(const Copy &&a) {
+return a;
+  }
+
+  void test() {
+constexpr const Copy C;
+// there is no the copy constructor call when its argument is a prvalue 
because of garanteed copy elision.
+// so we need to test with both prvalue and xvalues.
+{ Copy c(C); }
+{ Copy c((Copy(&f_eval))); } // expected-error {{cannot take address of 
consteval}} \
+ // ref-error {{cannot take address of 
consteval}}
+{ Copy c(std::move(C)); }
+{ Copy c(std::move(Copy(&f_eval))); } // expected-error {{is not a 
constant expression}} \
+  // expected-note {{to a consteval}} \
+  // ref-error {{is not a constant 
expression}} \
+  // ref-note {{to a consteval}}
+{ Copy c(to_lvalue_ref((Copy(&f_eval; } // expected-error {{is not a 
constant expression}} \
+// expected-note {{to a 
consteval}} \
+// ref-error {{is not a 
constant expression}} \
+// ref-note {{to a consteval}}
+{ Copy c(to_lvalue_ref(std::move(C))); }
+{ Copy c(to_lvalue_ref(std::move(Copy(&f_eval; }

[clang] c3ced6a - [clang][Interp] Implement IntegralAP::{div, rem} (#72614)

2024-01-15 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-01-15T09:36:19+01:00
New Revision: c3ced6ac62cdd7c50f2429beb8ab5fc69a1a1a75

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

LOG: [clang][Interp] Implement IntegralAP::{div, rem} (#72614)

Added: 


Modified: 
clang/lib/AST/Interp/IntegralAP.h
clang/test/AST/Interp/intap.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/IntegralAP.h 
b/clang/lib/AST/Interp/IntegralAP.h
index d5f46409d231d4..55e29caa1cd747 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -204,14 +204,18 @@ template  class IntegralAP final {
   }
 
   static bool rem(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R) {
-// FIXME: Implement.
-assert(false);
+if constexpr (Signed)
+  *R = IntegralAP(A.V.srem(B.V));
+else
+  *R = IntegralAP(A.V.urem(B.V));
 return false;
   }
 
   static bool div(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R) {
-// FIXME: Implement.
-assert(false);
+if constexpr (Signed)
+  *R = IntegralAP(A.V.sdiv(B.V));
+else
+  *R = IntegralAP(A.V.udiv(B.V));
 return false;
   }
 

diff  --git a/clang/test/AST/Interp/intap.cpp b/clang/test/AST/Interp/intap.cpp
index b99422dc8f9312..118dc21b67e875 100644
--- a/clang/test/AST/Interp/intap.cpp
+++ b/clang/test/AST/Interp/intap.cpp
@@ -5,6 +5,7 @@
 
 
 using MaxBitInt = _BitInt(128);
+#define INT_MIN (~__INT_MAX__)
 
 constexpr _BitInt(2) A = 0;
 constexpr _BitInt(2) B = A + 1;
@@ -44,6 +45,35 @@ static_assert(MulA * MulB == 50, ""); // ref-error {{not an 
integral constant ex
 static_assert(MulA * 5 == 25, "");
 static_assert(-1 * MulB == -7, "");
 
+
+constexpr _BitInt(4) DivA = 2;
+constexpr _BitInt(2) DivB = 1;
+static_assert(DivA / DivB == 2, "");
+
+constexpr _BitInt(4) DivC = DivA / 0; // ref-error {{must be initialized by a 
constant expression}} \
+  // ref-note {{division by zero}} \
+  // expected-error {{must be initialized 
by a constant expression}} \
+  // expected-note {{division by zero}}
+
+constexpr _BitInt(7) RemA = 47;
+constexpr _BitInt(6) RemB = 9;
+static_assert(RemA % RemB == 2, "");
+static_assert(RemA % 0 == 1, ""); // ref-error {{not an integral constant 
expression}} \
+  // ref-note {{division by zero}} \
+  // expected-error {{not an integral constant 
expression}} \
+  // expected-note {{division by zero}}
+
+constexpr _BitInt(32) bottom = -1;
+constexpr _BitInt(32) top = INT_MIN;
+constexpr _BitInt(32) nope = top / bottom;  // ref-error {{must be initialized 
by a constant expression}} \
+// ref-note {{value 2147483648 is 
outside the range}} \
+// expected-error {{must be 
initialized by a constant expression}} \
+// expected-note {{value 
2147483648 is outside the range}}
+constexpr _BitInt(32) n = top % bottom; // ref-error {{must be initialized 
by a constant expression}} \
+// ref-note {{value 2147483648 is 
outside the range}} \
+// expected-error {{must be 
initialized by a constant expression}} \
+// expected-note {{value 
2147483648 is outside the range}}
+
 namespace APCast {
   constexpr _BitInt(10) A = 1;
   constexpr _BitInt(11) B = A;



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


[clang] [clang][Interp] Implement IntegralAP::{div, rem} (PR #72614)

2024-01-15 Thread Timm Baeder via cfe-commits

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


[clang] [RISCV][clang] Optimize memory usage of intrinsic lookup table (PR #77487)

2024-01-15 Thread Brandon Wu via cfe-commits


@@ -416,8 +416,10 @@ class RVVIntrinsic {
   RVVTypePtr getOutputType() const { return OutputType; }
   const RVVTypes &getInputTypes() const { return InputTypes; }
   llvm::StringRef getBuiltinName() const { return BuiltinName; }
-  llvm::StringRef getName() const { return Name; }
-  llvm::StringRef getOverloadedName() const { return OverloadedName; }
+  llvm::StringRef getName() const { return "__riscv_" + Name; }

4vtomat wrote:

I just can't find where is `getName` and `getOverloadedName`, I just comment 
out this 2 member functions and run `ninja check-clang`, it passed.
Can we delete them?

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


[clang] [clang][Interp] Handle std::move etc. builtins (PR #70772)

2024-01-15 Thread via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
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 e3993e044ec5925e59c131f798f823a9f16f0433 
f4f4dd022d09dee65b6152d083af1c7fba9c8052 -- 
clang/lib/AST/Interp/ByteCodeExprGen.h clang/lib/AST/Interp/Context.h 
clang/lib/AST/Interp/Interp.cpp clang/lib/AST/Interp/InterpBuiltin.cpp 
clang/test/AST/Interp/functions.cpp clang/test/SemaCXX/builtin-std-move.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 3956eec6cd..ae25ce13fd 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -383,9 +383,9 @@ bool CheckCallable(InterpState &S, CodePtr OpPC, const 
Function *F) {
   << CD->getInheritedConstructor().getConstructor()->getParent();
 S.Note(DiagDecl->getLocation(), diag::note_declared_at);
   } else {
-// Don't emit anything if the function isn't defined and we're 
checking for
-// a constnat expression. It might be defined at the point we're 
actually
-// calling it.
+// Don't emit anything if the function isn't defined and we're checking
+// for a constnat expression. It might be defined at the point we're
+// actually calling it.
 if (!DiagDecl->isDefined() && S.checkingPotentialConstantExpression())
   return false;
 

``




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


[clang] [clang][Interp] Implement integral->complex casts (PR #75590)

2024-01-15 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Ping @shafik 

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


[clang] [clang][Interp] Add an EvaluationResult class (PR #71315)

2024-01-15 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Ping

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


[clang] [clang][Interp] IndirectMember initializers (PR #69900)

2024-01-15 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Ping

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


[clang] [clang][Interp] Support __real/__imag on primitives (PR #75485)

2024-01-15 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Ping

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


[clang] [clang][Interp] Fix diagnosing non-const variables pre-C++11 (PR #76718)

2024-01-15 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?B=C3=A4der?= 
Message-ID:
In-Reply-To: 


tbaederr wrote:

Ping

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


[clang] [clang][Interp] Implement ComplexToReal casts (PR #77294)

2024-01-15 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Ping

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


[clang] [clang][Interp] Add inline descriptor to global variables (PR #72892)

2024-01-15 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= 
Message-ID:
In-Reply-To: 


tbaederr wrote:

Pnig

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


[clang] [clang][Diagnostics] Highlight code snippets (PR #66514)

2024-01-15 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= 
Message-ID:
In-Reply-To: 


tbaederr wrote:

Ping

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


[clang] [clang][Interp] Implement ComplexToReal casts (PR #77294)

2024-01-15 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


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

>From 4c9d611f5ae8cbad083811261e08954d92b0ca41 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Mon, 8 Jan 2024 11:14:41 +0100
Subject: [PATCH 1/2] [clang][Interp] Implement ComplexToReal casts

Add a new emitComplexReal() helper function and use that for the
new casts as well as the old __real implementation.
---
 clang/lib/AST/Interp/ByteCodeExprGen.cpp | 45 
 clang/lib/AST/Interp/ByteCodeExprGen.h   |  2 ++
 clang/test/AST/Interp/complex.cpp| 16 +++--
 3 files changed, 46 insertions(+), 17 deletions(-)

diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 7f8bbe787324814..ef28673013e12d1 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -287,6 +287,10 @@ bool ByteCodeExprGen::VisitCastExpr(const 
CastExpr *CE) {
 return true;
   }
 
+  case CK_IntegralComplexToReal:
+  case CK_FloatingComplexToReal:
+return this->emitComplexReal(SubExpr);
+
   case CK_ToVoid:
 return discard(SubExpr);
 
@@ -2030,7 +2034,7 @@ bool ByteCodeExprGen::dereference(
   }
 
   if (LV->getType()->isAnyComplexType())
-return visit(LV);
+return this->delegate(LV);
 
   return false;
 }
@@ -2767,21 +2771,9 @@ bool ByteCodeExprGen::VisitUnaryOperator(const 
UnaryOperator *E) {
 if (!this->visit(SubExpr))
   return false;
 return DiscardResult ? this->emitPop(*T, E) : this->emitComp(*T, E);
-  case UO_Real: { // __real x
+  case UO_Real: // __real x
 assert(!T);
-if (!this->visit(SubExpr))
-  return false;
-if (!this->emitConstUint8(0, E))
-  return false;
-if (!this->emitArrayElemPtrPopUint8(E))
-  return false;
-
-// Since our _Complex implementation does not map to a primitive type,
-// we sometimes have to do the lvalue-to-rvalue conversion here manually.
-if (!SubExpr->isLValue())
-  return this->emitLoadPop(classifyPrim(E->getType()), E);
-return true;
-  }
+return this->emitComplexReal(SubExpr);
   case UO_Imag: { // __imag x
 assert(!T);
 if (!this->visit(SubExpr))
@@ -2948,6 +2940,29 @@ bool ByteCodeExprGen::emitPrimCast(PrimType 
FromT, PrimType ToT,
   return false;
 }
 
+/// Emits __real(SubExpr)
+template 
+bool ByteCodeExprGen::emitComplexReal(const Expr *SubExpr) {
+  assert(SubExpr->getType()->isAnyComplexType());
+
+  if (DiscardResult)
+return this->discard(SubExpr);
+
+  if (!this->visit(SubExpr))
+return false;
+  if (!this->emitConstUint8(0, SubExpr))
+return false;
+  if (!this->emitArrayElemPtrPopUint8(SubExpr))
+return false;
+
+  // Since our _Complex implementation does not map to a primitive type,
+  // we sometimes have to do the lvalue-to-rvalue conversion here manually.
+  if (!SubExpr->isLValue())
+return this->emitLoadPop(*classifyComplexElementType(SubExpr->getType()),
+ SubExpr);
+  return true;
+}
+
 /// When calling this, we have a pointer of the local-to-destroy
 /// on the stack.
 /// Emit destruction of record types (or arrays of record types).
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index bbb13e97e725692..48005ce05724b54 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -294,6 +294,8 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
 return this->classify(ElemType);
   }
 
+  bool emitComplexReal(const Expr *SubExpr);
+
   bool emitRecordDestruction(const Descriptor *Desc);
   unsigned collectBaseOffset(const RecordType *BaseType,
  const RecordType *DerivedType);
diff --git a/clang/test/AST/Interp/complex.cpp 
b/clang/test/AST/Interp/complex.cpp
index 66490e973988bb5..fd5cb8395550b55 100644
--- a/clang/test/AST/Interp/complex.cpp
+++ b/clang/test/AST/Interp/complex.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
-// RUN: %clang_cc1 -verify=ref %s
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify 
-Wno-unused-value %s
+// RUN: %clang_cc1 -verify=ref -Wno-unused-value %s
 
 // expected-no-diagnostics
 // ref-no-diagnostics
@@ -37,6 +37,18 @@ constexpr _Complex int I2 = {};
 static_assert(__real(I2) == 0, "");
 static_assert(__imag(I2) == 0, "");
 
+constexpr int ignoredCast() {
+  I2;
+  (int)I2;
+  /* (float)I2; FIXME*/
+  D1;
+  /* (int)D1; FIXME*/
+  (double)D1;
+  return 0;
+}
+static_assert(ignoredCast() == 0, "");
+static_assert((int)I1 == 1, "");
+
 
 /// Standalone complex expressions.
 static_assert(__real((_Complex float){1.0, 3.0}) == 1.0, "");

>From 95b1c77ecbde52162a5a80282176f693031c1322 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Mon, 15 Jan 2024 09:52:26 +0100
Subject: [PATCH 2/2] Enable commented-out tests

---
 clang/tes

[clang] 9c4cd79 - [Clang][SME2] Fix PSEL builtin predicates (#77097)

2024-01-15 Thread via cfe-commits

Author: Kerry McLaughlin
Date: 2024-01-15T08:55:30Z
New Revision: 9c4cd7971382ecbaf8e1530e381aa54ed23a2b0e

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

LOG: [Clang][SME2] Fix PSEL builtin predicates (#77097)

PSEL intrinsics which return a predicate-as-counter are available
in SVE2p1 & SME2.

Added: 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_psel_svcount.c

Modified: 
clang/include/clang/Basic/arm_sve.td
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_psel.c

Removed: 




diff  --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index 6de940b4da60334..628e325c858151d 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -1948,14 +1948,10 @@ def SVBGRP_N : SInst<"svbgrp[_n_{d}]", "dda", 
"UcUsUiUl", MergeNone, "aarch64_sv
 }
 
 let TargetGuard = "sve2p1|sme" in {
-def SVPSEL_B : SInst<"svpsel_lane_b8",  "PPPm", "Pc", MergeNone, "", 
[IsStreamingCompatible], []>;
-def SVPSEL_H : SInst<"svpsel_lane_b16", "PPPm", "Ps", MergeNone, "", 
[IsStreamingCompatible], []>;
-def SVPSEL_S : SInst<"svpsel_lane_b32", "PPPm", "Pi", MergeNone, "", 
[IsStreamingCompatible], []>;
-def SVPSEL_D : SInst<"svpsel_lane_b64", "PPPm", "Pl", MergeNone, "", 
[IsStreamingCompatible], []>;
-def SVPSEL_COUNT_ALIAS_B : SInst<"svpsel_lane_c8",  "}}Pm", "Pc", MergeNone, 
"", [IsStreamingCompatible], []>;
-def SVPSEL_COUNT_ALIAS_H : SInst<"svpsel_lane_c16", "}}Pm", "Ps", MergeNone, 
"", [IsStreamingCompatible], []>;
-def SVPSEL_COUNT_ALIAS_S : SInst<"svpsel_lane_c32", "}}Pm", "Pi", MergeNone, 
"", [IsStreamingCompatible], []>;
-def SVPSEL_COUNT_ALIAS_D : SInst<"svpsel_lane_c64", "}}Pm", "Pl", MergeNone, 
"", [IsStreamingCompatible], []>;
+def SVPSEL_B : SInst<"svpsel_lane_b8",  "PPPm", "Pc", MergeNone, "", 
[IsStreamingOrSVE2p1], []>;
+def SVPSEL_H : SInst<"svpsel_lane_b16", "PPPm", "Ps", MergeNone, "", 
[IsStreamingOrSVE2p1], []>;
+def SVPSEL_S : SInst<"svpsel_lane_b32", "PPPm", "Pi", MergeNone, "", 
[IsStreamingOrSVE2p1], []>;
+def SVPSEL_D : SInst<"svpsel_lane_b64", "PPPm", "Pl", MergeNone, "", 
[IsStreamingOrSVE2p1], []>;
 }
 
 // Standalone sve2.1 builtins
@@ -1979,6 +1975,11 @@ let TargetGuard = "sve2p1|sme2" in {
 def SVPEXT_SINGLE : SInst<"svpext_lane_{d}", "P}i", "QcQsQiQl", MergeNone, 
"aarch64_sve_pext", [IsStreamingOrSVE2p1], [ImmCheck<1, ImmCheck0_3>]>;
 def SVPEXT_X2 : SInst<"svpext_lane_{d}_x2", "2.P}i", "QcQsQiQl", 
MergeNone, "aarch64_sve_pext_x2", [IsStreamingOrSVE2p1], [ImmCheck<1, 
ImmCheck0_1>]>;
 
+def SVPSEL_COUNT_ALIAS_B : SInst<"svpsel_lane_c8",  "}}Pm", "Pc", MergeNone, 
"", [IsStreamingOrSVE2p1], []>;
+def SVPSEL_COUNT_ALIAS_H : SInst<"svpsel_lane_c16", "}}Pm", "Ps", MergeNone, 
"", [IsStreamingOrSVE2p1], []>;
+def SVPSEL_COUNT_ALIAS_S : SInst<"svpsel_lane_c32", "}}Pm", "Pi", MergeNone, 
"", [IsStreamingOrSVE2p1], []>;
+def SVPSEL_COUNT_ALIAS_D : SInst<"svpsel_lane_c64", "}}Pm", "Pl", MergeNone, 
"", [IsStreamingOrSVE2p1], []>;
+
 def SVWHILEGE_COUNT  : SInst<"svwhilege_{d}[_{1}]",  "}lli", "QcQsQiQl", 
MergeNone, "aarch64_sve_whilege_{d}", [IsOverloadNone, IsStreamingOrSVE2p1], 
[ImmCheck<2, ImmCheck2_4_Mul2>]>;
 def SVWHILEGT_COUNT  : SInst<"svwhilegt_{d}[_{1}]",  "}lli", "QcQsQiQl", 
MergeNone, "aarch64_sve_whilegt_{d}", [IsOverloadNone, IsStreamingOrSVE2p1], 
[ImmCheck<2, ImmCheck2_4_Mul2>]>;
 def SVWHILELE_COUNT  : SInst<"svwhilele_{d}[_{1}]",  "}lli", "QcQsQiQl", 
MergeNone, "aarch64_sve_whilele_{d}", [IsOverloadNone, IsStreamingOrSVE2p1], 
[ImmCheck<2, ImmCheck2_4_Mul2>]>;

diff  --git a/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_psel.c 
b/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_psel.c
index de3f6a9a57bfeb1..a61d874a1d9e90c 100644
--- a/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_psel.c
+++ b/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_psel.c
@@ -11,16 +11,16 @@
 // RUN:   -target-feature +sve2p1 -S -O1 -Werror -emit-llvm -o - -x c++ %s | 
FileCheck %s -check-prefix=CPP-CHECK
 // RUN: %clang_cc1 -fclang-abi-compat=latest -triple aarch64-none-linux-gnu 
-target-feature +sve2p1 -S -disable-O0-optnone -Werror -Wall -o /dev/null %s
 // RUN: %clang_cc1 -triple aarch64-none-linux-gnu \
-// RUN:   -target-feature +sme2 -S -DTEST_SME2 -O1 -Werror -emit-llvm -o - -x 
c++ %s | FileCheck %s -check-prefix=CPP-CHECK
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 -S 
-DTEST_SME2 -disable-O0-optnone -Werror -Wall -o /dev/null %s
+// RUN:   -target-feature +sme -S -DTEST_SME -O1 -Werror -emit-llvm -o - -x 
c++ %s | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -S 
-DTEST_SME -disable-O0-optnone -Werror -Wall -o /dev/null %s
 // RUN: %clang_cc

[clang] [Clang][SME2] Fix PSEL builtin predicates (PR #77097)

2024-01-15 Thread Kerry McLaughlin via cfe-commits

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


[clang] 7bc170a - [C++20] [Modules] [Serialization] Don't record '#pragma once' information in named modules

2024-01-15 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2024-01-15T17:00:49+08:00
New Revision: 7bc170a261ae0daaddcc1abeacf7e9e0f1f66d02

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

LOG: [C++20] [Modules] [Serialization] Don't record '#pragma once' information 
in named modules

Close https://github.com/llvm/llvm-project/issues/77995

The cause of the issue is that straight forward that we recorded the
'#pragma once' information in named modules, which is an overlook.

I tried to not record the header's information completely within named
modules. But the tests look not happy with some diagnosing problems,
which needs to be looked in details.

Added: 
clang/test/Modules/pr77995.cppm

Modified: 
clang/lib/Serialization/ASTWriter.cpp

Removed: 




diff  --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 9950fa9c08faaa..a3fa99c3d7e49f 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -1897,7 +1897,8 @@ namespace {
 
   unsigned char Flags = (Data.AlreadyIncluded << 6)
   | (Data.HFI.isImport << 5)
-  | (Data.HFI.isPragmaOnce << 4)
+  | (Writer.isWritingStdCXXNamedModules() ? 0 :
+ Data.HFI.isPragmaOnce << 4)
   | (Data.HFI.DirInfo << 1)
   | Data.HFI.IndexHeaderMapHeader;
   LE.write(Flags);

diff  --git a/clang/test/Modules/pr77995.cppm b/clang/test/Modules/pr77995.cppm
new file mode 100644
index 00..26442dacac4fb6
--- /dev/null
+++ b/clang/test/Modules/pr77995.cppm
@@ -0,0 +1,25 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/foo.cppm -emit-module-interface -o %t/foo.pcm
+// RUN: %clang_cc1 -std=c++20 %t/use.cpp -fmodule-file=foo=%t/foo.pcm -verify 
-fsyntax-only
+
+//--- a.hpp
+#pragma once
+#define A 43
+
+//--- foo.cppm
+module;
+#include "a.hpp"
+export module foo;
+export constexpr auto B = A;
+
+//--- use.cpp
+// expected-no-diagnostics
+import foo;
+#include "a.hpp"
+
+static_assert(A == 43);
+static_assert(B == 43);
+



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


[clang] [Modules] [HeaderSearch] Don't reenter headers if it is pragma once (PR #76119)

2024-01-15 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

@vsapsai gentle ping~

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


[clang] [CLANG][NFC] Modify test cases to suit assigned default sysroot path (PR #77075)

2024-01-15 Thread via cfe-commits

Yunzezhu94 wrote:

Gentle Ping.

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


[llvm] [clang] [CodeGen] Port AtomicExpand to new Pass Manager (PR #71220)

2024-01-15 Thread Matt Arsenault via cfe-commits


@@ -429,6 +429,7 @@ FUNCTION_PASS("strip-gc-relocates", StripGCRelocates())
 FUNCTION_PASS("structurizecfg", StructurizeCFGPass())
 FUNCTION_PASS("tailcallelim", TailCallElimPass())
 FUNCTION_PASS("typepromotion", TypePromotionPass(TM))
+FUNCTION_PASS("atomicexpand", AtomicExpandPass(TM))

arsenm wrote:

Renaming the pass shouldn't be done in the same change as the new PM support 

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


[clang] [clang][Interp] Add inline descriptor to global variables (PR #72892)

2024-01-15 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


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

>From 8072f1e064c817273943615c796b82b4b4bd68c6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Mon, 20 Nov 2023 11:53:40 +0100
Subject: [PATCH 1/3] [clang][Interp] Add inline descriptor to global variables

---
 clang/lib/AST/Interp/ByteCodeExprGen.cpp | 15 ++-
 clang/lib/AST/Interp/Descriptor.cpp  | 25 +--
 clang/lib/AST/Interp/Descriptor.h|  7 +--
 clang/lib/AST/Interp/Interp.cpp  | 16 +++
 clang/lib/AST/Interp/Interp.h| 23 +++---
 clang/lib/AST/Interp/Pointer.cpp |  4 +-
 clang/lib/AST/Interp/Pointer.h   | 30 +
 clang/lib/AST/Interp/Program.cpp | 54 ++--
 clang/test/AST/Interp/cxx17.cpp  | 23 --
 clang/test/AST/Interp/cxx23.cpp  | 24 ---
 clang/test/AST/Interp/literals.cpp   | 17 
 11 files changed, 183 insertions(+), 55 deletions(-)

diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 7f8bbe787324814..708b829045b988b 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -830,13 +830,26 @@ bool ByteCodeExprGen::VisitInitListExpr(const 
InitListExpr *E) {
 return this->visitInitList(E->inits(), E);
 
   if (T->isArrayType()) {
-// FIXME: Array fillers.
 unsigned ElementIndex = 0;
 for (const Expr *Init : E->inits()) {
   if (!this->visitArrayElemInit(ElementIndex, Init))
 return false;
   ++ElementIndex;
 }
+
+// Expand the filler expression.
+// FIXME: This should go away.
+if (const Expr *Filler = E->getArrayFiller()) {
+  const ConstantArrayType *CAT =
+  Ctx.getASTContext().getAsConstantArrayType(E->getType());
+  uint64_t NumElems = CAT->getSize().getZExtValue();
+
+  for (; ElementIndex != NumElems; ++ElementIndex) {
+if (!this->visitArrayElemInit(ElementIndex, Filler))
+  return false;
+  }
+}
+
 return true;
   }
 
diff --git a/clang/lib/AST/Interp/Descriptor.cpp 
b/clang/lib/AST/Interp/Descriptor.cpp
index b330e54baf335a7..5701cf0acf915dc 100644
--- a/clang/lib/AST/Interp/Descriptor.cpp
+++ b/clang/lib/AST/Interp/Descriptor.cpp
@@ -243,18 +243,19 @@ Descriptor::Descriptor(const DeclTy &D, PrimType Type, 
MetadataSize MD,
bool IsMutable)
 : Source(D), ElemSize(primSize(Type)), Size(ElemSize * NumElems),
   MDSize(MD.value_or(0)),
-  AllocSize(align(Size) + sizeof(InitMapPtr) + MDSize), IsConst(IsConst),
-  IsMutable(IsMutable), IsTemporary(IsTemporary), IsArray(true),
-  CtorFn(getCtorArrayPrim(Type)), DtorFn(getDtorArrayPrim(Type)),
-  MoveFn(getMoveArrayPrim(Type)) {
+  AllocSize(align(MDSize) + align(Size) + sizeof(InitMapPtr)),
+  IsConst(IsConst), IsMutable(IsMutable), IsTemporary(IsTemporary),
+  IsArray(true), CtorFn(getCtorArrayPrim(Type)),
+  DtorFn(getDtorArrayPrim(Type)), MoveFn(getMoveArrayPrim(Type)) {
   assert(Source && "Missing source");
 }
 
 /// Primitive unknown-size arrays.
-Descriptor::Descriptor(const DeclTy &D, PrimType Type, bool IsTemporary,
-   UnknownSize)
-: Source(D), ElemSize(primSize(Type)), Size(UnknownSizeMark), MDSize(0),
-  AllocSize(alignof(void *) + sizeof(InitMapPtr)), IsConst(true),
+Descriptor::Descriptor(const DeclTy &D, PrimType Type, MetadataSize MD,
+   bool IsTemporary, UnknownSize)
+: Source(D), ElemSize(primSize(Type)), Size(UnknownSizeMark),
+  MDSize(MD.value_or(0)),
+  AllocSize(MDSize + sizeof(InitMapPtr) + alignof(void *)), IsConst(true),
   IsMutable(false), IsTemporary(IsTemporary), IsArray(true),
   CtorFn(getCtorArrayPrim(Type)), DtorFn(getDtorArrayPrim(Type)),
   MoveFn(getMoveArrayPrim(Type)) {
@@ -275,12 +276,12 @@ Descriptor::Descriptor(const DeclTy &D, const Descriptor 
*Elem, MetadataSize MD,
 }
 
 /// Unknown-size arrays of composite elements.
-Descriptor::Descriptor(const DeclTy &D, const Descriptor *Elem,
+Descriptor::Descriptor(const DeclTy &D, const Descriptor *Elem, MetadataSize 
MD,
bool IsTemporary, UnknownSize)
 : Source(D), ElemSize(Elem->getAllocSize() + sizeof(InlineDescriptor)),
-  Size(UnknownSizeMark), MDSize(0),
-  AllocSize(alignof(void *) + sizeof(InitMapPtr)), ElemDesc(Elem),
-  IsConst(true), IsMutable(false), IsTemporary(IsTemporary), IsArray(true),
+  Size(UnknownSizeMark), MDSize(MD.value_or(0)),
+  AllocSize(MDSize + alignof(void *)), ElemDesc(Elem), IsConst(true),
+  IsMutable(false), IsTemporary(IsTemporary), IsArray(true),
   CtorFn(ctorArrayDesc), DtorFn(dtorArrayDesc), MoveFn(moveArrayDesc) {
   assert(Source && "Missing source");
 }
diff --git a/clang/lib/AST/Interp/Descriptor.h 
b/clang/lib/AST

[clang] [clang][ASTImporter] Improve structural equivalence of overloadable operators. (PR #72242)

2024-01-15 Thread via cfe-commits
=?utf-8?q?Balázs_Kéri?= ,
=?utf-8?q?Balázs_Kéri?= 
Message-ID:
In-Reply-To: 


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

Thanks for the clarifications, it looks good to me now. (Except for the 
`FIXME`, but that's an independent issue and you're right that it should be 
handled in another commit.)

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


[clang] [clang][ASTImporter] Fix import of variable template redeclarations. (PR #72841)

2024-01-15 Thread via cfe-commits
=?utf-8?q?Balázs_Kéri?= ,
=?utf-8?q?Balázs_Kéri?= 
Message-ID:
In-Reply-To: 


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

Thanks for the clarifications, LGTM. As others had lots of opportunities to 
comment on this change, I think it's safe to merge this now (assuming that the 
tests are OK).

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


[clang] [Clang][AArch64] Change SME attributes for shared/new/preserved state. (PR #76971)

2024-01-15 Thread Sander de Smalen via cfe-commits

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


[clang] [Clang] Amend SME attributes with support for ZT0. (PR #77941)

2024-01-15 Thread Sander de Smalen via cfe-commits

https://github.com/sdesmalen-arm updated 
https://github.com/llvm/llvm-project/pull/77941

>From 764e7aaecffb758e7a311c17a189ee605c623246 Mon Sep 17 00:00:00 2001
From: Sander de Smalen 
Date: Thu, 4 Jan 2024 14:03:04 +
Subject: [PATCH] [Clang] Amend SME attributes with support for ZT0.

This patch builds on top of #76971 and implements support for:
* __arm_new("zt0")
* __arm_in("zt0")
* __arm_out("zt0")
* __arm_inout("zt0")
* __arm_preserves("zt0")

The patch is ready for review but won't be able to land until LLVM
implements support for handling ZT0 state.
---
 clang/include/clang/AST/Type.h| 15 +++--
 clang/include/clang/Basic/Attr.td |  3 +
 .../clang/Basic/DiagnosticSemaKinds.td|  4 ++
 clang/lib/AST/TypePrinter.cpp |  8 +++
 clang/lib/CodeGen/CGCall.cpp  | 10 
 clang/lib/CodeGen/CodeGenModule.cpp   |  2 +
 clang/lib/Sema/SemaChecking.cpp   | 22 +++
 clang/lib/Sema/SemaDecl.cpp   | 11 
 clang/lib/Sema/SemaDeclAttr.cpp   |  8 +++
 clang/lib/Sema/SemaType.cpp   |  3 +
 .../aarch64-sme2-attrs.cpp| 57 +++
 ...-sme-func-attrs-without-target-feature.cpp |  2 +
 clang/test/Sema/aarch64-sme-func-attrs.c  | 45 +++
 13 files changed, 186 insertions(+), 4 deletions(-)
 create mode 100644 
clang/test/CodeGen/aarch64-sme2-intrinsics/aarch64-sme2-attrs.cpp

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index a7efe78591635e0..a56401f9da0450b 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -4040,9 +4040,12 @@ class FunctionType : public Type {
 // Describes the value of the state using ArmStateValue.
 SME_ZAShift = 2,
 SME_ZAMask = 0b111 << SME_ZAShift,
+SME_ZT0Shift = 5,
+SME_ZT0Mask = 0b111 << SME_ZT0Shift,
 
-SME_AttributeMask = 0b111'111 // We only support maximum 6 bits because of
-  // the bitmask in FunctionTypeExtraBitfields.
+SME_AttributeMask =
+0b111'111'11 // We can't support more than 8 bits because of
+ // the bitmask in FunctionTypeExtraBitfields.
   };
 
   enum ArmStateValue : unsigned {
@@ -4057,6 +4060,10 @@ class FunctionType : public Type {
 return (ArmStateValue)((AttrBits & SME_ZAMask) >> SME_ZAShift);
   }
 
+  static ArmStateValue getArmZT0State(unsigned AttrBits) {
+return (ArmStateValue)((AttrBits & SME_ZT0Mask) >> SME_ZT0Shift);
+  }
+
   /// A simple holder for various uncommon bits which do not fit in
   /// FunctionTypeBitfields. Aligned to alignof(void *) to maintain the
   /// alignment of subsequent objects in TrailingObjects.
@@ -4068,7 +4075,7 @@ class FunctionType : public Type {
 
 /// Any AArch64 SME ACLE type attributes that need to be propagated
 /// on declarations and function pointers.
-unsigned AArch64SMEAttributes : 6;
+unsigned AArch64SMEAttributes : 8;
 FunctionTypeExtraBitfields()
 : NumExceptionType(0), AArch64SMEAttributes(SME_NormalFunction) {}
   };
@@ -4253,7 +4260,7 @@ class FunctionProtoType final
 FunctionType::ExtInfo ExtInfo;
 unsigned Variadic : 1;
 unsigned HasTrailingReturn : 1;
-unsigned AArch64SMEAttributes : 6;
+unsigned AArch64SMEAttributes : 8;
 Qualifiers TypeQuals;
 RefQualifierKind RefQualifier = RQ_None;
 ExceptionSpecInfo ExceptionSpec;
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index b9ec720dd9e199c..174d4e14bfa0ecb 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2549,6 +2549,9 @@ def ArmNew : InheritableAttr, 
TargetSpecificAttr {
 bool isNewZA() const {
   return llvm::is_contained(newArgs(), "za");
 }
+bool isNewZT0() const {
+  return llvm::is_contained(newArgs(), "zt0");
+}
   }];
 }
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c50b188a1039acb..cca4a4419d0bf94 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3696,10 +3696,14 @@ def err_sme_call_in_non_sme_target : Error<
   "call to a streaming function requires 'sme'">;
 def err_sme_za_call_no_za_state : Error<
   "call to a shared ZA function requires the caller to have ZA state">;
+def err_sme_zt0_call_no_zt0_state : Error<
+  "call to a shared ZT0 function requires the caller to have ZT0 state">;
 def err_sme_definition_using_sm_in_non_sme_target : Error<
   "function executed in streaming-SVE mode requires 'sme'">;
 def err_sme_definition_using_za_in_non_sme_target : Error<
   "function using ZA state requires 'sme'">;
+def err_sme_definition_using_zt0_in_non_sme2_target : Error<
+  "function using ZT0 state requires 'sme2'">;
 def err_conflicting_attributes_arm_state : Error<
   "conflicting attributes for state '%0'

[clang] [Clang] Amend SME attributes with support for ZT0. (PR #77941)

2024-01-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Sander de Smalen (sdesmalen-arm)


Changes

This patch builds on top of #76971 and implements support for:
* __arm_new("zt0")
* __arm_in("zt0")
* __arm_out("zt0")
* __arm_inout("zt0")
* __arm_preserves("zt0")

I'll rebase this patch after I land #76971, as this is currently a
stacked pull-request on top of #76971.

The patch is ready for review but won't be able to land until LLVM
implements support for handling ZT0 state.

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


13 Files Affected:

- (modified) clang/include/clang/AST/Type.h (+11-4) 
- (modified) clang/include/clang/Basic/Attr.td (+3) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+4) 
- (modified) clang/lib/AST/TypePrinter.cpp (+8) 
- (modified) clang/lib/CodeGen/CGCall.cpp (+10) 
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+2) 
- (modified) clang/lib/Sema/SemaChecking.cpp (+22) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+11) 
- (modified) clang/lib/Sema/SemaDeclAttr.cpp (+8) 
- (modified) clang/lib/Sema/SemaType.cpp (+3) 
- (added) clang/test/CodeGen/aarch64-sme2-intrinsics/aarch64-sme2-attrs.cpp 
(+57) 
- (modified) clang/test/Sema/aarch64-sme-func-attrs-without-target-feature.cpp 
(+2) 
- (modified) clang/test/Sema/aarch64-sme-func-attrs.c (+45) 


``diff
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index a7efe78591635e0..a56401f9da0450b 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -4040,9 +4040,12 @@ class FunctionType : public Type {
 // Describes the value of the state using ArmStateValue.
 SME_ZAShift = 2,
 SME_ZAMask = 0b111 << SME_ZAShift,
+SME_ZT0Shift = 5,
+SME_ZT0Mask = 0b111 << SME_ZT0Shift,
 
-SME_AttributeMask = 0b111'111 // We only support maximum 6 bits because of
-  // the bitmask in FunctionTypeExtraBitfields.
+SME_AttributeMask =
+0b111'111'11 // We can't support more than 8 bits because of
+ // the bitmask in FunctionTypeExtraBitfields.
   };
 
   enum ArmStateValue : unsigned {
@@ -4057,6 +4060,10 @@ class FunctionType : public Type {
 return (ArmStateValue)((AttrBits & SME_ZAMask) >> SME_ZAShift);
   }
 
+  static ArmStateValue getArmZT0State(unsigned AttrBits) {
+return (ArmStateValue)((AttrBits & SME_ZT0Mask) >> SME_ZT0Shift);
+  }
+
   /// A simple holder for various uncommon bits which do not fit in
   /// FunctionTypeBitfields. Aligned to alignof(void *) to maintain the
   /// alignment of subsequent objects in TrailingObjects.
@@ -4068,7 +4075,7 @@ class FunctionType : public Type {
 
 /// Any AArch64 SME ACLE type attributes that need to be propagated
 /// on declarations and function pointers.
-unsigned AArch64SMEAttributes : 6;
+unsigned AArch64SMEAttributes : 8;
 FunctionTypeExtraBitfields()
 : NumExceptionType(0), AArch64SMEAttributes(SME_NormalFunction) {}
   };
@@ -4253,7 +4260,7 @@ class FunctionProtoType final
 FunctionType::ExtInfo ExtInfo;
 unsigned Variadic : 1;
 unsigned HasTrailingReturn : 1;
-unsigned AArch64SMEAttributes : 6;
+unsigned AArch64SMEAttributes : 8;
 Qualifiers TypeQuals;
 RefQualifierKind RefQualifier = RQ_None;
 ExceptionSpecInfo ExceptionSpec;
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index b9ec720dd9e199c..174d4e14bfa0ecb 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2549,6 +2549,9 @@ def ArmNew : InheritableAttr, 
TargetSpecificAttr {
 bool isNewZA() const {
   return llvm::is_contained(newArgs(), "za");
 }
+bool isNewZT0() const {
+  return llvm::is_contained(newArgs(), "zt0");
+}
   }];
 }
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c50b188a1039acb..cca4a4419d0bf94 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3696,10 +3696,14 @@ def err_sme_call_in_non_sme_target : Error<
   "call to a streaming function requires 'sme'">;
 def err_sme_za_call_no_za_state : Error<
   "call to a shared ZA function requires the caller to have ZA state">;
+def err_sme_zt0_call_no_zt0_state : Error<
+  "call to a shared ZT0 function requires the caller to have ZT0 state">;
 def err_sme_definition_using_sm_in_non_sme_target : Error<
   "function executed in streaming-SVE mode requires 'sme'">;
 def err_sme_definition_using_za_in_non_sme_target : Error<
   "function using ZA state requires 'sme'">;
+def err_sme_definition_using_zt0_in_non_sme2_target : Error<
+  "function using ZT0 state requires 'sme2'">;
 def err_conflicting_attributes_arm_state : Error<
   "conflicting attributes for state '%0'">;
 def err_unknown_arm_state : Error<
diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index 1b

[clang] [Clang] Amend SME attributes with support for ZT0. (PR #77941)

2024-01-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Sander de Smalen (sdesmalen-arm)


Changes

This patch builds on top of #76971 and implements support for:
* __arm_new("zt0")
* __arm_in("zt0")
* __arm_out("zt0")
* __arm_inout("zt0")
* __arm_preserves("zt0")

I'll rebase this patch after I land #76971, as this is currently a
stacked pull-request on top of #76971.

The patch is ready for review but won't be able to land until LLVM
implements support for handling ZT0 state.

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


13 Files Affected:

- (modified) clang/include/clang/AST/Type.h (+11-4) 
- (modified) clang/include/clang/Basic/Attr.td (+3) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+4) 
- (modified) clang/lib/AST/TypePrinter.cpp (+8) 
- (modified) clang/lib/CodeGen/CGCall.cpp (+10) 
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+2) 
- (modified) clang/lib/Sema/SemaChecking.cpp (+22) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+11) 
- (modified) clang/lib/Sema/SemaDeclAttr.cpp (+8) 
- (modified) clang/lib/Sema/SemaType.cpp (+3) 
- (added) clang/test/CodeGen/aarch64-sme2-intrinsics/aarch64-sme2-attrs.cpp 
(+57) 
- (modified) clang/test/Sema/aarch64-sme-func-attrs-without-target-feature.cpp 
(+2) 
- (modified) clang/test/Sema/aarch64-sme-func-attrs.c (+45) 


``diff
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index a7efe78591635e0..a56401f9da0450b 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -4040,9 +4040,12 @@ class FunctionType : public Type {
 // Describes the value of the state using ArmStateValue.
 SME_ZAShift = 2,
 SME_ZAMask = 0b111 << SME_ZAShift,
+SME_ZT0Shift = 5,
+SME_ZT0Mask = 0b111 << SME_ZT0Shift,
 
-SME_AttributeMask = 0b111'111 // We only support maximum 6 bits because of
-  // the bitmask in FunctionTypeExtraBitfields.
+SME_AttributeMask =
+0b111'111'11 // We can't support more than 8 bits because of
+ // the bitmask in FunctionTypeExtraBitfields.
   };
 
   enum ArmStateValue : unsigned {
@@ -4057,6 +4060,10 @@ class FunctionType : public Type {
 return (ArmStateValue)((AttrBits & SME_ZAMask) >> SME_ZAShift);
   }
 
+  static ArmStateValue getArmZT0State(unsigned AttrBits) {
+return (ArmStateValue)((AttrBits & SME_ZT0Mask) >> SME_ZT0Shift);
+  }
+
   /// A simple holder for various uncommon bits which do not fit in
   /// FunctionTypeBitfields. Aligned to alignof(void *) to maintain the
   /// alignment of subsequent objects in TrailingObjects.
@@ -4068,7 +4075,7 @@ class FunctionType : public Type {
 
 /// Any AArch64 SME ACLE type attributes that need to be propagated
 /// on declarations and function pointers.
-unsigned AArch64SMEAttributes : 6;
+unsigned AArch64SMEAttributes : 8;
 FunctionTypeExtraBitfields()
 : NumExceptionType(0), AArch64SMEAttributes(SME_NormalFunction) {}
   };
@@ -4253,7 +4260,7 @@ class FunctionProtoType final
 FunctionType::ExtInfo ExtInfo;
 unsigned Variadic : 1;
 unsigned HasTrailingReturn : 1;
-unsigned AArch64SMEAttributes : 6;
+unsigned AArch64SMEAttributes : 8;
 Qualifiers TypeQuals;
 RefQualifierKind RefQualifier = RQ_None;
 ExceptionSpecInfo ExceptionSpec;
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index b9ec720dd9e199c..174d4e14bfa0ecb 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2549,6 +2549,9 @@ def ArmNew : InheritableAttr, 
TargetSpecificAttr {
 bool isNewZA() const {
   return llvm::is_contained(newArgs(), "za");
 }
+bool isNewZT0() const {
+  return llvm::is_contained(newArgs(), "zt0");
+}
   }];
 }
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c50b188a1039acb..cca4a4419d0bf94 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3696,10 +3696,14 @@ def err_sme_call_in_non_sme_target : Error<
   "call to a streaming function requires 'sme'">;
 def err_sme_za_call_no_za_state : Error<
   "call to a shared ZA function requires the caller to have ZA state">;
+def err_sme_zt0_call_no_zt0_state : Error<
+  "call to a shared ZT0 function requires the caller to have ZT0 state">;
 def err_sme_definition_using_sm_in_non_sme_target : Error<
   "function executed in streaming-SVE mode requires 'sme'">;
 def err_sme_definition_using_za_in_non_sme_target : Error<
   "function using ZA state requires 'sme'">;
+def err_sme_definition_using_zt0_in_non_sme2_target : Error<
+  "function using ZT0 state requires 'sme2'">;
 def err_conflicting_attributes_arm_state : Error<
   "conflicting attributes for state '%0'">;
 def err_unknown_arm_state : Error<
diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp

[clang] [Clang] Amend SME attributes with support for ZT0. (PR #77941)

2024-01-15 Thread Sander de Smalen via cfe-commits

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


[clang] [Coverage] Map regions from system headers (PR #76950)

2024-01-15 Thread via cfe-commits

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


[clang] [Coverage] Map regions from system headers (PR #76950)

2024-01-15 Thread via cfe-commits

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


[clang] [Clang] Only compare template params of potential overload after checking their decl context (PR #78139)

2024-01-15 Thread via cfe-commits

https://github.com/cor3ntin created 
https://github.com/llvm/llvm-project/pull/78139



Fixes a regression from 69066ab3 in which we compared the template lists of 
potential overloads before checkings their declaration contexts.

This would cause a crash when doing constraint substitution as part of that 
template check, because we would try to refer to not yet instantiated entities 
(the underlying cause is unclear).

This patch reorders (again) when we look at template parameter so we don't when 
checkings friends in different lexical contexts.

Fixes #77953
Fixes #78101

>From e5be422e1d27a9e1066777e9114bba510e5195bb Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Mon, 15 Jan 2024 10:17:13 +0100
Subject: [PATCH] [Clang] Only compare template params of potential overload
 after checking their decl context

Fixes a regression from 69066ab3 in which we compared the template lists
of potential overloads before checkings their declaration contexts.

This would cause a crash when doing constraint substitution as part
of that template check, because we would try to refer to not yet
instantiated entities (the underlying cause is unclear).

This patch reorders (again) when we look at templaste parameter so
we don't when checkings friends in different lexical contexts.

Fixes #77953
Fixes #78101
---
 clang/lib/Sema/SemaOverload.cpp | 60 ++---
 clang/test/CXX/over/over.load/p2-0x.cpp | 32 ++---
 clang/test/Modules/GH77953.cpp  | 28 
 3 files changed, 89 insertions(+), 31 deletions(-)
 create mode 100644 clang/test/Modules/GH77953.cpp

diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 23b9bc0fe2d6e2..4b84a60d4780b5 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -1259,6 +1259,40 @@ static bool IsOverloadOrOverrideImpl(Sema &SemaRef, 
FunctionDecl *New,
   if ((OldTemplate == nullptr) != (NewTemplate == nullptr))
 return true;
 
+  // Is the function New an overload of the function Old?
+  QualType OldQType = SemaRef.Context.getCanonicalType(Old->getType());
+  QualType NewQType = SemaRef.Context.getCanonicalType(New->getType());
+
+  // Compare the signatures (C++ 1.3.10) of the two functions to
+  // determine whether they are overloads. If we find any mismatch
+  // in the signature, they are overloads.
+
+  // If either of these functions is a K&R-style function (no
+  // prototype), then we consider them to have matching signatures.
+  if (isa(OldQType.getTypePtr()) ||
+  isa(NewQType.getTypePtr()))
+return false;
+
+  const FunctionProtoType *OldType = cast(OldQType);
+  const FunctionProtoType *NewType = cast(NewQType);
+
+  // The signature of a function includes the types of its
+  // parameters (C++ 1.3.10), which includes the presence or absence
+  // of the ellipsis; see C++ DR 357).
+  if (OldQType != NewQType && OldType->isVariadic() != NewType->isVariadic())
+return true;
+
+  // For member-like friends, the enclosing class is part of the signature.
+  if ((New->isMemberLikeConstrainedFriend() ||
+   Old->isMemberLikeConstrainedFriend()) &&
+  !New->getLexicalDeclContext()->Equals(Old->getLexicalDeclContext()))
+return true;
+
+  // Compare the parameter lists.
+  // This can only be done once we have establish that friend functions
+  // inhabit the same context, otherwise we might tried to instantiate
+  // references to non-instantiated entities during constraint substitution.
+  // GH78101.
   if (NewTemplate) {
 // C++ [temp.over.link]p4:
 //   The signature of a function template consists of its function
@@ -1296,34 +1330,8 @@ static bool IsOverloadOrOverrideImpl(Sema &SemaRef, 
FunctionDecl *New,
   return true;
   }
 
-  // Is the function New an overload of the function Old?
-  QualType OldQType = SemaRef.Context.getCanonicalType(Old->getType());
-  QualType NewQType = SemaRef.Context.getCanonicalType(New->getType());
-
-  // Compare the signatures (C++ 1.3.10) of the two functions to
-  // determine whether they are overloads. If we find any mismatch
-  // in the signature, they are overloads.
 
-  // If either of these functions is a K&R-style function (no
-  // prototype), then we consider them to have matching signatures.
-  if (isa(OldQType.getTypePtr()) ||
-  isa(NewQType.getTypePtr()))
-return false;
 
-  const FunctionProtoType *OldType = cast(OldQType);
-  const FunctionProtoType *NewType = cast(NewQType);
-
-  // The signature of a function includes the types of its
-  // parameters (C++ 1.3.10), which includes the presence or absence
-  // of the ellipsis; see C++ DR 357).
-  if (OldQType != NewQType && OldType->isVariadic() != NewType->isVariadic())
-return true;
-
-  // For member-like friends, the enclosing class is part of the signature.
-  if ((New->isMemberLikeConstrainedFriend() ||
-   Old->isMemberLikeConstrainedFriend()) &&
-  !New->getLexicalDeclContext()->Equals(Old->getLexicalD

[clang] [Clang] Only compare template params of potential overload after checking their decl context (PR #78139)

2024-01-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: cor3ntin (cor3ntin)


Changes



Fixes a regression from 69066ab3 in which we compared the template lists of 
potential overloads before checkings their declaration contexts.

This would cause a crash when doing constraint substitution as part of that 
template check, because we would try to refer to not yet instantiated entities 
(the underlying cause is unclear).

This patch reorders (again) when we look at template parameter so we don't when 
checkings friends in different lexical contexts.

Fixes #77953
Fixes #78101

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


3 Files Affected:

- (modified) clang/lib/Sema/SemaOverload.cpp (+34-26) 
- (modified) clang/test/CXX/over/over.load/p2-0x.cpp (+27-5) 
- (added) clang/test/Modules/GH77953.cpp (+28) 


``diff
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 23b9bc0fe2d6e2e..4b84a60d4780b59 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -1259,6 +1259,40 @@ static bool IsOverloadOrOverrideImpl(Sema &SemaRef, 
FunctionDecl *New,
   if ((OldTemplate == nullptr) != (NewTemplate == nullptr))
 return true;
 
+  // Is the function New an overload of the function Old?
+  QualType OldQType = SemaRef.Context.getCanonicalType(Old->getType());
+  QualType NewQType = SemaRef.Context.getCanonicalType(New->getType());
+
+  // Compare the signatures (C++ 1.3.10) of the two functions to
+  // determine whether they are overloads. If we find any mismatch
+  // in the signature, they are overloads.
+
+  // If either of these functions is a K&R-style function (no
+  // prototype), then we consider them to have matching signatures.
+  if (isa(OldQType.getTypePtr()) ||
+  isa(NewQType.getTypePtr()))
+return false;
+
+  const FunctionProtoType *OldType = cast(OldQType);
+  const FunctionProtoType *NewType = cast(NewQType);
+
+  // The signature of a function includes the types of its
+  // parameters (C++ 1.3.10), which includes the presence or absence
+  // of the ellipsis; see C++ DR 357).
+  if (OldQType != NewQType && OldType->isVariadic() != NewType->isVariadic())
+return true;
+
+  // For member-like friends, the enclosing class is part of the signature.
+  if ((New->isMemberLikeConstrainedFriend() ||
+   Old->isMemberLikeConstrainedFriend()) &&
+  !New->getLexicalDeclContext()->Equals(Old->getLexicalDeclContext()))
+return true;
+
+  // Compare the parameter lists.
+  // This can only be done once we have establish that friend functions
+  // inhabit the same context, otherwise we might tried to instantiate
+  // references to non-instantiated entities during constraint substitution.
+  // GH78101.
   if (NewTemplate) {
 // C++ [temp.over.link]p4:
 //   The signature of a function template consists of its function
@@ -1296,34 +1330,8 @@ static bool IsOverloadOrOverrideImpl(Sema &SemaRef, 
FunctionDecl *New,
   return true;
   }
 
-  // Is the function New an overload of the function Old?
-  QualType OldQType = SemaRef.Context.getCanonicalType(Old->getType());
-  QualType NewQType = SemaRef.Context.getCanonicalType(New->getType());
-
-  // Compare the signatures (C++ 1.3.10) of the two functions to
-  // determine whether they are overloads. If we find any mismatch
-  // in the signature, they are overloads.
 
-  // If either of these functions is a K&R-style function (no
-  // prototype), then we consider them to have matching signatures.
-  if (isa(OldQType.getTypePtr()) ||
-  isa(NewQType.getTypePtr()))
-return false;
 
-  const FunctionProtoType *OldType = cast(OldQType);
-  const FunctionProtoType *NewType = cast(NewQType);
-
-  // The signature of a function includes the types of its
-  // parameters (C++ 1.3.10), which includes the presence or absence
-  // of the ellipsis; see C++ DR 357).
-  if (OldQType != NewQType && OldType->isVariadic() != NewType->isVariadic())
-return true;
-
-  // For member-like friends, the enclosing class is part of the signature.
-  if ((New->isMemberLikeConstrainedFriend() ||
-   Old->isMemberLikeConstrainedFriend()) &&
-  !New->getLexicalDeclContext()->Equals(Old->getLexicalDeclContext()))
-return true;
   const auto *OldMethod = dyn_cast(Old);
   const auto *NewMethod = dyn_cast(New);
 
diff --git a/clang/test/CXX/over/over.load/p2-0x.cpp 
b/clang/test/CXX/over/over.load/p2-0x.cpp
index 8fd9a1ce1e87ab4..a86e2d2a1d81e51 100644
--- a/clang/test/CXX/over/over.load/p2-0x.cpp
+++ b/clang/test/CXX/over/over.load/p2-0x.cpp
@@ -24,11 +24,6 @@ class Y {
   void k() &&; // expected-error{{cannot overload a member function with 
ref-qualifier '&&' with a member function without a ref-qualifier}}
 };
 
-struct GH76358 {
-template void f() && {}
-template void f() const {}
-};
-
 
 #if __cplusplus >= 202002L
 namespace GH58962 {
@@ -55,4 +50,31 @@ static_assert(not test&>);
 static_assert(test&&>);
 
 }
+
+namespace GH78

[clang] [Clang] Only compare template params of potential overload after checking their decl context (PR #78139)

2024-01-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-modules

Author: cor3ntin (cor3ntin)


Changes



Fixes a regression from 69066ab3 in which we compared the template lists of 
potential overloads before checkings their declaration contexts.

This would cause a crash when doing constraint substitution as part of that 
template check, because we would try to refer to not yet instantiated entities 
(the underlying cause is unclear).

This patch reorders (again) when we look at template parameter so we don't when 
checkings friends in different lexical contexts.

Fixes #77953
Fixes #78101

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


3 Files Affected:

- (modified) clang/lib/Sema/SemaOverload.cpp (+34-26) 
- (modified) clang/test/CXX/over/over.load/p2-0x.cpp (+27-5) 
- (added) clang/test/Modules/GH77953.cpp (+28) 


``diff
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 23b9bc0fe2d6e2..4b84a60d4780b5 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -1259,6 +1259,40 @@ static bool IsOverloadOrOverrideImpl(Sema &SemaRef, 
FunctionDecl *New,
   if ((OldTemplate == nullptr) != (NewTemplate == nullptr))
 return true;
 
+  // Is the function New an overload of the function Old?
+  QualType OldQType = SemaRef.Context.getCanonicalType(Old->getType());
+  QualType NewQType = SemaRef.Context.getCanonicalType(New->getType());
+
+  // Compare the signatures (C++ 1.3.10) of the two functions to
+  // determine whether they are overloads. If we find any mismatch
+  // in the signature, they are overloads.
+
+  // If either of these functions is a K&R-style function (no
+  // prototype), then we consider them to have matching signatures.
+  if (isa(OldQType.getTypePtr()) ||
+  isa(NewQType.getTypePtr()))
+return false;
+
+  const FunctionProtoType *OldType = cast(OldQType);
+  const FunctionProtoType *NewType = cast(NewQType);
+
+  // The signature of a function includes the types of its
+  // parameters (C++ 1.3.10), which includes the presence or absence
+  // of the ellipsis; see C++ DR 357).
+  if (OldQType != NewQType && OldType->isVariadic() != NewType->isVariadic())
+return true;
+
+  // For member-like friends, the enclosing class is part of the signature.
+  if ((New->isMemberLikeConstrainedFriend() ||
+   Old->isMemberLikeConstrainedFriend()) &&
+  !New->getLexicalDeclContext()->Equals(Old->getLexicalDeclContext()))
+return true;
+
+  // Compare the parameter lists.
+  // This can only be done once we have establish that friend functions
+  // inhabit the same context, otherwise we might tried to instantiate
+  // references to non-instantiated entities during constraint substitution.
+  // GH78101.
   if (NewTemplate) {
 // C++ [temp.over.link]p4:
 //   The signature of a function template consists of its function
@@ -1296,34 +1330,8 @@ static bool IsOverloadOrOverrideImpl(Sema &SemaRef, 
FunctionDecl *New,
   return true;
   }
 
-  // Is the function New an overload of the function Old?
-  QualType OldQType = SemaRef.Context.getCanonicalType(Old->getType());
-  QualType NewQType = SemaRef.Context.getCanonicalType(New->getType());
-
-  // Compare the signatures (C++ 1.3.10) of the two functions to
-  // determine whether they are overloads. If we find any mismatch
-  // in the signature, they are overloads.
 
-  // If either of these functions is a K&R-style function (no
-  // prototype), then we consider them to have matching signatures.
-  if (isa(OldQType.getTypePtr()) ||
-  isa(NewQType.getTypePtr()))
-return false;
 
-  const FunctionProtoType *OldType = cast(OldQType);
-  const FunctionProtoType *NewType = cast(NewQType);
-
-  // The signature of a function includes the types of its
-  // parameters (C++ 1.3.10), which includes the presence or absence
-  // of the ellipsis; see C++ DR 357).
-  if (OldQType != NewQType && OldType->isVariadic() != NewType->isVariadic())
-return true;
-
-  // For member-like friends, the enclosing class is part of the signature.
-  if ((New->isMemberLikeConstrainedFriend() ||
-   Old->isMemberLikeConstrainedFriend()) &&
-  !New->getLexicalDeclContext()->Equals(Old->getLexicalDeclContext()))
-return true;
   const auto *OldMethod = dyn_cast(Old);
   const auto *NewMethod = dyn_cast(New);
 
diff --git a/clang/test/CXX/over/over.load/p2-0x.cpp 
b/clang/test/CXX/over/over.load/p2-0x.cpp
index 8fd9a1ce1e87ab..a86e2d2a1d81e5 100644
--- a/clang/test/CXX/over/over.load/p2-0x.cpp
+++ b/clang/test/CXX/over/over.load/p2-0x.cpp
@@ -24,11 +24,6 @@ class Y {
   void k() &&; // expected-error{{cannot overload a member function with 
ref-qualifier '&&' with a member function without a ref-qualifier}}
 };
 
-struct GH76358 {
-template void f() && {}
-template void f() const {}
-};
-
 
 #if __cplusplus >= 202002L
 namespace GH58962 {
@@ -55,4 +50,31 @@ static_assert(not test&>);
 static_assert(test&&>);
 
 }
+
+namespace 

[clang] [Clang] Only compare template params of potential overload after checking their decl context (PR #78139)

2024-01-15 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 08e4386a2c91befabab317498b50ffc326ff4eae 
e5be422e1d27a9e1066777e9114bba510e5195bb -- clang/test/Modules/GH77953.cpp 
clang/lib/Sema/SemaOverload.cpp clang/test/CXX/over/over.load/p2-0x.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 4b84a60d47..0d1db8d176 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -1330,8 +1330,6 @@ static bool IsOverloadOrOverrideImpl(Sema &SemaRef, 
FunctionDecl *New,
   return true;
   }
 
-
-
   const auto *OldMethod = dyn_cast(Old);
   const auto *NewMethod = dyn_cast(New);
 

``




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


[clang] [Clang] Only compare template params of potential overload after checking their decl context (PR #78139)

2024-01-15 Thread via cfe-commits

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

>From e0eb639c9830599e184aec428164de0b2fb38b71 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Mon, 15 Jan 2024 10:17:13 +0100
Subject: [PATCH] [Clang] Only compare template params of potential overload
 after checking their decl context

Fixes a regression from 69066ab3 in which we compared the template lists
of potential overloads before checkings their declaration contexts.

This would cause a crash when doing constraint substitution as part
of that template check, because we would try to refer to not yet
instantiated entities (the underlying cause is unclear).

This patch reorders (again) when we look at templaste parameter so
we don't when checkings friends in different lexical contexts.

Fixes #77953
Fixes #78101
---
 clang/lib/Sema/SemaOverload.cpp | 62 ++---
 clang/test/CXX/over/over.load/p2-0x.cpp | 32 +++--
 clang/test/Modules/GH77953.cpp  | 28 +++
 3 files changed, 89 insertions(+), 33 deletions(-)
 create mode 100644 clang/test/Modules/GH77953.cpp

diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 23b9bc0fe2d6e2..0d1db8d17610b2 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -1259,6 +1259,40 @@ static bool IsOverloadOrOverrideImpl(Sema &SemaRef, 
FunctionDecl *New,
   if ((OldTemplate == nullptr) != (NewTemplate == nullptr))
 return true;
 
+  // Is the function New an overload of the function Old?
+  QualType OldQType = SemaRef.Context.getCanonicalType(Old->getType());
+  QualType NewQType = SemaRef.Context.getCanonicalType(New->getType());
+
+  // Compare the signatures (C++ 1.3.10) of the two functions to
+  // determine whether they are overloads. If we find any mismatch
+  // in the signature, they are overloads.
+
+  // If either of these functions is a K&R-style function (no
+  // prototype), then we consider them to have matching signatures.
+  if (isa(OldQType.getTypePtr()) ||
+  isa(NewQType.getTypePtr()))
+return false;
+
+  const FunctionProtoType *OldType = cast(OldQType);
+  const FunctionProtoType *NewType = cast(NewQType);
+
+  // The signature of a function includes the types of its
+  // parameters (C++ 1.3.10), which includes the presence or absence
+  // of the ellipsis; see C++ DR 357).
+  if (OldQType != NewQType && OldType->isVariadic() != NewType->isVariadic())
+return true;
+
+  // For member-like friends, the enclosing class is part of the signature.
+  if ((New->isMemberLikeConstrainedFriend() ||
+   Old->isMemberLikeConstrainedFriend()) &&
+  !New->getLexicalDeclContext()->Equals(Old->getLexicalDeclContext()))
+return true;
+
+  // Compare the parameter lists.
+  // This can only be done once we have establish that friend functions
+  // inhabit the same context, otherwise we might tried to instantiate
+  // references to non-instantiated entities during constraint substitution.
+  // GH78101.
   if (NewTemplate) {
 // C++ [temp.over.link]p4:
 //   The signature of a function template consists of its function
@@ -1296,34 +1330,6 @@ static bool IsOverloadOrOverrideImpl(Sema &SemaRef, 
FunctionDecl *New,
   return true;
   }
 
-  // Is the function New an overload of the function Old?
-  QualType OldQType = SemaRef.Context.getCanonicalType(Old->getType());
-  QualType NewQType = SemaRef.Context.getCanonicalType(New->getType());
-
-  // Compare the signatures (C++ 1.3.10) of the two functions to
-  // determine whether they are overloads. If we find any mismatch
-  // in the signature, they are overloads.
-
-  // If either of these functions is a K&R-style function (no
-  // prototype), then we consider them to have matching signatures.
-  if (isa(OldQType.getTypePtr()) ||
-  isa(NewQType.getTypePtr()))
-return false;
-
-  const FunctionProtoType *OldType = cast(OldQType);
-  const FunctionProtoType *NewType = cast(NewQType);
-
-  // The signature of a function includes the types of its
-  // parameters (C++ 1.3.10), which includes the presence or absence
-  // of the ellipsis; see C++ DR 357).
-  if (OldQType != NewQType && OldType->isVariadic() != NewType->isVariadic())
-return true;
-
-  // For member-like friends, the enclosing class is part of the signature.
-  if ((New->isMemberLikeConstrainedFriend() ||
-   Old->isMemberLikeConstrainedFriend()) &&
-  !New->getLexicalDeclContext()->Equals(Old->getLexicalDeclContext()))
-return true;
   const auto *OldMethod = dyn_cast(Old);
   const auto *NewMethod = dyn_cast(New);
 
diff --git a/clang/test/CXX/over/over.load/p2-0x.cpp 
b/clang/test/CXX/over/over.load/p2-0x.cpp
index 8fd9a1ce1e87ab..a86e2d2a1d81e5 100644
--- a/clang/test/CXX/over/over.load/p2-0x.cpp
+++ b/clang/test/CXX/over/over.load/p2-0x.cpp
@@ -24,11 +24,6 @@ class Y {
   void k() &&; // expected-error{{cannot overload a member function with 
ref-qualifier '&&' with a member function 

[clang] [llvm] [clang-tools-extra] [AMDGPU][GFX12] Add 16 bit atomic fadd instructions (PR #75917)

2024-01-15 Thread Mariusz Sikora via cfe-commits


@@ -0,0 +1,92 @@
+// RUN: %clang_cc1 -O0 -cl-std=CL2.0 -triple amdgcn-amd-amdhsa -target-cpu 
gfx1200 \
+// RUN:   %s -S -emit-llvm -o - | FileCheck %s
+
+// RUN: %clang_cc1 -O0 -cl-std=CL2.0 -triple amdgcn-amd-amdhsa -target-cpu 
gfx1200 \
+// RUN:   -S -o - %s | FileCheck -check-prefix=GFX12 %s
+

mariusz-sikora-at-amd wrote:

Added here: 
https://github.com/llvm/llvm-project/blob/main/clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx11-err.cl

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


[clang] [llvm] [clang-tools-extra] [AMDGPU][GFX12] Add 16 bit atomic fadd instructions (PR #75917)

2024-01-15 Thread Mariusz Sikora via cfe-commits


@@ -362,24 +358,34 @@ define amdgpu_ps void 
@struct_buffer_atomic_add_v2f16_noret(<2 x half> %val, <4
   ret void
 }
 
-define amdgpu_ps float @struct_buffer_atomic_add_v2bf16_ret(<2 x i16> %val, <4 
x i32> inreg %rsrc, i32 %vindex, i32 %voffset, i32 inreg %soffset) {
+define amdgpu_ps float @struct_buffer_atomic_add_v2bf16_ret(<2 x bfloat> %val, 
<4 x i32> inreg %rsrc, i32 %vindex, i32 %voffset, i32 inreg %soffset) {
 ; GFX12-LABEL: struct_buffer_atomic_add_v2bf16_ret:
 ; GFX12:   ; %bb.0:
 ; GFX12-NEXT:buffer_atomic_pk_add_bf16 v0, v[1:2], s[0:3], s4 idxen offen 
th:TH_ATOMIC_RETURN
+; GFX12-NEXT:v_mov_b32_e32 v1, 0
+; GFX12-NEXT:v_mov_b32_e32 v2, 0
 ; GFX12-NEXT:s_waitcnt vmcnt(0)
+; GFX12-NEXT:flat_store_b32 v[1:2], v0
+; GFX12-NEXT:v_mov_b32_e32 v0, 1.0
+; GFX12-NEXT:s_waitcnt lgkmcnt(0)
 ; GFX12-NEXT:; return to shader part epilog
 ;
 ; GFX12-GISEL-LABEL: struct_buffer_atomic_add_v2bf16_ret:
 ; GFX12-GISEL:   ; %bb.0:
 ; GFX12-GISEL-NEXT:buffer_atomic_pk_add_bf16 v0, v[1:2], s[0:3], s4 idxen 
offen th:TH_ATOMIC_RETURN
+; GFX12-GISEL-NEXT:v_mov_b32_e32 v1, 0
+; GFX12-GISEL-NEXT:v_mov_b32_e32 v2, 0
 ; GFX12-GISEL-NEXT:s_waitcnt vmcnt(0)
+; GFX12-GISEL-NEXT:flat_store_b32 v[1:2], v0
+; GFX12-GISEL-NEXT:v_mov_b32_e32 v0, 1.0
+; GFX12-GISEL-NEXT:s_waitcnt lgkmcnt(0)
 ; GFX12-GISEL-NEXT:; return to shader part epilog
-  %orig = call <2 x i16> @llvm.amdgcn.struct.buffer.atomic.fadd.v2bf16(<2 x 
i16> %val, <4 x i32> %rsrc, i32 %vindex, i32 %voffset, i32 %soffset, i32 0)
-  %r = bitcast <2 x i16> %orig to float

mariusz-sikora-at-amd wrote:

Found issue in GlobalISel and bitcast with bfloat type. I prepare fix and push 
in different change.

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


[clang] [llvm] [clang-tools-extra] [AMDGPU][GFX12] Add 16 bit atomic fadd instructions (PR #75917)

2024-01-15 Thread Mariusz Sikora via cfe-commits


@@ -27,34 +27,23 @@ main_body:
   ret float %out0
 }
 
-define amdgpu_ps float @atomic_pk_add_bf16_1d_v2(<8 x i32> inreg %rsrc, <2 x 
i16> %data, i32 %s) {
+define amdgpu_ps float @atomic_pk_add_bf16_1d_v2(<8 x i32> inreg %rsrc, <2 x 
bfloat> %data, i32 %s) {
 ; GFX12-LABEL: atomic_pk_add_bf16_1d_v2:
 ; GFX12:   ; %bb.0: ; %main_body
 ; GFX12-NEXT:image_atomic_pk_add_bf16 v0, v1, s[0:7] dmask:0x1 
dim:SQ_RSRC_IMG_1D th:TH_ATOMIC_RETURN
+; GFX12-NEXT:v_mov_b32_e32 v1, 0
+; GFX12-NEXT:v_mov_b32_e32 v2, 0
 ; GFX12-NEXT:s_waitcnt vmcnt(0)
+; GFX12-NEXT:flat_store_b32 v[1:2], v0
+; GFX12-NEXT:v_mov_b32_e32 v0, 1.0
+; GFX12-NEXT:s_waitcnt lgkmcnt(0)
 ; GFX12-NEXT:; return to shader part epilog
 main_body:
-  %out = call <2 x i16> 
@llvm.amdgcn.image.atomic.pk.add.bf16.1d.v2i16.v2i16(<2 x i16> %data, i32 %s, 
<8 x i32> %rsrc, i32 0, i32 0)
-  %out_i32 = bitcast <2 x i16> %out to i32
-  %out_float = bitcast i32 %out_i32 to float
-  ret float %out_float
-}
-
-define amdgpu_ps float @atomic_pk_add_bf16_1d_v4(<8 x i32> inreg %rsrc, <4 x 
i16> %data, i32 %s) {
-; GFX12-LABEL: atomic_pk_add_bf16_1d_v4:
-; GFX12:   ; %bb.0: ; %main_body
-; GFX12-NEXT:image_atomic_pk_add_bf16 v[0:1], v2, s[0:7] dmask:0x3 
dim:SQ_RSRC_IMG_1D th:TH_ATOMIC_RETURN
-; GFX12-NEXT:s_waitcnt vmcnt(0)
-; GFX12-NEXT:; return to shader part epilog
-main_body:
-  %out = call <4 x i16> 
@llvm.amdgcn.image.atomic.pk.add.bf16.1d.v4i16.v4i16(<4 x i16> %data, i32 %s, 
<8 x i32> %rsrc, i32 0, i32 0)

mariusz-sikora-at-amd wrote:

Found issue with <4 x bfloat> and GlobalISel. I will try to debug this and 
prepare fix.

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


[llvm] [lldb] [libcxx] [clang-tools-extra] [clang] [lld] [flang] [mlir] [compiler-rt] [clang-tidy]Add new check readability-avoid-nested-conditional-operator (PR #78022)

2024-01-15 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/78022

>From 0988bb25a35e5d50b44bf53d459098777280c3e5 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Sat, 13 Jan 2024 16:00:16 +0800
Subject: [PATCH 1/3] [clang-tidy]Add new check
 readability-avoid-nested-conditional-operator Finds nested conditional
 operator. Nested conditional operators lead code hard to understand, so they
 should be splited as several statement and stored in temporary varibale.

---
 .../AvoidNestedConditionalOperatorCheck.cpp   | 56 +++
 .../AvoidNestedConditionalOperatorCheck.h | 33 +++
 .../clang-tidy/readability/CMakeLists.txt |  1 +
 .../readability/ReadabilityTidyModule.cpp |  3 +
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 ++
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../avoid-nested-conditional-operator.rst | 20 +++
 .../avoid-nested-conditional-operator.cpp | 23 
 8 files changed, 142 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/readability/AvoidNestedConditionalOperatorCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/readability/AvoidNestedConditionalOperatorCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/readability/avoid-nested-conditional-operator.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/avoid-nested-conditional-operator.cpp

diff --git 
a/clang-tools-extra/clang-tidy/readability/AvoidNestedConditionalOperatorCheck.cpp
 
b/clang-tools-extra/clang-tidy/readability/AvoidNestedConditionalOperatorCheck.cpp
new file mode 100644
index 00..a0278c3ae32fa7
--- /dev/null
+++ 
b/clang-tools-extra/clang-tidy/readability/AvoidNestedConditionalOperatorCheck.cpp
@@ -0,0 +1,56 @@
+//===--- AvoidNestedConditionalOperatorCheck.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 "AvoidNestedConditionalOperatorCheck.h"
+#include "clang/AST/Expr.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/DiagnosticIDs.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+namespace {
+constexpr const char *Description = "don't use nested conditional operator";
+constexpr const char *OutSideConditionalOperatorNote =
+"outside conditional operator here";
+} // namespace
+
+void AvoidNestedConditionalOperatorCheck::registerMatchers(
+MatchFinder *Finder) {
+  Finder->addMatcher(
+  conditionalOperator(
+  anyOf(
+  hasCondition(ignoringParenCasts(
+  conditionalOperator().bind("nested-conditional-operator"))),
+  hasTrueExpression(ignoringParenCasts(
+  conditionalOperator().bind("nested-conditional-operator"))),
+  hasFalseExpression(ignoringParenCasts(
+  conditionalOperator().bind("nested-conditional-operator")
+  .bind("conditional-operator"),
+  this);
+}
+
+void AvoidNestedConditionalOperatorCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *CO =
+  Result.Nodes.getNodeAs("conditional-operator");
+  const auto *NCO = Result.Nodes.getNodeAs(
+  "nested-conditional-operator");
+  assert(CO);
+  assert(NCO);
+
+  if (CO->getBeginLoc().isMacroID() || NCO->getBeginLoc().isMacroID())
+return;
+
+  diag(NCO->getBeginLoc(), Description);
+  diag(CO->getBeginLoc(), OutSideConditionalOperatorNote, DiagnosticIDs::Note);
+}
+
+} // namespace clang::tidy::readability
diff --git 
a/clang-tools-extra/clang-tidy/readability/AvoidNestedConditionalOperatorCheck.h
 
b/clang-tools-extra/clang-tidy/readability/AvoidNestedConditionalOperatorCheck.h
new file mode 100644
index 00..2f82ea86cd849d
--- /dev/null
+++ 
b/clang-tools-extra/clang-tidy/readability/AvoidNestedConditionalOperatorCheck.h
@@ -0,0 +1,33 @@
+//===--- AvoidNestedConditionalOperatorCheck.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_READABILITY_AVOIDNestedConditionalOperatorCHECK_H
+#define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_AVOIDNestedConditionalOperatorCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::readability {
+
+/// Finds nested conditional operator.
+///
+/// For the user-facing documentation see:
+/// 
http://clang.llvm.org/extra/clang-tidy/checks/readability/avoid-nested-conditional-ope

[clang] [llvm] [clang-tools-extra] [AMDGPU][GFX12] Add 16 bit atomic fadd instructions (PR #75917)

2024-01-15 Thread Mariusz Sikora via cfe-commits

mariusz-sikora-at-amd wrote:

What is the plan for atomic_{flat/ds/global}_bf16 builtins ? Right now they are 
accepting <2 x i16> instead of <2 x bfloat>. Do we want to create new builtins 
or we want to override them to accept both <2 x i16> and <2 x bfloat> ? 

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


[clang] [clang] Implement CWG1878 "`operator auto` template" (PR #78103)

2024-01-15 Thread via cfe-commits


@@ -11322,9 +11322,22 @@ Decl 
*Sema::ActOnConversionDeclarator(CXXConversionDecl *Conversion) {
   << ClassType << ConvType;
   }
 
-  if (FunctionTemplateDecl *ConversionTemplate
-= Conversion->getDescribedFunctionTemplate())
+  if (FunctionTemplateDecl *ConversionTemplate =
+  Conversion->getDescribedFunctionTemplate()) {
+if (ConvType->isUndeducedAutoType()) {
+  Diag(Conversion->getTypeSpecStartLoc(), diag::err_auto_not_allowed)
+  << Conversion->getTypeSourceInfo()
+ ->getTypeLoc()
+ .getContainedAutoTypeLoc()

cor3ntin wrote:

Just the  return type.
There is even simpler actually

```cpp
getReturnTypeLoc(Conversion).getSourceRange()
```
 

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


[llvm] [clang] [clang-tools-extra] [AMDGPU][GFX12] Add Atomic cond_sub_u32 (PR #76224)

2024-01-15 Thread Mariusz Sikora via cfe-commits

mariusz-sikora-at-amd wrote:

ping

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


[clang] [clang-bindings] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-01-15 Thread Jannick Kremer via cfe-commits

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


[clang] [clang][ExprConst] allow single element access of vector object to be constant expression (PR #72607)

2024-01-15 Thread Timm Baeder via cfe-commits

tbaederr wrote:

This basically looks good to me, but I don't know much about vector types.

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


[clang] [clang-bindings] Add strict typing to clang Python bindings (#76664) (PR #78114)

2024-01-15 Thread Jannick Kremer via cfe-commits

DeinAlptraum wrote:

I was just made aware of 
[some](https://github.com/llvm/llvm-project/pull/77219) 
[changes](https://github.com/llvm/llvm-project/pull/77228) by @linux4life798 
that seem reasonable to merge before this, so I've returned this  to draft 
status for now. Sorry for the confusion.

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


[clang-tools-extra] 8e21557 - [clang-tidy]Add new check readability-avoid-nested-conditional-operator (#78022)

2024-01-15 Thread via cfe-commits

Author: Congcong Cai
Date: 2024-01-15T18:19:47+08:00
New Revision: 8e21557d0401a0046ff110daa50f21d02b71a2ee

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

LOG: [clang-tidy]Add new check readability-avoid-nested-conditional-operator 
(#78022)

Finds nested conditional operator.
Nested conditional operators lead code hard to understand, so they
should be splited as several statement and stored in temporary varibale.

Added: 

clang-tools-extra/clang-tidy/readability/AvoidNestedConditionalOperatorCheck.cpp

clang-tools-extra/clang-tidy/readability/AvoidNestedConditionalOperatorCheck.h

clang-tools-extra/docs/clang-tidy/checks/readability/avoid-nested-conditional-operator.rst

clang-tools-extra/test/clang-tidy/checkers/readability/avoid-nested-conditional-operator.cpp

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

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/AvoidNestedConditionalOperatorCheck.cpp
 
b/clang-tools-extra/clang-tidy/readability/AvoidNestedConditionalOperatorCheck.cpp
new file mode 100644
index 00..2ea03c9070526f
--- /dev/null
+++ 
b/clang-tools-extra/clang-tidy/readability/AvoidNestedConditionalOperatorCheck.cpp
@@ -0,0 +1,52 @@
+//===--- AvoidNestedConditionalOperatorCheck.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 "AvoidNestedConditionalOperatorCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/DiagnosticIDs.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+void AvoidNestedConditionalOperatorCheck::registerMatchers(
+MatchFinder *Finder) {
+  Finder->addMatcher(
+  conditionalOperator(
+  anyOf(
+  hasCondition(ignoringParenCasts(
+  conditionalOperator().bind("nested-conditional-operator"))),
+  hasTrueExpression(ignoringParenCasts(
+  conditionalOperator().bind("nested-conditional-operator"))),
+  hasFalseExpression(ignoringParenCasts(
+  conditionalOperator().bind("nested-conditional-operator")
+  .bind("conditional-operator"),
+  this);
+}
+
+void AvoidNestedConditionalOperatorCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *CO =
+  Result.Nodes.getNodeAs("conditional-operator");
+  const auto *NCO = Result.Nodes.getNodeAs(
+  "nested-conditional-operator");
+  assert(CO);
+  assert(NCO);
+
+  if (CO->getBeginLoc().isMacroID() || NCO->getBeginLoc().isMacroID())
+return;
+
+  diag(NCO->getBeginLoc(),
+   "conditional operator is used as sub-expression of parent conditional "
+   "operator, refrain from using nested conditional operators");
+  diag(CO->getBeginLoc(), "parent conditional operator here",
+   DiagnosticIDs::Note);
+}
+
+} // namespace clang::tidy::readability

diff  --git 
a/clang-tools-extra/clang-tidy/readability/AvoidNestedConditionalOperatorCheck.h
 
b/clang-tools-extra/clang-tidy/readability/AvoidNestedConditionalOperatorCheck.h
new file mode 100644
index 00..9010156de6ce2d
--- /dev/null
+++ 
b/clang-tools-extra/clang-tidy/readability/AvoidNestedConditionalOperatorCheck.h
@@ -0,0 +1,33 @@
+//===--- AvoidNestedConditionalOperatorCheck.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_READABILITY_AVOID_NESTED_CONDITIONAL_OPERATOR_CHECK_H
+#define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_AVOID_NESTED_CONDITIONAL_OPERATOR_CHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::readability {
+
+/// Identifies instances of nested conditional operators in the code.
+///
+/// For the user-facing documentation see:
+/// 
http://clang.llvm.org/extra/clang-tidy/checks/readability/avoid-nested-conditional-operator.html
+class AvoidNestedConditionalOperatorCheck : public ClangTidyCheck {
+public:
+  AvoidNestedConditionalOperatorCheck(StringRef Name, ClangTidyContext 
*Context)
+  : ClangTidyCheck(Name, 

[compiler-rt] [clang-tools-extra] [lld] [clang] [lldb] [libcxx] [llvm] [mlir] [flang] [clang-tidy]Add new check readability-avoid-nested-conditional-operator (PR #78022)

2024-01-15 Thread Congcong Cai via cfe-commits

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


[clang] [clang][Interp] Add inline descriptor to global variables (PR #72892)

2024-01-15 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


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

>From a5b16989efd7deaef47fc6e35032f2abf5e3a9da Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Mon, 20 Nov 2023 11:53:40 +0100
Subject: [PATCH 1/3] [clang][Interp] Add inline descriptor to global variables

---
 clang/lib/AST/Interp/ByteCodeExprGen.cpp | 15 ++-
 clang/lib/AST/Interp/Descriptor.cpp  | 25 +--
 clang/lib/AST/Interp/Descriptor.h|  7 +--
 clang/lib/AST/Interp/Interp.cpp  | 16 +++
 clang/lib/AST/Interp/Interp.h| 26 +---
 clang/lib/AST/Interp/Pointer.cpp |  4 +-
 clang/lib/AST/Interp/Pointer.h   | 30 +
 clang/lib/AST/Interp/Program.cpp | 54 ++--
 clang/test/AST/Interp/cxx17.cpp  | 23 --
 clang/test/AST/Interp/cxx23.cpp  | 24 ---
 clang/test/AST/Interp/literals.cpp   | 17 
 11 files changed, 184 insertions(+), 57 deletions(-)

diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index d6be9a306aeaf67..981e319a3080542 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -830,13 +830,26 @@ bool ByteCodeExprGen::VisitInitListExpr(const 
InitListExpr *E) {
 return this->visitInitList(E->inits(), E);
 
   if (T->isArrayType()) {
-// FIXME: Array fillers.
 unsigned ElementIndex = 0;
 for (const Expr *Init : E->inits()) {
   if (!this->visitArrayElemInit(ElementIndex, Init))
 return false;
   ++ElementIndex;
 }
+
+// Expand the filler expression.
+// FIXME: This should go away.
+if (const Expr *Filler = E->getArrayFiller()) {
+  const ConstantArrayType *CAT =
+  Ctx.getASTContext().getAsConstantArrayType(E->getType());
+  uint64_t NumElems = CAT->getSize().getZExtValue();
+
+  for (; ElementIndex != NumElems; ++ElementIndex) {
+if (!this->visitArrayElemInit(ElementIndex, Filler))
+  return false;
+  }
+}
+
 return true;
   }
 
diff --git a/clang/lib/AST/Interp/Descriptor.cpp 
b/clang/lib/AST/Interp/Descriptor.cpp
index b330e54baf335a7..5701cf0acf915dc 100644
--- a/clang/lib/AST/Interp/Descriptor.cpp
+++ b/clang/lib/AST/Interp/Descriptor.cpp
@@ -243,18 +243,19 @@ Descriptor::Descriptor(const DeclTy &D, PrimType Type, 
MetadataSize MD,
bool IsMutable)
 : Source(D), ElemSize(primSize(Type)), Size(ElemSize * NumElems),
   MDSize(MD.value_or(0)),
-  AllocSize(align(Size) + sizeof(InitMapPtr) + MDSize), IsConst(IsConst),
-  IsMutable(IsMutable), IsTemporary(IsTemporary), IsArray(true),
-  CtorFn(getCtorArrayPrim(Type)), DtorFn(getDtorArrayPrim(Type)),
-  MoveFn(getMoveArrayPrim(Type)) {
+  AllocSize(align(MDSize) + align(Size) + sizeof(InitMapPtr)),
+  IsConst(IsConst), IsMutable(IsMutable), IsTemporary(IsTemporary),
+  IsArray(true), CtorFn(getCtorArrayPrim(Type)),
+  DtorFn(getDtorArrayPrim(Type)), MoveFn(getMoveArrayPrim(Type)) {
   assert(Source && "Missing source");
 }
 
 /// Primitive unknown-size arrays.
-Descriptor::Descriptor(const DeclTy &D, PrimType Type, bool IsTemporary,
-   UnknownSize)
-: Source(D), ElemSize(primSize(Type)), Size(UnknownSizeMark), MDSize(0),
-  AllocSize(alignof(void *) + sizeof(InitMapPtr)), IsConst(true),
+Descriptor::Descriptor(const DeclTy &D, PrimType Type, MetadataSize MD,
+   bool IsTemporary, UnknownSize)
+: Source(D), ElemSize(primSize(Type)), Size(UnknownSizeMark),
+  MDSize(MD.value_or(0)),
+  AllocSize(MDSize + sizeof(InitMapPtr) + alignof(void *)), IsConst(true),
   IsMutable(false), IsTemporary(IsTemporary), IsArray(true),
   CtorFn(getCtorArrayPrim(Type)), DtorFn(getDtorArrayPrim(Type)),
   MoveFn(getMoveArrayPrim(Type)) {
@@ -275,12 +276,12 @@ Descriptor::Descriptor(const DeclTy &D, const Descriptor 
*Elem, MetadataSize MD,
 }
 
 /// Unknown-size arrays of composite elements.
-Descriptor::Descriptor(const DeclTy &D, const Descriptor *Elem,
+Descriptor::Descriptor(const DeclTy &D, const Descriptor *Elem, MetadataSize 
MD,
bool IsTemporary, UnknownSize)
 : Source(D), ElemSize(Elem->getAllocSize() + sizeof(InlineDescriptor)),
-  Size(UnknownSizeMark), MDSize(0),
-  AllocSize(alignof(void *) + sizeof(InitMapPtr)), ElemDesc(Elem),
-  IsConst(true), IsMutable(false), IsTemporary(IsTemporary), IsArray(true),
+  Size(UnknownSizeMark), MDSize(MD.value_or(0)),
+  AllocSize(MDSize + alignof(void *)), ElemDesc(Elem), IsConst(true),
+  IsMutable(false), IsTemporary(IsTemporary), IsArray(true),
   CtorFn(ctorArrayDesc), DtorFn(dtorArrayDesc), MoveFn(moveArrayDesc) {
   assert(Source && "Missing source");
 }
diff --git a/clang/lib/AST/Interp/Descriptor.h 
b/clang/lib/A

[clang] [Clang][SME] Detect always_inline used with mismatched streaming attributes (PR #77936)

2024-01-15 Thread Sam Tebbs via cfe-commits


@@ -812,6 +819,23 @@ Address AArch64ABIInfo::EmitMSVAArg(CodeGenFunction &CGF, 
Address VAListAddr,
   /*allowHigherAlign*/ false);
 }
 
+void AArch64TargetCodeGenInfo::checkFunctionCallABI(
+CodeGenModule &CGM, SourceLocation CallLoc, const FunctionDecl *Caller,
+const FunctionDecl *Callee, const CallArgList &Args) const {
+  if (!Callee->hasAttr())
+return;
+
+  auto CalleeIsStreaming =
+  Sema::getArmStreamingFnType(Callee) == Sema::ArmStreaming;
+  auto CallerIsStreaming =
+  Sema::getArmStreamingFnType(Caller) == Sema::ArmStreaming;
+
+  if (CalleeIsStreaming && !CallerIsStreaming)

SamTebbs33 wrote:

That makes sense, thank you. I also realised that it'll need to check if the 
caller is streaming_compatible but the callee isn't, so I'll add that too.

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


[clang-tools-extra] [llvm] [clang] [AMDGPU][GFX12] Add Atomic cond_sub_u32 (PR #76224)

2024-01-15 Thread Jay Foad via cfe-commits

jayfoad wrote:

> Adding support in atomicrmw. This will require to add new operation to 
> aromicrmw "cond_sub"

Yes, and we have (Matt has) done this in the past, but it will require a wider 
consensus. I think it's fine to add AMDGPU intrinsics for this in the mean time.

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


[clang] [clang][Interp] Fix diagnosing non-const variables pre-C++11 (PR #76718)

2024-01-15 Thread Timm Baeder via cfe-commits

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

>From aa6691d530024a57be78b19e9a682b4676a235d6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sat, 30 Dec 2023 20:46:13 +0100
Subject: [PATCH] [clang][Interp] Fix diagnosing non-const variables pre-C++11

In CheckConstant(), consider that in C++98 const variables may not be
read at all, and diagnose that accordingly.
---
 clang/lib/AST/Interp/Interp.cpp | 42 ++---
 clang/test/AST/Interp/cxx11.cpp | 24 +++
 clang/test/AST/Interp/cxx98.cpp | 36 
 3 files changed, 93 insertions(+), 9 deletions(-)
 create mode 100644 clang/test/AST/Interp/cxx11.cpp
 create mode 100644 clang/test/AST/Interp/cxx98.cpp

diff --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index b95a52199846fa0..bdb86322df663e9 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -59,12 +59,16 @@ static void diagnoseNonConstVariable(InterpState &S, 
CodePtr OpPC,
 return;
 
   const SourceInfo &Loc = S.Current->getSource(OpPC);
-  S.FFDiag(Loc,
-   VD->getType()->isIntegralOrEnumerationType()
-   ? diag::note_constexpr_ltor_non_const_int
-   : diag::note_constexpr_ltor_non_constexpr,
-   1)
-  << VD;
+
+  if (VD->getType()->isIntegralOrEnumerationType())
+S.FFDiag(Loc, diag::note_constexpr_ltor_non_const_int, 1) << VD;
+  else
+S.FFDiag(Loc,
+ S.getLangOpts().CPlusPlus11
+ ? diag::note_constexpr_ltor_non_constexpr
+ : diag::note_constexpr_ltor_non_integral,
+ 1)
+<< VD << VD->getType();
   S.Note(VD->getLocation(), diag::note_declared_at);
 }
 
@@ -231,12 +235,32 @@ bool CheckLive(InterpState &S, CodePtr OpPC, const 
Pointer &Ptr,
 
 bool CheckConstant(InterpState &S, CodePtr OpPC, const Descriptor *Desc) {
   assert(Desc);
+
+  auto IsConstType = [&S](const VarDecl *VD) -> bool {
+if (VD->isConstexpr())
+  return true;
+
+if (S.getLangOpts().CPlusPlus && !S.getLangOpts().CPlusPlus11)
+  return false;
+
+QualType T = VD->getType();
+if (T.isConstQualified())
+  return true;
+
+if (const auto *RT = T->getAs())
+  return RT->getPointeeType().isConstQualified();
+
+if (const auto *PT = T->getAs())
+  return PT->getPointeeType().isConstQualified();
+
+return false;
+  };
+
   if (const auto *D = Desc->asValueDecl()) {
 if (const auto *VD = dyn_cast(D);
-VD && VD->hasGlobalStorage() &&
-!(VD->isConstexpr() || VD->getType().isConstQualified())) {
+VD && VD->hasGlobalStorage() && !IsConstType(VD)) {
   diagnoseNonConstVariable(S, OpPC, VD);
-  return false;
+  return S.inConstantContext();
 }
   }
 
diff --git a/clang/test/AST/Interp/cxx11.cpp b/clang/test/AST/Interp/cxx11.cpp
new file mode 100644
index 000..81e293fec175020
--- /dev/null
+++ b/clang/test/AST/Interp/cxx11.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter 
-verify=both,expected -std=c++11 %s
+// RUN: %clang_cc1 -verify=both,ref -std=c++11 %s
+
+// expected-no-diagnostics
+
+namespace IntOrEnum {
+  const int k = 0;
+  const int &p = k;
+  template struct S {};
+  S s;
+}
+
+const int cval = 2;
+template  struct C{};
+template struct C;
+
+
+/// FIXME: This example does not get properly diagnosed in the new interpreter.
+extern const int recurse1;
+const int recurse2 = recurse1; // ref-note {{here}}
+const int recurse1 = 1;
+int array1[recurse1];
+int array2[recurse2]; // ref-warning 2{{variable length array}} \
+  // ref-note {{initializer of 'recurse2' is not a 
constant expression}}
diff --git a/clang/test/AST/Interp/cxx98.cpp b/clang/test/AST/Interp/cxx98.cpp
new file mode 100644
index 000..bc96723c2287da4
--- /dev/null
+++ b/clang/test/AST/Interp/cxx98.cpp
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter 
-verify=both,expected -std=c++98 %s
+// RUN: %clang_cc1 -verify=both,ref -std=c++98 %s
+
+
+
+namespace IntOrEnum {
+  const int k = 0;
+  const int &p = k; // both-note {{declared here}}
+  template struct S {};
+  S s; // both-error {{not an integral constant expression}} \
+  // both-note {{read of variable 'p' of non-integral, non-enumeration 
type 'const int &'}}
+}
+
+const int cval = 2;
+template  struct C{};
+template struct C;
+
+
+/// FIXME: This example does not get properly diagnosed in the new interpreter.
+extern const int recurse1;
+const int recurse2 = recurse1; // ref-note {{here}}
+const int recurse1 = 1;
+int array1[recurse1];
+int array2[recurse2]; // ref-warning 2{{variable length array}} \
+  // ref-note {{initializer of 'recurse2' is not a 
constant expression}} \
+  // expected-warning {{variable length array}} \
+  // expected-error {{variable length

[llvm] [clang] [AMDGPU] Add global_load_tr for GFX12 (PR #77772)

2024-01-15 Thread Piotr Sobczak via cfe-commits

https://github.com/piotrAMD updated 
https://github.com/llvm/llvm-project/pull/2

>From 1b2085465dd0988459a4c71dab6cd65b1de065be Mon Sep 17 00:00:00 2001
From: Piotr Sobczak 
Date: Thu, 11 Jan 2024 14:52:59 +0100
Subject: [PATCH 1/4] [AMDGPU] Add global_load_tr for GFX12

Support new amdgcn_global_load_tr instructions for load with transpose.

* MC layer support for GLOBAL_LOAD_TR_B64/GLOBAL_LOAD_TR_B128
* Intrinsics int_amdgcn_global_load_tr_b64/int_amdgcn_global_load_tr_b128
* Clang builtins amdgcn_global_load_tr_b64/amdgcn_global_load_tr_b128
---
 clang/include/clang/Basic/BuiltinsAMDGPU.def  |   7 ++
 clang/lib/CodeGen/CGBuiltin.cpp   |  45 
 ...uiltins-amdgcn-global-load-tr-gfx11-err.cl |  26 +
 ...ins-amdgcn-global-load-tr-gfx12-w32-err.cl |  15 +++
 ...ins-amdgcn-global-load-tr-gfx12-w64-err.cl |  16 +++
 .../builtins-amdgcn-global-load-tr-w32.cl |  48 
 .../builtins-amdgcn-global-load-tr-w64.cl |  47 
 llvm/include/llvm/IR/IntrinsicsAMDGPU.td  |  21 
 .../Target/AMDGPU/AMDGPURegisterBankInfo.cpp  |   2 +
 .../Disassembler/AMDGPUDisassembler.cpp   |   4 +
 llvm/lib/Target/AMDGPU/FLATInstructions.td|  33 ++
 .../AMDGPU/llvm.amdgcn.global.load.tr-w32.ll  | 106 ++
 .../AMDGPU/llvm.amdgcn.global.load.tr-w64.ll  | 106 ++
 llvm/test/MC/AMDGPU/gfx11_unsupported.s   |   6 +
 .../test/MC/AMDGPU/gfx12_asm_global_load_tr.s | 103 +
 .../AMDGPU/gfx12_dasm_global_load_tr.txt  |  34 ++
 16 files changed, 619 insertions(+)
 create mode 100644 
clang/test/CodeGenOpenCL/builtins-amdgcn-global-load-tr-gfx11-err.cl
 create mode 100644 
clang/test/CodeGenOpenCL/builtins-amdgcn-global-load-tr-gfx12-w32-err.cl
 create mode 100644 
clang/test/CodeGenOpenCL/builtins-amdgcn-global-load-tr-gfx12-w64-err.cl
 create mode 100644 
clang/test/CodeGenOpenCL/builtins-amdgcn-global-load-tr-w32.cl
 create mode 100644 
clang/test/CodeGenOpenCL/builtins-amdgcn-global-load-tr-w64.cl
 create mode 100644 llvm/test/CodeGen/AMDGPU/llvm.amdgcn.global.load.tr-w32.ll
 create mode 100644 llvm/test/CodeGen/AMDGPU/llvm.amdgcn.global.load.tr-w64.ll
 create mode 100644 llvm/test/MC/AMDGPU/gfx12_asm_global_load_tr.s
 create mode 100644 
llvm/test/MC/Disassembler/AMDGPU/gfx12_dasm_global_load_tr.txt

diff --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def 
b/clang/include/clang/Basic/BuiltinsAMDGPU.def
index e562ef04a30194e..098c309f8085375 100644
--- a/clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -423,6 +423,13 @@ TARGET_BUILTIN(__builtin_amdgcn_s_wakeup_barrier, "vi", 
"n", "gfx12-insts")
 TARGET_BUILTIN(__builtin_amdgcn_s_barrier_leave, "b", "n", "gfx12-insts")
 TARGET_BUILTIN(__builtin_amdgcn_s_get_barrier_state, "Uii", "n", "gfx12-insts")
 
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b64_v2i32, "V2iV2i*1", "nc", 
"gfx12-insts,wavefrontsize32")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v8i16, "V8sV8s*1", "nc", 
"gfx12-insts,wavefrontsize32")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v8f16, "V8hV8h*1", "nc", 
"gfx12-insts,wavefrontsize32")
+
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b64_i32, "ii*1", "nc", 
"gfx12-insts,wavefrontsize64")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v4i16, "V4sV4s*1", "nc", 
"gfx12-insts,wavefrontsize64")
+TARGET_BUILTIN(__builtin_amdgcn_global_load_tr_b128_v4f16, "V4hV4h*1", "nc", 
"gfx12-insts,wavefrontsize64")
 
 #undef BUILTIN
 #undef TARGET_BUILTIN
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 998fcc3af581753..dc634b1c388f46f 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18178,6 +18178,51 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
BuiltinID,
 llvm::Function *F = CGM.getIntrinsic(IID, {ArgTy});
 return Builder.CreateCall(F, {Addr, Val, ZeroI32, ZeroI32, ZeroI1});
   }
+  case AMDGPU::BI__builtin_amdgcn_global_load_tr_b64_v2i32:
+  case AMDGPU::BI__builtin_amdgcn_global_load_tr_b64_i32:
+  case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8i16:
+  case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8f16:
+  case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v4i16:
+  case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v4f16: {
+
+Intrinsic::ID IID;
+llvm::Type *ArgTy;
+switch (BuiltinID) {
+case AMDGPU::BI__builtin_amdgcn_global_load_tr_b64_v2i32:
+  ArgTy = llvm::FixedVectorType::get(
+  llvm::Type::getInt32Ty(getLLVMContext()), 2);
+  IID = Intrinsic::amdgcn_global_load_tr_b64;
+  break;
+case AMDGPU::BI__builtin_amdgcn_global_load_tr_b64_i32:
+  ArgTy = llvm::Type::getInt32Ty(getLLVMContext());
+  IID = Intrinsic::amdgcn_global_load_tr_b64;
+  break;
+case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8i16:
+  ArgTy = llvm::FixedVectorType::get(
+  llvm::Type::getInt16Ty(getLLVMContext()), 8);
+  IID = Intr

[llvm] [clang] [AMDGPU] Add global_load_tr for GFX12 (PR #77772)

2024-01-15 Thread Piotr Sobczak via cfe-commits


@@ -2496,6 +2496,26 @@ def int_amdgcn_flat_atomic_fmax_num   : 
AMDGPUAtomicRtn;
 def int_amdgcn_global_atomic_fmin_num : AMDGPUAtomicRtn;
 def int_amdgcn_global_atomic_fmax_num : AMDGPUAtomicRtn;
 
+class AMDGPUGlobalLoadTr :
+  Intrinsic<
+[data_ty],
+[global_ptr_ty],
+[IntrReadMem, IntrWillReturn, IntrConvergent, NoCapture>, 
IntrNoCallback, IntrNoFree],
+"",
+[SDNPMemOperand]
+  >;
+
+// Wave32
+// <2 x i32>  @llvm.amdgcn.global.load.tr.v2i32(ptr addrspace(1)) -> 
global_load_tr_b64
+// <8 x i16>  @llvm.amdgcn.global.load.tr.v8i16(ptr addrspace(1)) -> 
global_load_tr_b128
+// <8 x half> @llvm.amdgcn.global.load.tr.v8f16(ptr addrspace(1)) -> 
global_load_tr_b128

piotrAMD wrote:

Here is just a comment to say how the intrinsic could be used, but the right 
patterns need to be added. I added an extra one for bf16 in the most recent 
update.

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


[llvm] [mlir] [openmp] [compiler-rt] [lld] [clang] [libcxxabi] [libcxx] [runtimes] Use LLVM libunwind from libc++abi by default (PR #77687)

2024-01-15 Thread via cfe-commits

cor3ntin wrote:

FYI, This affects compiler explorer builds (trunk no longer builds)

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


[clang] [Clang] Amend SME attributes with support for ZT0. (PR #77941)

2024-01-15 Thread Sander de Smalen via cfe-commits

sdesmalen-arm wrote:

> I won't approve because of the growth in FunctionProtoType — someone more 
> qualified than me should sign off on that.

@AaronBallman or @erichkeane, would you be happy to sign off on this patch?

I think previously you raised concerns about the size of `ExtProtoInfo` when 
adding more bits to it. (This was discussed on 
https://reviews.llvm.org/D127762, but unfortunately this link currently results 
in a 404)

It's worth pointing out that extending `ExtProtoInfo` with some more bits 
doesn't change the actual size. It is 80 bytes at the moment and increasing it 
with 2 more bits doesn't change the total size of the struct. The size of 
`FunctionTypeExtraBitfields` will increase though, but I'm not sure if this is 
a problem because the comment above it says that these bits are uncommon to 
start with. I could shave off another two bits off `NumExceptionType` to avoid 
that, as the comment suggests 8 bits should be sufficient.

This also make me wonder if we should be reserving some extra bits for future 
state that may need adding?

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


[libunwind] [libunwind][WebAssembly] Omit unused parts of libunwind.cpp for Wasm (PR #73196)

2024-01-15 Thread Kazushi Marukawa via cfe-commits

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


[libunwind] [libunwind][WebAssembly] Omit unused parts of libunwind.cpp for Wasm (PR #73196)

2024-01-15 Thread Kazushi Marukawa via cfe-commits

https://github.com/kaz7 commented:

Please correct this code.  Thank you!

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


[libunwind] [libunwind][WebAssembly] Omit unused parts of libunwind.cpp for Wasm (PR #73196)

2024-01-15 Thread Kazushi Marukawa via cfe-commits


@@ -26,7 +26,7 @@
 #include 
 #endif
 
-#if !defined(__USING_SJLJ_EXCEPTIONS__)
+#if !defined(__USING_SJLJ_EXCEPTIONS__) || !defined(__USING_WASM_EXCEPTIONS__)

kaz7 wrote:

This must be `#if !defined(__USING_SJLJ_EXCEPTIONS__) && 
!defined(__USING_WASM_EXCEPTIONS__)` since we don't want to compile this code 
for either sjlj or wasm users.  `not (sjlj || wasm)` is equal to `not(sjlj) && 
not(wasm)` as you know...

VE use only SjLj, so it should be warnned by the buildbot for VE, but our 
buildbot has been stopped last 2 months.  I've noticed this problem when I've 
been trying to recover our buildbot.  ;-)

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


[lldb] [libc] [clang] [llvm] [libcxxabi] [clang-tools-extra] [lld] [flang] [compiler-rt] [libcxx] [Flang][OpenMP] Push genEval calls to individual operations, NFC (PR #77758)

2024-01-15 Thread Sergio Afonso via cfe-commits


@@ -3358,14 +3396,17 @@ genOMP(Fortran::lower::AbstractConverter &converter,
   .t);
   // Currently only private/firstprivate clause is handled, and
   // all privatization is done within `omp.section` operations.
+  symTable.pushScope();

skatrak wrote:

Thanks for the explanation, that clears it for me

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


[clang] 826fe84 - [clang][Interp][NFC] Remove outdated FIXME comment

2024-01-15 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-01-15T12:03:59+01:00
New Revision: 826fe84a2cb7dd7e488bc6dc53ce6342f6e17e93

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

LOG: [clang][Interp][NFC] Remove outdated FIXME comment

Virtual desturctors are already supported and tested in
AST/Interp/records.cpp.

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/records.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index d6be9a306aeaf6..8863c5f89027e4 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -2951,7 +2951,6 @@ bool ByteCodeExprGen::emitPrimCast(PrimType 
FromT, PrimType ToT,
 /// When calling this, we have a pointer of the local-to-destroy
 /// on the stack.
 /// Emit destruction of record types (or arrays of record types).
-/// FIXME: Handle virtual destructors.
 template 
 bool ByteCodeExprGen::emitRecordDestruction(const Descriptor *Desc) {
   assert(Desc);

diff  --git a/clang/test/AST/Interp/records.cpp 
b/clang/test/AST/Interp/records.cpp
index 280eaf34898cec..a1ced049dcedb8 100644
--- a/clang/test/AST/Interp/records.cpp
+++ b/clang/test/AST/Interp/records.cpp
@@ -734,8 +734,6 @@ namespace VirtualDtors {
   }
 
   static_assert(foo());
-
-
 };
 
 namespace QualifiedCalls {



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


[clang] [Clang] Only compare template params of potential overload after checking their decl context (PR #78139)

2024-01-15 Thread Timm Baeder via cfe-commits


@@ -1259,6 +1259,40 @@ static bool IsOverloadOrOverrideImpl(Sema &SemaRef, 
FunctionDecl *New,
   if ((OldTemplate == nullptr) != (NewTemplate == nullptr))
 return true;
 
+  // Is the function New an overload of the function Old?
+  QualType OldQType = SemaRef.Context.getCanonicalType(Old->getType());
+  QualType NewQType = SemaRef.Context.getCanonicalType(New->getType());
+
+  // Compare the signatures (C++ 1.3.10) of the two functions to
+  // determine whether they are overloads. If we find any mismatch
+  // in the signature, they are overloads.
+
+  // If either of these functions is a K&R-style function (no
+  // prototype), then we consider them to have matching signatures.
+  if (isa(OldQType.getTypePtr()) ||
+  isa(NewQType.getTypePtr()))
+return false;
+
+  const FunctionProtoType *OldType = cast(OldQType);
+  const FunctionProtoType *NewType = cast(NewQType);

tbaederr wrote:

```suggestion
  const auto *OldType = cast(OldQType);
  const auto *NewType = cast(NewQType);
```

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


[clang] [llvm] [libcxx] [compiler-rt] [flang] [libc] [lldb] [clang-tools-extra] [lld] [libcxxabi] [Flang][OpenMP] Push genEval calls to individual operations, NFC (PR #77758)

2024-01-15 Thread Sergio Afonso via cfe-commits

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

Thanks for addressing my comments, LGTM.

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


[lldb] [libc] [clang] [llvm] [libcxxabi] [clang-tools-extra] [lld] [flang] [compiler-rt] [libcxx] [Flang][OpenMP] Push genEval calls to individual operations, NFC (PR #77758)

2024-01-15 Thread Sergio Afonso via cfe-commits

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


[llvm] [lld] [compiler-rt] [flang] [clang] [libcxxabi] [lldb] [libcxx] [clang-tools-extra] [libc] [Flang][OpenMP] Push genEval calls to individual operations, NFC (PR #77758)

2024-01-15 Thread Sergio Afonso via cfe-commits


@@ -110,6 +110,34 @@ static void gatherFuncAndVarSyms(
   }
 }
 
+static Fortran::lower::pft::Evaluation *
+getCollapsedEval(Fortran::lower::pft::Evaluation &eval, int collapseValue) {

skatrak wrote:

Nit: Maybe `getCollapsedLoopEval` would be slightly more self-explanatory?

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


[clang-tools-extra] [llvm] [Kaleidoscope] LLVM is not needed for chapter two (PR #69823)

2024-01-15 Thread via cfe-commits

gonsolo wrote:

> Hey, anything required from my side?

No, @MaskRay was kind enough to merge this PR. I was just pinging all recent 
committers of this directory to get this merged.

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


[clang-tools-extra] [llvm] [Kaleidoscope] LLVM is not needed for chapter two (PR #69823)

2024-01-15 Thread via cfe-commits

gonsolo wrote:

Thanks, @MaskRay.

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


[clang] 5e35594 - [clang][ASTImporter] Fix import of variable template redeclarations. (#72841)

2024-01-15 Thread via cfe-commits

Author: Balázs Kéri
Date: 2024-01-15T12:38:02+01:00
New Revision: 5e355942cd8e5826394cdeceb140fb6d0a1f9561

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

LOG: [clang][ASTImporter] Fix import of variable template redeclarations. 
(#72841)

In some cases variable templates (specially if static member of record)
were not correctly imported and an assertion "Missing call to
MapImported?" could happen.

Added: 


Modified: 
clang/lib/AST/ASTImporter.cpp
clang/unittests/AST/ASTImporterTest.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index b762d6a4cd3800..aa23c99b599010 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -6280,17 +6280,21 @@ ExpectedDecl 
ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) {
   D->getTemplatedDecl()))
 continue;
   if (IsStructuralMatch(D, FoundTemplate)) {
-// The Decl in the "From" context has a definition, but in the
-// "To" context we already have a definition.
+// FIXME Check for ODR error if the two definitions have
+// 
diff erent initializers?
 VarTemplateDecl *FoundDef = getTemplateDefinition(FoundTemplate);
-if (D->isThisDeclarationADefinition() && FoundDef)
-  // FIXME Check for ODR error if the two definitions have
-  // 
diff erent initializers?
-  return Importer.MapImported(D, FoundDef);
-if (FoundTemplate->getDeclContext()->isRecord() &&
-D->getDeclContext()->isRecord())
-  return Importer.MapImported(D, FoundTemplate);
-
+if (D->getDeclContext()->isRecord()) {
+  assert(FoundTemplate->getDeclContext()->isRecord() &&
+ "Member variable template imported as non-member, "
+ "inconsistent imported AST?");
+  if (FoundDef)
+return Importer.MapImported(D, FoundDef);
+  if (!D->isThisDeclarationADefinition())
+return Importer.MapImported(D, FoundTemplate);
+} else {
+  if (FoundDef && D->isThisDeclarationADefinition())
+return Importer.MapImported(D, FoundDef);
+}
 FoundByLookup = FoundTemplate;
 break;
   }

diff  --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 37cf14bdff6b33..3d1f4c85c90ad5 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -5219,6 +5219,59 @@ TEST_P(ImportFriendClasses, RecordVarTemplateDecl) {
   EXPECT_EQ(ToTUX, ToX);
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, VarTemplateDeclConflict) {
+  getToTuDecl(
+  R"(
+  template 
+  constexpr int X = 1;
+  )",
+  Lang_CXX14);
+
+  Decl *FromTU = getTuDecl(
+  R"(
+  template 
+  constexpr int X = 2;
+  )",
+  Lang_CXX14, "input1.cc");
+  auto *FromX = FirstDeclMatcher().match(
+  FromTU, varTemplateDecl(hasName("X")));
+  auto *ToX = Import(FromX, Lang_CXX11);
+  // FIXME: This import should fail.
+  EXPECT_TRUE(ToX);
+}
+
+TEST_P(ASTImporterOptionSpecificTestBase, VarTemplateStaticDefinition) {
+  Decl *ToTU = getToTuDecl(
+  R"(
+  struct A {
+template 
+static int X;
+  };
+  )",
+  Lang_CXX14);
+  auto *ToX = FirstDeclMatcher().match(
+  ToTU, varTemplateDecl(hasName("X")));
+  ASSERT_FALSE(ToX->isThisDeclarationADefinition());
+
+  Decl *FromTU = getTuDecl(
+  R"(
+  struct A {
+template 
+static int X;
+  };
+  template 
+  int A::X = 2;
+  )",
+  Lang_CXX14, "input1.cc");
+  auto *FromXDef = LastDeclMatcher().match(
+  FromTU, varTemplateDecl(hasName("X")));
+  ASSERT_TRUE(FromXDef->isThisDeclarationADefinition());
+  auto *ToXDef = Import(FromXDef, Lang_CXX14);
+  EXPECT_TRUE(ToXDef);
+  EXPECT_TRUE(ToXDef->isThisDeclarationADefinition());
+  EXPECT_EQ(ToXDef->getPreviousDecl(), ToX);
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase, VarTemplateParameterDeclContext) {
   constexpr auto Code =
   R"(



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


[clang] [clang][ASTImporter] Fix import of variable template redeclarations. (PR #72841)

2024-01-15 Thread Balázs Kéri via cfe-commits

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


[clang] [Clang][SME] Detect always_inline used with mismatched streaming attributes (PR #77936)

2024-01-15 Thread Matthew Devereau via cfe-commits


@@ -812,6 +819,23 @@ Address AArch64ABIInfo::EmitMSVAArg(CodeGenFunction &CGF, 
Address VAListAddr,
   /*allowHigherAlign*/ false);
 }
 
+void AArch64TargetCodeGenInfo::checkFunctionCallABI(
+CodeGenModule &CGM, SourceLocation CallLoc, const FunctionDecl *Caller,
+const FunctionDecl *Callee, const CallArgList &Args) const {
+  if (!Callee->hasAttr())
+return;
+
+  auto CalleeIsStreaming =

MDevereau wrote:

nit: I think `bool` is better than `auto` here

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


[clang] [Clang][SME] Detect always_inline used with mismatched streaming attributes (PR #77936)

2024-01-15 Thread Matthew Devereau via cfe-commits


@@ -279,6 +279,8 @@ def err_builtin_needs_feature : Error<"%0 needs target 
feature %1">;
 def err_function_needs_feature : Error<
   "always_inline function %1 requires target feature '%2', but would "
   "be inlined into function %0 that is compiled without support for '%2'">;
+def err_function_alwaysinline_attribute_mismatch : Error<

MDevereau wrote:

```suggestion
def err_function_always_inline_attribute_mismatch : Error<
```

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


[clang] [Clang][SME] Detect always_inline used with mismatched streaming attributes (PR #77936)

2024-01-15 Thread Matthew Devereau via cfe-commits


@@ -0,0 +1,12 @@
+// RUN: %clang --target=aarch64-none-linux-gnu -march=armv9-a+sme -O3 -S 
-Xclang -verify %s
+
+// Conflicting attributes when using always_inline
+__attribute__((always_inline)) __arm_locally_streaming
+int inlined_fn_local(void) {
+return 42;
+}

MDevereau wrote:

Do these tests have to return an int? 42 looks like it could possibly be a 
significant magic number in some way. I think the tests can probably be 
combined into a single file like 
`clang/test/CodeGen/aarch64-sme-func-attrs-inline.c` too?

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


[clang-tools-extra] [libcxx] [compiler-rt] [libc] [lldb] [libcxxabi] [flang] [lld] [clang] [llvm] [Flang][OpenMP] Push genEval calls to individual operations, NFC (PR #77758)

2024-01-15 Thread Kiran Chandramohan via cfe-commits

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


[clang-tools-extra] [flang] [libcxx] [lld] [libcxxabi] [llvm] [lldb] [libc] [clang] [compiler-rt] [Flang][OpenMP] Push genEval calls to individual operations, NFC (PR #77758)

2024-01-15 Thread Kiran Chandramohan via cfe-commits

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

LG.

Please add a pointer to the discussion where it was agreed to pass a reference 
to the localSymbolTable.

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


[compiler-rt] [libcxxabi] [libcxx] [llvm] [libc] [clang-tools-extra] [lldb] [flang] [lld] [clang] [Flang][OpenMP] Push genEval calls to individual operations, NFC (PR #77758)

2024-01-15 Thread Kiran Chandramohan via cfe-commits


@@ -110,6 +110,34 @@ static void gatherFuncAndVarSyms(
   }
 }
 
+static Fortran::lower::pft::Evaluation *
+getCollapsedEval(Fortran::lower::pft::Evaluation &eval, int collapseValue) {
+  // Return the Evaluation of the innermost collapsed loop, or the current
+  // evaluation, if there is nothing to collapse.
+  if (collapseValue == 0)
+return &eval;

kiranchandramohan wrote:

Nit: Is it better to convert this to an assert (for > 0) and move this code to 
the parent function?

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


[flang] [clang] [flang][driver] Allow explicit specification of -lFortran_main (PR #78152)

2024-01-15 Thread Tom Eccles via cfe-commits

https://github.com/tblah created https://github.com/llvm/llvm-project/pull/78152

Currently, `flang-new -lFortran_main` will fail on multiple definitions of 
`main`.

I can understand there might be differing opinions on whether this is actually 
a bug.

My thinking is that `-lFortran_main` should behave the same as 
`-lFortranRuntime`.

>From 5c7fa9c3ef911674e5b6888fcba4289834d04fda Mon Sep 17 00:00:00 2001
From: Tom Eccles 
Date: Mon, 15 Jan 2024 11:27:46 +
Subject: [PATCH] [flang][driver] Allow explicit specification of
 -lFortran_main

I can understand there might be differing opinions on whether this is
actually a bug. My thinking is that -lFortran_main should behave the
same as -lFortranRuntime.
---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 8 
 flang/test/Driver/linker-flags.f90 | 3 +++
 2 files changed, 11 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 385f66f3782bc1..82edb93d157d3f 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1200,6 +1200,14 @@ static void addFortranMain(const ToolChain &TC, const 
ArgList &Args,
   // TODO: Find an equivalent of `--whole-archive` for Darwin and AIX.
   if (!isWholeArchivePresent(Args) && !TC.getTriple().isMacOSX() &&
   !TC.getTriple().isOSAIX()) {
+// Adding -lFortran_main with --whole-archive will create an error if the
+// user specifies -lFortran_main explicitly. Remove the user's
+// -lFortran_main arguments to avoid this (making sure -lFortran_main
+// behaves the same as -lFortranRuntime)
+llvm::erase_if(CmdArgs, [](const char *arg) {
+  return strcmp(arg, "-lFortran_main") == 0;
+});
+
 CmdArgs.push_back("--whole-archive");
 CmdArgs.push_back("-lFortran_main");
 CmdArgs.push_back("--no-whole-archive");
diff --git a/flang/test/Driver/linker-flags.f90 
b/flang/test/Driver/linker-flags.f90
index ea91946316cfaa..0d531cedff4bd2 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -12,6 +12,9 @@
 ! RUN: %flang -### --target=x86_64-unknown-haiku %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,HAIKU
 ! RUN: %flang -### --target=x86_64-windows-gnu %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,MINGW
 
+! Verify that linking the runtime explicitly doesn't result in a multiple 
definitions of main error
+! RUN: %flang -lFortran_main -lFortranRuntime -lFortranDecimal 
%S/Inputs/hello.f90 -o %s.out
+
 ! NOTE: Clang's driver library, clangDriver, usually adds 'oldnames' on 
Windows,
 !   but it is not needed when compiling Fortran code and they might bring 
in
 !   additional dependencies. Make sure its not added.

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


[clang] [flang] [flang][driver] Allow explicit specification of -lFortran_main (PR #78152)

2024-01-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Tom Eccles (tblah)


Changes

Currently, `flang-new -lFortran_main` will fail on multiple definitions of 
`main`.

I can understand there might be differing opinions on whether this is actually 
a bug.

My thinking is that `-lFortran_main` should behave the same as 
`-lFortranRuntime`.

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


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/CommonArgs.cpp (+8) 
- (modified) flang/test/Driver/linker-flags.f90 (+3) 


``diff
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 385f66f3782bc1a..82edb93d157d3f1 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1200,6 +1200,14 @@ static void addFortranMain(const ToolChain &TC, const 
ArgList &Args,
   // TODO: Find an equivalent of `--whole-archive` for Darwin and AIX.
   if (!isWholeArchivePresent(Args) && !TC.getTriple().isMacOSX() &&
   !TC.getTriple().isOSAIX()) {
+// Adding -lFortran_main with --whole-archive will create an error if the
+// user specifies -lFortran_main explicitly. Remove the user's
+// -lFortran_main arguments to avoid this (making sure -lFortran_main
+// behaves the same as -lFortranRuntime)
+llvm::erase_if(CmdArgs, [](const char *arg) {
+  return strcmp(arg, "-lFortran_main") == 0;
+});
+
 CmdArgs.push_back("--whole-archive");
 CmdArgs.push_back("-lFortran_main");
 CmdArgs.push_back("--no-whole-archive");
diff --git a/flang/test/Driver/linker-flags.f90 
b/flang/test/Driver/linker-flags.f90
index ea91946316cfaa6..0d531cedff4bd2c 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -12,6 +12,9 @@
 ! RUN: %flang -### --target=x86_64-unknown-haiku %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,HAIKU
 ! RUN: %flang -### --target=x86_64-windows-gnu %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,MINGW
 
+! Verify that linking the runtime explicitly doesn't result in a multiple 
definitions of main error
+! RUN: %flang -lFortran_main -lFortranRuntime -lFortranDecimal 
%S/Inputs/hello.f90 -o %s.out
+
 ! NOTE: Clang's driver library, clangDriver, usually adds 'oldnames' on 
Windows,
 !   but it is not needed when compiling Fortran code and they might bring 
in
 !   additional dependencies. Make sure its not added.

``




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


[flang] [clang] [flang][driver] Allow explicit specification of -lFortran_main (PR #78152)

2024-01-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Tom Eccles (tblah)


Changes

Currently, `flang-new -lFortran_main` will fail on multiple definitions of 
`main`.

I can understand there might be differing opinions on whether this is actually 
a bug.

My thinking is that `-lFortran_main` should behave the same as 
`-lFortranRuntime`.

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


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/CommonArgs.cpp (+8) 
- (modified) flang/test/Driver/linker-flags.f90 (+3) 


``diff
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 385f66f3782bc1..82edb93d157d3f 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1200,6 +1200,14 @@ static void addFortranMain(const ToolChain &TC, const 
ArgList &Args,
   // TODO: Find an equivalent of `--whole-archive` for Darwin and AIX.
   if (!isWholeArchivePresent(Args) && !TC.getTriple().isMacOSX() &&
   !TC.getTriple().isOSAIX()) {
+// Adding -lFortran_main with --whole-archive will create an error if the
+// user specifies -lFortran_main explicitly. Remove the user's
+// -lFortran_main arguments to avoid this (making sure -lFortran_main
+// behaves the same as -lFortranRuntime)
+llvm::erase_if(CmdArgs, [](const char *arg) {
+  return strcmp(arg, "-lFortran_main") == 0;
+});
+
 CmdArgs.push_back("--whole-archive");
 CmdArgs.push_back("-lFortran_main");
 CmdArgs.push_back("--no-whole-archive");
diff --git a/flang/test/Driver/linker-flags.f90 
b/flang/test/Driver/linker-flags.f90
index ea91946316cfaa..0d531cedff4bd2 100644
--- a/flang/test/Driver/linker-flags.f90
+++ b/flang/test/Driver/linker-flags.f90
@@ -12,6 +12,9 @@
 ! RUN: %flang -### --target=x86_64-unknown-haiku %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,HAIKU
 ! RUN: %flang -### --target=x86_64-windows-gnu %S/Inputs/hello.f90 2>&1 | 
FileCheck %s --check-prefixes=CHECK,MINGW
 
+! Verify that linking the runtime explicitly doesn't result in a multiple 
definitions of main error
+! RUN: %flang -lFortran_main -lFortranRuntime -lFortranDecimal 
%S/Inputs/hello.f90 -o %s.out
+
 ! NOTE: Clang's driver library, clangDriver, usually adds 'oldnames' on 
Windows,
 !   but it is not needed when compiling Fortran code and they might bring 
in
 !   additional dependencies. Make sure its not added.

``




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


[clang] [clang][Interp] Implement dynamic memory allocation handling (PR #70306)

2024-01-15 Thread Timm Baeder via cfe-commits

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

>From bf3dd8a13a2ed61d2cc9b2e49a7ff271f29c2ba9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Wed, 25 Oct 2023 08:33:30 +0200
Subject: [PATCH] [clang][Interp] Implement dynamic memory allocation handling

---
 clang/lib/AST/CMakeLists.txt   |   1 +
 clang/lib/AST/Interp/ByteCodeExprGen.cpp   |  76 +
 clang/lib/AST/Interp/ByteCodeExprGen.h |   2 +
 clang/lib/AST/Interp/Context.cpp   |   2 +-
 clang/lib/AST/Interp/Context.h |   9 +
 clang/lib/AST/Interp/DynamicAllocator.cpp  |  90 ++
 clang/lib/AST/Interp/DynamicAllocator.h|  92 ++
 clang/lib/AST/Interp/EvalEmitter.cpp   |   4 +-
 clang/lib/AST/Interp/Interp.cpp|  49 
 clang/lib/AST/Interp/Interp.h  | 141 +
 clang/lib/AST/Interp/InterpBuiltin.cpp |   3 +-
 clang/lib/AST/Interp/InterpState.cpp   |  15 +
 clang/lib/AST/Interp/InterpState.h |  10 +
 clang/lib/AST/Interp/Opcodes.td|  28 ++
 clang/test/AST/Interp/new-delete.cpp   | 320 +
 clang/test/SemaCXX/paren-list-agg-init.cpp |   8 +-
 16 files changed, 844 insertions(+), 6 deletions(-)
 create mode 100644 clang/lib/AST/Interp/DynamicAllocator.cpp
 create mode 100644 clang/lib/AST/Interp/DynamicAllocator.h
 create mode 100644 clang/test/AST/Interp/new-delete.cpp

diff --git a/clang/lib/AST/CMakeLists.txt b/clang/lib/AST/CMakeLists.txt
index fe3f8c485ec1c5..1423623fb038ca 100644
--- a/clang/lib/AST/CMakeLists.txt
+++ b/clang/lib/AST/CMakeLists.txt
@@ -75,6 +75,7 @@ add_clang_library(clangAST
   Interp/Function.cpp
   Interp/InterpBuiltin.cpp
   Interp/Floating.cpp
+  Interp/DynamicAllocator.cpp
   Interp/Interp.cpp
   Interp/InterpBlock.cpp
   Interp/InterpFrame.cpp
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 8863c5f89027e4..dcdfb77499421d 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1814,6 +1814,82 @@ bool ByteCodeExprGen::VisitSizeOfPackExpr(const 
SizeOfPackExpr *E) {
   return this->emitConst(E->getPackLength(), E);
 }
 
+template 
+bool ByteCodeExprGen::VisitCXXNewExpr(const CXXNewExpr *E) {
+  assert(classifyPrim(E->getType()) == PT_Ptr);
+  const Expr *Init = E->getInitializer();
+  QualType ElementType = E->getAllocatedType();
+  std::optional ElemT = classify(ElementType);
+
+  const Descriptor *Desc;
+  if (ElemT) {
+if (E->isArray())
+  Desc = nullptr; // We're not going to use it in this case.
+else
+  Desc = P.createDescriptor(E, *ElemT, Descriptor::InlineDescMD,
+/*IsConst=*/false, /*IsTemporary=*/false,
+/*IsMutable=*/false);
+  } else {
+Desc = P.createDescriptor(
+E, ElementType.getTypePtr(),
+E->isArray() ? std::nullopt : Descriptor::InlineDescMD,
+/*IsConst=*/false, /*IsTemporary=*/false, /*IsMutable=*/false, Init);
+  }
+
+  if (E->isArray()) {
+assert(E->getArraySize());
+PrimType SizeT = classifyPrim((*E->getArraySize())->getType());
+
+if (!this->visit(*E->getArraySize()))
+  return false;
+
+if (ElemT) {
+  // N primitive elements.
+  if (!this->emitAllocN(SizeT, *ElemT, E, E))
+return false;
+} else {
+  // N Composite elements.
+  if (!this->emitAllocCN(SizeT, Desc, E))
+return false;
+}
+
+  } else {
+// Allocate just one element.
+if (!this->emitAlloc(Desc, E))
+  return false;
+
+if (Init) {
+  if (ElemT) {
+if (!this->visit(Init))
+  return false;
+
+if (!this->emitInit(*ElemT, E))
+  return false;
+  } else {
+// Composite.
+if (!this->visitInitializer(Init))
+  return false;
+  }
+}
+  }
+
+  if (DiscardResult)
+return this->emitPopPtr(E);
+
+  return true;
+}
+
+template 
+bool ByteCodeExprGen::VisitCXXDeleteExpr(const CXXDeleteExpr *E) {
+  const Expr *Arg = E->getArgument();
+
+  // Arg must be an lvalue.
+  if (!this->visit(Arg))
+return false;
+
+  return this->emitFree(E->isArrayForm(), E);
+}
+
 template  bool ByteCodeExprGen::discard(const Expr *E) 
{
   if (E->containsErrors())
 return false;
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index bbb13e97e72569..03aea72316dad1 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -108,6 +108,8 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
   bool VisitOffsetOfExpr(const OffsetOfExpr *E);
   bool VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *E);
   bool VisitSizeOfPackExpr(const SizeOfPackExpr *E);
+  bool VisitCXXNewExpr(const CXXNewExpr *E);
+  bool VisitCXXDeleteExpr(const CXXDeleteExpr *E);
 
 protected:
   bool visitExpr(const Expr *E) override;
diff --git a/clang/lib/AST/

[flang] [clang] [flang][driver] Add support for -isysroot in the frontend (PR #77365)

2024-01-15 Thread Leandro Lupori via cfe-commits

luporl wrote:

> If the compiler is built with `DEFAULT_SYSROOT`, the `-isysroot` option is 
> ignored. Is that the expected behavior? My local MacOS build (with 
> `-DDEFAULT_SYSROOT="$(xcrun --show-sdk-path)"`) has `isysroot.f90` failed.

I expected `-isysroot` to override `DEFAULT_SYSROOT`. I'll take a look at that, 
thanks for reporting it.

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


[clang] [SystemZ][z/OS] Add support for recognizing z/OS personality function in Clang (PR #76073)

2024-01-15 Thread Ulrich Weigand via cfe-commits

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

LGTM

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


[clang] [X86_64] fix empty structure vaarg in c++ (PR #77907)

2024-01-15 Thread via cfe-commits

https://github.com/hstk30-hw updated 
https://github.com/llvm/llvm-project/pull/77907

>From 2f4290732804588d7c8f0de07836cfd5976085b8 Mon Sep 17 00:00:00 2001
From: Longsheng Mou 
Date: Fri, 12 Jan 2024 18:24:08 +0800
Subject: [PATCH] [X86_64] fix empty structure vaarg in c++

SizeInBytes of empty structure is 0 in C, while 1 in C++.
And empty structure argument of the function is ignored
in X86_64 backend.As a result, the value of variable
arguments in C++ is incorrect.
---
 clang/lib/CodeGen/Targets/X86.cpp  |  5 -
 clang/test/CodeGenCXX/x86_64-vaarg.cpp | 16 
 2 files changed, 20 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGenCXX/x86_64-vaarg.cpp

diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index d053f41ab168f5e..79b8306588277e8 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -2988,7 +2988,10 @@ static Address EmitX86_64VAArgFromMemory(CodeGenFunction 
&CGF,
   // AMD64-ABI 3.5.7p5: Step 10. Align l->overflow_arg_area upwards to
   // an 8 byte boundary.
 
-  uint64_t SizeInBytes = (CGF.getContext().getTypeSize(Ty) + 7) / 8;
+  uint64_t SizeInBytes = 0;
+  if (!isEmptyRecord(CGF.getContext(), Ty, true, true))
+SizeInBytes = (CGF.getContext().getTypeSize(Ty) + 7) / 8;
+
   llvm::Value *Offset =
   llvm::ConstantInt::get(CGF.Int32Ty, (SizeInBytes + 7)  & ~7);
   overflow_arg_area = CGF.Builder.CreateGEP(CGF.Int8Ty, overflow_arg_area,
diff --git a/clang/test/CodeGenCXX/x86_64-vaarg.cpp 
b/clang/test/CodeGenCXX/x86_64-vaarg.cpp
new file mode 100644
index 000..9c1af37fe429545
--- /dev/null
+++ b/clang/test/CodeGenCXX/x86_64-vaarg.cpp
@@ -0,0 +1,16 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s | FileCheck %s
+
+struct Empty { struct { struct { } e; }; };
+
+struct Empty emptyvar;
+
+void take_args(int a, ...) {
+// CHECK:  %overflow_arg_area = load ptr, ptr %overflow_arg_area_p, align 8
+// CHECK-NEXT: %overflow_arg_area.next = getelementptr i8, ptr 
%overflow_arg_area, i32 0
+// CHECK-NEXT: store ptr %overflow_arg_area.next, ptr %overflow_arg_area_p, 
align 8
+  __builtin_va_list l;
+  __builtin_va_start(l, a);
+  emptyvar = __builtin_va_arg(l, struct Empty);
+  __builtin_va_end(l);
+}

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


[clang] [clang-format] TableGen multi line string support. (PR #78032)

2024-01-15 Thread Hirofumi Nakamura via cfe-commits

https://github.com/hnakamura5 updated 
https://github.com/llvm/llvm-project/pull/78032

>From d0767350f26215e86dee039427183630b3f02668 Mon Sep 17 00:00:00 2001
From: hnakamura5 
Date: Sat, 13 Jan 2024 21:44:34 +0900
Subject: [PATCH 1/3] [clang-format] TableGen multi line string support.

---
 clang/lib/Format/ContinuationIndenter.cpp |  3 +
 clang/lib/Format/FormatToken.h|  1 +
 clang/lib/Format/FormatTokenLexer.cpp | 57 +++
 clang/lib/Format/FormatTokenLexer.h   |  3 +
 clang/lib/Format/TokenAnnotator.cpp   |  2 +-
 clang/unittests/Format/TokenAnnotatorTest.cpp |  5 ++
 6 files changed, 70 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 102504182c4505..e6eaaa9ab45706 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1591,6 +1591,9 @@ unsigned 
ContinuationIndenter::moveStateToNextToken(LineState &State,
 State.StartOfStringLiteral = State.Column + 1;
   if (Current.is(TT_CSharpStringLiteral) && State.StartOfStringLiteral == 0) {
 State.StartOfStringLiteral = State.Column + 1;
+  } else if (Current.is(TT_TableGenMultiLineString) &&
+ State.StartOfStringLiteral == 0) {
+State.StartOfStringLiteral = State.Column + 1;
   } else if (Current.isStringLiteral() && State.StartOfStringLiteral == 0) {
 State.StartOfStringLiteral = State.Column;
   } else if (!Current.isOneOf(tok::comment, tok::identifier, tok::hash) &&
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index d5ef627f1348d3..dede89f2600150 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -148,6 +148,7 @@ namespace format {
   TYPE(StructLBrace)   
\
   TYPE(StructRBrace)   
\
   TYPE(StructuredBindingLSquare)   
\
+  TYPE(TableGenMultiLineString)
\
   TYPE(TemplateCloser) 
\
   TYPE(TemplateOpener) 
\
   TYPE(TemplateString) 
\
diff --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index a1fd6dd6effe6c..1060009bdcf131 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -93,6 +93,8 @@ ArrayRef FormatTokenLexer::lex() {
   // string literals are correctly identified.
   handleCSharpVerbatimAndInterpolatedStrings();
 }
+if (Style.isTableGen())
+  handleTableGenMultilineString();
 if (Tokens.back()->NewlinesBefore > 0 || Tokens.back()->IsMultiline)
   FirstInLineIndex = Tokens.size() - 1;
   } while (Tokens.back()->isNot(tok::eof));
@@ -272,6 +274,14 @@ void FormatTokenLexer::tryMergePreviousTokens() {
   return;
 }
   }
+  if (Style.isTableGen()) {
+if (tryMergeTokens({tok::l_square, tok::l_brace},
+   TT_TableGenMultiLineString)) {
+  // Multi line string starts with [{
+  Tokens.back()->Tok.setKind(tok::string_literal);
+  return;
+}
+  }
 }
 
 bool FormatTokenLexer::tryMergeNSStringLiteral() {
@@ -763,6 +773,53 @@ void 
FormatTokenLexer::handleCSharpVerbatimAndInterpolatedStrings() {
   resetLexer(SourceMgr.getFileOffset(Lex->getSourceLocation(Offset + 1)));
 }
 
+void FormatTokenLexer::handleTableGenMultilineString() {
+  FormatToken *MultiLineString = Tokens.back();
+  if (MultiLineString->isNot(TT_TableGenMultiLineString))
+return;
+
+  bool PrevIsRBrace = false;
+  const char *FirstBreak = nullptr;
+  const char *LastBreak = nullptr;
+  const char *Begin = MultiLineString->TokenText.begin();
+  // Skip until }], the closer of multi line string found.
+  for (const char *Current = Begin, *End = Lex->getBuffer().end();
+   Current != End; ++Current) {
+if (PrevIsRBrace && *Current == ']') {
+  // }] is the end of multi line string.
+  if (!FirstBreak)
+FirstBreak = Current;
+  MultiLineString->TokenText = StringRef(Begin, Current - Begin + 1);
+  // ColumnWidth is only the width of the first line.
+  MultiLineString->ColumnWidth = encoding::columnWidthWithTabs(
+  StringRef(Begin, FirstBreak - Begin + 1),
+  MultiLineString->OriginalColumn, Style.TabWidth, Encoding);
+  if (LastBreak) {
+// Set LastLineColumnWidth if multi line string has multiple lines.
+MultiLineString->LastLineColumnWidth = encoding::columnWidthWithTabs(
+StringRef(LastBreak + 1, Current - LastBreak),
+MultiLineString->OriginalColumn, Style.TabWidth, Encoding);
+  }
+  resetLexer(SourceMgr.getFileOffset(Lex->getSourceLocation(Current + 1)));
+  return;
+}

[clang] [clang-format] TableGen multi line string support. (PR #78032)

2024-01-15 Thread Hirofumi Nakamura via cfe-commits


@@ -778,45 +778,31 @@ void FormatTokenLexer::handleTableGenMultilineString() {
   if (MultiLineString->isNot(TT_TableGenMultiLineString))
 return;
 
-  bool PrevIsRBrace = false;
-  const char *FirstBreak = nullptr;
-  const char *LastBreak = nullptr;
-  const char *Begin = MultiLineString->TokenText.begin();
-  // Skip until }], the closer of multi line string found.
-  for (const char *Current = Begin, *End = Lex->getBuffer().end();
-   Current != End; ++Current) {
-if (PrevIsRBrace && *Current == ']') {
-  // }] is the end of multi line string.
-  if (!FirstBreak)
-FirstBreak = Current;
-  MultiLineString->TokenText = StringRef(Begin, Current - Begin + 1);
-  // ColumnWidth is only the width of the first line.
-  MultiLineString->ColumnWidth = encoding::columnWidthWithTabs(
-  StringRef(Begin, FirstBreak - Begin + 1),
-  MultiLineString->OriginalColumn, Style.TabWidth, Encoding);
-  if (LastBreak) {
-// Set LastLineColumnWidth if multi line string has multiple lines.
-MultiLineString->LastLineColumnWidth = encoding::columnWidthWithTabs(
-StringRef(LastBreak + 1, Current - LastBreak),
-MultiLineString->OriginalColumn, Style.TabWidth, Encoding);
-  }
-  resetLexer(SourceMgr.getFileOffset(Lex->getSourceLocation(Current + 1)));
-  return;
-}
-PrevIsRBrace = false;
-if (*Current == '\n') {
-  MultiLineString->IsMultiline = true;
-  // Assure LastBreak is not equal to FirstBreak.
-  if (!FirstBreak)
-FirstBreak = Current;
-  LastBreak = Current;
-  continue;
-}
-if (*Current == '}') {
-  // Memorize '}'. If next character is ']', they are the closer.
-  PrevIsRBrace = true;
-  continue;
-}
+  auto OpenOffset = Lex->getCurrentBufferOffset() - 2 /* "[{" */;
+  // "}]" is the end of multi line string.
+  auto CloseOffset = Lex->getBuffer().find("}]", OpenOffset);
+  if (CloseOffset == StringRef::npos)
+return;
+  auto Text = Lex->getBuffer().substr(OpenOffset, CloseOffset + 2);
+  MultiLineString->TokenText = Text;
+  resetLexer(SourceMgr.getFileOffset(
+  Lex->getSourceLocation(Lex->getBufferLocation() - 2 + Text.size(;
+  // Set ColumnWidth and LastLineColumnWidth.
+  auto FirstLineText = Text;
+  auto FirstBreak = Text.find('\n');
+  if (FirstBreak != StringRef::npos) {
+MultiLineString->IsMultiline = true;
+FirstLineText = Text.substr(0, FirstBreak + 1);
+  }
+  // ColumnWidth holds only the width of the first line.
+  MultiLineString->ColumnWidth = encoding::columnWidthWithTabs(
+  FirstLineText, MultiLineString->OriginalColumn, Style.TabWidth, 
Encoding);
+  auto LastBreak = Text.rfind('\n');
+  if (LastBreak != StringRef::npos) {
+// Set LastLineColumnWidth if it has multiple lines.
+MultiLineString->LastLineColumnWidth = encoding::columnWidthWithTabs(
+Text.substr(LastBreak + 1, Text.size()),

hnakamura5 wrote:

Text.size() was redundant as you say. I removed it.

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


[clang] [clang-format] TableGen multi line string support. (PR #78032)

2024-01-15 Thread Hirofumi Nakamura via cfe-commits


@@ -778,45 +778,31 @@ void FormatTokenLexer::handleTableGenMultilineString() {
   if (MultiLineString->isNot(TT_TableGenMultiLineString))
 return;
 
-  bool PrevIsRBrace = false;
-  const char *FirstBreak = nullptr;
-  const char *LastBreak = nullptr;
-  const char *Begin = MultiLineString->TokenText.begin();
-  // Skip until }], the closer of multi line string found.
-  for (const char *Current = Begin, *End = Lex->getBuffer().end();
-   Current != End; ++Current) {
-if (PrevIsRBrace && *Current == ']') {
-  // }] is the end of multi line string.
-  if (!FirstBreak)
-FirstBreak = Current;
-  MultiLineString->TokenText = StringRef(Begin, Current - Begin + 1);
-  // ColumnWidth is only the width of the first line.
-  MultiLineString->ColumnWidth = encoding::columnWidthWithTabs(
-  StringRef(Begin, FirstBreak - Begin + 1),
-  MultiLineString->OriginalColumn, Style.TabWidth, Encoding);
-  if (LastBreak) {
-// Set LastLineColumnWidth if multi line string has multiple lines.
-MultiLineString->LastLineColumnWidth = encoding::columnWidthWithTabs(
-StringRef(LastBreak + 1, Current - LastBreak),
-MultiLineString->OriginalColumn, Style.TabWidth, Encoding);
-  }
-  resetLexer(SourceMgr.getFileOffset(Lex->getSourceLocation(Current + 1)));
-  return;
-}
-PrevIsRBrace = false;
-if (*Current == '\n') {
-  MultiLineString->IsMultiline = true;
-  // Assure LastBreak is not equal to FirstBreak.
-  if (!FirstBreak)
-FirstBreak = Current;
-  LastBreak = Current;
-  continue;
-}
-if (*Current == '}') {
-  // Memorize '}'. If next character is ']', they are the closer.
-  PrevIsRBrace = true;
-  continue;
-}
+  auto OpenOffset = Lex->getCurrentBufferOffset() - 2 /* "[{" */;
+  // "}]" is the end of multi line string.
+  auto CloseOffset = Lex->getBuffer().find("}]", OpenOffset);
+  if (CloseOffset == StringRef::npos)
+return;
+  auto Text = Lex->getBuffer().substr(OpenOffset, CloseOffset + 2);
+  MultiLineString->TokenText = Text;
+  resetLexer(SourceMgr.getFileOffset(
+  Lex->getSourceLocation(Lex->getBufferLocation() - 2 + Text.size(;
+  // Set ColumnWidth and LastLineColumnWidth.
+  auto FirstLineText = Text;
+  auto FirstBreak = Text.find('\n');
+  if (FirstBreak != StringRef::npos) {
+MultiLineString->IsMultiline = true;
+FirstLineText = Text.substr(0, FirstBreak + 1);
+  }
+  // ColumnWidth holds only the width of the first line.
+  MultiLineString->ColumnWidth = encoding::columnWidthWithTabs(
+  FirstLineText, MultiLineString->OriginalColumn, Style.TabWidth, 
Encoding);
+  auto LastBreak = Text.rfind('\n');

hnakamura5 wrote:

Modified as the suggestion.

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


[clang] [clang-format] TableGen multi line string support. (PR #78032)

2024-01-15 Thread Hirofumi Nakamura via cfe-commits


@@ -274,13 +274,13 @@ void FormatTokenLexer::tryMergePreviousTokens() {
   return;
 }
   }
-  if (Style.isTableGen()) {
-if (tryMergeTokens({tok::l_square, tok::l_brace},
-   TT_TableGenMultiLineString)) {
-  // Multi line string starts with [{
-  Tokens.back()->Tok.setKind(tok::string_literal);
-  return;
-}
+  // TableGen's Multi line string starts with [{
+  if (Style.isTableGen() && tryMergeTokens({tok::l_square, tok::l_brace},
+   TT_TableGenMultiLineString)) {
+// This must never be annotated as other types.
+Tokens.back()->setTypeIsFinalized();

hnakamura5 wrote:

This is to clarify the intention is only finalizing the merged token. And not 
setting type to something else.
How about that?

I know the both the plan does not differ so much. If you regards 
`setTypeIsFinalized()` is unsuitable API, I will change the way.

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


[clang] [clang-format] TableGen multi line string support. (PR #78032)

2024-01-15 Thread Hirofumi Nakamura via cfe-commits

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


  1   2   3   4   5   6   >