[clang] [Cygwin] Cygwin driver (PR #74933)

2023-12-13 Thread Martin Storsjö via cfe-commits

mstorsjo wrote:

> > @carlo-bramini has spent some effort on using Clang in Cygwin environments 
> > before, so as far as I know, it does work in general from before. So this 
> > change, which adds an entirely new driver for Cygwin environments, would 
> > need to be explained why it does that (I don't disagree, it's probably the 
> > right thing to do in general), how things worked before and how this 
> > changes things. And I would like to have @carlo-bramini's eye on this (and 
> > all the related Cygwin patches from @xu-chiheng).
> > And changes like this need some general tests, have a look at 
> > `clang/test/Driver` for how other drivers are tested.
> 
> The Cygwin driver is basically the same as MinGW driver with minor difference.

Right. What are the actual observable differences to what was executed before? 
(I presume this before used the `Generic_GCC` toolchain?) Also, I wonder if it 
would make sense to share the MinGW driver code with Cygwin, and just add 
exceptions where necessary, instead of duplicating it into a separate one? 
Maybe, but perhaps not.

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


[clang] [CMake] Include opt-viewer in Fuchsia toolchain (PR #75296)

2023-12-13 Thread Petr Hosek via cfe-commits

https://github.com/petrhosek created 
https://github.com/llvm/llvm-project/pull/75296

This is necessary for visualization of optimization remarks.

>From a35caa1369eabff183eb192fd4ad7566e55c8ea6 Mon Sep 17 00:00:00 2001
From: Petr Hosek 
Date: Wed, 13 Dec 2023 08:03:37 +
Subject: [PATCH] [CMake] Include opt-viewer in Fuchsia toolchain

This is necessary for visualization of optimization remarks.
---
 clang/cmake/caches/Fuchsia-stage2.cmake | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index 4b9085d99378c6..c4673c8a54c5ef 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -336,6 +336,7 @@ set(LLVM_TOOLCHAIN_TOOLS
   llvm-symbolizer
   llvm-undname
   llvm-xray
+  opt-viewer
   sancov
   scan-build-py
   CACHE STRING "")

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


[clang] [CMake] Include opt-viewer in Fuchsia toolchain (PR #75296)

2023-12-13 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Petr Hosek (petrhosek)


Changes

This is necessary for visualization of optimization remarks.

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


1 Files Affected:

- (modified) clang/cmake/caches/Fuchsia-stage2.cmake (+1) 


``diff
diff --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index 4b9085d99378c6..c4673c8a54c5ef 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -336,6 +336,7 @@ set(LLVM_TOOLCHAIN_TOOLS
   llvm-symbolizer
   llvm-undname
   llvm-xray
+  opt-viewer
   sancov
   scan-build-py
   CACHE STRING "")

``




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


[clang] [clang] Add per-global code model attribute (PR #72078)

2023-12-13 Thread via cfe-commits

https://github.com/heiher updated 
https://github.com/llvm/llvm-project/pull/72078

>From e3863873ab817dacf8680763bb42d91f005fe5ea Mon Sep 17 00:00:00 2001
From: WANG Rui 
Date: Fri, 10 Nov 2023 21:07:48 -0600
Subject: [PATCH 1/7] [clang] Add per-global code model attribute

This patch adds a per-global code model attribute, which can override
the target's code model to access global variables.

Currently, the code model attribute is only supported on LoongArch.
This patch also maps GCC's code model names to LLVM's, which allows
for better compatibility between the two compilers.

Suggested-by: Arthur Eubanks 
Signed-off-by: WANG Rui 
Link: 
https://discourse.llvm.org/t/how-to-best-implement-code-model-overriding-for-certain-values/71816
Link: https://discourse.llvm.org/t/rfc-add-per-global-code-model-attribute/74944
---
 clang/include/clang/Basic/Attr.td |  8 +
 clang/include/clang/Basic/AttrDocs.td |  9 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  2 ++
 clang/lib/CodeGen/CodeGenModule.cpp   | 13 
 clang/lib/Sema/SemaDeclAttr.cpp   | 30 +++
 clang/test/CodeGen/LoongArch/attributes.c | 10 +++
 ...a-attribute-supported-attributes-list.test |  1 +
 clang/test/Sema/loongarch-attr-model.c| 13 
 8 files changed, 86 insertions(+)
 create mode 100644 clang/test/CodeGen/LoongArch/attributes.c
 create mode 100644 clang/test/Sema/loongarch-attr-model.c

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 1800f584c7e108..d5b5717f3d77cb 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2718,6 +2718,14 @@ def PragmaClangTextSection : InheritableAttr {
   let Documentation = [InternalOnly];
 }
 
+def CodeModel : InheritableAttr {
+  let Spellings = [GCC<"model">];
+  let Args = [StringArgument<"Model">];
+  let Subjects =
+  SubjectList<[ GlobalVar ], ErrorDiag>;
+  let Documentation = [CodeModelDocs];
+}
+
 def Sentinel : InheritableAttr {
   let Spellings = [GCC<"sentinel">];
   let Args = [DefaultIntArgument<"Sentinel", 0>,
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index b45ec6bbb8d37e..1d37c2da6bec05 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -57,6 +57,15 @@ global variable or function should be in after translation.
   let Heading = "section, __declspec(allocate)";
 }
 
+def CodeModelDocs : Documentation {
+  let Category = DocCatVariable;
+  let Content = [{
+The ``model`` attribute allows you to specify a specific code model a
+global variable should be in after translation.
+  }];
+  let Heading = "model";
+}
+
 def UsedDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 6dfb2d7195203a..d438fdde9ac7eb 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3408,6 +3408,8 @@ def warn_objc_redundant_literal_use : Warning<
 def err_attr_tlsmodel_arg : Error<"tls_model must be \"global-dynamic\", "
   "\"local-dynamic\", \"initial-exec\" or \"local-exec\"">;
 
+def err_attr_codemodel_arg : Error<"code_model '%0' is not yet supported on 
this target">;
+
 def err_aix_attr_unsupported_tls_model : Error<"TLS model '%0' is not yet 
supported on AIX">;
 
 def err_tls_var_aligned_over_maximum : Error<
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index dea58a7ff4146a..1f49721e79ddc4 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4841,6 +4841,19 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef 
MangledName, llvm::Type *Ty,
 isExternallyVisible(D->getLinkageAndVisibility().getLinkage()))
   GV->setSection(".cp.rodata");
 
+// Handle code model attribute
+if (D->hasAttr()) {
+  if (const CodeModelAttr *CMA = D->getAttr()) {
+auto CM = llvm::StringSwitch(CMA->getModel())
+  .Case("tiny", llvm::CodeModel::Tiny)
+  .Case("kernel", llvm::CodeModel::Kernel)
+  .Case("medium", llvm::CodeModel::Medium)
+  .Case("large", llvm::CodeModel::Large)
+  .Default(llvm::CodeModel::Small);
+GV->setCodeModel(CM);
+  }
+}
+
 // Check if we a have a const declaration with an initializer, we may be
 // able to emit it as available_externally to expose it's value to the
 // optimizer.
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 87c78d742d0ff4..64aa242dbb04f8 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -3369,6 +3369,33 @@ static void handleSectionAttr(Sema &S, Decl *D, const 
ParsedAttr &AL) {
   }
 }
 
+static void handleCode

[clang] [clang] Add per-global code model attribute (PR #72078)

2023-12-13 Thread via cfe-commits


@@ -3408,6 +3408,8 @@ def warn_objc_redundant_literal_use : Warning<
 def err_attr_tlsmodel_arg : Error<"tls_model must be \"global-dynamic\", "
   "\"local-dynamic\", \"initial-exec\" or \"local-exec\"">;
 
+def err_attr_codemodel_arg : Error<"code_model '%0' is not yet supported on 
this target">;

heiher wrote:

Done. Thanks

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


[clang] [clang] Parse attribute [[gnu::no_stack_protector]] (PR #75289)

2023-12-13 Thread Yingchi Long via cfe-commits

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

The PR contains functional change so please add test & assertions under 
`clang/test`

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


[clang] [clang] Add per-global code model attribute (PR #72078)

2023-12-13 Thread WÁNG Xuěruì via cfe-commits

https://github.com/xen0n commented:

Overall this seems fine, thanks!

But I'm not sure if reporting a more generic "the model attribute is not 
supported on this target" for non-LoongArch would be better: it doesn't give 
the false impression that the target doesn't support the specified code model.

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


[clang] [clang] Add per-global code model attribute (PR #72078)

2023-12-13 Thread WÁNG Xuěruì via cfe-commits


@@ -3408,6 +3408,8 @@ def warn_objc_redundant_literal_use : Warning<
 def err_attr_tlsmodel_arg : Error<"tls_model must be \"global-dynamic\", "
   "\"local-dynamic\", \"initial-exec\" or \"local-exec\"">;
 
+def err_attr_codemodel_arg : Error<"code_model '%0' is not supported on this 
target">;

xen0n wrote:

`code_model` is LLVM-speak, not C; the user doesn't write `code_model` in the C 
code. "code model" may sound better.

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


[clang] [clang] Add per-global code model attribute (PR #72078)

2023-12-13 Thread WÁNG Xuěruì via cfe-commits

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


[llvm] [clang] [RISCV] Add MC layer support for Zicfiss. (PR #66043)

2023-12-13 Thread Yeting Kuo via cfe-commits

https://github.com/yetingk updated 
https://github.com/llvm/llvm-project/pull/66043

>From 01222b781e3a0a925d2cdf793c54c7d6050f82af Mon Sep 17 00:00:00 2001
From: Yeting Kuo 
Date: Tue, 12 Sep 2023 12:28:00 +0800
Subject: [PATCH] [RISCV] Add MC layer support for Zicfiss.

The patch adds the instructions in Zicfiss extension. Zicfiss extension is
to support shadow stack for control flow integrity.

Differential Revision: https://reviews.llvm.org/D152793
---
 .../test/Preprocessor/riscv-target-features.c |   9 ++
 llvm/docs/RISCVUsage.rst  |   2 +-
 llvm/lib/Support/RISCVISAInfo.cpp |   2 +
 .../RISCV/Disassembler/RISCVDisassembler.cpp  |  25 +
 llvm/lib/Target/RISCV/RISCVFeatures.td|   7 ++
 llvm/lib/Target/RISCV/RISCVInstrInfo.td   |   9 +-
 .../lib/Target/RISCV/RISCVInstrInfoZicfiss.td |  71 
 llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp   |   3 +
 llvm/lib/Target/RISCV/RISCVRegisterInfo.td|   9 ++
 llvm/test/MC/RISCV/attribute-arch.s   |   3 +
 llvm/test/MC/RISCV/compressed-zicfiss.s   |  53 +
 llvm/test/MC/RISCV/rv32zicfiss-invalid.s  |  17 +++
 llvm/test/MC/RISCV/rv64zicfiss-invalid.s  |  17 +++
 llvm/test/MC/RISCV/zicfiss-valid.s| 102 ++
 llvm/unittests/Support/RISCVISAInfoTest.cpp   |   1 +
 15 files changed, 325 insertions(+), 5 deletions(-)
 create mode 100644 llvm/lib/Target/RISCV/RISCVInstrInfoZicfiss.td
 create mode 100644 llvm/test/MC/RISCV/compressed-zicfiss.s
 create mode 100644 llvm/test/MC/RISCV/rv32zicfiss-invalid.s
 create mode 100644 llvm/test/MC/RISCV/rv64zicfiss-invalid.s
 create mode 100644 llvm/test/MC/RISCV/zicfiss-valid.s

diff --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 35208b2eae8fb..a480877dc5f2a 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -119,6 +119,7 @@
 // CHECK-NOT: __riscv_zfa {{.*$}}
 // CHECK-NOT: __riscv_zfbfmin {{.*$}}
 // CHECK-NOT: __riscv_zicfilp {{.*$}}
+// CHECK-NOT: __riscv_zicfiss {{.*$}}
 // CHECK-NOT: __riscv_zicond {{.*$}}
 // CHECK-NOT: __riscv_ztso {{.*$}}
 // CHECK-NOT: __riscv_zvbb {{.*$}}
@@ -1278,3 +1279,11 @@
 // RUN: %clang --target=riscv64-unknown-linux-gnu -march=rv64i -E -dM %s \
 // RUN:   -munaligned-access -o - | FileCheck %s 
--check-prefix=CHECK-MISALIGNED-FAST
 // CHECK-MISALIGNED-FAST: __riscv_misaligned_fast 1
+
+// RUN: %clang -target riscv32 -menable-experimental-extensions \
+// RUN: -march=rv32izicfiss0p4 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZICFISS-EXT %s
+// RUN: %clang -target riscv64 -menable-experimental-extensions \
+// RUN: -march=rv64izicfiss0p4 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZICFISS-EXT %s
+// CHECK-ZICFISS-EXT: __riscv_zicfiss 4000{{$}}
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 842ebf4530595..6bb00c096fde3 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -196,7 +196,7 @@ The primary goal of experimental support is to assist in 
the process of ratifica
 ``experimental-zfbfmin``, ``experimental-zvfbfmin``, ``experimental-zvfbfwma``
   LLVM implements assembler support for the `0.8.0 draft specification 
`_.
 
-``experimental-zicfilp``
+``experimental-zicfilp``, ``experimental-zicfiss``
   LLVM implements the `0.4 draft specification 
`__.
 
 ``experimental-zicond``
diff --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index 85c34dd620630..c8f1047c2fd47 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -175,6 +175,8 @@ static const RISCVSupportedExtension 
SupportedExperimentalExtensions[] = {
 {"zfbfmin", RISCVExtensionVersion{0, 8}},
 
 {"zicfilp", RISCVExtensionVersion{0, 4}},
+{"zicfiss", RISCVExtensionVersion{0, 4}},
+
 {"zicond", RISCVExtensionVersion{1, 0}},
 
 {"ztso", RISCVExtensionVersion{0, 1}},
diff --git a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp 
b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
index 53e2b6b4d94ea..8e7ba6a7029c2 100644
--- a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
+++ b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
@@ -74,6 +74,17 @@ static DecodeStatus DecodeGPRRegisterClass(MCInst &Inst, 
uint32_t RegNo,
   return MCDisassembler::Success;
 }
 
+static DecodeStatus DecodeGPRX1X5RegisterClass(MCInst &Inst, uint32_t RegNo,
+   uint64_t Address,
+   const MCDisassembler *Decoder) {
+  MCRegister Reg = RISCV::X0 + RegNo;
+  if (Reg != RISCV::X1 && Reg != RISCV::X5)
+return MCDisassembler::Fail;
+
+  Inst.addOperand(MCOperand::createReg(Reg));
+  return MCDisassembler::Success;
+}
+
 sta

[clang] [RISCV][RFC] BareMetal multilibs YAML usage (PR #75191)

2023-12-13 Thread Petr Hosek via cfe-commits

petrhosek wrote:

Regarding `-f[no-]exceptions` handling, see 
https://discourse.llvm.org/t/rfc-multilib/67494/32.

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


[flang] [lldb] [clang-tools-extra] [clang] [mlir] [llvm] [compiler-rt] [Profile] Add binary profile correlation for code coverage. (PR #69493)

2023-12-13 Thread Petr Hosek via cfe-commits

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


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


[clang] [clang] Add per-global code model attribute (PR #72078)

2023-12-13 Thread via cfe-commits

https://github.com/heiher updated 
https://github.com/llvm/llvm-project/pull/72078

>From e3863873ab817dacf8680763bb42d91f005fe5ea Mon Sep 17 00:00:00 2001
From: WANG Rui 
Date: Fri, 10 Nov 2023 21:07:48 -0600
Subject: [PATCH 1/8] [clang] Add per-global code model attribute

This patch adds a per-global code model attribute, which can override
the target's code model to access global variables.

Currently, the code model attribute is only supported on LoongArch.
This patch also maps GCC's code model names to LLVM's, which allows
for better compatibility between the two compilers.

Suggested-by: Arthur Eubanks 
Signed-off-by: WANG Rui 
Link: 
https://discourse.llvm.org/t/how-to-best-implement-code-model-overriding-for-certain-values/71816
Link: https://discourse.llvm.org/t/rfc-add-per-global-code-model-attribute/74944
---
 clang/include/clang/Basic/Attr.td |  8 +
 clang/include/clang/Basic/AttrDocs.td |  9 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  2 ++
 clang/lib/CodeGen/CodeGenModule.cpp   | 13 
 clang/lib/Sema/SemaDeclAttr.cpp   | 30 +++
 clang/test/CodeGen/LoongArch/attributes.c | 10 +++
 ...a-attribute-supported-attributes-list.test |  1 +
 clang/test/Sema/loongarch-attr-model.c| 13 
 8 files changed, 86 insertions(+)
 create mode 100644 clang/test/CodeGen/LoongArch/attributes.c
 create mode 100644 clang/test/Sema/loongarch-attr-model.c

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 1800f584c7e108..d5b5717f3d77cb 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2718,6 +2718,14 @@ def PragmaClangTextSection : InheritableAttr {
   let Documentation = [InternalOnly];
 }
 
+def CodeModel : InheritableAttr {
+  let Spellings = [GCC<"model">];
+  let Args = [StringArgument<"Model">];
+  let Subjects =
+  SubjectList<[ GlobalVar ], ErrorDiag>;
+  let Documentation = [CodeModelDocs];
+}
+
 def Sentinel : InheritableAttr {
   let Spellings = [GCC<"sentinel">];
   let Args = [DefaultIntArgument<"Sentinel", 0>,
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index b45ec6bbb8d37e..1d37c2da6bec05 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -57,6 +57,15 @@ global variable or function should be in after translation.
   let Heading = "section, __declspec(allocate)";
 }
 
+def CodeModelDocs : Documentation {
+  let Category = DocCatVariable;
+  let Content = [{
+The ``model`` attribute allows you to specify a specific code model a
+global variable should be in after translation.
+  }];
+  let Heading = "model";
+}
+
 def UsedDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 6dfb2d7195203a..d438fdde9ac7eb 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3408,6 +3408,8 @@ def warn_objc_redundant_literal_use : Warning<
 def err_attr_tlsmodel_arg : Error<"tls_model must be \"global-dynamic\", "
   "\"local-dynamic\", \"initial-exec\" or \"local-exec\"">;
 
+def err_attr_codemodel_arg : Error<"code_model '%0' is not yet supported on 
this target">;
+
 def err_aix_attr_unsupported_tls_model : Error<"TLS model '%0' is not yet 
supported on AIX">;
 
 def err_tls_var_aligned_over_maximum : Error<
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index dea58a7ff4146a..1f49721e79ddc4 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4841,6 +4841,19 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef 
MangledName, llvm::Type *Ty,
 isExternallyVisible(D->getLinkageAndVisibility().getLinkage()))
   GV->setSection(".cp.rodata");
 
+// Handle code model attribute
+if (D->hasAttr()) {
+  if (const CodeModelAttr *CMA = D->getAttr()) {
+auto CM = llvm::StringSwitch(CMA->getModel())
+  .Case("tiny", llvm::CodeModel::Tiny)
+  .Case("kernel", llvm::CodeModel::Kernel)
+  .Case("medium", llvm::CodeModel::Medium)
+  .Case("large", llvm::CodeModel::Large)
+  .Default(llvm::CodeModel::Small);
+GV->setCodeModel(CM);
+  }
+}
+
 // Check if we a have a const declaration with an initializer, we may be
 // able to emit it as available_externally to expose it's value to the
 // optimizer.
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 87c78d742d0ff4..64aa242dbb04f8 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -3369,6 +3369,33 @@ static void handleSectionAttr(Sema &S, Decl *D, const 
ParsedAttr &AL) {
   }
 }
 
+static void handleCode

[clang] [clang] Add per-global code model attribute (PR #72078)

2023-12-13 Thread via cfe-commits


@@ -3408,6 +3408,8 @@ def warn_objc_redundant_literal_use : Warning<
 def err_attr_tlsmodel_arg : Error<"tls_model must be \"global-dynamic\", "
   "\"local-dynamic\", \"initial-exec\" or \"local-exec\"">;
 
+def err_attr_codemodel_arg : Error<"code_model '%0' is not supported on this 
target">;

heiher wrote:

Done. Thanks

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


[clang] [clang][ASTImporter] skip TemplateTypeParmDecl in VisitTypeAliasTemplateDecl (PR #74919)

2023-12-13 Thread Qizhi Hu via cfe-commits

jcsxky wrote:

> The `VisitTypeAliasTemplateDecl` function should be re-designed to check for 
> structural equivalence at import. The following test does not pass because an 
> existing `TypeAliasTemplateDecl` declaration with the same name is always 
> found and returned, without check for structural equivalence.
> 
> ```
> TEST_P(ASTImporterOptionSpecificTestBase, ImportTypeAliasTemplateDecl1) {
>   const char *ToCode =
>   R"(
>   struct S;
>   template 
>   using Callable = S;
>   )";
>   const char *Code =
>   R"(
>   struct S;
>   template 
>   using Callable = S;
>   )";
>   Decl *ToTU = getToTuDecl(ToCode, Lang_CXX17);
>   Decl *FromTU = getTuDecl(Code, Lang_CXX17);
> 
>   auto *FromCallable = FirstDeclMatcher().match(
>   FromTU, typeAliasTemplateDecl(hasName("Callable")));
> 
>   auto *ToCallable = FirstDeclMatcher().match(
>   ToTU, typeAliasTemplateDecl(hasName("Callable")));
> 
>   auto *ImportedCallable = Import(FromCallable, Lang_CXX17);
>   EXPECT_TRUE(ImportedCallable);
>   EXPECT_NE(ImportedCallable, ToCallable);
> }
> ```
> 
> Additionally I discovered that import of `ClassTemplateDecl` is not correct 
> too: If there is an object with the same name that is not a 
> `ClassTemplateDecl`, it is just ignored at import. This is not correct, the 
> existing object may cause name conflict (for example it can be a non-template 
> `RecordDecl`). (I found this when checking the questions in my last comment.) 
> This is an independent problem but should be fixed.

I pulled the latest code of main branch and found it seems incorrect with the 
test case I have supplied. I will have a double check this pr and issues you 
mentioned here. Thank for your detail comments and guidance.

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


[clang] [llvm] [RISCV] Add MC layer support for Zicfiss. (PR #66043)

2023-12-13 Thread Yeting Kuo via cfe-commits

yetingk wrote:

Rebase and ping.

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


[clang] [clang] Add per-global code model attribute (PR #72078)

2023-12-13 Thread via cfe-commits

https://github.com/heiher updated 
https://github.com/llvm/llvm-project/pull/72078

>From e3863873ab817dacf8680763bb42d91f005fe5ea Mon Sep 17 00:00:00 2001
From: WANG Rui 
Date: Fri, 10 Nov 2023 21:07:48 -0600
Subject: [PATCH 1/9] [clang] Add per-global code model attribute

This patch adds a per-global code model attribute, which can override
the target's code model to access global variables.

Currently, the code model attribute is only supported on LoongArch.
This patch also maps GCC's code model names to LLVM's, which allows
for better compatibility between the two compilers.

Suggested-by: Arthur Eubanks 
Signed-off-by: WANG Rui 
Link: 
https://discourse.llvm.org/t/how-to-best-implement-code-model-overriding-for-certain-values/71816
Link: https://discourse.llvm.org/t/rfc-add-per-global-code-model-attribute/74944
---
 clang/include/clang/Basic/Attr.td |  8 +
 clang/include/clang/Basic/AttrDocs.td |  9 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  2 ++
 clang/lib/CodeGen/CodeGenModule.cpp   | 13 
 clang/lib/Sema/SemaDeclAttr.cpp   | 30 +++
 clang/test/CodeGen/LoongArch/attributes.c | 10 +++
 ...a-attribute-supported-attributes-list.test |  1 +
 clang/test/Sema/loongarch-attr-model.c| 13 
 8 files changed, 86 insertions(+)
 create mode 100644 clang/test/CodeGen/LoongArch/attributes.c
 create mode 100644 clang/test/Sema/loongarch-attr-model.c

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 1800f584c7e108..d5b5717f3d77cb 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2718,6 +2718,14 @@ def PragmaClangTextSection : InheritableAttr {
   let Documentation = [InternalOnly];
 }
 
+def CodeModel : InheritableAttr {
+  let Spellings = [GCC<"model">];
+  let Args = [StringArgument<"Model">];
+  let Subjects =
+  SubjectList<[ GlobalVar ], ErrorDiag>;
+  let Documentation = [CodeModelDocs];
+}
+
 def Sentinel : InheritableAttr {
   let Spellings = [GCC<"sentinel">];
   let Args = [DefaultIntArgument<"Sentinel", 0>,
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index b45ec6bbb8d37e..1d37c2da6bec05 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -57,6 +57,15 @@ global variable or function should be in after translation.
   let Heading = "section, __declspec(allocate)";
 }
 
+def CodeModelDocs : Documentation {
+  let Category = DocCatVariable;
+  let Content = [{
+The ``model`` attribute allows you to specify a specific code model a
+global variable should be in after translation.
+  }];
+  let Heading = "model";
+}
+
 def UsedDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 6dfb2d7195203a..d438fdde9ac7eb 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3408,6 +3408,8 @@ def warn_objc_redundant_literal_use : Warning<
 def err_attr_tlsmodel_arg : Error<"tls_model must be \"global-dynamic\", "
   "\"local-dynamic\", \"initial-exec\" or \"local-exec\"">;
 
+def err_attr_codemodel_arg : Error<"code_model '%0' is not yet supported on 
this target">;
+
 def err_aix_attr_unsupported_tls_model : Error<"TLS model '%0' is not yet 
supported on AIX">;
 
 def err_tls_var_aligned_over_maximum : Error<
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index dea58a7ff4146a..1f49721e79ddc4 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4841,6 +4841,19 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef 
MangledName, llvm::Type *Ty,
 isExternallyVisible(D->getLinkageAndVisibility().getLinkage()))
   GV->setSection(".cp.rodata");
 
+// Handle code model attribute
+if (D->hasAttr()) {
+  if (const CodeModelAttr *CMA = D->getAttr()) {
+auto CM = llvm::StringSwitch(CMA->getModel())
+  .Case("tiny", llvm::CodeModel::Tiny)
+  .Case("kernel", llvm::CodeModel::Kernel)
+  .Case("medium", llvm::CodeModel::Medium)
+  .Case("large", llvm::CodeModel::Large)
+  .Default(llvm::CodeModel::Small);
+GV->setCodeModel(CM);
+  }
+}
+
 // Check if we a have a const declaration with an initializer, we may be
 // able to emit it as available_externally to expose it's value to the
 // optimizer.
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 87c78d742d0ff4..64aa242dbb04f8 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -3369,6 +3369,33 @@ static void handleSectionAttr(Sema &S, Decl *D, const 
ParsedAttr &AL) {
   }
 }
 
+static void handleCode

[clang] [Clang][SVE2.1] Make a part of the name optional for `svwhileXX` builtins with predicate-as-counter (PR #75200)

2023-12-13 Thread via cfe-commits


@@ -1950,19 +1950,17 @@ let TargetGuard = "sve2p1|sme2" in {
 //FIXME: Replace IsStreamingCompatible with IsStreamingOrHasSVE2p1 when 
available
 def SVPEXT_SINGLE : SInst<"svpext_lane_{d}", "P}i", "QcQsQiQl", MergeNone, 
"aarch64_sve_pext", [IsStreamingCompatible], [ImmCheck<1, ImmCheck0_3>]>;
 def SVPEXT_X2 : SInst<"svpext_lane_{d}_x2", "2.P}i", "QcQsQiQl", 
MergeNone, "aarch64_sve_pext_x2", [IsStreamingCompatible], [ImmCheck<1, 
ImmCheck0_1>]>;
-}
 
-let TargetGuard = "sve2p1" in {
 def SVFCLAMP   : SInst<"svclamp[_{d}]", "", "hfd", MergeNone, 
"aarch64_sve_fclamp", [], []>;
 
-def SVWHILEGE_COUNT  : SInst<"svwhilege_{d}",  "}lli", "QcQsQiQl", MergeNone, 
"aarch64_sve_whilege_{d}", [IsOverloadNone], [ImmCheck<2, ImmCheck2_4_Mul2>]>;
-def SVWHILEGT_COUNT  : SInst<"svwhilegt_{d}",  "}lli", "QcQsQiQl", MergeNone, 
"aarch64_sve_whilegt_{d}", [IsOverloadNone], [ImmCheck<2, ImmCheck2_4_Mul2>]>;
-def SVWHILELE_COUNT  : SInst<"svwhilele_{d}",  "}lli", "QcQsQiQl", MergeNone, 
"aarch64_sve_whilele_{d}", [IsOverloadNone], [ImmCheck<2, ImmCheck2_4_Mul2>]>;
-def SVWHILELT_COUNT  : SInst<"svwhilelt_{d}",  "}lli", "QcQsQiQl", MergeNone, 
"aarch64_sve_whilelt_{d}", [IsOverloadNone], [ImmCheck<2, ImmCheck2_4_Mul2>]>;
-def SVWHILELO_COUNT  : SInst<"svwhilelo_{d}",  "}nni", "QcQsQiQl", MergeNone, 
"aarch64_sve_whilelo_{d}", [IsOverloadNone], [ImmCheck<2, ImmCheck2_4_Mul2>]>;
-def SVWHILELS_COUNT  : SInst<"svwhilels_{d}",  "}nni", "QcQsQiQl", MergeNone, 
"aarch64_sve_whilels_{d}", [IsOverloadNone], [ImmCheck<2, ImmCheck2_4_Mul2>]>;
-def SVWHILEHI_COUNT  : SInst<"svwhilehi_{d}",  "}nni", "QcQsQiQl", MergeNone, 
"aarch64_sve_whilehi_{d}", [IsOverloadNone], [ImmCheck<2, ImmCheck2_4_Mul2>]>;
-def SVWHILEHS_COUNT  : SInst<"svwhilehs_{d}",  "}nni", "QcQsQiQl", MergeNone, 
"aarch64_sve_whilehs_{d}", [IsOverloadNone], [ImmCheck<2, ImmCheck2_4_Mul2>]>;
+def SVWHILEGE_COUNT  : SInst<"svwhilege_{d}[_{1}]",  "}lli", "QcQsQiQl", 
MergeNone, "aarch64_sve_whilege_{d}", [IsOverloadNone], [ImmCheck<2, 
ImmCheck2_4_Mul2>]>;
+def SVWHILEGT_COUNT  : SInst<"svwhilegt_{d}[_{1}]",  "}lli", "QcQsQiQl", 
MergeNone, "aarch64_sve_whilegt_{d}", [IsOverloadNone], [ImmCheck<2, 
ImmCheck2_4_Mul2>]>;
+def SVWHILELE_COUNT  : SInst<"svwhilele_{d}[_{1}]",  "}lli", "QcQsQiQl", 
MergeNone, "aarch64_sve_whilele_{d}", [IsOverloadNone], [ImmCheck<2, 
ImmCheck2_4_Mul2>]>;
+def SVWHILELT_COUNT  : SInst<"svwhilelt_{d}[_{1}]",  "}lli", "QcQsQiQl", 
MergeNone, "aarch64_sve_whilelt_{d}", [IsOverloadNone], [ImmCheck<2, 
ImmCheck2_4_Mul2>]>;
+def SVWHILELO_COUNT  : SInst<"svwhilelo_{d}[_{1}]",  "}nni", "QcQsQiQl", 
MergeNone, "aarch64_sve_whilelo_{d}", [IsOverloadNone], [ImmCheck<2, 
ImmCheck2_4_Mul2>]>;
+def SVWHILELS_COUNT  : SInst<"svwhilels_{d}[_{1}]",  "}nni", "QcQsQiQl", 
MergeNone, "aarch64_sve_whilels_{d}", [IsOverloadNone], [ImmCheck<2, 
ImmCheck2_4_Mul2>]>;
+def SVWHILEHI_COUNT  : SInst<"svwhilehi_{d}[_{1}]",  "}nni", "QcQsQiQl", 
MergeNone, "aarch64_sve_whilehi_{d}", [IsOverloadNone], [ImmCheck<2, 
ImmCheck2_4_Mul2>]>;
+def SVWHILEHS_COUNT  : SInst<"svwhilehs_{d}[_{1}]",  "}nni", "QcQsQiQl", 
MergeNone, "aarch64_sve_whilehs_{d}", [IsOverloadNone], [ImmCheck<2, 
ImmCheck2_4_Mul2>]>;
 

CarolineConcatto wrote:

The latest change in the ACLE now the signed and unsigned are represented in 
only one intrinsic.
Now we only have 4 intrinsics instead of 8, and they are:
   // All the intrinsics below are [SVE2.1 or SME2]
   // Variants are also available for:
   // _b16[_s64]_x2, _b32[_s64]_x2 and _b64[_s64]_x2$
   // _b8[_u64]_x2,  _b16[_u64]_x2, _b32[_u64]_x2 and _b64[_u64]_x2$
   svboolx2_t svwhilege_b8[_s64]_x2(int64_t rn, int64_t rm); 
   svboolx2_t svwhilegt_b8[_s64]_x2(int64_t rn, int64_t rm);
   svboolx2_t svwhilele_b8[_s64]_x2(int64_t rn, int64_t rm);
   svboolx2_t svwhilelt_b8[_s64]_x2(int64_t rn, int64_t rm);

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


[clang] [clang] Add per-global code model attribute (PR #72078)

2023-12-13 Thread via cfe-commits

heiher wrote:

> Overall this seems fine, thanks!
> 
> But I'm not sure if reporting a more generic "the model attribute is not 
> supported on this target" for non-LoongArch would be better: it doesn't give 
> the false impression that the target doesn't support the specified code model.

In my opinion I think this is better. I put it in a separate commit so we can 
easily revert it if someone thinks otherwise.

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


[clang] ed2d497 - [Clang][AArch64] Add fix vector types to header into SVE (#73258)

2023-12-13 Thread via cfe-commits

Author: CarolineConcatto
Date: 2023-12-13T08:59:41Z
New Revision: ed2d497291f0de330e27109ce21375b41597b4a4

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

LOG: [Clang][AArch64] Add  fix vector types to header into SVE (#73258)

This patch is needed for the reduction instructions in sve2.1
 It add a new header to sve with all the fixed vector types.
  The new types are only added if neon is not declared.

Added: 
clang/test/CodeGen/arm-vector_type-params-returns.c

Modified: 
clang/lib/Headers/CMakeLists.txt
clang/lib/Sema/SemaType.cpp
clang/test/Sema/aarch64-sve-intrinsics/acle_sve_target.cpp
clang/test/Sema/arm-vector-types-support.c
clang/test/SemaCUDA/neon-attrs.cu
clang/utils/TableGen/NeonEmitter.cpp
clang/utils/TableGen/SveEmitter.cpp
clang/utils/TableGen/TableGen.cpp
clang/utils/TableGen/TableGenBackends.h

Removed: 




diff  --git a/clang/lib/Headers/CMakeLists.txt 
b/clang/lib/Headers/CMakeLists.txt
index fdd54c05eedf82..f8fdd402777e48 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -387,6 +387,8 @@ if(ARM IN_LIST LLVM_TARGETS_TO_BUILD OR AArch64 IN_LIST 
LLVM_TARGETS_TO_BUILD)
   clang_generate_header(-gen-arm-mve-header arm_mve.td arm_mve.h)
   # Generate arm_cde.h
   clang_generate_header(-gen-arm-cde-header arm_cde.td arm_cde.h)
+  # Generate arm_vector_types.h
+  clang_generate_header(-gen-arm-vector-type arm_neon.td arm_vector_types.h)
 
   # Add headers to target specific lists
   list(APPEND arm_common_generated_files
@@ -403,6 +405,7 @@ if(ARM IN_LIST LLVM_TARGETS_TO_BUILD OR AArch64 IN_LIST 
LLVM_TARGETS_TO_BUILD)
 "${CMAKE_CURRENT_BINARY_DIR}/arm_sve.h"
 "${CMAKE_CURRENT_BINARY_DIR}/arm_sme_draft_spec_subject_to_change.h"
 "${CMAKE_CURRENT_BINARY_DIR}/arm_bf16.h"
+"${CMAKE_CURRENT_BINARY_DIR}/arm_vector_types.h"
 )
 endif()
 if(RISCV IN_LIST LLVM_TARGETS_TO_BUILD)

diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 83610503ed9b16..c8ad8b6237c829 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -8360,12 +8360,25 @@ static void HandleNeonVectorTypeAttr(QualType &CurType, 
const ParsedAttr &Attr,
   // not to need a separate attribute)
   if (!(S.Context.getTargetInfo().hasFeature("neon") ||
 S.Context.getTargetInfo().hasFeature("mve") ||
-IsTargetCUDAAndHostARM)) {
+S.Context.getTargetInfo().hasFeature("sve") ||
+S.Context.getTargetInfo().hasFeature("sme") ||
+IsTargetCUDAAndHostARM) &&
+  VecKind == VectorKind::Neon) {
+S.Diag(Attr.getLoc(), diag::err_attribute_unsupported)
+<< Attr << "'neon', 'mve', 'sve' or 'sme'";
+Attr.setInvalid();
+return;
+  }
+  if (!(S.Context.getTargetInfo().hasFeature("neon") ||
+S.Context.getTargetInfo().hasFeature("mve") ||
+IsTargetCUDAAndHostARM) &&
+  VecKind == VectorKind::NeonPoly) {
 S.Diag(Attr.getLoc(), diag::err_attribute_unsupported)
 << Attr << "'neon' or 'mve'";
 Attr.setInvalid();
 return;
   }
+
   // Check the attribute arguments.
   if (Attr.getNumArgs() != 1) {
 S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments)

diff  --git a/clang/test/CodeGen/arm-vector_type-params-returns.c 
b/clang/test/CodeGen/arm-vector_type-params-returns.c
new file mode 100644
index 00..61b617083515a7
--- /dev/null
+++ b/clang/test/CodeGen/arm-vector_type-params-returns.c
@@ -0,0 +1,134 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 3
+
+// RUN: %clang_cc1 -DSVE_HEADER -triple aarch64 -target-feature +sve 
-emit-llvm -O2 -o - %s | opt -S -passes=mem2reg,sroa | FileCheck %s
+// RUN: %clang_cc1 -DSVE_HEADER -triple aarch64-none-linux-gnu -target-feature 
+sve2p1 -S -disable-O0-optnone -Werror -Wall -o - /dev/null %s
+
+// RUN: %clang_cc1 -DNEON_HEADER -triple aarch64 -target-feature +sve 
-emit-llvm -O2 -o - %s | opt -S -passes=mem2reg,sroa | FileCheck %s
+// RUN: %clang_cc1 -DNEON_HEADER -triple aarch64-none-linux-gnu 
-target-feature +sve2p1 -S -disable-O0-optnone -Werror -Wall -o - /dev/null %s
+
+// RUN: %clang_cc1 -DSVE_HEADER -DNEON_HEADER -triple aarch64 -target-feature 
+sve -emit-llvm -O2 -o - %s | opt -S -passes=mem2reg,sroa | FileCheck %s
+// RUN: %clang_cc1 -DSVE_HEADER -DNEON_HEADER -triple aarch64-none-linux-gnu 
-target-feature +sve2p1 -S -disable-O0-optnone -Werror -Wall -o - /dev/null %s
+
+// RUN: %clang_cc1 -DNEON_HEADER -DSVE_HEADER2  -triple aarch64 
-target-feature +sve -emit-llvm -O2 -o - %s | opt -S -passes=mem2reg,sroa | 
FileCheck %s
+// RUN: %clang_cc1 -DNEON_HEADER -DSVE_HEADER2 -triple aarch64-none-linux-gnu 
-target-feature +sve2p1 -S -disable-O0-optnone -Werror -Wall -o - /

[clang] [llvm] [clang-tools-extra] [Clang][AArch64] Add fix vector types to header into SVE (PR #73258)

2023-12-13 Thread via cfe-commits

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


[clang] [clang][Interp] Don't diagnose undefined functions when checking... (PR #75051)

2023-12-13 Thread via cfe-commits

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


[clang] [clang][Interp] Don't diagnose undefined functions when checking... (PR #75051)

2023-12-13 Thread via cfe-commits

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

LGTM modulo typo

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


[clang] [clang][Interp] Don't diagnose undefined functions when checking... (PR #75051)

2023-12-13 Thread via cfe-commits


@@ -371,13 +366,21 @@ bool CheckCallable(InterpState &S, CodePtr OpPC, const 
Function *F) {
   // FIXME: If DiagDecl is an implicitly-declared special member function
   // or an inheriting constructor, we should be much more explicit about 
why
   // it's not constexpr.
-  if (CD && CD->isInheritingConstructor())
+  if (CD && CD->isInheritingConstructor()) {
 S.FFDiag(Loc, diag::note_constexpr_invalid_inhctor, 1)
   << CD->getInheritedConstructor().getConstructor()->getParent();
-  else
+S.Note(DiagDecl->getLocation(), diag::note_declared_at);
+  } else {
+// Don't emit anything if the function isn't defined and we're checking
+// for a constnat expression. It might be defined at the point we're

cor3ntin wrote:

```suggestion
// for a constant expression. It might be defined at the point we're
```

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


[clang] [clang][ASTImporter] Import AlignValueAttr correctly. (PR #75308)

2023-12-13 Thread Balázs Kéri via cfe-commits

https://github.com/balazske created 
https://github.com/llvm/llvm-project/pull/75308

Expression of attribute `align_value` was not imported. Import of the attribute 
is corrected, a test for it is added, other related tests with FIXME are 
updated.
Fixes #75054.

From 2e6fe315bdebea705d84b4152a831e5934b659eb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= 
Date: Wed, 13 Dec 2023 10:23:48 +0100
Subject: [PATCH] [clang][ASTImporter] Import AlignValueAttr correctly.

Expression of attribute `align_value` was not imported.
Import of the attribute is corrected, a test for it is added,
other related tests with FIXME are updated.
---
 clang/lib/AST/ASTImporter.cpp   |  6 +++
 clang/unittests/AST/ASTImporterTest.cpp | 69 +
 2 files changed, 30 insertions(+), 45 deletions(-)

diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index f1f335118f37a4..cc29f4356ad755 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -9101,6 +9101,12 @@ Expected ASTImporter::Import(const Attr 
*FromAttr) {
 break;
   }
 
+  case attr::AlignValue: {
+auto *From = cast(FromAttr);
+AI.importAttr(From, AI.importArg(From->getAlignment()).value());
+break;
+  }
+
   case attr::Format: {
 const auto *From = cast(FromAttr);
 AI.importAttr(From, Import(From->getType()), From->getFormatIdx(),
diff --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 4dd7510bf8ddf8..da47e6b6653095 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -7425,67 +7425,46 @@ void ImportAttributes::checkImported(const Decl 
*From, const Decl *To) {
 ToAST->getASTContext().getTranslationUnitDecl());
 }
 
-// FIXME: Use ImportAttributes for this test.
-TEST_P(ASTImporterOptionSpecificTestBase, ImportExprOfAlignmentAttr) {
-  // Test if import of these packed and aligned attributes does not trigger an
-  // error situation where source location from 'From' context is referenced in
-  // 'To' context through evaluation of the alignof attribute.
-  // This happens if the 'alignof(A)' expression is not imported correctly.
-  Decl *FromTU = getTuDecl(
+TEST_P(ImportAttributes, ImportAligned) {
+  AlignedAttr *FromAttr, *ToAttr;
+  importAttr(
   R"(
   struct __attribute__((packed)) A { int __attribute__((aligned(8))) X; };
-  struct alignas(alignof(A)) S {};
+  struct alignas(alignof(A)) test {};
   )",
-  Lang_CXX11, "input.cc");
-  auto *FromD = FirstDeclMatcher().match(
-  FromTU, cxxRecordDecl(hasName("S"), unless(isImplicit(;
-  ASSERT_TRUE(FromD);
-
-  auto *ToD = Import(FromD, Lang_CXX11);
-  ASSERT_TRUE(ToD);
-
-  auto *FromAttr = FromD->getAttr();
-  auto *ToAttr = ToD->getAttr();
-  EXPECT_EQ(FromAttr->isInherited(), ToAttr->isInherited());
-  EXPECT_EQ(FromAttr->isPackExpansion(), ToAttr->isPackExpansion());
-  EXPECT_EQ(FromAttr->isImplicit(), ToAttr->isImplicit());
-  EXPECT_EQ(FromAttr->getSyntax(), ToAttr->getSyntax());
-  EXPECT_EQ(FromAttr->getSemanticSpelling(), ToAttr->getSemanticSpelling());
-  EXPECT_TRUE(ToAttr->getAlignmentExpr());
+  FromAttr, ToAttr);
+  checkImported(FromAttr->getAlignmentExpr(), ToAttr->getAlignmentExpr());
 
   auto *ToA = FirstDeclMatcher().match(
-  ToD->getTranslationUnitDecl(),
+  ToAST->getASTContext().getTranslationUnitDecl(),
   cxxRecordDecl(hasName("A"), unless(isImplicit(;
   // Ensure that 'struct A' was imported (through reference from attribute of
   // 'S').
   EXPECT_TRUE(ToA);
 }
 
-// FIXME: Use ImportAttributes for this test.
-TEST_P(ASTImporterOptionSpecificTestBase, ImportFormatAttr) {
-  Decl *FromTU = getTuDecl(
+TEST_P(ImportAttributes, ImportAlignValue) {
+  AlignValueAttr *FromAttr, *ToAttr;
+  importAttr(
+  R"(
+  void *test __attribute__((align_value(64)));
+  )",
+  FromAttr, ToAttr);
+  checkImported(FromAttr->getAlignment(), ToAttr->getAlignment());
+}
+
+TEST_P(ImportAttributes, ImportFormat) {
+  FormatAttr *FromAttr, *ToAttr;
+  importAttr(
   R"(
-  int foo(const char * fmt, ...)
+  int test(const char * fmt, ...)
   __attribute__ ((__format__ (__scanf__, 1, 2)));
   )",
-  Lang_CXX03, "input.cc");
-  auto *FromD = FirstDeclMatcher().match(
-  FromTU, functionDecl(hasName("foo")));
-  ASSERT_TRUE(FromD);
+  FromAttr, ToAttr);
 
-  auto *ToD = Import(FromD, Lang_CXX03);
-  ASSERT_TRUE(ToD);
-  ToD->dump(); // Should not crash!
-
-  auto *FromAttr = FromD->getAttr();
-  auto *ToAttr = ToD->getAttr();
-  EXPECT_EQ(FromAttr->isInherited(), ToAttr->isInherited());
-  EXPECT_EQ(FromAttr->isPackExpansion(), ToAttr->isPackExpansion());
-  EXPECT_EQ(FromAttr->isImplicit(), ToAttr->isImplicit());
-  EXPECT_EQ(FromAttr->getSyntax(), ToAttr->getSyntax());
-  EXPECT_EQ(FromAttr->getAttributeSpellingListIndex(),
-ToAttr->getAttributeSpellingListIndex());
   EXPECT_EQ(F

[clang] [clang][ASTImporter] Import AlignValueAttr correctly. (PR #75308)

2023-12-13 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Balázs Kéri (balazske)


Changes

Expression of attribute `align_value` was not imported. Import of the attribute 
is corrected, a test for it is added, other related tests with FIXME are 
updated.
Fixes #75054.

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


2 Files Affected:

- (modified) clang/lib/AST/ASTImporter.cpp (+6) 
- (modified) clang/unittests/AST/ASTImporterTest.cpp (+24-45) 


``diff
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index f1f335118f37a..cc29f4356ad75 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -9101,6 +9101,12 @@ Expected ASTImporter::Import(const Attr 
*FromAttr) {
 break;
   }
 
+  case attr::AlignValue: {
+auto *From = cast(FromAttr);
+AI.importAttr(From, AI.importArg(From->getAlignment()).value());
+break;
+  }
+
   case attr::Format: {
 const auto *From = cast(FromAttr);
 AI.importAttr(From, Import(From->getType()), From->getFormatIdx(),
diff --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 4dd7510bf8ddf..da47e6b665309 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -7425,67 +7425,46 @@ void ImportAttributes::checkImported(const Decl 
*From, const Decl *To) {
 ToAST->getASTContext().getTranslationUnitDecl());
 }
 
-// FIXME: Use ImportAttributes for this test.
-TEST_P(ASTImporterOptionSpecificTestBase, ImportExprOfAlignmentAttr) {
-  // Test if import of these packed and aligned attributes does not trigger an
-  // error situation where source location from 'From' context is referenced in
-  // 'To' context through evaluation of the alignof attribute.
-  // This happens if the 'alignof(A)' expression is not imported correctly.
-  Decl *FromTU = getTuDecl(
+TEST_P(ImportAttributes, ImportAligned) {
+  AlignedAttr *FromAttr, *ToAttr;
+  importAttr(
   R"(
   struct __attribute__((packed)) A { int __attribute__((aligned(8))) X; };
-  struct alignas(alignof(A)) S {};
+  struct alignas(alignof(A)) test {};
   )",
-  Lang_CXX11, "input.cc");
-  auto *FromD = FirstDeclMatcher().match(
-  FromTU, cxxRecordDecl(hasName("S"), unless(isImplicit(;
-  ASSERT_TRUE(FromD);
-
-  auto *ToD = Import(FromD, Lang_CXX11);
-  ASSERT_TRUE(ToD);
-
-  auto *FromAttr = FromD->getAttr();
-  auto *ToAttr = ToD->getAttr();
-  EXPECT_EQ(FromAttr->isInherited(), ToAttr->isInherited());
-  EXPECT_EQ(FromAttr->isPackExpansion(), ToAttr->isPackExpansion());
-  EXPECT_EQ(FromAttr->isImplicit(), ToAttr->isImplicit());
-  EXPECT_EQ(FromAttr->getSyntax(), ToAttr->getSyntax());
-  EXPECT_EQ(FromAttr->getSemanticSpelling(), ToAttr->getSemanticSpelling());
-  EXPECT_TRUE(ToAttr->getAlignmentExpr());
+  FromAttr, ToAttr);
+  checkImported(FromAttr->getAlignmentExpr(), ToAttr->getAlignmentExpr());
 
   auto *ToA = FirstDeclMatcher().match(
-  ToD->getTranslationUnitDecl(),
+  ToAST->getASTContext().getTranslationUnitDecl(),
   cxxRecordDecl(hasName("A"), unless(isImplicit(;
   // Ensure that 'struct A' was imported (through reference from attribute of
   // 'S').
   EXPECT_TRUE(ToA);
 }
 
-// FIXME: Use ImportAttributes for this test.
-TEST_P(ASTImporterOptionSpecificTestBase, ImportFormatAttr) {
-  Decl *FromTU = getTuDecl(
+TEST_P(ImportAttributes, ImportAlignValue) {
+  AlignValueAttr *FromAttr, *ToAttr;
+  importAttr(
+  R"(
+  void *test __attribute__((align_value(64)));
+  )",
+  FromAttr, ToAttr);
+  checkImported(FromAttr->getAlignment(), ToAttr->getAlignment());
+}
+
+TEST_P(ImportAttributes, ImportFormat) {
+  FormatAttr *FromAttr, *ToAttr;
+  importAttr(
   R"(
-  int foo(const char * fmt, ...)
+  int test(const char * fmt, ...)
   __attribute__ ((__format__ (__scanf__, 1, 2)));
   )",
-  Lang_CXX03, "input.cc");
-  auto *FromD = FirstDeclMatcher().match(
-  FromTU, functionDecl(hasName("foo")));
-  ASSERT_TRUE(FromD);
+  FromAttr, ToAttr);
 
-  auto *ToD = Import(FromD, Lang_CXX03);
-  ASSERT_TRUE(ToD);
-  ToD->dump(); // Should not crash!
-
-  auto *FromAttr = FromD->getAttr();
-  auto *ToAttr = ToD->getAttr();
-  EXPECT_EQ(FromAttr->isInherited(), ToAttr->isInherited());
-  EXPECT_EQ(FromAttr->isPackExpansion(), ToAttr->isPackExpansion());
-  EXPECT_EQ(FromAttr->isImplicit(), ToAttr->isImplicit());
-  EXPECT_EQ(FromAttr->getSyntax(), ToAttr->getSyntax());
-  EXPECT_EQ(FromAttr->getAttributeSpellingListIndex(),
-ToAttr->getAttributeSpellingListIndex());
   EXPECT_EQ(FromAttr->getType()->getName(), ToAttr->getType()->getName());
+  EXPECT_EQ(FromAttr->getFirstArg(), ToAttr->getFirstArg());
+  EXPECT_EQ(FromAttr->getFormatIdx(), ToAttr->getFormatIdx());
 }
 
 TEST_P(ImportAttributes, ImportEnableIf) {

``




https://github.com/llvm/llvm-project/pull/75308
___

[clang] [Clang] Eagerly instantiate used constexpr function upon definition. (PR #73463)

2023-12-13 Thread Sam McCall via cfe-commits


@@ -4836,6 +4837,16 @@ ASTFileSignature ASTWriter::WriteASTCore(Sema &SemaRef, 
StringRef isysroot,
   assert(SemaRef.PendingLocalImplicitInstantiations.empty() &&
  "There are local ones at end of translation unit!");
 
+  // Build a record containing all pending instantiations of constexpr
+  // entities.
+  RecordData PendingInstantiationsOfConstexprEntities;
+  for (const auto &I : SemaRef.PendingInstantiationsOfConstexprEntities) {

sam-mccall wrote:

In case this will be relanded in some form:

This loop uses arbitrary hashtable order, leading to nondeterministic PCM 
output.

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


[clang] [OpenACC] Add 'clause' parsing infrastructure plus a few clauses (PR #75052)

2023-12-13 Thread via cfe-commits


@@ -69,6 +69,29 @@ OpenACCDirectiveKindEx getOpenACCDirectiveKind(Token Tok) {
   .Default(OpenACCDirectiveKindEx::Invalid);
 }
 
+// Translate single-token string representations to the OpenCC Clause Kind.
+OpenACCClauseKind getOpenACCClauseKind(Token Tok) {
+  // auto is a keyword in some language modes, so make sure we parse it
+  // correctly.
+  if (Tok.is(tok::kw_auto))
+return OpenACCClauseKind::Auto;
+
+  if (!Tok.is(tok::identifier))
+return OpenACCClauseKind::Invalid;
+
+  return llvm::StringSwitch(
+ Tok.getIdentifierInfo()->getName())
+  .Case("finalize", OpenACCClauseKind::Finalize)
+  .Case("if_present", OpenACCClauseKind::IfPresent)
+  .Case("seq", OpenACCClauseKind::Seq)
+  .Case("independent", OpenACCClauseKind::Independent)
+  .Case("auto", OpenACCClauseKind::Auto)
+  .Case("worker", OpenACCClauseKind::Worker)
+  .Case("vector", OpenACCClauseKind::Vector)
+  .Case("nohost", OpenACCClauseKind::NoHost)
+  .Default(OpenACCClauseKind::Invalid);
+}

cor3ntin wrote:

Can you sort alphabetically?

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


[clang] [OpenACC] Add 'clause' parsing infrastructure plus a few clauses (PR #75052)

2023-12-13 Thread via cfe-commits


@@ -208,6 +233,10 @@ OpenACCDirectiveKind ParseOpenACCDirectiveKind(Parser &P) {
   // introspect on the spelling before then.
   if (FirstTok.isNot(tok::identifier)) {
 P.Diag(FirstTok, diag::err_acc_missing_directive);
+
+if (!FirstTok.isAnnotation())
+  P.ConsumeAnyToken();

cor3ntin wrote:

I'm assuming that's for the end of pragma annotation. Shouldn't the test be 
more specific?

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


[clang] [OpenACC] Add 'clause' parsing infrastructure plus a few clauses (PR #75052)

2023-12-13 Thread via cfe-commits


@@ -262,12 +291,52 @@ OpenACCDirectiveKind ParseOpenACCDirectiveKind(Parser &P) 
{
   return DirKind;
 }
 
+bool ParseOpenACCClause(Parser &P) {

cor3ntin wrote:

Can you add a description of the grammar?

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


[clang] [OpenACC] Add 'clause' parsing infrastructure plus a few clauses (PR #75052)

2023-12-13 Thread via cfe-commits


@@ -69,6 +69,29 @@ OpenACCDirectiveKindEx getOpenACCDirectiveKind(Token Tok) {
   .Default(OpenACCDirectiveKindEx::Invalid);
 }
 
+// Translate single-token string representations to the OpenCC Clause Kind.
+OpenACCClauseKind getOpenACCClauseKind(Token Tok) {

cor3ntin wrote:

Should this be static (ditto for the rest of the functions in the files)

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


[clang] [clang][ASTImporter] skip TemplateTypeParmDecl in VisitTypeAliasTemplateDecl (PR #74919)

2023-12-13 Thread Qizhi Hu via cfe-commits

jcsxky wrote:

> The problem may be related to the fact that template parameter declarations 
> can have the `TranslationUnitDecl` as parent until the template (with these 
> parameters) is finally created. In the temporary phase the object 
> (`TemplateTypeParmDecl`) is found with lookup if it has the same name as an 
> other imported object. Does the crash happen if in the test code the 
> `TypeAliasTemplateDecl` is replaced with a plain `ClassTemplateDecl` or 
> `FunctionTemplateDecl`? If yes the change is needed at these import functions 
> too.


Replace `TypeAliasTemplateDecl` with `ClassTemplateDecl` or 
`FunctionTemplateDecl` has no problem and passed the test with following test 
code
```cpp
struct S;
template 
class Callable {};
template 
int bindingFunctionVTable;
```
and
```cpp
struct S;
template 
void Callable(){}
template 
int bindingFunctionVTable;
```
Test code seems good to current issue and the two you mentioned above can't be 
fixed with this pr. Should I abandon this pr or fix current issue only first?

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


[clang] [AArch64][SME] Warn when using a streaming builtin from a non-streaming function (PR #74064)

2023-12-13 Thread Sander de Smalen via cfe-commits


@@ -1694,6 +1697,61 @@ void SVEEmitter::createSMERangeChecks(raw_ostream &OS) {
   OS << "#endif\n\n";
 }
 
+void SVEEmitter::createStreamingAttrs(raw_ostream &OS, ACLEKind Kind) {
+  std::vector RV = Records.getAllDerivedDefinitions("Inst");
+  SmallVector, 128> Defs;
+  for (auto *R : RV)
+createIntrinsic(R, Defs);
+
+  // The mappings must be sorted based on BuiltinID.
+  llvm::sort(Defs, [](const std::unique_ptr &A,
+  const std::unique_ptr &B) {
+return A->getMangledName() < B->getMangledName();
+  });
+
+  switch (Kind) {

sdesmalen-arm wrote:

nit: Rather than having two of these switch statements, you could do:

```
StringRef ExtensionKind;
switch (Kind) {
case ACLEKind::SME:
  ExtensionKind = "SME";
  break;
case ACLEKind::SVE:
  ExtensionKind = "SVE";
  break;
}

OS << "#ifdef GET_" << ExtensionKind << "_STREAMING_ATTRS\n";
...
for (...) {
  ...
  OS << "case " << ExtensionKind << "::BI_builtin_" << ExtensionKind.lower() << 
"_";
  ...
}
```

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


[clang] [AArch64][SME] Warn when using a streaming builtin from a non-streaming function (PR #74064)

2023-12-13 Thread Sander de Smalen via cfe-commits


@@ -3168,9 +3167,60 @@ static void checkArmStreamingBuiltin(Sema &S, CallExpr 
*TheCall,
 << TheCall->getSourceRange() << "streaming compatible";
 return;
   }
+
+  if (FnType == ArmNonStreaming && BuiltinType == ArmStreaming) {
+S.Diag(TheCall->getBeginLoc(), 
diag::warn_attribute_arm_sm_incompat_builtin)
+<< TheCall->getSourceRange() << "non-streaming";
+  }
+}
+
+bool Sema::CheckSMEBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
+  if (const FunctionDecl *FD = getCurFunctionDecl()) {
+ArmStreamingType BuiltinType;
+
+switch (BuiltinID) {
+default:
+  BuiltinType = ArmNonStreaming;
+  break;
+#define GET_SME_STREAMING_ATTRS
+#include "clang/Basic/arm_sme_streaming_attrs.inc"
+#undef GET_SME_STREAMING_ATTRS
+#define GET_SVE_STREAMING_ATTRS
+#include "clang/Basic/arm_sve_streaming_attrs.inc"

sdesmalen-arm wrote:

The SVE streaming-mode attributes already checked in 
`CheckSVEBuiltinFunctionCall`, there is no need to include them here again.

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


[clang] [AArch64][SME] Warn when using a streaming builtin from a non-streaming function (PR #74064)

2023-12-13 Thread Sander de Smalen via cfe-commits


@@ -3168,9 +3167,60 @@ static void checkArmStreamingBuiltin(Sema &S, CallExpr 
*TheCall,
 << TheCall->getSourceRange() << "streaming compatible";
 return;
   }
+
+  if (FnType == ArmNonStreaming && BuiltinType == ArmStreaming) {
+S.Diag(TheCall->getBeginLoc(), 
diag::warn_attribute_arm_sm_incompat_builtin)
+<< TheCall->getSourceRange() << "non-streaming";
+  }
+}
+
+bool Sema::CheckSMEBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
+  if (const FunctionDecl *FD = getCurFunctionDecl()) {
+ArmStreamingType BuiltinType;
+
+switch (BuiltinID) {
+default:
+  BuiltinType = ArmNonStreaming;
+  break;
+#define GET_SME_STREAMING_ATTRS
+#include "clang/Basic/arm_sme_streaming_attrs.inc"
+#undef GET_SME_STREAMING_ATTRS
+#define GET_SVE_STREAMING_ATTRS
+#include "clang/Basic/arm_sve_streaming_attrs.inc"
+#undef GET_SVE_STREAMING_ATTRS
+}
+
+if (BuiltinType)
+  checkArmStreamingBuiltin(*this, TheCall, FD, BuiltinType);
+  }
+
+  // Range check SME intrinsics that take immediate values.
+  SmallVector, 3> ImmChecks;
+
+  switch (BuiltinID) {
+  default:
+return false;
+#define GET_SME_IMMEDIATE_CHECK
+#include "clang/Basic/arm_sme_sema_rangechecks.inc"

sdesmalen-arm wrote:

The SME range checks should be removed from `CheckSVEBuiltinFunctionCall` now.

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


[clang] d36f72b - [clang][Sema][NFC] Add a boolean parameter comment

2023-12-13 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-12-13T11:11:39+01:00
New Revision: d36f72b4187c3d934fd0558d174ad0c5ecafe140

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

LOG: [clang][Sema][NFC] Add a boolean parameter comment

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 19d972ed8ab2d..63854846f3d8c 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -15800,7 +15800,7 @@ Decl *Sema::ActOnSkippedFunctionBody(Decl *Decl) {
 }
 
 Decl *Sema::ActOnFinishFunctionBody(Decl *D, Stmt *BodyArg) {
-  return ActOnFinishFunctionBody(D, BodyArg, false);
+  return ActOnFinishFunctionBody(D, BodyArg, /*IsInstantiation=*/false);
 }
 
 /// RAII object that pops an ExpressionEvaluationContext when exiting a 
function



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


[clang] [clang][Interp] Don't diagnose undefined functions when checking... (PR #75051)

2023-12-13 Thread Timm Baeder via cfe-commits

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

>From b98a9d3a203bbcf56e81c7be7e2c011088095713 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Mon, 11 Dec 2023 15:08:32 +0100
Subject: [PATCH] [clang][Interp] Don't diagnose undefined functions when
 checking...

... for a potential constant expression. They are not defined now, but
might be defined later when the function is actually called.
---
 clang/lib/AST/Interp/Interp.cpp | 19 +++
 clang/test/AST/Interp/functions.cpp | 11 +++
 2 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 13b77e9a87725c..a82d1c3c7c622a 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -350,11 +350,6 @@ bool CheckCallable(InterpState &S, CodePtr OpPC, const 
Function *F) {
   }
 
   if (!F->isConstexpr()) {
-// Don't emit anything if we're checking for a potential constant
-// expression. That will happen later when actually executing.
-if (S.checkingPotentialConstantExpression())
-  return false;
-
 const SourceLocation &Loc = S.Current->getLocation(OpPC);
 if (S.getLangOpts().CPlusPlus11) {
   const FunctionDecl *DiagDecl = F->getDecl();
@@ -371,13 +366,21 @@ bool CheckCallable(InterpState &S, CodePtr OpPC, const 
Function *F) {
   // FIXME: If DiagDecl is an implicitly-declared special member function
   // or an inheriting constructor, we should be much more explicit about 
why
   // it's not constexpr.
-  if (CD && CD->isInheritingConstructor())
+  if (CD && CD->isInheritingConstructor()) {
 S.FFDiag(Loc, diag::note_constexpr_invalid_inhctor, 1)
   << CD->getInheritedConstructor().getConstructor()->getParent();
-  else
+S.Note(DiagDecl->getLocation(), diag::note_declared_at);
+  } else {
+// Don't emit anything if the function isn't defined and we're checking
+// for a constant expression. It might be defined at the point we're
+// actually calling it.
+if (!DiagDecl->isDefined() && S.checkingPotentialConstantExpression())
+  return false;
+
 S.FFDiag(Loc, diag::note_constexpr_invalid_function, 1)
   << DiagDecl->isConstexpr() << (bool)CD << DiagDecl;
-  S.Note(DiagDecl->getLocation(), diag::note_declared_at);
+S.Note(DiagDecl->getLocation(), diag::note_declared_at);
+  }
 } else {
   S.FFDiag(Loc, diag::note_invalid_subexpr_in_const_expr);
 }
diff --git a/clang/test/AST/Interp/functions.cpp 
b/clang/test/AST/Interp/functions.cpp
index ab562e70606b67..179a195098b132 100644
--- a/clang/test/AST/Interp/functions.cpp
+++ b/clang/test/AST/Interp/functions.cpp
@@ -267,6 +267,17 @@ namespace InvalidCall {
// ref-error {{must be initialized by a constant 
expression}} \
// ref-note {{in call to 'SS()'}}
 
+
+  /// This should not emit a diagnostic.
+  constexpr int f();
+  constexpr int a() {
+return f();
+  }
+  constexpr int f() {
+return 5;
+  }
+  static_assert(a() == 5, "");
+
 }
 
 namespace CallWithArgs {

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


[llvm] [clang] [ValueTracking] Add dominating condition support in computeKnownBits() (PR #73662)

2023-12-13 Thread Nikita Popov via cfe-commits

nikic wrote:

@eddyz87 Right, this is exactly the change I have been working on, see 
https://github.com/llvm/llvm-project/pull/75311. Unfortunately, it doesn't 
actually fix the BPF case, because that one involves a loop, and LVI is 
currently terrible at handling those. (Basically, even though the relevant 
condition is outside the loop, just querying something in the loop will form a 
cycle, which will be resolved to overdefined.)

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


[llvm] [clang] [LVI] Support using block values when handling conditions (PR #75311)

2023-12-13 Thread Nikita Popov via cfe-commits

https://github.com/nikic updated https://github.com/llvm/llvm-project/pull/75311

>From 0b4f9e03bf84ffc0a24bc609879c96db9b1d2833 Mon Sep 17 00:00:00 2001
From: Nikita Popov 
Date: Tue, 12 Dec 2023 15:55:29 +0100
Subject: [PATCH 1/2] [LVI] Support using block values when handling conditions

Currently, LVI will only use conditions like "X < C" to constrain
the value of X on the relevant edge. This patch extends it to
handle conditions like "X < Y" by querying the known range of Y.

This means that getValueFromCondition() and various related APIs
can now return nullopt to indicate that they have pushed to the
worklist, and need to be called again later. This behavior is
currently controlled by a UseBlockValue option, and only enabled
for actual edge value handling. All other places deriving
constraints from conditions keep using the previous logic for
now.
---
 llvm/lib/Analysis/LazyValueInfo.cpp   | 155 --
 .../cond-using-block-value.ll |   8 +-
 2 files changed, 110 insertions(+), 53 deletions(-)

diff --git a/llvm/lib/Analysis/LazyValueInfo.cpp 
b/llvm/lib/Analysis/LazyValueInfo.cpp
index 910f6b72afefe..88cf0dd2f36df 100644
--- a/llvm/lib/Analysis/LazyValueInfo.cpp
+++ b/llvm/lib/Analysis/LazyValueInfo.cpp
@@ -434,6 +434,28 @@ class LazyValueInfoImpl {
 
   void solve();
 
+  // For the following methods, if UseBlockValue is true, the function may
+  // push additional values to the worklist and return nullopt. If
+  // UseBlockValue is false, it will never return nullopt.
+
+  std::optional
+  getValueFromSimpleICmpCondition(CmpInst::Predicate Pred, Value *RHS,
+  const APInt &Offset, Instruction *CxtI,
+  bool UseBlockValue);
+
+  std::optional
+  getValueFromICmpCondition(Value *Val, ICmpInst *ICI, bool isTrueDest,
+bool UseBlockValue);
+
+  std::optional
+  getValueFromCondition(Value *Val, Value *Cond, bool IsTrueDest,
+bool UseBlockValue, unsigned Depth = 0);
+
+  std::optional getEdgeValueLocal(Value *Val,
+   BasicBlock *BBFrom,
+   BasicBlock *BBTo,
+   bool UseBlockValue);
+
 public:
   /// This is the query interface to determine the lattice value for the
   /// specified Value* at the context instruction (if specified) or at the
@@ -755,14 +777,10 @@ LazyValueInfoImpl::solveBlockValuePHINode(PHINode *PN, 
BasicBlock *BB) {
   return Result;
 }
 
-static ValueLatticeElement getValueFromCondition(Value *Val, Value *Cond,
- bool isTrueDest = true,
- unsigned Depth = 0);
-
 // If we can determine a constraint on the value given conditions assumed by
 // the program, intersect those constraints with BBLV
 void LazyValueInfoImpl::intersectAssumeOrGuardBlockValueConstantRange(
-Value *Val, ValueLatticeElement &BBLV, Instruction *BBI) {
+Value *Val, ValueLatticeElement &BBLV, Instruction *BBI) {
   BBI = BBI ? BBI : dyn_cast(Val);
   if (!BBI)
 return;
@@ -779,17 +797,21 @@ void 
LazyValueInfoImpl::intersectAssumeOrGuardBlockValueConstantRange(
 if (I->getParent() != BB || !isValidAssumeForContext(I, BBI))
   continue;
 
-BBLV = intersect(BBLV, getValueFromCondition(Val, I->getArgOperand(0)));
+BBLV = intersect(BBLV, *getValueFromCondition(Val, I->getArgOperand(0),
+  /*IsTrueDest*/ true,
+  /*UseBlockValue*/ false));
   }
 
   // If guards are not used in the module, don't spend time looking for them
   if (GuardDecl && !GuardDecl->use_empty() &&
   BBI->getIterator() != BB->begin()) {
-for (Instruction &I : 
make_range(std::next(BBI->getIterator().getReverse()),
- BB->rend())) {
+for (Instruction &I :
+ make_range(std::next(BBI->getIterator().getReverse()), BB->rend())) {
   Value *Cond = nullptr;
   if (match(&I, m_Intrinsic(m_Value(Cond
-BBLV = intersect(BBLV, getValueFromCondition(Val, Cond));
+BBLV = intersect(BBLV,
+ *getValueFromCondition(Val, Cond, /*IsTrueDest*/ true,
+/*UseBlockValue*/ false));
 }
   }
 
@@ -886,10 +908,14 @@ LazyValueInfoImpl::solveBlockValueSelect(SelectInst *SI, 
BasicBlock *BB) {
   // If the value is undef, a different value may be chosen in
   // the select condition.
   if (isGuaranteedNotToBeUndef(Cond, AC)) {
-TrueVal = intersect(TrueVal,
-getValueFromCondition(SI->getTrueValue(), Cond, true));
-FalseVal = intersect(
-FalseVal, getValueFromCondition(SI->getFalseValue(), Cond, false));
+TrueVal =
+intersect(TrueVal, *getValueFromCo

[llvm] [clang] [LVI] Support using block values when handling conditions (PR #75311)

2023-12-13 Thread Nikita Popov via cfe-commits

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


[clang] [clang][ASTImporter] skip TemplateTypeParmDecl in VisitTypeAliasTemplateDecl (PR #74919)

2023-12-13 Thread Balázs Kéri via cfe-commits

balazske wrote:

`VisitTypeAliasTemplateDecl` looks wrong and some fix should be made, this PR 
is good for the fix. This import function is different from the others because 
`ConflictingDecls` is populated when an object with different type is found, 
but this is the correct way. I think that `TemplateTypeParmDecl` objects are 
found with the lookup. A good fix would be to change the loop in 
`VisitTypeAliasTemplateDecl` to check for structural equivalence too, if 
equivalent is found use `MapImported`, otherwise add to `ConflictingDecls`. But 
skip all found objects that are not `TypeAliasTemplateDecl`. This makes it 
similar to the others, even if not correct, the remaining problem can be fixed 
later (and looks less important).

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


[clang] [llvm] [lld] [mlir] [libcxx] [compiler-rt] [lldb] [libc] [clang-tools-extra] [MLIR][LLVM] Add Continuous Loop Peeling transform to SCF (PR #71555)

2023-12-13 Thread via cfe-commits

https://github.com/muneebkhan85 updated 
https://github.com/llvm/llvm-project/pull/71555

>From 7bb2f9793b2a2cccbaa401f6e2ac850b587f2b59 Mon Sep 17 00:00:00 2001
From: Muneeb Khan 
Date: Tue, 7 Nov 2023 23:52:17 +0800
Subject: [PATCH 1/7] [MLIR][LLVM] Add Continuous Loop Peeling transform to SCF

This patch adds continuous loop peeling to scf loop transforms
in the MLIR backend. This transforms the target loop into a
chain of loops, with step sizes that are powers of two and
decrease exponetially across subsequent loops. Originally
authored by Litu Zhou litu.z...@huawei.com.
---
 .../SCF/TransformOps/SCFTransformOps.td   |  36 +
 .../SCF/TransformOps/SCFTransformOps.cpp  | 147 ++
 .../Dialect/SCF/loop-continuous-peel.mlir |  98 
 3 files changed, 281 insertions(+)
 create mode 100644 mlir/test/Dialect/SCF/loop-continuous-peel.mlir

diff --git a/mlir/include/mlir/Dialect/SCF/TransformOps/SCFTransformOps.td 
b/mlir/include/mlir/Dialect/SCF/TransformOps/SCFTransformOps.td
index 14df7e23a430f..e3d79a7f0ae40 100644
--- a/mlir/include/mlir/Dialect/SCF/TransformOps/SCFTransformOps.td
+++ b/mlir/include/mlir/Dialect/SCF/TransformOps/SCFTransformOps.td
@@ -147,6 +147,42 @@ def LoopPeelOp : Op {
+  let description = [{
+Transforms the loop into a chain of loops, with step sizes that are
+powers of two and decrease exponetially across subsequent loops.
+The transform is similar to loop.peel in the effect that it creates a loop
+with a step (that is power of 2) to divide the range evenly, with the
+difference that the remaining iterations are spread across similar loops
+with exponentially decreasing step sizes, with the last loop with step size
+of 2^0 = 1.
+
+ Return modes
+
+This operation consumes the `target` handles and produces the
+continuously-peeled loop.
+  }];
+
+  let arguments =
+  (ins TransformHandleTypeInterface:$target,
+   DefaultValuedAttr:$single_iter_opt);
+  // TODO: Return both the peeled loop and the remainder loop.
+  let results = (outs TransformHandleTypeInterface:$transformed);
+
+  let assemblyFormat =
+"$target attr-dict `:` functional-type(operands, results)";
+
+  let extraClassDeclaration = [{
+::mlir::DiagnosedSilenceableFailure applyToOne(
+::mlir::transform::TransformRewriter &rewriter,
+::mlir::Operation *target,
+::mlir::transform::ApplyToEachResultList &results,
+::mlir::transform::TransformState &state);
+  }];
+}
+
 def LoopPipelineOp : Op {
diff --git a/mlir/lib/Dialect/SCF/TransformOps/SCFTransformOps.cpp 
b/mlir/lib/Dialect/SCF/TransformOps/SCFTransformOps.cpp
index 62370604142cd..dcba6a8b406b2 100644
--- a/mlir/lib/Dialect/SCF/TransformOps/SCFTransformOps.cpp
+++ b/mlir/lib/Dialect/SCF/TransformOps/SCFTransformOps.cpp
@@ -206,6 +206,153 @@ 
transform::LoopPeelOp::applyToOne(transform::TransformRewriter &rewriter,
   return DiagnosedSilenceableFailure::success();
 }
 
+//===-===//
+// LoopContinuousPeelOp
+//===-===//
+
+static LogicalResult splitLoopHelper(RewriterBase &b, scf::ForOp &forOp,
+ scf::ForOp &partialIteration,
+ Value &splitBound) {
+  RewriterBase::InsertionGuard guard(b);
+  auto lbInt = getConstantIntValue(forOp.getLowerBound());
+  auto ubInt = getConstantIntValue(forOp.getUpperBound());
+  auto stepInt = getConstantIntValue(forOp.getStep());
+
+  // No specialization necessary if step already divides upper bound evenly.
+  if (lbInt && ubInt && stepInt && (*ubInt - *lbInt) % *stepInt == 0)
+return failure();
+  // No specialization necessary if step size is 1.
+  if (stepInt == static_cast(1))
+return failure();
+
+  // Create ForOp for partial iteration.
+  b.setInsertionPointAfter(forOp);
+  partialIteration = cast(b.clone(*forOp.getOperation()));
+  partialIteration.getLowerBoundMutable().assign(splitBound);
+  forOp.replaceAllUsesWith(partialIteration->getResults());
+  partialIteration.getInitArgsMutable().assign(forOp->getResults());
+
+  // Set new upper loop bound.
+  b.updateRootInPlace(
+  forOp, [&]() { forOp.getUpperBoundMutable().assign(splitBound); });
+
+  return success();
+}
+
+static scf::IfOp convertSingleIterFor(RewriterBase &b, scf::ForOp &forOp) {
+  Location loc = forOp->getLoc();
+  IRMapping mapping;
+  mapping.map(forOp.getInductionVar(), forOp.getLowerBound());
+  for (auto [arg, operand] :
+   llvm::zip(forOp.getRegionIterArgs(), forOp.getInitsMutable())) {
+mapping.map(arg, operand.get());
+  }
+  b.setInsertionPoint(forOp);
+  auto cond =
+  b.create(loc, arith::CmpIPredicate::slt,
+  forOp.getLowerBound(), forOp.getUpperBound());
+  auto ifOp = b.create(loc, forOp->getResultTypes(), cond, true);
+  // then branch
+  b.setInsertionP

[clang] effd47e - [Clang][AArch64] Add REQUIRES to new test

2023-12-13 Thread Jay Foad via cfe-commits

Author: Jay Foad
Date: 2023-12-13T10:49:52Z
New Revision: effd47ed45e3badd756103346a7c3b9e1e939e5e

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

LOG: [Clang][AArch64] Add REQUIRES to new test

Added: 


Modified: 
clang/test/CodeGen/arm-vector_type-params-returns.c

Removed: 




diff  --git a/clang/test/CodeGen/arm-vector_type-params-returns.c 
b/clang/test/CodeGen/arm-vector_type-params-returns.c
index 61b617083515a7..14c3512ab81a9f 100644
--- a/clang/test/CodeGen/arm-vector_type-params-returns.c
+++ b/clang/test/CodeGen/arm-vector_type-params-returns.c
@@ -12,6 +12,8 @@
 // RUN: %clang_cc1 -DNEON_HEADER -DSVE_HEADER2  -triple aarch64 
-target-feature +sve -emit-llvm -O2 -o - %s | opt -S -passes=mem2reg,sroa | 
FileCheck %s
 // RUN: %clang_cc1 -DNEON_HEADER -DSVE_HEADER2 -triple aarch64-none-linux-gnu 
-target-feature +sve2p1 -S -disable-O0-optnone -Werror -Wall -o - /dev/null %s
 
+// REQUIRES: aarch64-registered-target
+
 #ifdef SVE_HEADER
   #include 
 #endif



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


[llvm] [clang] [clang-tools-extra] [Clang][AArch64] Add fix vector types to header into SVE (PR #73258)

2023-12-13 Thread Jay Foad via cfe-commits


@@ -0,0 +1,134 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 3
+
+// RUN: %clang_cc1 -DSVE_HEADER -triple aarch64 -target-feature +sve 
-emit-llvm -O2 -o - %s | opt -S -passes=mem2reg,sroa | FileCheck %s
+// RUN: %clang_cc1 -DSVE_HEADER -triple aarch64-none-linux-gnu -target-feature 
+sve2p1 -S -disable-O0-optnone -Werror -Wall -o - /dev/null %s
+
+// RUN: %clang_cc1 -DNEON_HEADER -triple aarch64 -target-feature +sve 
-emit-llvm -O2 -o - %s | opt -S -passes=mem2reg,sroa | FileCheck %s
+// RUN: %clang_cc1 -DNEON_HEADER -triple aarch64-none-linux-gnu 
-target-feature +sve2p1 -S -disable-O0-optnone -Werror -Wall -o - /dev/null %s
+
+// RUN: %clang_cc1 -DSVE_HEADER -DNEON_HEADER -triple aarch64 -target-feature 
+sve -emit-llvm -O2 -o - %s | opt -S -passes=mem2reg,sroa | FileCheck %s
+// RUN: %clang_cc1 -DSVE_HEADER -DNEON_HEADER -triple aarch64-none-linux-gnu 
-target-feature +sve2p1 -S -disable-O0-optnone -Werror -Wall -o - /dev/null %s
+
+// RUN: %clang_cc1 -DNEON_HEADER -DSVE_HEADER2  -triple aarch64 
-target-feature +sve -emit-llvm -O2 -o - %s | opt -S -passes=mem2reg,sroa | 
FileCheck %s
+// RUN: %clang_cc1 -DNEON_HEADER -DSVE_HEADER2 -triple aarch64-none-linux-gnu 
-target-feature +sve2p1 -S -disable-O0-optnone -Werror -Wall -o - /dev/null %s
+

jayfoad wrote:

I've just added a `REQUIRES` line to this test in 
effd47ed45e3badd756103346a7c3b9e1e939e5e since it was failing in my AMDGPU-only 
build.

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


[clang] [clang][dataflow] Strengthen pointer comparison. (PR #75170)

2023-12-13 Thread via cfe-commits

https://github.com/martinboehme updated 
https://github.com/llvm/llvm-project/pull/75170

>From 32fe6eb51c43e423e50178509a8020d392cd3a42 Mon Sep 17 00:00:00 2001
From: Martin Braenne 
Date: Wed, 13 Dec 2023 10:46:43 +
Subject: [PATCH 1/2] [clang][dataflow] Strengthen pointer comparison.

-  Instead of comparing the identity of the `PointerValue`s, compare the
   underlying `StorageLocation`s.

-  If the `StorageLocation`s are different, return a definite "false" as the
   result of the comparison. Before, if the `PointerValue`s were different, the
   best we could do was to return an atom (because the `StorageLocation`s might
   still be the same).

On an internal codebase, this change reduces SAT solver timeouts by over 20% and
"maximum iterations reached" errors by over 50%. In addition, it obviously
improves the precision of the analysis.

@Xazax-hun inspired me to think about this with his
[comments](https://github.com/llvm/llvm-project/pull/73860#pullrequestreview-1761484615)
on a different PR.

The one thing where the new code currently does the wrong thing is when
comparing the addresses of different members of a union. By the language
standard, all members of a union should have the same address, but we currently
model them with different `StorageLocation`s, and so with this change, we will
return false when comparing the addreses.

I propose that this is acceptable because is unlikely to affect the behavior of
real-world code in meaningful ways.

With this change, the test TransferTest.DifferentReferenceLocInJoin started to
fail because the code under test no longer set up the desired state where a
variable of reference type is mapped to two different storage locations in
environments being joined. Rather than trying to modify this test to set up the
test condition again, I have chosen to replace the test with an equivalent
test in DataflowEnvironmentTest.cpp that sets up the test condition directly;
because this test is more direct, it will also be less brittle in the face of
future changes.
---
 clang/lib/Analysis/FlowSensitive/Transfer.cpp |   5 +
 .../FlowSensitive/DataflowEnvironmentTest.cpp |  42 +++
 .../Analysis/FlowSensitive/TransferTest.cpp   | 104 ++
 3 files changed, 107 insertions(+), 44 deletions(-)

diff --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp 
b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
index bbf5f12359bc7..55db15e03b39c 100644
--- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -60,6 +60,11 @@ static BoolValue &evaluateBooleanEquality(const Expr &LHS, 
const Expr &RHS,
 if (auto *RHSBool = dyn_cast_or_null(RHSValue))
   return Env.makeIff(*LHSBool, *RHSBool);
 
+  if (auto *LHSPtr = dyn_cast_or_null(LHSValue))
+if (auto *RHSPtr = dyn_cast_or_null(RHSValue))
+  return Env.getBoolLiteralValue(&LHSPtr->getPointeeLoc() ==
+ &RHSPtr->getPointeeLoc());
+
   return Env.makeAtomicBoolValue();
 }
 
diff --git a/clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
index 003434a58b107..de18f7de02c12 100644
--- a/clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
@@ -24,6 +24,7 @@ namespace {
 
 using namespace clang;
 using namespace dataflow;
+using ::clang::dataflow::test::findValueDecl;
 using ::clang::dataflow::test::getFieldValue;
 using ::testing::Contains;
 using ::testing::IsNull;
@@ -152,6 +153,47 @@ TEST_F(EnvironmentTest, JoinRecords) {
   }
 }
 
+TEST_F(EnvironmentTest, DifferentReferenceLocInJoin) {
+  // This tests the case where the storage location for a reference-type
+  // variable is different for two states being joined. We used to believe this
+  // could not happen and therefore had an assertion disallowing this; this 
test
+  // exists to demonstrate that we can handle this condition without a failing
+  // assertion. See also the discussion here:
+  // https://discourse.llvm.org/t/70086/6
+
+  using namespace ast_matchers;
+
+  std::string Code = R"cc(
+void f(int &ref) {}
+  )cc";
+
+  auto Unit =
+  tooling::buildASTFromCodeWithArgs(Code, {"-fsyntax-only", "-std=c++11"});
+  auto &Context = Unit->getASTContext();
+
+  ASSERT_EQ(Context.getDiagnostics().getClient()->getNumErrors(), 0U);
+
+  const ValueDecl *Ref = findValueDecl(Context, "ref");
+
+  Environment Env1(DAContext);
+  StorageLocation &Loc1 = Env1.createStorageLocation(Context.IntTy);
+  Env1.setStorageLocation(*Ref, Loc1);
+
+  Environment Env2(DAContext);
+  StorageLocation &Loc2 = Env2.createStorageLocation(Context.IntTy);
+  Env2.setStorageLocation(*Ref, Loc2);
+
+  EXPECT_NE(&Loc1, &Loc2);
+
+  Environment::ValueModel Model;
+  Environment EnvJoined = Environment::join(Env1, Env2, Model);
+
+  // Joining environments with different storage locations for the same
+  // declara

[clang] [clang][dataflow] Strengthen pointer comparison. (PR #75170)

2023-12-13 Thread via cfe-commits


@@ -3893,6 +3893,66 @@ TEST(TransferTest, BooleanInequality) {
   });
 }
 
+TEST(TransferTest, PointerEquality) {

martinboehme wrote:

Good point -- done.

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


[clang] [clang][dataflow] Strengthen pointer comparison. (PR #75170)

2023-12-13 Thread via cfe-commits


@@ -152,6 +153,47 @@ TEST_F(EnvironmentTest, JoinRecords) {
   }
 }
 
+TEST_F(EnvironmentTest, DifferentReferenceLocInJoin) {

martinboehme wrote:

Agree. The original test case was minimized from a failing assertion, but it 
would likely be fiddly to try and recreate a test case that triggers this 
again. Testing directly also has the benefit of being less brittle, so I think 
it's an acceptable tradeoff in this case.

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


[clang] [clang][dataflow] Strengthen pointer comparison. (PR #75170)

2023-12-13 Thread via cfe-commits

martinboehme wrote:

> An alternative approach would be to do [hash 
> consing](https://en.wikipedia.org/wiki/Hash_consing). Since pointer values 
> are completely determined by the pointee (for some definition of the pointee, 
> e.g., we might have `void*` and `int*` pointers pointing to the same storage 
> location), we could have a single representation for all of the equal pointer 
> values and continue to rely on identity. This can also be beneficial for 
> memory consumption, but we have to pay for that by making value creation a 
> bit more expensive (and the pointer values needs to be immutable).
> 
> That being said, this would be a bit of a departure from the current 
> architecture, so I think even if we want to do this, it should be a separate 
> PR.

Thanks, these are good points.

I think we may want to revisit multiple aspects of pointer values and storage 
locations at some point. For example, storage locations always have a type, and 
so storage locations of different types necessarily compare different. For 
example:

```cxx
struct Base {};
struct Derived : public Base {};
Derived d;
Derived *p_derived = &d;
Base *p_base = d;

// `p_derived == p_base` should hold, but the framework assumes `p_derived != 
p_base`.
```

It's probably a good thing for storage locations to have types (because we want 
to be able to model the dynamic type of an object), but this probably means 
that we want to model addresses separately from storage locations. This would 
then also help in other cases, such as union members and pointer 
interconvertibility. But all of this would be a major undertaking, I think.

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


[clang] [llvm] [clang-tools-extra] [Clang][AArch64] Add fix vector types to header into SVE (PR #73258)

2023-12-13 Thread via cfe-commits


@@ -0,0 +1,134 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 3
+
+// RUN: %clang_cc1 -DSVE_HEADER -triple aarch64 -target-feature +sve 
-emit-llvm -O2 -o - %s | opt -S -passes=mem2reg,sroa | FileCheck %s
+// RUN: %clang_cc1 -DSVE_HEADER -triple aarch64-none-linux-gnu -target-feature 
+sve2p1 -S -disable-O0-optnone -Werror -Wall -o - /dev/null %s
+
+// RUN: %clang_cc1 -DNEON_HEADER -triple aarch64 -target-feature +sve 
-emit-llvm -O2 -o - %s | opt -S -passes=mem2reg,sroa | FileCheck %s
+// RUN: %clang_cc1 -DNEON_HEADER -triple aarch64-none-linux-gnu 
-target-feature +sve2p1 -S -disable-O0-optnone -Werror -Wall -o - /dev/null %s
+
+// RUN: %clang_cc1 -DSVE_HEADER -DNEON_HEADER -triple aarch64 -target-feature 
+sve -emit-llvm -O2 -o - %s | opt -S -passes=mem2reg,sroa | FileCheck %s
+// RUN: %clang_cc1 -DSVE_HEADER -DNEON_HEADER -triple aarch64-none-linux-gnu 
-target-feature +sve2p1 -S -disable-O0-optnone -Werror -Wall -o - /dev/null %s
+
+// RUN: %clang_cc1 -DNEON_HEADER -DSVE_HEADER2  -triple aarch64 
-target-feature +sve -emit-llvm -O2 -o - %s | opt -S -passes=mem2reg,sroa | 
FileCheck %s
+// RUN: %clang_cc1 -DNEON_HEADER -DSVE_HEADER2 -triple aarch64-none-linux-gnu 
-target-feature +sve2p1 -S -disable-O0-optnone -Werror -Wall -o - /dev/null %s
+

CarolineConcatto wrote:

Thank you.
I will fix that!

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


[lld] [clang-tools-extra] [lldb] [libcxx] [mlir] [openmp] [flang] [libcxxabi] [clang] [llvm] [libc] [compiler-rt] [libc++] Fix `take_view::__sentinel`'s `operator==` (PR #74655)

2023-12-13 Thread via cfe-commits

huixie90 wrote:

Hi, could you please apply clang-format to the lines you changed and I am going 
to merge it after that

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


[clang] a897700 - [clang][Interp] Don't diagnose undefined functions when checking... (#75051)

2023-12-13 Thread via cfe-commits

Author: Timm Baeder
Date: 2023-12-13T12:14:53+01:00
New Revision: a8977005b64986139e92b5a43e44cfac2bf81677

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

LOG: [clang][Interp] Don't diagnose undefined functions when checking... 
(#75051)

... for a potential constant expression. They are not defined now, but
might be defined later when the function is actually called.

Added: 


Modified: 
clang/lib/AST/Interp/Interp.cpp
clang/test/AST/Interp/functions.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 13b77e9a87725c..a82d1c3c7c622a 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -350,11 +350,6 @@ bool CheckCallable(InterpState &S, CodePtr OpPC, const 
Function *F) {
   }
 
   if (!F->isConstexpr()) {
-// Don't emit anything if we're checking for a potential constant
-// expression. That will happen later when actually executing.
-if (S.checkingPotentialConstantExpression())
-  return false;
-
 const SourceLocation &Loc = S.Current->getLocation(OpPC);
 if (S.getLangOpts().CPlusPlus11) {
   const FunctionDecl *DiagDecl = F->getDecl();
@@ -371,13 +366,21 @@ bool CheckCallable(InterpState &S, CodePtr OpPC, const 
Function *F) {
   // FIXME: If DiagDecl is an implicitly-declared special member function
   // or an inheriting constructor, we should be much more explicit about 
why
   // it's not constexpr.
-  if (CD && CD->isInheritingConstructor())
+  if (CD && CD->isInheritingConstructor()) {
 S.FFDiag(Loc, diag::note_constexpr_invalid_inhctor, 1)
   << CD->getInheritedConstructor().getConstructor()->getParent();
-  else
+S.Note(DiagDecl->getLocation(), diag::note_declared_at);
+  } else {
+// Don't emit anything if the function isn't defined and we're checking
+// for a constant expression. It might be defined at the point we're
+// actually calling it.
+if (!DiagDecl->isDefined() && S.checkingPotentialConstantExpression())
+  return false;
+
 S.FFDiag(Loc, diag::note_constexpr_invalid_function, 1)
   << DiagDecl->isConstexpr() << (bool)CD << DiagDecl;
-  S.Note(DiagDecl->getLocation(), diag::note_declared_at);
+S.Note(DiagDecl->getLocation(), diag::note_declared_at);
+  }
 } else {
   S.FFDiag(Loc, diag::note_invalid_subexpr_in_const_expr);
 }

diff  --git a/clang/test/AST/Interp/functions.cpp 
b/clang/test/AST/Interp/functions.cpp
index ab562e70606b67..179a195098b132 100644
--- a/clang/test/AST/Interp/functions.cpp
+++ b/clang/test/AST/Interp/functions.cpp
@@ -267,6 +267,17 @@ namespace InvalidCall {
// ref-error {{must be initialized by a constant 
expression}} \
// ref-note {{in call to 'SS()'}}
 
+
+  /// This should not emit a diagnostic.
+  constexpr int f();
+  constexpr int a() {
+return f();
+  }
+  constexpr int f() {
+return 5;
+  }
+  static_assert(a() == 5, "");
+
 }
 
 namespace CallWithArgs {



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


[clang] [clang][Interp] Don't diagnose undefined functions when checking... (PR #75051)

2023-12-13 Thread Timm Baeder via cfe-commits

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


[clang] [AArch64][SME] Warn when using a streaming builtin from a non-streaming function (PR #74064)

2023-12-13 Thread Sam Tebbs via cfe-commits


@@ -1694,6 +1697,61 @@ void SVEEmitter::createSMERangeChecks(raw_ostream &OS) {
   OS << "#endif\n\n";
 }
 
+void SVEEmitter::createStreamingAttrs(raw_ostream &OS, ACLEKind Kind) {
+  std::vector RV = Records.getAllDerivedDefinitions("Inst");
+  SmallVector, 128> Defs;
+  for (auto *R : RV)
+createIntrinsic(R, Defs);
+
+  // The mappings must be sorted based on BuiltinID.
+  llvm::sort(Defs, [](const std::unique_ptr &A,
+  const std::unique_ptr &B) {
+return A->getMangledName() < B->getMangledName();
+  });
+
+  switch (Kind) {

SamTebbs33 wrote:

That looks nice and clean to me. Thanks for the suggestion.

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


[clang] [AArch64][SME] Warn when using a streaming builtin from a non-streaming function (PR #74064)

2023-12-13 Thread Sam Tebbs via cfe-commits


@@ -3168,9 +3167,60 @@ static void checkArmStreamingBuiltin(Sema &S, CallExpr 
*TheCall,
 << TheCall->getSourceRange() << "streaming compatible";
 return;
   }
+
+  if (FnType == ArmNonStreaming && BuiltinType == ArmStreaming) {
+S.Diag(TheCall->getBeginLoc(), 
diag::warn_attribute_arm_sm_incompat_builtin)
+<< TheCall->getSourceRange() << "non-streaming";
+  }
+}
+
+bool Sema::CheckSMEBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
+  if (const FunctionDecl *FD = getCurFunctionDecl()) {
+ArmStreamingType BuiltinType;
+
+switch (BuiltinID) {
+default:
+  BuiltinType = ArmNonStreaming;
+  break;
+#define GET_SME_STREAMING_ATTRS
+#include "clang/Basic/arm_sme_streaming_attrs.inc"
+#undef GET_SME_STREAMING_ATTRS
+#define GET_SVE_STREAMING_ATTRS
+#include "clang/Basic/arm_sve_streaming_attrs.inc"

SamTebbs33 wrote:

Good spot, thanks.

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


[clang] [llvm] [clang-tools-extra] [AArch64] Add an AArch64 pass for loop idiom transformations (PR #72273)

2023-12-13 Thread David Green via cfe-commits


@@ -0,0 +1,839 @@
+//===- AArch64LoopIdiomTransform.cpp - Loop idiom recognition 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This pass implements a pass that recognizes certain loop idioms and
+// transforms them into more optimized versions of the same loop. In cases
+// where this happens, it can be a significant performance win.
+//
+// We currently only recognize one loop that finds the first mismatched byte
+// in an array and returns the index, i.e. something like:
+//
+//  while (++i != n) {
+//if (a[i] != b[i])
+//  break;
+//  }
+//
+// In this example we can actually vectorize the loop despite the early exit,
+// although the loop vectorizer does not support it. It requires some extra
+// checks to deal with the possibility of faulting loads when crossing page
+// boundaries. However, even with these checks it is still profitable to do the
+// transformation.
+//
+//===--===//
+//
+// TODO List:
+//
+// * When optimizing for code size we may want to avoid some transformations.
+// * We can also support the inverse case where we scan for a matching element.
+//
+//===--===//
+
+#include "AArch64LoopIdiomTransform.h"
+#include "llvm/Analysis/DomTreeUpdater.h"
+#include "llvm/Analysis/LoopPass.h"
+#include "llvm/Analysis/TargetTransformInfo.h"
+#include "llvm/IR/Dominators.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/Intrinsics.h"
+#include "llvm/IR/MDBuilder.h"
+#include "llvm/IR/PatternMatch.h"
+#include "llvm/InitializePasses.h"
+#include "llvm/Transforms/Utils/BasicBlockUtils.h"
+
+using namespace llvm;
+
+#define DEBUG_TYPE "aarch64-loop-idiom-transform"
+
+static cl::opt
+DisableAll("disable-aarch64-lit-all", cl::Hidden, cl::init(false),
+   cl::desc("Disable AArch64 Loop Idiom Transform Pass."));
+
+static cl::opt DisableByteCmp(
+"disable-aarch64-lit-bytecmp", cl::Hidden, cl::init(false),
+cl::desc("Proceed with AArch64 Loop Idiom Transform Pass, but do "
+ "not convert byte-compare loop(s)."));
+
+static cl::opt VerifyLoops(
+"aarch64-lit-verify", cl::Hidden, cl::init(false),
+cl::desc("Verify loops generated AArch64 Loop Idiom Transform Pass."));
+
+namespace llvm {
+
+void initializeAArch64LoopIdiomTransformLegacyPassPass(PassRegistry &);
+Pass *createAArch64LoopIdiomTransformPass();
+
+} // end namespace llvm
+
+namespace {
+
+class AArch64LoopIdiomTransform {
+  Loop *CurLoop = nullptr;
+  DominatorTree *DT;
+  LoopInfo *LI;
+  const TargetTransformInfo *TTI;
+  const DataLayout *DL;
+
+public:
+  explicit AArch64LoopIdiomTransform(DominatorTree *DT, LoopInfo *LI,
+ const TargetTransformInfo *TTI,
+ const DataLayout *DL)
+  : DT(DT), LI(LI), TTI(TTI), DL(DL) {}
+
+  bool run(Loop *L);
+
+private:
+  /// \name Countable Loop Idiom Handling
+  /// @{
+
+  bool runOnCountableLoop();
+  bool runOnLoopBlock(BasicBlock *BB, const SCEV *BECount,
+  SmallVectorImpl &ExitBlocks);
+
+  bool recognizeByteCompare();
+  Value *expandFindMismatch(IRBuilder<> &Builder, GetElementPtrInst *GEPA,
+GetElementPtrInst *GEPB, Value *Start,
+Value *MaxLen);
+  void transformByteCompare(GetElementPtrInst *GEPA, GetElementPtrInst *GEPB,
+Value *MaxLen, Value *Index, Value *Start,
+bool IncIdx, BasicBlock *FoundBB,
+BasicBlock *EndBB);
+  /// @}
+};
+
+class AArch64LoopIdiomTransformLegacyPass : public LoopPass {
+public:
+  static char ID;
+
+  explicit AArch64LoopIdiomTransformLegacyPass() : LoopPass(ID) {
+initializeAArch64LoopIdiomTransformLegacyPassPass(
+*PassRegistry::getPassRegistry());
+  }
+
+  StringRef getPassName() const override {
+return "Transform AArch64-specific loop idioms";
+  }
+
+  void getAnalysisUsage(AnalysisUsage &AU) const override {
+AU.addRequired();
+AU.addRequired();
+AU.addRequired();
+  }
+
+  bool runOnLoop(Loop *L, LPPassManager &LPM) override;
+};
+
+bool AArch64LoopIdiomTransformLegacyPass::runOnLoop(Loop *L,
+LPPassManager &LPM) {
+
+  if (skipLoop(L))
+return false;
+
+  auto *DT = &getAnalysis().getDomTree();
+  auto *LI = &getAnalysis().getLoopInfo();
+  auto &TTI = getAnalysis().getTTI(
+  *L->getHeader()->getParent());
+  return AArch64LoopIdiomTransform(
+ DT, LI, &TTI, &L->getHeader()->getModule()->getDataLayout())
+  .run(L);
+}
+
+} // end anonymou

[clang] [clang-tools-extra] [llvm] [AArch64] Add an AArch64 pass for loop idiom transformations (PR #72273)

2023-12-13 Thread David Green via cfe-commits


@@ -0,0 +1,839 @@
+//===- AArch64LoopIdiomTransform.cpp - Loop idiom recognition 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This pass implements a pass that recognizes certain loop idioms and
+// transforms them into more optimized versions of the same loop. In cases
+// where this happens, it can be a significant performance win.
+//
+// We currently only recognize one loop that finds the first mismatched byte
+// in an array and returns the index, i.e. something like:
+//
+//  while (++i != n) {
+//if (a[i] != b[i])
+//  break;
+//  }
+//
+// In this example we can actually vectorize the loop despite the early exit,
+// although the loop vectorizer does not support it. It requires some extra
+// checks to deal with the possibility of faulting loads when crossing page
+// boundaries. However, even with these checks it is still profitable to do the
+// transformation.
+//
+//===--===//
+//
+// TODO List:
+//
+// * When optimizing for code size we may want to avoid some transformations.

davemgreen wrote:

Can we add a check for this now? It looks like it will be quite a bit bigger?

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


[clang-tools-extra] [clang] [llvm] [AArch64] Add an AArch64 pass for loop idiom transformations (PR #72273)

2023-12-13 Thread David Green via cfe-commits


@@ -0,0 +1,839 @@
+//===- AArch64LoopIdiomTransform.cpp - Loop idiom recognition 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This pass implements a pass that recognizes certain loop idioms and
+// transforms them into more optimized versions of the same loop. In cases
+// where this happens, it can be a significant performance win.
+//
+// We currently only recognize one loop that finds the first mismatched byte
+// in an array and returns the index, i.e. something like:
+//
+//  while (++i != n) {
+//if (a[i] != b[i])
+//  break;
+//  }
+//
+// In this example we can actually vectorize the loop despite the early exit,
+// although the loop vectorizer does not support it. It requires some extra
+// checks to deal with the possibility of faulting loads when crossing page
+// boundaries. However, even with these checks it is still profitable to do the
+// transformation.
+//
+//===--===//
+//
+// TODO List:
+//
+// * When optimizing for code size we may want to avoid some transformations.
+// * We can also support the inverse case where we scan for a matching element.
+//
+//===--===//
+
+#include "AArch64LoopIdiomTransform.h"
+#include "llvm/Analysis/DomTreeUpdater.h"
+#include "llvm/Analysis/LoopPass.h"
+#include "llvm/Analysis/TargetTransformInfo.h"
+#include "llvm/IR/Dominators.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/Intrinsics.h"
+#include "llvm/IR/MDBuilder.h"
+#include "llvm/IR/PatternMatch.h"
+#include "llvm/InitializePasses.h"
+#include "llvm/Transforms/Utils/BasicBlockUtils.h"
+
+using namespace llvm;
+
+#define DEBUG_TYPE "aarch64-loop-idiom-transform"
+
+static cl::opt
+DisableAll("disable-aarch64-lit-all", cl::Hidden, cl::init(false),
+   cl::desc("Disable AArch64 Loop Idiom Transform Pass."));
+
+static cl::opt DisableByteCmp(
+"disable-aarch64-lit-bytecmp", cl::Hidden, cl::init(false),
+cl::desc("Proceed with AArch64 Loop Idiom Transform Pass, but do "
+ "not convert byte-compare loop(s)."));
+
+static cl::opt VerifyLoops(
+"aarch64-lit-verify", cl::Hidden, cl::init(false),
+cl::desc("Verify loops generated AArch64 Loop Idiom Transform Pass."));
+
+namespace llvm {
+
+void initializeAArch64LoopIdiomTransformLegacyPassPass(PassRegistry &);
+Pass *createAArch64LoopIdiomTransformPass();
+
+} // end namespace llvm
+
+namespace {
+
+class AArch64LoopIdiomTransform {
+  Loop *CurLoop = nullptr;
+  DominatorTree *DT;
+  LoopInfo *LI;
+  const TargetTransformInfo *TTI;
+  const DataLayout *DL;
+
+public:
+  explicit AArch64LoopIdiomTransform(DominatorTree *DT, LoopInfo *LI,
+ const TargetTransformInfo *TTI,
+ const DataLayout *DL)
+  : DT(DT), LI(LI), TTI(TTI), DL(DL) {}
+
+  bool run(Loop *L);
+
+private:
+  /// \name Countable Loop Idiom Handling
+  /// @{
+
+  bool runOnCountableLoop();
+  bool runOnLoopBlock(BasicBlock *BB, const SCEV *BECount,
+  SmallVectorImpl &ExitBlocks);
+
+  bool recognizeByteCompare();
+  Value *expandFindMismatch(IRBuilder<> &Builder, GetElementPtrInst *GEPA,
+GetElementPtrInst *GEPB, Value *Start,
+Value *MaxLen);
+  void transformByteCompare(GetElementPtrInst *GEPA, GetElementPtrInst *GEPB,
+Value *MaxLen, Value *Index, Value *Start,
+bool IncIdx, BasicBlock *FoundBB,
+BasicBlock *EndBB);
+  /// @}
+};
+
+class AArch64LoopIdiomTransformLegacyPass : public LoopPass {
+public:
+  static char ID;
+
+  explicit AArch64LoopIdiomTransformLegacyPass() : LoopPass(ID) {
+initializeAArch64LoopIdiomTransformLegacyPassPass(
+*PassRegistry::getPassRegistry());
+  }
+
+  StringRef getPassName() const override {
+return "Transform AArch64-specific loop idioms";
+  }
+
+  void getAnalysisUsage(AnalysisUsage &AU) const override {
+AU.addRequired();
+AU.addRequired();
+AU.addRequired();
+  }
+
+  bool runOnLoop(Loop *L, LPPassManager &LPM) override;
+};
+
+bool AArch64LoopIdiomTransformLegacyPass::runOnLoop(Loop *L,
+LPPassManager &LPM) {
+
+  if (skipLoop(L))
+return false;
+
+  auto *DT = &getAnalysis().getDomTree();
+  auto *LI = &getAnalysis().getLoopInfo();
+  auto &TTI = getAnalysis().getTTI(
+  *L->getHeader()->getParent());
+  return AArch64LoopIdiomTransform(
+ DT, LI, &TTI, &L->getHeader()->getModule()->getDataLayout())
+  .run(L);
+}
+
+} // end anonymou

[clang] [llvm] [clang-tools-extra] [AArch64] Add an AArch64 pass for loop idiom transformations (PR #72273)

2023-12-13 Thread David Green via cfe-commits


@@ -0,0 +1,839 @@
+//===- AArch64LoopIdiomTransform.cpp - Loop idiom recognition 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This pass implements a pass that recognizes certain loop idioms and
+// transforms them into more optimized versions of the same loop. In cases
+// where this happens, it can be a significant performance win.
+//
+// We currently only recognize one loop that finds the first mismatched byte
+// in an array and returns the index, i.e. something like:
+//
+//  while (++i != n) {
+//if (a[i] != b[i])
+//  break;
+//  }
+//
+// In this example we can actually vectorize the loop despite the early exit,
+// although the loop vectorizer does not support it. It requires some extra
+// checks to deal with the possibility of faulting loads when crossing page
+// boundaries. However, even with these checks it is still profitable to do the
+// transformation.
+//
+//===--===//
+//
+// TODO List:
+//
+// * When optimizing for code size we may want to avoid some transformations.
+// * We can also support the inverse case where we scan for a matching element.
+//
+//===--===//
+
+#include "AArch64LoopIdiomTransform.h"
+#include "llvm/Analysis/DomTreeUpdater.h"
+#include "llvm/Analysis/LoopPass.h"
+#include "llvm/Analysis/TargetTransformInfo.h"
+#include "llvm/IR/Dominators.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/Intrinsics.h"
+#include "llvm/IR/MDBuilder.h"
+#include "llvm/IR/PatternMatch.h"
+#include "llvm/InitializePasses.h"
+#include "llvm/Transforms/Utils/BasicBlockUtils.h"
+
+using namespace llvm;
+
+#define DEBUG_TYPE "aarch64-loop-idiom-transform"
+
+static cl::opt
+DisableAll("disable-aarch64-lit-all", cl::Hidden, cl::init(false),
+   cl::desc("Disable AArch64 Loop Idiom Transform Pass."));
+
+static cl::opt DisableByteCmp(
+"disable-aarch64-lit-bytecmp", cl::Hidden, cl::init(false),
+cl::desc("Proceed with AArch64 Loop Idiom Transform Pass, but do "
+ "not convert byte-compare loop(s)."));
+
+static cl::opt VerifyLoops(
+"aarch64-lit-verify", cl::Hidden, cl::init(false),
+cl::desc("Verify loops generated AArch64 Loop Idiom Transform Pass."));
+
+namespace llvm {
+
+void initializeAArch64LoopIdiomTransformLegacyPassPass(PassRegistry &);
+Pass *createAArch64LoopIdiomTransformPass();
+
+} // end namespace llvm
+
+namespace {
+
+class AArch64LoopIdiomTransform {
+  Loop *CurLoop = nullptr;
+  DominatorTree *DT;
+  LoopInfo *LI;
+  const TargetTransformInfo *TTI;
+  const DataLayout *DL;
+
+public:
+  explicit AArch64LoopIdiomTransform(DominatorTree *DT, LoopInfo *LI,
+ const TargetTransformInfo *TTI,
+ const DataLayout *DL)
+  : DT(DT), LI(LI), TTI(TTI), DL(DL) {}
+
+  bool run(Loop *L);
+
+private:
+  /// \name Countable Loop Idiom Handling
+  /// @{
+
+  bool runOnCountableLoop();
+  bool runOnLoopBlock(BasicBlock *BB, const SCEV *BECount,
+  SmallVectorImpl &ExitBlocks);
+
+  bool recognizeByteCompare();
+  Value *expandFindMismatch(IRBuilder<> &Builder, GetElementPtrInst *GEPA,
+GetElementPtrInst *GEPB, Value *Start,
+Value *MaxLen);
+  void transformByteCompare(GetElementPtrInst *GEPA, GetElementPtrInst *GEPB,
+Value *MaxLen, Value *Index, Value *Start,
+bool IncIdx, BasicBlock *FoundBB,
+BasicBlock *EndBB);
+  /// @}
+};
+
+class AArch64LoopIdiomTransformLegacyPass : public LoopPass {
+public:
+  static char ID;
+
+  explicit AArch64LoopIdiomTransformLegacyPass() : LoopPass(ID) {
+initializeAArch64LoopIdiomTransformLegacyPassPass(
+*PassRegistry::getPassRegistry());
+  }
+
+  StringRef getPassName() const override {
+return "Transform AArch64-specific loop idioms";
+  }
+
+  void getAnalysisUsage(AnalysisUsage &AU) const override {
+AU.addRequired();
+AU.addRequired();
+AU.addRequired();
+  }
+
+  bool runOnLoop(Loop *L, LPPassManager &LPM) override;
+};
+
+bool AArch64LoopIdiomTransformLegacyPass::runOnLoop(Loop *L,
+LPPassManager &LPM) {
+
+  if (skipLoop(L))
+return false;
+
+  auto *DT = &getAnalysis().getDomTree();
+  auto *LI = &getAnalysis().getLoopInfo();
+  auto &TTI = getAnalysis().getTTI(
+  *L->getHeader()->getParent());
+  return AArch64LoopIdiomTransform(
+ DT, LI, &TTI, &L->getHeader()->getModule()->getDataLayout())
+  .run(L);
+}
+
+} // end anonymou

[clang-tools-extra] [clang] [llvm] [AArch64] Add an AArch64 pass for loop idiom transformations (PR #72273)

2023-12-13 Thread David Green via cfe-commits


@@ -0,0 +1,839 @@
+//===- AArch64LoopIdiomTransform.cpp - Loop idiom recognition 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This pass implements a pass that recognizes certain loop idioms and
+// transforms them into more optimized versions of the same loop. In cases
+// where this happens, it can be a significant performance win.
+//
+// We currently only recognize one loop that finds the first mismatched byte
+// in an array and returns the index, i.e. something like:
+//
+//  while (++i != n) {
+//if (a[i] != b[i])
+//  break;
+//  }
+//
+// In this example we can actually vectorize the loop despite the early exit,
+// although the loop vectorizer does not support it. It requires some extra
+// checks to deal with the possibility of faulting loads when crossing page
+// boundaries. However, even with these checks it is still profitable to do the
+// transformation.
+//
+//===--===//
+//
+// TODO List:
+//
+// * When optimizing for code size we may want to avoid some transformations.
+// * We can also support the inverse case where we scan for a matching element.
+//
+//===--===//
+
+#include "AArch64LoopIdiomTransform.h"
+#include "llvm/Analysis/DomTreeUpdater.h"
+#include "llvm/Analysis/LoopPass.h"
+#include "llvm/Analysis/TargetTransformInfo.h"
+#include "llvm/IR/Dominators.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/Intrinsics.h"
+#include "llvm/IR/MDBuilder.h"
+#include "llvm/IR/PatternMatch.h"
+#include "llvm/InitializePasses.h"
+#include "llvm/Transforms/Utils/BasicBlockUtils.h"
+
+using namespace llvm;
+
+#define DEBUG_TYPE "aarch64-loop-idiom-transform"
+
+static cl::opt
+DisableAll("disable-aarch64-lit-all", cl::Hidden, cl::init(false),
+   cl::desc("Disable AArch64 Loop Idiom Transform Pass."));
+
+static cl::opt DisableByteCmp(
+"disable-aarch64-lit-bytecmp", cl::Hidden, cl::init(false),
+cl::desc("Proceed with AArch64 Loop Idiom Transform Pass, but do "
+ "not convert byte-compare loop(s)."));
+
+static cl::opt VerifyLoops(
+"aarch64-lit-verify", cl::Hidden, cl::init(false),
+cl::desc("Verify loops generated AArch64 Loop Idiom Transform Pass."));
+
+namespace llvm {
+
+void initializeAArch64LoopIdiomTransformLegacyPassPass(PassRegistry &);
+Pass *createAArch64LoopIdiomTransformPass();
+
+} // end namespace llvm
+
+namespace {
+
+class AArch64LoopIdiomTransform {
+  Loop *CurLoop = nullptr;
+  DominatorTree *DT;
+  LoopInfo *LI;
+  const TargetTransformInfo *TTI;
+  const DataLayout *DL;
+
+public:
+  explicit AArch64LoopIdiomTransform(DominatorTree *DT, LoopInfo *LI,
+ const TargetTransformInfo *TTI,
+ const DataLayout *DL)
+  : DT(DT), LI(LI), TTI(TTI), DL(DL) {}
+
+  bool run(Loop *L);
+
+private:
+  /// \name Countable Loop Idiom Handling
+  /// @{
+
+  bool runOnCountableLoop();
+  bool runOnLoopBlock(BasicBlock *BB, const SCEV *BECount,
+  SmallVectorImpl &ExitBlocks);
+
+  bool recognizeByteCompare();
+  Value *expandFindMismatch(IRBuilder<> &Builder, GetElementPtrInst *GEPA,
+GetElementPtrInst *GEPB, Value *Start,
+Value *MaxLen);
+  void transformByteCompare(GetElementPtrInst *GEPA, GetElementPtrInst *GEPB,
+Value *MaxLen, Value *Index, Value *Start,
+bool IncIdx, BasicBlock *FoundBB,
+BasicBlock *EndBB);
+  /// @}
+};
+
+class AArch64LoopIdiomTransformLegacyPass : public LoopPass {
+public:
+  static char ID;
+
+  explicit AArch64LoopIdiomTransformLegacyPass() : LoopPass(ID) {
+initializeAArch64LoopIdiomTransformLegacyPassPass(
+*PassRegistry::getPassRegistry());
+  }
+
+  StringRef getPassName() const override {
+return "Transform AArch64-specific loop idioms";
+  }
+
+  void getAnalysisUsage(AnalysisUsage &AU) const override {
+AU.addRequired();
+AU.addRequired();
+AU.addRequired();
+  }
+
+  bool runOnLoop(Loop *L, LPPassManager &LPM) override;
+};
+
+bool AArch64LoopIdiomTransformLegacyPass::runOnLoop(Loop *L,
+LPPassManager &LPM) {
+
+  if (skipLoop(L))
+return false;
+
+  auto *DT = &getAnalysis().getDomTree();
+  auto *LI = &getAnalysis().getLoopInfo();
+  auto &TTI = getAnalysis().getTTI(
+  *L->getHeader()->getParent());
+  return AArch64LoopIdiomTransform(
+ DT, LI, &TTI, &L->getHeader()->getModule()->getDataLayout())
+  .run(L);
+}
+
+} // end anonymou

[llvm] [clang] [clang-tools-extra] [AArch64] Add an AArch64 pass for loop idiom transformations (PR #72273)

2023-12-13 Thread David Green via cfe-commits


@@ -0,0 +1,839 @@
+//===- AArch64LoopIdiomTransform.cpp - Loop idiom recognition 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This pass implements a pass that recognizes certain loop idioms and
+// transforms them into more optimized versions of the same loop. In cases
+// where this happens, it can be a significant performance win.
+//
+// We currently only recognize one loop that finds the first mismatched byte
+// in an array and returns the index, i.e. something like:
+//
+//  while (++i != n) {
+//if (a[i] != b[i])
+//  break;
+//  }
+//
+// In this example we can actually vectorize the loop despite the early exit,
+// although the loop vectorizer does not support it. It requires some extra
+// checks to deal with the possibility of faulting loads when crossing page
+// boundaries. However, even with these checks it is still profitable to do the
+// transformation.
+//
+//===--===//
+//
+// TODO List:
+//
+// * When optimizing for code size we may want to avoid some transformations.
+// * We can also support the inverse case where we scan for a matching element.
+//
+//===--===//
+
+#include "AArch64LoopIdiomTransform.h"
+#include "llvm/Analysis/DomTreeUpdater.h"
+#include "llvm/Analysis/LoopPass.h"
+#include "llvm/Analysis/TargetTransformInfo.h"
+#include "llvm/IR/Dominators.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/Intrinsics.h"
+#include "llvm/IR/MDBuilder.h"
+#include "llvm/IR/PatternMatch.h"
+#include "llvm/InitializePasses.h"
+#include "llvm/Transforms/Utils/BasicBlockUtils.h"
+
+using namespace llvm;
+
+#define DEBUG_TYPE "aarch64-loop-idiom-transform"
+
+static cl::opt
+DisableAll("disable-aarch64-lit-all", cl::Hidden, cl::init(false),
+   cl::desc("Disable AArch64 Loop Idiom Transform Pass."));
+
+static cl::opt DisableByteCmp(
+"disable-aarch64-lit-bytecmp", cl::Hidden, cl::init(false),
+cl::desc("Proceed with AArch64 Loop Idiom Transform Pass, but do "
+ "not convert byte-compare loop(s)."));
+
+static cl::opt VerifyLoops(
+"aarch64-lit-verify", cl::Hidden, cl::init(false),
+cl::desc("Verify loops generated AArch64 Loop Idiom Transform Pass."));
+
+namespace llvm {
+
+void initializeAArch64LoopIdiomTransformLegacyPassPass(PassRegistry &);
+Pass *createAArch64LoopIdiomTransformPass();
+
+} // end namespace llvm
+
+namespace {
+
+class AArch64LoopIdiomTransform {
+  Loop *CurLoop = nullptr;
+  DominatorTree *DT;
+  LoopInfo *LI;
+  const TargetTransformInfo *TTI;
+  const DataLayout *DL;
+
+public:
+  explicit AArch64LoopIdiomTransform(DominatorTree *DT, LoopInfo *LI,
+ const TargetTransformInfo *TTI,
+ const DataLayout *DL)
+  : DT(DT), LI(LI), TTI(TTI), DL(DL) {}
+
+  bool run(Loop *L);
+
+private:
+  /// \name Countable Loop Idiom Handling
+  /// @{
+
+  bool runOnCountableLoop();
+  bool runOnLoopBlock(BasicBlock *BB, const SCEV *BECount,
+  SmallVectorImpl &ExitBlocks);
+
+  bool recognizeByteCompare();
+  Value *expandFindMismatch(IRBuilder<> &Builder, GetElementPtrInst *GEPA,
+GetElementPtrInst *GEPB, Value *Start,
+Value *MaxLen);
+  void transformByteCompare(GetElementPtrInst *GEPA, GetElementPtrInst *GEPB,
+Value *MaxLen, Value *Index, Value *Start,
+bool IncIdx, BasicBlock *FoundBB,
+BasicBlock *EndBB);
+  /// @}
+};
+
+class AArch64LoopIdiomTransformLegacyPass : public LoopPass {
+public:
+  static char ID;
+
+  explicit AArch64LoopIdiomTransformLegacyPass() : LoopPass(ID) {
+initializeAArch64LoopIdiomTransformLegacyPassPass(
+*PassRegistry::getPassRegistry());
+  }
+
+  StringRef getPassName() const override {
+return "Transform AArch64-specific loop idioms";
+  }
+
+  void getAnalysisUsage(AnalysisUsage &AU) const override {
+AU.addRequired();
+AU.addRequired();
+AU.addRequired();
+  }
+
+  bool runOnLoop(Loop *L, LPPassManager &LPM) override;
+};
+
+bool AArch64LoopIdiomTransformLegacyPass::runOnLoop(Loop *L,
+LPPassManager &LPM) {
+
+  if (skipLoop(L))
+return false;
+
+  auto *DT = &getAnalysis().getDomTree();
+  auto *LI = &getAnalysis().getLoopInfo();
+  auto &TTI = getAnalysis().getTTI(
+  *L->getHeader()->getParent());
+  return AArch64LoopIdiomTransform(
+ DT, LI, &TTI, &L->getHeader()->getModule()->getDataLayout())
+  .run(L);
+}
+
+} // end anonymou

[llvm] [clang] [ValueTracking] Add dominating condition support in computeKnownBits() (PR #73662)

2023-12-13 Thread via cfe-commits

joanahalili wrote:

heads-up, we are seeing some performance regressions due to this patch 8about 
6-7%! We will add more details about this soon.

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


[llvm] [clang] [clang-tools-extra] [Clang][AArch64] Add fix vector types to header into SVE (PR #73258)

2023-12-13 Thread David Spickett via cfe-commits

DavidSpickett wrote:

I think this caused a test suite program to fail to build:
```
cd 
/home/tcwg-buildbot/worker/clang-aarch64-global-isel/test/sandbox/build/SingleSource/UnitTests
 && 
/home/tcwg-buildbot/worker/clang-aarch64-global-isel/stage1.install/bin/llvm-size
 --format=sysv 
/home/tcwg-buildbot/worker/clang-aarch64-global-isel/test/sandbox/build/SingleSource/UnitTests/testcase-CGExprConstant
 > 
/home/tcwg-buildbot/worker/clang-aarch64-global-isel/test/sandbox/build/SingleSource/UnitTests/testcase-CGExprConstant.size
  |   
~^
   38 |   (value))
  |   
/home/tcwg-buildbot/worker/clang-aarch64-global-isel/test/test-suite/SingleSource/UnitTests/Float/test_isfpclass.h:28:11:
 note: expanded from macro 'CHECK_CLASS'
   28 | if (!(cond)) {  
   \
  |   ^~~~
/home/tcwg-buildbot/worker/clang-aarch64-global-isel/test/test-suite/SingleSource/UnitTests/Float/test_isfpclass.h:58:3:
 error: floating point classification requires argument of floating point type 
(passed in 'int')
   58 |   CHECK(fcFinite, x);
  |   ^~
/home/tcwg-buildbot/worker/clang-aarch64-global-isel/test/test-suite/SingleSource/UnitTests/Float/test_isfpclass.h:37:60:
 note: expanded from macro 'CHECK'
   37 |   CHECK_CLASS(!!((flags)&FPCLASS) == !!__builtin_isfpclass((flags), 
(value)),  \
  |   
~^
   38 |   (value))
  |   
/home/tcwg-buildbot/worker/clang-aarch64-global-isel/test/test-suite/SingleSource/UnitTests/Float/test_isfpclass.h:28:11:
 note: expanded from macro 'CHECK_CLASS'
   28 | if (!(cond)) {  
   \
  |   ^~~~
/home/tcwg-buildbot/worker/clang-aarch64-global-isel/test/test-suite/SingleSource/UnitTests/Float/test_isfpclass.h:60:3:
 error: floating point classification requires argument of floating point type 
(passed in 'int')
   60 |   CHECK(fcQNan | fcInf | fcNormal | fcSubnormal | fcZero, x);
  |   ^~
/home/tcwg-buildbot/worker/clang-aarch64-global-isel/test/test-suite/SingleSource/UnitTests/Float/test_isfpclass.h:37:60:
 note: expanded from macro 'CHECK'
   37 |   CHECK_CLASS(!!((flags)&FPCLASS) == !!__builtin_isfpclass((flags), 
(value)),  \
  |   
~^
   38 |   (value))
  |   
/home/tcwg-buildbot/worker/clang-aarch64-global-isel/test/test-suite/SingleSource/UnitTests/Float/test_isfpclass.h:28:11:
 note: expanded from macro 'CHECK_CLASS'
   28 | if (!(cond)) {  
   \
  |   ^~~~
```
https://lab.llvm.org/buildbot/#/builders/183/builds/18017

I'm guessing it includes a header effected by this change.

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


[llvm] [clang] [AMDGPU] Add an option to disable unsafe uses of atomic xor (PR #69229)

2023-12-13 Thread Pierre-Andre Saulais via cfe-commits

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


[llvm] [clang] [clang-tools-extra] [Clang][AArch64] Add fix vector types to header into SVE (PR #73258)

2023-12-13 Thread David Spickett via cfe-commits

DavidSpickett wrote:

Actually this may be https://github.com/llvm/llvm-test-suite/pull/59, which 
landed in the test suite just now as well, but is not listed as a change there 
(which is a known issue with buildbot).

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


[clang] [AArch64][SME2] Add SQRSHRN, UQRSHRN, SQRSHRUN builtins for SME2, SVE2p1 (PR #75325)

2023-12-13 Thread Dinar Temirbulatov via cfe-commits

https://github.com/dtemirbulatov created 
https://github.com/llvm/llvm-project/pull/75325

Add SQRSHRN, UQRSHRN, SQRSHRUN builtins for SME2, SVE2p1.

>From 83d1e213a5dce7621f8f87668a4ab1f15306fc5b Mon Sep 17 00:00:00 2001
From: Dinar Temirbulatov 
Date: Wed, 13 Dec 2023 11:28:06 +
Subject: [PATCH] [AArch64][SME2] Add SQRSHRN, UQRSHRN, SQRSHRUN builtins for
 SME2, SVE2p1

Add SQRSHRN, UQRSHRN, SQRSHRUN builtins for SME2, SVE2p1.
---
 clang/include/clang/Basic/arm_sve.td  |  9 +++
 .../acle_sve2p1_qrshr.c   | 78 +++
 2 files changed, 87 insertions(+)
 create mode 100644 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_qrshr.c

diff --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index aa9b105364a51a..4e9e318e7ade85 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -2170,6 +2170,15 @@ let TargetGuard = "sme2" in {
   def REINTERPRET_SVCOUNT_TO_SVBOOL : Inst<"svreinterpret[_b]", "P}", "Pc", 
MergeNone, "", [IsStreamingCompatible], []>;
 }
 
+let TargetGuard = "sve2p1|sme2" in {
+  // SQRSHRN / UQRSHRN
+  def SVQRSHRN_X2   : SInst<"svqrshrn[_n]_{0}[_{d}_x2]", "h2i", "i",
MergeNone, "aarch64_sve_sqrshrn_x2", [IsStreamingCompatible], [ImmCheck<1, 
ImmCheck1_16>]>;
+  def SVUQRSHRN_X2  : SInst<"svqrshrn[_n]_{0}[_{d}_x2]", "e2i", "Ui",   
MergeNone, "aarch64_sve_uqrshrn_x2", [IsStreamingCompatible], [ImmCheck<1, 
ImmCheck1_16>]>;
+
+  // SQRSHRUN
+  def SVSQRSHRUN_X2 : SInst<"svqrshrun[_n]_{0}[_{d}_x2]", "e2i", "i",  
MergeNone, "aarch64_sve_sqrshrun_x2", [IsStreamingCompatible], [ImmCheck<1, 
ImmCheck1_16>]>;
+}
+
 let TargetGuard = "sve2p1" in {
   // ZIPQ1, ZIPQ2, UZPQ1, UZPQ2
   def SVZIPQ1 : SInst<"svzipq1[_{d}]", "ddd", "cUcsUsiUilUlbhfd", MergeNone, 
"aarch64_sve_zipq1", [], []>;
diff --git a/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_qrshr.c 
b/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_qrshr.c
new file mode 100644
index 00..8e8b7203148934
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_qrshr.c
@@ -0,0 +1,78 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | 
opt -S  -passes=mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S  
-passes=mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - -x 
c++ %s | opt -S  -passes=mem2reg,instcombine,tailcallelim | FileCheck %s 
-check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve -target-feature +sme2 -S -disable-O0-optnone -Werror -Wall 
-emit-llvm -o - %s | opt -S  -passes=mem2reg,instcombine,tailcallelim | 
FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve -target-feature +sme2 -S -disable-O0-optnone -Werror -Wall 
-emit-llvm -o - -x c++ %s | opt -S  -passes=mem2reg,instcombine,tailcallelim | 
FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +sme2 -target-feature +sme-f64f64 -S -disable-O0-optnone 
-Werror -Wall -o /dev/null %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -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,A4_UNUSED,A5) A1##A3##A5
+#else
+#define SVE_ACLE_FUNC(A1,A2,A3,A4,A5) A1##A2##A3##A4##A5
+#endif
+
+
+// SQRSHRN x 2
+
+// CHECK-LABEL: @test_svqrshrn_s16_s32_x2(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv4i32.nxv8i32( [[ZN:%.*]], i64 0)
+// CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.extract.nxv4i32.nxv8i32( [[ZN]], i64 4)
+// CHECK-NEXT:[[TMP2:%.*]] = tail call  
@llvm.aarch64.sve.sqrshrn.x2.nxv4i32( [[TMP0]],  [[TMP1]], i32 16)
+// CHECK-NEXT:ret  [[TMP2]]
+//
+// CPP-CHECK-LABEL: @_Z24test_svqrshrn_s16_s32_x211svint32x2_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv4i32.nxv8i32( [[ZN:%.*]], i64 0)
+// CPP-CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.extract.nxv4i32.nxv8i32( [[ZN]], i64 4)
+// CPP-CHECK-NEXT:[[TMP2:%.*]] = tail call  
@llvm.aarch64.sve.sqrshrn.x2.nxv4i32( [[TMP0]],  [[TMP1]], i32 16)
+// CPP-CHECK-NEXT:ret  [[TMP2]]
+//
+svint16_t test_svqrshrn_s16_s32_x2(svint32x2_t zn) __arm_streaming_compatible {
+  return SVE_ACLE_FUNC(svqrshrn

[clang] [AArch64][SME2] Add SQRSHRN, UQRSHRN, SQRSHRUN builtins for SME2, SVE2p1 (PR #75325)

2023-12-13 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Dinar Temirbulatov (dtemirbulatov)


Changes

Add SQRSHRN, UQRSHRN, SQRSHRUN builtins for SME2, SVE2p1.

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


2 Files Affected:

- (modified) clang/include/clang/Basic/arm_sve.td (+9) 
- (added) clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_qrshr.c 
(+78) 


``diff
diff --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index aa9b105364a51a..4e9e318e7ade85 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -2170,6 +2170,15 @@ let TargetGuard = "sme2" in {
   def REINTERPRET_SVCOUNT_TO_SVBOOL : Inst<"svreinterpret[_b]", "P}", "Pc", 
MergeNone, "", [IsStreamingCompatible], []>;
 }
 
+let TargetGuard = "sve2p1|sme2" in {
+  // SQRSHRN / UQRSHRN
+  def SVQRSHRN_X2   : SInst<"svqrshrn[_n]_{0}[_{d}_x2]", "h2i", "i",
MergeNone, "aarch64_sve_sqrshrn_x2", [IsStreamingCompatible], [ImmCheck<1, 
ImmCheck1_16>]>;
+  def SVUQRSHRN_X2  : SInst<"svqrshrn[_n]_{0}[_{d}_x2]", "e2i", "Ui",   
MergeNone, "aarch64_sve_uqrshrn_x2", [IsStreamingCompatible], [ImmCheck<1, 
ImmCheck1_16>]>;
+
+  // SQRSHRUN
+  def SVSQRSHRUN_X2 : SInst<"svqrshrun[_n]_{0}[_{d}_x2]", "e2i", "i",  
MergeNone, "aarch64_sve_sqrshrun_x2", [IsStreamingCompatible], [ImmCheck<1, 
ImmCheck1_16>]>;
+}
+
 let TargetGuard = "sve2p1" in {
   // ZIPQ1, ZIPQ2, UZPQ1, UZPQ2
   def SVZIPQ1 : SInst<"svzipq1[_{d}]", "ddd", "cUcsUsiUilUlbhfd", MergeNone, 
"aarch64_sve_zipq1", [], []>;
diff --git a/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_qrshr.c 
b/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_qrshr.c
new file mode 100644
index 00..8e8b7203148934
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_qrshr.c
@@ -0,0 +1,78 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | 
opt -S  -passes=mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S  
-passes=mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - -x 
c++ %s | opt -S  -passes=mem2reg,instcombine,tailcallelim | FileCheck %s 
-check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve -target-feature +sme2 -S -disable-O0-optnone -Werror -Wall 
-emit-llvm -o - %s | opt -S  -passes=mem2reg,instcombine,tailcallelim | 
FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sve -target-feature +sme2 -S -disable-O0-optnone -Werror -Wall 
-emit-llvm -o - -x c++ %s | opt -S  -passes=mem2reg,instcombine,tailcallelim | 
FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +sme2 -target-feature +sme-f64f64 -S -disable-O0-optnone 
-Werror -Wall -o /dev/null %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -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,A4_UNUSED,A5) A1##A3##A5
+#else
+#define SVE_ACLE_FUNC(A1,A2,A3,A4,A5) A1##A2##A3##A4##A5
+#endif
+
+
+// SQRSHRN x 2
+
+// CHECK-LABEL: @test_svqrshrn_s16_s32_x2(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv4i32.nxv8i32( [[ZN:%.*]], i64 0)
+// CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.extract.nxv4i32.nxv8i32( [[ZN]], i64 4)
+// CHECK-NEXT:[[TMP2:%.*]] = tail call  
@llvm.aarch64.sve.sqrshrn.x2.nxv4i32( [[TMP0]],  [[TMP1]], i32 16)
+// CHECK-NEXT:ret  [[TMP2]]
+//
+// CPP-CHECK-LABEL: @_Z24test_svqrshrn_s16_s32_x211svint32x2_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv4i32.nxv8i32( [[ZN:%.*]], i64 0)
+// CPP-CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.extract.nxv4i32.nxv8i32( [[ZN]], i64 4)
+// CPP-CHECK-NEXT:[[TMP2:%.*]] = tail call  
@llvm.aarch64.sve.sqrshrn.x2.nxv4i32( [[TMP0]],  [[TMP1]], i32 16)
+// CPP-CHECK-NEXT:ret  [[TMP2]]
+//
+svint16_t test_svqrshrn_s16_s32_x2(svint32x2_t zn) __arm_streaming_compatible {
+  return SVE_ACLE_FUNC(svqrshrn,_n,_s16,_s32_x2,)(zn, 16);
+}
+
+// UQRSHRN x 2
+
+// CHECK-LABEL: @test_svqrshrn_u16_u32_x2(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv4i32.nxv8i32( [[ZN:%.*]], i64 0)
+// CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.extr

[clang-tools-extra] [flang] [llvm] [libc] [libunwind] [lldb] [openmp] [libcxxabi] [libcxx] [mlir] [compiler-rt] [clang] [lld] [C23] Implement N3018: The constexpr specifier for object definitions (PR

2023-12-13 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

Adding more reviewers since Aaron is on vacation...

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


[clang] [AArch64][SME2] Add builtins for SQDMULH (PR #75326)

2023-12-13 Thread Dinar Temirbulatov via cfe-commits

https://github.com/dtemirbulatov created 
https://github.com/llvm/llvm-project/pull/75326

Patch by: Kerry McLaughlin 

>From 2b0d280b59e244600ebc4b8373ab5494b88942df Mon Sep 17 00:00:00 2001
From: Dinar Temirbulatov 
Date: Wed, 13 Dec 2023 12:00:11 +
Subject: [PATCH] [AArch64][SME2] Add builtins for SQDMULH

Patch by: Kerry McLaughlin 
---
 clang/include/clang/Basic/arm_sve.td  |   6 +
 .../acle_sme2_sqdmulh.c   | 584 ++
 2 files changed, 590 insertions(+)
 create mode 100644 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_sqdmulh.c

diff --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index aa9b105364a51a..7f46f20ba7a1a7 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -2168,6 +2168,12 @@ let TargetGuard = "sme2" in {
 
   def REINTERPRET_SVBOOL_TO_SVCOUNT : Inst<"svreinterpret[_c]", "}P", "Pc", 
MergeNone, "", [IsStreamingCompatible], []>;
   def REINTERPRET_SVCOUNT_TO_SVBOOL : Inst<"svreinterpret[_b]", "P}", "Pc", 
MergeNone, "", [IsStreamingCompatible], []>;
+
+  // SQDMULH
+  def SVSQDMULH_SINGLE_X2 : SInst<"svqdmulh[_single_{d}_x2]", "22d", "csil", 
MergeNone, "aarch64_sve_sqdmulh_single_vgx2", [IsStreaming], []>;
+  def SVSQDMULH_SINGLE_X4 : SInst<"svqdmulh[_single_{d}_x4]", "44d", "csil", 
MergeNone, "aarch64_sve_sqdmulh_single_vgx4", [IsStreaming], []>;
+  def SVSQDMULH_X2: SInst<"svqdmulh[_{d}_x2]","222", "csil", 
MergeNone, "aarch64_sve_sqdmulh_vgx2",[IsStreaming], []>;
+  def SVSQDMULH_X4: SInst<"svqdmulh[_{d}_x4]","444", "csil", 
MergeNone, "aarch64_sve_sqdmulh_vgx4",[IsStreaming], []>;
 }
 
 let TargetGuard = "sve2p1" in {
diff --git a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_sqdmulh.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_sqdmulh.c
new file mode 100644
index 00..6bbd23ccd32a52
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_sqdmulh.c
@@ -0,0 +1,584 @@
+// 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,A3,A4_UNUSED,A5) A1##A3##A5
+#else
+#define SVE_ACLE_FUNC(A1,A2,A3,A4,A5) A1##A2##A3##A4##A5
+#endif
+
+// Single, x2
+
+// CHECK-LABEL: @test_svqdmulh_single_s8_x2(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv16i8.nxv32i8( [[ZDN:%.*]], i64 0)
+// CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.extract.nxv16i8.nxv32i8( [[ZDN]], i64 16)
+// CHECK-NEXT:[[TMP2:%.*]] = tail call { ,  } @llvm.aarch64.sve.sqdmulh.single.vgx2.nxv16i8( 
[[TMP0]],  [[TMP1]],  [[ZM:%.*]])
+// CHECK-NEXT:[[TMP3:%.*]] = extractvalue { ,  } [[TMP2]], 0
+// CHECK-NEXT:[[TMP4:%.*]] = tail call  
@llvm.vector.insert.nxv32i8.nxv16i8( poison,  [[TMP3]], i64 0)
+// CHECK-NEXT:[[TMP5:%.*]] = extractvalue { ,  } [[TMP2]], 1
+// CHECK-NEXT:[[TMP6:%.*]] = tail call  
@llvm.vector.insert.nxv32i8.nxv16i8( [[TMP4]],  [[TMP5]], i64 16)
+// CHECK-NEXT:ret  [[TMP6]]
+//
+// CPP-CHECK-LABEL: @_Z26test_svqdmulh_single_s8_x210svint8x2_tu10__SVInt8_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv16i8.nxv32i8( [[ZDN:%.*]], i64 0)
+// CPP-CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.extract.nxv16i8.nxv32i8( [[ZDN]], i64 16)
+// CPP-CHECK-NEXT:[[TMP2:%.*]] = tail call { ,  } @llvm.aarch64.sve.sqdmulh.single.vgx2.nxv16i8( 
[[TMP0]],  [[TMP1]],  [[ZM:%.*]])
+// CPP-CHECK-NEXT:[[TMP3:%.*]] = extractvalue { , 
 } [[TMP2]], 0
+// CPP-CHECK-NEXT:[[TMP4:%.*]] = tail call  
@llvm.vector.insert.nxv32i8.nxv16i8( poison,  [[TMP3]], i64 0)
+// CPP-CHECK-NEXT:[[TMP5:%.*]] = extractvalue { , 
 } [[TMP2]], 1
+// CPP-CHECK-NEXT:[[TMP6:%.*]] = tai

[clang] [AArch64][SME2] Add builtins for SQDMULH (PR #75326)

2023-12-13 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Dinar Temirbulatov (dtemirbulatov)


Changes

Patch by: Kerry McLaughlin 

---

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


2 Files Affected:

- (modified) clang/include/clang/Basic/arm_sve.td (+6) 
- (added) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_sqdmulh.c (+584) 


``diff
diff --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index aa9b105364a51a..7f46f20ba7a1a7 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -2168,6 +2168,12 @@ let TargetGuard = "sme2" in {
 
   def REINTERPRET_SVBOOL_TO_SVCOUNT : Inst<"svreinterpret[_c]", "}P", "Pc", 
MergeNone, "", [IsStreamingCompatible], []>;
   def REINTERPRET_SVCOUNT_TO_SVBOOL : Inst<"svreinterpret[_b]", "P}", "Pc", 
MergeNone, "", [IsStreamingCompatible], []>;
+
+  // SQDMULH
+  def SVSQDMULH_SINGLE_X2 : SInst<"svqdmulh[_single_{d}_x2]", "22d", "csil", 
MergeNone, "aarch64_sve_sqdmulh_single_vgx2", [IsStreaming], []>;
+  def SVSQDMULH_SINGLE_X4 : SInst<"svqdmulh[_single_{d}_x4]", "44d", "csil", 
MergeNone, "aarch64_sve_sqdmulh_single_vgx4", [IsStreaming], []>;
+  def SVSQDMULH_X2: SInst<"svqdmulh[_{d}_x2]","222", "csil", 
MergeNone, "aarch64_sve_sqdmulh_vgx2",[IsStreaming], []>;
+  def SVSQDMULH_X4: SInst<"svqdmulh[_{d}_x4]","444", "csil", 
MergeNone, "aarch64_sve_sqdmulh_vgx4",[IsStreaming], []>;
 }
 
 let TargetGuard = "sve2p1" in {
diff --git a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_sqdmulh.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_sqdmulh.c
new file mode 100644
index 00..6bbd23ccd32a52
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_sqdmulh.c
@@ -0,0 +1,584 @@
+// 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,A3,A4_UNUSED,A5) A1##A3##A5
+#else
+#define SVE_ACLE_FUNC(A1,A2,A3,A4,A5) A1##A2##A3##A4##A5
+#endif
+
+// Single, x2
+
+// CHECK-LABEL: @test_svqdmulh_single_s8_x2(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv16i8.nxv32i8( [[ZDN:%.*]], i64 0)
+// CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.extract.nxv16i8.nxv32i8( [[ZDN]], i64 16)
+// CHECK-NEXT:[[TMP2:%.*]] = tail call { ,  } @llvm.aarch64.sve.sqdmulh.single.vgx2.nxv16i8( 
[[TMP0]],  [[TMP1]],  [[ZM:%.*]])
+// CHECK-NEXT:[[TMP3:%.*]] = extractvalue { ,  } [[TMP2]], 0
+// CHECK-NEXT:[[TMP4:%.*]] = tail call  
@llvm.vector.insert.nxv32i8.nxv16i8( poison,  [[TMP3]], i64 0)
+// CHECK-NEXT:[[TMP5:%.*]] = extractvalue { ,  } [[TMP2]], 1
+// CHECK-NEXT:[[TMP6:%.*]] = tail call  
@llvm.vector.insert.nxv32i8.nxv16i8( [[TMP4]],  [[TMP5]], i64 16)
+// CHECK-NEXT:ret  [[TMP6]]
+//
+// CPP-CHECK-LABEL: @_Z26test_svqdmulh_single_s8_x210svint8x2_tu10__SVInt8_t(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv16i8.nxv32i8( [[ZDN:%.*]], i64 0)
+// CPP-CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.extract.nxv16i8.nxv32i8( [[ZDN]], i64 16)
+// CPP-CHECK-NEXT:[[TMP2:%.*]] = tail call { ,  } @llvm.aarch64.sve.sqdmulh.single.vgx2.nxv16i8( 
[[TMP0]],  [[TMP1]],  [[ZM:%.*]])
+// CPP-CHECK-NEXT:[[TMP3:%.*]] = extractvalue { , 
 } [[TMP2]], 0
+// CPP-CHECK-NEXT:[[TMP4:%.*]] = tail call  
@llvm.vector.insert.nxv32i8.nxv16i8( poison,  [[TMP3]], i64 0)
+// CPP-CHECK-NEXT:[[TMP5:%.*]] = extractvalue { , 
 } [[TMP2]], 1
+// CPP-CHECK-NEXT:[[TMP6:%.*]] = tail call  
@llvm.vector.insert.nxv32i8.nxv16i8( [[TMP4]],  [[TMP5]], i64 16)
+// CPP-CHECK-NEXT:ret  [[TMP6]]
+//
+svint8x2_t test_svqdmulh

[clang] [llvm] [clang][RISCV] Change default abi with f extension but without d extension (PR #73489)

2023-12-13 Thread Alex Bradbury via cfe-commits

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

LGTM

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


[openmp] [clang-tools-extra] [libcxx] [mlir] [clang] [compiler-rt] [lldb] [llvm] [libcxxabi] [flang] [MachineCopyPropagation] When the source of PreviousCopy is undef, we cannot replace sub register (

2023-12-13 Thread David Green via cfe-commits

davemgreen wrote:

Thanks. It sounds like there are not a lot of code changes, which is a good 
sign. I didn't expect the debug problems though.

I'll try and take a look at the patch. Perhaps you are right that we need a new 
method for the debug info to use.

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


[clang] [libc] [flang] [openmp] [mlir] [libcxx] [llvm] [lld] [libcxxabi] [compiler-rt] [clang-tools-extra] [lldb] [libc++] Fix `take_view::__sentinel`'s `operator==` (PR #74655)

2023-12-13 Thread Jakub Mazurkiewicz via cfe-commits

https://github.com/JMazurkiewicz updated 
https://github.com/llvm/llvm-project/pull/74655

>From b3de573887cdd86fd6ce168bdcc6d729d73b13b2 Mon Sep 17 00:00:00 2001
From: Jakub Mazurkiewicz 
Date: Wed, 6 Dec 2023 14:03:51 +0100
Subject: [PATCH 01/12] [libc++] Fix `take_view::__sentinel`'s `operator==`

---
 libcxx/include/__ranges/take_view.h   |   2 +-
 .../base.pass.cpp |   5 +-
 .../ctor.pass.cpp |   0
 .../range.take.sentinel/eq.pass.cpp   | 192 ++
 .../range.take/sentinel/eq.pass.cpp   |  55 -
 5 files changed, 194 insertions(+), 60 deletions(-)
 rename libcxx/test/std/ranges/range.adaptors/range.take/{sentinel => 
range.take.sentinel}/base.pass.cpp (83%)
 rename libcxx/test/std/ranges/range.adaptors/range.take/{sentinel => 
range.take.sentinel}/ctor.pass.cpp (100%)
 create mode 100644 
libcxx/test/std/ranges/range.adaptors/range.take/range.take.sentinel/eq.pass.cpp
 delete mode 100644 
libcxx/test/std/ranges/range.adaptors/range.take/sentinel/eq.pass.cpp

diff --git a/libcxx/include/__ranges/take_view.h 
b/libcxx/include/__ranges/take_view.h
index 4204017d9249bc..811428e529f59a 100644
--- a/libcxx/include/__ranges/take_view.h
+++ b/libcxx/include/__ranges/take_view.h
@@ -183,7 +183,7 @@ class take_view<_View>::__sentinel {
   template
 requires sentinel_for, 
iterator_t<__maybe_const<_OtherConst, _View>>>
   _LIBCPP_HIDE_FROM_ABI
-  friend constexpr bool operator==(const _Iter<_Const>& __lhs, const 
__sentinel& __rhs) {
+  friend constexpr bool operator==(const _Iter<_OtherConst>& __lhs, const 
__sentinel& __rhs) {
 return __lhs.count() == 0 || __lhs.base() == __rhs.__end_;
   }
 };
diff --git 
a/libcxx/test/std/ranges/range.adaptors/range.take/sentinel/base.pass.cpp 
b/libcxx/test/std/ranges/range.adaptors/range.take/range.take.sentinel/base.pass.cpp
similarity index 83%
rename from 
libcxx/test/std/ranges/range.adaptors/range.take/sentinel/base.pass.cpp
rename to 
libcxx/test/std/ranges/range.adaptors/range.take/range.take.sentinel/base.pass.cpp
index c949eb7cc08469..15b2b5476e86dd 100644
--- a/libcxx/test/std/ranges/range.adaptors/range.take/sentinel/base.pass.cpp
+++ 
b/libcxx/test/std/ranges/range.adaptors/range.take/range.take.sentinel/base.pass.cpp
@@ -8,10 +8,7 @@
 
 // UNSUPPORTED: c++03, c++11, c++14, c++17
 
-// sentinel() = default;
-// constexpr explicit sentinel(sentinel_t end);
-// constexpr sentinel(sentinel s)
-//   requires Const && convertible_to, sentinel_t>;
+// constexpr sentinel_t base() const;
 
 #include 
 #include 
diff --git 
a/libcxx/test/std/ranges/range.adaptors/range.take/sentinel/ctor.pass.cpp 
b/libcxx/test/std/ranges/range.adaptors/range.take/range.take.sentinel/ctor.pass.cpp
similarity index 100%
rename from 
libcxx/test/std/ranges/range.adaptors/range.take/sentinel/ctor.pass.cpp
rename to 
libcxx/test/std/ranges/range.adaptors/range.take/range.take.sentinel/ctor.pass.cpp
diff --git 
a/libcxx/test/std/ranges/range.adaptors/range.take/range.take.sentinel/eq.pass.cpp
 
b/libcxx/test/std/ranges/range.adaptors/range.take/range.take.sentinel/eq.pass.cpp
new file mode 100644
index 00..f20c29b4c64714
--- /dev/null
+++ 
b/libcxx/test/std/ranges/range.adaptors/range.take/range.take.sentinel/eq.pass.cpp
@@ -0,0 +1,192 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+
+// friend constexpr bool operator==(const CI& y, const sentinel& x);
+// template
+//   requires sentinel_for, 
iterator_t>>
+// friend constexpr bool operator==(const CI& y, const sentinel& 
x);
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "test_iterators.h"
+
+template 
+class StrictIterator {
+  using Base = std::conditional_t;
+  Base base_;
+
+public:
+  using value_type  = int;
+  using difference_type = std::ptrdiff_t;
+
+  constexpr explicit StrictIterator(Base base) : base_(base) {}
+
+  StrictIterator(StrictIterator&&)= default;
+  StrictIterator& operator=(StrictIterator&&) = default;
+
+  constexpr StrictIterator& operator++() {
+++base_;
+return *this;
+  }
+
+  constexpr void operator++(int) { ++*this; }
+  constexpr decltype(auto) operator*() const { return *base_; }
+  constexpr Base base() const { return base_; }
+};
+
+static_assert(std::input_iterator>);
+static_assert(!std::copyable>);
+static_assert(!std::forward_iterator>);
+static_assert(std::input_iterator>);
+static_assert(!std::copyable>);
+static_assert(!std::forward_iterator>);
+
+template 
+class StrictSentinel {
+  using Base = std::conditional_t;
+  Base base_;
+
+public:
+  StrictSentinel() = def

[clang] [clang-format] Fix parsing of `operator<() {}` (PR #75144)

2023-12-13 Thread via cfe-commits

https://github.com/XDeme updated https://github.com/llvm/llvm-project/pull/75144

>From dddc20d967498c739baedb8d67303a28596f09e0 Mon Sep 17 00:00:00 2001
From: XDeme 
Date: Tue, 12 Dec 2023 03:06:56 -0300
Subject: [PATCH 1/3] Fix operator<() parsing

---
 clang/lib/Format/TokenAnnotator.cpp   |  9 +
 clang/unittests/Format/FormatTest.cpp |  7 +++
 clang/unittests/Format/TokenAnnotatorTest.cpp | 11 +++
 3 files changed, 27 insertions(+)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index eaccb5881ca30f..957612088c7bb0 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -23,6 +23,9 @@
 
 namespace clang {
 namespace format {
+static bool isFunctionDeclarationName(bool IsCpp, const FormatToken &Current,
+  const AnnotatedLine &Line,
+  FormatToken *&ClosingParen);
 
 static bool mustBreakAfterAttributes(const FormatToken &Tok,
  const FormatStyle &Style) {
@@ -164,6 +167,12 @@ class AnnotatingParser {
TT_OverloadedOperatorLParen))) {
 return false;
   }
+  FormatToken *ClosingParen = nullptr;
+  if (Previous.Previous->is(tok::kw_operator) &&
+  isFunctionDeclarationName(Style.isCpp(), *Previous.Previous, Line,
+ClosingParen)) {
+return false;
+  }
 }
 
 FormatToken *Left = CurrentToken->Previous;
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 24b2fd599dc397..79013a473a7c2e 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -11727,6 +11727,13 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
"  void func(type &a) { a & member; }\n"
"  anotherType &member;\n"
"}");
+
+  Style.ReferenceAlignment = FormatStyle::RAS_Left;
+  verifyFormat("class Foo {\n"
+   "  void operator<(Foo&) {}\n"
+   "  Foo& f;\n"
+   "};",
+   Style);
 }
 
 TEST_F(FormatTest, UnderstandsAttributes) {
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 65b1f0f4b57659..58a782f909d6aa 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -298,6 +298,17 @@ TEST_F(TokenAnnotatorTest, UnderstandsUsesOfStarAndAmp) {
   ASSERT_EQ(Tokens.size(), 12u) << Tokens;
   EXPECT_TOKEN(Tokens[2], tok::identifier, TT_TypeName);
   EXPECT_TOKEN(Tokens[3], tok::star, TT_PointerOrReference);
+
+  Tokens = annotate("class Foo {\n"
+"void operator<(Foo&) {}\n"
+"Foo& f;\n"
+"};");
+  ASSERT_EQ(Tokens.size(), 19u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::kw_operator, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[5], tok::less, TT_OverloadedOperator);
+  EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_OverloadedOperatorLParen);
+  EXPECT_TOKEN(Tokens[10], tok::l_brace, TT_FunctionLBrace);
+  EXPECT_TOKEN(Tokens[13], tok::amp, TT_PointerOrReference);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsUsesOfPlusAndMinus) {

>From 8e5f57d51f4d542ff6bb4bf5faab04ceb709f8d0 Mon Sep 17 00:00:00 2001
From: XDeme 
Date: Tue, 12 Dec 2023 23:39:52 -0300
Subject: [PATCH 2/3] Addresses comments

---
 clang/lib/Format/TokenAnnotator.cpp | 7 +--
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 957612088c7bb0..bcf46d7ef46029 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -23,9 +23,6 @@
 
 namespace clang {
 namespace format {
-static bool isFunctionDeclarationName(bool IsCpp, const FormatToken &Current,
-  const AnnotatedLine &Line,
-  FormatToken *&ClosingParen);
 
 static bool mustBreakAfterAttributes(const FormatToken &Tok,
  const FormatStyle &Style) {
@@ -167,10 +164,8 @@ class AnnotatingParser {
TT_OverloadedOperatorLParen))) {
 return false;
   }
-  FormatToken *ClosingParen = nullptr;
   if (Previous.Previous->is(tok::kw_operator) &&
-  isFunctionDeclarationName(Style.isCpp(), *Previous.Previous, Line,
-ClosingParen)) {
+  CurrentToken->is(tok::l_paren)) {
 return false;
   }
 }

>From 188958463343f930c7b0a7f350356873664d556c Mon Sep 17 00:00:00 2001
From: XDeme 
Date: Wed, 13 Dec 2023 09:34:53 -0300
Subject: [PATCH 3/3] Addresses comments

---
 clang/unittests/Format/FormatTest.cpp |  7 ---
 clang/unittests/Format/TokenAnnotatorTest.cpp | 10 +-
 2 files changed, 5 insertions(+), 12 deletions(-)

diff --git a/clan

[clang] [clang] Report narrowing conversions with const references (PR #75332)

2023-12-13 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon created 
https://github.com/llvm/llvm-project/pull/75332

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

>From d0a7276eb8014693656d3d931616d56ffe46730c Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Wed, 13 Dec 2023 04:25:12 -0800
Subject: [PATCH] [clang] Report narrowing conversions with const references

Fixes https://github.com/llvm/llvm-project/issues/63151
---
 clang/docs/ReleaseNotes.rst|  3 +++
 clang/lib/Sema/SemaInit.cpp| 30 ++
 clang/test/SemaCXX/GH63151.cpp | 12 
 3 files changed, 33 insertions(+), 12 deletions(-)
 create mode 100644 clang/test/SemaCXX/GH63151.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 05d59d0da264f3..2aba1740a6b610 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -521,6 +521,9 @@ Improvements to Clang's diagnostics
   |   ~~~^
 
 - Clang now diagnoses definitions of friend function specializations, e.g. 
``friend void f<>(int) {}``.
+- Clang now diagnoses narrowing conversions involving const references.
+  (`#63151: `_).
+
 
 Improvements to Clang's time-trace
 --
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 4028b2d642b212..7ff1b55d1fcba0 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -4432,7 +4432,8 @@ static void TryReferenceInitializationCore(Sema &S,
Qualifiers T1Quals,
QualType cv2T2, QualType T2,
Qualifiers T2Quals,
-   InitializationSequence &Sequence);
+   InitializationSequence &Sequence,
+   bool TopLevelOfInitList);
 
 static void TryValueInitialization(Sema &S,
const InitializedEntity &Entity,
@@ -4486,7 +4487,8 @@ static void TryReferenceListInitialization(Sema &S,
 if (RefRelationship >= Sema::Ref_Related) {
   // Try to bind the reference here.
   TryReferenceInitializationCore(S, Entity, Kind, Initializer, cv1T1, T1,
- T1Quals, cv2T2, T2, T2Quals, Sequence);
+ T1Quals, cv2T2, T2, T2Quals, Sequence,
+ true);
   if (Sequence)
 Sequence.RewrapReferenceInitList(cv1T1, InitList);
   return;
@@ -4945,11 +4947,11 @@ static void CheckCXX98CompatAccessibleCopy(Sema &S,
Expr *CurInitExpr);
 
 /// Attempt reference initialization (C++0x [dcl.init.ref])
-static void TryReferenceInitialization(Sema &S,
-   const InitializedEntity &Entity,
+static void TryReferenceInitialization(Sema &S, const InitializedEntity 
&Entity,
const InitializationKind &Kind,
Expr *Initializer,
-   InitializationSequence &Sequence) {
+   InitializationSequence &Sequence,
+   bool TopLevelOfInitList) {
   QualType DestType = Entity.getType();
   QualType cv1T1 = DestType->castAs()->getPointeeType();
   Qualifiers T1Quals;
@@ -4967,7 +4969,8 @@ static void TryReferenceInitialization(Sema &S,
 
   // Delegate everything else to a subfunction.
   TryReferenceInitializationCore(S, Entity, Kind, Initializer, cv1T1, T1,
- T1Quals, cv2T2, T2, T2Quals, Sequence);
+ T1Quals, cv2T2, T2, T2Quals, Sequence,
+ TopLevelOfInitList);
 }
 
 /// Determine whether an expression is a non-referenceable glvalue (one to
@@ -4990,7 +4993,8 @@ static void TryReferenceInitializationCore(Sema &S,
Qualifiers T1Quals,
QualType cv2T2, QualType T2,
Qualifiers T2Quals,
-   InitializationSequence &Sequence) {
+   InitializationSequence &Sequence,
+   bool TopLevelOfInitList) {
   QualType DestType = Entity.getType();
   SourceLocation DeclLoc = Initializer->getBeginLoc();
 
@@ -5264,7 +5268,8 @@ static void TryReferenceInitializationCore(Sema &S,
   Sequence.SetFailed(InitializationSequence::FK_ReferenceInitFailed);
 return;
   } else {
-Sequence.AddConversionSequenceStep(ICS, TempEntity.getType());
+Sequence.AddConversionSequenceStep(ICS, TempEntity.getType(),
+   TopLevelOfInitList);
   }
 
   //[...] If T1 is r

[clang] [clang] Report narrowing conversions with const references (PR #75332)

2023-12-13 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Mariya Podchishchaeva (Fznamznon)


Changes

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

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+3) 
- (modified) clang/lib/Sema/SemaInit.cpp (+18-12) 
- (added) clang/test/SemaCXX/GH63151.cpp (+12) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 05d59d0da264f3..2aba1740a6b610 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -521,6 +521,9 @@ Improvements to Clang's diagnostics
   |   ~~~^
 
 - Clang now diagnoses definitions of friend function specializations, e.g. 
``friend void f<>(int) {}``.
+- Clang now diagnoses narrowing conversions involving const references.
+  (`#63151: `_).
+
 
 Improvements to Clang's time-trace
 --
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 4028b2d642b212..7ff1b55d1fcba0 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -4432,7 +4432,8 @@ static void TryReferenceInitializationCore(Sema &S,
Qualifiers T1Quals,
QualType cv2T2, QualType T2,
Qualifiers T2Quals,
-   InitializationSequence &Sequence);
+   InitializationSequence &Sequence,
+   bool TopLevelOfInitList);
 
 static void TryValueInitialization(Sema &S,
const InitializedEntity &Entity,
@@ -4486,7 +4487,8 @@ static void TryReferenceListInitialization(Sema &S,
 if (RefRelationship >= Sema::Ref_Related) {
   // Try to bind the reference here.
   TryReferenceInitializationCore(S, Entity, Kind, Initializer, cv1T1, T1,
- T1Quals, cv2T2, T2, T2Quals, Sequence);
+ T1Quals, cv2T2, T2, T2Quals, Sequence,
+ true);
   if (Sequence)
 Sequence.RewrapReferenceInitList(cv1T1, InitList);
   return;
@@ -4945,11 +4947,11 @@ static void CheckCXX98CompatAccessibleCopy(Sema &S,
Expr *CurInitExpr);
 
 /// Attempt reference initialization (C++0x [dcl.init.ref])
-static void TryReferenceInitialization(Sema &S,
-   const InitializedEntity &Entity,
+static void TryReferenceInitialization(Sema &S, const InitializedEntity 
&Entity,
const InitializationKind &Kind,
Expr *Initializer,
-   InitializationSequence &Sequence) {
+   InitializationSequence &Sequence,
+   bool TopLevelOfInitList) {
   QualType DestType = Entity.getType();
   QualType cv1T1 = DestType->castAs()->getPointeeType();
   Qualifiers T1Quals;
@@ -4967,7 +4969,8 @@ static void TryReferenceInitialization(Sema &S,
 
   // Delegate everything else to a subfunction.
   TryReferenceInitializationCore(S, Entity, Kind, Initializer, cv1T1, T1,
- T1Quals, cv2T2, T2, T2Quals, Sequence);
+ T1Quals, cv2T2, T2, T2Quals, Sequence,
+ TopLevelOfInitList);
 }
 
 /// Determine whether an expression is a non-referenceable glvalue (one to
@@ -4990,7 +4993,8 @@ static void TryReferenceInitializationCore(Sema &S,
Qualifiers T1Quals,
QualType cv2T2, QualType T2,
Qualifiers T2Quals,
-   InitializationSequence &Sequence) {
+   InitializationSequence &Sequence,
+   bool TopLevelOfInitList) {
   QualType DestType = Entity.getType();
   SourceLocation DeclLoc = Initializer->getBeginLoc();
 
@@ -5264,7 +5268,8 @@ static void TryReferenceInitializationCore(Sema &S,
   Sequence.SetFailed(InitializationSequence::FK_ReferenceInitFailed);
 return;
   } else {
-Sequence.AddConversionSequenceStep(ICS, TempEntity.getType());
+Sequence.AddConversionSequenceStep(ICS, TempEntity.getType(),
+   TopLevelOfInitList);
   }
 
   //[...] If T1 is reference-related to T2, cv1 must be the
@@ -6228,7 +6233,8 @@ void InitializationSequence::InitializeFrom(Sema &S,
 else if (isa(Args[0]))
   SetFailed(FK_ParenthesizedListInitForReference);
 else
-  TryReferenceInitialization(S, Entity, Kind, Args[0], *this);

[clang] ab380c2 - [SystemZ][z/OS] Complete EBCDIC I/O support (#75212)

2023-12-13 Thread via cfe-commits

Author: Abhina Sree
Date: 2023-12-13T07:46:02-05:00
New Revision: ab380c287a42c0701cd86ae2932c0cb125b9a294

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

LOG: [SystemZ][z/OS] Complete EBCDIC I/O support (#75212)

This patch completes the support for EBCDIC I/O support on z/OS using the 
autoconversion functions.

Added: 


Modified: 
clang/tools/c-arcmt-test/c-arcmt-test.c
clang/tools/c-index-test/c-index-test.c
llvm/include/llvm/Support/AutoConvert.h
llvm/lib/Support/AutoConvert.cpp
llvm/lib/Support/InitLLVM.cpp
llvm/lib/Support/Unix/Program.inc
llvm/lib/Support/raw_ostream.cpp
llvm/utils/count/CMakeLists.txt
llvm/utils/count/count.c

Removed: 




diff  --git a/clang/tools/c-arcmt-test/c-arcmt-test.c 
b/clang/tools/c-arcmt-test/c-arcmt-test.c
index 3bbb2d5d6a8564..00999f188c7dce 100644
--- a/clang/tools/c-arcmt-test/c-arcmt-test.c
+++ b/clang/tools/c-arcmt-test/c-arcmt-test.c
@@ -1,8 +1,9 @@
 /* c-arcmt-test.c */
 
 #include "clang-c/Index.h"
-#include 
+#include "llvm/Support/AutoConvert.h"
 #include 
+#include 
 #include 
 #if defined(_WIN32)
 #include 
@@ -107,6 +108,14 @@ static void flush_atexit(void) {
 }
 
 int main(int argc, const char **argv) {
+#ifdef __MVS__
+  if (enableAutoConversion(fileno(stdout)) == -1)
+fprintf(stderr, "Setting conversion on stdout failed\n");
+
+  if (enableAutoConversion(fileno(stderr)) == -1)
+fprintf(stderr, "Setting conversion on stderr failed\n");
+#endif
+
   thread_info client_data;
 
   atexit(flush_atexit);

diff  --git a/clang/tools/c-index-test/c-index-test.c 
b/clang/tools/c-index-test/c-index-test.c
index 2c0c9cb8eb5e42..6fa400a0675b7a 100644
--- a/clang/tools/c-index-test/c-index-test.c
+++ b/clang/tools/c-index-test/c-index-test.c
@@ -8,6 +8,7 @@
 #include "clang-c/Documentation.h"
 #include "clang-c/Index.h"
 #include "clang/Config/config.h"
+#include "llvm/Support/AutoConvert.h"
 #include 
 #include 
 #include 
@@ -5150,6 +5151,14 @@ static void flush_atexit(void) {
 int main(int argc, const char **argv) {
   thread_info client_data;
 
+#ifdef __MVS__
+  if (enableAutoConversion(fileno(stdout)) == -1)
+fprintf(stderr, "Setting conversion on stdout failed\n");
+
+  if (enableAutoConversion(fileno(stderr)) == -1)
+fprintf(stderr, "Setting conversion on stderr failed\n");
+#endif
+
   atexit(flush_atexit);
 
 #ifdef CLANG_HAVE_LIBXML

diff  --git a/llvm/include/llvm/Support/AutoConvert.h 
b/llvm/include/llvm/Support/AutoConvert.h
index bcf7473feac8f7..6608dd461d7265 100644
--- a/llvm/include/llvm/Support/AutoConvert.h
+++ b/llvm/include/llvm/Support/AutoConvert.h
@@ -15,10 +15,27 @@
 #define LLVM_SUPPORT_AUTOCONVERT_H
 
 #ifdef __MVS__
-#define CCSID_IBM_1047 1047
-#define CCSID_UTF_8 1208
+#include <_Ccsid.h>
+#ifdef __cplusplus
 #include 
+#endif // __cplusplus
 
+#define CCSID_IBM_1047 1047
+#define CCSID_UTF_8 1208
+#define CCSID_ISO8859_1 819
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
+int enableAutoConversion(int FD);
+int disableAutoConversion(int FD);
+int restoreStdHandleAutoConversion(int FD);
+int overrideAutoConversion(int FD, char *Filetag);
+#ifdef __cplusplus
+}
+#endif // __cplusplus
+
+#ifdef __cplusplus
 namespace llvm {
 
 /// \brief Disable the z/OS enhanced ASCII auto-conversion for the file
@@ -30,10 +47,14 @@ std::error_code disableAutoConversion(int FD);
 /// codepage.
 std::error_code enableAutoConversion(int FD);
 
+/// Restore the z/OS enhanced ASCII auto-conversion for the std handle.
+std::error_code restoreStdHandleAutoConversion(int FD);
+
 /// \brief Set the tag information for a file descriptor.
 std::error_code setFileTag(int FD, int CCSID, bool Text);
 
 } // namespace llvm
+#endif // __cplusplus
 
 #endif // __MVS__
 

diff  --git a/llvm/lib/Support/AutoConvert.cpp 
b/llvm/lib/Support/AutoConvert.cpp
index 4fb7e242c34806..8170e553ac6e10 100644
--- a/llvm/lib/Support/AutoConvert.cpp
+++ b/llvm/lib/Support/AutoConvert.cpp
@@ -14,21 +14,36 @@
 #ifdef __MVS__
 
 #include "llvm/Support/AutoConvert.h"
+#include 
 #include 
 #include 
+#include 
 
-std::error_code llvm::disableAutoConversion(int FD) {
+static int savedStdHandleAutoConversionMode[3] = {-1, -1, -1};
+
+int disableAutoConversion(int FD) {
   static const struct f_cnvrt Convert = {
-  SETCVTOFF,// cvtcmd
-  0,// pccsid
-  (short)FT_BINARY, // fccsid
+  SETCVTOFF, // cvtcmd
+  0, // pccsid
+  0, // fccsid
   };
-  if (fcntl(FD, F_CONTROL_CVT, &Convert) == -1)
-return std::error_code(errno, std::generic_category());
-  return std::error_code();
+
+  return fcntl(FD, F_CONTROL_CVT, &Convert);
 }
 
-std::error_code llvm::enableAutoConversion(int FD) {
+int restoreStdHandleAutoConversion(int FD) {
+  assert(F

[clang] [llvm] [SystemZ][z/OS] Complete EBCDIC I/O support (PR #75212)

2023-12-13 Thread Abhina Sree via cfe-commits

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


[clang] [clang] Report narrowing conversions with const references (PR #75332)

2023-12-13 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 e418988175c2dee9d7c7976cf822b41aaf321c26 
d0a7276eb8014693656d3d931616d56ffe46730c -- clang/test/SemaCXX/GH63151.cpp 
clang/lib/Sema/SemaInit.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 7ff1b55d1f..b7ded88940 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -4424,16 +4424,11 @@ ResolveOverloadedFunctionForReferenceBinding(Sema &S,
   return false;
 }
 
-static void TryReferenceInitializationCore(Sema &S,
-   const InitializedEntity &Entity,
-   const InitializationKind &Kind,
-   Expr *Initializer,
-   QualType cv1T1, QualType T1,
-   Qualifiers T1Quals,
-   QualType cv2T2, QualType T2,
-   Qualifiers T2Quals,
-   InitializationSequence &Sequence,
-   bool TopLevelOfInitList);
+static void TryReferenceInitializationCore(
+Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind,
+Expr *Initializer, QualType cv1T1, QualType T1, Qualifiers T1Quals,
+QualType cv2T2, QualType T2, Qualifiers T2Quals,
+InitializationSequence &Sequence, bool TopLevelOfInitList);
 
 static void TryValueInitialization(Sema &S,
const InitializedEntity &Entity,
@@ -4985,16 +4980,11 @@ static bool isNonReferenceableGLValue(Expr *E) {
 ///
 /// We also can get here in C if we call a builtin which is declared as
 /// a function with a parameter of reference type (such as __builtin_va_end()).
-static void TryReferenceInitializationCore(Sema &S,
-   const InitializedEntity &Entity,
-   const InitializationKind &Kind,
-   Expr *Initializer,
-   QualType cv1T1, QualType T1,
-   Qualifiers T1Quals,
-   QualType cv2T2, QualType T2,
-   Qualifiers T2Quals,
-   InitializationSequence &Sequence,
-   bool TopLevelOfInitList) {
+static void TryReferenceInitializationCore(
+Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind,
+Expr *Initializer, QualType cv1T1, QualType T1, Qualifiers T1Quals,
+QualType cv2T2, QualType T2, Qualifiers T2Quals,
+InitializationSequence &Sequence, bool TopLevelOfInitList) {
   QualType DestType = Entity.getType();
   SourceLocation DeclLoc = Initializer->getBeginLoc();
 

``




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


[clang] [clang] Report narrowing conversions with const references (PR #75332)

2023-12-13 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

Formatting trouble is intentional.

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


[clang] [libcxx] [llvm] [lld] [compiler-rt] [flang] [libc] [lldb] [clang-tools-extra] [AMDGPU] Update IEEE and DX10_CLAMP for GFX12 (PR #75030)

2023-12-13 Thread Piotr Sobczak via cfe-commits

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


[clang] [libcxx] [llvm] [openmp] [libcxxabi] [compiler-rt] [flang] [mlir] [lldb] [clang-tools-extra] [MachineCopyPropagation] When the source of PreviousCopy is undef, we cannot replace sub register (

2023-12-13 Thread via cfe-commits

DianQK wrote:

> I'll try and take a look at the patch. Perhaps you are right that we need a 
> new method for the debug info to use.

Based on 
https://github.com/llvm/llvm-project/blob/fd8fa31c55a3413f643443ecf3301441428ce513/llvm/docs/InstrRefDebugInfo.md?plain=1#L125-L127,
 perhaps we could add an `isCopyLikeInstr` method? This should be a good name 
while changing very little.I 'll give it a try later.

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


[clang] [clang] Parse attribute [[gnu::no_stack_protector]] (PR #75289)

2023-12-13 Thread Sirui Mu via cfe-commits

https://github.com/Lancern updated 
https://github.com/llvm/llvm-project/pull/75289

>From d8de529580101ba68dc1c981aec8711aa0c58da4 Mon Sep 17 00:00:00 2001
From: Sirui Mu 
Date: Wed, 13 Dec 2023 06:51:09 +
Subject: [PATCH 1/2] [clang] Parse attribute [[gnu::no_stack_protector]]

This commit adds relative TableGen definitions to parse the
[[gnu::no_stack_protector]] attribute.
---
 clang/include/clang/Basic/Attr.td | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 0d94ea2851c9ab..0344fa23e15369 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2212,7 +2212,8 @@ def NotTailCalled : InheritableAttr {
 def : MutualExclusions<[AlwaysInline, NotTailCalled]>;
 
 def NoStackProtector : InheritableAttr {
-  let Spellings = [Clang<"no_stack_protector">, Declspec<"safebuffers">];
+  let Spellings = [Clang<"no_stack_protector">, CXX11<"gnu", 
"no_stack_protector">,
+   C23<"gnu", "no_stack_protector">, Declspec<"safebuffers">];
   let Subjects = SubjectList<[Function]>;
   let Documentation = [NoStackProtectorDocs];
   let SimpleHandler = 1;

>From 0efedf8a3af361077c59174b008862cc8a0a Mon Sep 17 00:00:00 2001
From: Sirui Mu 
Date: Wed, 13 Dec 2023 14:29:12 +0800
Subject: [PATCH 2/2] [clang] Add unit tests for parsing
 [[gnu::no_stack_protector]]

---
 clang/test/Parser/gnu-attributes.c   | 4 
 clang/test/Parser/gnu-attributes.cpp | 4 
 2 files changed, 8 insertions(+)
 create mode 100644 clang/test/Parser/gnu-attributes.c
 create mode 100644 clang/test/Parser/gnu-attributes.cpp

diff --git a/clang/test/Parser/gnu-attributes.c 
b/clang/test/Parser/gnu-attributes.c
new file mode 100644
index 00..f75728915b685d
--- /dev/null
+++ b/clang/test/Parser/gnu-attributes.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c23 %s
+// expected-no-diagnostics
+
+[[gnu::no_stack_protector]] void test1(int i) {} // ok
diff --git a/clang/test/Parser/gnu-attributes.cpp 
b/clang/test/Parser/gnu-attributes.cpp
new file mode 100644
index 00..a1c3c7abe92ed8
--- /dev/null
+++ b/clang/test/Parser/gnu-attributes.cpp
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify 
-std=c++11 %s
+// expected-no-diagnostics
+
+[[gnu::no_stack_protector]] void test1(int i) {} // ok

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


[lld] [libc] [clang] [llvm] [lldb] [mlir] [clang-tools-extra] [libcxx] [compiler-rt] [MLIR][LLVM] Add Continuous Loop Peeling transform to SCF (PR #71555)

2023-12-13 Thread via cfe-commits

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


[clang] [llvm] [LLVM][IR] Replace ConstantInt's specialisation of getType() with getIntegerType(). (PR #75217)

2023-12-13 Thread Nikita Popov via cfe-commits

nikic wrote:

> Most all the recommended changes assume the code paths will work equally well 
> for vector types as they do for scalar types. Can we be so sure this is the 
> case? This is why I opted to keep the casting assertions with the exception 
> of a few places where I could be sure the code path was clean.

I don't think any of those code paths would cause a silent miscompile with 
vectors, which is the only thing we have to be concerned about (if it just hits 
a different assertion, that's fine).

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


[clang] [clang] Parse attribute [[gnu::no_stack_protector]] (PR #75289)

2023-12-13 Thread Yingchi Long via cfe-commits

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


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


[clang] [clang] Parse attribute [[gnu::no_stack_protector]] (PR #75289)

2023-12-13 Thread Yingchi Long via cfe-commits


@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c23 %s

inclyc wrote:

the file name `gnu-attributes.c` is too "generic", perhaps better place these 
files under `clang/test/Sema/attr-no-stack-protector.c` and 
`clang/test/SemaCXX/attr-no-stack-protector.c`

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


[clang] [clang] Parse attribute [[gnu::no_stack_protector]] (PR #75289)

2023-12-13 Thread Yingchi Long via cfe-commits

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


[lld] [libc] [clang] [flang] [llvm] [lldb] [clang-tools-extra] [libcxx] [mlir] [compiler-rt] [AMDGPU] Min/max changes for GFX12 (PR #75214)

2023-12-13 Thread Piotr Sobczak via cfe-commits

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


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

2023-12-13 Thread Yi Wu via cfe-commits

yi-wu-arm wrote:

Hi @jeanPerier Sorry to throw a ping. I have changed the structure and 
implementation of `getlog`, it now does the following:
On Linux: use `getlogin_r`, if fail get from environment variable. 
On Windows: get from environment variable to avoid linking to library 
`Advapi32.lib`.
Username will be pad with spaces as how gfortran does it.
e.g.
```
loginNameX   <- if length is longer than name, pad with 
space
loginName<- just right
logi <- if shorter still fill with name
```
Proper test has been added on both Linux and Windows for `getlog_r` and 
environment variable.

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


[clang] [llvm] [SystemZ][z/OS] Add missing strnlen function for z/OS to fix build failures (PR #75339)

2023-12-13 Thread Abhina Sree via cfe-commits

https://github.com/abhina-sree created 
https://github.com/llvm/llvm-project/pull/75339

This patch adds strnlen to the zOSSupport.h file to fix build failures in 
multiple files.

>From 1b234e926dc6396fe4053f3c3463ed36e5d58778 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Wed, 13 Dec 2023 08:35:52 -0500
Subject: [PATCH] fix strnlen build failure for z/OS

---
 clang/lib/Lex/HeaderMap.cpp  | 1 +
 llvm/include/llvm/Support/SystemZ/zOSSupport.h   | 8 
 llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp| 1 +
 llvm/lib/ObjCopy/MachO/MachOObject.cpp   | 1 +
 llvm/lib/ObjCopy/MachO/MachOReader.cpp   | 1 +
 llvm/lib/ObjectYAML/MachOEmitter.cpp | 1 +
 llvm/lib/ObjectYAML/MachOYAML.cpp| 1 +
 llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp | 1 +
 llvm/tools/llvm-readobj/ELFDumper.cpp| 1 +
 llvm/tools/llvm-readobj/ObjDumper.cpp| 1 +
 llvm/tools/obj2yaml/macho2yaml.cpp   | 1 +
 11 files changed, 18 insertions(+)

diff --git a/clang/lib/Lex/HeaderMap.cpp b/clang/lib/Lex/HeaderMap.cpp
index 22a1532c2d9383..adc56dc270e5f0 100644
--- a/clang/lib/Lex/HeaderMap.cpp
+++ b/clang/lib/Lex/HeaderMap.cpp
@@ -20,6 +20,7 @@
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/SwapByteOrder.h"
+#include "llvm/Support/SystemZ/zOSSupport.h"
 #include "llvm/Support/Debug.h"
 #include 
 #include 
diff --git a/llvm/include/llvm/Support/SystemZ/zOSSupport.h 
b/llvm/include/llvm/Support/SystemZ/zOSSupport.h
index ee78147cb21554..f9a61f887d5dd1 100644
--- a/llvm/include/llvm/Support/SystemZ/zOSSupport.h
+++ b/llvm/include/llvm/Support/SystemZ/zOSSupport.h
@@ -35,5 +35,13 @@ inline pid_t wait4(pid_t pid, int *wstatus, int options,
   return Result;
 }
 
+// z/OS Unix System Services does not have strnlen() support, so the strnlen()
+// function is implemented here.
+inline std::size_t strnlen(const char *S, std::size_t MaxLen) {
+  const char *PtrToNullChar =
+  static_cast(std::memchr(S, '\0', MaxLen));
+  return PtrToNullChar ? PtrToNullChar - S : MaxLen;
+}
+
 #endif
 #endif
diff --git a/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp 
b/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp
index 067ef39d90522f..a3d4ba3a94f7ac 100644
--- a/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp
+++ b/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp
@@ -10,6 +10,7 @@
 #include "llvm/Support/Alignment.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/SystemZ/zOSSupport.h"
 
 using namespace llvm;
 using namespace llvm::objcopy::macho;
diff --git a/llvm/lib/ObjCopy/MachO/MachOObject.cpp 
b/llvm/lib/ObjCopy/MachO/MachOObject.cpp
index 9a4abadc8710a4..d593d6788e112f 100644
--- a/llvm/lib/ObjCopy/MachO/MachOObject.cpp
+++ b/llvm/lib/ObjCopy/MachO/MachOObject.cpp
@@ -8,6 +8,7 @@
 
 #include "MachOObject.h"
 #include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/Support/SystemZ/zOSSupport.h"
 #include 
 
 using namespace llvm;
diff --git a/llvm/lib/ObjCopy/MachO/MachOReader.cpp 
b/llvm/lib/ObjCopy/MachO/MachOReader.cpp
index 25f8c020cde94d..4549977c12c3db 100644
--- a/llvm/lib/ObjCopy/MachO/MachOReader.cpp
+++ b/llvm/lib/ObjCopy/MachO/MachOReader.cpp
@@ -11,6 +11,7 @@
 #include "llvm/BinaryFormat/MachO.h"
 #include "llvm/Object/MachO.h"
 #include "llvm/Support/Errc.h"
+#include "llvm/Support/SystemZ/zOSSupport.h"
 #include 
 
 using namespace llvm;
diff --git a/llvm/lib/ObjectYAML/MachOEmitter.cpp 
b/llvm/lib/ObjectYAML/MachOEmitter.cpp
index 6bcc2cee27edb6..c08b389daea9c3 100644
--- a/llvm/lib/ObjectYAML/MachOEmitter.cpp
+++ b/llvm/lib/ObjectYAML/MachOEmitter.cpp
@@ -19,6 +19,7 @@
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/LEB128.h"
+#include "llvm/Support/SystemZ/zOSSupport.h"
 #include "llvm/Support/YAMLTraits.h"
 #include "llvm/Support/raw_ostream.h"
 
diff --git a/llvm/lib/ObjectYAML/MachOYAML.cpp 
b/llvm/lib/ObjectYAML/MachOYAML.cpp
index 86342c5501c708..82b2eaecec9be9 100644
--- a/llvm/lib/ObjectYAML/MachOYAML.cpp
+++ b/llvm/lib/ObjectYAML/MachOYAML.cpp
@@ -14,6 +14,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/BinaryFormat/MachO.h"
 #include "llvm/Support/Format.h"
+#include "llvm/Support/SystemZ/zOSSupport.h"
 #include "llvm/Support/YAMLTraits.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/Host.h"
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp 
b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
index 2d396df7337f89..7bb0218ed53386 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
@@ -25,6 +25,7 @@
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Program.h"
 #include "llvm/Support/Signals.h"
+#include "llvm/Support/SystemZ/zOSSupport.h"
 
 #ifdef __linux__
 #ifdef HAVE_LIBPFM
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp 
b/llvm/tools/llvm-readobj/ELFDumpe

[clang] [llvm] [SystemZ][z/OS] Add missing strnlen function for z/OS to fix build failures (PR #75339)

2023-12-13 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Abhina Sree (abhina-sree)


Changes

This patch adds strnlen to the zOSSupport.h file to fix build failures in 
multiple files.

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


11 Files Affected:

- (modified) clang/lib/Lex/HeaderMap.cpp (+1) 
- (modified) llvm/include/llvm/Support/SystemZ/zOSSupport.h (+8) 
- (modified) llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp (+1) 
- (modified) llvm/lib/ObjCopy/MachO/MachOObject.cpp (+1) 
- (modified) llvm/lib/ObjCopy/MachO/MachOReader.cpp (+1) 
- (modified) llvm/lib/ObjectYAML/MachOEmitter.cpp (+1) 
- (modified) llvm/lib/ObjectYAML/MachOYAML.cpp (+1) 
- (modified) llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp (+1) 
- (modified) llvm/tools/llvm-readobj/ELFDumper.cpp (+1) 
- (modified) llvm/tools/llvm-readobj/ObjDumper.cpp (+1) 
- (modified) llvm/tools/obj2yaml/macho2yaml.cpp (+1) 


``diff
diff --git a/clang/lib/Lex/HeaderMap.cpp b/clang/lib/Lex/HeaderMap.cpp
index 22a1532c2d9383..adc56dc270e5f0 100644
--- a/clang/lib/Lex/HeaderMap.cpp
+++ b/clang/lib/Lex/HeaderMap.cpp
@@ -20,6 +20,7 @@
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/SwapByteOrder.h"
+#include "llvm/Support/SystemZ/zOSSupport.h"
 #include "llvm/Support/Debug.h"
 #include 
 #include 
diff --git a/llvm/include/llvm/Support/SystemZ/zOSSupport.h 
b/llvm/include/llvm/Support/SystemZ/zOSSupport.h
index ee78147cb21554..f9a61f887d5dd1 100644
--- a/llvm/include/llvm/Support/SystemZ/zOSSupport.h
+++ b/llvm/include/llvm/Support/SystemZ/zOSSupport.h
@@ -35,5 +35,13 @@ inline pid_t wait4(pid_t pid, int *wstatus, int options,
   return Result;
 }
 
+// z/OS Unix System Services does not have strnlen() support, so the strnlen()
+// function is implemented here.
+inline std::size_t strnlen(const char *S, std::size_t MaxLen) {
+  const char *PtrToNullChar =
+  static_cast(std::memchr(S, '\0', MaxLen));
+  return PtrToNullChar ? PtrToNullChar - S : MaxLen;
+}
+
 #endif
 #endif
diff --git a/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp 
b/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp
index 067ef39d90522f..a3d4ba3a94f7ac 100644
--- a/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp
+++ b/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp
@@ -10,6 +10,7 @@
 #include "llvm/Support/Alignment.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/SystemZ/zOSSupport.h"
 
 using namespace llvm;
 using namespace llvm::objcopy::macho;
diff --git a/llvm/lib/ObjCopy/MachO/MachOObject.cpp 
b/llvm/lib/ObjCopy/MachO/MachOObject.cpp
index 9a4abadc8710a4..d593d6788e112f 100644
--- a/llvm/lib/ObjCopy/MachO/MachOObject.cpp
+++ b/llvm/lib/ObjCopy/MachO/MachOObject.cpp
@@ -8,6 +8,7 @@
 
 #include "MachOObject.h"
 #include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/Support/SystemZ/zOSSupport.h"
 #include 
 
 using namespace llvm;
diff --git a/llvm/lib/ObjCopy/MachO/MachOReader.cpp 
b/llvm/lib/ObjCopy/MachO/MachOReader.cpp
index 25f8c020cde94d..4549977c12c3db 100644
--- a/llvm/lib/ObjCopy/MachO/MachOReader.cpp
+++ b/llvm/lib/ObjCopy/MachO/MachOReader.cpp
@@ -11,6 +11,7 @@
 #include "llvm/BinaryFormat/MachO.h"
 #include "llvm/Object/MachO.h"
 #include "llvm/Support/Errc.h"
+#include "llvm/Support/SystemZ/zOSSupport.h"
 #include 
 
 using namespace llvm;
diff --git a/llvm/lib/ObjectYAML/MachOEmitter.cpp 
b/llvm/lib/ObjectYAML/MachOEmitter.cpp
index 6bcc2cee27edb6..c08b389daea9c3 100644
--- a/llvm/lib/ObjectYAML/MachOEmitter.cpp
+++ b/llvm/lib/ObjectYAML/MachOEmitter.cpp
@@ -19,6 +19,7 @@
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/LEB128.h"
+#include "llvm/Support/SystemZ/zOSSupport.h"
 #include "llvm/Support/YAMLTraits.h"
 #include "llvm/Support/raw_ostream.h"
 
diff --git a/llvm/lib/ObjectYAML/MachOYAML.cpp 
b/llvm/lib/ObjectYAML/MachOYAML.cpp
index 86342c5501c708..82b2eaecec9be9 100644
--- a/llvm/lib/ObjectYAML/MachOYAML.cpp
+++ b/llvm/lib/ObjectYAML/MachOYAML.cpp
@@ -14,6 +14,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/BinaryFormat/MachO.h"
 #include "llvm/Support/Format.h"
+#include "llvm/Support/SystemZ/zOSSupport.h"
 #include "llvm/Support/YAMLTraits.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/Host.h"
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp 
b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
index 2d396df7337f89..7bb0218ed53386 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
@@ -25,6 +25,7 @@
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Program.h"
 #include "llvm/Support/Signals.h"
+#include "llvm/Support/SystemZ/zOSSupport.h"
 
 #ifdef __linux__
 #ifdef HAVE_LIBPFM
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp 
b/llvm/tools/llvm-readobj/ELFDumper.cpp
index 96564211622d26..3cf7c5a3b18955 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tool

[clang] [llvm] [SystemZ][z/OS] Add missing strnlen function for z/OS to fix build failures (PR #75339)

2023-12-13 Thread Fanbo Meng via cfe-commits

https://github.com/fanbo-meng approved this pull request.

LGTM

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


[clang] [llvm] [SystemZ][z/OS] Add missing strnlen function for z/OS to fix build failures (PR #75339)

2023-12-13 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 c2d3188d5dcb8158d9b8fa2a85f984fc621c7044 
1b234e926dc6396fe4053f3c3463ed36e5d58778 -- clang/lib/Lex/HeaderMap.cpp 
llvm/include/llvm/Support/SystemZ/zOSSupport.h 
llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp 
llvm/lib/ObjCopy/MachO/MachOObject.cpp llvm/lib/ObjCopy/MachO/MachOReader.cpp 
llvm/lib/ObjectYAML/MachOEmitter.cpp llvm/lib/ObjectYAML/MachOYAML.cpp 
llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp 
llvm/tools/llvm-readobj/ELFDumper.cpp llvm/tools/llvm-readobj/ObjDumper.cpp 
llvm/tools/obj2yaml/macho2yaml.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Lex/HeaderMap.cpp b/clang/lib/Lex/HeaderMap.cpp
index adc56dc270..00bf880726 100644
--- a/clang/lib/Lex/HeaderMap.cpp
+++ b/clang/lib/Lex/HeaderMap.cpp
@@ -11,17 +11,17 @@
 
//===--===//
 
 #include "clang/Lex/HeaderMap.h"
-#include "clang/Lex/HeaderMapTypes.h"
 #include "clang/Basic/CharInfo.h"
 #include "clang/Basic/FileManager.h"
+#include "clang/Lex/HeaderMapTypes.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/DataTypes.h"
+#include "llvm/Support/Debug.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/SwapByteOrder.h"
 #include "llvm/Support/SystemZ/zOSSupport.h"
-#include "llvm/Support/Debug.h"
 #include 
 #include 
 #include 

``




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


[clang] [llvm] [SystemZ][z/OS] Add missing strnlen function for z/OS to fix build failures (PR #75339)

2023-12-13 Thread Abhina Sree via cfe-commits

https://github.com/abhina-sree updated 
https://github.com/llvm/llvm-project/pull/75339

>From 1b234e926dc6396fe4053f3c3463ed36e5d58778 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Wed, 13 Dec 2023 08:35:52 -0500
Subject: [PATCH 1/2] fix strnlen build failure for z/OS

---
 clang/lib/Lex/HeaderMap.cpp  | 1 +
 llvm/include/llvm/Support/SystemZ/zOSSupport.h   | 8 
 llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp| 1 +
 llvm/lib/ObjCopy/MachO/MachOObject.cpp   | 1 +
 llvm/lib/ObjCopy/MachO/MachOReader.cpp   | 1 +
 llvm/lib/ObjectYAML/MachOEmitter.cpp | 1 +
 llvm/lib/ObjectYAML/MachOYAML.cpp| 1 +
 llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp | 1 +
 llvm/tools/llvm-readobj/ELFDumper.cpp| 1 +
 llvm/tools/llvm-readobj/ObjDumper.cpp| 1 +
 llvm/tools/obj2yaml/macho2yaml.cpp   | 1 +
 11 files changed, 18 insertions(+)

diff --git a/clang/lib/Lex/HeaderMap.cpp b/clang/lib/Lex/HeaderMap.cpp
index 22a1532c2d9383..adc56dc270e5f0 100644
--- a/clang/lib/Lex/HeaderMap.cpp
+++ b/clang/lib/Lex/HeaderMap.cpp
@@ -20,6 +20,7 @@
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/SwapByteOrder.h"
+#include "llvm/Support/SystemZ/zOSSupport.h"
 #include "llvm/Support/Debug.h"
 #include 
 #include 
diff --git a/llvm/include/llvm/Support/SystemZ/zOSSupport.h 
b/llvm/include/llvm/Support/SystemZ/zOSSupport.h
index ee78147cb21554..f9a61f887d5dd1 100644
--- a/llvm/include/llvm/Support/SystemZ/zOSSupport.h
+++ b/llvm/include/llvm/Support/SystemZ/zOSSupport.h
@@ -35,5 +35,13 @@ inline pid_t wait4(pid_t pid, int *wstatus, int options,
   return Result;
 }
 
+// z/OS Unix System Services does not have strnlen() support, so the strnlen()
+// function is implemented here.
+inline std::size_t strnlen(const char *S, std::size_t MaxLen) {
+  const char *PtrToNullChar =
+  static_cast(std::memchr(S, '\0', MaxLen));
+  return PtrToNullChar ? PtrToNullChar - S : MaxLen;
+}
+
 #endif
 #endif
diff --git a/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp 
b/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp
index 067ef39d90522f..a3d4ba3a94f7ac 100644
--- a/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp
+++ b/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp
@@ -10,6 +10,7 @@
 #include "llvm/Support/Alignment.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/SystemZ/zOSSupport.h"
 
 using namespace llvm;
 using namespace llvm::objcopy::macho;
diff --git a/llvm/lib/ObjCopy/MachO/MachOObject.cpp 
b/llvm/lib/ObjCopy/MachO/MachOObject.cpp
index 9a4abadc8710a4..d593d6788e112f 100644
--- a/llvm/lib/ObjCopy/MachO/MachOObject.cpp
+++ b/llvm/lib/ObjCopy/MachO/MachOObject.cpp
@@ -8,6 +8,7 @@
 
 #include "MachOObject.h"
 #include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/Support/SystemZ/zOSSupport.h"
 #include 
 
 using namespace llvm;
diff --git a/llvm/lib/ObjCopy/MachO/MachOReader.cpp 
b/llvm/lib/ObjCopy/MachO/MachOReader.cpp
index 25f8c020cde94d..4549977c12c3db 100644
--- a/llvm/lib/ObjCopy/MachO/MachOReader.cpp
+++ b/llvm/lib/ObjCopy/MachO/MachOReader.cpp
@@ -11,6 +11,7 @@
 #include "llvm/BinaryFormat/MachO.h"
 #include "llvm/Object/MachO.h"
 #include "llvm/Support/Errc.h"
+#include "llvm/Support/SystemZ/zOSSupport.h"
 #include 
 
 using namespace llvm;
diff --git a/llvm/lib/ObjectYAML/MachOEmitter.cpp 
b/llvm/lib/ObjectYAML/MachOEmitter.cpp
index 6bcc2cee27edb6..c08b389daea9c3 100644
--- a/llvm/lib/ObjectYAML/MachOEmitter.cpp
+++ b/llvm/lib/ObjectYAML/MachOEmitter.cpp
@@ -19,6 +19,7 @@
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/LEB128.h"
+#include "llvm/Support/SystemZ/zOSSupport.h"
 #include "llvm/Support/YAMLTraits.h"
 #include "llvm/Support/raw_ostream.h"
 
diff --git a/llvm/lib/ObjectYAML/MachOYAML.cpp 
b/llvm/lib/ObjectYAML/MachOYAML.cpp
index 86342c5501c708..82b2eaecec9be9 100644
--- a/llvm/lib/ObjectYAML/MachOYAML.cpp
+++ b/llvm/lib/ObjectYAML/MachOYAML.cpp
@@ -14,6 +14,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/BinaryFormat/MachO.h"
 #include "llvm/Support/Format.h"
+#include "llvm/Support/SystemZ/zOSSupport.h"
 #include "llvm/Support/YAMLTraits.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/Host.h"
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp 
b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
index 2d396df7337f89..7bb0218ed53386 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
@@ -25,6 +25,7 @@
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Program.h"
 #include "llvm/Support/Signals.h"
+#include "llvm/Support/SystemZ/zOSSupport.h"
 
 #ifdef __linux__
 #ifdef HAVE_LIBPFM
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp 
b/llvm/tools/llvm-readobj/ELFDumper.cpp
index 96564211622d26..3cf7c5a3b18955 100644
--- a/llvm/tools/llvm-readobj/ELFDumpe

[clang] [AArch64][SME2] Add SQRSHRN, UQRSHRN, SQRSHRUN builtins for SME2, SVE2p1 (PR #75325)

2023-12-13 Thread via cfe-commits

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


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


[clang] [Clang][SVE2.1] Make a part of the name optional for `svwhileXX` builtins with predicate-as-counter (PR #75200)

2023-12-13 Thread Momchil Velikov via cfe-commits

https://github.com/momchil-velikov updated 
https://github.com/llvm/llvm-project/pull/75200

>From bb881371fb036819a1d6489a9779e2c5ac7e7d3c Mon Sep 17 00:00:00 2001
From: Momchil Velikov 
Date: Tue, 12 Dec 2023 15:08:33 +
Subject: [PATCH 1/2] [Clang][SVE2.1] Make the part of the name optional for
 `svewhileXX` builtins with predicate-as-counter

The `_s64`/`_u64` part can be omitted now. It's inferred from
the argument types.
---
 clang/include/clang/Basic/arm_sve.td  |  18 ++-
 .../acle_sve2p1_while_pn.c| 136 +-
 2 files changed, 80 insertions(+), 74 deletions(-)

diff --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index aa9b105364a51a..004a381523afcc 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -1950,19 +1950,17 @@ let TargetGuard = "sve2p1|sme2" in {
 //FIXME: Replace IsStreamingCompatible with IsStreamingOrHasSVE2p1 when 
available
 def SVPEXT_SINGLE : SInst<"svpext_lane_{d}", "P}i", "QcQsQiQl", MergeNone, 
"aarch64_sve_pext", [IsStreamingCompatible], [ImmCheck<1, ImmCheck0_3>]>;
 def SVPEXT_X2 : SInst<"svpext_lane_{d}_x2", "2.P}i", "QcQsQiQl", 
MergeNone, "aarch64_sve_pext_x2", [IsStreamingCompatible], [ImmCheck<1, 
ImmCheck0_1>]>;
-}
 
-let TargetGuard = "sve2p1" in {
 def SVFCLAMP   : SInst<"svclamp[_{d}]", "", "hfd", MergeNone, 
"aarch64_sve_fclamp", [], []>;
 
-def SVWHILEGE_COUNT  : SInst<"svwhilege_{d}",  "}lli", "QcQsQiQl", MergeNone, 
"aarch64_sve_whilege_{d}", [IsOverloadNone], [ImmCheck<2, ImmCheck2_4_Mul2>]>;
-def SVWHILEGT_COUNT  : SInst<"svwhilegt_{d}",  "}lli", "QcQsQiQl", MergeNone, 
"aarch64_sve_whilegt_{d}", [IsOverloadNone], [ImmCheck<2, ImmCheck2_4_Mul2>]>;
-def SVWHILELE_COUNT  : SInst<"svwhilele_{d}",  "}lli", "QcQsQiQl", MergeNone, 
"aarch64_sve_whilele_{d}", [IsOverloadNone], [ImmCheck<2, ImmCheck2_4_Mul2>]>;
-def SVWHILELT_COUNT  : SInst<"svwhilelt_{d}",  "}lli", "QcQsQiQl", MergeNone, 
"aarch64_sve_whilelt_{d}", [IsOverloadNone], [ImmCheck<2, ImmCheck2_4_Mul2>]>;
-def SVWHILELO_COUNT  : SInst<"svwhilelo_{d}",  "}nni", "QcQsQiQl", MergeNone, 
"aarch64_sve_whilelo_{d}", [IsOverloadNone], [ImmCheck<2, ImmCheck2_4_Mul2>]>;
-def SVWHILELS_COUNT  : SInst<"svwhilels_{d}",  "}nni", "QcQsQiQl", MergeNone, 
"aarch64_sve_whilels_{d}", [IsOverloadNone], [ImmCheck<2, ImmCheck2_4_Mul2>]>;
-def SVWHILEHI_COUNT  : SInst<"svwhilehi_{d}",  "}nni", "QcQsQiQl", MergeNone, 
"aarch64_sve_whilehi_{d}", [IsOverloadNone], [ImmCheck<2, ImmCheck2_4_Mul2>]>;
-def SVWHILEHS_COUNT  : SInst<"svwhilehs_{d}",  "}nni", "QcQsQiQl", MergeNone, 
"aarch64_sve_whilehs_{d}", [IsOverloadNone], [ImmCheck<2, ImmCheck2_4_Mul2>]>;
+def SVWHILEGE_COUNT  : SInst<"svwhilege_{d}[_{1}]",  "}lli", "QcQsQiQl", 
MergeNone, "aarch64_sve_whilege_{d}", [IsOverloadNone], [ImmCheck<2, 
ImmCheck2_4_Mul2>]>;
+def SVWHILEGT_COUNT  : SInst<"svwhilegt_{d}[_{1}]",  "}lli", "QcQsQiQl", 
MergeNone, "aarch64_sve_whilegt_{d}", [IsOverloadNone], [ImmCheck<2, 
ImmCheck2_4_Mul2>]>;
+def SVWHILELE_COUNT  : SInst<"svwhilele_{d}[_{1}]",  "}lli", "QcQsQiQl", 
MergeNone, "aarch64_sve_whilele_{d}", [IsOverloadNone], [ImmCheck<2, 
ImmCheck2_4_Mul2>]>;
+def SVWHILELT_COUNT  : SInst<"svwhilelt_{d}[_{1}]",  "}lli", "QcQsQiQl", 
MergeNone, "aarch64_sve_whilelt_{d}", [IsOverloadNone], [ImmCheck<2, 
ImmCheck2_4_Mul2>]>;
+def SVWHILELO_COUNT  : SInst<"svwhilelo_{d}[_{1}]",  "}nni", "QcQsQiQl", 
MergeNone, "aarch64_sve_whilelo_{d}", [IsOverloadNone], [ImmCheck<2, 
ImmCheck2_4_Mul2>]>;
+def SVWHILELS_COUNT  : SInst<"svwhilels_{d}[_{1}]",  "}nni", "QcQsQiQl", 
MergeNone, "aarch64_sve_whilels_{d}", [IsOverloadNone], [ImmCheck<2, 
ImmCheck2_4_Mul2>]>;
+def SVWHILEHI_COUNT  : SInst<"svwhilehi_{d}[_{1}]",  "}nni", "QcQsQiQl", 
MergeNone, "aarch64_sve_whilehi_{d}", [IsOverloadNone], [ImmCheck<2, 
ImmCheck2_4_Mul2>]>;
+def SVWHILEHS_COUNT  : SInst<"svwhilehs_{d}[_{1}]",  "}nni", "QcQsQiQl", 
MergeNone, "aarch64_sve_whilehs_{d}", [IsOverloadNone], [ImmCheck<2, 
ImmCheck2_4_Mul2>]>;
 
 def SVLD1B_X2 : MInst<"svld1[_{2}]_x2", "2}c", "cUc", [IsStructLoad], 
MemEltTyDefault, "aarch64_sve_ld1_pn_x2">;
 def SVLD1H_X2 : MInst<"svld1[_{2}]_x2", "2}c", "sUshb", [IsStructLoad], 
MemEltTyDefault, "aarch64_sve_ld1_pn_x2">;
diff --git 
a/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_while_pn.c 
b/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_while_pn.c
index 3dbb38582b676c..08c1ee949c1116 100644
--- a/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_while_pn.c
+++ b/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_while_pn.c
@@ -1,12 +1,20 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
 // RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S 
-O1 -Werror -Wall -emit-llvm -o - %s | FileCheck %s
 // RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve2p1 -S 
-O1 -Werror -Wall -emit-llvm -o - -x c++ %s | FileCheck %s 
-check-prefix=CPP

[clang] [Clang][SVE2.1] Make a part of the name optional for `svwhileXX` builtins with predicate-as-counter (PR #75200)

2023-12-13 Thread Momchil Velikov via cfe-commits


@@ -1950,19 +1950,17 @@ let TargetGuard = "sve2p1|sme2" in {
 //FIXME: Replace IsStreamingCompatible with IsStreamingOrHasSVE2p1 when 
available
 def SVPEXT_SINGLE : SInst<"svpext_lane_{d}", "P}i", "QcQsQiQl", MergeNone, 
"aarch64_sve_pext", [IsStreamingCompatible], [ImmCheck<1, ImmCheck0_3>]>;
 def SVPEXT_X2 : SInst<"svpext_lane_{d}_x2", "2.P}i", "QcQsQiQl", 
MergeNone, "aarch64_sve_pext_x2", [IsStreamingCompatible], [ImmCheck<1, 
ImmCheck0_1>]>;
-}
 
-let TargetGuard = "sve2p1" in {
 def SVFCLAMP   : SInst<"svclamp[_{d}]", "", "hfd", MergeNone, 
"aarch64_sve_fclamp", [], []>;
 
-def SVWHILEGE_COUNT  : SInst<"svwhilege_{d}",  "}lli", "QcQsQiQl", MergeNone, 
"aarch64_sve_whilege_{d}", [IsOverloadNone], [ImmCheck<2, ImmCheck2_4_Mul2>]>;
-def SVWHILEGT_COUNT  : SInst<"svwhilegt_{d}",  "}lli", "QcQsQiQl", MergeNone, 
"aarch64_sve_whilegt_{d}", [IsOverloadNone], [ImmCheck<2, ImmCheck2_4_Mul2>]>;
-def SVWHILELE_COUNT  : SInst<"svwhilele_{d}",  "}lli", "QcQsQiQl", MergeNone, 
"aarch64_sve_whilele_{d}", [IsOverloadNone], [ImmCheck<2, ImmCheck2_4_Mul2>]>;
-def SVWHILELT_COUNT  : SInst<"svwhilelt_{d}",  "}lli", "QcQsQiQl", MergeNone, 
"aarch64_sve_whilelt_{d}", [IsOverloadNone], [ImmCheck<2, ImmCheck2_4_Mul2>]>;
-def SVWHILELO_COUNT  : SInst<"svwhilelo_{d}",  "}nni", "QcQsQiQl", MergeNone, 
"aarch64_sve_whilelo_{d}", [IsOverloadNone], [ImmCheck<2, ImmCheck2_4_Mul2>]>;
-def SVWHILELS_COUNT  : SInst<"svwhilels_{d}",  "}nni", "QcQsQiQl", MergeNone, 
"aarch64_sve_whilels_{d}", [IsOverloadNone], [ImmCheck<2, ImmCheck2_4_Mul2>]>;
-def SVWHILEHI_COUNT  : SInst<"svwhilehi_{d}",  "}nni", "QcQsQiQl", MergeNone, 
"aarch64_sve_whilehi_{d}", [IsOverloadNone], [ImmCheck<2, ImmCheck2_4_Mul2>]>;
-def SVWHILEHS_COUNT  : SInst<"svwhilehs_{d}",  "}nni", "QcQsQiQl", MergeNone, 
"aarch64_sve_whilehs_{d}", [IsOverloadNone], [ImmCheck<2, ImmCheck2_4_Mul2>]>;
+def SVWHILEGE_COUNT  : SInst<"svwhilege_{d}[_{1}]",  "}lli", "QcQsQiQl", 
MergeNone, "aarch64_sve_whilege_{d}", [IsOverloadNone], [ImmCheck<2, 
ImmCheck2_4_Mul2>]>;
+def SVWHILEGT_COUNT  : SInst<"svwhilegt_{d}[_{1}]",  "}lli", "QcQsQiQl", 
MergeNone, "aarch64_sve_whilegt_{d}", [IsOverloadNone], [ImmCheck<2, 
ImmCheck2_4_Mul2>]>;
+def SVWHILELE_COUNT  : SInst<"svwhilele_{d}[_{1}]",  "}lli", "QcQsQiQl", 
MergeNone, "aarch64_sve_whilele_{d}", [IsOverloadNone], [ImmCheck<2, 
ImmCheck2_4_Mul2>]>;
+def SVWHILELT_COUNT  : SInst<"svwhilelt_{d}[_{1}]",  "}lli", "QcQsQiQl", 
MergeNone, "aarch64_sve_whilelt_{d}", [IsOverloadNone], [ImmCheck<2, 
ImmCheck2_4_Mul2>]>;
+def SVWHILELO_COUNT  : SInst<"svwhilelo_{d}[_{1}]",  "}nni", "QcQsQiQl", 
MergeNone, "aarch64_sve_whilelo_{d}", [IsOverloadNone], [ImmCheck<2, 
ImmCheck2_4_Mul2>]>;
+def SVWHILELS_COUNT  : SInst<"svwhilels_{d}[_{1}]",  "}nni", "QcQsQiQl", 
MergeNone, "aarch64_sve_whilels_{d}", [IsOverloadNone], [ImmCheck<2, 
ImmCheck2_4_Mul2>]>;
+def SVWHILEHI_COUNT  : SInst<"svwhilehi_{d}[_{1}]",  "}nni", "QcQsQiQl", 
MergeNone, "aarch64_sve_whilehi_{d}", [IsOverloadNone], [ImmCheck<2, 
ImmCheck2_4_Mul2>]>;
+def SVWHILEHS_COUNT  : SInst<"svwhilehs_{d}[_{1}]",  "}nni", "QcQsQiQl", 
MergeNone, "aarch64_sve_whilehs_{d}", [IsOverloadNone], [ImmCheck<2, 
ImmCheck2_4_Mul2>]>;
 

momchil-velikov wrote:

Done.

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


[clang] [clang][ASTImporter] Improve import of friend class templates. (PR #74627)

2023-12-13 Thread Balázs Kéri via cfe-commits

https://github.com/balazske updated 
https://github.com/llvm/llvm-project/pull/74627

From cbcb81ebdbc49e3bd11b6f716ac14658a729b787 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= 
Date: Tue, 5 Dec 2023 15:23:37 +0100
Subject: [PATCH 1/3] [clang][ASTImporter] Improve import of friend class
 templates.

A friend template that is in a dependent context is not linked into
declaration chains (for example with the definition of the befriended
template). This condition was not correctly handled by ASTImporter.
---
 clang/lib/AST/ASTImporter.cpp   |  26 +++-
 clang/unittests/AST/ASTImporterTest.cpp | 162 
 2 files changed, 182 insertions(+), 6 deletions(-)

diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index f1f335118f37a4..a243bf65cca274 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -5919,15 +5919,26 @@ ExpectedDecl 
ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
   if (ToD)
 return ToD;
 
-  bool IsFriendTemplate = D->getFriendObjectKind() != Decl::FOK_None;
-  bool IsDependentContext = DC != LexicalDC ? LexicalDC->isDependentContext()
+  // Should check if a declaration is friend in a dependent context.
+  // Such templates are not linked together in a declaration chain.
+  // The ASTImporter strategy is to map existing forward declarations to
+  // imported ones only if strictly necessary, otherwise import these as new
+  // forward declarations. In case of the "dependent friend" declarations, new
+  // declarations are created, but not linked in a declaration chain.
+  auto IsDependentFriend = [](ClassTemplateDecl *TD) {
+bool IsFriendTemplate = TD->getFriendObjectKind() != Decl::FOK_None;
+DeclContext *DC = TD->getDeclContext();
+DeclContext *LexicalDC = TD->getLexicalDeclContext();
+bool IsDependentContext = DC != LexicalDC ? LexicalDC->isDependentContext()
 : DC->isDependentContext();
-  bool DependentFriend = IsFriendTemplate && IsDependentContext;
+return IsFriendTemplate && IsDependentContext;
+  };
+  bool DependentFriend = IsDependentFriend(D);
 
   ClassTemplateDecl *FoundByLookup = nullptr;
 
   // We may already have a template of the same name; try to find and match it.
-  if (!DependentFriend && !DC->isFunctionOrMethod()) {
+  if (!DC->isFunctionOrMethod()) {
 SmallVector ConflictingDecls;
 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
 for (auto *FoundDecl : FoundDecls) {
@@ -5943,10 +5954,13 @@ ExpectedDecl 
ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
 
 // FIXME: sufficient conditon for 'IgnoreTemplateParmDepth'?
 bool IgnoreTemplateParmDepth =
-FoundTemplate->getFriendObjectKind() != Decl::FOK_None &&
-!D->specializations().empty();
+(FoundTemplate->getFriendObjectKind() != Decl::FOK_None) !=
+(D->getFriendObjectKind() != Decl::FOK_None);
 if (IsStructuralMatch(D, FoundTemplate, /*Complain=*/true,
   IgnoreTemplateParmDepth)) {
+  if (DependentFriend || IsDependentFriend(FoundTemplate))
+continue;
+
   ClassTemplateDecl *TemplateWithDef =
   getTemplateDefinition(FoundTemplate);
   if (D->isThisDeclarationADefinition() && TemplateWithDef)
diff --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 4dd7510bf8ddf8..f9ee73626c948e 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -4528,6 +4528,168 @@ TEST_P(ImportFriendClasses, 
ImportOfClassDefinitionAndFwdFriendShouldBeLinked) {
   EXPECT_EQ(ImportedFwd, ImportedDef->getPreviousDecl());
 }
 
+TEST_P(ImportFriendClasses,
+   ImportFriendTemplatesInDependentContext_DefToFriend) {
+  Decl *ToTU = getToTuDecl(
+  R"(
+  template
+  struct X {
+template
+friend struct Y;
+  };
+  )",
+  Lang_CXX03);
+  auto *ToYFriend = FirstDeclMatcher().match(
+  ToTU, classTemplateDecl(hasName("Y")));
+  Decl *FromTU = getTuDecl(
+  R"(
+  template
+  struct Y {};
+  )",
+  Lang_CXX03, "input0.cc");
+  auto *FromYDef = FirstDeclMatcher().match(
+  FromTU, classTemplateDecl(hasName("Y")));
+  auto *ImportedYDef = Import(FromYDef, Lang_CXX03);
+  EXPECT_TRUE(ImportedYDef);
+  EXPECT_FALSE(ImportedYDef->getPreviousDecl());
+  EXPECT_NE(ImportedYDef, ToYFriend);
+}
+
+TEST_P(ImportFriendClasses,
+   ImportFriendTemplatesInDependentContext_DefToFriend_NE) {
+  Decl *ToTU = getToTuDecl(
+  R"(
+  template
+  struct X {
+template
+friend struct Y;
+  };
+  )",
+  Lang_CXX03);
+  auto *ToYFriend = FirstDeclMatcher().match(
+  ToTU, classTemplateDecl(hasName("Y")));
+  Decl *FromTU = getTuDecl(
+  R"(
+  template
+  struct Y {};
+  )",
+  Lang_CXX03, "input

[clang] [clang-format] Fix parsing of `operator<() {}` (PR #75144)

2023-12-13 Thread via cfe-commits

XDeme wrote:

Thanks for reviewing. If the patch is ok, could you land this patch for me? I 
don't have commit access.

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


[clang] [llvm] [SystemZ][z/OS] Add missing strnlen function for z/OS to fix build failures (PR #75339)

2023-12-13 Thread Abhina Sree via cfe-commits

https://github.com/abhina-sree updated 
https://github.com/llvm/llvm-project/pull/75339

>From 71695feb1770ff939c6571de98c965d87e03ad29 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan 
Date: Wed, 13 Dec 2023 08:35:52 -0500
Subject: [PATCH 1/2] fix strnlen build failure for z/OS

---
 clang/lib/Lex/HeaderMap.cpp  | 1 +
 llvm/include/llvm/Support/SystemZ/zOSSupport.h   | 8 
 llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp| 1 +
 llvm/lib/ObjCopy/MachO/MachOObject.cpp   | 1 +
 llvm/lib/ObjCopy/MachO/MachOReader.cpp   | 1 +
 llvm/lib/ObjectYAML/MachOEmitter.cpp | 1 +
 llvm/lib/ObjectYAML/MachOYAML.cpp| 1 +
 llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp | 1 +
 llvm/tools/llvm-readobj/ELFDumper.cpp| 1 +
 llvm/tools/llvm-readobj/ObjDumper.cpp| 1 +
 llvm/tools/obj2yaml/macho2yaml.cpp   | 1 +
 11 files changed, 18 insertions(+)

diff --git a/clang/lib/Lex/HeaderMap.cpp b/clang/lib/Lex/HeaderMap.cpp
index 22a1532c2d9383..adc56dc270e5f0 100644
--- a/clang/lib/Lex/HeaderMap.cpp
+++ b/clang/lib/Lex/HeaderMap.cpp
@@ -20,6 +20,7 @@
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/SwapByteOrder.h"
+#include "llvm/Support/SystemZ/zOSSupport.h"
 #include "llvm/Support/Debug.h"
 #include 
 #include 
diff --git a/llvm/include/llvm/Support/SystemZ/zOSSupport.h 
b/llvm/include/llvm/Support/SystemZ/zOSSupport.h
index ee78147cb21554..f9a61f887d5dd1 100644
--- a/llvm/include/llvm/Support/SystemZ/zOSSupport.h
+++ b/llvm/include/llvm/Support/SystemZ/zOSSupport.h
@@ -35,5 +35,13 @@ inline pid_t wait4(pid_t pid, int *wstatus, int options,
   return Result;
 }
 
+// z/OS Unix System Services does not have strnlen() support, so the strnlen()
+// function is implemented here.
+inline std::size_t strnlen(const char *S, std::size_t MaxLen) {
+  const char *PtrToNullChar =
+  static_cast(std::memchr(S, '\0', MaxLen));
+  return PtrToNullChar ? PtrToNullChar - S : MaxLen;
+}
+
 #endif
 #endif
diff --git a/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp 
b/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp
index 067ef39d90522f..a3d4ba3a94f7ac 100644
--- a/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp
+++ b/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp
@@ -10,6 +10,7 @@
 #include "llvm/Support/Alignment.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/SystemZ/zOSSupport.h"
 
 using namespace llvm;
 using namespace llvm::objcopy::macho;
diff --git a/llvm/lib/ObjCopy/MachO/MachOObject.cpp 
b/llvm/lib/ObjCopy/MachO/MachOObject.cpp
index 9a4abadc8710a4..d593d6788e112f 100644
--- a/llvm/lib/ObjCopy/MachO/MachOObject.cpp
+++ b/llvm/lib/ObjCopy/MachO/MachOObject.cpp
@@ -8,6 +8,7 @@
 
 #include "MachOObject.h"
 #include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/Support/SystemZ/zOSSupport.h"
 #include 
 
 using namespace llvm;
diff --git a/llvm/lib/ObjCopy/MachO/MachOReader.cpp 
b/llvm/lib/ObjCopy/MachO/MachOReader.cpp
index 25f8c020cde94d..4549977c12c3db 100644
--- a/llvm/lib/ObjCopy/MachO/MachOReader.cpp
+++ b/llvm/lib/ObjCopy/MachO/MachOReader.cpp
@@ -11,6 +11,7 @@
 #include "llvm/BinaryFormat/MachO.h"
 #include "llvm/Object/MachO.h"
 #include "llvm/Support/Errc.h"
+#include "llvm/Support/SystemZ/zOSSupport.h"
 #include 
 
 using namespace llvm;
diff --git a/llvm/lib/ObjectYAML/MachOEmitter.cpp 
b/llvm/lib/ObjectYAML/MachOEmitter.cpp
index 6bcc2cee27edb6..c08b389daea9c3 100644
--- a/llvm/lib/ObjectYAML/MachOEmitter.cpp
+++ b/llvm/lib/ObjectYAML/MachOEmitter.cpp
@@ -19,6 +19,7 @@
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/LEB128.h"
+#include "llvm/Support/SystemZ/zOSSupport.h"
 #include "llvm/Support/YAMLTraits.h"
 #include "llvm/Support/raw_ostream.h"
 
diff --git a/llvm/lib/ObjectYAML/MachOYAML.cpp 
b/llvm/lib/ObjectYAML/MachOYAML.cpp
index 86342c5501c708..82b2eaecec9be9 100644
--- a/llvm/lib/ObjectYAML/MachOYAML.cpp
+++ b/llvm/lib/ObjectYAML/MachOYAML.cpp
@@ -14,6 +14,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/BinaryFormat/MachO.h"
 #include "llvm/Support/Format.h"
+#include "llvm/Support/SystemZ/zOSSupport.h"
 #include "llvm/Support/YAMLTraits.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/Host.h"
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp 
b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
index 2d396df7337f89..7bb0218ed53386 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
@@ -25,6 +25,7 @@
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Program.h"
 #include "llvm/Support/Signals.h"
+#include "llvm/Support/SystemZ/zOSSupport.h"
 
 #ifdef __linux__
 #ifdef HAVE_LIBPFM
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp 
b/llvm/tools/llvm-readobj/ELFDumper.cpp
index 96564211622d26..3cf7c5a3b18955 100644
--- a/llvm/tools/llvm-readobj/ELFDumpe

  1   2   3   4   >