[clang] [X86][AVX10.2] Add comments for the avx10_2convertintrin.h file (PR #120766)

2024-12-21 Thread Mikołaj Piróg via cfe-commits

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


[clang] [clang-format] Add AlignAfterOpenBracketOptions (PR #108332)

2024-12-21 Thread Björn Schäpers via cfe-commits


@@ -1452,6 +1476,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   FormatStyle LLVMStyle;
   LLVMStyle.AccessModifierOffset = -2;
   LLVMStyle.AlignAfterOpenBracket = FormatStyle::BAS_Align;
+  LLVMStyle.AlignAfterOpenBracketBreak = {};

HazardyKnusperkeks wrote:

But when it is not set to Align when reading the configuration, but that didn't 
set `AlignAfterOpenBracketBreak`.

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


[clang] [clang] fix uefi target for aarch64 & x86_64 (PR #120632)

2024-12-21 Thread via cfe-commits


@@ -788,16 +789,28 @@ class LLVM_LIBRARY_VISIBILITY ZOSTargetInfo : public 
OSTargetInfo {
 // UEFI target
 template 
 class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo {
+  llvm::Triple Triple;
+
 protected:
   void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
-MacroBuilder &Builder) const override {}
+MacroBuilder &Builder) const override {
+DefineStd(Builder, "uefi", Opts);

Prabhuk wrote:

I have approvals to land #111719 and #111473 which breaks out some aspects of 
this large PR. I am happy to either land them first or wait for all those 
changes to be part of this PR. @RossComputerGuy I am happy to go with whichever 
way makes landing this patch faster. Let me know.



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


[clang] [clang] Introduce a new UEFI target predefine. (PR #111719)

2024-12-21 Thread via cfe-commits

Prabhuk wrote:

> Didn't know this existed, but we have #120632 tracking it now.

Thanks. I left another comment there for @RossComputerGuy to decide on whether 
to land this patch or not.

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


[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)

2024-12-21 Thread Björn Schäpers via cfe-commits

HazardyKnusperkeks wrote:

> > I think it should be merges with `BinPackArguments` to get an enum
> > 
> > * Never
> > * TwentyOrAbove (name is debatable)
> > * Always
> > * (Leave?)
> 
> Currently the 20 item limit is only enforced on C++ initializer lists. Making 
> it part of the `BinPackArguments` means it has to apply to any bin packing 
> situation, so the scope of the style option increases. I'm not convinced it 
> is worth doing.

Fair enough.

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


[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)

2024-12-21 Thread Björn Schäpers via cfe-commits

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


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


[clang] [clang] fix uefi target for aarch64 & x86_64 (PR #120632)

2024-12-21 Thread Tristan Ross via cfe-commits


@@ -788,16 +789,28 @@ class LLVM_LIBRARY_VISIBILITY ZOSTargetInfo : public 
OSTargetInfo {
 // UEFI target
 template 
 class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo {
+  llvm::Triple Triple;
+
 protected:
   void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
-MacroBuilder &Builder) const override {}
+MacroBuilder &Builder) const override {
+DefineStd(Builder, "uefi", Opts);

RossComputerGuy wrote:

We can probably get the cleanup PR first then this one. Kinda on the fence with 
the define one.

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


[clang] Mechanically port bulk of x86 builtins to TableGen (PR #120831)

2024-12-21 Thread Craig Topper via cfe-commits

topperc wrote:

When I was still involved in X86 my recollection was we primarily used LLi. It 
looks like there was a large replacement of LLi with Oi here 
fa8cd7691ac28d07f6a127ed26f0dbe49699bd59.

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


[clang] Mechanically port bulk of x86 builtins to TableGen (PR #120831)

2024-12-21 Thread Chandler Carruth via cfe-commits

chandlerc wrote:

A long way from an expert on OpenCL, but it seems to not even have the concept 
of `long long`, and `long` is defined as a 64-bit type (and just optional for 
embedded stuff)?

https://registry.khronos.org/OpenCL/sdk/3.0/docs/man/html/scalarDataTypes.html

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


[clang] Remove the `CustomEntry` escape hatch from builtin TableGen (PR #120861)

2024-12-21 Thread Chandler Carruth via cfe-commits

https://github.com/chandlerc created 
https://github.com/llvm/llvm-project/pull/120861

This was an especially challenging escape hatch because it directly forced the 
use of a specific X-macro structure and prevented any other form of TableGen 
emission.

The problematic feature that motivated this is a case where a builtin's 
prototype can't be represented in the mini-language used by TableGen. Instead 
of adding a complete custom entry for this, this PR just teaches the prototype 
handling to do the same thing the X-macros did in this case: emit an empty 
string and let the Clang builtin handling respond appropriately.

This should produce identical results while preserving all the rest of the 
structured representation in the builtin TableGen code.

>From b803cab4877afc4c9f1c140c4f86c048916ca2bf Mon Sep 17 00:00:00 2001
From: Chandler Carruth 
Date: Sat, 21 Dec 2024 23:42:57 +
Subject: [PATCH] Remove the `CustomEntry` escape hatch from builtin TableGen

This was an especially challenging escape hatch because it directly
forced the use of a specific X-macro structure and prevented any other
form of TableGen emission.

The problematic feature that motivated this is a case where a builtin's
prototype can't be represented in the mini-language used by TableGen.
Instead of adding a complete custom entry for this, this PR just teaches
the prototype handling to do the same thing the X-macros did in this
case: emit an empty string and let the Clang builtin handling respond
appropriately.

This should produce identical results while preserving all the rest of
the structured representation in the builtin TableGen code.
---
 clang/include/clang/Basic/Builtins.td |  8 ---
 clang/include/clang/Basic/BuiltinsBase.td | 13 +++
 clang/utils/TableGen/ClangBuiltinsEmitter.cpp | 22 ++-
 3 files changed, 31 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index d64a66fc9d9cf7..9f5647dc719f33 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -3347,10 +3347,12 @@ def VFork : LibBuiltin<"unistd.h"> {
 }
 
 // POSIX pthread.h
-// FIXME: This should be a GNULibBuiltin, but it's currently missing the 
prototype.
 
-def PthreadCreate : CustomEntry {
-  let Entry = "LIBBUILTIN(pthread_create, \"\",  \"fC<2,3>\", PTHREAD_H, 
ALL_GNU_LANGUAGES)";
+def PthreadCreate : GNULibBuiltin<"pthread.h"> {
+  let Spellings = ["pthread_create"];
+  let Attributes = [FunctionWithoutBuiltinPrefix, Callback<[2, 3]>];
+  // Note that we don't have an expressable prototype so we leave it empty.
+  let Prototype = "";
 }
 
 def SigSetJmp : LibBuiltin<"setjmp.h"> {
diff --git a/clang/include/clang/Basic/BuiltinsBase.td 
b/clang/include/clang/Basic/BuiltinsBase.td
index cff182f3f282cb..8a3f024c20f446 100644
--- a/clang/include/clang/Basic/BuiltinsBase.td
+++ b/clang/include/clang/Basic/BuiltinsBase.td
@@ -17,6 +17,11 @@ class IndexedAttribute : 
Attribute {
   int Index = I;
 }
 
+class MultiIndexAttribute Is>
+: Attribute {
+  list Indices = Is;
+}
+
 // Standard Attributes
 // ---
 def NoReturn : Attribute<"r">;
@@ -77,6 +82,10 @@ def Constexpr : Attribute<"E">;
 // Builtin is immediate and must be constant evaluated. Implies Constexpr, and 
will only be supported in C++20 mode.
 def Consteval : Attribute<"EG">;
 
+// Callback behavior: the first index argument is called with the arguments
+// indicated by the remaining indices.
+class Callback ArgIndices> : MultiIndexAttribute<"C", ArgIndices>;
+
 // Builtin kinds
 // =
 
@@ -90,10 +99,6 @@ class Builtin {
   bit RequiresUndef = 0;
 }
 
-class CustomEntry {
-  string Entry;
-}
-
 class AtomicBuiltin : Builtin;
 class TargetBuiltin : Builtin {
   string Features = "";
diff --git a/clang/utils/TableGen/ClangBuiltinsEmitter.cpp 
b/clang/utils/TableGen/ClangBuiltinsEmitter.cpp
index 6c3604adc92b99..f675dd154a7c97 100644
--- a/clang/utils/TableGen/ClangBuiltinsEmitter.cpp
+++ b/clang/utils/TableGen/ClangBuiltinsEmitter.cpp
@@ -11,6 +11,7 @@
 
//===--===//
 
 #include "TableGenBackends.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/TableGen/Error.h"
 #include "llvm/TableGen/Record.h"
@@ -37,6 +38,14 @@ class PrototypeParser {
 private:
   void ParsePrototype(StringRef Prototype) {
 Prototype = Prototype.trim();
+
+// Some builtins don't have an expressible prototype, simply emit an empty
+// string for them.
+if (Prototype.empty()) {
+  Type = "";
+  return;
+}
+
 ParseTypes(Prototype);
   }
 
@@ -236,8 +245,15 @@ void PrintAttributes(const Record *Builtin, BuiltinType 
BT, raw_ostream &OS) {
 
   for (const auto *Attr : Builtin->getValueAsListOfDefs("Attributes")) {
 OS << Attr->getValueAsString("Mangling");
-if (Attr->isSubClassOf("IndexedAttribute"))
+if

[clang] Remove the `CustomEntry` escape hatch from builtin TableGen (PR #120861)

2024-12-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Chandler Carruth (chandlerc)


Changes

This was an especially challenging escape hatch because it directly forced the 
use of a specific X-macro structure and prevented any other form of TableGen 
emission.

The problematic feature that motivated this is a case where a builtin's 
prototype can't be represented in the mini-language used by TableGen. Instead 
of adding a complete custom entry for this, this PR just teaches the prototype 
handling to do the same thing the X-macros did in this case: emit an empty 
string and let the Clang builtin handling respond appropriately.

This should produce identical results while preserving all the rest of the 
structured representation in the builtin TableGen code.

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


3 Files Affected:

- (modified) clang/include/clang/Basic/Builtins.td (+5-3) 
- (modified) clang/include/clang/Basic/BuiltinsBase.td (+9-4) 
- (modified) clang/utils/TableGen/ClangBuiltinsEmitter.cpp (+17-5) 


``diff
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index d64a66fc9d9cf7..9f5647dc719f33 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -3347,10 +3347,12 @@ def VFork : LibBuiltin<"unistd.h"> {
 }
 
 // POSIX pthread.h
-// FIXME: This should be a GNULibBuiltin, but it's currently missing the 
prototype.
 
-def PthreadCreate : CustomEntry {
-  let Entry = "LIBBUILTIN(pthread_create, \"\",  \"fC<2,3>\", PTHREAD_H, 
ALL_GNU_LANGUAGES)";
+def PthreadCreate : GNULibBuiltin<"pthread.h"> {
+  let Spellings = ["pthread_create"];
+  let Attributes = [FunctionWithoutBuiltinPrefix, Callback<[2, 3]>];
+  // Note that we don't have an expressable prototype so we leave it empty.
+  let Prototype = "";
 }
 
 def SigSetJmp : LibBuiltin<"setjmp.h"> {
diff --git a/clang/include/clang/Basic/BuiltinsBase.td 
b/clang/include/clang/Basic/BuiltinsBase.td
index cff182f3f282cb..8a3f024c20f446 100644
--- a/clang/include/clang/Basic/BuiltinsBase.td
+++ b/clang/include/clang/Basic/BuiltinsBase.td
@@ -17,6 +17,11 @@ class IndexedAttribute : 
Attribute {
   int Index = I;
 }
 
+class MultiIndexAttribute Is>
+: Attribute {
+  list Indices = Is;
+}
+
 // Standard Attributes
 // ---
 def NoReturn : Attribute<"r">;
@@ -77,6 +82,10 @@ def Constexpr : Attribute<"E">;
 // Builtin is immediate and must be constant evaluated. Implies Constexpr, and 
will only be supported in C++20 mode.
 def Consteval : Attribute<"EG">;
 
+// Callback behavior: the first index argument is called with the arguments
+// indicated by the remaining indices.
+class Callback ArgIndices> : MultiIndexAttribute<"C", ArgIndices>;
+
 // Builtin kinds
 // =
 
@@ -90,10 +99,6 @@ class Builtin {
   bit RequiresUndef = 0;
 }
 
-class CustomEntry {
-  string Entry;
-}
-
 class AtomicBuiltin : Builtin;
 class TargetBuiltin : Builtin {
   string Features = "";
diff --git a/clang/utils/TableGen/ClangBuiltinsEmitter.cpp 
b/clang/utils/TableGen/ClangBuiltinsEmitter.cpp
index 6c3604adc92b99..f675dd154a7c97 100644
--- a/clang/utils/TableGen/ClangBuiltinsEmitter.cpp
+++ b/clang/utils/TableGen/ClangBuiltinsEmitter.cpp
@@ -11,6 +11,7 @@
 
//===--===//
 
 #include "TableGenBackends.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/TableGen/Error.h"
 #include "llvm/TableGen/Record.h"
@@ -37,6 +38,14 @@ class PrototypeParser {
 private:
   void ParsePrototype(StringRef Prototype) {
 Prototype = Prototype.trim();
+
+// Some builtins don't have an expressible prototype, simply emit an empty
+// string for them.
+if (Prototype.empty()) {
+  Type = "";
+  return;
+}
+
 ParseTypes(Prototype);
   }
 
@@ -236,8 +245,15 @@ void PrintAttributes(const Record *Builtin, BuiltinType 
BT, raw_ostream &OS) {
 
   for (const auto *Attr : Builtin->getValueAsListOfDefs("Attributes")) {
 OS << Attr->getValueAsString("Mangling");
-if (Attr->isSubClassOf("IndexedAttribute"))
+if (Attr->isSubClassOf("IndexedAttribute")) {
   OS << ':' << Attr->getValueAsInt("Index") << ':';
+} else if (Attr->isSubClassOf("MultiIndexAttribute")) {
+  OS << '<';
+  llvm::ListSeparator Sep(",");
+  for (int64_t Index : Attr->getValueAsListOfInts("Indices"))
+OS << Sep << Index;
+  OS << '>';
+}
   }
   OS << '\"';
 }
@@ -380,10 +396,6 @@ void clang::EmitClangBuiltins(const RecordKeeper &Records, 
raw_ostream &OS) {
 EmitBuiltin(OS, Builtin);
   }
 
-  for (const auto *Entry : Records.getAllDerivedDefinitions("CustomEntry")) {
-OS << Entry->getValueAsString("Entry") << '\n';
-  }
-
   OS << R"c++(
 #undef ATOMIC_BUILTIN
 #undef BUILTIN

``




https://github.com/llvm/llvm-project/pull/120861
___
cfe-commits mailing lis

[clang] dce2245 - [clang][driver] Cleanup UEFI toolchain driver (#111473)

2024-12-21 Thread via cfe-commits

Author: Prabhuk
Date: 2024-12-21T17:44:45-08:00
New Revision: dce2245ba49fad419e551b0143f41431ec8e7f03

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

LOG: [clang][driver] Cleanup UEFI toolchain driver (#111473)

Updating UEFI header includes to not include system include directories,
adding includes from compiler resource directory and minor cleanups.

Added: 


Modified: 
clang/lib/Basic/Targets/X86.h
clang/lib/Driver/ToolChains/UEFI.cpp
clang/lib/Driver/ToolChains/UEFI.h
clang/lib/Lex/InitHeaderSearch.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index 3ed36c8fa724b5..553c452d4ba3c2 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -832,11 +832,6 @@ class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo
   "i64:64-i128:128-f80:128-n8:16:32:64-S128");
   }
 
-  void getTargetDefines(const LangOptions &Opts,
-MacroBuilder &Builder) const override {
-getOSDefines(Opts, X86TargetInfo::getTriple(), Builder);
-  }
-
   BuiltinVaListKind getBuiltinVaListKind() const override {
 return TargetInfo::CharPtrBuiltinVaList;
   }

diff  --git a/clang/lib/Driver/ToolChains/UEFI.cpp 
b/clang/lib/Driver/ToolChains/UEFI.cpp
index 66cbbec59246c0..a9d7e7892c5a64 100644
--- a/clang/lib/Driver/ToolChains/UEFI.cpp
+++ b/clang/lib/Driver/ToolChains/UEFI.cpp
@@ -35,6 +35,24 @@ UEFI::UEFI(const Driver &D, const llvm::Triple &Triple, 
const ArgList &Args)
 
 Tool *UEFI::buildLinker() const { return new tools::uefi::Linker(*this); }
 
+void UEFI::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
+ ArgStringList &CC1Args) const {
+  if (DriverArgs.hasArg(options::OPT_nostdinc))
+return;
+
+  if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
+SmallString<128> Dir(getDriver().ResourceDir);
+llvm::sys::path::append(Dir, "include");
+addSystemInclude(DriverArgs, CC1Args, Dir.str());
+  }
+
+  if (DriverArgs.hasArg(options::OPT_nostdlibinc))
+return;
+
+  if (std::optional Path = getStdlibIncludePath())
+addSystemInclude(DriverArgs, CC1Args, *Path);
+}
+
 void tools::uefi::Linker::ConstructJob(Compilation &C, const JobAction &JA,
const InputInfo &Output,
const InputInfoList &Inputs,

diff  --git a/clang/lib/Driver/ToolChains/UEFI.h 
b/clang/lib/Driver/ToolChains/UEFI.h
index a126ac32db6c6c..7e038b5cb8b186 100644
--- a/clang/lib/Driver/ToolChains/UEFI.h
+++ b/clang/lib/Driver/ToolChains/UEFI.h
@@ -51,6 +51,10 @@ class LLVM_LIBRARY_VISIBILITY UEFI : public ToolChain {
 return false;
   }
   bool isPICDefaultForced() const override { return true; }
+
+  void
+  AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
+llvm::opt::ArgStringList &CC1Args) const override;
 };
 
 } // namespace toolchains

diff  --git a/clang/lib/Lex/InitHeaderSearch.cpp 
b/clang/lib/Lex/InitHeaderSearch.cpp
index ea02f5dfb62644..67c9d92b849ea3 100644
--- a/clang/lib/Lex/InitHeaderSearch.cpp
+++ b/clang/lib/Lex/InitHeaderSearch.cpp
@@ -301,6 +301,7 @@ bool InitHeaderSearch::ShouldAddDefaultIncludePaths(
   case llvm::Triple::PS5:
   case llvm::Triple::RTEMS:
   case llvm::Triple::Solaris:
+  case llvm::Triple::UEFI:
   case llvm::Triple::WASI:
   case llvm::Triple::ZOS:
 return false;



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


[clang] [libcxx] [clang][driver] Cleanup UEFI toolchain driver (PR #111473)

2024-12-21 Thread via cfe-commits

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


[clang] [clang] fix uefi target for aarch64 & x86_64 (PR #120632)

2024-12-21 Thread via cfe-commits


@@ -788,16 +789,28 @@ class LLVM_LIBRARY_VISIBILITY ZOSTargetInfo : public 
OSTargetInfo {
 // UEFI target
 template 
 class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo {
+  llvm::Triple Triple;
+
 protected:
   void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
-MacroBuilder &Builder) const override {}
+MacroBuilder &Builder) const override {
+DefineStd(Builder, "uefi", Opts);

Prabhuk wrote:

Merged the clean up PR. @petrhosek's thoughts on DefineMacro over DefineStd is 
sound in my opinion.  Going to merge the predefine PR as well #111719 which we 
can revert/reland if we have significant push back and deal with it in a way 
that it doesn't block this PR.

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


[clang-tools-extra] Added options to readability-implicit-bool-conversion (PR #120087)

2024-12-21 Thread via cfe-commits

https://github.com/4m4n-x-B4w4ne updated 
https://github.com/llvm/llvm-project/pull/120087

>From 03f536888ddc5b7be2514c2d880c6d3119b7f4ee Mon Sep 17 00:00:00 2001
From: 4m4n-x-B4w4ne <125849251+4m4n-x-b4w...@users.noreply.github.com>
Date: Mon, 16 Dec 2024 19:43:42 +0530
Subject: [PATCH 01/31] Update ImplicitBoolConversionCheck.cpp

Added new options in ImplicitBoolConversionCheck CheckConversionToBool and 
CheckConversionFromBool.
---
 .../readability/ImplicitBoolConversionCheck.cpp   | 15 +--
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
index f9fd1d903e231e..517a5d2b982751 100644
--- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
@@ -258,14 +258,17 @@ ImplicitBoolConversionCheck::ImplicitBoolConversionCheck(
 : ClangTidyCheck(Name, Context),
   AllowIntegerConditions(Options.get("AllowIntegerConditions", false)),
   AllowPointerConditions(Options.get("AllowPointerConditions", false)),
-  UseUpperCaseLiteralSuffix(
-  Options.get("UseUpperCaseLiteralSuffix", false)) {}
+  UseUpperCaseLiteralSuffix(Options.get("UseUpperCaseLiteralSuffix", 
false)),
+  CheckConversionsToBool(Options.get("CheckConversionsToBool",true)),
+  CheckConversionsFromBool(Options.get("CheckConversionsFromBool",true)) {}
 
 void ImplicitBoolConversionCheck::storeOptions(
 ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "AllowIntegerConditions", AllowIntegerConditions);
   Options.store(Opts, "AllowPointerConditions", AllowPointerConditions);
   Options.store(Opts, "UseUpperCaseLiteralSuffix", UseUpperCaseLiteralSuffix);
+  Options.store(Opts,"CheckConversionsToBool",CheckConversionsToBool);
+  Options.store(Opts,"CheckConversionsFromBool",CheckConversionsFromBool);
 }
 
 void ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
@@ -358,14 +361,14 @@ void 
ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
 void ImplicitBoolConversionCheck::check(
 const MatchFinder::MatchResult &Result) {
 
-  if (const auto *CastToBool =
-  Result.Nodes.getNodeAs("implicitCastToBool")) {
+  if (CheckConversionsToBool && (const auto *CastToBool =
+  Result.Nodes.getNodeAs("implicitCastToBool"))) {
 const auto *Parent = Result.Nodes.getNodeAs("parentStmt");
 return handleCastToBool(CastToBool, Parent, *Result.Context);
   }
 
-  if (const auto *CastFromBool =
-  Result.Nodes.getNodeAs("implicitCastFromBool")) {
+  if (CheckConversionsFromBool && (const auto *CastFromBool =
+  Result.Nodes.getNodeAs("implicitCastFromBool"))) {
 const auto *NextImplicitCast =
 Result.Nodes.getNodeAs("furtherImplicitCast");
 return handleCastFromBool(CastFromBool, NextImplicitCast, *Result.Context);

>From 16c7c95939b4c0c38ebccbbc6cd1da3739244a24 Mon Sep 17 00:00:00 2001
From: 4m4n-x-B4w4ne <125849251+4m4n-x-b4w...@users.noreply.github.com>
Date: Mon, 16 Dec 2024 19:45:37 +0530
Subject: [PATCH 02/31] Update ImplicitBoolConversionCheck.h

Added CheckConversionToBool and CheckConversionFromBool Options in the header
---
 .../clang-tidy/readability/ImplicitBoolConversionCheck.h| 2 ++
 1 file changed, 2 insertions(+)

diff --git 
a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.h 
b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.h
index 5947f7316e67cc..b0c3c2943e649c 100644
--- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.h
@@ -37,6 +37,8 @@ class ImplicitBoolConversionCheck : public ClangTidyCheck {
   const bool AllowIntegerConditions;
   const bool AllowPointerConditions;
   const bool UseUpperCaseLiteralSuffix;
+  const bool CheckConversionsToBool;
+  const bool CheckConversionsFromBool;
 };
 
 } // namespace clang::tidy::readability

>From 0d6fae8b08a4a365c9295ac8a96de2aba9974c98 Mon Sep 17 00:00:00 2001
From: 4m4n-x-B4w4ne <125849251+4m4n-x-b4w...@users.noreply.github.com>
Date: Mon, 16 Dec 2024 19:48:48 +0530
Subject: [PATCH 03/31] Create implicit-bool-conversion-check.cpp

Added new test to check the new options added in the 
ImplicitBoolConversionCheck.cpp
---
 .../implicit-bool-conversion-check.cpp| 92 +++
 1 file changed, 92 insertions(+)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion-check.cpp

diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion-check.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion-check.cpp
new file mode 100644
index 00..506769d5a57322
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers

[clang] [clang-format] Fix crashes when the macro expansion is empty (PR #119428)

2024-12-21 Thread via cfe-commits

https://github.com/amane-ame updated 
https://github.com/llvm/llvm-project/pull/119428

From 3a4c1a924faef3a7a09126694fcb943bd7083451 Mon Sep 17 00:00:00 2001
From: amane-ame 
Date: Wed, 11 Dec 2024 02:13:43 +0800
Subject: [PATCH 1/7] Fix crashes when the macro expansion is empty

---
 clang/lib/Format/MacroExpander.cpp | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang/lib/Format/MacroExpander.cpp 
b/clang/lib/Format/MacroExpander.cpp
index fd2a16894d643d..ed9e51dfbfef1f 100644
--- a/clang/lib/Format/MacroExpander.cpp
+++ b/clang/lib/Format/MacroExpander.cpp
@@ -233,6 +233,10 @@ MacroExpander::expand(FormatToken *ID,
   if (Result.size() > 1) {
 ++Result[0]->MacroCtx->StartOfExpansion;
 ++Result[Result.size() - 2]->MacroCtx->EndOfExpansion;
+  } else {
+// If the macro expansion is empty, mark the start and end
+Result[0]->MacroCtx->StartOfExpansion = 1;
+Result[0]->MacroCtx->EndOfExpansion = 1;
   }
   return Result;
 }

From 8bf68f87b897bab9da9464d594082be5012afdb1 Mon Sep 17 00:00:00 2001
From: amane-ame 
Date: Sun, 15 Dec 2024 15:15:17 +0800
Subject: [PATCH 2/7] [clang-format] Add a testcase for empty macro

---
 clang/test/Format/empty-macro.cpp | 5 +
 1 file changed, 5 insertions(+)
 create mode 100644 clang/test/Format/empty-macro.cpp

diff --git a/clang/test/Format/empty-macro.cpp 
b/clang/test/Format/empty-macro.cpp
new file mode 100644
index 00..81b255219b0c2b
--- /dev/null
+++ b/clang/test/Format/empty-macro.cpp
@@ -0,0 +1,5 @@
+// RUN: grep -Ev "// *[A-Z-]+:" %s | clang-format -style="{Macros: [A(x)=x]}" \
+// RUN:   | FileCheck -strict-whitespace %s
+
+// CHECK: A()
+A()

From 37a5b1b1877a7292869a93f7bfd4c0ec9814 Mon Sep 17 00:00:00 2001
From: amane-ame 
Date: Mon, 16 Dec 2024 16:30:27 +0800
Subject: [PATCH 3/7] [clang-format] Move the testcase to unittest

---
 clang/test/Format/empty-macro.cpp   |  5 -
 .../unittests/Format/MacroCallReconstructorTest.cpp | 13 +
 2 files changed, 13 insertions(+), 5 deletions(-)
 delete mode 100644 clang/test/Format/empty-macro.cpp

diff --git a/clang/test/Format/empty-macro.cpp 
b/clang/test/Format/empty-macro.cpp
deleted file mode 100644
index 81b255219b0c2b..00
--- a/clang/test/Format/empty-macro.cpp
+++ /dev/null
@@ -1,5 +0,0 @@
-// RUN: grep -Ev "// *[A-Z-]+:" %s | clang-format -style="{Macros: [A(x)=x]}" \
-// RUN:   | FileCheck -strict-whitespace %s
-
-// CHECK: A()
-A()
diff --git a/clang/unittests/Format/MacroCallReconstructorTest.cpp 
b/clang/unittests/Format/MacroCallReconstructorTest.cpp
index b4ee8d0e37efa8..08088fe48fdf6a 100644
--- a/clang/unittests/Format/MacroCallReconstructorTest.cpp
+++ b/clang/unittests/Format/MacroCallReconstructorTest.cpp
@@ -217,6 +217,19 @@ TEST_F(MacroCallReconstructorTest, Identifier) {
   EXPECT_THAT(std::move(Unexp).takeResult(), 
matchesLine(line(U.consume("X";
 }
 
+TEST_F(MacroCallReconstructorTest, EmptyExpansion) {
+  auto Macros = createExpander({"A(x)=y"});
+  Expansion Exp(Lex, *Macros);
+  TokenList Call = Exp.expand("A", {""});
+
+  MacroCallReconstructor Unexp(0, Exp.getUnexpanded());
+  Unexp.addLine(line(Exp.getTokens()));
+  EXPECT_TRUE(Unexp.finished());
+  Matcher U(Call, Lex);
+  EXPECT_THAT(std::move(Unexp).takeResult(),
+  matchesLine(line(U.consume("A()";
+}
+
 TEST_F(MacroCallReconstructorTest, NestedLineWithinCall) {
   auto Macros = createExpander({"C(a)=class X { a; };"});
   Expansion Exp(Lex, *Macros);

From e46f0e059d61fb370c5f76ede99423846f5959c8 Mon Sep 17 00:00:00 2001
From: amane-ame 
Date: Thu, 19 Dec 2024 17:11:16 +0800
Subject: [PATCH 4/7] [clang-format] Fix about Tokens in
 MacroCallReconstructorTest

When the macro expansion is empty, the tok::eof Token should be preserved.
The reason is we have marked the start point and end point on this token in 
MacroExpander::expand.
---
 clang/unittests/Format/MacroCallReconstructorTest.cpp | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/unittests/Format/MacroCallReconstructorTest.cpp 
b/clang/unittests/Format/MacroCallReconstructorTest.cpp
index 08088fe48fdf6a..1364de0727f4e7 100644
--- a/clang/unittests/Format/MacroCallReconstructorTest.cpp
+++ b/clang/unittests/Format/MacroCallReconstructorTest.cpp
@@ -65,7 +65,9 @@ class Expansion {
 }
 Unexpanded[ID] = std::move(UnexpandedLine);
 
-auto Expanded = uneof(Macros.expand(ID, Args));
+auto Expanded = Macros.expand(ID, Args);
+if (Expanded.size() > 1)
+  Expanded = uneof(Expanded);
 Tokens.append(Expanded.begin(), Expanded.end());
 
 TokenList UnexpandedTokens;
@@ -218,7 +220,7 @@ TEST_F(MacroCallReconstructorTest, Identifier) {
 }
 
 TEST_F(MacroCallReconstructorTest, EmptyExpansion) {
-  auto Macros = createExpander({"A(x)=y"});
+  auto Macros = createExpander({"A(x)=x"});
   Expansion Exp(Lex, *Macros);
   TokenList Call = Exp.expand("A", {""});
 

From 6a390e3cf9e7fff9c55d8bc516aa8aba4d15dedf Mon Sep 17 00:00:

[clang-tools-extra] Added options to readability-implicit-bool-conversion (PR #120087)

2024-12-21 Thread via cfe-commits




4m4n-x-B4w4ne wrote:

I have wrote a basic-level test similar to other checks and also have done a 
clean PR build.
Can you please review it?

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


[clang] [clang] Introduce a new UEFI target predefine. (PR #111719)

2024-12-21 Thread via cfe-commits

https://github.com/Prabhuk updated 
https://github.com/llvm/llvm-project/pull/111719

>From 05eab970b59c61b22e8afa1ed9381906ae925c03 Mon Sep 17 00:00:00 2001
From: prabhukr 
Date: Wed, 9 Oct 2024 10:16:58 -0700
Subject: [PATCH 1/6] [clang] Introduce a new UEFI target predefine.

---
 clang/lib/Basic/Targets/OSTargets.h | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index a83d6464e789d6..92c76b303def65 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -783,7 +783,10 @@ template 
 class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo {
 protected:
   void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
-MacroBuilder &Builder) const override {}
+MacroBuilder &Builder) const override {
+Builder.defineMacro("__UEFI__");
+Builder.defineMacro("__PECOFF__");
+  }
 
 public:
   UEFITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)

>From 4ef8bcd3a9019299145b59d4f26cd4307171bed5 Mon Sep 17 00:00:00 2001
From: Prabhuk 
Date: Wed, 13 Nov 2024 10:30:50 -0800
Subject: [PATCH 2/6] Update OSTargets.h

Remove PE_COFF
---
 clang/lib/Basic/Targets/OSTargets.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index 92c76b303def65..5a23eef0117294 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -785,7 +785,6 @@ class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public 
OSTargetInfo {
   void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
 MacroBuilder &Builder) const override {
 Builder.defineMacro("__UEFI__");
-Builder.defineMacro("__PECOFF__");
   }
 
 public:

>From bcccf1f86609a828130c1a9474d10b78c8f212c9 Mon Sep 17 00:00:00 2001
From: Prabhuk 
Date: Wed, 13 Nov 2024 10:36:15 -0800
Subject: [PATCH 3/6] add __UEFI__ to windows predefines

Updating the PE COFF generating windows code path to predefine the new __UEFI__ 
macro.
---
 clang/lib/Basic/Targets/OSTargets.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/lib/Basic/Targets/OSTargets.cpp 
b/clang/lib/Basic/Targets/OSTargets.cpp
index b56e2c7ca9c494..b9edeefa60148e 100644
--- a/clang/lib/Basic/Targets/OSTargets.cpp
+++ b/clang/lib/Basic/Targets/OSTargets.cpp
@@ -259,6 +259,7 @@ static void addVisualCDefines(const LangOptions &Opts, 
MacroBuilder &Builder) {
 
 void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts,
MacroBuilder &Builder) {
+  Builder.defineMacro("__UEFI__");
   Builder.defineMacro("_WIN32");
   if (Triple.isArch64Bit())
 Builder.defineMacro("_WIN64");

>From 2f6af5664bbd6f3cc01dfb7b46f67190dc4efba4 Mon Sep 17 00:00:00 2001
From: prabhukr 
Date: Fri, 20 Dec 2024 10:18:18 -0800
Subject: [PATCH 4/6] Removing the predefine from Windows targets. Keeping it
 only on UEFI.

---
 clang/lib/Basic/Targets/OSTargets.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/lib/Basic/Targets/OSTargets.cpp 
b/clang/lib/Basic/Targets/OSTargets.cpp
index b9edeefa60148e..b56e2c7ca9c494 100644
--- a/clang/lib/Basic/Targets/OSTargets.cpp
+++ b/clang/lib/Basic/Targets/OSTargets.cpp
@@ -259,7 +259,6 @@ static void addVisualCDefines(const LangOptions &Opts, 
MacroBuilder &Builder) {
 
 void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts,
MacroBuilder &Builder) {
-  Builder.defineMacro("__UEFI__");
   Builder.defineMacro("_WIN32");
   if (Triple.isArch64Bit())
 Builder.defineMacro("_WIN64");

>From 4c96e0d1bbae207301aacaee9044f3da7dc8bd3f Mon Sep 17 00:00:00 2001
From: prabhukr 
Date: Sat, 21 Dec 2024 13:16:38 -0800
Subject: [PATCH 5/6] Add a test to check if __UEFI__ is defined for UEFI
 targets.

---
 clang/test/Driver/uefi-defines.c | 6 ++
 1 file changed, 6 insertions(+)
 create mode 100644 clang/test/Driver/uefi-defines.c

diff --git a/clang/test/Driver/uefi-defines.c b/clang/test/Driver/uefi-defines.c
new file mode 100644
index 00..45f27bfdb9fa98
--- /dev/null
+++ b/clang/test/Driver/uefi-defines.c
@@ -0,0 +1,6 @@
+// RUN: %clang -target x86_64-unknown-uefi %s -emit-llvm -S -c -o - | 
FileCheck %s
+
+// CHECK: __UEFI__defined
+#ifdef __UEFI__
+void __UEFI__defined() {}
+#endif

>From 2bdba34c073852622a5adef9147c4c3fbc6e3562 Mon Sep 17 00:00:00 2001
From: prabhukr 
Date: Sat, 21 Dec 2024 14:09:00 -0800
Subject: [PATCH 6/6] Add a second test for __UEFI__ predefine.

---
 clang/test/Preprocessor/init.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c
index 05225c120b13de..3b99204acd7a44 100644
--- a/clang/test/Preprocessor/init.c
+++ b/clang/test/Preprocessor/init.c
@@ -2742,3 +2742,7 @@
 // RISCV64-LINUX: #define __unix__ 1
 // RISCV64-LINUX: #define linux 1
 // RISCV64-LINUX:

[clang] [X86][AVX10.2] Add comments for the avx10_2convertintrin.h file (PR #120766)

2024-12-21 Thread Mikołaj Piróg via cfe-commits

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


[clang] [X86][AVX10.2] Add comments for the avx10_2convertintrin.h file (PR #120766)

2024-12-21 Thread Mikołaj Piróg via cfe-commits


@@ -24,567 +24,3243 @@
   __attribute__((__always_inline__, __nodebug__, __target__("avx10.2-256"),
\
  __min_vector_width__(256)))
 
+/// Convert two 128-bit vectors, \a __A and \a __B, containing packed
+/// single-precision (32-bit) floating-point elements to a 128-bit vector
+/// containing FP16 elements.
+///
+/// \code{.operation}
+/// FOR i := 0 to 7
+///IF i < 4
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4])
+///FI
+/// ENDFOR
+/// \endcode

mikolaj-pirog wrote:

Recent intrinsics (amxfp8intrin.h) also follows this order, as vast majority of 
existing intrinsic do. It shouldn't be problematic to the tooling -- if it is, 
I will fix it (the tooling)

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


[clang] [compiler-rt] [llvm] Single byte coverage with branch coverage (PR #113115)

2024-12-21 Thread NAKAMURA Takumi via cfe-commits

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


[clang] [Coverage] Introduce `getBranchCounterPair()`. NFC. (PR #112702)

2024-12-21 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni updated 
https://github.com/llvm/llvm-project/pull/112702

>From fc697f04fd6c9f3c217ce04e3f1dd082c1f1a705 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi 
Date: Wed, 16 Oct 2024 23:16:53 +0900
Subject: [PATCH 1/4] [Coverage] Introduce `getBranchCounterPair()`. NFC.

This aggregates the generation of branch counter pair as `ExecCnt` and
`SkipCnt`, to aggregate `CounterExpr::subtract`. At the moment:

- This change preserves the behavior of
  `llvm::EnableSingleByteCoverage`. Almost of SingleByteCoverage will
  be cleaned up by coming commits.

- `getBranchCounterPair()` is not called in
  `llvm::EnableSingleByteCoverage`. I will implement the new behavior
  of SingleByteCoverage in it.

- `IsCounterEqual(Out, Par)` is introduced instead of
  `Counter::operator==`. Tweaks would be required for the comparison
  for additional counters.

- Braces around `assert()` is intentional. I will add a statement there.

https://discourse.llvm.org/t/rfc-integrating-singlebytecoverage-with-branch-coverage/82492
---
 clang/lib/CodeGen/CoverageMappingGen.cpp | 177 +--
 1 file changed, 102 insertions(+), 75 deletions(-)

diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 07015834bc84f3..0bfad9cbcbe12b 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -941,6 +941,19 @@ struct CounterCoverageMappingBuilder
 return Counter::getCounter(CounterMap[S]);
   }
 
+  std::pair getBranchCounterPair(const Stmt *S,
+   Counter ParentCnt) {
+Counter ExecCnt = getRegionCounter(S);
+return {ExecCnt, Builder.subtract(ParentCnt, ExecCnt)};
+  }
+
+  bool IsCounterEqual(Counter OutCount, Counter ParentCount) {
+if (OutCount == ParentCount)
+  return true;
+
+return false;
+  }
+
   /// Push a region onto the stack.
   ///
   /// Returns the index on the stack where the region was pushed. This can be
@@ -1592,6 +1605,13 @@ struct CounterCoverageMappingBuilder
 llvm::EnableSingleByteCoverage
 ? getRegionCounter(S->getCond())
 : addCounters(ParentCount, BackedgeCount, BC.ContinueCount);
+auto [ExecCount, ExitCount] =
+(llvm::EnableSingleByteCoverage
+ ? std::make_pair(getRegionCounter(S), Counter::getZero())
+ : getBranchCounterPair(S, CondCount));
+if (!llvm::EnableSingleByteCoverage) {
+  assert(ExecCount.isZero() || ExecCount == BodyCount);
+}
 propagateCounts(CondCount, S->getCond());
 adjustForOutOfOrderTraversal(getEnd(S));
 
@@ -1600,13 +1620,11 @@ struct CounterCoverageMappingBuilder
 if (Gap)
   fillGapAreaWithCount(Gap->getBegin(), Gap->getEnd(), BodyCount);
 
-Counter OutCount =
-llvm::EnableSingleByteCoverage
-? getRegionCounter(S)
-: addCounters(BC.BreakCount,
-  subtractCounters(CondCount, BodyCount));
+Counter OutCount = llvm::EnableSingleByteCoverage
+   ? getRegionCounter(S)
+   : addCounters(BC.BreakCount, ExitCount);
 
-if (OutCount != ParentCount) {
+if (!IsCounterEqual(OutCount, ParentCount)) {
   pushRegion(OutCount);
   GapRegionCounter = OutCount;
   if (BodyHasTerminateStmt)
@@ -1615,8 +1633,7 @@ struct CounterCoverageMappingBuilder
 
 // Create Branch Region around condition.
 if (!llvm::EnableSingleByteCoverage)
-  createBranchRegion(S->getCond(), BodyCount,
- subtractCounters(CondCount, BodyCount));
+  createBranchRegion(S->getCond(), BodyCount, ExitCount);
   }
 
   void VisitDoStmt(const DoStmt *S) {
@@ -1645,22 +1662,26 @@ struct CounterCoverageMappingBuilder
 Counter CondCount = llvm::EnableSingleByteCoverage
 ? getRegionCounter(S->getCond())
 : addCounters(BackedgeCount, BC.ContinueCount);
+auto [ExecCount, ExitCount] =
+(llvm::EnableSingleByteCoverage
+ ? std::make_pair(getRegionCounter(S), Counter::getZero())
+ : getBranchCounterPair(S, CondCount));
+if (!llvm::EnableSingleByteCoverage) {
+  assert(ExecCount.isZero() || ExecCount == BodyCount);
+}
 propagateCounts(CondCount, S->getCond());
 
-Counter OutCount =
-llvm::EnableSingleByteCoverage
-? getRegionCounter(S)
-: addCounters(BC.BreakCount,
-  subtractCounters(CondCount, BodyCount));
-if (OutCount != ParentCount) {
+Counter OutCount = llvm::EnableSingleByteCoverage
+   ? getRegionCounter(S)
+   : addCounters(BC.BreakCount, ExitCount);
+if (!IsCounterEqual(OutCount, ParentCount)) {
   pushRegion(OutCount);
   GapRegionCounter = OutCount;
 }
 
 // Create Branch Region around condition.
 if (!llvm::EnableSingleByteCoverage)
-

[clang] [Coverage] Introduce the type `CounterPair` for RegionCounterMap. NFC. (PR #112724)

2024-12-21 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni updated 
https://github.com/llvm/llvm-project/pull/112724

>From e4172ca273a6fdfcbfc4662c9e37276ef34c2df4 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi 
Date: Thu, 17 Oct 2024 00:32:26 +0900
Subject: [PATCH 1/3] Introduce the type `CounterPair` for RegionCounterMap

`CounterPair` can hold `` instead of current
`unsigned`, to hold also the counter number of SkipPath. For now, this
change provides the skeleton and only `CounterPair::first` is used.

Each counter number can have `None` to suppress emitting counter
increment. `second` is initialized as `None` by default, since most
`Stmt*` don't have a pair of counters.

This change also provides stubs for the verifyer. I'll provide the
impl of verifier for `+Asserts` later.

`markStmtAsUsed(bool, Stmt*)` may be used to inform that other side
counter may not emitted.

`markStmtMaybeUsed(S)` may be used for the `Stmt` and its inner will
be excluded for emission in the case of skipping by constant
folding. I put it into places where I found.

`verifyCounterMap()` will check the coverage map the counter map and
can be used to report inconsistency.

These verifier methods shall be eliminated in `-Asserts`.

https://discourse.llvm.org/t/rfc-integrating-singlebytecoverage-with-branch-coverage/82492
---
 clang/lib/CodeGen/CGDecl.cpp |  9 -
 clang/lib/CodeGen/CGExpr.cpp |  1 +
 clang/lib/CodeGen/CGExprScalar.cpp   |  9 +++--
 clang/lib/CodeGen/CGStmt.cpp |  3 +++
 clang/lib/CodeGen/CodeGenFunction.cpp|  3 +++
 clang/lib/CodeGen/CodeGenFunction.h  |  6 ++
 clang/lib/CodeGen/CodeGenModule.h| 19 +++
 clang/lib/CodeGen/CodeGenPGO.cpp | 14 ++
 clang/lib/CodeGen/CodeGenPGO.h   | 17 +++--
 clang/lib/CodeGen/CoverageMappingGen.cpp |  6 +++---
 clang/lib/CodeGen/CoverageMappingGen.h   |  5 +++--
 11 files changed, 78 insertions(+), 14 deletions(-)

diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 563f728e29d781..ed5f41b624b62b 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -362,6 +362,8 @@ CodeGenFunction::AddInitializerToStaticVarDecl(const 
VarDecl &D,
 return GV;
   }
 
+  PGO.markStmtMaybeUsed(D.getInit()); // FIXME: Too lazy
+
 #ifndef NDEBUG
   CharUnits VarSize = CGM.getContext().getTypeSizeInChars(D.getType()) +
   D.getFlexibleArrayInitChars(getContext());
@@ -1869,7 +1871,10 @@ void CodeGenFunction::EmitAutoVarInit(const 
AutoVarEmission &emission) {
   // If we are at an unreachable point, we don't need to emit the initializer
   // unless it contains a label.
   if (!HaveInsertPoint()) {
-if (!Init || !ContainsLabel(Init)) return;
+if (!Init || !ContainsLabel(Init)) {
+  PGO.markStmtMaybeUsed(Init);
+  return;
+}
 EnsureInsertPoint();
   }
 
@@ -1978,6 +1983,8 @@ void CodeGenFunction::EmitAutoVarInit(const 
AutoVarEmission &emission) {
 return EmitExprAsInit(Init, &D, lv, capturedByInit);
   }
 
+  PGO.markStmtMaybeUsed(Init);
+
   if (!emission.IsConstantAggregate) {
 // For simple scalar/complex initialization, store the value directly.
 LValue lv = MakeAddrLValue(Loc, type);
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 52d2f6d52abf94..2fd6b02a3395ee 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -5134,6 +5134,7 @@ std::optional 
HandleConditionalOperatorLValueSimpleCase(
   // If the true case is live, we need to track its region.
   if (CondExprBool)
 CGF.incrementProfileCounter(E);
+  CGF.markStmtMaybeUsed(Dead);
   // If a throw expression we emit it and return an undefined lvalue
   // because it can't be used.
   if (auto *ThrowExpr = dyn_cast(Live->IgnoreParens())) {
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index b7f5b932c56b6f..74e93f889f4261 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -4982,8 +4982,10 @@ Value *ScalarExprEmitter::VisitBinLAnd(const 
BinaryOperator *E) {
 }
 
 // 0 && RHS: If it is safe, just elide the RHS, and return 0/false.
-if (!CGF.ContainsLabel(E->getRHS()))
+if (!CGF.ContainsLabel(E->getRHS())) {
+  CGF.markStmtMaybeUsed(E->getRHS());
   return llvm::Constant::getNullValue(ResTy);
+}
   }
 
   // If the top of the logical operator nest, reset the MCDC temp to 0.
@@ -5122,8 +5124,10 @@ Value *ScalarExprEmitter::VisitBinLOr(const 
BinaryOperator *E) {
 }
 
 // 1 || RHS: If it is safe, just elide the RHS, and return 1/true.
-if (!CGF.ContainsLabel(E->getRHS()))
+if (!CGF.ContainsLabel(E->getRHS())) {
+  CGF.markStmtMaybeUsed(E->getRHS());
   return llvm::ConstantInt::get(ResTy, 1);
+}
   }
 
   // If the top of the logical operator nest, reset the MCDC temp to 0.
@@ -5247,6 +5251,7 @@ VisitAbstractConditionalOperator

[clang-tools-extra] [clang-tidy] Added bugprone-exception-rethrow check (PR #86448)

2024-12-21 Thread Denis Mikhailov via cfe-commits


@@ -0,0 +1,103 @@
+// RUN: %check_clang_tidy %s bugprone-exception-rethrow %t -- -- -fexceptions
+
+struct exception {};
+
+namespace std {
+  template 
+  T&& move(T &&x) {
+return static_cast(x);
+  }
+}
+
+void correct() {
+  try {
+  throw exception();
+  } catch(const exception &) {
+  throw;
+  }
+}
+
+void correct2() {
+  try {
+  throw exception();
+  } catch(const exception &e) {
+  try {
+throw exception();
+  } catch(...) {}
+  }
+}
+
+void not_correct() {
+  try {
+  throw exception();
+  } catch(const exception &e) {
+  throw e;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: throwing a copy of the caught 
'exception' exception, remove the argument to throw the original exception 
object [bugprone-exception-rethrow]
+  }
+}
+
+void not_correct2() {
+  try {
+  throw exception();
+  } catch(const exception &e) {
+  throw (e);
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: throwing a copy of the caught 
'exception' exception, remove the argument to throw the original exception 
object [bugprone-exception-rethrow]
+  }
+}
+
+void not_correct3() {
+  try {
+  throw exception();
+  } catch(const exception &e) {
+  throw exception(e);
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: throwing a copy of the caught 
'exception' exception, remove the argument to throw the original exception 
object [bugprone-exception-rethrow]
+  }
+}
+
+void not_correct4() {
+  try {
+  throw exception();
+  } catch(exception &e) {
+  throw std::move(e);
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: throwing a copy of the caught 
'exception' exception, remove the argument to throw the original exception 
object [bugprone-exception-rethrow]
+  }
+}
+
+void not_correct5() {
+  try {
+  throw 5;
+  } catch(const int &e) {
+  throw e;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: throwing a copy of the caught 
'int' exception, remove the argument to throw the original exception object 
[bugprone-exception-rethrow]
+  }
+}
+

denzor200 wrote:

```
void not_correct6() {
  try {
  throw exception();
  } catch(const exception &e) {
  exception e1 = e;
  throw e1;
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: throwing a copy of the caught 
'exception' exception, remove the argument to throw the original exception 
object [bugprone-exception-rethrow]
  }
}
```
please

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


[clang-tools-extra] [clang-tidy] Add readability-string-view-substr check (PR #120055)

2024-12-21 Thread Denis Mikhailov via cfe-commits


@@ -0,0 +1,108 @@
+// RUN: %check_clang_tidy %s readability-stringview-substr %t
+
+namespace std {
+template 
+class basic_string_view {
+public:
+  using size_type = unsigned long;
+  static constexpr size_type npos = -1;
+
+  basic_string_view(const char*) {}
+  basic_string_view substr(size_type pos, size_type count = npos) const { 
return *this; }
+  void remove_prefix(size_type n) {}
+  void remove_suffix(size_type n) {}
+  size_type length() const { return 0; }
+  basic_string_view& operator=(const basic_string_view&) { return *this; }
+};
+
+using string_view = basic_string_view;
+} // namespace std
+
+void test_basic() {
+  std::string_view sv("test");
+  std::string_view sv1("test");
+  std::string_view sv2("test");
+
+  // Should match: remove_prefix
+  sv = sv.substr(5);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer 'remove_prefix' over 
'substr' for removing characters from the start [readability-stringview-substr]
+  // CHECK-FIXES: sv.remove_prefix(5)
+
+  // Should match: remove_suffix
+  sv = sv.substr(0, sv.length() - 3);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer 'remove_suffix' over 
'substr' for removing characters from the end [readability-stringview-substr]
+  // CHECK-FIXES: sv.remove_suffix(3)
+
+  // Should match: remove_suffix with complex expression
+  sv = sv.substr(0, sv.length() - (3 + 2));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer 'remove_suffix' over 
'substr' for removing characters from the end [readability-stringview-substr]
+  // CHECK-FIXES: sv.remove_suffix((3 + 2))
+}
+
+void test_copies() {
+  std::string_view sv("test");
+  std::string_view sv1("test");
+  std::string_view sv2("test");
+
+  // Should match: remove redundant self copies
+  sv = sv.substr(0, sv.length());
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: redundant self-copy 
[readability-stringview-substr]
+
+  sv = sv.substr(0, sv.length() - 0);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: redundant self-copy 
[readability-stringview-substr]
+
+  // Should match: simplify copies between different variables
+  sv1 = sv.substr(0, sv.length());
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer direct copy over substr 
[readability-stringview-substr]
+  // CHECK-FIXES: sv1 = sv
+
+  sv2 = sv.substr(0, sv.length() - 0);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer direct copy over substr 
[readability-stringview-substr]
+  // CHECK-FIXES: sv2 = sv
+}
+
+void test_zero_forms() {
+  std::string_view sv("test");
+  const int kZero = 0;
+  constexpr std::string_view::size_type Zero = 0;
+  #define START_POS 0
+
+  // Should match: various forms of zero in first argument
+  sv = sv.substr(kZero, sv.length() - 3);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer 'remove_suffix' over 
'substr' for removing characters from the end [readability-stringview-substr]
+  // CHECK-FIXES: sv.remove_suffix(3)
+
+  sv = sv.substr(Zero, sv.length() - 3);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer 'remove_suffix' over 
'substr' for removing characters from the end [readability-stringview-substr]
+  // CHECK-FIXES: sv.remove_suffix(3)
+
+  sv = sv.substr(START_POS, sv.length() - 3);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer 'remove_suffix' over 
'substr' for removing characters from the end [readability-stringview-substr]
+  // CHECK-FIXES: sv.remove_suffix(3)
+
+  sv = sv.substr((0), sv.length() - 3);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer 'remove_suffix' over 
'substr' for removing characters from the end [readability-stringview-substr]
+  // CHECK-FIXES: sv.remove_suffix(3)
+
+  sv = sv.substr(0u, sv.length() - 3);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer 'remove_suffix' over 
'substr' for removing characters from the end [readability-stringview-substr]
+  // CHECK-FIXES: sv.remove_suffix(3)
+
+  sv = sv.substr(0UL, sv.length() - 3);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer 'remove_suffix' over 
'substr' for removing characters from the end [readability-stringview-substr]
+  // CHECK-FIXES: sv.remove_suffix(3)
+}
+
+void test_should_not_match() {
+  std::string_view sv("test");
+  std::string_view sv1("test");
+  std::string_view sv2("test");
+
+  // No match: substr used for prefix or mid-view
+  sv = sv.substr(1, sv.length() - 3); // No warning
+
+  // No match: Different string_views
+  sv = sv2.substr(0, sv2.length() - 3); // No warning

denzor200 wrote:

Why no match? I don't see any trouble with
```
sv = sv2;
sv.remove_suffix(3);
```
Of couse still no match for const version of `sv`

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


[clang-tools-extra] [clang-tidy] Add readability-string-view-substr check (PR #120055)

2024-12-21 Thread Denis Mikhailov via cfe-commits


@@ -0,0 +1,108 @@
+// RUN: %check_clang_tidy %s readability-stringview-substr %t
+
+namespace std {
+template 
+class basic_string_view {
+public:
+  using size_type = unsigned long;
+  static constexpr size_type npos = -1;
+
+  basic_string_view(const char*) {}
+  basic_string_view substr(size_type pos, size_type count = npos) const { 
return *this; }
+  void remove_prefix(size_type n) {}
+  void remove_suffix(size_type n) {}
+  size_type length() const { return 0; }

denzor200 wrote:

Please add `size_type size() const { return 0; }` and unit-tests for it

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


[clang-tools-extra] [clang-tidy] Add readability-use-span-first-last check (PR #118074)

2024-12-21 Thread Denis Mikhailov via cfe-commits


@@ -0,0 +1,149 @@
+// RUN: %check_clang_tidy -std=c++20 %s readability-use-span-first-last %t
+
+namespace std {
+template 
+class span {
+  T* ptr;
+  __SIZE_TYPE__ len;
+
+public:
+  span(T* p, __SIZE_TYPE__ l) : ptr(p), len(l) {}
+  
+  span subspan(__SIZE_TYPE__ offset) const {
+return span(ptr + offset, len - offset);
+  }
+  
+  span subspan(__SIZE_TYPE__ offset, __SIZE_TYPE__ count) const {
+return span(ptr + offset, count);
+  }
+
+  span first(__SIZE_TYPE__ count) const {
+return span(ptr, count);
+  }
+
+  span last(__SIZE_TYPE__ count) const {
+return span(ptr + (len - count), count);
+  }
+
+  __SIZE_TYPE__ size() const { return len; }
+};
+} // namespace std
+
+// Add here, right after the std namespace closes:
+namespace std::ranges {
+  template
+  __SIZE_TYPE__ size(const span& s) { return s.size(); }
+}
+
+void test() {
+  int arr[] = {1, 2, 3, 4, 5};
+  std::span s(arr, 5);
+
+  auto sub1 = s.subspan(0, 3);
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer 'span::first()' over 
'subspan()'
+  // CHECK-FIXES: auto sub1 = s.first(3);
+
+  auto sub2 = s.subspan(s.size() - 2);
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer 'span::last()' over 
'subspan()'
+  // CHECK-FIXES: auto sub2 = s.last(2);
+
+  __SIZE_TYPE__ n = 2;
+  auto sub3 = s.subspan(0, n);
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer 'span::first()' over 
'subspan()'
+  // CHECK-FIXES: auto sub3 = s.first(n);
+
+  auto sub4 = s.subspan(1, 2);  // No warning
+  auto sub5 = s.subspan(2); // No warning
+
+
+#define ZERO 0
+#define TWO 2
+#define SIZE_MINUS(s, n) s.size() - n
+#define MAKE_SUBSPAN(obj, n) obj.subspan(0, n)
+#define MAKE_LAST_N(obj, n) obj.subspan(obj.size() - n)
+
+  auto sub6 = s.subspan(SIZE_MINUS(s, 2));
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer 'span::last()' over 
'subspan()'
+  // CHECK-FIXES: auto sub6 = s.last(2);
+
+  auto sub7 = MAKE_SUBSPAN(s, 3);
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: prefer 'span::first()' over 
'subspan()'
+  // CHECK-FIXES: auto sub7 = s.first(3);
+
+  auto sub8 = MAKE_LAST_N(s, 2);
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: prefer 'span::last()' over 
'subspan()'
+  // CHECK-FIXES: auto sub8 = s.last(2);
+
+}
+
+template 
+void testTemplate() {
+  T arr[] = {1, 2, 3, 4, 5};
+  std::span s(arr, 5);
+
+  auto sub1 = s.subspan(0, 3);
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer 'span::first()' over 
'subspan()'
+  // CHECK-FIXES: auto sub1 = s.first(3);
+
+  auto sub2 = s.subspan(s.size() - 2);
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer 'span::last()' over 
'subspan()'
+  // CHECK-FIXES: auto sub2 = s.last(2);
+
+  __SIZE_TYPE__ n = 2;
+  auto sub3 = s.subspan(0, n);
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer 'span::first()' over 
'subspan()'
+  // CHECK-FIXES: auto sub3 = s.first(n);
+
+  auto sub4 = s.subspan(1, 2);  // No warning
+  auto sub5 = s.subspan(2); // No warning
+
+  auto complex = s.subspan(0 + (s.size() - 2), 3);  // No warning
+
+  auto complex2 = s.subspan(100 + (s.size() - 2));  // No warning
+}
+
+// Test instantiation
+void testInt() {
+  testTemplate();
+}
+
+void test_ranges() {
+  int arr[] = {1, 2, 3, 4, 5};
+  std::span s(arr, 5);
+
+  auto sub1 = s.subspan(std::ranges::size(s) - 2);
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer 'span::last()' over 
'subspan()'
+  // CHECK-FIXES: auto sub1 = s.last(2);
+
+  __SIZE_TYPE__ n = 2;
+  auto sub2 = s.subspan(std::ranges::size(s) - n);
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer 'span::last()' over 
'subspan()'
+  // CHECK-FIXES: auto sub2 = s.last(n);
+}
+
+void test_different_spans() {
+  int arr1[] = {1, 2, 3, 4, 5};
+  int arr2[] = {6, 7, 8, 9, 10};
+  std::span s1(arr1, 5);
+  std::span s2(arr2, 5);
+
+  // These should NOT trigger warnings as they use size() from a different span
+  auto sub1 = s1.subspan(s2.size() - 2); // No warning
+  auto sub2 = s2.subspan(s1.size() - 3); // No warning
+  
+  // Also check with std::ranges::size
+  auto sub3 = s1.subspan(std::ranges::size(s2) - 2);  // No warning
+  auto sub4 = s2.subspan(std::ranges::size(s1) - 3);  // No warning
+
+  // Mixed usage should also not trigger
+  auto sub5 = s1.subspan(s2.size() - s1.size());  // No warning
+  
+  // Verify that correct usage still triggers warnings
+  auto good1 = s1.subspan(s1.size() - 2);
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer 'span::last()' over 
'subspan()'
+  // CHECK-FIXES: auto good1 = s1.last(2);
+  
+  auto good2 = s2.subspan(std::ranges::size(s2) - 3);
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer 'span::last()' over 
'subspan()'
+  // CHECK-FIXES: auto good2 = s2.last(3);
+}

denzor200 wrote:

please add `test_span_of_bytes`:
```
  std::byte arr[] = {0x1, 0x2, 0x3, 0x4, 0x5};
  std::span s(arr, 5);

  // ...

   auto sub2 = s.subspan(s.size_bytes() - 2);
  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: prefer 'span::last()'

[clang] [clang-format] Fix crashes when the macro expansion is empty (PR #119428)

2024-12-21 Thread Owen Pan via cfe-commits


@@ -217,6 +219,31 @@ TEST_F(MacroCallReconstructorTest, Identifier) {
   EXPECT_THAT(std::move(Unexp).takeResult(), 
matchesLine(line(U.consume("X";
 }
 
+TEST_F(MacroCallReconstructorTest, IdentifierObject) {

owenca wrote:

How about`EmptyDefinition` instead of `IdentifierObject`?

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


[clang] [clang-format] Fix crashes when the macro expansion is empty (PR #119428)

2024-12-21 Thread Owen Pan via cfe-commits

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


[clang] [clang-format] Fix crashes when the macro expansion is empty (PR #119428)

2024-12-21 Thread Owen Pan via cfe-commits

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


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


[clang] [clang][bytecode] Create local scopes for if then/else statements (PR #120852)

2024-12-21 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/120852

In case those aren't compound statements.

>From a2cf825d002c867804bb65e6f156a87c8da6b07d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sat, 21 Dec 2024 20:04:44 +0100
Subject: [PATCH] [clang][bytecode] Create local scopes for if then/else
 statements

In case those aren't compound statements.
---
 clang/lib/AST/ByteCode/Compiler.cpp | 27 +--
 clang/test/AST/ByteCode/if.cpp  | 27 +++
 2 files changed, 48 insertions(+), 6 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 59c77f0ce78d2b..68c75b01e6f6df 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -4974,20 +4974,35 @@ template  bool 
Compiler::visitIfStmt(const IfStmt *IS) {
 LabelTy LabelEnd = this->getLabel();
 if (!this->jumpFalse(LabelElse))
   return false;
-if (!visitStmt(IS->getThen()))
-  return false;
+{
+  LocalScope ThenScope(this);
+  if (!visitStmt(IS->getThen()))
+return false;
+  if (!ThenScope.destroyLocals())
+return false;
+}
 if (!this->jump(LabelEnd))
   return false;
 this->emitLabel(LabelElse);
-if (!visitStmt(Else))
-  return false;
+{
+  LocalScope ElseScope(this);
+  if (!visitStmt(Else))
+return false;
+  if (!ElseScope.destroyLocals())
+return false;
+}
 this->emitLabel(LabelEnd);
   } else {
 LabelTy LabelEnd = this->getLabel();
 if (!this->jumpFalse(LabelEnd))
   return false;
-if (!visitStmt(IS->getThen()))
-  return false;
+{
+  LocalScope ThenScope(this);
+  if (!visitStmt(IS->getThen()))
+return false;
+  if (!ThenScope.destroyLocals())
+return false;
+}
 this->emitLabel(LabelEnd);
   }
 
diff --git a/clang/test/AST/ByteCode/if.cpp b/clang/test/AST/ByteCode/if.cpp
index 540cb76fbaac3c..c48b2b8d378c85 100644
--- a/clang/test/AST/ByteCode/if.cpp
+++ b/clang/test/AST/ByteCode/if.cpp
@@ -76,3 +76,30 @@ namespace IfScope {
   }
   static_assert(foo() == 13, "");
 }
+
+namespace IfScope2 {
+  struct __bit_iterator {
+unsigned __ctz_;
+  };
+  constexpr void __fill_n_bool(__bit_iterator) {}
+
+  constexpr void fill_n(__bit_iterator __first) {
+if (false)
+  __fill_n_bool(__first);
+else
+  __fill_n_bool(__first);
+  }
+
+  struct bitset{
+constexpr void reset() {
+  auto m = __bit_iterator(8);
+  fill_n(m);
+}
+  };
+  consteval bool foo() {
+bitset v;
+v.reset();
+return true;
+  }
+  static_assert(foo());
+}

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


[clang] [clang][bytecode] Create local scopes for if then/else statements (PR #120852)

2024-12-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

In case those aren't compound statements.

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


2 Files Affected:

- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+21-6) 
- (modified) clang/test/AST/ByteCode/if.cpp (+27) 


``diff
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 59c77f0ce78d2b..68c75b01e6f6df 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -4974,20 +4974,35 @@ template  bool 
Compiler::visitIfStmt(const IfStmt *IS) {
 LabelTy LabelEnd = this->getLabel();
 if (!this->jumpFalse(LabelElse))
   return false;
-if (!visitStmt(IS->getThen()))
-  return false;
+{
+  LocalScope ThenScope(this);
+  if (!visitStmt(IS->getThen()))
+return false;
+  if (!ThenScope.destroyLocals())
+return false;
+}
 if (!this->jump(LabelEnd))
   return false;
 this->emitLabel(LabelElse);
-if (!visitStmt(Else))
-  return false;
+{
+  LocalScope ElseScope(this);
+  if (!visitStmt(Else))
+return false;
+  if (!ElseScope.destroyLocals())
+return false;
+}
 this->emitLabel(LabelEnd);
   } else {
 LabelTy LabelEnd = this->getLabel();
 if (!this->jumpFalse(LabelEnd))
   return false;
-if (!visitStmt(IS->getThen()))
-  return false;
+{
+  LocalScope ThenScope(this);
+  if (!visitStmt(IS->getThen()))
+return false;
+  if (!ThenScope.destroyLocals())
+return false;
+}
 this->emitLabel(LabelEnd);
   }
 
diff --git a/clang/test/AST/ByteCode/if.cpp b/clang/test/AST/ByteCode/if.cpp
index 540cb76fbaac3c..c48b2b8d378c85 100644
--- a/clang/test/AST/ByteCode/if.cpp
+++ b/clang/test/AST/ByteCode/if.cpp
@@ -76,3 +76,30 @@ namespace IfScope {
   }
   static_assert(foo() == 13, "");
 }
+
+namespace IfScope2 {
+  struct __bit_iterator {
+unsigned __ctz_;
+  };
+  constexpr void __fill_n_bool(__bit_iterator) {}
+
+  constexpr void fill_n(__bit_iterator __first) {
+if (false)
+  __fill_n_bool(__first);
+else
+  __fill_n_bool(__first);
+  }
+
+  struct bitset{
+constexpr void reset() {
+  auto m = __bit_iterator(8);
+  fill_n(m);
+}
+  };
+  consteval bool foo() {
+bitset v;
+v.reset();
+return true;
+  }
+  static_assert(foo());
+}

``




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


[clang] 1e146df - [Sema] Migrate away from PointerUnion::{is,get} (NFC) (#120829)

2024-12-21 Thread via cfe-commits

Author: Kazu Hirata
Date: 2024-12-21T08:17:41-08:00
New Revision: 1e146dfb4fc82229c17ba5a7da847d87de214351

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

LOG: [Sema] Migrate away from PointerUnion::{is,get} (NFC) (#120829)

Note that PointerUnion::{is,get} have been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //isa, cast and the llvm::dyn_cast

I'm moving the definitions of several functions to SemaConcept.cpp
because llvm::cast requires the full definitions of
NormalizedConstraintPair, which is used like so:

using CompoundConstraint = llvm::PointerIntPair;

Added: 


Modified: 
clang/include/clang/Sema/SemaConcept.h
clang/lib/Sema/SemaConcept.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/SemaConcept.h 
b/clang/include/clang/Sema/SemaConcept.h
index fa5309a597b3a5..5c599a70532f63 100644
--- a/clang/include/clang/Sema/SemaConcept.h
+++ b/clang/include/clang/Sema/SemaConcept.h
@@ -135,31 +135,20 @@ struct NormalizedConstraint {
 return *this;
   }
 
-  bool isAtomic() const { return Constraint.is(); }
+  bool isAtomic() const { return llvm::isa(Constraint); }
   bool isFoldExpanded() const {
-return Constraint.is();
+return llvm::isa(Constraint);
   }
-  bool isCompound() const { return Constraint.is(); }
+  bool isCompound() const { return llvm::isa(Constraint); }
 
-  CompoundConstraintKind getCompoundKind() const {
-assert(isCompound() && "getCompoundKind on a non-compound constraint..");
-return Constraint.get().getInt();
-  }
+  CompoundConstraintKind getCompoundKind() const;
 
   NormalizedConstraint &getLHS() const;
   NormalizedConstraint &getRHS() const;
 
-  AtomicConstraint *getAtomicConstraint() const {
-assert(isAtomic() &&
-   "getAtomicConstraint called on non-atomic constraint.");
-return Constraint.get();
-  }
+  AtomicConstraint *getAtomicConstraint() const;
 
-  FoldExpandedConstraint *getFoldExpandedConstraint() const {
-assert(isFoldExpanded() &&
-   "getFoldExpandedConstraint called on non-fold-expanded 
constraint.");
-return Constraint.get();
-  }
+  FoldExpandedConstraint *getFoldExpandedConstraint() const;
 
 private:
   static std::optional

diff  --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index ff1df7b71b1a4f..539de00bd104f5 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -1958,3 +1958,21 @@ 
concepts::TypeRequirement::TypeRequirement(TypeSourceInfo *T) :
 Value(T),
 Status(T->getType()->isInstantiationDependentType() ? SS_Dependent
 : SS_Satisfied) {}
+
+NormalizedConstraint::CompoundConstraintKind
+NormalizedConstraint::getCompoundKind() const {
+  assert(isCompound() && "getCompoundKind on a non-compound constraint..");
+  return cast(Constraint).getInt();
+}
+
+AtomicConstraint *NormalizedConstraint::getAtomicConstraint() const {
+  assert(isAtomic() && "getAtomicConstraint called on non-atomic constraint.");
+  return cast(Constraint);
+}
+
+FoldExpandedConstraint *
+NormalizedConstraint::getFoldExpandedConstraint() const {
+  assert(isFoldExpanded() &&
+ "getFoldExpandedConstraint called on non-fold-expanded constraint.");
+  return cast(Constraint);
+}



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


[clang] [Sema] Migrate away from PointerUnion::{is, get} (NFC) (PR #120829)

2024-12-21 Thread Kazu Hirata via cfe-commits

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


[clang] [Clang][Comments] Allow HTML tags across multiple lines (PR #120843)

2024-12-21 Thread via cfe-commits

https://github.com/Nerixyz created 
https://github.com/llvm/llvm-project/pull/120843

HTML starting tags that span multiple lines were previously not allowed (or 
rather, only the starting line was lexed as HTML). Doxygen allows those tags.

This PR allows the starting tags to span multiple lines. They can't span 
multiple (C-)Comments, though (it's likely a user-error). Multiple BCPL 
comments are fine as those are single lines (shown below).

Example:

```c
/// Aaab
int Test;
```

Fixes #28321.

>From 589388b36e158efcde1c7f2cc228442576e407b7 Mon Sep 17 00:00:00 2001
From: Nerixyz 
Date: Sat, 21 Dec 2024 16:23:32 +0100
Subject: [PATCH] [Clang][Comments] Allow HTML tags across multiple lines

---
 clang/lib/AST/CommentLexer.cpp|  69 +--
 clang/test/AST/ast-dump-comment.cpp   |  13 +++
 clang/unittests/AST/CommentLexer.cpp  | 123 ++
 clang/unittests/AST/CommentParser.cpp |  23 ++---
 4 files changed, 211 insertions(+), 17 deletions(-)

diff --git a/clang/lib/AST/CommentLexer.cpp b/clang/lib/AST/CommentLexer.cpp
index ec9a5b480aa295..804be89a8d4ddc 100644
--- a/clang/lib/AST/CommentLexer.cpp
+++ b/clang/lib/AST/CommentLexer.cpp
@@ -196,6 +196,15 @@ const char *skipWhitespace(const char *BufferPtr, const 
char *BufferEnd) {
   return BufferEnd;
 }
 
+const char *skipHorizontalWhitespace(const char *BufferPtr,
+ const char *BufferEnd) {
+  for (; BufferPtr != BufferEnd; ++BufferPtr) {
+if (!isHorizontalWhitespace(*BufferPtr))
+  return BufferPtr;
+  }
+  return BufferEnd;
+}
+
 bool isWhitespace(const char *BufferPtr, const char *BufferEnd) {
   return skipWhitespace(BufferPtr, BufferEnd) == BufferEnd;
 }
@@ -637,17 +646,41 @@ void Lexer::setupAndLexHTMLStartTag(Token &T) {
   formTokenWithChars(T, TagNameEnd, tok::html_start_tag);
   T.setHTMLTagStartName(Name);
 
-  BufferPtr = skipWhitespace(BufferPtr, CommentEnd);
+  BufferPtr = skipHorizontalWhitespace(BufferPtr, CommentEnd);
+  if (BufferPtr == CommentEnd) { // in BCPL comments
+State = LS_HTMLStartTag;
+return;
+  }
 
   const char C = *BufferPtr;
   if (BufferPtr != CommentEnd &&
-  (C == '>' || C == '/' || isHTMLIdentifierStartingCharacter(C)))
+  (C == '>' || C == '/' || isVerticalWhitespace(C) ||
+   isHTMLIdentifierStartingCharacter(C)))
 State = LS_HTMLStartTag;
 }
 
 void Lexer::lexHTMLStartTag(Token &T) {
   assert(State == LS_HTMLStartTag);
 
+  // Skip leading whitespace and comment decorations
+  while (isVerticalWhitespace(*BufferPtr)) {
+BufferPtr = skipNewline(BufferPtr, CommentEnd);
+
+if (CommentState == LCS_InsideCComment)
+  skipLineStartingDecorations();
+
+BufferPtr = skipHorizontalWhitespace(BufferPtr, CommentEnd);
+if (BufferPtr == CommentEnd) {
+  // HTML starting tags must be defined in a single comment block.
+  // It's likely a user-error where they forgot to terminate the comment.
+  State = LS_Normal;
+  // Since at least one newline was skipped and one token needs to be 
lexed,
+  // return a newline.
+  formTokenWithChars(T, BufferPtr, tok::newline);
+  return;
+}
+  }
+
   const char *TokenPtr = BufferPtr;
   char C = *TokenPtr;
   if (isHTMLIdentifierCharacter(C)) {
@@ -693,14 +726,13 @@ void Lexer::lexHTMLStartTag(Token &T) {
 
   // Now look ahead and return to normal state if we don't see any HTML tokens
   // ahead.
-  BufferPtr = skipWhitespace(BufferPtr, CommentEnd);
+  BufferPtr = skipHorizontalWhitespace(BufferPtr, CommentEnd);
   if (BufferPtr == CommentEnd) {
-State = LS_Normal;
 return;
   }
 
   C = *BufferPtr;
-  if (!isHTMLIdentifierStartingCharacter(C) &&
+  if (!isHTMLIdentifierStartingCharacter(C) && !isVerticalWhitespace(C) &&
   C != '=' && C != '\"' && C != '\'' && C != '>' && C != '/') {
 State = LS_Normal;
 return;
@@ -774,8 +806,17 @@ void Lexer::lex(Token &T) {
 BufferPtr++;
 
   CommentState = LCS_InsideBCPLComment;
-  if (State != LS_VerbatimBlockBody && State != LS_VerbatimBlockFirstLine)
+  switch (State) {
+  case LS_VerbatimBlockFirstLine:
+  case LS_VerbatimBlockBody:
+break;
+  case LS_HTMLStartTag:
+BufferPtr = skipHorizontalWhitespace(BufferPtr, BufferEnd);
+break;
+  default:
 State = LS_Normal;
+break;
+  }
   CommentEnd = findBCPLCommentEnd(BufferPtr, BufferEnd);
   goto again;
 }
@@ -807,6 +848,14 @@ void Lexer::lex(Token &T) {
 while(EndWhitespace != BufferEnd && *EndWhitespace != '/')
   EndWhitespace++;
 
+// When lexing the start of an HTML tag (i.e. going through the attributes)
+// there won't be any newlines generated.
+if (State == LS_HTMLStartTag && EndWhitespace != BufferEnd) {
+  CommentState = LCS_BeforeComment;
+  BufferPtr = EndWhitespace;
+  goto again;
+}
+
 // Turn any whitespace between comments (and there is only whitespace
 // between them -- guarant

[clang] [llvm] Depot runners pgo (PR #120777)

2024-12-21 Thread Tom Stellard via cfe-commits

https://github.com/tstellar updated 
https://github.com/llvm/llvm-project/pull/120777

>From cb87398ea7f654559799ff7f79f292842832c29c Mon Sep 17 00:00:00 2001
From: Tom Stellard 
Date: Wed, 20 Nov 2024 20:59:38 -0800
Subject: [PATCH 01/12] Workflows: Use new depot runners for x86 Linux release
 builds

---
 .github/workflows/release-binaries.yml | 89 +-
 1 file changed, 73 insertions(+), 16 deletions(-)

diff --git a/.github/workflows/release-binaries.yml 
b/.github/workflows/release-binaries.yml
index 1cde628d3f66c3..eeb92f2e039b98 100644
--- a/.github/workflows/release-binaries.yml
+++ b/.github/workflows/release-binaries.yml
@@ -60,6 +60,8 @@ jobs:
   enable-pgo: ${{ steps.vars.outputs.enable-pgo }}
   release-binary-basename: ${{ steps.vars.outputs.release-binary-basename 
}}
   release-binary-filename: ${{ steps.vars.outputs.release-binary-filename 
}}
+  runs-on: ${{ steps.vars.outputs.runs-on }}
+  multi-stage: ${{ steps.vars.outputs.multi-stage }}
 
 steps:
 # It's good practice to use setup-python, but this is also required on 
macos-14
@@ -144,12 +146,26 @@ jobs:
 
 echo "target-cmake-flags=$target_cmake_flags" >> $GITHUB_OUTPUT
 echo "build-flang=$build_flang" >> $GITHUB_OUTPUT
+case "${{ inputs.runs-on }}" in
+  ubuntu-22.04)
+runs_on="depot-${{ inputs.runs-on }}-16"
+multi_stage="false"
+;;
+  *)
+runs_on="${{ inputs.runs-on }}"
+multi_stage="true"
+;;
+esac
+echo "runs-on=$runs_on" >> $GITHUB_OUTPUT
+echo "multi-stage=$multi_stage" >> $GITHUB_OUTPUT
 
   build-stage1:
 name: "Build Stage 1"
 needs: prepare
-if: github.repository == 'llvm/llvm-project'
-runs-on: ${{ inputs.runs-on }}
+if: >-
+  github.repository == 'llvm/llvm-project' &&
+  needs.prepare.outputs.multi-stage == 'true'
+runs-on: ${{ needs.prepare.outputs.runs-on }}
 steps:
 
 - name: Checkout Actions
@@ -195,7 +211,7 @@ jobs:
 key: sccache-${{ runner.os }}-${{ runner.arch }}-release
 variant: sccache
 
-- name: Build Stage 1 Clang
+- name: Configure Stage 1 Clang
   id: build
   shell: bash
   run: |
@@ -208,12 +224,44 @@ jobs:
 -DBOOTSTRAP_CPACK_PACKAGE_FILE_NAME="${{ 
needs.prepare.outputs.release-binary-basename }}" \
 -DCMAKE_C_COMPILER_LAUNCHER=sccache \
 -DCMAKE_CXX_COMPILER_LAUNCHER=sccache
-ninja -v -C ${{ steps.setup-stage.outputs.build-prefix }}/build
-# There is a race condition on the MacOS builders and this command is 
here
-# to help debug that when it happens.
-ls -ltr ${{ steps.setup-stage.outputs.build-prefix }}/build
+- name: Build Stage 1 Clang
+  shell: bash
+  run: |
+if "${{ steps.needs.prepare.outputs.multi-stage}}" = "true"; then
+  ninja -v -C ${{ steps.setup-stage.outputs.build-prefix }}/build 
stage2-package
+  mv ${{ steps.setup-stage.outputs.build-prefix  
}}/build/tools/clang/stage2-bins/${{ 
needs.prepare.outputs.release-binary-filename }} .
+else
+  ninja -v -C ${{ steps.setup-stage.outputs.build-prefix }}/build
+  # There is a race condition on the MacOS builders and this command 
is here
+  # to help debug that when it happens.
+  ls -ltr ${{ steps.setup-stage.outputs.build-prefix }}/build
+fi
+
+- uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 
#v4.3.0
+  if: needs.prepare.outputs.multi-stage == "false"
+  with:
+name: ${{ runner.os }}-${{ runner.arch }}-release-binary
+# Due to path differences on Windows when running in bash vs running 
on node,
+# we need to search for files in the current workspace.
+path: |
+  ${{ needs.prepare.outputs.release-binary-filename }}
+
+# Clean up some build files to reduce size of artifact.
+- name: Clean Up Build Directory
+  if: needs.prepare.outputs.multi-stage == "false"
+  shell: bash
+  run: |
+find ${{ steps.setup-stage.outputs.build-prefix }}/build -iname ${{ 
needs.prepare.outputs.release-binary-filename }} -delete
+rm -Rf ${{ steps.setup-stage.outputs.build-prefix 
}}/build/tools/clang/stage2-bins/_CPack_Packages
 
+- name: Run Tests
+  shell: bash
+  if: needs.prepare.outputs.multi-stage == "false"
+  run: |
+ninja -C ${{ steps.setup-stage.outputs.build-prefix }}/build 
stage2-check-all
+
 - name: Save Stage
+  if: needs.prepare.outputs.multi-stage == "true"
   uses: ./workflows-main/.github/workflows/release-binaries-save-stage
   with:
 build-prefix: ${{ steps.setup-stage.outputs.build-prefix }}
@@ -223,8 +271,10 @@ jobs:
 needs:
   - prepare
   - build-stage1
-if: github.repository == 'llvm/llvm-project'
-runs-on: ${{ inputs.runs-on }}
+if: >- 
+   

[clang] [Clang][Comments] Allow HTML tags across multiple lines (PR #120843)

2024-12-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: nerix (Nerixyz)


Changes

HTML starting tags that span multiple lines were previously not allowed (or 
rather, only the starting line was lexed as HTML). Doxygen allows those tags.

This PR allows the starting tags to span multiple lines. They can't span 
multiple (C-)Comments, though (it's likely a user-error). Multiple BCPL 
comments are fine as those are single lines (shown below).

Example:

```c
/// Aaab
int Test;
```

Fixes #28321.

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


4 Files Affected:

- (modified) clang/lib/AST/CommentLexer.cpp (+63-6) 
- (modified) clang/test/AST/ast-dump-comment.cpp (+13) 
- (modified) clang/unittests/AST/CommentLexer.cpp (+123) 
- (modified) clang/unittests/AST/CommentParser.cpp (+12-11) 


``diff
diff --git a/clang/lib/AST/CommentLexer.cpp b/clang/lib/AST/CommentLexer.cpp
index ec9a5b480aa295..804be89a8d4ddc 100644
--- a/clang/lib/AST/CommentLexer.cpp
+++ b/clang/lib/AST/CommentLexer.cpp
@@ -196,6 +196,15 @@ const char *skipWhitespace(const char *BufferPtr, const 
char *BufferEnd) {
   return BufferEnd;
 }
 
+const char *skipHorizontalWhitespace(const char *BufferPtr,
+ const char *BufferEnd) {
+  for (; BufferPtr != BufferEnd; ++BufferPtr) {
+if (!isHorizontalWhitespace(*BufferPtr))
+  return BufferPtr;
+  }
+  return BufferEnd;
+}
+
 bool isWhitespace(const char *BufferPtr, const char *BufferEnd) {
   return skipWhitespace(BufferPtr, BufferEnd) == BufferEnd;
 }
@@ -637,17 +646,41 @@ void Lexer::setupAndLexHTMLStartTag(Token &T) {
   formTokenWithChars(T, TagNameEnd, tok::html_start_tag);
   T.setHTMLTagStartName(Name);
 
-  BufferPtr = skipWhitespace(BufferPtr, CommentEnd);
+  BufferPtr = skipHorizontalWhitespace(BufferPtr, CommentEnd);
+  if (BufferPtr == CommentEnd) { // in BCPL comments
+State = LS_HTMLStartTag;
+return;
+  }
 
   const char C = *BufferPtr;
   if (BufferPtr != CommentEnd &&
-  (C == '>' || C == '/' || isHTMLIdentifierStartingCharacter(C)))
+  (C == '>' || C == '/' || isVerticalWhitespace(C) ||
+   isHTMLIdentifierStartingCharacter(C)))
 State = LS_HTMLStartTag;
 }
 
 void Lexer::lexHTMLStartTag(Token &T) {
   assert(State == LS_HTMLStartTag);
 
+  // Skip leading whitespace and comment decorations
+  while (isVerticalWhitespace(*BufferPtr)) {
+BufferPtr = skipNewline(BufferPtr, CommentEnd);
+
+if (CommentState == LCS_InsideCComment)
+  skipLineStartingDecorations();
+
+BufferPtr = skipHorizontalWhitespace(BufferPtr, CommentEnd);
+if (BufferPtr == CommentEnd) {
+  // HTML starting tags must be defined in a single comment block.
+  // It's likely a user-error where they forgot to terminate the comment.
+  State = LS_Normal;
+  // Since at least one newline was skipped and one token needs to be 
lexed,
+  // return a newline.
+  formTokenWithChars(T, BufferPtr, tok::newline);
+  return;
+}
+  }
+
   const char *TokenPtr = BufferPtr;
   char C = *TokenPtr;
   if (isHTMLIdentifierCharacter(C)) {
@@ -693,14 +726,13 @@ void Lexer::lexHTMLStartTag(Token &T) {
 
   // Now look ahead and return to normal state if we don't see any HTML tokens
   // ahead.
-  BufferPtr = skipWhitespace(BufferPtr, CommentEnd);
+  BufferPtr = skipHorizontalWhitespace(BufferPtr, CommentEnd);
   if (BufferPtr == CommentEnd) {
-State = LS_Normal;
 return;
   }
 
   C = *BufferPtr;
-  if (!isHTMLIdentifierStartingCharacter(C) &&
+  if (!isHTMLIdentifierStartingCharacter(C) && !isVerticalWhitespace(C) &&
   C != '=' && C != '\"' && C != '\'' && C != '>' && C != '/') {
 State = LS_Normal;
 return;
@@ -774,8 +806,17 @@ void Lexer::lex(Token &T) {
 BufferPtr++;
 
   CommentState = LCS_InsideBCPLComment;
-  if (State != LS_VerbatimBlockBody && State != LS_VerbatimBlockFirstLine)
+  switch (State) {
+  case LS_VerbatimBlockFirstLine:
+  case LS_VerbatimBlockBody:
+break;
+  case LS_HTMLStartTag:
+BufferPtr = skipHorizontalWhitespace(BufferPtr, BufferEnd);
+break;
+  default:
 State = LS_Normal;
+break;
+  }
   CommentEnd = findBCPLCommentEnd(BufferPtr, BufferEnd);
   goto again;
 }
@@ -807,6 +848,14 @@ void Lexer::lex(Token &T) {
 while(EndWhitespace != BufferEnd && *EndWhitespace != '/')
   EndWhitespace++;
 
+// When lexing the start of an HTML tag (i.e. going through the attributes)
+// there won't be any newlines generated.
+if (State == LS_HTMLStartTag && EndWhitespace != BufferEnd) {
+  CommentState = LCS_BeforeComment;
+  BufferPtr = EndWhitespace;
+  goto again;
+}
+
 // Turn any whitespace between comments (and there is only whitespace
 // between them -- guaranteed by comment extraction) into a newline.  We
 // have two newlines between C comments in total (first one was synthesized

[clang] [Clang][Comments] Allow HTML tags across multiple lines (PR #120843)

2024-12-21 Thread via cfe-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write 
permissions for the repository. In which case you can instead tag reviewers by 
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a 
review by "ping"ing the PR by adding a comment “Ping”. The common courtesy 
"ping" rate is once a week. Please remember that you are asking for valuable 
time from other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[clang] [Serialization] Migrate away from PointerUnion::get (NFC) (PR #120844)

2024-12-21 Thread Kazu Hirata via cfe-commits

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

Note that PointerUnion::get has been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //isa, cast and the llvm::dyn_cast

I'm not touching PointerUnion::dyn_cast for now because it's a bit
complicated; we could blindly migrate it to dyn_cast_if_present, but
we should probably use dyn_cast when the operand is known to be
non-null.


>From 0cbc706b04ccbafa9adb0295c86b72119196b01d Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Sat, 21 Dec 2024 08:55:08 -0800
Subject: [PATCH] [Serialization] Migrate away from PointerUnion::get (NFC)

Note that PointerUnion::get has been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //isa, cast and the llvm::dyn_cast

I'm not touching PointerUnion::dyn_cast for now because it's a bit
complicated; we could blindly migrate it to dyn_cast_if_present, but
we should probably use dyn_cast when the operand is known to be
non-null.
---
 clang/lib/Serialization/MultiOnDiskHashTable.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Serialization/MultiOnDiskHashTable.h 
b/clang/lib/Serialization/MultiOnDiskHashTable.h
index a0d75ec3a9e76e..6464220f13aeff 100644
--- a/clang/lib/Serialization/MultiOnDiskHashTable.h
+++ b/clang/lib/Serialization/MultiOnDiskHashTable.h
@@ -93,7 +93,7 @@ template class MultiOnDiskHashTable {
 using result_type = OnDiskTable *;
 
 result_type operator()(void *P) const {
-  return Table::getFromOpaqueValue(P).template get();
+  return llvm::cast(Table::getFromOpaqueValue(P));
 }
   };
 
@@ -130,7 +130,7 @@ template class MultiOnDiskHashTable {
 Files.insert(PendingOverrides.begin(), PendingOverrides.end());
 // Explicitly capture Files to work around an MSVC 2015 rejects-valid bug.
 auto ShouldRemove = [&Files](void *T) -> bool {
-  auto *ODT = Table::getFromOpaqueValue(T).template get();
+  auto *ODT = llvm::cast(Table::getFromOpaqueValue(T));
   bool Remove = Files.count(ODT->File);
   if (Remove)
 delete ODT;

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


[clang] [Serialization] Migrate away from PointerUnion::get (NFC) (PR #120844)

2024-12-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-modules

Author: Kazu Hirata (kazutakahirata)


Changes

Note that PointerUnion::get has been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //isa, cast and the llvm::dyn_cast

I'm not touching PointerUnion::dyn_cast for now because it's a bit
complicated; we could blindly migrate it to dyn_cast_if_present, but
we should probably use dyn_cast when the operand is known to be
non-null.


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


1 Files Affected:

- (modified) clang/lib/Serialization/MultiOnDiskHashTable.h (+2-2) 


``diff
diff --git a/clang/lib/Serialization/MultiOnDiskHashTable.h 
b/clang/lib/Serialization/MultiOnDiskHashTable.h
index a0d75ec3a9e76e..6464220f13aeff 100644
--- a/clang/lib/Serialization/MultiOnDiskHashTable.h
+++ b/clang/lib/Serialization/MultiOnDiskHashTable.h
@@ -93,7 +93,7 @@ template class MultiOnDiskHashTable {
 using result_type = OnDiskTable *;
 
 result_type operator()(void *P) const {
-  return Table::getFromOpaqueValue(P).template get();
+  return llvm::cast(Table::getFromOpaqueValue(P));
 }
   };
 
@@ -130,7 +130,7 @@ template class MultiOnDiskHashTable {
 Files.insert(PendingOverrides.begin(), PendingOverrides.end());
 // Explicitly capture Files to work around an MSVC 2015 rejects-valid bug.
 auto ShouldRemove = [&Files](void *T) -> bool {
-  auto *ODT = Table::getFromOpaqueValue(T).template get();
+  auto *ODT = llvm::cast(Table::getFromOpaqueValue(T));
   bool Remove = Files.count(ODT->File);
   if (Remove)
 delete ODT;

``




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


[clang] [Serialization] Migrate away from PointerUnion::get (NFC) (PR #120844)

2024-12-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)


Changes

Note that PointerUnion::get has been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //isa, cast and the llvm::dyn_cast

I'm not touching PointerUnion::dyn_cast for now because it's a bit
complicated; we could blindly migrate it to dyn_cast_if_present, but
we should probably use dyn_cast when the operand is known to be
non-null.


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


1 Files Affected:

- (modified) clang/lib/Serialization/MultiOnDiskHashTable.h (+2-2) 


``diff
diff --git a/clang/lib/Serialization/MultiOnDiskHashTable.h 
b/clang/lib/Serialization/MultiOnDiskHashTable.h
index a0d75ec3a9e76e..6464220f13aeff 100644
--- a/clang/lib/Serialization/MultiOnDiskHashTable.h
+++ b/clang/lib/Serialization/MultiOnDiskHashTable.h
@@ -93,7 +93,7 @@ template class MultiOnDiskHashTable {
 using result_type = OnDiskTable *;
 
 result_type operator()(void *P) const {
-  return Table::getFromOpaqueValue(P).template get();
+  return llvm::cast(Table::getFromOpaqueValue(P));
 }
   };
 
@@ -130,7 +130,7 @@ template class MultiOnDiskHashTable {
 Files.insert(PendingOverrides.begin(), PendingOverrides.end());
 // Explicitly capture Files to work around an MSVC 2015 rejects-valid bug.
 auto ShouldRemove = [&Files](void *T) -> bool {
-  auto *ODT = Table::getFromOpaqueValue(T).template get();
+  auto *ODT = llvm::cast(Table::getFromOpaqueValue(T));
   bool Remove = Files.count(ODT->File);
   if (Remove)
 delete ODT;

``




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


[clang] [Sema] Migrate away from PointerUnion::{is, get} (NFC) (PR #120829)

2024-12-21 Thread Younan Zhang via cfe-commits

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


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


[clang] [X86][AVX10.2] Add comments for the avx10_2convertintrin.h file (PR #120766)

2024-12-21 Thread Phoebe Wang via cfe-commits


@@ -24,567 +24,3243 @@
   __attribute__((__always_inline__, __nodebug__, __target__("avx10.2-256"),
\
  __min_vector_width__(256)))
 
+/// Convert two 128-bit vectors, \a __A and \a __B, containing packed
+/// single-precision (32-bit) floating-point elements to a 128-bit vector
+/// containing FP16 elements.
+///
+/// \code{.operation}
+/// FOR i := 0 to 7
+///IF i < 4
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4])
+///FI
+/// ENDFOR
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction.
+///
+/// \param __A
+///A 128-bit vector of [4 x float].
+/// \param __B
+///A 128-bit vector of [4 x float].
+/// \returns
+///A 128-bit vector of [8 x fp16]. Lower elements correspond to the
+///(converted) elements from \a __B; higher order elements correspond to 
the
+///(converted) elements from \a __A.
 static __inline__ __m128h __DEFAULT_FN_ATTRS128 _mm_cvtx2ps_ph(__m128 __A,
__m128 __B) {
   return (__m128h)__builtin_ia32_vcvt2ps2phx128_mask(
   (__v4sf)__A, (__v4sf)__B, (__v8hf)_mm_setzero_ph(), (__mmask8)(-1));
 }
 
+/// Convert two 128-bit vectors, \a __A and \a __B, containing packed
+/// single-precision (32-bit) floating-point elements to a 128-bit vector
+/// containing FP16 elements. Merging mask \a __U is used to determine if given
+/// element should be taken from \a __W instead.
+///
+/// \code{.operation}
+/// FOR i := 0 to 7
+///IF mask[i]
+///dst.fp16[i] := __W[i]
+///ELSE
+///IF i < 4
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4])
+///FI
+///FI
+/// ENDFOR
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction.
+///
+/// \param __W
+///A 128-bit vector of [8 x fp16].
+/// \param __U
+///A 8-bit merging mask.
+/// \param __A
+///A 128-bit vector of [4 x float].
+/// \param __B
+///A 128-bit vector of [4 x float].
+/// \returns
+///A 128-bit vector of [8 x fp16]. Lower elements correspond to the
+///(converted) elements from \a __B; higher order elements correspond to 
the
+///(converted) elements from \a __A. If corresponding mask bit is set, then
+///element from \a __W is taken instead.
 static __inline__ __m128h __DEFAULT_FN_ATTRS128
 _mm_mask_cvtx2ps_ph(__m128h __W, __mmask8 __U, __m128 __A, __m128 __B) {
   return (__m128h)__builtin_ia32_vcvt2ps2phx128_mask(
   (__v4sf)__A, (__v4sf)__B, (__v8hf)__W, (__mmask8)__U);
 }
 
+/// Convert two 128-bit vectors, \a __A and \a __B, containing packed
+/// single-precision (32-bit) floating-point elements to a 128-bit vector
+/// containing FP16 elements. Zeroing mask \a __U is used to determine if given
+/// element should be zeroed instead.
+///
+/// \code{.operation}
+/// FOR i := 0 to 7
+///IF mask[i]
+///IF i < 4
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4])
+///FI
+///ELSE
+///dst.fp16[i] := 0
+///FI
+/// ENDFOR
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction.
+///
+/// \param __U
+///A 8-bit zeroing mask.
+/// \param __A
+///A 128-bit vector of [4 x float].
+/// \param __B
+///A 128-bit vector of [4 x float].
+/// \returns
+///A 128-bit vector of [8 x fp16]. Lower elements correspond to the
+///(converted) elements from \a __B; higher order elements correspond to 
the
+///(converted) elements from \a __A. If corresponding mask bit is not set,
+///then zero is taken instead.
 static __inline__ __m128h __DEFAULT_FN_ATTRS128
 _mm_maskz_cvtx2ps_ph(__mmask8 __U, __m128 __A, __m128 __B) {
   return (__m128h)__builtin_ia32_vcvt2ps2phx128_mask(
   (__v4sf)__A, (__v4sf)__B, (__v8hf)_mm_setzero_ph(), (__mmask8)__U);
 }
 
+/// Convert two 256-bit vectors, \a __A and \a __B, containing packed
+/// single-precision (32-bit) floating-point elements to a 256-bit vector
+/// containing FP16 elements.
+///
+/// \code{.operation}
+/// FOR i := 0 to 15
+///IF i < 8
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 8])
+///FI
+/// ENDFOR
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction.
+///
+/// \param __A
+///A 256-bit vector of [8 x float].
+/// \param __B
+///A 256-bit vector of [8 x float].
+/// \returns
+///A 256-bit vector of [16 x fp16]. Lower elements correspond to the
+///(converted) elem

[clang] [X86][AVX10.2] Add comments for the avx10_2convertintrin.h file (PR #120766)

2024-12-21 Thread Phoebe Wang via cfe-commits


@@ -24,567 +24,3243 @@
   __attribute__((__always_inline__, __nodebug__, __target__("avx10.2-256"),
\
  __min_vector_width__(256)))
 
+/// Convert two 128-bit vectors, \a __A and \a __B, containing packed
+/// single-precision (32-bit) floating-point elements to a 128-bit vector
+/// containing FP16 elements.
+///
+/// \code{.operation}
+/// FOR i := 0 to 7
+///IF i < 4
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4])
+///FI
+/// ENDFOR
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction.
+///
+/// \param __A
+///A 128-bit vector of [4 x float].
+/// \param __B
+///A 128-bit vector of [4 x float].
+/// \returns
+///A 128-bit vector of [8 x fp16]. Lower elements correspond to the
+///(converted) elements from \a __B; higher order elements correspond to 
the
+///(converted) elements from \a __A.
 static __inline__ __m128h __DEFAULT_FN_ATTRS128 _mm_cvtx2ps_ph(__m128 __A,
__m128 __B) {
   return (__m128h)__builtin_ia32_vcvt2ps2phx128_mask(
   (__v4sf)__A, (__v4sf)__B, (__v8hf)_mm_setzero_ph(), (__mmask8)(-1));
 }
 
+/// Convert two 128-bit vectors, \a __A and \a __B, containing packed
+/// single-precision (32-bit) floating-point elements to a 128-bit vector
+/// containing FP16 elements. Merging mask \a __U is used to determine if given
+/// element should be taken from \a __W instead.
+///
+/// \code{.operation}
+/// FOR i := 0 to 7
+///IF mask[i]
+///dst.fp16[i] := __W[i]
+///ELSE
+///IF i < 4
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4])
+///FI
+///FI
+/// ENDFOR
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction.
+///
+/// \param __W
+///A 128-bit vector of [8 x fp16].
+/// \param __U
+///A 8-bit merging mask.
+/// \param __A
+///A 128-bit vector of [4 x float].
+/// \param __B
+///A 128-bit vector of [4 x float].
+/// \returns
+///A 128-bit vector of [8 x fp16]. Lower elements correspond to the
+///(converted) elements from \a __B; higher order elements correspond to 
the
+///(converted) elements from \a __A. If corresponding mask bit is set, then
+///element from \a __W is taken instead.
 static __inline__ __m128h __DEFAULT_FN_ATTRS128
 _mm_mask_cvtx2ps_ph(__m128h __W, __mmask8 __U, __m128 __A, __m128 __B) {
   return (__m128h)__builtin_ia32_vcvt2ps2phx128_mask(
   (__v4sf)__A, (__v4sf)__B, (__v8hf)__W, (__mmask8)__U);
 }
 
+/// Convert two 128-bit vectors, \a __A and \a __B, containing packed
+/// single-precision (32-bit) floating-point elements to a 128-bit vector
+/// containing FP16 elements. Zeroing mask \a __U is used to determine if given
+/// element should be zeroed instead.
+///
+/// \code{.operation}
+/// FOR i := 0 to 7
+///IF mask[i]
+///IF i < 4
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4])
+///FI
+///ELSE
+///dst.fp16[i] := 0
+///FI
+/// ENDFOR
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction.
+///
+/// \param __U
+///A 8-bit zeroing mask.
+/// \param __A
+///A 128-bit vector of [4 x float].
+/// \param __B
+///A 128-bit vector of [4 x float].
+/// \returns
+///A 128-bit vector of [8 x fp16]. Lower elements correspond to the
+///(converted) elements from \a __B; higher order elements correspond to 
the
+///(converted) elements from \a __A. If corresponding mask bit is not set,
+///then zero is taken instead.
 static __inline__ __m128h __DEFAULT_FN_ATTRS128
 _mm_maskz_cvtx2ps_ph(__mmask8 __U, __m128 __A, __m128 __B) {
   return (__m128h)__builtin_ia32_vcvt2ps2phx128_mask(
   (__v4sf)__A, (__v4sf)__B, (__v8hf)_mm_setzero_ph(), (__mmask8)__U);
 }
 
+/// Convert two 256-bit vectors, \a __A and \a __B, containing packed
+/// single-precision (32-bit) floating-point elements to a 256-bit vector
+/// containing FP16 elements.
+///
+/// \code{.operation}
+/// FOR i := 0 to 15
+///IF i < 8
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 8])
+///FI
+/// ENDFOR
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction.
+///
+/// \param __A
+///A 256-bit vector of [8 x float].
+/// \param __B
+///A 256-bit vector of [8 x float].
+/// \returns
+///A 256-bit vector of [16 x fp16]. Lower elements correspond to the
+///(converted) elem

[clang] [X86][AVX10.2] Add comments for the avx10_2convertintrin.h file (PR #120766)

2024-12-21 Thread Phoebe Wang via cfe-commits


@@ -24,567 +24,3243 @@
   __attribute__((__always_inline__, __nodebug__, __target__("avx10.2-256"),
\
  __min_vector_width__(256)))
 
+/// Convert two 128-bit vectors, \a __A and \a __B, containing packed
+/// single-precision (32-bit) floating-point elements to a 128-bit vector
+/// containing FP16 elements.
+///
+/// \code{.operation}
+/// FOR i := 0 to 7
+///IF i < 4
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4])
+///FI
+/// ENDFOR
+/// \endcode

phoebewang wrote:

It looks to me we put this section in the end in recent features. Does the 
place matter to our internal tool?

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


[clang] [X86][AVX10.2] Add comments for the avx10_2convertintrin.h file (PR #120766)

2024-12-21 Thread Phoebe Wang via cfe-commits


@@ -24,567 +24,3243 @@
   __attribute__((__always_inline__, __nodebug__, __target__("avx10.2-256"),
\
  __min_vector_width__(256)))
 
+/// Convert two 128-bit vectors, \a __A and \a __B, containing packed
+/// single-precision (32-bit) floating-point elements to a 128-bit vector
+/// containing FP16 elements.

phoebewang wrote:

Needs 3 more spaces. The same for the rest.

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


[clang] [X86][AVX10.2] Add comments for the avx10_2convertintrin.h file (PR #120766)

2024-12-21 Thread Phoebe Wang via cfe-commits


@@ -24,567 +24,3243 @@
   __attribute__((__always_inline__, __nodebug__, __target__("avx10.2-256"),
\
  __min_vector_width__(256)))
 
+/// Convert two 128-bit vectors, \a __A and \a __B, containing packed
+/// single-precision (32-bit) floating-point elements to a 128-bit vector
+/// containing FP16 elements.
+///
+/// \code{.operation}
+/// FOR i := 0 to 7
+///IF i < 4
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4])
+///FI
+/// ENDFOR
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction.
+///
+/// \param __A
+///A 128-bit vector of [4 x float].
+/// \param __B
+///A 128-bit vector of [4 x float].
+/// \returns
+///A 128-bit vector of [8 x fp16]. Lower elements correspond to the
+///(converted) elements from \a __B; higher order elements correspond to 
the
+///(converted) elements from \a __A.
 static __inline__ __m128h __DEFAULT_FN_ATTRS128 _mm_cvtx2ps_ph(__m128 __A,
__m128 __B) {
   return (__m128h)__builtin_ia32_vcvt2ps2phx128_mask(
   (__v4sf)__A, (__v4sf)__B, (__v8hf)_mm_setzero_ph(), (__mmask8)(-1));
 }
 
+/// Convert two 128-bit vectors, \a __A and \a __B, containing packed
+/// single-precision (32-bit) floating-point elements to a 128-bit vector
+/// containing FP16 elements. Merging mask \a __U is used to determine if given
+/// element should be taken from \a __W instead.
+///
+/// \code{.operation}
+/// FOR i := 0 to 7
+///IF mask[i]
+///dst.fp16[i] := __W[i]
+///ELSE
+///IF i < 4
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4])
+///FI
+///FI
+/// ENDFOR
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction.
+///
+/// \param __W
+///A 128-bit vector of [8 x fp16].
+/// \param __U
+///A 8-bit merging mask.
+/// \param __A
+///A 128-bit vector of [4 x float].
+/// \param __B
+///A 128-bit vector of [4 x float].
+/// \returns
+///A 128-bit vector of [8 x fp16]. Lower elements correspond to the
+///(converted) elements from \a __B; higher order elements correspond to 
the
+///(converted) elements from \a __A. If corresponding mask bit is set, then
+///element from \a __W is taken instead.
 static __inline__ __m128h __DEFAULT_FN_ATTRS128
 _mm_mask_cvtx2ps_ph(__m128h __W, __mmask8 __U, __m128 __A, __m128 __B) {
   return (__m128h)__builtin_ia32_vcvt2ps2phx128_mask(
   (__v4sf)__A, (__v4sf)__B, (__v8hf)__W, (__mmask8)__U);
 }
 
+/// Convert two 128-bit vectors, \a __A and \a __B, containing packed
+/// single-precision (32-bit) floating-point elements to a 128-bit vector
+/// containing FP16 elements. Zeroing mask \a __U is used to determine if given
+/// element should be zeroed instead.
+///
+/// \code{.operation}
+/// FOR i := 0 to 7
+///IF mask[i]
+///IF i < 4
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4])
+///FI
+///ELSE
+///dst.fp16[i] := 0
+///FI
+/// ENDFOR
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction.
+///
+/// \param __U
+///A 8-bit zeroing mask.
+/// \param __A
+///A 128-bit vector of [4 x float].
+/// \param __B
+///A 128-bit vector of [4 x float].
+/// \returns
+///A 128-bit vector of [8 x fp16]. Lower elements correspond to the
+///(converted) elements from \a __B; higher order elements correspond to 
the
+///(converted) elements from \a __A. If corresponding mask bit is not set,
+///then zero is taken instead.
 static __inline__ __m128h __DEFAULT_FN_ATTRS128
 _mm_maskz_cvtx2ps_ph(__mmask8 __U, __m128 __A, __m128 __B) {
   return (__m128h)__builtin_ia32_vcvt2ps2phx128_mask(
   (__v4sf)__A, (__v4sf)__B, (__v8hf)_mm_setzero_ph(), (__mmask8)__U);
 }
 
+/// Convert two 256-bit vectors, \a __A and \a __B, containing packed
+/// single-precision (32-bit) floating-point elements to a 256-bit vector
+/// containing FP16 elements.
+///
+/// \code{.operation}
+/// FOR i := 0 to 15
+///IF i < 8
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 8])
+///FI
+/// ENDFOR
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction.
+///
+/// \param __A
+///A 256-bit vector of [8 x float].
+/// \param __B
+///A 256-bit vector of [8 x float].
+/// \returns
+///A 256-bit vector of [16 x fp16]. Lower elements correspond to the
+///(converted) elem

[clang] [X86][AVX10.2] Add comments for the avx10_2convertintrin.h file (PR #120766)

2024-12-21 Thread Phoebe Wang via cfe-commits


@@ -24,567 +24,3243 @@
   __attribute__((__always_inline__, __nodebug__, __target__("avx10.2-256"),
\
  __min_vector_width__(256)))
 
+/// Convert two 128-bit vectors, \a __A and \a __B, containing packed
+/// single-precision (32-bit) floating-point elements to a 128-bit vector
+/// containing FP16 elements.
+///
+/// \code{.operation}
+/// FOR i := 0 to 7
+///IF i < 4
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4])
+///FI
+/// ENDFOR

phoebewang wrote:

Missing `DEST[MAX:128] := 0`, the same for the rest.

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


[clang] [X86][AVX10.2] Add comments for the avx10_2convertintrin.h file (PR #120766)

2024-12-21 Thread Phoebe Wang via cfe-commits


@@ -24,567 +24,3243 @@
   __attribute__((__always_inline__, __nodebug__, __target__("avx10.2-256"),
\
  __min_vector_width__(256)))
 
+/// Convert two 128-bit vectors, \a __A and \a __B, containing packed
+/// single-precision (32-bit) floating-point elements to a 128-bit vector
+/// containing FP16 elements.
+///
+/// \code{.operation}
+/// FOR i := 0 to 7
+///IF i < 4
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4])
+///FI
+/// ENDFOR
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction.
+///
+/// \param __A
+///A 128-bit vector of [4 x float].
+/// \param __B
+///A 128-bit vector of [4 x float].
+/// \returns
+///A 128-bit vector of [8 x fp16]. Lower elements correspond to the
+///(converted) elements from \a __B; higher order elements correspond to 
the
+///(converted) elements from \a __A.
 static __inline__ __m128h __DEFAULT_FN_ATTRS128 _mm_cvtx2ps_ph(__m128 __A,
__m128 __B) {
   return (__m128h)__builtin_ia32_vcvt2ps2phx128_mask(
   (__v4sf)__A, (__v4sf)__B, (__v8hf)_mm_setzero_ph(), (__mmask8)(-1));
 }
 
+/// Convert two 128-bit vectors, \a __A and \a __B, containing packed
+/// single-precision (32-bit) floating-point elements to a 128-bit vector
+/// containing FP16 elements. Merging mask \a __U is used to determine if given
+/// element should be taken from \a __W instead.
+///
+/// \code{.operation}
+/// FOR i := 0 to 7
+///IF mask[i]
+///dst.fp16[i] := __W[i]
+///ELSE
+///IF i < 4
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4])
+///FI
+///FI
+/// ENDFOR
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction.
+///
+/// \param __W
+///A 128-bit vector of [8 x fp16].
+/// \param __U
+///A 8-bit merging mask.
+/// \param __A
+///A 128-bit vector of [4 x float].
+/// \param __B
+///A 128-bit vector of [4 x float].
+/// \returns
+///A 128-bit vector of [8 x fp16]. Lower elements correspond to the
+///(converted) elements from \a __B; higher order elements correspond to 
the
+///(converted) elements from \a __A. If corresponding mask bit is set, then
+///element from \a __W is taken instead.
 static __inline__ __m128h __DEFAULT_FN_ATTRS128
 _mm_mask_cvtx2ps_ph(__m128h __W, __mmask8 __U, __m128 __A, __m128 __B) {
   return (__m128h)__builtin_ia32_vcvt2ps2phx128_mask(
   (__v4sf)__A, (__v4sf)__B, (__v8hf)__W, (__mmask8)__U);
 }
 
+/// Convert two 128-bit vectors, \a __A and \a __B, containing packed
+/// single-precision (32-bit) floating-point elements to a 128-bit vector
+/// containing FP16 elements. Zeroing mask \a __U is used to determine if given
+/// element should be zeroed instead.
+///
+/// \code{.operation}
+/// FOR i := 0 to 7
+///IF mask[i]
+///IF i < 4
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4])
+///FI
+///ELSE
+///dst.fp16[i] := 0
+///FI
+/// ENDFOR
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction.
+///
+/// \param __U
+///A 8-bit zeroing mask.
+/// \param __A
+///A 128-bit vector of [4 x float].
+/// \param __B
+///A 128-bit vector of [4 x float].
+/// \returns
+///A 128-bit vector of [8 x fp16]. Lower elements correspond to the
+///(converted) elements from \a __B; higher order elements correspond to 
the
+///(converted) elements from \a __A. If corresponding mask bit is not set,
+///then zero is taken instead.
 static __inline__ __m128h __DEFAULT_FN_ATTRS128
 _mm_maskz_cvtx2ps_ph(__mmask8 __U, __m128 __A, __m128 __B) {
   return (__m128h)__builtin_ia32_vcvt2ps2phx128_mask(
   (__v4sf)__A, (__v4sf)__B, (__v8hf)_mm_setzero_ph(), (__mmask8)__U);
 }
 
+/// Convert two 256-bit vectors, \a __A and \a __B, containing packed
+/// single-precision (32-bit) floating-point elements to a 256-bit vector
+/// containing FP16 elements.
+///
+/// \code{.operation}
+/// FOR i := 0 to 15
+///IF i < 8
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 8])
+///FI
+/// ENDFOR
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction.
+///
+/// \param __A
+///A 256-bit vector of [8 x float].
+/// \param __B
+///A 256-bit vector of [8 x float].
+/// \returns
+///A 256-bit vector of [16 x fp16]. Lower elements correspond to the
+///(converted) elem

[clang] [X86][AVX10.2] Add comments for the avx10_2convertintrin.h file (PR #120766)

2024-12-21 Thread Phoebe Wang via cfe-commits


@@ -24,567 +24,3243 @@
   __attribute__((__always_inline__, __nodebug__, __target__("avx10.2-256"),
\
  __min_vector_width__(256)))
 
+/// Convert two 128-bit vectors, \a __A and \a __B, containing packed
+/// single-precision (32-bit) floating-point elements to a 128-bit vector
+/// containing FP16 elements.
+///
+/// \code{.operation}
+/// FOR i := 0 to 7
+///IF i < 4
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4])
+///FI
+/// ENDFOR
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction.
+///
+/// \param __A
+///A 128-bit vector of [4 x float].
+/// \param __B
+///A 128-bit vector of [4 x float].
+/// \returns
+///A 128-bit vector of [8 x fp16]. Lower elements correspond to the
+///(converted) elements from \a __B; higher order elements correspond to 
the
+///(converted) elements from \a __A.
 static __inline__ __m128h __DEFAULT_FN_ATTRS128 _mm_cvtx2ps_ph(__m128 __A,
__m128 __B) {
   return (__m128h)__builtin_ia32_vcvt2ps2phx128_mask(
   (__v4sf)__A, (__v4sf)__B, (__v8hf)_mm_setzero_ph(), (__mmask8)(-1));
 }
 
+/// Convert two 128-bit vectors, \a __A and \a __B, containing packed
+/// single-precision (32-bit) floating-point elements to a 128-bit vector
+/// containing FP16 elements. Merging mask \a __U is used to determine if given
+/// element should be taken from \a __W instead.
+///
+/// \code{.operation}
+/// FOR i := 0 to 7
+///IF mask[i]
+///dst.fp16[i] := __W[i]

phoebewang wrote:

Switch it with the ELSE branch.

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


[clang] [X86][AVX10.2] Add comments for the avx10_2convertintrin.h file (PR #120766)

2024-12-21 Thread Phoebe Wang via cfe-commits

phoebewang wrote:

We cannot let clang-format to format it. Maybe use `clang-format off` to turn 
it off.

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


[clang] [Sema] Migrate away from PointerUnion::{is, get} (NFC) (PR #120829)

2024-12-21 Thread Kazu Hirata via cfe-commits

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

Note that PointerUnion::{is,get} have been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //isa, cast and the llvm::dyn_cast

I'm moving the definitions of several functions to SemaConcept.cpp
because llvm::cast requires the full definitions of
NormalizedConstraintPair, which is used like so:

  using CompoundConstraint = llvm::PointerIntPair;


>From 39e2008fe0e47ccac5e089ae07d8d0586c39f3dc Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Fri, 20 Dec 2024 23:33:54 -0800
Subject: [PATCH] [Sema] Migrate away from PointerUnion::{is,get} (NFC)

Note that PointerUnion::{is,get} have been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //isa, cast and the llvm::dyn_cast

I'm moving the definitions of several functions to SemaConcept.cpp
because llvm::cast requires the full definitions of
NormalizedConstraintPair, which is used like so:

  using CompoundConstraint = llvm::PointerIntPair;
---
 clang/include/clang/Sema/SemaConcept.h | 23 ++-
 clang/lib/Sema/SemaConcept.cpp | 18 ++
 2 files changed, 24 insertions(+), 17 deletions(-)

diff --git a/clang/include/clang/Sema/SemaConcept.h 
b/clang/include/clang/Sema/SemaConcept.h
index fa5309a597b3a5..5c599a70532f63 100644
--- a/clang/include/clang/Sema/SemaConcept.h
+++ b/clang/include/clang/Sema/SemaConcept.h
@@ -135,31 +135,20 @@ struct NormalizedConstraint {
 return *this;
   }
 
-  bool isAtomic() const { return Constraint.is(); }
+  bool isAtomic() const { return llvm::isa(Constraint); }
   bool isFoldExpanded() const {
-return Constraint.is();
+return llvm::isa(Constraint);
   }
-  bool isCompound() const { return Constraint.is(); }
+  bool isCompound() const { return llvm::isa(Constraint); }
 
-  CompoundConstraintKind getCompoundKind() const {
-assert(isCompound() && "getCompoundKind on a non-compound constraint..");
-return Constraint.get().getInt();
-  }
+  CompoundConstraintKind getCompoundKind() const;
 
   NormalizedConstraint &getLHS() const;
   NormalizedConstraint &getRHS() const;
 
-  AtomicConstraint *getAtomicConstraint() const {
-assert(isAtomic() &&
-   "getAtomicConstraint called on non-atomic constraint.");
-return Constraint.get();
-  }
+  AtomicConstraint *getAtomicConstraint() const;
 
-  FoldExpandedConstraint *getFoldExpandedConstraint() const {
-assert(isFoldExpanded() &&
-   "getFoldExpandedConstraint called on non-fold-expanded 
constraint.");
-return Constraint.get();
-  }
+  FoldExpandedConstraint *getFoldExpandedConstraint() const;
 
 private:
   static std::optional
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index ff1df7b71b1a4f..539de00bd104f5 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -1958,3 +1958,21 @@ 
concepts::TypeRequirement::TypeRequirement(TypeSourceInfo *T) :
 Value(T),
 Status(T->getType()->isInstantiationDependentType() ? SS_Dependent
 : SS_Satisfied) {}
+
+NormalizedConstraint::CompoundConstraintKind
+NormalizedConstraint::getCompoundKind() const {
+  assert(isCompound() && "getCompoundKind on a non-compound constraint..");
+  return cast(Constraint).getInt();
+}
+
+AtomicConstraint *NormalizedConstraint::getAtomicConstraint() const {
+  assert(isAtomic() && "getAtomicConstraint called on non-atomic constraint.");
+  return cast(Constraint);
+}
+
+FoldExpandedConstraint *
+NormalizedConstraint::getFoldExpandedConstraint() const {
+  assert(isFoldExpanded() &&
+ "getFoldExpandedConstraint called on non-fold-expanded constraint.");
+  return cast(Constraint);
+}

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


[clang] [Sema] Migrate away from PointerUnion::{is, get} (NFC) (PR #120829)

2024-12-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)


Changes

Note that PointerUnion::{is,get} have been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //isa, cast and the llvm::dyn_cast

I'm moving the definitions of several functions to SemaConcept.cpp
because llvm::cast requires the full definitions of
NormalizedConstraintPair, which is used like so:

  using CompoundConstraint = llvm::PointerIntPair;


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


2 Files Affected:

- (modified) clang/include/clang/Sema/SemaConcept.h (+6-17) 
- (modified) clang/lib/Sema/SemaConcept.cpp (+18) 


``diff
diff --git a/clang/include/clang/Sema/SemaConcept.h 
b/clang/include/clang/Sema/SemaConcept.h
index fa5309a597b3a5..5c599a70532f63 100644
--- a/clang/include/clang/Sema/SemaConcept.h
+++ b/clang/include/clang/Sema/SemaConcept.h
@@ -135,31 +135,20 @@ struct NormalizedConstraint {
 return *this;
   }
 
-  bool isAtomic() const { return Constraint.is(); }
+  bool isAtomic() const { return llvm::isa(Constraint); }
   bool isFoldExpanded() const {
-return Constraint.is();
+return llvm::isa(Constraint);
   }
-  bool isCompound() const { return Constraint.is(); }
+  bool isCompound() const { return llvm::isa(Constraint); }
 
-  CompoundConstraintKind getCompoundKind() const {
-assert(isCompound() && "getCompoundKind on a non-compound constraint..");
-return Constraint.get().getInt();
-  }
+  CompoundConstraintKind getCompoundKind() const;
 
   NormalizedConstraint &getLHS() const;
   NormalizedConstraint &getRHS() const;
 
-  AtomicConstraint *getAtomicConstraint() const {
-assert(isAtomic() &&
-   "getAtomicConstraint called on non-atomic constraint.");
-return Constraint.get();
-  }
+  AtomicConstraint *getAtomicConstraint() const;
 
-  FoldExpandedConstraint *getFoldExpandedConstraint() const {
-assert(isFoldExpanded() &&
-   "getFoldExpandedConstraint called on non-fold-expanded 
constraint.");
-return Constraint.get();
-  }
+  FoldExpandedConstraint *getFoldExpandedConstraint() const;
 
 private:
   static std::optional
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index ff1df7b71b1a4f..539de00bd104f5 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -1958,3 +1958,21 @@ 
concepts::TypeRequirement::TypeRequirement(TypeSourceInfo *T) :
 Value(T),
 Status(T->getType()->isInstantiationDependentType() ? SS_Dependent
 : SS_Satisfied) {}
+
+NormalizedConstraint::CompoundConstraintKind
+NormalizedConstraint::getCompoundKind() const {
+  assert(isCompound() && "getCompoundKind on a non-compound constraint..");
+  return cast(Constraint).getInt();
+}
+
+AtomicConstraint *NormalizedConstraint::getAtomicConstraint() const {
+  assert(isAtomic() && "getAtomicConstraint called on non-atomic constraint.");
+  return cast(Constraint);
+}
+
+FoldExpandedConstraint *
+NormalizedConstraint::getFoldExpandedConstraint() const {
+  assert(isFoldExpanded() &&
+ "getFoldExpandedConstraint called on non-fold-expanded constraint.");
+  return cast(Constraint);
+}

``




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


[clang] [clang-format] Fix crashes when the macro expansion is empty (PR #119428)

2024-12-21 Thread via cfe-commits

https://github.com/amane-ame updated 
https://github.com/llvm/llvm-project/pull/119428

From 3a4c1a924faef3a7a09126694fcb943bd7083451 Mon Sep 17 00:00:00 2001
From: amane-ame 
Date: Wed, 11 Dec 2024 02:13:43 +0800
Subject: [PATCH 1/6] Fix crashes when the macro expansion is empty

---
 clang/lib/Format/MacroExpander.cpp | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang/lib/Format/MacroExpander.cpp 
b/clang/lib/Format/MacroExpander.cpp
index fd2a16894d643d..ed9e51dfbfef1f 100644
--- a/clang/lib/Format/MacroExpander.cpp
+++ b/clang/lib/Format/MacroExpander.cpp
@@ -233,6 +233,10 @@ MacroExpander::expand(FormatToken *ID,
   if (Result.size() > 1) {
 ++Result[0]->MacroCtx->StartOfExpansion;
 ++Result[Result.size() - 2]->MacroCtx->EndOfExpansion;
+  } else {
+// If the macro expansion is empty, mark the start and end
+Result[0]->MacroCtx->StartOfExpansion = 1;
+Result[0]->MacroCtx->EndOfExpansion = 1;
   }
   return Result;
 }

From 8bf68f87b897bab9da9464d594082be5012afdb1 Mon Sep 17 00:00:00 2001
From: amane-ame 
Date: Sun, 15 Dec 2024 15:15:17 +0800
Subject: [PATCH 2/6] [clang-format] Add a testcase for empty macro

---
 clang/test/Format/empty-macro.cpp | 5 +
 1 file changed, 5 insertions(+)
 create mode 100644 clang/test/Format/empty-macro.cpp

diff --git a/clang/test/Format/empty-macro.cpp 
b/clang/test/Format/empty-macro.cpp
new file mode 100644
index 00..81b255219b0c2b
--- /dev/null
+++ b/clang/test/Format/empty-macro.cpp
@@ -0,0 +1,5 @@
+// RUN: grep -Ev "// *[A-Z-]+:" %s | clang-format -style="{Macros: [A(x)=x]}" \
+// RUN:   | FileCheck -strict-whitespace %s
+
+// CHECK: A()
+A()

From 37a5b1b1877a7292869a93f7bfd4c0ec9814 Mon Sep 17 00:00:00 2001
From: amane-ame 
Date: Mon, 16 Dec 2024 16:30:27 +0800
Subject: [PATCH 3/6] [clang-format] Move the testcase to unittest

---
 clang/test/Format/empty-macro.cpp   |  5 -
 .../unittests/Format/MacroCallReconstructorTest.cpp | 13 +
 2 files changed, 13 insertions(+), 5 deletions(-)
 delete mode 100644 clang/test/Format/empty-macro.cpp

diff --git a/clang/test/Format/empty-macro.cpp 
b/clang/test/Format/empty-macro.cpp
deleted file mode 100644
index 81b255219b0c2b..00
--- a/clang/test/Format/empty-macro.cpp
+++ /dev/null
@@ -1,5 +0,0 @@
-// RUN: grep -Ev "// *[A-Z-]+:" %s | clang-format -style="{Macros: [A(x)=x]}" \
-// RUN:   | FileCheck -strict-whitespace %s
-
-// CHECK: A()
-A()
diff --git a/clang/unittests/Format/MacroCallReconstructorTest.cpp 
b/clang/unittests/Format/MacroCallReconstructorTest.cpp
index b4ee8d0e37efa8..08088fe48fdf6a 100644
--- a/clang/unittests/Format/MacroCallReconstructorTest.cpp
+++ b/clang/unittests/Format/MacroCallReconstructorTest.cpp
@@ -217,6 +217,19 @@ TEST_F(MacroCallReconstructorTest, Identifier) {
   EXPECT_THAT(std::move(Unexp).takeResult(), 
matchesLine(line(U.consume("X";
 }
 
+TEST_F(MacroCallReconstructorTest, EmptyExpansion) {
+  auto Macros = createExpander({"A(x)=y"});
+  Expansion Exp(Lex, *Macros);
+  TokenList Call = Exp.expand("A", {""});
+
+  MacroCallReconstructor Unexp(0, Exp.getUnexpanded());
+  Unexp.addLine(line(Exp.getTokens()));
+  EXPECT_TRUE(Unexp.finished());
+  Matcher U(Call, Lex);
+  EXPECT_THAT(std::move(Unexp).takeResult(),
+  matchesLine(line(U.consume("A()";
+}
+
 TEST_F(MacroCallReconstructorTest, NestedLineWithinCall) {
   auto Macros = createExpander({"C(a)=class X { a; };"});
   Expansion Exp(Lex, *Macros);

From e46f0e059d61fb370c5f76ede99423846f5959c8 Mon Sep 17 00:00:00 2001
From: amane-ame 
Date: Thu, 19 Dec 2024 17:11:16 +0800
Subject: [PATCH 4/6] [clang-format] Fix about Tokens in
 MacroCallReconstructorTest

When the macro expansion is empty, the tok::eof Token should be preserved.
The reason is we have marked the start point and end point on this token in 
MacroExpander::expand.
---
 clang/unittests/Format/MacroCallReconstructorTest.cpp | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/unittests/Format/MacroCallReconstructorTest.cpp 
b/clang/unittests/Format/MacroCallReconstructorTest.cpp
index 08088fe48fdf6a..1364de0727f4e7 100644
--- a/clang/unittests/Format/MacroCallReconstructorTest.cpp
+++ b/clang/unittests/Format/MacroCallReconstructorTest.cpp
@@ -65,7 +65,9 @@ class Expansion {
 }
 Unexpanded[ID] = std::move(UnexpandedLine);
 
-auto Expanded = uneof(Macros.expand(ID, Args));
+auto Expanded = Macros.expand(ID, Args);
+if (Expanded.size() > 1)
+  Expanded = uneof(Expanded);
 Tokens.append(Expanded.begin(), Expanded.end());
 
 TokenList UnexpandedTokens;
@@ -218,7 +220,7 @@ TEST_F(MacroCallReconstructorTest, Identifier) {
 }
 
 TEST_F(MacroCallReconstructorTest, EmptyExpansion) {
-  auto Macros = createExpander({"A(x)=y"});
+  auto Macros = createExpander({"A(x)=x"});
   Expansion Exp(Lex, *Macros);
   TokenList Call = Exp.expand("A", {""});
 

From 6a390e3cf9e7fff9c55d8bc516aa8aba4d15dedf Mon Sep 17 00:00:

[clang] [clang-format] Fix crashes when the macro expansion is empty (PR #119428)

2024-12-21 Thread via cfe-commits


@@ -0,0 +1,5 @@
+// RUN: grep -Ev "// *[A-Z-]+:" %s | clang-format -style="{Macros: [A(x)=x]}" \
+// RUN:   | FileCheck -strict-whitespace %s
+
+// CHECK: A()
+A()

amane-ame wrote:

Sorry for misunderstood.

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


[clang] Factor common code for quoting a builtin name (PR #120835)

2024-12-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Chandler Carruth (chandlerc)


Changes

This shows up in several places in order to match the quoting of other uses of 
the same diagnostic. Handling it centrally simplifies the code and reduces 
changes if the storage for builtin names changes.

This refactoring is extracted out of #120534 as requested in code 
review.

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


4 Files Affected:

- (modified) clang/include/clang/Basic/Builtins.h (+3) 
- (modified) clang/lib/AST/ByteCode/InterpBuiltin.cpp (+2-2) 
- (modified) clang/lib/AST/ExprConstant.cpp (+7-8) 
- (modified) clang/lib/Basic/Builtins.cpp (+4) 


``diff
diff --git a/clang/include/clang/Basic/Builtins.h 
b/clang/include/clang/Basic/Builtins.h
index e27d8ccce73664..63559d977ce6b6 100644
--- a/clang/include/clang/Basic/Builtins.h
+++ b/clang/include/clang/Basic/Builtins.h
@@ -102,6 +102,9 @@ class Context {
   /// e.g. "__builtin_abs".
   llvm::StringRef getName(unsigned ID) const { return getRecord(ID).Name; }
 
+  /// Return a quoted name for the specified builtin for use in diagnostics.
+  std::string getQuotedName(unsigned ID) const;
+
   /// Get the type descriptor string for the specified builtin.
   const char *getTypeString(unsigned ID) const { return getRecord(ID).Type; }
 
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 2ae91feb2d9e8e..ed18e1b24c323e 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -154,7 +154,7 @@ static void diagnoseNonConstexprBuiltin(InterpState &S, 
CodePtr OpPC,
   if (S.getLangOpts().CPlusPlus11)
 S.CCEDiag(Loc, diag::note_constexpr_invalid_function)
 << /*isConstexpr=*/0 << /*isConstructor=*/0
-<< ("'" + S.getASTContext().BuiltinInfo.getName(ID) + "'").str();
+<< S.getASTContext().BuiltinInfo.getQuotedName(ID);
   else
 S.CCEDiag(Loc, diag::note_invalid_subexpr_in_const_expr);
 }
@@ -1948,7 +1948,7 @@ static bool interp__builtin_memcmp(InterpState &S, 
CodePtr OpPC,
   !isOneByteCharacterType(PtrB.getType( {
 S.FFDiag(S.Current->getSource(OpPC),
  diag::note_constexpr_memcmp_unsupported)
-<< ("'" + ASTCtx.BuiltinInfo.getName(ID) + "'").str() << PtrA.getType()
+<< ASTCtx.BuiltinInfo.getQuotedName(ID) << PtrA.getType()
 << PtrB.getType();
 return false;
   }
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 89c515e6392764..c667fddfbf8120 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -9858,7 +9858,7 @@ bool PointerExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
 if (Info.getLangOpts().CPlusPlus11)
   Info.CCEDiag(E, diag::note_constexpr_invalid_function)
   << /*isConstexpr*/ 0 << /*isConstructor*/ 0
-  << ("'" + Info.Ctx.BuiltinInfo.getName(BuiltinOp) + "'").str();
+  << Info.Ctx.BuiltinInfo.getQuotedName(BuiltinOp);
 else
   Info.CCEDiag(E, diag::note_invalid_subexpr_in_const_expr);
 [[fallthrough]];
@@ -9903,8 +9903,7 @@ bool PointerExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
 // FIXME: We can compare the bytes in the correct order.
 if (IsRawByte && !isOneByteCharacterType(CharTy)) {
   Info.FFDiag(E, diag::note_constexpr_memchr_unsupported)
-  << ("'" + Info.Ctx.BuiltinInfo.getName(BuiltinOp) + "'").str()
-  << CharTy;
+  << Info.Ctx.BuiltinInfo.getQuotedName(BuiltinOp) << CharTy;
   return false;
 }
 // Figure out what value we're actually looking for (after converting to
@@ -9966,7 +9965,7 @@ bool PointerExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
 if (Info.getLangOpts().CPlusPlus11)
   Info.CCEDiag(E, diag::note_constexpr_invalid_function)
   << /*isConstexpr*/ 0 << /*isConstructor*/ 0
-  << ("'" + Info.Ctx.BuiltinInfo.getName(BuiltinOp) + "'").str();
+  << Info.Ctx.BuiltinInfo.getQuotedName(BuiltinOp);
 else
   Info.CCEDiag(E, diag::note_invalid_subexpr_in_const_expr);
 [[fallthrough]];
@@ -13241,7 +13240,7 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
 if (Info.getLangOpts().CPlusPlus11)
   Info.CCEDiag(E, diag::note_constexpr_invalid_function)
   << /*isConstexpr*/ 0 << /*isConstructor*/ 0
-  << ("'" + Info.Ctx.BuiltinInfo.getName(BuiltinOp) + "'").str();
+  << Info.Ctx.BuiltinInfo.getQuotedName(BuiltinOp);
 else
   Info.CCEDiag(E, diag::note_invalid_subexpr_in_const_expr);
 [[fallthrough]];
@@ -13266,7 +13265,7 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
 if (Info.getLangOpts().CPlusPlus11)
   Info.CCEDiag(E, diag::note_constexpr_invalid_function)
   << /*isConstexpr*/ 0 << /*isConstructor*/ 0
-  << ("'" + Info.Ctx.BuiltinInfo.getName(BuiltinOp) + "'").str();
+  << Info

[clang] Factor common code for quoting a builtin name (PR #120835)

2024-12-21 Thread Chandler Carruth via cfe-commits

https://github.com/chandlerc created 
https://github.com/llvm/llvm-project/pull/120835

This shows up in several places in order to match the quoting of other uses of 
the same diagnostic. Handling it centrally simplifies the code and reduces 
changes if the storage for builtin names changes.

This refactoring is extracted out of #120534 as requested in code review.

>From ab211da29a4f5910e21ef626f6a9df448c910d55 Mon Sep 17 00:00:00 2001
From: Chandler Carruth 
Date: Sat, 21 Dec 2024 09:26:24 +
Subject: [PATCH] Factor common code for quoting a builtin name

This shows up in several places in order to match the quoting of other
uses of the same diagnostic. Handling it centrally simplifies the code
and reduces changes if the storage for builtin names changes.

This refactoring is extracted out of #120534 as requested in code
review.
---
 clang/include/clang/Basic/Builtins.h |  3 +++
 clang/lib/AST/ByteCode/InterpBuiltin.cpp |  4 ++--
 clang/lib/AST/ExprConstant.cpp   | 15 +++
 clang/lib/Basic/Builtins.cpp |  4 
 4 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/clang/include/clang/Basic/Builtins.h 
b/clang/include/clang/Basic/Builtins.h
index e27d8ccce73664..63559d977ce6b6 100644
--- a/clang/include/clang/Basic/Builtins.h
+++ b/clang/include/clang/Basic/Builtins.h
@@ -102,6 +102,9 @@ class Context {
   /// e.g. "__builtin_abs".
   llvm::StringRef getName(unsigned ID) const { return getRecord(ID).Name; }
 
+  /// Return a quoted name for the specified builtin for use in diagnostics.
+  std::string getQuotedName(unsigned ID) const;
+
   /// Get the type descriptor string for the specified builtin.
   const char *getTypeString(unsigned ID) const { return getRecord(ID).Type; }
 
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 2ae91feb2d9e8e..ed18e1b24c323e 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -154,7 +154,7 @@ static void diagnoseNonConstexprBuiltin(InterpState &S, 
CodePtr OpPC,
   if (S.getLangOpts().CPlusPlus11)
 S.CCEDiag(Loc, diag::note_constexpr_invalid_function)
 << /*isConstexpr=*/0 << /*isConstructor=*/0
-<< ("'" + S.getASTContext().BuiltinInfo.getName(ID) + "'").str();
+<< S.getASTContext().BuiltinInfo.getQuotedName(ID);
   else
 S.CCEDiag(Loc, diag::note_invalid_subexpr_in_const_expr);
 }
@@ -1948,7 +1948,7 @@ static bool interp__builtin_memcmp(InterpState &S, 
CodePtr OpPC,
   !isOneByteCharacterType(PtrB.getType( {
 S.FFDiag(S.Current->getSource(OpPC),
  diag::note_constexpr_memcmp_unsupported)
-<< ("'" + ASTCtx.BuiltinInfo.getName(ID) + "'").str() << PtrA.getType()
+<< ASTCtx.BuiltinInfo.getQuotedName(ID) << PtrA.getType()
 << PtrB.getType();
 return false;
   }
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 89c515e6392764..c667fddfbf8120 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -9858,7 +9858,7 @@ bool PointerExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
 if (Info.getLangOpts().CPlusPlus11)
   Info.CCEDiag(E, diag::note_constexpr_invalid_function)
   << /*isConstexpr*/ 0 << /*isConstructor*/ 0
-  << ("'" + Info.Ctx.BuiltinInfo.getName(BuiltinOp) + "'").str();
+  << Info.Ctx.BuiltinInfo.getQuotedName(BuiltinOp);
 else
   Info.CCEDiag(E, diag::note_invalid_subexpr_in_const_expr);
 [[fallthrough]];
@@ -9903,8 +9903,7 @@ bool PointerExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
 // FIXME: We can compare the bytes in the correct order.
 if (IsRawByte && !isOneByteCharacterType(CharTy)) {
   Info.FFDiag(E, diag::note_constexpr_memchr_unsupported)
-  << ("'" + Info.Ctx.BuiltinInfo.getName(BuiltinOp) + "'").str()
-  << CharTy;
+  << Info.Ctx.BuiltinInfo.getQuotedName(BuiltinOp) << CharTy;
   return false;
 }
 // Figure out what value we're actually looking for (after converting to
@@ -9966,7 +9965,7 @@ bool PointerExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
 if (Info.getLangOpts().CPlusPlus11)
   Info.CCEDiag(E, diag::note_constexpr_invalid_function)
   << /*isConstexpr*/ 0 << /*isConstructor*/ 0
-  << ("'" + Info.Ctx.BuiltinInfo.getName(BuiltinOp) + "'").str();
+  << Info.Ctx.BuiltinInfo.getQuotedName(BuiltinOp);
 else
   Info.CCEDiag(E, diag::note_invalid_subexpr_in_const_expr);
 [[fallthrough]];
@@ -13241,7 +13240,7 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
 if (Info.getLangOpts().CPlusPlus11)
   Info.CCEDiag(E, diag::note_constexpr_invalid_function)
   << /*isConstexpr*/ 0 << /*isConstructor*/ 0
-  << ("'" + Info.Ctx.BuiltinInfo.getName(BuiltinOp) + "'").str();
+  << Info.Ctx.BuiltinInfo.getQuotedName(BuiltinOp);
 else
   I

[clang] [clang] Return larger CXX records in memory (PR #120670)

2024-12-21 Thread Phoebe Wang via cfe-commits


@@ -245,6 +245,7 @@ class LangOptionsBase {
 ///   construction vtable because it hasn't added 'type' as a substitution.
 ///   - Skip mangling enclosing class templates of member-like friend
 ///   function templates.
+///   - Incorrectly return C++ records in AVX registers.

phoebewang wrote:

in AVX registers on x86_64.

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


[clang] [Clang] Prevent assignment to captured structured bindings inside immutable lambda (PR #120849)

2024-12-21 Thread via cfe-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write 
permissions for the repository. In which case you can instead tag reviewers by 
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a 
review by "ping"ing the PR by adding a comment “Ping”. The common courtesy 
"ping" rate is once a week. Please remember that you are asking for valuable 
time from other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[clang] [Clang] Prevent assignment to captured structured bindings inside immutable lambda (PR #120849)

2024-12-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: TilakChad (TilakChad)


Changes

For structured bindings, a call to getCapturedDeclRefType(...) was missing. 
This PR fixes that behavior and adds the related diagnostics too. 

This fixes https://github.com/llvm/llvm-project/issues/95081.

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+1) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+16-9) 
- (modified) clang/test/SemaCXX/cxx20-decomposition.cpp (+23) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6b9e1109f3906e..8b79ab4f551a8a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -884,6 +884,7 @@ Bug Fixes to C++ Support
 - Fixed recognition of ``std::initializer_list`` when it's surrounded with 
``extern "C++"`` and exported
   out of a module (which is the case e.g. in MSVC's implementation of ``std`` 
module). (#GH118218)
 - Fixed a pack expansion issue in checking unexpanded parameter sizes. 
(#GH17042)
+- Fixed a bug where captured structured bindings were modifiable inside 
non-mutable lambda (#GH95081)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 24f7d27c691154..b5e247644ef36e 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -3352,6 +3352,7 @@ ExprResult Sema::BuildDeclarationNameExpr(
   case Decl::VarTemplateSpecialization:
   case Decl::VarTemplatePartialSpecialization:
   case Decl::Decomposition:
+  case Decl::Binding:
   case Decl::OMPCapturedExpr:
 // In C, "extern void blah;" is valid and is an r-value.
 if (!getLangOpts().CPlusPlus && !type.hasQualifiers() &&
@@ -3371,20 +3372,13 @@ ExprResult Sema::BuildDeclarationNameExpr(
 // potentially-evaluated contexts? Since the variable isn't actually
 // captured in an unevaluated context, it seems that the answer is no.
 if (!isUnevaluatedContext()) {
-  QualType CapturedType = getCapturedDeclRefType(cast(VD), Loc);
+  QualType CapturedType = getCapturedDeclRefType(cast(VD), Loc);
   if (!CapturedType.isNull())
 type = CapturedType;
 }
-
 break;
   }
 
-  case Decl::Binding:
-// These are always lvalues.
-valueKind = VK_LValue;
-type = type.getNonReferenceType();
-break;
-
   case Decl::Function: {
 if (unsigned BID = cast(VD)->getBuiltinID()) {
   if (!Context.BuiltinInfo.isDirectlyAddressable(BID)) {
@@ -13299,7 +13293,18 @@ static NonConstCaptureKind 
isReferenceToNonConstCapture(Sema &S, Expr *E) {
 
   // The declaration must be a variable which is not declared 'const'.
   VarDecl *var = dyn_cast(DRE->getDecl());
-  if (!var) return NCCK_None;
+  if (!var) {
+// Bindings also can be captured by lambda in C++
+BindingDecl *binding = dyn_cast(DRE->getDecl());
+if (!binding || binding->getType().isConstQualified())
+  return NCCK_None;
+
+assert(S.getLangOpts().CPlusPlus && "BindingDecl outside of C++?");
+assert(!isa(binding->getDeclContext()));
+
+return NCCK_Lambda;
+  }
+
   if (var->getType().isConstQualified()) return NCCK_None;
   assert(var->hasLocalStorage() && "capture added 'const' to non-local?");
 
@@ -19247,6 +19252,8 @@ bool Sema::NeedToCaptureVariable(ValueDecl *Var, 
SourceLocation Loc) {
 }
 
 QualType Sema::getCapturedDeclRefType(ValueDecl *Var, SourceLocation Loc) {
+  assert(Var && "Null value cannot be captured");
+
   QualType CaptureType;
   QualType DeclRefType;
 
diff --git a/clang/test/SemaCXX/cxx20-decomposition.cpp 
b/clang/test/SemaCXX/cxx20-decomposition.cpp
index 430a158ff458ed..ccc1af5898059f 100644
--- a/clang/test/SemaCXX/cxx20-decomposition.cpp
+++ b/clang/test/SemaCXX/cxx20-decomposition.cpp
@@ -183,3 +183,26 @@ namespace ODRUseTests {
 }(0); }(0); // expected-note 2{{in instantiation}}
   }
 }
+
+
+namespace GH95081 {
+void prevent_assignment_check() {
+int arr[] = {1,2};
+auto [e1, e2] = arr;
+
+auto lambda = [e1] {
+e1 = 42;  // expected-error {{cannot assign to a variable captured 
by copy in a non-mutable lambda}}
+};
+}
+
+void f(int&) = delete;
+void f(const int&);
+
+int arr[1];
+void foo() {
+auto [x] = arr;
+[x]() {
+f(x); // deleted f(int&) used to be picked up erroneously
+} ();
+}
+}

``




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


[clang] [Clang] Prevent assignment to captured structured bindings inside immutable lambda (PR #120849)

2024-12-21 Thread via cfe-commits

https://github.com/TilakChad created 
https://github.com/llvm/llvm-project/pull/120849

For structured bindings, a call to getCapturedDeclRefType(...) was missing. 
This PR fixes that behavior and adds the related diagnostics too. 

This fixes https://github.com/llvm/llvm-project/issues/95081.

>From f35f0712ea3fcb8c053e7f0405b606c01450ad57 Mon Sep 17 00:00:00 2001
From: Tilak Chad 
Date: Sat, 21 Dec 2024 19:22:37 +0545
Subject: [PATCH] [Clang] Prevent assignment to captured structured bindings
 inside immutable lambda

---
 clang/docs/ReleaseNotes.rst|  1 +
 clang/lib/Sema/SemaExpr.cpp| 25 ++
 clang/test/SemaCXX/cxx20-decomposition.cpp | 23 
 3 files changed, 40 insertions(+), 9 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6b9e1109f3906e..8b79ab4f551a8a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -884,6 +884,7 @@ Bug Fixes to C++ Support
 - Fixed recognition of ``std::initializer_list`` when it's surrounded with 
``extern "C++"`` and exported
   out of a module (which is the case e.g. in MSVC's implementation of ``std`` 
module). (#GH118218)
 - Fixed a pack expansion issue in checking unexpanded parameter sizes. 
(#GH17042)
+- Fixed a bug where captured structured bindings were modifiable inside 
non-mutable lambda (#GH95081)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 24f7d27c691154..b5e247644ef36e 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -3352,6 +3352,7 @@ ExprResult Sema::BuildDeclarationNameExpr(
   case Decl::VarTemplateSpecialization:
   case Decl::VarTemplatePartialSpecialization:
   case Decl::Decomposition:
+  case Decl::Binding:
   case Decl::OMPCapturedExpr:
 // In C, "extern void blah;" is valid and is an r-value.
 if (!getLangOpts().CPlusPlus && !type.hasQualifiers() &&
@@ -3371,20 +3372,13 @@ ExprResult Sema::BuildDeclarationNameExpr(
 // potentially-evaluated contexts? Since the variable isn't actually
 // captured in an unevaluated context, it seems that the answer is no.
 if (!isUnevaluatedContext()) {
-  QualType CapturedType = getCapturedDeclRefType(cast(VD), Loc);
+  QualType CapturedType = getCapturedDeclRefType(cast(VD), Loc);
   if (!CapturedType.isNull())
 type = CapturedType;
 }
-
 break;
   }
 
-  case Decl::Binding:
-// These are always lvalues.
-valueKind = VK_LValue;
-type = type.getNonReferenceType();
-break;
-
   case Decl::Function: {
 if (unsigned BID = cast(VD)->getBuiltinID()) {
   if (!Context.BuiltinInfo.isDirectlyAddressable(BID)) {
@@ -13299,7 +13293,18 @@ static NonConstCaptureKind 
isReferenceToNonConstCapture(Sema &S, Expr *E) {
 
   // The declaration must be a variable which is not declared 'const'.
   VarDecl *var = dyn_cast(DRE->getDecl());
-  if (!var) return NCCK_None;
+  if (!var) {
+// Bindings also can be captured by lambda in C++
+BindingDecl *binding = dyn_cast(DRE->getDecl());
+if (!binding || binding->getType().isConstQualified())
+  return NCCK_None;
+
+assert(S.getLangOpts().CPlusPlus && "BindingDecl outside of C++?");
+assert(!isa(binding->getDeclContext()));
+
+return NCCK_Lambda;
+  }
+
   if (var->getType().isConstQualified()) return NCCK_None;
   assert(var->hasLocalStorage() && "capture added 'const' to non-local?");
 
@@ -19247,6 +19252,8 @@ bool Sema::NeedToCaptureVariable(ValueDecl *Var, 
SourceLocation Loc) {
 }
 
 QualType Sema::getCapturedDeclRefType(ValueDecl *Var, SourceLocation Loc) {
+  assert(Var && "Null value cannot be captured");
+
   QualType CaptureType;
   QualType DeclRefType;
 
diff --git a/clang/test/SemaCXX/cxx20-decomposition.cpp 
b/clang/test/SemaCXX/cxx20-decomposition.cpp
index 430a158ff458ed..ccc1af5898059f 100644
--- a/clang/test/SemaCXX/cxx20-decomposition.cpp
+++ b/clang/test/SemaCXX/cxx20-decomposition.cpp
@@ -183,3 +183,26 @@ namespace ODRUseTests {
 }(0); }(0); // expected-note 2{{in instantiation}}
   }
 }
+
+
+namespace GH95081 {
+void prevent_assignment_check() {
+int arr[] = {1,2};
+auto [e1, e2] = arr;
+
+auto lambda = [e1] {
+e1 = 42;  // expected-error {{cannot assign to a variable captured 
by copy in a non-mutable lambda}}
+};
+}
+
+void f(int&) = delete;
+void f(const int&);
+
+int arr[1];
+void foo() {
+auto [x] = arr;
+[x]() {
+f(x); // deleted f(int&) used to be picked up erroneously
+} ();
+}
+}

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


[clang] [clang] Introduce a new UEFI target predefine. (PR #111719)

2024-12-21 Thread via cfe-commits

https://github.com/Prabhuk updated 
https://github.com/llvm/llvm-project/pull/111719

>From 05eab970b59c61b22e8afa1ed9381906ae925c03 Mon Sep 17 00:00:00 2001
From: prabhukr 
Date: Wed, 9 Oct 2024 10:16:58 -0700
Subject: [PATCH 1/5] [clang] Introduce a new UEFI target predefine.

---
 clang/lib/Basic/Targets/OSTargets.h | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index a83d6464e789d6..92c76b303def65 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -783,7 +783,10 @@ template 
 class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo {
 protected:
   void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
-MacroBuilder &Builder) const override {}
+MacroBuilder &Builder) const override {
+Builder.defineMacro("__UEFI__");
+Builder.defineMacro("__PECOFF__");
+  }
 
 public:
   UEFITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)

>From 4ef8bcd3a9019299145b59d4f26cd4307171bed5 Mon Sep 17 00:00:00 2001
From: Prabhuk 
Date: Wed, 13 Nov 2024 10:30:50 -0800
Subject: [PATCH 2/5] Update OSTargets.h

Remove PE_COFF
---
 clang/lib/Basic/Targets/OSTargets.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index 92c76b303def65..5a23eef0117294 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -785,7 +785,6 @@ class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public 
OSTargetInfo {
   void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
 MacroBuilder &Builder) const override {
 Builder.defineMacro("__UEFI__");
-Builder.defineMacro("__PECOFF__");
   }
 
 public:

>From bcccf1f86609a828130c1a9474d10b78c8f212c9 Mon Sep 17 00:00:00 2001
From: Prabhuk 
Date: Wed, 13 Nov 2024 10:36:15 -0800
Subject: [PATCH 3/5] add __UEFI__ to windows predefines

Updating the PE COFF generating windows code path to predefine the new __UEFI__ 
macro.
---
 clang/lib/Basic/Targets/OSTargets.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/lib/Basic/Targets/OSTargets.cpp 
b/clang/lib/Basic/Targets/OSTargets.cpp
index b56e2c7ca9c494..b9edeefa60148e 100644
--- a/clang/lib/Basic/Targets/OSTargets.cpp
+++ b/clang/lib/Basic/Targets/OSTargets.cpp
@@ -259,6 +259,7 @@ static void addVisualCDefines(const LangOptions &Opts, 
MacroBuilder &Builder) {
 
 void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts,
MacroBuilder &Builder) {
+  Builder.defineMacro("__UEFI__");
   Builder.defineMacro("_WIN32");
   if (Triple.isArch64Bit())
 Builder.defineMacro("_WIN64");

>From 2f6af5664bbd6f3cc01dfb7b46f67190dc4efba4 Mon Sep 17 00:00:00 2001
From: prabhukr 
Date: Fri, 20 Dec 2024 10:18:18 -0800
Subject: [PATCH 4/5] Removing the predefine from Windows targets. Keeping it
 only on UEFI.

---
 clang/lib/Basic/Targets/OSTargets.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/lib/Basic/Targets/OSTargets.cpp 
b/clang/lib/Basic/Targets/OSTargets.cpp
index b9edeefa60148e..b56e2c7ca9c494 100644
--- a/clang/lib/Basic/Targets/OSTargets.cpp
+++ b/clang/lib/Basic/Targets/OSTargets.cpp
@@ -259,7 +259,6 @@ static void addVisualCDefines(const LangOptions &Opts, 
MacroBuilder &Builder) {
 
 void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts,
MacroBuilder &Builder) {
-  Builder.defineMacro("__UEFI__");
   Builder.defineMacro("_WIN32");
   if (Triple.isArch64Bit())
 Builder.defineMacro("_WIN64");

>From 4c96e0d1bbae207301aacaee9044f3da7dc8bd3f Mon Sep 17 00:00:00 2001
From: prabhukr 
Date: Sat, 21 Dec 2024 13:16:38 -0800
Subject: [PATCH 5/5] Add a test to check if __UEFI__ is defined for UEFI
 targets.

---
 clang/test/Driver/uefi-defines.c | 6 ++
 1 file changed, 6 insertions(+)
 create mode 100644 clang/test/Driver/uefi-defines.c

diff --git a/clang/test/Driver/uefi-defines.c b/clang/test/Driver/uefi-defines.c
new file mode 100644
index 00..45f27bfdb9fa98
--- /dev/null
+++ b/clang/test/Driver/uefi-defines.c
@@ -0,0 +1,6 @@
+// RUN: %clang -target x86_64-unknown-uefi %s -emit-llvm -S -c -o - | 
FileCheck %s
+
+// CHECK: __UEFI__defined
+#ifdef __UEFI__
+void __UEFI__defined() {}
+#endif

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


[clang] [clang] Introduce a new UEFI target predefine. (PR #111719)

2024-12-21 Thread via cfe-commits

https://github.com/Prabhuk updated 
https://github.com/llvm/llvm-project/pull/111719

>From 05eab970b59c61b22e8afa1ed9381906ae925c03 Mon Sep 17 00:00:00 2001
From: prabhukr 
Date: Wed, 9 Oct 2024 10:16:58 -0700
Subject: [PATCH 1/5] [clang] Introduce a new UEFI target predefine.

---
 clang/lib/Basic/Targets/OSTargets.h | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index a83d6464e789d6..92c76b303def65 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -783,7 +783,10 @@ template 
 class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo {
 protected:
   void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
-MacroBuilder &Builder) const override {}
+MacroBuilder &Builder) const override {
+Builder.defineMacro("__UEFI__");
+Builder.defineMacro("__PECOFF__");
+  }
 
 public:
   UEFITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)

>From 4ef8bcd3a9019299145b59d4f26cd4307171bed5 Mon Sep 17 00:00:00 2001
From: Prabhuk 
Date: Wed, 13 Nov 2024 10:30:50 -0800
Subject: [PATCH 2/5] Update OSTargets.h

Remove PE_COFF
---
 clang/lib/Basic/Targets/OSTargets.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index 92c76b303def65..5a23eef0117294 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -785,7 +785,6 @@ class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public 
OSTargetInfo {
   void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
 MacroBuilder &Builder) const override {
 Builder.defineMacro("__UEFI__");
-Builder.defineMacro("__PECOFF__");
   }
 
 public:

>From bcccf1f86609a828130c1a9474d10b78c8f212c9 Mon Sep 17 00:00:00 2001
From: Prabhuk 
Date: Wed, 13 Nov 2024 10:36:15 -0800
Subject: [PATCH 3/5] add __UEFI__ to windows predefines

Updating the PE COFF generating windows code path to predefine the new __UEFI__ 
macro.
---
 clang/lib/Basic/Targets/OSTargets.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/lib/Basic/Targets/OSTargets.cpp 
b/clang/lib/Basic/Targets/OSTargets.cpp
index b56e2c7ca9c494..b9edeefa60148e 100644
--- a/clang/lib/Basic/Targets/OSTargets.cpp
+++ b/clang/lib/Basic/Targets/OSTargets.cpp
@@ -259,6 +259,7 @@ static void addVisualCDefines(const LangOptions &Opts, 
MacroBuilder &Builder) {
 
 void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts,
MacroBuilder &Builder) {
+  Builder.defineMacro("__UEFI__");
   Builder.defineMacro("_WIN32");
   if (Triple.isArch64Bit())
 Builder.defineMacro("_WIN64");

>From 2f6af5664bbd6f3cc01dfb7b46f67190dc4efba4 Mon Sep 17 00:00:00 2001
From: prabhukr 
Date: Fri, 20 Dec 2024 10:18:18 -0800
Subject: [PATCH 4/5] Removing the predefine from Windows targets. Keeping it
 only on UEFI.

---
 clang/lib/Basic/Targets/OSTargets.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/lib/Basic/Targets/OSTargets.cpp 
b/clang/lib/Basic/Targets/OSTargets.cpp
index b9edeefa60148e..b56e2c7ca9c494 100644
--- a/clang/lib/Basic/Targets/OSTargets.cpp
+++ b/clang/lib/Basic/Targets/OSTargets.cpp
@@ -259,7 +259,6 @@ static void addVisualCDefines(const LangOptions &Opts, 
MacroBuilder &Builder) {
 
 void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts,
MacroBuilder &Builder) {
-  Builder.defineMacro("__UEFI__");
   Builder.defineMacro("_WIN32");
   if (Triple.isArch64Bit())
 Builder.defineMacro("_WIN64");

>From 4c96e0d1bbae207301aacaee9044f3da7dc8bd3f Mon Sep 17 00:00:00 2001
From: prabhukr 
Date: Sat, 21 Dec 2024 13:16:38 -0800
Subject: [PATCH 5/5] Add a test to check if __UEFI__ is defined for UEFI
 targets.

---
 clang/test/Driver/uefi-defines.c | 6 ++
 1 file changed, 6 insertions(+)
 create mode 100644 clang/test/Driver/uefi-defines.c

diff --git a/clang/test/Driver/uefi-defines.c b/clang/test/Driver/uefi-defines.c
new file mode 100644
index 00..45f27bfdb9fa98
--- /dev/null
+++ b/clang/test/Driver/uefi-defines.c
@@ -0,0 +1,6 @@
+// RUN: %clang -target x86_64-unknown-uefi %s -emit-llvm -S -c -o - | 
FileCheck %s
+
+// CHECK: __UEFI__defined
+#ifdef __UEFI__
+void __UEFI__defined() {}
+#endif

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


[clang] [X86][AVX10.2] Add comments for the avx10_2convertintrin.h file (PR #120766)

2024-12-21 Thread Mikołaj Piróg via cfe-commits


@@ -24,567 +24,3243 @@
   __attribute__((__always_inline__, __nodebug__, __target__("avx10.2-256"),
\
  __min_vector_width__(256)))
 
+/// Convert two 128-bit vectors, \a __A and \a __B, containing packed
+/// single-precision (32-bit) floating-point elements to a 128-bit vector
+/// containing FP16 elements.
+///
+/// \code{.operation}
+/// FOR i := 0 to 7
+///IF i < 4
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4])
+///FI
+/// ENDFOR
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction.
+///
+/// \param __A
+///A 128-bit vector of [4 x float].
+/// \param __B
+///A 128-bit vector of [4 x float].
+/// \returns
+///A 128-bit vector of [8 x fp16]. Lower elements correspond to the
+///(converted) elements from \a __B; higher order elements correspond to 
the
+///(converted) elements from \a __A.
 static __inline__ __m128h __DEFAULT_FN_ATTRS128 _mm_cvtx2ps_ph(__m128 __A,
__m128 __B) {
   return (__m128h)__builtin_ia32_vcvt2ps2phx128_mask(
   (__v4sf)__A, (__v4sf)__B, (__v8hf)_mm_setzero_ph(), (__mmask8)(-1));
 }
 
+/// Convert two 128-bit vectors, \a __A and \a __B, containing packed
+/// single-precision (32-bit) floating-point elements to a 128-bit vector
+/// containing FP16 elements. Merging mask \a __U is used to determine if given
+/// element should be taken from \a __W instead.
+///
+/// \code{.operation}
+/// FOR i := 0 to 7
+///IF mask[i]
+///dst.fp16[i] := __W[i]
+///ELSE
+///IF i < 4
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4])
+///FI
+///FI
+/// ENDFOR
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction.
+///
+/// \param __W
+///A 128-bit vector of [8 x fp16].
+/// \param __U
+///A 8-bit merging mask.
+/// \param __A
+///A 128-bit vector of [4 x float].
+/// \param __B
+///A 128-bit vector of [4 x float].
+/// \returns
+///A 128-bit vector of [8 x fp16]. Lower elements correspond to the
+///(converted) elements from \a __B; higher order elements correspond to 
the
+///(converted) elements from \a __A. If corresponding mask bit is set, then
+///element from \a __W is taken instead.
 static __inline__ __m128h __DEFAULT_FN_ATTRS128
 _mm_mask_cvtx2ps_ph(__m128h __W, __mmask8 __U, __m128 __A, __m128 __B) {
   return (__m128h)__builtin_ia32_vcvt2ps2phx128_mask(
   (__v4sf)__A, (__v4sf)__B, (__v8hf)__W, (__mmask8)__U);
 }
 
+/// Convert two 128-bit vectors, \a __A and \a __B, containing packed
+/// single-precision (32-bit) floating-point elements to a 128-bit vector
+/// containing FP16 elements. Zeroing mask \a __U is used to determine if given
+/// element should be zeroed instead.
+///
+/// \code{.operation}
+/// FOR i := 0 to 7
+///IF mask[i]
+///IF i < 4
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4])
+///FI
+///ELSE
+///dst.fp16[i] := 0
+///FI
+/// ENDFOR
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction.
+///
+/// \param __U
+///A 8-bit zeroing mask.
+/// \param __A
+///A 128-bit vector of [4 x float].
+/// \param __B
+///A 128-bit vector of [4 x float].
+/// \returns
+///A 128-bit vector of [8 x fp16]. Lower elements correspond to the
+///(converted) elements from \a __B; higher order elements correspond to 
the
+///(converted) elements from \a __A. If corresponding mask bit is not set,
+///then zero is taken instead.
 static __inline__ __m128h __DEFAULT_FN_ATTRS128
 _mm_maskz_cvtx2ps_ph(__mmask8 __U, __m128 __A, __m128 __B) {
   return (__m128h)__builtin_ia32_vcvt2ps2phx128_mask(
   (__v4sf)__A, (__v4sf)__B, (__v8hf)_mm_setzero_ph(), (__mmask8)__U);
 }
 
+/// Convert two 256-bit vectors, \a __A and \a __B, containing packed
+/// single-precision (32-bit) floating-point elements to a 256-bit vector
+/// containing FP16 elements.
+///
+/// \code{.operation}
+/// FOR i := 0 to 15
+///IF i < 8
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 8])
+///FI
+/// ENDFOR
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction.
+///
+/// \param __A
+///A 256-bit vector of [8 x float].
+/// \param __B
+///A 256-bit vector of [8 x float].
+/// \returns
+///A 256-bit vector of [16 x fp16]. Lower elements correspond to the
+///(converted) elem

[clang] [clang-format] Add BreakBeforeTemplateClose option (PR #118046)

2024-12-21 Thread via cfe-commits

https://github.com/leijurv updated 
https://github.com/llvm/llvm-project/pull/118046

>From 1caf823165b16f6701993d586df51d5cdbf0885e Mon Sep 17 00:00:00 2001
From: Leijurv 
Date: Fri, 29 Nov 2024 21:54:36 -0600
Subject: [PATCH 1/4] [clang-format] Add BreakBeforeTemplateClose option

---
 clang/docs/ClangFormatStyleOptions.rst |  21 
 clang/docs/ReleaseNotes.rst|   1 +
 clang/include/clang/Format/Format.h|  20 
 clang/lib/Format/ContinuationIndenter.cpp  |  11 ++
 clang/lib/Format/ContinuationIndenter.h|  26 ++--
 clang/lib/Format/Format.cpp|   2 +
 clang/lib/Format/TokenAnnotator.cpp|   2 +-
 clang/unittests/Format/ConfigParseTest.cpp |   1 +
 clang/unittests/Format/FormatTest.cpp  | 131 +
 9 files changed, 206 insertions(+), 9 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 4be448171699ca..84ab1b0a2eff61 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -3416,6 +3416,27 @@ the configuration (without a prefix: ``Auto``).
 
 
 
+.. _BreakBeforeTemplateClose:
+
+**BreakBeforeTemplateClose** (``Boolean``) :versionbadge:`clang-format 20` 
:ref:`¶ `
+  If ``true``, a line break will be placed before the ``>`` in a multiline
+  template declaration.
+
+  .. code-block:: c++
+
+ true:
+ template <
+ typename Foo,
+ typename Bar,
+ typename Baz
+ >
+
+ false:
+ template <
+ typename Foo,
+ typename Bar,
+ typename Baz>
+
 .. _BreakBeforeTernaryOperators:
 
 **BreakBeforeTernaryOperators** (``Boolean``) :versionbadge:`clang-format 3.7` 
:ref:`¶ `
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e44aefa90ab386..867d4b5d8c3f18 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -976,6 +976,7 @@ clang-format
   ``Never``, and ``true`` to ``Always``.
 - Adds ``RemoveEmptyLinesInUnwrappedLines`` option.
 - Adds ``KeepFormFeed`` option and set it to ``true`` for ``GNU`` style.
+- Adds ``BreakBeforeTemplateClose`` option.
 
 libclang
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 6383934afa2c40..bffd964f6aa8aa 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2248,6 +2248,25 @@ struct FormatStyle {
   /// \version 16
   BreakBeforeInlineASMColonStyle BreakBeforeInlineASMColon;
 
+  /// If ``true``, a line break will be placed before the ``>`` in a multiline
+  /// template declaration.
+  /// \code
+  ///true:
+  ///template <
+  ///typename Foo,
+  ///typename Bar,
+  ///typename Baz
+  ///>
+  ///
+  ///false:
+  ///template <
+  ///typename Foo,
+  ///typename Bar,
+  ///typename Baz>
+  /// \endcode
+  /// \version 20
+  bool BreakBeforeTemplateClose;
+
   /// If ``true``, ternary operators will be placed after line breaks.
   /// \code
   ///true:
@@ -5184,6 +5203,7 @@ struct FormatStyle {
BreakBeforeBraces == R.BreakBeforeBraces &&
BreakBeforeConceptDeclarations == R.BreakBeforeConceptDeclarations 
&&
BreakBeforeInlineASMColon == R.BreakBeforeInlineASMColon &&
+   BreakBeforeTemplateClose == R.BreakBeforeTemplateClose &&
BreakBeforeTernaryOperators == R.BreakBeforeTernaryOperators &&
BreakBinaryOperations == R.BreakBinaryOperations &&
BreakConstructorInitializers == R.BreakConstructorInitializers &&
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index aed86c1fb99551..4c783623afc535 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -406,6 +406,10 @@ bool ContinuationIndenter::mustBreak(const LineState 
&State) {
   }
   if (CurrentState.BreakBeforeClosingParen && Current.is(tok::r_paren))
 return true;
+  if (CurrentState.BreakBeforeClosingAngle &&
+  Current.ClosesTemplateDeclaration && Style.BreakBeforeTemplateClose) {
+return true;
+  }
   if (Style.Language == FormatStyle::LK_ObjC &&
   Style.ObjCBreakBeforeNestedBlockParam &&
   Current.ObjCSelectorNameParts > 1 &&
@@ -1234,6 +1238,9 @@ unsigned 
ContinuationIndenter::addTokenOnNewLine(LineState &State,
 Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent;
   }
 
+  if (PreviousNonComment && PreviousNonComment->is(tok::less))
+CurrentState.BreakBeforeClosingAngle = true;
+
   if (CurrentState.AvoidBinPacking) {
 // If we are breaking after '(', '{', '<', or this is the break after a ':'
 // to start a member initializer list in a constructor, this should not
@@ -1370,6 +1377,10 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState &State) {
   State.Stack.size() > 1) {
 return State.Stack[State.Stack.size() - 2].Last

[clang] [clang-format] Add BreakBeforeTemplateClose option (PR #118046)

2024-12-21 Thread via cfe-commits


@@ -11077,6 +11077,221 @@ TEST_F(FormatTest, 
WrapsTemplateDeclarationsWithComments) {
   Style);
 }
 
+TEST_F(FormatTest, BreakBeforeTemplateClose) {
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_Cpp);
+  Style.ColumnLimit = 0;
+  verifyNoChange("template \n"
+ "void foo() {}",
+ Style);
+  verifyNoChange("template <\n"
+ "typename Foo,\n"
+ "typename Bar>\n"
+ "void foo() {}",
+ Style);
+  // when BreakBeforeTemplateClose is off, this line break is removed:
+  verifyFormat("template <\n"
+   "typename Foo,\n"
+   "typename Bar>\n"
+   "void foo() {}",
+   "template <\n"
+   "typename Foo,\n"
+   "typename Bar\n"
+   ">\n"
+   "void foo() {}",
+   Style);
+  Style.BreakBeforeTemplateClose = true;
+  // BreakBeforeTemplateClose should NOT force multiline templates
+  verifyNoChange("template \n"
+ "void foo() {}",
+ Style);
+  verifyNoChange("template \n"
+ "void foo() {}",
+ Style);
+  // it should allow a line break:
+  verifyNoChange("template <\n"
+ "typename Foo\n"
+ ">\n"
+ "void foo() {}",
+ Style);
+  verifyNoChange("template <\n"
+ "typename Foo,\n"
+ "typename Bar\n"
+ ">\n"
+ "void foo() {}",
+ Style);
+  // it should add a line break if not already present:
+  verifyFormat("template <\n"
+   "typename Foo\n"
+   ">\n"
+   "void foo() {}",
+   "template <\n"
+   "typename Foo>\n"
+   "void foo() {}",
+   Style);
+  verifyFormat("template <\n"
+   "typename Foo,\n"
+   "typename Bar\n"
+   ">\n"
+   "void foo() {}",
+   "template <\n"
+   "typename Foo,\n"
+   "typename Bar>\n"
+   "void foo() {}",
+   Style);
+  // when within an indent scope, the > should be placed appropriately:
+  verifyFormat("struct Baz {\n"
+   "  template <\n"
+   "  typename Foo,\n"
+   "  typename Bar\n"
+   "  >\n"
+   "  void foo() {}\n"
+   "};",
+   "struct Baz {\n"
+   "  template <\n"
+   "  typename Foo,\n"
+   "  typename Bar>\n"
+   "  void foo() {}\n"
+   "};",
+   Style);
+
+  // test from issue #80049
+  verifyFormat(
+  "void foo() {\n"
+  "  using type = std::remove_cv_t<\n"
+  "  add_common_cv_reference<\n"
+  "  std::common_type_t, std::decay_t>,\n"
+  "  T0,\n"
+  "  T1\n"
+  "  >\n"
+  "  >;\n"
+  "}\n",
+  "void foo() {\n"
+  "  using type = std::remove_cv_t<\n"
+  "  add_common_cv_reference<\n"
+  "  std::common_type_t, std::decay_t>,\n"
+  "  T0,\n"
+  "  T1>>;\n"
+  "}\n",
+  Style);
+
+  // test lambda goes to next line:

leijurv wrote:

Sure! 
https://github.com/llvm/llvm-project/pull/118046/commits/2c3a64c8f32a5c43887db4d107a4142490898c20

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


[clang] [clang-format] Add BreakBeforeTemplateClose option (PR #118046)

2024-12-21 Thread via cfe-commits


@@ -11077,6 +11077,221 @@ TEST_F(FormatTest, 
WrapsTemplateDeclarationsWithComments) {
   Style);
 }
 
+TEST_F(FormatTest, BreakBeforeTemplateClose) {

leijurv wrote:

Sure! 
https://github.com/llvm/llvm-project/pull/118046/commits/2c3a64c8f32a5c43887db4d107a4142490898c20

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


[clang] [Serialization] Migrate away from PointerUnion::get (NFC) (PR #120844)

2024-12-21 Thread Nikita Popov via cfe-commits

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


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


[clang] [libcxx] [clang][driver] Cleanup UEFI toolchain driver (PR #111473)

2024-12-21 Thread via cfe-commits


@@ -35,6 +35,24 @@ UEFI::UEFI(const Driver &D, const llvm::Triple &Triple, 
const ArgList &Args)
 
 Tool *UEFI::buildLinker() const { return new tools::uefi::Linker(*this); }
 
+void UEFI::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
+ ArgStringList &CC1Args) const {
+  if (DriverArgs.hasArg(options::OPT_nostdinc))
+return;
+
+  if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
+SmallString<128> Dir(getDriver().ResourceDir);
+llvm::sys::path::append(Dir, "include");
+addSystemInclude(DriverArgs, CC1Args, Dir.str());

Prabhuk wrote:

We have a minimal test here: 
https://github.com/llvm/llvm-project/blob/main/clang/test/Driver/uefi-constructed-args.c

This is the header search paths with this PR. My original goal of this change 
was to remove `/usr/include` and `/usr/local/include` from the search list.

```
[hi on] prabhukr@prabhukr:~/llvm-builds/b2$ ./bin/clang -E -v 
--target=x86_64-uefi - < /dev/null
Fuchsia clang version 20.0.0git (g...@github.com:prabhuk/llvm-project.git 
e30c180214f2ca102ba6fcf1b542db7c5f2ac5fd)
Target: x86_64-unknown-uefi
Thread model: posix
InstalledDir: /usr/local/google/home/prabhukr/llvm-builds/b2/bin
Build config: +assertions
 (in-process)
 "/usr/local/google/home/prabhukr/llvm-builds/b2/bin/llvm" "clang" -cc1 -triple 
x86_64-unknown-uefi -E -disable-free -clear-ast-before-backend -main-file-name 
- -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fmath-errno 
-ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 
-target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb 
-fdebug-compilation-dir=/usr/local/google/home/prabhukr/llvm-builds/b2 -v 
-fcoverage-compilation-dir=/usr/local/google/home/prabhukr/llvm-builds/b2 
-resource-dir /usr/local/google/home/prabhukr/llvm-builds/b2/lib/clang/20 
-internal-isystem 
/usr/local/google/home/prabhukr/llvm-builds/b2/lib/clang/20/include 
-ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf 
-fcolor-diagnostics -faddrsig -o - -x c -
clang -cc1 version 20.0.0git based upon LLVM 20.0.0git default target 
x86_64-unknown-linux-gnu
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/google/home/prabhukr/llvm-builds/b2/lib/clang/20/include
End of search list.
# 1 ""
# 1 "" 1
# 1 "" 3
# 389 "" 3
# 1 "" 1
# 1 "" 2
# 1 "" 2

```


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


[clang] Mechanically port bulk of x86 builtins to TableGen (PR #120831)

2024-12-21 Thread Chandler Carruth via cfe-commits

chandlerc wrote:

> > * Systematically using `Oi` instead of `LLi` for the type `long long int`. 
> > The `.def` file uses a mixture of `Oi` and `LLi`. I chose the shorter 
> > encoding.
> 
> The mixture use of `Oi` and `LLi` is a mess, but `Oi` has different meaning 
> for OpenCL targets. I think we should not change `LLi` to `Oi`. I think a lot 
> `Oi` can be replaced with `LLi`, but I cannot tell which are required with a 
> quick look.

I do understand that, but I'm actually a bit more confident that these changes 
are correct... Or at least not a regression.

Specifically, the x86 intrinsic builtins use `Oi` *very* consistently for "quad 
word" (64-bit) vector operations from SSE through AVX2. For example 
`__builtin_ia32_psllqi256` uses `V4Oi`. This seems quite intentional, so I was 
very hesitant to reverse it.

The places where `LLi` has crept in are:
- 1 or 2 very isolated cases I'll list explicitly below
- Some AVX-512 and SHA512 intrinsics. This seems like a mistake as they're also 
using it for "double word" (64-bit) vector elements, the exact same element 
size that uses `Oi` elsewhere. And some actually *do* use `Oi` with the same 
feature (`avx10.2-256`), so I couldn't see any pattern that seemed to indicate 
a critical distinction...

I think the AVX-512 stuff was just added without realizing the historical use 
of `Oi` here?

The only examples outside of AVX-512 and SHA512 I could find:
- `__builtin_ia32_rdpru`
- `__emul` and `__emulu` (MS intrinsics)
- `__readfsqword` and `__readgsqword` (also MS intrinsics)

I can understand that these don't make lots of sense in OpenCL, but they also 
seem very unlikely to show up or do the wrong thing here, when getting the same 
type that OpenCL uses for 64-bit vector elements on x86?

The reason I'd like to consolidate here is that preserving this distinction 
would add complexity to the tablegen code, and at least *seems* like it may be 
propagating more of a mistake than a careful choice in AVX-512 (especially 
given the lack of test coverage that errors with the change as is).

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


[clang] [clang-format] Fix a crash in `QualifierAlignment: Right` (PR #120821)

2024-12-21 Thread Emilia Kond via cfe-commits

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


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


[clang] [compiler-rt] [llvm] Single byte coverage with branch coverage (PR #113115)

2024-12-21 Thread NAKAMURA Takumi via cfe-commits

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


[clang] [clang-format] Fix a crash in `QualifierAlignment: Right` (PR #120821)

2024-12-21 Thread Owen Pan via cfe-commits

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


[clang] 40acaa3 - [clang-format] Fix a crash in `QualifierAlignment: Right` (#120821)

2024-12-21 Thread via cfe-commits

Author: Owen Pan
Date: 2024-12-21T17:16:29-08:00
New Revision: 40acaa394fa235796c2d98de87380887c59d5448

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

LOG: [clang-format] Fix a crash in `QualifierAlignment: Right` (#120821)

Fixes #120793.

Added: 


Modified: 
clang/lib/Format/QualifierAlignmentFixer.cpp
clang/unittests/Format/QualifierFixerTest.cpp

Removed: 




diff  --git a/clang/lib/Format/QualifierAlignmentFixer.cpp 
b/clang/lib/Format/QualifierAlignmentFixer.cpp
index 593f8efff25aa9..530b2dd538cee0 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.cpp
+++ b/clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -348,7 +348,7 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeRight(
   }
 }
 
-if (Next->is(tok::kw_auto))
+if (Next && Next->is(tok::kw_auto))
   TypeToken = Next;
 
 // Place the Qualifier at the end of the list of qualifiers.

diff  --git a/clang/unittests/Format/QualifierFixerTest.cpp 
b/clang/unittests/Format/QualifierFixerTest.cpp
index f9255c6e4c7088..9ed567445eb07e 100644
--- a/clang/unittests/Format/QualifierFixerTest.cpp
+++ b/clang/unittests/Format/QualifierFixerTest.cpp
@@ -531,6 +531,11 @@ TEST_F(QualifierFixerTest, RightQualifier) {
   verifyFormat("float (C::*const p)(int);", Style);
   verifyFormat("float (C::*p)(int) const;", Style);
   verifyFormat("float const (C::*p)(int);", "const float (C::*p)(int);", 
Style);
+
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  Style.BraceWrapping.AfterFunction = true;
+  verifyFormat("auto foo() -> T const { return bar; }",
+   "auto foo() -> const T { return bar; }", Style);
 }
 
 TEST_F(QualifierFixerTest, LeftQualifier) {



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


[clang] [clang] constexpr built-in reduce min/max function. (PR #120866)

2024-12-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (c8ef)


Changes

Part of #51787.

This patch adds constexpr support for the built-in reduce min/max function.

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


5 Files Affected:

- (modified) clang/docs/LanguageExtensions.rst (+4-3) 
- (modified) clang/docs/ReleaseNotes.rst (+2-1) 
- (modified) clang/include/clang/Basic/Builtins.td (+2-2) 
- (modified) clang/lib/AST/ExprConstant.cpp (+11-1) 
- (modified) clang/test/Sema/constant_builtins_vector.cpp (+15) 


``diff
diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 3d4f68b818bce7..cc5f1d4ddf4477 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -736,9 +736,10 @@ at the end to the next power of 2.
 
 These reductions support both fixed-sized and scalable vector types.
 
-The integer reduction intrinsics, including ``__builtin_reduce_add``,
-``__builtin_reduce_mul``, ``__builtin_reduce_and``, ``__builtin_reduce_or``,
-and ``__builtin_reduce_xor``, can be called in a ``constexpr`` context.
+The integer reduction intrinsics, including ``__builtin_reduce_max``,
+``__builtin_reduce_min``, ``__builtin_reduce_add``, ``__builtin_reduce_mul``,
+``__builtin_reduce_and``, ``__builtin_reduce_or``, and 
``__builtin_reduce_xor``,
+can be called in a ``constexpr`` context.
 
 Example:
 
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6b9e1109f3906e..8b984ecaefecaf 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -421,7 +421,8 @@ Non-comprehensive list of changes in this release
   ``__builtin_reduce_mul``, ``__builtin_reduce_and``, ``__builtin_reduce_or``,
   ``__builtin_reduce_xor``, ``__builtin_elementwise_popcount``,
   ``__builtin_elementwise_bitreverse``, ``__builtin_elementwise_add_sat``,
-  ``__builtin_elementwise_sub_sat``.
+  ``__builtin_elementwise_sub_sat``, ``__builtin_reduce_min`` (For integral 
element type),
+  ``__builtin_reduce_max`` (For integral element type).
 
 - Clang now rejects ``_BitInt`` matrix element types if the bit width is less 
than ``CHAR_WIDTH`` or
   not a power of two, matching preexisting behaviour for vector types.
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index d64a66fc9d9cf7..b5b47ae2746011 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -1462,13 +1462,13 @@ def ElementwiseSubSat : Builtin {
 
 def ReduceMax : Builtin {
   let Spellings = ["__builtin_reduce_max"];
-  let Attributes = [NoThrow, Const, CustomTypeChecking];
+  let Attributes = [NoThrow, Const, CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def ReduceMin : Builtin {
   let Spellings = ["__builtin_reduce_min"];
-  let Attributes = [NoThrow, Const, CustomTypeChecking];
+  let Attributes = [NoThrow, Const, CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 89c515e6392764..dd75dca647540a 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -13604,7 +13604,9 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
   case Builtin::BI__builtin_reduce_mul:
   case Builtin::BI__builtin_reduce_and:
   case Builtin::BI__builtin_reduce_or:
-  case Builtin::BI__builtin_reduce_xor: {
+  case Builtin::BI__builtin_reduce_xor:
+  case Builtin::BI__builtin_reduce_min:
+  case Builtin::BI__builtin_reduce_max: {
 APValue Source;
 if (!EvaluateAsRValue(Info, E->getArg(0), Source))
   return false;
@@ -13641,6 +13643,14 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
 Reduced ^= Source.getVectorElt(EltNum).getInt();
 break;
   }
+  case Builtin::BI__builtin_reduce_min: {
+Reduced = std::min(Reduced, Source.getVectorElt(EltNum).getInt());
+break;
+  }
+  case Builtin::BI__builtin_reduce_max: {
+Reduced = std::max(Reduced, Source.getVectorElt(EltNum).getInt());
+break;
+  }
   }
 }
 
diff --git a/clang/test/Sema/constant_builtins_vector.cpp 
b/clang/test/Sema/constant_builtins_vector.cpp
index b2f56e5a87ab1a..d8f04b313835ea 100644
--- a/clang/test/Sema/constant_builtins_vector.cpp
+++ b/clang/test/Sema/constant_builtins_vector.cpp
@@ -838,3 +838,18 @@ static_assert(__builtin_elementwise_sub_sat((1 << 31), 42) 
== (1 << 31));
 static_assert(__builtin_elementwise_sub_sat(0U, 1U) == 0U);
 static_assert(__builtin_bit_cast(unsigned, 
__builtin_elementwise_sub_sat((vector4char){5, 4, 3, 2}, (vector4char){1, 1, 1, 
1})) == (LITTLE_END ? 0x01020304 : 0x04030201));
 static_assert(__builtin_bit_cast(unsigned long long, 
__builtin_elementwise_sub_sat((vector4short){(short)0x8000, (short)0x8001, 
(short)0x8002, (short)0x8003}, (vector4short){7, 8, 9, 10}) == (LITTLE_END ? 
0x8000800080008000 : 0x8000800080008000)));

[clang] [clang] constexpr built-in reduce min/max function. (PR #120866)

2024-12-21 Thread via cfe-commits

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


[clang] Mechanically port bulk of x86 builtins to TableGen (PR #120831)

2024-12-21 Thread Phoebe Wang via cfe-commits

phoebewang wrote:

> A long way from an expert on OpenCL, but it seems to not even have the 
> concept of `long long`, and `long` is defined as a 64-bit type (and just 
> optional for embedded stuff)?
> 
> https://registry.khronos.org/OpenCL/sdk/3.0/docs/man/html/scalarDataTypes.html

Thanks for the confirmation! Does OpenCL supports Windows? IIRC, long is 32-bit 
on Windows.

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


[clang] [clang] Introduce a new UEFI target predefine. (PR #111719)

2024-12-21 Thread via cfe-commits

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


[clang] [clang] fix uefi target for aarch64 & x86_64 (PR #120632)

2024-12-21 Thread Tristan Ross via cfe-commits

https://github.com/RossComputerGuy updated 
https://github.com/llvm/llvm-project/pull/120632

>From a9b162f2dbf8e2e102bc8f4cf7af51331e648502 Mon Sep 17 00:00:00 2001
From: Tristan Ross 
Date: Thu, 19 Dec 2024 10:54:58 -0800
Subject: [PATCH 1/5] [clang] fix uefi data layout on x86 & aarch64

---
 clang/lib/Basic/Targets/AArch64.cpp | 3 +++
 clang/lib/Basic/Targets/X86.h   | 4 ++--
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 53e102bbe44687..dd5d033afd8763 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -1537,6 +1537,9 @@ void AArch64leTargetInfo::setDataLayout() {
   resetDataLayout("e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-"
   "n32:64-S128-Fn32",
   "_");
+  } else if (getTriple().isUEFI() && getTriple().isOSBinFormatCOFF()) {
+resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-p:64:64-i32:32-"
+"i64:64-i128:128-n32:64-S128-Fn32");
   } else
 resetDataLayout("e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-"
 "i64:64-i128:128-n32:64-S128-Fn32");
diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index 553c452d4ba3c2..033c7c525bb6cd 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -713,8 +713,8 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public 
X86TargetInfo {
   X86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
   : X86TargetInfo(Triple, Opts) {
 const bool IsX32 = getTriple().isX32();
-bool IsWinCOFF =
-getTriple().isOSWindows() && getTriple().isOSBinFormatCOFF();
+bool IsWinCOFF = (getTriple().isOSWindows() || getTriple().isUEFI()) &&
+ getTriple().isOSBinFormatCOFF();
 LongWidth = LongAlign = PointerWidth = PointerAlign = IsX32 ? 32 : 64;
 LongDoubleWidth = 128;
 LongDoubleAlign = 128;

>From e0008eb4fd9081ca00c1e3813f724450bcce0ce2 Mon Sep 17 00:00:00 2001
From: Tristan Ross 
Date: Thu, 19 Dec 2024 08:37:46 -0800
Subject: [PATCH 2/5] [clang] add __uefi__ define

---
 clang/lib/Basic/Targets/OSTargets.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index cd9b3760ca5874..24ffd542d664c7 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -790,7 +790,9 @@ template 
 class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo {
 protected:
   void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
-MacroBuilder &Builder) const override {}
+MacroBuilder &Builder) const override {
+DefineStd(Builder, "uefi", Opts);
+  }
 
 public:
   UEFITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)

>From 166e2fdbe0db4098a20fb72c1ffb3dec43e4f159 Mon Sep 17 00:00:00 2001
From: Tristan Ross 
Date: Thu, 19 Dec 2024 13:40:50 -0800
Subject: [PATCH 3/5] [clang] add __uefi__ test for aarch64 & x86_64

---
 clang/test/Preprocessor/init.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c
index 05225c120b13de..8708b12e6cf0c5 100644
--- a/clang/test/Preprocessor/init.c
+++ b/clang/test/Preprocessor/init.c
@@ -2742,3 +2742,10 @@
 // RISCV64-LINUX: #define __unix__ 1
 // RISCV64-LINUX: #define linux 1
 // RISCV64-LINUX: #define unix 1
+//
+// RUN: %clang_cc1 -dM -triple=aarch64-unknown-uefi -E < /dev/null | FileCheck 
-match-full-lines -check-prefix UEFI %s
+// RUN: %clang_cc1 -dM -triple=x86_64-unknown-uefi -E /dev/null | FileCheck 
-match-full-lines -check-prefix UEFI %s
+//
+// UEFI: #define __uefi 1
+// UEFI: #define __uefi__ 1
+// UEFI: #define uefi 1

>From 7d89fa6997b36bc0ab00093a0e407128d2996dd9 Mon Sep 17 00:00:00 2001
From: Tristan Ross 
Date: Thu, 19 Dec 2024 13:52:26 -0800
Subject: [PATCH 4/5] [clang] add uefi to target os macros

---
 clang/include/clang/Basic/TargetOSMacros.def | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang/include/clang/Basic/TargetOSMacros.def 
b/clang/include/clang/Basic/TargetOSMacros.def
index 58dce330f9c8fd..f4f3276ad1c256 100644
--- a/clang/include/clang/Basic/TargetOSMacros.def
+++ b/clang/include/clang/Basic/TargetOSMacros.def
@@ -53,4 +53,7 @@ TARGET_OS(TARGET_OS_NANO, Triple.isWatchOS())
 TARGET_OS(TARGET_IPHONE_SIMULATOR, Triple.isSimulatorEnvironment())
 TARGET_OS(TARGET_OS_UIKITFORMAC, Triple.isMacCatalystEnvironment())
 
+// UEFI target.
+TARGET_OS(TARGET_OS_UEFI, Triple.isUEFI())
+
 #undef TARGET_OS

>From b41e7a80f67fb9c82fdf81d2acebf9aa4ff11b57 Mon Sep 17 00:00:00 2001
From: Tristan Ross 
Date: Thu, 19 Dec 2024 14:13:09 -0800
Subject: [PATCH 5/5] [clang] use mixin for aarch64 and x86_64 uefi

---
 clang/lib/Basic/Targets.cpp |  6 +-
 clang/lib/Basic/Targets/OST

[clang] [clang] Introduce a new UEFI target predefine. (PR #111719)

2024-12-21 Thread via cfe-commits

https://github.com/Prabhuk updated 
https://github.com/llvm/llvm-project/pull/111719

>From 05eab970b59c61b22e8afa1ed9381906ae925c03 Mon Sep 17 00:00:00 2001
From: prabhukr 
Date: Wed, 9 Oct 2024 10:16:58 -0700
Subject: [PATCH 1/6] [clang] Introduce a new UEFI target predefine.

---
 clang/lib/Basic/Targets/OSTargets.h | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index a83d6464e789d6..92c76b303def65 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -783,7 +783,10 @@ template 
 class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo {
 protected:
   void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
-MacroBuilder &Builder) const override {}
+MacroBuilder &Builder) const override {
+Builder.defineMacro("__UEFI__");
+Builder.defineMacro("__PECOFF__");
+  }
 
 public:
   UEFITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)

>From 4ef8bcd3a9019299145b59d4f26cd4307171bed5 Mon Sep 17 00:00:00 2001
From: Prabhuk 
Date: Wed, 13 Nov 2024 10:30:50 -0800
Subject: [PATCH 2/6] Update OSTargets.h

Remove PE_COFF
---
 clang/lib/Basic/Targets/OSTargets.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index 92c76b303def65..5a23eef0117294 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -785,7 +785,6 @@ class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public 
OSTargetInfo {
   void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
 MacroBuilder &Builder) const override {
 Builder.defineMacro("__UEFI__");
-Builder.defineMacro("__PECOFF__");
   }
 
 public:

>From bcccf1f86609a828130c1a9474d10b78c8f212c9 Mon Sep 17 00:00:00 2001
From: Prabhuk 
Date: Wed, 13 Nov 2024 10:36:15 -0800
Subject: [PATCH 3/6] add __UEFI__ to windows predefines

Updating the PE COFF generating windows code path to predefine the new __UEFI__ 
macro.
---
 clang/lib/Basic/Targets/OSTargets.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/lib/Basic/Targets/OSTargets.cpp 
b/clang/lib/Basic/Targets/OSTargets.cpp
index b56e2c7ca9c494..b9edeefa60148e 100644
--- a/clang/lib/Basic/Targets/OSTargets.cpp
+++ b/clang/lib/Basic/Targets/OSTargets.cpp
@@ -259,6 +259,7 @@ static void addVisualCDefines(const LangOptions &Opts, 
MacroBuilder &Builder) {
 
 void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts,
MacroBuilder &Builder) {
+  Builder.defineMacro("__UEFI__");
   Builder.defineMacro("_WIN32");
   if (Triple.isArch64Bit())
 Builder.defineMacro("_WIN64");

>From 2f6af5664bbd6f3cc01dfb7b46f67190dc4efba4 Mon Sep 17 00:00:00 2001
From: prabhukr 
Date: Fri, 20 Dec 2024 10:18:18 -0800
Subject: [PATCH 4/6] Removing the predefine from Windows targets. Keeping it
 only on UEFI.

---
 clang/lib/Basic/Targets/OSTargets.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/lib/Basic/Targets/OSTargets.cpp 
b/clang/lib/Basic/Targets/OSTargets.cpp
index b9edeefa60148e..b56e2c7ca9c494 100644
--- a/clang/lib/Basic/Targets/OSTargets.cpp
+++ b/clang/lib/Basic/Targets/OSTargets.cpp
@@ -259,7 +259,6 @@ static void addVisualCDefines(const LangOptions &Opts, 
MacroBuilder &Builder) {
 
 void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts,
MacroBuilder &Builder) {
-  Builder.defineMacro("__UEFI__");
   Builder.defineMacro("_WIN32");
   if (Triple.isArch64Bit())
 Builder.defineMacro("_WIN64");

>From 4c96e0d1bbae207301aacaee9044f3da7dc8bd3f Mon Sep 17 00:00:00 2001
From: prabhukr 
Date: Sat, 21 Dec 2024 13:16:38 -0800
Subject: [PATCH 5/6] Add a test to check if __UEFI__ is defined for UEFI
 targets.

---
 clang/test/Driver/uefi-defines.c | 6 ++
 1 file changed, 6 insertions(+)
 create mode 100644 clang/test/Driver/uefi-defines.c

diff --git a/clang/test/Driver/uefi-defines.c b/clang/test/Driver/uefi-defines.c
new file mode 100644
index 00..45f27bfdb9fa98
--- /dev/null
+++ b/clang/test/Driver/uefi-defines.c
@@ -0,0 +1,6 @@
+// RUN: %clang -target x86_64-unknown-uefi %s -emit-llvm -S -c -o - | 
FileCheck %s
+
+// CHECK: __UEFI__defined
+#ifdef __UEFI__
+void __UEFI__defined() {}
+#endif

>From 2bdba34c073852622a5adef9147c4c3fbc6e3562 Mon Sep 17 00:00:00 2001
From: prabhukr 
Date: Sat, 21 Dec 2024 14:09:00 -0800
Subject: [PATCH 6/6] Add a second test for __UEFI__ predefine.

---
 clang/test/Preprocessor/init.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c
index 05225c120b13de..3b99204acd7a44 100644
--- a/clang/test/Preprocessor/init.c
+++ b/clang/test/Preprocessor/init.c
@@ -2742,3 +2742,7 @@
 // RISCV64-LINUX: #define __unix__ 1
 // RISCV64-LINUX: #define linux 1
 // RISCV64-LINUX:

[clang-tools-extra] [clangd] Augment code completion results with documentation from the index. (PR #120099)

2024-12-21 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

> I've come across an issue with this, again. This seems to work for headers 
> I've written myself (or at least ones in my own project), but for e.g. 
> standard library include types, it doesn't work. Something like
> 
> ```
>   std::string a;
>   a.^
> ```
> 
> still contains no documentation in the autocompletion results even though 
> there are doccomments in the header in question.

Seems to be template-related.

test.hpp:
```c++
template 
struct templated {
  // comment
  void foo();
};
struct nontemplated {
  // comment
  void foo();
};
```

test.cpp:
```c++
#include "main.hpp"
void foo() {
  nontemplated n;
  n.f^   // comment is shown
  templated t;
  t.f^  // comment is not shown
}
```

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


[clang] [HLSL] Fix debug info generation for RWBuffer types (PR #119041)

2024-12-21 Thread via cfe-commits

https://github.com/joaosaffran updated 
https://github.com/llvm/llvm-project/pull/119041

>From 999f15be166d25521dfca4f95c1c909152f382e0 Mon Sep 17 00:00:00 2001
From: Joao Saffran 
Date: Fri, 6 Dec 2024 01:27:24 +
Subject: [PATCH 1/8] Apply DXC fix and add tests

---
 clang/test/CodeGenHLSL/debug/rwbuffer_debug_info.hlsl | 8 
 1 file changed, 8 insertions(+)
 create mode 100644 clang/test/CodeGenHLSL/debug/rwbuffer_debug_info.hlsl

diff --git a/clang/test/CodeGenHLSL/debug/rwbuffer_debug_info.hlsl 
b/clang/test/CodeGenHLSL/debug/rwbuffer_debug_info.hlsl
new file mode 100644
index 00..b3fce914828b47
--- /dev/null
+++ b/clang/test/CodeGenHLSL/debug/rwbuffer_debug_info.hlsl
@@ -0,0 +1,8 @@
+// RUN: %clang  --driver-mode=dxc -Zi -Fc out.s -T cs_6_3 %s
+
+RWBuffer Out : register(u7, space4);
+
+[numthreads(8,1,1)]
+void main(uint GI : SV_GroupIndex) {
+  Out[GI] = 0;
+}

>From 6c26251d9cc0349afd836e9a933444a9bf943008 Mon Sep 17 00:00:00 2001
From: Joao Saffran 
Date: Fri, 6 Dec 2024 23:17:11 +
Subject: [PATCH 2/8] first attempt

---
 clang/lib/CodeGen/CGDebugInfo.cpp | 9 -
 clang/lib/CodeGen/CGDebugInfo.h   | 2 ++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index f29ddece5dbc95..0cc7cb6bf64a42 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -3492,6 +3492,11 @@ llvm::DIType *CGDebugInfo::CreateType(const PipeType 
*Ty, llvm::DIFile *U) {
   return getOrCreateType(Ty->getElementType(), U);
 }
 
+llvm::DIType *CGDebugInfo::CreateType(const HLSLAttributedResourceType *Ty,
+  llvm::DIFile *U) {
+  return getOrCreateType(Ty->getWrappedType(), U);
+}
+
 llvm::DIType *CGDebugInfo::CreateEnumType(const EnumType *Ty) {
   const EnumDecl *ED = Ty->getDecl();
 
@@ -3834,12 +3839,14 @@ llvm::DIType *CGDebugInfo::CreateTypeNode(QualType Ty, 
llvm::DIFile *Unit) {
 
   case Type::TemplateSpecialization:
 return CreateType(cast(Ty), Unit);
+  case Type::HLSLAttributedResource: {
+return CreateType(cast(Ty), Unit);
+  }
 
   case Type::CountAttributed:
   case Type::Auto:
   case Type::Attributed:
   case Type::BTFTagAttributed:
-  case Type::HLSLAttributedResource:
   case Type::Adjusted:
   case Type::Decayed:
   case Type::DeducedTemplateSpecialization:
diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h
index 3fd0237a1c61dd..38f73eca561b7e 100644
--- a/clang/lib/CodeGen/CGDebugInfo.h
+++ b/clang/lib/CodeGen/CGDebugInfo.h
@@ -196,6 +196,8 @@ class CGDebugInfo {
   llvm::DIType *CreateType(const PointerType *Ty, llvm::DIFile *F);
   llvm::DIType *CreateType(const BlockPointerType *Ty, llvm::DIFile *F);
   llvm::DIType *CreateType(const FunctionType *Ty, llvm::DIFile *F);
+  llvm::DIType *CreateType(const HLSLAttributedResourceType *Ty,
+   llvm::DIFile *F);
   /// Get structure or union type.
   llvm::DIType *CreateType(const RecordType *Tyg);
 

>From 3a198591b39dbf5c2df7455d892cb47544a48e15 Mon Sep 17 00:00:00 2001
From: Joao Saffran 
Date: Fri, 6 Dec 2024 23:24:54 +
Subject: [PATCH 3/8] clean

---
 clang/lib/Sema/HLSLExternalSemaSource.cpp | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp 
b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index f3362fb619afc1..5a0cd8e793753c 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -931,7 +931,7 @@ void 
HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
   constructTypedBufferConceptDecl(*SemaPtr, HLSLNamespace);
   Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "RWBuffer")
  .addSimpleTemplateParams({"element_type"}, TypedBufferConcept)
- .finalizeForwardDeclaration();
+ .Record;
 
   onCompletion(Decl, [this](CXXRecordDecl *Decl) {
 setupBufferType(Decl, *SemaPtr, ResourceClass::UAV,
@@ -945,7 +945,7 @@ void 
HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
   Decl =
   BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, 
"RasterizerOrderedBuffer")
   .addSimpleTemplateParams({"element_type"})
-  .finalizeForwardDeclaration();
+  .Record;
   onCompletion(Decl, [this](CXXRecordDecl *Decl) {
 setupBufferType(Decl, *SemaPtr, ResourceClass::UAV,
 ResourceKind::TypedBuffer, /*IsROV=*/true,
@@ -957,7 +957,7 @@ void 
HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
 
   Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "StructuredBuffer")
  .addSimpleTemplateParams({"element_type"})
- .finalizeForwardDeclaration();
+ .Record;
   onCompletion(Decl, [this](CXXRecordDecl *Decl) {
 setupBufferType(Decl, *SemaPtr, ResourceClass::SRV, 
ResourceKind::RawBuffer,
 /*IsROV=*/false, /*RawBuffer=

[clang] [Clang] Add __builtin_selectvector and use it for AVX512 intrinsics (PR #91306)

2024-12-21 Thread Nikolas Klauser via cfe-commits

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


[clang] c9df8da - [Serialization] Migrate away from PointerUnion::get (NFC) (#120844)

2024-12-21 Thread via cfe-commits

Author: Kazu Hirata
Date: 2024-12-21T17:40:39-08:00
New Revision: c9df8da659acde9445e1de5259d34ccf96948b44

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

LOG: [Serialization] Migrate away from PointerUnion::get (NFC) (#120844)

Note that PointerUnion::get has been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //isa, cast and the llvm::dyn_cast

I'm not touching PointerUnion::dyn_cast for now because it's a bit
complicated; we could blindly migrate it to dyn_cast_if_present, but
we should probably use dyn_cast when the operand is known to be
non-null.

Added: 


Modified: 
clang/lib/Serialization/MultiOnDiskHashTable.h

Removed: 




diff  --git a/clang/lib/Serialization/MultiOnDiskHashTable.h 
b/clang/lib/Serialization/MultiOnDiskHashTable.h
index a0d75ec3a9e76e..6464220f13aeff 100644
--- a/clang/lib/Serialization/MultiOnDiskHashTable.h
+++ b/clang/lib/Serialization/MultiOnDiskHashTable.h
@@ -93,7 +93,7 @@ template class MultiOnDiskHashTable {
 using result_type = OnDiskTable *;
 
 result_type operator()(void *P) const {
-  return Table::getFromOpaqueValue(P).template get();
+  return llvm::cast(Table::getFromOpaqueValue(P));
 }
   };
 
@@ -130,7 +130,7 @@ template class MultiOnDiskHashTable {
 Files.insert(PendingOverrides.begin(), PendingOverrides.end());
 // Explicitly capture Files to work around an MSVC 2015 rejects-valid bug.
 auto ShouldRemove = [&Files](void *T) -> bool {
-  auto *ODT = Table::getFromOpaqueValue(T).template get();
+  auto *ODT = llvm::cast(Table::getFromOpaqueValue(T));
   bool Remove = Files.count(ODT->File);
   if (Remove)
 delete ODT;



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


[clang] [Serialization] Migrate away from PointerUnion::get (NFC) (PR #120844)

2024-12-21 Thread Kazu Hirata via cfe-commits

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


[clang] [clang] constexpr built-in reduce min/max function. (PR #120866)

2024-12-21 Thread via cfe-commits

https://github.com/c8ef created https://github.com/llvm/llvm-project/pull/120866

Part of #51787.

This patch adds constexpr support for the built-in reduce min/max function.

>From 4e16d47641bd02203753752636f1fe90182552e9 Mon Sep 17 00:00:00 2001
From: c8ef 
Date: Sun, 22 Dec 2024 11:08:43 +0800
Subject: [PATCH] constexpr reduce min/max

---
 clang/docs/LanguageExtensions.rst|  7 ---
 clang/docs/ReleaseNotes.rst  |  3 ++-
 clang/include/clang/Basic/Builtins.td|  4 ++--
 clang/lib/AST/ExprConstant.cpp   | 12 +++-
 clang/test/Sema/constant_builtins_vector.cpp | 15 +++
 5 files changed, 34 insertions(+), 7 deletions(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 3d4f68b818bce7..cc5f1d4ddf4477 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -736,9 +736,10 @@ at the end to the next power of 2.
 
 These reductions support both fixed-sized and scalable vector types.
 
-The integer reduction intrinsics, including ``__builtin_reduce_add``,
-``__builtin_reduce_mul``, ``__builtin_reduce_and``, ``__builtin_reduce_or``,
-and ``__builtin_reduce_xor``, can be called in a ``constexpr`` context.
+The integer reduction intrinsics, including ``__builtin_reduce_max``,
+``__builtin_reduce_min``, ``__builtin_reduce_add``, ``__builtin_reduce_mul``,
+``__builtin_reduce_and``, ``__builtin_reduce_or``, and 
``__builtin_reduce_xor``,
+can be called in a ``constexpr`` context.
 
 Example:
 
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6b9e1109f3906e..8b984ecaefecaf 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -421,7 +421,8 @@ Non-comprehensive list of changes in this release
   ``__builtin_reduce_mul``, ``__builtin_reduce_and``, ``__builtin_reduce_or``,
   ``__builtin_reduce_xor``, ``__builtin_elementwise_popcount``,
   ``__builtin_elementwise_bitreverse``, ``__builtin_elementwise_add_sat``,
-  ``__builtin_elementwise_sub_sat``.
+  ``__builtin_elementwise_sub_sat``, ``__builtin_reduce_min`` (For integral 
element type),
+  ``__builtin_reduce_max`` (For integral element type).
 
 - Clang now rejects ``_BitInt`` matrix element types if the bit width is less 
than ``CHAR_WIDTH`` or
   not a power of two, matching preexisting behaviour for vector types.
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index d64a66fc9d9cf7..b5b47ae2746011 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -1462,13 +1462,13 @@ def ElementwiseSubSat : Builtin {
 
 def ReduceMax : Builtin {
   let Spellings = ["__builtin_reduce_max"];
-  let Attributes = [NoThrow, Const, CustomTypeChecking];
+  let Attributes = [NoThrow, Const, CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def ReduceMin : Builtin {
   let Spellings = ["__builtin_reduce_min"];
-  let Attributes = [NoThrow, Const, CustomTypeChecking];
+  let Attributes = [NoThrow, Const, CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 89c515e6392764..dd75dca647540a 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -13604,7 +13604,9 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
   case Builtin::BI__builtin_reduce_mul:
   case Builtin::BI__builtin_reduce_and:
   case Builtin::BI__builtin_reduce_or:
-  case Builtin::BI__builtin_reduce_xor: {
+  case Builtin::BI__builtin_reduce_xor:
+  case Builtin::BI__builtin_reduce_min:
+  case Builtin::BI__builtin_reduce_max: {
 APValue Source;
 if (!EvaluateAsRValue(Info, E->getArg(0), Source))
   return false;
@@ -13641,6 +13643,14 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
 Reduced ^= Source.getVectorElt(EltNum).getInt();
 break;
   }
+  case Builtin::BI__builtin_reduce_min: {
+Reduced = std::min(Reduced, Source.getVectorElt(EltNum).getInt());
+break;
+  }
+  case Builtin::BI__builtin_reduce_max: {
+Reduced = std::max(Reduced, Source.getVectorElt(EltNum).getInt());
+break;
+  }
   }
 }
 
diff --git a/clang/test/Sema/constant_builtins_vector.cpp 
b/clang/test/Sema/constant_builtins_vector.cpp
index b2f56e5a87ab1a..d8f04b313835ea 100644
--- a/clang/test/Sema/constant_builtins_vector.cpp
+++ b/clang/test/Sema/constant_builtins_vector.cpp
@@ -838,3 +838,18 @@ static_assert(__builtin_elementwise_sub_sat((1 << 31), 42) 
== (1 << 31));
 static_assert(__builtin_elementwise_sub_sat(0U, 1U) == 0U);
 static_assert(__builtin_bit_cast(unsigned, 
__builtin_elementwise_sub_sat((vector4char){5, 4, 3, 2}, (vector4char){1, 1, 1, 
1})) == (LITTLE_END ? 0x01020304 : 0x04030201));
 static_assert(__builtin_bit_cast(unsigned long long, 
__builtin_elementwise_sub_sat((vector4short){(short)0x8000,

[clang] [X86][AVX10.2] Add comments for the avx10_2convertintrin.h file (PR #120766)

2024-12-21 Thread Phoebe Wang via cfe-commits
=?utf-8?q?Mikołaj_Piróg?= ,
=?utf-8?q?Mikołaj_Piróg?= ,
=?utf-8?q?Mikołaj_Piróg?= ,
=?utf-8?q?Mikołaj_Piróg?= 
Message-ID:
In-Reply-To: 



@@ -24,573 +24,3369 @@
   __attribute__((__always_inline__, __nodebug__, __target__("avx10.2-256"),
\
  __min_vector_width__(256)))
 
+//clang-format off
+
+/// Convert two 128-bit vectors, \a __A and \a __B, containing packed
+///single-precision (32-bit) floating-point elements to a 128-bit vector
+///containing FP16 elements.
+///
+/// \code{.operation}
+/// FOR i := 0 to 7
+///IF i < 4
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4])
+///FI
+///
+/// dst[MAX:127] := 0
+/// ENDFOR
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction.
+///
+/// \param __A
+///A 128-bit vector of [4 x float].
+/// \param __B
+///A 128-bit vector of [4 x float].
+/// \returns
+///A 128-bit vector of [8 x fp16]. Lower elements correspond to the
+///(converted) elements from \a __B; higher order elements correspond to 
the
+///(converted) elements from \a __A.
 static __inline__ __m128h __DEFAULT_FN_ATTRS128 _mm_cvtx2ps_ph(__m128 __A,
__m128 __B) {
   return (__m128h)__builtin_ia32_vcvt2ps2phx128_mask(
   (__v4sf)__A, (__v4sf)__B, (__v8hf)_mm_setzero_ph(), (__mmask8)(-1));
 }
 
+/// Convert two 128-bit vectors, \a __A and \a __B, containing packed
+///single-precision (32-bit) floating-point elements to a 128-bit vector
+///containing FP16 elements. Merging mask \a __U is used to determine if 
given
+///element should be taken from \a __W instead.
+///
+/// \code{.operation}
+/// FOR i := 0 to 7
+///IF __U[i]
+///IF i < 4
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4])
+///FI
+///ELSE
+///dst.fp16[i] := __W.fp16[i]
+///FI
+///
+/// dst[MAX:127] := 0
+/// ENDFOR
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction.
+///
+/// \param __W
+///A 128-bit vector of [8 x fp16].
+/// \param __U
+///A 8-bit merging mask.
+/// \param __A
+///A 128-bit vector of [4 x float].
+/// \param __B
+///A 128-bit vector of [4 x float].
+/// \returns
+///A 128-bit vector of [8 x fp16]. Lower elements correspond to the
+///(converted) elements from \a __B; higher order elements correspond to 
the
+///(converted) elements from \a __A. If corresponding mask bit is not set, 
then
+///element from \a __W is taken instead.
 static __inline__ __m128h __DEFAULT_FN_ATTRS128
 _mm_mask_cvtx2ps_ph(__m128h __W, __mmask8 __U, __m128 __A, __m128 __B) {
   return (__m128h)__builtin_ia32_vcvt2ps2phx128_mask(
   (__v4sf)__A, (__v4sf)__B, (__v8hf)__W, (__mmask8)__U);
 }
 
+/// Convert two 128-bit vectors, \a __A and \a __B, containing packed
+///single-precision (32-bit) floating-point elements to a 128-bit vector
+///containing FP16 elements. Zeroing mask \a __U is used to determine if 
given
+///element should be zeroed instead.
+///
+/// \code{.operation}
+/// FOR i := 0 to 7
+///IF __U[i]
+///IF i < 4
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4])
+///FI
+///ELSE
+///dst.fp16[i] := 0
+///FI
+/// ENDFOR
+///
+/// dst[MAX:127] := 0
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction.
+///
+/// \param __U
+///A 8-bit zeroing mask.
+/// \param __A
+///A 128-bit vector of [4 x float].
+/// \param __B
+///A 128-bit vector of [4 x float].
+/// \returns
+///A 128-bit vector of [8 x fp16]. Lower elements correspond to the
+///(converted) elements from \a __B; higher order elements correspond to 
the
+///(converted) elements from \a __A. If corresponding mask bit is not set,
+///then zero is taken instead.
 static __inline__ __m128h __DEFAULT_FN_ATTRS128
 _mm_maskz_cvtx2ps_ph(__mmask8 __U, __m128 __A, __m128 __B) {
   return (__m128h)__builtin_ia32_vcvt2ps2phx128_mask(
   (__v4sf)__A, (__v4sf)__B, (__v8hf)_mm_setzero_ph(), (__mmask8)__U);
 }
 
+/// Convert two 256-bit vectors, \a __A and \a __B, containing packed
+///single-precision (32-bit) floating-point elements to a 256-bit vector
+///containing FP16 elements.
+///
+/// \code{.operation}
+/// FOR i := 0 to 15 
+///IF i < 8
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 8])
+///FI
+/// ENDFOR
+///
+/// dst[MAX:256] := 0
+/// \endcode
+///
+/// \he

[clang] [X86][AVX10.2] Add comments for the avx10_2convertintrin.h file (PR #120766)

2024-12-21 Thread Phoebe Wang via cfe-commits
=?utf-8?q?Mikołaj_Piróg?= ,
=?utf-8?q?Mikołaj_Piróg?= ,
=?utf-8?q?Mikołaj_Piróg?= ,
=?utf-8?q?Mikołaj_Piróg?= 
Message-ID:
In-Reply-To: 



@@ -24,573 +24,3369 @@
   __attribute__((__always_inline__, __nodebug__, __target__("avx10.2-256"),
\
  __min_vector_width__(256)))
 
+//clang-format off
+
+/// Convert two 128-bit vectors, \a __A and \a __B, containing packed
+///single-precision (32-bit) floating-point elements to a 128-bit vector
+///containing FP16 elements.
+///
+/// \code{.operation}
+/// FOR i := 0 to 7
+///IF i < 4
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4])
+///FI
+///
+/// dst[MAX:127] := 0
+/// ENDFOR
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction.
+///
+/// \param __A
+///A 128-bit vector of [4 x float].
+/// \param __B
+///A 128-bit vector of [4 x float].
+/// \returns
+///A 128-bit vector of [8 x fp16]. Lower elements correspond to the
+///(converted) elements from \a __B; higher order elements correspond to 
the
+///(converted) elements from \a __A.
 static __inline__ __m128h __DEFAULT_FN_ATTRS128 _mm_cvtx2ps_ph(__m128 __A,
__m128 __B) {
   return (__m128h)__builtin_ia32_vcvt2ps2phx128_mask(
   (__v4sf)__A, (__v4sf)__B, (__v8hf)_mm_setzero_ph(), (__mmask8)(-1));
 }
 
+/// Convert two 128-bit vectors, \a __A and \a __B, containing packed
+///single-precision (32-bit) floating-point elements to a 128-bit vector
+///containing FP16 elements. Merging mask \a __U is used to determine if 
given
+///element should be taken from \a __W instead.
+///
+/// \code{.operation}
+/// FOR i := 0 to 7
+///IF __U[i]
+///IF i < 4
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4])
+///FI
+///ELSE
+///dst.fp16[i] := __W.fp16[i]
+///FI
+///
+/// dst[MAX:127] := 0
+/// ENDFOR
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction.
+///
+/// \param __W
+///A 128-bit vector of [8 x fp16].
+/// \param __U
+///A 8-bit merging mask.
+/// \param __A
+///A 128-bit vector of [4 x float].
+/// \param __B
+///A 128-bit vector of [4 x float].
+/// \returns
+///A 128-bit vector of [8 x fp16]. Lower elements correspond to the
+///(converted) elements from \a __B; higher order elements correspond to 
the
+///(converted) elements from \a __A. If corresponding mask bit is not set, 
then
+///element from \a __W is taken instead.
 static __inline__ __m128h __DEFAULT_FN_ATTRS128
 _mm_mask_cvtx2ps_ph(__m128h __W, __mmask8 __U, __m128 __A, __m128 __B) {
   return (__m128h)__builtin_ia32_vcvt2ps2phx128_mask(
   (__v4sf)__A, (__v4sf)__B, (__v8hf)__W, (__mmask8)__U);
 }
 
+/// Convert two 128-bit vectors, \a __A and \a __B, containing packed
+///single-precision (32-bit) floating-point elements to a 128-bit vector
+///containing FP16 elements. Zeroing mask \a __U is used to determine if 
given
+///element should be zeroed instead.
+///
+/// \code{.operation}
+/// FOR i := 0 to 7
+///IF __U[i]
+///IF i < 4
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4])
+///FI
+///ELSE
+///dst.fp16[i] := 0
+///FI
+/// ENDFOR
+///
+/// dst[MAX:127] := 0
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction.
+///
+/// \param __U
+///A 8-bit zeroing mask.
+/// \param __A
+///A 128-bit vector of [4 x float].
+/// \param __B
+///A 128-bit vector of [4 x float].
+/// \returns
+///A 128-bit vector of [8 x fp16]. Lower elements correspond to the
+///(converted) elements from \a __B; higher order elements correspond to 
the
+///(converted) elements from \a __A. If corresponding mask bit is not set,
+///then zero is taken instead.
 static __inline__ __m128h __DEFAULT_FN_ATTRS128
 _mm_maskz_cvtx2ps_ph(__mmask8 __U, __m128 __A, __m128 __B) {
   return (__m128h)__builtin_ia32_vcvt2ps2phx128_mask(
   (__v4sf)__A, (__v4sf)__B, (__v8hf)_mm_setzero_ph(), (__mmask8)__U);
 }
 
+/// Convert two 256-bit vectors, \a __A and \a __B, containing packed
+///single-precision (32-bit) floating-point elements to a 256-bit vector
+///containing FP16 elements.
+///
+/// \code{.operation}
+/// FOR i := 0 to 15 
+///IF i < 8
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 8])
+///FI
+/// ENDFOR
+///
+/// dst[MAX:256] := 0
+/// \endcode
+///
+/// \he

[clang] [X86][AVX10.2] Add comments for the avx10_2convertintrin.h file (PR #120766)

2024-12-21 Thread Phoebe Wang via cfe-commits
=?utf-8?q?Mikołaj_Piróg?= ,
=?utf-8?q?Mikołaj_Piróg?= ,
=?utf-8?q?Mikołaj_Piróg?= ,
=?utf-8?q?Mikołaj_Piróg?= 
Message-ID:
In-Reply-To: 



@@ -24,573 +24,3369 @@
   __attribute__((__always_inline__, __nodebug__, __target__("avx10.2-256"),
\
  __min_vector_width__(256)))
 
+//clang-format off
+
+/// Convert two 128-bit vectors, \a __A and \a __B, containing packed
+///single-precision (32-bit) floating-point elements to a 128-bit vector
+///containing FP16 elements.
+///
+/// \code{.operation}
+/// FOR i := 0 to 7
+///IF i < 4
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4])
+///FI
+///
+/// dst[MAX:127] := 0
+/// ENDFOR
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction.
+///
+/// \param __A
+///A 128-bit vector of [4 x float].
+/// \param __B
+///A 128-bit vector of [4 x float].
+/// \returns
+///A 128-bit vector of [8 x fp16]. Lower elements correspond to the
+///(converted) elements from \a __B; higher order elements correspond to 
the
+///(converted) elements from \a __A.
 static __inline__ __m128h __DEFAULT_FN_ATTRS128 _mm_cvtx2ps_ph(__m128 __A,
__m128 __B) {
   return (__m128h)__builtin_ia32_vcvt2ps2phx128_mask(
   (__v4sf)__A, (__v4sf)__B, (__v8hf)_mm_setzero_ph(), (__mmask8)(-1));
 }
 
+/// Convert two 128-bit vectors, \a __A and \a __B, containing packed
+///single-precision (32-bit) floating-point elements to a 128-bit vector
+///containing FP16 elements. Merging mask \a __U is used to determine if 
given
+///element should be taken from \a __W instead.
+///
+/// \code{.operation}
+/// FOR i := 0 to 7
+///IF __U[i]
+///IF i < 4
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4])
+///FI
+///ELSE
+///dst.fp16[i] := __W.fp16[i]
+///FI
+///
+/// dst[MAX:127] := 0
+/// ENDFOR
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction.
+///
+/// \param __W
+///A 128-bit vector of [8 x fp16].
+/// \param __U
+///A 8-bit merging mask.
+/// \param __A
+///A 128-bit vector of [4 x float].
+/// \param __B
+///A 128-bit vector of [4 x float].
+/// \returns
+///A 128-bit vector of [8 x fp16]. Lower elements correspond to the
+///(converted) elements from \a __B; higher order elements correspond to 
the
+///(converted) elements from \a __A. If corresponding mask bit is not set, 
then
+///element from \a __W is taken instead.
 static __inline__ __m128h __DEFAULT_FN_ATTRS128
 _mm_mask_cvtx2ps_ph(__m128h __W, __mmask8 __U, __m128 __A, __m128 __B) {
   return (__m128h)__builtin_ia32_vcvt2ps2phx128_mask(
   (__v4sf)__A, (__v4sf)__B, (__v8hf)__W, (__mmask8)__U);
 }
 
+/// Convert two 128-bit vectors, \a __A and \a __B, containing packed
+///single-precision (32-bit) floating-point elements to a 128-bit vector
+///containing FP16 elements. Zeroing mask \a __U is used to determine if 
given
+///element should be zeroed instead.
+///
+/// \code{.operation}
+/// FOR i := 0 to 7
+///IF __U[i]
+///IF i < 4
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4])
+///FI
+///ELSE
+///dst.fp16[i] := 0
+///FI
+/// ENDFOR
+///
+/// dst[MAX:127] := 0
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction.
+///
+/// \param __U
+///A 8-bit zeroing mask.
+/// \param __A
+///A 128-bit vector of [4 x float].
+/// \param __B
+///A 128-bit vector of [4 x float].
+/// \returns
+///A 128-bit vector of [8 x fp16]. Lower elements correspond to the
+///(converted) elements from \a __B; higher order elements correspond to 
the
+///(converted) elements from \a __A. If corresponding mask bit is not set,
+///then zero is taken instead.
 static __inline__ __m128h __DEFAULT_FN_ATTRS128
 _mm_maskz_cvtx2ps_ph(__mmask8 __U, __m128 __A, __m128 __B) {
   return (__m128h)__builtin_ia32_vcvt2ps2phx128_mask(
   (__v4sf)__A, (__v4sf)__B, (__v8hf)_mm_setzero_ph(), (__mmask8)__U);
 }
 
+/// Convert two 256-bit vectors, \a __A and \a __B, containing packed
+///single-precision (32-bit) floating-point elements to a 256-bit vector
+///containing FP16 elements.
+///
+/// \code{.operation}
+/// FOR i := 0 to 15 
+///IF i < 8
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 8])
+///FI
+/// ENDFOR
+///
+/// dst[MAX:256] := 0
+/// \endcode
+///
+/// \he

[clang] [X86][AVX10.2] Add comments for the avx10_2convertintrin.h file (PR #120766)

2024-12-21 Thread Phoebe Wang via cfe-commits
=?utf-8?q?Mikołaj_Piróg?= ,
=?utf-8?q?Mikołaj_Piróg?= ,
=?utf-8?q?Mikołaj_Piróg?= ,
=?utf-8?q?Mikołaj_Piróg?= 
Message-ID:
In-Reply-To: 



@@ -24,573 +24,3369 @@
   __attribute__((__always_inline__, __nodebug__, __target__("avx10.2-256"),
\
  __min_vector_width__(256)))
 
+//clang-format off
+
+/// Convert two 128-bit vectors, \a __A and \a __B, containing packed
+///single-precision (32-bit) floating-point elements to a 128-bit vector
+///containing FP16 elements.
+///
+/// \code{.operation}
+/// FOR i := 0 to 7
+///IF i < 4
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4])
+///FI
+///
+/// dst[MAX:127] := 0
+/// ENDFOR
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction.
+///
+/// \param __A
+///A 128-bit vector of [4 x float].
+/// \param __B
+///A 128-bit vector of [4 x float].
+/// \returns
+///A 128-bit vector of [8 x fp16]. Lower elements correspond to the
+///(converted) elements from \a __B; higher order elements correspond to 
the
+///(converted) elements from \a __A.
 static __inline__ __m128h __DEFAULT_FN_ATTRS128 _mm_cvtx2ps_ph(__m128 __A,
__m128 __B) {
   return (__m128h)__builtin_ia32_vcvt2ps2phx128_mask(
   (__v4sf)__A, (__v4sf)__B, (__v8hf)_mm_setzero_ph(), (__mmask8)(-1));
 }
 
+/// Convert two 128-bit vectors, \a __A and \a __B, containing packed
+///single-precision (32-bit) floating-point elements to a 128-bit vector
+///containing FP16 elements. Merging mask \a __U is used to determine if 
given
+///element should be taken from \a __W instead.
+///
+/// \code{.operation}
+/// FOR i := 0 to 7
+///IF __U[i]
+///IF i < 4
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4])
+///FI
+///ELSE
+///dst.fp16[i] := __W.fp16[i]
+///FI
+///
+/// dst[MAX:127] := 0
+/// ENDFOR
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction.
+///
+/// \param __W
+///A 128-bit vector of [8 x fp16].
+/// \param __U
+///A 8-bit merging mask.
+/// \param __A
+///A 128-bit vector of [4 x float].
+/// \param __B
+///A 128-bit vector of [4 x float].
+/// \returns
+///A 128-bit vector of [8 x fp16]. Lower elements correspond to the
+///(converted) elements from \a __B; higher order elements correspond to 
the
+///(converted) elements from \a __A. If corresponding mask bit is not set, 
then
+///element from \a __W is taken instead.
 static __inline__ __m128h __DEFAULT_FN_ATTRS128
 _mm_mask_cvtx2ps_ph(__m128h __W, __mmask8 __U, __m128 __A, __m128 __B) {
   return (__m128h)__builtin_ia32_vcvt2ps2phx128_mask(
   (__v4sf)__A, (__v4sf)__B, (__v8hf)__W, (__mmask8)__U);
 }
 
+/// Convert two 128-bit vectors, \a __A and \a __B, containing packed
+///single-precision (32-bit) floating-point elements to a 128-bit vector
+///containing FP16 elements. Zeroing mask \a __U is used to determine if 
given
+///element should be zeroed instead.
+///
+/// \code{.operation}
+/// FOR i := 0 to 7
+///IF __U[i]
+///IF i < 4
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4])
+///FI
+///ELSE
+///dst.fp16[i] := 0
+///FI
+/// ENDFOR
+///
+/// dst[MAX:127] := 0
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction.
+///
+/// \param __U
+///A 8-bit zeroing mask.
+/// \param __A
+///A 128-bit vector of [4 x float].
+/// \param __B
+///A 128-bit vector of [4 x float].
+/// \returns
+///A 128-bit vector of [8 x fp16]. Lower elements correspond to the
+///(converted) elements from \a __B; higher order elements correspond to 
the
+///(converted) elements from \a __A. If corresponding mask bit is not set,
+///then zero is taken instead.
 static __inline__ __m128h __DEFAULT_FN_ATTRS128
 _mm_maskz_cvtx2ps_ph(__mmask8 __U, __m128 __A, __m128 __B) {
   return (__m128h)__builtin_ia32_vcvt2ps2phx128_mask(
   (__v4sf)__A, (__v4sf)__B, (__v8hf)_mm_setzero_ph(), (__mmask8)__U);
 }
 
+/// Convert two 256-bit vectors, \a __A and \a __B, containing packed
+///single-precision (32-bit) floating-point elements to a 256-bit vector
+///containing FP16 elements.
+///
+/// \code{.operation}
+/// FOR i := 0 to 15 
+///IF i < 8
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 8])
+///FI
+/// ENDFOR
+///
+/// dst[MAX:256] := 0
+/// \endcode
+///
+/// \he

[clang] [X86][AVX10.2] Add comments for the avx10_2convertintrin.h file (PR #120766)

2024-12-21 Thread Phoebe Wang via cfe-commits
=?utf-8?q?Mikołaj_Piróg?= ,
=?utf-8?q?Mikołaj_Piróg?= ,
=?utf-8?q?Mikołaj_Piróg?= ,
=?utf-8?q?Mikołaj_Piróg?= 
Message-ID:
In-Reply-To: 



@@ -24,573 +24,3369 @@
   __attribute__((__always_inline__, __nodebug__, __target__("avx10.2-256"),
\
  __min_vector_width__(256)))
 
+//clang-format off
+
+/// Convert two 128-bit vectors, \a __A and \a __B, containing packed
+///single-precision (32-bit) floating-point elements to a 128-bit vector
+///containing FP16 elements.
+///
+/// \code{.operation}
+/// FOR i := 0 to 7
+///IF i < 4
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4])
+///FI
+///
+/// dst[MAX:127] := 0
+/// ENDFOR
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction.
+///
+/// \param __A
+///A 128-bit vector of [4 x float].
+/// \param __B
+///A 128-bit vector of [4 x float].
+/// \returns
+///A 128-bit vector of [8 x fp16]. Lower elements correspond to the

phoebewang wrote:

We use `half` instread of `fp16`.

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


[clang] [X86][AVX10.2] Add comments for the avx10_2convertintrin.h file (PR #120766)

2024-12-21 Thread Phoebe Wang via cfe-commits
=?utf-8?q?Mikołaj_Piróg?= ,
=?utf-8?q?Mikołaj_Piróg?= ,
=?utf-8?q?Mikołaj_Piróg?= ,
=?utf-8?q?Mikołaj_Piróg?= 
Message-ID:
In-Reply-To: 



@@ -24,573 +24,3369 @@
   __attribute__((__always_inline__, __nodebug__, __target__("avx10.2-256"),
\
  __min_vector_width__(256)))
 
+//clang-format off

phoebewang wrote:

`// clang-format off`

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


[clang] [X86][AVX10.2] Add comments for the avx10_2convertintrin.h file (PR #120766)

2024-12-21 Thread Phoebe Wang via cfe-commits
=?utf-8?q?Mikołaj_Piróg?= ,
=?utf-8?q?Mikołaj_Piróg?= ,
=?utf-8?q?Mikołaj_Piróg?= ,
=?utf-8?q?Mikołaj_Piróg?= 
Message-ID:
In-Reply-To: 



@@ -24,573 +24,3369 @@
   __attribute__((__always_inline__, __nodebug__, __target__("avx10.2-256"),
\
  __min_vector_width__(256)))
 
+//clang-format off
+
+/// Convert two 128-bit vectors, \a __A and \a __B, containing packed
+///single-precision (32-bit) floating-point elements to a 128-bit vector
+///containing FP16 elements.
+///
+/// \code{.operation}
+/// FOR i := 0 to 7
+///IF i < 4
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4])
+///FI
+///
+/// dst[MAX:127] := 0
+/// ENDFOR
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction.
+///
+/// \param __A
+///A 128-bit vector of [4 x float].
+/// \param __B
+///A 128-bit vector of [4 x float].
+/// \returns
+///A 128-bit vector of [8 x fp16]. Lower elements correspond to the
+///(converted) elements from \a __B; higher order elements correspond to 
the
+///(converted) elements from \a __A.
 static __inline__ __m128h __DEFAULT_FN_ATTRS128 _mm_cvtx2ps_ph(__m128 __A,
__m128 __B) {
   return (__m128h)__builtin_ia32_vcvt2ps2phx128_mask(
   (__v4sf)__A, (__v4sf)__B, (__v8hf)_mm_setzero_ph(), (__mmask8)(-1));
 }
 
+/// Convert two 128-bit vectors, \a __A and \a __B, containing packed
+///single-precision (32-bit) floating-point elements to a 128-bit vector
+///containing FP16 elements. Merging mask \a __U is used to determine if 
given
+///element should be taken from \a __W instead.
+///
+/// \code{.operation}
+/// FOR i := 0 to 7
+///IF __U[i]
+///IF i < 4
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4])
+///FI
+///ELSE
+///dst.fp16[i] := __W.fp16[i]
+///FI
+///
+/// dst[MAX:127] := 0
+/// ENDFOR
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction.
+///
+/// \param __W
+///A 128-bit vector of [8 x fp16].
+/// \param __U
+///A 8-bit merging mask.
+/// \param __A
+///A 128-bit vector of [4 x float].
+/// \param __B
+///A 128-bit vector of [4 x float].
+/// \returns
+///A 128-bit vector of [8 x fp16]. Lower elements correspond to the
+///(converted) elements from \a __B; higher order elements correspond to 
the
+///(converted) elements from \a __A. If corresponding mask bit is not set, 
then
+///element from \a __W is taken instead.
 static __inline__ __m128h __DEFAULT_FN_ATTRS128
 _mm_mask_cvtx2ps_ph(__m128h __W, __mmask8 __U, __m128 __A, __m128 __B) {
   return (__m128h)__builtin_ia32_vcvt2ps2phx128_mask(
   (__v4sf)__A, (__v4sf)__B, (__v8hf)__W, (__mmask8)__U);
 }
 
+/// Convert two 128-bit vectors, \a __A and \a __B, containing packed
+///single-precision (32-bit) floating-point elements to a 128-bit vector
+///containing FP16 elements. Zeroing mask \a __U is used to determine if 
given
+///element should be zeroed instead.
+///
+/// \code{.operation}
+/// FOR i := 0 to 7
+///IF __U[i]
+///IF i < 4
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4])
+///FI
+///ELSE
+///dst.fp16[i] := 0
+///FI
+/// ENDFOR
+///
+/// dst[MAX:127] := 0
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction.
+///
+/// \param __U
+///A 8-bit zeroing mask.
+/// \param __A
+///A 128-bit vector of [4 x float].
+/// \param __B
+///A 128-bit vector of [4 x float].
+/// \returns
+///A 128-bit vector of [8 x fp16]. Lower elements correspond to the
+///(converted) elements from \a __B; higher order elements correspond to 
the
+///(converted) elements from \a __A. If corresponding mask bit is not set,
+///then zero is taken instead.
 static __inline__ __m128h __DEFAULT_FN_ATTRS128
 _mm_maskz_cvtx2ps_ph(__mmask8 __U, __m128 __A, __m128 __B) {
   return (__m128h)__builtin_ia32_vcvt2ps2phx128_mask(
   (__v4sf)__A, (__v4sf)__B, (__v8hf)_mm_setzero_ph(), (__mmask8)__U);
 }
 
+/// Convert two 256-bit vectors, \a __A and \a __B, containing packed
+///single-precision (32-bit) floating-point elements to a 256-bit vector
+///containing FP16 elements.
+///
+/// \code{.operation}
+/// FOR i := 0 to 15 
+///IF i < 8
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 8])
+///FI
+/// ENDFOR
+///
+/// dst[MAX:256] := 0
+/// \endcode
+///
+/// \he

[clang] [X86][AVX10.2] Add comments for the avx10_2convertintrin.h file (PR #120766)

2024-12-21 Thread Phoebe Wang via cfe-commits
=?utf-8?q?Mikołaj_Piróg?= ,
=?utf-8?q?Mikołaj_Piróg?= ,
=?utf-8?q?Mikołaj_Piróg?= ,
=?utf-8?q?Mikołaj_Piróg?= 
Message-ID:
In-Reply-To: 



@@ -24,573 +24,3369 @@
   __attribute__((__always_inline__, __nodebug__, __target__("avx10.2-256"),
\
  __min_vector_width__(256)))
 
+//clang-format off
+
+/// Convert two 128-bit vectors, \a __A and \a __B, containing packed
+///single-precision (32-bit) floating-point elements to a 128-bit vector
+///containing FP16 elements.
+///
+/// \code{.operation}
+/// FOR i := 0 to 7
+///IF i < 4
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4])
+///FI
+///
+/// dst[MAX:127] := 0
+/// ENDFOR
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction.
+///
+/// \param __A
+///A 128-bit vector of [4 x float].
+/// \param __B
+///A 128-bit vector of [4 x float].
+/// \returns
+///A 128-bit vector of [8 x fp16]. Lower elements correspond to the
+///(converted) elements from \a __B; higher order elements correspond to 
the
+///(converted) elements from \a __A.
 static __inline__ __m128h __DEFAULT_FN_ATTRS128 _mm_cvtx2ps_ph(__m128 __A,
__m128 __B) {
   return (__m128h)__builtin_ia32_vcvt2ps2phx128_mask(
   (__v4sf)__A, (__v4sf)__B, (__v8hf)_mm_setzero_ph(), (__mmask8)(-1));
 }
 
+/// Convert two 128-bit vectors, \a __A and \a __B, containing packed
+///single-precision (32-bit) floating-point elements to a 128-bit vector
+///containing FP16 elements. Merging mask \a __U is used to determine if 
given
+///element should be taken from \a __W instead.
+///
+/// \code{.operation}
+/// FOR i := 0 to 7
+///IF __U[i]
+///IF i < 4
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4])
+///FI
+///ELSE
+///dst.fp16[i] := __W.fp16[i]
+///FI
+///
+/// dst[MAX:127] := 0
+/// ENDFOR
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction.
+///
+/// \param __W
+///A 128-bit vector of [8 x fp16].
+/// \param __U
+///A 8-bit merging mask.
+/// \param __A
+///A 128-bit vector of [4 x float].
+/// \param __B
+///A 128-bit vector of [4 x float].
+/// \returns
+///A 128-bit vector of [8 x fp16]. Lower elements correspond to the
+///(converted) elements from \a __B; higher order elements correspond to 
the
+///(converted) elements from \a __A. If corresponding mask bit is not set, 
then
+///element from \a __W is taken instead.
 static __inline__ __m128h __DEFAULT_FN_ATTRS128
 _mm_mask_cvtx2ps_ph(__m128h __W, __mmask8 __U, __m128 __A, __m128 __B) {
   return (__m128h)__builtin_ia32_vcvt2ps2phx128_mask(
   (__v4sf)__A, (__v4sf)__B, (__v8hf)__W, (__mmask8)__U);
 }
 
+/// Convert two 128-bit vectors, \a __A and \a __B, containing packed
+///single-precision (32-bit) floating-point elements to a 128-bit vector
+///containing FP16 elements. Zeroing mask \a __U is used to determine if 
given
+///element should be zeroed instead.
+///
+/// \code{.operation}
+/// FOR i := 0 to 7
+///IF __U[i]
+///IF i < 4
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 4])
+///FI
+///ELSE
+///dst.fp16[i] := 0
+///FI
+/// ENDFOR
+///
+/// dst[MAX:127] := 0
+/// \endcode
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VCVT2PS2PHX instruction.
+///
+/// \param __U
+///A 8-bit zeroing mask.
+/// \param __A
+///A 128-bit vector of [4 x float].
+/// \param __B
+///A 128-bit vector of [4 x float].
+/// \returns
+///A 128-bit vector of [8 x fp16]. Lower elements correspond to the
+///(converted) elements from \a __B; higher order elements correspond to 
the
+///(converted) elements from \a __A. If corresponding mask bit is not set,
+///then zero is taken instead.
 static __inline__ __m128h __DEFAULT_FN_ATTRS128
 _mm_maskz_cvtx2ps_ph(__mmask8 __U, __m128 __A, __m128 __B) {
   return (__m128h)__builtin_ia32_vcvt2ps2phx128_mask(
   (__v4sf)__A, (__v4sf)__B, (__v8hf)_mm_setzero_ph(), (__mmask8)__U);
 }
 
+/// Convert two 256-bit vectors, \a __A and \a __B, containing packed
+///single-precision (32-bit) floating-point elements to a 256-bit vector
+///containing FP16 elements.
+///
+/// \code{.operation}
+/// FOR i := 0 to 15 
+///IF i < 8
+///dst.fp16[i] := convert_fp32_to_fp16(__B.fp32[i])
+///ELSE
+///dst.fp16[i] := convert_fp32_to_fp16(__A.fp32[i - 8])
+///FI
+/// ENDFOR
+///
+/// dst[MAX:256] := 0
+/// \endcode
+///
+/// \he

[clang] [clang][bytecode] Create local scopes for if then/else statements (PR #120852)

2024-12-21 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

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

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


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

```
Step 6 (test) failure: build (failure)
...
PASS: lldb-unit :: ValueObject/./LLDBValueObjectTests/0/3 (2060 of 2069)
PASS: lldb-unit :: ValueObject/./LLDBValueObjectTests/1/3 (2061 of 2069)
PASS: lldb-unit :: Utility/./UtilityTests/4/8 (2062 of 2069)
PASS: lldb-unit :: ValueObject/./LLDBValueObjectTests/2/3 (2063 of 2069)
PASS: lldb-unit :: tools/lldb-server/tests/./LLDBServerTests/0/2 (2064 of 2069)
PASS: lldb-unit :: tools/lldb-server/tests/./LLDBServerTests/1/2 (2065 of 2069)
PASS: lldb-unit :: Target/./TargetTests/11/14 (2066 of 2069)
PASS: lldb-unit :: Host/./HostTests/2/13 (2067 of 2069)
PASS: lldb-unit :: Process/gdb-remote/./ProcessGdbRemoteTests/8/9 (2068 of 2069)
UNRESOLVED: lldb-api :: tools/lldb-server/TestLldbGdbServer.py (2069 of 2069)
 TEST 'lldb-api :: tools/lldb-server/TestLldbGdbServer.py' 
FAILED 
Script:
--
/usr/bin/python3.10 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/API/dotest.py
 -u CXXFLAGS -u CFLAGS --env 
LLVM_LIBS_DIR=/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./lib --env 
LLVM_INCLUDE_DIR=/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/include 
--env LLVM_TOOLS_DIR=/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin 
--arch aarch64 --build-dir 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex 
--lldb-module-cache-dir 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api
 --clang-module-cache-dir 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex/module-cache-clang/lldb-api
 --executable /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin/lldb 
--compiler /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin/clang 
--dsymutil /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin/dsymutil 
--make /usr/bin/gmake --llvm-tools-dir 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin --lldb-obj-root 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb --lldb-libs-dir 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./lib 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/API/tools/lldb-server
 -p TestLldbGdbServer.py
--
Exit Code: 1

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

--
Command Output (stderr):
--
UNSUPPORTED: LLDB 
(/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: 
test_Hc_then_Csignal_signals_correct_thread_launch_debugserver 
(TestLldbGdbServer.LldbGdbServerTestCase) (test case does not fall in any 
category of interest for this run) 
PASS: LLDB 
(/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: 
test_Hc_then_Csignal_signals_correct_thread_launch_llgs 
(TestLldbGdbServer.LldbGdbServerTestCase)
PASS: LLDB 
(/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: 
test_Hg_fails_on_another_pid_llgs (TestLldbGdbServer.LldbGdbServerTestCase)
PASS: LLDB 
(/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: 
test_Hg_fails_on_minus_one_pid_llgs (TestLldbGdbServer.LldbGdbServerTestCase)
PASS: LLDB 
(/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: 
test_Hg_fails_on_zero_pid_llgs (TestLldbGdbServer.LldbGdbServerTestCase)
UNSUPPORTED: LLDB 
(/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: 
test_Hg_switches_to_3_threads_launch_debugserver 
(TestLldbGdbServer.LldbGdbServerTestCase) (test case does not fall in any 
category of interest for this run) 
PASS: LLDB 
(/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: 
test_Hg_switches_to_3_threads_launch_llgs 
(TestLldbGdbServer.LldbGdbServerTestCase)
UNSUPPORTED: LLDB 
(/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: 
test_P_and_p_thread_suffix_work_debugserver 
(TestLldbGdbServer.LldbGdbServerTestCase) (test case does not fall in any 
category of interest for this run) 
PASS: LLDB 
(/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: 
test_P_and_p_thread_suffix_work_llgs (TestLldbGdbServer.LldbGdbServerTestCase)
UNSUPPORTED: LLDB 
(/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: 
test_P_writes_all_gpr_registers_debugserver 
(TestLldbGdbServer.LldbGdbServerTestCase) (test case does not fall in any 
category of i

[clang-tools-extra] [clang-doc] Migrate away from PointerUnion::{is,get} (NFC) (PR #120872)

2024-12-21 Thread Kazu Hirata via cfe-commits

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

Note that PointerUnion::{is,get} have been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //isa, cast and the llvm::dyn_cast


>From 74f40fd73d831e46c782525e25fa4a8881a081dc Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Sat, 21 Dec 2024 21:42:41 -0800
Subject: [PATCH] [clang-doc] Migrate away from PointerUnion::{is,get} (NFC)

Note that PointerUnion::{is,get} have been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //isa, cast and the llvm::dyn_cast
---
 clang-tools-extra/clang-doc/Serialize.cpp | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/clang-tools-extra/clang-doc/Serialize.cpp 
b/clang-tools-extra/clang-doc/Serialize.cpp
index 93efdd44f45898..f737fc75135a19 100644
--- a/clang-tools-extra/clang-doc/Serialize.cpp
+++ b/clang-tools-extra/clang-doc/Serialize.cpp
@@ -696,13 +696,11 @@ emitInfo(const RecordDecl *D, const FullComment *FC, int 
LineNumber,
 
 // What this is a specialization of.
 auto SpecOf = CTSD->getSpecializedTemplateOrPartial();
-if (SpecOf.is()) {
-  Specialization.SpecializationOf =
-  getUSRForDecl(SpecOf.get());
-} else if (SpecOf.is()) {
-  Specialization.SpecializationOf =
-  getUSRForDecl(SpecOf.get());
-}
+if (auto *CTD = dyn_cast(SpecOf))
+  Specialization.SpecializationOf = getUSRForDecl(CTD);
+else if (auto *CTPSD =
+ dyn_cast(SpecOf))
+  Specialization.SpecializationOf = getUSRForDecl(CTPSD);
 
 // Parameters to the specilization. For partial specializations, get the
 // parameters "as written" from the ClassTemplatePartialSpecializationDecl

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


[clang-tools-extra] [clang-doc] Migrate away from PointerUnion::{is,get} (NFC) (PR #120872)

2024-12-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tools-extra

Author: Kazu Hirata (kazutakahirata)


Changes

Note that PointerUnion::{is,get} have been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //isa, cast and the llvm::dyn_cast


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


1 Files Affected:

- (modified) clang-tools-extra/clang-doc/Serialize.cpp (+5-7) 


``diff
diff --git a/clang-tools-extra/clang-doc/Serialize.cpp 
b/clang-tools-extra/clang-doc/Serialize.cpp
index 93efdd44f45898..f737fc75135a19 100644
--- a/clang-tools-extra/clang-doc/Serialize.cpp
+++ b/clang-tools-extra/clang-doc/Serialize.cpp
@@ -696,13 +696,11 @@ emitInfo(const RecordDecl *D, const FullComment *FC, int 
LineNumber,
 
 // What this is a specialization of.
 auto SpecOf = CTSD->getSpecializedTemplateOrPartial();
-if (SpecOf.is()) {
-  Specialization.SpecializationOf =
-  getUSRForDecl(SpecOf.get());
-} else if (SpecOf.is()) {
-  Specialization.SpecializationOf =
-  getUSRForDecl(SpecOf.get());
-}
+if (auto *CTD = dyn_cast(SpecOf))
+  Specialization.SpecializationOf = getUSRForDecl(CTD);
+else if (auto *CTPSD =
+ dyn_cast(SpecOf))
+  Specialization.SpecializationOf = getUSRForDecl(CTPSD);
 
 // Parameters to the specilization. For partial specializations, get the
 // parameters "as written" from the ClassTemplatePartialSpecializationDecl

``




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


[clang] cac6777 - [clang-format] Fix crashes when the macro expansion is empty (#119428)

2024-12-21 Thread via cfe-commits

Author: 天音あめ
Date: 2024-12-21T22:21:27-08:00
New Revision: cac6777ca14e162eb6e97e20da266802846ab953

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

LOG: [clang-format] Fix crashes when the macro expansion is empty (#119428)

An empty expansion should be valid, like `echo 'A()' | clang-format
--style='{Macros: [A(x)=x]}'`.

Fixes #119258.

Added: 


Modified: 
clang/lib/Format/MacroExpander.cpp
clang/unittests/Format/MacroCallReconstructorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/MacroExpander.cpp 
b/clang/lib/Format/MacroExpander.cpp
index fd2a16894d643d..ba2992889e6743 100644
--- a/clang/lib/Format/MacroExpander.cpp
+++ b/clang/lib/Format/MacroExpander.cpp
@@ -233,6 +233,10 @@ MacroExpander::expand(FormatToken *ID,
   if (Result.size() > 1) {
 ++Result[0]->MacroCtx->StartOfExpansion;
 ++Result[Result.size() - 2]->MacroCtx->EndOfExpansion;
+  } else {
+// If the macro expansion is empty, mark the start and end.
+Result[0]->MacroCtx->StartOfExpansion = 1;
+Result[0]->MacroCtx->EndOfExpansion = 1;
   }
   return Result;
 }

diff  --git a/clang/unittests/Format/MacroCallReconstructorTest.cpp 
b/clang/unittests/Format/MacroCallReconstructorTest.cpp
index b4ee8d0e37efa8..b58241fd8c4e80 100644
--- a/clang/unittests/Format/MacroCallReconstructorTest.cpp
+++ b/clang/unittests/Format/MacroCallReconstructorTest.cpp
@@ -65,7 +65,9 @@ class Expansion {
 }
 Unexpanded[ID] = std::move(UnexpandedLine);
 
-auto Expanded = uneof(Macros.expand(ID, Args));
+auto Expanded = Macros.expand(ID, Args);
+if (Expanded.size() > 1)
+  Expanded = uneof(Expanded);
 Tokens.append(Expanded.begin(), Expanded.end());
 
 TokenList UnexpandedTokens;
@@ -217,6 +219,31 @@ TEST_F(MacroCallReconstructorTest, Identifier) {
   EXPECT_THAT(std::move(Unexp).takeResult(), 
matchesLine(line(U.consume("X";
 }
 
+TEST_F(MacroCallReconstructorTest, EmptyDefinition) {
+  auto Macros = createExpander({"X"});
+  Expansion Exp(Lex, *Macros);
+  TokenList Call = Exp.expand("X");
+
+  MacroCallReconstructor Unexp(0, Exp.getUnexpanded());
+  Unexp.addLine(line(Exp.getTokens()));
+  EXPECT_TRUE(Unexp.finished());
+  Matcher U(Call, Lex);
+  EXPECT_THAT(std::move(Unexp).takeResult(), 
matchesLine(line(U.consume("X";
+}
+
+TEST_F(MacroCallReconstructorTest, EmptyExpansion) {
+  auto Macros = createExpander({"A(x)=x"});
+  Expansion Exp(Lex, *Macros);
+  TokenList Call = Exp.expand("A", {""});
+
+  MacroCallReconstructor Unexp(0, Exp.getUnexpanded());
+  Unexp.addLine(line(Exp.getTokens()));
+  EXPECT_TRUE(Unexp.finished());
+  Matcher U(Call, Lex);
+  EXPECT_THAT(std::move(Unexp).takeResult(),
+  matchesLine(line(U.consume("A()";
+}
+
 TEST_F(MacroCallReconstructorTest, NestedLineWithinCall) {
   auto Macros = createExpander({"C(a)=class X { a; };"});
   Expansion Exp(Lex, *Macros);



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


[clang] [clang-format] Fix crashes when the macro expansion is empty (PR #119428)

2024-12-21 Thread Owen Pan via cfe-commits

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


[clang] [clang-format] Fix crashes when the macro expansion is empty (PR #119428)

2024-12-21 Thread via cfe-commits

github-actions[bot] wrote:



@amane-ame Congratulations on having your first Pull Request (PR) merged into 
the LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested by our [build bots](https://lab.llvm.org/buildbot/). If there is a 
problem with a build, you may receive a report in an email or a comment on this 
PR.

Please check whether problems have been caused by your change specifically, as 
the builds can include changes from many authors. It is not uncommon for your 
change to be included in a build that fails due to someone else's changes, or 
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself. This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


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


  1   2   >