[clang] [llvm] [HLSL] Adding Flatten and Branch if attributes (PR #116331)

2024-11-18 Thread Chris B via cfe-commits

https://github.com/llvm-beanz commented:

I think we need to think a bit about the IR metadata in the middle of the 
compiler and how it will be used in various scenarios.

DXIL and SPIR-V both have branch hints that indicate to the GPU backends if a 
branch should be profitable to flatten or preserve.

1) We shouldn't use a DirectX-named metadata field to drive behaviors in the 
SPIR-V backend.
2) In the case where we load SPIR-V or DXIL into LLVM and then lower to a GPU 
ISA (like AMDGPU), we'll want to translate SPIR-V and DXIL's annotations into a 
generic LLVM annotation that backends can broadly accept. This same case comes 
into play if we ever support direct from HLSL -> ISA compiling where we'll want 
the backends to respect the metadata.
 

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


[clang] [llvm] AMDGPU: Handle gfx950 96/128-bit buffer_load_lds (PR #116681)

2024-11-18 Thread Matt Arsenault via cfe-commits

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


[clang] [lld] [llvm] [X86][MC,LLD][NFC] Rename R_X86_64_REX2_GOTPCRELX (PR #116737)

2024-11-18 Thread Feng Zou via cfe-commits

https://github.com/fzou1 updated 
https://github.com/llvm/llvm-project/pull/116737

>From c1716f030d8503b5a4742447ef8883d900521c34 Mon Sep 17 00:00:00 2001
From: Feng Zou 
Date: Tue, 19 Nov 2024 11:19:17 +0800
Subject: [PATCH 1/2] [X86][MC,LLD][NFC] Rename R_X86_64_REX2_GOTPCRELX to
 R_X86_64_CODE_4_GOTPCRELX

This is to align with GCC/binutils and ABI.
GCC/binutils: 
https://github.com/bminor/binutils-gdb/commit/3d5a60de52556f6a53d71d7e607c6696450ae3e4
and 
https://github.com/bminor/binutils-gdb/commit/4a54cb06585f568031dfd291d0fe45979ad75e98

ABI: 
https://gitlab.com/x86-psABIs/x86-64-ABI/-/commit/357de358ba68eb779822dfcbb45f7ee2d9d09193
---
 lld/ELF/Arch/X86_64.cpp   | 13 ++--
 lld/test/ELF/x86-64-gotpc-no-relax-err.s  |  2 +-
 lld/test/ELF/x86-64-gotpc-relax-nopic.s   |  2 +-
 lld/test/ELF/x86-64-gotpc-relax.s |  2 +-
 .../llvm/BinaryFormat/ELFRelocs/x86_64.def|  2 +-
 llvm/lib/MC/MCTargetOptionsCommandFlags.cpp   |  2 +-
 .../X86/MCTargetDesc/X86ELFObjectWriter.cpp   |  4 ++--
 .../X86/MCTargetDesc/X86MCCodeEmitter.cpp |  2 +-
 llvm/test/MC/ELF/relocation-alias.s   |  2 +-
 llvm/test/MC/X86/gotpcrelx.s  | 20 +--
 llvm/test/MC/X86/reloc-directive-elf-64.s |  6 +++---
 11 files changed, 29 insertions(+), 28 deletions(-)

diff --git a/lld/ELF/Arch/X86_64.cpp b/lld/ELF/Arch/X86_64.cpp
index e9267bd4128d18..2dcce5c224d5d6 100644
--- a/lld/ELF/Arch/X86_64.cpp
+++ b/lld/ELF/Arch/X86_64.cpp
@@ -394,7 +394,7 @@ RelExpr X86_64::getRelExpr(RelType type, const Symbol &s,
   case R_X86_64_GOTPCREL:
   case R_X86_64_GOTPCRELX:
   case R_X86_64_REX_GOTPCRELX:
-  case R_X86_64_REX2_GOTPCRELX:
+  case R_X86_64_CODE_4_GOTPCRELX:
   case R_X86_64_GOTTPOFF:
 return R_GOT_PC;
   case R_X86_64_GOTOFF64:
@@ -738,7 +738,7 @@ int64_t X86_64::getImplicitAddend(const uint8_t *buf, 
RelType type) const {
   case R_X86_64_GOTPCREL:
   case R_X86_64_GOTPCRELX:
   case R_X86_64_REX_GOTPCRELX:
-  case R_X86_64_REX2_GOTPCRELX:
+  case R_X86_64_CODE_4_GOTPCRELX:
   case R_X86_64_PC32:
   case R_X86_64_GOTTPOFF:
   case R_X86_64_PLT32:
@@ -821,7 +821,7 @@ void X86_64::relocate(uint8_t *loc, const Relocation &rel, 
uint64_t val) const {
 break;
   case R_X86_64_GOTPCRELX:
   case R_X86_64_REX_GOTPCRELX:
-  case R_X86_64_REX2_GOTPCRELX:
+  case R_X86_64_CODE_4_GOTPCRELX:
 if (rel.expr != R_GOT_PC) {
   relaxGot(loc, rel, val);
 } else {
@@ -873,13 +873,13 @@ void X86_64::relocate(uint8_t *loc, const Relocation 
&rel, uint64_t val) const {
 
 RelExpr X86_64::adjustGotPcExpr(RelType type, int64_t addend,
 const uint8_t *loc) const {
-  // Only R_X86_64_[REX_]|[REX2_]GOTPCRELX can be relaxed. GNU as may emit
+  // Only R_X86_64_[REX_]|[CODE_4_]GOTPCRELX can be relaxed. GNU as may emit
   // GOTPCRELX with addend != -4. Such an instruction does not load the full 
GOT
   // entry, so we cannot relax the relocation. E.g. movl x@GOTPCREL+4(%rip),
   // %rax (addend=0) loads the high 32 bits of the GOT entry.
   if (!ctx.arg.relax || addend != -4 ||
   (type != R_X86_64_GOTPCRELX && type != R_X86_64_REX_GOTPCRELX &&
-   type != R_X86_64_REX2_GOTPCRELX))
+   type != R_X86_64_CODE_4_GOTPCRELX))
 return R_GOT_PC;
   const uint8_t op = loc[-2];
   const uint8_t modRm = loc[-1];
@@ -1002,7 +1002,8 @@ static void relaxGot(uint8_t *loc, const Relocation &rel, 
uint64_t val) {
 // We are relaxing a rip relative to an absolute, so compensate
 // for the old -4 addend.
 assert(!rel.sym->file || !rel.sym->file->ctx.arg.isPic);
-relaxGotNoPic(loc, val + 4, op, modRm, rel.type == 
R_X86_64_REX2_GOTPCRELX);
+relaxGotNoPic(loc, val + 4, op, modRm,
+  rel.type == R_X86_64_CODE_4_GOTPCRELX);
 return;
   }
 
diff --git a/lld/test/ELF/x86-64-gotpc-no-relax-err.s 
b/lld/test/ELF/x86-64-gotpc-no-relax-err.s
index 4280c8fd1dc97e..8452090e2c35a0 100644
--- a/lld/test/ELF/x86-64-gotpc-no-relax-err.s
+++ b/lld/test/ELF/x86-64-gotpc-no-relax-err.s
@@ -13,7 +13,7 @@
 # CHECK-NEXT: error: {{.*}}:(.text+0x9): relocation R_X86_64_REX_GOTPCRELX out 
of range: 2147483659 is not in [-2147483648, 2147483647]; references 
'__stop_data'
 # CHECK-NEXT: >>> defined in 
 # CHECK-EMPTY:
-# CHECK-NEXT: error: {{.*}}:(.text+0x11): relocation R_X86_64_REX2_GOTPCRELX 
out of range: 2147483651 is not in [-2147483648, 2147483647]; references 
'__stop_data'
+# CHECK-NEXT: error: {{.*}}:(.text+0x11): relocation R_X86_64_CODE_4_GOTPCRELX 
out of range: 2147483651 is not in [-2147483648, 2147483647]; references 
'__stop_data'
 # CHECK-NEXT: >>> defined in 
 
 #--- a.s
diff --git a/lld/test/ELF/x86-64-gotpc-relax-nopic.s 
b/lld/test/ELF/x86-64-gotpc-relax-nopic.s
index e3cd93d1d57962..be55c7d7006fe5 100644
--- a/lld/test/ELF/x86-64-gotpc-relax-nopic.s
+++ b/lld/test/ELF/x86-64-gotpc-relax-nopic.s
@@ -134,7 +134,7 @@ _start:
   xorqbar@GOTPCREL(%rip), %r8
   testq   %r15, bar@GOTPCREL(%r

[clang] [TargetVersion] Only enable on RISC-V and AArch64 (PR #115991)

2024-11-18 Thread Piyou Chen via cfe-commits

BeMg wrote:

Fix the merge conflict

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


[clang] [llvm] AMDGPU: Add v_mfma_ld_scale_b32 for gfx950 (PR #116722)

2024-11-18 Thread Matt Arsenault via cfe-commits

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


[clang] [clang] Implement __attribute__((format_matches)) (PR #116708)

2024-11-18 Thread via cfe-commits

https://github.com/apple-fcloutier created 
https://github.com/llvm/llvm-project/pull/116708

This implements ``__attribute__((format_matches))``, as described in the RFC: 
https://discourse.llvm.org/t/rfc-format-attribute-attribute-format-like/83076

The ``format`` attribute only allows the compiler to check that a format string 
matches its arguments. If the format string is passed independently of its 
arguments, there is no way to have the compiler check it. 
``format_matches(flavor, fmtidx, example)`` allows the compiler to check format 
strings against the ``example`` format string instead of against format 
arguments. See the changes to AttrDocs.td in this diff for more information.

Implementation-wise, this change subclasses CheckPrintfHandler and 
CheckScanfHandler to allow them to collect specifiers into arrays, and 
implements comparing that two specifiers are equivalent. 
`checkFormatStringExpr` gets a new `ReferenceFormatString` argument that is 
piped down when calling a function with the `format_matches` attribute (and is 
`nullptr` otherwise); this is the string that the actual format string is 
compared against.

Although this change does not enable -Wformat-nonliteral by default, IMO, all 
the pieces are now in place such that it could be.

>From 11aa136f4e9e2d3d3dc133dec37af62714ed607b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix=20Cloutier?= 
Date: Tue, 12 Nov 2024 10:39:18 -0800
Subject: [PATCH] [clang] Implement __attribute__((format_matches))

This implements ``__attribute__((format_matches))``, as described in the RFC:
https://discourse.llvm.org/t/rfc-format-attribute-attribute-format-like/83076

The ``format`` attribute only allows the compiler to check that a format
string matches its arguments. If the format string is passed independently
of its arguments, there is no way to have the compiler check it.
``format_matches(flavor, fmtidx, example)`` allows the compiler to check
format strings against the ``example`` format string instead of against
format arguments. See the changes to AttrDocs.td in this diff for more
information.

Implementation-wise, this change subclasses CheckPrintfHandler and
CheckScanfHandler to allow them to collect specifiers into arrays,
and implements comparing that two specifiers are equivalent.

Radar-Id: 84936554
---
 clang/docs/ReleaseNotes.rst   |  44 +
 clang/include/clang/AST/FormatString.h|   3 +-
 clang/include/clang/Basic/Attr.td |  10 +
 clang/include/clang/Basic/AttrDocs.td |  97 +++
 .../clang/Basic/DiagnosticSemaKinds.td|  21 +
 clang/include/clang/Sema/Sema.h   |  37 +-
 clang/lib/AST/AttrImpl.cpp|   5 +
 clang/lib/AST/FormatString.cpp|  91 +++
 clang/lib/Sema/SemaChecking.cpp   | 754 ++
 clang/lib/Sema/SemaDeclAttr.cpp   | 120 ++-
 clang/lib/Sema/SemaObjC.cpp   |   3 +-
 clang/test/Sema/format-string-matches.c   | 122 +++
 12 files changed, 1121 insertions(+), 186 deletions(-)
 create mode 100644 clang/test/Sema/format-string-matches.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0efe62f1804cd0a..66e4758fe89e243 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -357,6 +357,50 @@ Non-comprehensive list of changes in this release
 
 - ``__builtin_reduce_add`` function can now be used in constant expressions.
 
+- There is a new ``format_matches`` attribute to complement the existing
+  ``format`` attribute. ``format_matches`` allows the compiler to verify that
+  a format string argument is equivalent to a reference format string: it is
+  useful when a function accepts a format string without its accompanying
+  arguments to format. For instance:
+
+  .. code-block:: c
+
+static int status_code;
+static const char *status_string;
+
+void print_status(const char *fmt) {
+  fprintf(stderr, fmt, status_code, status_string);
+  // ^ warning: format string is not a string literal [-Wformat-nonliteral]
+}
+
+void stuff(void) {
+  print_status("%s (%#08x)\n");
+  // order of %s and %x is swapped but there is no diagnostic
+}
+  
+  Before the introducion of ``format_matches``, this code cannot be verified
+  at compile-time. ``format_matches`` plugs that hole:
+
+  .. code-block:: c
+
+__attribute__((format_matches(printf, 1, "%x %s")))
+void print_status(const char *fmt) {
+  fprintf(stderr, fmt, status_code, status_string);
+  // ^ `fmt` verified as if it was "%x %s" here; no longer triggers
+  //   -Wformat-nonliteral, would warn if arguments did not match "%x %s"
+}
+
+void stuff(void) {
+  print_status("%s (%#08x)\n");
+  // warning: format specifier 's' is incompatible with 'x'
+  // warning: format specifier 'x' is incompatible with 's'
+}
+
+  Like with ``format``, the first argument is the format string flavor and the
+  second argu

[clang] [Driver] Remove ignored Flag form of -fauto-profile/-fprofile-sample-use (PR #113528)

2024-11-18 Thread Fangrui Song via cfe-commits

MaskRay wrote:

Ping:)

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


[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-11-18 Thread via cfe-commits


@@ -0,0 +1,730 @@
+//===-- Mustache.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Support/Mustache.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::json;
+
+namespace llvm {
+namespace mustache {
+namespace {
+
+class Token {
+public:
+  enum class Type {
+Text,
+Variable,
+Partial,
+SectionOpen,
+SectionClose,
+InvertSectionOpen,
+UnescapeVariable,
+Comment,
+  };
+
+  Token(std::string Str);
+
+  Token(std::string RawBody, std::string TokenBody, char Identifier);
+
+  StringRef getTokenBody() const { return TokenBody; };
+
+  StringRef getRawBody() const { return RawBody; };
+
+  void setTokenBody(std::string NewBody) { TokenBody = std::move(NewBody); };
+
+  Accessor getAccessor() const { return Accessor; };
+
+  Type getType() const { return TokenType; };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  size_t getIndentation() const { return Indentation; };
+
+  static Type getTokenType(char Identifier);
+
+private:
+  Type TokenType;
+  // RawBody is the original string that was tokenized
+  std::string RawBody;
+  // TokenBody is the original string with the identifier removed
+  std::string TokenBody;
+  Accessor Accessor;
+  size_t Indentation;
+};
+
+class ASTNode {
+public:
+  enum Type {
+Root,
+Text,
+Partial,
+Variable,
+UnescapeVariable,
+Section,
+InvertSection,
+  };
+
+  ASTNode() : T(Type::Root), ParentContext(nullptr) {};
+
+  ASTNode(StringRef Body, ASTNode *Parent)
+  : T(Type::Text), Body(Body), Parent(Parent), ParentContext(nullptr) {};
+
+  // Constructor for Section/InvertSection/Variable/UnescapeVariable
+  ASTNode(Type T, Accessor Accessor, ASTNode *Parent)
+  : T(T), Parent(Parent), Children({}), Accessor(Accessor),
+ParentContext(nullptr) {};
+
+  void addChild(ASTNode *Child) { Children.emplace_back(Child); };
+
+  void setRawBody(std::string NewBody) { RawBody = std::move(NewBody); };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  void render(const llvm::json::Value &Data, llvm::raw_ostream &OS);
+
+  void setUpNode(llvm::BumpPtrAllocator &Alloc, StringMap &Partials,
+ StringMap &Lambdas,
+ StringMap &SectionLambdas,
+ DenseMap &Escapes);
+
+private:
+  void renderLambdas(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ Lambda &L);
+
+  void renderSectionLambdas(const llvm::json::Value &Contexts,
+llvm::raw_ostream &OS, SectionLambda &L);
+
+  void renderPartial(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ ASTNode *Partial);
+
+  void renderChild(const llvm::json::Value &Context, llvm::raw_ostream &OS);
+
+  const llvm::json::Value *findContext();
+
+  llvm::BumpPtrAllocator *Allocator;
+  StringMap *Partials;
+  StringMap *Lambdas;
+  StringMap *SectionLambdas;
+  DenseMap *Escapes;
+  Type T;
+  size_t Indentation = 0;
+  std::string RawBody;
+  std::string Body;
+  ASTNode *Parent;
+  // TODO: switch implementation to SmallVector
+  std::vector Children;
+  const Accessor Accessor;
+  const llvm::json::Value *ParentContext;
+};
+
+// Custom stream to escape strings
+class EscapeStringStream : public raw_ostream {
+public:
+  explicit EscapeStringStream(llvm::raw_ostream &WrappedStream,
+  DenseMap &Escape)
+  : Escape(Escape), WrappedStream(WrappedStream) {
+SetUnbuffered();
+  }
+
+protected:
+  void write_impl(const char *Ptr, size_t Size) override {
+llvm::StringRef Data(Ptr, Size);
+for (char C : Data) {
+  auto It = Escape.find(C);
+  if (It != Escape.end())
+WrappedStream << It->getSecond();
+  else
+WrappedStream << C;
+}
+  }
+
+  uint64_t current_pos() const override { return WrappedStream.tell(); }
+
+private:
+  DenseMap &Escape;
+  llvm::raw_ostream &WrappedStream;
+};
+
+// Custom stream to add indentation used to for rendering partials
+class AddIndentationStringStream : public raw_ostream {
+public:
+  explicit AddIndentationStringStream(llvm::raw_ostream &WrappedStream,
+  size_t Indentation)
+  : Indentation(Indentation), WrappedStream(WrappedStream) {
+SetUnbuffered();
+  }
+
+protected:
+  void write_impl(const char *Ptr, size_t Size) override {
+llvm::StringRef Data(Ptr, Size);
+std::string Indent(Indentation, ' ');
+for (char C : Data) {
+  WrappedStream << C;
+  if (C == '\n')
+WrappedSt

[clang] [Clang][Parser] Make 'T...[N]' within a function parameter a valid pack expansion prior to C++2c (PR #116332)

2024-11-18 Thread Erich Keane via cfe-commits

erichkeane wrote:

> @erichkeane Nah, it's technically valid in C++23. There was no 
> deprecate/remove period because how unused/useless that feature is. (just 
> spell it T*)

Ah, oof!  Thank you for clarifying.  That is really unfortunate.  I don't have 
a great idea on how to handle the transition.  Are we finding that we have uses 
of this?  If so, there is perhaps value to a warning diagnostic that it is 
changing (and re-enabling the old behavior?).  Else, I wonder if we are OK 
being non-conforming in Pre-C++26 mode and just leaving this as an error, 
despite being valid code.  A diagnostic to say "we know we aren't conforming 
here, but this changes meaning, so give this an identifier" is perhaps 
acceptable there? 

I don't have a great idea here as far as what appetite we have for 
accepting/disallowing the older meaning.

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


[clang] [llvm] [aarch64][clang][llvm] Allow AArch64 TLB maintenance instructions to be enabled via -march (PR #116707)

2024-11-18 Thread David Green via cfe-commits

davemgreen wrote:

Could you give more details about why you would want these added? As far as I 
understand they are mandatory features for 8.4 and 8.7, and would usually be 
added via -march=armv8.4-a for example. We try to keep the options between GCC 
and clang the same, and GCC doesn't seem to support either 
https://godbolt.org/z/TTnq48W81. 

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


[clang] [Clang] Fix typo 'dereferencable' to 'dereferenceable' (PR #116761)

2024-11-18 Thread via cfe-commits

https://github.com/kordood created 
https://github.com/llvm/llvm-project/pull/116761

This patch corrects the typo 'dereferencable' to 'dereferenceable' in 
CGCall.cpp.
The typo is located within a comment inside the `void 
CodeGenModule::ConstructAttributeList` function.

>From 462fd333d9986e60d769a04abdfc56a1e8051538 Mon Sep 17 00:00:00 2001
From: Liberty 
Date: Tue, 19 Nov 2024 16:51:16 +0900
Subject: [PATCH] [Clang] Fix typo 'dereferencable' to 'dereferenceable'

---
 clang/lib/CodeGen/CGCall.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 35d495d4dfab82..d22bc688193955 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -2665,7 +2665,7 @@ void CodeGenModule::ConstructAttributeList(StringRef Name,
 llvm::AttributeSet::get(getLLVMContext(), Attrs);
   }
 
-  // Apply `nonnull`, `dereferencable(N)` and `align N` to the `this` argument,
+  // Apply `nonnull`, `dereferenceable(N)` and `align N` to the `this` 
argument,
   // unless this is a thunk function.
   // FIXME: fix this properly, https://reviews.llvm.org/D100388
   if (FI.isInstanceMethod() && !IRFunctionArgs.hasInallocaArg() &&

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


[clang] [Clang] Fix typo 'dereferencable' to 'dereferenceable' (PR #116761)

2024-11-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Liberty (kordood)


Changes

This patch corrects the typo 'dereferencable' to 'dereferenceable' in 
CGCall.cpp.
The typo is located within a comment inside the `void 
CodeGenModule::ConstructAttributeList` function.

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


1 Files Affected:

- (modified) clang/lib/CodeGen/CGCall.cpp (+1-1) 


``diff
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 35d495d4dfab82..d22bc688193955 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -2665,7 +2665,7 @@ void CodeGenModule::ConstructAttributeList(StringRef Name,
 llvm::AttributeSet::get(getLLVMContext(), Attrs);
   }
 
-  // Apply `nonnull`, `dereferencable(N)` and `align N` to the `this` argument,
+  // Apply `nonnull`, `dereferenceable(N)` and `align N` to the `this` 
argument,
   // unless this is a thunk function.
   // FIXME: fix this properly, https://reviews.llvm.org/D100388
   if (FI.isInstanceMethod() && !IRFunctionArgs.hasInallocaArg() &&

``




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


[clang-tools-extra] [clangd] Let DefineOutline tweak handle member function templates (PR #112345)

2024-11-18 Thread Nathan Ridge via cfe-commits


@@ -443,13 +461,26 @@ class DefineOutline : public Tweak {
 SameFile = true;
 
 // Bail out if the template parameter is unnamed.
+// FIXME: Is this really needed? It inhibits application on

HighCommander4 wrote:

Reviewing the discussion 
[here](https://github.com/llvm/llvm-project/pull/95235#discussion_r1730025569), 
the reason is that we have to mention the template parameter as part of the 
out-of-line declaration, e.g.:

Before:
```c++
template 
struct A {
  void foo() {}
};
```

After:
```c++
template 
struct A {
  void foo();
};
template 
void A::foo() {}
```

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


[clang-tools-extra] [clangd] Check for other clangd extension capabilities under 'experimental' (PR #116531)

2024-11-18 Thread Nathan Ridge via cfe-commits

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


[clang-tools-extra] 44a41b0 - [clangd] Check for other clangd extension capabilities under 'experimental' (#116531)

2024-11-18 Thread via cfe-commits

Author: Nathan Ridge
Date: 2024-11-19T01:47:45-05:00
New Revision: 44a41b0660912a90be903a843e8b6f234fa0a2be

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

LOG: [clangd] Check for other clangd extension capabilities under 
'experimental' (#116531)

This is a follow-up to PR114699, with the same motivation: to support
clients which only support adding custom (language-specific or
server-specific) capabilities under 'experimental'.

Added: 


Modified: 
clang-tools-extra/clangd/Protocol.cpp
clang-tools-extra/clangd/Protocol.h

Removed: 




diff  --git a/clang-tools-extra/clangd/Protocol.cpp 
b/clang-tools-extra/clangd/Protocol.cpp
index 761f96846d4538..05c8041df7de75 100644
--- a/clang-tools-extra/clangd/Protocol.cpp
+++ b/clang-tools-extra/clangd/Protocol.cpp
@@ -511,6 +511,35 @@ bool fromJSON(const llvm::json::Value &Params, 
ClientCapabilities &R,
 if (auto EditsNearCursor = Completion->getBoolean("editsNearCursor"))
   R.CompletionFixes |= *EditsNearCursor;
   }
+  if (auto *References = TextDocument->getObject("references")) {
+if (auto ContainerSupport = References->getBoolean("container")) {
+  R.ReferenceContainer |= *ContainerSupport;
+}
+  }
+  if (auto *Diagnostics = TextDocument->getObject("publishDiagnostics")) {
+if (auto CodeActions = Diagnostics->getBoolean("codeActionsInline")) {
+  R.DiagnosticFixes |= *CodeActions;
+}
+  }
+  if (auto *InactiveRegions =
+  TextDocument->getObject("inactiveRegionsCapabilities")) {
+if (auto InactiveRegionsSupport =
+InactiveRegions->getBoolean("inactiveRegions")) {
+  R.InactiveRegions |= *InactiveRegionsSupport;
+}
+  }
+}
+if (auto *Window = Experimental->getObject("window")) {
+  if (auto Implicit =
+  Window->getBoolean("implicitWorkDoneProgressCreate")) {
+R.ImplicitProgressCreation |= *Implicit;
+  }
+}
+if (auto *OffsetEncoding = Experimental->get("offsetEncoding")) {
+  R.offsetEncoding.emplace();
+  if (!fromJSON(*OffsetEncoding, *R.offsetEncoding,
+P.field("offsetEncoding")))
+return false;
 }
   }
 

diff  --git a/clang-tools-extra/clangd/Protocol.h 
b/clang-tools-extra/clangd/Protocol.h
index 5b28095758198d..c7ef1a13e6e39e 100644
--- a/clang-tools-extra/clangd/Protocol.h
+++ b/clang-tools-extra/clangd/Protocol.h
@@ -452,6 +452,7 @@ struct ClientCapabilities {
   std::optional WorkspaceSymbolKinds;
 
   /// Whether the client accepts diagnostics with codeActions attached inline.
+  /// This is a clangd extension.
   /// textDocument.publishDiagnostics.codeActionsInline.
   bool DiagnosticFixes = false;
 
@@ -475,6 +476,7 @@ struct ClientCapabilities {
 
   /// Client supports displaying a container string for results of
   /// textDocument/reference (clangd extension)
+  /// textDocument.references.container
   bool ReferenceContainer = false;
 
   /// Client supports hierarchical document symbols.
@@ -563,6 +565,7 @@ struct ClientCapabilities {
 
   /// Whether the client supports the textDocument/inactiveRegions
   /// notification. This is a clangd extension.
+  /// textDocument.inactiveRegionsCapabilities.inactiveRegions
   bool InactiveRegions = false;
 };
 bool fromJSON(const llvm::json::Value &, ClientCapabilities &,



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


[clang] [clang][RISCV] Bump RVV intrinsic to version 1.0 (PR #116597)

2024-11-18 Thread Brandon Wu via cfe-commits

https://github.com/4vtomat updated 
https://github.com/llvm/llvm-project/pull/116597

>From 5addb1d33fc195b084a4869217d763abb1eef1af Mon Sep 17 00:00:00 2001
From: Brandon Wu 
Date: Mon, 18 Nov 2024 02:02:34 -0800
Subject: [PATCH 1/2] [clang][RISCV] Bump RVV intrinsic to version 1.0

The spec: 
https://github.com/riscv-non-isa/rvv-intrinsic-doc/releases/tag/v1.0.0-rc4
Also remove __riscv_v_intrinsic_overloading since it's no longer in
spec, the overloading intrinsics should be also enabled when RVV
intrinsics are defined.
---
 clang/lib/Basic/Targets/RISCV.cpp   |  4 ++--
 clang/test/Preprocessor/riscv-target-features.c | 12 ++--
 clang/utils/TableGen/RISCVVEmitter.cpp  |  2 --
 3 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index eaaba7642bd7b2..628fdfd404698d 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -214,8 +214,8 @@ void RISCVTargetInfo::getTargetDefines(const LangOptions 
&Opts,
 
   if (ISAInfo->hasExtension("zve32x")) {
 Builder.defineMacro("__riscv_vector");
-// Currently we support the v0.12 RISC-V V intrinsics.
-Builder.defineMacro("__riscv_v_intrinsic", Twine(getVersionValue(0, 12)));
+// Currently we support the v1.0 RISC-V V intrinsics.
+Builder.defineMacro("__riscv_v_intrinsic", Twine(getVersionValue(1, 0)));
   }
 
   auto VScale = getVScaleRange(Opts);
diff --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 7e8d1fa2448b80..13125d749c5fab 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -536,7 +536,7 @@
 // CHECK-V-EXT: __riscv_v 100{{$}}
 // CHECK-V-EXT: __riscv_v_elen 64
 // CHECK-V-EXT: __riscv_v_elen_fp 64
-// CHECK-V-EXT: __riscv_v_intrinsic 12000{{$}}
+// CHECK-V-EXT: __riscv_v_intrinsic 100{{$}}
 // CHECK-V-EXT: __riscv_v_min_vlen 128
 // CHECK-V-EXT: __riscv_vector 1
 
@@ -1244,7 +1244,7 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZVE32F-EXT %s
 // CHECK-ZVE32F-EXT: __riscv_v_elen 32
 // CHECK-ZVE32F-EXT: __riscv_v_elen_fp 32
-// CHECK-ZVE32F-EXT: __riscv_v_intrinsic 12000{{$}}
+// CHECK-ZVE32F-EXT: __riscv_v_intrinsic 100{{$}}
 // CHECK-ZVE32F-EXT: __riscv_v_min_vlen 32
 // CHECK-ZVE32F-EXT: __riscv_vector 1
 // CHECK-ZVE32F-EXT: __riscv_zve32f 100{{$}}
@@ -1258,7 +1258,7 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZVE32X-EXT %s
 // CHECK-ZVE32X-EXT: __riscv_v_elen 32
 // CHECK-ZVE32X-EXT: __riscv_v_elen_fp 0
-// CHECK-ZVE32X-EXT: __riscv_v_intrinsic 12000{{$}}
+// CHECK-ZVE32X-EXT: __riscv_v_intrinsic 100{{$}}
 // CHECK-ZVE32X-EXT: __riscv_v_min_vlen 32
 // CHECK-ZVE32X-EXT: __riscv_vector 1
 // CHECK-ZVE32X-EXT: __riscv_zve32x 100{{$}}
@@ -1271,7 +1271,7 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZVE64D-EXT %s
 // CHECK-ZVE64D-EXT: __riscv_v_elen 64
 // CHECK-ZVE64D-EXT: __riscv_v_elen_fp 64
-// CHECK-ZVE64D-EXT: __riscv_v_intrinsic 12000{{$}}
+// CHECK-ZVE64D-EXT: __riscv_v_intrinsic 100{{$}}
 // CHECK-ZVE64D-EXT: __riscv_v_min_vlen 64
 // CHECK-ZVE64D-EXT: __riscv_vector 1
 // CHECK-ZVE64D-EXT: __riscv_zve32f 100{{$}}
@@ -1288,7 +1288,7 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZVE64F-EXT %s
 // CHECK-ZVE64F-EXT: __riscv_v_elen 64
 // CHECK-ZVE64F-EXT: __riscv_v_elen_fp 32
-// CHECK-ZVE64F-EXT: __riscv_v_intrinsic 12000{{$}}
+// CHECK-ZVE64F-EXT: __riscv_v_intrinsic 100{{$}}
 // CHECK-ZVE64F-EXT: __riscv_v_min_vlen 64
 // CHECK-ZVE64F-EXT: __riscv_vector 1
 // CHECK-ZVE64F-EXT: __riscv_zve32f 100{{$}}
@@ -1304,7 +1304,7 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZVE64X-EXT %s
 // CHECK-ZVE64X-EXT: __riscv_v_elen 64
 // CHECK-ZVE64X-EXT: __riscv_v_elen_fp 0
-// CHECK-ZVE64X-EXT: __riscv_v_intrinsic 12000{{$}}
+// CHECK-ZVE64X-EXT: __riscv_v_intrinsic 100{{$}}
 // CHECK-ZVE64X-EXT: __riscv_v_min_vlen 64
 // CHECK-ZVE64X-EXT: __riscv_vector 1
 // CHECK-ZVE64X-EXT: __riscv_zve32x 100{{$}}
diff --git a/clang/utils/TableGen/RISCVVEmitter.cpp 
b/clang/utils/TableGen/RISCVVEmitter.cpp
index 68d7831c117458..acba1a31912816 100644
--- a/clang/utils/TableGen/RISCVVEmitter.cpp
+++ b/clang/utils/TableGen/RISCVVEmitter.cpp
@@ -488,8 +488,6 @@ void RVVEmitter::createHeader(raw_ostream &OS) {
 }
   }
 
-  OS << "#define __riscv_v_intrinsic_overloading 1\n";
-
   OS << "\n#ifdef __cplusplus\n";
   OS << "}\n";
   OS << "#endif // __cplusplus\n";

>From 7de5a3819b516fb6f6b00c3b4d25a680c34644bf Mon Sep 17 00:00:00 2001
From: Brandon Wu 
Date: Mon, 18 Nov 2024 23:02:11 -0800
Subject: [PATCH 2/2] fixup! [clang][RISCV] Bump RVV intrinsic to version 1.0

---
 clang/docs/ReleaseNotes.rst | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 044f62e770a7a0..f2590b79ae14ce 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNote

[clang] [llvm] [RISCV] Support `svukte` extension (PR #115657)

2024-11-18 Thread Craig Topper via cfe-commits


@@ -158,6 +158,7 @@ on support follow.
  ``Svinval``   Assembly Support
  ``Svnapot``   Assembly Support
  ``Svpbmt``Supported
+ ``Svukte``Supported

topperc wrote:

This should be in the experimental section with the link to the spec.

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


[clang] [llvm] [RISCV] Support `svukte` extension (PR #115657)

2024-11-18 Thread Brandon Wu via cfe-commits


@@ -158,6 +158,7 @@ on support follow.
  ``Svinval``   Assembly Support
  ``Svnapot``   Assembly Support
  ``Svpbmt``Supported
+ ``Svukte``Supported

4vtomat wrote:

I thought it's frozen, hasn't it?

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


[clang] [llvm] Adjust MSVC disabled optimization pragmas to be _MSC_VER only (PR #116704)

2024-11-18 Thread Martin Storsjö via cfe-commits


@@ -1616,7 +1616,7 @@ bool Interpret(InterpState &S, APValue &Result) {
   }
 }
 // https://github.com/llvm/llvm-project/issues/102513
-#if defined(_WIN32) && !defined(__clang__) && !defined(NDEBUG)
+#if defined(_MSC_VER) && !defined(__clang__) && !defined(NDEBUG)
 #pragma optimize("", on)

mstorsjo wrote:

Isn't this missing a second instance of the same further up in the file?

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


[clang] [HLSL] Fix resource kind for RasterizerOrderedStructuredBuffer (PR #116700)

2024-11-18 Thread Justin Bogner via cfe-commits

https://github.com/bogner created 
https://github.com/llvm/llvm-project/pull/116700

This is a kind of StructuredBuffer, so it should be "Raw" and not "Typed".

>From 0650fee514af7b4e5ca58f2bba4a8447ef1dd9c4 Mon Sep 17 00:00:00 2001
From: Justin Bogner 
Date: Wed, 13 Nov 2024 17:02:52 -0800
Subject: [PATCH] [HLSL] Fix resource kind for
 RasterizerOrderedStructuredBuffer

This is a kind of StructuredBuffer, so it should be "Raw" and not "Typed".
---
 clang/lib/Sema/HLSLExternalSemaSource.cpp | 2 +-
 .../test/AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl  | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp 
b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index cac15b974a276e..1013885928b1d8 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -548,7 +548,7 @@ void 
HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
  .Record;
   onCompletion(Decl, [this](CXXRecordDecl *Decl) {
 setupBufferType(Decl, *SemaPtr, ResourceClass::UAV,
-ResourceKind::TypedBuffer, /*IsROV=*/true,
+ResourceKind::RawBuffer, /*IsROV=*/true,
 /*RawBuffer=*/true)
 .addArraySubscriptOperators()
 .completeDefinition();
diff --git a/clang/test/AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl 
b/clang/test/AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl
index f334e1bb6db3fc..eb8bfeffb481f1 100644
--- a/clang/test/AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl
+++ b/clang/test/AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl
@@ -35,7 +35,7 @@ RasterizerOrderedStructuredBuffer Buffer;
 // CHECK-SAME{LITERAL}: [[hlsl::is_rov]]
 // CHECK-SAME{LITERAL}: [[hlsl::raw_buffer]]
 // CHECK-SAME{LITERAL}: [[hlsl::contained_type(element_type)]]
-// CHECK-NEXT: HLSLResourceAttr 0x{{[0-9A-Fa-f]+}} <> Implicit 
TypedBuffer
+// CHECK-NEXT: HLSLResourceAttr 0x{{[0-9A-Fa-f]+}} <> Implicit 
RawBuffer
 
 // CHECK: CXXMethodDecl 0x{{[0-9A-Fa-f]+}} <>  
operator[] 'element_type &const (unsigned int) const'
 // CHECK-NEXT: ParmVarDecl 0x{{[0-9A-Fa-f]+}} <>  
Idx 'unsigned int'
@@ -63,4 +63,4 @@ RasterizerOrderedStructuredBuffer Buffer;
 // CHECK-SAME{LITERAL}: [[hlsl::is_rov]]
 // CHECK-SAME{LITERAL}: [[hlsl::raw_buffer]]
 // CHECK-SAME{LITERAL}: [[hlsl::contained_type(int)]]
-// CHECK-NEXT: HLSLResourceAttr 0x{{[0-9A-Fa-f]+}} <> Implicit 
TypedBuffer
+// CHECK-NEXT: HLSLResourceAttr 0x{{[0-9A-Fa-f]+}} <> Implicit 
RawBuffer

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


[clang] 1ced565 - [Clang] Add support for scoped atomic thread fence (#115545)

2024-11-18 Thread via cfe-commits

Author: Joseph Huber
Date: 2024-11-18T16:43:33-06:00
New Revision: 1ced56540071476d0a4aa8cb5134106d02b5b7f1

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

LOG: [Clang] Add support for scoped atomic thread fence (#115545)

Summary:
Previously we added support for all of the atomic GNU extensions with
optional memory scoped except for `__atomic_thread_fence`. This patch
adds support for that. This should ideally allow us to generically emit
these LLVM scopes.

Added: 
clang/test/CodeGen/scoped-fence-ops.c

Modified: 
clang/include/clang/Basic/Builtins.td
clang/lib/CodeGen/CGBuiltin.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index f5124f4633364f..191dfa1dd2c77c 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -1995,6 +1995,12 @@ def AtomicThreadFence : Builtin {
   let Prototype = "void(int)";
 }
 
+def ScopedAtomicThreadFence : Builtin {
+  let Spellings = ["__scoped_atomic_thread_fence"];
+  let Attributes = [NoThrow];
+  let Prototype = "void(int, int)";
+}
+
 def AtomicSignalFence : Builtin {
   let Spellings = ["__atomic_signal_fence"];
   let Attributes = [NoThrow];

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index df69d188306be0..0916e14f182ddd 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5213,6 +5213,136 @@ RValue CodeGenFunction::EmitBuiltinExpr(const 
GlobalDecl GD, unsigned BuiltinID,
 Builder.SetInsertPoint(ContBB);
 return RValue::get(nullptr);
   }
+  case Builtin::BI__scoped_atomic_thread_fence: {
+auto ScopeModel = AtomicScopeModel::create(AtomicScopeModelKind::Generic);
+
+Value *Order = EmitScalarExpr(E->getArg(0));
+Value *Scope = EmitScalarExpr(E->getArg(1));
+auto Ord = dyn_cast(Order);
+auto Scp = dyn_cast(Scope);
+if (Ord && Scp) {
+  SyncScope SS = ScopeModel->isValid(Scp->getZExtValue())
+ ? ScopeModel->map(Scp->getZExtValue())
+ : ScopeModel->map(ScopeModel->getFallBackValue());
+  switch (Ord->getZExtValue()) {
+  case 0:  // memory_order_relaxed
+  default: // invalid order
+break;
+  case 1: // memory_order_consume
+  case 2: // memory_order_acquire
+Builder.CreateFence(
+llvm::AtomicOrdering::Acquire,
+getTargetHooks().getLLVMSyncScopeID(getLangOpts(), SS,
+llvm::AtomicOrdering::Acquire,
+getLLVMContext()));
+break;
+  case 3: // memory_order_release
+Builder.CreateFence(
+llvm::AtomicOrdering::Release,
+getTargetHooks().getLLVMSyncScopeID(getLangOpts(), SS,
+llvm::AtomicOrdering::Release,
+getLLVMContext()));
+break;
+  case 4: // memory_order_acq_rel
+Builder.CreateFence(llvm::AtomicOrdering::AcquireRelease,
+getTargetHooks().getLLVMSyncScopeID(
+getLangOpts(), SS,
+llvm::AtomicOrdering::AcquireRelease,
+getLLVMContext()));
+break;
+  case 5: // memory_order_seq_cst
+Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent,
+getTargetHooks().getLLVMSyncScopeID(
+getLangOpts(), SS,
+llvm::AtomicOrdering::SequentiallyConsistent,
+getLLVMContext()));
+break;
+  }
+  return RValue::get(nullptr);
+}
+
+llvm::BasicBlock *ContBB = createBasicBlock("atomic.scope.continue", 
CurFn);
+
+llvm::SmallVector>
+OrderBBs;
+if (Ord) {
+  switch (Ord->getZExtValue()) {
+  case 0:  // memory_order_relaxed
+  default: // invalid order
+ContBB->eraseFromParent();
+return RValue::get(nullptr);
+  case 1: // memory_order_consume
+  case 2: // memory_order_acquire
+OrderBBs.emplace_back(Builder.GetInsertBlock(),
+  llvm::AtomicOrdering::Acquire);
+break;
+  case 3: // memory_order_release
+OrderBBs.emplace_back(Builder.GetInsertBlock(),
+  llvm::AtomicOrdering::Release);
+break;
+  case 4: // memory_order_acq_rel
+OrderBBs.emplace_back(Builder.GetInsertBlock(),
+  llvm::AtomicOrdering::AcquireRelease);
+break;
+  case 5: // memory_order_seq_cst
+OrderBBs.emplace_back(Builder.GetInsertBl

[clang] [Clang] Add support for scoped atomic thread fence (PR #115545)

2024-11-18 Thread Joseph Huber via cfe-commits

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


[clang] [clang] Implement __attribute__((format_matches)) (PR #116708)

2024-11-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (apple-fcloutier)


Changes

This implements ``__attribute__((format_matches))``, as described in the RFC: 
https://discourse.llvm.org/t/rfc-format-attribute-attribute-format-like/83076

The ``format`` attribute only allows the compiler to check that a format string 
matches its arguments. If the format string is passed independently of its 
arguments, there is no way to have the compiler check it. 
``format_matches(flavor, fmtidx, example)`` allows the compiler to check format 
strings against the ``example`` format string instead of against format 
arguments. See the changes to AttrDocs.td in this diff for more information.

Implementation-wise, this change subclasses CheckPrintfHandler and 
CheckScanfHandler to allow them to collect specifiers into arrays, and 
implements comparing that two specifiers are equivalent. 
`checkFormatStringExpr` gets a new `ReferenceFormatString` argument that is 
piped down when calling a function with the `format_matches` attribute (and is 
`nullptr` otherwise); this is the string that the actual format string is 
compared against.

Although this change does not enable -Wformat-nonliteral by default, IMO, all 
the pieces are now in place such that it could be.

---

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


12 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+44) 
- (modified) clang/include/clang/AST/FormatString.h (+2-1) 
- (modified) clang/include/clang/Basic/Attr.td (+10) 
- (modified) clang/include/clang/Basic/AttrDocs.td (+97) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+21) 
- (modified) clang/include/clang/Sema/Sema.h (+27-10) 
- (modified) clang/lib/AST/AttrImpl.cpp (+5) 
- (modified) clang/lib/AST/FormatString.cpp (+91) 
- (modified) clang/lib/Sema/SemaChecking.cpp (+607-147) 
- (modified) clang/lib/Sema/SemaDeclAttr.cpp (+93-27) 
- (modified) clang/lib/Sema/SemaObjC.cpp (+2-1) 
- (added) clang/test/Sema/format-string-matches.c (+122) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0efe62f1804cd0a..66e4758fe89e243 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -357,6 +357,50 @@ Non-comprehensive list of changes in this release
 
 - ``__builtin_reduce_add`` function can now be used in constant expressions.
 
+- There is a new ``format_matches`` attribute to complement the existing
+  ``format`` attribute. ``format_matches`` allows the compiler to verify that
+  a format string argument is equivalent to a reference format string: it is
+  useful when a function accepts a format string without its accompanying
+  arguments to format. For instance:
+
+  .. code-block:: c
+
+static int status_code;
+static const char *status_string;
+
+void print_status(const char *fmt) {
+  fprintf(stderr, fmt, status_code, status_string);
+  // ^ warning: format string is not a string literal [-Wformat-nonliteral]
+}
+
+void stuff(void) {
+  print_status("%s (%#08x)\n");
+  // order of %s and %x is swapped but there is no diagnostic
+}
+  
+  Before the introducion of ``format_matches``, this code cannot be verified
+  at compile-time. ``format_matches`` plugs that hole:
+
+  .. code-block:: c
+
+__attribute__((format_matches(printf, 1, "%x %s")))
+void print_status(const char *fmt) {
+  fprintf(stderr, fmt, status_code, status_string);
+  // ^ `fmt` verified as if it was "%x %s" here; no longer triggers
+  //   -Wformat-nonliteral, would warn if arguments did not match "%x %s"
+}
+
+void stuff(void) {
+  print_status("%s (%#08x)\n");
+  // warning: format specifier 's' is incompatible with 'x'
+  // warning: format specifier 'x' is incompatible with 's'
+}
+
+  Like with ``format``, the first argument is the format string flavor and the
+  second argument is the index of the format string parameter.
+  ``format_matches`` accepts an example valid format string as its third
+  argument. For more information, see the Clang attributes documentation.
+
 New Compiler Flags
 --
 
diff --git a/clang/include/clang/AST/FormatString.h 
b/clang/include/clang/AST/FormatString.h
index a074dd23e2ad4c7..3560766433fe220 100644
--- a/clang/include/clang/AST/FormatString.h
+++ b/clang/include/clang/AST/FormatString.h
@@ -292,7 +292,7 @@ class ArgType {
   };
 
 private:
-  const Kind K;
+  Kind K;
   QualType T;
   const char *Name = nullptr;
   bool Ptr = false;
@@ -338,6 +338,7 @@ class ArgType {
   }
 
   MatchKind matchesType(ASTContext &C, QualType argTy) const;
+  MatchKind matchesArgType(ASTContext &C, const ArgType &other) const;
 
   QualType getRepresentativeType(ASTContext &C) const;
 
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 6035a563d5fce77..7723e631aa2529c 100644
--- a/clang/include/clang/Basic/Att

[clang] [HLSL] Fix placement of `const` for resource operator[] (PR #116698)

2024-11-18 Thread Chris B via cfe-commits

https://github.com/llvm-beanz approved this pull request.


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


[clang] [analyzer] Handle [[assume(cond)]] as __builtin_assume(cond) (PR #116462)

2024-11-18 Thread Vinay Deshmukh via cfe-commits

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


[clang] [analyzer][Solver] Early return if sym is concrete on assuming (PR #115579)

2024-11-18 Thread Ding Fei via cfe-commits

danix800 wrote:

> @danix800 Could you please have a look at the failed test, such that we could 
> reapply this PR? I reverted this soon after I realized the broken test is 
> from this PR.

The test randomly fails for unknown reason, on VS2019~2022, after 
1c154bd755153b5c6ada4bbed58facf23f6abffc (seems totally irrelevant to this 
randomness). Not sure if it's a compiler bug.

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


[clang] [TBAA] Extend pointer TBAA to pointers of non-builtin types. (PR #110569)

2024-11-18 Thread Florian Hahn via cfe-commits

fhahn wrote:

I think the initial version didn't correctly account for unnamed structs in C, 
for which the compatible types rule applies. Put up a fix: 
https://github.com/llvm/llvm-project/pull/116596

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


[clang] [clang][RISCV] Bump RVV intrinsic to version 1.0 (PR #116597)

2024-11-18 Thread Brandon Wu via cfe-commits

4vtomat wrote:

> Add ReleaseNote to Clang?

Updated!

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


[clang] [clang][RISCV] Bump RVV intrinsic to version 1.0 (PR #116597)

2024-11-18 Thread Craig Topper via cfe-commits

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

LGTM

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


[clang] [llvm] [RISCV] Support `svukte` extension (PR #115657)

2024-11-18 Thread Brandon Wu via cfe-commits

https://github.com/4vtomat updated 
https://github.com/llvm/llvm-project/pull/115657

>From 0c95051b617be8fd242e317c442a1881d5f28034 Mon Sep 17 00:00:00 2001
From: Brandon Wu 
Date: Mon, 5 Aug 2024 11:59:52 +0800
Subject: [PATCH 1/2] [RISCV] Support `svukte` extension

This is the extension for "Address-Independent Latency of User-Mode
Faults to Supervisor Addresses".
Spec: https://github.com/riscv/riscv-isa-manual/pull/1564
The spec states that the `svukte` depends on `sv39`, but we don't have
`sv39` yet, so I didn't add it to the implied list.
---
 clang/test/Driver/print-supported-extensions-riscv.c | 1 +
 clang/test/Preprocessor/riscv-target-features.c  | 8 
 llvm/lib/Target/RISCV/RISCVFeatures.td   | 4 
 llvm/test/CodeGen/RISCV/attributes.ll| 4 
 llvm/test/MC/RISCV/attribute-arch.s  | 3 +++
 llvm/unittests/TargetParser/RISCVISAInfoTest.cpp | 1 +
 6 files changed, 21 insertions(+)

diff --git a/clang/test/Driver/print-supported-extensions-riscv.c 
b/clang/test/Driver/print-supported-extensions-riscv.c
index 774dc3a4e1e756..151e4701a1da84 100644
--- a/clang/test/Driver/print-supported-extensions-riscv.c
+++ b/clang/test/Driver/print-supported-extensions-riscv.c
@@ -187,6 +187,7 @@
 // CHECK-NEXT: zvkgs0.7   'Zvkgs' (Vector-Scalar GCM 
instructions for Cryptography)
 // CHECK-NEXT: smctr1.0   'Smctr' (Control Transfer 
Records Machine Level)
 // CHECK-NEXT: ssctr1.0   'Ssctr' (Control Transfer 
Records Supervisor Level)
+// CHECK-NEXT: svukte   0.3   'Svukte' 
(Address-Independent Latency of User-Mode Faults to Supervisor Addresses)
 // CHECK-EMPTY:
 // CHECK-NEXT: Supported Profiles
 // CHECK-NEXT: rva20s64
diff --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 7e8d1fa2448b80..f1ec6d5734f251 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -1811,6 +1811,14 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-SSCTR-EXT %s
 // CHECK-SSCTR-EXT: __riscv_ssctr 100{{$}}
 
+// RUN: %clang --target=riscv32 -menable-experimental-extensions \
+// RUN:   -march=rv32i_svukte0p3 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-SVUKTE-EXT %s
+// RUN: %clang --target=riscv64 -menable-experimental-extensions \
+// RUN:   -march=rv64i_svukte0p3 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-SVUKTE-EXT %s
+// CHECK-SVUKTE-EXT: __riscv_svukte 3000{{$}}
+
 // Misaligned
 
 // RUN: %clang --target=riscv32-unknown-linux-gnu -march=rv32i -E -dM %s \
diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td 
b/llvm/lib/Target/RISCV/RISCVFeatures.td
index ad733e1488b5ca..d0d9aa64af4e20 100644
--- a/llvm/lib/Target/RISCV/RISCVFeatures.td
+++ b/llvm/lib/Target/RISCV/RISCVFeatures.td
@@ -1056,6 +1056,10 @@ def FeatureStdExtSha
   FeatureStdExtShvstvala, FeatureStdExtShtvala, 
FeatureStdExtShvstvecd,
   FeatureStdExtShvsatpa, FeatureStdExtShgatpa]>;
 
+def FeatureStdExtSvukte
+: RISCVExperimentalExtension<"svukte", 0, 3,
+ "'Svukte' (Address-Independent Latency of 
User-Mode Faults to Supervisor Addresses)">;
+
 // Pointer Masking extensions
 
 // A supervisor-level extension that provides pointer masking for the next 
lower
diff --git a/llvm/test/CodeGen/RISCV/attributes.ll 
b/llvm/test/CodeGen/RISCV/attributes.ll
index 7624071f4f93ec..35c8cc94f40902 100644
--- a/llvm/test/CodeGen/RISCV/attributes.ll
+++ b/llvm/test/CodeGen/RISCV/attributes.ll
@@ -62,6 +62,7 @@
 ; RUN: llc -mtriple=riscv32 -mattr=+svbare %s -o - | FileCheck 
--check-prefixes=CHECK,RV32SVBARE %s
 ; RUN: llc -mtriple=riscv32 -mattr=+svnapot %s -o - | FileCheck 
--check-prefixes=CHECK,RV32SVNAPOT %s
 ; RUN: llc -mtriple=riscv32 -mattr=+svpbmt %s -o - | FileCheck 
--check-prefixes=CHECK,RV32SVPBMT %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-svukte %s -o - | FileCheck 
--check-prefixes=CHECK,RV32SVUKTE %s
 ; RUN: llc -mtriple=riscv32 -mattr=+svvptc %s -o - | FileCheck 
--check-prefixes=CHECK,RV32SVVPTC %s
 ; RUN: llc -mtriple=riscv32 -mattr=+svinval %s -o - | FileCheck 
--check-prefixes=CHECK,RV32SVINVAL %s
 ; RUN: llc -mtriple=riscv32 -mattr=+xcvalu %s -o - | FileCheck 
--check-prefix=RV32XCVALU %s
@@ -205,6 +206,7 @@
 ; RUN: llc -mtriple=riscv64 -mattr=+svbare %s -o - | FileCheck 
--check-prefixes=CHECK,RV64SVBARE %s
 ; RUN: llc -mtriple=riscv64 -mattr=+svnapot %s -o - | FileCheck 
--check-prefixes=CHECK,RV64SVNAPOT %s
 ; RUN: llc -mtriple=riscv64 -mattr=+svpbmt %s -o - | FileCheck 
--check-prefixes=CHECK,RV64SVPBMT %s
+; RUN: llc -mtriple=riscv64 -mattr=+experimental-svukte %s -o - | FileCheck 
--check-prefixes=CHECK,RV64SVUKTE %s
 ; RUN: llc -mtriple=riscv64 -mattr=+svvptc %s -o - | FileCheck 
--check-prefixes=CHECK,RV64SVVPTC %s
 ; RUN: llc -mtriple=riscv64 -mattr=+s

[clang] 130a315 - AMDGPU: Define v_mfma_f32_32x32x16_bf16 for gfx950 (#116679)

2024-11-18 Thread via cfe-commits

Author: Matt Arsenault
Date: 2024-11-18T21:53:56-08:00
New Revision: 130a3150ec9cdaecdf9b0fa773b8c23a6b9bc527

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

LOG: AMDGPU: Define v_mfma_f32_32x32x16_bf16 for gfx950 (#116679)

Unlike the existing gfx940 intrinsics using short/i16 in place of
bfloat, this uses the natural bfloat type.

Added: 
llvm/test/CodeGen/AMDGPU/llvm.amdgcn.mfma.gfx950.bf16.ll

Modified: 
clang/include/clang/Basic/BuiltinsAMDGPU.def
clang/test/CodeGenOpenCL/builtins-amdgcn-mfma.cl
clang/test/SemaOpenCL/builtins-amdgcn-error-gfx950-param.cl
clang/test/SemaOpenCL/builtins-amdgcn-error-gfx950.cl
llvm/include/llvm/IR/IntrinsicsAMDGPU.td
llvm/lib/Target/AMDGPU/SIInstrInfo.td
llvm/lib/Target/AMDGPU/VOP3PInstructions.td
llvm/test/Analysis/UniformityAnalysis/AMDGPU/intrinsics.ll
llvm/test/MC/AMDGPU/mai-gfx950.s
llvm/test/MC/Disassembler/AMDGPU/gfx950_mai.txt
llvm/test/tools/llvm-mca/AMDGPU/gfx950.s

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def 
b/clang/include/clang/Basic/BuiltinsAMDGPU.def
index 6917d8d1aca69d..7ce8f2c1669d67 100644
--- a/clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -437,6 +437,8 @@ TARGET_BUILTIN(__builtin_amdgcn_cvt_sr_fp8_f32, "ifiiIi", 
"nc", "fp8-conversion-
 TARGET_BUILTIN(__builtin_amdgcn_mfma_f32_16x16x32_f16, "V4fV8hV8hV4fIiIiIi", 
"nc", "gfx950-insts")
 TARGET_BUILTIN(__builtin_amdgcn_mfma_f32_32x32x16_f16, "V16fV8hV8hV16fIiIiIi", 
"nc", "gfx950-insts")
 
+TARGET_BUILTIN(__builtin_amdgcn_mfma_f32_32x32x16_bf16, 
"V16fV8yV8yV16fIiIiIi", "nc", "gfx950-insts")
+
 
//===--===//
 // GFX12+ only builtins.
 
//===--===//

diff  --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-mfma.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-mfma.cl
index a644a60f9ec381..841d8fcad0fee0 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn-mfma.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-mfma.cl
@@ -24,6 +24,7 @@ typedef short  v8s   __attribute__((ext_vector_type(8)));
 typedef short  v16s  __attribute__((ext_vector_type(16)));
 typedef short  v32s  __attribute__((ext_vector_type(32)));
 typedef double v4d   __attribute__((ext_vector_type(4)));
+typedef __bf16 v8bf16   __attribute__((ext_vector_type(8)));
 
 
 #ifdef MFMA_GFX908_TESTS
@@ -424,5 +425,10 @@ v16f test_mfma_f32_32x32x16_f16(v8h a, v8h b, v16f c)
   return __builtin_amdgcn_mfma_f32_32x32x16_f16(a, b, c, 1, 2, 3);
 }
 
+// CHECK-GFX950-LABEL: @test_mfma_f32_32x32x16_bf16(
+// CHECK-GFX950: tail call <16 x float> @llvm.amdgcn.mfma.f32.32x32x16.bf16(<8 
x bfloat> %a, <8 x bfloat> %b, <16 x float> %c, i32 1, i32 2, i32 3)
+v16f test_mfma_f32_32x32x16_bf16(v8bf16 a, v8bf16 b, v16f c) {
+  return __builtin_amdgcn_mfma_f32_32x32x16_bf16(a, b, c, 1, 2, 3);
+}
 
 #endif

diff  --git a/clang/test/SemaOpenCL/builtins-amdgcn-error-gfx950-param.cl 
b/clang/test/SemaOpenCL/builtins-amdgcn-error-gfx950-param.cl
index 4c267e2cac5cad..4af67763c40dd2 100644
--- a/clang/test/SemaOpenCL/builtins-amdgcn-error-gfx950-param.cl
+++ b/clang/test/SemaOpenCL/builtins-amdgcn-error-gfx950-param.cl
@@ -4,6 +4,7 @@
 typedef float float4 __attribute__((ext_vector_type(4)));
 typedef float float16 __attribute__((ext_vector_type(16)));
 typedef half half8 __attribute__((ext_vector_type(8)));
+typedef __bf16 bfloat8 __attribute__((ext_vector_type(8)));
 
 
 void test_mfma_f32_16x16x32_f16(__global float4* out, half8 a, half8 b, float4 
c, int X) {
@@ -19,3 +20,9 @@ void test_mfma_f32_32x32x16_f16(__global float16* out, half8 
a, half8 b, float16
   *out = __builtin_amdgcn_mfma_f32_32x32x16_f16(a, b, c, 0, X, 0); // 
expected-error{{argument to '__builtin_amdgcn_mfma_f32_32x32x16_f16' must be a 
constant integer}}
   *out = __builtin_amdgcn_mfma_f32_32x32x16_f16(a, b, c, 0, 0, X); // 
expected-error{{argument to '__builtin_amdgcn_mfma_f32_32x32x16_f16' must be a 
constant integer}}
 }
+
+void test_mfma_f32_32x32x16_bf16(__global float16* out, bfloat8 a, bfloat8 b, 
float16 c, int X) {
+  *out = __builtin_amdgcn_mfma_f32_32x32x16_bf16(a, b, c, X, 0, 0); // 
expected-error{{argument to '__builtin_amdgcn_mfma_f32_32x32x16_bf16' must be a 
constant integer}}
+  *out = __builtin_amdgcn_mfma_f32_32x32x16_bf16(a, b, c, 0, X, 0);  // 
expected-error{{argument to '__builtin_amdgcn_mfma_f32_32x32x16_bf16' must be a 
constant integer}}
+  *out = __builtin_amdgcn_mfma_f32_32x32x16_bf16(a, b, c, 0, 0, X);  // 
expected-error{{argument to '__builtin_amdgcn_mfma_f32_32x32x16_bf16' must be a 
constant integer}}
+}

diff  --git a/clang/test/SemaOpenCL/builtins-amdgcn-error-gfx950.cl 
b/cla

[clang] [llvm] AMDGPU: Define v_mfma_f32_32x32x16_bf16 for gfx950 (PR #116679)

2024-11-18 Thread Matt Arsenault via cfe-commits

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


[clang] [llvm] AMDGPU: Handle gfx950 global_load_lds_* instructions (PR #116680)

2024-11-18 Thread Matt Arsenault via cfe-commits

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


[clang] [CMake] Update CMake cache file for the ARM/Aarch64 cross toolchain builds. NFC. (PR #116744)

2024-11-18 Thread Vladimir Vereschaka via cfe-commits

https://github.com/vvereschaka created 
https://github.com/llvm/llvm-project/pull/116744

Forcely disable the libc++ benchmarks on Windows build hosts. The benchmark 
configuration currently does not support the cross builds on Windows hosts.

Also removed unnecessary `CMAKE_CROSSCOMPILING` CMake option.

>From 9fe3b6d922a72ff8fff4ec24bbc1b4b45e2130e8 Mon Sep 17 00:00:00 2001
From: Vladimir Vereschaka 
Date: Mon, 18 Nov 2024 21:41:57 -0800
Subject: [PATCH] [CMake] Update CMake cache file for the ARM/Aarch64 cross
 toolchain builds. NFC.

Forcly disable the libc++ benchmarks on Windows build hosts. The benchmark 
configuration
currently does not support the cross builds on Windows hosts.
---
 clang/cmake/caches/CrossWinToARMLinux.cmake | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/clang/cmake/caches/CrossWinToARMLinux.cmake 
b/clang/cmake/caches/CrossWinToARMLinux.cmake
index 87118bbd33377d..64f9ae296ae51e 100644
--- a/clang/cmake/caches/CrossWinToARMLinux.cmake
+++ b/clang/cmake/caches/CrossWinToARMLinux.cmake
@@ -119,7 +119,6 @@ if (NOT DEFINED CMAKE_BUILD_TYPE)
   set(CMAKE_BUILD_TYPE "Release" CACHE STRING "")
 endif()
 
-set(CMAKE_CROSSCOMPILINGON CACHE BOOL "")
 set(CMAKE_CL_SHOWINCLUDES_PREFIX"Note: including file: " CACHE 
STRING "")
 # Required if COMPILER_RT_DEFAULT_TARGET_ONLY is ON
 set(CMAKE_C_COMPILER_TARGET "${TOOLCHAIN_TARGET_TRIPLE}" CACHE 
STRING "")
@@ -219,6 +218,11 @@ set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_CXX_ABI
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS   
   ON CACHE BOOL "")
 # Merge libc++ and libc++abi libraries into the single libc++ library file.
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ENABLE_STATIC_ABI_LIBRARY   
   ON CACHE BOOL "")
+# Forcly disable the libc++ benchmarks on Windows build hosts
+# (currently the benchmark test configuration does not support the cross 
builds there).
+if (WIN32)
+  set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_INCLUDE_BENCHMARKS
   OFF CACHE BOOL "")
+endif(WIN32)
 
 # Avoid searching for the python3 interpreter during the runtimes 
configuration for the cross builds.
 # It starts searching the python3 package using the target's sysroot path, 
that usually is not compatible with the build host.

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


[clang] [CMake] Update CMake cache file for the ARM/Aarch64 cross toolchain builds. NFC. (PR #116744)

2024-11-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Vladimir Vereschaka (vvereschaka)


Changes

Forcely disable the libc++ benchmarks on Windows build hosts. The benchmark 
configuration currently does not support the cross builds on Windows hosts.

Also removed unnecessary `CMAKE_CROSSCOMPILING` CMake option.

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


1 Files Affected:

- (modified) clang/cmake/caches/CrossWinToARMLinux.cmake (+5-1) 


``diff
diff --git a/clang/cmake/caches/CrossWinToARMLinux.cmake 
b/clang/cmake/caches/CrossWinToARMLinux.cmake
index 87118bbd33377d..64f9ae296ae51e 100644
--- a/clang/cmake/caches/CrossWinToARMLinux.cmake
+++ b/clang/cmake/caches/CrossWinToARMLinux.cmake
@@ -119,7 +119,6 @@ if (NOT DEFINED CMAKE_BUILD_TYPE)
   set(CMAKE_BUILD_TYPE "Release" CACHE STRING "")
 endif()
 
-set(CMAKE_CROSSCOMPILINGON CACHE BOOL "")
 set(CMAKE_CL_SHOWINCLUDES_PREFIX"Note: including file: " CACHE 
STRING "")
 # Required if COMPILER_RT_DEFAULT_TARGET_ONLY is ON
 set(CMAKE_C_COMPILER_TARGET "${TOOLCHAIN_TARGET_TRIPLE}" CACHE 
STRING "")
@@ -219,6 +218,11 @@ set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_CXX_ABI
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS   
   ON CACHE BOOL "")
 # Merge libc++ and libc++abi libraries into the single libc++ library file.
 set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_ENABLE_STATIC_ABI_LIBRARY   
   ON CACHE BOOL "")
+# Forcly disable the libc++ benchmarks on Windows build hosts
+# (currently the benchmark test configuration does not support the cross 
builds there).
+if (WIN32)
+  set(RUNTIMES_${TOOLCHAIN_TARGET_TRIPLE}_LIBCXX_INCLUDE_BENCHMARKS
   OFF CACHE BOOL "")
+endif(WIN32)
 
 # Avoid searching for the python3 interpreter during the runtimes 
configuration for the cross builds.
 # It starts searching the python3 package using the target's sysroot path, 
that usually is not compatible with the build host.

``




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


[clang] [llvm] AMDGPU: Define v_mfma_f32_32x32x16_bf16 for gfx950 (PR #116679)

2024-11-18 Thread Matt Arsenault via cfe-commits

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


[clang] [llvm] AMDGPU: Define v_mfma_f32_32x32x16_bf16 for gfx950 (PR #116679)

2024-11-18 Thread Matt Arsenault via cfe-commits

https://github.com/arsenm updated 
https://github.com/llvm/llvm-project/pull/116679

>From 05a1cf72c9ee13af0a8c33294401a77827a86b1f Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Tue, 19 Dec 2023 12:46:00 +0700
Subject: [PATCH] AMDGPU: Define v_mfma_f32_32x32x16_bf16 for gfx950

Unlike the existing gfx940 intrinsics using short/i16 in place of
bfloat, this uses the natural bfloat type.
---
 clang/include/clang/Basic/BuiltinsAMDGPU.def  |   2 +
 .../CodeGenOpenCL/builtins-amdgcn-mfma.cl |   6 +
 .../builtins-amdgcn-error-gfx950-param.cl |   7 +
 .../builtins-amdgcn-error-gfx950.cl   |   5 +-
 llvm/include/llvm/IR/IntrinsicsAMDGPU.td  |   2 +
 llvm/lib/Target/AMDGPU/SIInstrInfo.td |   1 +
 llvm/lib/Target/AMDGPU/VOP3PInstructions.td   |   6 +
 .../UniformityAnalysis/AMDGPU/intrinsics.ll   |   8 +
 .../AMDGPU/llvm.amdgcn.mfma.gfx950.bf16.ll| 474 ++
 llvm/test/MC/AMDGPU/mai-gfx950.s  |  56 ++-
 .../MC/Disassembler/AMDGPU/gfx950_mai.txt |  27 +
 llvm/test/tools/llvm-mca/AMDGPU/gfx950.s  |  10 +-
 12 files changed, 596 insertions(+), 8 deletions(-)
 create mode 100644 llvm/test/CodeGen/AMDGPU/llvm.amdgcn.mfma.gfx950.bf16.ll

diff --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def 
b/clang/include/clang/Basic/BuiltinsAMDGPU.def
index 6917d8d1aca69d..7ce8f2c1669d67 100644
--- a/clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -437,6 +437,8 @@ TARGET_BUILTIN(__builtin_amdgcn_cvt_sr_fp8_f32, "ifiiIi", 
"nc", "fp8-conversion-
 TARGET_BUILTIN(__builtin_amdgcn_mfma_f32_16x16x32_f16, "V4fV8hV8hV4fIiIiIi", 
"nc", "gfx950-insts")
 TARGET_BUILTIN(__builtin_amdgcn_mfma_f32_32x32x16_f16, "V16fV8hV8hV16fIiIiIi", 
"nc", "gfx950-insts")
 
+TARGET_BUILTIN(__builtin_amdgcn_mfma_f32_32x32x16_bf16, 
"V16fV8yV8yV16fIiIiIi", "nc", "gfx950-insts")
+
 
//===--===//
 // GFX12+ only builtins.
 
//===--===//
diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-mfma.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-mfma.cl
index a644a60f9ec381..841d8fcad0fee0 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn-mfma.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-mfma.cl
@@ -24,6 +24,7 @@ typedef short  v8s   __attribute__((ext_vector_type(8)));
 typedef short  v16s  __attribute__((ext_vector_type(16)));
 typedef short  v32s  __attribute__((ext_vector_type(32)));
 typedef double v4d   __attribute__((ext_vector_type(4)));
+typedef __bf16 v8bf16   __attribute__((ext_vector_type(8)));
 
 
 #ifdef MFMA_GFX908_TESTS
@@ -424,5 +425,10 @@ v16f test_mfma_f32_32x32x16_f16(v8h a, v8h b, v16f c)
   return __builtin_amdgcn_mfma_f32_32x32x16_f16(a, b, c, 1, 2, 3);
 }
 
+// CHECK-GFX950-LABEL: @test_mfma_f32_32x32x16_bf16(
+// CHECK-GFX950: tail call <16 x float> @llvm.amdgcn.mfma.f32.32x32x16.bf16(<8 
x bfloat> %a, <8 x bfloat> %b, <16 x float> %c, i32 1, i32 2, i32 3)
+v16f test_mfma_f32_32x32x16_bf16(v8bf16 a, v8bf16 b, v16f c) {
+  return __builtin_amdgcn_mfma_f32_32x32x16_bf16(a, b, c, 1, 2, 3);
+}
 
 #endif
diff --git a/clang/test/SemaOpenCL/builtins-amdgcn-error-gfx950-param.cl 
b/clang/test/SemaOpenCL/builtins-amdgcn-error-gfx950-param.cl
index 4c267e2cac5cad..4af67763c40dd2 100644
--- a/clang/test/SemaOpenCL/builtins-amdgcn-error-gfx950-param.cl
+++ b/clang/test/SemaOpenCL/builtins-amdgcn-error-gfx950-param.cl
@@ -4,6 +4,7 @@
 typedef float float4 __attribute__((ext_vector_type(4)));
 typedef float float16 __attribute__((ext_vector_type(16)));
 typedef half half8 __attribute__((ext_vector_type(8)));
+typedef __bf16 bfloat8 __attribute__((ext_vector_type(8)));
 
 
 void test_mfma_f32_16x16x32_f16(__global float4* out, half8 a, half8 b, float4 
c, int X) {
@@ -19,3 +20,9 @@ void test_mfma_f32_32x32x16_f16(__global float16* out, half8 
a, half8 b, float16
   *out = __builtin_amdgcn_mfma_f32_32x32x16_f16(a, b, c, 0, X, 0); // 
expected-error{{argument to '__builtin_amdgcn_mfma_f32_32x32x16_f16' must be a 
constant integer}}
   *out = __builtin_amdgcn_mfma_f32_32x32x16_f16(a, b, c, 0, 0, X); // 
expected-error{{argument to '__builtin_amdgcn_mfma_f32_32x32x16_f16' must be a 
constant integer}}
 }
+
+void test_mfma_f32_32x32x16_bf16(__global float16* out, bfloat8 a, bfloat8 b, 
float16 c, int X) {
+  *out = __builtin_amdgcn_mfma_f32_32x32x16_bf16(a, b, c, X, 0, 0); // 
expected-error{{argument to '__builtin_amdgcn_mfma_f32_32x32x16_bf16' must be a 
constant integer}}
+  *out = __builtin_amdgcn_mfma_f32_32x32x16_bf16(a, b, c, 0, X, 0);  // 
expected-error{{argument to '__builtin_amdgcn_mfma_f32_32x32x16_bf16' must be a 
constant integer}}
+  *out = __builtin_amdgcn_mfma_f32_32x32x16_bf16(a, b, c, 0, 0, X);  // 
expected-error{{argument to '__builtin_amdgcn_mfma_f32_32x32x16_bf16' must be a 
constant integer}}
+}
diff --git a/clang/test/SemaOpenCL/builtins-amdgcn-error-gfx950.cl 
b/clang/test/S

[clang] [PAC][clang] Add signed GOT cc1 flag (PR #96160)

2024-11-18 Thread Daniil Kovalev via cfe-commits

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


[clang] [llvm] [RISCV] Support `svukte` extension (PR #115657)

2024-11-18 Thread Craig Topper via cfe-commits


@@ -158,6 +158,7 @@ on support follow.
  ``Svinval``   Assembly Support
  ``Svnapot``   Assembly Support
  ``Svpbmt``Supported
+ ``Svukte``Supported

topperc wrote:

It has to be experimental until ratified. The ratification process can still 
change a frozen spec.

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


[clang] [PAC][clang] Add signed GOT cc1 flag (PR #96160)

2024-11-18 Thread Daniil Kovalev via cfe-commits

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


[clang] 3b162f7 - [PAC][clang] Add signed GOT cc1 flag (#96160)

2024-11-18 Thread via cfe-commits

Author: Daniil Kovalev
Date: 2024-11-19T10:20:15+03:00
New Revision: 3b162f73d8027dcd8261666a40e9bdfb40f4dacc

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

LOG: [PAC][clang] Add signed GOT cc1 flag (#96160)

Add `-fptrauth-elf-got` clang cc1 flag and set `ptrauth_elf_got`
preprocessor feature and `PointerAuthELFGOT` LangOption correspondingly.
No additional checks like ensuring OS binary format is ELF are
performed: it should be done on clang driver level when a pauth-enabled
environment implying signed GOT enabled is requested.

If the cc1 flag is passed, "ptrauth-elf-got" IR module flag is set.

Added: 
clang/test/CodeGen/ptrauth-module-flags.c

Modified: 
clang/include/clang/Basic/Features.def
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/CodeGen/AArch64/elf-pauthabi.c
clang/test/Preprocessor/ptrauth_feature.c

Removed: 




diff  --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index 7f5d26118bdc71..9088c867d53ce4 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -116,6 +116,7 @@ FEATURE(ptrauth_function_pointer_type_discrimination, 
LangOpts.PointerAuthFuncti
 FEATURE(ptrauth_indirect_gotos, LangOpts.PointerAuthIndirectGotos)
 FEATURE(ptrauth_init_fini, LangOpts.PointerAuthInitFini)
 FEATURE(ptrauth_init_fini_address_discrimination, 
LangOpts.PointerAuthInitFiniAddressDiscrimination)
+FEATURE(ptrauth_elf_got, LangOpts.PointerAuthELFGOT)
 EXTENSION(swiftcc,
   PP.getTargetInfo().checkCallingConvention(CC_Swift) ==
   clang::TargetInfo::CCCR_OK)

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d7230dd7272fd6..f2f9c20c9bc264 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4356,6 +4356,7 @@ defm ptrauth_indirect_gotos : 
OptInCC1FFlag<"ptrauth-indirect-gotos",
 defm ptrauth_init_fini : OptInCC1FFlag<"ptrauth-init-fini", "Enable signing of 
function pointers in init/fini arrays">;
 defm ptrauth_init_fini_address_discrimination : 
OptInCC1FFlag<"ptrauth-init-fini-address-discrimination",
   "Enable address discrimination of function pointers in init/fini arrays">;
+defm ptrauth_elf_got : OptInCC1FFlag<"ptrauth-elf-got", "Enable authentication 
of pointers from GOT (ELF only)">;
 }
 
 def fenable_matrix : Flag<["-"], "fenable-matrix">, Group,

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 508f53482d4e1f..4f456981cf0de8 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1213,6 +1213,9 @@ void CodeGenModule::Release() {
   getModule().addModuleFlag(llvm::Module::Min,
 "sign-return-address-with-bkey", 1);
 
+if (LangOpts.PointerAuthELFGOT)
+  getModule().addModuleFlag(llvm::Module::Min, "ptrauth-elf-got", 1);
+
 if (getTriple().isOSLinux()) {
   assert(getTriple().isOSBinFormatELF());
   using namespace llvm::ELF;

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index e3145dcacf58d1..3dd94c31b2bc7a 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -3452,6 +3452,8 @@ static void GeneratePointerAuthArgs(const LangOptions 
&Opts,
 GenerateArg(Consumer, OPT_fptrauth_init_fini);
   if (Opts.PointerAuthInitFiniAddressDiscrimination)
 GenerateArg(Consumer, OPT_fptrauth_init_fini_address_discrimination);
+  if (Opts.PointerAuthELFGOT)
+GenerateArg(Consumer, OPT_fptrauth_elf_got);
 }
 
 static void ParsePointerAuthArgs(LangOptions &Opts, ArgList &Args,
@@ -3472,6 +3474,7 @@ static void ParsePointerAuthArgs(LangOptions &Opts, 
ArgList &Args,
   Opts.PointerAuthInitFini = Args.hasArg(OPT_fptrauth_init_fini);
   Opts.PointerAuthInitFiniAddressDiscrimination =
   Args.hasArg(OPT_fptrauth_init_fini_address_discrimination);
+  Opts.PointerAuthELFGOT = Args.hasArg(OPT_fptrauth_elf_got);
 }
 
 /// Check if input file kind and language standard are compatible.

diff  --git a/clang/test/CodeGen/AArch64/elf-pauthabi.c 
b/clang/test/CodeGen/AArch64/elf-pauthabi.c
index 023fa8c18e1300..b176f708db85b4 100644
--- a/clang/test/CodeGen/AArch64/elf-pauthabi.c
+++ b/clang/test/CodeGen/AArch64/elf-pauthabi.c
@@ -1,5 +1,3 @@
- TODO: also test with -fptrauth-elf-got when the driver flag is supported
-
 // RUN: %clang_cc1 -triple aarch64-linux -emit-llvm -o - \
 // RUN:   -fptrauth-intrinsics \
 // RUN:   -fptrauth-calls \
@@ -9,6 +7,7 @@
 // RUN:   -fptrauth-vtable-pointer-type-discrimination \
 // RUN:   -fptrauth-init-fini \
 // RUN:   -fptrauth-i

[clang] [clang-repl] Improve flags responsible for generating shared wasm binaries (PR #116735)

2024-11-18 Thread Anutosh Bhat via cfe-commits


@@ -72,13 +72,13 @@ llvm::Error 
WasmIncrementalExecutor::addModule(PartialTranslationUnit &PTU) {
   OutputFile.close();
 
   std::vector LinkerArgs = {"wasm-ld",
-  "-pie",
+  "-shared",
   "--import-memory",
   "--no-entry",
   "--export-all",
   "--experimental-pic",
-  "--no-export-dynamic",

anutosh491 wrote:

This change has been made cause `-shared` by default invokes `--export-dynamic`.
Not a breaking change that harms us (but surely we would want `shared` instead 
of `pie`) 

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


[clang] [llvm] [RISCV] Support `svukte` extension (PR #115657)

2024-11-18 Thread Brandon Wu via cfe-commits

4vtomat wrote:

> RISCVUsage.rst

Updated!

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


[clang] [HLSL] Add implicit resource element type concepts to AST (PR #116413)

2024-11-18 Thread Joshua Batista via cfe-commits

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


[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-11-18 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,730 @@
+//===-- Mustache.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Support/Mustache.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::json;
+
+namespace llvm {
+namespace mustache {
+namespace {
+
+class Token {
+public:
+  enum class Type {
+Text,
+Variable,
+Partial,
+SectionOpen,
+SectionClose,
+InvertSectionOpen,
+UnescapeVariable,
+Comment,
+  };
+
+  Token(std::string Str);
+
+  Token(std::string RawBody, std::string TokenBody, char Identifier);
+
+  StringRef getTokenBody() const { return TokenBody; };
+
+  StringRef getRawBody() const { return RawBody; };
+
+  void setTokenBody(std::string NewBody) { TokenBody = std::move(NewBody); };
+
+  Accessor getAccessor() const { return Accessor; };
+
+  Type getType() const { return TokenType; };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  size_t getIndentation() const { return Indentation; };
+
+  static Type getTokenType(char Identifier);
+
+private:
+  Type TokenType;
+  // RawBody is the original string that was tokenized
+  std::string RawBody;
+  // TokenBody is the original string with the identifier removed
+  std::string TokenBody;
+  Accessor Accessor;
+  size_t Indentation;
+};
+
+class ASTNode {
+public:
+  enum Type {
+Root,
+Text,
+Partial,
+Variable,
+UnescapeVariable,
+Section,
+InvertSection,
+  };
+
+  ASTNode() : T(Type::Root), ParentContext(nullptr) {};
+
+  ASTNode(StringRef Body, ASTNode *Parent)
+  : T(Type::Text), Body(Body), Parent(Parent), ParentContext(nullptr) {};
+
+  // Constructor for Section/InvertSection/Variable/UnescapeVariable
+  ASTNode(Type T, Accessor Accessor, ASTNode *Parent)
+  : T(T), Parent(Parent), Children({}), Accessor(Accessor),
+ParentContext(nullptr) {};
+
+  void addChild(ASTNode *Child) { Children.emplace_back(Child); };
+
+  void setRawBody(std::string NewBody) { RawBody = std::move(NewBody); };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  void render(const llvm::json::Value &Data, llvm::raw_ostream &OS);
+
+  void setUpNode(llvm::BumpPtrAllocator &Alloc, StringMap &Partials,
+ StringMap &Lambdas,
+ StringMap &SectionLambdas,
+ DenseMap &Escapes);
+
+private:
+  void renderLambdas(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ Lambda &L);
+
+  void renderSectionLambdas(const llvm::json::Value &Contexts,
+llvm::raw_ostream &OS, SectionLambda &L);
+
+  void renderPartial(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ ASTNode *Partial);
+
+  void renderChild(const llvm::json::Value &Context, llvm::raw_ostream &OS);
+
+  const llvm::json::Value *findContext();
+
+  llvm::BumpPtrAllocator *Allocator;
+  StringMap *Partials;
+  StringMap *Lambdas;
+  StringMap *SectionLambdas;
+  DenseMap *Escapes;
+  Type T;
+  size_t Indentation = 0;
+  std::string RawBody;
+  std::string Body;
+  ASTNode *Parent;
+  // TODO: switch implementation to SmallVector
+  std::vector Children;
+  const Accessor Accessor;
+  const llvm::json::Value *ParentContext;
+};
+
+// Custom stream to escape strings
+class EscapeStringStream : public raw_ostream {
+public:
+  explicit EscapeStringStream(llvm::raw_ostream &WrappedStream,
+  DenseMap &Escape)
+  : Escape(Escape), WrappedStream(WrappedStream) {
+SetUnbuffered();
+  }
+
+protected:
+  void write_impl(const char *Ptr, size_t Size) override {
+llvm::StringRef Data(Ptr, Size);
+for (char C : Data) {
+  auto It = Escape.find(C);
+  if (It != Escape.end())
+WrappedStream << It->getSecond();
+  else
+WrappedStream << C;
+}
+  }
+
+  uint64_t current_pos() const override { return WrappedStream.tell(); }
+
+private:
+  DenseMap &Escape;
+  llvm::raw_ostream &WrappedStream;
+};
+
+// Custom stream to add indentation used to for rendering partials
+class AddIndentationStringStream : public raw_ostream {
+public:
+  explicit AddIndentationStringStream(llvm::raw_ostream &WrappedStream,
+  size_t Indentation)
+  : Indentation(Indentation), WrappedStream(WrappedStream) {
+SetUnbuffered();
+  }
+
+protected:
+  void write_impl(const char *Ptr, size_t Size) override {
+llvm::StringRef Data(Ptr, Size);
+std::string Indent(Indentation, ' ');
+for (char C : Data) {
+  WrappedStream << C;
+  if (C == '\n')
+WrappedSt

[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-11-18 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,730 @@
+//===-- Mustache.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Support/Mustache.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::json;
+
+namespace llvm {
+namespace mustache {
+namespace {
+
+class Token {
+public:
+  enum class Type {
+Text,
+Variable,
+Partial,
+SectionOpen,
+SectionClose,
+InvertSectionOpen,
+UnescapeVariable,
+Comment,
+  };
+
+  Token(std::string Str);
+
+  Token(std::string RawBody, std::string TokenBody, char Identifier);
+
+  StringRef getTokenBody() const { return TokenBody; };
+
+  StringRef getRawBody() const { return RawBody; };
+
+  void setTokenBody(std::string NewBody) { TokenBody = std::move(NewBody); };
+
+  Accessor getAccessor() const { return Accessor; };
+
+  Type getType() const { return TokenType; };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  size_t getIndentation() const { return Indentation; };
+
+  static Type getTokenType(char Identifier);
+
+private:
+  Type TokenType;
+  // RawBody is the original string that was tokenized
+  std::string RawBody;
+  // TokenBody is the original string with the identifier removed
+  std::string TokenBody;
+  Accessor Accessor;
+  size_t Indentation;
+};
+
+class ASTNode {
+public:
+  enum Type {
+Root,
+Text,
+Partial,
+Variable,
+UnescapeVariable,
+Section,
+InvertSection,
+  };
+
+  ASTNode() : T(Type::Root), ParentContext(nullptr) {};
+
+  ASTNode(StringRef Body, ASTNode *Parent)
+  : T(Type::Text), Body(Body), Parent(Parent), ParentContext(nullptr) {};
+
+  // Constructor for Section/InvertSection/Variable/UnescapeVariable
+  ASTNode(Type T, Accessor Accessor, ASTNode *Parent)
+  : T(T), Parent(Parent), Children({}), Accessor(Accessor),
+ParentContext(nullptr) {};
+
+  void addChild(ASTNode *Child) { Children.emplace_back(Child); };
+
+  void setRawBody(std::string NewBody) { RawBody = std::move(NewBody); };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  void render(const llvm::json::Value &Data, llvm::raw_ostream &OS);
+
+  void setUpNode(llvm::BumpPtrAllocator &Alloc, StringMap &Partials,
+ StringMap &Lambdas,
+ StringMap &SectionLambdas,
+ DenseMap &Escapes);
+
+private:
+  void renderLambdas(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ Lambda &L);
+
+  void renderSectionLambdas(const llvm::json::Value &Contexts,
+llvm::raw_ostream &OS, SectionLambda &L);
+
+  void renderPartial(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ ASTNode *Partial);
+
+  void renderChild(const llvm::json::Value &Context, llvm::raw_ostream &OS);
+
+  const llvm::json::Value *findContext();
+
+  llvm::BumpPtrAllocator *Allocator;
+  StringMap *Partials;
+  StringMap *Lambdas;
+  StringMap *SectionLambdas;
+  DenseMap *Escapes;
+  Type T;
+  size_t Indentation = 0;
+  std::string RawBody;
+  std::string Body;
+  ASTNode *Parent;
+  // TODO: switch implementation to SmallVector
+  std::vector Children;
+  const Accessor Accessor;
+  const llvm::json::Value *ParentContext;
+};
+
+// Custom stream to escape strings
+class EscapeStringStream : public raw_ostream {
+public:
+  explicit EscapeStringStream(llvm::raw_ostream &WrappedStream,
+  DenseMap &Escape)
+  : Escape(Escape), WrappedStream(WrappedStream) {
+SetUnbuffered();
+  }
+
+protected:
+  void write_impl(const char *Ptr, size_t Size) override {
+llvm::StringRef Data(Ptr, Size);
+for (char C : Data) {
+  auto It = Escape.find(C);
+  if (It != Escape.end())
+WrappedStream << It->getSecond();
+  else
+WrappedStream << C;
+}
+  }
+
+  uint64_t current_pos() const override { return WrappedStream.tell(); }
+
+private:
+  DenseMap &Escape;
+  llvm::raw_ostream &WrappedStream;
+};
+
+// Custom stream to add indentation used to for rendering partials
+class AddIndentationStringStream : public raw_ostream {
+public:
+  explicit AddIndentationStringStream(llvm::raw_ostream &WrappedStream,
+  size_t Indentation)
+  : Indentation(Indentation), WrappedStream(WrappedStream) {
+SetUnbuffered();
+  }
+
+protected:
+  void write_impl(const char *Ptr, size_t Size) override {
+llvm::StringRef Data(Ptr, Size);
+std::string Indent(Indentation, ' ');
+for (char C : Data) {
+  WrappedStream << C;
+  if (C == '\n')
+WrappedSt

[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-11-18 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,730 @@
+//===-- Mustache.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Support/Mustache.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::json;
+
+namespace llvm {
+namespace mustache {
+namespace {
+
+class Token {
+public:
+  enum class Type {
+Text,
+Variable,
+Partial,
+SectionOpen,
+SectionClose,
+InvertSectionOpen,
+UnescapeVariable,
+Comment,
+  };
+
+  Token(std::string Str);
+
+  Token(std::string RawBody, std::string TokenBody, char Identifier);
+
+  StringRef getTokenBody() const { return TokenBody; };
+
+  StringRef getRawBody() const { return RawBody; };
+
+  void setTokenBody(std::string NewBody) { TokenBody = std::move(NewBody); };
+
+  Accessor getAccessor() const { return Accessor; };
+
+  Type getType() const { return TokenType; };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  size_t getIndentation() const { return Indentation; };
+
+  static Type getTokenType(char Identifier);
+
+private:
+  Type TokenType;
+  // RawBody is the original string that was tokenized
+  std::string RawBody;
+  // TokenBody is the original string with the identifier removed
+  std::string TokenBody;
+  Accessor Accessor;
+  size_t Indentation;
+};
+
+class ASTNode {
+public:
+  enum Type {
+Root,
+Text,
+Partial,
+Variable,
+UnescapeVariable,
+Section,
+InvertSection,
+  };
+
+  ASTNode() : T(Type::Root), ParentContext(nullptr) {};
+
+  ASTNode(StringRef Body, ASTNode *Parent)
+  : T(Type::Text), Body(Body), Parent(Parent), ParentContext(nullptr) {};
+
+  // Constructor for Section/InvertSection/Variable/UnescapeVariable
+  ASTNode(Type T, Accessor Accessor, ASTNode *Parent)
+  : T(T), Parent(Parent), Children({}), Accessor(Accessor),
+ParentContext(nullptr) {};
+
+  void addChild(ASTNode *Child) { Children.emplace_back(Child); };
+
+  void setRawBody(std::string NewBody) { RawBody = std::move(NewBody); };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  void render(const llvm::json::Value &Data, llvm::raw_ostream &OS);
+
+  void setUpNode(llvm::BumpPtrAllocator &Alloc, StringMap &Partials,
+ StringMap &Lambdas,
+ StringMap &SectionLambdas,
+ DenseMap &Escapes);
+
+private:
+  void renderLambdas(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ Lambda &L);
+
+  void renderSectionLambdas(const llvm::json::Value &Contexts,
+llvm::raw_ostream &OS, SectionLambda &L);
+
+  void renderPartial(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ ASTNode *Partial);
+
+  void renderChild(const llvm::json::Value &Context, llvm::raw_ostream &OS);
+
+  const llvm::json::Value *findContext();
+
+  llvm::BumpPtrAllocator *Allocator;
+  StringMap *Partials;
+  StringMap *Lambdas;
+  StringMap *SectionLambdas;
+  DenseMap *Escapes;
+  Type T;
+  size_t Indentation = 0;
+  std::string RawBody;
+  std::string Body;
+  ASTNode *Parent;
+  // TODO: switch implementation to SmallVector
+  std::vector Children;
+  const Accessor Accessor;
+  const llvm::json::Value *ParentContext;
+};
+
+// Custom stream to escape strings
+class EscapeStringStream : public raw_ostream {
+public:
+  explicit EscapeStringStream(llvm::raw_ostream &WrappedStream,
+  DenseMap &Escape)
+  : Escape(Escape), WrappedStream(WrappedStream) {
+SetUnbuffered();
+  }
+
+protected:
+  void write_impl(const char *Ptr, size_t Size) override {
+llvm::StringRef Data(Ptr, Size);
+for (char C : Data) {
+  auto It = Escape.find(C);
+  if (It != Escape.end())
+WrappedStream << It->getSecond();
+  else
+WrappedStream << C;
+}
+  }
+
+  uint64_t current_pos() const override { return WrappedStream.tell(); }
+
+private:
+  DenseMap &Escape;
+  llvm::raw_ostream &WrappedStream;
+};
+
+// Custom stream to add indentation used to for rendering partials
+class AddIndentationStringStream : public raw_ostream {
+public:
+  explicit AddIndentationStringStream(llvm::raw_ostream &WrappedStream,
+  size_t Indentation)
+  : Indentation(Indentation), WrappedStream(WrappedStream) {
+SetUnbuffered();
+  }
+
+protected:
+  void write_impl(const char *Ptr, size_t Size) override {
+llvm::StringRef Data(Ptr, Size);
+std::string Indent(Indentation, ' ');
+for (char C : Data) {
+  WrappedStream << C;
+  if (C == '\n')
+WrappedSt

[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-11-18 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,730 @@
+//===-- Mustache.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Support/Mustache.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::json;
+
+namespace llvm {
+namespace mustache {
+namespace {
+
+class Token {
+public:
+  enum class Type {
+Text,
+Variable,
+Partial,
+SectionOpen,
+SectionClose,
+InvertSectionOpen,
+UnescapeVariable,
+Comment,
+  };
+
+  Token(std::string Str);
+
+  Token(std::string RawBody, std::string TokenBody, char Identifier);
+
+  StringRef getTokenBody() const { return TokenBody; };
+
+  StringRef getRawBody() const { return RawBody; };
+
+  void setTokenBody(std::string NewBody) { TokenBody = std::move(NewBody); };
+
+  Accessor getAccessor() const { return Accessor; };
+
+  Type getType() const { return TokenType; };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  size_t getIndentation() const { return Indentation; };
+
+  static Type getTokenType(char Identifier);
+
+private:
+  Type TokenType;
+  // RawBody is the original string that was tokenized
+  std::string RawBody;
+  // TokenBody is the original string with the identifier removed
+  std::string TokenBody;
+  Accessor Accessor;
+  size_t Indentation;
+};
+
+class ASTNode {
+public:
+  enum Type {
+Root,
+Text,
+Partial,
+Variable,
+UnescapeVariable,
+Section,
+InvertSection,
+  };
+
+  ASTNode() : T(Type::Root), ParentContext(nullptr) {};
+
+  ASTNode(StringRef Body, ASTNode *Parent)
+  : T(Type::Text), Body(Body), Parent(Parent), ParentContext(nullptr) {};
+
+  // Constructor for Section/InvertSection/Variable/UnescapeVariable
+  ASTNode(Type T, Accessor Accessor, ASTNode *Parent)
+  : T(T), Parent(Parent), Children({}), Accessor(Accessor),
+ParentContext(nullptr) {};
+
+  void addChild(ASTNode *Child) { Children.emplace_back(Child); };
+
+  void setRawBody(std::string NewBody) { RawBody = std::move(NewBody); };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  void render(const llvm::json::Value &Data, llvm::raw_ostream &OS);
+
+  void setUpNode(llvm::BumpPtrAllocator &Alloc, StringMap &Partials,
+ StringMap &Lambdas,
+ StringMap &SectionLambdas,
+ DenseMap &Escapes);
+
+private:
+  void renderLambdas(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ Lambda &L);
+
+  void renderSectionLambdas(const llvm::json::Value &Contexts,
+llvm::raw_ostream &OS, SectionLambda &L);
+
+  void renderPartial(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ ASTNode *Partial);
+
+  void renderChild(const llvm::json::Value &Context, llvm::raw_ostream &OS);
+
+  const llvm::json::Value *findContext();
+
+  llvm::BumpPtrAllocator *Allocator;
+  StringMap *Partials;
+  StringMap *Lambdas;
+  StringMap *SectionLambdas;
+  DenseMap *Escapes;
+  Type T;
+  size_t Indentation = 0;
+  std::string RawBody;
+  std::string Body;
+  ASTNode *Parent;
+  // TODO: switch implementation to SmallVector
+  std::vector Children;
+  const Accessor Accessor;
+  const llvm::json::Value *ParentContext;
+};
+
+// Custom stream to escape strings
+class EscapeStringStream : public raw_ostream {
+public:
+  explicit EscapeStringStream(llvm::raw_ostream &WrappedStream,
+  DenseMap &Escape)
+  : Escape(Escape), WrappedStream(WrappedStream) {
+SetUnbuffered();
+  }
+
+protected:
+  void write_impl(const char *Ptr, size_t Size) override {
+llvm::StringRef Data(Ptr, Size);
+for (char C : Data) {
+  auto It = Escape.find(C);
+  if (It != Escape.end())
+WrappedStream << It->getSecond();
+  else
+WrappedStream << C;
+}
+  }
+
+  uint64_t current_pos() const override { return WrappedStream.tell(); }
+
+private:
+  DenseMap &Escape;
+  llvm::raw_ostream &WrappedStream;
+};
+
+// Custom stream to add indentation used to for rendering partials

ilovepi wrote:

```suggestion
// Custom stream to add indentation used to for rendering partials.
```

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


[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-11-18 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,730 @@
+//===-- Mustache.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Support/Mustache.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::json;
+
+namespace llvm {
+namespace mustache {
+namespace {
+
+class Token {
+public:
+  enum class Type {
+Text,
+Variable,
+Partial,
+SectionOpen,
+SectionClose,
+InvertSectionOpen,
+UnescapeVariable,
+Comment,
+  };
+
+  Token(std::string Str);
+
+  Token(std::string RawBody, std::string TokenBody, char Identifier);
+
+  StringRef getTokenBody() const { return TokenBody; };
+
+  StringRef getRawBody() const { return RawBody; };
+
+  void setTokenBody(std::string NewBody) { TokenBody = std::move(NewBody); };
+
+  Accessor getAccessor() const { return Accessor; };
+
+  Type getType() const { return TokenType; };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  size_t getIndentation() const { return Indentation; };
+
+  static Type getTokenType(char Identifier);
+
+private:
+  Type TokenType;
+  // RawBody is the original string that was tokenized
+  std::string RawBody;
+  // TokenBody is the original string with the identifier removed
+  std::string TokenBody;
+  Accessor Accessor;
+  size_t Indentation;
+};
+
+class ASTNode {
+public:
+  enum Type {
+Root,
+Text,
+Partial,
+Variable,
+UnescapeVariable,
+Section,
+InvertSection,
+  };
+
+  ASTNode() : T(Type::Root), ParentContext(nullptr) {};
+
+  ASTNode(StringRef Body, ASTNode *Parent)
+  : T(Type::Text), Body(Body), Parent(Parent), ParentContext(nullptr) {};
+
+  // Constructor for Section/InvertSection/Variable/UnescapeVariable
+  ASTNode(Type T, Accessor Accessor, ASTNode *Parent)
+  : T(T), Parent(Parent), Children({}), Accessor(Accessor),
+ParentContext(nullptr) {};
+
+  void addChild(ASTNode *Child) { Children.emplace_back(Child); };
+
+  void setRawBody(std::string NewBody) { RawBody = std::move(NewBody); };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  void render(const llvm::json::Value &Data, llvm::raw_ostream &OS);
+
+  void setUpNode(llvm::BumpPtrAllocator &Alloc, StringMap &Partials,
+ StringMap &Lambdas,
+ StringMap &SectionLambdas,
+ DenseMap &Escapes);
+
+private:
+  void renderLambdas(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ Lambda &L);
+
+  void renderSectionLambdas(const llvm::json::Value &Contexts,
+llvm::raw_ostream &OS, SectionLambda &L);
+
+  void renderPartial(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ ASTNode *Partial);
+
+  void renderChild(const llvm::json::Value &Context, llvm::raw_ostream &OS);
+
+  const llvm::json::Value *findContext();
+
+  llvm::BumpPtrAllocator *Allocator;
+  StringMap *Partials;
+  StringMap *Lambdas;
+  StringMap *SectionLambdas;
+  DenseMap *Escapes;
+  Type T;
+  size_t Indentation = 0;
+  std::string RawBody;
+  std::string Body;
+  ASTNode *Parent;
+  // TODO: switch implementation to SmallVector
+  std::vector Children;
+  const Accessor Accessor;
+  const llvm::json::Value *ParentContext;
+};
+
+// Custom stream to escape strings
+class EscapeStringStream : public raw_ostream {
+public:
+  explicit EscapeStringStream(llvm::raw_ostream &WrappedStream,
+  DenseMap &Escape)
+  : Escape(Escape), WrappedStream(WrappedStream) {
+SetUnbuffered();
+  }
+
+protected:
+  void write_impl(const char *Ptr, size_t Size) override {
+llvm::StringRef Data(Ptr, Size);
+for (char C : Data) {
+  auto It = Escape.find(C);
+  if (It != Escape.end())
+WrappedStream << It->getSecond();
+  else
+WrappedStream << C;
+}
+  }
+
+  uint64_t current_pos() const override { return WrappedStream.tell(); }
+
+private:
+  DenseMap &Escape;
+  llvm::raw_ostream &WrappedStream;
+};
+
+// Custom stream to add indentation used to for rendering partials
+class AddIndentationStringStream : public raw_ostream {
+public:
+  explicit AddIndentationStringStream(llvm::raw_ostream &WrappedStream,
+  size_t Indentation)
+  : Indentation(Indentation), WrappedStream(WrappedStream) {
+SetUnbuffered();
+  }
+
+protected:
+  void write_impl(const char *Ptr, size_t Size) override {
+llvm::StringRef Data(Ptr, Size);
+std::string Indent(Indentation, ' ');
+for (char C : Data) {
+  WrappedStream << C;
+  if (C == '\n')
+WrappedSt

[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-11-18 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,730 @@
+//===-- Mustache.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Support/Mustache.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::json;
+
+namespace llvm {
+namespace mustache {
+namespace {
+
+class Token {
+public:
+  enum class Type {
+Text,
+Variable,
+Partial,
+SectionOpen,
+SectionClose,
+InvertSectionOpen,
+UnescapeVariable,
+Comment,
+  };
+
+  Token(std::string Str);
+
+  Token(std::string RawBody, std::string TokenBody, char Identifier);
+
+  StringRef getTokenBody() const { return TokenBody; };
+
+  StringRef getRawBody() const { return RawBody; };
+
+  void setTokenBody(std::string NewBody) { TokenBody = std::move(NewBody); };
+
+  Accessor getAccessor() const { return Accessor; };
+
+  Type getType() const { return TokenType; };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  size_t getIndentation() const { return Indentation; };
+
+  static Type getTokenType(char Identifier);
+
+private:
+  Type TokenType;
+  // RawBody is the original string that was tokenized
+  std::string RawBody;
+  // TokenBody is the original string with the identifier removed
+  std::string TokenBody;
+  Accessor Accessor;
+  size_t Indentation;
+};
+
+class ASTNode {
+public:
+  enum Type {
+Root,
+Text,
+Partial,
+Variable,
+UnescapeVariable,
+Section,
+InvertSection,
+  };
+
+  ASTNode() : T(Type::Root), ParentContext(nullptr) {};
+
+  ASTNode(StringRef Body, ASTNode *Parent)
+  : T(Type::Text), Body(Body), Parent(Parent), ParentContext(nullptr) {};
+
+  // Constructor for Section/InvertSection/Variable/UnescapeVariable
+  ASTNode(Type T, Accessor Accessor, ASTNode *Parent)
+  : T(T), Parent(Parent), Children({}), Accessor(Accessor),
+ParentContext(nullptr) {};
+
+  void addChild(ASTNode *Child) { Children.emplace_back(Child); };
+
+  void setRawBody(std::string NewBody) { RawBody = std::move(NewBody); };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  void render(const llvm::json::Value &Data, llvm::raw_ostream &OS);
+
+  void setUpNode(llvm::BumpPtrAllocator &Alloc, StringMap &Partials,
+ StringMap &Lambdas,
+ StringMap &SectionLambdas,
+ DenseMap &Escapes);
+
+private:
+  void renderLambdas(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ Lambda &L);
+
+  void renderSectionLambdas(const llvm::json::Value &Contexts,
+llvm::raw_ostream &OS, SectionLambda &L);
+
+  void renderPartial(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ ASTNode *Partial);
+
+  void renderChild(const llvm::json::Value &Context, llvm::raw_ostream &OS);
+
+  const llvm::json::Value *findContext();
+
+  llvm::BumpPtrAllocator *Allocator;
+  StringMap *Partials;
+  StringMap *Lambdas;
+  StringMap *SectionLambdas;
+  DenseMap *Escapes;
+  Type T;
+  size_t Indentation = 0;
+  std::string RawBody;
+  std::string Body;
+  ASTNode *Parent;
+  // TODO: switch implementation to SmallVector
+  std::vector Children;
+  const Accessor Accessor;
+  const llvm::json::Value *ParentContext;
+};
+
+// Custom stream to escape strings
+class EscapeStringStream : public raw_ostream {
+public:
+  explicit EscapeStringStream(llvm::raw_ostream &WrappedStream,
+  DenseMap &Escape)
+  : Escape(Escape), WrappedStream(WrappedStream) {
+SetUnbuffered();
+  }
+
+protected:
+  void write_impl(const char *Ptr, size_t Size) override {
+llvm::StringRef Data(Ptr, Size);
+for (char C : Data) {
+  auto It = Escape.find(C);
+  if (It != Escape.end())
+WrappedStream << It->getSecond();
+  else
+WrappedStream << C;
+}
+  }
+
+  uint64_t current_pos() const override { return WrappedStream.tell(); }
+
+private:
+  DenseMap &Escape;
+  llvm::raw_ostream &WrappedStream;
+};
+
+// Custom stream to add indentation used to for rendering partials
+class AddIndentationStringStream : public raw_ostream {
+public:
+  explicit AddIndentationStringStream(llvm::raw_ostream &WrappedStream,
+  size_t Indentation)
+  : Indentation(Indentation), WrappedStream(WrappedStream) {
+SetUnbuffered();
+  }
+
+protected:
+  void write_impl(const char *Ptr, size_t Size) override {
+llvm::StringRef Data(Ptr, Size);
+std::string Indent(Indentation, ' ');
+for (char C : Data) {
+  WrappedStream << C;
+  if (C == '\n')
+WrappedSt

[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-11-18 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,730 @@
+//===-- Mustache.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Support/Mustache.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::json;
+
+namespace llvm {
+namespace mustache {
+namespace {
+
+class Token {
+public:
+  enum class Type {
+Text,
+Variable,
+Partial,
+SectionOpen,
+SectionClose,
+InvertSectionOpen,
+UnescapeVariable,
+Comment,
+  };
+
+  Token(std::string Str);
+
+  Token(std::string RawBody, std::string TokenBody, char Identifier);
+
+  StringRef getTokenBody() const { return TokenBody; };
+
+  StringRef getRawBody() const { return RawBody; };
+
+  void setTokenBody(std::string NewBody) { TokenBody = std::move(NewBody); };
+
+  Accessor getAccessor() const { return Accessor; };
+
+  Type getType() const { return TokenType; };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  size_t getIndentation() const { return Indentation; };
+
+  static Type getTokenType(char Identifier);
+
+private:
+  Type TokenType;
+  // RawBody is the original string that was tokenized
+  std::string RawBody;
+  // TokenBody is the original string with the identifier removed
+  std::string TokenBody;
+  Accessor Accessor;
+  size_t Indentation;
+};
+
+class ASTNode {
+public:
+  enum Type {
+Root,
+Text,
+Partial,
+Variable,
+UnescapeVariable,
+Section,
+InvertSection,
+  };
+
+  ASTNode() : T(Type::Root), ParentContext(nullptr) {};
+
+  ASTNode(StringRef Body, ASTNode *Parent)
+  : T(Type::Text), Body(Body), Parent(Parent), ParentContext(nullptr) {};
+
+  // Constructor for Section/InvertSection/Variable/UnescapeVariable
+  ASTNode(Type T, Accessor Accessor, ASTNode *Parent)
+  : T(T), Parent(Parent), Children({}), Accessor(Accessor),
+ParentContext(nullptr) {};
+
+  void addChild(ASTNode *Child) { Children.emplace_back(Child); };
+
+  void setRawBody(std::string NewBody) { RawBody = std::move(NewBody); };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  void render(const llvm::json::Value &Data, llvm::raw_ostream &OS);
+
+  void setUpNode(llvm::BumpPtrAllocator &Alloc, StringMap &Partials,
+ StringMap &Lambdas,
+ StringMap &SectionLambdas,
+ DenseMap &Escapes);
+
+private:
+  void renderLambdas(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ Lambda &L);
+
+  void renderSectionLambdas(const llvm::json::Value &Contexts,
+llvm::raw_ostream &OS, SectionLambda &L);
+
+  void renderPartial(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ ASTNode *Partial);
+
+  void renderChild(const llvm::json::Value &Context, llvm::raw_ostream &OS);
+
+  const llvm::json::Value *findContext();
+
+  llvm::BumpPtrAllocator *Allocator;
+  StringMap *Partials;
+  StringMap *Lambdas;
+  StringMap *SectionLambdas;
+  DenseMap *Escapes;
+  Type T;
+  size_t Indentation = 0;
+  std::string RawBody;
+  std::string Body;
+  ASTNode *Parent;
+  // TODO: switch implementation to SmallVector
+  std::vector Children;
+  const Accessor Accessor;
+  const llvm::json::Value *ParentContext;
+};
+
+// Custom stream to escape strings
+class EscapeStringStream : public raw_ostream {
+public:
+  explicit EscapeStringStream(llvm::raw_ostream &WrappedStream,
+  DenseMap &Escape)
+  : Escape(Escape), WrappedStream(WrappedStream) {
+SetUnbuffered();
+  }
+
+protected:
+  void write_impl(const char *Ptr, size_t Size) override {
+llvm::StringRef Data(Ptr, Size);
+for (char C : Data) {
+  auto It = Escape.find(C);
+  if (It != Escape.end())
+WrappedStream << It->getSecond();
+  else
+WrappedStream << C;
+}
+  }
+
+  uint64_t current_pos() const override { return WrappedStream.tell(); }
+
+private:
+  DenseMap &Escape;
+  llvm::raw_ostream &WrappedStream;
+};
+
+// Custom stream to add indentation used to for rendering partials
+class AddIndentationStringStream : public raw_ostream {
+public:
+  explicit AddIndentationStringStream(llvm::raw_ostream &WrappedStream,
+  size_t Indentation)
+  : Indentation(Indentation), WrappedStream(WrappedStream) {
+SetUnbuffered();
+  }
+
+protected:
+  void write_impl(const char *Ptr, size_t Size) override {
+llvm::StringRef Data(Ptr, Size);
+std::string Indent(Indentation, ' ');
+for (char C : Data) {
+  WrappedStream << C;
+  if (C == '\n')
+WrappedSt

[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-11-18 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,730 @@
+//===-- Mustache.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Support/Mustache.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::json;
+
+namespace llvm {
+namespace mustache {
+namespace {
+
+class Token {
+public:
+  enum class Type {
+Text,
+Variable,
+Partial,
+SectionOpen,
+SectionClose,
+InvertSectionOpen,
+UnescapeVariable,
+Comment,
+  };
+
+  Token(std::string Str);
+
+  Token(std::string RawBody, std::string TokenBody, char Identifier);
+
+  StringRef getTokenBody() const { return TokenBody; };
+
+  StringRef getRawBody() const { return RawBody; };
+
+  void setTokenBody(std::string NewBody) { TokenBody = std::move(NewBody); };
+
+  Accessor getAccessor() const { return Accessor; };
+
+  Type getType() const { return TokenType; };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  size_t getIndentation() const { return Indentation; };
+
+  static Type getTokenType(char Identifier);
+
+private:
+  Type TokenType;
+  // RawBody is the original string that was tokenized
+  std::string RawBody;
+  // TokenBody is the original string with the identifier removed
+  std::string TokenBody;
+  Accessor Accessor;
+  size_t Indentation;
+};
+
+class ASTNode {
+public:
+  enum Type {
+Root,
+Text,
+Partial,
+Variable,
+UnescapeVariable,
+Section,
+InvertSection,
+  };
+
+  ASTNode() : T(Type::Root), ParentContext(nullptr) {};
+
+  ASTNode(StringRef Body, ASTNode *Parent)
+  : T(Type::Text), Body(Body), Parent(Parent), ParentContext(nullptr) {};
+
+  // Constructor for Section/InvertSection/Variable/UnescapeVariable
+  ASTNode(Type T, Accessor Accessor, ASTNode *Parent)
+  : T(T), Parent(Parent), Children({}), Accessor(Accessor),
+ParentContext(nullptr) {};
+
+  void addChild(ASTNode *Child) { Children.emplace_back(Child); };
+
+  void setRawBody(std::string NewBody) { RawBody = std::move(NewBody); };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  void render(const llvm::json::Value &Data, llvm::raw_ostream &OS);
+
+  void setUpNode(llvm::BumpPtrAllocator &Alloc, StringMap &Partials,
+ StringMap &Lambdas,
+ StringMap &SectionLambdas,
+ DenseMap &Escapes);
+
+private:
+  void renderLambdas(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ Lambda &L);
+
+  void renderSectionLambdas(const llvm::json::Value &Contexts,
+llvm::raw_ostream &OS, SectionLambda &L);
+
+  void renderPartial(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ ASTNode *Partial);
+
+  void renderChild(const llvm::json::Value &Context, llvm::raw_ostream &OS);
+
+  const llvm::json::Value *findContext();
+
+  llvm::BumpPtrAllocator *Allocator;
+  StringMap *Partials;
+  StringMap *Lambdas;
+  StringMap *SectionLambdas;
+  DenseMap *Escapes;
+  Type T;
+  size_t Indentation = 0;
+  std::string RawBody;
+  std::string Body;
+  ASTNode *Parent;
+  // TODO: switch implementation to SmallVector
+  std::vector Children;
+  const Accessor Accessor;
+  const llvm::json::Value *ParentContext;
+};
+
+// Custom stream to escape strings
+class EscapeStringStream : public raw_ostream {
+public:
+  explicit EscapeStringStream(llvm::raw_ostream &WrappedStream,
+  DenseMap &Escape)
+  : Escape(Escape), WrappedStream(WrappedStream) {
+SetUnbuffered();
+  }
+
+protected:
+  void write_impl(const char *Ptr, size_t Size) override {
+llvm::StringRef Data(Ptr, Size);
+for (char C : Data) {
+  auto It = Escape.find(C);
+  if (It != Escape.end())
+WrappedStream << It->getSecond();
+  else
+WrappedStream << C;
+}
+  }
+
+  uint64_t current_pos() const override { return WrappedStream.tell(); }
+
+private:
+  DenseMap &Escape;
+  llvm::raw_ostream &WrappedStream;
+};
+
+// Custom stream to add indentation used to for rendering partials
+class AddIndentationStringStream : public raw_ostream {
+public:
+  explicit AddIndentationStringStream(llvm::raw_ostream &WrappedStream,
+  size_t Indentation)
+  : Indentation(Indentation), WrappedStream(WrappedStream) {
+SetUnbuffered();
+  }
+
+protected:
+  void write_impl(const char *Ptr, size_t Size) override {
+llvm::StringRef Data(Ptr, Size);
+std::string Indent(Indentation, ' ');
+for (char C : Data) {
+  WrappedStream << C;
+  if (C == '\n')
+WrappedSt

[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-11-18 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,730 @@
+//===-- Mustache.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Support/Mustache.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::json;
+
+namespace llvm {
+namespace mustache {
+namespace {
+
+class Token {
+public:
+  enum class Type {
+Text,
+Variable,
+Partial,
+SectionOpen,
+SectionClose,
+InvertSectionOpen,
+UnescapeVariable,
+Comment,
+  };
+
+  Token(std::string Str);
+
+  Token(std::string RawBody, std::string TokenBody, char Identifier);
+
+  StringRef getTokenBody() const { return TokenBody; };
+
+  StringRef getRawBody() const { return RawBody; };
+
+  void setTokenBody(std::string NewBody) { TokenBody = std::move(NewBody); };
+
+  Accessor getAccessor() const { return Accessor; };
+
+  Type getType() const { return TokenType; };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  size_t getIndentation() const { return Indentation; };
+
+  static Type getTokenType(char Identifier);
+
+private:
+  Type TokenType;
+  // RawBody is the original string that was tokenized
+  std::string RawBody;
+  // TokenBody is the original string with the identifier removed
+  std::string TokenBody;
+  Accessor Accessor;
+  size_t Indentation;
+};
+
+class ASTNode {
+public:
+  enum Type {
+Root,
+Text,
+Partial,
+Variable,
+UnescapeVariable,
+Section,
+InvertSection,
+  };
+
+  ASTNode() : T(Type::Root), ParentContext(nullptr) {};
+
+  ASTNode(StringRef Body, ASTNode *Parent)
+  : T(Type::Text), Body(Body), Parent(Parent), ParentContext(nullptr) {};
+
+  // Constructor for Section/InvertSection/Variable/UnescapeVariable
+  ASTNode(Type T, Accessor Accessor, ASTNode *Parent)
+  : T(T), Parent(Parent), Children({}), Accessor(Accessor),
+ParentContext(nullptr) {};
+
+  void addChild(ASTNode *Child) { Children.emplace_back(Child); };
+
+  void setRawBody(std::string NewBody) { RawBody = std::move(NewBody); };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  void render(const llvm::json::Value &Data, llvm::raw_ostream &OS);
+
+  void setUpNode(llvm::BumpPtrAllocator &Alloc, StringMap &Partials,
+ StringMap &Lambdas,
+ StringMap &SectionLambdas,
+ DenseMap &Escapes);
+
+private:
+  void renderLambdas(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ Lambda &L);
+
+  void renderSectionLambdas(const llvm::json::Value &Contexts,
+llvm::raw_ostream &OS, SectionLambda &L);
+
+  void renderPartial(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ ASTNode *Partial);
+
+  void renderChild(const llvm::json::Value &Context, llvm::raw_ostream &OS);
+
+  const llvm::json::Value *findContext();
+
+  llvm::BumpPtrAllocator *Allocator;
+  StringMap *Partials;
+  StringMap *Lambdas;
+  StringMap *SectionLambdas;
+  DenseMap *Escapes;
+  Type T;
+  size_t Indentation = 0;
+  std::string RawBody;
+  std::string Body;
+  ASTNode *Parent;
+  // TODO: switch implementation to SmallVector
+  std::vector Children;
+  const Accessor Accessor;
+  const llvm::json::Value *ParentContext;
+};
+
+// Custom stream to escape strings
+class EscapeStringStream : public raw_ostream {
+public:
+  explicit EscapeStringStream(llvm::raw_ostream &WrappedStream,
+  DenseMap &Escape)
+  : Escape(Escape), WrappedStream(WrappedStream) {
+SetUnbuffered();
+  }
+
+protected:
+  void write_impl(const char *Ptr, size_t Size) override {
+llvm::StringRef Data(Ptr, Size);
+for (char C : Data) {
+  auto It = Escape.find(C);
+  if (It != Escape.end())
+WrappedStream << It->getSecond();
+  else
+WrappedStream << C;
+}
+  }
+
+  uint64_t current_pos() const override { return WrappedStream.tell(); }
+
+private:
+  DenseMap &Escape;
+  llvm::raw_ostream &WrappedStream;
+};
+
+// Custom stream to add indentation used to for rendering partials
+class AddIndentationStringStream : public raw_ostream {
+public:
+  explicit AddIndentationStringStream(llvm::raw_ostream &WrappedStream,
+  size_t Indentation)
+  : Indentation(Indentation), WrappedStream(WrappedStream) {
+SetUnbuffered();
+  }
+
+protected:
+  void write_impl(const char *Ptr, size_t Size) override {
+llvm::StringRef Data(Ptr, Size);
+std::string Indent(Indentation, ' ');

ilovepi wrote:

Since this is just used in the stream, and doesn't need to li

[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-11-18 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,730 @@
+//===-- Mustache.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Support/Mustache.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::json;
+
+namespace llvm {
+namespace mustache {
+namespace {
+
+class Token {
+public:
+  enum class Type {
+Text,
+Variable,
+Partial,
+SectionOpen,
+SectionClose,
+InvertSectionOpen,
+UnescapeVariable,
+Comment,
+  };
+
+  Token(std::string Str);
+
+  Token(std::string RawBody, std::string TokenBody, char Identifier);
+
+  StringRef getTokenBody() const { return TokenBody; };
+
+  StringRef getRawBody() const { return RawBody; };
+
+  void setTokenBody(std::string NewBody) { TokenBody = std::move(NewBody); };
+
+  Accessor getAccessor() const { return Accessor; };
+
+  Type getType() const { return TokenType; };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  size_t getIndentation() const { return Indentation; };
+
+  static Type getTokenType(char Identifier);
+
+private:
+  Type TokenType;
+  // RawBody is the original string that was tokenized
+  std::string RawBody;
+  // TokenBody is the original string with the identifier removed
+  std::string TokenBody;
+  Accessor Accessor;
+  size_t Indentation;
+};
+
+class ASTNode {
+public:
+  enum Type {
+Root,
+Text,
+Partial,
+Variable,
+UnescapeVariable,
+Section,
+InvertSection,
+  };
+
+  ASTNode() : T(Type::Root), ParentContext(nullptr) {};
+
+  ASTNode(StringRef Body, ASTNode *Parent)
+  : T(Type::Text), Body(Body), Parent(Parent), ParentContext(nullptr) {};
+
+  // Constructor for Section/InvertSection/Variable/UnescapeVariable
+  ASTNode(Type T, Accessor Accessor, ASTNode *Parent)
+  : T(T), Parent(Parent), Children({}), Accessor(Accessor),
+ParentContext(nullptr) {};
+
+  void addChild(ASTNode *Child) { Children.emplace_back(Child); };
+
+  void setRawBody(std::string NewBody) { RawBody = std::move(NewBody); };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  void render(const llvm::json::Value &Data, llvm::raw_ostream &OS);
+
+  void setUpNode(llvm::BumpPtrAllocator &Alloc, StringMap &Partials,
+ StringMap &Lambdas,
+ StringMap &SectionLambdas,
+ DenseMap &Escapes);
+
+private:
+  void renderLambdas(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ Lambda &L);
+
+  void renderSectionLambdas(const llvm::json::Value &Contexts,
+llvm::raw_ostream &OS, SectionLambda &L);
+
+  void renderPartial(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ ASTNode *Partial);
+
+  void renderChild(const llvm::json::Value &Context, llvm::raw_ostream &OS);
+
+  const llvm::json::Value *findContext();
+
+  llvm::BumpPtrAllocator *Allocator;
+  StringMap *Partials;
+  StringMap *Lambdas;
+  StringMap *SectionLambdas;
+  DenseMap *Escapes;
+  Type T;
+  size_t Indentation = 0;
+  std::string RawBody;
+  std::string Body;
+  ASTNode *Parent;
+  // TODO: switch implementation to SmallVector
+  std::vector Children;
+  const Accessor Accessor;
+  const llvm::json::Value *ParentContext;
+};
+
+// Custom stream to escape strings

ilovepi wrote:

```suggestion
// Custom stream to escape strings.
```

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


[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-11-18 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,730 @@
+//===-- Mustache.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Support/Mustache.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::json;
+
+namespace llvm {
+namespace mustache {
+namespace {
+
+class Token {
+public:
+  enum class Type {
+Text,
+Variable,
+Partial,
+SectionOpen,
+SectionClose,
+InvertSectionOpen,
+UnescapeVariable,
+Comment,
+  };
+
+  Token(std::string Str);
+
+  Token(std::string RawBody, std::string TokenBody, char Identifier);
+
+  StringRef getTokenBody() const { return TokenBody; };
+
+  StringRef getRawBody() const { return RawBody; };
+
+  void setTokenBody(std::string NewBody) { TokenBody = std::move(NewBody); };
+
+  Accessor getAccessor() const { return Accessor; };
+
+  Type getType() const { return TokenType; };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  size_t getIndentation() const { return Indentation; };
+
+  static Type getTokenType(char Identifier);
+
+private:
+  Type TokenType;
+  // RawBody is the original string that was tokenized
+  std::string RawBody;
+  // TokenBody is the original string with the identifier removed
+  std::string TokenBody;
+  Accessor Accessor;
+  size_t Indentation;
+};
+
+class ASTNode {
+public:
+  enum Type {
+Root,
+Text,
+Partial,
+Variable,
+UnescapeVariable,
+Section,
+InvertSection,
+  };
+
+  ASTNode() : T(Type::Root), ParentContext(nullptr) {};
+
+  ASTNode(StringRef Body, ASTNode *Parent)
+  : T(Type::Text), Body(Body), Parent(Parent), ParentContext(nullptr) {};
+
+  // Constructor for Section/InvertSection/Variable/UnescapeVariable

ilovepi wrote:

```suggestion
  // Constructor for Section/InvertSection/Variable/UnescapeVariable.
```

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


[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-11-18 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,730 @@
+//===-- Mustache.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Support/Mustache.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::json;
+
+namespace llvm {
+namespace mustache {
+namespace {
+
+class Token {
+public:
+  enum class Type {
+Text,
+Variable,
+Partial,
+SectionOpen,
+SectionClose,
+InvertSectionOpen,
+UnescapeVariable,
+Comment,
+  };
+
+  Token(std::string Str);
+
+  Token(std::string RawBody, std::string TokenBody, char Identifier);
+
+  StringRef getTokenBody() const { return TokenBody; };
+
+  StringRef getRawBody() const { return RawBody; };
+
+  void setTokenBody(std::string NewBody) { TokenBody = std::move(NewBody); };
+
+  Accessor getAccessor() const { return Accessor; };
+
+  Type getType() const { return TokenType; };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  size_t getIndentation() const { return Indentation; };
+
+  static Type getTokenType(char Identifier);
+
+private:
+  Type TokenType;
+  // RawBody is the original string that was tokenized
+  std::string RawBody;
+  // TokenBody is the original string with the identifier removed
+  std::string TokenBody;
+  Accessor Accessor;
+  size_t Indentation;
+};
+
+class ASTNode {
+public:
+  enum Type {
+Root,
+Text,
+Partial,
+Variable,
+UnescapeVariable,
+Section,
+InvertSection,
+  };
+
+  ASTNode() : T(Type::Root), ParentContext(nullptr) {};
+
+  ASTNode(StringRef Body, ASTNode *Parent)
+  : T(Type::Text), Body(Body), Parent(Parent), ParentContext(nullptr) {};
+
+  // Constructor for Section/InvertSection/Variable/UnescapeVariable
+  ASTNode(Type T, Accessor Accessor, ASTNode *Parent)
+  : T(T), Parent(Parent), Children({}), Accessor(Accessor),
+ParentContext(nullptr) {};
+
+  void addChild(ASTNode *Child) { Children.emplace_back(Child); };
+
+  void setRawBody(std::string NewBody) { RawBody = std::move(NewBody); };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  void render(const llvm::json::Value &Data, llvm::raw_ostream &OS);
+
+  void setUpNode(llvm::BumpPtrAllocator &Alloc, StringMap &Partials,
+ StringMap &Lambdas,
+ StringMap &SectionLambdas,
+ DenseMap &Escapes);
+
+private:
+  void renderLambdas(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ Lambda &L);
+
+  void renderSectionLambdas(const llvm::json::Value &Contexts,
+llvm::raw_ostream &OS, SectionLambda &L);
+
+  void renderPartial(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ ASTNode *Partial);
+
+  void renderChild(const llvm::json::Value &Context, llvm::raw_ostream &OS);
+
+  const llvm::json::Value *findContext();
+
+  llvm::BumpPtrAllocator *Allocator;
+  StringMap *Partials;
+  StringMap *Lambdas;
+  StringMap *SectionLambdas;
+  DenseMap *Escapes;
+  Type T;
+  size_t Indentation = 0;
+  std::string RawBody;
+  std::string Body;
+  ASTNode *Parent;
+  // TODO: switch implementation to SmallVector
+  std::vector Children;
+  const Accessor Accessor;
+  const llvm::json::Value *ParentContext;
+};
+
+// Custom stream to escape strings
+class EscapeStringStream : public raw_ostream {
+public:
+  explicit EscapeStringStream(llvm::raw_ostream &WrappedStream,
+  DenseMap &Escape)
+  : Escape(Escape), WrappedStream(WrappedStream) {
+SetUnbuffered();
+  }
+
+protected:
+  void write_impl(const char *Ptr, size_t Size) override {
+llvm::StringRef Data(Ptr, Size);
+for (char C : Data) {
+  auto It = Escape.find(C);
+  if (It != Escape.end())
+WrappedStream << It->getSecond();
+  else
+WrappedStream << C;
+}
+  }
+
+  uint64_t current_pos() const override { return WrappedStream.tell(); }
+
+private:
+  DenseMap &Escape;
+  llvm::raw_ostream &WrappedStream;
+};
+
+// Custom stream to add indentation used to for rendering partials
+class AddIndentationStringStream : public raw_ostream {
+public:
+  explicit AddIndentationStringStream(llvm::raw_ostream &WrappedStream,
+  size_t Indentation)
+  : Indentation(Indentation), WrappedStream(WrappedStream) {
+SetUnbuffered();
+  }
+
+protected:
+  void write_impl(const char *Ptr, size_t Size) override {
+llvm::StringRef Data(Ptr, Size);
+std::string Indent(Indentation, ' ');
+for (char C : Data) {
+  WrappedStream << C;
+  if (C == '\n')
+WrappedSt

[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-11-18 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,115 @@
+//===--- Mustache.h -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Implementation of the Mustache templating language supports version 1.4.2
+// currently relies on llvm::json::Value for data input
+// see the Mustache spec for more information
+// (https://mustache.github.io/mustache.5.html).

ilovepi wrote:

```suggestion
// Implementation of the Mustache templating language supports version 1.4.2
// currently relies on llvm::json::Value for data input.
// See the Mustache spec for more information
// (https://mustache.github.io/mustache.5.html).
```

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


[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-11-18 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,730 @@
+//===-- Mustache.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Support/Mustache.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::json;
+
+namespace llvm {
+namespace mustache {
+namespace {
+
+class Token {
+public:
+  enum class Type {
+Text,
+Variable,
+Partial,
+SectionOpen,
+SectionClose,
+InvertSectionOpen,
+UnescapeVariable,
+Comment,
+  };
+
+  Token(std::string Str);
+
+  Token(std::string RawBody, std::string TokenBody, char Identifier);
+
+  StringRef getTokenBody() const { return TokenBody; };
+
+  StringRef getRawBody() const { return RawBody; };
+
+  void setTokenBody(std::string NewBody) { TokenBody = std::move(NewBody); };
+
+  Accessor getAccessor() const { return Accessor; };
+
+  Type getType() const { return TokenType; };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  size_t getIndentation() const { return Indentation; };
+
+  static Type getTokenType(char Identifier);
+
+private:
+  Type TokenType;
+  // RawBody is the original string that was tokenized
+  std::string RawBody;
+  // TokenBody is the original string with the identifier removed

ilovepi wrote:

```suggestion
  // RawBody is the original string that was tokenized.
  std::string RawBody;
  // TokenBody is the original string with the identifier removed.
```

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


[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-11-18 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,730 @@
+//===-- Mustache.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Support/Mustache.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::json;
+
+namespace llvm {
+namespace mustache {
+namespace {
+
+class Token {
+public:
+  enum class Type {
+Text,
+Variable,
+Partial,
+SectionOpen,
+SectionClose,
+InvertSectionOpen,
+UnescapeVariable,
+Comment,
+  };
+
+  Token(std::string Str);
+
+  Token(std::string RawBody, std::string TokenBody, char Identifier);
+
+  StringRef getTokenBody() const { return TokenBody; };
+
+  StringRef getRawBody() const { return RawBody; };
+
+  void setTokenBody(std::string NewBody) { TokenBody = std::move(NewBody); };
+
+  Accessor getAccessor() const { return Accessor; };
+
+  Type getType() const { return TokenType; };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  size_t getIndentation() const { return Indentation; };
+
+  static Type getTokenType(char Identifier);
+
+private:
+  Type TokenType;
+  // RawBody is the original string that was tokenized
+  std::string RawBody;
+  // TokenBody is the original string with the identifier removed
+  std::string TokenBody;
+  Accessor Accessor;
+  size_t Indentation;
+};
+
+class ASTNode {
+public:
+  enum Type {
+Root,
+Text,
+Partial,
+Variable,
+UnescapeVariable,
+Section,
+InvertSection,
+  };
+
+  ASTNode() : T(Type::Root), ParentContext(nullptr) {};
+
+  ASTNode(StringRef Body, ASTNode *Parent)
+  : T(Type::Text), Body(Body), Parent(Parent), ParentContext(nullptr) {};
+
+  // Constructor for Section/InvertSection/Variable/UnescapeVariable
+  ASTNode(Type T, Accessor Accessor, ASTNode *Parent)
+  : T(T), Parent(Parent), Children({}), Accessor(Accessor),
+ParentContext(nullptr) {};
+
+  void addChild(ASTNode *Child) { Children.emplace_back(Child); };
+
+  void setRawBody(std::string NewBody) { RawBody = std::move(NewBody); };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  void render(const llvm::json::Value &Data, llvm::raw_ostream &OS);
+
+  void setUpNode(llvm::BumpPtrAllocator &Alloc, StringMap &Partials,
+ StringMap &Lambdas,
+ StringMap &SectionLambdas,
+ DenseMap &Escapes);
+
+private:
+  void renderLambdas(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ Lambda &L);
+
+  void renderSectionLambdas(const llvm::json::Value &Contexts,
+llvm::raw_ostream &OS, SectionLambda &L);
+
+  void renderPartial(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ ASTNode *Partial);
+
+  void renderChild(const llvm::json::Value &Context, llvm::raw_ostream &OS);
+
+  const llvm::json::Value *findContext();
+
+  llvm::BumpPtrAllocator *Allocator;
+  StringMap *Partials;
+  StringMap *Lambdas;
+  StringMap *SectionLambdas;
+  DenseMap *Escapes;
+  Type T;
+  size_t Indentation = 0;
+  std::string RawBody;
+  std::string Body;
+  ASTNode *Parent;
+  // TODO: switch implementation to SmallVector
+  std::vector Children;
+  const Accessor Accessor;
+  const llvm::json::Value *ParentContext;
+};
+
+// Custom stream to escape strings
+class EscapeStringStream : public raw_ostream {
+public:
+  explicit EscapeStringStream(llvm::raw_ostream &WrappedStream,
+  DenseMap &Escape)
+  : Escape(Escape), WrappedStream(WrappedStream) {
+SetUnbuffered();
+  }
+
+protected:
+  void write_impl(const char *Ptr, size_t Size) override {
+llvm::StringRef Data(Ptr, Size);
+for (char C : Data) {
+  auto It = Escape.find(C);
+  if (It != Escape.end())
+WrappedStream << It->getSecond();
+  else
+WrappedStream << C;
+}
+  }
+
+  uint64_t current_pos() const override { return WrappedStream.tell(); }
+
+private:
+  DenseMap &Escape;
+  llvm::raw_ostream &WrappedStream;
+};
+
+// Custom stream to add indentation used to for rendering partials
+class AddIndentationStringStream : public raw_ostream {
+public:
+  explicit AddIndentationStringStream(llvm::raw_ostream &WrappedStream,
+  size_t Indentation)
+  : Indentation(Indentation), WrappedStream(WrappedStream) {
+SetUnbuffered();
+  }
+
+protected:
+  void write_impl(const char *Ptr, size_t Size) override {
+llvm::StringRef Data(Ptr, Size);
+std::string Indent(Indentation, ' ');
+for (char C : Data) {
+  WrappedStream << C;
+  if (C == '\n')
+WrappedSt

[clang-tools-extra] [llvm] [llvm] add support for mustache templating language (PR #105893)

2024-11-18 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,730 @@
+//===-- Mustache.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Support/Mustache.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+using namespace llvm;
+using namespace llvm::json;
+
+namespace llvm {
+namespace mustache {
+namespace {
+
+class Token {
+public:
+  enum class Type {
+Text,
+Variable,
+Partial,
+SectionOpen,
+SectionClose,
+InvertSectionOpen,
+UnescapeVariable,
+Comment,
+  };
+
+  Token(std::string Str);
+
+  Token(std::string RawBody, std::string TokenBody, char Identifier);
+
+  StringRef getTokenBody() const { return TokenBody; };
+
+  StringRef getRawBody() const { return RawBody; };
+
+  void setTokenBody(std::string NewBody) { TokenBody = std::move(NewBody); };
+
+  Accessor getAccessor() const { return Accessor; };
+
+  Type getType() const { return TokenType; };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  size_t getIndentation() const { return Indentation; };
+
+  static Type getTokenType(char Identifier);
+
+private:
+  Type TokenType;
+  // RawBody is the original string that was tokenized
+  std::string RawBody;
+  // TokenBody is the original string with the identifier removed
+  std::string TokenBody;
+  Accessor Accessor;
+  size_t Indentation;
+};
+
+class ASTNode {
+public:
+  enum Type {
+Root,
+Text,
+Partial,
+Variable,
+UnescapeVariable,
+Section,
+InvertSection,
+  };
+
+  ASTNode() : T(Type::Root), ParentContext(nullptr) {};
+
+  ASTNode(StringRef Body, ASTNode *Parent)
+  : T(Type::Text), Body(Body), Parent(Parent), ParentContext(nullptr) {};
+
+  // Constructor for Section/InvertSection/Variable/UnescapeVariable
+  ASTNode(Type T, Accessor Accessor, ASTNode *Parent)
+  : T(T), Parent(Parent), Children({}), Accessor(Accessor),
+ParentContext(nullptr) {};
+
+  void addChild(ASTNode *Child) { Children.emplace_back(Child); };
+
+  void setRawBody(std::string NewBody) { RawBody = std::move(NewBody); };
+
+  void setIndentation(size_t NewIndentation) { Indentation = NewIndentation; };
+
+  void render(const llvm::json::Value &Data, llvm::raw_ostream &OS);
+
+  void setUpNode(llvm::BumpPtrAllocator &Alloc, StringMap &Partials,
+ StringMap &Lambdas,
+ StringMap &SectionLambdas,
+ DenseMap &Escapes);
+
+private:
+  void renderLambdas(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ Lambda &L);
+
+  void renderSectionLambdas(const llvm::json::Value &Contexts,
+llvm::raw_ostream &OS, SectionLambda &L);
+
+  void renderPartial(const llvm::json::Value &Contexts, llvm::raw_ostream &OS,
+ ASTNode *Partial);
+
+  void renderChild(const llvm::json::Value &Context, llvm::raw_ostream &OS);
+
+  const llvm::json::Value *findContext();
+
+  llvm::BumpPtrAllocator *Allocator;
+  StringMap *Partials;
+  StringMap *Lambdas;
+  StringMap *SectionLambdas;
+  DenseMap *Escapes;
+  Type T;
+  size_t Indentation = 0;
+  std::string RawBody;
+  std::string Body;
+  ASTNode *Parent;
+  // TODO: switch implementation to SmallVector
+  std::vector Children;
+  const Accessor Accessor;
+  const llvm::json::Value *ParentContext;
+};
+
+// Custom stream to escape strings
+class EscapeStringStream : public raw_ostream {
+public:
+  explicit EscapeStringStream(llvm::raw_ostream &WrappedStream,
+  DenseMap &Escape)
+  : Escape(Escape), WrappedStream(WrappedStream) {
+SetUnbuffered();
+  }
+
+protected:
+  void write_impl(const char *Ptr, size_t Size) override {
+llvm::StringRef Data(Ptr, Size);
+for (char C : Data) {
+  auto It = Escape.find(C);
+  if (It != Escape.end())
+WrappedStream << It->getSecond();
+  else
+WrappedStream << C;
+}
+  }
+
+  uint64_t current_pos() const override { return WrappedStream.tell(); }
+
+private:
+  DenseMap &Escape;
+  llvm::raw_ostream &WrappedStream;
+};
+
+// Custom stream to add indentation used to for rendering partials
+class AddIndentationStringStream : public raw_ostream {
+public:
+  explicit AddIndentationStringStream(llvm::raw_ostream &WrappedStream,
+  size_t Indentation)
+  : Indentation(Indentation), WrappedStream(WrappedStream) {
+SetUnbuffered();
+  }
+
+protected:
+  void write_impl(const char *Ptr, size_t Size) override {
+llvm::StringRef Data(Ptr, Size);
+std::string Indent(Indentation, ' ');
+for (char C : Data) {
+  WrappedStream << C;
+  if (C == '\n')
+WrappedSt

[clang] [analyzer] [MallocChecker] Less aggressive analysis of functions (PR #116383)

2024-11-18 Thread Balazs Benics via cfe-commits

steakhal wrote:

The difference is that here, in this scope the dev has full context and 
control, and we can see that it's safe.
While acrossing a function boundary a completely different set of assumptions 
can be made. E.g. just follow best practices and dont pass dangling pointers 
that the fn body cant even check if valid. Frankly, having null pointers are 
usually enough to miss to check, lets not open the door for dangling pointers.

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


[clang] [llvm] [HLSL] Adding Flatten and Branch if attributes (PR #116331)

2024-11-18 Thread Nikita Popov via cfe-commits

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


[clang] [HLSL] Add implicit resource element type concepts to AST (PR #116413)

2024-11-18 Thread Damyan Pepper via cfe-commits

damyanp wrote:

@bob80905 - can you associate this with an issue please?

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


[clang] [amdgpu-arch] Replace use of HSA with reading sysfs directly (PR #116651)

2024-11-18 Thread Jon Chesterfield via cfe-commits

JonChesterfield wrote:

> Would only work for Linux unfortunately, unless some Windows driver developer 
> out there knows if there's some similar win32 magic.

Windows getting subprocess calls until their driver catches up (or someone 
points out how to do this) seems fine to me. Linux people get a slightly faster 
clang, and maybe even one that prints useful error messages while it dies 
derived from the return code.

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


[clang] [clang][serialization] Blobify IMPORTS strings and signatures (PR #116095)

2024-11-18 Thread Jan Svoboda via cfe-commits

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


[clang] [analyzer] [MallocChecker] Less aggressive analysis of functions (PR #116383)

2024-11-18 Thread via cfe-commits

likeamahoney wrote:

> Hi, thanks for the report. This is the intended behavior AFAICT. My question 
> is, why would you ever pass a dangling pointer to a function? I can't think 
> of a valid use-case for doing that. They could just pass a null-pointer if 
> they really wanted. Am I missing something?

Hi! Thank you for response! Sorry, I can’t come up with a good example of using 
dangling pointers from real-world code, only exotic ones. I was just puzzled by 
the fact that such an example with dangling pointer using doesn’t trigger a 
warning from the checker, while, for example, the one from the topic raise "use 
after free":

```c
#include "stdio.h"
#include "stdlib.h"

void test() {
  int *p = (int*)malloc(sizeof(int));
  free(p);

  if (p) {   // no warning
printf("smth");
  }
```

[godbolt](https://godbolt.org/z/7z41GchPe)

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


[clang] [ObjC] Enable diagnose_if on Objective-C methods (PR #115056)

2024-11-18 Thread via cfe-commits

AreaZR wrote:

Any update on this?

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


[clang-tools-extra] [clang-tidy] Enhance modernize-use-starts-ends-with to handle substr patterns (PR #116033)

2024-11-18 Thread Helmut Januschka via cfe-commits


@@ -183,40 +209,44 @@ void UseStartsEndsWithCheck::check(const 
MatchFinder::MatchResult &Result) {
   const auto *EndsWithFunction =
   Result.Nodes.getNodeAs("ends_with_fun");
   assert(bool(StartsWithFunction) != bool(EndsWithFunction));
+
   const CXXMethodDecl *ReplacementFunction =
   StartsWithFunction ? StartsWithFunction : EndsWithFunction;
 
   if (ComparisonExpr->getBeginLoc().isMacroID())

hjanuschka wrote:

ok - that works, pushed.
this is what you meant with moving down, still not fully understanding why it 
works when its there.

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


[clang] [analyzer] [MallocChecker] Less aggressive analysis of functions (PR #116383)

2024-11-18 Thread Balazs Benics via cfe-commits

steakhal wrote:

This example also makes sense to me. Here the dangling pointer has a 
well-defined value. It's not null. Its some invalid value that one should not 
dereference. And nobody does that so there is no issue.

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


[libunwind] [libunwind] Fix compilation for the x32 ABI. (PR #116608)

2024-11-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-libunwind

Author: Alex Rønne Petersen (alexrp)


Changes

This would previously fail the static assertions in `UnwindCursor.hpp` due to 
`UnwindCursor`'s size not matching `unw_cursor_t`'s size. As is done for MIPS 
N32, this just declares the appropriate size in `__libunwind_config.h`.

Note: I don't have commit access.

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


1 Files Affected:

- (modified) libunwind/include/__libunwind_config.h (+3) 


``diff
diff --git a/libunwind/include/__libunwind_config.h 
b/libunwind/include/__libunwind_config.h
index 028b9e3baa8065..bb7fe4c83a3c17 100644
--- a/libunwind/include/__libunwind_config.h
+++ b/libunwind/include/__libunwind_config.h
@@ -53,6 +53,9 @@
 #else
 #  define _LIBUNWIND_CURSOR_SIZE 66
 #endif
+#  elif defined(__ILP32__)
+#define _LIBUNWIND_CONTEXT_SIZE 21
+#define _LIBUNWIND_CURSOR_SIZE 28
 #  else
 #define _LIBUNWIND_CONTEXT_SIZE 21
 #define _LIBUNWIND_CURSOR_SIZE 33

``




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


[clang] [clang-repl] Include consistency using the default clang actions. (PR #116610)

2024-11-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Vassil Vassilev (vgvassilev)


Changes

This patch improves the code reuse of the actions system and adds several 
improvements for easier debugging via clang-repl --debug-only=clang-repl.

The change inimproves the consistency of the TUKind when actions are handled 
within a WrapperFrontendAction. In this case instead of falling back to default 
TU_Complete, we forward to the TUKind of the ASTContext which presumably was 
created by the intended action. This enables the incremental infrastructure to 
reuse code.

This patch also clones the first llvm::Module because the first PTU now can 
come from -include A.h and the presumption of llvm::Module being empty does not 
hold. The changes are a first step to fix the issues with `clang-repl --cuda`.

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


5 Files Affected:

- (modified) clang/include/clang/Frontend/FrontendAction.h (+7-1) 
- (modified) clang/include/clang/Interpreter/Interpreter.h (+2-1) 
- (modified) clang/include/clang/Interpreter/PartialTranslationUnit.h (+3) 
- (modified) clang/lib/Interpreter/CMakeLists.txt (+2-1) 
- (modified) clang/lib/Interpreter/Interpreter.cpp (+43-28) 


``diff
diff --git a/clang/include/clang/Frontend/FrontendAction.h 
b/clang/include/clang/Frontend/FrontendAction.h
index 039f6f247b6d8c..718684a67771a2 100644
--- a/clang/include/clang/Frontend/FrontendAction.h
+++ b/clang/include/clang/Frontend/FrontendAction.h
@@ -21,6 +21,7 @@
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Frontend/ASTUnit.h"
+#include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendOptions.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
@@ -185,7 +186,12 @@ class FrontendAction {
   virtual bool usesPreprocessorOnly() const = 0;
 
   /// For AST-based actions, the kind of translation unit we're handling.
-  virtual TranslationUnitKind getTranslationUnitKind() { return TU_Complete; }
+  virtual TranslationUnitKind getTranslationUnitKind() {
+// The ASTContext, if exists, knows the exact TUKind of the frondend.
+if (Instance && Instance->hasASTContext())
+  return Instance->getASTContext().TUKind;
+return TU_Complete;
+  }
 
   /// Does this action support use with PCH?
   virtual bool hasPCHSupport() const { return true; }
diff --git a/clang/include/clang/Interpreter/Interpreter.h 
b/clang/include/clang/Interpreter/Interpreter.h
index 1230a3a7016fae..b1b63aedf86aba 100644
--- a/clang/include/clang/Interpreter/Interpreter.h
+++ b/clang/include/clang/Interpreter/Interpreter.h
@@ -177,7 +177,8 @@ class Interpreter {
 
   CodeGenerator *getCodeGen() const;
   std::unique_ptr GenModule();
-  PartialTranslationUnit &RegisterPTU(TranslationUnitDecl *TU);
+  PartialTranslationUnit &RegisterPTU(TranslationUnitDecl *TU,
+  std::unique_ptr M = {});
 
   // A cache for the compiled destructors used to for de-allocation of managed
   // clang::Values.
diff --git a/clang/include/clang/Interpreter/PartialTranslationUnit.h 
b/clang/include/clang/Interpreter/PartialTranslationUnit.h
index bf91d559452b8a..c878e139fe70d0 100644
--- a/clang/include/clang/Interpreter/PartialTranslationUnit.h
+++ b/clang/include/clang/Interpreter/PartialTranslationUnit.h
@@ -31,6 +31,9 @@ struct PartialTranslationUnit {
 
   /// The llvm IR produced for the input.
   std::unique_ptr TheModule;
+  bool operator==(const PartialTranslationUnit &other) {
+return other.TUPart == TUPart && other.TheModule == TheModule;
+  }
 };
 } // namespace clang
 
diff --git a/clang/lib/Interpreter/CMakeLists.txt 
b/clang/lib/Interpreter/CMakeLists.txt
index d5ffe78251d253..df7ea82e0dada5 100644
--- a/clang/lib/Interpreter/CMakeLists.txt
+++ b/clang/lib/Interpreter/CMakeLists.txt
@@ -10,7 +10,8 @@ set(LLVM_LINK_COMPONENTS
Support
Target
TargetParser
-  )
+   TransformUtils
+   )
 
 if (EMSCRIPTEN AND "lld" IN_LIST LLVM_ENABLE_PROJECTS)
   set(WASM_SRC Wasm.cpp)
diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index bc96da811d44cb..1859c6802c6f2c 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -50,6 +50,9 @@
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/Host.h"
+#include "llvm/Transforms/Utils/Cloning.h" // for CloneModule
+
+#define DEBUG_TYPE "clang-repl"
 
 using namespace clang;
 // FIXME: Figure out how to unify with namespace init_convenience from
@@ -339,19 +342,8 @@ class IncrementalAction : public WrapperFrontendAction {
   }
 
   void ExecuteAction() override {
-CompilerInstance &CI = getCompilerInstance();
-assert(CI.hasPreprocessor() && "No PP!");
-
-// Use a code completion consumer?
-CodeCompleteConsumer *CompletionConsumer = nullptr;
-if (CI.hasCodeCompletionConsumer())
-  CompletionCons

[clang-tools-extra] [clangd] Support symbolTags for document symbol (PR #113669)

2024-11-18 Thread via cfe-commits

chouzz wrote:

@travkin79 I replaced `Constant` with `Read-only` tag and updated `SymbolTag` 
based on your changes.

https://github.com/llvm/llvm-project/pull/113669
___
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 add function. (PR #116243)

2024-11-18 Thread via cfe-commits

c8ef wrote:

> Thanks @c8ef - are you OK to add the remaining integer reduction cases next? 
> Also, please can you also update the LanguageExtensions docs page to mention 
> that they are constexpr legal?

Will do.

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


[clang] [llvm] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-18 Thread Boaz Brickner via cfe-commits


@@ -3951,7 +3958,7 @@ The capturing entity ``X`` can be one of the following:
   std::set s;
 };
 
-- 'global', 'unknown' (without quotes).
+- `global`, `unknown`.

bricknerb wrote:

Thanks for clarifying!
I think we should try to find an alternative for limiting the parameter name 
this way, since it's possible it won't be easy to change in some cases.
Was this already discussed somewhere else?
What constraints do we have on attribute param names?

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


[clang] [AArch64ABI] Don't pass small types with padding as wide ints. (WIP) (PR #116615)

2024-11-18 Thread Florian Hahn via cfe-commits

https://github.com/fhahn updated 
https://github.com/llvm/llvm-project/pull/116615

>From 5d057e29a150fd1efb0c5892dc4a9b1ef9fad050 Mon Sep 17 00:00:00 2001
From: Florian Hahn 
Date: Mon, 18 Nov 2024 13:26:12 +
Subject: [PATCH] [AArch64ABI] Don't pass small types with padding as wide
 ints. (WIP)

Currently Clang returns data types with sizes <= 128 as wide integers (or
pairs of wide integers). This lowering appears incorrect if the type
contains padding.

For example, consider returning a type that contains 32 bits of data and
32 bits of padding (as in the example below). On AArch64, Clang uses i64
to return the result. To load the result value to return, it loads an
i64, with loads the 32 bit data but also accesses 32 bits of
uninitialized memory. Loading an integer where some bits are poison means
the whole integer is poison (which is different to LLVM's undef)

Unless I am missing something, Clang should pass small types with
padding using types that separate the data and padding bits, e.g. by
using a array of i8 (assuming all fields are multiple of 8 bits) or a
struct with the unpadded type as first and the padding as second
element.

Computing the padding in AArch64ABI seems difficult, maybe there's a
better way I am missing? For this to work at the moment, I had to adjust
mustSkipTalPadding, which certainly isn't correct

The current patch passes types with padding indirectly, unless there's
only tail-padding.

struct alignas(8) S {float a;};
struct Foo {
  union {
struct { float x; };
S s;
  };
};
Foo bar() {  Foo r; r.s.a = 1; return r;}

Clang generates:

define i64 @bar() {
entry:
  %0 = getelementptr inbounds nuw %struct.Foo, ptr %retval, i32 0, i32 0
  %a = getelementptr inbounds nuw %struct.S, ptr %0, i32 0, i32 0
  store float 1.00e+00, ptr %a, align 8
  %coerce.dive = getelementptr inbounds nuw %struct.Foo, ptr %retval, i32 0, 
i32 0
  %coerce.dive1 = getelementptr inbounds nuw %union.anon, ptr %coerce.dive, i32 
0, i32 0
  %1 = load i64, ptr %coerce.dive1, align 8
  ret i64 %1
}

https://clang.godbolt.org/z/YWGdcqna7

The function can be simplified to `ret i64 poison`

https://alive2.llvm.org/ce/z/DwkvmT
---
 clang/lib/AST/RecordLayoutBuilder.cpp |  2 +-
 clang/lib/CodeGen/Targets/AArch64.cpp | 36 +++
 .../AArch64/small-types-with-padding.cpp  | 18 ++
 3 files changed, 55 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGen/AArch64/small-types-with-padding.cpp

diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index b1b13b66a5e504..6734b350c3a91e 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -2450,7 +2450,7 @@ static bool mustSkipTailPadding(TargetCXXABI ABI, const 
CXXRecordDecl *RD) {
 // mode; fortunately, that is true because we want to assign
 // consistently semantics to the type-traits intrinsics (or at
 // least as many of them as possible).
-return RD->isTrivial() && RD->isCXX11StandardLayout();
+return false; // RD->isTrivial() && RD->isCXX11StandardLayout();
   }
 
   llvm_unreachable("bad tail-padding use kind");
diff --git a/clang/lib/CodeGen/Targets/AArch64.cpp 
b/clang/lib/CodeGen/Targets/AArch64.cpp
index 9320c6ef06efab..dc64b51098b8c3 100644
--- a/clang/lib/CodeGen/Targets/AArch64.cpp
+++ b/clang/lib/CodeGen/Targets/AArch64.cpp
@@ -484,6 +484,30 @@ ABIArgInfo AArch64ABIInfo::classifyArgumentType(QualType 
Ty, bool IsVariadicFn,
   return getNaturalAlignIndirect(Ty, /*ByVal=*/false);
 }
 
+static std::pair computePadding(QualType T,
+ASTContext &Ctx) {
+  unsigned Padding = 0;
+  unsigned TailPadding = 0;
+  if (auto *RD = T->getAs()) {
+for (auto I = RD->getDecl()->field_begin(),
+  End = RD->getDecl()->field_end();
+ I != End; ++I) {
+  QualType FieldTy = I->getType();
+  if (auto *ET = FieldTy->getAs())
+FieldTy = ET->getNamedType();
+  if (auto *RD2 = FieldTy->getAs()) {
+auto &Layout = Ctx.getASTRecordLayout(RD2->getDecl());
+auto [SubPadding, SubTailPadding] = computePadding(I->getType(), Ctx);
+TailPadding = Ctx.toBits(Layout.getSize() - Layout.getDataSize()) +
+  SubTailPadding;
+Padding +=
+Ctx.toBits(Layout.getSize() - Layout.getDataSize()) + SubPadding;
+  }
+}
+  }
+  return {Padding, TailPadding};
+}
+
 ABIArgInfo AArch64ABIInfo::classifyReturnType(QualType RetTy,
   bool IsVariadicFn) const {
   if (RetTy->isVoidType())
@@ -543,6 +567,18 @@ ABIArgInfo AArch64ABIInfo::classifyReturnType(QualType 
RetTy,
 
   // Aggregates <= 16 bytes are returned directly in registers or on the stack.
   if (Size <= 128) {
+auto [Padding, TailPadding] = computePadding(RetTy, getContext());
+// If the type contains any padding, be careful not to lower to wide types
+// 

[clang] [flang] [clang][driver] When -fveclib=ArmPL flag is in use, always link against libamath (PR #116432)

2024-11-18 Thread David Truby via cfe-commits


@@ -490,6 +490,16 @@ void tools::AddLinkerInputs(const ToolChain &TC, const 
InputInfoList &Inputs,
 else
   A.renderAsInput(Args, CmdArgs);
   }
+  if (const Arg *A = Args.getLastArg(options::OPT_fveclib)) {
+if (A->getNumValues() == 1) {
+  StringRef V = A->getValue();
+  if (V == "ArmPL") {
+CmdArgs.push_back(Args.MakeArgString("-lamath"));
+CmdArgs.push_back(Args.MakeArgString("-lm"));

DavidTruby wrote:

We actually do support this on Windows, I was wrong above. So we should not be 
breaking this for Windows users.

I suppose the other option is to say that if someone passes `-fveclib=ArmPL` 
they will also have to pass the right flags to link to ArmPL and libamath 
themselves, rather than doing anything in the driver automatically? Assuming 
that's what @paulwalker-arm means, I'd probably agree and say that should be on 
the user to sort out and not on the driver. 

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


[clang] [NFC][Clang][AArch64]Refactor implementation of Neon vectors MFloat8… (PR #114804)

2024-11-18 Thread via cfe-commits

CarolineConcatto wrote:

Hi @paulwalker-arm ,
I think I misunderstand what we had agreed in a previous patch.
I am not sure if I still understand.
I am assuming now that you would like to keep clang target independent(without 
any reference to MFloat8), and change NeonEmmiter to use the BuiltIns.
What we will have looks  a bit like a Frankenstein. 
My previous implementation made the Neon vectors all look the same. Let me know 
if that is the direction you had in mind.

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


[clang] [llvm] [PAC][ELF][AArch64] Support signed personality function pointer (PR #113148)

2024-11-18 Thread Daniil Kovalev via cfe-commits

https://github.com/kovdan01 updated 
https://github.com/llvm/llvm-project/pull/113148

>From e192b193471831d004a715ce3b1684198342dba4 Mon Sep 17 00:00:00 2001
From: Daniil Kovalev 
Date: Mon, 21 Oct 2024 13:28:58 +0300
Subject: [PATCH] [PAC][ELF][AArch64] Support signed personality function
 pointer

If function pointer signing is enabled, sign personality function pointer
stored in `.DW.ref.__gxx_personality_v0` section with IA key,
0x7EAD = `ptrauth_string_discriminator("personality")` constant discriminator
and address diversity enabled.
---
 clang/lib/CodeGen/CodeGenModule.cpp   |  3 ++
 clang/test/CodeGen/ptrauth-module-flags.c |  8 
 .../llvm/CodeGen/MachineModuleInfoImpls.h |  8 +++-
 .../CodeGen/TargetLoweringObjectFileImpl.h|  8 +++-
 .../llvm/Target/TargetLoweringObjectFile.h|  3 +-
 .../CodeGen/AsmPrinter/DwarfCFIException.cpp  |  3 +-
 llvm/lib/CodeGen/MachineModuleInfoImpls.cpp   | 12 ++
 .../CodeGen/TargetLoweringObjectFileImpl.cpp  | 10 -
 .../AArch64/AArch64TargetObjectFile.cpp   | 16 
 .../Target/AArch64/AArch64TargetObjectFile.h  |  4 ++
 .../MCTargetDesc/AArch64TargetStreamer.cpp| 10 +
 .../MCTargetDesc/AArch64TargetStreamer.h  |  7 
 llvm/lib/Target/TargetLoweringObjectFile.cpp  |  7 ++--
 .../AArch64/ptrauth-sign-personality.ll   | 39 +++
 14 files changed, 129 insertions(+), 9 deletions(-)
 create mode 100644 clang/test/CodeGen/ptrauth-module-flags.c
 create mode 100644 llvm/test/CodeGen/AArch64/ptrauth-sign-personality.ll

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 508f53482d4e1f..8b2d92a6cc9379 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1214,6 +1214,9 @@ void CodeGenModule::Release() {
 "sign-return-address-with-bkey", 1);
 
 if (getTriple().isOSLinux()) {
+  if (LangOpts.PointerAuthCalls)
+getModule().addModuleFlag(llvm::Module::Min, 
"ptrauth-sign-personality",
+  1);
   assert(getTriple().isOSBinFormatELF());
   using namespace llvm::ELF;
   uint64_t PAuthABIVersion =
diff --git a/clang/test/CodeGen/ptrauth-module-flags.c 
b/clang/test/CodeGen/ptrauth-module-flags.c
new file mode 100644
index 00..150e5bf59fb05e
--- /dev/null
+++ b/clang/test/CodeGen/ptrauth-module-flags.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple aarch64-linux-gnu   -emit-llvm %s  
-o - | FileCheck %s --check-prefix=OFF
+// RUN: %clang_cc1 -triple aarch64-linux-gnu -fptrauth-calls   -emit-llvm %s  
-o - | FileCheck %s --check-prefix=PERSONALITY
+
+// PERSONALITY:  !llvm.module.flags = !{
+// PERSONALITY-SAME: !1
+// PERSONALITY:  !1 = !{i32 8, !"ptrauth-sign-personality", i32 1}
+
+// OFF-NOT: "ptrauth-
diff --git a/llvm/include/llvm/CodeGen/MachineModuleInfoImpls.h 
b/llvm/include/llvm/CodeGen/MachineModuleInfoImpls.h
index c1ae3d2d966df5..f7a028625ee3c8 100644
--- a/llvm/include/llvm/CodeGen/MachineModuleInfoImpls.h
+++ b/llvm/include/llvm/CodeGen/MachineModuleInfoImpls.h
@@ -83,10 +83,14 @@ class MachineModuleInfoELF : public MachineModuleInfoImpl {
   /// extern_weak symbols.
   DenseMap AuthPtrStubs;
 
+  /// HasSignedPersonality is true if the corresponding IR module has the
+  /// "ptrauth-sign-personality" flag set to 1.
+  bool HasSignedPersonality = false;
+
   virtual void anchor(); // Out of line virtual method.
 
 public:
-  MachineModuleInfoELF(const MachineModuleInfo &) {}
+  MachineModuleInfoELF(const MachineModuleInfo &);
 
   StubValueTy &getGVStubEntry(MCSymbol *Sym) {
 assert(Sym && "Key cannot be null");
@@ -105,6 +109,8 @@ class MachineModuleInfoELF : public MachineModuleInfoImpl {
   ExprStubListTy getAuthGVStubList() {
 return getSortedExprStubs(AuthPtrStubs);
   }
+
+  bool hasSignedPersonality() const { return HasSignedPersonality; }
 };
 
 /// MachineModuleInfoCOFF - This is a MachineModuleInfoImpl implementation
diff --git a/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h 
b/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
index 8eef45ce565deb..a2a9e5d499e527 100644
--- a/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
+++ b/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
@@ -52,7 +52,13 @@ class TargetLoweringObjectFileELF : public 
TargetLoweringObjectFile {
   void emitModuleMetadata(MCStreamer &Streamer, Module &M) const override;
 
   void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &DL,
-const MCSymbol *Sym) const override;
+const MCSymbol *Sym,
+const MachineModuleInfo *MMI) const override;
+
+  virtual void emitPersonalityValueImpl(MCStreamer &Streamer,
+const DataLayout &DL,
+const MCSymbol *Sym,
+const Mac

[clang] [llvm] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-18 Thread Boaz Brickner via cfe-commits


@@ -3951,7 +3958,7 @@ The capturing entity ``X`` can be one of the following:
   std::set s;
 };
 
-- 'global', 'unknown' (without quotes).
+- `global`, `unknown`.

bricknerb wrote:

To clarify, I suggested the following:

```c++
void captureInt(const int &i [[clang::lifetime_capture_by(global)]],
X &global);
```

If the parameter is named "global" then it is a known function parameter, no?
As a user I might not understand what the error is trying to say in this case.

So we're introducing new keywords ("global" and "unknown") implicitly, and 
prevent using them as parameter names in some cases.
Are there alternatives for this behavior?

We should also make sure we test this use case.

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


[clang] [llvm] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-18 Thread Boaz Brickner via cfe-commits


@@ -3922,16 +3922,41 @@ def LifetimeCaptureByDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
 Similar to `lifetimebound`_, the ``lifetime_capture_by(X)`` attribute on a 
function
-parameter or implicit object parameter indicates that that objects that are 
referred to
-by that parameter may also be referred to by the capturing entity ``X``.
+parameter or implicit object parameter indicates that objects that are 
referred to by
+that parameter may also be referred to by a capturing entity ``X``.

bricknerb wrote:

How about

... indicates that X may refer to the object referred by that parameter.

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


[clang] [llvm] [LLVM][IR] Use splat syntax when printing Constant[Data]Vector. (PR #112548)

2024-11-18 Thread Christian Ulmann via cfe-commits

Dinistro wrote:

We have a, temporary, odd use-case where we need to feed the textual IR back to 
a tool that is built with LLVM 17. For now, we were able to bypass all 
incompatibilities by simple workarounds on either the LLVM head, or on the LLVM 
17 side. Unfortunately, this change seems the first change that leads to a 
non-trivial breakage that we cannot temporary circumvent.

I'm aware that our use case is not officially supported, I just wanted to check 
what is supposed to happen. We will find a way to deal with this.

Either way, thanks for the quick answer and thanks for working on improvements 
like these 🙂 

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


[clang] [analyzer] Untangle subcheckers of CStringChecker (PR #113312)

2024-11-18 Thread Kristóf Umann via cfe-commits

Szelethus wrote:

@steakhal, and especially @isuckatcs, I greatly appreciate the reviews! I 
happen to have gotten some very ugrent task on my plate that drew away my 
attention from this project. I will fix this PR up as soon as I'm done!

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


[clang] 826b845 - [X86] Support -march=diamondrapids (#113881)

2024-11-18 Thread via cfe-commits

Author: Freddy Ye
Date: 2024-11-18T08:31:17+08:00
New Revision: 826b845c9e97448395431be3e4e5da585bd98c5e

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

LOG: [X86] Support -march=diamondrapids (#113881)

Ref.: https://cdrdv2.intel.com/v1/dl/getContent/671368

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Basic/Targets/X86.cpp
clang/test/CodeGen/attr-cpuspecific-cpus.c
clang/test/CodeGen/attr-target-mv.c
clang/test/CodeGen/target-builtin-noerror.c
clang/test/Driver/x86-march.c
clang/test/Misc/target-invalid-cpu-note/x86.c
clang/test/Preprocessor/predefined-arch-macros.c
compiler-rt/lib/builtins/cpu_model/x86.c
llvm/docs/ReleaseNotes.md
llvm/include/llvm/TargetParser/X86TargetParser.def
llvm/include/llvm/TargetParser/X86TargetParser.h
llvm/lib/Target/X86/X86.td
llvm/lib/TargetParser/Host.cpp
llvm/lib/TargetParser/X86TargetParser.cpp
llvm/test/CodeGen/X86/cpus-intel.ll

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a8830a5658c7da..044f62e770a7a0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -769,6 +769,8 @@ X86 Support
 - Support ISA of ``AMX-TF32``.
 - Support ISA of ``MOVRS``.
 
+- Supported ``-march/tune=diamondrapids``
+
 Arm and AArch64 Support
 ^^^
 

diff  --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 086b4415412e67..5993257e27d5a9 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -667,6 +667,7 @@ void X86TargetInfo::getTargetDefines(const LangOptions 
&Opts,
   case CK_GraniterapidsD:
   case CK_Emeraldrapids:
   case CK_Clearwaterforest:
+  case CK_Diamondrapids:
 // FIXME: Historically, we defined this legacy name, it would be nice to
 // remove it at some point. We've never exposed fine-grained names for
 // recent primary x86 CPUs, and we should keep it that way.
@@ -1651,6 +1652,7 @@ std::optional 
X86TargetInfo::getCPUCacheLineSize() const {
 case CK_GraniterapidsD:
 case CK_Emeraldrapids:
 case CK_Clearwaterforest:
+case CK_Diamondrapids:
 case CK_KNL:
 case CK_KNM:
 // K7

diff  --git a/clang/test/CodeGen/attr-cpuspecific-cpus.c 
b/clang/test/CodeGen/attr-cpuspecific-cpus.c
index dd154fd227b25b..1dd095ec9e191f 100644
--- a/clang/test/CodeGen/attr-cpuspecific-cpus.c
+++ b/clang/test/CodeGen/attr-cpuspecific-cpus.c
@@ -43,6 +43,7 @@ ATTR(cpu_specific(icelake_client)) void CPU(void){}
 ATTR(cpu_specific(tigerlake)) void CPU(void){}
 ATTR(cpu_specific(alderlake)) void CPU(void){}
 ATTR(cpu_specific(sapphirerapids)) void CPU(void){}
+ATTR(cpu_specific(diamondrapids)) void CPU(void){}
 
 // ALIAS CPUs
 ATTR(cpu_specific(pentium_iii_no_xmm_regs)) void CPU0(void){}

diff  --git a/clang/test/CodeGen/attr-target-mv.c 
b/clang/test/CodeGen/attr-target-mv.c
index 2c4b95ca04370a..6911b55203b7e7 100644
--- a/clang/test/CodeGen/attr-target-mv.c
+++ b/clang/test/CodeGen/attr-target-mv.c
@@ -29,6 +29,7 @@ int __attribute__((target("arch=lunarlake"))) foo(void) 
{return 23;}
 int __attribute__((target("arch=gracemont"))) foo(void) {return 24;}
 int __attribute__((target("arch=pantherlake"))) foo(void) {return 25;}
 int __attribute__((target("arch=clearwaterforest"))) foo(void) {return 26;}
+int __attribute__((target("arch=diamondrapids"))) foo(void) {return 27;}
 int __attribute__((target("default"))) foo(void) { return 2; }
 
 int bar(void) {

diff  --git a/clang/test/CodeGen/target-builtin-noerror.c 
b/clang/test/CodeGen/target-builtin-noerror.c
index 1e53621bc6b5ae..0bbd8c3e5ddd81 100644
--- a/clang/test/CodeGen/target-builtin-noerror.c
+++ b/clang/test/CodeGen/target-builtin-noerror.c
@@ -209,4 +209,5 @@ void verifycpustrings(void) {
   (void)__builtin_cpu_is("znver3");
   (void)__builtin_cpu_is("znver4");
   (void)__builtin_cpu_is("znver5");
+  (void)__builtin_cpu_is("diamondrapids");
 }

diff  --git a/clang/test/Driver/x86-march.c b/clang/test/Driver/x86-march.c
index 3bc2a82ae778d6..341f01c8d668df 100644
--- a/clang/test/Driver/x86-march.c
+++ b/clang/test/Driver/x86-march.c
@@ -120,6 +120,10 @@
 // RUN:   | FileCheck %s -check-prefix=clearwaterforest
 // clearwaterforest: "-target-cpu" "clearwaterforest"
 //
+// RUN: %clang -target x86_64-unknown-unknown -c -### %s -march=diamondrapids 
2>&1 \
+// RUN:   | FileCheck %s -check-prefix=diamondrapids
+// diamondrapids: "-target-cpu" "diamondrapids"
+//
 // RUN: %clang -target x86_64-unknown-unknown -c -### %s -march=lakemont 2>&1 \
 // RUN:   | FileCheck %s -check-prefix=lakemont
 // lakemont: "-target-cpu" "lakemont"

diff  --git a/clang/test/Misc/target-invalid-cpu-note/x86.c 
b/clang/test/Misc/target-invalid-cpu-note/x86.c
index 7879676040af46..f89

[clang] [ARM] Fix NaN behaviour for MVE compare intrinsics (PR #116371)

2024-11-18 Thread David Green via cfe-commits


@@ -118,6 +118,8 @@ def fcmp_gt: IRBuilder<"CreateFCmpOGT">;
 def fcmp_ge: IRBuilder<"CreateFCmpOGE">;
 def fcmp_lt: IRBuilder<"CreateFCmpOLT">;
 def fcmp_le: IRBuilder<"CreateFCmpOLE">;

davemgreen wrote:

Can _le and _lt be removed now.

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


[clang] Draft (PR #116626)

2024-11-18 Thread via cfe-commits

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

None

>From 78a7ca9bf5f168dd7733e6ebdab86e504c45f48a Mon Sep 17 00:00:00 2001
From: c8ef 
Date: Mon, 18 Nov 2024 14:14:51 +
Subject: [PATCH] add constexpr reduce mul

---
 clang/docs/ReleaseNotes.rst  |  1 +
 clang/include/clang/Basic/Builtins.td|  2 +-
 clang/lib/AST/ExprConstant.cpp   | 23 
 clang/test/Sema/constant_builtins_vector.cpp | 20 +
 4 files changed, 41 insertions(+), 5 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2bd67138ecc048..af0c7f41baa3e7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -356,6 +356,7 @@ Non-comprehensive list of changes in this release
   issues with the sanitizer because the counter is automatically set.
 
 - ``__builtin_reduce_add`` function can now be used in constant expressions.
+- ``__builtin_reduce_mul`` function can now be used in constant expressions.
 
 New Compiler Flags
 --
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index f5124f4633364f..f9c36bd64943db 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -1510,7 +1510,7 @@ def ReduceAdd : Builtin {
 
 def ReduceMul : Builtin {
   let Spellings = ["__builtin_reduce_mul"];
-  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 833b99bf1bd9f1..f597f05807069c 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -13527,7 +13527,8 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
 return Success(DidOverflow, E);
   }
 
-  case Builtin::BI__builtin_reduce_add: {
+  case Builtin::BI__builtin_reduce_add:
+  case Builtin::BI__builtin_reduce_mul: {
 APValue Source;
 if (!EvaluateAsRValue(Info, E->getArg(0), Source))
   return false;
@@ -13535,10 +13536,24 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
 unsigned SourceLen = Source.getVectorLength();
 APSInt Reduced = Source.getVectorElt(0).getInt();
 for (unsigned EltNum = 1; EltNum < SourceLen; ++EltNum) {
-  if (!CheckedIntArithmetic(
-  Info, E, Reduced, Source.getVectorElt(EltNum).getInt(),
-  Reduced.getBitWidth() + 1, std::plus(), Reduced))
+  switch (BuiltinOp) {
+  default:
 return false;
+  case Builtin::BI__builtin_reduce_add: {
+if (!CheckedIntArithmetic(
+Info, E, Reduced, Source.getVectorElt(EltNum).getInt(),
+Reduced.getBitWidth() + 1, std::plus(), Reduced))
+  return false;
+break;
+  }
+  case Builtin::BI__builtin_reduce_mul: {
+if (!CheckedIntArithmetic(
+Info, E, Reduced, Source.getVectorElt(EltNum).getInt(),
+Reduced.getBitWidth() * 2, std::multiplies(), Reduced))
+  return false;
+break;
+  }
+  }
 }
 
 return Success(Reduced, E);
diff --git a/clang/test/Sema/constant_builtins_vector.cpp 
b/clang/test/Sema/constant_builtins_vector.cpp
index d15c587cfffc49..b9dc17f73f7a92 100644
--- a/clang/test/Sema/constant_builtins_vector.cpp
+++ b/clang/test/Sema/constant_builtins_vector.cpp
@@ -745,3 +745,23 @@ constexpr long long reduceAddLong2 = 
__builtin_reduce_add((vector4long){(1LL <<
 // expected-note@-1 {{outside the range of representable values of type 'long 
long'}}
 static_assert(__builtin_reduce_add((vector4uint){~0U, 0, 0, 1}) == 0);
 static_assert(__builtin_reduce_add((vector4ulong){~0ULL, 0, 0, 1}) == 0);
+
+static_assert(__builtin_reduce_mul((vector4char){}) == 0);
+static_assert(__builtin_reduce_mul((vector4char){1, 2, 3, 4}) == 24);
+static_assert(__builtin_reduce_mul((vector4short){1, 2, 30, 40}) == 2400);
+static_assert(__builtin_reduce_mul((vector4int){10, 20, 300, 400}) == 
2400);
+static_assert(__builtin_reduce_mul((vector4long){1000L, 2000L, 3000L, 4000L}) 
== 24L);
+constexpr int reduceMulInt1 = __builtin_reduce_mul((vector4int){~(1 << 31), 1, 
1, 2});
+// expected-error@-1 {{must be initialized by a constant expression}} \
+// expected-note@-1 {{outside the range of representable values of type 'int'}}
+constexpr long long reduceMulLong1 = __builtin_reduce_mul((vector4long){~(1LL 
<< 63), 1, 1, 2});
+// expected-error@-1 {{must be initialized by a constant expression}} \
+// expected-note@-1 {{outside the range of representable values of type 'long 
long'}}
+constexpr int reduceMulInt2 = __builtin_reduce_mul((vector4int){(1 << 31), 1, 
1, 2});
+// expected-error@-1 {{must be initialized by a constant expression}} \
+// expected-note@-1 {{outside the range of representable values of type 'int'}}
+constexpr long long reduceM

[clang] [PAC][clang] Add signed GOT cc1 flag (PR #96160)

2024-11-18 Thread Daniil Kovalev via cfe-commits

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


[clang] [llvm] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-18 Thread Utkarsh Saxena via cfe-commits


@@ -3951,7 +3958,7 @@ The capturing entity ``X`` can be one of the following:
   std::set s;
 };
 
-- 'global', 'unknown' (without quotes).
+- `global`, `unknown`.

usx95 wrote:

> Was this already discussed somewhere else?

This was discussed in 
https://github.com/llvm/llvm-project/pull/111499#discussion_r1836463450

> I think we should try to find an alternative for limiting the parameter name 
> this way, since it's possible it won't be easy to change in some cases.

Changing parameter names should be relatively easy though. It is not part of 
the signature/mangled name so it should be relatively local change.
Other alternatives include 
- using parameter indices: But this reduces readability and is very brittle.
- `[[clang::lifetime_capture_by(__global)]]`: But this only reduces the 
likelyhood of name collision.

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


[clang] [analyzer] [MallocChecker] Less aggressive analysis of functions (PR #116383)

2024-11-18 Thread via cfe-commits

likeamahoney wrote:

> The difference is that here, in this scope the dev has full context and 
> control, and we can see that it's safe. While acrossing a function boundary a 
> completely different set of assumptions can be made. E.g. just follow best 
> practices and dont pass dangling pointers that the fn body cant even check if 
> valid. Frankly, having null pointers are usually enough to miss to check, 
> lets not open the door for dangling pointers.

Thank you for review! I can close the issue.

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


[clang] [analyzer] [MallocChecker] Less aggressive analysis of functions (PR #116383)

2024-11-18 Thread via cfe-commits

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


[clang] [llvm] [clang] Implement lifetime analysis for lifetime_capture_by(X) (PR #115921)

2024-11-18 Thread Haojian Wu via cfe-commits


@@ -793,3 +793,108 @@ void test13() {
 }
 
 } // namespace GH100526
+
+namespace lifetime_capture_by {
+struct S {
+  const int *x;
+  void captureInt(const int&x [[clang::lifetime_capture_by(this)]]) { this->x 
= &x; }
+  void captureSV(std::string_view sv [[clang::lifetime_capture_by(this)]]);
+};
+///
+// Detect dangling cases.
+///
+void captureInt(const int&x [[clang::lifetime_capture_by(s)]], S&s);
+void captureRValInt(int&&x [[clang::lifetime_capture_by(s)]], S&s);
+void noCaptureInt(int x [[clang::lifetime_capture_by(s)]], S&s);
+std::string_view substr(const std::string& s [[clang::lifetimebound]]);
+std::string_view strcopy(const std::string& s);
+void captureSV(std::string_view x [[clang::lifetime_capture_by(s)]], S&s);
+void captureRValSV(std::string_view&& x [[clang::lifetime_capture_by(s)]], 
S&s);
+void noCaptureSV(std::string_view x, S&s);
+void captureS(const std::string& x [[clang::lifetime_capture_by(s)]], S&s);
+void captureRValS(std::string&& x [[clang::lifetime_capture_by(s)]], S&s);
+const std::string* getPointerLB(const std::string& s[[clang::lifetimebound]]);
+const std::string* getPointerNoLB(const std::string& s);
+void capturePointer(const std::string* x [[clang::lifetime_capture_by(s)]], 
S&s);
+struct ThisIsCaptured {
+  void capture(S& s) [[clang::lifetime_capture_by(s)]];
+  void bar(S& s) [[clang::lifetime_capture_by(abcd)]]; // expected-error 
{{'lifetime_capture_by' attribute argument 'abcd' is not a known function 
parameter}}
+  void baz(S& s) [[clang::lifetime_capture_by(this)]]; // expected-error 
{{'lifetime_capture_by' argument references itself}}
+};
+void use() {
+  std::string_view local_sv;
+  std::string local_s;
+  S s;
+  // Capture an 'int'.
+  int local;
+  captureInt(1, // expected-warning {{object captured by 's' will be destroyed 
at the end of the full-expression}}
+s);
+  captureRValInt(1, s); // expected-warning {{object captured by 's'}}
+  captureInt(local, s);
+  noCaptureInt(1, s);
+  noCaptureInt(local, s);
+
+  // Capture lifetimebound pointer.
+  capturePointer(getPointerLB(std::string()), s); // expected-warning {{object 
captured by 's'}}
+  capturePointer(getPointerLB(*getPointerLB(std::string())), s); // 
expected-warning {{object captured by 's'}}
+  capturePointer(getPointerNoLB(std::string()), s);
+
+  // Capture using std::string_view.
+  captureSV(local_sv, s);
+  captureSV(std::string(), // expected-warning {{object captured by 's'}}
+s);
+  captureSV(substr(
+  std::string() // expected-warning {{object captured by 's'}}
+  ), s);
+  captureSV(substr(local_s), s);
+  captureSV(strcopy(std::string()), s);
+  captureRValSV(std::move(local_sv), s);
+  captureRValSV(std::string(), s); // expected-warning {{object captured by 
's'}}
+  captureRValSV(std::string_view{"abcd"}, s);
+  captureRValSV(substr(local_s), s);
+  captureRValSV(substr(std::string()), s); // expected-warning {{object 
captured by 's'}}
+  captureRValSV(strcopy(std::string()), s);
+  noCaptureSV(local_sv, s);
+  noCaptureSV(std::string(), s);
+  noCaptureSV(substr(std::string()), s);
+
+  // Capture using std::string.
+  captureS(std::string(), s); // expected-warning {{object captured by 's'}}
+  captureS(local_s, s);
+  captureRValS(std::move(local_s), s);
+  captureRValS(std::string(), s); // expected-warning {{object captured by 
's'}}
+
+  // Member functions.
+  s.captureInt(1); // expected-warning {{object captured by 's'}}
+  s.captureSV(std::string()); // expected-warning {{object captured by 's'}}
+  s.captureSV(substr(std::string())); // expected-warning {{object captured by 
's'}}
+  s.captureSV(strcopy(std::string()));
+
+  // 'this' is captured.
+  ThisIsCaptured{}.capture(s); // expected-warning {{object captured by 's'}}
+  ThisIsCaptured TIS;
+  TIS.capture(s);
+}
+class [[gsl::Pointer()]] my_string_view : public std::string_view {};
+class my_string_view_not_pointer : public std::string_view {};
+std::optional getOptionalSV();
+std::optional getOptionalS();
+std::optional getOptionalMySV();
+std::optional getOptionalMySVNotP();
+my_string_view getMySV();
+my_string_view_not_pointer getMySVNotP();
+
+template
+struct MySet {
+void insert(T&& t [[clang::lifetime_capture_by(this)]]);
+void insert(const T& t [[clang::lifetime_capture_by(this)]]);
+};
+void user_defined_containers() {
+  MySet set_of_int;
+  set_of_int.insert(1); // expected-warning {{object captured by 'set_of_int' 
will be destroyed}}

hokein wrote:

I believe the current behavior is working as intended, although it doesn't 
align with user expectations.

This issue arises when involving a `gsl::pointer` type with a templated 
constructor that takes a const reference:

```cpp
#include 

template 
struct [[gsl::Pointer]] MySpan2 {
   template 
   MySpan2(const Container& container);
};

template 
struct [[gsl::Pointer]] MySpan {
   template 
   MySpan(const Container& containe

[clang-tools-extra] Rename CODE_OWNERS -> Maintainers (PR #114544)

2024-11-18 Thread kadir çetinkaya via cfe-commits

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


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


[clang] 5ff5243 - Relax clang/test/CodeGen/tbaa-pointers.c for -Asserts.

2024-11-18 Thread NAKAMURA Takumi via cfe-commits

Author: NAKAMURA Takumi
Date: 2024-11-18T15:27:49+09:00
New Revision: 5ff52436fd0c7739765f1d849992713a3e9ae237

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

LOG: Relax clang/test/CodeGen/tbaa-pointers.c for -Asserts.

Fixes c4eeef32d5dc (llvmorg-20-init-12475-gc4eeef32d5dc)

Added: 


Modified: 
clang/test/CodeGen/tbaa-pointers.c

Removed: 




diff  --git a/clang/test/CodeGen/tbaa-pointers.c 
b/clang/test/CodeGen/tbaa-pointers.c
index cf6061486b6ee4..9417a0e2f09e8c 100644
--- a/clang/test/CodeGen/tbaa-pointers.c
+++ b/clang/test/CodeGen/tbaa-pointers.c
@@ -194,12 +194,11 @@ typedef struct {
 // types in C.
 void unamed_struct_typedef(TypedefS *ptr) {
 // COMMON-LABEL: define void @unamed_struct_typedef(
-// COMMON-SAME: ptr noundef %ptr)
-// COMMON-NEXT: entry:
-// COMMON-NEXT:   [[PTR_ADDR:%.+]]  = alloca ptr, align 8
-// DEFAULT-NEXT:  store ptr %ptr, ptr [[PTR_ADDR]], align 8, !tbaa [[ANYPTR]]
+// COMMON-SAME: ptr noundef [[PTRA:%.+]])
+// COMMON:   [[PTR_ADDR:%.+]]  = alloca ptr, align 8
+// DEFAULT-NEXT:  store ptr [[PTRA]], ptr [[PTR_ADDR]], align 8, !tbaa 
[[ANYPTR]]
 // DEFAULT-NEXT:  [[L0:%.+]] = load ptr, ptr  [[PTR_ADDR]], align 8, !tbaa  
[[ANYPTR]]
-// ENABLED-NEXT:  store ptr %ptr, ptr [[PTR_ADDR]], align 8, !tbaa 
[[P1TYPEDEF:!.+]]
+// ENABLED-NEXT:  store ptr [[PTRA]], ptr [[PTR_ADDR]], align 8, !tbaa 
[[P1TYPEDEF:!.+]]
 // ENABLED-NEXT:  [[L0:%.+]] = load ptr, ptr [[PTR_ADDR]], align 8, !tbaa  
[[P1TYPEDEF]]
 // COMMON-NEXT:   [[GEP:%.+]]  = getelementptr inbounds nuw %struct.TypedefS, 
ptr [[L0]], i32 0, i32 0
 // COMMON-NEXT:   store i32 0, ptr [[GEP]], align 4



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


[clang] [llvm] [HLSL] Adding Flatten and Branch if attributes (PR #116331)

2024-11-18 Thread Nikita Popov via cfe-commits


@@ -53,3 +53,6 @@ LLVM_FIXED_MD_KIND(MD_DIAssignID, "DIAssignID", 38)
 LLVM_FIXED_MD_KIND(MD_coro_outside_frame, "coro.outside.frame", 39)
 LLVM_FIXED_MD_KIND(MD_mmra, "mmra", 40)
 LLVM_FIXED_MD_KIND(MD_noalias_addrspace, "noalias.addrspace", 41)
+// TODO: this will likelly be placed somewhere else,
+// so we don't mix dxil/hlsl/spirv and clang metadata
+LLVM_FIXED_MD_KIND(MD_dxil_controlflow_hints, "dx.controlflow.hints", 42)

nikic wrote:

We already have `!unpredictable` and `!prof` metadata serving a fairly similar 
purpose from an optimization perspective. I'd be concerned about adding another 
generic metadata that has overlapping purpose -- essentially "flatten" should 
be treated like `!unpredictable` and "branch" like a strongly predicted `!prof` 
where we don't know in which direction the prediction is. There was a proposal 
for `!consistent` metadata 
(https://discourse.llvm.org/t/rfc-consistent-branches-support-in-llvm/74889) to 
encode that. At the time there was no consensus to introduce it.

So if you wanted to keep this generic, I'd consider the direction of 
`!unpredictable` and `!consistent`. But if all you're doing is passing through 
to the backend, then just doing target-specific metadata is fine (though you 
really shouldn't be touching any files in IR when doing that).

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


[clang-tools-extra] [clang-tidy] Enhance modernize-use-starts-ends-with to handle substr patterns (PR #116033)

2024-11-18 Thread Nicolas van Kempen via cfe-commits

https://github.com/nicovank commented:

Looks good minus nits and IMO ignore any macro issues as commented.

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


[clang] 0c42168 - AMDGPU: Add first gfx950 mfma instructions (#116312)

2024-11-18 Thread via cfe-commits

Author: Matt Arsenault
Date: 2024-11-18T13:38:07-08:00
New Revision: 0c421687f897b530a0fd3481fa03a2d29fd0b97c

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

LOG: AMDGPU: Add first gfx950 mfma instructions (#116312)

Scheduling info and hazards are wrong and TBD.

Added: 
clang/test/SemaOpenCL/builtins-amdgcn-error-gfx950-param.cl
clang/test/SemaOpenCL/builtins-amdgcn-error-gfx950.cl
llvm/test/CodeGen/AMDGPU/llvm.amdgcn.mfma.gfx950.ll
llvm/test/MC/AMDGPU/mai-gfx950.s
llvm/test/MC/Disassembler/AMDGPU/gfx950_mai.txt
llvm/test/tools/llvm-mca/AMDGPU/gfx950.s

Modified: 
clang/include/clang/Basic/BuiltinsAMDGPU.def
clang/test/CodeGenOpenCL/builtins-amdgcn-mfma.cl
llvm/include/llvm/IR/IntrinsicsAMDGPU.td
llvm/lib/Target/AMDGPU/AMDGPU.td
llvm/lib/Target/AMDGPU/AMDGPURegisterBankInfo.cpp
llvm/lib/Target/AMDGPU/AMDGPUSearchableTables.td
llvm/lib/Target/AMDGPU/GCNSubtarget.h
llvm/lib/Target/AMDGPU/SIInstrInfo.td
llvm/lib/Target/AMDGPU/VOP3PInstructions.td
llvm/test/Analysis/UniformityAnalysis/AMDGPU/intrinsics.ll

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def 
b/clang/include/clang/Basic/BuiltinsAMDGPU.def
index 61516eb2a4a723..6917d8d1aca69d 100644
--- a/clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -431,6 +431,12 @@ TARGET_BUILTIN(__builtin_amdgcn_cvt_pk_fp8_f32, "iffiIb", 
"nc", "fp8-conversion-
 TARGET_BUILTIN(__builtin_amdgcn_cvt_sr_bf8_f32, "ifiiIi", "nc", 
"fp8-conversion-insts")
 TARGET_BUILTIN(__builtin_amdgcn_cvt_sr_fp8_f32, "ifiiIi", "nc", 
"fp8-conversion-insts")
 
+//===--===//
+// GFX950 only builtins.
+//===--===//
+TARGET_BUILTIN(__builtin_amdgcn_mfma_f32_16x16x32_f16, "V4fV8hV8hV4fIiIiIi", 
"nc", "gfx950-insts")
+TARGET_BUILTIN(__builtin_amdgcn_mfma_f32_32x32x16_f16, "V16fV8hV8hV16fIiIiIi", 
"nc", "gfx950-insts")
+
 
//===--===//
 // GFX12+ only builtins.
 
//===--===//

diff  --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-mfma.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-mfma.cl
index dcdeee6b6acc40..a644a60f9ec381 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn-mfma.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-mfma.cl
@@ -2,6 +2,7 @@
 // RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx908 
-DMFMA_GFX908_TESTS -emit-llvm -o - %s | FileCheck %s 
--check-prefix=CHECK-GFX908
 // RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx90a 
-DMFMA_GFX90A_TESTS -emit-llvm -o - %s | FileCheck %s 
--check-prefix=CHECK-GFX90A
 // RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx940 
-DMFMA_GFX940_TESTS -emit-llvm -o - %s | FileCheck %s 
--check-prefix=CHECK-GFX940
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx950 
-DMFMA_GFX950_TESTS -emit-llvm -o - %s | FileCheck %s 
--check-prefix=CHECK-GFX950
 
 #pragma OPENCL EXTENSION cl_khr_fp64:enable
 
@@ -222,7 +223,7 @@ void test_mfma_f64_4x4x4f64(global double* out, double a, 
double b, double c)
 
 #endif // MFMA_GFX90A_TESTS
 
-#ifdef MFMA_GFX940_TESTS
+#if defined(MFMA_GFX940_TESTS) || defined(MFMA_GFX950_TESTS)
 // CHECK-GFX940-LABEL: @test_mfma_i32_16x16x32_i8
 // CHECK-GFX940: call <4 x i32> @llvm.amdgcn.mfma.i32.16x16x32.i8(i64 %a, i64 
%b, <4 x i32> %c, i32 0, i32 0, i32 0)
 void test_mfma_i32_16x16x32_i8(global v4i* out, long a, long b, v4i c)
@@ -404,4 +405,24 @@ void test_smfmac_f32_32x32x32_fp8_fp8(global v16f* out, 
v2i a, v4i b, v16f c, in
 {
   *out = __builtin_amdgcn_smfmac_f32_32x32x32_fp8_fp8(a, b, c, idx, 0, 0);
 }
-#endif // MFMA_GFX940_TESTS
+#endif // defined(MFMA_GFX940_TESTS) || defined(MFMA_GFX950_TESTS)
+
+#ifdef MFMA_GFX950_TESTS
+
+// CHECK-GFX950-LABEL: @test_mfma_f32_16x16x32_f16(
+// CHECK-GFX950: tail call <4 x float> @llvm.amdgcn.mfma.f32.16x16x32.f16(<8 x 
half> %a, <8 x half> %b, <4 x float> %c, i32 1, i32 2, i32 3)
+
+v4f test_mfma_f32_16x16x32_f16(v8h a, v8h b, v4f c)
+{
+  return __builtin_amdgcn_mfma_f32_16x16x32_f16(a, b, c, 1, 2, 3);
+}
+
+// CHECK-GFX950-LABEL: @test_mfma_f32_32x32x16_f16
+// CHECK-GFX950: tail call <16 x float> @llvm.amdgcn.mfma.f32.32x32x16.f16(<8 
x half> %a, <8 x half> %b, <16 x float> %c, i32 1, i32 2, i32 3)
+v16f test_mfma_f32_32x32x16_f16(v8h a, v8h b, v16f c)
+{
+  return __builtin_amdgcn_mfma_f32_32x32x16_f16(a, b, c, 1, 2, 3);
+}
+
+
+#endif

diff  --git a/clang/test/SemaOpenCL/builtins-amdgcn-error-gfx950-param.cl 
b/clang/test/SemaOpenCL/builtins-amdgcn-error-gfx950-param.cl
new file mode 100644

[clang] [llvm] AMDGPU: Add first gfx950 mfma instructions (PR #116312)

2024-11-18 Thread Matt Arsenault via cfe-commits

https://github.com/arsenm updated 
https://github.com/llvm/llvm-project/pull/116312

>From d5a560bccbc2ea5ed6c5f3bde740ace8feeb28c7 Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Tue, 21 Nov 2023 10:03:19 +0900
Subject: [PATCH] AMDGPU: Add first gfx950 mfma instructions

Scheduling info and hazards are wrong and TBD.
---
 clang/include/clang/Basic/BuiltinsAMDGPU.def  |   6 +
 .../CodeGenOpenCL/builtins-amdgcn-mfma.cl |  25 +-
 .../builtins-amdgcn-error-gfx950-param.cl |  21 ++
 .../builtins-amdgcn-error-gfx950.cl   |  12 +
 llvm/include/llvm/IR/IntrinsicsAMDGPU.td  |   9 +
 llvm/lib/Target/AMDGPU/AMDGPU.td  |   4 +
 .../Target/AMDGPU/AMDGPURegisterBankInfo.cpp  |   4 +-
 .../Target/AMDGPU/AMDGPUSearchableTables.td   |   2 +
 llvm/lib/Target/AMDGPU/GCNSubtarget.h |   4 +
 llvm/lib/Target/AMDGPU/SIInstrInfo.td |   4 +
 llvm/lib/Target/AMDGPU/VOP3PInstructions.td   |  22 ++
 .../UniformityAnalysis/AMDGPU/intrinsics.ll   |  17 ++
 .../CodeGen/AMDGPU/llvm.amdgcn.mfma.gfx950.ll | 274 ++
 llvm/test/MC/AMDGPU/mai-gfx950.s  | 112 +++
 .../MC/Disassembler/AMDGPU/gfx950_mai.txt |  61 
 llvm/test/tools/llvm-mca/AMDGPU/gfx950.s  |  18 ++
 16 files changed, 592 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/SemaOpenCL/builtins-amdgcn-error-gfx950-param.cl
 create mode 100644 clang/test/SemaOpenCL/builtins-amdgcn-error-gfx950.cl
 create mode 100644 llvm/test/CodeGen/AMDGPU/llvm.amdgcn.mfma.gfx950.ll
 create mode 100644 llvm/test/MC/AMDGPU/mai-gfx950.s
 create mode 100644 llvm/test/MC/Disassembler/AMDGPU/gfx950_mai.txt
 create mode 100644 llvm/test/tools/llvm-mca/AMDGPU/gfx950.s

diff --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def 
b/clang/include/clang/Basic/BuiltinsAMDGPU.def
index 61516eb2a4a723..6917d8d1aca69d 100644
--- a/clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -431,6 +431,12 @@ TARGET_BUILTIN(__builtin_amdgcn_cvt_pk_fp8_f32, "iffiIb", 
"nc", "fp8-conversion-
 TARGET_BUILTIN(__builtin_amdgcn_cvt_sr_bf8_f32, "ifiiIi", "nc", 
"fp8-conversion-insts")
 TARGET_BUILTIN(__builtin_amdgcn_cvt_sr_fp8_f32, "ifiiIi", "nc", 
"fp8-conversion-insts")
 
+//===--===//
+// GFX950 only builtins.
+//===--===//
+TARGET_BUILTIN(__builtin_amdgcn_mfma_f32_16x16x32_f16, "V4fV8hV8hV4fIiIiIi", 
"nc", "gfx950-insts")
+TARGET_BUILTIN(__builtin_amdgcn_mfma_f32_32x32x16_f16, "V16fV8hV8hV16fIiIiIi", 
"nc", "gfx950-insts")
+
 
//===--===//
 // GFX12+ only builtins.
 
//===--===//
diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-mfma.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-mfma.cl
index dcdeee6b6acc40..a644a60f9ec381 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn-mfma.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-mfma.cl
@@ -2,6 +2,7 @@
 // RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx908 
-DMFMA_GFX908_TESTS -emit-llvm -o - %s | FileCheck %s 
--check-prefix=CHECK-GFX908
 // RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx90a 
-DMFMA_GFX90A_TESTS -emit-llvm -o - %s | FileCheck %s 
--check-prefix=CHECK-GFX90A
 // RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx940 
-DMFMA_GFX940_TESTS -emit-llvm -o - %s | FileCheck %s 
--check-prefix=CHECK-GFX940
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx950 
-DMFMA_GFX950_TESTS -emit-llvm -o - %s | FileCheck %s 
--check-prefix=CHECK-GFX950
 
 #pragma OPENCL EXTENSION cl_khr_fp64:enable
 
@@ -222,7 +223,7 @@ void test_mfma_f64_4x4x4f64(global double* out, double a, 
double b, double c)
 
 #endif // MFMA_GFX90A_TESTS
 
-#ifdef MFMA_GFX940_TESTS
+#if defined(MFMA_GFX940_TESTS) || defined(MFMA_GFX950_TESTS)
 // CHECK-GFX940-LABEL: @test_mfma_i32_16x16x32_i8
 // CHECK-GFX940: call <4 x i32> @llvm.amdgcn.mfma.i32.16x16x32.i8(i64 %a, i64 
%b, <4 x i32> %c, i32 0, i32 0, i32 0)
 void test_mfma_i32_16x16x32_i8(global v4i* out, long a, long b, v4i c)
@@ -404,4 +405,24 @@ void test_smfmac_f32_32x32x32_fp8_fp8(global v16f* out, 
v2i a, v4i b, v16f c, in
 {
   *out = __builtin_amdgcn_smfmac_f32_32x32x32_fp8_fp8(a, b, c, idx, 0, 0);
 }
-#endif // MFMA_GFX940_TESTS
+#endif // defined(MFMA_GFX940_TESTS) || defined(MFMA_GFX950_TESTS)
+
+#ifdef MFMA_GFX950_TESTS
+
+// CHECK-GFX950-LABEL: @test_mfma_f32_16x16x32_f16(
+// CHECK-GFX950: tail call <4 x float> @llvm.amdgcn.mfma.f32.16x16x32.f16(<8 x 
half> %a, <8 x half> %b, <4 x float> %c, i32 1, i32 2, i32 3)
+
+v4f test_mfma_f32_16x16x32_f16(v8h a, v8h b, v4f c)
+{
+  return __builtin_amdgcn_mfma_f32_16x16x32_f16(a, b, c, 1, 2, 3);
+}
+
+// CHECK-GFX950-LABEL: @test_mfma_f32_32x32x16_f16
+// CHECK-GFX950: tail call <16 x float> @llvm.amdgcn.mfma.f32.32x32

[clang] e44c28f - [clang] Replace "can't" and "can not" in diagnostics with "cannot" (#116623)

2024-11-18 Thread via cfe-commits

Author: Krzysztof Parzyszek
Date: 2024-11-18T15:28:17-06:00
New Revision: e44c28f07ede2bd693e2372317880f57a635fa73

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

LOG: [clang] Replace "can't" and "can not" in diagnostics with "cannot" 
(#116623)

See
https://discourse.llvm.org/t/cant-cannot-can-not-in-diagnostic-messages/83171

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticCommonKinds.td
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/include/clang/Basic/DiagnosticRefactoringKinds.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/test/CodeGen/PowerPC/musttail-forward-declaration-inline.c
clang/test/CodeGen/PowerPC/musttail-forward-declaration-weak.c
clang/test/CodeGen/PowerPC/musttail-indirect.cpp
clang/test/CodeGen/PowerPC/musttail-inline.c
clang/test/CodeGen/PowerPC/musttail-undefined.c
clang/test/CodeGen/PowerPC/musttail-weak.c
clang/test/CodeGen/PowerPC/musttail.c
clang/test/CodeGen/X86/x86_64-PR42672.c
clang/test/Driver/module-output.cppm
clang/test/Misc/pragma-attribute-strict-subjects.c
clang/test/Modules/no-eager-load.cppm
clang/test/Modules/same-decl-in-different-modules.cppm
clang/test/OpenMP/for_simd_loop_messages.cpp
clang/test/OpenMP/masked_taskloop_simd_linear_messages.cpp
clang/test/OpenMP/master_taskloop_simd_linear_messages.cpp
clang/test/OpenMP/parallel_for_simd_loop_messages.cpp
clang/test/OpenMP/parallel_for_simd_messages.cpp
clang/test/OpenMP/parallel_masked_taskloop_simd_linear_messages.cpp
clang/test/OpenMP/parallel_master_taskloop_simd_linear_messages.cpp
clang/test/OpenMP/simd_linear_messages.cpp
clang/test/OpenMP/target_parallel_for_simd_ordered_messages.cpp
clang/test/OpenMP/taskloop_simd_linear_messages.cpp
clang/test/Parser/pragma-attribute.cpp
clang/test/Refactor/Extract/ObjCProperty.m
clang/test/Sema/asm.c
clang/test/Sema/pragma-attribute-strict-subjects.c
clang/test/SemaObjC/comptypes-legal.m
clang/test/SemaOpenCL/access-qualifier.cl

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index 0c131166aff28d..f4a155bb00bb37 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -364,9 +364,9 @@ def err_target_unsupported_abi_with_fpu : Error<
 
 def err_ppc_impossible_musttail: Error<
   "'musttail' attribute for this call is impossible because %select{"
-  "long calls can not be tail called on PPC|"
-  "indirect calls can not be tail called on PPC|"
-  "external calls can not be tail called on PPC}0"
+  "long calls cannot be tail called on PPC|"
+  "indirect calls cannot be tail called on PPC|"
+  "external calls cannot be tail called on PPC}0"
   >;
 def err_aix_musttail_unsupported: Error<
   "'musttail' attribute is not supported on AIX">;

diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 76fdbdbfb01d94..5155b23d151c04 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -553,7 +553,7 @@ def err_test_module_file_extension_format : Error<
   "'blockname:major:minor:hashed:user info'">;
 
 def err_drv_module_output_with_multiple_arch : Error<
-  "option '-fmodule-output' can't be used with multiple arch options">;
+  "option '-fmodule-output' cannot be used with multiple arch options">;
 
 def warn_drv_delayed_template_parsing_after_cxx20 : Warning<
   "-fdelayed-template-parsing is deprecated after C++20">,

diff  --git a/clang/include/clang/Basic/DiagnosticRefactoringKinds.td 
b/clang/include/clang/Basic/DiagnosticRefactoringKinds.td
index 5446b32efbdd47..e060fffc7280a7 100644
--- a/clang/include/clang/Basic/DiagnosticRefactoringKinds.td
+++ b/clang/include/clang/Basic/DiagnosticRefactoringKinds.td
@@ -14,7 +14,7 @@ let Component = "Refactoring" in {
 
 let CategoryName = "Refactoring Invocation Issue" in {
 
-def err_refactor_no_selection : Error<"refactoring action can't be initiated "
+def err_refactor_no_selection : Error<"refactoring action cannot be initiated "
   "without a selection">;
 def err_refactor_selection_no_symbol : Error<"there is no symbol at the given "
   "location">;
@@ -26,7 +26,7 @@ def err_refactor_code_outside_of_function : Error<"the 
selected code is not a "
 def err_refactor_extract_simple_expression : Error<"the selected expression "
   "is too simple to extract">;
 def err_refactor_extract_prohibited_expression : Error<"the selected "
-  "expression can't be extracted">;
+  "expression cannot be extracted">;
 
 }
 

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKi

[clang] [clang] Replace "can't" and "can not" in diagnostics with "cannot" (PR #116623)

2024-11-18 Thread Krzysztof Parzyszek via cfe-commits

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


[clang] Reland "[clang] Add nuw attribute to GEPs (#105496)" (PR #107257)

2024-11-18 Thread Sam Clegg via cfe-commits

sbc100 wrote:

I bisecting this emscripten (wasm32-unknown-emscripten) miscompile to this PR: 
https://github.com/emscripten-core/emscripten/issues/22794.

It looks like llvm is generating a load with a negative office (which is not 
supported under wasm).   There is a reproducer in that but and I used the 
following commend to detect the bad load:

```
$ clang++ --target=wasm32-unknown-emscripten -std=c++20 -O2 -c 
3.1.71_temps/GltfImporter.ii && wasm-objdump -d GltfImporter.o | grep 
i64.load.*4294967280
 01c4a3: 29 02 f0 ff ff ff 0f   |   i64.load 2 4294967280
```

Here you can see an i64.load instruction with an offset of 4294967280 (which is 
-16 interpreted as an unsigned int).


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


[clang] [analyzer] [MallocChecker] Less aggressive analysis of functions (PR #116383)

2024-11-18 Thread Balazs Benics via cfe-commits

steakhal wrote:

Hi, thanks for the report. This is the intended behavior AFAICT.
My question is, why would you ever pass a dangling pointer to a function? I 
can't think of a valid use-case for doing that. They could just pass a 
null-pointer if they really wanted.
Am I missing something?

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


  1   2   3   4   5   >