[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-28 Thread Fangrui Song via cfe-commits
https://github.com/MaskRay updated 
https://github.com/llvm/llvm-project/pull/91280

>From a0cfafb82db825512b0ca44778fa9d4bb435563d Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Mon, 6 May 2024 15:37:50 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5-bogner
---
 clang/include/clang/Basic/CodeGenOptions.def  |   1 +
 .../clang/Basic/DiagnosticDriverKinds.td  |   3 +
 clang/include/clang/Driver/Options.td |   3 +
 clang/lib/CodeGen/BackendUtil.cpp |   1 +
 clang/lib/Driver/ToolChains/Clang.cpp |  18 ++
 clang/lib/Driver/ToolChains/CommonArgs.cpp|  21 ++
 clang/test/Driver/crel.c  |  24 +++
 clang/test/Misc/cc1as-crel.s  |   6 +
 clang/tools/driver/cc1as_main.cpp |   6 +
 .../include/llvm/BinaryFormat/DynamicTags.def |   2 +
 llvm/include/llvm/BinaryFormat/ELF.h  |   1 +
 llvm/include/llvm/MC/MCTargetOptions.h|   3 +
 .../llvm/MC/MCTargetOptionsCommandFlags.h |   1 +
 llvm/include/llvm/Object/ELF.h|   5 +
 llvm/include/llvm/Object/ELFObjectFile.h  |  70 ++-
 llvm/include/llvm/Object/ELFTypes.h   |  25 +++
 llvm/lib/MC/ELFObjectWriter.cpp   | 110 ---
 llvm/lib/MC/MCTargetOptionsCommandFlags.cpp   |   6 +
 llvm/lib/Object/ELF.cpp   |  63 ++
 llvm/lib/ObjectYAML/ELFEmitter.cpp|  60 +-
 llvm/lib/ObjectYAML/ELFYAML.cpp   |   2 +
 llvm/test/MC/ELF/crel-32.s|  16 ++
 llvm/test/MC/ELF/crel.s   | 100 ++
 llvm/test/tools/llvm-readobj/ELF/crel.test| 180 ++
 .../tools/llvm-readobj/ELF/dynamic-reloc.test |  31 ++-
 .../llvm-readobj/ELF/relocation-errors.test   |  19 +-
 .../yaml2obj/ELF/dynamic-relocations.yaml |   5 +-
 .../yaml2obj/ELF/reloc-sec-entry-size.yaml|   5 +
 .../tools/yaml2obj/ELF/relocation-crel.yaml   |  63 ++
 .../ELF/relocation-missing-symbol.yaml|   3 +-
 .../tools/yaml2obj/ELF/relocation-type.yaml   |   4 +-
 llvm/tools/llvm-readobj/ELFDumper.cpp |  81 +++-
 32 files changed, 883 insertions(+), 55 deletions(-)
 create mode 100644 clang/test/Driver/crel.c
 create mode 100644 clang/test/Misc/cc1as-crel.s
 create mode 100644 llvm/test/MC/ELF/crel-32.s
 create mode 100644 llvm/test/MC/ELF/crel.s
 create mode 100644 llvm/test/tools/llvm-readobj/ELF/crel.test
 create mode 100644 llvm/test/tools/yaml2obj/ELF/relocation-crel.yaml

diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 340b08dd7e2a3..3229f77eef1fc 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -36,6 +36,7 @@ VALUE_CODEGENOPT(Name, Bits, Default)
 #endif
 
 CODEGENOPT(DisableIntegratedAS, 1, 0) ///< -no-integrated-as
+CODEGENOPT(Crel, 1, 0) ///< -Wa,--crel
 CODEGENOPT(RelaxELFRelocations, 1, 1) ///< -Wa,-mrelax-relocations={yes,no}
 CODEGENOPT(AsmVerbose, 1, 0) ///< -dA, -fverbose-asm.
 CODEGENOPT(PreserveAsmComments, 1, 1) ///< -dA, -fno-preserve-as-comments.
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 9781fcaa4ff5e..e9cea8967c133 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -809,6 +809,9 @@ def warn_drv_missing_multilib : Warning<
 def note_drv_available_multilibs : Note<
   "available multilibs are:%0">;
 
+def err_drv_experimental_crel : Error<
+  "-Wa,--experimental-crel must be specified to use -Wa,--crel. CREL is 
experimental and takes a non-standard section type code">;
+
 def warn_android_unversioned_fallback : Warning<
   "Using unversioned Android target directory %0 for target %1. Unversioned"
   " directories will not be used in Clang 19. Provide a versioned directory"
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c9f7c4e5f718b..55f0c9aff6a49 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6958,6 +6958,9 @@ def massembler_no_warn : Flag<["-"], 
"massembler-no-warn">,
 def massembler_fatal_warnings : Flag<["-"], "massembler-fatal-warnings">,
   HelpText<"Make assembler warnings fatal">,
   MarshallingInfoFlag>;
+def crel : Flag<["--"], "crel">,
+  HelpText<"Enable CREL relocation format (ELF only)">,
+  MarshallingInfoFlag>;
 def mrelax_relocations_no : Flag<["-"], "mrelax-relocations=no">,
 HelpText<"Disable x86 relax relocations">,
 MarshallingInfoNegativeFlag>;
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 22c3f8642ad8e..ed37085d69ac5 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil

[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-28 Thread Fangrui Song via cfe-commits
https://github.com/MaskRay edited 
https://github.com/llvm/llvm-project/pull/91280
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-28 Thread Fangrui Song via cfe-commits
https://github.com/MaskRay commented:

Thanks for the comments. Addressed

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


[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-28 Thread Fangrui Song via cfe-commits

@@ -392,6 +393,70 @@ ELFFile::decode_relrs(Elf_Relr_Range relrs) const {
   return Relocs;
 }
 
+template 
+uint64_t ELFFile::crelHeader(ArrayRef Content) const {
+  DataExtractor Data(Content, true, 8); // endian/class is irrelevant
+  DataExtractor::Cursor Cur(0);
+  uint64_t Hdr = Data.getULEB128(Cur);
+  // In case of an error, return 0 and postpone error reporting to decodeCrel.
+  consumeError(Cur.takeError());
+  return Hdr;
+}
+
+template 
+Expected::RelsOrRelas>
+ELFFile::decodeCrel(ArrayRef Content) const {
+  DataExtractor Data(Content, true, 8); // endian/class is irrelevant
+  DataExtractor::Cursor Cur(0);
+  const uint64_t Hdr = Data.getULEB128(Cur);
+  const size_t Count = Hdr / 8, FlagBits = Hdr & ELF::CREL_HDR_ADDEND ? 3 : 2,
+   Shift = Hdr % ELF::CREL_HDR_ADDEND;

MaskRay wrote:

done

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


[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-28 Thread Fangrui Song via cfe-commits

@@ -321,6 +321,11 @@ class ELFFile {
 
   std::vector decode_relrs(Elf_Relr_Range relrs) const;
 
+  uint64_t crelHeader(ArrayRef Content) const;

MaskRay wrote:

renamed to `getCrelHeader`

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


[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-28 Thread Fangrui Song via cfe-commits

@@ -392,6 +393,70 @@ ELFFile::decode_relrs(Elf_Relr_Range relrs) const {
   return Relocs;
 }
 
+template 
+uint64_t ELFFile::crelHeader(ArrayRef Content) const {
+  DataExtractor Data(Content, true, 8); // endian/class is irrelevant

MaskRay wrote:

done

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


[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-28 Thread Fangrui Song via cfe-commits

@@ -474,9 +480,28 @@ struct Elf_Rel_Impl, true>
 : public Elf_Rel_Impl, false> {
   LLVM_ELF_IMPORT_TYPES(Endianness, true)
   static const bool IsRela = true;
+  static const bool IsCrel = false;
   Elf_Sxword r_addend; // Compute value for relocatable field by adding this.
 };
 
+template  struct Elf_Crel_Impl {
+  using uint = std::conditional_t;
+  static const bool IsRela = true;
+  static const bool IsCrel = true;
+  uint r_offset;
+  uint32_t r_symidx;
+  uint32_t r_type;
+  std::conditional_t r_addend;

MaskRay wrote:

Ditto, here I want to avoid unneeded endianness difference. `Elf_Addend` is a 
`packed` type, which we want to avoid here.

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


[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-28 Thread Fangrui Song via cfe-commits

@@ -86,6 +86,8 @@ DYNAMIC_TAG(RELRSZ, 35)  // Size of Relr relocation table.
 DYNAMIC_TAG(RELR, 36)// Address of relocation table (Relr entries).
 DYNAMIC_TAG(RELRENT, 37) // Size of a Relr relocation entry.
 
+DYNAMIC_TAG(CREL,  38)   // CREL relocation table
+

MaskRay wrote:

> it might use up the slot you've "allocated"

I understand the concern but this is just impossible given the essential state 
of the generic ABI...

(I have some notes at 
https://maskray.me/blog/2024-05-26-evolution-of-elf-object-file-format#a-future-in-flux)

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


[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-28 Thread Fangrui Song via cfe-commits

@@ -474,9 +480,28 @@ struct Elf_Rel_Impl, true>
 : public Elf_Rel_Impl, false> {
   LLVM_ELF_IMPORT_TYPES(Endianness, true)
   static const bool IsRela = true;
+  static const bool IsCrel = false;
   Elf_Sxword r_addend; // Compute value for relocatable field by adding this.
 };
 
+template  struct Elf_Crel_Impl {
+  using uint = std::conditional_t;

MaskRay wrote:

Using Is64 instead of ELFType is intentional to avoid unneeded endianness 
difference. The structure is for in-memory representation and has no endianness 
difference.

I added a comment before `struct Elf_Crel_Impl`.

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


[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-28 Thread Fangrui Song via cfe-commits

@@ -934,10 +943,51 @@ void ELFWriter::WriteSecHdrEntry(uint32_t Name, uint32_t 
Type, uint64_t Flags,
   WriteWord(EntrySize); // sh_entsize
 }
 
+template 
+static void encodeCrel(ArrayRef Relocs, raw_ostream &os) {

MaskRay wrote:

done

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


[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-28 Thread Fangrui Song via cfe-commits

@@ -934,10 +943,51 @@ void ELFWriter::WriteSecHdrEntry(uint32_t Name, uint32_t 
Type, uint64_t Flags,
   WriteWord(EntrySize); // sh_entsize
 }
 
+template 
+static void encodeCrel(ArrayRef Relocs, raw_ostream &os) {
+  uint OffsetMask = 8, Offset = 0, Addend = 0;
+  uint32_t Symidx = 0, Type = 0;
+  // hdr & 4 indicates 3 flag bits in delta offset and flags members.
+  for (size_t i = 0, e = Relocs.size(); i != e; ++i)

MaskRay wrote:

changed to a for each loop

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


[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

2024-05-28 Thread Fangrui Song via cfe-commits

@@ -259,7 +260,7 @@ class ELFObjectWriter : public MCObjectWriter {
   void recordRelocation(MCAssembler &Asm, const MCAsmLayout &Layout,
 const MCFragment *Fragment, const MCFixup &Fixup,
 MCValue Target, uint64_t &FixedValue) override;
-  bool usesRela(const MCSectionELF &Sec) const;
+  bool usesRela(const MCTargetOptions *, const MCSectionELF &Sec) const;

MaskRay wrote:

added

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


[clang] [llvm] [mlir] [OpenMP] Migrate GPU Reductions CodeGen from Clang to OMPIRBuilder (PR #80343)

2024-05-28 Thread Akash Banerjee via cfe-commits
TIFitis wrote:

Ping for review.

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


[clang] 9aa56db - Revert "[Driver] Remove unneeded *-linux-gnu after D158183"

2024-05-28 Thread JP Lehr via cfe-commits
Author: JP Lehr
Date: 2024-05-28T03:23:53-05:00
New Revision: 9aa56db6a8d5ef0e70b82387df857da5fffa310a

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

LOG: Revert "[Driver] Remove unneeded *-linux-gnu after D158183"

This broke several buildbots:
https://lab.llvm.org/buildbot/#/builders/193
https://lab.llvm.org/buildbot/#/builders/259
https://lab.llvm.org/staging/#/builders/185
https://lab.llvm.org/staging/#/builders/140

This reverts commit 435ea21c897f94b5a3777a9f152e4c5bb4a371a3.

Added: 


Modified: 
clang/lib/Driver/ToolChains/Gnu.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index c0100fed15131..9849c59685cca 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2227,19 +2227,10 @@ void Generic_GCC::GCCInstallationDetector::init(
   SmallVector CandidateBiarchTripleAliases;
   // Add some triples that we want to check first.
   CandidateTripleAliases.push_back(TargetTriple.str());
-  std::string TripleNoVendor, BiarchTripleNoVendor;
-  if (TargetTriple.getVendor() == llvm::Triple::UnknownVendor) {
-StringRef OSEnv = TargetTriple.getOSAndEnvironmentName();
-if (TargetTriple.getEnvironment() == llvm::Triple::GNUX32)
-  OSEnv = "linux-gnu";
-TripleNoVendor = (TargetTriple.getArchName().str() + '-' + OSEnv).str();
+  std::string TripleNoVendor = TargetTriple.getArchName().str() + "-" +
+   TargetTriple.getOSAndEnvironmentName().str();
+  if (TargetTriple.getVendor() == llvm::Triple::UnknownVendor)
 CandidateTripleAliases.push_back(TripleNoVendor);
-if (BiarchVariantTriple.getArch() != llvm::Triple::UnknownArch) {
-  BiarchTripleNoVendor =
-  (BiarchVariantTriple.getArchName().str() + '-' + OSEnv).str();
-  CandidateBiarchTripleAliases.push_back(BiarchTripleNoVendor);
-}
-  }
 
   CollectLibDirsAndTriples(TargetTriple, BiarchVariantTriple, CandidateLibDirs,
CandidateTripleAliases, CandidateBiarchLibDirs,
@@ -2462,9 +2453,11 @@ void 
Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
   // lists should shrink over time. Please don't add more elements to *Triples.
   static const char *const AArch64LibDirs[] = {"/lib64", "/lib"};
   static const char *const AArch64Triples[] = {
-  "aarch64-none-linux-gnu", "aarch64-redhat-linux", "aarch64-suse-linux"};
+  "aarch64-none-linux-gnu", "aarch64-linux-gnu", "aarch64-redhat-linux",
+  "aarch64-suse-linux"};
   static const char *const AArch64beLibDirs[] = {"/lib"};
-  static const char *const AArch64beTriples[] = {"aarch64_be-none-linux-gnu"};
+  static const char *const AArch64beTriples[] = {"aarch64_be-none-linux-gnu",
+ "aarch64_be-linux-gnu"};
 
   static const char *const ARMLibDirs[] = {"/lib"};
   static const char *const ARMTriples[] = {"arm-linux-gnueabi"};
@@ -2486,19 +2479,20 @@ void 
Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
 
   static const char *const X86_64LibDirs[] = {"/lib64", "/lib"};
   static const char *const X86_64Triples[] = {
-  "x86_64-unknown-linux-gnu", "x86_64-pc-linux-gnu",
-  "x86_64-redhat-linux6E","x86_64-redhat-linux",
-  "x86_64-suse-linux","x86_64-manbo-linux-gnu",
-  "x86_64-slackware-linux",   "x86_64-unknown-linux",
+  "x86_64-linux-gnu",   "x86_64-unknown-linux-gnu",
+  "x86_64-pc-linux-gnu","x86_64-redhat-linux6E",
+  "x86_64-redhat-linux","x86_64-suse-linux",
+  "x86_64-manbo-linux-gnu", "x86_64-linux-gnu",
+  "x86_64-slackware-linux", "x86_64-unknown-linux",
   "x86_64-amazon-linux"};
   static const char *const X32Triples[] = {"x86_64-linux-gnux32",
"x86_64-pc-linux-gnux32"};
   static const char *const X32LibDirs[] = {"/libx32", "/lib"};
   static const char *const X86LibDirs[] = {"/lib32", "/lib"};
   static const char *const X86Triples[] = {
-  "i686-linux-gnu","i686-pc-linux-gnu", "i386-redhat-linux6E",
-  "i686-redhat-linux", "i386-redhat-linux", "i586-suse-linux",
-  "i686-montavista-linux",
+  "i586-linux-gnu",  "i686-linux-gnu","i686-pc-linux-gnu",
+  "i386-redhat-linux6E", "i686-redhat-linux", "i386-redhat-linux",
+  "i586-suse-linux", "i686-montavista-linux",
   };
 
   static const char *const LoongArch64LibDirs[] = {"/lib64", "/lib"};
@@ -2506,24 +2500,26 @@ void 
Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
   "loongarch64-linux-gnu", "loongarch64-unknown-linux-gnu"};
 
   static const char *const M68kLibDirs[] = {"/lib"};
-  static const char *const M68kTriples[] = {"m68k-unknown-linux-gnu",
- 

[clang] [clang-tools-extra] [libcxx] [clang][Modules] Remove unnecessary includes of `Module.h` (PR #93417)

2024-05-28 Thread kadir çetinkaya via cfe-commits

@@ -42,7 +41,11 @@
 #include 
 #include 
 
-namespace clang::clangd {
+namespace clang {
+
+class Module;

kadircet wrote:

yes that's mostly something we try in clangd, but fair point, feel free to 
ignore this one.

i was mostly pushing because this is just a leaf hence having that dependency 
won't affect compile times drastically, and we'll probably keep pulling it 
through other headers anyway. (e.g. even after this change, we still have 
`clangd/SourceCode.h -> clang/Lex/HeaderSearch.h -> clang/Lex/DirectoryLookup.h 
-> clang/Lex/ModuleMap.h -> clang/Basic/Module.h, hence this isn't really 
changing much in practice, while hiding the dependency)

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


[clang] [clang-repl] Set up executor implicitly to account for init PTUs (PR #84758)

2024-05-28 Thread Stefan Gränitz via cfe-commits
weliveindetail wrote:

@vgvassilev Thanks for the ping. I got derailed and missed the fix for the 
blocker!

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


[clang] cb7995a - [clang-repl] Set up executor implicitly to account for init PTUs (#84758)

2024-05-28 Thread via cfe-commits
Author: Stefan Gränitz
Date: 2024-05-28T11:22:49+02:00
New Revision: cb7995a1308c1bef396f9a2b2b14472cbdcca755

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

LOG: [clang-repl] Set up executor implicitly to account for init PTUs  (#84758)

Until now the IncrExecutor was created lazily on the first execution
request. In order to process the PTUs that come from initialization, we
have to do it upfront implicitly.

Added: 


Modified: 
clang/include/clang/Interpreter/Interpreter.h
clang/lib/Interpreter/Interpreter.cpp
clang/test/Interpreter/execute.cpp
clang/test/Interpreter/inline-virtual.cpp
clang/unittests/Interpreter/InterpreterExtensionsTest.cpp

Removed: 




diff  --git a/clang/include/clang/Interpreter/Interpreter.h 
b/clang/include/clang/Interpreter/Interpreter.h
index 970e0245417b5..1234608bb5864 100644
--- a/clang/include/clang/Interpreter/Interpreter.h
+++ b/clang/include/clang/Interpreter/Interpreter.h
@@ -110,9 +110,9 @@ class Interpreter {
   RuntimeInterfaceBuilder::TransformExprFunction *AddPrintValueCall = nullptr;
 
 protected:
-  // Derived classes can make use an extended interface of the Interpreter.
-  // That's useful for testing and out-of-tree clients.
-  Interpreter(std::unique_ptr CI, llvm::Error &Err);
+  // Derived classes can use an extended interface of the Interpreter.
+  Interpreter(std::unique_ptr CI, llvm::Error &Err,
+  std::unique_ptr JITBuilder = nullptr);
 
   // Create the internal IncrementalExecutor, or re-create it after calling
   // ResetExecutor().
@@ -128,13 +128,6 @@ class Interpreter {
   // custom runtime.
   virtual std::unique_ptr FindRuntimeInterface();
 
-  // Lazily construct thev ORCv2 JITBuilder. This called when the internal
-  // IncrementalExecutor is created. The default implementation populates an
-  // in-process JIT with debugging support. Override this to configure the JIT
-  // engine used for execution.
-  virtual llvm::Expected>
-  CreateJITBuilder(CompilerInstance &CI);
-
 public:
   virtual ~Interpreter();
 
@@ -189,6 +182,8 @@ class Interpreter {
   llvm::DenseMap Dtors;
 
   llvm::SmallVector ValuePrintingInfo;
+
+  std::unique_ptr JITBuilder;
 };
 } // namespace clang
 

diff  --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index b20e6efcebfd1..683f87e8c8c79 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -229,12 +229,32 @@ IncrementalCompilerBuilder::CreateCudaHost() {
 }
 
 Interpreter::Interpreter(std::unique_ptr CI,
- llvm::Error &Err) {
-  llvm::ErrorAsOutParameter EAO(&Err);
+ llvm::Error &ErrOut,
+ std::unique_ptr JITBuilder)
+: JITBuilder(std::move(JITBuilder)) {
+  llvm::ErrorAsOutParameter EAO(&ErrOut);
   auto LLVMCtx = std::make_unique();
   TSCtx = std::make_unique(std::move(LLVMCtx));
-  IncrParser = std::make_unique(*this, std::move(CI),
-   *TSCtx->getContext(), Err);
+  IncrParser = std::make_unique(
+  *this, std::move(CI), *TSCtx->getContext(), ErrOut);
+  if (ErrOut)
+return;
+
+  // Not all frontends support code-generation, e.g. ast-dump actions don't
+  if (IncrParser->getCodeGen()) {
+if (llvm::Error Err = CreateExecutor()) {
+  ErrOut = joinErrors(std::move(ErrOut), std::move(Err));
+  return;
+}
+
+// Process the PTUs that came from initialization. For example -include 
will
+// give us a header that's processed at initialization of the preprocessor.
+for (PartialTranslationUnit &PTU : IncrParser->getPTUs())
+  if (llvm::Error Err = Execute(PTU)) {
+ErrOut = joinErrors(std::move(ErrOut), std::move(Err));
+return;
+  }
+  }
 }
 
 Interpreter::~Interpreter() {
@@ -382,25 +402,29 @@ createJITTargetMachineBuilder(const std::string &TT) {
   return llvm::orc::JITTargetMachineBuilder(llvm::Triple(TT));
 }
 
-llvm::Expected>
-Interpreter::CreateJITBuilder(CompilerInstance &CI) {
-  auto JTMB = createJITTargetMachineBuilder(CI.getTargetOpts().Triple);
-  if (!JTMB)
-return JTMB.takeError();
-  return IncrementalExecutor::createDefaultJITBuilder(std::move(*JTMB));
-}
-
 llvm::Error Interpreter::CreateExecutor() {
   if (IncrExecutor)
 return llvm::make_error("Operation failed. "
"Execution engine exists",
std::error_code());
-  llvm::Expected> JB =
-  CreateJITBuilder(*getCompilerInstance());
-  if (!JB)
-return JB.takeError();
+  if (!IncrParser->getCodeGen())
+return llvm::make_error("Operation failed. "
+   "No code generator available

[clang] [clang-repl] Set up executor implicitly to account for init PTUs (PR #84758)

2024-05-28 Thread Stefan Gränitz via cfe-commits
https://github.com/weliveindetail closed 
https://github.com/llvm/llvm-project/pull/84758
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [mlir] Avoid object libraries in the VS IDE (PR #93519)

2024-05-28 Thread Michael Kruse via cfe-commits
https://github.com/Meinersbur created 
https://github.com/llvm/llvm-project/pull/93519

As discussed in #89743, when using the Visual Studio solution generators, 
object library projects are displayed as a collection of non-editable *.obj 
files. To look for the corresponding source files, one has to browse (or 
search) to the library's obj.libname project. This patch tries to avoid this as 
much as possible.

For Clang, there is already an exception for XCode. We handle MSVC_IDE the same 
way.

For MLIR, this is more complicated. There are explicit references to the 
obj.libname target that only work when there is an object library. This patch 
cleans up the reasons for why an object library is needed:

1. The obj.libname is modified in the calling CMakeLists.txt. Note that with 
use-only references, `add_library( ALIAS )` could have been used. 

2. An libMLIR.so (mlir-shlib) is also created. This works by adding linking the 
object libraries' object file into libMLIR.so (in addition to the library's own 
.so/.a). XCode is handled using the `-force_load` linker option instead. 
Windows is not even supported. This mechanism is different from LLVM's 
llvm-shlib that is created by linking static libraries with 
`-Wl,--whole-archive` (and `-Wl,-all_load` on MacOS).

3. The library might be added to an aggregate library. In-tree, the seems to be 
only libMLIR-C.so and the standalone example. It uses the object library and 
`-force_load` mechanism as above. Again, this is different from libLLVM-C.so. 

4. Build an object library whenever it was before this patch, except when 
generating a Visual Studio solution. This condition could be removed, but I am 
trying to avoid build breakages of whatever configurations others use.

This seem to not have worked with XCode because of the explicit references to 
obj.libname. I don't have access to XCode, but I tried to preserve the current 
working. IMHO there should be a common mechanism to build aggregate libraries 
for all LLVM projects instead of the 4 that we have now.

As far as I can see, this means for LLVM there are the following changes on 
whether object libraries are created:

1. An object library is created even in XCode if FORCE_OBJECT_LIBRARY is set. I 
do not know how XCode handles it, but I also know CMake will abort otherwise.

2. An object library is created even for explicitly SHARED libraries for 
building libMLIR.so. Again, mlir-shlib does not work otherwise. libMLIR.so 
itself is created using SHARED so this is marking it as EXCLUDE_FROM_LIBMLIR.

3. For the second condition, it is now sensitive to whether the mlir-shlib is 
built at all (LLVM_BUILD_LLVM_DYLIB). However, an object library is still built 
using the fourth condition unless using the MSVC solution generator. That is, 
except with MSVC_IDE, when an object library was built before, it will also be 
an object library now.

>From a08815e3b5e204c4f7eccbfbfcdb04d00ab7f895 Mon Sep 17 00:00:00 2001
From: Michael Kruse 
Date: Tue, 28 May 2024 09:50:21 +0200
Subject: [PATCH] Avoid object libraries in the VS IDE

---
 clang/cmake/modules/AddClang.cmake   |  6 ++-
 clang/lib/Support/CMakeLists.txt |  2 +-
 flang/cmake/modules/AddFlang.cmake   | 21 +++---
 mlir/cmake/modules/AddMLIR.cmake | 62 +++-
 mlir/lib/Dialect/GPU/CMakeLists.txt  |  2 +
 mlir/lib/Target/LLVM/CMakeLists.txt  |  4 ++
 mlir/tools/mlir-shlib/CMakeLists.txt |  1 +
 7 files changed, 70 insertions(+), 28 deletions(-)

diff --git a/clang/cmake/modules/AddClang.cmake 
b/clang/cmake/modules/AddClang.cmake
index a5ef639187d9d..9d09be1936847 100644
--- a/clang/cmake/modules/AddClang.cmake
+++ b/clang/cmake/modules/AddClang.cmake
@@ -96,8 +96,12 @@ macro(add_clang_library name)
 else()
   set(LIBTYPE STATIC)
 endif()
-if(NOT XCODE)
+if(NOT XCODE AND NOT MSVC_IDE)
   # The Xcode generator doesn't handle object libraries correctly.
+  # The Visual Studio CMake generator does handle object libraries
+  # correctly, but it is preferable to list the libraries with their
+  # source files (instead of the object files and the source files in
+  # a separate target in the "Object Libraries" folder)
   list(APPEND LIBTYPE OBJECT)
 endif()
 set_property(GLOBAL APPEND PROPERTY CLANG_STATIC_LIBS ${name})
diff --git a/clang/lib/Support/CMakeLists.txt b/clang/lib/Support/CMakeLists.txt
index 8ea5620052ed8..de06271e914ae 100644
--- a/clang/lib/Support/CMakeLists.txt
+++ b/clang/lib/Support/CMakeLists.txt
@@ -15,7 +15,7 @@ set(clangSupport_sources
 
 add_clang_library(clangSupport ${clangSupport_sources})
 
-if (NOT XCODE)
+if (TARGET obj.clangSupport)
   add_library(clangSupport_tablegen ALIAS obj.clangSupport)
 elseif (NOT LLVM_LINK_LLVM_DYLIB)
   add_library(clangSupport_tablegen ALIAS clangSupport)
diff --git a/flang/cmake/modules/AddFlang.cmake 
b/flang/cmake/modules/AddFlang.cmake
index 3a5119b83831f..aeb4d862cf780 100644
--- a/flang/cmake/modules/AddFlang.cma

[clang] [llvm] [AArch64] Fix feature flags dependecies (PR #90612)

2024-05-28 Thread Momchil Velikov via cfe-commits
momchil-velikov wrote:

> > This patch removes FEAT_FPMR from list of available of architecture 
> > features, instead enabling FMPR register by default.
> 
> Can you expand a little bit on the reasoning? It doesn't seem all that 
> problematic but is still eyebrow-raising.

The overall idea is that system registers ought be available everywhere without 
the need to explicitly enable them with a command line option. Since 
`FEAT_FPMR` has no function other than enabling the register and it is going to 
be enabled by default, having a command line option, predicate, feature 
definition, etc becomes pointless.

The FP8 instructions themselves are still guarded by a target feature.



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


[clang] [llvm] [AArch64][SME] Add intrinsics for multi-vector BFCLAMP (PR #88251)

2024-05-28 Thread via cfe-commits
https://github.com/Lukacma updated 
https://github.com/llvm/llvm-project/pull/88251

>From fe692284cd248e372302671e094eb9950edb5ee5 Mon Sep 17 00:00:00 2001
From: Marian Lukac 
Date: Wed, 10 Apr 2024 10:20:03 +
Subject: [PATCH 1/3] [AArch64][SME] Add intrinsics for multi-vector BFCLAMP

---
 clang/include/clang/Basic/arm_sve.td  |  5 ++
 .../aarch64-sme2-intrinsics/acle_sme2_clamp.c | 72 +--
 llvm/include/llvm/IR/IntrinsicsAArch64.td |  2 +
 .../Target/AArch64/AArch64ISelDAGToDAG.cpp|  6 ++
 .../AArch64/sve2p1-intrinsics-bfclamp.ll  | 26 ++-
 5 files changed, 106 insertions(+), 5 deletions(-)

diff --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index 6da30e08e7521..63ca495a1bc9f 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -2148,6 +2148,11 @@ let TargetGuard = "sme2" in {
   def SVSCLAMP_X4 : SInst<"svclamp[_single_{d}_x4]",  "44dd",   "csil", 
MergeNone, "aarch64_sve_sclamp_single_x4",  [IsStreaming], []>;
   def SVUCLAMP_X4 : SInst<"svclamp[_single_{d}_x4]",  "44dd",   "UcUsUiUl", 
MergeNone, "aarch64_sve_uclamp_single_x4",  [IsStreaming], []>;
   def SVFCLAMP_X4 : SInst<"svclamp[_single_{d}_x4]",  "44dd",   "hfd",  
MergeNone, "aarch64_sve_fclamp_single_x4",  [IsStreaming], []>;
+
+  let TargetGuard = "b16b16"in {
+def SVBFCLAMP_X2 : SInst<"svclamp[_single_{d}_x2]",  "22dd",   "b",  
MergeNone, "aarch64_sve_bfclamp_single_x2",  [IsStreaming], []>;
+def SVBFCLAMP_X4 : SInst<"svclamp[_single_{d}_x4]",  "44dd",   "b",  
MergeNone, "aarch64_sve_bfclamp_single_x4",  [IsStreaming], []>;
+  }
 }
 
 let TargetGuard = "sme2" in {
diff --git a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c
index 257cb59525018..1dd5aeee35fe7 100644
--- a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c
@@ -1,12 +1,12 @@
 // 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 \
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 
-target-feature +b16b16 \
 // RUN:  -S -Werror -emit-llvm -disable-O0-optnone -o - %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s
-// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme2 \
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme2 -target-feature +b16b16 \
 // RUN:  -S -Werror -emit-llvm -disable-O0-optnone -o - %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 \
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 
-target-feature +b16b16 \
 // RUN:  -S -Werror -emit-llvm -disable-O0-optnone -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 \
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme2 -target-feature +b16b16 \
 // RUN:  -S -Werror -emit-llvm -disable-O0-optnone -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 \
 // RUN:  -S -disable-O0-optnone -Werror -Wall -o /dev/null %s
@@ -745,3 +745,67 @@ svfloat32x4_t test_svclamp_single_f32_x4(svfloat32x4_t 
op1, svfloat32_t op2, svf
 svfloat64x4_t test_svclamp_single_f64_x4(svfloat64x4_t op1, svfloat64_t op2, 
svfloat64_t op3) __arm_streaming {
   return SVE_ACLE_FUNC(svclamp, _single_f64_x4, , )(op1, op2, op3);
 }
+
+// CHECK-LABEL: @test_svclamp_single_bf16_x2(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv16bf16( [[OP1:%.*]], i64 
0)
+// CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv16bf16( [[OP1]], i64 8)
+// CHECK-NEXT:[[TMP2:%.*]] = tail call { ,  } @llvm.aarch64.sve.bfclamp.single.x2.nxv8bf16( [[TMP0]],  [[TMP1]],  
[[OP2:%.*]],  [[OP3:%.*]])
+// CHECK-NEXT:[[TMP3:%.*]] = extractvalue { ,  } [[TMP2]], 0
+// CHECK-NEXT:[[TMP4:%.*]] = tail call  
@llvm.vector.insert.nxv16bf16.nxv8bf16( poison,  [[TMP3]], i64 0)
+// CHECK-NEXT:[[TMP5:%.*]] = extractvalue { ,  } [[TMP2]], 1
+// CHECK-NEXT:[[TMP6:%.*]] = tail call  
@llvm.vector.insert.nxv16bf16.nxv8bf16( [[TMP4]],  [[TMP5]], i64 8)
+// CHECK-NEXT:ret  [[TMP6]]
+//
+// CPP-CHECK-LABEL: 
@_Z27test_svclamp_single_bf16_x214svbfloat16x2_tu14__SVBfloat16_tS0_(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv16bf16( [[OP1:%.*]], i64 
0)
+// CPP-CHECK-N

[clang] [llvm] [mlir] [Clang][CodeGen] Start migrating away from assuming the Default AS is 0 (PR #88182)

2024-05-28 Thread Matt Arsenault via cfe-commits

@@ -368,7 +368,8 @@ CodeGenModule::CodeGenModule(ASTContext &C,
   IntTy = llvm::IntegerType::get(LLVMContext, C.getTargetInfo().getIntWidth());
   IntPtrTy = llvm::IntegerType::get(LLVMContext,
 C.getTargetInfo().getMaxPointerWidth());
-  Int8PtrTy = llvm::PointerType::get(LLVMContext, 0);
+  Int8PtrTy = llvm::PointerType::get(LLVMContext,

arsenm wrote:

The IR address space is a pure target concept. Any address space error would be 
on the frontend emitting the wrong IR for the target 

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


[clang] [llvm] [AMDGPU] Extend readlane, writelane and readfirstlane intrinsic lowering for generic types (PR #89217)

2024-05-28 Thread Vikram Hegde via cfe-commits

@@ -6086,6 +6086,63 @@ static SDValue lowerBALLOTIntrinsic(const 
SITargetLowering &TLI, SDNode *N,
   DAG.getConstant(0, SL, MVT::i32), DAG.getCondCode(ISD::SETNE));
 }
 
+static SDValue lowerLaneOp(const SITargetLowering &TLI, SDNode *N,
+   SelectionDAG &DAG) {
+  EVT VT = N->getValueType(0);
+  unsigned ValSize = VT.getSizeInBits();
+  unsigned IntrinsicID = N->getConstantOperandVal(0);
+  SDValue Src0 = N->getOperand(1);
+  SDLoc SL(N);
+  MVT IntVT = MVT::getIntegerVT(ValSize);
+
+  auto createLaneOp = [&DAG, &SL](SDValue Src0, SDValue Src1, SDValue Src2,
+  MVT VT) -> SDValue {
+return (Src2 ? DAG.getNode(AMDGPUISD::WRITELANE, SL, VT, {Src0, Src1, 
Src2})
+: Src1 ? DAG.getNode(AMDGPUISD::READLANE, SL, VT, {Src0, Src1})
+   : DAG.getNode(AMDGPUISD::READFIRSTLANE, SL, VT, {Src0}));
+  };
+
+  SDValue Src1, Src2;
+  if (IntrinsicID == Intrinsic::amdgcn_readlane ||
+  IntrinsicID == Intrinsic::amdgcn_writelane) {
+Src1 = N->getOperand(2);
+if (IntrinsicID == Intrinsic::amdgcn_writelane)
+  Src2 = N->getOperand(3);
+  }
+
+  if (ValSize == 32) {
+// Already legal
+return SDValue();
+  }
+
+  if (ValSize < 32) {
+bool IsFloat = VT.isFloatingPoint();
+Src0 = DAG.getAnyExtOrTrunc(IsFloat ? DAG.getBitcast(IntVT, Src0) : Src0,
+SL, MVT::i32);
+if (Src2.getNode()) {
+  Src2 = DAG.getAnyExtOrTrunc(IsFloat ? DAG.getBitcast(IntVT, Src2) : Src2,
+  SL, MVT::i32);
+}
+SDValue LaneOp = createLaneOp(Src0, Src1, Src2, MVT::i32);
+SDValue Trunc = DAG.getAnyExtOrTrunc(LaneOp, SL, IntVT);
+return IsFloat ? DAG.getBitcast(VT, Trunc) : Trunc;
+  }
+
+  if ((ValSize % 32) == 0) {
+MVT VecVT = MVT::getVectorVT(MVT::i32, ValSize / 32);
+Src0 = DAG.getBitcast(VecVT, Src0);
+
+if (Src2.getNode())
+  Src2 = DAG.getBitcast(VecVT, Src2);
+
+SDValue LaneOp = createLaneOp(Src0, Src1, Src2, VecVT);
+SDValue UnrolledLaneOp = DAG.UnrollVectorOp(LaneOp.getNode());
+return DAG.getBitcast(VT, UnrolledLaneOp);

vikramRH wrote:

```suggestion
  MVT LaneOpT =
VT.isVector() && VT.getVectorElementType().getSizeInBits() == 16
? MVT::v2i16
: MVT::i32;
SDValue Src0SubReg, Src2SubReg;
SmallVector LaneOps;
LaneOps.push_back(DAG.getTargetConstant(
TLI.getRegClassFor(VT.getSimpleVT(), N->isDivergent())->getID(), SL,
MVT::i32));
for (unsigned i = 0; i < (ValSize / 32); i++) {
  unsigned SubRegIdx = SIRegisterInfo::getSubRegFromChannel(i);
  Src0SubReg = DAG.getTargetExtractSubreg(SubRegIdx, SL, LaneOpT, Src0);
  if (Src2)
Src2SubReg = DAG.getTargetExtractSubreg(SubRegIdx, SL, LaneOpT, Src2);
  LaneOps.push_back(createLaneOp(Src0SubReg, Src1, Src2SubReg, LaneOpT));
  LaneOps.push_back(DAG.getTargetConstant(SubRegIdx, SL, MVT::i32));
}
return SDValue(
DAG.getMachineNode(TargetOpcode::REG_SEQUENCE, SL, VT, LaneOps), 0);
```

@arsenm , @jayfoad , an alternate idea here that is much closer in logic to the 
GIsel implementation and doesn't rely on bitcasts. how does this look ? 

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


[clang] cbed9a6 - [clang][Interp] Fix ignoring assumptions

2024-05-28 Thread Timm Bäder via cfe-commits
Author: Timm Bäder
Date: 2024-05-28T12:14:45+02:00
New Revision: cbed9a64491d82d6c4a3a7d0cd97cdee32ff2301

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

LOG: [clang][Interp] Fix ignoring assumptions

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeStmtGen.cpp
clang/test/SemaCXX/cxx23-assume-disabled.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp 
b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
index ff92bc117f9ef..6ee7898f228de 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -687,26 +687,29 @@ bool ByteCodeStmtGen::visitDefaultStmt(const 
DefaultStmt *S) {
 template 
 bool ByteCodeStmtGen::visitAttributedStmt(const AttributedStmt *S) {
 
-  for (const Attr *A : S->getAttrs()) {
-auto *AA = dyn_cast(A);
-if (!AA)
-  continue;
+  if (this->Ctx.getLangOpts().CXXAssumptions &&
+  !this->Ctx.getLangOpts().MSVCCompat) {
+for (const Attr *A : S->getAttrs()) {
+  auto *AA = dyn_cast(A);
+  if (!AA)
+continue;
 
-assert(isa(S->getSubStmt()));
+  assert(isa(S->getSubStmt()));
 
-const Expr *Assumption = AA->getAssumption();
-if (Assumption->isValueDependent())
-  return false;
+  const Expr *Assumption = AA->getAssumption();
+  if (Assumption->isValueDependent())
+return false;
 
-if (Assumption->HasSideEffects(this->Ctx.getASTContext()))
-  continue;
+  if (Assumption->HasSideEffects(this->Ctx.getASTContext()))
+continue;
 
-// Evaluate assumption.
-if (!this->visitBool(Assumption))
-  return false;
+  // Evaluate assumption.
+  if (!this->visitBool(Assumption))
+return false;
 
-if (!this->emitAssume(Assumption))
-  return false;
+  if (!this->emitAssume(Assumption))
+return false;
+}
   }
 
   // Ignore other attributes.

diff  --git a/clang/test/SemaCXX/cxx23-assume-disabled.cpp 
b/clang/test/SemaCXX/cxx23-assume-disabled.cpp
index 4233a2f7f4338..674e16f5ae9b3 100644
--- a/clang/test/SemaCXX/cxx23-assume-disabled.cpp
+++ b/clang/test/SemaCXX/cxx23-assume-disabled.cpp
@@ -1,5 +1,8 @@
 // RUN: %clang_cc1 -std=c++23 -x c++ %s -fno-assumptions -verify
 // RUN: %clang_cc1 -std=c++23 -x c++ %s -fms-compatibility -verify
+// RUN: %clang_cc1 -std=c++23 -x c++ %s -fno-assumptions 
-fexperimental-new-constant-interpreter -verify
+// RUN: %clang_cc1 -std=c++23 -x c++ %s -fms-compatibility 
-fexperimental-new-constant-interpreter -verify
+
 // expected-no-diagnostics
 
 // We don't check assumptions at compile time if '-fno-assumptions' is passed,



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


[clang] [llvm] [clang][ci] Move libc++ testing into the main PR pipeline (PR #93318)

2024-05-28 Thread Louis Dionne via cfe-commits

@@ -1,82 +0,0 @@
-#===--===##

ldionne wrote:

I did check and it can be removed. I wrote that script so hopefully I’m not 
mistaken!

I will also go and clean up (remove the clang-ci pipeline on Buildkite, since 
it’s not used anymore). I will wait a week begore doing so to avoid breaking 
any ongoing PR that might trigger it.

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


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

2024-05-28 Thread Timm Baeder via cfe-commits
https://github.com/tbaederr closed 
https://github.com/llvm/llvm-project/pull/72865
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 1227171 - [AArch64][SME] Add intrinsics for multi-vector BFCLAMP (#88251)

2024-05-28 Thread via cfe-commits
Author: Lukacma
Date: 2024-05-28T11:34:03+01:00
New Revision: 12271710da72a11d3958a2824fe269363c34

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

LOG: [AArch64][SME] Add intrinsics for multi-vector BFCLAMP (#88251)

According to the specification in
https://github.com/ARM-software/acle/pull/309 this adds the intrinsics

```
  svbfloat16x2_t svclamp[_single_bf16_x2](svbfloat16x2_t zd, svbfloat16_t zn,
svbfloat16_t zm)  __arm_streaming;

  svbfloat16x4_t svclamp[_single_bf16_x4](svbfloat16x4_t zd, svbfloat16_t zn,
svbfloat16_t zm)  __arm_streaming;
```
These are available only  if __ARM_FEATURE_SME_B16B16 is enabled.

Added: 
clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_b16b16.cpp

Modified: 
clang/include/clang/Basic/arm_sve.td
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c
llvm/include/llvm/IR/IntrinsicsAArch64.td
llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
llvm/test/CodeGen/AArch64/sve2p1-intrinsics-bfclamp.ll

Removed: 




diff  --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index 03570f94de666..078ef576342a7 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -2151,6 +2151,11 @@ let TargetGuard = "sme2" in {
   def SVFCLAMP_X4 : SInst<"svclamp[_single_{d}_x4]",  "44dd",   "hfd",  
MergeNone, "aarch64_sve_fclamp_single_x4",  [IsStreaming], []>;
 }
 
+let TargetGuard = "sme2,b16b16"in {
+  def SVBFCLAMP_X2 : SInst<"svclamp[_single_{d}_x2]",  "22dd",   "b",  
MergeNone, "aarch64_sve_bfclamp_single_x2",  [IsStreaming], []>;
+  def SVBFCLAMP_X4 : SInst<"svclamp[_single_{d}_x4]",  "44dd",   "b",  
MergeNone, "aarch64_sve_bfclamp_single_x4",  [IsStreaming], []>;
+}
+
 let TargetGuard = "sme2" in {
 // == ADD (vectors) ==
   def SVADD_SINGLE_X2 : SInst<"svadd[_single_{d}_x2]", "22d", "cUcsUsiUilUl", 
MergeNone, "aarch64_sve_add_single_x2", [IsStreaming], []>;

diff  --git a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c
index 57ea4d2a1ac47..54b480eec97cd 100644
--- a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c
@@ -745,3 +745,67 @@ svfloat32x4_t test_svclamp_single_f32_x4(svfloat32x4_t 
op1, svfloat32_t op2, svf
 svfloat64x4_t test_svclamp_single_f64_x4(svfloat64x4_t op1, svfloat64_t op2, 
svfloat64_t op3) __arm_streaming {
   return SVE_ACLE_FUNC(svclamp, _single_f64_x4, , )(op1, op2, op3);
 }
+
+// CHECK-LABEL: @test_svclamp_single_bf16_x2(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv16bf16( [[OP1:%.*]], i64 
0)
+// CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv16bf16( [[OP1]], i64 8)
+// CHECK-NEXT:[[TMP2:%.*]] = tail call { ,  } @llvm.aarch64.sve.bfclamp.single.x2.nxv8bf16( [[TMP0]],  [[TMP1]],  
[[OP2:%.*]],  [[OP3:%.*]])
+// CHECK-NEXT:[[TMP3:%.*]] = extractvalue { ,  } [[TMP2]], 0
+// CHECK-NEXT:[[TMP4:%.*]] = tail call  
@llvm.vector.insert.nxv16bf16.nxv8bf16( poison,  [[TMP3]], i64 0)
+// CHECK-NEXT:[[TMP5:%.*]] = extractvalue { ,  } [[TMP2]], 1
+// CHECK-NEXT:[[TMP6:%.*]] = tail call  
@llvm.vector.insert.nxv16bf16.nxv8bf16( [[TMP4]],  [[TMP5]], i64 8)
+// CHECK-NEXT:ret  [[TMP6]]
+//
+// CPP-CHECK-LABEL: 
@_Z27test_svclamp_single_bf16_x214svbfloat16x2_tu14__SVBfloat16_tS0_(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv16bf16( [[OP1:%.*]], i64 
0)
+// CPP-CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv16bf16( [[OP1]], i64 8)
+// CPP-CHECK-NEXT:[[TMP2:%.*]] = tail call { , 
 } @llvm.aarch64.sve.bfclamp.single.x2.nxv8bf16( [[TMP0]],  [[TMP1]],  
[[OP2:%.*]],  [[OP3:%.*]])
+// CPP-CHECK-NEXT:[[TMP3:%.*]] = extractvalue { , 
 } [[TMP2]], 0
+// CPP-CHECK-NEXT:[[TMP4:%.*]] = tail call  
@llvm.vector.insert.nxv16bf16.nxv8bf16( poison,  [[TMP3]], i64 0)
+// CPP-CHECK-NEXT:[[TMP5:%.*]] = extractvalue { , 
 } [[TMP2]], 1
+// CPP-CHECK-NEXT:[[TMP6:%.*]] = tail call  
@llvm.vector.insert.nxv16bf16.nxv8bf16( [[TMP4]],  [[TMP5]], i64 8)
+// CPP-CHECK-NEXT:ret  [[TMP6]]
+//
+svbfloat16x2_t test_svclamp_single_bf16_x2(svbfloat16x2_t op1, svbfloat16_t 
op2, svbfloat16_t op3) __arm_streaming {
+  return SVE_ACLE_FUNC(svclamp, _single_bf16_x2, , )(op1, op2, op3);
+}
+
+// CHECK-LABEL: @test_svclamp_single_bf16_x4(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv32bf16( [[OP1:%.*]], i64 
0)
+// CHECK-NEXT:[[TMP1:%.*]] = tail call  
@l

[clang] [llvm] [AArch64][SME] Add intrinsics for multi-vector BFCLAMP (PR #88251)

2024-05-28 Thread via cfe-commits
https://github.com/Lukacma closed 
https://github.com/llvm/llvm-project/pull/88251
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 42b4be6 - [clang][NFC] Remove `utils/ci/run-buildbot` script

2024-05-28 Thread Vlad Serebrennikov via cfe-commits
Author: Vlad Serebrennikov
Date: 2024-05-28T13:45:22+03:00
New Revision: 42b4be6d7b896fcf2ef16818862a5be3e98ca791

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

LOG: [clang][NFC] Remove `utils/ci/run-buildbot` script

A follow up for #93318. Discussion happened at 
https://github.com/llvm/llvm-project/pull/93318#discussion_r1616281934

Added: 


Modified: 


Removed: 
clang/utils/ci/run-buildbot



diff  --git a/clang/utils/ci/run-buildbot b/clang/utils/ci/run-buildbot
deleted file mode 100755
index c68ddad571f3c..0
--- a/clang/utils/ci/run-buildbot
+++ /dev/null
@@ -1,160 +0,0 @@
-#!/usr/bin/env bash
-#===--===##
-#
-# 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
-#
-#===--===##
-
-set -ex
-set -o pipefail
-unset LANG
-unset LC_ALL
-unset LC_COLLATE
-
-PROGNAME="$(basename "${0}")"
-
-function usage() {
-cat <
-
-[-h|--help] Display this help and exit.
-
---llvm-rootPath to the root of the LLVM monorepo. By default, we try
-to figure it out based on the current working directory.
-
---build-dirThe directory to use for building the library. By default,
-this is '/build/'.
-EOF
-}
-
-if [[ $# == 0 ]]; then
-   usage
-   exit 0
-fi
-
-while [[ $# -gt 0 ]]; do
-case ${1} in
--h|--help)
-usage
-exit 0
-;;
---llvm-root)
-MONOREPO_ROOT="${2}"
-shift; shift
-;;
---build-dir)
-BUILD_DIR="${2}"
-shift; shift
-;;
-*)
-BUILDER="${1}"
-shift
-;;
-esac
-done
-
-MONOREPO_ROOT="${MONOREPO_ROOT:="$(git rev-parse --show-toplevel)"}"
-BUILD_DIR="${BUILD_DIR:=${MONOREPO_ROOT}/build/${BUILDER}}"
-INSTALL_DIR="${BUILD_DIR}/install"
-
-function clean() {
-rm -rf "${BUILD_DIR}"
-}
-
-# Print the version of a few tools to aid diagnostics in some cases
-cmake --version
-ninja --version
-
-case "${BUILDER}" in
-build-clang)
-mkdir install
-# We use Release here to avoid including debug information. Otherwise, the
-# clang binary is very large, which is problematic because we need to 
upload
-# the artifacts for other jobs to use. This may seem like nothing, but with
-# the number of jobs we run daily, this can result in thousands of GB of
-# network I/O.
-cmake  
\
--S llvm
\
--B ${BUILD_DIR}
\
--G Ninja   
\
--DCMAKE_CXX_COMPILER_LAUNCHER="ccache" 
\
--DCMAKE_BUILD_TYPE=Release 
\
--DCMAKE_INSTALL_PREFIX=install 
\
--DLLVM_TARGETS_TO_BUILD=Native 
\
--DLLVM_ENABLE_PROJECTS="clang;compiler-rt" 
\
-
-ninja -C ${BUILD_DIR} install-clang install-clang-resource-headers
-ccache -s
-tar -cJvf install.tar.xz install/
-buildkite-agent artifact upload --debug install.tar.xz
-;;
-generic-cxx03)
-buildkite-agent artifact download install.tar.xz .
-tar -xvf install.tar.xz
-export CC=$(pwd)/install/bin/clang
-export CXX=$(pwd)/install/bin/clang++
-chmod +x install/bin/clang install/bin/clang++
-
-clean
-cmake -S "${MONOREPO_ROOT}/runtimes" -B "${BUILD_DIR}" -GNinja \
-  -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" \
-  -DLIBCXX_CXX_ABI=libcxxabi \
-  -DCMAKE_BUILD_TYPE=RelWithDebInfo \
-  -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \
-  -DLIBCXX_TEST_PARAMS="std=c++03" \
-  -DLIBCXXABI_TEST_PARAMS="std=c++03"
-
-ninja -vC "${BUILD_DIR}" check-runtimes
-;;
-generic-cxx26)
-buildkite-agent artifact download install.tar.xz .
-tar -xvf install.tar.xz
-export CC=$(pwd)/install/bin/clang
-export CXX=$(pwd)/install/bin/clang++
-chmod +x install/bin/clang install/bin/clang++
-
-clean
-cmake -S "${MONOREPO_ROOT}/runtimes" -B "${BUILD_DIR}" -GNinja \
-  -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" \
-  -DLIBCXX_CXX_ABI=libcxxabi \
-  -DCMAKE_BUILD_TYPE=RelWithDebInfo \
-  -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" 

[clang] [C++20] [Modules] Don't mark variables from other modules as constant if its initializer is not constant (PR #93530)

2024-05-28 Thread Chuanqi Xu via cfe-commits
https://github.com/ChuanqiXu9 created 
https://github.com/llvm/llvm-project/pull/93530

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

The root cause of the problem is, we mark the variable from other modules as 
constnant in LLVM incorrectly. This patch fixes this problem and only mark the 
variable from other modules as constant if its initializer is const.

>From 778205df51376ddd38253b2ce5bab9dcab512774 Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Tue, 28 May 2024 18:44:18 +0800
Subject: [PATCH] [C++20] [Modules] Don't mark variables from other modules as
 constant if its initializer is not constant

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

The root cause of the problem is, we mark the variable from other
modules as constnant in LLVM incorrectly. This patch fixes this problem
and only mark the variable from other modules as constant if its
initializer is const.
---
 clang/lib/CodeGen/CodeGenModule.cpp |  2 +
 clang/test/Modules/pr93497.cppm | 81 +
 2 files changed, 83 insertions(+)
 create mode 100644 clang/test/Modules/pr93497.cppm

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index e4774a587707a..5596a6708e4a1 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -5492,6 +5492,8 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl 
*D,
 
   // If it is safe to mark the global 'constant', do so now.
   GV->setConstant(!NeedsGlobalCtor && !NeedsGlobalDtor &&
+  (!IsDefinitionAvailableExternally ||
+   D->hasConstantInitialization()) &&
   D->getType().isConstantStorage(getContext(), true, true));
 
   // If it is in a read-only section, mark it 'constant'.
diff --git a/clang/test/Modules/pr93497.cppm b/clang/test/Modules/pr93497.cppm
new file mode 100644
index 0..dc0d8eb462e27
--- /dev/null
+++ b/clang/test/Modules/pr93497.cppm
@@ -0,0 +1,81 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 %t/mod.cppm \
+// RUN: -emit-module-interface -o %t/mod.pcm
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 %t/use.cpp \
+// RUN: -fmodule-file=mod=%t/mod.pcm -emit-llvm \
+// RUN: -o - | FileCheck %t/use.cpp
+
+//--- mod.cppm
+export module mod;
+
+export struct Thing {
+static const Thing One;
+explicit Thing(int raw) :raw(raw) { }
+int raw;
+};
+
+const Thing Thing::One = Thing(1);
+
+export struct C {
+int value;
+};
+export const C ConstantValue = {1};
+
+export const C *ConstantPtr = &ConstantValue;
+
+C NonConstantValue = {1};
+export const C &ConstantRef = NonConstantValue;
+
+//--- use.cpp
+import mod;
+
+int consume(int);
+int consumeC(C);
+
+extern "C" __attribute__((noinline)) inline int unneeded() {
+return consume(43);
+}
+
+extern "C" __attribute__((noinline)) inline int needed() {
+return consume(43);
+}
+
+int use() {
+Thing t1 = Thing::One;
+return consume(t1.raw);
+}
+
+int use2() {
+if (ConstantValue.value)
+return consumeC(ConstantValue);
+return unneeded();
+}
+
+int use3() {
+if (ConstantPtr->value)
+return consumeC(*ConstantPtr);
+return needed();
+}
+
+int use4() {
+if (ConstantRef.value)
+return consumeC(ConstantRef);
+return needed();
+}
+
+// CHECK-NOT: @_ZNW3mod5Thing3OneE = {{.*}}constant
+// CHECK: @_ZW3mod13ConstantValue ={{.*}}available_externally{{.*}} constant 
+
+// Check that the middle end can optimize the program by the constant 
information.
+// CHECK-NOT: @unneeded(
+
+// Check that the use of ConstantPtr won't get optimized incorrectly.
+// CHECK-LABEL: @_Z4use3v(
+// CHECK: @needed(
+
+// Check that the use of ConstantRef won't get optimized incorrectly.
+// CHECK-LABEL: @_Z4use4v(
+// CHECK: @needed(

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


[clang] [llvm] [clang][ci] Move libc++ testing into the main PR pipeline (PR #93318)

2024-05-28 Thread Vlad Serebrennikov via cfe-commits

@@ -1,82 +0,0 @@
-#===--===##

Endilll wrote:

Committed as 681fc40d68936f145963207236d62886e5a34e5d

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


[clang] [C++20] [Modules] Don't mark variables from other modules as constant if its initializer is not constant (PR #93530)

2024-05-28 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-clang-modules

Author: Chuanqi Xu (ChuanqiXu9)


Changes

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

The root cause of the problem is, we mark the variable from other modules as 
constnant in LLVM incorrectly. This patch fixes this problem and only mark the 
variable from other modules as constant if its initializer is const.

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


2 Files Affected:

- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+2) 
- (added) clang/test/Modules/pr93497.cppm (+81) 


``diff
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index e4774a587707a..5596a6708e4a1 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -5492,6 +5492,8 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl 
*D,
 
   // If it is safe to mark the global 'constant', do so now.
   GV->setConstant(!NeedsGlobalCtor && !NeedsGlobalDtor &&
+  (!IsDefinitionAvailableExternally ||
+   D->hasConstantInitialization()) &&
   D->getType().isConstantStorage(getContext(), true, true));
 
   // If it is in a read-only section, mark it 'constant'.
diff --git a/clang/test/Modules/pr93497.cppm b/clang/test/Modules/pr93497.cppm
new file mode 100644
index 0..dc0d8eb462e27
--- /dev/null
+++ b/clang/test/Modules/pr93497.cppm
@@ -0,0 +1,81 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 %t/mod.cppm \
+// RUN: -emit-module-interface -o %t/mod.pcm
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 %t/use.cpp \
+// RUN: -fmodule-file=mod=%t/mod.pcm -emit-llvm \
+// RUN: -o - | FileCheck %t/use.cpp
+
+//--- mod.cppm
+export module mod;
+
+export struct Thing {
+static const Thing One;
+explicit Thing(int raw) :raw(raw) { }
+int raw;
+};
+
+const Thing Thing::One = Thing(1);
+
+export struct C {
+int value;
+};
+export const C ConstantValue = {1};
+
+export const C *ConstantPtr = &ConstantValue;
+
+C NonConstantValue = {1};
+export const C &ConstantRef = NonConstantValue;
+
+//--- use.cpp
+import mod;
+
+int consume(int);
+int consumeC(C);
+
+extern "C" __attribute__((noinline)) inline int unneeded() {
+return consume(43);
+}
+
+extern "C" __attribute__((noinline)) inline int needed() {
+return consume(43);
+}
+
+int use() {
+Thing t1 = Thing::One;
+return consume(t1.raw);
+}
+
+int use2() {
+if (ConstantValue.value)
+return consumeC(ConstantValue);
+return unneeded();
+}
+
+int use3() {
+if (ConstantPtr->value)
+return consumeC(*ConstantPtr);
+return needed();
+}
+
+int use4() {
+if (ConstantRef.value)
+return consumeC(ConstantRef);
+return needed();
+}
+
+// CHECK-NOT: @_ZNW3mod5Thing3OneE = {{.*}}constant
+// CHECK: @_ZW3mod13ConstantValue ={{.*}}available_externally{{.*}} constant 
+
+// Check that the middle end can optimize the program by the constant 
information.
+// CHECK-NOT: @unneeded(
+
+// Check that the use of ConstantPtr won't get optimized incorrectly.
+// CHECK-LABEL: @_Z4use3v(
+// CHECK: @needed(
+
+// Check that the use of ConstantRef won't get optimized incorrectly.
+// CHECK-LABEL: @_Z4use4v(
+// CHECK: @needed(

``




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


[clang] [llvm] [clang][ci] Move libc++ testing into the main PR pipeline (PR #93318)

2024-05-28 Thread Vlad Serebrennikov via cfe-commits
https://github.com/Endilll edited 
https://github.com/llvm/llvm-project/pull/93318
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [C++20] [Modules] Don't mark variables from other modules as constant if its initializer is not constant (PR #93530)

2024-05-28 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 ea20647023f7bb110e8a198485727458684c43c6 
778205df51376ddd38253b2ce5bab9dcab512774 -- clang/test/Modules/pr93497.cppm 
clang/lib/CodeGen/CodeGenModule.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 5596a6708e..256825fde0 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -5491,10 +5491,10 @@ void CodeGenModule::EmitGlobalVarDefinition(const 
VarDecl *D,
 emitter->finalize(GV);
 
   // If it is safe to mark the global 'constant', do so now.
-  GV->setConstant(!NeedsGlobalCtor && !NeedsGlobalDtor &&
-  (!IsDefinitionAvailableExternally ||
-   D->hasConstantInitialization()) &&
-  D->getType().isConstantStorage(getContext(), true, true));
+  GV->setConstant(
+  !NeedsGlobalCtor && !NeedsGlobalDtor &&
+  (!IsDefinitionAvailableExternally || D->hasConstantInitialization()) &&
+  D->getType().isConstantStorage(getContext(), true, true));
 
   // If it is in a read-only section, mark it 'constant'.
   if (const SectionAttr *SA = D->getAttr()) {

``




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


[clang] [llvm] Revert "[AArch64][SME] Add intrinsics for multi-vector BFCLAMP" (PR #93531)

2024-05-28 Thread via cfe-commits
https://github.com/Lukacma created 
https://github.com/llvm/llvm-project/pull/93531

Reverts llvm/llvm-project#88251

>From 9b2488e3047e92070a86ecd15128779255e76290 Mon Sep 17 00:00:00 2001
From: Lukacma 
Date: Tue, 28 May 2024 12:07:37 +0100
Subject: [PATCH] Revert "[AArch64][SME] Add intrinsics for multi-vector
 BFCLAMP (#88251)"

This reverts commit 12271710da72a11d3958a2824fe269363c34.
---
 clang/include/clang/Basic/arm_sve.td  |  5 --
 .../aarch64-sme2-intrinsics/acle_sme2_clamp.c | 64 ---
 .../acle_sme2_b16b16.cpp  | 13 
 llvm/include/llvm/IR/IntrinsicsAArch64.td |  2 -
 .../Target/AArch64/AArch64ISelDAGToDAG.cpp|  6 --
 .../AArch64/sve2p1-intrinsics-bfclamp.ll  | 26 +---
 6 files changed, 1 insertion(+), 115 deletions(-)
 delete mode 100644 clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_b16b16.cpp

diff --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index 078ef576342a7..03570f94de666 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -2151,11 +2151,6 @@ let TargetGuard = "sme2" in {
   def SVFCLAMP_X4 : SInst<"svclamp[_single_{d}_x4]",  "44dd",   "hfd",  
MergeNone, "aarch64_sve_fclamp_single_x4",  [IsStreaming], []>;
 }
 
-let TargetGuard = "sme2,b16b16"in {
-  def SVBFCLAMP_X2 : SInst<"svclamp[_single_{d}_x2]",  "22dd",   "b",  
MergeNone, "aarch64_sve_bfclamp_single_x2",  [IsStreaming], []>;
-  def SVBFCLAMP_X4 : SInst<"svclamp[_single_{d}_x4]",  "44dd",   "b",  
MergeNone, "aarch64_sve_bfclamp_single_x4",  [IsStreaming], []>;
-}
-
 let TargetGuard = "sme2" in {
 // == ADD (vectors) ==
   def SVADD_SINGLE_X2 : SInst<"svadd[_single_{d}_x2]", "22d", "cUcsUsiUilUl", 
MergeNone, "aarch64_sve_add_single_x2", [IsStreaming], []>;
diff --git a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c
index 54b480eec97cd..57ea4d2a1ac47 100644
--- a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c
@@ -745,67 +745,3 @@ svfloat32x4_t test_svclamp_single_f32_x4(svfloat32x4_t 
op1, svfloat32_t op2, svf
 svfloat64x4_t test_svclamp_single_f64_x4(svfloat64x4_t op1, svfloat64_t op2, 
svfloat64_t op3) __arm_streaming {
   return SVE_ACLE_FUNC(svclamp, _single_f64_x4, , )(op1, op2, op3);
 }
-
-// CHECK-LABEL: @test_svclamp_single_bf16_x2(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv16bf16( [[OP1:%.*]], i64 
0)
-// CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv16bf16( [[OP1]], i64 8)
-// CHECK-NEXT:[[TMP2:%.*]] = tail call { ,  } @llvm.aarch64.sve.bfclamp.single.x2.nxv8bf16( [[TMP0]],  [[TMP1]],  
[[OP2:%.*]],  [[OP3:%.*]])
-// CHECK-NEXT:[[TMP3:%.*]] = extractvalue { ,  } [[TMP2]], 0
-// CHECK-NEXT:[[TMP4:%.*]] = tail call  
@llvm.vector.insert.nxv16bf16.nxv8bf16( poison,  [[TMP3]], i64 0)
-// CHECK-NEXT:[[TMP5:%.*]] = extractvalue { ,  } [[TMP2]], 1
-// CHECK-NEXT:[[TMP6:%.*]] = tail call  
@llvm.vector.insert.nxv16bf16.nxv8bf16( [[TMP4]],  [[TMP5]], i64 8)
-// CHECK-NEXT:ret  [[TMP6]]
-//
-// CPP-CHECK-LABEL: 
@_Z27test_svclamp_single_bf16_x214svbfloat16x2_tu14__SVBfloat16_tS0_(
-// CPP-CHECK-NEXT:  entry:
-// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv16bf16( [[OP1:%.*]], i64 
0)
-// CPP-CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv16bf16( [[OP1]], i64 8)
-// CPP-CHECK-NEXT:[[TMP2:%.*]] = tail call { , 
 } @llvm.aarch64.sve.bfclamp.single.x2.nxv8bf16( [[TMP0]],  [[TMP1]],  
[[OP2:%.*]],  [[OP3:%.*]])
-// CPP-CHECK-NEXT:[[TMP3:%.*]] = extractvalue { , 
 } [[TMP2]], 0
-// CPP-CHECK-NEXT:[[TMP4:%.*]] = tail call  
@llvm.vector.insert.nxv16bf16.nxv8bf16( poison,  [[TMP3]], i64 0)
-// CPP-CHECK-NEXT:[[TMP5:%.*]] = extractvalue { , 
 } [[TMP2]], 1
-// CPP-CHECK-NEXT:[[TMP6:%.*]] = tail call  
@llvm.vector.insert.nxv16bf16.nxv8bf16( [[TMP4]],  [[TMP5]], i64 8)
-// CPP-CHECK-NEXT:ret  [[TMP6]]
-//
-svbfloat16x2_t test_svclamp_single_bf16_x2(svbfloat16x2_t op1, svbfloat16_t 
op2, svbfloat16_t op3) __arm_streaming {
-  return SVE_ACLE_FUNC(svclamp, _single_bf16_x2, , )(op1, op2, op3);
-}
-
-// CHECK-LABEL: @test_svclamp_single_bf16_x4(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv32bf16( [[OP1:%.*]], i64 
0)
-// CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv32bf16( [[OP1]], i64 8)
-// CHECK-NEXT:[[TMP2:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv32bf16( [[OP1]], i64 16)
-// CHECK-NEXT:[[TMP3:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv32bf16( [[OP1]], i64 24)
-// CHECK-NEXT:[[TMP4:%.*]] = tail call { , , ,  } 
@llvm.aarch64.sve.bfclamp.single.x4.nxv8bf16( [[TMP0]], 
 [[TMP1]],  [[TMP2]],  [[TMP3]],  [[O

[clang] d67200e - Revert "[AArch64][SME] Add intrinsics for multi-vector BFCLAMP" (#93531)

2024-05-28 Thread via cfe-commits
Author: Lukacma
Date: 2024-05-28T12:07:49+01:00
New Revision: d67200e0842e972abbd1fd3e48a5b13d717bcbd6

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

LOG: Revert "[AArch64][SME] Add intrinsics for multi-vector BFCLAMP" (#93531)

Reverts llvm/llvm-project#88251

Added: 


Modified: 
clang/include/clang/Basic/arm_sve.td
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c
llvm/include/llvm/IR/IntrinsicsAArch64.td
llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
llvm/test/CodeGen/AArch64/sve2p1-intrinsics-bfclamp.ll

Removed: 
clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_b16b16.cpp



diff  --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index 078ef576342a7..03570f94de666 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -2151,11 +2151,6 @@ let TargetGuard = "sme2" in {
   def SVFCLAMP_X4 : SInst<"svclamp[_single_{d}_x4]",  "44dd",   "hfd",  
MergeNone, "aarch64_sve_fclamp_single_x4",  [IsStreaming], []>;
 }
 
-let TargetGuard = "sme2,b16b16"in {
-  def SVBFCLAMP_X2 : SInst<"svclamp[_single_{d}_x2]",  "22dd",   "b",  
MergeNone, "aarch64_sve_bfclamp_single_x2",  [IsStreaming], []>;
-  def SVBFCLAMP_X4 : SInst<"svclamp[_single_{d}_x4]",  "44dd",   "b",  
MergeNone, "aarch64_sve_bfclamp_single_x4",  [IsStreaming], []>;
-}
-
 let TargetGuard = "sme2" in {
 // == ADD (vectors) ==
   def SVADD_SINGLE_X2 : SInst<"svadd[_single_{d}_x2]", "22d", "cUcsUsiUilUl", 
MergeNone, "aarch64_sve_add_single_x2", [IsStreaming], []>;

diff  --git a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c
index 54b480eec97cd..57ea4d2a1ac47 100644
--- a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c
@@ -745,67 +745,3 @@ svfloat32x4_t test_svclamp_single_f32_x4(svfloat32x4_t 
op1, svfloat32_t op2, svf
 svfloat64x4_t test_svclamp_single_f64_x4(svfloat64x4_t op1, svfloat64_t op2, 
svfloat64_t op3) __arm_streaming {
   return SVE_ACLE_FUNC(svclamp, _single_f64_x4, , )(op1, op2, op3);
 }
-
-// CHECK-LABEL: @test_svclamp_single_bf16_x2(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv16bf16( [[OP1:%.*]], i64 
0)
-// CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv16bf16( [[OP1]], i64 8)
-// CHECK-NEXT:[[TMP2:%.*]] = tail call { ,  } @llvm.aarch64.sve.bfclamp.single.x2.nxv8bf16( [[TMP0]],  [[TMP1]],  
[[OP2:%.*]],  [[OP3:%.*]])
-// CHECK-NEXT:[[TMP3:%.*]] = extractvalue { ,  } [[TMP2]], 0
-// CHECK-NEXT:[[TMP4:%.*]] = tail call  
@llvm.vector.insert.nxv16bf16.nxv8bf16( poison,  [[TMP3]], i64 0)
-// CHECK-NEXT:[[TMP5:%.*]] = extractvalue { ,  } [[TMP2]], 1
-// CHECK-NEXT:[[TMP6:%.*]] = tail call  
@llvm.vector.insert.nxv16bf16.nxv8bf16( [[TMP4]],  [[TMP5]], i64 8)
-// CHECK-NEXT:ret  [[TMP6]]
-//
-// CPP-CHECK-LABEL: 
@_Z27test_svclamp_single_bf16_x214svbfloat16x2_tu14__SVBfloat16_tS0_(
-// CPP-CHECK-NEXT:  entry:
-// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv16bf16( [[OP1:%.*]], i64 
0)
-// CPP-CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv16bf16( [[OP1]], i64 8)
-// CPP-CHECK-NEXT:[[TMP2:%.*]] = tail call { , 
 } @llvm.aarch64.sve.bfclamp.single.x2.nxv8bf16( [[TMP0]],  [[TMP1]],  
[[OP2:%.*]],  [[OP3:%.*]])
-// CPP-CHECK-NEXT:[[TMP3:%.*]] = extractvalue { , 
 } [[TMP2]], 0
-// CPP-CHECK-NEXT:[[TMP4:%.*]] = tail call  
@llvm.vector.insert.nxv16bf16.nxv8bf16( poison,  [[TMP3]], i64 0)
-// CPP-CHECK-NEXT:[[TMP5:%.*]] = extractvalue { , 
 } [[TMP2]], 1
-// CPP-CHECK-NEXT:[[TMP6:%.*]] = tail call  
@llvm.vector.insert.nxv16bf16.nxv8bf16( [[TMP4]],  [[TMP5]], i64 8)
-// CPP-CHECK-NEXT:ret  [[TMP6]]
-//
-svbfloat16x2_t test_svclamp_single_bf16_x2(svbfloat16x2_t op1, svbfloat16_t 
op2, svbfloat16_t op3) __arm_streaming {
-  return SVE_ACLE_FUNC(svclamp, _single_bf16_x2, , )(op1, op2, op3);
-}
-
-// CHECK-LABEL: @test_svclamp_single_bf16_x4(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv32bf16( [[OP1:%.*]], i64 
0)
-// CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv32bf16( [[OP1]], i64 8)
-// CHECK-NEXT:[[TMP2:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv32bf16( [[OP1]], i64 16)
-// CHECK-NEXT:[[TMP3:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv32bf16( [[OP1]], i64 24)
-// CHECK-NEXT:[[TMP4:%.*]] = tail call { , , ,  } 
@llvm.aarch64.sve.bfclamp.single.x4.nxv8bf16( [[TMP0]], 
 [[TMP1]],  [[TMP2]],  [[TMP3]],  [[OP2:%.*]],  
[[OP3:%.*]])
-// CHEC

[clang] [llvm] Revert "[AArch64][SME] Add intrinsics for multi-vector BFCLAMP" (PR #93531)

2024-05-28 Thread via cfe-commits
https://github.com/Lukacma closed 
https://github.com/llvm/llvm-project/pull/93531
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Revert "[AArch64][SME] Add intrinsics for multi-vector BFCLAMP" (PR #93531)

2024-05-28 Thread via cfe-commits
llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-llvm-ir

Author: None (Lukacma)


Changes

Reverts llvm/llvm-project#88251

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


6 Files Affected:

- (modified) clang/include/clang/Basic/arm_sve.td (-5) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c (-64) 
- (removed) clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_b16b16.cpp (-13) 
- (modified) llvm/include/llvm/IR/IntrinsicsAArch64.td (-2) 
- (modified) llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp (-6) 
- (modified) llvm/test/CodeGen/AArch64/sve2p1-intrinsics-bfclamp.ll (+1-25) 


``diff
diff --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index 078ef576342a7..03570f94de666 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -2151,11 +2151,6 @@ let TargetGuard = "sme2" in {
   def SVFCLAMP_X4 : SInst<"svclamp[_single_{d}_x4]",  "44dd",   "hfd",  
MergeNone, "aarch64_sve_fclamp_single_x4",  [IsStreaming], []>;
 }
 
-let TargetGuard = "sme2,b16b16"in {
-  def SVBFCLAMP_X2 : SInst<"svclamp[_single_{d}_x2]",  "22dd",   "b",  
MergeNone, "aarch64_sve_bfclamp_single_x2",  [IsStreaming], []>;
-  def SVBFCLAMP_X4 : SInst<"svclamp[_single_{d}_x4]",  "44dd",   "b",  
MergeNone, "aarch64_sve_bfclamp_single_x4",  [IsStreaming], []>;
-}
-
 let TargetGuard = "sme2" in {
 // == ADD (vectors) ==
   def SVADD_SINGLE_X2 : SInst<"svadd[_single_{d}_x2]", "22d", "cUcsUsiUilUl", 
MergeNone, "aarch64_sve_add_single_x2", [IsStreaming], []>;
diff --git a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c
index 54b480eec97cd..57ea4d2a1ac47 100644
--- a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c
@@ -745,67 +745,3 @@ svfloat32x4_t test_svclamp_single_f32_x4(svfloat32x4_t 
op1, svfloat32_t op2, svf
 svfloat64x4_t test_svclamp_single_f64_x4(svfloat64x4_t op1, svfloat64_t op2, 
svfloat64_t op3) __arm_streaming {
   return SVE_ACLE_FUNC(svclamp, _single_f64_x4, , )(op1, op2, op3);
 }
-
-// CHECK-LABEL: @test_svclamp_single_bf16_x2(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv16bf16( [[OP1:%.*]], i64 
0)
-// CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv16bf16( [[OP1]], i64 8)
-// CHECK-NEXT:[[TMP2:%.*]] = tail call { ,  } @llvm.aarch64.sve.bfclamp.single.x2.nxv8bf16( [[TMP0]],  [[TMP1]],  
[[OP2:%.*]],  [[OP3:%.*]])
-// CHECK-NEXT:[[TMP3:%.*]] = extractvalue { ,  } [[TMP2]], 0
-// CHECK-NEXT:[[TMP4:%.*]] = tail call  
@llvm.vector.insert.nxv16bf16.nxv8bf16( poison,  [[TMP3]], i64 0)
-// CHECK-NEXT:[[TMP5:%.*]] = extractvalue { ,  } [[TMP2]], 1
-// CHECK-NEXT:[[TMP6:%.*]] = tail call  
@llvm.vector.insert.nxv16bf16.nxv8bf16( [[TMP4]],  [[TMP5]], i64 8)
-// CHECK-NEXT:ret  [[TMP6]]
-//
-// CPP-CHECK-LABEL: 
@_Z27test_svclamp_single_bf16_x214svbfloat16x2_tu14__SVBfloat16_tS0_(
-// CPP-CHECK-NEXT:  entry:
-// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv16bf16( [[OP1:%.*]], i64 
0)
-// CPP-CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv16bf16( [[OP1]], i64 8)
-// CPP-CHECK-NEXT:[[TMP2:%.*]] = tail call { , 
 } @llvm.aarch64.sve.bfclamp.single.x2.nxv8bf16( [[TMP0]],  [[TMP1]],  
[[OP2:%.*]],  [[OP3:%.*]])
-// CPP-CHECK-NEXT:[[TMP3:%.*]] = extractvalue { , 
 } [[TMP2]], 0
-// CPP-CHECK-NEXT:[[TMP4:%.*]] = tail call  
@llvm.vector.insert.nxv16bf16.nxv8bf16( poison,  [[TMP3]], i64 0)
-// CPP-CHECK-NEXT:[[TMP5:%.*]] = extractvalue { , 
 } [[TMP2]], 1
-// CPP-CHECK-NEXT:[[TMP6:%.*]] = tail call  
@llvm.vector.insert.nxv16bf16.nxv8bf16( [[TMP4]],  [[TMP5]], i64 8)
-// CPP-CHECK-NEXT:ret  [[TMP6]]
-//
-svbfloat16x2_t test_svclamp_single_bf16_x2(svbfloat16x2_t op1, svbfloat16_t 
op2, svbfloat16_t op3) __arm_streaming {
-  return SVE_ACLE_FUNC(svclamp, _single_bf16_x2, , )(op1, op2, op3);
-}
-
-// CHECK-LABEL: @test_svclamp_single_bf16_x4(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv32bf16( [[OP1:%.*]], i64 
0)
-// CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv32bf16( [[OP1]], i64 8)
-// CHECK-NEXT:[[TMP2:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv32bf16( [[OP1]], i64 16)
-// CHECK-NEXT:[[TMP3:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv32bf16( [[OP1]], i64 24)
-// CHECK-NEXT:[[TMP4:%.*]] = tail call { , , ,  } 
@llvm.aarch64.sve.bfclamp.single.x4.nxv8bf16( [[TMP0]], 
 [[TMP1]],  [[TMP2]],  [[TMP3]],  [[OP2:%.*]],  
[[OP3:%.*]])
-// CHECK-NEXT:[[TMP5:%.*]] = extractvalue { , , ,  } [[TMP4]], 0
-// CHECK-NEXT:[[TMP6:%.*]] = tail call  
@llvm.vector.insert.nxv32bf16.nxv8bf16( poison,  [[TMP5]], i64 0)
-// CHECK-

[clang] [llvm] [AArch64][SME] Add intrinsics for multi-vector BFCLAMP (PR #93532)

2024-05-28 Thread via cfe-commits
https://github.com/Lukacma created 
https://github.com/llvm/llvm-project/pull/93532

According to the specification in
https://github.com/ARM-software/acle/pull/309 this adds the intrinsics

```
  svbfloat16x2_t svclamp[_single_bf16_x2](svbfloat16x2_t zd, svbfloat16_t zn,
svbfloat16_t zm)  __arm_streaming;

  svbfloat16x4_t svclamp[_single_bf16_x4](svbfloat16x4_t zd, svbfloat16_t zn,
svbfloat16_t zm)  __arm_streaming;
```
These are available only  if __ARM_FEATURE_SME_B16B16 is enabled.

>From fe692284cd248e372302671e094eb9950edb5ee5 Mon Sep 17 00:00:00 2001
From: Marian Lukac 
Date: Wed, 10 Apr 2024 10:20:03 +
Subject: [PATCH 1/3] [AArch64][SME] Add intrinsics for multi-vector BFCLAMP

---
 clang/include/clang/Basic/arm_sve.td  |  5 ++
 .../aarch64-sme2-intrinsics/acle_sme2_clamp.c | 72 +--
 llvm/include/llvm/IR/IntrinsicsAArch64.td |  2 +
 .../Target/AArch64/AArch64ISelDAGToDAG.cpp|  6 ++
 .../AArch64/sve2p1-intrinsics-bfclamp.ll  | 26 ++-
 5 files changed, 106 insertions(+), 5 deletions(-)

diff --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index 6da30e08e7521..63ca495a1bc9f 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -2148,6 +2148,11 @@ let TargetGuard = "sme2" in {
   def SVSCLAMP_X4 : SInst<"svclamp[_single_{d}_x4]",  "44dd",   "csil", 
MergeNone, "aarch64_sve_sclamp_single_x4",  [IsStreaming], []>;
   def SVUCLAMP_X4 : SInst<"svclamp[_single_{d}_x4]",  "44dd",   "UcUsUiUl", 
MergeNone, "aarch64_sve_uclamp_single_x4",  [IsStreaming], []>;
   def SVFCLAMP_X4 : SInst<"svclamp[_single_{d}_x4]",  "44dd",   "hfd",  
MergeNone, "aarch64_sve_fclamp_single_x4",  [IsStreaming], []>;
+
+  let TargetGuard = "b16b16"in {
+def SVBFCLAMP_X2 : SInst<"svclamp[_single_{d}_x2]",  "22dd",   "b",  
MergeNone, "aarch64_sve_bfclamp_single_x2",  [IsStreaming], []>;
+def SVBFCLAMP_X4 : SInst<"svclamp[_single_{d}_x4]",  "44dd",   "b",  
MergeNone, "aarch64_sve_bfclamp_single_x4",  [IsStreaming], []>;
+  }
 }
 
 let TargetGuard = "sme2" in {
diff --git a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c
index 257cb59525018..1dd5aeee35fe7 100644
--- a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c
@@ -1,12 +1,12 @@
 // 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 \
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 
-target-feature +b16b16 \
 // RUN:  -S -Werror -emit-llvm -disable-O0-optnone -o - %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s
-// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme2 \
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme2 -target-feature +b16b16 \
 // RUN:  -S -Werror -emit-llvm -disable-O0-optnone -o - %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 \
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 
-target-feature +b16b16 \
 // RUN:  -S -Werror -emit-llvm -disable-O0-optnone -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 \
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme2 -target-feature +b16b16 \
 // RUN:  -S -Werror -emit-llvm -disable-O0-optnone -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 \
 // RUN:  -S -disable-O0-optnone -Werror -Wall -o /dev/null %s
@@ -745,3 +745,67 @@ svfloat32x4_t test_svclamp_single_f32_x4(svfloat32x4_t 
op1, svfloat32_t op2, svf
 svfloat64x4_t test_svclamp_single_f64_x4(svfloat64x4_t op1, svfloat64_t op2, 
svfloat64_t op3) __arm_streaming {
   return SVE_ACLE_FUNC(svclamp, _single_f64_x4, , )(op1, op2, op3);
 }
+
+// CHECK-LABEL: @test_svclamp_single_bf16_x2(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv16bf16( [[OP1:%.*]], i64 
0)
+// CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv16bf16( [[OP1]], i64 8)
+// CHECK-NEXT:[[TMP2:%.*]] = tail call { ,  } @llvm.aarch64.sve.bfclamp.single.x2.nxv8bf16( [[TMP0]],  [[TMP1]],  
[[OP2:%.*]],  [[OP3:%.*]])
+// CHECK-NEXT:[[TMP3:%.*]] = extractvalue { ,  } [[TMP2]], 0
+// CHECK-NEXT:[[TMP4:%.*]] = tail call  
@llvm.vector.insert.nxv16bf16.nxv8bf16( po

[clang] [llvm] [AArch64][SME] Add intrinsics for multi-vector BFCLAMP (PR #93532)

2024-05-28 Thread via cfe-commits
llvmbot wrote:



@llvm/pr-subscribers-llvm-ir

@llvm/pr-subscribers-clang

Author: None (Lukacma)


Changes

According to the specification in
https://github.com/ARM-software/acle/pull/309 this adds the intrinsics

```
  svbfloat16x2_t svclamp[_single_bf16_x2](svbfloat16x2_t zd, svbfloat16_t zn,
svbfloat16_t zm)  __arm_streaming;

  svbfloat16x4_t svclamp[_single_bf16_x4](svbfloat16x4_t zd, svbfloat16_t zn,
svbfloat16_t zm)  __arm_streaming;
```
These are available only  if __ARM_FEATURE_SME_B16B16 is enabled.

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


6 Files Affected:

- (modified) clang/include/clang/Basic/arm_sve.td (+5) 
- (modified) clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c (+64) 
- (added) clang/test/Sema/aarch64-sme2-intrinsics/acle_sme2_b16b16.cpp (+13) 
- (modified) llvm/include/llvm/IR/IntrinsicsAArch64.td (+2) 
- (modified) llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp (+6) 
- (modified) llvm/test/CodeGen/AArch64/sve2p1-intrinsics-bfclamp.ll (+25-1) 


``diff
diff --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index 03570f94de666..078ef576342a7 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -2151,6 +2151,11 @@ let TargetGuard = "sme2" in {
   def SVFCLAMP_X4 : SInst<"svclamp[_single_{d}_x4]",  "44dd",   "hfd",  
MergeNone, "aarch64_sve_fclamp_single_x4",  [IsStreaming], []>;
 }
 
+let TargetGuard = "sme2,b16b16"in {
+  def SVBFCLAMP_X2 : SInst<"svclamp[_single_{d}_x2]",  "22dd",   "b",  
MergeNone, "aarch64_sve_bfclamp_single_x2",  [IsStreaming], []>;
+  def SVBFCLAMP_X4 : SInst<"svclamp[_single_{d}_x4]",  "44dd",   "b",  
MergeNone, "aarch64_sve_bfclamp_single_x4",  [IsStreaming], []>;
+}
+
 let TargetGuard = "sme2" in {
 // == ADD (vectors) ==
   def SVADD_SINGLE_X2 : SInst<"svadd[_single_{d}_x2]", "22d", "cUcsUsiUilUl", 
MergeNone, "aarch64_sve_add_single_x2", [IsStreaming], []>;
diff --git a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c
index 57ea4d2a1ac47..54b480eec97cd 100644
--- a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c
@@ -745,3 +745,67 @@ svfloat32x4_t test_svclamp_single_f32_x4(svfloat32x4_t 
op1, svfloat32_t op2, svf
 svfloat64x4_t test_svclamp_single_f64_x4(svfloat64x4_t op1, svfloat64_t op2, 
svfloat64_t op3) __arm_streaming {
   return SVE_ACLE_FUNC(svclamp, _single_f64_x4, , )(op1, op2, op3);
 }
+
+// CHECK-LABEL: @test_svclamp_single_bf16_x2(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv16bf16( [[OP1:%.*]], i64 
0)
+// CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv16bf16( [[OP1]], i64 8)
+// CHECK-NEXT:[[TMP2:%.*]] = tail call { ,  } @llvm.aarch64.sve.bfclamp.single.x2.nxv8bf16( [[TMP0]],  [[TMP1]],  
[[OP2:%.*]],  [[OP3:%.*]])
+// CHECK-NEXT:[[TMP3:%.*]] = extractvalue { ,  } [[TMP2]], 0
+// CHECK-NEXT:[[TMP4:%.*]] = tail call  
@llvm.vector.insert.nxv16bf16.nxv8bf16( poison,  [[TMP3]], i64 0)
+// CHECK-NEXT:[[TMP5:%.*]] = extractvalue { ,  } [[TMP2]], 1
+// CHECK-NEXT:[[TMP6:%.*]] = tail call  
@llvm.vector.insert.nxv16bf16.nxv8bf16( [[TMP4]],  [[TMP5]], i64 8)
+// CHECK-NEXT:ret  [[TMP6]]
+//
+// CPP-CHECK-LABEL: 
@_Z27test_svclamp_single_bf16_x214svbfloat16x2_tu14__SVBfloat16_tS0_(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv16bf16( [[OP1:%.*]], i64 
0)
+// CPP-CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv16bf16( [[OP1]], i64 8)
+// CPP-CHECK-NEXT:[[TMP2:%.*]] = tail call { , 
 } @llvm.aarch64.sve.bfclamp.single.x2.nxv8bf16( [[TMP0]],  [[TMP1]],  
[[OP2:%.*]],  [[OP3:%.*]])
+// CPP-CHECK-NEXT:[[TMP3:%.*]] = extractvalue { , 
 } [[TMP2]], 0
+// CPP-CHECK-NEXT:[[TMP4:%.*]] = tail call  
@llvm.vector.insert.nxv16bf16.nxv8bf16( poison,  [[TMP3]], i64 0)
+// CPP-CHECK-NEXT:[[TMP5:%.*]] = extractvalue { , 
 } [[TMP2]], 1
+// CPP-CHECK-NEXT:[[TMP6:%.*]] = tail call  
@llvm.vector.insert.nxv16bf16.nxv8bf16( [[TMP4]],  [[TMP5]], i64 8)
+// CPP-CHECK-NEXT:ret  [[TMP6]]
+//
+svbfloat16x2_t test_svclamp_single_bf16_x2(svbfloat16x2_t op1, svbfloat16_t 
op2, svbfloat16_t op3) __arm_streaming {
+  return SVE_ACLE_FUNC(svclamp, _single_bf16_x2, , )(op1, op2, op3);
+}
+
+// CHECK-LABEL: @test_svclamp_single_bf16_x4(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv32bf16( [[OP1:%.*]], i64 
0)
+// CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv32bf16( [[OP1]], i64 8)
+// CHECK-NEXT:[[TMP2:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv32bf16( [[OP1]], i64 16)
+// CHECK-NEXT:   

[clang] [clang-repl] Set up executor implicitly to account for init PTUs (PR #84758)

2024-05-28 Thread Stefan Gränitz via cfe-commits
weliveindetail wrote:

Some bots report failures after this patch landed. I will push a fix soon.

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


[clang] [clang] CTAD alias: fix transformation for require-clause expr Part2. (PR #93533)

2024-05-28 Thread Haojian Wu via cfe-commits
https://github.com/hokein created 
https://github.com/llvm/llvm-project/pull/93533

In the https://github.com/llvm/llvm-project/pull/90961 fix, we miss a case 
where the undeduced template parameters of the underlying deduction guide are 
not transformed, which leaves incorrect depth/index information, and causes 
crashes when evaluating constraints.

This patch fix this missing case.

Fixes #92596
Fixes #92212

>From efd657d537e57fd791dcd9cf0c38cc578c023e00 Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Fri, 17 May 2024 15:28:48 +0200
Subject: [PATCH] [clang] CTAD alias: fix transformation for require-clause
 expr Part2.

In the https://github.com/llvm/llvm-project/pull/90961 fix, we miss a
case where the undeduced template parameters of the underlying deduction
guide is not transformed, which leaves incorrect depth/index
information, and causes crash when evaluating the constraints.

This patch fix this missing case.

Fixes #92596
Fixes #92212
---
 clang/lib/Sema/SemaTemplate.cpp  | 32 
 clang/test/AST/ast-dump-ctad-alias.cpp   | 25 +++
 clang/test/SemaCXX/cxx20-ctad-type-alias.cpp | 25 +++
 3 files changed, 76 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 39e9dbed0c3e0..62d7097f68785 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -2780,6 +2780,7 @@ Expr *
 buildAssociatedConstraints(Sema &SemaRef, FunctionTemplateDecl *F,
TypeAliasTemplateDecl *AliasTemplate,
ArrayRef DeduceResults,
+   unsigned UndeducedTemplateParameterStartIndex,
Expr *IsDeducible) {
   Expr *RC = F->getTemplateParameters()->getRequiresClause();
   if (!RC)
@@ -2840,8 +2841,22 @@ buildAssociatedConstraints(Sema &SemaRef, 
FunctionTemplateDecl *F,
 
   for (unsigned Index = 0; Index < DeduceResults.size(); ++Index) {
 const auto &D = DeduceResults[Index];
-if (D.isNull())
+if (D.isNull()) { // non-deduced template parameters of f
+  auto TP = F->getTemplateParameters()->getParam(Index);
+  MultiLevelTemplateArgumentList Args;
+  Args.setKind(TemplateSubstitutionKind::Rewrite);
+  Args.addOuterTemplateArguments(TemplateArgsForBuildingRC);
+  // Rebuild the template parameter with updated depth and index.
+  NamedDecl *NewParam = transformTemplateParameter(
+  SemaRef, F->getDeclContext(), TP, Args,
+  /*NewIndex=*/UndeducedTemplateParameterStartIndex++,
+  getTemplateParameterDepth(TP) + AdjustDepth);
+
+  assert(TemplateArgsForBuildingRC[Index].isNull());
+  TemplateArgsForBuildingRC[Index] = Context.getCanonicalTemplateArgument(
+  Context.getInjectedTemplateArg(NewParam));
   continue;
+}
 TemplateArgumentLoc Input =
 SemaRef.getTrivialTemplateArgumentLoc(D, QualType(), SourceLocation{});
 TemplateArgumentLoc Output;
@@ -2857,9 +2872,11 @@ buildAssociatedConstraints(Sema &SemaRef, 
FunctionTemplateDecl *F,
   MultiLevelTemplateArgumentList ArgsForBuildingRC;
   ArgsForBuildingRC.setKind(clang::TemplateSubstitutionKind::Rewrite);
   ArgsForBuildingRC.addOuterTemplateArguments(TemplateArgsForBuildingRC);
-  // For 2), if the underlying F is instantiated from a member template, we 
need
-  // the entire template argument list, as the constraint AST in the
-  // require-clause of F remains completely uninstantiated.
+  // For 2), if the underlying function template F is nested in a class 
template
+  // (either instantiated from an explicitly-written deduction guide, or
+  // synthesized from a constructor), we need the entire template argument 
list,
+  // as the constraint AST in the require-clause of F remains completely
+  // uninstantiated.
   //
   // For example:
   //   template  // depth 0
@@ -2882,7 +2899,8 @@ buildAssociatedConstraints(Sema &SemaRef, 
FunctionTemplateDecl *F,
   // We add the outer template arguments which is [int] to the multi-level arg
   // list to ensure that the occurrence U in `C` will be replaced with int
   // during the substitution.
-  if (F->getInstantiatedFromMemberTemplate()) {
+  if (F->getLexicalDeclContext()->getDeclKind() ==
+  clang::Decl::ClassTemplateSpecialization) {
 auto OuterLevelArgs = SemaRef.getTemplateInstantiationArgs(
 F, F->getLexicalDeclContext(),
 /*Final=*/false, /*Innermost=*/std::nullopt,
@@ -3100,6 +3118,7 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
 Context.getInjectedTemplateArg(NewParam));
 TransformedDeducedAliasArgs[AliasTemplateParamIdx] = NewTemplateArgument;
   }
+  unsigned UndeducedTemplateParameterStartIndex = FPrimeTemplateParams.size();
   //   ...followed by the template parameters of f that were not deduced
   //   (including their default template arguments)
   for (unsigned FTemplateParamIdx : NonDeducedTemplateParamsInFIndex) {
@@ -3169,7 +3

[clang] [clang] CTAD alias: fix transformation for require-clause expr Part2. (PR #93533)

2024-05-28 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Haojian Wu (hokein)


Changes

In the https://github.com/llvm/llvm-project/pull/90961 fix, we miss a case 
where the undeduced template parameters of the underlying deduction guide are 
not transformed, which leaves incorrect depth/index information, and causes 
crashes when evaluating constraints.

This patch fix this missing case.

Fixes #92596
Fixes #92212

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


3 Files Affected:

- (modified) clang/lib/Sema/SemaTemplate.cpp (+26-6) 
- (modified) clang/test/AST/ast-dump-ctad-alias.cpp (+25) 
- (modified) clang/test/SemaCXX/cxx20-ctad-type-alias.cpp (+25) 


``diff
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 39e9dbed0c3e0..62d7097f68785 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -2780,6 +2780,7 @@ Expr *
 buildAssociatedConstraints(Sema &SemaRef, FunctionTemplateDecl *F,
TypeAliasTemplateDecl *AliasTemplate,
ArrayRef DeduceResults,
+   unsigned UndeducedTemplateParameterStartIndex,
Expr *IsDeducible) {
   Expr *RC = F->getTemplateParameters()->getRequiresClause();
   if (!RC)
@@ -2840,8 +2841,22 @@ buildAssociatedConstraints(Sema &SemaRef, 
FunctionTemplateDecl *F,
 
   for (unsigned Index = 0; Index < DeduceResults.size(); ++Index) {
 const auto &D = DeduceResults[Index];
-if (D.isNull())
+if (D.isNull()) { // non-deduced template parameters of f
+  auto TP = F->getTemplateParameters()->getParam(Index);
+  MultiLevelTemplateArgumentList Args;
+  Args.setKind(TemplateSubstitutionKind::Rewrite);
+  Args.addOuterTemplateArguments(TemplateArgsForBuildingRC);
+  // Rebuild the template parameter with updated depth and index.
+  NamedDecl *NewParam = transformTemplateParameter(
+  SemaRef, F->getDeclContext(), TP, Args,
+  /*NewIndex=*/UndeducedTemplateParameterStartIndex++,
+  getTemplateParameterDepth(TP) + AdjustDepth);
+
+  assert(TemplateArgsForBuildingRC[Index].isNull());
+  TemplateArgsForBuildingRC[Index] = Context.getCanonicalTemplateArgument(
+  Context.getInjectedTemplateArg(NewParam));
   continue;
+}
 TemplateArgumentLoc Input =
 SemaRef.getTrivialTemplateArgumentLoc(D, QualType(), SourceLocation{});
 TemplateArgumentLoc Output;
@@ -2857,9 +2872,11 @@ buildAssociatedConstraints(Sema &SemaRef, 
FunctionTemplateDecl *F,
   MultiLevelTemplateArgumentList ArgsForBuildingRC;
   ArgsForBuildingRC.setKind(clang::TemplateSubstitutionKind::Rewrite);
   ArgsForBuildingRC.addOuterTemplateArguments(TemplateArgsForBuildingRC);
-  // For 2), if the underlying F is instantiated from a member template, we 
need
-  // the entire template argument list, as the constraint AST in the
-  // require-clause of F remains completely uninstantiated.
+  // For 2), if the underlying function template F is nested in a class 
template
+  // (either instantiated from an explicitly-written deduction guide, or
+  // synthesized from a constructor), we need the entire template argument 
list,
+  // as the constraint AST in the require-clause of F remains completely
+  // uninstantiated.
   //
   // For example:
   //   template  // depth 0
@@ -2882,7 +2899,8 @@ buildAssociatedConstraints(Sema &SemaRef, 
FunctionTemplateDecl *F,
   // We add the outer template arguments which is [int] to the multi-level arg
   // list to ensure that the occurrence U in `C` will be replaced with int
   // during the substitution.
-  if (F->getInstantiatedFromMemberTemplate()) {
+  if (F->getLexicalDeclContext()->getDeclKind() ==
+  clang::Decl::ClassTemplateSpecialization) {
 auto OuterLevelArgs = SemaRef.getTemplateInstantiationArgs(
 F, F->getLexicalDeclContext(),
 /*Final=*/false, /*Innermost=*/std::nullopt,
@@ -3100,6 +3118,7 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
 Context.getInjectedTemplateArg(NewParam));
 TransformedDeducedAliasArgs[AliasTemplateParamIdx] = NewTemplateArgument;
   }
+  unsigned UndeducedTemplateParameterStartIndex = FPrimeTemplateParams.size();
   //   ...followed by the template parameters of f that were not deduced
   //   (including their default template arguments)
   for (unsigned FTemplateParamIdx : NonDeducedTemplateParamsInFIndex) {
@@ -3169,7 +3188,8 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
 Expr *IsDeducible = buildIsDeducibleConstraint(
 SemaRef, AliasTemplate, FPrime->getReturnType(), FPrimeTemplateParams);
 Expr *RequiresClause = buildAssociatedConstraints(
-SemaRef, F, AliasTemplate, DeduceResults, IsDeducible);
+SemaRef, F, AliasTemplate, DeduceResults,
+UndeducedTemplateParameterStartIndex, IsDeducible);
 
 // FIXME: implement the is_deducible constraint per C++
 // [over.match.class.deduct]p3.

[clang] fix(91536): clang 18.1 parser crash (PR #93490)

2024-05-28 Thread via cfe-commits
cor3ntin wrote:

Thanks!

The change looks good but the commit message could be improved (ie it should 
give some description of the bug/fix)


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


[clang] [llvm] [SME] Add intrinsics for FCVT(wid.) and FCVTL (PR #93202)

2024-05-28 Thread via cfe-commits
https://github.com/Lukacma updated 
https://github.com/llvm/llvm-project/pull/93202

>From a1750b2b5658f8ced700bbf010019703fc52f126 Mon Sep 17 00:00:00 2001
From: Caroline Concatto 
Date: Mon, 15 Apr 2024 13:31:00 +
Subject: [PATCH 1/7] [LLVM][AARCH64]Replace +sme2p1+smef16f16 by +smef16f16

According to the latest ISA Spec release[1] all instructions under:
 HasSME2p1 and HasSMEF16F16
should now only require:
HasSMEF16F16

[1]https://developer.arm.com
---
 llvm/test/MC/AArch64/SME2p1/fadd.s | 8 
 llvm/test/MC/AArch64/SME2p1/fmla-diagnostics.s | 2 +-
 llvm/test/MC/AArch64/SME2p1/fmls-diagnostics.s | 2 +-
 llvm/test/MC/AArch64/SME2p1/fsub.s | 8 
 4 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/llvm/test/MC/AArch64/SME2p1/fadd.s 
b/llvm/test/MC/AArch64/SME2p1/fadd.s
index bdb769093c838..ec4f27e021a00 100644
--- a/llvm/test/MC/AArch64/SME2p1/fadd.s
+++ b/llvm/test/MC/AArch64/SME2p1/fadd.s
@@ -1,16 +1,24 @@
 // RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sme-f16f16 < %s \
 // RUN:| FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
 // RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sme-f8f16 < %s \
+// RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sme-f16f16 < %s \
+// RUN:| FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
+// RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sme-f8f16 < %s \
 // RUN:| FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
 // RUN: not llvm-mc -triple=aarch64 -show-encoding < %s 2>&1 \
 // RUN:| FileCheck %s --check-prefix=CHECK-ERROR
 // RUN: llvm-mc -triple=aarch64 -filetype=obj -mattr=+sme-f16f16 < %s \
 // RUN:| llvm-objdump -d --mattr=+sme-f16f16 - | FileCheck %s 
--check-prefix=CHECK-INST
 // RUN: llvm-mc -triple=aarch64 -filetype=obj -mattr=+sme-f16f16 < %s \
+// RUN: llvm-mc -triple=aarch64 -filetype=obj -mattr=+sme-f16f16 < %s \
+// RUN:| llvm-objdump -d --mattr=+sme-f16f16 - | FileCheck %s 
--check-prefix=CHECK-INST
+// RUN: llvm-mc -triple=aarch64 -filetype=obj -mattr=+sme-f16f16 < %s \
 // RUN:| llvm-objdump -d --mattr=-sme2p1 - | FileCheck %s 
--check-prefix=CHECK-UNKNOWN
 // RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sme-f16f16 < %s \
+// RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sme-f16f16 < %s \
 // RUN:| sed '/.text/d' | sed 's/.*encoding: //g' \
 // RUN:| llvm-mc -triple=aarch64 -mattr=+sme-f16f16 -disassemble 
-show-encoding \
+// RUN:| llvm-mc -triple=aarch64 -mattr=+sme-f16f16 -disassemble 
-show-encoding \
 // RUN:| FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
 
 faddza.h[w8, 0, vgx2], {z0.h, z1.h}  // 1101-10100100-00011100-
diff --git a/llvm/test/MC/AArch64/SME2p1/fmla-diagnostics.s 
b/llvm/test/MC/AArch64/SME2p1/fmla-diagnostics.s
index 2f0dccb57c907..c31b54fc05dea 100644
--- a/llvm/test/MC/AArch64/SME2p1/fmla-diagnostics.s
+++ b/llvm/test/MC/AArch64/SME2p1/fmla-diagnostics.s
@@ -66,7 +66,7 @@ fmla za.h[w8, 8, vgx2], {z12.h-z13.h}, {z8.h-z9.h}
 // Invalid Register Suffix
 
 fmla za.d[w8, 7, vgx2], {z12.h-z13.h}, {z8.h-z9.h}
-// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid matrix operand, expected 
suffix .s
+// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid matrix operand, expected 
suffix .h
 // CHECK-NEXT: fmla za.d[w8, 7, vgx2], {z12.h-z13.h}, {z8.h-z9.h}
 // CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
 
diff --git a/llvm/test/MC/AArch64/SME2p1/fmls-diagnostics.s 
b/llvm/test/MC/AArch64/SME2p1/fmls-diagnostics.s
index 3ff09321e3436..2deb18186eafc 100644
--- a/llvm/test/MC/AArch64/SME2p1/fmls-diagnostics.s
+++ b/llvm/test/MC/AArch64/SME2p1/fmls-diagnostics.s
@@ -66,7 +66,7 @@ fmls za.h[w8, 8, vgx2], {z12.h-z13.h}, {z8.h-z9.h}
 // Invalid Register Suffix
 
 fmls za.d[w8, 7, vgx2], {z12.h-z13.h}, {z8.h-z9.h}
-// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid matrix operand, expected 
suffix .s
+// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid matrix operand, expected 
suffix .h
 // CHECK-NEXT: fmls za.d[w8, 7, vgx2], {z12.h-z13.h}, {z8.h-z9.h}
 // CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
 
diff --git a/llvm/test/MC/AArch64/SME2p1/fsub.s 
b/llvm/test/MC/AArch64/SME2p1/fsub.s
index 66410008eb11d..e42a819e0d415 100644
--- a/llvm/test/MC/AArch64/SME2p1/fsub.s
+++ b/llvm/test/MC/AArch64/SME2p1/fsub.s
@@ -1,16 +1,24 @@
 // RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sme-f16f16 < %s \
 // RUN:| FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
 // RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sme-f8f16 < %s \
+// RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sme-f16f16 < %s \
+// RUN:| FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
+// RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sme-f8f16 < %s \
 // RUN:| FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
 // RUN: not llvm-mc -triple=aarch64 -show-encoding < %s 2>&1 \
 // RUN:| FileCheck %s --check-prefix=CHECK-ERROR
 // 

[clang] 98f9bb3 - [clang-repl] Check host JIT support in all tests that create an Interpreter (#84758)

2024-05-28 Thread Stefan Gränitz via cfe-commits
Author: Stefan Gränitz
Date: 2024-05-28T13:54:09+02:00
New Revision: 98f9bb384af1beb62eb62a353f0585281bee8c26

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

LOG: [clang-repl] Check host JIT support in all tests that create an 
Interpreter (#84758)

Added: 


Modified: 
clang/unittests/Interpreter/IncrementalProcessingTest.cpp
clang/unittests/Interpreter/InterpreterExtensionsTest.cpp
clang/unittests/Interpreter/InterpreterTest.cpp

Removed: 




diff  --git a/clang/unittests/Interpreter/IncrementalProcessingTest.cpp 
b/clang/unittests/Interpreter/IncrementalProcessingTest.cpp
index accdf68289634..54159173d91e3 100644
--- a/clang/unittests/Interpreter/IncrementalProcessingTest.cpp
+++ b/clang/unittests/Interpreter/IncrementalProcessingTest.cpp
@@ -16,6 +16,8 @@
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Parse/Parser.h"
 #include "clang/Sema/Sema.h"
+
+#include "llvm/ExecutionEngine/Orc/LLJIT.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
 #include "llvm/Support/MemoryBuffer.h"
@@ -25,11 +27,23 @@
 
 #include 
 
+#if defined(_AIX) || defined(__MVS__)
+#define CLANG_INTERPRETER_PLATFORM_CANNOT_CREATE_LLJIT
+#endif
+
 using namespace llvm;
 using namespace clang;
 
 namespace {
 
+static bool HostSupportsJit() {
+  auto J = llvm::orc::LLJITBuilder().create();
+  if (J)
+return true;
+  LLVMConsumeError(llvm::wrap(J.takeError()));
+  return false;
+}
+
 // Incremental processing produces several modules, all using the same "main
 // file". Make sure CodeGen can cope with that, e.g. for static initializers.
 const char TestProgram1[] = "extern \"C\" int funcForProg1() { return 17; }\n"
@@ -50,7 +64,11 @@ const Function *getGlobalInit(llvm::Module *M) {
   return nullptr;
 }
 
+#ifdef CLANG_INTERPRETER_PLATFORM_CANNOT_CREATE_LLJIT
+TEST(IncrementalProcessing, DISABLED_EmitCXXGlobalInitFunc) {
+#else
 TEST(IncrementalProcessing, EmitCXXGlobalInitFunc) {
+#endif
   std::vector ClangArgv = {"-Xclang", "-emit-llvm-only"};
   auto CB = clang::IncrementalCompilerBuilder();
   CB.SetCompilerArgs(ClangArgv);

diff  --git a/clang/unittests/Interpreter/InterpreterExtensionsTest.cpp 
b/clang/unittests/Interpreter/InterpreterExtensionsTest.cpp
index 3651ba332124b..e22a78048d525 100644
--- a/clang/unittests/Interpreter/InterpreterExtensionsTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterExtensionsTest.cpp
@@ -103,7 +103,14 @@ class RecordRuntimeIBMetrics : public Interpreter {
   NoopRuntimeInterfaceBuilder *RuntimeIBPtr = nullptr;
 };
 
+#ifdef CLANG_INTERPRETER_PLATFORM_CANNOT_CREATE_LLJIT
+TEST(InterpreterExtensionsTest, DISABLED_FindRuntimeInterface) {
+#else
 TEST(InterpreterExtensionsTest, FindRuntimeInterface) {
+#endif
+  if (!HostSupportsJit())
+GTEST_SKIP();
+
   clang::IncrementalCompilerBuilder CB;
   llvm::Error ErrOut = llvm::Error::success();
   RecordRuntimeIBMetrics Interp(cantFail(CB.CreateCpp()), ErrOut);

diff  --git a/clang/unittests/Interpreter/InterpreterTest.cpp 
b/clang/unittests/Interpreter/InterpreterTest.cpp
index 69bc2da242884..86eeb4bb733fd 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -54,11 +54,30 @@ createInterpreter(const Args &ExtraArgs = {},
   return cantFail(clang::Interpreter::create(std::move(CI)));
 }
 
+static bool HostSupportsJit() {
+  auto J = llvm::orc::LLJITBuilder().create();
+  if (J)
+return true;
+  LLVMConsumeError(llvm::wrap(J.takeError()));
+  return false;
+}
+
+struct LLVMInitRAII {
+  LLVMInitRAII() {
+llvm::InitializeNativeTarget();
+llvm::InitializeNativeTargetAsmPrinter();
+  }
+  ~LLVMInitRAII() { llvm::llvm_shutdown(); }
+} LLVMInit;
+
 static size_t DeclsSize(TranslationUnitDecl *PTUDecl) {
   return std::distance(PTUDecl->decls().begin(), PTUDecl->decls().end());
 }
 
 TEST(InterpreterTest, Sanity) {
+  if (!HostSupportsJit())
+GTEST_SKIP();
+
   std::unique_ptr Interp = createInterpreter();
 
   using PTU = PartialTranslationUnit;
@@ -74,7 +93,14 @@ static std::string DeclToString(Decl *D) {
   return llvm::cast(D)->getQualifiedNameAsString();
 }
 
+#ifdef CLANG_INTERPRETER_NO_SUPPORT_EXEC
+TEST(InterpreterTest, DISABLED_IncrementalInputTopLevelDecls) {
+#else
 TEST(InterpreterTest, IncrementalInputTopLevelDecls) {
+#endif
+  if (!HostSupportsJit())
+GTEST_SKIP();
+
   std::unique_ptr Interp = createInterpreter();
   auto R1 = Interp->Parse("int var1 = 42; int f() { return var1; }");
   // gtest doesn't expand into explicit bool conversions.
@@ -91,7 +117,14 @@ TEST(InterpreterTest, IncrementalInputTopLevelDecls) {
   EXPECT_EQ("var2", DeclToString(*R2DeclRange.begin()));
 }
 
+#ifdef CLANG_INTERPRETER_NO_SUPPORT_EXEC
+TEST(InterpreterTest, DISABLED_Errors) {
+#else
 TEST(InterpreterTest, E

[clang] [clang-repl] Set up executor implicitly to account for init PTUs (PR #84758)

2024-05-28 Thread Stefan Gränitz via cfe-commits
weliveindetail wrote:

@vgvassilev I pushed a quick fix for the tests. I think we should 
revisit/refactor the test story here though in the mid-term.

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


[libcxx] [libcxxabi] [libunwind] [runtimes] Reintroduce a way to select the compiler used for the test suite (PR #93542)

2024-05-28 Thread Louis Dionne via cfe-commits
https://github.com/ldionne created 
https://github.com/llvm/llvm-project/pull/93542

A while back, the cxx_under_test Lit parameter was removed. This patch 
reintroduces a Lit parameter called "compiler" which controls the value of the 
%{cxx} substitution used in the test suite.

To run the test suite with a different compiler, one can now pass --param 
compiler=.

>From 95ca5b389506f0a2e32abd0af632af5a87d3c356 Mon Sep 17 00:00:00 2001
From: Louis Dionne 
Date: Tue, 28 May 2024 07:43:34 -0400
Subject: [PATCH] [runtimes] Reintroduce a way to select the compiler used for
 the test suite

A while back, the cxx_under_test Lit parameter was removed. This patch
reintroduces a Lit parameter called "compiler" which controls the value
of the %{cxx} substitution used in the test suite.

To run the test suite with a different compiler, one can now pass
--param compiler=.
---
 libcxx/test/CMakeLists.txt | 2 ++
 libcxx/test/configs/cmake-bridge.cfg.in| 2 --
 libcxx/utils/libcxx/test/params.py | 8 
 libcxxabi/test/CMakeLists.txt  | 2 ++
 libcxxabi/test/configs/cmake-bridge.cfg.in | 1 -
 libunwind/test/CMakeLists.txt  | 2 ++
 libunwind/test/configs/cmake-bridge.cfg.in | 2 --
 7 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/libcxx/test/CMakeLists.txt b/libcxx/test/CMakeLists.txt
index fd57aa9fe8b37..ee3502d32f7ae 100644
--- a/libcxx/test/CMakeLists.txt
+++ b/libcxx/test/CMakeLists.txt
@@ -16,6 +16,8 @@ endif()
 set(AUTO_GEN_COMMENT "## Autogenerated by libcxx configuration.\n# Do not 
edit!")
 set(SERIALIZED_LIT_PARAMS "# Lit parameters serialized here for llvm-lit to 
pick them up\n")
 
+serialize_lit_string_param(SERIALIZED_LIT_PARAMS compiler 
"${CMAKE_CXX_COMPILER}")
+
 if (NOT LIBCXX_ENABLE_EXCEPTIONS)
   serialize_lit_param(SERIALIZED_LIT_PARAMS enable_exceptions False)
 endif()
diff --git a/libcxx/test/configs/cmake-bridge.cfg.in 
b/libcxx/test/configs/cmake-bridge.cfg.in
index 84b3270a8940a..78d0cb5a25748 100644
--- a/libcxx/test/configs/cmake-bridge.cfg.in
+++ b/libcxx/test/configs/cmake-bridge.cfg.in
@@ -23,8 +23,6 @@ config.recursiveExpansionLimit = 10
 config.test_exec_root = os.path.join('@CMAKE_BINARY_DIR@', 'test')
 
 # Add substitutions for bootstrapping the test suite configuration
-import shlex
-config.substitutions.append(('%{cxx}', shlex.quote('@CMAKE_CXX_COMPILER@')))
 config.substitutions.append(('%{libcxx-dir}', '@LIBCXX_SOURCE_DIR@'))
 config.substitutions.append(('%{include-dir}', 
'@LIBCXX_GENERATED_INCLUDE_DIR@'))
 config.substitutions.append(('%{target-include-dir}', 
'@LIBCXX_GENERATED_INCLUDE_TARGET_DIR@'))
diff --git a/libcxx/utils/libcxx/test/params.py 
b/libcxx/utils/libcxx/test/params.py
index c2d294e49f488..0370a2da0ac75 100644
--- a/libcxx/utils/libcxx/test/params.py
+++ b/libcxx/utils/libcxx/test/params.py
@@ -143,6 +143,14 @@ def getSuitableClangTidy(cfg):
 
 # fmt: off
 DEFAULT_PARAMETERS = [
+Parameter(
+name="compiler",
+type=str,
+help="The path of the compiler to use for testing.",
+actions=lambda cxx: [
+AddSubstitution("%{cxx}", cxx),
+],
+),
 Parameter(
 name="target_triple",
 type=str,
diff --git a/libcxxabi/test/CMakeLists.txt b/libcxxabi/test/CMakeLists.txt
index 586927189cf1d..cd908a3514cb2 100644
--- a/libcxxabi/test/CMakeLists.txt
+++ b/libcxxabi/test/CMakeLists.txt
@@ -24,6 +24,8 @@ endif()
 set(AUTO_GEN_COMMENT "## Autogenerated by libcxxabi configuration.\n# Do not 
edit!")
 set(SERIALIZED_LIT_PARAMS "# Lit parameters serialized here for llvm-lit to 
pick them up\n")
 
+serialize_lit_string_param(SERIALIZED_LIT_PARAMS compiler 
"${CMAKE_CXX_COMPILER}")
+
 if (NOT LIBCXXABI_ENABLE_EXCEPTIONS)
   serialize_lit_param(SERIALIZED_LIT_PARAMS enable_exceptions False)
 endif()
diff --git a/libcxxabi/test/configs/cmake-bridge.cfg.in 
b/libcxxabi/test/configs/cmake-bridge.cfg.in
index 1d0f51d37437b..3fefc6a7fdc88 100644
--- a/libcxxabi/test/configs/cmake-bridge.cfg.in
+++ b/libcxxabi/test/configs/cmake-bridge.cfg.in
@@ -26,7 +26,6 @@ config.test_exec_root = os.path.join('@CMAKE_BINARY_DIR@', 
'test')
 # TODO: This is a non-standard Lit attribute and we should have another way of 
accessing this.
 config.host_triple = '@LLVM_HOST_TRIPLE@'
 
-config.substitutions.append(('%{cxx}', '@CMAKE_CXX_COMPILER@'))
 config.substitutions.append(('%{libcxx}', '@LIBCXXABI_LIBCXX_PATH@'))
 config.substitutions.append(('%{include}', '@LIBCXXABI_SOURCE_DIR@/include'))
 config.substitutions.append(('%{cxx-include}', 
'@LIBCXXABI_HEADER_DIR@/include/c++/v1'))
diff --git a/libunwind/test/CMakeLists.txt b/libunwind/test/CMakeLists.txt
index 21dfbb0a84f0a..bd2e575f2a296 100644
--- a/libunwind/test/CMakeLists.txt
+++ b/libunwind/test/CMakeLists.txt
@@ -15,6 +15,8 @@ pythonize_bool(LIBUNWIND_USES_ARM_EHABI)
 set(AUTO_GEN_COMMENT "## Autogenerated by libunwind configuration.\n# Do not 
edit!")
 set(SERIALIZED_LIT_PARAMS "# Lit parameters serialized

[libcxx] [libcxxabi] [libunwind] [runtimes] Reintroduce a way to select the compiler used for the test suite (PR #93542)

2024-05-28 Thread via cfe-commits
llvmbot wrote:



@llvm/pr-subscribers-libunwind

@llvm/pr-subscribers-libcxx

Author: Louis Dionne (ldionne)


Changes

A while back, the cxx_under_test Lit parameter was removed. This patch 
reintroduces a Lit parameter called "compiler" which controls the value of the 
%{cxx} substitution used in the test suite.

To run the test suite with a different compiler, one can now pass --param 
compiler=.

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


7 Files Affected:

- (modified) libcxx/test/CMakeLists.txt (+2) 
- (modified) libcxx/test/configs/cmake-bridge.cfg.in (-2) 
- (modified) libcxx/utils/libcxx/test/params.py (+8) 
- (modified) libcxxabi/test/CMakeLists.txt (+2) 
- (modified) libcxxabi/test/configs/cmake-bridge.cfg.in (-1) 
- (modified) libunwind/test/CMakeLists.txt (+2) 
- (modified) libunwind/test/configs/cmake-bridge.cfg.in (-2) 


``diff
diff --git a/libcxx/test/CMakeLists.txt b/libcxx/test/CMakeLists.txt
index fd57aa9fe8b37..ee3502d32f7ae 100644
--- a/libcxx/test/CMakeLists.txt
+++ b/libcxx/test/CMakeLists.txt
@@ -16,6 +16,8 @@ endif()
 set(AUTO_GEN_COMMENT "## Autogenerated by libcxx configuration.\n# Do not 
edit!")
 set(SERIALIZED_LIT_PARAMS "# Lit parameters serialized here for llvm-lit to 
pick them up\n")
 
+serialize_lit_string_param(SERIALIZED_LIT_PARAMS compiler 
"${CMAKE_CXX_COMPILER}")
+
 if (NOT LIBCXX_ENABLE_EXCEPTIONS)
   serialize_lit_param(SERIALIZED_LIT_PARAMS enable_exceptions False)
 endif()
diff --git a/libcxx/test/configs/cmake-bridge.cfg.in 
b/libcxx/test/configs/cmake-bridge.cfg.in
index 84b3270a8940a..78d0cb5a25748 100644
--- a/libcxx/test/configs/cmake-bridge.cfg.in
+++ b/libcxx/test/configs/cmake-bridge.cfg.in
@@ -23,8 +23,6 @@ config.recursiveExpansionLimit = 10
 config.test_exec_root = os.path.join('@CMAKE_BINARY_DIR@', 'test')
 
 # Add substitutions for bootstrapping the test suite configuration
-import shlex
-config.substitutions.append(('%{cxx}', shlex.quote('@CMAKE_CXX_COMPILER@')))
 config.substitutions.append(('%{libcxx-dir}', '@LIBCXX_SOURCE_DIR@'))
 config.substitutions.append(('%{include-dir}', 
'@LIBCXX_GENERATED_INCLUDE_DIR@'))
 config.substitutions.append(('%{target-include-dir}', 
'@LIBCXX_GENERATED_INCLUDE_TARGET_DIR@'))
diff --git a/libcxx/utils/libcxx/test/params.py 
b/libcxx/utils/libcxx/test/params.py
index c2d294e49f488..0370a2da0ac75 100644
--- a/libcxx/utils/libcxx/test/params.py
+++ b/libcxx/utils/libcxx/test/params.py
@@ -143,6 +143,14 @@ def getSuitableClangTidy(cfg):
 
 # fmt: off
 DEFAULT_PARAMETERS = [
+Parameter(
+name="compiler",
+type=str,
+help="The path of the compiler to use for testing.",
+actions=lambda cxx: [
+AddSubstitution("%{cxx}", cxx),
+],
+),
 Parameter(
 name="target_triple",
 type=str,
diff --git a/libcxxabi/test/CMakeLists.txt b/libcxxabi/test/CMakeLists.txt
index 586927189cf1d..cd908a3514cb2 100644
--- a/libcxxabi/test/CMakeLists.txt
+++ b/libcxxabi/test/CMakeLists.txt
@@ -24,6 +24,8 @@ endif()
 set(AUTO_GEN_COMMENT "## Autogenerated by libcxxabi configuration.\n# Do not 
edit!")
 set(SERIALIZED_LIT_PARAMS "# Lit parameters serialized here for llvm-lit to 
pick them up\n")
 
+serialize_lit_string_param(SERIALIZED_LIT_PARAMS compiler 
"${CMAKE_CXX_COMPILER}")
+
 if (NOT LIBCXXABI_ENABLE_EXCEPTIONS)
   serialize_lit_param(SERIALIZED_LIT_PARAMS enable_exceptions False)
 endif()
diff --git a/libcxxabi/test/configs/cmake-bridge.cfg.in 
b/libcxxabi/test/configs/cmake-bridge.cfg.in
index 1d0f51d37437b..3fefc6a7fdc88 100644
--- a/libcxxabi/test/configs/cmake-bridge.cfg.in
+++ b/libcxxabi/test/configs/cmake-bridge.cfg.in
@@ -26,7 +26,6 @@ config.test_exec_root = os.path.join('@CMAKE_BINARY_DIR@', 
'test')
 # TODO: This is a non-standard Lit attribute and we should have another way of 
accessing this.
 config.host_triple = '@LLVM_HOST_TRIPLE@'
 
-config.substitutions.append(('%{cxx}', '@CMAKE_CXX_COMPILER@'))
 config.substitutions.append(('%{libcxx}', '@LIBCXXABI_LIBCXX_PATH@'))
 config.substitutions.append(('%{include}', '@LIBCXXABI_SOURCE_DIR@/include'))
 config.substitutions.append(('%{cxx-include}', 
'@LIBCXXABI_HEADER_DIR@/include/c++/v1'))
diff --git a/libunwind/test/CMakeLists.txt b/libunwind/test/CMakeLists.txt
index 21dfbb0a84f0a..bd2e575f2a296 100644
--- a/libunwind/test/CMakeLists.txt
+++ b/libunwind/test/CMakeLists.txt
@@ -15,6 +15,8 @@ pythonize_bool(LIBUNWIND_USES_ARM_EHABI)
 set(AUTO_GEN_COMMENT "## Autogenerated by libunwind configuration.\n# Do not 
edit!")
 set(SERIALIZED_LIT_PARAMS "# Lit parameters serialized here for llvm-lit to 
pick them up\n")
 
+serialize_lit_string_param(SERIALIZED_LIT_PARAMS compiler 
"${CMAKE_CXX_COMPILER}")
+
 if (LIBUNWIND_EXECUTOR)
   message(DEPRECATION "LIBUNWIND_EXECUTOR is deprecated, please add 
executor=... to LIBUNWIND_TEST_PARAMS")
   serialize_lit_string_param(SERIALIZED_LIT_PARAMS executor 
"${LIBUNWIND_EXECUTOR}")
diff --git a/libunwind/test/configs/cmake-b

[clang] [clang-repl] Set up executor implicitly to account for init PTUs (PR #84758)

2024-05-28 Thread Vassil Vassilev via cfe-commits
Stefan =?utf-8?q?Gr=C3=A4nitz?= ,
Stefan =?utf-8?q?Gr=C3=A4nitz?= ,
Stefan =?utf-8?q?Gr=C3=A4nitz?= 
Message-ID:
In-Reply-To: 


vgvassilev wrote:

What do you mean?

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


[clang] [Clang] allow `` `@$ `` in raw string delimiters in C++26 (PR #93216)

2024-05-28 Thread via cfe-commits
https://github.com/cor3ntin updated 
https://github.com/llvm/llvm-project/pull/93216

>From 556c622275c630b74c0f9000c5c599ff665595e1 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Thu, 23 May 2024 18:45:58 +0200
Subject: [PATCH 1/2] [Clang] allow `` `@$ `` in raw string delimiters in C++26

And as an extension in older language modes.

Per https://eel.is/c++draft/lex.string#nt:d-char

Fixes #93130
---
 clang/docs/ReleaseNotes.rst   |  1 +
 clang/include/clang/Basic/CharInfo.h  | 15 +++---
 .../include/clang/Basic/DiagnosticLexKinds.td |  8 
 clang/lib/Basic/CharInfo.cpp  | 20 +--
 clang/lib/Lex/Lexer.cpp   | 11 +-
 clang/test/Lexer/cxx2c-raw-strings.cpp| 12 +++
 6 files changed, 49 insertions(+), 18 deletions(-)
 create mode 100644 clang/test/Lexer/cxx2c-raw-strings.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7bcdee96e213e..2e298cd9cdb82 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -771,6 +771,7 @@ Bug Fixes to C++ Support
   Fixes (#GH87210), (GH89541).
 - Clang no longer tries to check if an expression is immediate-escalating in 
an unevaluated context.
   Fixes (#GH91308).
+- Clang now allow ``@$``` in raw string literals. Fixes (#GH93130).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/Basic/CharInfo.h 
b/clang/include/clang/Basic/CharInfo.h
index d807955311828..4d90528f7992e 100644
--- a/clang/include/clang/Basic/CharInfo.h
+++ b/clang/include/clang/Basic/CharInfo.h
@@ -28,8 +28,7 @@ namespace charinfo {
 CHAR_LOWER= 0x0040,  // a-z
 CHAR_UNDER= 0x0080,  // _
 CHAR_PERIOD   = 0x0100,  // .
-CHAR_RAWDEL   = 0x0200,  // {}[]#<>%:;?*+-/^&|~!=,"'
-CHAR_PUNCT= 0x0400   // `$@()
+CHAR_PUNCT= 0x0200,  // {}[]#<>%:;?*+-/^&|~!=,"'`$@()
   };
 
   enum {
@@ -152,7 +151,8 @@ LLVM_READONLY inline bool isHexDigit(unsigned char c) {
 /// Note that '_' is both a punctuation character and an identifier character!
 LLVM_READONLY inline bool isPunctuation(unsigned char c) {
   using namespace charinfo;
-  return (InfoTable[c] & (CHAR_UNDER|CHAR_PERIOD|CHAR_RAWDEL|CHAR_PUNCT)) != 0;
+  return (InfoTable[c] &
+  (CHAR_UNDER | CHAR_PERIOD | CHAR_PUNCT | CHAR_PUNCT)) != 0;
 }
 
 /// Return true if this character is an ASCII printable character; that is, a
@@ -160,8 +160,8 @@ LLVM_READONLY inline bool isPunctuation(unsigned char c) {
 /// terminal.
 LLVM_READONLY inline bool isPrintable(unsigned char c) {
   using namespace charinfo;
-  return (InfoTable[c] & (CHAR_UPPER|CHAR_LOWER|CHAR_PERIOD|CHAR_PUNCT|
-  CHAR_DIGIT|CHAR_UNDER|CHAR_RAWDEL|CHAR_SPACE)) != 0;
+  return (InfoTable[c] & (CHAR_UPPER | CHAR_LOWER | CHAR_PERIOD | CHAR_PUNCT |
+  CHAR_DIGIT | CHAR_UNDER | CHAR_SPACE)) != 0;
 }
 
 /// Return true if this is the body character of a C preprocessing number,
@@ -175,8 +175,9 @@ LLVM_READONLY inline bool 
isPreprocessingNumberBody(unsigned char c) {
 /// Return true if this is the body character of a C++ raw string delimiter.
 LLVM_READONLY inline bool isRawStringDelimBody(unsigned char c) {
   using namespace charinfo;
-  return (InfoTable[c] & (CHAR_UPPER|CHAR_LOWER|CHAR_PERIOD|
-  CHAR_DIGIT|CHAR_UNDER|CHAR_RAWDEL)) != 0;
+  return (InfoTable[c] & (CHAR_UPPER | CHAR_LOWER | CHAR_PERIOD | CHAR_DIGIT |
+  CHAR_UNDER | CHAR_PUNCT)) != 0 &&
+ c != '(' && c != ')';
 }
 
 enum class EscapeChar {
diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index ad6bacfb118d4..8411842490c4e 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -111,6 +111,14 @@ def warn_cxx98_compat_raw_string_literal : Warning<
   "raw string literals are incompatible with C++98">,
   InGroup, DefaultIgnore;
 
+def warn_cxx26_compat_raw_string_literal_character_set : Warning<
+  "'%0'in a raw string literal delimiter is incompatible "
+  "with standards before C++2c">,
+  InGroup, DefaultIgnore;
+def ext_cxx26_raw_string_literal_character_set : Extension<
+  "'%0'in a raw string literal delimiter is a C++2c extension">,
+  InGroup, DefaultIgnore;
+
 def warn_multichar_character_literal : Warning<
   "multi-character character constant">, InGroup;
 def warn_four_char_character_literal : Warning<
diff --git a/clang/lib/Basic/CharInfo.cpp b/clang/lib/Basic/CharInfo.cpp
index d02054c9718f5..26d693b8e9b94 100644
--- a/clang/lib/Basic/CharInfo.cpp
+++ b/clang/lib/Basic/CharInfo.cpp
@@ -31,20 +31,20 @@ const uint16_t clang::charinfo::InfoTable[256] = {
   0   , 0   , 0   , 0   ,
   //32 SP 33  ! 34  " 35  #
   //36  $ 37  % 38  & 39  '
-  CHAR_SPACE  , CHAR_RAWDEL , CHAR_R

[clang] [llvm] Split fmv and extensions (PR #92882)

2024-05-28 Thread Alexandros Lamprineas via cfe-commits

@@ -13664,16 +13665,23 @@ QualType 
ASTContext::getCorrespondingSignedFixedPointType(QualType Ty) const {
   }
 }
 
+// Given a list of FMV features, add each of their backend features to the 
list.
+static void
+GetFMVBackendFeaturesFor(const llvm::SmallVector FMVFeatStrings,

labrinea wrote:

pass by reference?

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


[clang] [llvm] Split fmv and extensions (PR #92882)

2024-05-28 Thread Alexandros Lamprineas via cfe-commits
https://github.com/labrinea edited 
https://github.com/llvm/llvm-project/pull/92882
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Split fmv and extensions (PR #92882)

2024-05-28 Thread Alexandros Lamprineas via cfe-commits
https://github.com/labrinea edited 
https://github.com/llvm/llvm-project/pull/92882
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Adding taint analysis capability to unix.Malloc checker (PR #92420)

2024-05-28 Thread Daniel Krupp via cfe-commits
https://github.com/dkrupp updated 
https://github.com/llvm/llvm-project/pull/92420

>From 80767176cbe8e5717c5f42b113f305d81b635cb9 Mon Sep 17 00:00:00 2001
From: Daniel Krupp 
Date: Tue, 30 Apr 2024 15:20:52 +0200
Subject: [PATCH 1/4] [analyzer] Adding taint analysis capability to
 unix.Malloc checker

unix.Malloc checker will warn if a memory allocation function
(malloc, calloc, realloc, alloca) is called with a tainted
(attacker controlled) size parameter.
A large, maliciously set size value can trigger memory exhaustion.
To get this warning, the alpha.security.taint.TaintPropagation checker
also needs to be switched on.

The warning will only be emitted, if the analyzer cannot prove
that the size is below reasonable bounds (https://wiki.sei.cmu.edu/confluence/display/c/INT04-C.+Enforce+limits+on+integer+values+originating+from+tainted+sources>`_.
+
+You can silence this warning either by bound checking the ``size`` parameter, 
or
+by explicitly marking the ``size`` parameter as sanitized. See the
+:ref:`alpha-security-taint-TaintPropagation` checker for more details.
+
+.. code-block:: c
+
+  void t1(void) {
+size_t size;
+scanf("%zu", &size);
+int *p = malloc(size); // warn: malloc is called with a tainted 
(potentially attacker controlled) value
+free(p);
+  }
+
+  void t3(void) {
+size_t size;
+scanf("%zu", &size);
+if (1024 BT_MismatchedDealloc;
   mutable std::unique_ptr BT_OffsetFree[CK_NumCheckKinds];
   mutable std::unique_ptr BT_UseZerroAllocated[CK_NumCheckKinds];
+  mutable std::unique_ptr BT_TaintedAlloc[CK_NumCheckKinds];
 
 #define CHECK_FN(NAME) 
\
   void NAME(const CallEvent &Call, CheckerContext &C) const;
@@ -462,6 +464,13 @@ class MallocChecker
   };
 
   bool isMemCall(const CallEvent &Call) const;
+  void reportTaintBug(StringRef Msg, ProgramStateRef State, CheckerContext &C,
+  llvm::ArrayRef TaintedSyms,
+  AllocationFamily Family, const Expr *SizeEx) const;
+
+  void CheckTaintedness(CheckerContext &C, const CallEvent &Call,
+const SVal SizeSVal, ProgramStateRef State,
+AllocationFamily Family) const;
 
   // TODO: Remove mutable by moving the initializtaion to the registry 
function.
   mutable std::optional KernelZeroFlagVal;
@@ -521,9 +530,9 @@ class MallocChecker
   /// malloc leaves it undefined.
   /// \param [in] State The \c ProgramState right before allocation.
   /// \returns The ProgramState right after allocation.
-  [[nodiscard]] static ProgramStateRef
+  [[nodiscard]] ProgramStateRef
   MallocMemAux(CheckerContext &C, const CallEvent &Call, const Expr *SizeEx,
-   SVal Init, ProgramStateRef State, AllocationFamily Family);
+   SVal Init, ProgramStateRef State, AllocationFamily Family) 
const;
 
   /// Models memory allocation.
   ///
@@ -534,9 +543,10 @@ class MallocChecker
   /// malloc leaves it undefined.
   /// \param [in] State The \c ProgramState right before allocation.
   /// \returns The ProgramState right after allocation.
-  [[nodiscard]] static ProgramStateRef
-  MallocMemAux(CheckerContext &C, const CallEvent &Call, SVal Size, SVal Init,
-   ProgramStateRef State, AllocationFamily Family);
+  [[nodiscard]] ProgramStateRef MallocMemAux(CheckerContext &C,
+ const CallEvent &Call, SVal Size,
+ SVal Init, ProgramStateRef State,
+ AllocationFamily Family) const;
 
   // Check if this malloc() for special flags. At present that means M_ZERO or
   // __GFP_ZERO (in which case, treat it like calloc).
@@ -649,8 +659,9 @@ class MallocChecker
   /// \param [in] Call The expression that reallocated memory
   /// \param [in] State The \c ProgramState right before reallocation.
   /// \returns The ProgramState right after allocation.
-  [[nodiscard]] static ProgramStateRef
-  CallocMem(CheckerContext &C, const CallEvent &Call, ProgramStateRef State);
+  [[nodiscard]] ProgramStateRef CallocMem(CheckerContext &C,
+  const CallEvent &Call,
+  ProgramStateRef State) const;
 
   /// See if deallocation happens in a suspicious context. If so, escape the
   /// pointers that otherwise would have been deallocated and return true.
@@ -1779,7 +1790,7 @@ ProgramStateRef 
MallocChecker::MallocMemAux(CheckerContext &C,
 const CallEvent &Call,
 const Expr *SizeEx, SVal Init,
 ProgramStateRef State,
-AllocationFamily Family) {
+AllocationFamily Family) const {
   if (!State)
 return nullptr;
 
@@ -1787,10 +1798,71 @@ ProgramStateRef 
MallocChecker:

[clang] [Clang] Static and explicit object member functions with the same parameter-type-lists (PR #93430)

2024-05-28 Thread via cfe-commits
https://github.com/cor3ntin updated 
https://github.com/llvm/llvm-project/pull/93430

>From 131f515c1341122896ea3c9624751a634db06cb7 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Mon, 27 May 2024 01:16:06 +0200
Subject: [PATCH 1/2] [Clang] Static and explicit object member functions with
 the same parameter-type-lists

Implement wg21.link/P2797.

Because taking the address of an explicit object member function
results in a function pointer, a call expression where
the id-expression is an explicit object member is made to behave
consistently with that model.

This change forces clang to perform overload resolution
in the presence of an ixpression of the form `(&Foo::bar)(args...)`,
which we previously failed to do consistently.
---
 clang/docs/ReleaseNotes.rst   |  3 +
 clang/include/clang/AST/ExprCXX.h |  4 +
 clang/include/clang/Sema/Overload.h   |  4 +
 clang/lib/Sema/SemaExpr.cpp   | 27 ++-
 clang/lib/Sema/SemaOverload.cpp   | 74 ---
 clang/test/CXX/drs/cwg1xx.cpp |  8 +-
 clang/test/CXX/drs/cwg26xx.cpp| 26 +++
 clang/test/CXX/drs/cwg2771.cpp| 18 +
 clang/test/CodeGenCXX/cxx2b-deducing-this.cpp | 20 +
 clang/test/SemaCXX/cxx2b-deducing-this.cpp| 27 +++
 clang/www/cxx_dr_status.html  |  6 +-
 clang/www/cxx_status.html |  2 +-
 12 files changed, 197 insertions(+), 22 deletions(-)
 create mode 100644 clang/test/CXX/drs/cwg2771.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 825e91876ffce..0a945a9989b0d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -209,6 +209,9 @@ C++23 Feature Support
 - Added a ``__reference_converts_from_temporary`` builtin, completing the 
necessary compiler support for
   `P2255R2: Type trait to determine if a reference binds to a temporary 
`_.
 
+- Implemented `P2797R0: Static and explicit object member functions with the 
same parameter-type-lists `.
+  This completes the support for "deducing this".
+
 C++2c Feature Support
 ^
 
diff --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index dbf693611a7fa..557e9fd99c293 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -3027,6 +3027,7 @@ class OverloadExpr : public Expr {
   struct FindResult {
 OverloadExpr *Expression;
 bool IsAddressOfOperand;
+bool IsAddressOfOperandWithParen;
 bool HasFormOfMemberPointer;
   };
 
@@ -3039,6 +3040,7 @@ class OverloadExpr : public Expr {
 assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload));
 
 FindResult Result;
+bool HasParen = isa(E);
 
 E = E->IgnoreParens();
 if (isa(E)) {
@@ -3048,10 +3050,12 @@ class OverloadExpr : public Expr {
 
   Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier());
   Result.IsAddressOfOperand = true;
+  Result.IsAddressOfOperandWithParen = HasParen;
   Result.Expression = Ovl;
 } else {
   Result.HasFormOfMemberPointer = false;
   Result.IsAddressOfOperand = false;
+  Result.IsAddressOfOperandWithParen = false;
   Result.Expression = cast(E);
 }
 
diff --git a/clang/include/clang/Sema/Overload.h 
b/clang/include/clang/Sema/Overload.h
index 76311b00d2fc5..64cdd6cdf043d 100644
--- a/clang/include/clang/Sema/Overload.h
+++ b/clang/include/clang/Sema/Overload.h
@@ -899,6 +899,8 @@ class Sema;
 /// object argument.
 bool IgnoreObjectArgument : 1;
 
+bool TookAddressOfOverload : 1;
+
 /// True if the candidate was found using ADL.
 CallExpr::ADLCallKind IsADLCandidate : 1;
 
@@ -999,6 +1001,8 @@ class Sema;
   /// Initialization of an object of class type by constructor,
   /// using either a parenthesized or braced list of arguments.
   CSK_InitByConstructor,
+
+  CSK_AddressOfOverloadSet,
 };
 
 /// Information about operator rewrites to consider when adding operator
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 410f80ae864a1..15496f3323b02 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -5813,6 +5813,24 @@ static TypoCorrection TryTypoCorrectionForCall(Sema &S, 
Expr *Fn,
   return TypoCorrection();
 }
 
+static bool isParenthetizedAndQualifiedAddressOfExpr(Expr *Fn) {
+  if (!isa(Fn))
+return false;
+
+  Fn = Fn->IgnoreParens();
+  auto *UO = dyn_cast(Fn);
+  if (!UO)
+return false;
+  assert(cast(Fn)->getOpcode() == UO_AddrOf);
+  if (auto *DRE = dyn_cast(UO->getSubExpr()->IgnoreParens())) {
+return DRE->hasQualifier();
+  }
+  if (auto *OVL = dyn_cast(UO->getSubExpr()->IgnoreParens())) {
+return OVL->getQualifier();
+  }
+  return false;
+}
+
 /// ConvertArgumentsForCall - Converts the arguments specified in
 /// Args/NumArgs to the parameter types of

[clang] [clang] Implement a bitwise_copyable builtin type trait. (PR #86512)

2024-05-28 Thread Haojian Wu via cfe-commits
https://github.com/hokein updated 
https://github.com/llvm/llvm-project/pull/86512

>From 49747cde60dc8a1f4ed4ddcee020f71c88f35287 Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Mon, 25 Mar 2024 15:10:51 +0100
Subject: [PATCH] [clang] Implement a bitwise_copyable builtin type trait.

This patch implements a `__is_bitwise_copyable` builtin in clang.

The bitwise copyable types act as the trivially copyable types, but
they support a wider range of types (e.g. classes with virtual methods) --
their underlying types can be safely copied by `memcopy` or `memmove`,
the clang compiler guarantees that both source and destination objects
have the same *object* representations after the copy operation, and the
lifetime of the destination object implicitly starts.

A particular use case of this builtin is to clone an object via memcopy
(without running the constructor):

```
Message* clone(const Message* src, char* buffer, int size) {
  if constexpr __is_bitwise_copyable(Message) {
// bitwise copy to buffer
__builtin_memcpy(buffer, src, size);
// using __builtin_launder to prevent miscompile for 
-fstrict-vtable-pointers.
return __builtin_launder(reinterpret_cast(buffer));
  }
  // Fallback the operator new, which calls the constructor to start the 
lifetime.
  return new(buffer) Message(src);
}
```

Note that the definition of bitwise copyable is not tied to the Rule Of
Five, so users of this builtin must guarantee that program semantic constraints
are satisfied, e.g. no double resource deallocations.

Context: https://discourse.llvm.org/t/extension-for-creating-objects-via-memcpy
---
 clang/docs/LanguageExtensions.rst | 28 +++
 clang/include/clang/AST/Type.h|  8 ++
 clang/include/clang/Basic/TokenKinds.def  |  2 ++
 clang/lib/AST/Type.cpp| 11 
 clang/lib/Sema/SemaExprCXX.cpp|  3 ++
 ...builtin-is-bitwise-cloneable-fsanitize.cpp | 20 +
 .../SemaCXX/builtin-is-bitwise-cloneable.cpp  |  6 
 7 files changed, 78 insertions(+)
 create mode 100644 
clang/test/SemaCXX/builtin-is-bitwise-cloneable-fsanitize.cpp
 create mode 100644 clang/test/SemaCXX/builtin-is-bitwise-cloneable.cpp

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 46f99d0bbdd06..0168411d04f50 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -4016,6 +4016,34 @@ Note that the `size` argument must be a compile time 
constant.
 
 Note that this intrinsic cannot yet be called in a ``constexpr`` context.
 
+``__is_bitwise_cloneable``
+--
+
+A type trait is used to check whether a type can be safely copied by memcpy.
+
+**Syntax**:
+
+.. code-block:: c++
+
+  bool __is_bitwise_cloneable(Type)
+
+**Description**:
+
+This trait is similar to `std::is_trivially_copyable`, but additionally allows
+to have user-defined constructors, virtual functions and virtual bases. It is 
up
+to the user code to guarantee that a bitwise copy results in non-broken object
+and that the lifetime of an object is properly started.
+
+Objects of bitwise cloneable types can be bitwise copied by memcpy/memmove. The
+Clang compiler warrants that this behavior is well defined, and won't be
+broken by compiler optimizations.
+
+After the copy, the lifetime of the new object isn't started yet (unless the
+type is trivially copyable). Users must ensure its lifetime is started to avoid
+undefined behavior.
+
+This builtin can be used in constant expressions.
+
 Atomic Min/Max builtins with memory ordering
 
 
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 263b632df23ce..d79b942c599cf 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -1120,6 +1120,14 @@ class QualType {
   /// Return true if this is a trivially copyable type (C++0x [basic.types]p9)
   bool isTriviallyCopyableType(const ASTContext &Context) const;
 
+  /// Return true if the type is safe to bitwise copy by memcpy.
+  ///
+  /// This is an extension in clang: bitwise clonable types act as trivially
+  /// copyable types, their underlying bytes can be safely copied by memcpy or
+  /// memmove. Clang guarantees that the destination has the same **object**
+  /// representations after the copy.
+  bool isBitwiseCloneableType(const ASTContext &Context) const;
+
   /// Return true if this is a trivially copyable type
   bool isTriviallyCopyConstructibleType(const ASTContext &Context) const;
 
diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index b5a0e9df9f7ae..9c4b17465e18a 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -542,6 +542,8 @@ TYPE_TRAIT_2(__reference_converts_from_temporary, 
ReferenceConvertsFromTemporary
 // is not exposed to users.
 TYPE_TRAIT_2(/*EmptySpellingName*/, I

[clang] [llvm] [AArch64][SME] Add intrinsics for multi-vector BFCLAMP (PR #93532)

2024-05-28 Thread via cfe-commits
https://github.com/Lukacma updated 
https://github.com/llvm/llvm-project/pull/93532

>From fe692284cd248e372302671e094eb9950edb5ee5 Mon Sep 17 00:00:00 2001
From: Marian Lukac 
Date: Wed, 10 Apr 2024 10:20:03 +
Subject: [PATCH 1/4] [AArch64][SME] Add intrinsics for multi-vector BFCLAMP

---
 clang/include/clang/Basic/arm_sve.td  |  5 ++
 .../aarch64-sme2-intrinsics/acle_sme2_clamp.c | 72 +--
 llvm/include/llvm/IR/IntrinsicsAArch64.td |  2 +
 .../Target/AArch64/AArch64ISelDAGToDAG.cpp|  6 ++
 .../AArch64/sve2p1-intrinsics-bfclamp.ll  | 26 ++-
 5 files changed, 106 insertions(+), 5 deletions(-)

diff --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index 6da30e08e7521..63ca495a1bc9f 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -2148,6 +2148,11 @@ let TargetGuard = "sme2" in {
   def SVSCLAMP_X4 : SInst<"svclamp[_single_{d}_x4]",  "44dd",   "csil", 
MergeNone, "aarch64_sve_sclamp_single_x4",  [IsStreaming], []>;
   def SVUCLAMP_X4 : SInst<"svclamp[_single_{d}_x4]",  "44dd",   "UcUsUiUl", 
MergeNone, "aarch64_sve_uclamp_single_x4",  [IsStreaming], []>;
   def SVFCLAMP_X4 : SInst<"svclamp[_single_{d}_x4]",  "44dd",   "hfd",  
MergeNone, "aarch64_sve_fclamp_single_x4",  [IsStreaming], []>;
+
+  let TargetGuard = "b16b16"in {
+def SVBFCLAMP_X2 : SInst<"svclamp[_single_{d}_x2]",  "22dd",   "b",  
MergeNone, "aarch64_sve_bfclamp_single_x2",  [IsStreaming], []>;
+def SVBFCLAMP_X4 : SInst<"svclamp[_single_{d}_x4]",  "44dd",   "b",  
MergeNone, "aarch64_sve_bfclamp_single_x4",  [IsStreaming], []>;
+  }
 }
 
 let TargetGuard = "sme2" in {
diff --git a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c
index 257cb59525018..1dd5aeee35fe7 100644
--- a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_clamp.c
@@ -1,12 +1,12 @@
 // 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 \
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 
-target-feature +b16b16 \
 // RUN:  -S -Werror -emit-llvm -disable-O0-optnone -o - %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s
-// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme2 \
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme2 -target-feature +b16b16 \
 // RUN:  -S -Werror -emit-llvm -disable-O0-optnone -o - %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 \
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 
-target-feature +b16b16 \
 // RUN:  -S -Werror -emit-llvm -disable-O0-optnone -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 \
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme2 -target-feature +b16b16 \
 // RUN:  -S -Werror -emit-llvm -disable-O0-optnone -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 \
 // RUN:  -S -disable-O0-optnone -Werror -Wall -o /dev/null %s
@@ -745,3 +745,67 @@ svfloat32x4_t test_svclamp_single_f32_x4(svfloat32x4_t 
op1, svfloat32_t op2, svf
 svfloat64x4_t test_svclamp_single_f64_x4(svfloat64x4_t op1, svfloat64_t op2, 
svfloat64_t op3) __arm_streaming {
   return SVE_ACLE_FUNC(svclamp, _single_f64_x4, , )(op1, op2, op3);
 }
+
+// CHECK-LABEL: @test_svclamp_single_bf16_x2(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv16bf16( [[OP1:%.*]], i64 
0)
+// CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv16bf16( [[OP1]], i64 8)
+// CHECK-NEXT:[[TMP2:%.*]] = tail call { ,  } @llvm.aarch64.sve.bfclamp.single.x2.nxv8bf16( [[TMP0]],  [[TMP1]],  
[[OP2:%.*]],  [[OP3:%.*]])
+// CHECK-NEXT:[[TMP3:%.*]] = extractvalue { ,  } [[TMP2]], 0
+// CHECK-NEXT:[[TMP4:%.*]] = tail call  
@llvm.vector.insert.nxv16bf16.nxv8bf16( poison,  [[TMP3]], i64 0)
+// CHECK-NEXT:[[TMP5:%.*]] = extractvalue { ,  } [[TMP2]], 1
+// CHECK-NEXT:[[TMP6:%.*]] = tail call  
@llvm.vector.insert.nxv16bf16.nxv8bf16( [[TMP4]],  [[TMP5]], i64 8)
+// CHECK-NEXT:ret  [[TMP6]]
+//
+// CPP-CHECK-LABEL: 
@_Z27test_svclamp_single_bf16_x214svbfloat16x2_tu14__SVBfloat16_tS0_(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv8bf16.nxv16bf16( [[OP1:%.*]], i64 
0)
+// CPP-CHECK-N

[clang] [llvm] Split fmv and extensions (PR #92882)

2024-05-28 Thread Alexandros Lamprineas via cfe-commits

@@ -1062,35 +1064,41 @@ bool AArch64TargetInfo::initFeatureMap(
 llvm::AArch64::getExtensionFeatures(Exts, CPUFeats);

labrinea wrote:

I am wondering if calling ExtensionSet::addCPUDefaults here would be 
preferable. It's not NFC. I saw a test failing because the attribute string for 
cortex-a710 would contain +v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8a,+v9a whereas 
before it didn't. That was `clang/test/CodeGen/aarch64-targetattr.c` for 
`__attribute__((target("cpu=cortex-a710")))`.

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


[clang] [llvm] Split fmv and extensions (PR #92882)

2024-05-28 Thread Alexandros Lamprineas via cfe-commits
https://github.com/labrinea edited 
https://github.com/llvm/llvm-project/pull/92882
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [SME] Add intrinsics for FCVT(wid.) and FCVTL (PR #93202)

2024-05-28 Thread via cfe-commits
https://github.com/Lukacma updated 
https://github.com/llvm/llvm-project/pull/93202

>From a1750b2b5658f8ced700bbf010019703fc52f126 Mon Sep 17 00:00:00 2001
From: Caroline Concatto 
Date: Mon, 15 Apr 2024 13:31:00 +
Subject: [PATCH 1/7] [LLVM][AARCH64]Replace +sme2p1+smef16f16 by +smef16f16

According to the latest ISA Spec release[1] all instructions under:
 HasSME2p1 and HasSMEF16F16
should now only require:
HasSMEF16F16

[1]https://developer.arm.com
---
 llvm/test/MC/AArch64/SME2p1/fadd.s | 8 
 llvm/test/MC/AArch64/SME2p1/fmla-diagnostics.s | 2 +-
 llvm/test/MC/AArch64/SME2p1/fmls-diagnostics.s | 2 +-
 llvm/test/MC/AArch64/SME2p1/fsub.s | 8 
 4 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/llvm/test/MC/AArch64/SME2p1/fadd.s 
b/llvm/test/MC/AArch64/SME2p1/fadd.s
index bdb769093c838..ec4f27e021a00 100644
--- a/llvm/test/MC/AArch64/SME2p1/fadd.s
+++ b/llvm/test/MC/AArch64/SME2p1/fadd.s
@@ -1,16 +1,24 @@
 // RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sme-f16f16 < %s \
 // RUN:| FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
 // RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sme-f8f16 < %s \
+// RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sme-f16f16 < %s \
+// RUN:| FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
+// RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sme-f8f16 < %s \
 // RUN:| FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
 // RUN: not llvm-mc -triple=aarch64 -show-encoding < %s 2>&1 \
 // RUN:| FileCheck %s --check-prefix=CHECK-ERROR
 // RUN: llvm-mc -triple=aarch64 -filetype=obj -mattr=+sme-f16f16 < %s \
 // RUN:| llvm-objdump -d --mattr=+sme-f16f16 - | FileCheck %s 
--check-prefix=CHECK-INST
 // RUN: llvm-mc -triple=aarch64 -filetype=obj -mattr=+sme-f16f16 < %s \
+// RUN: llvm-mc -triple=aarch64 -filetype=obj -mattr=+sme-f16f16 < %s \
+// RUN:| llvm-objdump -d --mattr=+sme-f16f16 - | FileCheck %s 
--check-prefix=CHECK-INST
+// RUN: llvm-mc -triple=aarch64 -filetype=obj -mattr=+sme-f16f16 < %s \
 // RUN:| llvm-objdump -d --mattr=-sme2p1 - | FileCheck %s 
--check-prefix=CHECK-UNKNOWN
 // RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sme-f16f16 < %s \
+// RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sme-f16f16 < %s \
 // RUN:| sed '/.text/d' | sed 's/.*encoding: //g' \
 // RUN:| llvm-mc -triple=aarch64 -mattr=+sme-f16f16 -disassemble 
-show-encoding \
+// RUN:| llvm-mc -triple=aarch64 -mattr=+sme-f16f16 -disassemble 
-show-encoding \
 // RUN:| FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
 
 faddza.h[w8, 0, vgx2], {z0.h, z1.h}  // 1101-10100100-00011100-
diff --git a/llvm/test/MC/AArch64/SME2p1/fmla-diagnostics.s 
b/llvm/test/MC/AArch64/SME2p1/fmla-diagnostics.s
index 2f0dccb57c907..c31b54fc05dea 100644
--- a/llvm/test/MC/AArch64/SME2p1/fmla-diagnostics.s
+++ b/llvm/test/MC/AArch64/SME2p1/fmla-diagnostics.s
@@ -66,7 +66,7 @@ fmla za.h[w8, 8, vgx2], {z12.h-z13.h}, {z8.h-z9.h}
 // Invalid Register Suffix
 
 fmla za.d[w8, 7, vgx2], {z12.h-z13.h}, {z8.h-z9.h}
-// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid matrix operand, expected 
suffix .s
+// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid matrix operand, expected 
suffix .h
 // CHECK-NEXT: fmla za.d[w8, 7, vgx2], {z12.h-z13.h}, {z8.h-z9.h}
 // CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
 
diff --git a/llvm/test/MC/AArch64/SME2p1/fmls-diagnostics.s 
b/llvm/test/MC/AArch64/SME2p1/fmls-diagnostics.s
index 3ff09321e3436..2deb18186eafc 100644
--- a/llvm/test/MC/AArch64/SME2p1/fmls-diagnostics.s
+++ b/llvm/test/MC/AArch64/SME2p1/fmls-diagnostics.s
@@ -66,7 +66,7 @@ fmls za.h[w8, 8, vgx2], {z12.h-z13.h}, {z8.h-z9.h}
 // Invalid Register Suffix
 
 fmls za.d[w8, 7, vgx2], {z12.h-z13.h}, {z8.h-z9.h}
-// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid matrix operand, expected 
suffix .s
+// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid matrix operand, expected 
suffix .h
 // CHECK-NEXT: fmls za.d[w8, 7, vgx2], {z12.h-z13.h}, {z8.h-z9.h}
 // CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
 
diff --git a/llvm/test/MC/AArch64/SME2p1/fsub.s 
b/llvm/test/MC/AArch64/SME2p1/fsub.s
index 66410008eb11d..e42a819e0d415 100644
--- a/llvm/test/MC/AArch64/SME2p1/fsub.s
+++ b/llvm/test/MC/AArch64/SME2p1/fsub.s
@@ -1,16 +1,24 @@
 // RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sme-f16f16 < %s \
 // RUN:| FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
 // RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sme-f8f16 < %s \
+// RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sme-f16f16 < %s \
+// RUN:| FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
+// RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sme-f8f16 < %s \
 // RUN:| FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
 // RUN: not llvm-mc -triple=aarch64 -show-encoding < %s 2>&1 \
 // RUN:| FileCheck %s --check-prefix=CHECK-ERROR
 // 

[clang] [clang/www/get_started.html] Use newer `cmake` syntax (PR #93503)

2024-05-28 Thread Vlad Serebrennikov via cfe-commits

@@ -67,15 +67,13 @@ On Unix-like Systems
   Build LLVM and Clang:
   
 cd llvm-project
-mkdir build (in-tree build is not supported)
-cd build
 This builds both LLVM and Clang in release mode. Alternatively, if
 you need a debug build, switch Release to Debug. See
 https://llvm.org/docs/CMake.html#frequently-used-cmake-variables";>frequently
 used cmake variables
 for more options.
 
-cmake -DLLVM_ENABLE_PROJECTS=clang -DCMAKE_BUILD_TYPE=Release -G 
"Unix Makefiles" ../llvm

Endilll wrote:

I don't necessarily agree that `-S` and `-B` are newer or better than what our 
documentation currently says. `-G "Unix Makefiles"` is clearly outdated, 
though, in the presence of `ninja`.

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


[clang] [llvm] [AArch64][SME] Add intrinsics for multi-vector BFCLAMP (PR #93532)

2024-05-28 Thread via cfe-commits
Lukacma wrote:

This pull request reapplies  https://github.com/llvm/llvm-project/pull/88251 
with fixed test

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


[clang] [Clang] allow `` `@$ `` in raw string delimiters in C++26 (PR #93216)

2024-05-28 Thread Aaron Ballman via cfe-commits
https://github.com/AaronBallman edited 
https://github.com/llvm/llvm-project/pull/93216
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] allow `` `@$ `` in raw string delimiters in C++26 (PR #93216)

2024-05-28 Thread Aaron Ballman via cfe-commits
https://github.com/AaronBallman approved this pull request.

LGTM, thank you!

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


[clang] 24a12a9 - [clang] Diagnose problematic diagnostic messages (#93229)

2024-05-28 Thread via cfe-commits
Author: Aaron Ballman
Date: 2024-05-28T09:22:55-04:00
New Revision: 24a12a9c85b1ec08ff597f43e3414271d8439a97

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

LOG: [clang] Diagnose problematic diagnostic messages (#93229)

Clang has some unwritten rules about diagnostic wording regarding things
like punctuation and capitalization. This patch documents those rules
and adds some tablegen support for checking diagnostics follow the
rules.

Specifically: tablegen now checks that a diagnostic does not start with
a capital letter or end with punctuation, except for the usual
exceptions like proper nouns or ending with a question.

Now that the code base is clean of such issues, the diagnostics are
emitted as an error rather than a warning to ensure that failure to
follow these rules is either addressed by an author, or a new exception
is added to the checking logic.

Added: 
clang/test/TableGen/wording-errors.td

Modified: 
clang/docs/InternalsManual.rst
clang/test/TableGen/deferred-diag.td
clang/test/TableGen/text-substitution.td
clang/utils/TableGen/ClangDiagnosticsEmitter.cpp

Removed: 




diff  --git a/clang/docs/InternalsManual.rst b/clang/docs/InternalsManual.rst
index b3e2b870ae5f9..3d21e37784b36 100644
--- a/clang/docs/InternalsManual.rst
+++ b/clang/docs/InternalsManual.rst
@@ -123,6 +123,44 @@ severe that error recovery won't be able to recover 
sensibly from them (thus
 spewing a ton of bogus errors).  One example of this class of error are failure
 to ``#include`` a file.
 
+Diagnostic Wording
+^^
+The wording used for a diagnostic is critical because it is the only way for a
+user to know how to correct their code. Use the following suggestions when
+wording a diagnostic.
+
+* Diagnostics in Clang do not start with a capital letter and do not end with
+  punctuation.
+
+* This does not apply to proper nouns like ``Clang`` or ``OpenMP``, to
+  acronyms like ``GCC`` or ``ARC``, or to language standards like ``C23``
+  or ``C++17``.
+* A trailing question mark is allowed. e.g., ``unknown identifier %0; did
+  you mean %1?``.
+
+* Appropriately capitalize proper nouns like ``Clang``, ``OpenCL``, ``GCC``,
+  ``Objective-C``, etc and language standard versions like ``C11`` or 
``C++11``.
+* The wording should be succinct. If necessary, use a semicolon to combine
+  sentence fragments instead of using complete sentences. e.g., prefer wording
+  like ``'%0' is deprecated; it will be removed in a future release of Clang``
+  over wording like ``'%0' is deprecated. It will be removed in a future 
release
+  of Clang``.
+* The wording should be actionable and avoid using standards terms or grammar
+  productions that a new user would not be familiar with. e.g., prefer wording
+  like ``missing semicolon`` over wording like ``syntax error`` (which is not
+  actionable) or ``expected unqualified-id`` (which uses standards 
terminology).
+* The wording should clearly explain what is wrong with the code rather than
+  restating what the code does. e.g., prefer wording like ``type %0 requires a
+  value in the range %1 to %2`` over wording like ``%0 is invalid``.
+* The wording should have enough contextual information to help the user
+  identify the issue in a complex expression. e.g., prefer wording like
+  ``both sides of the %0 binary operator are identical`` over wording like
+  ``identical operands to binary operator``.
+* Use single quotes to denote syntactic constructs or command line arguments
+  named in a diagnostic message. e.g., prefer wording like ``'this' pointer
+  cannot be null in well-defined C++ code`` over wording like ``this pointer
+  cannot be null in well-defined C++ code``.
+
 The Format String
 ^
 

diff  --git a/clang/test/TableGen/deferred-diag.td 
b/clang/test/TableGen/deferred-diag.td
index c1906d4a9e45e..d7e8e694c7b3e 100644
--- a/clang/test/TableGen/deferred-diag.td
+++ b/clang/test/TableGen/deferred-diag.td
@@ -4,24 +4,24 @@ include "DiagnosticBase.inc"
 
 // Test usage of Deferrable and NonDeferrable in diagnostics.
 
-def test_default : Error<"This error is non-deferrable by default">;
+def test_default : Error<"this error is non-deferrable by default">;
 // CHECK-DAG: DIAG(test_default, {{.*}}SFINAE_SubstitutionFailure, false, 
true, true, false, 0)
 
-def test_deferrable : Error<"This error is deferrable">, Deferrable;
+def test_deferrable : Error<"this error is deferrable">, Deferrable;
 // CHECK-DAG: DIAG(test_deferrable, {{.*}} SFINAE_SubstitutionFailure, false, 
true, true, true, 0)
 
-def test_non_deferrable : Error<"This error is non-deferrable">, NonDeferrable;
+def test_non_deferrable : Error<"this error is non-deferrable">, NonDeferrable;
 // CHECK-DAG: DIAG(test_non_deferrab

[clang] [clang] Diagnose problematic diagnostic messages (PR #93229)

2024-05-28 Thread Aaron Ballman via cfe-commits
https://github.com/AaronBallman closed 
https://github.com/llvm/llvm-project/pull/93229
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] [libcxxabi] [libunwind] [runtimes] Reintroduce a way to select the compiler used for the test suite (PR #93542)

2024-05-28 Thread via cfe-commits
https://github.com/EricWF approved this pull request.

Thanks for doing this.

I know from trying this yesterday than some of the configuration options 
surrounding `clang-tidy` don't tolerate this (in particular when switching from 
clang->gcc), but I'll send a separate change to address that.

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


[clang] [Clang][Sema] Tweak tryCaptureVariable for unevaluated lambdas (PR #93206)

2024-05-28 Thread Erich Keane via cfe-commits

@@ -1576,7 +1576,10 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
   TrailingReturnTypeLoc, &DS),
   std::move(Attributes), DeclEndLoc);
 
-Actions.ActOnLambdaClosureQualifiers(Intro, MutableLoc);
+// We have called ActOnLambdaClosureQualifiers for parentheses-less cases

erichkeane wrote:

I think I'd be ok with this as a followup.  But @cor3ntin is the one who knows 
the most about lambda stuff (particularly parsing, etc), so I'd like to see him 
approve this.

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


[clang] [Clang][HIP] Suppress availability diagnostics for mismatched host/device overloads (PR #93546)

2024-05-28 Thread Fabian Ritter via cfe-commits
https://github.com/ritter-x2a created 
https://github.com/llvm/llvm-project/pull/93546

Outside of function bodies, the resolution of host/device overloads for 
functions in HIP/CUDA operates as if in a host-device context. This means that 
the device overload is used in the device compilation phase and the host 
overload is used in the host compilation phase.

Therefore, the following code would cause a deprecation warning during host 
compilation, even though val is only used as part of a device function:

```C++
__attribute__((host, deprecated)) constexpr int val(void) {return 1;}
__attribute__((device)) constexpr int val(void) {return 1;}
__attribute__((device)) std::enable_if<(val() > 0), int>::type fun(void) {
return 42;
}
```

As only the available device overload is used during device compilation, where 
code for fun is actually generated, this diagnostic is spurious.

This patch suppresses availability diagnostics in such situations: When an 
unavailable host function is used in a device context during host compilation 
or when an unavailable device function is used in a host context during device 
compilation.

This change is necessary to avoid spurious warnings with #91478, e.g., in the 
rocPRIM library.

>From d88250fc1493ed8ab2780678deb15620b1897620 Mon Sep 17 00:00:00 2001
From: Fabian Ritter 
Date: Tue, 28 May 2024 07:45:52 -0400
Subject: [PATCH] [Clang][HIP] Suppress availability diagnostics for mismatched
 host/device overloads

Outside of function bodies, the resolution of host/device overloads for
functions in HIP/CUDA operates as if in a host-device context. This means that
the device overload is used in the device compilation phase and the host
overload is used in the host compilation phase.

Therefore, the following code would cause a deprecation warning during host
compilation, even though val is only used as part of a device function:

__attribute__((host, deprecated)) constexpr int val(void) {return 1;}
__attribute__((device)) constexpr int val(void) {return 1;}
__attribute__((device)) std::enable_if<(val() > 0), int>::type fun(void) {
return 42;
}

As only the available device overload is used during device compilation, where
code for fun is actually generated, this diagnostic is spurious.

This patch suppresses availability diagnostics in such situations: When an
unavailable host function is used in a device context during host compilation
or when an unavailable device function is used in a host context during device
compilation.
---
 clang/lib/Sema/SemaAvailability.cpp   |  53 +++
 ...lability-warnings-mismatched-attributes.cu | 149 ++
 2 files changed, 202 insertions(+)
 create mode 100644 
clang/test/SemaCUDA/suppress-availability-warnings-mismatched-attributes.cu

diff --git a/clang/lib/Sema/SemaAvailability.cpp 
b/clang/lib/Sema/SemaAvailability.cpp
index 22f5a2f663477..984789489098a 100644
--- a/clang/lib/Sema/SemaAvailability.cpp
+++ b/clang/lib/Sema/SemaAvailability.cpp
@@ -20,6 +20,7 @@
 #include "clang/Sema/DelayedDiagnostic.h"
 #include "clang/Sema/ScopeInfo.h"
 #include "clang/Sema/Sema.h"
+#include "clang/Sema/SemaCUDA.h"
 #include "clang/Sema/SemaObjC.h"
 #include "llvm/ADT/StringRef.h"
 #include 
@@ -156,6 +157,58 @@ static bool ShouldDiagnoseAvailabilityInContext(
 }
   }
 
+  if (S.getLangOpts().CUDA || S.getLangOpts().HIP) {
+// In CUDA/HIP, do not diagnose uses of unavailable host or device function
+// overloads when they occur in the context of a Decl with an explicitly
+// given opposite target.
+// We encounter this if the OffendingDecl is used outside of a function
+// body, e.g., in template arguments for a function's return or parameter
+// types. In this case, overloads of the called function are resolved as if
+// in a host-device context, i.e., the device overload is chosen in the
+// device compilation phase and the host overload in the host compilation
+// phase. As code is only generated for the variant with matching targets,
+// an availabiliy diagnostic for the variant with non-matching targets 
would
+// be spurious.
+
+if (auto *OffendingFunDecl = llvm::dyn_cast(OffendingDecl)) {
+  Decl *ActualCtx = Ctx;
+  if (auto *FTD = llvm::dyn_cast(Ctx)) {
+// Attributes of template Decls are only on the templated Decl
+ActualCtx = FTD->getTemplatedDecl();
+  }
+  if (auto *CtxFun = llvm::dyn_cast(ActualCtx)) {
+auto TargetIs = [&S](const FunctionDecl *FD, CUDAFunctionTarget FT) {
+  return S.CUDA().IdentifyTarget(FD, /* IgnoreImplicitHDAttr */ true) 
==
+ FT;
+};
+
+bool CtxIsHost = TargetIs(CtxFun, CUDAFunctionTarget::Host);
+bool CtxIsDevice = TargetIs(CtxFun, CUDAFunctionTarget::Device);
+
+bool OffendingDeclIsHost =
+TargetIs(OffendingFunDecl, CUDAFunctionTarget::Host);
+bool OffendingDeclIsDevice =
+TargetIs(OffendingFunDecl, CUDAFunct

[clang] [Clang][HIP] Suppress availability diagnostics for mismatched host/device overloads (PR #93546)

2024-05-28 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Fabian Ritter (ritter-x2a)


Changes

Outside of function bodies, the resolution of host/device overloads for 
functions in HIP/CUDA operates as if in a host-device context. This means that 
the device overload is used in the device compilation phase and the host 
overload is used in the host compilation phase.

Therefore, the following code would cause a deprecation warning during host 
compilation, even though val is only used as part of a device function:

```C++
__attribute__((host, deprecated)) constexpr int val(void) {return 1;}
__attribute__((device)) constexpr int val(void) {return 1;}
__attribute__((device)) std::enable_if<(val() > 0), int>::type 
fun(void) {
return 42;
}
```

As only the available device overload is used during device compilation, where 
code for fun is actually generated, this diagnostic is spurious.

This patch suppresses availability diagnostics in such situations: When an 
unavailable host function is used in a device context during host compilation 
or when an unavailable device function is used in a host context during device 
compilation.

This change is necessary to avoid spurious warnings with #91478, e.g., 
in the rocPRIM library.

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaAvailability.cpp (+53) 
- (added) 
clang/test/SemaCUDA/suppress-availability-warnings-mismatched-attributes.cu 
(+149) 


``diff
diff --git a/clang/lib/Sema/SemaAvailability.cpp 
b/clang/lib/Sema/SemaAvailability.cpp
index 22f5a2f663477..984789489098a 100644
--- a/clang/lib/Sema/SemaAvailability.cpp
+++ b/clang/lib/Sema/SemaAvailability.cpp
@@ -20,6 +20,7 @@
 #include "clang/Sema/DelayedDiagnostic.h"
 #include "clang/Sema/ScopeInfo.h"
 #include "clang/Sema/Sema.h"
+#include "clang/Sema/SemaCUDA.h"
 #include "clang/Sema/SemaObjC.h"
 #include "llvm/ADT/StringRef.h"
 #include 
@@ -156,6 +157,58 @@ static bool ShouldDiagnoseAvailabilityInContext(
 }
   }
 
+  if (S.getLangOpts().CUDA || S.getLangOpts().HIP) {
+// In CUDA/HIP, do not diagnose uses of unavailable host or device function
+// overloads when they occur in the context of a Decl with an explicitly
+// given opposite target.
+// We encounter this if the OffendingDecl is used outside of a function
+// body, e.g., in template arguments for a function's return or parameter
+// types. In this case, overloads of the called function are resolved as if
+// in a host-device context, i.e., the device overload is chosen in the
+// device compilation phase and the host overload in the host compilation
+// phase. As code is only generated for the variant with matching targets,
+// an availabiliy diagnostic for the variant with non-matching targets 
would
+// be spurious.
+
+if (auto *OffendingFunDecl = llvm::dyn_cast(OffendingDecl)) {
+  Decl *ActualCtx = Ctx;
+  if (auto *FTD = llvm::dyn_cast(Ctx)) {
+// Attributes of template Decls are only on the templated Decl
+ActualCtx = FTD->getTemplatedDecl();
+  }
+  if (auto *CtxFun = llvm::dyn_cast(ActualCtx)) {
+auto TargetIs = [&S](const FunctionDecl *FD, CUDAFunctionTarget FT) {
+  return S.CUDA().IdentifyTarget(FD, /* IgnoreImplicitHDAttr */ true) 
==
+ FT;
+};
+
+bool CtxIsHost = TargetIs(CtxFun, CUDAFunctionTarget::Host);
+bool CtxIsDevice = TargetIs(CtxFun, CUDAFunctionTarget::Device);
+
+bool OffendingDeclIsHost =
+TargetIs(OffendingFunDecl, CUDAFunctionTarget::Host);
+bool OffendingDeclIsDevice =
+TargetIs(OffendingFunDecl, CUDAFunctionTarget::Device);
+
+// There is a way to call a device function from host code (and vice
+// versa, analogously) that passes semantic analysis: As constexprs,
+// when there is no host overload. In this case, a diagnostic is
+// necessary. Characteristic for this situation is that the device
+// function will also be used in a host context during host 
compilation.
+// Therefore, only suppress diagnostics if a host function is used in a
+// device context during host compilation or a device function is used
+// in a host context during device compilation.
+bool CompilingForDevice = S.getLangOpts().CUDAIsDevice;
+bool CompilingForHost = !CompilingForDevice;
+
+if ((OffendingDeclIsHost && CtxIsDevice && CompilingForHost) ||
+(OffendingDeclIsDevice && CtxIsHost && CompilingForDevice)) {
+  return false;
+}
+  }
+}
+  }
+
   // Checks if we should emit the availability diagnostic in the context of C.
   auto CheckContext = [&](const Decl *C) {
 if (K == AR_NotYetIntroduced) {
diff --git 
a/clang/test/SemaCUDA/suppress-availability-warnings-mismatched-attributes.cu 
b/clang/test/SemaCUDA/suppress-availability-warnings-mismatched-att

[clang] 8995ccc - [Clang] Add support for [[msvc::noinline]] attribute. (#91720)

2024-05-28 Thread via cfe-commits
Author: Xu Zhang
Date: 2024-05-28T06:29:31-07:00
New Revision: 8995ccc4460ed8a90dcc9bd023743a8f59458f50

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

LOG: [Clang] Add support for [[msvc::noinline]] attribute. (#91720)

Fixes #90941.
Add support for ``[[msvc::noinline]]`` attribute, which is actually an
alias of ``[[clang::noinline]]``.

Added: 


Modified: 
clang/include/clang/Basic/Attr.td
clang/lib/Sema/SemaStmtAttr.cpp
clang/test/CodeGen/attr-noinline.cpp
clang/test/Sema/attr-noinline.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index e59cdd369..ef9df1e9d8b4a 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2025,9 +2025,12 @@ def Convergent : InheritableAttr {
 def NoInline : DeclOrStmtAttr {
   let Spellings = [CustomKeyword<"__noinline__">, GCC<"noinline">,
CXX11<"clang", "noinline">, C23<"clang", "noinline">,
+   CXX11<"msvc", "noinline">, C23<"msvc", "noinline">,
Declspec<"noinline">];
-  let Accessors = [Accessor<"isClangNoInline", [CXX11<"clang", "noinline">,
-C23<"clang", "noinline">]>];
+  let Accessors = [Accessor<"isStmtNoInline", [CXX11<"clang", "noinline">,
+   C23<"clang", "noinline">,
+   CXX11<"msvc", "noinline">,
+   C23<"msvc", "noinline">]>];
   let Documentation = [NoInlineDocs];
   let Subjects = SubjectList<[Function, Stmt], WarnDiag,
  "functions and statements">;

diff  --git a/clang/lib/Sema/SemaStmtAttr.cpp b/clang/lib/Sema/SemaStmtAttr.cpp
index 8735d96c84079..82373fe96a824 100644
--- a/clang/lib/Sema/SemaStmtAttr.cpp
+++ b/clang/lib/Sema/SemaStmtAttr.cpp
@@ -285,7 +285,7 @@ bool Sema::CheckAlwaysInlineAttr(const Stmt *OrigSt, const 
Stmt *CurSt,
 static Attr *handleNoInlineAttr(Sema &S, Stmt *St, const ParsedAttr &A,
 SourceRange Range) {
   NoInlineAttr NIA(S.Context, A);
-  if (!NIA.isClangNoInline()) {
+  if (!NIA.isStmtNoInline()) {
 S.Diag(St->getBeginLoc(), diag::warn_function_attribute_ignored_in_stmt)
 << "[[clang::noinline]]";
 return nullptr;

diff  --git a/clang/test/CodeGen/attr-noinline.cpp 
b/clang/test/CodeGen/attr-noinline.cpp
index f0588cfecf463..c1fb9941b5251 100644
--- a/clang/test/CodeGen/attr-noinline.cpp
+++ b/clang/test/CodeGen/attr-noinline.cpp
@@ -9,6 +9,7 @@ static int baz(int x) {
 }
 
 [[clang::noinline]] bool noi() { }
+[[msvc::noinline]] bool ms_noi() { return true; }
 
 void foo(int i) {
   [[clang::noinline]] bar();
@@ -39,6 +40,31 @@ void foo(int i) {
 // CHECK: call noundef zeroext i1 @_Z3barv()
 }
 
+void ms_noi_check(int i) {
+  [[msvc::noinline]] bar();
+// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR:[0-9]+]]
+  [[msvc::noinline]] i = baz(i);
+// CHECK: call noundef i32 @_ZL3bazi({{.*}}) #[[NOINLINEATTR]]
+  [[msvc::noinline]] (i = 4, bar());
+// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR]]
+  [[msvc::noinline]] (void)(bar());
+// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR]]
+  [[msvc::noinline]] f(bar(), bar());
+// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR]]
+// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR]]
+// CHECK: call void @_Z1fbb({{.*}}) #[[NOINLINEATTR]]
+  [[msvc::noinline]] [] { bar(); bar(); }(); // noinline only applies to the 
anonymous function call
+// CHECK: call void @"_ZZ12ms_noi_checkiENK3$_0clEv"(ptr {{[^,]*}} %ref.tmp) 
#[[NOINLINEATTR]]
+  [[msvc::noinline]] for (bar(); bar(); bar()) {}
+// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR]]
+// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR]]
+// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR]]
+  [[msvc::noinline]] ms_noi();
+// CHECK: call noundef zeroext i1 @_Z6ms_noiv()
+  ms_noi();
+// CHECK: call noundef zeroext i1 @_Z6ms_noiv()
+}
+
 struct S {
   friend bool operator==(const S &LHS, const S &RHS);
 };
@@ -50,6 +76,12 @@ void func(const S &s1, const S &s2) {
   bool b;
   [[clang::noinline]] b = s1 == s2;
 // CHECK: call noundef zeroext i1 @_ZeqRK1SS1_({{.*}}) #[[NOINLINEATTR]]
+
+  [[msvc::noinline]]g(s1 == s2);
+// CHECK: call noundef zeroext i1 @_ZeqRK1SS1_({{.*}}) #[[NOINLINEATTR]]
+// CHECK: call void @_Z1gb({{.*}}) #[[NOINLINEATTR]]
+  [[msvc::noinline]] b = s1 == s2;
+// CHECK: call noundef zeroext i1 @_ZeqRK1SS1_({{.*}}) #[[NOINLINEATTR]]
 }
 
 // CHECK: attributes #[[NOINLINEATTR]] = { noinline }

diff  --git a/clang/test/Sema/attr-noinline.cpp 
b/clang/test/Sema/attr-noinline.cpp
index bd6505b9f

[clang] [Clang] Add support for [[msvc::noinline]] attribute. (PR #91720)

2024-05-28 Thread Erich Keane via cfe-commits
https://github.com/erichkeane closed 
https://github.com/llvm/llvm-project/pull/91720
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Adding taint analysis capability to unix.Malloc checker (PR #92420)

2024-05-28 Thread Daniel Krupp via cfe-commits
https://github.com/dkrupp edited https://github.com/llvm/llvm-project/pull/92420
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 2ace7bd - [Clang] allow `` `@$ `` in raw string delimiters in C++26 (#93216)

2024-05-28 Thread via cfe-commits
Author: cor3ntin
Date: 2024-05-28T15:38:02+02:00
New Revision: 2ace7bdcfe640c69bd4dcf508d39485e0ef7ea06

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

LOG: [Clang] allow `` `@$ `` in raw string delimiters in C++26 (#93216)

And as an extension in older language modes.

Per https://eel.is/c++draft/lex.string#nt:d-char

Fixes #93130

Added: 
clang/test/Lexer/cxx2c-raw-strings.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/CharInfo.h
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/lib/Basic/CharInfo.cpp
clang/lib/Lex/Lexer.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 182f8b5824258..6b746cda53c71 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -802,6 +802,7 @@ Bug Fixes to C++ Support
 - Fixed a regression introduced in Clang 18 causing a static function 
overloading a non-static function
   with the same parameters not to be diagnosed. (Fixes #GH93456).
 - Clang now diagnoses unexpanded parameter packs in attributes. (Fixes 
#GH93269).
+- Clang now allows ``@$``` in raw string literals. Fixes (#GH93130).
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/include/clang/Basic/CharInfo.h 
b/clang/include/clang/Basic/CharInfo.h
index d807955311828..4d90528f7992e 100644
--- a/clang/include/clang/Basic/CharInfo.h
+++ b/clang/include/clang/Basic/CharInfo.h
@@ -28,8 +28,7 @@ namespace charinfo {
 CHAR_LOWER= 0x0040,  // a-z
 CHAR_UNDER= 0x0080,  // _
 CHAR_PERIOD   = 0x0100,  // .
-CHAR_RAWDEL   = 0x0200,  // {}[]#<>%:;?*+-/^&|~!=,"'
-CHAR_PUNCT= 0x0400   // `$@()
+CHAR_PUNCT= 0x0200,  // {}[]#<>%:;?*+-/^&|~!=,"'`$@()
   };
 
   enum {
@@ -152,7 +151,8 @@ LLVM_READONLY inline bool isHexDigit(unsigned char c) {
 /// Note that '_' is both a punctuation character and an identifier character!
 LLVM_READONLY inline bool isPunctuation(unsigned char c) {
   using namespace charinfo;
-  return (InfoTable[c] & (CHAR_UNDER|CHAR_PERIOD|CHAR_RAWDEL|CHAR_PUNCT)) != 0;
+  return (InfoTable[c] &
+  (CHAR_UNDER | CHAR_PERIOD | CHAR_PUNCT | CHAR_PUNCT)) != 0;
 }
 
 /// Return true if this character is an ASCII printable character; that is, a
@@ -160,8 +160,8 @@ LLVM_READONLY inline bool isPunctuation(unsigned char c) {
 /// terminal.
 LLVM_READONLY inline bool isPrintable(unsigned char c) {
   using namespace charinfo;
-  return (InfoTable[c] & (CHAR_UPPER|CHAR_LOWER|CHAR_PERIOD|CHAR_PUNCT|
-  CHAR_DIGIT|CHAR_UNDER|CHAR_RAWDEL|CHAR_SPACE)) != 0;
+  return (InfoTable[c] & (CHAR_UPPER | CHAR_LOWER | CHAR_PERIOD | CHAR_PUNCT |
+  CHAR_DIGIT | CHAR_UNDER | CHAR_SPACE)) != 0;
 }
 
 /// Return true if this is the body character of a C preprocessing number,
@@ -175,8 +175,9 @@ LLVM_READONLY inline bool 
isPreprocessingNumberBody(unsigned char c) {
 /// Return true if this is the body character of a C++ raw string delimiter.
 LLVM_READONLY inline bool isRawStringDelimBody(unsigned char c) {
   using namespace charinfo;
-  return (InfoTable[c] & (CHAR_UPPER|CHAR_LOWER|CHAR_PERIOD|
-  CHAR_DIGIT|CHAR_UNDER|CHAR_RAWDEL)) != 0;
+  return (InfoTable[c] & (CHAR_UPPER | CHAR_LOWER | CHAR_PERIOD | CHAR_DIGIT |
+  CHAR_UNDER | CHAR_PUNCT)) != 0 &&
+ c != '(' && c != ')';
 }
 
 enum class EscapeChar {

diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index 5a4551a96ca4e..25fbfe83fa2bc 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -111,6 +111,14 @@ def warn_cxx98_compat_raw_string_literal : Warning<
   "raw string literals are incompatible with C++98">,
   InGroup, DefaultIgnore;
 
+def warn_cxx26_compat_raw_string_literal_character_set : Warning<
+  " '%0' in a raw string literal delimiter is incompatible "
+  "with standards before C++2c">,
+  InGroup, DefaultIgnore;
+def ext_cxx26_raw_string_literal_character_set : Extension<
+  " '%0' in a raw string literal delimiter is a C++2c extension">,
+  InGroup, DefaultIgnore;
+
 def warn_multichar_character_literal : Warning<
   "multi-character character constant">, InGroup;
 def warn_four_char_character_literal : Warning<

diff  --git a/clang/lib/Basic/CharInfo.cpp b/clang/lib/Basic/CharInfo.cpp
index d02054c9718f5..26d693b8e9b94 100644
--- a/clang/lib/Basic/CharInfo.cpp
+++ b/clang/lib/Basic/CharInfo.cpp
@@ -31,20 +31,20 @@ const uint16_t clang::charinfo::InfoTable[256] = {
   0   , 0   , 0   , 0   ,
   //32 SP 33  ! 34  " 35  #
   //36  $ 37  % 38  & 39  '
-  

[clang] [Clang] allow `` `@$ `` in raw string delimiters in C++26 (PR #93216)

2024-05-28 Thread via cfe-commits
https://github.com/cor3ntin closed 
https://github.com/llvm/llvm-project/pull/93216
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [C] Disallow declarations where a statement is required (PR #92908)

2024-05-28 Thread Aaron Ballman via cfe-commits
https://github.com/AaronBallman updated 
https://github.com/llvm/llvm-project/pull/92908

>From 219dae02c3235c17bc4568496a7df9763d798e2a Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Mon, 20 May 2024 13:40:28 -0400
Subject: [PATCH 1/4] [C] Fix declaration parsing

8bd06d5b65845e5e01dd899a2deb773580460b89 removed the notion of parsed
statement contexts that track whether a declaration is valid for C or
not. This resurrects the concept, because C still does not allow a
declaration as a substatement.
---
 clang/include/clang/Parse/Parser.h | 9 ++---
 clang/lib/Parse/ParseStmt.cpp  | 5 -
 clang/test/C/C99/block-scopes.c| 3 ++-
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 5f04664141d29..5e455b16fb8c0 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -467,15 +467,18 @@ class Parser : public CodeCompletionHandler {
 
   /// Flags describing a context in which we're parsing a statement.
   enum class ParsedStmtContext {
+/// This context permits declarations in language modes where declarations
+/// are not statements.
+AllowDeclarationsInC = 0x1,
 /// This context permits standalone OpenMP directives.
-AllowStandaloneOpenMPDirectives = 0x1,
+AllowStandaloneOpenMPDirectives = 0x2,
 /// This context is at the top level of a GNU statement expression.
-InStmtExpr = 0x2,
+InStmtExpr = 0x4,
 
 /// The context of a regular substatement.
 SubStmt = 0,
 /// The context of a compound-statement.
-Compound = AllowStandaloneOpenMPDirectives,
+Compound = AllowDeclarationsInC | AllowStandaloneOpenMPDirectives,
 
 LLVM_MARK_AS_BITMASK_ENUM(InStmtExpr)
   };
diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp
index b0af04451166c..57b9fb10a1e08 100644
--- a/clang/lib/Parse/ParseStmt.cpp
+++ b/clang/lib/Parse/ParseStmt.cpp
@@ -239,7 +239,10 @@ StmtResult 
Parser::ParseStatementOrDeclarationAfterAttributes(
 auto IsStmtAttr = [](ParsedAttr &Attr) { return Attr.isStmtAttr(); };
 bool AllAttrsAreStmtAttrs = llvm::all_of(CXX11Attrs, IsStmtAttr) &&
 llvm::all_of(GNUAttrs, IsStmtAttr);
-if (((GNUAttributeLoc.isValid() && !(HaveAttrs && AllAttrsAreStmtAttrs)) ||
+if ((getLangOpts().CPlusPlus || getLangOpts().MicrosoftExt ||
+ (StmtCtx & ParsedStmtContext::AllowDeclarationsInC) !=
+ ParsedStmtContext()) &&
+((GNUAttributeLoc.isValid() && !(HaveAttrs && AllAttrsAreStmtAttrs)) ||
  isDeclarationStatement())) {
   SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
   DeclGroupPtrTy Decl;
diff --git a/clang/test/C/C99/block-scopes.c b/clang/test/C/C99/block-scopes.c
index 589047df3e52b..116e5d922593e 100644
--- a/clang/test/C/C99/block-scopes.c
+++ b/clang/test/C/C99/block-scopes.c
@@ -18,8 +18,9 @@
 
 enum {a, b};
 void different(void) {
-  if (sizeof(enum {b, a}) != sizeof(int))
+  if (sizeof(enum {b, a}) != sizeof(int)) {
 _Static_assert(a == 1, "");
+  }
   /* In C89, the 'b' found here would have been from the enum declaration in
* the controlling expression of the selection statement, not from the global
* declaration. In C99 and later, that enumeration is scoped to the 'if'

>From c67502ddeb0c1db5c71fe1eb115250bd238c0d9d Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Tue, 21 May 2024 08:34:01 -0400
Subject: [PATCH 2/4] Update OpenACC test for slight behavioral change

---
 clang/test/SemaOpenACC/parallel-loc-and-stmt.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/test/SemaOpenACC/parallel-loc-and-stmt.c 
b/clang/test/SemaOpenACC/parallel-loc-and-stmt.c
index ba29f6da8ba25..bbcdd823483a5 100644
--- a/clang/test/SemaOpenACC/parallel-loc-and-stmt.c
+++ b/clang/test/SemaOpenACC/parallel-loc-and-stmt.c
@@ -33,9 +33,11 @@ int foo3;
 
 void func() {
   // FIXME: Should we disallow this on declarations, or consider this to be on
-  // the initialization?
+  // the initialization? This is currently rejected in C because
+  // Parser::ParseOpenACCDirectiveStmt() calls ParseStatement() and passes the
+  // statement context as "SubStmt" which does not allow for a declaration in 
C.
 #pragma acc parallel
-  int foo;
+  int foo; // expected-error {{expected expression}}
 
 #pragma acc parallel
   {

>From 6e2e9c015ba5c60204f3ef71ebd63db8d986835a Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Tue, 21 May 2024 08:40:46 -0400
Subject: [PATCH 3/4] Add test coverage for changes

---
 clang/test/Parser/decls.c | 39 +++
 1 file changed, 39 insertions(+)
 create mode 100644 clang/test/Parser/decls.c

diff --git a/clang/test/Parser/decls.c b/clang/test/Parser/decls.c
new file mode 100644
index 0..39ef05bf4bd99
--- /dev/null
+++ b/clang/test/Parser/decls.c
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -p

[clang] [llvm] [IR] Avoid creating icmp/fcmp constant expressions (PR #92885)

2024-05-28 Thread Nikita Popov via cfe-commits
nikic wrote:

Okay, I managed to get access to a MacOS machine (turns out the GCC compile 
farm has one!) and figured out what the problem is. Basically, the presence of 
the constant expression meant that we previously always fell back to JIT and 
now we use the IR interpreter instead, which fails to handle the weak function 
symbol correctly. I put up a candidate fix at 
https://github.com/llvm/llvm-project/pull/93548.

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


[clang] [z/OS] Set the default arch for z/OS to be arch10 (PR #89854)

2024-05-28 Thread Sean Perry via cfe-commits
https://github.com/perry-ca updated 
https://github.com/llvm/llvm-project/pull/89854

>From 85da4a229ddeeb6c86ecfb0ba19ac921494a2b40 Mon Sep 17 00:00:00 2001
From: Sean Perry 
Date: Tue, 23 Apr 2024 20:16:15 -0500
Subject: [PATCH 1/2] Set the default arch for z/OS to be arch10

---
 clang/CMakeLists.txt |  2 ++
 clang/include/clang/Config/config.h.cmake|  3 +++
 clang/lib/Basic/Targets/SystemZ.h|  7 +++
 clang/lib/Driver/ToolChains/Arch/SystemZ.cpp |  5 -
 clang/lib/Driver/ToolChains/Arch/SystemZ.h   |  3 ++-
 clang/lib/Driver/ToolChains/CommonArgs.cpp   |  2 +-
 clang/lib/Driver/ToolChains/Gnu.cpp  |  3 ++-
 clang/test/Preprocessor/predefined-arch-macros.c | 16 
 8 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index f092766fa19f0..f06fbec1d02f9 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -270,6 +270,8 @@ set(CLANG_DEFAULT_OPENMP_RUNTIME "libomp" CACHE STRING
 
 set(CLANG_SYSTEMZ_DEFAULT_ARCH "z10" CACHE STRING "SystemZ Default Arch")
 
+set(CLANG_SYSTEMZ_ZOS_DEFAULT_ARCH "zEC12" CACHE STRING "SystemZ z/OS Default 
Arch")
+
 set(CLANG_VENDOR ${PACKAGE_VENDOR} CACHE STRING
   "Vendor-specific text for showing with version information.")
 
diff --git a/clang/include/clang/Config/config.h.cmake 
b/clang/include/clang/Config/config.h.cmake
index 27ed69e21562b..004c5c95c00cf 100644
--- a/clang/include/clang/Config/config.h.cmake
+++ b/clang/include/clang/Config/config.h.cmake
@@ -32,6 +32,9 @@
 /* Default architecture for SystemZ. */
 #define CLANG_SYSTEMZ_DEFAULT_ARCH "${CLANG_SYSTEMZ_DEFAULT_ARCH}"
 
+/* Default architecture for SystemZ for z/OS. */
+#define CLANG_SYSTEMZ_ZOS_DEFAULT_ARCH "${CLANG_SYSTEMZ_ZOS_DEFAULT_ARCH}"
+
 /* Multilib basename for libdir. */
 #define CLANG_INSTALL_LIBDIR_BASENAME "${CLANG_INSTALL_LIBDIR_BASENAME}"
 
diff --git a/clang/lib/Basic/Targets/SystemZ.h 
b/clang/lib/Basic/Targets/SystemZ.h
index 8e302acd51b8a..45fb7e447b642 100644
--- a/clang/lib/Basic/Targets/SystemZ.h
+++ b/clang/lib/Basic/Targets/SystemZ.h
@@ -24,7 +24,6 @@ namespace targets {
 class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public TargetInfo {
 
   static const char *const GCCRegNames[];
-  std::string CPU;
   int ISARevision;
   bool HasTransactionalExecution;
   bool HasVector;
@@ -33,7 +32,8 @@ class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public 
TargetInfo {
 
 public:
   SystemZTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
-  : TargetInfo(Triple), CPU("z10"), ISARevision(8),
+  : TargetInfo(Triple),
+ISARevision(getISARevision(Triple.isOSzOS() ? "zEC12" : "z10")),
 HasTransactionalExecution(false), HasVector(false), SoftFloat(false),
 UnalignedSymbols(false) {
 IntMaxType = SignedLong;
@@ -140,8 +140,7 @@ class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public 
TargetInfo {
   }
 
   bool setCPU(const std::string &Name) override {
-CPU = Name;
-ISARevision = getISARevision(CPU);
+ISARevision = getISARevision(Name);
 return ISARevision != -1;
   }
 
diff --git a/clang/lib/Driver/ToolChains/Arch/SystemZ.cpp 
b/clang/lib/Driver/ToolChains/Arch/SystemZ.cpp
index 2213f431eb811..7baeffc00053a 100644
--- a/clang/lib/Driver/ToolChains/Arch/SystemZ.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/SystemZ.cpp
@@ -34,7 +34,8 @@ systemz::FloatABI systemz::getSystemZFloatABI(const Driver &D,
   return ABI;
 }
 
-std::string systemz::getSystemZTargetCPU(const ArgList &Args) {
+std::string systemz::getSystemZTargetCPU(const Driver &, const ArgList &Args,
+ const llvm::Triple &T) {
   if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_march_EQ)) {
 llvm::StringRef CPUName = A->getValue();
 
@@ -48,6 +49,8 @@ std::string systemz::getSystemZTargetCPU(const ArgList &Args) 
{
 
 return std::string(CPUName);
   }
+  if (T.isOSzOS())
+return CLANG_SYSTEMZ_ZOS_DEFAULT_ARCH;
   return CLANG_SYSTEMZ_DEFAULT_ARCH;
 }
 
diff --git a/clang/lib/Driver/ToolChains/Arch/SystemZ.h 
b/clang/lib/Driver/ToolChains/Arch/SystemZ.h
index 1e42b68a8f3c2..438dab8765bc3 100644
--- a/clang/lib/Driver/ToolChains/Arch/SystemZ.h
+++ b/clang/lib/Driver/ToolChains/Arch/SystemZ.h
@@ -27,7 +27,8 @@ enum class FloatABI {
 
 FloatABI getSystemZFloatABI(const Driver &D, const llvm::opt::ArgList &Args);
 
-std::string getSystemZTargetCPU(const llvm::opt::ArgList &Args);
+std::string getSystemZTargetCPU(const Driver &D, const llvm::opt::ArgList 
&Args,
+const llvm::Triple &T);
 
 void getSystemZTargetFeatures(const Driver &D, const llvm::opt::ArgList &Args,
   std::vector &Features);
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index b65b96db16bd7..73f5abfaafcba 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Dr

[clang] [C] Disallow declarations where a statement is required (PR #92908)

2024-05-28 Thread Aaron Ballman via cfe-commits
https://github.com/AaronBallman updated 
https://github.com/llvm/llvm-project/pull/92908

>From 219dae02c3235c17bc4568496a7df9763d798e2a Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Mon, 20 May 2024 13:40:28 -0400
Subject: [PATCH 1/5] [C] Fix declaration parsing

8bd06d5b65845e5e01dd899a2deb773580460b89 removed the notion of parsed
statement contexts that track whether a declaration is valid for C or
not. This resurrects the concept, because C still does not allow a
declaration as a substatement.
---
 clang/include/clang/Parse/Parser.h | 9 ++---
 clang/lib/Parse/ParseStmt.cpp  | 5 -
 clang/test/C/C99/block-scopes.c| 3 ++-
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 5f04664141d29..5e455b16fb8c0 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -467,15 +467,18 @@ class Parser : public CodeCompletionHandler {
 
   /// Flags describing a context in which we're parsing a statement.
   enum class ParsedStmtContext {
+/// This context permits declarations in language modes where declarations
+/// are not statements.
+AllowDeclarationsInC = 0x1,
 /// This context permits standalone OpenMP directives.
-AllowStandaloneOpenMPDirectives = 0x1,
+AllowStandaloneOpenMPDirectives = 0x2,
 /// This context is at the top level of a GNU statement expression.
-InStmtExpr = 0x2,
+InStmtExpr = 0x4,
 
 /// The context of a regular substatement.
 SubStmt = 0,
 /// The context of a compound-statement.
-Compound = AllowStandaloneOpenMPDirectives,
+Compound = AllowDeclarationsInC | AllowStandaloneOpenMPDirectives,
 
 LLVM_MARK_AS_BITMASK_ENUM(InStmtExpr)
   };
diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp
index b0af04451166c..57b9fb10a1e08 100644
--- a/clang/lib/Parse/ParseStmt.cpp
+++ b/clang/lib/Parse/ParseStmt.cpp
@@ -239,7 +239,10 @@ StmtResult 
Parser::ParseStatementOrDeclarationAfterAttributes(
 auto IsStmtAttr = [](ParsedAttr &Attr) { return Attr.isStmtAttr(); };
 bool AllAttrsAreStmtAttrs = llvm::all_of(CXX11Attrs, IsStmtAttr) &&
 llvm::all_of(GNUAttrs, IsStmtAttr);
-if (((GNUAttributeLoc.isValid() && !(HaveAttrs && AllAttrsAreStmtAttrs)) ||
+if ((getLangOpts().CPlusPlus || getLangOpts().MicrosoftExt ||
+ (StmtCtx & ParsedStmtContext::AllowDeclarationsInC) !=
+ ParsedStmtContext()) &&
+((GNUAttributeLoc.isValid() && !(HaveAttrs && AllAttrsAreStmtAttrs)) ||
  isDeclarationStatement())) {
   SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
   DeclGroupPtrTy Decl;
diff --git a/clang/test/C/C99/block-scopes.c b/clang/test/C/C99/block-scopes.c
index 589047df3e52b..116e5d922593e 100644
--- a/clang/test/C/C99/block-scopes.c
+++ b/clang/test/C/C99/block-scopes.c
@@ -18,8 +18,9 @@
 
 enum {a, b};
 void different(void) {
-  if (sizeof(enum {b, a}) != sizeof(int))
+  if (sizeof(enum {b, a}) != sizeof(int)) {
 _Static_assert(a == 1, "");
+  }
   /* In C89, the 'b' found here would have been from the enum declaration in
* the controlling expression of the selection statement, not from the global
* declaration. In C99 and later, that enumeration is scoped to the 'if'

>From c67502ddeb0c1db5c71fe1eb115250bd238c0d9d Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Tue, 21 May 2024 08:34:01 -0400
Subject: [PATCH 2/5] Update OpenACC test for slight behavioral change

---
 clang/test/SemaOpenACC/parallel-loc-and-stmt.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/test/SemaOpenACC/parallel-loc-and-stmt.c 
b/clang/test/SemaOpenACC/parallel-loc-and-stmt.c
index ba29f6da8ba25..bbcdd823483a5 100644
--- a/clang/test/SemaOpenACC/parallel-loc-and-stmt.c
+++ b/clang/test/SemaOpenACC/parallel-loc-and-stmt.c
@@ -33,9 +33,11 @@ int foo3;
 
 void func() {
   // FIXME: Should we disallow this on declarations, or consider this to be on
-  // the initialization?
+  // the initialization? This is currently rejected in C because
+  // Parser::ParseOpenACCDirectiveStmt() calls ParseStatement() and passes the
+  // statement context as "SubStmt" which does not allow for a declaration in 
C.
 #pragma acc parallel
-  int foo;
+  int foo; // expected-error {{expected expression}}
 
 #pragma acc parallel
   {

>From 6e2e9c015ba5c60204f3ef71ebd63db8d986835a Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Tue, 21 May 2024 08:40:46 -0400
Subject: [PATCH 3/5] Add test coverage for changes

---
 clang/test/Parser/decls.c | 39 +++
 1 file changed, 39 insertions(+)
 create mode 100644 clang/test/Parser/decls.c

diff --git a/clang/test/Parser/decls.c b/clang/test/Parser/decls.c
new file mode 100644
index 0..39ef05bf4bd99
--- /dev/null
+++ b/clang/test/Parser/decls.c
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -p

[clang] [C] Disallow declarations where a statement is required (PR #92908)

2024-05-28 Thread Aaron Ballman via cfe-commits

@@ -239,7 +239,10 @@ StmtResult 
Parser::ParseStatementOrDeclarationAfterAttributes(
 auto IsStmtAttr = [](ParsedAttr &Attr) { return Attr.isStmtAttr(); };
 bool AllAttrsAreStmtAttrs = llvm::all_of(CXX11Attrs, IsStmtAttr) &&
 llvm::all_of(GNUAttrs, IsStmtAttr);
-if (((GNUAttributeLoc.isValid() && !(HaveAttrs && AllAttrsAreStmtAttrs)) ||
+if ((getLangOpts().CPlusPlus || getLangOpts().MicrosoftExt ||
+ (StmtCtx & ParsedStmtContext::AllowDeclarationsInC) !=
+ ParsedStmtContext()) &&
+((GNUAttributeLoc.isValid() && !(HaveAttrs && AllAttrsAreStmtAttrs)) ||

AaronBallman wrote:

I've added one, let me know if you're happy with it.

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


[clang] [z/OS] Set the default arch for z/OS to be arch10 (PR #89854)

2024-05-28 Thread Dimitri John Ledkov via cfe-commits
xnox wrote:

@fhe

> > > @MaskRay Got it.
> > > The problem with that solution is that if you use --target you won't get 
> > > the correct arch. This would be a problem for any cross compilation. For 
> > > example, say you cross compile from zLinux (which wouldn't have the 
> > > config file), the arch would be arch8. And if you cross compiled from 
> > > z/OS (with the config file) to zLinux then the default arch would be 
> > > arch10. Both of these would be incorrect.
> > > We also use the config files for installation specific information. It is 
> > > common for users to have their own config files. If we require that the 
> > > option be in the config file then we would be creating a very error prone 
> > > situation.
> > > We need to be able to change the arch default based on the target triple.
> > 
> > 
> > Sorry for the late reply. Such driver defaults via cmake variable would 
> > make testing brittle. Users expect that `check-clang` pass regardless of 
> > the cmake variable setting. If a test changes behavior due to different 
> > `-march=`, there are a few choices:
> > 
> > * add a `REQUIRES: zos-new-default-march` directive
> > * hard code a `-march=`
> > 
> > Neither is immediately noticeable. In the past clang/test/Driver has had 
> > many such tests that require fixup. We have tried removing some unnecessary 
> > `CLANG_DEFAULT_*`.
> 
> I just realized that https://reviews.llvm.org/D75914 added 
> `CLANG_SYSTEMZ_DEFAULT_ARCH` for Ubuntu. @xnox @uweigand
> 
> I think we want to avoid such CMake options/clang `config.h`
> 
> As an alternative, if the clang executable is at `/tmp/Rel/bin/clang`, you 
> can add `/tmp/Rel/bin/s390x-unknown-linux-gnu.cfg` with content `-march=z13`.
> 
> Once we drop `CLANG_SYSTEMZ_DEFAULT_ARCH`, the `config.h` include will not be 
> needed.

I don't understand your proposal. In Ubuntu we need to set built-in default 
arch value, to a higher one than upstream has it at, for all builds without any 
toolchain configs. Such that any builds with any toolchain configs by default 
target a higher arch setting.

arch10 is way too old and slow.

and z13 might not be enough either for latest devel distributions, i.e. next 
development ubuntu release may be bumping further above z13.

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


[clang] [clang] Enable C++17 relaxed template template argument matching by default (PR #89807)

2024-05-28 Thread via cfe-commits
eaeltsin wrote:

@mizvekov - can you please take a look at https://godbolt.org/z/ahro3vnPd ?

This is what I ended up reducing yet another `xtensor` thing that failed with 
too deep recursive template instantiation with relaxed argument matching and 
compiled okay without relaxed argument matching.

The reduced example fails somewhat differently, but it complains on `implicit 
instantiation of undefined template` _with_ relaxed argument matching enabled 
and compiles OK without...


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


[clang] [llvm] Split fmv and extensions (PR #92882)

2024-05-28 Thread Tomas Matheson via cfe-commits
https://github.com/tmatheson-arm updated 
https://github.com/llvm/llvm-project/pull/92882

>From 76ccb775de5103dde3b59b838ba3f71be367418d Mon Sep 17 00:00:00 2001
From: Tomas Matheson 
Date: Tue, 21 May 2024 09:36:48 +0100
Subject: [PATCH] Separate FMV and Extensions

---
 clang/include/clang/AST/ASTContext.h  |   3 -
 clang/include/clang/Basic/TargetInfo.h|   5 -
 clang/lib/AST/ASTContext.cpp  |  31 ++-
 clang/lib/Basic/Targets/AArch64.cpp   |  97 +---
 clang/lib/Basic/Targets/AArch64.h |   1 -
 clang/lib/CodeGen/CGBuiltin.cpp   |   2 +-
 clang/lib/CodeGen/Targets/AArch64.cpp |   2 +-
 clang/test/CodeGen/aarch64-fmv-dependencies.c |  92 
 clang/test/CodeGen/attr-target-version.c  |  46 ++--
 .../llvm/TargetParser/AArch64TargetParser.h   |  39 +++-
 llvm/lib/Target/AArch64/AArch64.td|   1 +
 llvm/lib/Target/AArch64/AArch64FMV.td |  78 +++
 llvm/lib/Target/AArch64/AArch64Features.td| 211 --
 llvm/lib/TargetParser/AArch64TargetParser.cpp |  39 +++-
 llvm/utils/TableGen/ARMTargetDefEmitter.cpp   |  36 ++-
 15 files changed, 373 insertions(+), 310 deletions(-)
 create mode 100644 llvm/lib/Target/AArch64/AArch64FMV.td

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 2ce2b810d3636..e2ed06a3d8b6b 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -3194,9 +3194,6 @@ class ASTContext : public RefCountedBase {
   /// valid feature names.
   ParsedTargetAttr filterFunctionTargetAttrs(const TargetAttr *TD) const;
 
-  std::vector
-  filterFunctionTargetVersionAttrs(const TargetVersionAttr *TV) const;
-
   void getFunctionFeatureMap(llvm::StringMap &FeatureMap,
  const FunctionDecl *) const;
   void getFunctionFeatureMap(llvm::StringMap &FeatureMap,
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 8a6511b9ced83..9b0ae2102e098 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1400,11 +1400,6 @@ class TargetInfo : public TransferrableTargetInfo,
 return true;
   }
 
-  /// For given feature return dependent ones.
-  virtual StringRef getFeatureDependencies(StringRef Feature) const {
-return StringRef();
-  }
-
   struct BranchProtectionInfo {
 LangOptions::SignReturnAddressScopeKind SignReturnAddr;
 LangOptions::SignReturnAddressKeyKind SignKey;
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 52eab5feb062b..bbf72b1440e91 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -87,6 +87,7 @@
 #include "llvm/Support/MD5.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/TargetParser/AArch64TargetParser.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
 #include 
@@ -13664,16 +13665,23 @@ QualType 
ASTContext::getCorrespondingSignedFixedPointType(QualType Ty) const {
   }
 }
 
+// Given a list of FMV features, add each of their backend features to the 
list.
+static void
+GetFMVBackendFeaturesFor(const llvm::SmallVector FMVFeatStrings,
+ std::vector& BackendFeats) {
+  for (auto &F : FMVFeatStrings)
+if (auto FMVExt = llvm::AArch64::parseFMVExtension(F))
+  for (auto F : FMVExt->getImpliedFeatures())
+BackendFeats.push_back(F.str());
+}
+
 std::vector ASTContext::filterFunctionTargetVersionAttrs(
 const TargetVersionAttr *TV) const {
   assert(TV != nullptr);
   llvm::SmallVector Feats;
   std::vector ResFeats;
   TV->getFeatures(Feats);
-  for (auto &Feature : Feats)
-if (Target->validateCpuSupports(Feature.str()))
-  // Use '?' to mark features that came from TargetVersion.
-  ResFeats.push_back("?" + Feature.str());
+  GetFMVBackendFeaturesFor(Feats, ResFeats);
   return ResFeats;
 }
 
@@ -13735,13 +13743,11 @@ void 
ASTContext::getFunctionFeatureMap(llvm::StringMap &FeatureMap,
   } else if (const auto *TC = FD->getAttr()) {
 std::vector Features;
 if (Target->getTriple().isAArch64()) {
-  // TargetClones for AArch64
   llvm::SmallVector Feats;
   TC->getFeatures(Feats, GD.getMultiVersionIndex());
-  for (StringRef Feat : Feats)
-if (Target->validateCpuSupports(Feat.str()))
-  // Use '?' to mark features that came from AArch64 TargetClones.
-  Features.push_back("?" + Feat.str());
+  GetFMVBackendFeaturesFor(Feats, Features);
+
+  // Combine with the features from the Target, not expanded
   Features.insert(Features.begin(),
   Target->getTargetOpts().FeaturesAsWritten.begin(),
   Target->getTargetOpts().FeaturesAsWritten.end());
@@ -13754,11 +13760,14 @@ void 
ASTContext::getFunctionFeatureMap(llvm::StringMap &FeatureMap,
 }
 Target->initFeatureMap(FeatureMap, getDiagnostics(), TargetCPU, Fea

[clang] [llvm] Split fmv and extensions (PR #92882)

2024-05-28 Thread Tomas Matheson via cfe-commits

@@ -0,0 +1,84 @@
+// Function MultiVersioning (FMV) properties
+
+// Something you can add to target_version or target_clones
+class FMVExtension {
+// Name, as spelled in target_version or target_clones. e.g. "memtag"
+string Name = n;
+
+// A C++ expression giving the number of the bit in the FMV ABI.
+// Currently this is given as a value from the enum "CPUFeatures".
+// If this is not set, it indicates that this is not an FMV extension.
+string Bit = b;
+
+// SubtargetFeatures to enable for code functions with this FMV feature.
+// TODO list BackendFeatures = f;
+string BackendFeatures = f;
+
+// The FMV priority.
+int Priority = p;

tmatheson-arm wrote:

There is no `unsigned` in tablegen, afaik.

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


[clang] [analyzer] Adding taint analysis capability to unix.Malloc checker (PR #92420)

2024-05-28 Thread Daniel Krupp via cfe-commits
https://github.com/dkrupp updated 
https://github.com/llvm/llvm-project/pull/92420

>From f6fdd544a90b865e5e0e530930db87cad405216e Mon Sep 17 00:00:00 2001
From: Daniel Krupp 
Date: Tue, 30 Apr 2024 15:20:52 +0200
Subject: [PATCH 1/4] [analyzer] Adding taint analysis capability to
 unix.Malloc checker

unix.Malloc checker will warn if a memory allocation function
(malloc, calloc, realloc, alloca) is called with a tainted
(attacker controlled) size parameter.
A large, maliciously set size value can trigger memory exhaustion.
To get this warning, the alpha.security.taint.TaintPropagation checker
also needs to be switched on.

The warning will only be emitted, if the analyzer cannot prove
that the size is below reasonable bounds (https://wiki.sei.cmu.edu/confluence/display/c/INT04-C.+Enforce+limits+on+integer+values+originating+from+tainted+sources>`_.
+
+You can silence this warning either by bound checking the ``size`` parameter, 
or
+by explicitly marking the ``size`` parameter as sanitized. See the
+:ref:`alpha-security-taint-TaintPropagation` checker for more details.
+
+.. code-block:: c
+
+  void t1(void) {
+size_t size;
+scanf("%zu", &size);
+int *p = malloc(size); // warn: malloc is called with a tainted 
(potentially attacker controlled) value
+free(p);
+  }
+
+  void t3(void) {
+size_t size;
+scanf("%zu", &size);
+if (1024 BT_MismatchedDealloc;
   mutable std::unique_ptr BT_OffsetFree[CK_NumCheckKinds];
   mutable std::unique_ptr BT_UseZerroAllocated[CK_NumCheckKinds];
+  mutable std::unique_ptr BT_TaintedAlloc[CK_NumCheckKinds];
 
 #define CHECK_FN(NAME) 
\
   void NAME(const CallEvent &Call, CheckerContext &C) const;
@@ -462,6 +464,13 @@ class MallocChecker
   };
 
   bool isMemCall(const CallEvent &Call) const;
+  void reportTaintBug(StringRef Msg, ProgramStateRef State, CheckerContext &C,
+  llvm::ArrayRef TaintedSyms,
+  AllocationFamily Family, const Expr *SizeEx) const;
+
+  void CheckTaintedness(CheckerContext &C, const CallEvent &Call,
+const SVal SizeSVal, ProgramStateRef State,
+AllocationFamily Family) const;
 
   // TODO: Remove mutable by moving the initializtaion to the registry 
function.
   mutable std::optional KernelZeroFlagVal;
@@ -521,9 +530,9 @@ class MallocChecker
   /// malloc leaves it undefined.
   /// \param [in] State The \c ProgramState right before allocation.
   /// \returns The ProgramState right after allocation.
-  [[nodiscard]] static ProgramStateRef
+  [[nodiscard]] ProgramStateRef
   MallocMemAux(CheckerContext &C, const CallEvent &Call, const Expr *SizeEx,
-   SVal Init, ProgramStateRef State, AllocationFamily Family);
+   SVal Init, ProgramStateRef State, AllocationFamily Family) 
const;
 
   /// Models memory allocation.
   ///
@@ -534,9 +543,10 @@ class MallocChecker
   /// malloc leaves it undefined.
   /// \param [in] State The \c ProgramState right before allocation.
   /// \returns The ProgramState right after allocation.
-  [[nodiscard]] static ProgramStateRef
-  MallocMemAux(CheckerContext &C, const CallEvent &Call, SVal Size, SVal Init,
-   ProgramStateRef State, AllocationFamily Family);
+  [[nodiscard]] ProgramStateRef MallocMemAux(CheckerContext &C,
+ const CallEvent &Call, SVal Size,
+ SVal Init, ProgramStateRef State,
+ AllocationFamily Family) const;
 
   // Check if this malloc() for special flags. At present that means M_ZERO or
   // __GFP_ZERO (in which case, treat it like calloc).
@@ -649,8 +659,9 @@ class MallocChecker
   /// \param [in] Call The expression that reallocated memory
   /// \param [in] State The \c ProgramState right before reallocation.
   /// \returns The ProgramState right after allocation.
-  [[nodiscard]] static ProgramStateRef
-  CallocMem(CheckerContext &C, const CallEvent &Call, ProgramStateRef State);
+  [[nodiscard]] ProgramStateRef CallocMem(CheckerContext &C,
+  const CallEvent &Call,
+  ProgramStateRef State) const;
 
   /// See if deallocation happens in a suspicious context. If so, escape the
   /// pointers that otherwise would have been deallocated and return true.
@@ -1779,7 +1790,7 @@ ProgramStateRef 
MallocChecker::MallocMemAux(CheckerContext &C,
 const CallEvent &Call,
 const Expr *SizeEx, SVal Init,
 ProgramStateRef State,
-AllocationFamily Family) {
+AllocationFamily Family) const {
   if (!State)
 return nullptr;
 
@@ -1787,10 +1798,71 @@ ProgramStateRef 
MallocChecker:

[clang] [clang] Improve ast-dumper text printing of TemplateArgument (PR #93431)

2024-05-28 Thread Aaron Ballman via cfe-commits

@@ -947,6 +947,26 @@ void TextNodeDumper::dumpDeclRef(const Decl *D, StringRef 
Label) {
   });
 }
 
+void TextNodeDumper::dumpTemplateArgument(const TemplateArgument &TA) {
+  llvm::SmallString<128> Str;
+  {
+llvm::raw_svector_ostream SS(Str);
+TA.print(PrintPolicy, SS, /*IncludeType=*/true);
+  }
+  OS << " '" << Str << "'";
+
+  if (TemplateArgument CanonTA = Context->getCanonicalTemplateArgument(TA);

AaronBallman wrote:

```suggestion
  if (const TemplateArgument &CanonTA = 
Context->getCanonicalTemplateArgument(TA);
```

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


[clang] [clang] Improve ast-dumper text printing of TemplateArgument (PR #93431)

2024-05-28 Thread Aaron Ballman via cfe-commits
https://github.com/AaronBallman commented:

Should we also be updating JSONNodeDumper.cpp at the same time?

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


[clang] [clang] Improve ast-dumper text printing of TemplateArgument (PR #93431)

2024-05-28 Thread Aaron Ballman via cfe-commits
https://github.com/AaronBallman edited 
https://github.com/llvm/llvm-project/pull/93431
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Improve ast-dumper text printing of TemplateArgument (PR #93431)

2024-05-28 Thread Aaron Ballman via cfe-commits

@@ -1086,45 +1106,100 @@ void TextNodeDumper::VisitNullTemplateArgument(const 
TemplateArgument &) {
 
 void TextNodeDumper::VisitTypeTemplateArgument(const TemplateArgument &TA) {
   OS << " type";
-  dumpType(TA.getAsType());
+  dumpTemplateArgument(TA);
 }
 
 void TextNodeDumper::VisitDeclarationTemplateArgument(
 const TemplateArgument &TA) {
   OS << " decl";
+  dumpTemplateArgument(TA);
   dumpDeclRef(TA.getAsDecl());
 }
 
-void TextNodeDumper::VisitNullPtrTemplateArgument(const TemplateArgument &) {
+void TextNodeDumper::VisitNullPtrTemplateArgument(const TemplateArgument &TA) {
   OS << " nullptr";
+  dumpTemplateArgument(TA);
 }
 
 void TextNodeDumper::VisitIntegralTemplateArgument(const TemplateArgument &TA) 
{
-  OS << " integral " << TA.getAsIntegral();
+  OS << " integral";
+  dumpTemplateArgument(TA);
+}
+
+void TextNodeDumper::dumpTemplateName(TemplateName TN) {
+  switch (TN.getKind()) {
+  case TemplateName::Template:
+AddChild([=] { Visit(TN.getAsTemplateDecl()); });
+return;
+  case TemplateName::UsingTemplate: {
+const UsingShadowDecl *USD = TN.getAsUsingShadowDecl();
+AddChild([=] { Visit(USD); });
+AddChild("target", [=] { Visit(USD->getTargetDecl()); });
+return;
+  }
+  case TemplateName::QualifiedTemplate: {
+OS << " qualified";
+const QualifiedTemplateName *QTN = TN.getAsQualifiedTemplateName();
+if (QTN->hasTemplateKeyword())
+  OS << " keyword";
+dumpNestedNameSpecifier(QTN->getQualifier());
+dumpTemplateName(QTN->getUnderlyingTemplate());
+return;
+  }
+  case TemplateName::DependentTemplate: {
+OS << " dependent";
+const DependentTemplateName *DTN = TN.getAsDependentTemplateName();
+dumpNestedNameSpecifier(DTN->getQualifier());
+return;
+  }
+  case TemplateName::SubstTemplateTemplateParm: {
+const SubstTemplateTemplateParmStorage *STS =
+TN.getAsSubstTemplateTemplateParm();
+OS << " subst index " << STS->getIndex();
+if (std::optional PackIndex = STS->getPackIndex())
+  OS << " pack_index " << *PackIndex;

AaronBallman wrote:

Yeah, I'd say let's go with `subst_index` instead.

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


[clang] [llvm] Split fmv and extensions (PR #92882)

2024-05-28 Thread Alexandros Lamprineas via cfe-commits

@@ -13754,11 +13760,14 @@ void 
ASTContext::getFunctionFeatureMap(llvm::StringMap &FeatureMap,
 }
 Target->initFeatureMap(FeatureMap, getDiagnostics(), TargetCPU, Features);
   } else if (const auto *TV = FD->getAttr()) {
-std::vector Feats = filterFunctionTargetVersionAttrs(TV);

labrinea wrote:

Why this change? If this was the only use can we just delete 
filterFunctionTargetVersionAttrs?

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


[clang] [analyzer] New optin.taint.TaintAlloc checker for catching malicious memory allocation calls (PR #92420)

2024-05-28 Thread Daniel Krupp via cfe-commits
https://github.com/dkrupp edited https://github.com/llvm/llvm-project/pull/92420
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] New optin.taint.TaintAlloc checker for catching unbounded memory allocation calls (PR #92420)

2024-05-28 Thread Daniel Krupp via cfe-commits
https://github.com/dkrupp edited https://github.com/llvm/llvm-project/pull/92420
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AMDGPU] Implement variadic functions by IR lowering (PR #93362)

2024-05-28 Thread Jon Chesterfield via cfe-commits
JonChesterfield wrote:

Joseph reports "memory error" from a libc test when running with this patch. 
This is unfortunate. I haven't reproduced that yet (I don't mean libc passes, I 
mean libc fails with or without this patch). The blast radius for "memory 
error" on amdgpu is wide but there is very little amdgpu specific code in this 
patch so it's either something handling addrspacecast incorrectly or an unlucky 
interaction with something outside of this patch.

My plan is to spin up a separate patch which is the non-amdgpu part of this and 
hope someone signs off on it - the development overhead of juggling lots of 
branches is significantly compromising time to solution here. Bringing up x64 / 
aarch64 / nvptx or similar will, if I'm lucky, uncover a bug in this pass which 
is causing the libc test failure.

For debugging amdgpu, I'll add more tests around addrspace cast and hope to see 
a bug in the IR, try to get libc to pass and, in extremis, try to build rocm 
from source in case the debugger helps.

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


[clang] [llvm] Split fmv and extensions (PR #92882)

2024-05-28 Thread Tomas Matheson via cfe-commits
https://github.com/tmatheson-arm updated 
https://github.com/llvm/llvm-project/pull/92882

>From 76ccb775de5103dde3b59b838ba3f71be367418d Mon Sep 17 00:00:00 2001
From: Tomas Matheson 
Date: Tue, 21 May 2024 09:36:48 +0100
Subject: [PATCH 1/2] Separate FMV and Extensions

---
 clang/include/clang/AST/ASTContext.h  |   3 -
 clang/include/clang/Basic/TargetInfo.h|   5 -
 clang/lib/AST/ASTContext.cpp  |  31 ++-
 clang/lib/Basic/Targets/AArch64.cpp   |  97 +---
 clang/lib/Basic/Targets/AArch64.h |   1 -
 clang/lib/CodeGen/CGBuiltin.cpp   |   2 +-
 clang/lib/CodeGen/Targets/AArch64.cpp |   2 +-
 clang/test/CodeGen/aarch64-fmv-dependencies.c |  92 
 clang/test/CodeGen/attr-target-version.c  |  46 ++--
 .../llvm/TargetParser/AArch64TargetParser.h   |  39 +++-
 llvm/lib/Target/AArch64/AArch64.td|   1 +
 llvm/lib/Target/AArch64/AArch64FMV.td |  78 +++
 llvm/lib/Target/AArch64/AArch64Features.td| 211 --
 llvm/lib/TargetParser/AArch64TargetParser.cpp |  39 +++-
 llvm/utils/TableGen/ARMTargetDefEmitter.cpp   |  36 ++-
 15 files changed, 373 insertions(+), 310 deletions(-)
 create mode 100644 llvm/lib/Target/AArch64/AArch64FMV.td

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 2ce2b810d3636..e2ed06a3d8b6b 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -3194,9 +3194,6 @@ class ASTContext : public RefCountedBase {
   /// valid feature names.
   ParsedTargetAttr filterFunctionTargetAttrs(const TargetAttr *TD) const;
 
-  std::vector
-  filterFunctionTargetVersionAttrs(const TargetVersionAttr *TV) const;
-
   void getFunctionFeatureMap(llvm::StringMap &FeatureMap,
  const FunctionDecl *) const;
   void getFunctionFeatureMap(llvm::StringMap &FeatureMap,
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 8a6511b9ced83..9b0ae2102e098 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1400,11 +1400,6 @@ class TargetInfo : public TransferrableTargetInfo,
 return true;
   }
 
-  /// For given feature return dependent ones.
-  virtual StringRef getFeatureDependencies(StringRef Feature) const {
-return StringRef();
-  }
-
   struct BranchProtectionInfo {
 LangOptions::SignReturnAddressScopeKind SignReturnAddr;
 LangOptions::SignReturnAddressKeyKind SignKey;
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 52eab5feb062b..bbf72b1440e91 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -87,6 +87,7 @@
 #include "llvm/Support/MD5.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/TargetParser/AArch64TargetParser.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
 #include 
@@ -13664,16 +13665,23 @@ QualType 
ASTContext::getCorrespondingSignedFixedPointType(QualType Ty) const {
   }
 }
 
+// Given a list of FMV features, add each of their backend features to the 
list.
+static void
+GetFMVBackendFeaturesFor(const llvm::SmallVector FMVFeatStrings,
+ std::vector& BackendFeats) {
+  for (auto &F : FMVFeatStrings)
+if (auto FMVExt = llvm::AArch64::parseFMVExtension(F))
+  for (auto F : FMVExt->getImpliedFeatures())
+BackendFeats.push_back(F.str());
+}
+
 std::vector ASTContext::filterFunctionTargetVersionAttrs(
 const TargetVersionAttr *TV) const {
   assert(TV != nullptr);
   llvm::SmallVector Feats;
   std::vector ResFeats;
   TV->getFeatures(Feats);
-  for (auto &Feature : Feats)
-if (Target->validateCpuSupports(Feature.str()))
-  // Use '?' to mark features that came from TargetVersion.
-  ResFeats.push_back("?" + Feature.str());
+  GetFMVBackendFeaturesFor(Feats, ResFeats);
   return ResFeats;
 }
 
@@ -13735,13 +13743,11 @@ void 
ASTContext::getFunctionFeatureMap(llvm::StringMap &FeatureMap,
   } else if (const auto *TC = FD->getAttr()) {
 std::vector Features;
 if (Target->getTriple().isAArch64()) {
-  // TargetClones for AArch64
   llvm::SmallVector Feats;
   TC->getFeatures(Feats, GD.getMultiVersionIndex());
-  for (StringRef Feat : Feats)
-if (Target->validateCpuSupports(Feat.str()))
-  // Use '?' to mark features that came from AArch64 TargetClones.
-  Features.push_back("?" + Feat.str());
+  GetFMVBackendFeaturesFor(Feats, Features);
+
+  // Combine with the features from the Target, not expanded
   Features.insert(Features.begin(),
   Target->getTargetOpts().FeaturesAsWritten.begin(),
   Target->getTargetOpts().FeaturesAsWritten.end());
@@ -13754,11 +13760,14 @@ void 
ASTContext::getFunctionFeatureMap(llvm::StringMap &FeatureMap,
 }
 Target->initFeatureMap(FeatureMap, getDiagnostics(), TargetCPU,

[clang] [llvm] Split fmv and extensions (PR #92882)

2024-05-28 Thread Tomas Matheson via cfe-commits

@@ -13754,11 +13760,14 @@ void 
ASTContext::getFunctionFeatureMap(llvm::StringMap &FeatureMap,
 }
 Target->initFeatureMap(FeatureMap, getDiagnostics(), TargetCPU, Features);
   } else if (const auto *TV = FD->getAttr()) {
-std::vector Feats = filterFunctionTargetVersionAttrs(TV);

tmatheson-arm wrote:

Just to make it consistent with the TargetClones case.

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


[clang] [Clang] [C23] Fix typeof_unqual for qualified array types (PR #92767)

2024-05-28 Thread Aaron Ballman via cfe-commits
https://github.com/AaronBallman approved this pull request.

LGTM! Precommit CI failure is unrelated to your changes.

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


[clang] [Clang] [C23] Fix typeof_unqual for qualified array types (PR #92767)

2024-05-28 Thread Aaron Ballman via cfe-commits
https://github.com/AaronBallman edited 
https://github.com/llvm/llvm-project/pull/92767
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [libcxx] [llvm] [mlir] [SPIR-V] Introduce support of llvm.ptr.annotation to SPIR-V Backend and implement extensions which make use of spirv.Decorations (PR #93479)

2024-05-28 Thread Vyacheslav Levytskyy via cfe-commits
Stefan =?utf-8?q?Gränitz?= ,Shengchen Kan
 ,David Green ,josel-amd
 <166385423+josel-...@users.noreply.github.com>,Matt Arsenault
 ,Kelvin Li ,Artem
 Kroviakov <71938912+akrovia...@users.noreply.github.com>,Benjamin Kramer
 ,Shengchen Kan ,Nico
 Weber ,Tom Eccles ,Sayan Saha
 ,Aaron Ballman ,Tyker
 ,Xu Zhang ,cor3ntin
 ,LLVM GN Syncbot ,Sander
 de Smalen ,"Levytskyy, Vyacheslav"
 
Message-ID:
In-Reply-To: 


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


[clang] [Clang][Sema] Use correct TemplateName when transforming TemplateSpecializationType (PR #93411)

2024-05-28 Thread Qizhi Hu via cfe-commits
https://github.com/jcsxky closed https://github.com/llvm/llvm-project/pull/93411
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   3   4   5   >