[clang-tools-extra] [clangd] Resolve the dependent type from its single instantiation. Take 1 (PR #71279)

2023-11-20 Thread Nathan Ridge via cfe-commits
HighCommander4 wrote:

> I suspect it won't work with the present `TemplateTypeParm{Type,Decl}` 
> models. `TemplateTypeParmDecl` per se is not tied to any `CXXRecordDecl` nor 
> `FunctionDecl` that the template parameter is declaring with. (For the most 
> seemingly-relevant part, i.e. the `DeclContext` it records, is the scope that 
> the template defines.)

I've done some local experimentation, and what I'm seeing is that 
`TemplateTypeParmDecl::getDeclContext()` does return the `FunctionDecl` or 
`CXXRecordDecl` which owns the template parameter.

One tricky thing I found is that when starting from a template parameter 
**type**, it's important to use `dyn_cast(T)` rather than 
`T->getAs()`; the latter does more than just cast, it 
returns the canonical type whose associated Decl is null.

I also discovered some complications related to nested templates, and I have 
some thoughts on how to resolve them, but I'm going to suggest that we start 
with getting a simple case (e.g. just one level of templates, no nested 
templates) to work, and then tackle nested templates as a next step.

> > If so, find the argument type substituted for this template parameter, and 
> > replace the template parameter with this type.
> 
> I was thinking this way before getting into the details :-). Soon I realized 
> that we had to tackle synthesized types e.g.
> 
> ```c++
> template  typename C, typename D, int E>
> void work() {
>   C complicated_type;
>   // ^ Shall we perform the type substitution once again? ;)
> }
> ```

I'm not too concerned about this. The idea behind `HeuristicResolver` is to 
perform name lookups in the primary template as a heuristic.

So, to give an example:

```c++
template 
void work() {
  std::vector a;
  a.pop_back();
}
```

here, `pop_back` is looked up in the primary template scope of `std::vector`; 
information from the argument list `` is not used.

Now, applying this to your example:

```c++
template  class A, typename T>
void work() {
  A a;
  a.pop_back();
}

// work() has one instantiation, with [A = std::vector, T = bar] 
```

applying the "only instantiation" heuristic will tell us that `A = 
std::vector`, and then we can look up `pop_back` in the primary template scope 
of `std::vector`; we still don't use information from the argument list ``.

We could potentially envision future enhancements to make use of information 
from the "only instantiation" to make lookup inside template specialization 
types more accurate than just "use the primary template" (which could then 
apply to the `std::vector` case as well, and e.g. return a more accurate 
result if the "only instantiation" is `T = bool`), but that seems like more of 
an edge case and I'd rather leave it to a future change.

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


[llvm] [clang-tools-extra] [clang] [clang] Fix false positive -Wmissing-field-initializer for anonymous unions (PR #70829)

2023-11-20 Thread Mariya Podchishchaeva via cfe-commits
Fznamznon wrote:

Ping.

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


[clang] cdf6693 - [AArch64][SME] Add support for sme-fa64 (#70809)

2023-11-20 Thread via cfe-commits
Author: Matthew Devereau
Date: 2023-11-20T08:37:52Z
New Revision: cdf6693f072b97ec42a95f569115ad7f0afd37d5

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

LOG: [AArch64][SME] Add support for sme-fa64 (#70809)

Added: 
llvm/test/CodeGen/AArch64/sve-streaming-mode-fixed-length-fp-reduce-fa64.ll

llvm/test/CodeGen/AArch64/sve-streaming-mode-fixed-length-int-mla-neon-fa64.ll
llvm/test/MC/AArch64/SME/fa64-implies-sve2.s

Modified: 
clang/lib/Basic/Targets/AArch64.cpp
clang/lib/Basic/Targets/AArch64.h
llvm/include/llvm/TargetParser/AArch64TargetParser.h
llvm/lib/Target/AArch64/AArch64.td
llvm/lib/Target/AArch64/AArch64InstrInfo.td
llvm/lib/Target/AArch64/AArch64SchedA64FX.td
llvm/lib/Target/AArch64/AArch64Subtarget.cpp
llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
llvm/unittests/TargetParser/TargetParserTest.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index fde220163805554..c31f2e0bee54393 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -685,6 +685,7 @@ bool AArch64TargetInfo::hasFeature(StringRef Feature) const 
{
   .Case("sme", HasSME)
   .Case("sme-f64f64", HasSMEF64F64)
   .Case("sme-i16i64", HasSMEI16I64)
+  .Case("sme-fa64", HasSMEFA64)
   .Cases("memtag", "memtag2", HasMTE)
   .Case("sb", HasSB)
   .Case("predres", HasPredRes)
@@ -814,6 +815,13 @@ bool 
AArch64TargetInfo::handleTargetFeatures(std::vector &Features,
   HasBFloat16 = true;
   HasFullFP16 = true;
 }
+if (Feature == "+sme-fa64") {
+  FPU |= NeonMode;
+  FPU |= SveMode;
+  HasSME = true;
+  HasSVE2 = true;
+  HasSMEFA64 = true;
+}
 if (Feature == "+sb")
   HasSB = true;
 if (Feature == "+predres")

diff  --git a/clang/lib/Basic/Targets/AArch64.h 
b/clang/lib/Basic/Targets/AArch64.h
index 9ccc637f5494784..f0e0782e7abe973 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -83,6 +83,7 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public 
TargetInfo {
   bool HasFMV = true;
   bool HasGCS = false;
   bool HasRCPC3 = false;
+  bool HasSMEFA64 = false;
 
   const llvm::AArch64::ArchInfo *ArchInfo = &llvm::AArch64::ARMV8A;
 

diff  --git a/llvm/include/llvm/TargetParser/AArch64TargetParser.h 
b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
index c74b7b80749ea31..5637c9b4ec37b2b 100644
--- a/llvm/include/llvm/TargetParser/AArch64TargetParser.h
+++ b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
@@ -172,6 +172,7 @@ enum ArchExtKind : unsigned {
   AEK_SME_LUTv2 = 68, // FEAT_SME_LUTv2
   AEK_SMEF8F16 =  69, // FEAT_SME_F8F16
   AEK_SMEF8F32 =  70, // FEAT_SME_F8F32
+  AEK_SMEFA64 =   71, // FEAT_SME_FA64
   AEK_NUM_EXTENSIONS
 };
 using ExtensionBitset = Bitset;
@@ -293,6 +294,7 @@ inline constexpr ExtensionInfo Extensions[] = {
 {"sme-lutv2", AArch64::AEK_SME_LUTv2, "+sme-lutv2", "-sme-lutv2", 
FEAT_INIT, "", 0},
 {"sme-f8f16", AArch64::AEK_SMEF8F16, "+sme-f8f16", "-sme-f8f16", 
FEAT_INIT, "+sme2,+fp8", 0},
 {"sme-f8f32", AArch64::AEK_SMEF8F32, "+sme-f8f32", "-sme-f8f32", 
FEAT_INIT, "+sme2,+fp8", 0},
+{"sme-fa64",  AArch64::AEK_SMEFA64,  "+sme-fa64", "-sme-fa64",  FEAT_INIT, 
"", 0},
 // Special cases
 {"none", AArch64::AEK_NONE, {}, {}, FEAT_INIT, "", 
ExtensionInfo::MaxFMVPriority},
 };

diff  --git a/llvm/lib/Target/AArch64/AArch64.td 
b/llvm/lib/Target/AArch64/AArch64.td
index f1f3d56335e3c1f..7176139ec1b7302 100644
--- a/llvm/lib/Target/AArch64/AArch64.td
+++ b/llvm/lib/Target/AArch64/AArch64.td
@@ -508,6 +508,9 @@ def FeatureSMEI16I64 : SubtargetFeature<"sme-i16i64", 
"HasSMEI16I64", "true",
 def FeatureSMEF16F16 : SubtargetFeature<"sme-f16f16", "HasSMEF16F16", "true",
   "Enable SME2.1 non-widening Float16 instructions (FEAT_SME_F16F16)", []>;
 
+def FeatureSMEFA64 : SubtargetFeature<"sme-fa64", "HasSMEFA64", "true",
+  "Enable the full A64 instruction set in streaming SVE mode (FEAT_SME_FA64)", 
[FeatureSME, FeatureSVE2]>;
+
 def FeatureSME2 : SubtargetFeature<"sme2", "HasSME2", "true",
   "Enable Scalable Matrix Extension 2 (SME2) instructions", [FeatureSME]>;
 
@@ -800,7 +803,7 @@ def SME2Unsupported : AArch64Unsupported {
 }
 
 def SMEUnsupported : AArch64Unsupported {
-  let F = !listconcat([HasSME, HasSMEI16I64, HasSMEF16F16, HasSMEF64F64],
+  let F = !listconcat([HasSME, HasSMEI16I64, HasSMEF16F16, HasSMEF64F64, 
HasSMEFA64],
   SME2Unsupported.F);
 }
 

diff  --git a/llvm/lib/Target/AArch64/AArch64InstrInfo.td 
b/llvm/lib/Target/AArch64/AArch64InstrInfo.td
index 290c79f7bacdb8f..e32209655ba955f 100644
--- a/llvm/lib/Target/AArch64/AArch64InstrInfo.td
+

[compiler-rt] [llvm] [clang] [AArch64][SME] Add support for sme-fa64 (PR #70809)

2023-11-20 Thread Matthew Devereau via cfe-commits
https://github.com/MDevereau closed 
https://github.com/llvm/llvm-project/pull/70809
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70401: [RISCV] CodeGen of RVE and ilp32e/lp64e ABIs

2023-11-20 Thread Wang Pengcheng via Phabricator via cfe-commits
wangpc added a comment.

@craig.topper Thanks!
@asb Hi Alex, I'd like to get another approval from you. Are there any more 
concerns?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70401

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


[PATCH] D70401: [RISCV] CodeGen of RVE and ilp32e/lp64e ABIs

2023-11-20 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added a comment.

GCC only ever defines __riscv_32e




Comment at: clang/lib/Basic/Targets/RISCV.cpp:210
+if (Is64Bit)
+  Builder.defineMacro("__riscv_64e");
+else

Ugh, these don't align with the normal pattern. __riscv_e already exists in the 
spec, can we just leave __riscv_32e as deprecated for RV32E and not introduce 
the old-style __riscv_64e?



Comment at: clang/lib/Basic/Targets/RISCV.h:139
 if (Name == "ilp32" || Name == "ilp32f" || Name == "ilp32d") {
   ABI = Name;
   return true;

Does it matter we don't undo the effects of the RVE ABI here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70401

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


[PATCH] D70401: [RISCV] CodeGen of RVE and ilp32e/lp64e ABIs

2023-11-20 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added a comment.

In D70401#4657098 , @jrtc27 wrote:

> GCC only ever defines __riscv_32e

Hm, seems the comments about __riscv_32e were from months ago, ignore them if 
they aren't correct or have become outdated...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70401

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


[clang] edd675a - [OpenMP] atomic compare fail : Parser & AST support

2023-11-20 Thread Sandeep Kosuri via cfe-commits
Author: Sunil Kuravinakop
Date: 2023-11-20T03:05:31-06:00
New Revision: edd675ac283909397880f85ba68d0d5f99dc1be2

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

LOG: [OpenMP] atomic compare fail : Parser & AST support

Diff Revision: https://reviews.llvm.org/D123235

Added: 


Modified: 
clang/include/clang/AST/OpenMPClause.h
clang/include/clang/AST/RecursiveASTVisitor.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/OpenMPKinds.def
clang/include/clang/Basic/OpenMPKinds.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/OpenMPClause.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/Basic/OpenMPKinds.cpp
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/OpenMP/atomic_ast_print.cpp
clang/test/OpenMP/atomic_messages.cpp
clang/tools/libclang/CIndex.cpp
flang/lib/Semantics/check-omp-structure.cpp
llvm/include/llvm/Frontend/OpenMP/OMP.td

Removed: 




diff  --git a/clang/include/clang/AST/OpenMPClause.h 
b/clang/include/clang/AST/OpenMPClause.h
index 549f12e87df597a..ccceadeabedc7ff 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -2513,6 +2513,89 @@ class OMPRelaxedClause final : public OMPClause {
   }
 };
 
+/// This represents 'fail' clause in the '#pragma omp atomic'
+/// directive.
+///
+/// \code
+/// #pragma omp atomic compare fail
+/// \endcode
+/// In this example directive '#pragma omp atomic compare' has 'fail' clause.
+class OMPFailClause final : public OMPClause {
+
+  // FailParameter is a memory-order-clause. Storing the ClauseKind is
+  // sufficient for our purpose.
+  OpenMPClauseKind FailParameter = llvm::omp::Clause::OMPC_unknown;
+  SourceLocation FailParameterLoc;
+  SourceLocation LParenLoc;
+
+  friend class OMPClauseReader;
+
+  /// Sets the location of '(' in fail clause.
+  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
+
+  /// Sets the location of memoryOrder clause argument in fail clause.
+  void setFailParameterLoc(SourceLocation Loc) { FailParameterLoc = Loc; }
+
+  /// Sets the mem_order clause for 'atomic compare fail' directive.
+  void setFailParameter(OpenMPClauseKind FailParameter) {
+this->FailParameter = FailParameter;
+assert(checkFailClauseParameter(FailParameter) &&
+   "Invalid fail clause parameter");
+  }
+
+public:
+  /// Build 'fail' clause.
+  ///
+  /// \param StartLoc Starting location of the clause.
+  /// \param EndLoc Ending location of the clause.
+  OMPFailClause(SourceLocation StartLoc, SourceLocation EndLoc)
+  : OMPClause(llvm::omp::OMPC_fail, StartLoc, EndLoc) {}
+
+  OMPFailClause(OpenMPClauseKind FailParameter, SourceLocation 
FailParameterLoc,
+SourceLocation StartLoc, SourceLocation LParenLoc,
+SourceLocation EndLoc)
+  : OMPClause(llvm::omp::OMPC_fail, StartLoc, EndLoc),
+FailParameterLoc(FailParameterLoc), LParenLoc(LParenLoc) {
+
+setFailParameter(FailParameter);
+  }
+
+  /// Build an empty clause.
+  OMPFailClause()
+  : OMPClause(llvm::omp::OMPC_fail, SourceLocation(), SourceLocation()) {}
+
+  child_range children() {
+return child_range(child_iterator(), child_iterator());
+  }
+
+  const_child_range children() const {
+return const_child_range(const_child_iterator(), const_child_iterator());
+  }
+
+  child_range used_children() {
+return child_range(child_iterator(), child_iterator());
+  }
+  const_child_range used_children() const {
+return const_child_range(const_child_iterator(), const_child_iterator());
+  }
+
+  static bool classof(const OMPClause *T) {
+return T->getClauseKind() == llvm::omp::OMPC_fail;
+  }
+
+  /// Gets the location of '(' (for the parameter) in fail clause.
+  SourceLocation getLParenLoc() const {
+return LParenLoc;
+  }
+
+  /// Gets the location of Fail Parameter (type memory-order-clause) in
+  /// fail clause.
+  SourceLocation getFailParameterLoc() const { return FailParameterLoc; }
+
+  /// Gets the parameter (type memory-order-clause) in Fail clause.
+  OpenMPClauseKind getFailParameter() const { return FailParameter; }
+};
+
 /// This represents clause 'private' in the '#pragma omp ...' directives.
 ///
 /// \code

diff  --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index 53bc15e1b19f668..c501801b95bd955 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -3398,6 +3398,11 @@ bool 
RecursiveASTVisitor::VisitOMPCompareClause(OMPCompareClause *) {

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

2023-11-20 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-tools-extra] [llvm] [SVE2.1][Clang][LLVM]Add BFloat16 builtin in Clang and LLVM intrinisc (PR #70362)

2023-11-20 Thread via cfe-commits

@@ -0,0 +1,61 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 
-target-feature +b16b16 -target-feature +sve -S -disable-O0-optnone -Werror 
-Wall -emit-llvm -o - %s | opt -S -p mem2reg,instcombine,tailcallelim | 
FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 
-target-feature +b16b16 -target-feature +sve -S -disable-O0-optnone -Werror 
-Wall -emit-llvm -o - -x c++ %s | opt -S -p mem2reg,instcombine,tailcallelim | 
FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve2p1 -target-feature +b16b16 -target-feature +sve -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve2p1 -target-feature +b16b16 -target-feature +sve -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - -x c++ %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 
-target-feature +b16b16 -target-feature +sve -target-feature -S 
-disable-O0-optnone -Werror -Wall -o /dev/null %s
+#include 
+
+#ifdef SVE_OVERLOADED_FORMS
+// A simple used,unused... macro, long enough to represent any SVE builtin.
+#define SVE_ACLE_FUNC(A1,A2_UNUSED,A3) A1##A3
+#else
+#define SVE_ACLE_FUNC(A1,A2,A3) A1##A2##A3
+#endif
+
+// CHECK-LABEL: @test_svmul_lane_bf16_idx1(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.fmul.lane.nxv8bf16( [[OP1:%.*]],  [[OP2:%.*]], i32 1)
+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: 
@_Z25test_svmul_lane_bf16_idx1u14__SVBFloat16_tu14__SVBFloat16_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.fmul.lane.nxv8bf16( [[OP1:%.*]],  [[OP2:%.*]], i32 1)
+// CPP-CHECK-NEXT:ret  [[TMP0]]
+//
+svbfloat16_t test_svmul_lane_bf16_idx1(svbfloat16_t op1, svbfloat16_t op2)
+{
+  return SVE_ACLE_FUNC(svmul_lane, _bf16, )(op1, op2, 1);
+}
+
+// CHECK-LABEL: @test_svmul_lane_bf16_idx3(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.fmul.lane.nxv8bf16( [[OP1:%.*]],  [[OP2:%.*]], i32 3)
+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: 
@_Z25test_svmul_lane_bf16_idx3u14__SVBFloat16_tu14__SVBFloat16_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.fmul.lane.nxv8bf16( [[OP1:%.*]],  [[OP2:%.*]], i32 3)
+// CPP-CHECK-NEXT:ret  [[TMP0]]
+//
+svbfloat16_t test_svmul_lane_bf16_idx3(svbfloat16_t op1, svbfloat16_t op2)
+{
+  return SVE_ACLE_FUNC(svmul_lane, _bf16, )(op1, op2, 3);
+}
+
+// CHECK-LABEL: @test_svmul_lane_bf16_idx7(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.fmul.lane.nxv8bf16( [[OP1:%.*]],  [[OP2:%.*]], i32 7)
+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: 
@_Z25test_svmul_lane_bf16_idx7u14__SVBFloat16_tu14__SVBFloat16_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.fmul.lane.nxv8bf16( [[OP1:%.*]],  [[OP2:%.*]], i32 7)
+// CPP-CHECK-NEXT:ret  [[TMP0]]
+//
+svbfloat16_t test_svmul_lane_bf16_idx7(svbfloat16_t op1, svbfloat16_t op2)
+{
+  return SVE_ACLE_FUNC(svmul_lane, _bf16, )(op1, op2, 7);

CarolineConcatto wrote:

This is needs to be a constant. If you check the arm_sve_sme.td you will see 
that this is the definitions of these intrinsics:
i - {d} stands for default and {i} for  constant uint64_t.
The index lane always needs to be a constant.


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


[clang-tools-extra] [clangd] Add includes from source to non-self-contained headers (PR #72479)

2023-11-20 Thread kadir çetinkaya via cfe-commits
kadircet wrote:

hi! thanks for the interest @sr-tream but I am afraid this is likely to cause 
disruption in more cases than it might improve.

apart from technical details like the threading concerns and reliance on 
certain variants that we don't really have (eg order of includes); at a high 
level the idea of "finding a representative source file for the header and 
replicating the PP state" is hard to work in general.

The current approach of finding a candidate through `HeaderIncluders` will pick 
an arbitrary source file that transitively includes the header you're 
interested in. Hence you'll actually create a set of `-include XX` commands, 
that **might** (and probably will) recursively include the header itself. Also 
there's nothing detecting a failure in processing of the compilation unit, this 
is done without checking self-containedness (which is again hard to check) 
hence will definitely regress both performance and correctness for 
self-contained headers as well.

sorry for forgetting to hit send on friday, i see that you did some more 
iterations on the weekend. but i think it'd be better to discuss the general 
approach first, to see if that makes sense. not only to ensure 
non-self-contained headers can be handled properly rather than adding an edge 
case where things look like they're working (but they're not, hence resulting 
in more bug reports and hard-to-maintain fixes), but also to make sure they're 
not regressing anything for regular code paths.

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


[clang] [analyzer] Use AllocaRegion in MallocChecker (PR #72402)

2023-11-20 Thread Endre Fülöp via cfe-commits

@@ -81,22 +81,21 @@ bool BuiltinFunctionChecker::evalCall(const CallEvent &Call,
 
   case Builtin::BI__builtin_alloca_with_align:
   case Builtin::BI__builtin_alloca: {
-// FIXME: Refactor into StoreManager itself?
-MemRegionManager& RM = C.getStoreManager().getRegionManager();
-const AllocaRegion* R =
-  RM.getAllocaRegion(CE, C.blockCount(), C.getLocationContext());
-
-// Set the extent of the region in bytes. This enables us to use the
-// SVal of the argument directly. If we save the extent in bits, we
-// cannot represent values like symbol*8.
-auto Size = Call.getArgSVal(0);
-if (Size.isUndef())
-  return true; // Return true to model purity.
-
-state = setDynamicExtent(state, R, Size.castAs(),
- C.getSValBuilder());
+SValBuilder &SVB = C.getSValBuilder();
+const loc::MemRegionVal R =
+SVB.getAllocaRegionVal(CE, C.getLocationContext(), C.blockCount());
 
-C.addTransition(state->BindExpr(CE, LCtx, loc::MemRegionVal(R)));
+// Set the extent of the region in bytes. This enables us to use the SVal
+// of the argument directly. If we saved the extent in bits, it'd be more
+// difficult to reason about values like symbol*8.
+auto Size = Call.getArgSVal(0);
+if (auto DefSize = Size.getAs()) {
+  state = setDynamicExtent(state, R.getRegion(), *DefSize, SVB);
+  // FIXME: perhaps the following transition should be moved out of the

gamesh411 wrote:

I would go with first asserting that the Size is DefinedOrUnknown anyway, and 
if we have a crash with a reproducer, then we can add the if and the test case 
for it.

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


[clang] [analyzer] Use AllocaRegion in MallocChecker (PR #72402)

2023-11-20 Thread Endre Fülöp via cfe-commits
https://github.com/gamesh411 approved this pull request.

LGTM, added two remarks inline, but those can be separate patches as well.

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


[clang] [analyzer] Use AllocaRegion in MallocChecker (PR #72402)

2023-11-20 Thread Endre Fülöp via cfe-commits
https://github.com/gamesh411 edited 
https://github.com/llvm/llvm-project/pull/72402
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Use AllocaRegion in MallocChecker (PR #72402)

2023-11-20 Thread Endre Fülöp via cfe-commits

@@ -266,13 +266,18 @@ void CheckUseZeroAllocated1(void) {
 }
 
 char CheckUseZeroAllocated2(void) {
+  // FIXME: The return value of `alloca()` is modeled with `AllocaRegion`
+  // instead of `SymbolicRegion`, so the current implementation of
+  // `MallocChecker::checkUseZeroAllocated()` cannot handle it; and we get an
+  // unrelated, but suitable warning from core.uninitialized.UndefReturn.
   char *p = alloca(0);
-  return *p; // expected-warning {{Use of memory allocated with size zero}}
+  return *p; // expected-warning {{Undefined or garbage value returned to 
caller}}

gamesh411 wrote:

Even if it is not the real question, what we are to do with the 0-size `alloca` 
calls, but just to highlight some practical concerns, I found these sources:
https://discourse.llvm.org/t/malloc-free-and-alloca-with-zero-size/9284/3
https://stackoverflow.com/questions/8036654/what-does-alloca0-do-and-return-on-various-platforms

So `alloca(0)` sometimes has a special meaning. If we can give more specific 
error messages in these cases, I would prefer to handle those error messages in 
the more specific checker.
Even if ArrayBoundV2 has more user-friendly and mature error reporting (and 
would cover this case strictly speaking), making this more specific checker 
emit better diagnostics as well is something worth considering IMO.

https://github.com/llvm/llvm-project/pull/72402
___
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)

2023-11-20 Thread Balázs Kéri via cfe-commits
https://github.com/balazske created 
https://github.com/llvm/llvm-project/pull/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.

From 99d6169f62862b7b1147da7fd26a85df20a0aba5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= 
Date: Mon, 20 Nov 2023 10:14:52 +0100
Subject: [PATCH] [clang][ASTImporter] Fix import of variable template
 redeclarations.

In some cases variable templates (specially if static member of record)
were not correctly imported and an assertion "Missing call to MapImported?"
could happen.
---
 clang/lib/AST/ASTImporter.cpp   |  27 +++---
 clang/unittests/AST/ASTImporterTest.cpp | 105 
 2 files changed, 122 insertions(+), 10 deletions(-)

diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index c4e931e220f69b5..7a5e3d665328532 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -6245,17 +6245,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
+// different initializers?
 VarTemplateDecl *FoundDef = getTemplateDefinition(FoundTemplate);
-if (D->isThisDeclarationADefinition() && FoundDef)
-  // FIXME Check for ODR error if the two definitions have
-  // different 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;
   }
@@ -6374,7 +6378,10 @@ ExpectedDecl 
ASTNodeImporter::VisitVarTemplateSpecializationDecl(
 // variable.
 return Importer.MapImported(D, FoundDef);
   }
+  // FIXME HandleNameConflict
+  return make_error(ASTImportError::NameConflict);
 }
+return Importer.MapImported(D, D2);
   } else {
 TemplateArgumentListInfo ToTAInfo;
 if (const ASTTemplateArgumentListInfo *Args = D->getTemplateArgsInfo()) {
diff --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 5f4d8d040772cb1..d439a14b7b9985f 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -5050,6 +5050,111 @@ TEST_P(ImportFriendClasses, RecordVarTemplateDecl) {
   EXPECT_EQ(ToTUX, ToX);
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, VarTemplateDeclConflict) {
+  Decl *ToTU = 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, VarTemplateSpecializationDeclValue) {
+  Decl *ToTU = getToTuDecl(
+  R"(
+  template 
+  constexpr int X = U::Value;
+  struct A { static constexpr int Value = 1; };
+ 

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

2023-11-20 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Balázs Kéri (balazske)


Changes

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

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


2 Files Affected:

- (modified) clang/lib/AST/ASTImporter.cpp (+17-10) 
- (modified) clang/unittests/AST/ASTImporterTest.cpp (+105) 


``diff
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index c4e931e220f69b5..7a5e3d665328532 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -6245,17 +6245,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
+// different initializers?
 VarTemplateDecl *FoundDef = getTemplateDefinition(FoundTemplate);
-if (D->isThisDeclarationADefinition() && FoundDef)
-  // FIXME Check for ODR error if the two definitions have
-  // different 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;
   }
@@ -6374,7 +6378,10 @@ ExpectedDecl 
ASTNodeImporter::VisitVarTemplateSpecializationDecl(
 // variable.
 return Importer.MapImported(D, FoundDef);
   }
+  // FIXME HandleNameConflict
+  return make_error(ASTImportError::NameConflict);
 }
+return Importer.MapImported(D, D2);
   } else {
 TemplateArgumentListInfo ToTAInfo;
 if (const ASTTemplateArgumentListInfo *Args = D->getTemplateArgsInfo()) {
diff --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 5f4d8d040772cb1..d439a14b7b9985f 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -5050,6 +5050,111 @@ TEST_P(ImportFriendClasses, RecordVarTemplateDecl) {
   EXPECT_EQ(ToTUX, ToX);
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, VarTemplateDeclConflict) {
+  Decl *ToTU = 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, VarTemplateSpecializationDeclValue) {
+  Decl *ToTU = getToTuDecl(
+  R"(
+  template 
+  constexpr int X = U::Value;
+  struct A { static constexpr int Value = 1; };
+  constexpr int Y = X;
+  )",
+  Lang_CXX14);
+
+  auto *ToTUX = FirstDeclMatcher().match(
+  ToTU, varTemplateSpecializationDecl(hasName("X")));
+  Decl *FromTU = getTuDecl(
+  R"(
+  template 
+  constexpr int X = U::Value;
+  struct A { static constexpr int Value = 1; };
+  constexpr int Y = X;
+  )",
+  Lang_CXX14, "in

[clang-tools-extra] [clangd] Add includes from source to non-self-contained headers (PR #72479)

2023-11-20 Thread via cfe-commits
sr-tream wrote:

> apart from technical details like the threading concerns and reliance on 
> certain variants that we don't really have (eg order of includes); at a high 
> level the idea of "finding a representative source file for the header and 
> replicating the PP state" is hard to work in general.
> 
> The current approach of finding a candidate through `HeaderIncluders` will 
> pick an arbitrary source file that transitively includes the header you're 
> interested in. Hence you'll actually create a set of `-include XX` commands, 
> that **might** (and probably will) recursively include the header itself. 
> Also there's nothing detecting a failure in processing of the compilation 
> unit, this is done without checking self-containedness (which is again hard 
> to check) hence will definitely regress both performance and correctness for 
> self-contained headers as well.

We can limit ourselves to only the paired source file, and cancel inclusions if 
the source file does not include a non-self-contained header directly. This 
will reduce the number of situations in which this hack works, but will avoid 
the problems you describe

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


[clang] [clang-tools-extra] [llvm] [SVE2.1][Clang][LLVM]Add BFloat16 builtin in Clang and LLVM intrinisc (PR #70362)

2023-11-20 Thread Momchil Velikov via cfe-commits

@@ -0,0 +1,61 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 
-target-feature +b16b16 -target-feature +sve -S -disable-O0-optnone -Werror 
-Wall -emit-llvm -o - %s | opt -S -p mem2reg,instcombine,tailcallelim | 
FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 
-target-feature +b16b16 -target-feature +sve -S -disable-O0-optnone -Werror 
-Wall -emit-llvm -o - -x c++ %s | opt -S -p mem2reg,instcombine,tailcallelim | 
FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve2p1 -target-feature +b16b16 -target-feature +sve -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve2p1 -target-feature +b16b16 -target-feature +sve -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - -x c++ %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 
-target-feature +b16b16 -target-feature +sve -target-feature -S 
-disable-O0-optnone -Werror -Wall -o /dev/null %s
+#include 
+
+#ifdef SVE_OVERLOADED_FORMS
+// A simple used,unused... macro, long enough to represent any SVE builtin.
+#define SVE_ACLE_FUNC(A1,A2_UNUSED,A3) A1##A3
+#else
+#define SVE_ACLE_FUNC(A1,A2,A3) A1##A2##A3
+#endif
+
+// CHECK-LABEL: @test_svmul_lane_bf16_idx1(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.fmul.lane.nxv8bf16( [[OP1:%.*]],  [[OP2:%.*]], i32 1)
+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: 
@_Z25test_svmul_lane_bf16_idx1u14__SVBFloat16_tu14__SVBFloat16_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.fmul.lane.nxv8bf16( [[OP1:%.*]],  [[OP2:%.*]], i32 1)
+// CPP-CHECK-NEXT:ret  [[TMP0]]
+//
+svbfloat16_t test_svmul_lane_bf16_idx1(svbfloat16_t op1, svbfloat16_t op2)
+{
+  return SVE_ACLE_FUNC(svmul_lane, _bf16, )(op1, op2, 1);
+}
+
+// CHECK-LABEL: @test_svmul_lane_bf16_idx3(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.fmul.lane.nxv8bf16( [[OP1:%.*]],  [[OP2:%.*]], i32 3)
+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: 
@_Z25test_svmul_lane_bf16_idx3u14__SVBFloat16_tu14__SVBFloat16_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.fmul.lane.nxv8bf16( [[OP1:%.*]],  [[OP2:%.*]], i32 3)
+// CPP-CHECK-NEXT:ret  [[TMP0]]
+//
+svbfloat16_t test_svmul_lane_bf16_idx3(svbfloat16_t op1, svbfloat16_t op2)
+{
+  return SVE_ACLE_FUNC(svmul_lane, _bf16, )(op1, op2, 3);
+}
+
+// CHECK-LABEL: @test_svmul_lane_bf16_idx7(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.fmul.lane.nxv8bf16( [[OP1:%.*]],  [[OP2:%.*]], i32 7)
+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: 
@_Z25test_svmul_lane_bf16_idx7u14__SVBFloat16_tu14__SVBFloat16_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.fmul.lane.nxv8bf16( [[OP1:%.*]],  [[OP2:%.*]], i32 7)
+// CPP-CHECK-NEXT:ret  [[TMP0]]
+//
+svbfloat16_t test_svmul_lane_bf16_idx7(svbfloat16_t op1, svbfloat16_t op2)
+{
+  return SVE_ACLE_FUNC(svmul_lane, _bf16, )(op1, op2, 7);

momchil-velikov wrote:

Yes, that's what these tests do, check that you get an error if you pass a 
non-constant.

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


[libc] [llvm] [lldb] [clang] [flang] [mlir] [compiler-rt] [libunwind] [clang-tools-extra] [libcxxabi] [lld] [libcxx] PR#72453 : Exceeding maximum file name length (PR #72654)

2023-11-20 Thread Shahid Iqbal via cfe-commits
https://github.com/shahidiqbal13 updated 
https://github.com/llvm/llvm-project/pull/72654

>From b6bfb18e25c111baf6c95a0a4a1c3d667bb25b6d Mon Sep 17 00:00:00 2001
From: Shahid Iqbal 
Date: Thu, 16 Nov 2023 11:26:43 -0500
Subject: [PATCH 1/6] TESTING infra

---
 clang/NOTES.txt | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/NOTES.txt b/clang/NOTES.txt
index f06ea8c70cd3409..c83dda52a1fc21e 100644
--- a/clang/NOTES.txt
+++ b/clang/NOTES.txt
@@ -4,6 +4,8 @@
 
 //===-===//
 
+//TESTING git infra//
+
 To time GCC preprocessing speed without output, use:
"time gcc -MM file"
 This is similar to -Eonly.

>From 7662d4f177d32c3159c1c48b11ce3884e4ea78c8 Mon Sep 17 00:00:00 2001
From: Shahid Iqbal 
Date: Fri, 17 Nov 2023 09:26:31 -0500
Subject: [PATCH 2/6] PR#72453 : Exceeding maximum file name length

---
 llvm/include/llvm/Analysis/DOTGraphTraitsPass.h | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h 
b/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h
index 07c08bc1cc3bcb6..f78d8ff52ee3932 100644
--- a/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h
+++ b/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h
@@ -17,6 +17,8 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/GraphWriter.h"
 
+#define MAX_FILENAME_LEN 255
+
 namespace llvm {
 
 /// Default traits class for extracting a graph from an analysis pass.
@@ -94,7 +96,7 @@ void printGraphForFunction(Function &F, GraphT Graph, 
StringRef Name,
   raw_fd_ostream File(Filename, EC, sys::fs::OF_TextWithCRLF);
   std::string GraphName = DOTGraphTraits::getGraphName(Graph);
 
-  if (!EC)
+  if (!EC && (Filename.length() <= MAX_FILENAME_LEN ))
 WriteGraph(File, Graph, IsSimple,
GraphName + " for '" + F.getName() + "' function");
   else
@@ -280,7 +282,7 @@ class DOTGraphTraitsModulePrinterWrapperPass : public 
ModulePass {
 raw_fd_ostream File(Filename, EC, sys::fs::OF_TextWithCRLF);
 std::string Title = DOTGraphTraits::getGraphName(Graph);
 
-if (!EC)
+if (!EC && (Filename.length() <= MAX_FILENAME_LEN ))
   WriteGraph(File, Graph, IsSimple, Title);
 else
   errs() << "  error opening file for writing!";
@@ -310,7 +312,7 @@ void WriteDOTGraphToFile(Function &F, GraphT &&Graph,
   std::string GraphName = DOTGraphTraits::getGraphName(Graph);
   std::string Title = GraphName + " for '" + F.getName().str() + "' function";
 
-  if (!EC)
+  if (!EC && (Filename.length() <= MAX_FILENAME_LEN ))
 WriteGraph(File, Graph, IsSimple, Title);
   else
 errs() << "  error opening file for writing!";

>From d3d33e5bfe907b761ecb9065fe45b698c3ce0672 Mon Sep 17 00:00:00 2001
From: Shahid Iqbal 
Date: Fri, 17 Nov 2023 09:48:43 -0500
Subject: [PATCH 3/6] Reverted the earlier test text

---
 clang/NOTES.txt | 2 --
 1 file changed, 2 deletions(-)

diff --git a/clang/NOTES.txt b/clang/NOTES.txt
index c83dda52a1fc21e..f06ea8c70cd3409 100644
--- a/clang/NOTES.txt
+++ b/clang/NOTES.txt
@@ -4,8 +4,6 @@
 
 //===-===//
 
-//TESTING git infra//
-
 To time GCC preprocessing speed without output, use:
"time gcc -MM file"
 This is similar to -Eonly.

>From 41c19e2ceee80cce8a60d0fd869958a0783ddb7f Mon Sep 17 00:00:00 2001
From: Shahid Iqbal 
Date: Fri, 17 Nov 2023 10:06:52 -0500
Subject: [PATCH 4/6] Code refactoring

---
 llvm/include/llvm/Analysis/DOTGraphTraitsPass.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h 
b/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h
index f78d8ff52ee3932..f7ab6df3b4dd819 100644
--- a/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h
+++ b/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h
@@ -96,7 +96,7 @@ void printGraphForFunction(Function &F, GraphT Graph, 
StringRef Name,
   raw_fd_ostream File(Filename, EC, sys::fs::OF_TextWithCRLF);
   std::string GraphName = DOTGraphTraits::getGraphName(Graph);
 
-  if (!EC && (Filename.length() <= MAX_FILENAME_LEN ))
+  if (!EC && (Filename.length() <= MAX_FILENAME_LEN))
 WriteGraph(File, Graph, IsSimple,
GraphName + " for '" + F.getName() + "' function");
   else
@@ -282,7 +282,7 @@ class DOTGraphTraitsModulePrinterWrapperPass : public 
ModulePass {
 raw_fd_ostream File(Filename, EC, sys::fs::OF_TextWithCRLF);
 std::string Title = DOTGraphTraits::getGraphName(Graph);
 
-if (!EC && (Filename.length() <= MAX_FILENAME_LEN ))
+if (!EC && (Filename.length() <= MAX_FILENAME_LEN))
   WriteGraph(File, Graph, IsSimple, Title);
 else
   errs() << "  error opening file for writing!";
@@ -312,7 +312,7 @@ void WriteDOTGraphToFile(Function &F, GraphT &&Graph,
   std::string GraphName = DOTGraphTraits::getGraphName(Graph);
   std::string Title = GraphName + " for '" + F.getName().str() + "' function";
 
-  if (!EC && (Filename.length() 

[PATCH] D70401: [RISCV] CodeGen of RVE and ilp32e/lp64e ABIs

2023-11-20 Thread Wang Pengcheng via Phabricator via cfe-commits
wangpc added a comment.

In D70401#4657101 , @jrtc27 wrote:

> In D70401#4657098 , @jrtc27 wrote:
>
>> GCC only ever defines __riscv_32e
>
> Hm, seems the comments about __riscv_32e were from months ago, ignore them if 
> they aren't correct or have become outdated...

FYI: https://github.com/riscv-non-isa/riscv-c-api-doc/pull/52


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D70401

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


[clang] [analyzer] Use AllocaRegion in MallocChecker (PR #72402)

2023-11-20 Thread via cfe-commits

@@ -266,13 +266,18 @@ void CheckUseZeroAllocated1(void) {
 }
 
 char CheckUseZeroAllocated2(void) {
+  // FIXME: The return value of `alloca()` is modeled with `AllocaRegion`
+  // instead of `SymbolicRegion`, so the current implementation of
+  // `MallocChecker::checkUseZeroAllocated()` cannot handle it; and we get an
+  // unrelated, but suitable warning from core.uninitialized.UndefReturn.
   char *p = alloca(0);
-  return *p; // expected-warning {{Use of memory allocated with size zero}}
+  return *p; // expected-warning {{Undefined or garbage value returned to 
caller}}

DonatNagyE wrote:

It seems that `alloca()` in general and `alloca(0)` in particular can mean many 
things, and I don't think that it's worth to create a specific error message 
because I cannot say anything concrete in it. This is a nonstandard function, 
and while we can model its "basic" behavior, I think that we shouldn't try to 
deal with its corner cases.

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


[clang-tools-extra] [clangd] Add includes from source to non-self-contained headers (PR #72479)

2023-11-20 Thread kadir çetinkaya via cfe-commits
kadircet wrote:

> We can limit ourselves to only the paired source file, and cancel inclusions 
> if the source file does not include a non-self-contained header directly. 
> This will reduce the number of situations in which this hack works, but will 
> avoid the problems you describe

deducing the paired source file is also a heuristic, which will likely go wrong 
at times. more importantly it'll still regress the behavior for self-contained 
headers, even if we ignore that, it still creates this new illusion of working 
when the user is lucky, and will trigger extra maintenance load (that's IMHO 
not justified) by already thin stretched maintainers.

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


[clang] f7b5c25 - [AArch64][SME] Remove immediate argument restriction for svldr and svstr (#68565)

2023-11-20 Thread via cfe-commits
Author: Sam Tebbs
Date: 2023-11-20T09:57:29Z
New Revision: f7b5c255070ef2d8a4492a45613a6a7df0b5f0cb

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

LOG: [AArch64][SME] Remove immediate argument restriction for svldr and svstr 
(#68565)

The svldr_vnum and svstr_vnum builtins always modify the base register
and tile slice and provide immediate offsets of zero, even when the
offset provided to the builtin is an immediate. This patch optimises the
output of the builtins when the offset is an immediate, to pass it
directly to the instruction and to not need the base register and tile
slice updates.

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_str.c
llvm/include/llvm/IR/IntrinsicsAArch64.td
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
llvm/lib/Target/AArch64/AArch64ISelLowering.h
llvm/lib/Target/AArch64/SMEInstrFormats.td
llvm/test/CodeGen/AArch64/sme-intrinsics-loads.ll
llvm/test/CodeGen/AArch64/sme-intrinsics-stores.ll
mlir/include/mlir/Dialect/ArmSME/IR/ArmSMEIntrinsicOps.td
mlir/test/Target/LLVMIR/arm-sme.mlir

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 570675b590eae6c..cc76b3a229be02a 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -9886,18 +9886,10 @@ Value *CodeGenFunction::EmitSMEZero(const SVETypeFlags 
&TypeFlags,
 Value *CodeGenFunction::EmitSMELdrStr(const SVETypeFlags &TypeFlags,
   SmallVectorImpl &Ops,
   unsigned IntID) {
-  if (Ops.size() == 3) {
-Function *Cntsb = CGM.getIntrinsic(Intrinsic::aarch64_sme_cntsb);
-llvm::Value *CntsbCall = Builder.CreateCall(Cntsb, {}, "svlb");
-
-llvm::Value *VecNum = Ops[2];
-llvm::Value *MulVL = Builder.CreateMul(CntsbCall, VecNum, "mulvl");
-
-Ops[1] = Builder.CreateGEP(Int8Ty, Ops[1], MulVL);
-Ops[0] = Builder.CreateAdd(
-Ops[0], Builder.CreateIntCast(VecNum, Int32Ty, true), "tileslice");
-Ops.erase(&Ops[2]);
-  }
+  if (Ops.size() == 2)
+Ops.push_back(Builder.getInt32(0));
+  else
+Ops[2] = Builder.CreateIntCast(Ops[2], Int32Ty, true);
   Function *F = CGM.getIntrinsic(IntID, {});
   return Builder.CreateCall(F, Ops);
 }

diff  --git a/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c 
b/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
index e85c47072f2df80..9af0778e89c5ec0 100644
--- a/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
+++ b/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
@@ -6,86 +6,53 @@
 
 #include 
 
-// CHECK-C-LABEL: define dso_local void @test_svldr_vnum_za(
-// CHECK-C-SAME: i32 noundef [[SLICE_BASE:%.*]], ptr noundef [[PTR:%.*]]) 
local_unnamed_addr #[[ATTR0:[0-9]+]] {
-// CHECK-C-NEXT:  entry:
-// CHECK-C-NEXT:tail call void @llvm.aarch64.sme.ldr(i32 [[SLICE_BASE]], 
ptr [[PTR]])
-// CHECK-C-NEXT:ret void
-//
-// CHECK-CXX-LABEL: define dso_local void @_Z18test_svldr_vnum_zajPKv(
-// CHECK-CXX-SAME: i32 noundef [[SLICE_BASE:%.*]], ptr noundef [[PTR:%.*]]) 
local_unnamed_addr #[[ATTR0:[0-9]+]] {
-// CHECK-CXX-NEXT:  entry:
-// CHECK-CXX-NEXT:tail call void @llvm.aarch64.sme.ldr(i32 [[SLICE_BASE]], 
ptr [[PTR]])
-// CHECK-CXX-NEXT:ret void
+// CHECK-C-LABEL: @test_svldr_vnum_za(
+// CHECK-CXX-LABEL: @_Z18test_svldr_vnum_zajPKv(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.ldr(i32 [[SLICE_BASE:%.*]], 
ptr [[PTR:%.*]], i32 0)
+// CHECK-NEXT:ret void
 //
 void test_svldr_vnum_za(uint32_t slice_base, const void *ptr) {
   svldr_vnum_za(slice_base, ptr, 0);
 }
 
-// CHECK-C-LABEL: define dso_local void @test_svldr_vnum_za_1(
-// CHECK-C-SAME: i32 noundef [[SLICE_BASE:%.*]], ptr noundef [[PTR:%.*]]) 
local_unnamed_addr #[[ATTR0]] {
-// CHECK-C-NEXT:  entry:
-// CHECK-C-NEXT:[[SVLB:%.*]] = tail call i64 @llvm.aarch64.sme.cntsb()
-// CHECK-C-NEXT:[[MULVL:%.*]] = mul i64 [[SVLB]], 15
-// CHECK-C-NEXT:[[TMP0:%.*]] = getelementptr i8, ptr [[PTR]], i64 [[MULVL]]
-// CHECK-C-NEXT:[[TILESLICE:%.*]] = add i32 [[SLICE_BASE]], 15
-// CHECK-C-NEXT:tail call void @llvm.aarch64.sme.ldr(i32 [[TILESLICE]], 
ptr [[TMP0]])
-// CHECK-C-NEXT:ret void
-//
-// CHECK-CXX-LABEL: define dso_local void @_Z20test_svldr_vnum_za_1jPKv(
-// CHECK-CXX-SAME: i32 noundef [[SLICE_BASE:%.*]], ptr noundef [[PTR:%.*]]) 
local_unnamed_addr #[[ATTR0]] {
-// CHECK-CXX-NEXT:  entry:
-// CHECK-CXX-NEXT:[[SVLB:%.*]] = tail call i64 @llvm.aarch64.sme.cntsb()
-// CHECK-CXX-NEXT:[[MULVL:%.*]] = mul i64 [[SVLB]], 15
-// CHECK-CXX-NEXT:[[TMP0:%.*]] = getelementptr i8, ptr [[P

[clang] [mlir] [llvm] [AArch64][SME] Remove immediate argument restriction for svldr and svstr (PR #68565)

2023-11-20 Thread Sam Tebbs via cfe-commits
https://github.com/SamTebbs33 closed 
https://github.com/llvm/llvm-project/pull/68565
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] Add includes from source to non-self-contained headers (PR #72479)

2023-11-20 Thread via cfe-commits
https://github.com/sr-tream closed 
https://github.com/llvm/llvm-project/pull/72479
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [clang-tools-extra] [MachineLICM][AArch64] Hoist COPY instructions with other uses in the loop (PR #71403)

2023-11-20 Thread via cfe-commits
https://github.com/Rin18 closed https://github.com/llvm/llvm-project/pull/71403
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [flang] [clang-tools-extra] [flang ]GETLOG runtime and extension implementation: get login username (PR #70917)

2023-11-20 Thread via cfe-commits
https://github.com/jeanPerier approved this pull request.

LGTM, thanks for addressing all my comments!

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


[clang] [analyzer] Use AllocaRegion in MallocChecker (PR #72402)

2023-11-20 Thread via cfe-commits
=?utf-8?q?Donát?= Nagy 
Message-ID:
In-Reply-To: 


https://github.com/DonatNagyE updated 
https://github.com/llvm/llvm-project/pull/72402

>From 703c06e2d6781c45e55d7021929a06cdb0275a14 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Don=C3=A1t=20Nagy?= 
Date: Wed, 15 Nov 2023 16:03:22 +0100
Subject: [PATCH 1/2] [analyzer] Use AllocaRegion in MallocChecker

...to model the results of alloca() and _alloca() calls. Previously it
acted as if these functions were returning memory from the heap, which
led to alpha.security.ArrayBoundV2 producing incorrect messages.
---
 .../Core/PathSensitive/SValBuilder.h  |  9 ++
 .../Checkers/BuiltinFunctionChecker.cpp   | 29 +--
 .../StaticAnalyzer/Checkers/MallocChecker.cpp | 10 ---
 clang/lib/StaticAnalyzer/Core/SValBuilder.cpp |  8 +
 clang/test/Analysis/malloc.c  | 14 +++--
 clang/test/Analysis/memory-model.cpp  |  2 +-
 .../test/Analysis/out-of-bounds-diagnostics.c |  8 ++---
 7 files changed, 52 insertions(+), 28 deletions(-)

diff --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
index 692c4384586569e..a64cf7ae4efcb82 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
@@ -215,6 +215,15 @@ class SValBuilder {
 const LocationContext *LCtx,
 QualType type, unsigned Count);
 
+  /// Create an SVal representing the result of an alloca()-like call, that is,
+  /// an AllocaRegion on the stack.
+  ///
+  /// After calling this function, it's a good idea to set the extent of the
+  /// returned AllocaRegion.
+  loc::MemRegionVal getAllocaRegionVal(const Expr *E,
+   const LocationContext *LCtx,
+   unsigned Count);
+
   DefinedOrUnknownSVal getDerivedRegionValueSymbolVal(
   SymbolRef parentSymbol, const TypedValueRegion *region);
 
diff --git a/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
index 4a56156de4b27fe..143326c435cf815 100644
--- a/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
@@ -81,22 +81,21 @@ bool BuiltinFunctionChecker::evalCall(const CallEvent &Call,
 
   case Builtin::BI__builtin_alloca_with_align:
   case Builtin::BI__builtin_alloca: {
-// FIXME: Refactor into StoreManager itself?
-MemRegionManager& RM = C.getStoreManager().getRegionManager();
-const AllocaRegion* R =
-  RM.getAllocaRegion(CE, C.blockCount(), C.getLocationContext());
-
-// Set the extent of the region in bytes. This enables us to use the
-// SVal of the argument directly. If we save the extent in bits, we
-// cannot represent values like symbol*8.
-auto Size = Call.getArgSVal(0);
-if (Size.isUndef())
-  return true; // Return true to model purity.
-
-state = setDynamicExtent(state, R, Size.castAs(),
- C.getSValBuilder());
+SValBuilder &SVB = C.getSValBuilder();
+const loc::MemRegionVal R =
+SVB.getAllocaRegionVal(CE, C.getLocationContext(), C.blockCount());
 
-C.addTransition(state->BindExpr(CE, LCtx, loc::MemRegionVal(R)));
+// Set the extent of the region in bytes. This enables us to use the SVal
+// of the argument directly. If we saved the extent in bits, it'd be more
+// difficult to reason about values like symbol*8.
+auto Size = Call.getArgSVal(0);
+if (auto DefSize = Size.getAs()) {
+  state = setDynamicExtent(state, R.getRegion(), *DefSize, SVB);
+  // FIXME: perhaps the following transition should be moved out of the
+  // 'if' to bind an AllocaRegion (with unknown/unspecified size) even in
+  // the unlikely case when the size argument is undefined.
+  C.addTransition(state->BindExpr(CE, LCtx, R));
+}
 return true;
   }
 
diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index d3a4020280616b0..417305e26c41b09 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -1731,10 +1731,12 @@ ProgramStateRef 
MallocChecker::MallocMemAux(CheckerContext &C,
   // TODO: We could rewrite post visit to eval call; 'malloc' does not have
   // side effects other than what we model here.
   unsigned Count = C.blockCount();
-  SValBuilder &svalBuilder = C.getSValBuilder();
+  SValBuilder &SVB = C.getSValBuilder();
   const LocationContext *LCtx = C.getPredecessor()->getLocationContext();
-  DefinedSVal RetVal = svalBuilder.getConjuredHeapSymbolVal(CE, LCtx, Count)
-  .castAs();
+  DefinedSVal RetVal =
+  ((Family == AF_Alloca) ?

[clang] [analyzer] Use AllocaRegion in MallocChecker (PR #72402)

2023-11-20 Thread via cfe-commits
=?utf-8?q?Donát?= Nagy 
Message-ID:
In-Reply-To: 



@@ -81,22 +81,21 @@ bool BuiltinFunctionChecker::evalCall(const CallEvent &Call,
 
   case Builtin::BI__builtin_alloca_with_align:
   case Builtin::BI__builtin_alloca: {
-// FIXME: Refactor into StoreManager itself?
-MemRegionManager& RM = C.getStoreManager().getRegionManager();
-const AllocaRegion* R =
-  RM.getAllocaRegion(CE, C.blockCount(), C.getLocationContext());
-
-// Set the extent of the region in bytes. This enables us to use the
-// SVal of the argument directly. If we save the extent in bits, we
-// cannot represent values like symbol*8.
-auto Size = Call.getArgSVal(0);
-if (Size.isUndef())
-  return true; // Return true to model purity.
-
-state = setDynamicExtent(state, R, Size.castAs(),
- C.getSValBuilder());
+SValBuilder &SVB = C.getSValBuilder();
+const loc::MemRegionVal R =
+SVB.getAllocaRegionVal(CE, C.getLocationContext(), C.blockCount());
 
-C.addTransition(state->BindExpr(CE, LCtx, loc::MemRegionVal(R)));
+// Set the extent of the region in bytes. This enables us to use the SVal
+// of the argument directly. If we saved the extent in bits, it'd be more
+// difficult to reason about values like symbol*8.
+auto Size = Call.getArgSVal(0);
+if (auto DefSize = Size.getAs()) {
+  state = setDynamicExtent(state, R.getRegion(), *DefSize, SVB);
+  // FIXME: perhaps the following transition should be moved out of the

DonatNagyE wrote:

I checked the situation with an assert and a straightforward testcase, and it 
turns out that currently the `getAs()` always succeeds, because 
`core.CallAndMessage` stops the execution with a bug report when an undefined 
argument is passed to a function. (However, if I disabled this functionality of 
`core.CallAndMessage`, the test -- obviously -- triggered the assertion.)

Based on this, I decided to keep the current defensive check, because I didn't 
want to add a hidden and marginal dependency relationship between these two 
checkers. I know that we may assume that `core` checkers are always on, but 
that doesn't mean that I should hide landmines like `assert(core.CallAndMessage 
is active and works as I assume)` in unrelated checkers.

I updated the comment to explain this situation, and I also moved the 
`addTransition()` call out of the `if` because that's the more logical place 
for that method call and this `supporting fire` from `core.CallAndMessage` 
guarantees that this change won't have unintended side effects (because the 
`if` succeeds in normal operation).

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


[clang] [analyzer] Use AllocaRegion in MallocChecker (PR #72402)

2023-11-20 Thread via cfe-commits
=?utf-8?q?Donát?= Nagy 
Message-ID:
In-Reply-To: 


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


[clang] [clang][DebugInfo] Attach DW_AT_const_value to static data-member definitions if available (PR #72730)

2023-11-20 Thread Michael Buch via cfe-commits
https://github.com/Michael137 updated 
https://github.com/llvm/llvm-project/pull/72730

>From 6dcb09dcc50a9b9e92640412242927b3e226929e Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Sat, 18 Nov 2023 00:20:05 +
Subject: [PATCH 1/6] [clang][DebugInfo][NFC] Create
 evaluateConstantInitializer helper function

---
 clang/lib/CodeGen/CGDebugInfo.cpp | 18 ++
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 0b52d99ad07f164..4840581b5d03f89 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -69,6 +69,19 @@ static uint32_t getDeclAlignIfRequired(const Decl *D, const 
ASTContext &Ctx) {
   return D->hasAttr() ? D->getMaxAlignment() : 0;
 }
 
+APValue const * evaluateConstantInitializer(clang::VarDecl const * VD) {
+  assert (VD != nullptr);
+
+  VD = VD->getCanonicalDecl();
+  if (!VD)
+return nullptr;
+
+  if (!VD->hasConstantInitialization() || !VD->hasInit())
+return nullptr;
+
+  return VD->evaluateValue();
+}
+
 CGDebugInfo::CGDebugInfo(CodeGenModule &CGM)
 : CGM(CGM), DebugKind(CGM.getCodeGenOpts().getDebugInfo()),
   DebugTypeExtRefs(CGM.getCodeGenOpts().DebugTypeExtRefs),
@@ -5596,14 +5609,11 @@ void CGDebugInfo::EmitGlobalVariable(const VarDecl *VD) 
{
   if (VD->hasAttr())
 return;
 
-  if (!VD->hasInit())
-return;
-
   const auto CacheIt = DeclCache.find(VD);
   if (CacheIt != DeclCache.end())
 return;
 
-  auto const *InitVal = VD->evaluateValue();
+  auto const * InitVal = evaluateConstantInitializer(VD);
   if (!InitVal)
 return;
 

>From fcc6e19d108798fb18c1973e4d4cc3800da07f9f Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Sat, 18 Nov 2023 00:52:24 +
Subject: [PATCH 2/6] fixup! clang-format

---
 clang/lib/CodeGen/CGDebugInfo.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 4840581b5d03f89..9bba6e6b13e9318 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -69,8 +69,8 @@ static uint32_t getDeclAlignIfRequired(const Decl *D, const 
ASTContext &Ctx) {
   return D->hasAttr() ? D->getMaxAlignment() : 0;
 }
 
-APValue const * evaluateConstantInitializer(clang::VarDecl const * VD) {
-  assert (VD != nullptr);
+APValue const *evaluateConstantInitializer(clang::VarDecl const *VD) {
+  assert(VD != nullptr);
 
   VD = VD->getCanonicalDecl();
   if (!VD)
@@ -5613,7 +5613,7 @@ void CGDebugInfo::EmitGlobalVariable(const VarDecl *VD) {
   if (CacheIt != DeclCache.end())
 return;
 
-  auto const * InitVal = evaluateConstantInitializer(VD);
+  auto const *InitVal = evaluateConstantInitializer(VD);
   if (!InitVal)
 return;
 

>From 148ab1793a866111060f77807ff065040fad92d8 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Sat, 18 Nov 2023 00:22:06 +
Subject: [PATCH 3/6] [clang][DebugInfo] Attach DW_AT_const_value to static
 data-member definitions if available

---
 clang/lib/CodeGen/CGDebugInfo.cpp  | 10 --
 .../CodeGenCXX/debug-info-static-inline-member.cpp |  2 +-
 clang/test/CodeGenCXX/inline-dllexport-member.cpp  |  2 +-
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 9bba6e6b13e9318..e01c57baef19931 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -5516,11 +5516,17 @@ void 
CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var,
 }
 AppendAddressSpaceXDeref(AddressSpace, Expr);
 
+llvm::DIExpression *E = nullptr;
+if (Expr.empty()) {
+  if (auto const *InitVal = evaluateConstantInitializer(D))
+E = createConstantValueExpression(D, *InitVal);
+} else
+  E = DBuilder.createExpression(Expr);
+
 llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(D);
 GVE = DBuilder.createGlobalVariableExpression(
 DContext, DeclName, LinkageName, Unit, LineNo, getOrCreateType(T, 
Unit),
-Var->hasLocalLinkage(), true,
-Expr.empty() ? nullptr : DBuilder.createExpression(Expr),
+Var->hasLocalLinkage(), true, E,
 getOrCreateStaticDataMemberDeclarationOrNull(D), TemplateParameters,
 Align, Annotations);
 Var->addDebugInfo(GVE);
diff --git a/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp 
b/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
index f2d4d9408a8297a..950ea9b302b290c 100644
--- a/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
+++ b/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
@@ -43,7 +43,7 @@ int main() {
 // CHECK:  @{{.*}}cexpr_struct_with_addr{{.*}} = 
 // CHECK-SAME!dbg ![[EMPTY_GLOBAL:[0-9]+]]
 
-// CHECK:  !DIGlobalVariableExpression(var: ![[INT_VAR:[0-9]+]], expr: 
!DIExpression())
+// CHECK:  !DIGlobalVariableExpression(var: ![[INT_VAR:[

[clang] [llvm] [AArch64][SME2] Add ldr_zt, str_zt builtins and intrinsics (PR #72849)

2023-11-20 Thread Matthew Devereau via cfe-commits
https://github.com/MDevereau created 
https://github.com/llvm/llvm-project/pull/72849

Use ZTR instead of MatrixOP to prevent expensive test check and machine 
verifier failures.

>From e1685cc0dea9501a993cbe3f8185a40e1f285591 Mon Sep 17 00:00:00 2001
From: Matt Devereau 
Date: Mon, 20 Nov 2023 10:49:27 +
Subject: [PATCH] [AArch64][SME2] Add ldr_zt, str_zt builtins and intrinsics

---
 clang/include/clang/Basic/arm_sme.td  |  8 +++
 .../acle_sme2_ldr_str_zt.c| 51 +++
 llvm/include/llvm/IR/IntrinsicsAArch64.td | 11 ++--
 .../Target/AArch64/AArch64ISelDAGToDAG.cpp|  8 ++-
 .../Target/AArch64/AArch64ISelLowering.cpp| 20 
 llvm/lib/Target/AArch64/AArch64ISelLowering.h |  2 +
 .../Target/AArch64/AArch64RegisterInfo.cpp|  6 +++
 .../lib/Target/AArch64/AArch64SMEInstrInfo.td |  4 +-
 llvm/lib/Target/AArch64/SMEInstrFormats.td| 23 +++--
 .../CodeGen/AArch64/sme2-intrinsics-zt0.ll| 27 ++
 10 files changed, 147 insertions(+), 13 deletions(-)
 create mode 100644 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_ldr_str_zt.c
 create mode 100644 llvm/test/CodeGen/AArch64/sme2-intrinsics-zt0.ll

diff --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index b5655afdf419ecf..fb3f54ecff95080 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -298,3 +298,11 @@ multiclass ZAAddSub {
 
 defm SVADD : ZAAddSub<"add">;
 defm SVSUB : ZAAddSub<"sub">;
+
+//
+// Spill and fill of ZT0
+//
+let TargetGuard = "sme2" in {
+  def SVLDR_ZT : Inst<"svldr_zt", "viQ", "", MergeNone, "aarch64_sme_ldr_zt", 
[IsOverloadNone, IsStreamingCompatible, IsSharedZA, IsPreservesZA], 
[ImmCheck<0, ImmCheck0_0>]>;
+  def SVSTR_ZT : Inst<"svstr_zt", "vi%", "", MergeNone, "aarch64_sme_str_zt", 
[IsOverloadNone, IsStreamingCompatible, IsSharedZA, IsPreservesZA], 
[ImmCheck<0, ImmCheck0_0>]>;
+}
diff --git a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_ldr_str_zt.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_ldr_str_zt.c
new file mode 100644
index 000..3d70ded6b469ba1
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_ldr_str_zt.c
@@ -0,0 +1,51 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+
+// REQUIRES: aarch64-registered-target
+
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - -x c++ %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | 
opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - -x 
c++ %s | opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s 
-check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 -S 
-disable-O0-optnone -Werror -Wall -o /dev/null %s
+
+#include 
+
+#ifdef SVE_OVERLOADED_FORMS
+// A simple used,unused... macro, long enough to represent any SVE builtin.
+#define SVE_ACLE_FUNC(A1,A2_UNUSED) A1
+#else
+#define SVE_ACLE_FUNC(A1,A2) A1##A2
+#endif
+
+// LDR ZT0
+
+// CHECK-LABEL: @test_svldr_zt(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.ldr.zt(i32 0, ptr 
[[BASE:%.*]])
+// CHECK-NEXT:ret void
+//
+// CPP-CHECK-LABEL: @_Z13test_svldr_ztPKv(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:tail call void @llvm.aarch64.sme.ldr.zt(i32 0, ptr 
[[BASE:%.*]])
+// CPP-CHECK-NEXT:ret void
+//
+void test_svldr_zt(const void *base) __arm_streaming_compatible 
__arm_shared_za __arm_preserves_za {
+  svldr_zt(0, base);
+} ;
+
+
+// STR ZT0
+
+// CHECK-LABEL: @test_svstr_zt(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.str.zt(i32 0, ptr 
[[BASE:%.*]])
+// CHECK-NEXT:ret void
+//
+// CPP-CHECK-LABEL: @_Z13test_svstr_ztPv(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:tail call void @llvm.aarch64.sme.str.zt(i32 0, ptr 
[[BASE:%.*]])
+// CPP-CHECK-NEXT:ret void
+//
+void test_svstr_zt(void *base) __arm_streaming_compatible __arm_shared_za 
__arm_preserves_za {
+  svstr_zt(0, base);
+}
diff --git a/llvm/include/llvm/IR/IntrinsicsAArch64.td 
b/llvm/include/llvm/IR/IntrinsicsAArch64.td
index a42e2c49cb477ba..9164604f7d78cbc 100644
--- a/llvm/include/llvm/IR/IntrinsicsAArch64.td
+++ b/llvm/include/llvm/IR/IntrinsicsAArch64.td
@@ -2679,10 +2679,10 @@ let TargetPrefix = "aarch64" in {
   def int_aarch64_sme_st1q_vert  : SME_Load_Store_Intrinsic;
 
   // Spil

[clang] [llvm] [AArch64][SME2] Add ldr_zt, str_zt builtins and intrinsics (PR #72849)

2023-11-20 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Matthew Devereau (MDevereau)


Changes

Use ZTR instead of MatrixOP to prevent expensive test check and machine 
verifier failures.

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


10 Files Affected:

- (modified) clang/include/clang/Basic/arm_sme.td (+8) 
- (added) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_ldr_str_zt.c 
(+51) 
- (modified) llvm/include/llvm/IR/IntrinsicsAArch64.td (+7-4) 
- (modified) llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp (+6-2) 
- (modified) llvm/lib/Target/AArch64/AArch64ISelLowering.cpp (+20) 
- (modified) llvm/lib/Target/AArch64/AArch64ISelLowering.h (+2) 
- (modified) llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp (+6) 
- (modified) llvm/lib/Target/AArch64/AArch64SMEInstrInfo.td (+2-2) 
- (modified) llvm/lib/Target/AArch64/SMEInstrFormats.td (+18-5) 
- (added) llvm/test/CodeGen/AArch64/sme2-intrinsics-zt0.ll (+27) 


``diff
diff --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index b5655afdf419ecf..fb3f54ecff95080 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -298,3 +298,11 @@ multiclass ZAAddSub {
 
 defm SVADD : ZAAddSub<"add">;
 defm SVSUB : ZAAddSub<"sub">;
+
+//
+// Spill and fill of ZT0
+//
+let TargetGuard = "sme2" in {
+  def SVLDR_ZT : Inst<"svldr_zt", "viQ", "", MergeNone, "aarch64_sme_ldr_zt", 
[IsOverloadNone, IsStreamingCompatible, IsSharedZA, IsPreservesZA], 
[ImmCheck<0, ImmCheck0_0>]>;
+  def SVSTR_ZT : Inst<"svstr_zt", "vi%", "", MergeNone, "aarch64_sme_str_zt", 
[IsOverloadNone, IsStreamingCompatible, IsSharedZA, IsPreservesZA], 
[ImmCheck<0, ImmCheck0_0>]>;
+}
diff --git a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_ldr_str_zt.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_ldr_str_zt.c
new file mode 100644
index 000..3d70ded6b469ba1
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_ldr_str_zt.c
@@ -0,0 +1,51 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+
+// REQUIRES: aarch64-registered-target
+
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - -x c++ %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | 
opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - -x 
c++ %s | opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s 
-check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 -S 
-disable-O0-optnone -Werror -Wall -o /dev/null %s
+
+#include 
+
+#ifdef SVE_OVERLOADED_FORMS
+// A simple used,unused... macro, long enough to represent any SVE builtin.
+#define SVE_ACLE_FUNC(A1,A2_UNUSED) A1
+#else
+#define SVE_ACLE_FUNC(A1,A2) A1##A2
+#endif
+
+// LDR ZT0
+
+// CHECK-LABEL: @test_svldr_zt(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.ldr.zt(i32 0, ptr 
[[BASE:%.*]])
+// CHECK-NEXT:ret void
+//
+// CPP-CHECK-LABEL: @_Z13test_svldr_ztPKv(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:tail call void @llvm.aarch64.sme.ldr.zt(i32 0, ptr 
[[BASE:%.*]])
+// CPP-CHECK-NEXT:ret void
+//
+void test_svldr_zt(const void *base) __arm_streaming_compatible 
__arm_shared_za __arm_preserves_za {
+  svldr_zt(0, base);
+} ;
+
+
+// STR ZT0
+
+// CHECK-LABEL: @test_svstr_zt(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.str.zt(i32 0, ptr 
[[BASE:%.*]])
+// CHECK-NEXT:ret void
+//
+// CPP-CHECK-LABEL: @_Z13test_svstr_ztPv(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:tail call void @llvm.aarch64.sme.str.zt(i32 0, ptr 
[[BASE:%.*]])
+// CPP-CHECK-NEXT:ret void
+//
+void test_svstr_zt(void *base) __arm_streaming_compatible __arm_shared_za 
__arm_preserves_za {
+  svstr_zt(0, base);
+}
diff --git a/llvm/include/llvm/IR/IntrinsicsAArch64.td 
b/llvm/include/llvm/IR/IntrinsicsAArch64.td
index a42e2c49cb477ba..9164604f7d78cbc 100644
--- a/llvm/include/llvm/IR/IntrinsicsAArch64.td
+++ b/llvm/include/llvm/IR/IntrinsicsAArch64.td
@@ -2679,10 +2679,10 @@ let TargetPrefix = "aarch64" in {
   def int_aarch64_sme_st1q_vert  : SME_Load_Store_Intrinsic;
 
   // Spill + fill
-  def int_aarch64_sme_ldr : DefaultAttrsIntrinsic<
-[], [llvm_i32_ty, llvm_ptr_ty]>;
-  def int_aarch64_sme_str : DefaultAttrsIntrinsic<
-[], [llvm_i32_ty, llvm_ptr_ty]>;
+  class SME_LDR_STR_Intrinsic
+: De

[llvm] [clang] [AArch64][SME2] Add ldr_zt, str_zt builtins and intrinsics (PR #72849)

2023-11-20 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-llvm-ir

Author: Matthew Devereau (MDevereau)


Changes

Use ZTR instead of MatrixOP to prevent expensive test check and machine 
verifier failures.

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


10 Files Affected:

- (modified) clang/include/clang/Basic/arm_sme.td (+8) 
- (added) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_ldr_str_zt.c 
(+51) 
- (modified) llvm/include/llvm/IR/IntrinsicsAArch64.td (+7-4) 
- (modified) llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp (+6-2) 
- (modified) llvm/lib/Target/AArch64/AArch64ISelLowering.cpp (+20) 
- (modified) llvm/lib/Target/AArch64/AArch64ISelLowering.h (+2) 
- (modified) llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp (+6) 
- (modified) llvm/lib/Target/AArch64/AArch64SMEInstrInfo.td (+2-2) 
- (modified) llvm/lib/Target/AArch64/SMEInstrFormats.td (+18-5) 
- (added) llvm/test/CodeGen/AArch64/sme2-intrinsics-zt0.ll (+27) 


``diff
diff --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index b5655afdf419ecf..fb3f54ecff95080 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -298,3 +298,11 @@ multiclass ZAAddSub {
 
 defm SVADD : ZAAddSub<"add">;
 defm SVSUB : ZAAddSub<"sub">;
+
+//
+// Spill and fill of ZT0
+//
+let TargetGuard = "sme2" in {
+  def SVLDR_ZT : Inst<"svldr_zt", "viQ", "", MergeNone, "aarch64_sme_ldr_zt", 
[IsOverloadNone, IsStreamingCompatible, IsSharedZA, IsPreservesZA], 
[ImmCheck<0, ImmCheck0_0>]>;
+  def SVSTR_ZT : Inst<"svstr_zt", "vi%", "", MergeNone, "aarch64_sme_str_zt", 
[IsOverloadNone, IsStreamingCompatible, IsSharedZA, IsPreservesZA], 
[ImmCheck<0, ImmCheck0_0>]>;
+}
diff --git a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_ldr_str_zt.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_ldr_str_zt.c
new file mode 100644
index 000..3d70ded6b469ba1
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_ldr_str_zt.c
@@ -0,0 +1,51 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+
+// REQUIRES: aarch64-registered-target
+
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - -x c++ %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | 
opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - -x 
c++ %s | opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s 
-check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 -S 
-disable-O0-optnone -Werror -Wall -o /dev/null %s
+
+#include 
+
+#ifdef SVE_OVERLOADED_FORMS
+// A simple used,unused... macro, long enough to represent any SVE builtin.
+#define SVE_ACLE_FUNC(A1,A2_UNUSED) A1
+#else
+#define SVE_ACLE_FUNC(A1,A2) A1##A2
+#endif
+
+// LDR ZT0
+
+// CHECK-LABEL: @test_svldr_zt(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.ldr.zt(i32 0, ptr 
[[BASE:%.*]])
+// CHECK-NEXT:ret void
+//
+// CPP-CHECK-LABEL: @_Z13test_svldr_ztPKv(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:tail call void @llvm.aarch64.sme.ldr.zt(i32 0, ptr 
[[BASE:%.*]])
+// CPP-CHECK-NEXT:ret void
+//
+void test_svldr_zt(const void *base) __arm_streaming_compatible 
__arm_shared_za __arm_preserves_za {
+  svldr_zt(0, base);
+} ;
+
+
+// STR ZT0
+
+// CHECK-LABEL: @test_svstr_zt(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.str.zt(i32 0, ptr 
[[BASE:%.*]])
+// CHECK-NEXT:ret void
+//
+// CPP-CHECK-LABEL: @_Z13test_svstr_ztPv(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:tail call void @llvm.aarch64.sme.str.zt(i32 0, ptr 
[[BASE:%.*]])
+// CPP-CHECK-NEXT:ret void
+//
+void test_svstr_zt(void *base) __arm_streaming_compatible __arm_shared_za 
__arm_preserves_za {
+  svstr_zt(0, base);
+}
diff --git a/llvm/include/llvm/IR/IntrinsicsAArch64.td 
b/llvm/include/llvm/IR/IntrinsicsAArch64.td
index a42e2c49cb477ba..9164604f7d78cbc 100644
--- a/llvm/include/llvm/IR/IntrinsicsAArch64.td
+++ b/llvm/include/llvm/IR/IntrinsicsAArch64.td
@@ -2679,10 +2679,10 @@ let TargetPrefix = "aarch64" in {
   def int_aarch64_sme_st1q_vert  : SME_Load_Store_Intrinsic;
 
   // Spill + fill
-  def int_aarch64_sme_ldr : DefaultAttrsIntrinsic<
-[], [llvm_i32_ty, llvm_ptr_ty]>;
-  def int_aarch64_sme_str : DefaultAttrsIntrinsic<
-[], [llvm_i32_ty, llvm_ptr_ty]>;
+  class SME_LDR_STR_Intrinsic
+: 

[llvm] [clang] [AArch64][SME2] Add ldr_zt, str_zt builtins and intrinsics (PR #72849)

2023-11-20 Thread Matthew Devereau via cfe-commits
https://github.com/MDevereau edited 
https://github.com/llvm/llvm-project/pull/72849
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][dataflow] Discard unneeded `ExprToLoc` and `ExprToVal` entries. (PR #72850)

2023-11-20 Thread via cfe-commits
https://github.com/martinboehme created 
https://github.com/llvm/llvm-project/pull/72850

This has two major benefits:

*  We avoid performing joins on boolean expressions and hence extending the flow
   condition in cases where this is not needed. Simpler flow conditions should
   reduce the amount of work we do in the SAT solver.

*  Debugging becomes easier when flow conditions are simpler and ExprToVal
   doesn’t contain any extraneous entries.

In tests on an internal codebase, we see a reduction in SAT solver timeouts of
over 40% and a reduction in "reached maximum iterations" errors of over 60%.

Benchmark results on Crubit's `pointer_nullability_analysis_benchmark show a
slight runtime increase for simple benchmarks, offset by runtime reductions
(some of them substantial) for more complex benchmarks:

```
name  old cpu/op   new cpu/op   delta
BM_PointerAnalysisCopyPointer 29.5µs ± 2%  32.0µs ± 3%   +8.42%  (p=0.000 
n=46+47)
BM_PointerAnalysisIntLoop  100µs ± 3%   109µs ± 3%   +9.40%  (p=0.000 
n=54+60)
BM_PointerAnalysisPointerLoop  376µs ± 4%   253µs ± 3%  -32.51%  (p=0.000 
n=48+55)
BM_PointerAnalysisBranch   116µs ± 3%   126µs ± 3%   +9.23%  (p=0.000 
n=60+59)
BM_PointerAnalysisLoopAndBranch776µs ± 3%   425µs ± 4%  -45.20%  (p=0.000 
n=59+59)
BM_PointerAnalysisTwoLoops 184µs ± 2%   200µs ± 3%   +8.48%  (p=0.000 
n=59+58)
BM_PointerAnalysisJoinFilePath17.3ms ± 3%   9.4ms ± 2%  -45.48%  (p=0.000 
n=60+60)
BM_PointerAnalysisCallInLoop  14.7ms ± 2%  11.0ms ± 3%  -25.02%  (p=0.000 
n=57+56)
```

Running the pointer nullability check on several real-world files shows no
significant change in runtime.


>From d5c011c6f922e98da44b1ffa573c3630e3532b3d Mon Sep 17 00:00:00 2001
From: Martin Braenne 
Date: Mon, 20 Nov 2023 10:56:28 +
Subject: [PATCH] [clang][dataflow] Discard unneeded `ExprToLoc` and
 `ExprToVal` entries.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This has two major benefits:

*  We avoid performing joins on boolean expressions and hence extending the flow
   condition in cases where this is not needed. Simpler flow conditions should
   reduce the amount of work we do in the SAT solver.

*  Debugging becomes easier when flow conditions are simpler and ExprToVal
   doesn’t contain any extraneous entries.

In tests on an internal codebase, we see a reduction in SAT solver timeouts of
over 40% and a reduction in "reached maximum iterations" errors of over 60%.

Benchmark results on Crubit's `pointer_nullability_analysis_benchmark show a
slight runtime increase for simple benchmarks, offset by runtime reductions
(some of them substantial) for more complex benchmarks:

```
name  old cpu/op   new cpu/op   delta
BM_PointerAnalysisCopyPointer 29.5µs ± 2%  32.0µs ± 3%   +8.42%  (p=0.000 
n=46+47)
BM_PointerAnalysisIntLoop  100µs ± 3%   109µs ± 3%   +9.40%  (p=0.000 
n=54+60)
BM_PointerAnalysisPointerLoop  376µs ± 4%   253µs ± 3%  -32.51%  (p=0.000 
n=48+55)
BM_PointerAnalysisBranch   116µs ± 3%   126µs ± 3%   +9.23%  (p=0.000 
n=60+59)
BM_PointerAnalysisLoopAndBranch776µs ± 3%   425µs ± 4%  -45.20%  (p=0.000 
n=59+59)
BM_PointerAnalysisTwoLoops 184µs ± 2%   200µs ± 3%   +8.48%  (p=0.000 
n=59+58)
BM_PointerAnalysisJoinFilePath17.3ms ± 3%   9.4ms ± 2%  -45.48%  (p=0.000 
n=60+60)
BM_PointerAnalysisCallInLoop  14.7ms ± 2%  11.0ms ± 3%  -25.02%  (p=0.000 
n=57+56)
```

Running the pointer nullability check on several real-world files shows no
significant change in runtime.
---
 .../FlowSensitive/ControlFlowContext.h|  22 ++-
 .../FlowSensitive/DataflowEnvironment.h   |   8 +-
 .../FlowSensitive/ControlFlowContext.cpp  |  35 ++--
 .../FlowSensitive/DataflowEnvironment.cpp |  22 ++-
 .../TypeErasedDataflowAnalysis.cpp|  18 +-
 .../FlowSensitive/DataflowEnvironmentTest.cpp |  36 
 .../TypeErasedDataflowAnalysisTest.cpp| 158 +++---
 7 files changed, 250 insertions(+), 49 deletions(-)

diff --git a/clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h 
b/clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
index 768387a121b920a..3a5c5235838f630 100644
--- a/clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
+++ b/clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
@@ -52,23 +52,39 @@ class ControlFlowContext {
 return StmtToBlock;
   }
 
+  /// Returns the expressions consumed by `Block`. These are all children of
+  /// statements in `Block` as well as children of a possible terminator.
+  const llvm::DenseSet *
+  getExprConsumedByBlock(const CFGBlock *Block) const {
+auto It = ExprConsumedByBlock.find(Block);
+if (It == ExprConsumedByBlock.end())
+  return nullptr;
+return &It->second;
+  }
+
   /// Returns whether `B` is reachable from the entry block.
   bool isBlockReachable(const CFGBlo

[clang] [clang][dataflow] Discard unneeded `ExprToLoc` and `ExprToVal` entries. (PR #72850)

2023-11-20 Thread via cfe-commits
llvmbot wrote:



@llvm/pr-subscribers-clang-analysis

@llvm/pr-subscribers-clang

Author: None (martinboehme)


Changes

This has two major benefits:

*  We avoid performing joins on boolean expressions and hence extending the flow
   condition in cases where this is not needed. Simpler flow conditions should
   reduce the amount of work we do in the SAT solver.

*  Debugging becomes easier when flow conditions are simpler and ExprToVal
   doesn’t contain any extraneous entries.

In tests on an internal codebase, we see a reduction in SAT solver timeouts of
over 40% and a reduction in "reached maximum iterations" errors of over 60%.

Benchmark results on Crubit's `pointer_nullability_analysis_benchmark show a
slight runtime increase for simple benchmarks, offset by runtime reductions
(some of them substantial) for more complex benchmarks:

```
name  old cpu/op   new cpu/op   delta
BM_PointerAnalysisCopyPointer 29.5µs ± 2%  32.0µs ± 3%   +8.42%  (p=0.000 
n=46+47)
BM_PointerAnalysisIntLoop  100µs ± 3%   109µs ± 3%   +9.40%  (p=0.000 
n=54+60)
BM_PointerAnalysisPointerLoop  376µs ± 4%   253µs ± 3%  -32.51%  (p=0.000 
n=48+55)
BM_PointerAnalysisBranch   116µs ± 3%   126µs ± 3%   +9.23%  (p=0.000 
n=60+59)
BM_PointerAnalysisLoopAndBranch776µs ± 3%   425µs ± 4%  -45.20%  (p=0.000 
n=59+59)
BM_PointerAnalysisTwoLoops 184µs ± 2%   200µs ± 3%   +8.48%  (p=0.000 
n=59+58)
BM_PointerAnalysisJoinFilePath17.3ms ± 3%   9.4ms ± 2%  -45.48%  (p=0.000 
n=60+60)
BM_PointerAnalysisCallInLoop  14.7ms ± 2%  11.0ms ± 3%  -25.02%  (p=0.000 
n=57+56)
```

Running the pointer nullability check on several real-world files shows no
significant change in runtime.


---

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


7 Files Affected:

- (modified) clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h 
(+19-3) 
- (modified) clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h 
(+6-2) 
- (modified) clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp (+24-11) 
- (modified) clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp (+16-6) 
- (modified) clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp 
(+14-4) 
- (modified) clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp 
(+36) 
- (modified) 
clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp 
(+135-23) 


``diff
diff --git a/clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h 
b/clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
index 768387a121b920a..3a5c5235838f630 100644
--- a/clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
+++ b/clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
@@ -52,23 +52,39 @@ class ControlFlowContext {
 return StmtToBlock;
   }
 
+  /// Returns the expressions consumed by `Block`. These are all children of
+  /// statements in `Block` as well as children of a possible terminator.
+  const llvm::DenseSet *
+  getExprConsumedByBlock(const CFGBlock *Block) const {
+auto It = ExprConsumedByBlock.find(Block);
+if (It == ExprConsumedByBlock.end())
+  return nullptr;
+return &It->second;
+  }
+
   /// Returns whether `B` is reachable from the entry block.
   bool isBlockReachable(const CFGBlock &B) const {
 return BlockReachable[B.getBlockID()];
   }
 
 private:
-  ControlFlowContext(const Decl &D, std::unique_ptr Cfg,
- llvm::DenseMap 
StmtToBlock,
- llvm::BitVector BlockReachable)
+  ControlFlowContext(
+  const Decl &D, std::unique_ptr Cfg,
+  llvm::DenseMap StmtToBlock,
+  llvm::DenseMap>
+  ExprConsumedByBlock,
+  llvm::BitVector BlockReachable)
   : ContainingDecl(D), Cfg(std::move(Cfg)),
 StmtToBlock(std::move(StmtToBlock)),
+ExprConsumedByBlock(std::move(ExprConsumedByBlock)),
 BlockReachable(std::move(BlockReachable)) {}
 
   /// The `Decl` containing the statement used to construct the CFG.
   const Decl &ContainingDecl;
   std::unique_ptr Cfg;
   llvm::DenseMap StmtToBlock;
+  const llvm::DenseMap>
+  ExprConsumedByBlock;
   llvm::BitVector BlockReachable;
 };
 
diff --git a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
index 963197b728f4273..a2f97122567fbe7 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -211,12 +211,16 @@ class Environment {
   /// Joins two environments by taking the intersection of storage locations 
and
   /// values that are stored in them. Distinct values that are assigned to the
   /// same storage locations in `EnvA` and `EnvB` are merged using `Model`.
+  /// If `ExprsToKeep` is non-null, only retains state for expressions 
contained
+  //

[clang] 661a73f - Fix typo in DiagnosticSemaKinds.td

2023-11-20 Thread via cfe-commits
Author: Utkarsh Saxena
Date: 2023-11-20T12:04:32+01:00
New Revision: 661a73ff712c54d05042eb37d536be4bade307b4

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

LOG: Fix typo in DiagnosticSemaKinds.td

s/makred/marked

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 1a6c4d80ccb6ac2..9a7dafa4a298273 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11594,7 +11594,7 @@ def err_coro_invalid_addr_of_label : Error<
   "the GNU address of label extension is not allowed in coroutines."
 >;
 def err_coroutine_return_type : Error<
-  "function returns a type %0 makred with [[clang::coro_return_type]] but is 
neither a coroutine nor a coroutine wrapper; "
+  "function returns a type %0 marked with [[clang::coro_return_type]] but is 
neither a coroutine nor a coroutine wrapper; "
   "non-coroutines should be marked with [[clang::coro_wrapper]] to allow 
returning coroutine return type"
 >;
 } // end of coroutines issue category



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


[PATCH] D151730: [RISCV] Support target attribute for function

2023-11-20 Thread Piyou Chen via Phabricator via cfe-commits
BeMg updated this revision to Diff 558134.
BeMg added a comment.

1. reuse the find result
2. replace for loop with llvm::copy_if
3. use explicit std::vector declaration instead of auto


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151730

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Basic/Targets/RISCV.h
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGen/RISCV/riscv-func-attr-target-err.c
  clang/test/CodeGen/RISCV/riscv-func-attr-target.c

Index: clang/test/CodeGen/RISCV/riscv-func-attr-target.c
===
--- /dev/null
+++ clang/test/CodeGen/RISCV/riscv-func-attr-target.c
@@ -0,0 +1,46 @@
+// REQUIRES: riscv-registered-target
+// RUN: %clang_cc1 -triple riscv64 -target-feature +zifencei -target-feature +m \
+// RUN:  -target-feature +a -target-feature +save-restore \
+// RUN:  -emit-llvm %s -o - | FileCheck %s
+
+// CHECK-LABEL: define dso_local void @testDefault
+// CHECK-SAME: () #0 {
+void testDefault() {}
+// CHECK-LABEL: define dso_local void @testMultiAttrStr
+// CHECK-SAME: () #1 {
+__attribute__((target("cpu=rocket-rv64;tune=generic-rv64;arch=+v"))) void
+testMultiAttrStr() {}
+// CHECK-LABEL: define dso_local void @testSingleExtension
+// CHECK-SAME: () #2 {
+__attribute__((target("arch=+zbb"))) void testSingleExtension() {}
+// CHECK-LABEL: define dso_local void @testMultiExtension
+// CHECK-SAME: () #3 {
+__attribute__((target("arch=+zbb,+v,+zicond"))) void testMultiExtension() {}
+// CHECK-LABEL: define dso_local void @testFullArch
+// CHECK-SAME: () #4 {
+__attribute__((target("arch=rv64gc_zbb"))) void testFullArch() {}
+// CHECK-LABEL: define dso_local void @testFullArchButSmallThanCmdArch
+// CHECK-SAME: () #5 {
+__attribute__((target("arch=rv64im"))) void testFullArchButSmallThanCmdArch() {}
+// CHECK-LABEL: define dso_local void @testAttrArchAndAttrCpu
+// CHECK-SAME: () #6 {
+__attribute__((target("cpu=sifive-u54;arch=+zbb"))) void
+testAttrArchAndAttrCpu() {}
+// CHECK-LABEL: define dso_local void @testAttrFullArchAndAttrCpu
+// CHECK-SAME: () #7 {
+__attribute__((target("cpu=sifive-u54;arch=rv64im"))) void
+testAttrFullArchAndAttrCpu() {}
+// CHECK-LABEL: define dso_local void @testAttrCpuOnly
+// CHECK-SAME: () #8 {
+__attribute__((target("cpu=sifive-u54"))) void testAttrCpuOnly() {}
+
+//.
+// CHECK: attributes #0 = { {{.*}}"target-features"="+64bit,+a,+m,+save-restore,+zifencei" }
+// CHECK: attributes #1 = { {{.*}}"target-cpu"="rocket-rv64" "target-features"="+64bit,+a,+d,+f,+m,+save-restore,+v,+zicsr,+zifencei,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b" "tune-cpu"="generic-rv64" }
+// CHECK: attributes #2 = { {{.*}}"target-features"="+64bit,+a,+m,+save-restore,+zbb,+zifencei" }
+// CHECK: attributes #3 = { {{.*}}"target-features"="+64bit,+a,+d,+experimental-zicond,+f,+m,+save-restore,+v,+zbb,+zicsr,+zifencei,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b" }
+// CHECK: attributes #4 = { {{.*}}"target-features"="+64bit,+a,+c,+d,+f,+m,+save-restore,+zbb,+zicsr,+zifencei" }
+// CHECK: attributes #5 = { {{.*}}"target-features"="+64bit,+m,+save-restore" }
+// CHECK: attributes #6 = { {{.*}}"target-cpu"="sifive-u54" "target-features"="+64bit,+a,+m,+save-restore,+zbb,+zifencei" }
+// CHECK: attributes #7 = { {{.*}}"target-cpu"="sifive-u54" "target-features"="+64bit,+m,+save-restore" }
+// CHECK: attributes #8 = { {{.*}}"target-cpu"="sifive-u54" "target-features"="+64bit,+a,+c,+d,+f,+m,+save-restore,+zicsr,+zifencei" }
Index: clang/test/CodeGen/RISCV/riscv-func-attr-target-err.c
===
--- /dev/null
+++ clang/test/CodeGen/RISCV/riscv-func-attr-target-err.c
@@ -0,0 +1,10 @@
+// REQUIRES: riscv-registered-target
+// RUN: not %clang_cc1 -triple riscv64 -target-feature +zifencei -target-feature +m -target-feature +a \
+// RUN:  -emit-llvm %s 2>&1 | FileCheck %s
+
+// CHECK: error: duplicate 'arch=' in the 'target' attribute string;
+__attribute__((target("arch=rv64gc;arch=rv64gc_zbb"))) void testMultiArchSelectLast() {}
+// CHECK: error: duplicate 'cpu=' in the 'target' attribute string;
+__attribute__((target("cpu=sifive-u74;cpu=sifive-u54"))) void testMultiCpuSelectLast() {}
+// CHECK: error: duplicate 'tune=' in the 'target' attribute string;
+__attribute__((target("tune=sifive-u74;tune=sifive-u54"))) void testMultiTuneSelectLast() {}
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -3450,6 +3450,11 @@
 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
<< Unknown << Tune << ParsedAttrs.Tune << Target;
 
+  if (Context.getTargetInfo().getTriple().isRISCV() &&
+  ParsedAttrs.Duplicate != "")
+return Diag(LiteralLoc, 

[flang] [llvm] [clang] [flang][OpenMP] Add semantic check for declare target (PR #72770)

2023-11-20 Thread Sergio Afonso via cfe-commits

@@ -1851,6 +1853,18 @@ bool ClauseProcessor::processTo(
   });
 }
 
+bool ClauseProcessor::processEnter(
+llvm::SmallVectorImpl &result) const {
+  return findRepeatableClause(
+  [&](const ClauseTy::Enter *enterClause,
+  const Fortran::parser::CharBlock &) {
+// Case: declare target to(func, var1, var2)...

skatrak wrote:

Nit: Update comment

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


[clang] [llvm] [flang] [flang][OpenMP] Add semantic check for declare target (PR #72770)

2023-11-20 Thread Sergio Afonso via cfe-commits
https://github.com/skatrak edited 
https://github.com/llvm/llvm-project/pull/72770
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [flang] [flang][OpenMP] Add semantic check for declare target (PR #72770)

2023-11-20 Thread Sergio Afonso via cfe-commits

@@ -590,6 +590,8 @@ class ClauseProcessor {
   bool processSectionsReduction(mlir::Location currentLocation) const;
   bool processTo(llvm::SmallVectorImpl &result) 
const;
   bool
+  processEnter(llvm::SmallVectorImpl &result) const;

skatrak wrote:

Nit: It would be good to keep the alphabetic order of declarations here and 
definitions below, so I'd add this between `processDeviceType` and 
`processFinal`.

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


[clang] [flang] [llvm] [flang][OpenMP] Add semantic check for declare target (PR #72770)

2023-11-20 Thread Sergio Afonso via cfe-commits
https://github.com/skatrak commented:

Thank you Shraiysh, I just have a couple of nits.

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


[clang] [llvm] [SVE2.1][Clang][LLVM]Add 128bits builtin in Clang and LLVM intrinisc (PR #71930)

2023-11-20 Thread via cfe-commits
https://github.com/CarolineConcatto edited 
https://github.com/llvm/llvm-project/pull/71930
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [coroutines] Introduce [[clang::coro_lifetimebound]] (PR #72516)

2023-11-20 Thread Utkarsh Saxena via cfe-commits
https://github.com/usx95 closed https://github.com/llvm/llvm-project/pull/72516
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [coroutines] Introduce [[clang::coro_lifetimebound]] (PR #72851)

2023-11-20 Thread Utkarsh Saxena via cfe-commits
https://github.com/usx95 created https://github.com/llvm/llvm-project/pull/72851

None

>From 28e9fda4b78e1e60287048891cc92bafdef3ac4c Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Mon, 20 Nov 2023 12:17:30 +0100
Subject: [PATCH] Introduce [[clang::coro_lifetimebound]]

---
 clang/include/clang/Basic/Attr.td |  8 ++
 clang/include/clang/Basic/AttrDocs.td |  8 +-
 clang/lib/Sema/SemaInit.cpp   |  7 +-
 ...a-attribute-supported-attributes-list.test |  3 +-
 clang/test/SemaCXX/coro-lifetimebound.cpp | 93 +++
 5 files changed, 116 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/SemaCXX/coro-lifetimebound.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index f7a2b83b15ef5bc..dfe6f8999f832a3 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1110,6 +1110,14 @@ def CoroWrapper : InheritableAttr {
   let SimpleHandler = 1;
 }
 
+def CoroLifetimeBound : InheritableAttr {
+  let Spellings = [Clang<"coro_lifetimebound">];
+  let Subjects = SubjectList<[CXXRecord]>;
+  let LangOpts = [CPlusPlus];
+  let Documentation = [CoroLifetimeBoundDoc];
+  let SimpleHandler = 1;
+}
+
 // OSObject-based attributes.
 def OSConsumed : InheritableParamAttr {
   let Spellings = [Clang<"os_consumed">];
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 438d846c39eaa57..39efaee20694a43 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7483,7 +7483,6 @@ generation of the other destruction cases, optimizing the 
above `foo.destroy` to
   }];
 }
 
-
 def CoroReturnTypeAndWrapperDoc : Documentation {
   let Category = DocCatDecl;
   let Content = [{
@@ -7540,3 +7539,10 @@ Note: ``a_promise_type::get_return_object`` is exempted 
from this analysis as it
 implementation detail of any coroutine library.
 }];
 }
+
+def CoroLifetimeBoundDoc : Documentation {
+  let Category = DocCatDecl;
+  let Content = [{
+asdam
+}];
+}
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 80b51b09bf5445f..631b6a266412ccb 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -7580,10 +7580,15 @@ static void 
visitLifetimeBoundArguments(IndirectLocalPath &Path, Expr *Call,
   if (ObjectArg && implicitObjectParamIsLifetimeBound(Callee))
 VisitLifetimeBoundArg(Callee, ObjectArg);
 
+  bool checkCoroCall = false;
+  if (const auto *RD = Callee->getReturnType()->getAsRecordDecl()) {
+checkCoroCall |= RD->hasAttr() &&
+ RD->hasAttr();
+  }
   for (unsigned I = 0,
 N = std::min(Callee->getNumParams(), Args.size());
I != N; ++I) {
-if (Callee->getParamDecl(I)->hasAttr())
+if (checkCoroCall || Callee->getParamDecl(I)->hasAttr())
   VisitLifetimeBoundArg(Callee->getParamDecl(I), Args[I]);
   }
 }
diff --git a/clang/test/Misc/pragma-attribute-supported-attributes-list.test 
b/clang/test/Misc/pragma-attribute-supported-attributes-list.test
index a57bc011c059483..dd91f4f88ad685b 100644
--- a/clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ b/clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -56,9 +56,10 @@
 // CHECK-NEXT: ConsumableAutoCast (SubjectMatchRule_record)
 // CHECK-NEXT: ConsumableSetOnRead (SubjectMatchRule_record)
 // CHECK-NEXT: Convergent (SubjectMatchRule_function)
+// CHECK-NEXT: CoroLifetimeBound (SubjectMatchRule_record)
 // CHECK-NEXT: CoroOnlyDestroyWhenComplete (SubjectMatchRule_record)
 // CHECK-NEXT: CoroReturnType (SubjectMatchRule_record)
-// CHECK-NEXT: CoroWrapper
+// CHECK-NEXT: CoroWrapper (SubjectMatchRule_function)
 // CHECK-NEXT: CountedBy (SubjectMatchRule_field)
 // CHECK-NEXT: DLLExport (SubjectMatchRule_function, 
SubjectMatchRule_variable, SubjectMatchRule_record, 
SubjectMatchRule_objc_interface)
 // CHECK-NEXT: DLLImport (SubjectMatchRule_function, 
SubjectMatchRule_variable, SubjectMatchRule_record, 
SubjectMatchRule_objc_interface)
diff --git a/clang/test/SemaCXX/coro-lifetimebound.cpp 
b/clang/test/SemaCXX/coro-lifetimebound.cpp
new file mode 100644
index 000..3f719866eae0ee4
--- /dev/null
+++ b/clang/test/SemaCXX/coro-lifetimebound.cpp
@@ -0,0 +1,93 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++20 -fsyntax-only 
-verify -Wall -Wextra -Wno-error=unreachable-code -Wno-unused
+
+#include "Inputs/std-coroutine.h"
+
+using std::suspend_always;
+using std::suspend_never;
+
+template  struct [[clang::coro_lifetimebound, 
clang::coro_return_type]] Gen {
+  struct promise_type {
+Gen get_return_object() {
+  return {};
+}
+suspend_always initial_suspend();
+suspend_always final_suspend() noexcept;
+void unhandled_exception();
+void return_value(const T &t);
+
+template 
+auto await_transform(const Gen &) {
+  struct awaitable {
+bool await_ready() noexcept { return fal

[clang] [llvm] [AArch64][SME2] Add ldr_zt, str_zt builtins and intrinsics (PR #72849)

2023-11-20 Thread Matthew Devereau via cfe-commits
https://github.com/MDevereau updated 
https://github.com/llvm/llvm-project/pull/72849

>From 3b1d34afb1ae365f48716ae5eb9202a474adf234 Mon Sep 17 00:00:00 2001
From: Matt Devereau 
Date: Mon, 20 Nov 2023 10:49:27 +
Subject: [PATCH] [AArch64][SME2] Add ldr_zt, str_zt builtins and intrinsics

---
 clang/include/clang/Basic/arm_sme.td  |  8 +++
 .../acle_sme2_ldr_str_zt.c| 51 +++
 .../Target/AArch64/AArch64ISelDAGToDAG.cpp|  8 ++-
 .../Target/AArch64/AArch64ISelLowering.cpp| 20 
 llvm/lib/Target/AArch64/AArch64ISelLowering.h |  2 +
 .../Target/AArch64/AArch64RegisterInfo.cpp|  6 +++
 .../lib/Target/AArch64/AArch64SMEInstrInfo.td |  4 +-
 llvm/lib/Target/AArch64/SMEInstrFormats.td| 23 +++--
 .../CodeGen/AArch64/sme2-intrinsics-zt0.ll| 27 ++
 9 files changed, 140 insertions(+), 9 deletions(-)
 create mode 100644 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_ldr_str_zt.c
 create mode 100644 llvm/test/CodeGen/AArch64/sme2-intrinsics-zt0.ll

diff --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index b5655afdf419ecf2..fb3f54ecff95080d 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -298,3 +298,11 @@ multiclass ZAAddSub {
 
 defm SVADD : ZAAddSub<"add">;
 defm SVSUB : ZAAddSub<"sub">;
+
+//
+// Spill and fill of ZT0
+//
+let TargetGuard = "sme2" in {
+  def SVLDR_ZT : Inst<"svldr_zt", "viQ", "", MergeNone, "aarch64_sme_ldr_zt", 
[IsOverloadNone, IsStreamingCompatible, IsSharedZA, IsPreservesZA], 
[ImmCheck<0, ImmCheck0_0>]>;
+  def SVSTR_ZT : Inst<"svstr_zt", "vi%", "", MergeNone, "aarch64_sme_str_zt", 
[IsOverloadNone, IsStreamingCompatible, IsSharedZA, IsPreservesZA], 
[ImmCheck<0, ImmCheck0_0>]>;
+}
diff --git a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_ldr_str_zt.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_ldr_str_zt.c
new file mode 100644
index ..3d70ded6b469ba15
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_ldr_str_zt.c
@@ -0,0 +1,51 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+
+// REQUIRES: aarch64-registered-target
+
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - -x c++ %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | 
opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - -x 
c++ %s | opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s 
-check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 -S 
-disable-O0-optnone -Werror -Wall -o /dev/null %s
+
+#include 
+
+#ifdef SVE_OVERLOADED_FORMS
+// A simple used,unused... macro, long enough to represent any SVE builtin.
+#define SVE_ACLE_FUNC(A1,A2_UNUSED) A1
+#else
+#define SVE_ACLE_FUNC(A1,A2) A1##A2
+#endif
+
+// LDR ZT0
+
+// CHECK-LABEL: @test_svldr_zt(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.ldr.zt(i32 0, ptr 
[[BASE:%.*]])
+// CHECK-NEXT:ret void
+//
+// CPP-CHECK-LABEL: @_Z13test_svldr_ztPKv(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:tail call void @llvm.aarch64.sme.ldr.zt(i32 0, ptr 
[[BASE:%.*]])
+// CPP-CHECK-NEXT:ret void
+//
+void test_svldr_zt(const void *base) __arm_streaming_compatible 
__arm_shared_za __arm_preserves_za {
+  svldr_zt(0, base);
+} ;
+
+
+// STR ZT0
+
+// CHECK-LABEL: @test_svstr_zt(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.str.zt(i32 0, ptr 
[[BASE:%.*]])
+// CHECK-NEXT:ret void
+//
+// CPP-CHECK-LABEL: @_Z13test_svstr_ztPv(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:tail call void @llvm.aarch64.sme.str.zt(i32 0, ptr 
[[BASE:%.*]])
+// CPP-CHECK-NEXT:ret void
+//
+void test_svstr_zt(void *base) __arm_streaming_compatible __arm_shared_za 
__arm_preserves_za {
+  svstr_zt(0, base);
+}
diff --git a/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp 
b/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
index 7617dccdeee397f7..abfe14e52509d58a 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
@@ -326,15 +326,19 @@ class AArch64DAGToDAGISel : public SelectionDAGISel {
 return false;
   }
 
-  template  bool ImmToTile(SDValue N, SDValue &Imm) {
+  template 
+  bool ImmToTile(SDValue N, SDValue &Imm) {
 if (auto *CI = dyn_cast(N)) {

[clang] [flang] [Flang][Clang] Add support for frame pointers in Flang Driver (PR #72146)

2023-11-20 Thread Radu Salavat via cfe-commits
https://github.com/Radu2k updated 
https://github.com/llvm/llvm-project/pull/72146

>From 0b0f02eab4dc02adf79461bc865be6f7580938cf Mon Sep 17 00:00:00 2001
From: Radu2k 
Date: Mon, 13 Nov 2023 17:49:06 +
Subject: [PATCH 1/5] [Flang][Clang] Add support for frame pointers in Flang

---
 clang/include/clang/Driver/Options.td |  14 +-
 clang/lib/Driver/ToolChains/Clang.cpp | 133 -
 clang/lib/Driver/ToolChains/CommonArgs.cpp| 141 ++
 clang/lib/Driver/ToolChains/CommonArgs.h  |   4 +
 clang/lib/Driver/ToolChains/Flang.cpp |  19 +++
 .../include/flang/Frontend/CodeGenOptions.def |   1 +
 flang/include/flang/Frontend/CodeGenOptions.h |  23 +++
 flang/include/flang/Tools/CrossToolHelpers.h  |   2 +
 flang/lib/Frontend/CompilerInvocation.cpp |  13 ++
 flang/lib/Frontend/FrontendActions.cpp|   5 +
 flang/test/Driver/driver-help-hidden.f90  |   1 +
 flang/test/Driver/driver-help.f90 |   2 +
 flang/test/Driver/frontend-forwarding.f90 |   2 +
 13 files changed, 222 insertions(+), 138 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d1b67a448b2a59b..bf99786d017b318 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3147,7 +3147,8 @@ def fno_ms_compatibility : Flag<["-"], 
"fno-ms-compatibility">, Group,
 def fno_objc_legacy_dispatch : Flag<["-"], "fno-objc-legacy-dispatch">, 
Group;
 def fno_objc_weak : Flag<["-"], "fno-objc-weak">, Group,
   Visibility<[ClangOption, CC1Option]>;
-def fno_omit_frame_pointer : Flag<["-"], "fno-omit-frame-pointer">, 
Group;
+def fno_omit_frame_pointer : Flag<["-"], "fno-omit-frame-pointer">, 
Group,
+  Visibility<[ClangOption, FlangOption]>;
 defm operator_names : BoolFOption<"operator-names",
   LangOpts<"CXXOperatorNames">, Default,
   NegFlag>;
 
 def fomit_frame_pointer : Flag<["-"], "fomit-frame-pointer">, Group,
+  Visibility<[ClangOption, FlangOption]>,
   HelpText<"Omit the frame pointer from functions that don't need it. "
   "Some stack unwinding cases, such as profilers and sanitizers, may prefer 
specifying -fno-omit-frame-pointer. "
   "On many targets, -O1 and higher omit the frame pointer by default. "
@@ -6752,10 +6754,7 @@ def new_struct_path_tbaa : Flag<["-"], 
"new-struct-path-tbaa">,
 def mdebug_pass : Separate<["-"], "mdebug-pass">,
   HelpText<"Enable additional debug output">,
   MarshallingInfoString>;
-def mframe_pointer_EQ : Joined<["-"], "mframe-pointer=">,
-  HelpText<"Specify which frame pointers to retain.">, 
Values<"all,non-leaf,none">,
-  NormalizedValuesScope<"CodeGenOptions::FramePointerKind">, 
NormalizedValues<["All", "NonLeaf", "None"]>,
-  MarshallingInfoEnum, "None">;
+
 def mabi_EQ_ieeelongdouble : Flag<["-"], "mabi=ieeelongdouble">,
   HelpText<"Use IEEE 754 quadruple-precision for long double">,
   MarshallingInfoFlag>;
@@ -7368,6 +7367,11 @@ def pic_level : Separate<["-"], "pic-level">,
 def pic_is_pie : Flag<["-"], "pic-is-pie">,
   HelpText<"File is for a position independent executable">,
   MarshallingInfoFlag>;
+  
+def mframe_pointer_EQ : Joined<["-"], "mframe-pointer=">,
+  HelpText<"Specify which frame pointers to retain.">, 
Values<"all,non-leaf,none">,
+  NormalizedValuesScope<"CodeGenOptions::FramePointerKind">, 
NormalizedValues<["All", "NonLeaf", "None"]>,
+  MarshallingInfoEnum, "None">;
 
 } // let Visibility = [CC1Option, FC1Option]
 
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 3b98c7ae6e6ec66..3273bd1d2c0c6fa 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -409,139 +409,6 @@ static bool ShouldEnableAutolink(const ArgList &Args, 
const ToolChain &TC,
   Default);
 }
 
-static bool mustUseNonLeafFramePointerForTarget(const llvm::Triple &Triple) {
-  switch (Triple.getArch()){
-  default:
-return false;
-  case llvm::Triple::arm:
-  case llvm::Triple::thumb:
-// ARM Darwin targets require a frame pointer to be always present to aid
-// offline debugging via backtraces.
-return Triple.isOSDarwin();
-  }
-}
-
-static bool useFramePointerForTargetByDefault(const ArgList &Args,
-  const llvm::Triple &Triple) {
-  if (Args.hasArg(options::OPT_pg) && !Args.hasArg(options::OPT_mfentry))
-return true;
-
-  if (Triple.isAndroid()) {
-switch (Triple.getArch()) {
-case llvm::Triple::aarch64:
-case llvm::Triple::arm:
-case llvm::Triple::armeb:
-case llvm::Triple::thumb:
-case llvm::Triple::thumbeb:
-case llvm::Triple::riscv64:
-  return true;
-default:
-  break;
-}
-  }
-
-  switch (Triple.getArch()) {
-  case llvm::Triple::xcore:
-  case llvm::Triple::wasm32:
-  case llvm::Triple::wasm64:
-  case llvm::Triple::msp430:
-// XCore never wants frame pointers, regardless of OS.
-// WebAssembly never wants

[clang] [llvm] [AArch64][SME2] Add ldr_zt, str_zt builtins and intrinsics (PR #72849)

2023-11-20 Thread Matthew Devereau via cfe-commits
https://github.com/MDevereau edited 
https://github.com/llvm/llvm-project/pull/72849
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-apply-replacements] Apply format only if --format is specified (PR #70801)

2023-11-20 Thread via cfe-commits
https://github.com/kuganv converted_to_draft 
https://github.com/llvm/llvm-project/pull/70801
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-apply-replacements] Apply format only if --format is specified (PR #70801)

2023-11-20 Thread via cfe-commits
https://github.com/kuganv ready_for_review 
https://github.com/llvm/llvm-project/pull/70801
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-apply-replacements] Apply format only if --format is specified (PR #70801)

2023-11-20 Thread via cfe-commits
kuganv wrote:

@revane, @pepsiman: Could you  please review this. Thanks.  

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


[clang] 4a8b43b - [clang][Interp][NFC] Factor array element init into its own function

2023-11-20 Thread Timm Bäder via cfe-commits
Author: Timm Bäder
Date: 2023-11-20T13:00:57+01:00
New Revision: 4a8b43ba3bd5427dd98a7a93d1b1ed25051c31e8

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

LOG: [clang][Interp][NFC] Factor array element init into its own function

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeExprGen.h

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index a1f45f5e3658d26..5dc1f9dfb10ff32 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -614,6 +614,29 @@ bool 
ByteCodeExprGen::visitInitList(ArrayRef Inits,
   return true;
 }
 
+/// Pointer to the array(not the element!) must be on the stack when calling
+/// this.
+template 
+bool ByteCodeExprGen::visitArrayElemInit(unsigned ElemIndex,
+  const Expr *Init) {
+  if (std::optional T = classify(Init->getType())) {
+// Visit the primitive element like normal.
+if (!this->visit(Init))
+  return false;
+return this->emitInitElem(*T, ElemIndex, Init);
+  }
+
+  // Advance the pointer currently on the stack to the given
+  // dimension.
+  if (!this->emitConstUint32(ElemIndex, Init))
+return false;
+  if (!this->emitArrayElemPtrUint32(Init))
+return false;
+  if (!this->visitInitializer(Init))
+return false;
+  return this->emitPopPtr(Init);
+}
+
 template 
 bool ByteCodeExprGen::VisitInitListExpr(const InitListExpr *E) {
   // Handle discarding first.
@@ -642,25 +665,8 @@ bool ByteCodeExprGen::VisitInitListExpr(const 
InitListExpr *E) {
 // FIXME: Array fillers.
 unsigned ElementIndex = 0;
 for (const Expr *Init : E->inits()) {
-  if (std::optional T = classify(Init->getType())) {
-// Visit the primitive element like normal.
-if (!this->visit(Init))
-  return false;
-if (!this->emitInitElem(*T, ElementIndex, Init))
-  return false;
-  } else {
-// Advance the pointer currently on the stack to the given
-// dimension.
-if (!this->emitConstUint32(ElementIndex, Init))
-  return false;
-if (!this->emitArrayElemPtrUint32(Init))
-  return false;
-if (!this->visitInitializer(Init))
-  return false;
-if (!this->emitPopPtr(Init))
-  return false;
-  }
-
+  if (!this->visitArrayElemInit(ElementIndex, Init))
+return false;
   ++ElementIndex;
 }
 return true;
@@ -831,7 +837,6 @@ bool ByteCodeExprGen::VisitArrayInitLoopExpr(
   const Expr *SubExpr = E->getSubExpr();
   const Expr *CommonExpr = E->getCommonExpr();
   size_t Size = E->getArraySize().getZExtValue();
-  std::optional ElemT = classify(SubExpr->getType());
 
   // If the common expression is an opaque expression, we visit it
   // here once so we have its value cached.
@@ -848,22 +853,8 @@ bool ByteCodeExprGen::VisitArrayInitLoopExpr(
 ArrayIndexScope IndexScope(this, I);
 BlockScope BS(this);
 
-if (ElemT) {
-  if (!this->visit(SubExpr))
-return false;
-  if (!this->emitInitElem(*ElemT, I, E))
-return false;
-} else {
-  // Get to our array element and recurse into visitInitializer()
-  if (!this->emitConstUint64(I, SubExpr))
-return false;
-  if (!this->emitArrayElemPtrUint64(SubExpr))
-return false;
-  if (!visitInitializer(SubExpr))
-return false;
-  if (!this->emitPopPtr(E))
-return false;
-}
+if (!this->visitArrayElemInit(I, SubExpr))
+  return false;
   }
   return true;
 }

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 602cee45f381df5..bc1d5d11a115135 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -209,6 +209,7 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
   }
 
   bool visitInitList(ArrayRef Inits, const Expr *E);
+  bool visitArrayElemInit(unsigned ElemIndex, const Expr *Init);
 
   /// Creates a local primitive value.
   unsigned allocateLocalPrimitive(DeclTy &&Decl, PrimType Ty, bool IsConst,



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


[clang] 9bdbb82 - [clang][Interp][NFC] Use isArrayRoot() when comparing pointers

2023-11-20 Thread Timm Bäder via cfe-commits
Author: Timm Bäder
Date: 2023-11-20T13:17:47+01:00
New Revision: 9bdbb8226e70fb248b40a4b5002699ee9eeeda93

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

LOG: [clang][Interp][NFC] Use isArrayRoot() when comparing pointers

The previous code was just an open-coded version of isArrayRoot().

Added: 


Modified: 
clang/lib/AST/Interp/Interp.h

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 026a95d65488da9..64b376e101c8720 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -770,9 +770,9 @@ inline bool CmpHelperEQ(InterpState &S, CodePtr 
OpPC, CompareFn Fn) {
 // element in the same array are NOT equal. They have the same Base value,
 // but a 
diff erent Offset. This is a pretty rare case, so we fix this here
 // by comparing pointers to the first elements.
-if (LHS.inArray() && LHS.isRoot())
+if (LHS.isArrayRoot())
   VL = LHS.atIndex(0).getByteOffset();
-if (RHS.inArray() && RHS.isRoot())
+if (RHS.isArrayRoot())
   VR = RHS.atIndex(0).getByteOffset();
 
 S.Stk.push(BoolT::from(Fn(Compare(VL, VR;



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


[clang] [clang][DebugInfo] Attach DW_AT_const_value to static data-member definitions if available (PR #72730)

2023-11-20 Thread Michael Buch via cfe-commits
https://github.com/Michael137 updated 
https://github.com/llvm/llvm-project/pull/72730

>From 6dcb09dcc50a9b9e92640412242927b3e226929e Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Sat, 18 Nov 2023 00:20:05 +
Subject: [PATCH 1/7] [clang][DebugInfo][NFC] Create
 evaluateConstantInitializer helper function

---
 clang/lib/CodeGen/CGDebugInfo.cpp | 18 ++
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 0b52d99ad07f164..4840581b5d03f89 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -69,6 +69,19 @@ static uint32_t getDeclAlignIfRequired(const Decl *D, const 
ASTContext &Ctx) {
   return D->hasAttr() ? D->getMaxAlignment() : 0;
 }
 
+APValue const * evaluateConstantInitializer(clang::VarDecl const * VD) {
+  assert (VD != nullptr);
+
+  VD = VD->getCanonicalDecl();
+  if (!VD)
+return nullptr;
+
+  if (!VD->hasConstantInitialization() || !VD->hasInit())
+return nullptr;
+
+  return VD->evaluateValue();
+}
+
 CGDebugInfo::CGDebugInfo(CodeGenModule &CGM)
 : CGM(CGM), DebugKind(CGM.getCodeGenOpts().getDebugInfo()),
   DebugTypeExtRefs(CGM.getCodeGenOpts().DebugTypeExtRefs),
@@ -5596,14 +5609,11 @@ void CGDebugInfo::EmitGlobalVariable(const VarDecl *VD) 
{
   if (VD->hasAttr())
 return;
 
-  if (!VD->hasInit())
-return;
-
   const auto CacheIt = DeclCache.find(VD);
   if (CacheIt != DeclCache.end())
 return;
 
-  auto const *InitVal = VD->evaluateValue();
+  auto const * InitVal = evaluateConstantInitializer(VD);
   if (!InitVal)
 return;
 

>From fcc6e19d108798fb18c1973e4d4cc3800da07f9f Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Sat, 18 Nov 2023 00:52:24 +
Subject: [PATCH 2/7] fixup! clang-format

---
 clang/lib/CodeGen/CGDebugInfo.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 4840581b5d03f89..9bba6e6b13e9318 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -69,8 +69,8 @@ static uint32_t getDeclAlignIfRequired(const Decl *D, const 
ASTContext &Ctx) {
   return D->hasAttr() ? D->getMaxAlignment() : 0;
 }
 
-APValue const * evaluateConstantInitializer(clang::VarDecl const * VD) {
-  assert (VD != nullptr);
+APValue const *evaluateConstantInitializer(clang::VarDecl const *VD) {
+  assert(VD != nullptr);
 
   VD = VD->getCanonicalDecl();
   if (!VD)
@@ -5613,7 +5613,7 @@ void CGDebugInfo::EmitGlobalVariable(const VarDecl *VD) {
   if (CacheIt != DeclCache.end())
 return;
 
-  auto const * InitVal = evaluateConstantInitializer(VD);
+  auto const *InitVal = evaluateConstantInitializer(VD);
   if (!InitVal)
 return;
 

>From 148ab1793a866111060f77807ff065040fad92d8 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Sat, 18 Nov 2023 00:22:06 +
Subject: [PATCH 3/7] [clang][DebugInfo] Attach DW_AT_const_value to static
 data-member definitions if available

---
 clang/lib/CodeGen/CGDebugInfo.cpp  | 10 --
 .../CodeGenCXX/debug-info-static-inline-member.cpp |  2 +-
 clang/test/CodeGenCXX/inline-dllexport-member.cpp  |  2 +-
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 9bba6e6b13e9318..e01c57baef19931 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -5516,11 +5516,17 @@ void 
CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var,
 }
 AppendAddressSpaceXDeref(AddressSpace, Expr);
 
+llvm::DIExpression *E = nullptr;
+if (Expr.empty()) {
+  if (auto const *InitVal = evaluateConstantInitializer(D))
+E = createConstantValueExpression(D, *InitVal);
+} else
+  E = DBuilder.createExpression(Expr);
+
 llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(D);
 GVE = DBuilder.createGlobalVariableExpression(
 DContext, DeclName, LinkageName, Unit, LineNo, getOrCreateType(T, 
Unit),
-Var->hasLocalLinkage(), true,
-Expr.empty() ? nullptr : DBuilder.createExpression(Expr),
+Var->hasLocalLinkage(), true, E,
 getOrCreateStaticDataMemberDeclarationOrNull(D), TemplateParameters,
 Align, Annotations);
 Var->addDebugInfo(GVE);
diff --git a/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp 
b/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
index f2d4d9408a8297a..950ea9b302b290c 100644
--- a/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
+++ b/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
@@ -43,7 +43,7 @@ int main() {
 // CHECK:  @{{.*}}cexpr_struct_with_addr{{.*}} = 
 // CHECK-SAME!dbg ![[EMPTY_GLOBAL:[0-9]+]]
 
-// CHECK:  !DIGlobalVariableExpression(var: ![[INT_VAR:[0-9]+]], expr: 
!DIExpression())
+// CHECK:  !DIGlobalVariableExpression(var: ![[INT_VAR:[

[clang] [clang][DebugInfo] Attach DW_AT_const_value to static data-member definitions if available (PR #72730)

2023-11-20 Thread Michael Buch via cfe-commits
https://github.com/Michael137 edited 
https://github.com/llvm/llvm-project/pull/72730
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema] Diagnose friend function specialization definitions (PR #72863)

2023-11-20 Thread Krystian Stasiowski via cfe-commits
https://github.com/sdkrystian created 
https://github.com/llvm/llvm-project/pull/72863

Per [[class.friend]p6](http://eel.is/c++draft/class.friend#6) a friend function 
shall not be defined if its name isn't unqualified. A _template-id_ is not a 
name, meaning that a friend function specialization does not meet this criteria 
and cannot be defined. 

GCC, MSVC, and EDG all consider friend function specialization definitions to 
be invalid de facto explicit specializations and diagnose them as such. 

Instantiating a dependent friend function specialization definition [currently 
trips an assert](https://godbolt.org/z/sonhbKWKT) in 
`FunctionDecl::setFunctionTemplateSpecialization`. This happens because we do 
not set the `TemplateSpecializationKind` of the `FunctionDecl` created by 
template argument deduction to `TSK_ExplicitSpecialization` for friend 
functions 
[here](https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/SemaTemplate.cpp#L9600).
 I changed the assert condition because I believe this is the correct behavior. 


>From 3e191f245325742338eba223a3f98b6bb5ad414b Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Mon, 20 Nov 2023 07:11:41 -0500
Subject: [PATCH] [Clang][Sema] Diagnose friend function specialization
 definitions

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td   |  2 ++
 clang/lib/AST/Decl.cpp |  1 +
 clang/lib/Sema/SemaDeclCXX.cpp | 14 ++
 clang/test/CXX/class.access/class.friend/p6.cpp| 13 +
 clang/test/CXX/temp/temp.decls/temp.friend/p1.cpp  |  8 +---
 .../CXX/temp/temp.spec/temp.expl.spec/p20-2.cpp|  3 ++-
 6 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 3f6ca64baf23ae6..35acbb40a4b4f38 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1669,6 +1669,8 @@ def err_qualified_friend_def : Error<
   "friend function definition cannot be qualified with '%0'">;
 def err_friend_def_in_local_class : Error<
   "friend function cannot be defined in a local class">;
+def err_friend_specialization_def : Error<
+  "friend function specialization cannot be defined">;
 def err_friend_not_first_in_declaration : Error<
   "'friend' must appear first in a non-function declaration">;
 def err_using_decl_friend : Error<
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index c5c2edf1bfe3aba..527ea6042daa034 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -4150,6 +4150,7 @@ 
FunctionDecl::setFunctionTemplateSpecialization(ASTContext &C,
   assert(TSK != TSK_Undeclared &&
  "Must specify the type of function template specialization");
   assert((TemplateOrSpecialization.isNull() ||
+  getFriendObjectKind() != FOK_None ||
   TSK == TSK_ExplicitSpecialization) &&
  "Member specialization must be an explicit specialization");
   FunctionTemplateSpecializationInfo *Info =
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 3688192e6cbe5c5..2bfb02da08bde54 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -17960,6 +17960,20 @@ NamedDecl *Sema::ActOnFriendFunctionDecl(Scope *S, 
Declarator &D,
 
 DCScope = getScopeForDeclContext(S, DC);
 
+// C++ [class.friend]p6:
+//   A function may be defined in a friend declaration of a class if and
+//   only if the class is a non-local class, and the function name is
+//   unqualified.
+//
+// Per [basic.pre]p4, a template-id is not a name. Therefore, if we have
+// a template-id, the function name is not unqualified because these is no
+// name. While the wording requires some reading in-between the lines, GCC,
+// MSVC, and EDG all consider a friend function specialization definitions
+// to be de facto explicit specialization and diagnose them as such.
+if (D.isFunctionDefinition() && isTemplateId) {
+  Diag(NameInfo.getBeginLoc(), diag::err_friend_specialization_def);
+}
+
   //   - There's a non-dependent scope specifier, in which case we
   // compute it and do a previous lookup there for a function
   // or function template.
diff --git a/clang/test/CXX/class.access/class.friend/p6.cpp 
b/clang/test/CXX/class.access/class.friend/p6.cpp
index 2fe20fe77fc8f21..47104e29dc6b3c7 100644
--- a/clang/test/CXX/class.access/class.friend/p6.cpp
+++ b/clang/test/CXX/class.access/class.friend/p6.cpp
@@ -22,3 +22,16 @@ void local() {
 friend void f() { } // expected-error{{friend function cannot be defined 
in a local class}}
   };
 }
+
+template void f3(T);
+
+namespace N {
+  template void f4(T);
+}
+
+template struct A {
+  friend void f3(T) {}
+  friend void f3(T) {} // expected-error{{friend function specialization 
cannot be defined}}
+  friend void N::f4(T) {} // expected-error{

[clang] [Clang][Sema] Diagnose friend function specialization definitions (PR #72863)

2023-11-20 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Krystian Stasiowski (sdkrystian)


Changes

Per [[class.friend]p6](http://eel.is/c++draft/class.friend#6) a friend 
function shall not be defined if its name isn't unqualified. A _template-id_ is 
not a name, meaning that a friend function specialization does not meet this 
criteria and cannot be defined. 

GCC, MSVC, and EDG all consider friend function specialization definitions to 
be invalid de facto explicit specializations and diagnose them as such. 

Instantiating a dependent friend function specialization definition [currently 
trips an assert](https://godbolt.org/z/sonhbKWKT) in 
`FunctionDecl::setFunctionTemplateSpecialization`. This happens because we do 
not set the `TemplateSpecializationKind` of the `FunctionDecl` created by 
template argument deduction to `TSK_ExplicitSpecialization` for friend 
functions 
[here](https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/SemaTemplate.cpp#L9600).
 I changed the assert condition because I believe this is the correct behavior. 


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


6 Files Affected:

- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+2) 
- (modified) clang/lib/AST/Decl.cpp (+1) 
- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+14) 
- (modified) clang/test/CXX/class.access/class.friend/p6.cpp (+13) 
- (modified) clang/test/CXX/temp/temp.decls/temp.friend/p1.cpp (+5-3) 
- (modified) clang/test/CXX/temp/temp.spec/temp.expl.spec/p20-2.cpp (+2-1) 


``diff
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 3f6ca64baf23ae6..35acbb40a4b4f38 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1669,6 +1669,8 @@ def err_qualified_friend_def : Error<
   "friend function definition cannot be qualified with '%0'">;
 def err_friend_def_in_local_class : Error<
   "friend function cannot be defined in a local class">;
+def err_friend_specialization_def : Error<
+  "friend function specialization cannot be defined">;
 def err_friend_not_first_in_declaration : Error<
   "'friend' must appear first in a non-function declaration">;
 def err_using_decl_friend : Error<
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index c5c2edf1bfe3aba..527ea6042daa034 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -4150,6 +4150,7 @@ 
FunctionDecl::setFunctionTemplateSpecialization(ASTContext &C,
   assert(TSK != TSK_Undeclared &&
  "Must specify the type of function template specialization");
   assert((TemplateOrSpecialization.isNull() ||
+  getFriendObjectKind() != FOK_None ||
   TSK == TSK_ExplicitSpecialization) &&
  "Member specialization must be an explicit specialization");
   FunctionTemplateSpecializationInfo *Info =
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 3688192e6cbe5c5..2bfb02da08bde54 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -17960,6 +17960,20 @@ NamedDecl *Sema::ActOnFriendFunctionDecl(Scope *S, 
Declarator &D,
 
 DCScope = getScopeForDeclContext(S, DC);
 
+// C++ [class.friend]p6:
+//   A function may be defined in a friend declaration of a class if and
+//   only if the class is a non-local class, and the function name is
+//   unqualified.
+//
+// Per [basic.pre]p4, a template-id is not a name. Therefore, if we have
+// a template-id, the function name is not unqualified because these is no
+// name. While the wording requires some reading in-between the lines, GCC,
+// MSVC, and EDG all consider a friend function specialization definitions
+// to be de facto explicit specialization and diagnose them as such.
+if (D.isFunctionDefinition() && isTemplateId) {
+  Diag(NameInfo.getBeginLoc(), diag::err_friend_specialization_def);
+}
+
   //   - There's a non-dependent scope specifier, in which case we
   // compute it and do a previous lookup there for a function
   // or function template.
diff --git a/clang/test/CXX/class.access/class.friend/p6.cpp 
b/clang/test/CXX/class.access/class.friend/p6.cpp
index 2fe20fe77fc8f21..47104e29dc6b3c7 100644
--- a/clang/test/CXX/class.access/class.friend/p6.cpp
+++ b/clang/test/CXX/class.access/class.friend/p6.cpp
@@ -22,3 +22,16 @@ void local() {
 friend void f() { } // expected-error{{friend function cannot be defined 
in a local class}}
   };
 }
+
+template void f3(T);
+
+namespace N {
+  template void f4(T);
+}
+
+template struct A {
+  friend void f3(T) {}
+  friend void f3(T) {} // expected-error{{friend function specialization 
cannot be defined}}
+  friend void N::f4(T) {} // expected-error{{friend function definition cannot 
be qualified with 'N::'}}
+  friend void N::f4(T) {} // expected-error{{friend function definition 
cannot be qualified with 'N::'}}
+};
d

[clang] [clang][Interp] Use array filler expression (PR #72865)

2023-11-20 Thread Timm Baeder via cfe-commits
https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/72865

This is obviously not what we should ideally do, but the current state is also 
broken. We are just leaving the other elements uninitialized and rely on them 
being zero-ed.

>From c6a945bcd760803909ec085b384ead6376dd7abe Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Mon, 20 Nov 2023 14:02:54 +0100
Subject: [PATCH] [clang][Interp] Use array filler expression

This is obviously not what we should ideally do, but the current state
is also broken. We are just leaving the other elements uninitialized and
rely on them being zero-ed.
---
 clang/lib/AST/Interp/ByteCodeExprGen.cpp | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 5dc1f9dfb10ff32..180749a75ebd22e 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -662,13 +662,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;
   }
 

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


[clang] [clang][Interp] Use array filler expression (PR #72865)

2023-11-20 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

This is obviously not what we should ideally do, but the current state is also 
broken. We are just leaving the other elements uninitialized and rely on them 
being zero-ed.

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


1 Files Affected:

- (modified) clang/lib/AST/Interp/ByteCodeExprGen.cpp (+14-1) 


``diff
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 5dc1f9dfb10ff32..180749a75ebd22e 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -662,13 +662,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;
   }
 

``




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


[clang] [Clang][Sema] Diagnose friend function specialization definitions (PR #72863)

2023-11-20 Thread Krystian Stasiowski via cfe-commits
https://github.com/sdkrystian edited 
https://github.com/llvm/llvm-project/pull/72863
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [llvm] [clang] [SVE2.1][Clang][LLVM]Add BFloat16 builtin in Clang and LLVM intrinisc (PR #70362)

2023-11-20 Thread via cfe-commits

@@ -0,0 +1,61 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 
-target-feature +b16b16 -target-feature +sve -S -disable-O0-optnone -Werror 
-Wall -emit-llvm -o - %s | opt -S -p mem2reg,instcombine,tailcallelim | 
FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 
-target-feature +b16b16 -target-feature +sve -S -disable-O0-optnone -Werror 
-Wall -emit-llvm -o - -x c++ %s | opt -S -p mem2reg,instcombine,tailcallelim | 
FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve2p1 -target-feature +b16b16 -target-feature +sve -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve2p1 -target-feature +b16b16 -target-feature +sve -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - -x c++ %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 
-target-feature +b16b16 -target-feature +sve -target-feature -S 
-disable-O0-optnone -Werror -Wall -o /dev/null %s
+#include 
+
+#ifdef SVE_OVERLOADED_FORMS
+// A simple used,unused... macro, long enough to represent any SVE builtin.
+#define SVE_ACLE_FUNC(A1,A2_UNUSED,A3) A1##A3
+#else
+#define SVE_ACLE_FUNC(A1,A2,A3) A1##A2##A3
+#endif
+
+// CHECK-LABEL: @test_svmul_lane_bf16_idx1(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.fmul.lane.nxv8bf16( [[OP1:%.*]],  [[OP2:%.*]], i32 1)
+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: 
@_Z25test_svmul_lane_bf16_idx1u14__SVBFloat16_tu14__SVBFloat16_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.fmul.lane.nxv8bf16( [[OP1:%.*]],  [[OP2:%.*]], i32 1)
+// CPP-CHECK-NEXT:ret  [[TMP0]]
+//
+svbfloat16_t test_svmul_lane_bf16_idx1(svbfloat16_t op1, svbfloat16_t op2)
+{
+  return SVE_ACLE_FUNC(svmul_lane, _bf16, )(op1, op2, 1);
+}
+
+// CHECK-LABEL: @test_svmul_lane_bf16_idx3(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.fmul.lane.nxv8bf16( [[OP1:%.*]],  [[OP2:%.*]], i32 3)
+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: 
@_Z25test_svmul_lane_bf16_idx3u14__SVBFloat16_tu14__SVBFloat16_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.fmul.lane.nxv8bf16( [[OP1:%.*]],  [[OP2:%.*]], i32 3)
+// CPP-CHECK-NEXT:ret  [[TMP0]]
+//
+svbfloat16_t test_svmul_lane_bf16_idx3(svbfloat16_t op1, svbfloat16_t op2)
+{
+  return SVE_ACLE_FUNC(svmul_lane, _bf16, )(op1, op2, 3);
+}
+
+// CHECK-LABEL: @test_svmul_lane_bf16_idx7(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.fmul.lane.nxv8bf16( [[OP1:%.*]],  [[OP2:%.*]], i32 7)
+// CHECK-NEXT:ret  [[TMP0]]
+//
+// CPP-CHECK-LABEL: 
@_Z25test_svmul_lane_bf16_idx7u14__SVBFloat16_tu14__SVBFloat16_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.fmul.lane.nxv8bf16( [[OP1:%.*]],  [[OP2:%.*]], i32 7)
+// CPP-CHECK-NEXT:ret  [[TMP0]]
+//
+svbfloat16_t test_svmul_lane_bf16_idx7(svbfloat16_t op1, svbfloat16_t op2)
+{
+  return SVE_ACLE_FUNC(svmul_lane, _bf16, )(op1, op2, 7);

CarolineConcatto wrote:

Thank you Momchil,
Negative tests were added for bmful and bfmla and bfmla

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


[clang] [clang][NFC] Refactor Builtins.def to be a tablegen file (PR #68324)

2023-11-20 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 ba24b814f2a20a136f0a7a0b492b6ad8a62114c6 
da81d45e7bb78b611886035b0f331318e5fdd7e7 -- 
clang/utils/TableGen/ClangBuiltinsEmitter.cpp clang/include/clang/AST/Expr.h 
clang/include/clang/Basic/Builtins.h clang/include/clang/Basic/TargetBuiltins.h 
clang/lib/AST/Expr.cpp clang/lib/AST/StmtPrinter.cpp 
clang/lib/Basic/Builtins.cpp clang/lib/Basic/Targets/BPF.cpp 
clang/lib/Sema/SemaChecking.cpp clang/lib/Sema/SemaExpr.cpp 
clang/test/Analysis/bstring.c clang/test/CodeGen/callback_pthread_create.c 
clang/utils/TableGen/MveEmitter.cpp clang/utils/TableGen/TableGen.cpp 
clang/utils/TableGen/TableGenBackends.h
``





View the diff from clang-format here.


``diff
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index ec013dd0a2..94990db126 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -1606,13 +1606,7 @@ class FixedPointLiteral : public Expr, public 
APIntStorage {
 
 class CharacterLiteral : public Expr {
 public:
-  enum CharacterKind {
-Ascii,
-Wide,
-UTF8,
-UTF16,
-UTF32
-  };
+  enum CharacterKind { Ascii, Wide, UTF8, UTF16, UTF32 };
 
 private:
   unsigned Value;
diff --git a/clang/include/clang/Basic/Builtins.h 
b/clang/include/clang/Basic/Builtins.h
index f955d21169..b749ca4307 100644
--- a/clang/include/clang/Basic/Builtins.h
+++ b/clang/include/clang/Basic/Builtins.h
@@ -62,7 +62,7 @@ struct HeaderDesc {
 
 namespace Builtin {
 enum ID {
-  NotBuiltin  = 0,  // This is not a builtin function.
+  NotBuiltin = 0, // This is not a builtin function.
 #define BUILTIN(ID, TYPE, ATTRS) BI##ID,
 #include "clang/Basic/Builtins.inc"
   FirstTSBuiltin
diff --git a/clang/include/clang/Basic/TargetBuiltins.h 
b/clang/include/clang/Basic/TargetBuiltins.h
index d5de5a286f..df7fb19135 100644
--- a/clang/include/clang/Basic/TargetBuiltins.h
+++ b/clang/include/clang/Basic/TargetBuiltins.h
@@ -83,8 +83,8 @@ namespace clang {
   namespace BPF {
   enum {
 LastTIBuiltin = clang::Builtin::FirstTSBuiltin - 1,
-  #define BUILTIN(ID, TYPE, ATTRS) BI##ID,
-  #include "clang/Basic/BuiltinsBPF.inc"
+#define BUILTIN(ID, TYPE, ATTRS) BI##ID,
+#include "clang/Basic/BuiltinsBPF.inc"
 LastTSBuiltin
   };
   }
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 65fa1c69ce..cb7a3e98e3 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -1247,10 +1247,18 @@ void StringLiteral::outputString(raw_ostream &OS) const 
{
   case Unevaluated:
   case Ordinary:
 break; // no prefix.
-  case Wide:  OS << 'L'; break;
-  case UTF8:  OS << "u8"; break;
-  case UTF16: OS << 'u'; break;
-  case UTF32: OS << 'U'; break;
+  case Wide:
+OS << 'L';
+break;
+  case UTF8:
+OS << "u8";
+break;
+  case UTF16:
+OS << 'u';
+break;
+  case UTF32:
+OS << 'U';
+break;
   }
   OS << '"';
   static const char Hex[] = "0123456789ABCDEF";
@@ -1277,8 +1285,8 @@ void StringLiteral::outputString(raw_ostream &OS) const {
 // If this is a wide string, output characters over 0xff using \x
 // escapes. Otherwise, this is a UTF-16 or UTF-32 string, and Char is a
 // codepoint: use \x escapes for invalid codepoints.
-if (getKind() == Wide ||
-(Char >= 0xd800 && Char <= 0xdfff) || Char >= 0x11) {
+if (getKind() == Wide || (Char >= 0xd800 && Char <= 0xdfff) ||
+Char >= 0x11) {
   // FIXME: Is this the best way to print wchar_t?
   OS << "\\x";
   int Shift = 28;
@@ -5035,7 +5043,7 @@ QualType OMPArraySectionExpr::getBaseOriginalType(const 
Expr *Base) {
 if (OriginalTy->isAnyPointerType())
   OriginalTy = OriginalTy->getPointeeType();
 else {
-  assert (OriginalTy->isArrayType());
+  assert(OriginalTy->isArrayType());
   OriginalTy = OriginalTy->castAsArrayTypeUnsafe()->getElementType();
 }
   }
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 183f389b79..13c318b6a9 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -394,12 +394,11 @@ static bool SemaBuiltinOverflow(Sema &S, CallExpr 
*TheCall,
 
 QualType Ty = Arg.get()->getType();
 const auto *PtrTy = Ty->getAs();
-if (!PtrTy ||
-!PtrTy->getPointeeType()->isIntegerType() ||
+if (!PtrTy || !PtrTy->getPointeeType()->isIntegerType() ||
 PtrTy->getPointeeType().isConstQualified()) {
   S.Diag(Arg.get()->getBeginLoc(),
  diag::err_overflow_builtin_must_be_ptr_int)
-<< Ty << Arg.get()->getSourceRange();
+  << Ty << Arg.get()->getSourceRange();
   return true;
 }
   }
@@ -7152,7 +7151,7 @@ ExprResult Sema::BuildAtomicExpr(SourceRange CallRange, 
SourceRange ExprRange,
   bool IsHIP = O

[clang] [APINotes] Upstream APINotesManager (PR #72389)

2023-11-20 Thread Egor Zhdan via cfe-commits
egorzhdan wrote:

@nico sorry for not leaving a more detailed description. I'll make sure to add 
a release note once the API notes are upstreamed entirely.

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


[flang] [clang] [Flang][Clang] Add support for frame pointers in Flang Driver (PR #72146)

2023-11-20 Thread Radu Salavat via cfe-commits
https://github.com/Radu2k updated 
https://github.com/llvm/llvm-project/pull/72146

>From 0b0f02eab4dc02adf79461bc865be6f7580938cf Mon Sep 17 00:00:00 2001
From: Radu2k 
Date: Mon, 13 Nov 2023 17:49:06 +
Subject: [PATCH 1/6] [Flang][Clang] Add support for frame pointers in Flang

---
 clang/include/clang/Driver/Options.td |  14 +-
 clang/lib/Driver/ToolChains/Clang.cpp | 133 -
 clang/lib/Driver/ToolChains/CommonArgs.cpp| 141 ++
 clang/lib/Driver/ToolChains/CommonArgs.h  |   4 +
 clang/lib/Driver/ToolChains/Flang.cpp |  19 +++
 .../include/flang/Frontend/CodeGenOptions.def |   1 +
 flang/include/flang/Frontend/CodeGenOptions.h |  23 +++
 flang/include/flang/Tools/CrossToolHelpers.h  |   2 +
 flang/lib/Frontend/CompilerInvocation.cpp |  13 ++
 flang/lib/Frontend/FrontendActions.cpp|   5 +
 flang/test/Driver/driver-help-hidden.f90  |   1 +
 flang/test/Driver/driver-help.f90 |   2 +
 flang/test/Driver/frontend-forwarding.f90 |   2 +
 13 files changed, 222 insertions(+), 138 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d1b67a448b2a59b..bf99786d017b318 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3147,7 +3147,8 @@ def fno_ms_compatibility : Flag<["-"], 
"fno-ms-compatibility">, Group,
 def fno_objc_legacy_dispatch : Flag<["-"], "fno-objc-legacy-dispatch">, 
Group;
 def fno_objc_weak : Flag<["-"], "fno-objc-weak">, Group,
   Visibility<[ClangOption, CC1Option]>;
-def fno_omit_frame_pointer : Flag<["-"], "fno-omit-frame-pointer">, 
Group;
+def fno_omit_frame_pointer : Flag<["-"], "fno-omit-frame-pointer">, 
Group,
+  Visibility<[ClangOption, FlangOption]>;
 defm operator_names : BoolFOption<"operator-names",
   LangOpts<"CXXOperatorNames">, Default,
   NegFlag>;
 
 def fomit_frame_pointer : Flag<["-"], "fomit-frame-pointer">, Group,
+  Visibility<[ClangOption, FlangOption]>,
   HelpText<"Omit the frame pointer from functions that don't need it. "
   "Some stack unwinding cases, such as profilers and sanitizers, may prefer 
specifying -fno-omit-frame-pointer. "
   "On many targets, -O1 and higher omit the frame pointer by default. "
@@ -6752,10 +6754,7 @@ def new_struct_path_tbaa : Flag<["-"], 
"new-struct-path-tbaa">,
 def mdebug_pass : Separate<["-"], "mdebug-pass">,
   HelpText<"Enable additional debug output">,
   MarshallingInfoString>;
-def mframe_pointer_EQ : Joined<["-"], "mframe-pointer=">,
-  HelpText<"Specify which frame pointers to retain.">, 
Values<"all,non-leaf,none">,
-  NormalizedValuesScope<"CodeGenOptions::FramePointerKind">, 
NormalizedValues<["All", "NonLeaf", "None"]>,
-  MarshallingInfoEnum, "None">;
+
 def mabi_EQ_ieeelongdouble : Flag<["-"], "mabi=ieeelongdouble">,
   HelpText<"Use IEEE 754 quadruple-precision for long double">,
   MarshallingInfoFlag>;
@@ -7368,6 +7367,11 @@ def pic_level : Separate<["-"], "pic-level">,
 def pic_is_pie : Flag<["-"], "pic-is-pie">,
   HelpText<"File is for a position independent executable">,
   MarshallingInfoFlag>;
+  
+def mframe_pointer_EQ : Joined<["-"], "mframe-pointer=">,
+  HelpText<"Specify which frame pointers to retain.">, 
Values<"all,non-leaf,none">,
+  NormalizedValuesScope<"CodeGenOptions::FramePointerKind">, 
NormalizedValues<["All", "NonLeaf", "None"]>,
+  MarshallingInfoEnum, "None">;
 
 } // let Visibility = [CC1Option, FC1Option]
 
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 3b98c7ae6e6ec66..3273bd1d2c0c6fa 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -409,139 +409,6 @@ static bool ShouldEnableAutolink(const ArgList &Args, 
const ToolChain &TC,
   Default);
 }
 
-static bool mustUseNonLeafFramePointerForTarget(const llvm::Triple &Triple) {
-  switch (Triple.getArch()){
-  default:
-return false;
-  case llvm::Triple::arm:
-  case llvm::Triple::thumb:
-// ARM Darwin targets require a frame pointer to be always present to aid
-// offline debugging via backtraces.
-return Triple.isOSDarwin();
-  }
-}
-
-static bool useFramePointerForTargetByDefault(const ArgList &Args,
-  const llvm::Triple &Triple) {
-  if (Args.hasArg(options::OPT_pg) && !Args.hasArg(options::OPT_mfentry))
-return true;
-
-  if (Triple.isAndroid()) {
-switch (Triple.getArch()) {
-case llvm::Triple::aarch64:
-case llvm::Triple::arm:
-case llvm::Triple::armeb:
-case llvm::Triple::thumb:
-case llvm::Triple::thumbeb:
-case llvm::Triple::riscv64:
-  return true;
-default:
-  break;
-}
-  }
-
-  switch (Triple.getArch()) {
-  case llvm::Triple::xcore:
-  case llvm::Triple::wasm32:
-  case llvm::Triple::wasm64:
-  case llvm::Triple::msp430:
-// XCore never wants frame pointers, regardless of OS.
-// WebAssembly never wants

[clang] [flang] [llvm] [flang][OpenMP] Add semantic check for declare target (PR #72770)

2023-11-20 Thread via cfe-commits
https://github.com/agozillon approved this pull request.

LGTM, aside from Sergio's Nits! 

Might be worth asking someone from the Clang team to have a look at the Clang 
changes if you're a little unsure on them, but if you're happy with them can 
disregard doing that!

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


[clang] [llvm] [AArch64][SVE2.1] Add intrinsics for quadword loads/stores with unscaled offset (PR #70474)

2023-11-20 Thread David Sherwood via cfe-commits
https://github.com/david-arm approved this pull request.

LGTM. I think I would have preferred the patch to be split up into 3 - one for 
contiguous extending loads/truncating stores, one for structured loads/stores, 
and one for the gathers. That's why it took me so long to review this patch as 
I was constantly trying to keep all the information about each 
builtin/instruction in my head whilst reviewing the tests for correctness!

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


[clang] [clang][DebugInfo] Attach DW_AT_const_value to static data-member definitions if available (PR #72730)

2023-11-20 Thread Michael Buch via cfe-commits
https://github.com/Michael137 edited 
https://github.com/llvm/llvm-project/pull/72730
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [CUDA][HIP] ignore implicit host/device attr for override (PR #72815)

2023-11-20 Thread Yaxun Liu via cfe-commits
https://github.com/yxsamliu updated 
https://github.com/llvm/llvm-project/pull/72815

>From 1f48a0eb04df6ccc2d8117ebd6b68cc45484a0f3 Mon Sep 17 00:00:00 2001
From: "Yaxun (Sam) Liu" 
Date: Sun, 19 Nov 2023 19:34:35 -0500
Subject: [PATCH] [CUDA][HIP] ignore implicit host/device attr for override

When deciding whether a previous function declaration is an
overload or override, implicit host/device attrs should
not be considered.

This fixes the failure for the following code:

`template 
class C {
explicit C() {};
};

template <> C::C() {};
`

The issue was introduced by https://github.com/llvm/llvm-project/pull/72394

sine the template specialization is treated as overload
due to implicit host/device attrs are considered for
overload/override differentiation.
---
 clang/lib/Sema/SemaOverload.cpp  |  6 --
 .../SemaCUDA/implicit-member-target-inherited.cu |  1 +
 clang/test/SemaCUDA/trivial-ctor-dtor.cu | 16 
 3 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 9800d7f1c9cfee9..64607e28b8b35e6 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -1491,8 +1491,10 @@ static bool IsOverloadOrOverrideImpl(Sema &SemaRef, 
FunctionDecl *New,
 // Don't allow overloading of destructors.  (In theory we could, but it
 // would be a giant change to clang.)
 if (!isa(New)) {
-  Sema::CUDAFunctionTarget NewTarget = SemaRef.IdentifyCUDATarget(New),
-   OldTarget = SemaRef.IdentifyCUDATarget(Old);
+  Sema::CUDAFunctionTarget NewTarget = SemaRef.IdentifyCUDATarget(
+   New, isa(New)),
+   OldTarget = SemaRef.IdentifyCUDATarget(
+   Old, isa(New));
   if (NewTarget != Sema::CFT_InvalidTarget) {
 assert((OldTarget != Sema::CFT_InvalidTarget) &&
"Unexpected invalid target.");
diff --git a/clang/test/SemaCUDA/implicit-member-target-inherited.cu 
b/clang/test/SemaCUDA/implicit-member-target-inherited.cu
index 781199bba6b5a11..ceca0891fc9b03c 100644
--- a/clang/test/SemaCUDA/implicit-member-target-inherited.cu
+++ b/clang/test/SemaCUDA/implicit-member-target-inherited.cu
@@ -39,6 +39,7 @@ struct A2_with_device_ctor {
 };
 // expected-note@-3 {{candidate constructor (the implicit copy constructor) 
not viable}}
 // expected-note@-4 {{candidate constructor (the implicit move constructor) 
not viable}}
+// expected-note@-4 {{candidate inherited constructor not viable: call to 
__device__ function from __host__ function}}
 
 struct B2_with_implicit_default_ctor : A2_with_device_ctor {
   using A2_with_device_ctor::A2_with_device_ctor;
diff --git a/clang/test/SemaCUDA/trivial-ctor-dtor.cu 
b/clang/test/SemaCUDA/trivial-ctor-dtor.cu
index 1df8adc62bab590..21d698d28492ac3 100644
--- a/clang/test/SemaCUDA/trivial-ctor-dtor.cu
+++ b/clang/test/SemaCUDA/trivial-ctor-dtor.cu
@@ -38,3 +38,19 @@ struct TC : TB {
 };
 
 __device__ TC tc; //expected-error {{dynamic initialization is not 
supported for __device__, __constant__, __shared__, and __managed__ variables}}
+
+// Check trivial ctor specialization
+template 
+struct C { //expected-note {{candidate constructor (the implicit copy 
constructor) not viable}}
+   //expected-note@-1 {{candidate constructor (the implicit move 
constructor) not viable}}
+explicit C() {};
+};
+
+template <> C::C() {};
+__device__ C ci_d;
+C ci_h;
+
+// Check non-trivial ctor specialization
+template <> C::C() { static int nontrivial_ctor = 1; } //expected-note 
{{candidate constructor not viable: call to __host__ function from __device__ 
function}}
+__device__ C cf_d; //expected-error {{no matching constructor for 
initialization of 'C'}}
+C cf_h;

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


[clang] [CUDA][HIP] ignore implicit host/device attr for override (PR #72815)

2023-11-20 Thread Yaxun Liu via cfe-commits

@@ -1000,13 +1000,9 @@ void Sema::checkCUDATargetOverload(FunctionDecl *NewFD,
 // should have the same implementation on both sides.
 if (NewTarget != OldTarget &&
 ((NewTarget == CFT_HostDevice &&
-  !(LangOpts.OffloadImplicitHostDeviceTemplates &&
-isCUDAImplicitHostDeviceFunction(NewFD) &&
-OldTarget == CFT_Device)) ||
+  !isCUDAImplicitHostDeviceFunction(NewFD)) ||

yxsamliu wrote:

actually we do not need this part of change to fix this issue, since this part 
only affects overloading. As we fixed the overloading/overriding 
differentiation, this part is not needed. I have removed this part in the 
updated change.

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


[clang] [Clang][Sema] Diagnose friend function specialization definitions (PR #72863)

2023-11-20 Thread Krystian Stasiowski via cfe-commits
sdkrystian wrote:

Ping @AaronBallman @erichkeane 

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


[clang-tools-extra] [clang-apply-replacements] Apply format only if --format is specified (PR #70801)

2023-11-20 Thread Edwin Vane via cfe-commits
revane wrote:

Does this PR address a bug I logged? I'm not sure why you've requested my input.

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


[clang-tools-extra] [clang-apply-replacements] Apply format only if --format is specified (PR #70801)

2023-11-20 Thread via cfe-commits
kuganv wrote:

> Does this PR address a bug I logged? I'm not sure why you've requested my 
> input.

Sorry for not being clear. I was tagging developers who touched this part of 
the codebase to see if you can review this change.

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


[clang] [llvm] [SVE2.1][Clang][LLVM]Add 128bits builtin in Clang and LLVM intrinisc (PR #71930)

2023-11-20 Thread via cfe-commits

@@ -1992,3 +1992,36 @@ let TargetGuard = "sme2" in {
   def SVADD_SINGLE_X2 : SInst<"svadd[_single_{d}_x2]", "22d", "cUcsUsiUilUl", 
MergeNone, "aarch64_sve_add_single_x2", [IsStreaming], []>;
   def SVADD_SINGLE_X4 : SInst<"svadd[_single_{d}_x4]", "44d", "cUcsUsiUilUl", 
MergeNone, "aarch64_sve_add_single_x4", [IsStreaming], []>;
 }
+
+let TargetGuard = "sve2p1" in {
+  // ZIPQ1, ZIPQ2, UZPQ1, UZPQ2
+  def SVZIPQ1 : SInst<"svzipq1[_{d}]", "ddd", "cUcsUsiUilUlbhfd", MergeNone, 
"aarch64_sve_zipq1", [], []>;
+  def SVZIPQ2 : SInst<"svzipq2[_{d}]", "ddd", "cUcsUsiUilUlbhfd", MergeNone, 
"aarch64_sve_zipq2", [], []>;
+  def SVUZPQ1 : SInst<"svuzpq1[_{d}]", "ddd", "cUcsUsiUilUlbhfd", MergeNone, 
"aarch64_sve_uzpq1", [], []>;
+  def SVUZPQ2 : SInst<"svuzpq2[_{d}]", "ddd", "cUcsUsiUilUlbhfd", MergeNone, 
"aarch64_sve_uzpq2", [], []>;
+  // TBLQ, TBXQ
+  def SVTBLQ : SInst<"svtblq[_{d}]", "ddu", "cUcsUsiUilUlbhfd", MergeNone, 
"aarch64_sve_tblq">;
+  def SVTBXQ : SInst<"svtbxq[_{d}]", "dddu", "cUcsUsiUilUlbhfd", MergeNone, 
"aarch64_sve_tbxq">;
+  // EXTQ
+  def EXTQ : SInst<"svextq_lane[_{d}]", "dddk", "cUcsUsiUilUlbhfd", MergeNone, 
"aarch64_sve_extq_lane", [], [ImmCheck<2, ImmCheck0_15>]>;
+  // PMOV
+  // Move to Pred
+  multiclass PMOV_TO_PRED flags=[], ImmCheckType immCh > {
+def _LANE : SInst]>;

CarolineConcatto wrote:

This is  required because of the assembly/disassembly. They are all 32 bits 
values.
Maybe we can change the assembly/disassembly, but I am not sure we should.



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


[clang] [llvm] [SVE2.1][Clang][LLVM]Add 128bits builtin in Clang and LLVM intrinisc (PR #71930)

2023-11-20 Thread via cfe-commits

@@ -1992,3 +1992,36 @@ let TargetGuard = "sme2" in {
   def SVADD_SINGLE_X2 : SInst<"svadd[_single_{d}_x2]", "22d", "cUcsUsiUilUl", 
MergeNone, "aarch64_sve_add_single_x2", [IsStreaming], []>;
   def SVADD_SINGLE_X4 : SInst<"svadd[_single_{d}_x4]", "44d", "cUcsUsiUilUl", 
MergeNone, "aarch64_sve_add_single_x4", [IsStreaming], []>;
 }
+
+let TargetGuard = "sve2p1" in {
+  // ZIPQ1, ZIPQ2, UZPQ1, UZPQ2
+  def SVZIPQ1 : SInst<"svzipq1[_{d}]", "ddd", "cUcsUsiUilUlbhfd", MergeNone, 
"aarch64_sve_zipq1", [], []>;
+  def SVZIPQ2 : SInst<"svzipq2[_{d}]", "ddd", "cUcsUsiUilUlbhfd", MergeNone, 
"aarch64_sve_zipq2", [], []>;
+  def SVUZPQ1 : SInst<"svuzpq1[_{d}]", "ddd", "cUcsUsiUilUlbhfd", MergeNone, 
"aarch64_sve_uzpq1", [], []>;
+  def SVUZPQ2 : SInst<"svuzpq2[_{d}]", "ddd", "cUcsUsiUilUlbhfd", MergeNone, 
"aarch64_sve_uzpq2", [], []>;
+  // TBLQ, TBXQ
+  def SVTBLQ : SInst<"svtblq[_{d}]", "ddu", "cUcsUsiUilUlbhfd", MergeNone, 
"aarch64_sve_tblq">;
+  def SVTBXQ : SInst<"svtbxq[_{d}]", "dddu", "cUcsUsiUilUlbhfd", MergeNone, 
"aarch64_sve_tbxq">;
+  // EXTQ
+  def EXTQ : SInst<"svextq_lane[_{d}]", "dddk", "cUcsUsiUilUlbhfd", MergeNone, 
"aarch64_sve_extq_lane", [], [ImmCheck<2, ImmCheck0_15>]>;
+  // PMOV
+  // Move to Pred
+  multiclass PMOV_TO_PRED flags=[], ImmCheckType immCh > {
+def _LANE : SInst]>;
+def _ZERO : SInst;
+  }
+  defm SVPMOV_B_TO_PRED_LANE : PMOV_TO_PRED<"svpmov", "cUc", 
"aarch64_sve_pmov_to_pred_lane", [], ImmCheck0_0>;
+  defm SVPMOV_H_TO_PRED_LANE : PMOV_TO_PRED<"svpmov", "sUs", 
"aarch64_sve_pmov_to_pred_lane", [], ImmCheck0_1>;
+  defm SVPMOV_S_TO_PRED_LANE : PMOV_TO_PRED<"svpmov", "iUi", 
"aarch64_sve_pmov_to_pred_lane", [], ImmCheck0_3>;
+  defm SVPMOV_D_TO_PRED_LANE : PMOV_TO_PRED<"svpmov", "lUl", 
"aarch64_sve_pmov_to_pred_lane", [], ImmCheck0_7>;
+
+  // Move to Vector
+  multiclass PMOV_TO_VEC flags=[], ImmCheckType immCh > {
+def _M : SInst]>;

CarolineConcatto wrote:

This is  required because of the assembly/disassembly. They are all 32 bits 
values.
Maybe we can change the assembly/disassembly, but I am not sure we should.

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


[clang-tools-extra] [clang-apply-replacements] Apply format only if --format is specified (PR #70801)

2023-11-20 Thread Edwin Vane via cfe-commits
revane wrote:

I haven't touched this code in 10 years. I don't think I'm a good candidate for 
providing a review.

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


[compiler-rt] [lld] [libcxx] [clang-tools-extra] [clang] [llvm] [libc] [lldb] [mlir] [flang] [MLIR] Enable GPU Dialect to SYCL runtime integration (PR #71430)

2023-11-20 Thread Fabian Mora via cfe-commits

@@ -61,6 +63,7 @@ registerAllGPUToLLVMIRTranslations(DialectRegistry ®istry) 
{
   registerLLVMDialectTranslation(registry);
   registerNVVMDialectTranslation(registry);
   registerROCDLDialectTranslation(registry);
+  registerSPIRVDialectTranslation(registry);

fabianmcg wrote:

@silee2 can you add a test 
[here](https://github.com/llvm/llvm-project/blob/main/mlir/test/Target/LLVMIR/gpu.mlir#L46-L49)
 using the GPU SPIR-V target attribute?

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


[clang] [Clang][Sema] Diagnose friend function specialization definitions (PR #72863)

2023-11-20 Thread Erich Keane via cfe-commits

@@ -4,7 +4,8 @@ void f(T);
 
 template
 struct A {
-  // expected-error@+1{{cannot declare an explicit specialization in a friend}}
+  // expected-error@+2{{cannot declare an explicit specialization in a friend}}
+  // expected-error@+1{{friend function specialization cannot be defined}}

erichkeane wrote:

We probably shouldn't be double-erroring on all of these.  In this case, the 
existing error seems preferential.

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


[clang] [Clang][Sema] Diagnose friend function specialization definitions (PR #72863)

2023-11-20 Thread Erich Keane via cfe-commits

@@ -373,6 +373,7 @@ template  void foo() {} // 
expected-note{{candidate ignored: not a memb
 }
 using ns::foo;
 template  struct A {
+  // expected-error@+1{{friend function specialization cannot be defined}}

erichkeane wrote:

These already error, and doing a double-error here is not the right way to go.  
In this case, it seems to make sense that the 2nd error doesn't happen, same 
with the next one.

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


[clang] [Clang][Sema] Diagnose friend function specialization definitions (PR #72863)

2023-11-20 Thread Erich Keane via cfe-commits
https://github.com/erichkeane edited 
https://github.com/llvm/llvm-project/pull/72863
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema] Diagnose friend function specialization definitions (PR #72863)

2023-11-20 Thread Erich Keane via cfe-commits
https://github.com/erichkeane commented:

Needs a release note, + this should be replacing errors in the below cases.

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


[clang] [coroutines] Introduce [[clang::coro_lifetimebound]] (PR #72851)

2023-11-20 Thread Utkarsh Saxena via cfe-commits
https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/72851

>From 28e9fda4b78e1e60287048891cc92bafdef3ac4c Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Mon, 20 Nov 2023 12:17:30 +0100
Subject: [PATCH 1/2] Introduce [[clang::coro_lifetimebound]]

---
 clang/include/clang/Basic/Attr.td |  8 ++
 clang/include/clang/Basic/AttrDocs.td |  8 +-
 clang/lib/Sema/SemaInit.cpp   |  7 +-
 ...a-attribute-supported-attributes-list.test |  3 +-
 clang/test/SemaCXX/coro-lifetimebound.cpp | 93 +++
 5 files changed, 116 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/SemaCXX/coro-lifetimebound.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index f7a2b83b15ef5bc..dfe6f8999f832a3 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1110,6 +1110,14 @@ def CoroWrapper : InheritableAttr {
   let SimpleHandler = 1;
 }
 
+def CoroLifetimeBound : InheritableAttr {
+  let Spellings = [Clang<"coro_lifetimebound">];
+  let Subjects = SubjectList<[CXXRecord]>;
+  let LangOpts = [CPlusPlus];
+  let Documentation = [CoroLifetimeBoundDoc];
+  let SimpleHandler = 1;
+}
+
 // OSObject-based attributes.
 def OSConsumed : InheritableParamAttr {
   let Spellings = [Clang<"os_consumed">];
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 438d846c39eaa57..39efaee20694a43 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7483,7 +7483,6 @@ generation of the other destruction cases, optimizing the 
above `foo.destroy` to
   }];
 }
 
-
 def CoroReturnTypeAndWrapperDoc : Documentation {
   let Category = DocCatDecl;
   let Content = [{
@@ -7540,3 +7539,10 @@ Note: ``a_promise_type::get_return_object`` is exempted 
from this analysis as it
 implementation detail of any coroutine library.
 }];
 }
+
+def CoroLifetimeBoundDoc : Documentation {
+  let Category = DocCatDecl;
+  let Content = [{
+asdam
+}];
+}
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 80b51b09bf5445f..631b6a266412ccb 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -7580,10 +7580,15 @@ static void 
visitLifetimeBoundArguments(IndirectLocalPath &Path, Expr *Call,
   if (ObjectArg && implicitObjectParamIsLifetimeBound(Callee))
 VisitLifetimeBoundArg(Callee, ObjectArg);
 
+  bool checkCoroCall = false;
+  if (const auto *RD = Callee->getReturnType()->getAsRecordDecl()) {
+checkCoroCall |= RD->hasAttr() &&
+ RD->hasAttr();
+  }
   for (unsigned I = 0,
 N = std::min(Callee->getNumParams(), Args.size());
I != N; ++I) {
-if (Callee->getParamDecl(I)->hasAttr())
+if (checkCoroCall || Callee->getParamDecl(I)->hasAttr())
   VisitLifetimeBoundArg(Callee->getParamDecl(I), Args[I]);
   }
 }
diff --git a/clang/test/Misc/pragma-attribute-supported-attributes-list.test 
b/clang/test/Misc/pragma-attribute-supported-attributes-list.test
index a57bc011c059483..dd91f4f88ad685b 100644
--- a/clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ b/clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -56,9 +56,10 @@
 // CHECK-NEXT: ConsumableAutoCast (SubjectMatchRule_record)
 // CHECK-NEXT: ConsumableSetOnRead (SubjectMatchRule_record)
 // CHECK-NEXT: Convergent (SubjectMatchRule_function)
+// CHECK-NEXT: CoroLifetimeBound (SubjectMatchRule_record)
 // CHECK-NEXT: CoroOnlyDestroyWhenComplete (SubjectMatchRule_record)
 // CHECK-NEXT: CoroReturnType (SubjectMatchRule_record)
-// CHECK-NEXT: CoroWrapper
+// CHECK-NEXT: CoroWrapper (SubjectMatchRule_function)
 // CHECK-NEXT: CountedBy (SubjectMatchRule_field)
 // CHECK-NEXT: DLLExport (SubjectMatchRule_function, 
SubjectMatchRule_variable, SubjectMatchRule_record, 
SubjectMatchRule_objc_interface)
 // CHECK-NEXT: DLLImport (SubjectMatchRule_function, 
SubjectMatchRule_variable, SubjectMatchRule_record, 
SubjectMatchRule_objc_interface)
diff --git a/clang/test/SemaCXX/coro-lifetimebound.cpp 
b/clang/test/SemaCXX/coro-lifetimebound.cpp
new file mode 100644
index 000..3f719866eae0ee4
--- /dev/null
+++ b/clang/test/SemaCXX/coro-lifetimebound.cpp
@@ -0,0 +1,93 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++20 -fsyntax-only 
-verify -Wall -Wextra -Wno-error=unreachable-code -Wno-unused
+
+#include "Inputs/std-coroutine.h"
+
+using std::suspend_always;
+using std::suspend_never;
+
+template  struct [[clang::coro_lifetimebound, 
clang::coro_return_type]] Gen {
+  struct promise_type {
+Gen get_return_object() {
+  return {};
+}
+suspend_always initial_suspend();
+suspend_always final_suspend() noexcept;
+void unhandled_exception();
+void return_value(const T &t);
+
+template 
+auto await_transform(const Gen &) {
+  struct awaitable {
+bool await_ready() noexcept { return false

[clang] [coroutines] Introduce [[clang::coro_lifetimebound]] (PR #72851)

2023-11-20 Thread Utkarsh Saxena via cfe-commits
https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/72851

>From 28e9fda4b78e1e60287048891cc92bafdef3ac4c Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Mon, 20 Nov 2023 12:17:30 +0100
Subject: [PATCH 1/3] Introduce [[clang::coro_lifetimebound]]

---
 clang/include/clang/Basic/Attr.td |  8 ++
 clang/include/clang/Basic/AttrDocs.td |  8 +-
 clang/lib/Sema/SemaInit.cpp   |  7 +-
 ...a-attribute-supported-attributes-list.test |  3 +-
 clang/test/SemaCXX/coro-lifetimebound.cpp | 93 +++
 5 files changed, 116 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/SemaCXX/coro-lifetimebound.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index f7a2b83b15ef5bc..dfe6f8999f832a3 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1110,6 +1110,14 @@ def CoroWrapper : InheritableAttr {
   let SimpleHandler = 1;
 }
 
+def CoroLifetimeBound : InheritableAttr {
+  let Spellings = [Clang<"coro_lifetimebound">];
+  let Subjects = SubjectList<[CXXRecord]>;
+  let LangOpts = [CPlusPlus];
+  let Documentation = [CoroLifetimeBoundDoc];
+  let SimpleHandler = 1;
+}
+
 // OSObject-based attributes.
 def OSConsumed : InheritableParamAttr {
   let Spellings = [Clang<"os_consumed">];
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 438d846c39eaa57..39efaee20694a43 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7483,7 +7483,6 @@ generation of the other destruction cases, optimizing the 
above `foo.destroy` to
   }];
 }
 
-
 def CoroReturnTypeAndWrapperDoc : Documentation {
   let Category = DocCatDecl;
   let Content = [{
@@ -7540,3 +7539,10 @@ Note: ``a_promise_type::get_return_object`` is exempted 
from this analysis as it
 implementation detail of any coroutine library.
 }];
 }
+
+def CoroLifetimeBoundDoc : Documentation {
+  let Category = DocCatDecl;
+  let Content = [{
+asdam
+}];
+}
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 80b51b09bf5445f..631b6a266412ccb 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -7580,10 +7580,15 @@ static void 
visitLifetimeBoundArguments(IndirectLocalPath &Path, Expr *Call,
   if (ObjectArg && implicitObjectParamIsLifetimeBound(Callee))
 VisitLifetimeBoundArg(Callee, ObjectArg);
 
+  bool checkCoroCall = false;
+  if (const auto *RD = Callee->getReturnType()->getAsRecordDecl()) {
+checkCoroCall |= RD->hasAttr() &&
+ RD->hasAttr();
+  }
   for (unsigned I = 0,
 N = std::min(Callee->getNumParams(), Args.size());
I != N; ++I) {
-if (Callee->getParamDecl(I)->hasAttr())
+if (checkCoroCall || Callee->getParamDecl(I)->hasAttr())
   VisitLifetimeBoundArg(Callee->getParamDecl(I), Args[I]);
   }
 }
diff --git a/clang/test/Misc/pragma-attribute-supported-attributes-list.test 
b/clang/test/Misc/pragma-attribute-supported-attributes-list.test
index a57bc011c059483..dd91f4f88ad685b 100644
--- a/clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ b/clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -56,9 +56,10 @@
 // CHECK-NEXT: ConsumableAutoCast (SubjectMatchRule_record)
 // CHECK-NEXT: ConsumableSetOnRead (SubjectMatchRule_record)
 // CHECK-NEXT: Convergent (SubjectMatchRule_function)
+// CHECK-NEXT: CoroLifetimeBound (SubjectMatchRule_record)
 // CHECK-NEXT: CoroOnlyDestroyWhenComplete (SubjectMatchRule_record)
 // CHECK-NEXT: CoroReturnType (SubjectMatchRule_record)
-// CHECK-NEXT: CoroWrapper
+// CHECK-NEXT: CoroWrapper (SubjectMatchRule_function)
 // CHECK-NEXT: CountedBy (SubjectMatchRule_field)
 // CHECK-NEXT: DLLExport (SubjectMatchRule_function, 
SubjectMatchRule_variable, SubjectMatchRule_record, 
SubjectMatchRule_objc_interface)
 // CHECK-NEXT: DLLImport (SubjectMatchRule_function, 
SubjectMatchRule_variable, SubjectMatchRule_record, 
SubjectMatchRule_objc_interface)
diff --git a/clang/test/SemaCXX/coro-lifetimebound.cpp 
b/clang/test/SemaCXX/coro-lifetimebound.cpp
new file mode 100644
index 000..3f719866eae0ee4
--- /dev/null
+++ b/clang/test/SemaCXX/coro-lifetimebound.cpp
@@ -0,0 +1,93 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -std=c++20 -fsyntax-only 
-verify -Wall -Wextra -Wno-error=unreachable-code -Wno-unused
+
+#include "Inputs/std-coroutine.h"
+
+using std::suspend_always;
+using std::suspend_never;
+
+template  struct [[clang::coro_lifetimebound, 
clang::coro_return_type]] Gen {
+  struct promise_type {
+Gen get_return_object() {
+  return {};
+}
+suspend_always initial_suspend();
+suspend_always final_suspend() noexcept;
+void unhandled_exception();
+void return_value(const T &t);
+
+template 
+auto await_transform(const Gen &) {
+  struct awaitable {
+bool await_ready() noexcept { return false

[clang] [coroutines] Introduce [[clang::coro_lifetimebound]] (PR #72851)

2023-11-20 Thread Utkarsh Saxena via cfe-commits
https://github.com/usx95 edited https://github.com/llvm/llvm-project/pull/72851
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [coroutines] Introduce [[clang::coro_lifetimebound]] (PR #72851)

2023-11-20 Thread Utkarsh Saxena via cfe-commits
https://github.com/usx95 ready_for_review 
https://github.com/llvm/llvm-project/pull/72851
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [coroutines] Introduce [[clang::coro_lifetimebound]] (PR #72851)

2023-11-20 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Utkarsh Saxena (usx95)


Changes

Adds attribute `[[clang::coro_lifetimebound]]`.

All arguments to a function are considered to be **lifetime bound** if the 
function 
returns a type annotated with ``[[clang::coro_lifetimebound]]`` and 
``[[clang::coro_return_type]]``.


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


6 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+4) 
- (modified) clang/include/clang/Basic/Attr.td (+8) 
- (modified) clang/include/clang/Basic/AttrDocs.td (+54-1) 
- (modified) clang/lib/Sema/SemaInit.cpp (+6-1) 
- (modified) clang/test/Misc/pragma-attribute-supported-attributes-list.test 
(+2-1) 
- (added) clang/test/SemaCXX/coro-lifetimebound.cpp (+100) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 52c9d6eb69617b0..3fdb93fda8eec7f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -311,6 +311,10 @@ Attribute Changes in Clang
   should be a coroutine. A non-coroutine function marked with 
``[[clang::coro_wrapper]]``
   is still allowed to return the such a type. This is helpful for analyzers to 
recognize coroutines from the function signatures.
 
+- Clang now introduced ``[[clang::coro_lifetimebound]]`` attribute.
+  All arguments to a function are considered to be lifetime bound if the 
function 
+  returns a type annotated with ``[[clang::coro_lifetimebound]]`` and 
``[[clang::coro_return_type]]``.
+
 Improvements to Clang's diagnostics
 ---
 - Clang constexpr evaluator now prints template arguments when displaying
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index f7a2b83b15ef5bc..dfe6f8999f832a3 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1110,6 +1110,14 @@ def CoroWrapper : InheritableAttr {
   let SimpleHandler = 1;
 }
 
+def CoroLifetimeBound : InheritableAttr {
+  let Spellings = [Clang<"coro_lifetimebound">];
+  let Subjects = SubjectList<[CXXRecord]>;
+  let LangOpts = [CPlusPlus];
+  let Documentation = [CoroLifetimeBoundDoc];
+  let SimpleHandler = 1;
+}
+
 // OSObject-based attributes.
 def OSConsumed : InheritableParamAttr {
   let Spellings = [Clang<"os_consumed">];
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 438d846c39eaa57..516ef76615f40f1 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -7483,7 +7483,6 @@ generation of the other destruction cases, optimizing the 
above `foo.destroy` to
   }];
 }
 
-
 def CoroReturnTypeAndWrapperDoc : Documentation {
   let Category = DocCatDecl;
   let Content = [{
@@ -7540,3 +7539,57 @@ Note: ``a_promise_type::get_return_object`` is exempted 
from this analysis as it
 implementation detail of any coroutine library.
 }];
 }
+
+def CoroLifetimeBoundDoc : Documentation {
+  let Category = DocCatDecl;
+  let Content = [{
+The ``[[clang::coro_lifetimebound]]`` is a class attribute which can be applied
+to a `coroutine return type (CRT) 
` _ (i.e.
+it should also be annotated with ``[[clang::coro_return_type]]``).
+
+All arguments to a function are considered to be `lifetime bound 
 _`
+if the function returns a coroutine return type (CRT) annotated with 
``[[clang::coro_lifetimebound]]``.
+
+Reference parameters of a coroutine are susceptible to capturing references to 
temporaries or local variables.
+
+For example,
+
+.. code-block:: c++
+  task coro(const int& a) { co_return a + 1; }
+  task dangling_refs(int a) {
+// `coro` captures reference to a temporary. `foo` would now contain a 
dangling reference to `a`.
+auto foo = coro(1);
+// `coro` captures reference to local variable `a` which is destroyed 
after the return. 
+return coro(a);
+  }
+
+`Lifetime bound 
 _` static 
analysis
+can be used to detect such instances when coroutines capture references which 
may die earlier than the
+coroutine frame itself. In the above example, if the CRT `task` is annotated 
with 
+``[[clang::coro_lifetimebound]]``, then lifetime bound analysis would detect 
capturing reference to
+temporaries or return address of a local variable.
+
+Both coroutines and coroutine wrappers are part of this analysis.
+
+.. code-block:: c++
+  template  struct [[clang::coro_return_type, 
clang::coro_lifetimebound]] Task {
+using promise_type = some_promise_type;
+  };
+
+  Task coro(const int& a) { co_return a + 1; }
+  Task [[clang::coro_wrapper]] coro_wrapper(const int& a, const int& b) { 
+return a > b ? coro(a) : coro(b);
+  }
+  Task temporary_reference() {
+auto foo = coro(1); // warning: capturing reference to a temporary which 
would die after the exp

[clang] [OpenACC] Implement compound construct parsing (PR #72692)

2023-11-20 Thread Alexey Bataev via cfe-commits
alexey-bataev wrote:

Need to add tests

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


[clang] [OpenACC] Implement compound construct parsing (PR #72692)

2023-11-20 Thread Alexey Bataev via cfe-commits

@@ -45,11 +47,36 @@ OpenACCDirectiveKind ParseOpenACCDirectiveKind(Parser &P) {
   P.ConsumeToken();
   std::string FirstTokSpelling = P.getPreprocessor().getSpelling(FirstTok);
 
-  OpenACCDirectiveKind DirKind = GetOpenACCDirectiveKind(FirstTokSpelling);
+  OpenACCDirectiveKind DirKind = getOpenACCDirectiveKind(FirstTokSpelling);
 
   if (DirKind == OpenACCDirectiveKind::Invalid)
 P.Diag(FirstTok, diag::err_acc_invalid_directive) << FirstTokSpelling;
 
+  // Combined Constructs allows parallel loop, serial loop, or kernels loop. 
Any
+  // other attempt at a combined construct will be diagnosed as an invalid
+  // clause.
+  Token SecondTok = P.getCurToken();
+  if (!SecondTok.isAnnotation() &&
+  P.getPreprocessor().getSpelling(SecondTok) == "loop") {

alexey-bataev wrote:

The better to add a function isOpenACCDirectiveKind(OpenACCDirectiveKind Kind, 
StringRef Tok)
```
switch (Kind) {
case OpenACCDirectiveKind::Loop:
  return Tok == "loop";
case OpenACCDirectiveKind::Parallel:
  return Tok == "parallel";
...
}
```

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


[clang] [OpenACC] Implement compound construct parsing (PR #72692)

2023-11-20 Thread Erich Keane via cfe-commits
erichkeane wrote:

> Need to add tests

I mentioned in the commit message, that unfortunately this doesn't change 
behavior in a way that we can discover in our testing (unless you know how to 
check which character a diagnostic was issued on with 
`VerifyDiagnosticsConsumer`?).  I'd left the tests for these in place already, 
but the `loop` was being interpreted as the beginning of a `clause`, so it ends 
up being diagnosed as `unknown clause`.  However, now that we're consuming 
'loop' as well, we still get the same diagnostic for the NEXT token.

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


[clang] [OpenACC] Implement compound construct parsing (PR #72692)

2023-11-20 Thread Erich Keane via cfe-commits
erichkeane wrote:

> > Need to add tests
> 
> I mentioned in the commit message, that unfortunately this doesn't change 
> behavior in a way that we can discover in our testing (unless you know how to 
> check which character a diagnostic was issued on with 
> `VerifyDiagnosticsConsumer`?). I'd left the tests for these in place already, 
> but the `loop` was being interpreted as the beginning of a `clause`, so it 
> ends up being diagnosed as `unknown clause`. However, now that we're 
> consuming 'loop' as well, we still get the same diagnostic for the NEXT token.

Actually, just realized there would be a difference in behavior for `pragma acc 
parallel loop` (with no clause).  So I'll add tests for those.

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


[clang] [Clang] Introduce scoped variants of GNU atomic functions (PR #72280)

2023-11-20 Thread Yaxun Liu via cfe-commits
yxsamliu wrote:

> > > The underlying implementation is a string literal in the LLVM syncscope 
> > > argument, but the problem is that this isn't standardized at all and 
> > > varies between backends potentially
> > 
> > 
> > We don't have to use the same set of strings as syncscope if that doesn't 
> > make sense.
> 
> I don't think there's much of a point to making them strings if it's not 
> directly invoking the syncscope name for the backend. Realistically as long 
> as we give them descriptive names we can just ignore ones that don't apply on 
> various targets. Like right now you can use these scoped variants in x64 code 
> but it has no effect. Either that or we could use logic to go to the next 
> heirarchy level that makes sense. As always, naming stuff is hard.

There is another reason that string syncscope is not favored is that some 
languages uses enums for syncscope in their own atomic APIs, e.g. OpenCL. 
Currently clang is able to define macros that matches the language's enum for 
syncscope so that implementing OpenCL atomic API is just a trivial mapping to 
clang's builtin. However, if clang's atomic builtin uses string for syncscope, 
that would be quite inconvenient to use those builtin's to implement OpenCL's 
atomic API.

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


[clang] [OpenACC] Implement compound construct parsing (PR #72692)

2023-11-20 Thread Erich Keane via cfe-commits

@@ -45,11 +47,36 @@ OpenACCDirectiveKind ParseOpenACCDirectiveKind(Parser &P) {
   P.ConsumeToken();
   std::string FirstTokSpelling = P.getPreprocessor().getSpelling(FirstTok);
 
-  OpenACCDirectiveKind DirKind = GetOpenACCDirectiveKind(FirstTokSpelling);
+  OpenACCDirectiveKind DirKind = getOpenACCDirectiveKind(FirstTokSpelling);
 
   if (DirKind == OpenACCDirectiveKind::Invalid)
 P.Diag(FirstTok, diag::err_acc_invalid_directive) << FirstTokSpelling;
 
+  // Combined Constructs allows parallel loop, serial loop, or kernels loop. 
Any
+  // other attempt at a combined construct will be diagnosed as an invalid
+  // clause.
+  Token SecondTok = P.getCurToken();
+  if (!SecondTok.isAnnotation() &&
+  P.getPreprocessor().getSpelling(SecondTok) == "loop") {

erichkeane wrote:

Done.

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


[clang] [OpenACC] Implement compound construct parsing (PR #72692)

2023-11-20 Thread Erich Keane via cfe-commits
https://github.com/erichkeane updated 
https://github.com/llvm/llvm-project/pull/72692

>From 33ca88871b48fcfb16bdf7fa636a9ecfa4f38e08 Mon Sep 17 00:00:00 2001
From: erichkeane 
Date: Fri, 17 Nov 2023 11:34:43 -0800
Subject: [PATCH 1/4] [OpenACC] Implement compound construct parsing

This patch implements the compound construct parsing, which allows
'parallel loop', 'serial loop', and 'kernel loop' to act as their own
constructs.

Note that this doesn't end up making any changes to the tests, as
previously these ended up being considered clauses, which are also not
implemented. However, the location of that diagnostic is now 1 token
further along.
---
 clang/include/clang/Basic/OpenACCKinds.h |  5 +++-
 clang/lib/Parse/ParseOpenACC.cpp | 33 +++-
 2 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/OpenACCKinds.h 
b/clang/include/clang/Basic/OpenACCKinds.h
index 8da02b93b2b974c..d53b7223b5334b3 100644
--- a/clang/include/clang/Basic/OpenACCKinds.h
+++ b/clang/include/clang/Basic/OpenACCKinds.h
@@ -33,7 +33,10 @@ enum class OpenACCDirectiveKind {
   Loop,
   // FIXME: 'cache'
 
-  // FIXME: Combined Constructs.
+  // Combined Constructs.
+  ParallelLoop,
+  SerialLoop,
+  KernelsLoop,
 
   // FIXME: atomic Construct variants.
 
diff --git a/clang/lib/Parse/ParseOpenACC.cpp b/clang/lib/Parse/ParseOpenACC.cpp
index ba29d75fe35a500..a3c802b1f829877 100644
--- a/clang/lib/Parse/ParseOpenACC.cpp
+++ b/clang/lib/Parse/ParseOpenACC.cpp
@@ -22,7 +22,9 @@ using namespace llvm;
 
 namespace {
 
-// Translate single-token string representations to the OpenACC Directive Kind.
+// This doesn't completely comprehend 'Compound Constructs' (as it just
+// identifies the first token) just the first token of each.  So
+// this should only be used by `ParseOpenACCDirectiveKind`.
 OpenACCDirectiveKind GetOpenACCDirectiveKind(StringRef Name) {
   return llvm::StringSwitch(Name)
   .Case("parallel", OpenACCDirectiveKind::Parallel)
@@ -50,6 +52,35 @@ OpenACCDirectiveKind ParseOpenACCDirectiveKind(Parser &P) {
   if (DirKind == OpenACCDirectiveKind::Invalid)
 P.Diag(FirstTok, diag::err_acc_invalid_directive) << FirstTokSpelling;
 
+  // Combined Constructs allows parallel loop, serial loop, or kernels loop. 
Any
+  // other attempt at a combined construct will be diagnosed as an invalid
+  // clause.
+  Token SecondTok = P.getCurToken();
+  switch (DirKind) {
+  default:
+// Nothing to do except in the below cases, as they should be diagnosed as
+// a clause.
+break;
+  case OpenACCDirectiveKind::Parallel:
+if (P.getPreprocessor().getSpelling(SecondTok) == "loop") {
+  P.ConsumeToken();
+  return OpenACCDirectiveKind::ParallelLoop;
+}
+break;
+  case OpenACCDirectiveKind::Serial:
+if (P.getPreprocessor().getSpelling(SecondTok) == "loop") {
+  P.ConsumeToken();
+  return OpenACCDirectiveKind::SerialLoop;
+}
+break;
+  case OpenACCDirectiveKind::Kernels:
+if (P.getPreprocessor().getSpelling(SecondTok) == "loop") {
+  P.ConsumeToken();
+  return OpenACCDirectiveKind::KernelsLoop;
+}
+break;
+  }
+
   return DirKind;
 }
 

>From bb2020318ec35858293f4c7a42e3fb2904a3013f Mon Sep 17 00:00:00 2001
From: erichkeane 
Date: Fri, 17 Nov 2023 13:35:53 -0800
Subject: [PATCH 2/4] Fix Alexeys comments

---
 clang/lib/Parse/ParseOpenACC.cpp | 48 +++-
 1 file changed, 22 insertions(+), 26 deletions(-)

diff --git a/clang/lib/Parse/ParseOpenACC.cpp b/clang/lib/Parse/ParseOpenACC.cpp
index a3c802b1f829877..7a29c825c146f6b 100644
--- a/clang/lib/Parse/ParseOpenACC.cpp
+++ b/clang/lib/Parse/ParseOpenACC.cpp
@@ -22,10 +22,10 @@ using namespace llvm;
 
 namespace {
 
-// This doesn't completely comprehend 'Compound Constructs' (as it just
-// identifies the first token) just the first token of each.  So
-// this should only be used by `ParseOpenACCDirectiveKind`.
-OpenACCDirectiveKind GetOpenACCDirectiveKind(StringRef Name) {
+/// This doesn't completely comprehend 'Compound Constructs' (as it just
+/// identifies the first token) just the first token of each.  So
+/// this should only be used by `ParseOpenACCDirectiveKind`.
+OpenACCDirectiveKind getOpenACCDirectiveKind(StringRef Name) {
   return llvm::StringSwitch(Name)
   .Case("parallel", OpenACCDirectiveKind::Parallel)
   .Case("serial", OpenACCDirectiveKind::Serial)
@@ -47,7 +47,7 @@ OpenACCDirectiveKind ParseOpenACCDirectiveKind(Parser &P) {
   P.ConsumeToken();
   std::string FirstTokSpelling = P.getPreprocessor().getSpelling(FirstTok);
 
-  OpenACCDirectiveKind DirKind = GetOpenACCDirectiveKind(FirstTokSpelling);
+  OpenACCDirectiveKind DirKind = getOpenACCDirectiveKind(FirstTokSpelling);
 
   if (DirKind == OpenACCDirectiveKind::Invalid)
 P.Diag(FirstTok, diag::err_acc_invalid_directive) << FirstTokSpelling;
@@ -56,29 +56,25 @@ OpenACCDirectiveKind ParseOpenACCDirectiveKind(Parser &P) {
   // other attempt at a 

[clang] [llvm] [SVE2.1][Clang][LLVM]Add 128bits builtin in Clang and LLVM intrinisc (PR #71930)

2023-11-20 Thread Momchil Velikov via cfe-commits

@@ -1992,3 +1992,36 @@ let TargetGuard = "sme2" in {
   def SVADD_SINGLE_X2 : SInst<"svadd[_single_{d}_x2]", "22d", "cUcsUsiUilUl", 
MergeNone, "aarch64_sve_add_single_x2", [IsStreaming], []>;
   def SVADD_SINGLE_X4 : SInst<"svadd[_single_{d}_x4]", "44d", "cUcsUsiUilUl", 
MergeNone, "aarch64_sve_add_single_x4", [IsStreaming], []>;
 }
+
+let TargetGuard = "sve2p1" in {
+  // ZIPQ1, ZIPQ2, UZPQ1, UZPQ2
+  def SVZIPQ1 : SInst<"svzipq1[_{d}]", "ddd", "cUcsUsiUilUlbhfd", MergeNone, 
"aarch64_sve_zipq1", [], []>;
+  def SVZIPQ2 : SInst<"svzipq2[_{d}]", "ddd", "cUcsUsiUilUlbhfd", MergeNone, 
"aarch64_sve_zipq2", [], []>;
+  def SVUZPQ1 : SInst<"svuzpq1[_{d}]", "ddd", "cUcsUsiUilUlbhfd", MergeNone, 
"aarch64_sve_uzpq1", [], []>;
+  def SVUZPQ2 : SInst<"svuzpq2[_{d}]", "ddd", "cUcsUsiUilUlbhfd", MergeNone, 
"aarch64_sve_uzpq2", [], []>;
+  // TBLQ, TBXQ
+  def SVTBLQ : SInst<"svtblq[_{d}]", "ddu", "cUcsUsiUilUlbhfd", MergeNone, 
"aarch64_sve_tblq">;
+  def SVTBXQ : SInst<"svtbxq[_{d}]", "dddu", "cUcsUsiUilUlbhfd", MergeNone, 
"aarch64_sve_tbxq">;
+  // EXTQ
+  def EXTQ : SInst<"svextq_lane[_{d}]", "dddk", "cUcsUsiUilUlbhfd", MergeNone, 
"aarch64_sve_extq_lane", [], [ImmCheck<2, ImmCheck0_15>]>;
+  // PMOV
+  // Move to Pred
+  multiclass PMOV_TO_PRED flags=[], ImmCheckType immCh > {
+def _LANE : SInst]>;

momchil-velikov wrote:

The proposed ACLE spec says the parameter for the builtin needs to be 
`uint64_t`. : 
https://github.com/CarolineConcatto/acle/blob/sve2.1/main/acle.md#pmov
Right now the prototypes  in `arm_sve.h` look like `svbool_t 
svpmov_lane(svint64_t, int32_t);`

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


[clang] 8bd06d5 - [C23] Complete support for WG14 N2508 (#71398)

2023-11-20 Thread via cfe-commits
Author: Aaron Ballman
Date: 2023-11-20T10:52:11-05:00
New Revision: 8bd06d5b65845e5e01dd899a2deb773580460b89

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

LOG: [C23] Complete support for WG14 N2508 (#71398)

In Clang 16, we implemented the ability to add a label at the end of a
compound statement. These changes complete the implementation by
allowing a label to be followed by a declaration in C.

Note, this seems to have fixed an issue with some OpenMP stand-alone
directives not being properly diagnosed as per:
https://www.openmp.org/spec-html/5.1/openmpsu19.html#x34-330002.1.3
(The same requirement exists in OpenMP 5.2 as well.)

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/include/clang/Parse/Parser.h
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Parse/ParseStmt.cpp
clang/test/C/C2x/n2508.c
clang/test/OpenMP/barrier_ast_print.cpp
clang/test/OpenMP/barrier_messages.cpp
clang/test/OpenMP/cancel_messages.cpp
clang/test/OpenMP/cancellation_point_messages.cpp
clang/test/OpenMP/depobj_messages.cpp
clang/test/OpenMP/error_message.cpp
clang/test/OpenMP/flush_messages.cpp
clang/test/OpenMP/scan_messages.cpp
clang/test/OpenMP/taskwait_messages.cpp
clang/test/OpenMP/taskyield_messages.cpp
clang/www/c_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 52c9d6eb69617b0..5fdc061c32cb998 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -209,6 +209,12 @@ C23 Feature Support
 - Clang now supports  which defines several macros for 
performing
   checked integer arithmetic. It is also exposed in pre-C23 modes.
 
+- Completed the implementation of
+  `N2508 `_. We
+  previously implemented allowing a label at the end of a compound statement,
+  and now we've implemented allowing a label to be followed by a declaration
+  instead of a statement.
+
 Non-comprehensive list of changes in this release
 -
 
@@ -566,6 +572,23 @@ Bug Fixes in This Version
   Fixes (`#67687 `_)
 - Fix crash from constexpr evaluator evaluating uninitialized arrays as rvalue.
   Fixes (`#67317 `_)
+- Clang now properly diagnoses use of stand-alone OpenMP directives after a
+  label (including ``case`` or ``default`` labels).
+
+  Before:
+
+  .. code-block:: c++
+
+label:
+#pragma omp barrier // ok
+
+  After:
+
+  .. code-block:: c++
+
+label:
+#pragma omp barrier // error: '#pragma omp barrier' cannot be an immediate 
substatement
+
 - Fixed an issue that a benign assertion might hit when instantiating a pack 
expansion
   inside a lambda. (`#61460 
`_)
 

diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index b66ecf0724b1c77..c3753ca2828e25e 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -299,6 +299,12 @@ def note_missing_selector_name : Note<
 def note_force_empty_selector_name : Note<
   "or insert whitespace before ':' to use %0 as parameter name "
   "and have an empty entry in the selector">;
+def ext_c_label_followed_by_declaration : ExtWarn<
+  "label followed by a declaration is a C23 extension">,
+  InGroup;
+def warn_c23_compat_label_followed_by_declaration : Warning<
+  "label followed by a declaration is incompatible with C standards before "
+  "C23">, InGroup, DefaultIgnore;
 def ext_c_label_end_of_compound_statement : ExtWarn<
   "label at end of compound statement is a C23 extension">,
InGroup;

diff  --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index d20a26dbf2562a7..465453826c0b982 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -415,18 +415,15 @@ class Parser : public CodeCompletionHandler {
 
   /// Flags describing a context in which we're parsing a statement.
   enum class ParsedStmtContext {
-/// This context permits declarations in language modes where declarations
-/// are not statements.
-AllowDeclarationsInC = 0x1,
 /// This context permits standalone OpenMP directives.
-AllowStandaloneOpenMPDirectives = 0x2,
+AllowStandaloneOpenMPDirectives = 0x1,
 /// This context is at the top level of a GNU statement expression.
-InStmtExpr = 0x4,
+InStmtExpr = 0x2,
 
 /// The context of a regular substatement.
 SubStmt = 0,
 /// The context of a compound-sta

[clang-tools-extra] [flang] [llvm] [clang] [libc] [libcxx] [compiler-rt] [C23] Complete support for WG14 N2508 (PR #71398)

2023-11-20 Thread Aaron Ballman via cfe-commits
https://github.com/AaronBallman closed 
https://github.com/llvm/llvm-project/pull/71398
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenACC] Implement compound construct parsing (PR #72692)

2023-11-20 Thread Erich Keane via cfe-commits
https://github.com/erichkeane edited 
https://github.com/llvm/llvm-project/pull/72692
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenACC] Implement compound construct parsing (PR #72692)

2023-11-20 Thread Alexey Bataev via cfe-commits
https://github.com/alexey-bataev approved this pull request.


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


[clang] [llvm] [clang-tools-extra] Dont alter cold function alignment unless using Os (PR #72387)

2023-11-20 Thread Paul T Robinson via cfe-commits
pogo59 wrote:

> We already have a way to set alignment: it's the "align" attribute.

Is clang aware of the target's default function alignment? I'd thought not, in 
which case deferring to LLVM (as this new attribute does) is correct. Happy to 
be corrected on this point.

> there isn't any obvious reason to special-case "cold" functions.

I'd thought that was clear. Cold implies opt-for-size, which implies align(1). 
We want cold not to imply align(1), directly or indirectly; but, if 
opt-for-size was requested explicitly, that should still imply align(1). The 
implied align(1) does interfere with a useful feature for PS4/PS5, and has for 
some time. If the tweak to the definition of "cold" should be specific to our 
targets, we can certainly do that.

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


  1   2   3   4   >