[clang] [clang-format]: Add `Custom` to `ShortFunctionStyle`; add new AllowShortFunctionsOnASingleLineOptions for granular setup (PR #134337)

2025-04-12 Thread via cfe-commits

https://github.com/irymarchyk updated 
https://github.com/llvm/llvm-project/pull/134337

>From df25a8bbfd827085265c51a44bedbf38deebbab4 Mon Sep 17 00:00:00 2001
From: Ivan Rymarchyk <>
Date: Sat, 29 Mar 2025 13:54:32 -0700
Subject: [PATCH 1/5] [clang-format]: Add `Custom` to `ShortFunctionStyle`; add
 new AllowShortFunctionsOnASingleLineOptions for granular setup
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The current clang-format configuration option AllowShortFunctionsOnASingleLine 
uses a single enum (ShortFunctionStyle) to control when short function 
definitions can be merged onto a single line. This enum provides predefined 
combinations of conditions (e.g., None, Empty only, Inline only, Inline 
including Empty, All).

This approach has limitations:

1. **Lack of Granularity:** Users cannot specify arbitrary combinations of 
conditions. For example, a user might want to allow merging for both empty 
functions and short top-level functions, but not for short functions defined 
within classes. This is not possible with the current enum options except by 
choosing All, which might merge more than desired.

2. **Inflexibility:** Adding new conditions for merging (e.g., distinguishing 
between member functions and constructors, handling lambdas specifically) would 
require adding many new combined enum values, leading to a combinatorial 
explosion and making the configuration complex.

3. **Implicit Behavior:** Some options imply others (e.g., Inline implies 
Empty), which might not always be intuitive or desired.

The goal is to replace this single-choice enum with a more flexible mechanism 
allowing users to specify a set of conditions that must be met for a short 
function to be merged onto a single line.

**Proposed Solution**

1. Introduce a new configuration option: AllowShortFunctionsOnSingleLineOptions.

2. This option will accept a list of strings, where each string represents a 
specific condition allowing merging.

3. **Backward Compatibility:**

- If AllowShortFunctionsOnSingleLineOptions is present in the 
configuration, it takes precedence.

- If AllowShortFunctionsOnSingleLineOptions is not present, but the old 
AllowShortFunctionsOnASingleLine is present, the old option should be parsed 
and mapped to the corresponding new semantics for compatibility.
---
 clang/docs/ClangFormatStyleOptions.rst  |  64 +++
 clang/include/clang/Format/Format.h |  70 
 clang/lib/Format/Format.cpp |  52 +
 clang/lib/Format/TokenAnnotator.cpp |   7 +-
 clang/lib/Format/UnwrappedLineFormatter.cpp |   9 +-
 clang/unittests/Format/ConfigParseTest.cpp  |   6 ++
 clang/unittests/Format/FormatTest.cpp   | 111 
 7 files changed, 310 insertions(+), 9 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 9ecac68ae72bf..167701cf6585d 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -1959,6 +1959,70 @@ the configuration (without a prefix: ``Auto``).
   };
   void f() { bar(); }
 
+  * ``SFS_Custom`` (in configuration: ``Custom``)
+Configure merge behavior using AllowShortFunctionsOnASingleLineOptions
+
+
+
+.. _AllowShortFunctionsOnASingleLineOptions:
+
+**AllowShortFunctionsOnASingleLineOptions** (``ShortFunctionMergeFlags``) 
:versionbadge:`clang-format 21` :ref:`¶ 
`
+  Precise control over merging short functions
+
+  If ``AllowShortFunctionsOnASingleLine`` is set to ``Custom``, use this to
+  specify behavior in different situations.
+
+  .. code-block:: yaml
+
+# Example of usage:
+AllowShortFunctionsOnASingleLine: Custom
+AllowShortFunctionsOnASingleLineOptions:
+  Empty: false
+  Inline: true
+  All: false
+
+  Nested configuration flags:
+
+  Precise control over merging short functions
+
+  .. code-block:: c++
+
+# Should be declared this way:
+AllowShortFunctionsOnASingleLine: Custom
+AllowShortFunctionsOnASingleLineOptions:
+  Empty: false
+  Inline: true
+  All: false
+
+  * ``bool Empty`` Only merge empty functions.
+
+.. code-block:: c++
+
+  void f() {}
+  void f2() {
+bar2();
+  }
+
+  * ``bool Inline`` Only merge functions defined inside a class.
+
+.. code-block:: c++
+
+  class Foo {
+void f() { foo(); }
+  };
+  void f() {
+foo();
+  }
+  void f() {}
+
+  * ``bool All`` Merge all functions fitting on a single line.
+
+.. code-block:: c++
+
+  class Foo {
+void f() { foo(); }
+  };
+  void f() { bar(); }
 
 
 .. _AllowShortIfStatementsOnASingleLine:
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index fec47a248abb4..96b1ecab04e63 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -871,6 +871,8 @@ struct FormatStyle {
 /

[libunwind] [libunwind][Haiku] Fix signal frame unwinding (PR #135367)

2025-04-12 Thread via cfe-commits


@@ -3032,6 +2983,162 @@ int UnwindCursor::stepThroughSigReturn(Registers_s390x &) {
 #endif // defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN) &&
// defined(_LIBUNWIND_TARGET_S390X)
 
+#if defined(_LIBUNWIND_CHECK_HAIKU_SIGRETURN)
+
+#if defined(B_HAIKU_32_BIT)
+typedef Elf32_Sym elf_sym;
+#define ELF_ST_TYPE ELF32_ST_TYPE
+#elif defined(B_HAIKU_64_BIT)
+typedef Elf64_Sym elf_sym;
+#define ELF_ST_TYPE ELF64_ST_TYPE
+#endif
+
+// Private syscall declared as a weak symbol to prevent ABI breaks.

X547 wrote:

Maybe it is better and simpler to provide syscall address and size in commpage 
entries.

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


[libunwind] [libunwind][Haiku] Fix signal frame unwinding (PR #135367)

2025-04-12 Thread via cfe-commits

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


[libunwind] [libunwind][Haiku] Fix signal frame unwinding (PR #135367)

2025-04-12 Thread Trung Nguyen via cfe-commits


@@ -3032,6 +2983,162 @@ int UnwindCursor::stepThroughSigReturn(Registers_s390x &) {
 #endif // defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN) &&
// defined(_LIBUNWIND_TARGET_S390X)
 
+#if defined(_LIBUNWIND_CHECK_HAIKU_SIGRETURN)
+
+#if defined(B_HAIKU_32_BIT)
+typedef Elf32_Sym elf_sym;
+#define ELF_ST_TYPE ELF32_ST_TYPE
+#elif defined(B_HAIKU_64_BIT)
+typedef Elf64_Sym elf_sym;
+#define ELF_ST_TYPE ELF64_ST_TYPE
+#endif
+
+// Private syscall declared as a weak symbol to prevent ABI breaks.

trungnt2910 wrote:

> provide signal handler address and size in commpage entries.

But `commpage` entries are private ABIs, aren't they?

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


[clang] [clang-format]: Add `Custom` to `ShortFunctionStyle`; add new AllowShortFunctionsOnASingleLineOptions for granular setup (PR #134337)

2025-04-12 Thread via cfe-commits

irymarchyk wrote:

Sorry, I forgot to push latest changes

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


[libunwind] [libunwind][Haiku] Fix signal frame unwinding (PR #135367)

2025-04-12 Thread Trung Nguyen via cfe-commits


@@ -3032,6 +2983,162 @@ int UnwindCursor::stepThroughSigReturn(Registers_s390x &) {
 #endif // defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN) &&
// defined(_LIBUNWIND_TARGET_S390X)
 
+#if defined(_LIBUNWIND_CHECK_HAIKU_SIGRETURN)
+
+#if defined(B_HAIKU_32_BIT)
+typedef Elf32_Sym elf_sym;
+#define ELF_ST_TYPE ELF32_ST_TYPE
+#elif defined(B_HAIKU_64_BIT)
+typedef Elf64_Sym elf_sym;
+#define ELF_ST_TYPE ELF64_ST_TYPE
+#endif
+
+// Private syscall declared as a weak symbol to prevent ABI breaks.

trungnt2910 wrote:

> If this is getting upstreamed we should really export this symbol not as a 
> syscall so we can avoid ABI breaks.

Just like in the [GDB 
port](https://www.haiku-os.org/blog/trungnt2910/2024-07-28_gsoc_2024_debugging_progress_2/#private-syscalls),
 if the syscall disappears the function will silently fail, and other normal 
unwinding can still happen as usual.

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


[libunwind] [libunwind][Haiku] Fix signal frame unwinding (PR #135367)

2025-04-12 Thread Trung Nguyen via cfe-commits


@@ -3032,6 +2983,162 @@ int UnwindCursor::stepThroughSigReturn(Registers_s390x &) {
 #endif // defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN) &&
// defined(_LIBUNWIND_TARGET_S390X)
 
+#if defined(_LIBUNWIND_CHECK_HAIKU_SIGRETURN)
+
+#if defined(B_HAIKU_32_BIT)
+typedef Elf32_Sym elf_sym;
+#define ELF_ST_TYPE ELF32_ST_TYPE
+#elif defined(B_HAIKU_64_BIT)
+typedef Elf64_Sym elf_sym;
+#define ELF_ST_TYPE ELF64_ST_TYPE
+#endif
+
+// Private syscall declared as a weak symbol to prevent ABI breaks.
+extern "C" status_t __attribute__((weak))
+_kern_read_kernel_image_symbols(image_id id, elf_sym *symbolTable,
+int32 *_symbolCount, char *stringTable,
+size_t *_stringTableSize, addr_t *_imageDelta);
+
+static addr_t signalHandlerBegin = 0;
+static addr_t signalHandlerEnd = 0;
+
+template 
+bool UnwindCursor::setInfoForSigReturn() {
+  if (signalHandlerBegin == 0) {
+// If we do not have the addresses yet, find them now.
+
+// Determine if the private function is there and usable.
+if (_kern_read_kernel_image_symbols == nullptr) {
+  signalHandlerBegin = (addr_t)-1;
+  return false;
+}
+
+// Get the system commpage and enumerate its symbols.
+image_id commpageImage = -1;
+image_info info;
+int32 cookie = 0;
+while (get_next_image_info(B_SYSTEM_TEAM, &cookie, &info) == B_OK) {

trungnt2910 wrote:

That'd require some kernel side changes, wouldn't that?

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


[clang-tools-extra] 0681483 - [clang-tidy] treat unsigned char and signed char as char type by default in bugprone-unintended-char-ostream-output (#134870)

2025-04-12 Thread via cfe-commits

Author: Congcong Cai
Date: 2025-04-13T12:09:50+08:00
New Revision: 06814834a63139ff27efe3bdbc6dc15d4b39

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

LOG: [clang-tidy] treat unsigned char and signed char as char type by default 
in bugprone-unintended-char-ostream-output (#134870)

Add `AllowedTypes` options to support custom defined char like type.
treat `unsigned char` and `signed char` as char like type by default.
The allowed types only effect when the var decl or explicit cast to this
non-canonical type names.

Fixed: #133425

Added: 

clang-tools-extra/test/clang-tidy/checkers/bugprone/unintended-char-ostream-output-allowed-types.cpp

Modified: 
clang-tools-extra/clang-tidy/bugprone/UnintendedCharOstreamOutputCheck.cpp
clang-tools-extra/clang-tidy/bugprone/UnintendedCharOstreamOutputCheck.h

clang-tools-extra/docs/clang-tidy/checks/bugprone/unintended-char-ostream-output.rst

clang-tools-extra/test/clang-tidy/checkers/bugprone/unintended-char-ostream-output-cast-type.cpp

clang-tools-extra/test/clang-tidy/checkers/bugprone/unintended-char-ostream-output.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/bugprone/UnintendedCharOstreamOutputCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/UnintendedCharOstreamOutputCheck.cpp
index 7250e4ccb8c69..57e1f744fcd7d 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UnintendedCharOstreamOutputCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UnintendedCharOstreamOutputCheck.cpp
@@ -7,6 +7,8 @@
 
//===--===//
 
 #include "UnintendedCharOstreamOutputCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
 #include "clang/AST/Type.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
@@ -35,10 +37,14 @@ AST_MATCHER(Type, isChar) {
 
 UnintendedCharOstreamOutputCheck::UnintendedCharOstreamOutputCheck(
 StringRef Name, ClangTidyContext *Context)
-: ClangTidyCheck(Name, Context), CastTypeName(Options.get("CastTypeName")) 
{
-}
+: ClangTidyCheck(Name, Context),
+  AllowedTypes(utils::options::parseStringList(
+  Options.get("AllowedTypes", "unsigned char;signed char"))),
+  CastTypeName(Options.get("CastTypeName")) {}
 void UnintendedCharOstreamOutputCheck::storeOptions(
 ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "AllowedTypes",
+utils::options::serializeStringList(AllowedTypes));
   if (CastTypeName.has_value())
 Options.store(Opts, "CastTypeName", CastTypeName.value());
 }
@@ -50,13 +56,20 @@ void 
UnintendedCharOstreamOutputCheck::registerMatchers(MatchFinder *Finder) {
 // with char / unsigned char / signed char
 classTemplateSpecializationDecl(
 hasTemplateArgument(0, refersToType(isChar();
+  auto IsDeclRefExprFromAllowedTypes = declRefExpr(to(varDecl(
+  hasType(matchers::matchesAnyListedTypeName(AllowedTypes, false);
+  auto IsExplicitCastExprFromAllowedTypes = 
explicitCastExpr(hasDestinationType(
+  matchers::matchesAnyListedTypeName(AllowedTypes, false)));
   Finder->addMatcher(
   cxxOperatorCallExpr(
   hasOverloadedOperatorName("<<"),
   hasLHS(hasType(hasUnqualifiedDesugaredType(
   recordType(hasDeclaration(cxxRecordDecl(
   anyOf(BasicOstream, isDerivedFrom(BasicOstream,
-  hasRHS(hasType(hasUnqualifiedDesugaredType(isNumericChar()
+  hasRHS(expr(hasType(hasUnqualifiedDesugaredType(isNumericChar())),
+  unless(ignoringParenImpCasts(
+  anyOf(IsDeclRefExprFromAllowedTypes,
+IsExplicitCastExprFromAllowedTypes))
   .bind("x"),
   this);
 }

diff  --git 
a/clang-tools-extra/clang-tidy/bugprone/UnintendedCharOstreamOutputCheck.h 
b/clang-tools-extra/clang-tidy/bugprone/UnintendedCharOstreamOutputCheck.h
index 61ea623d139ea..0759e3d1eb460 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UnintendedCharOstreamOutputCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/UnintendedCharOstreamOutputCheck.h
@@ -30,6 +30,7 @@ class UnintendedCharOstreamOutputCheck : public 
ClangTidyCheck {
   }
 
 private:
+  const std::vector AllowedTypes;
   const std::optional CastTypeName;
 };
 

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/unintended-char-ostream-output.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/unintended-char-ostream-output.rst
index 95d02b3e2ddda..29254c4321f68 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/unintended-char-ostream-output.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/bugpro

[clang-tools-extra] [clang-tidy] treat unsigned char and signed char as char type by default in bugprone-unintended-char-ostream-output (PR #134870)

2025-04-12 Thread Congcong Cai via cfe-commits

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


[libunwind] [libunwind][Haiku] Fix signal frame unwinding (PR #135367)

2025-04-12 Thread Trung Nguyen via cfe-commits

trungnt2910 wrote:

Yes, tested on `x86_64` and only `x86_64` (though support for other archs can 
be added by as easy as defining a few offsets and registers). Requires Haiku 
`hrev58811` to fully work with `tests/signal_unwind.pass.cpp`.

This is also the same implementation used in my debugger ports for Haiku.

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


[clang] [llvm] [mlir] [NVPTX] Add support for Shared Cluster Memory address space. (PR #135444)

2025-04-12 Thread Alex MacLean via cfe-commits


@@ -982,8 +982,9 @@ void NVPTXDAGToDAGISel::SelectAddrSpaceCast(SDNode *N) {
 case ADDRESS_SPACE_SHARED:
   Opc = TM.is64Bit() ? NVPTX::cvta_shared_64 : NVPTX::cvta_shared;
   break;
-case ADDRESS_SPACE_DSHARED:
-  Opc = TM.is64Bit() ? NVPTX::cvta_dshared_64 : NVPTX::cvta_dshared;
+case ADDRESS_SPACE_SHARED_CLUSTER:
+  Opc = TM.is64Bit() ? NVPTX::cvta_shared_cluster_64
+ : NVPTX::cvta_shared_cluster;

AlexMaclean wrote:

My understanding is that cluster is not supported until sm_90, and that sm_90+ 
do not support 32bit compilation. Is there something I'm missing? If not we 
should never select the 32-bit version here and instead check to ensure we're 
compiling for sm_90+.

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


[clang] [llvm] [mlir] [NVPTX] Add support for Shared Cluster Memory address space. (PR #135444)

2025-04-12 Thread Alex MacLean via cfe-commits


@@ -2038,15 +2038,15 @@ multiclass F_ATOMIC_2_AS, 
preds>;
   defm _S : F_ATOMIC_2, 
preds>;
-  defm _DS : F_ATOMIC_2, !listconcat([hasSM<80>], preds)>;
+  defm _S_C : F_ATOMIC_2, !listconcat([hasSM<80>], preds)>;

AlexMaclean wrote:

The PTX doc seems to say this is supported only for sm_90 and ptx_78

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


[clang] [llvm] [mlir] [NVPTX] Add support for Shared Cluster Memory address space. (PR #135444)

2025-04-12 Thread Alex MacLean via cfe-commits


@@ -0,0 +1,258 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 5
+; RUN: llc < %s -o - -mcpu=sm_90 -march=nvptx64 -mattr=+ptx80 | FileCheck %s
+; RUN: %if ptxas-12.0 %{ llc < %s -mtriple=nvptx64 -mcpu=sm_90 -mattr=+ptx80| 
%ptxas-verify -arch=sm_90 %}

AlexMaclean wrote:

nit: the -march and -mtriple can be removed here.

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


[clang] [llvm] [mlir] [NVPTX] Add support for Shared Cluster Memory address space. (PR #135444)

2025-04-12 Thread Alex MacLean via cfe-commits


@@ -137,6 +137,7 @@ def hasAtomBitwise64 : 
Predicate<"Subtarget->hasAtomBitwise64()">;
 def hasAtomMinMax64 : Predicate<"Subtarget->hasAtomMinMax64()">;
 def hasVote : Predicate<"Subtarget->hasVote()">;
 def hasDouble : Predicate<"Subtarget->hasDouble()">;
+def hasClusters : Predicate<"Subtarget->hasClusters()">;

AlexMaclean wrote:

Is this actually getting used anywhere? If not please remove. 

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


[clang-tools-extra] [clang-doc] Pre-commit tests for static members and functions (PR #135456)

2025-04-12 Thread Paul Kirth via cfe-commits

ilovepi wrote:

### Merge activity

* **Apr 12, 1:52 PM EDT**: A user started a stack merge that includes this pull 
request via 
[Graphite](https://app.graphite.dev/github/pr/llvm/llvm-project/135456).


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


[clang] [llvm] [mlir] [NVPTX] Add support for Shared Cluster Memory address space. (PR #135444)

2025-04-12 Thread Alex MacLean via cfe-commits

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


[clang] [llvm] [mlir] [NVPTX] Add support for Shared Cluster Memory address space. (PR #135444)

2025-04-12 Thread Alex MacLean via cfe-commits


@@ -0,0 +1,258 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 5
+; RUN: llc < %s -o - -mcpu=sm_90 -march=nvptx64 -mattr=+ptx80 | FileCheck %s
+; RUN: %if ptxas-12.0 %{ llc < %s -mtriple=nvptx64 -mcpu=sm_90 -mattr=+ptx80| 
%ptxas-verify -arch=sm_90 %}
+
+target triple = "nvptx64-nvidia-cuda"
+
+@llvm.used = appending global [1 x ptr] [ptr 
@test_distributed_shared_cluster], section "llvm.metadata"
+
+declare ptr addrspace(7) @llvm.nvvm.mapa.shared.cluster(ptr addrspace(3), i32)
+declare i1 @llvm.nvvm.isspacep.shared.cluster(ptr)
+declare i32 @llvm.nvvm.read.ptx.sreg.ctaid.x()
+declare ptr @llvm.nvvm.mapa(ptr, i32)
+
+define i32 @test_distributed_shared_cluster(ptr %ptr, ptr addrspace(3) 
%smem_ptr) local_unnamed_addr {

AlexMaclean wrote:

Please break this up into more than one big function. Perhaps group some of the 
atomic cases together but otherwise each instruction/intrinsic should have it's 
own function. This will make the test easier to debug if something starts 
failing at some point.

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


[clang] [llvm] [mlir] [NVPTX] Add support for Shared Cluster Memory address space. (PR #135444)

2025-04-12 Thread Alex MacLean via cfe-commits


@@ -0,0 +1,258 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 5
+; RUN: llc < %s -o - -mcpu=sm_90 -march=nvptx64 -mattr=+ptx80 | FileCheck %s
+; RUN: %if ptxas-12.0 %{ llc < %s -mtriple=nvptx64 -mcpu=sm_90 -mattr=+ptx80| 
%ptxas-verify -arch=sm_90 %}
+
+target triple = "nvptx64-nvidia-cuda"
+
+@llvm.used = appending global [1 x ptr] [ptr 
@test_distributed_shared_cluster], section "llvm.metadata"
+
+declare ptr addrspace(7) @llvm.nvvm.mapa.shared.cluster(ptr addrspace(3), i32)
+declare i1 @llvm.nvvm.isspacep.shared.cluster(ptr)
+declare i32 @llvm.nvvm.read.ptx.sreg.ctaid.x()
+declare ptr @llvm.nvvm.mapa(ptr, i32)
+
+define i32 @test_distributed_shared_cluster(ptr %ptr, ptr addrspace(3) 
%smem_ptr) local_unnamed_addr {
+; CHECK-LABEL: test_distributed_shared_cluster(
+; CHECK:   {
+; CHECK-NEXT:.reg .pred %p<13>;
+; CHECK-NEXT:.reg .b16 %rs<5>;
+; CHECK-NEXT:.reg .b32 %r<69>;
+; CHECK-NEXT:.reg .f32 %f<2>;
+; CHECK-NEXT:.reg .b64 %rd<24>;
+; CHECK-NEXT:.reg .f64 %fd<2>;
+; CHECK-EMPTY:
+; CHECK-NEXT:  // %bb.0: // %entry
+; CHECK-NEXT:ld.param.u64 %rd2, [test_distributed_shared_cluster_param_0];
+; CHECK-NEXT:ld.param.u64 %rd3, [test_distributed_shared_cluster_param_1];
+; CHECK-NEXT:mov.u32 %r24, %ctaid.x;
+; CHECK-NEXT:xor.b32 %r25, %r24, 1;
+; CHECK-NEXT:isspacep.shared::cluster %p1, %rd2;
+; CHECK-NEXT:mapa.u64 %rd4, %rd2, %r25;
+; CHECK-NEXT:isspacep.shared::cluster %p2, %rd4;
+; CHECK-NEXT:mapa.shared::cluster.u64 %rd5, %rd3, %r25;
+; CHECK-NEXT:mov.b16 %rs1, 0x3C00;
+; CHECK-NEXT:atom.shared::cluster.add.noftz.f16 %rs2, [%rd5], %rs1;
+; CHECK-NEXT:mov.b16 %rs3, 0x3F80;
+; CHECK-NEXT:atom.shared::cluster.add.noftz.bf16 %rs4, [%rd5], %rs3;
+; CHECK-NEXT:atom.shared::cluster.add.f32 %f1, [%rd5], 0f3F80;
+; CHECK-NEXT:atom.shared::cluster.add.f64 %fd1, [%rd5], 0d3FF0;
+; CHECK-NEXT:atom.shared::cluster.add.u32 %r26, [%rd5], 1;
+; CHECK-NEXT:atom.shared::cluster.add.u64 %rd6, [%rd5], 1;
+; CHECK-NEXT:atom.shared::cluster.exch.b32 %r27, [%rd5], 1;
+; CHECK-NEXT:atom.shared::cluster.exch.b64 %rd7, [%rd5], 1;
+; CHECK-NEXT:atom.shared::cluster.min.s32 %r28, [%rd5], 1;
+; CHECK-NEXT:atom.shared::cluster.min.s64 %rd8, [%rd5], 1;
+; CHECK-NEXT:atom.shared::cluster.min.u32 %r29, [%rd5], 1;
+; CHECK-NEXT:atom.shared::cluster.min.u64 %rd9, [%rd5], 1;
+; CHECK-NEXT:atom.shared::cluster.max.s32 %r30, [%rd5], 1;
+; CHECK-NEXT:atom.shared::cluster.max.s64 %rd10, [%rd5], 1;
+; CHECK-NEXT:atom.shared::cluster.max.u32 %r31, [%rd5], 1;
+; CHECK-NEXT:atom.shared::cluster.max.u64 %rd11, [%rd5], 1;
+; CHECK-NEXT:atom.shared::cluster.inc.u32 %r32, [%rd5], 1;
+; CHECK-NEXT:atom.shared::cluster.dec.u32 %r33, [%rd5], 1;
+; CHECK-NEXT:atom.shared::cluster.and.b32 %r34, [%rd5], 1;
+; CHECK-NEXT:atom.shared::cluster.and.b64 %rd12, [%rd5], 1;
+; CHECK-NEXT:atom.shared::cluster.or.b32 %r35, [%rd5], 1;
+; CHECK-NEXT:atom.shared::cluster.or.b64 %rd13, [%rd5], 1;
+; CHECK-NEXT:atom.shared::cluster.xor.b32 %r36, [%rd5], 1;
+; CHECK-NEXT:atom.shared::cluster.xor.b64 %rd14, [%rd5], 1;
+; CHECK-NEXT:atom.relaxed.shared::cluster.cas.b32 %r37, [%rd5], 1, 0;
+; CHECK-NEXT:atom.acquire.shared::cluster.cas.b32 %r38, [%rd5], 1, 0;
+; CHECK-NEXT:atom.acquire.shared::cluster.cas.b32 %r39, [%rd5], 1, 0;
+; CHECK-NEXT:atom.release.shared::cluster.cas.b32 %r40, [%rd5], 1, 0;
+; CHECK-NEXT:atom.acq_rel.shared::cluster.cas.b32 %r41, [%rd5], 1, 0;
+; CHECK-NEXT:atom.acq_rel.shared::cluster.cas.b32 %r42, [%rd5], 1, 0;
+; CHECK-NEXT:fence.sc.sys;
+; CHECK-NEXT:atom.acquire.shared::cluster.cas.b32 %r43, [%rd5], 1, 0;
+; CHECK-NEXT:fence.sc.sys;
+; CHECK-NEXT:atom.acquire.shared::cluster.cas.b32 %r44, [%rd5], 1, 0;
+; CHECK-NEXT:fence.sc.sys;
+; CHECK-NEXT:atom.acquire.shared::cluster.cas.b32 %r45, [%rd5], 1, 0;
+; CHECK-NEXT:atom.relaxed.shared::cluster.cas.b64 %rd15, [%rd5], 1, 0;
+; CHECK-NEXT:atom.acquire.shared::cluster.cas.b64 %rd16, [%rd5], 1, 0;
+; CHECK-NEXT:atom.acquire.shared::cluster.cas.b64 %rd17, [%rd5], 1, 0;
+; CHECK-NEXT:atom.release.shared::cluster.cas.b64 %rd18, [%rd5], 1, 0;
+; CHECK-NEXT:atom.acq_rel.shared::cluster.cas.b64 %rd19, [%rd5], 1, 0;
+; CHECK-NEXT:atom.acq_rel.shared::cluster.cas.b64 %rd20, [%rd5], 1, 0;
+; CHECK-NEXT:fence.sc.sys;
+; CHECK-NEXT:atom.acquire.shared::cluster.cas.b64 %rd21, [%rd5], 1, 0;
+; CHECK-NEXT:fence.sc.sys;
+; CHECK-NEXT:atom.acquire.shared::cluster.cas.b64 %rd22, [%rd5], 1, 0;
+; CHECK-NEXT:fence.sc.sys;
+; CHECK-NEXT:atom.acquire.shared::cluster.cas.b64 %rd23, [%rd5], 1, 0;
+; CHECK-NEXT:and.b64 %rd1, %rd5, -4;
+; CHECK-NEXT:cvt.u32.u64 %r46, %rd5;
+; CHECK-NEXT:and.b32 %r47, %r46, 3;
+; CHECK-NEXT:shl.b32 %r1, %r47, 3;
+; CHECK-NEXT:mov.b

[clang] [llvm] [mlir] [NVPTX] Add support for Shared Cluster Memory address space. (PR #135444)

2025-04-12 Thread Alex MacLean via cfe-commits

https://github.com/AlexMaclean commented:

Backend changes look reasonable so far. One concern I have with this change is 
that until now we've assumed specific address-spaces are non-overlapping. 
You've addressed some of the places where this assumption is encoded but I 
think there are others you have not. For example, addrspacecasts between 
shared::cta and shared::cluster seem like they should be valid and should be 
expanded via a pair of cvta instructions through generic space, I think this 
would produce an error right now. I also wonder if InferAS or other places have 
made this assumption as well. 

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


[clang-tools-extra] [clang-doc] Handle static members and functions (PR #135457)

2025-04-12 Thread Paul Kirth via cfe-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/135457

>From 32f60cd27c9234fd945443e801f1788930b1cd57 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Mon, 7 Apr 2025 08:37:40 -0700
Subject: [PATCH 1/5] [clang-doc] Handle static members and functions

clang-doc didn't visit VarDecl, and hence never collected info
from class statics members and functions.

Fixes #59813.
---
 clang-tools-extra/clang-doc/Mapper.cpp|  4 ++
 clang-tools-extra/clang-doc/Mapper.h  |  1 +
 clang-tools-extra/clang-doc/Serialize.cpp | 56 +++
 clang-tools-extra/clang-doc/Serialize.h   |  4 ++
 .../test/clang-doc/basic-project.test | 13 -
 5 files changed, 77 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-doc/Mapper.cpp 
b/clang-tools-extra/clang-doc/Mapper.cpp
index 6c90db03424c6..98698f9151280 100644
--- a/clang-tools-extra/clang-doc/Mapper.cpp
+++ b/clang-tools-extra/clang-doc/Mapper.cpp
@@ -82,6 +82,10 @@ bool MapASTVisitor::VisitRecordDecl(const RecordDecl *D) {
   return mapDecl(D, D->isThisDeclarationADefinition());
 }
 
+bool MapASTVisitor::VisitVarDecl(const VarDecl *D) {
+  return mapDecl(D, D->isThisDeclarationADefinition());
+}
+
 bool MapASTVisitor::VisitEnumDecl(const EnumDecl *D) {
   return mapDecl(D, D->isThisDeclarationADefinition());
 }
diff --git a/clang-tools-extra/clang-doc/Mapper.h 
b/clang-tools-extra/clang-doc/Mapper.h
index 75c8e947c8f90..62fc5fbbdf3da 100644
--- a/clang-tools-extra/clang-doc/Mapper.h
+++ b/clang-tools-extra/clang-doc/Mapper.h
@@ -36,6 +36,7 @@ class MapASTVisitor : public 
clang::RecursiveASTVisitor,
   void HandleTranslationUnit(ASTContext &Context) override;
   bool VisitNamespaceDecl(const NamespaceDecl *D);
   bool VisitRecordDecl(const RecordDecl *D);
+  bool VisitVarDecl(const VarDecl *D);
   bool VisitEnumDecl(const EnumDecl *D);
   bool VisitCXXMethodDecl(const CXXMethodDecl *D);
   bool VisitFunctionDecl(const FunctionDecl *D);
diff --git a/clang-tools-extra/clang-doc/Serialize.cpp 
b/clang-tools-extra/clang-doc/Serialize.cpp
index f737fc75135a1..d34451cd10484 100644
--- a/clang-tools-extra/clang-doc/Serialize.cpp
+++ b/clang-tools-extra/clang-doc/Serialize.cpp
@@ -729,6 +729,62 @@ emitInfo(const RecordDecl *D, const FullComment *FC, int 
LineNumber,
   return {std::move(I), std::move(Parent)};
 }
 
+std::pair, std::unique_ptr>
+emitInfo(const VarDecl *D, const FullComment *FC, int LineNumber,
+ llvm::StringRef File, bool IsFileInRootDir, bool PublicOnly) {
+  auto I = std::make_unique();
+  bool IsInAnonymousNamespace = false;
+  populateSymbolInfo(*I, D, FC, LineNumber, File, IsFileInRootDir,
+ IsInAnonymousNamespace);
+  if (!shouldSerializeInfo(PublicOnly, IsInAnonymousNamespace, D))
+return {};
+
+  I->Path = getInfoRelativePath(I->Namespace);
+
+  PopulateTemplateParameters(I->Template, D);
+
+  // Full and partial specializations.
+  if (auto *CTSD = dyn_cast(D)) {
+if (!I->Template)
+  I->Template.emplace();
+I->Template->Specialization.emplace();
+auto &Specialization = *I->Template->Specialization;
+
+// What this is a specialization of.
+auto SpecOf = CTSD->getSpecializedTemplateOrPartial();
+if (auto *CTD = dyn_cast(SpecOf))
+  Specialization.SpecializationOf = getUSRForDecl(CTD);
+else if (auto *CTPSD =
+ dyn_cast(SpecOf))
+  Specialization.SpecializationOf = getUSRForDecl(CTPSD);
+
+// Parameters to the specilization. For partial specializations, get the
+// parameters "as written" from the ClassTemplatePartialSpecializationDecl
+// because the non-explicit template parameters will have generated 
internal
+// placeholder names rather than the names the user typed that match the
+// template parameters.
+if (const ClassTemplatePartialSpecializationDecl *CTPSD =
+dyn_cast(D)) {
+  if (const ASTTemplateArgumentListInfo *AsWritten =
+  CTPSD->getTemplateArgsAsWritten()) {
+for (unsigned i = 0; i < AsWritten->getNumTemplateArgs(); i++) {
+  Specialization.Params.emplace_back(
+  getSourceCode(D, (*AsWritten)[i].getSourceRange()));
+}
+  }
+} else {
+  for (const TemplateArgument &Arg : CTSD->getTemplateArgs().asArray()) {
+Specialization.Params.push_back(TemplateArgumentToInfo(D, Arg));
+  }
+}
+  }
+
+  // Records are inserted into the parent by reference, so we need to return
+  // both the parent and the record itself.
+  auto Parent = MakeAndInsertIntoParent(*I);
+  return {std::move(I), std::move(Parent)};
+}
+
 std::pair, std::unique_ptr>
 emitInfo(const FunctionDecl *D, const FullComment *FC, int LineNumber,
  llvm::StringRef File, bool IsFileInRootDir, bool PublicOnly) {
diff --git a/clang-tools-extra/clang-doc/Serialize.h 
b/clang-tools-extra/clang-doc/Serialize.h
index 4e203ca7891ac..41946796f39f6 100644
--- a/clang-tools-extra/clang-doc/Serialize.h
+++

[clang-tools-extra] b71123f - [clang-doc] Pre-commit tests for static members and functions (#135456)

2025-04-12 Thread via cfe-commits

Author: Paul Kirth
Date: 2025-04-12T10:54:27-07:00
New Revision: b71123f1272ee081b18b8ced1925d6e9300e7310

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

LOG: [clang-doc] Pre-commit tests for static members and functions (#135456)

Issue #59813 mentions that static members are not included in
the documentation generated by clang-doc. This patch adds
some basic testing for that property, with the current incorrect
behavior. Follow up patches will address the missing documentation.

Added: 


Modified: 
clang-tools-extra/test/clang-doc/Inputs/basic-project/include/Calculator.h
clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Calculator.cpp
clang-tools-extra/test/clang-doc/basic-project.test

Removed: 




diff  --git 
a/clang-tools-extra/test/clang-doc/Inputs/basic-project/include/Calculator.h 
b/clang-tools-extra/test/clang-doc/Inputs/basic-project/include/Calculator.h
index 6811834bc0159..195721d56fff6 100644
--- a/clang-tools-extra/test/clang-doc/Inputs/basic-project/include/Calculator.h
+++ b/clang-tools-extra/test/clang-doc/Inputs/basic-project/include/Calculator.h
@@ -43,4 +43,25 @@ class Calculator {
  * @throw std::invalid_argument if b is zero.
  */
 double divide(int a, int b);
-};
\ No newline at end of file
+
+/**
+ * @brief Performs the mod operation on integers.
+ *
+ * @param a First integer.
+ * @param b Second integer.
+ * @return The result of a % b.
+ */
+static int mod(int a, int b) {
+  return a % b;
+}
+
+/**
+ * @brief A static value.
+ */
+static constexpr int static_val = 10;
+
+/**
+ * @brief Holds a public value.
+ */
+int public_val = -1;
+};

diff  --git 
a/clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Calculator.cpp 
b/clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Calculator.cpp
index 258ea22e46184..483d050e3225a 100644
--- a/clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Calculator.cpp
+++ b/clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Calculator.cpp
@@ -15,3 +15,4 @@ int Calculator::multiply(int a, int b) {
 double Calculator::divide(int a, int b) {
   return static_cast(a) / b;
 }
+

diff  --git a/clang-tools-extra/test/clang-doc/basic-project.test 
b/clang-tools-extra/test/clang-doc/basic-project.test
index ef26e5b8916b4..94484b393df59 100644
--- a/clang-tools-extra/test/clang-doc/basic-project.test
+++ b/clang-tools-extra/test/clang-doc/basic-project.test
@@ -129,6 +129,12 @@
 //  HTML-CALC: brief
 //  HTML-CALC:  A simple calculator class.
 //  HTML-CALC:  Provides basic arithmetic operations.
+
+//  HTML-CALC: Members
+//  HTML-CALC: brief
+//  HTML-CALC:  Holds a public value.
+//  HTML-CALC: public int public_val
+
 //  HTML-CALC: Functions
 //  HTML-CALC: add
 //  HTML-CALC: public int add(int a, int b)
@@ -185,6 +191,18 @@
 //  HTML-CALC: throw
 //  HTML-CALC: if b is zero.
 
+//  HTML-CALC: public int mod(int a, int b)
+//   CALC-NO-REPOSITORY: Defined at line 54 of file 
.{{.}}include{{.}}Calculator.h
+//  CALC-REPOSITORY: Defined at line 
+// CALC-REPOSITORY-NEXT: https://repository.com/./include/Calculator.h#54";>54
+// CALC-LINE-PREFIX: https://repository.com/./include/Calculator.h#L54";>54
+// CALC-REPOSITORY-NEXT: of file 
+// CALC-REPOSITORY-NEXT: https://repository.com/./include/Calculator.h";>Calculator.h
+//  HTML-CALC: brief
+//  HTML-CALC:  Performs the mod operation on integers.
+//  HTML-CALC: return
+//  HTML-CALC:  The result of a % b.
+
 //  HTML-RECTANGLE: class Rectangle
 // RECTANGLE-NO-REPOSITORY: Defined at line 10 of file 
.{{.}}include{{.}}Rectangle.h
 //  RECTANGLE-REPOSITORY: 
@@ -306,6 +324,8 @@
 // MD-CALC: *Defined at .{{[\/]}}include{{[\/]}}Calculator.h#8*
 // MD-CALC: **brief** A simple calculator class.
 // MD-CALC:  Provides basic arithmetic operations.
+// MD-CALC: ## Members
+// MD-CALC: public int public_val
 // MD-CALC: ## Functions
 // MD-CALC: ### add
 // MD-CALC: *public int add(int a, int b)*
@@ -336,6 +356,13 @@
 // MD-CALC: **b** Second integer.
 // MD-CALC: **return** double The result of a / b.
 // MD-CALC: **throw**if b is zero.
+// MD-CALC: ### mod
+// MD-CALC: *public int mod(int a, int b)*
+// MD-CALC: *Defined at ./include{{[\/]}}Calculator.h#54*
+// MD-CALC: **brief** Performs the mod operation on integers.
+// MD-CALC: **a** First integer.
+// MD-CALC: **b** Second integer.
+// MD-CALC: **return** The result of a % b.
 
 // MD-CIRCLE: # class Circle
 // MD-CIRCLE: *Defined at .{{[\/]}}include{{[\/]}}Circle.h#10*



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

[clang-tools-extra] [clang-doc] Handle static members and functions (PR #135457)

2025-04-12 Thread Paul Kirth via cfe-commits

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


[clang-tools-extra] [clang-doc] Pre-commit tests for static members and functions (PR #135456)

2025-04-12 Thread Paul Kirth via cfe-commits

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


[clang] [Clang] Improve ``-Wtautological-overlap-compare`` diagnostics flag (PR #133653)

2025-04-12 Thread Yutong Zhu via cfe-commits

https://github.com/YutongZhuu updated 
https://github.com/llvm/llvm-project/pull/133653

>From ca795c3f27e37ad8a8f165a3b10e9415cbfd66a5 Mon Sep 17 00:00:00 2001
From: Yutong Zhu 
Date: Sat, 12 Apr 2025 15:32:46 -0400
Subject: [PATCH] Improved the -Wtautological-overlap-compare diagnostics to
 warn about overlapping and non-overlapping ranges involving character
 literals and floating-point literals.

---
 clang/docs/ReleaseNotes.rst   |   3 +
 .../clang/Basic/DiagnosticSemaKinds.td|   2 +-
 clang/lib/Analysis/CFG.cpp| 179 +++---
 clang/lib/Sema/AnalysisBasedWarnings.cpp  |   5 +-
 clang/test/Sema/warn-overlap.c| 119 ++--
 5 files changed, 211 insertions(+), 97 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 11f62bc881b03..de5c877cf996b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -352,6 +352,9 @@ Improvements to Clang's diagnostics
 - Now correctly diagnose a tentative definition of an array with static
   storage duration in pedantic mode in C. (#GH50661)
 
+- Improved the ``-Wtautological-overlap-compare`` diagnostics to warn about 
overlapping and non-overlapping ranges involving character literals and 
floating-point literals. 
+  The warning message for non-overlapping cases has also been improved 
(#GH13473).
+  
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 180ca39bc07e9..c8b5c94676d18 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10356,7 +10356,7 @@ def warn_tautological_negation_or_compare: Warning<
   "'||' of a value and its negation always evaluates to true">,
   InGroup, DefaultIgnore;
 def warn_tautological_overlap_comparison : Warning<
-  "overlapping comparisons always evaluate to %select{false|true}0">,
+  "%select{non-|}0overlapping comparisons always evaluate to 
%select{false|true}0">,
   InGroup, DefaultIgnore;
 def warn_depr_array_comparison : Warning<
   "comparison between two arrays is deprecated; "
diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index 9af1e915482da..ec7c1fbfc423a 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/lib/Analysis/CFG.cpp
@@ -70,19 +70,18 @@ static SourceLocation GetEndLoc(Decl *D) {
   return D->getLocation();
 }
 
-/// Returns true on constant values based around a single IntegerLiteral.
-/// Allow for use of parentheses, integer casts, and negative signs.
-/// FIXME: it would be good to unify this function with
-/// getIntegerLiteralSubexpressionValue at some point given the similarity
-/// between the functions.
+/// Returns true on constant values based around a single IntegerLiteral,
+/// CharacterLiteral, or FloatingLiteral. Allow for use of parentheses, integer
+/// casts, and negative signs.
 
-static bool IsIntegerLiteralConstantExpr(const Expr *E) {
+static bool IsLiteralConstantExpr(const Expr *E) {
   // Allow parentheses
   E = E->IgnoreParens();
 
   // Allow conversions to different integer kind.
   if (const auto *CE = dyn_cast(E)) {
-if (CE->getCastKind() != CK_IntegralCast)
+if (CE->getCastKind() != CK_IntegralCast &&
+CE->getCastKind() != CK_IntegralToFloating)
   return false;
 E = CE->getSubExpr();
   }
@@ -93,16 +92,16 @@ static bool IsIntegerLiteralConstantExpr(const Expr *E) {
   return false;
 E = UO->getSubExpr();
   }
-
-  return isa(E);
+  return isa(E) || isa(E) ||
+ isa(E);
 }
 
 /// Helper for tryNormalizeBinaryOperator. Attempts to extract an 
IntegerLiteral
-/// constant expression or EnumConstantDecl from the given Expr. If it fails,
-/// returns nullptr.
-static const Expr *tryTransformToIntOrEnumConstant(const Expr *E) {
+/// FloatingLiteral, CharacterLiteral or EnumConstantDecl from the given Expr.
+/// If it fails, returns nullptr.
+static const Expr *tryTransformToLiteralConstant(const Expr *E) {
   E = E->IgnoreParens();
-  if (IsIntegerLiteralConstantExpr(E))
+  if (IsLiteralConstantExpr(E))
 return E;
   if (auto *DR = dyn_cast(E->IgnoreParenImpCasts()))
 return isa(DR->getDecl()) ? DR : nullptr;
@@ -119,7 +118,7 @@ tryNormalizeBinaryOperator(const BinaryOperator *B) {
   BinaryOperatorKind Op = B->getOpcode();
 
   const Expr *MaybeDecl = B->getLHS();
-  const Expr *Constant = tryTransformToIntOrEnumConstant(B->getRHS());
+  const Expr *Constant = tryTransformToLiteralConstant(B->getRHS());
   // Expr looked like `0 == Foo` instead of `Foo == 0`
   if (Constant == nullptr) {
 // Flip the operator
@@ -133,7 +132,7 @@ tryNormalizeBinaryOperator(const BinaryOperator *B) {
   Op = BO_GE;
 
 MaybeDecl = B->getRHS();
-Constant = tryTransformToIntOrEnumConstant(B->getLHS());
+Constant = tryTransformToLiteralConstant(B->getLHS());
   }
 
   return std:

[clang-tools-extra] [clang-doc] Handle static members and functions (PR #135457)

2025-04-12 Thread Paul Kirth via cfe-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/135457

>From 32f60cd27c9234fd945443e801f1788930b1cd57 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Mon, 7 Apr 2025 08:37:40 -0700
Subject: [PATCH 1/6] [clang-doc] Handle static members and functions

clang-doc didn't visit VarDecl, and hence never collected info
from class statics members and functions.

Fixes #59813.
---
 clang-tools-extra/clang-doc/Mapper.cpp|  4 ++
 clang-tools-extra/clang-doc/Mapper.h  |  1 +
 clang-tools-extra/clang-doc/Serialize.cpp | 56 +++
 clang-tools-extra/clang-doc/Serialize.h   |  4 ++
 .../test/clang-doc/basic-project.test | 13 -
 5 files changed, 77 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-doc/Mapper.cpp 
b/clang-tools-extra/clang-doc/Mapper.cpp
index 6c90db03424c6..98698f9151280 100644
--- a/clang-tools-extra/clang-doc/Mapper.cpp
+++ b/clang-tools-extra/clang-doc/Mapper.cpp
@@ -82,6 +82,10 @@ bool MapASTVisitor::VisitRecordDecl(const RecordDecl *D) {
   return mapDecl(D, D->isThisDeclarationADefinition());
 }
 
+bool MapASTVisitor::VisitVarDecl(const VarDecl *D) {
+  return mapDecl(D, D->isThisDeclarationADefinition());
+}
+
 bool MapASTVisitor::VisitEnumDecl(const EnumDecl *D) {
   return mapDecl(D, D->isThisDeclarationADefinition());
 }
diff --git a/clang-tools-extra/clang-doc/Mapper.h 
b/clang-tools-extra/clang-doc/Mapper.h
index 75c8e947c8f90..62fc5fbbdf3da 100644
--- a/clang-tools-extra/clang-doc/Mapper.h
+++ b/clang-tools-extra/clang-doc/Mapper.h
@@ -36,6 +36,7 @@ class MapASTVisitor : public 
clang::RecursiveASTVisitor,
   void HandleTranslationUnit(ASTContext &Context) override;
   bool VisitNamespaceDecl(const NamespaceDecl *D);
   bool VisitRecordDecl(const RecordDecl *D);
+  bool VisitVarDecl(const VarDecl *D);
   bool VisitEnumDecl(const EnumDecl *D);
   bool VisitCXXMethodDecl(const CXXMethodDecl *D);
   bool VisitFunctionDecl(const FunctionDecl *D);
diff --git a/clang-tools-extra/clang-doc/Serialize.cpp 
b/clang-tools-extra/clang-doc/Serialize.cpp
index f737fc75135a1..d34451cd10484 100644
--- a/clang-tools-extra/clang-doc/Serialize.cpp
+++ b/clang-tools-extra/clang-doc/Serialize.cpp
@@ -729,6 +729,62 @@ emitInfo(const RecordDecl *D, const FullComment *FC, int 
LineNumber,
   return {std::move(I), std::move(Parent)};
 }
 
+std::pair, std::unique_ptr>
+emitInfo(const VarDecl *D, const FullComment *FC, int LineNumber,
+ llvm::StringRef File, bool IsFileInRootDir, bool PublicOnly) {
+  auto I = std::make_unique();
+  bool IsInAnonymousNamespace = false;
+  populateSymbolInfo(*I, D, FC, LineNumber, File, IsFileInRootDir,
+ IsInAnonymousNamespace);
+  if (!shouldSerializeInfo(PublicOnly, IsInAnonymousNamespace, D))
+return {};
+
+  I->Path = getInfoRelativePath(I->Namespace);
+
+  PopulateTemplateParameters(I->Template, D);
+
+  // Full and partial specializations.
+  if (auto *CTSD = dyn_cast(D)) {
+if (!I->Template)
+  I->Template.emplace();
+I->Template->Specialization.emplace();
+auto &Specialization = *I->Template->Specialization;
+
+// What this is a specialization of.
+auto SpecOf = CTSD->getSpecializedTemplateOrPartial();
+if (auto *CTD = dyn_cast(SpecOf))
+  Specialization.SpecializationOf = getUSRForDecl(CTD);
+else if (auto *CTPSD =
+ dyn_cast(SpecOf))
+  Specialization.SpecializationOf = getUSRForDecl(CTPSD);
+
+// Parameters to the specilization. For partial specializations, get the
+// parameters "as written" from the ClassTemplatePartialSpecializationDecl
+// because the non-explicit template parameters will have generated 
internal
+// placeholder names rather than the names the user typed that match the
+// template parameters.
+if (const ClassTemplatePartialSpecializationDecl *CTPSD =
+dyn_cast(D)) {
+  if (const ASTTemplateArgumentListInfo *AsWritten =
+  CTPSD->getTemplateArgsAsWritten()) {
+for (unsigned i = 0; i < AsWritten->getNumTemplateArgs(); i++) {
+  Specialization.Params.emplace_back(
+  getSourceCode(D, (*AsWritten)[i].getSourceRange()));
+}
+  }
+} else {
+  for (const TemplateArgument &Arg : CTSD->getTemplateArgs().asArray()) {
+Specialization.Params.push_back(TemplateArgumentToInfo(D, Arg));
+  }
+}
+  }
+
+  // Records are inserted into the parent by reference, so we need to return
+  // both the parent and the record itself.
+  auto Parent = MakeAndInsertIntoParent(*I);
+  return {std::move(I), std::move(Parent)};
+}
+
 std::pair, std::unique_ptr>
 emitInfo(const FunctionDecl *D, const FullComment *FC, int LineNumber,
  llvm::StringRef File, bool IsFileInRootDir, bool PublicOnly) {
diff --git a/clang-tools-extra/clang-doc/Serialize.h 
b/clang-tools-extra/clang-doc/Serialize.h
index 4e203ca7891ac..41946796f39f6 100644
--- a/clang-tools-extra/clang-doc/Serialize.h
+++

[clang-tools-extra] [clang-doc] Handle static members and functions (PR #135457)

2025-04-12 Thread Paul Kirth via cfe-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/135457

>From ca38d210bd3058575752ff9d21232e87a550a943 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Mon, 7 Apr 2025 08:37:40 -0700
Subject: [PATCH 1/7] [clang-doc] Handle static members and functions

clang-doc didn't visit VarDecl, and hence never collected info
from class statics members and functions.

Fixes #59813.
---
 clang-tools-extra/clang-doc/Mapper.cpp|  4 ++
 clang-tools-extra/clang-doc/Mapper.h  |  1 +
 clang-tools-extra/clang-doc/Serialize.cpp | 56 +++
 clang-tools-extra/clang-doc/Serialize.h   |  4 ++
 .../test/clang-doc/basic-project.test | 13 -
 5 files changed, 77 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-doc/Mapper.cpp 
b/clang-tools-extra/clang-doc/Mapper.cpp
index 6c90db03424c6..98698f9151280 100644
--- a/clang-tools-extra/clang-doc/Mapper.cpp
+++ b/clang-tools-extra/clang-doc/Mapper.cpp
@@ -82,6 +82,10 @@ bool MapASTVisitor::VisitRecordDecl(const RecordDecl *D) {
   return mapDecl(D, D->isThisDeclarationADefinition());
 }
 
+bool MapASTVisitor::VisitVarDecl(const VarDecl *D) {
+  return mapDecl(D, D->isThisDeclarationADefinition());
+}
+
 bool MapASTVisitor::VisitEnumDecl(const EnumDecl *D) {
   return mapDecl(D, D->isThisDeclarationADefinition());
 }
diff --git a/clang-tools-extra/clang-doc/Mapper.h 
b/clang-tools-extra/clang-doc/Mapper.h
index 75c8e947c8f90..62fc5fbbdf3da 100644
--- a/clang-tools-extra/clang-doc/Mapper.h
+++ b/clang-tools-extra/clang-doc/Mapper.h
@@ -36,6 +36,7 @@ class MapASTVisitor : public 
clang::RecursiveASTVisitor,
   void HandleTranslationUnit(ASTContext &Context) override;
   bool VisitNamespaceDecl(const NamespaceDecl *D);
   bool VisitRecordDecl(const RecordDecl *D);
+  bool VisitVarDecl(const VarDecl *D);
   bool VisitEnumDecl(const EnumDecl *D);
   bool VisitCXXMethodDecl(const CXXMethodDecl *D);
   bool VisitFunctionDecl(const FunctionDecl *D);
diff --git a/clang-tools-extra/clang-doc/Serialize.cpp 
b/clang-tools-extra/clang-doc/Serialize.cpp
index f737fc75135a1..d34451cd10484 100644
--- a/clang-tools-extra/clang-doc/Serialize.cpp
+++ b/clang-tools-extra/clang-doc/Serialize.cpp
@@ -729,6 +729,62 @@ emitInfo(const RecordDecl *D, const FullComment *FC, int 
LineNumber,
   return {std::move(I), std::move(Parent)};
 }
 
+std::pair, std::unique_ptr>
+emitInfo(const VarDecl *D, const FullComment *FC, int LineNumber,
+ llvm::StringRef File, bool IsFileInRootDir, bool PublicOnly) {
+  auto I = std::make_unique();
+  bool IsInAnonymousNamespace = false;
+  populateSymbolInfo(*I, D, FC, LineNumber, File, IsFileInRootDir,
+ IsInAnonymousNamespace);
+  if (!shouldSerializeInfo(PublicOnly, IsInAnonymousNamespace, D))
+return {};
+
+  I->Path = getInfoRelativePath(I->Namespace);
+
+  PopulateTemplateParameters(I->Template, D);
+
+  // Full and partial specializations.
+  if (auto *CTSD = dyn_cast(D)) {
+if (!I->Template)
+  I->Template.emplace();
+I->Template->Specialization.emplace();
+auto &Specialization = *I->Template->Specialization;
+
+// What this is a specialization of.
+auto SpecOf = CTSD->getSpecializedTemplateOrPartial();
+if (auto *CTD = dyn_cast(SpecOf))
+  Specialization.SpecializationOf = getUSRForDecl(CTD);
+else if (auto *CTPSD =
+ dyn_cast(SpecOf))
+  Specialization.SpecializationOf = getUSRForDecl(CTPSD);
+
+// Parameters to the specilization. For partial specializations, get the
+// parameters "as written" from the ClassTemplatePartialSpecializationDecl
+// because the non-explicit template parameters will have generated 
internal
+// placeholder names rather than the names the user typed that match the
+// template parameters.
+if (const ClassTemplatePartialSpecializationDecl *CTPSD =
+dyn_cast(D)) {
+  if (const ASTTemplateArgumentListInfo *AsWritten =
+  CTPSD->getTemplateArgsAsWritten()) {
+for (unsigned i = 0; i < AsWritten->getNumTemplateArgs(); i++) {
+  Specialization.Params.emplace_back(
+  getSourceCode(D, (*AsWritten)[i].getSourceRange()));
+}
+  }
+} else {
+  for (const TemplateArgument &Arg : CTSD->getTemplateArgs().asArray()) {
+Specialization.Params.push_back(TemplateArgumentToInfo(D, Arg));
+  }
+}
+  }
+
+  // Records are inserted into the parent by reference, so we need to return
+  // both the parent and the record itself.
+  auto Parent = MakeAndInsertIntoParent(*I);
+  return {std::move(I), std::move(Parent)};
+}
+
 std::pair, std::unique_ptr>
 emitInfo(const FunctionDecl *D, const FullComment *FC, int LineNumber,
  llvm::StringRef File, bool IsFileInRootDir, bool PublicOnly) {
diff --git a/clang-tools-extra/clang-doc/Serialize.h 
b/clang-tools-extra/clang-doc/Serialize.h
index 4e203ca7891ac..41946796f39f6 100644
--- a/clang-tools-extra/clang-doc/Serialize.h
+++

[clang-tools-extra] [clang-doc] Handle static members and functions (PR #135457)

2025-04-12 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff HEAD~1 HEAD --extensions cpp,h -- 
clang-tools-extra/clang-doc/BitcodeReader.cpp 
clang-tools-extra/clang-doc/BitcodeWriter.cpp 
clang-tools-extra/clang-doc/BitcodeWriter.h 
clang-tools-extra/clang-doc/HTMLGenerator.cpp 
clang-tools-extra/clang-doc/Representation.h 
clang-tools-extra/clang-doc/Serialize.cpp 
clang-tools-extra/clang-doc/Serialize.h
``





View the diff from clang-format here.


``diff
diff --git a/clang-tools-extra/clang-doc/BitcodeWriter.cpp 
b/clang-tools-extra/clang-doc/BitcodeWriter.cpp
index fbc3f9969..621af4e51 100644
--- a/clang-tools-extra/clang-doc/BitcodeWriter.cpp
+++ b/clang-tools-extra/clang-doc/BitcodeWriter.cpp
@@ -224,7 +224,8 @@ static const std::vector>>
 // FieldType Block
 {BI_FIELD_TYPE_BLOCK_ID, {FIELD_TYPE_NAME, FIELD_DEFAULT_VALUE}},
 // MemberType Block
-{BI_MEMBER_TYPE_BLOCK_ID, {MEMBER_TYPE_NAME, MEMBER_TYPE_ACCESS, 
MEMBER_TYPE_IS_STATIC}},
+{BI_MEMBER_TYPE_BLOCK_ID,
+ {MEMBER_TYPE_NAME, MEMBER_TYPE_ACCESS, MEMBER_TYPE_IS_STATIC}},
 // Enum Block
 {BI_ENUM_BLOCK_ID,
  {ENUM_USR, ENUM_NAME, ENUM_DEFLOCATION, ENUM_LOCATION, ENUM_SCOPED}},
diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp 
b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
index 1bc3265c1..e54c3f8a4 100644
--- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -419,7 +419,7 @@ genRecordMembersBlock(const 
llvm::SmallVector &Members,
 std::string Access = getAccessSpelling(M.Access).str();
 if (Access != "")
   Access = Access + " ";
-if(M.IsStatic)
+if (M.IsStatic)
   Access += "static ";
 auto LIBody = std::make_unique(HTMLTag::TAG_LI);
 auto MemberDecl = std::make_unique(HTMLTag::TAG_DIV);
@@ -742,10 +742,10 @@ genHTML(const FunctionInfo &I, const ClangDocContext 
&CDCtx,
   if (Access != "")
 FunctionHeader->Children.emplace_back(
 std::make_unique(Access + " "));
-  if(I.IsStatic)
+  if (I.IsStatic)
 FunctionHeader->Children.emplace_back(
 std::make_unique("static "));
-  else{
+  else {
 llvm::errs() << I.Name << " is not static\n";
   }
   if (I.ReturnType.Type.Name != "") {
diff --git a/clang-tools-extra/clang-doc/Serialize.cpp 
b/clang-tools-extra/clang-doc/Serialize.cpp
index 429f7de5a..727e2ed6e 100644
--- a/clang-tools-extra/clang-doc/Serialize.cpp
+++ b/clang-tools-extra/clang-doc/Serialize.cpp
@@ -743,7 +743,6 @@ emitInfo(const RecordDecl *D, const FullComment *FC, int 
LineNumber,
   return {std::move(I), std::move(Parent)};
 }
 
-
 std::pair, std::unique_ptr>
 emitInfo(const FunctionDecl *D, const FullComment *FC, int LineNumber,
  llvm::StringRef File, bool IsFileInRootDir, bool PublicOnly) {

``




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


[clang] [Clang] Improve ``-Wtautological-overlap-compare`` diagnostics flag (PR #133653)

2025-04-12 Thread Yutong Zhu via cfe-commits

https://github.com/YutongZhuu updated 
https://github.com/llvm/llvm-project/pull/133653

>From ca795c3f27e37ad8a8f165a3b10e9415cbfd66a5 Mon Sep 17 00:00:00 2001
From: Yutong Zhu 
Date: Sat, 12 Apr 2025 15:32:46 -0400
Subject: [PATCH] Improved the -Wtautological-overlap-compare diagnostics to
 warn about overlapping and non-overlapping ranges involving character
 literals and floating-point literals.

---
 clang/docs/ReleaseNotes.rst   |   3 +
 .../clang/Basic/DiagnosticSemaKinds.td|   2 +-
 clang/lib/Analysis/CFG.cpp| 179 +++---
 clang/lib/Sema/AnalysisBasedWarnings.cpp  |   5 +-
 clang/test/Sema/warn-overlap.c| 119 ++--
 5 files changed, 211 insertions(+), 97 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 11f62bc881b03..de5c877cf996b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -352,6 +352,9 @@ Improvements to Clang's diagnostics
 - Now correctly diagnose a tentative definition of an array with static
   storage duration in pedantic mode in C. (#GH50661)
 
+- Improved the ``-Wtautological-overlap-compare`` diagnostics to warn about 
overlapping and non-overlapping ranges involving character literals and 
floating-point literals. 
+  The warning message for non-overlapping cases has also been improved 
(#GH13473).
+  
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 180ca39bc07e9..c8b5c94676d18 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10356,7 +10356,7 @@ def warn_tautological_negation_or_compare: Warning<
   "'||' of a value and its negation always evaluates to true">,
   InGroup, DefaultIgnore;
 def warn_tautological_overlap_comparison : Warning<
-  "overlapping comparisons always evaluate to %select{false|true}0">,
+  "%select{non-|}0overlapping comparisons always evaluate to 
%select{false|true}0">,
   InGroup, DefaultIgnore;
 def warn_depr_array_comparison : Warning<
   "comparison between two arrays is deprecated; "
diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index 9af1e915482da..ec7c1fbfc423a 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/lib/Analysis/CFG.cpp
@@ -70,19 +70,18 @@ static SourceLocation GetEndLoc(Decl *D) {
   return D->getLocation();
 }
 
-/// Returns true on constant values based around a single IntegerLiteral.
-/// Allow for use of parentheses, integer casts, and negative signs.
-/// FIXME: it would be good to unify this function with
-/// getIntegerLiteralSubexpressionValue at some point given the similarity
-/// between the functions.
+/// Returns true on constant values based around a single IntegerLiteral,
+/// CharacterLiteral, or FloatingLiteral. Allow for use of parentheses, integer
+/// casts, and negative signs.
 
-static bool IsIntegerLiteralConstantExpr(const Expr *E) {
+static bool IsLiteralConstantExpr(const Expr *E) {
   // Allow parentheses
   E = E->IgnoreParens();
 
   // Allow conversions to different integer kind.
   if (const auto *CE = dyn_cast(E)) {
-if (CE->getCastKind() != CK_IntegralCast)
+if (CE->getCastKind() != CK_IntegralCast &&
+CE->getCastKind() != CK_IntegralToFloating)
   return false;
 E = CE->getSubExpr();
   }
@@ -93,16 +92,16 @@ static bool IsIntegerLiteralConstantExpr(const Expr *E) {
   return false;
 E = UO->getSubExpr();
   }
-
-  return isa(E);
+  return isa(E) || isa(E) ||
+ isa(E);
 }
 
 /// Helper for tryNormalizeBinaryOperator. Attempts to extract an 
IntegerLiteral
-/// constant expression or EnumConstantDecl from the given Expr. If it fails,
-/// returns nullptr.
-static const Expr *tryTransformToIntOrEnumConstant(const Expr *E) {
+/// FloatingLiteral, CharacterLiteral or EnumConstantDecl from the given Expr.
+/// If it fails, returns nullptr.
+static const Expr *tryTransformToLiteralConstant(const Expr *E) {
   E = E->IgnoreParens();
-  if (IsIntegerLiteralConstantExpr(E))
+  if (IsLiteralConstantExpr(E))
 return E;
   if (auto *DR = dyn_cast(E->IgnoreParenImpCasts()))
 return isa(DR->getDecl()) ? DR : nullptr;
@@ -119,7 +118,7 @@ tryNormalizeBinaryOperator(const BinaryOperator *B) {
   BinaryOperatorKind Op = B->getOpcode();
 
   const Expr *MaybeDecl = B->getLHS();
-  const Expr *Constant = tryTransformToIntOrEnumConstant(B->getRHS());
+  const Expr *Constant = tryTransformToLiteralConstant(B->getRHS());
   // Expr looked like `0 == Foo` instead of `Foo == 0`
   if (Constant == nullptr) {
 // Flip the operator
@@ -133,7 +132,7 @@ tryNormalizeBinaryOperator(const BinaryOperator *B) {
   Op = BO_GE;
 
 MaybeDecl = B->getRHS();
-Constant = tryTransformToIntOrEnumConstant(B->getLHS());
+Constant = tryTransformToLiteralConstant(B->getLHS());
   }
 
   return std:

[clang-tools-extra] [clang-tidy] do not diagnose array types within implicit instantiations of a template (PR #132924)

2025-04-12 Thread Baranov Victor via cfe-commits


@@ -92,3 +92,162 @@ const char name[] = "Some string";
 
 void takeCharArray(const char name[]);
 // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: do not declare C-style arrays, 
use 'std::array' or 'std::vector' instead [modernize-avoid-c-arrays]
+
+namespace std {
+  template
+  struct is_same { constexpr static bool value{false}; };
+
+  template
+  struct is_same { constexpr static bool value{true}; };
+
+  template
+  constexpr bool is_same_v = is_same::value;
+
+  template struct remove_const { typedef T type; };
+  template struct remove_const { typedef T type; };
+
+  template
+  using remove_const_t = typename remove_const::type;
+
+  template struct enable_if {};
+  template struct enable_if { typedef T type; };
+
+  template< bool B, class T = void >
+  using enable_if_t = typename enable_if::type;
+}
+
+// below, no array type findings are expected within the template parameter 
declarations since no array type gets written explicitly
+template ,
+  bool = std::is_same::value,
+  bool = std::is_same_v, int>,
+  bool = std::is_same, int>::value,
+  bool = std::is_same_v::type, int>,
+  bool = std::is_same::type, int>::value,
+  std::enable_if_t, int>) && 
not(std::is_same_v::type, char>), bool> = true,
+  typename std::enable_if, 
int>) && not(std::is_same_v::type, char>), 
bool>::type = true,
+  typename = 
std::enable_if_t, int>) && 
not(std::is_same_v::type, char>)>,
+  typename = typename std::remove_const::type,
+  typename = std::remove_const_t>
+class MyClassTemplate {
+ public:
+  // here, plenty of array type findings are expected for below template 
parameter declarations since array types get written explicitly
+  template ,
+// CHECK-MESSAGES: :[[@LINE-1]]:38: warning: do not declare 
C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
+bool = std::is_same::value,
+// CHECK-MESSAGES: :[[@LINE-1]]:36: warning: do not declare 
C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
+std::enable_if_t, 
int[]>) && not(std::is_same_v::type, char[10]>), 
bool> = true,
+// CHECK-MESSAGES: :[[@LINE-1]]:73: warning: do not declare 
C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
+// CHECK-MESSAGES: :[[@LINE-2]]:140: warning: do not declare 
C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
+typename = typename std::remove_const::type,
+// CHECK-MESSAGES: :[[@LINE-1]]:51: warning: do not declare 
C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
+typename = std::remove_const_t>
+// CHECK-MESSAGES: :[[@LINE-1]]:44: warning: do not declare 
C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
+class MyInnerClassTemplate {
+ public:
+  MyInnerClassTemplate(const U&) {}
+ private:
+  U field[3];
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: do not declare C-style 
arrays, use 'std::array' instead [modernize-avoid-c-arrays]
+};
+
+MyClassTemplate(const T&) {}
+
+ private:
+T field[7];
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not declare C-style arrays, 
use 'std::array' instead [modernize-avoid-c-arrays]
+};
+
+// an explicit instantiation
+template
+class MyClassTemplate;
+// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: do not declare C-style arrays, 
use 'std::array' instead [modernize-avoid-c-arrays]
+
+using MyArrayType = int[3];
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: do not declare C-style arrays, 
use 'std::array' instead [modernize-avoid-c-arrays]
+
+// another explicit instantiation
+template
+class MyClassTemplate;
+
+// below, no array type findings are expected within the template parameter 
declarations since no array type gets written explicitly
+template ,
+  bool = std::is_same::value,
+  bool = std::is_same_v, int>,
+  bool = std::is_same, int>::value,
+  bool = std::is_same_v::type, int>,
+  bool = std::is_same::type, int>::value,
+  std::enable_if_t, int>) && 
not(std::is_same_v::type, char>), bool> = true,
+  typename std::enable_if, 
int>) && not(std::is_same_v::type, char>), 
bool>::type = true,
+  typename = 
std::enable_if_t, int>) && 
not(std::is_same_v::type, char>)>,
+  typename = typename std::remove_const::type,
+  typename = std::remove_const_t>
+void func(const T& param) {
+  int array1[1];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, 
use 'std::array' instead [modernize-avoid-c-arrays]
+
+  T array2[2];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, 
use 'std::array' instead [modernize-avoid-c-arrays]
+
+  T value;
+}
+
+// here, plenty of array type findings are expected for below template 
parameter declarations since array types get written explicitly
+template ,
+ 

[clang-tools-extra] [clang-doc] Handle static members and functions (PR #135457)

2025-04-12 Thread Paul Kirth via cfe-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/135457

>From ca38d210bd3058575752ff9d21232e87a550a943 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Mon, 7 Apr 2025 08:37:40 -0700
Subject: [PATCH 1/8] [clang-doc] Handle static members and functions

clang-doc didn't visit VarDecl, and hence never collected info
from class statics members and functions.

Fixes #59813.
---
 clang-tools-extra/clang-doc/Mapper.cpp|  4 ++
 clang-tools-extra/clang-doc/Mapper.h  |  1 +
 clang-tools-extra/clang-doc/Serialize.cpp | 56 +++
 clang-tools-extra/clang-doc/Serialize.h   |  4 ++
 .../test/clang-doc/basic-project.test | 13 -
 5 files changed, 77 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-doc/Mapper.cpp 
b/clang-tools-extra/clang-doc/Mapper.cpp
index 6c90db03424c6..98698f9151280 100644
--- a/clang-tools-extra/clang-doc/Mapper.cpp
+++ b/clang-tools-extra/clang-doc/Mapper.cpp
@@ -82,6 +82,10 @@ bool MapASTVisitor::VisitRecordDecl(const RecordDecl *D) {
   return mapDecl(D, D->isThisDeclarationADefinition());
 }
 
+bool MapASTVisitor::VisitVarDecl(const VarDecl *D) {
+  return mapDecl(D, D->isThisDeclarationADefinition());
+}
+
 bool MapASTVisitor::VisitEnumDecl(const EnumDecl *D) {
   return mapDecl(D, D->isThisDeclarationADefinition());
 }
diff --git a/clang-tools-extra/clang-doc/Mapper.h 
b/clang-tools-extra/clang-doc/Mapper.h
index 75c8e947c8f90..62fc5fbbdf3da 100644
--- a/clang-tools-extra/clang-doc/Mapper.h
+++ b/clang-tools-extra/clang-doc/Mapper.h
@@ -36,6 +36,7 @@ class MapASTVisitor : public 
clang::RecursiveASTVisitor,
   void HandleTranslationUnit(ASTContext &Context) override;
   bool VisitNamespaceDecl(const NamespaceDecl *D);
   bool VisitRecordDecl(const RecordDecl *D);
+  bool VisitVarDecl(const VarDecl *D);
   bool VisitEnumDecl(const EnumDecl *D);
   bool VisitCXXMethodDecl(const CXXMethodDecl *D);
   bool VisitFunctionDecl(const FunctionDecl *D);
diff --git a/clang-tools-extra/clang-doc/Serialize.cpp 
b/clang-tools-extra/clang-doc/Serialize.cpp
index f737fc75135a1..d34451cd10484 100644
--- a/clang-tools-extra/clang-doc/Serialize.cpp
+++ b/clang-tools-extra/clang-doc/Serialize.cpp
@@ -729,6 +729,62 @@ emitInfo(const RecordDecl *D, const FullComment *FC, int 
LineNumber,
   return {std::move(I), std::move(Parent)};
 }
 
+std::pair, std::unique_ptr>
+emitInfo(const VarDecl *D, const FullComment *FC, int LineNumber,
+ llvm::StringRef File, bool IsFileInRootDir, bool PublicOnly) {
+  auto I = std::make_unique();
+  bool IsInAnonymousNamespace = false;
+  populateSymbolInfo(*I, D, FC, LineNumber, File, IsFileInRootDir,
+ IsInAnonymousNamespace);
+  if (!shouldSerializeInfo(PublicOnly, IsInAnonymousNamespace, D))
+return {};
+
+  I->Path = getInfoRelativePath(I->Namespace);
+
+  PopulateTemplateParameters(I->Template, D);
+
+  // Full and partial specializations.
+  if (auto *CTSD = dyn_cast(D)) {
+if (!I->Template)
+  I->Template.emplace();
+I->Template->Specialization.emplace();
+auto &Specialization = *I->Template->Specialization;
+
+// What this is a specialization of.
+auto SpecOf = CTSD->getSpecializedTemplateOrPartial();
+if (auto *CTD = dyn_cast(SpecOf))
+  Specialization.SpecializationOf = getUSRForDecl(CTD);
+else if (auto *CTPSD =
+ dyn_cast(SpecOf))
+  Specialization.SpecializationOf = getUSRForDecl(CTPSD);
+
+// Parameters to the specilization. For partial specializations, get the
+// parameters "as written" from the ClassTemplatePartialSpecializationDecl
+// because the non-explicit template parameters will have generated 
internal
+// placeholder names rather than the names the user typed that match the
+// template parameters.
+if (const ClassTemplatePartialSpecializationDecl *CTPSD =
+dyn_cast(D)) {
+  if (const ASTTemplateArgumentListInfo *AsWritten =
+  CTPSD->getTemplateArgsAsWritten()) {
+for (unsigned i = 0; i < AsWritten->getNumTemplateArgs(); i++) {
+  Specialization.Params.emplace_back(
+  getSourceCode(D, (*AsWritten)[i].getSourceRange()));
+}
+  }
+} else {
+  for (const TemplateArgument &Arg : CTSD->getTemplateArgs().asArray()) {
+Specialization.Params.push_back(TemplateArgumentToInfo(D, Arg));
+  }
+}
+  }
+
+  // Records are inserted into the parent by reference, so we need to return
+  // both the parent and the record itself.
+  auto Parent = MakeAndInsertIntoParent(*I);
+  return {std::move(I), std::move(Parent)};
+}
+
 std::pair, std::unique_ptr>
 emitInfo(const FunctionDecl *D, const FullComment *FC, int LineNumber,
  llvm::StringRef File, bool IsFileInRootDir, bool PublicOnly) {
diff --git a/clang-tools-extra/clang-doc/Serialize.h 
b/clang-tools-extra/clang-doc/Serialize.h
index 4e203ca7891ac..41946796f39f6 100644
--- a/clang-tools-extra/clang-doc/Serialize.h
+++

[clang] [Clang] Improve ``-Wtautological-overlap-compare`` diagnostics flag (PR #133653)

2025-04-12 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff HEAD~1 HEAD --extensions c,cpp -- 
clang/lib/Analysis/CFG.cpp clang/lib/Sema/AnalysisBasedWarnings.cpp 
clang/test/Sema/warn-overlap.c
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index 0a7cbdb70..4abf5ed42 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/lib/Analysis/CFG.cpp
@@ -1261,7 +1261,8 @@ private:
   llvm::APFloat L2 = L2Result.Val.getFloat();
   llvm::APFloat MidValue = L1;
   MidValue.add(L2, llvm::APFloat::rmNearestTiesToEven);
-  MidValue.divide(llvm::APFloat(L1.getSemantics(), llvm::APInt(64, 2)), 
llvm::APFloat::rmNearestTiesToEven);
+  MidValue.divide(llvm::APFloat(L1.getSemantics(), llvm::APInt(64, 2)),
+  llvm::APFloat::rmNearestTiesToEven);
 
   const llvm::APFloat Values[] = {
   llvm::APFloat::getSmallest(L1.getSemantics(), true), L1, MidValue, 
L2,

``




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


[clang] [Clang] Improve ``-Wtautological-overlap-compare`` diagnostics flag (PR #133653)

2025-04-12 Thread Yutong Zhu via cfe-commits

https://github.com/YutongZhuu updated 
https://github.com/llvm/llvm-project/pull/133653

>From ca795c3f27e37ad8a8f165a3b10e9415cbfd66a5 Mon Sep 17 00:00:00 2001
From: Yutong Zhu 
Date: Sat, 12 Apr 2025 15:32:46 -0400
Subject: [PATCH 1/2] Improved the -Wtautological-overlap-compare diagnostics
 to warn about overlapping and non-overlapping ranges involving character
 literals and floating-point literals.

---
 clang/docs/ReleaseNotes.rst   |   3 +
 .../clang/Basic/DiagnosticSemaKinds.td|   2 +-
 clang/lib/Analysis/CFG.cpp| 179 +++---
 clang/lib/Sema/AnalysisBasedWarnings.cpp  |   5 +-
 clang/test/Sema/warn-overlap.c| 119 ++--
 5 files changed, 211 insertions(+), 97 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 11f62bc881b03..de5c877cf996b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -352,6 +352,9 @@ Improvements to Clang's diagnostics
 - Now correctly diagnose a tentative definition of an array with static
   storage duration in pedantic mode in C. (#GH50661)
 
+- Improved the ``-Wtautological-overlap-compare`` diagnostics to warn about 
overlapping and non-overlapping ranges involving character literals and 
floating-point literals. 
+  The warning message for non-overlapping cases has also been improved 
(#GH13473).
+  
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 180ca39bc07e9..c8b5c94676d18 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10356,7 +10356,7 @@ def warn_tautological_negation_or_compare: Warning<
   "'||' of a value and its negation always evaluates to true">,
   InGroup, DefaultIgnore;
 def warn_tautological_overlap_comparison : Warning<
-  "overlapping comparisons always evaluate to %select{false|true}0">,
+  "%select{non-|}0overlapping comparisons always evaluate to 
%select{false|true}0">,
   InGroup, DefaultIgnore;
 def warn_depr_array_comparison : Warning<
   "comparison between two arrays is deprecated; "
diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index 9af1e915482da..ec7c1fbfc423a 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/lib/Analysis/CFG.cpp
@@ -70,19 +70,18 @@ static SourceLocation GetEndLoc(Decl *D) {
   return D->getLocation();
 }
 
-/// Returns true on constant values based around a single IntegerLiteral.
-/// Allow for use of parentheses, integer casts, and negative signs.
-/// FIXME: it would be good to unify this function with
-/// getIntegerLiteralSubexpressionValue at some point given the similarity
-/// between the functions.
+/// Returns true on constant values based around a single IntegerLiteral,
+/// CharacterLiteral, or FloatingLiteral. Allow for use of parentheses, integer
+/// casts, and negative signs.
 
-static bool IsIntegerLiteralConstantExpr(const Expr *E) {
+static bool IsLiteralConstantExpr(const Expr *E) {
   // Allow parentheses
   E = E->IgnoreParens();
 
   // Allow conversions to different integer kind.
   if (const auto *CE = dyn_cast(E)) {
-if (CE->getCastKind() != CK_IntegralCast)
+if (CE->getCastKind() != CK_IntegralCast &&
+CE->getCastKind() != CK_IntegralToFloating)
   return false;
 E = CE->getSubExpr();
   }
@@ -93,16 +92,16 @@ static bool IsIntegerLiteralConstantExpr(const Expr *E) {
   return false;
 E = UO->getSubExpr();
   }
-
-  return isa(E);
+  return isa(E) || isa(E) ||
+ isa(E);
 }
 
 /// Helper for tryNormalizeBinaryOperator. Attempts to extract an 
IntegerLiteral
-/// constant expression or EnumConstantDecl from the given Expr. If it fails,
-/// returns nullptr.
-static const Expr *tryTransformToIntOrEnumConstant(const Expr *E) {
+/// FloatingLiteral, CharacterLiteral or EnumConstantDecl from the given Expr.
+/// If it fails, returns nullptr.
+static const Expr *tryTransformToLiteralConstant(const Expr *E) {
   E = E->IgnoreParens();
-  if (IsIntegerLiteralConstantExpr(E))
+  if (IsLiteralConstantExpr(E))
 return E;
   if (auto *DR = dyn_cast(E->IgnoreParenImpCasts()))
 return isa(DR->getDecl()) ? DR : nullptr;
@@ -119,7 +118,7 @@ tryNormalizeBinaryOperator(const BinaryOperator *B) {
   BinaryOperatorKind Op = B->getOpcode();
 
   const Expr *MaybeDecl = B->getLHS();
-  const Expr *Constant = tryTransformToIntOrEnumConstant(B->getRHS());
+  const Expr *Constant = tryTransformToLiteralConstant(B->getRHS());
   // Expr looked like `0 == Foo` instead of `Foo == 0`
   if (Constant == nullptr) {
 // Flip the operator
@@ -133,7 +132,7 @@ tryNormalizeBinaryOperator(const BinaryOperator *B) {
   Op = BO_GE;
 
 MaybeDecl = B->getRHS();
-Constant = tryTransformToIntOrEnumConstant(B->getLHS());
+Constant = tryTransformToLiteralConstant(B->getLHS());
   }
 
   return 

[clang] [Clang] Improve ``-Wtautological-overlap-compare`` diagnostics flag (PR #133653)

2025-04-12 Thread Yutong Zhu via cfe-commits

https://github.com/YutongZhuu updated 
https://github.com/llvm/llvm-project/pull/133653

>From ca795c3f27e37ad8a8f165a3b10e9415cbfd66a5 Mon Sep 17 00:00:00 2001
From: Yutong Zhu 
Date: Sat, 12 Apr 2025 15:32:46 -0400
Subject: [PATCH 1/3] Improved the -Wtautological-overlap-compare diagnostics
 to warn about overlapping and non-overlapping ranges involving character
 literals and floating-point literals.

---
 clang/docs/ReleaseNotes.rst   |   3 +
 .../clang/Basic/DiagnosticSemaKinds.td|   2 +-
 clang/lib/Analysis/CFG.cpp| 179 +++---
 clang/lib/Sema/AnalysisBasedWarnings.cpp  |   5 +-
 clang/test/Sema/warn-overlap.c| 119 ++--
 5 files changed, 211 insertions(+), 97 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 11f62bc881b03..de5c877cf996b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -352,6 +352,9 @@ Improvements to Clang's diagnostics
 - Now correctly diagnose a tentative definition of an array with static
   storage duration in pedantic mode in C. (#GH50661)
 
+- Improved the ``-Wtautological-overlap-compare`` diagnostics to warn about 
overlapping and non-overlapping ranges involving character literals and 
floating-point literals. 
+  The warning message for non-overlapping cases has also been improved 
(#GH13473).
+  
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 180ca39bc07e9..c8b5c94676d18 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10356,7 +10356,7 @@ def warn_tautological_negation_or_compare: Warning<
   "'||' of a value and its negation always evaluates to true">,
   InGroup, DefaultIgnore;
 def warn_tautological_overlap_comparison : Warning<
-  "overlapping comparisons always evaluate to %select{false|true}0">,
+  "%select{non-|}0overlapping comparisons always evaluate to 
%select{false|true}0">,
   InGroup, DefaultIgnore;
 def warn_depr_array_comparison : Warning<
   "comparison between two arrays is deprecated; "
diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index 9af1e915482da..ec7c1fbfc423a 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/lib/Analysis/CFG.cpp
@@ -70,19 +70,18 @@ static SourceLocation GetEndLoc(Decl *D) {
   return D->getLocation();
 }
 
-/// Returns true on constant values based around a single IntegerLiteral.
-/// Allow for use of parentheses, integer casts, and negative signs.
-/// FIXME: it would be good to unify this function with
-/// getIntegerLiteralSubexpressionValue at some point given the similarity
-/// between the functions.
+/// Returns true on constant values based around a single IntegerLiteral,
+/// CharacterLiteral, or FloatingLiteral. Allow for use of parentheses, integer
+/// casts, and negative signs.
 
-static bool IsIntegerLiteralConstantExpr(const Expr *E) {
+static bool IsLiteralConstantExpr(const Expr *E) {
   // Allow parentheses
   E = E->IgnoreParens();
 
   // Allow conversions to different integer kind.
   if (const auto *CE = dyn_cast(E)) {
-if (CE->getCastKind() != CK_IntegralCast)
+if (CE->getCastKind() != CK_IntegralCast &&
+CE->getCastKind() != CK_IntegralToFloating)
   return false;
 E = CE->getSubExpr();
   }
@@ -93,16 +92,16 @@ static bool IsIntegerLiteralConstantExpr(const Expr *E) {
   return false;
 E = UO->getSubExpr();
   }
-
-  return isa(E);
+  return isa(E) || isa(E) ||
+ isa(E);
 }
 
 /// Helper for tryNormalizeBinaryOperator. Attempts to extract an 
IntegerLiteral
-/// constant expression or EnumConstantDecl from the given Expr. If it fails,
-/// returns nullptr.
-static const Expr *tryTransformToIntOrEnumConstant(const Expr *E) {
+/// FloatingLiteral, CharacterLiteral or EnumConstantDecl from the given Expr.
+/// If it fails, returns nullptr.
+static const Expr *tryTransformToLiteralConstant(const Expr *E) {
   E = E->IgnoreParens();
-  if (IsIntegerLiteralConstantExpr(E))
+  if (IsLiteralConstantExpr(E))
 return E;
   if (auto *DR = dyn_cast(E->IgnoreParenImpCasts()))
 return isa(DR->getDecl()) ? DR : nullptr;
@@ -119,7 +118,7 @@ tryNormalizeBinaryOperator(const BinaryOperator *B) {
   BinaryOperatorKind Op = B->getOpcode();
 
   const Expr *MaybeDecl = B->getLHS();
-  const Expr *Constant = tryTransformToIntOrEnumConstant(B->getRHS());
+  const Expr *Constant = tryTransformToLiteralConstant(B->getRHS());
   // Expr looked like `0 == Foo` instead of `Foo == 0`
   if (Constant == nullptr) {
 // Flip the operator
@@ -133,7 +132,7 @@ tryNormalizeBinaryOperator(const BinaryOperator *B) {
   Op = BO_GE;
 
 MaybeDecl = B->getRHS();
-Constant = tryTransformToIntOrEnumConstant(B->getLHS());
+Constant = tryTransformToLiteralConstant(B->getLHS());
   }
 
   return 

[clang] 09c8cfe - [clang-format][NFC] Add isJava() and isTextProto() in FormatStyle (#135466)

2025-04-12 Thread via cfe-commits

Author: Owen Pan
Date: 2025-04-12T15:04:29-07:00
New Revision: 09c8cfe219481a8fc20c6711dc5c87451f5a5ef1

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

LOG: [clang-format][NFC] Add isJava() and isTextProto() in FormatStyle (#135466)

Also remove redundant name qualifiers format::, FormatStyle::, and
LanguageKind::.

Added: 


Modified: 
clang/include/clang/Format/Format.h
clang/lib/Format/BreakableToken.cpp
clang/lib/Format/ContinuationIndenter.cpp
clang/lib/Format/Format.cpp
clang/lib/Format/FormatTokenLexer.cpp
clang/lib/Format/TokenAnnotator.cpp
clang/lib/Format/UnwrappedLineFormatter.cpp
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/CleanupTest.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index cea5e257659d6..f6ceef08b46da 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -3383,11 +3383,11 @@ struct FormatStyle {
   }
   bool isCSharp() const { return Language == LK_CSharp; }
   bool isJson() const { return Language == LK_Json; }
+  bool isJava() const { return Language == LK_Java; }
   bool isJavaScript() const { return Language == LK_JavaScript; }
   bool isVerilog() const { return Language == LK_Verilog; }
-  bool isProto() const {
-return Language == LK_Proto || Language == LK_TextProto;
-  }
+  bool isTextProto() const { return Language == LK_TextProto; }
+  bool isProto() const { return Language == LK_Proto || isTextProto(); }
   bool isTableGen() const { return Language == LK_TableGen; }
 
   /// The language that this format style targets.
@@ -5482,9 +5482,9 @@ struct FormatStyle {
   // The memory management and ownership reminds of a birds nest: chicks
   // leaving the nest take photos of the nest with them.
   struct FormatStyleSet {
-typedef std::map MapType;
+typedef std::map MapType;
 
-std::optional Get(FormatStyle::LanguageKind Language) const;
+std::optional Get(LanguageKind Language) const;
 
 // Adds \p Style to this FormatStyleSet. Style must not have an associated
 // FormatStyleSet.
@@ -5516,8 +5516,8 @@ struct FormatStyle {
 
 /// Returns a format style complying with the LLVM coding standards:
 /// http://llvm.org/docs/CodingStandards.html.
-FormatStyle getLLVMStyle(
-FormatStyle::LanguageKind Language = FormatStyle::LanguageKind::LK_Cpp);
+FormatStyle
+getLLVMStyle(FormatStyle::LanguageKind Language = FormatStyle::LK_Cpp);
 
 /// Returns a format style complying with one of Google's style guides:
 /// http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml.

diff  --git a/clang/lib/Format/BreakableToken.cpp 
b/clang/lib/Format/BreakableToken.cpp
index bde7757876990..5317c05f3a460 100644
--- a/clang/lib/Format/BreakableToken.cpp
+++ b/clang/lib/Format/BreakableToken.cpp
@@ -46,7 +46,7 @@ static StringRef getLineCommentIndentPrefix(StringRef Comment,
   static constexpr StringRef KnownTextProtoPrefixes[] = {"", "###", "##",
  "//", "#"};
   ArrayRef KnownPrefixes(KnownCStylePrefixes);
-  if (Style.Language == FormatStyle::LK_TextProto)
+  if (Style.isTextProto())
 KnownPrefixes = KnownTextProtoPrefixes;
 
   assert(
@@ -576,7 +576,7 @@ BreakableBlockComment::BreakableBlockComment(
   IndentAtLineBreak = std::max(IndentAtLineBreak, Decoration.size());
 
   // Detect a multiline jsdoc comment and set DelimitersOnNewline in that case.
-  if (Style.isJavaScript() || Style.Language == FormatStyle::LK_Java) {
+  if (Style.isJavaScript() || Style.isJava()) {
 if ((Lines[0] == "*" || Lines[0].starts_with("* ")) && Lines.size() > 1) {
   // This is a multiline jsdoc comment.
   DelimitersOnNewline = true;
@@ -694,7 +694,7 @@ const llvm::StringSet<>
 };
 
 unsigned BreakableBlockComment::getContentIndent(unsigned LineIndex) const {
-  if (Style.Language != FormatStyle::LK_Java && !Style.isJavaScript())
+  if (!Style.isJava() && !Style.isJavaScript())
 return 0;
   // The content at LineIndex 0 of a comment like:
   // /** line 0 */

diff  --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 1969f4297b211..39eb706fc2fd9 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -158,7 +158,7 @@ static bool opensProtoMessageField(const FormatToken 
&LessTok,
const FormatStyle &Style) {
   if (LessTok.isNot(tok::less))
 return false;
-  return Style.Language == FormatStyle::LK_TextProto ||
+  return Style.isTextProto() ||
  (Style.Language == FormatStyle::LK_Proto &&
   (LessTok.NestingLevel > 0 ||
  

[clang] [clang-format][NFC] Add isJava() and isTextProto() in FormatStyle (PR #135466)

2025-04-12 Thread Owen Pan via cfe-commits

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


[clang] 5f744cc - [clang-format] Wrap and indent lambda braces in GNU style (#135479)

2025-04-12 Thread via cfe-commits

Author: Owen Pan
Date: 2025-04-12T15:06:21-07:00
New Revision: 5f744cc6301abb3be5a500b2fcbc944fe2bd3241

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

LOG: [clang-format] Wrap and indent lambda braces in GNU style (#135479)

Fix #133135

Added: 


Modified: 
clang/lib/Format/ContinuationIndenter.cpp
clang/lib/Format/Format.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 39eb706fc2fd9..55e1d1ceb55b7 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1334,6 +1334,14 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState &State) {
Style.IndentWidth;
   }
 
+  if (Style.BraceWrapping.BeforeLambdaBody &&
+  Style.BraceWrapping.IndentBraces && Current.is(TT_LambdaLBrace)) {
+const auto From = Style.LambdaBodyIndentation == FormatStyle::LBI_Signature
+  ? CurrentState.Indent
+  : State.FirstIndent;
+return From + Style.IndentWidth;
+  }
+
   if ((NextNonComment->is(tok::l_brace) && NextNonComment->is(BK_Block)) ||
   (Style.isVerilog() && Keywords.isVerilogBegin(*NextNonComment))) {
 if (Current.NestingLevel == 0 ||
@@ -2113,7 +2121,8 @@ void ContinuationIndenter::moveStateToNewBlock(LineState 
&State, bool NewLine) {
   if (Style.LambdaBodyIndentation == FormatStyle::LBI_OuterScope &&
   State.NextToken->is(TT_LambdaLBrace) &&
   !State.Line->MightBeFunctionDecl) {
-State.Stack.back().NestedBlockIndent = State.FirstIndent;
+const auto Indent = Style.IndentWidth * Style.BraceWrapping.IndentBraces;
+State.Stack.back().NestedBlockIndent = State.FirstIndent + Indent;
   }
   unsigned NestedBlockIndent = State.Stack.back().NestedBlockIndent;
   // ObjC block sometimes follow special indentation rules.

diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 3802766b652d7..c601967a8715c 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1435,7 +1435,7 @@ static void expandPresetsBraceWrapping(FormatStyle 
&Expanded) {
 /*AfterExternBlock=*/true,
 /*BeforeCatch=*/true,
 /*BeforeElse=*/true,
-/*BeforeLambdaBody=*/false,
+/*BeforeLambdaBody=*/true,
 /*BeforeWhile=*/true,
 /*IndentBraces=*/true,
 /*SplitEmptyFunction=*/true,

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 9dac6d6c5f5b4..bf3260c6216da 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -24267,6 +24267,37 @@ TEST_F(FormatTest, EmptyLinesInLambdas) {
"};");
 }
 
+TEST_F(FormatTest, LambdaBracesInGNU) {
+  auto Style = getGNUStyle();
+  EXPECT_EQ(Style.LambdaBodyIndentation, FormatStyle::LBI_Signature);
+
+  constexpr StringRef Code("auto x = [&] ()\n"
+   "  {\n"
+   "for (int i = 0; i < y; ++i)\n"
+   "  return 97;\n"
+   "  };");
+  verifyFormat(Code, Style);
+
+  Style.LambdaBodyIndentation = FormatStyle::LBI_OuterScope;
+  verifyFormat(Code, Style);
+  verifyFormat("for_each_thread ([] (thread_info *thread)\n"
+   "  {\n"
+   "/* Lambda body.  */\n"
+   "  });",
+   "for_each_thread([](thread_info *thread) {\n"
+   "  /* Lambda body.  */\n"
+   "});",
+   Style);
+  verifyFormat("iterate_over_lwps (scope_ptid, [=] (struct lwp_info *info)\n"
+   "  {\n"
+   "/* Lambda body.  */\n"
+   "  });",
+   "iterate_over_lwps(scope_ptid, [=](struct lwp_info *info) {\n"
+   "  /* Lambda body.  */\n"
+   "});",
+   Style);
+}
+
 TEST_F(FormatTest, FormatsBlocks) {
   FormatStyle ShortBlocks = getLLVMStyle();
   ShortBlocks.AllowShortBlocksOnASingleLine = FormatStyle::SBS_Always;



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


[clang] [clang-format] Wrap and indent lambda braces in GNU style (PR #135479)

2025-04-12 Thread Owen Pan via cfe-commits

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


[clang-tools-extra] [clang-doc][NFC] clean unused variable in HTML generator (PR #135505)

2025-04-12 Thread Mohamed Emad via cfe-commits

https://github.com/hulxv created 
https://github.com/llvm/llvm-project/pull/135505

While reading the code, I found some dead variables that are not used anymore 
but it still declared without removing them. I think it should be removed.

CC @ilovepi @petrhosek 

>From 5c2d71ade401ad29335d1518ff48d9bad844da5a Mon Sep 17 00:00:00 2001
From: hulxv 
Date: Sat, 12 Apr 2025 03:05:44 +0200
Subject: [PATCH] [clang-doc][NFC] clean unused variable in HTML generator

---
 clang-tools-extra/clang-doc/HTMLGenerator.cpp | 4 
 1 file changed, 4 deletions(-)

diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp 
b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
index cb10f16804024..aceb83e8c4c57 100644
--- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -716,7 +716,6 @@ genHTML(const EnumInfo &I, const ClangDocContext &CDCtx) {
 
   maybeWriteSourceFileRef(Out, CDCtx, I.DefLoc);
 
-  std::string Description;
   if (!I.Description.empty())
 Out.emplace_back(genHTML(I.Description));
 
@@ -759,7 +758,6 @@ genHTML(const FunctionInfo &I, const ClangDocContext &CDCtx,
 
   maybeWriteSourceFileRef(Out, CDCtx, I.DefLoc);
 
-  std::string Description;
   if (!I.Description.empty())
 Out.emplace_back(genHTML(I.Description));
 
@@ -777,7 +775,6 @@ genHTML(const NamespaceInfo &I, Index &InfoIndex, const 
ClangDocContext &CDCtx,
 
   Out.emplace_back(std::make_unique(HTMLTag::TAG_H1, InfoTitle));
 
-  std::string Description;
   if (!I.Description.empty())
 Out.emplace_back(genHTML(I.Description));
 
@@ -820,7 +817,6 @@ genHTML(const RecordInfo &I, Index &InfoIndex, const 
ClangDocContext &CDCtx,
 
   maybeWriteSourceFileRef(Out, CDCtx, I.DefLoc);
 
-  std::string Description;
   if (!I.Description.empty())
 Out.emplace_back(genHTML(I.Description));
 

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


[clang-tools-extra] [clang-doc][NFC] clean unused variable in HTML generator (PR #135505)

2025-04-12 Thread via cfe-commits

llvmbot wrote:




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

Author: Mohamed Emad (hulxv)


Changes

While reading the code, I found some dead variables that are not used anymore 
but it still declared without removing them. I think it should be removed.

CC @ilovepi @petrhosek 

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


1 Files Affected:

- (modified) clang-tools-extra/clang-doc/HTMLGenerator.cpp (-4) 


``diff
diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp 
b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
index cb10f16804024..aceb83e8c4c57 100644
--- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -716,7 +716,6 @@ genHTML(const EnumInfo &I, const ClangDocContext &CDCtx) {
 
   maybeWriteSourceFileRef(Out, CDCtx, I.DefLoc);
 
-  std::string Description;
   if (!I.Description.empty())
 Out.emplace_back(genHTML(I.Description));
 
@@ -759,7 +758,6 @@ genHTML(const FunctionInfo &I, const ClangDocContext &CDCtx,
 
   maybeWriteSourceFileRef(Out, CDCtx, I.DefLoc);
 
-  std::string Description;
   if (!I.Description.empty())
 Out.emplace_back(genHTML(I.Description));
 
@@ -777,7 +775,6 @@ genHTML(const NamespaceInfo &I, Index &InfoIndex, const 
ClangDocContext &CDCtx,
 
   Out.emplace_back(std::make_unique(HTMLTag::TAG_H1, InfoTitle));
 
-  std::string Description;
   if (!I.Description.empty())
 Out.emplace_back(genHTML(I.Description));
 
@@ -820,7 +817,6 @@ genHTML(const RecordInfo &I, Index &InfoIndex, const 
ClangDocContext &CDCtx,
 
   maybeWriteSourceFileRef(Out, CDCtx, I.DefLoc);
 
-  std::string Description;
   if (!I.Description.empty())
 Out.emplace_back(genHTML(I.Description));
 

``




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


[clang-tools-extra] [clang-doc] Handle static members and functions (PR #135457)

2025-04-12 Thread Paul Kirth via cfe-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/135457

>From ca38d210bd3058575752ff9d21232e87a550a943 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Mon, 7 Apr 2025 08:37:40 -0700
Subject: [PATCH 1/9] [clang-doc] Handle static members and functions

clang-doc didn't visit VarDecl, and hence never collected info
from class statics members and functions.

Fixes #59813.
---
 clang-tools-extra/clang-doc/Mapper.cpp|  4 ++
 clang-tools-extra/clang-doc/Mapper.h  |  1 +
 clang-tools-extra/clang-doc/Serialize.cpp | 56 +++
 clang-tools-extra/clang-doc/Serialize.h   |  4 ++
 .../test/clang-doc/basic-project.test | 13 -
 5 files changed, 77 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-doc/Mapper.cpp 
b/clang-tools-extra/clang-doc/Mapper.cpp
index 6c90db03424c6..98698f9151280 100644
--- a/clang-tools-extra/clang-doc/Mapper.cpp
+++ b/clang-tools-extra/clang-doc/Mapper.cpp
@@ -82,6 +82,10 @@ bool MapASTVisitor::VisitRecordDecl(const RecordDecl *D) {
   return mapDecl(D, D->isThisDeclarationADefinition());
 }
 
+bool MapASTVisitor::VisitVarDecl(const VarDecl *D) {
+  return mapDecl(D, D->isThisDeclarationADefinition());
+}
+
 bool MapASTVisitor::VisitEnumDecl(const EnumDecl *D) {
   return mapDecl(D, D->isThisDeclarationADefinition());
 }
diff --git a/clang-tools-extra/clang-doc/Mapper.h 
b/clang-tools-extra/clang-doc/Mapper.h
index 75c8e947c8f90..62fc5fbbdf3da 100644
--- a/clang-tools-extra/clang-doc/Mapper.h
+++ b/clang-tools-extra/clang-doc/Mapper.h
@@ -36,6 +36,7 @@ class MapASTVisitor : public 
clang::RecursiveASTVisitor,
   void HandleTranslationUnit(ASTContext &Context) override;
   bool VisitNamespaceDecl(const NamespaceDecl *D);
   bool VisitRecordDecl(const RecordDecl *D);
+  bool VisitVarDecl(const VarDecl *D);
   bool VisitEnumDecl(const EnumDecl *D);
   bool VisitCXXMethodDecl(const CXXMethodDecl *D);
   bool VisitFunctionDecl(const FunctionDecl *D);
diff --git a/clang-tools-extra/clang-doc/Serialize.cpp 
b/clang-tools-extra/clang-doc/Serialize.cpp
index f737fc75135a1..d34451cd10484 100644
--- a/clang-tools-extra/clang-doc/Serialize.cpp
+++ b/clang-tools-extra/clang-doc/Serialize.cpp
@@ -729,6 +729,62 @@ emitInfo(const RecordDecl *D, const FullComment *FC, int 
LineNumber,
   return {std::move(I), std::move(Parent)};
 }
 
+std::pair, std::unique_ptr>
+emitInfo(const VarDecl *D, const FullComment *FC, int LineNumber,
+ llvm::StringRef File, bool IsFileInRootDir, bool PublicOnly) {
+  auto I = std::make_unique();
+  bool IsInAnonymousNamespace = false;
+  populateSymbolInfo(*I, D, FC, LineNumber, File, IsFileInRootDir,
+ IsInAnonymousNamespace);
+  if (!shouldSerializeInfo(PublicOnly, IsInAnonymousNamespace, D))
+return {};
+
+  I->Path = getInfoRelativePath(I->Namespace);
+
+  PopulateTemplateParameters(I->Template, D);
+
+  // Full and partial specializations.
+  if (auto *CTSD = dyn_cast(D)) {
+if (!I->Template)
+  I->Template.emplace();
+I->Template->Specialization.emplace();
+auto &Specialization = *I->Template->Specialization;
+
+// What this is a specialization of.
+auto SpecOf = CTSD->getSpecializedTemplateOrPartial();
+if (auto *CTD = dyn_cast(SpecOf))
+  Specialization.SpecializationOf = getUSRForDecl(CTD);
+else if (auto *CTPSD =
+ dyn_cast(SpecOf))
+  Specialization.SpecializationOf = getUSRForDecl(CTPSD);
+
+// Parameters to the specilization. For partial specializations, get the
+// parameters "as written" from the ClassTemplatePartialSpecializationDecl
+// because the non-explicit template parameters will have generated 
internal
+// placeholder names rather than the names the user typed that match the
+// template parameters.
+if (const ClassTemplatePartialSpecializationDecl *CTPSD =
+dyn_cast(D)) {
+  if (const ASTTemplateArgumentListInfo *AsWritten =
+  CTPSD->getTemplateArgsAsWritten()) {
+for (unsigned i = 0; i < AsWritten->getNumTemplateArgs(); i++) {
+  Specialization.Params.emplace_back(
+  getSourceCode(D, (*AsWritten)[i].getSourceRange()));
+}
+  }
+} else {
+  for (const TemplateArgument &Arg : CTSD->getTemplateArgs().asArray()) {
+Specialization.Params.push_back(TemplateArgumentToInfo(D, Arg));
+  }
+}
+  }
+
+  // Records are inserted into the parent by reference, so we need to return
+  // both the parent and the record itself.
+  auto Parent = MakeAndInsertIntoParent(*I);
+  return {std::move(I), std::move(Parent)};
+}
+
 std::pair, std::unique_ptr>
 emitInfo(const FunctionDecl *D, const FullComment *FC, int LineNumber,
  llvm::StringRef File, bool IsFileInRootDir, bool PublicOnly) {
diff --git a/clang-tools-extra/clang-doc/Serialize.h 
b/clang-tools-extra/clang-doc/Serialize.h
index 4e203ca7891ac..41946796f39f6 100644
--- a/clang-tools-extra/clang-doc/Serialize.h
+++

[clang-tools-extra] [clang-doc] Handle static members and functions (PR #135457)

2025-04-12 Thread Paul Kirth via cfe-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/135457

>From ca38d210bd3058575752ff9d21232e87a550a943 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Mon, 7 Apr 2025 08:37:40 -0700
Subject: [PATCH 01/10] [clang-doc] Handle static members and functions

clang-doc didn't visit VarDecl, and hence never collected info
from class statics members and functions.

Fixes #59813.
---
 clang-tools-extra/clang-doc/Mapper.cpp|  4 ++
 clang-tools-extra/clang-doc/Mapper.h  |  1 +
 clang-tools-extra/clang-doc/Serialize.cpp | 56 +++
 clang-tools-extra/clang-doc/Serialize.h   |  4 ++
 .../test/clang-doc/basic-project.test | 13 -
 5 files changed, 77 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-doc/Mapper.cpp 
b/clang-tools-extra/clang-doc/Mapper.cpp
index 6c90db03424c6..98698f9151280 100644
--- a/clang-tools-extra/clang-doc/Mapper.cpp
+++ b/clang-tools-extra/clang-doc/Mapper.cpp
@@ -82,6 +82,10 @@ bool MapASTVisitor::VisitRecordDecl(const RecordDecl *D) {
   return mapDecl(D, D->isThisDeclarationADefinition());
 }
 
+bool MapASTVisitor::VisitVarDecl(const VarDecl *D) {
+  return mapDecl(D, D->isThisDeclarationADefinition());
+}
+
 bool MapASTVisitor::VisitEnumDecl(const EnumDecl *D) {
   return mapDecl(D, D->isThisDeclarationADefinition());
 }
diff --git a/clang-tools-extra/clang-doc/Mapper.h 
b/clang-tools-extra/clang-doc/Mapper.h
index 75c8e947c8f90..62fc5fbbdf3da 100644
--- a/clang-tools-extra/clang-doc/Mapper.h
+++ b/clang-tools-extra/clang-doc/Mapper.h
@@ -36,6 +36,7 @@ class MapASTVisitor : public 
clang::RecursiveASTVisitor,
   void HandleTranslationUnit(ASTContext &Context) override;
   bool VisitNamespaceDecl(const NamespaceDecl *D);
   bool VisitRecordDecl(const RecordDecl *D);
+  bool VisitVarDecl(const VarDecl *D);
   bool VisitEnumDecl(const EnumDecl *D);
   bool VisitCXXMethodDecl(const CXXMethodDecl *D);
   bool VisitFunctionDecl(const FunctionDecl *D);
diff --git a/clang-tools-extra/clang-doc/Serialize.cpp 
b/clang-tools-extra/clang-doc/Serialize.cpp
index f737fc75135a1..d34451cd10484 100644
--- a/clang-tools-extra/clang-doc/Serialize.cpp
+++ b/clang-tools-extra/clang-doc/Serialize.cpp
@@ -729,6 +729,62 @@ emitInfo(const RecordDecl *D, const FullComment *FC, int 
LineNumber,
   return {std::move(I), std::move(Parent)};
 }
 
+std::pair, std::unique_ptr>
+emitInfo(const VarDecl *D, const FullComment *FC, int LineNumber,
+ llvm::StringRef File, bool IsFileInRootDir, bool PublicOnly) {
+  auto I = std::make_unique();
+  bool IsInAnonymousNamespace = false;
+  populateSymbolInfo(*I, D, FC, LineNumber, File, IsFileInRootDir,
+ IsInAnonymousNamespace);
+  if (!shouldSerializeInfo(PublicOnly, IsInAnonymousNamespace, D))
+return {};
+
+  I->Path = getInfoRelativePath(I->Namespace);
+
+  PopulateTemplateParameters(I->Template, D);
+
+  // Full and partial specializations.
+  if (auto *CTSD = dyn_cast(D)) {
+if (!I->Template)
+  I->Template.emplace();
+I->Template->Specialization.emplace();
+auto &Specialization = *I->Template->Specialization;
+
+// What this is a specialization of.
+auto SpecOf = CTSD->getSpecializedTemplateOrPartial();
+if (auto *CTD = dyn_cast(SpecOf))
+  Specialization.SpecializationOf = getUSRForDecl(CTD);
+else if (auto *CTPSD =
+ dyn_cast(SpecOf))
+  Specialization.SpecializationOf = getUSRForDecl(CTPSD);
+
+// Parameters to the specilization. For partial specializations, get the
+// parameters "as written" from the ClassTemplatePartialSpecializationDecl
+// because the non-explicit template parameters will have generated 
internal
+// placeholder names rather than the names the user typed that match the
+// template parameters.
+if (const ClassTemplatePartialSpecializationDecl *CTPSD =
+dyn_cast(D)) {
+  if (const ASTTemplateArgumentListInfo *AsWritten =
+  CTPSD->getTemplateArgsAsWritten()) {
+for (unsigned i = 0; i < AsWritten->getNumTemplateArgs(); i++) {
+  Specialization.Params.emplace_back(
+  getSourceCode(D, (*AsWritten)[i].getSourceRange()));
+}
+  }
+} else {
+  for (const TemplateArgument &Arg : CTSD->getTemplateArgs().asArray()) {
+Specialization.Params.push_back(TemplateArgumentToInfo(D, Arg));
+  }
+}
+  }
+
+  // Records are inserted into the parent by reference, so we need to return
+  // both the parent and the record itself.
+  auto Parent = MakeAndInsertIntoParent(*I);
+  return {std::move(I), std::move(Parent)};
+}
+
 std::pair, std::unique_ptr>
 emitInfo(const FunctionDecl *D, const FullComment *FC, int LineNumber,
  llvm::StringRef File, bool IsFileInRootDir, bool PublicOnly) {
diff --git a/clang-tools-extra/clang-doc/Serialize.h 
b/clang-tools-extra/clang-doc/Serialize.h
index 4e203ca7891ac..41946796f39f6 100644
--- a/clang-tools-extra/clang-doc/Serialize.h
+

[clang-tools-extra] [clang-doc] Handle static members and functions (PR #135457)

2025-04-12 Thread Paul Kirth via cfe-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/135457

>From ca38d210bd3058575752ff9d21232e87a550a943 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Mon, 7 Apr 2025 08:37:40 -0700
Subject: [PATCH 01/11] [clang-doc] Handle static members and functions

clang-doc didn't visit VarDecl, and hence never collected info
from class statics members and functions.

Fixes #59813.
---
 clang-tools-extra/clang-doc/Mapper.cpp|  4 ++
 clang-tools-extra/clang-doc/Mapper.h  |  1 +
 clang-tools-extra/clang-doc/Serialize.cpp | 56 +++
 clang-tools-extra/clang-doc/Serialize.h   |  4 ++
 .../test/clang-doc/basic-project.test | 13 -
 5 files changed, 77 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-doc/Mapper.cpp 
b/clang-tools-extra/clang-doc/Mapper.cpp
index 6c90db03424c6..98698f9151280 100644
--- a/clang-tools-extra/clang-doc/Mapper.cpp
+++ b/clang-tools-extra/clang-doc/Mapper.cpp
@@ -82,6 +82,10 @@ bool MapASTVisitor::VisitRecordDecl(const RecordDecl *D) {
   return mapDecl(D, D->isThisDeclarationADefinition());
 }
 
+bool MapASTVisitor::VisitVarDecl(const VarDecl *D) {
+  return mapDecl(D, D->isThisDeclarationADefinition());
+}
+
 bool MapASTVisitor::VisitEnumDecl(const EnumDecl *D) {
   return mapDecl(D, D->isThisDeclarationADefinition());
 }
diff --git a/clang-tools-extra/clang-doc/Mapper.h 
b/clang-tools-extra/clang-doc/Mapper.h
index 75c8e947c8f90..62fc5fbbdf3da 100644
--- a/clang-tools-extra/clang-doc/Mapper.h
+++ b/clang-tools-extra/clang-doc/Mapper.h
@@ -36,6 +36,7 @@ class MapASTVisitor : public 
clang::RecursiveASTVisitor,
   void HandleTranslationUnit(ASTContext &Context) override;
   bool VisitNamespaceDecl(const NamespaceDecl *D);
   bool VisitRecordDecl(const RecordDecl *D);
+  bool VisitVarDecl(const VarDecl *D);
   bool VisitEnumDecl(const EnumDecl *D);
   bool VisitCXXMethodDecl(const CXXMethodDecl *D);
   bool VisitFunctionDecl(const FunctionDecl *D);
diff --git a/clang-tools-extra/clang-doc/Serialize.cpp 
b/clang-tools-extra/clang-doc/Serialize.cpp
index f737fc75135a1..d34451cd10484 100644
--- a/clang-tools-extra/clang-doc/Serialize.cpp
+++ b/clang-tools-extra/clang-doc/Serialize.cpp
@@ -729,6 +729,62 @@ emitInfo(const RecordDecl *D, const FullComment *FC, int 
LineNumber,
   return {std::move(I), std::move(Parent)};
 }
 
+std::pair, std::unique_ptr>
+emitInfo(const VarDecl *D, const FullComment *FC, int LineNumber,
+ llvm::StringRef File, bool IsFileInRootDir, bool PublicOnly) {
+  auto I = std::make_unique();
+  bool IsInAnonymousNamespace = false;
+  populateSymbolInfo(*I, D, FC, LineNumber, File, IsFileInRootDir,
+ IsInAnonymousNamespace);
+  if (!shouldSerializeInfo(PublicOnly, IsInAnonymousNamespace, D))
+return {};
+
+  I->Path = getInfoRelativePath(I->Namespace);
+
+  PopulateTemplateParameters(I->Template, D);
+
+  // Full and partial specializations.
+  if (auto *CTSD = dyn_cast(D)) {
+if (!I->Template)
+  I->Template.emplace();
+I->Template->Specialization.emplace();
+auto &Specialization = *I->Template->Specialization;
+
+// What this is a specialization of.
+auto SpecOf = CTSD->getSpecializedTemplateOrPartial();
+if (auto *CTD = dyn_cast(SpecOf))
+  Specialization.SpecializationOf = getUSRForDecl(CTD);
+else if (auto *CTPSD =
+ dyn_cast(SpecOf))
+  Specialization.SpecializationOf = getUSRForDecl(CTPSD);
+
+// Parameters to the specilization. For partial specializations, get the
+// parameters "as written" from the ClassTemplatePartialSpecializationDecl
+// because the non-explicit template parameters will have generated 
internal
+// placeholder names rather than the names the user typed that match the
+// template parameters.
+if (const ClassTemplatePartialSpecializationDecl *CTPSD =
+dyn_cast(D)) {
+  if (const ASTTemplateArgumentListInfo *AsWritten =
+  CTPSD->getTemplateArgsAsWritten()) {
+for (unsigned i = 0; i < AsWritten->getNumTemplateArgs(); i++) {
+  Specialization.Params.emplace_back(
+  getSourceCode(D, (*AsWritten)[i].getSourceRange()));
+}
+  }
+} else {
+  for (const TemplateArgument &Arg : CTSD->getTemplateArgs().asArray()) {
+Specialization.Params.push_back(TemplateArgumentToInfo(D, Arg));
+  }
+}
+  }
+
+  // Records are inserted into the parent by reference, so we need to return
+  // both the parent and the record itself.
+  auto Parent = MakeAndInsertIntoParent(*I);
+  return {std::move(I), std::move(Parent)};
+}
+
 std::pair, std::unique_ptr>
 emitInfo(const FunctionDecl *D, const FullComment *FC, int LineNumber,
  llvm::StringRef File, bool IsFileInRootDir, bool PublicOnly) {
diff --git a/clang-tools-extra/clang-doc/Serialize.h 
b/clang-tools-extra/clang-doc/Serialize.h
index 4e203ca7891ac..41946796f39f6 100644
--- a/clang-tools-extra/clang-doc/Serialize.h
+

[clang] [clang-format][NFC] Add isJava() and isTextProto() in FormatStyle (PR #135466)

2025-04-12 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `llvm-clang-x86_64-darwin` 
running on `doug-worker-3` while building `clang` at step 6 
"test-build-unified-tree-check-all".

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


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

```
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
 TEST 'lld :: ELF/no-inhibit-exec.s' FAILED 

Exit Code: 134

Command Output (stderr):
--
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/llvm-mc -filetype=obj 
-triple=x86_64-unknown-linux 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/lld/test/ELF/no-inhibit-exec.s
 -o 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/lld/test/ELF/Output/no-inhibit-exec.s.tmp
 # RUN: at line 2
+ /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/llvm-mc -filetype=obj 
-triple=x86_64-unknown-linux 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/lld/test/ELF/no-inhibit-exec.s
 -o 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/lld/test/ELF/Output/no-inhibit-exec.s.tmp
not /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/ld.lld 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/lld/test/ELF/Output/no-inhibit-exec.s.tmp
 -o /dev/null # RUN: at line 3
+ not /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/ld.lld 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/lld/test/ELF/Output/no-inhibit-exec.s.tmp
 -o /dev/null
ld.lld: error: undefined symbol: _bar
>>> referenced by 
>>> /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/lld/test/ELF/Output/no-inhibit-exec.s.tmp:(.text+0x1)
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/ld.lld 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/lld/test/ELF/Output/no-inhibit-exec.s.tmp
 --noinhibit-exec -o 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/lld/test/ELF/Output/no-inhibit-exec.s.tmp2
 # RUN: at line 4
+ /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/ld.lld 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/lld/test/ELF/Output/no-inhibit-exec.s.tmp
 --noinhibit-exec -o 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/lld/test/ELF/Output/no-inhibit-exec.s.tmp2
ld.lld: warning: undefined symbol: _bar
>>> referenced by 
>>> /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/lld/test/ELF/Output/no-inhibit-exec.s.tmp:(.text+0x1)
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/llvm-objdump -d 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/lld/test/ELF/Output/no-inhibit-exec.s.tmp2
 | /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/FileCheck 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/lld/test/ELF/no-inhibit-exec.s
 # RUN: at line 5
+ /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/llvm-objdump -d 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/lld/test/ELF/Output/no-inhibit-exec.s.tmp2
+ /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/FileCheck 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/lld/test/ELF/no-inhibit-exec.s
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/llvm-readobj -r 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/lld/test/ELF/Output/no-inhibit-exec.s.tmp2
 | /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/FileCheck 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/lld/test/ELF/no-inhibit-exec.s
 --check-prefix=RELOC # RUN: at line 6
+ /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/llvm-readobj -r 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/tools/lld/test/ELF/Output/no-inhibit-exec.s.tmp2
+ /Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/FileCheck 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/lld/test/ELF/no-inhibit-exec.s
 --check-prefix=RELOC
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and 
include the crash backtrace.
Stack dump:
0.  Program arguments: 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/FileCheck 
/Volumes/RAMDisk/buildbot-root/x86_64-darwin/llvm-project/lld/test/ELF/no-inhibit-exec.s
 --check-prefix=RELOC
 #0 0x00010ebb8d58 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
(/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/FileCheck+0x10007bd58)
 #1 0x00010ebb7038 llvm::sys::RunSignalHandlers() 
(/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/FileCheck+0x10007a038)
 #2 0x00010ebb93e0 SignalHandler(int, __siginfo*, void*) 
(/Volumes/RAMDisk/buildbot-root/x86_64-darwin/build/bin/FileCheck+0x10007c3e0)
 #3 0x7ff809342fdd (/usr/lib/system/libsystem_platform.dylib+0x7ff80046afdd)
 #4 0x 
 #5 0x7ff809239a79 (/usr/lib/system/libsystem_c.dylib+0x7ff800361a79)
 #6 0x7ff80913e3a9 (/usr/lib/system/libsystem_malloc.dylib+0x7ff8002663a9)
 #7 0x7ff80914197a (/usr/lib/system/libsystem_malloc.dylib+0x7ff80026997a)
 #8 0x00010eb84e

[clang-tools-extra] [clang-doc][NFC] clean unused variable in HTML generator (PR #135505)

2025-04-12 Thread Mohamed Emad via cfe-commits

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


[clang-tools-extra] [clang-doc] Handle static members and functions (PR #135457)

2025-04-12 Thread Paul Kirth via cfe-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/135457

>From ca38d210bd3058575752ff9d21232e87a550a943 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Mon, 7 Apr 2025 08:37:40 -0700
Subject: [PATCH 01/12] [clang-doc] Handle static members and functions

clang-doc didn't visit VarDecl, and hence never collected info
from class statics members and functions.

Fixes #59813.
---
 clang-tools-extra/clang-doc/Mapper.cpp|  4 ++
 clang-tools-extra/clang-doc/Mapper.h  |  1 +
 clang-tools-extra/clang-doc/Serialize.cpp | 56 +++
 clang-tools-extra/clang-doc/Serialize.h   |  4 ++
 .../test/clang-doc/basic-project.test | 13 -
 5 files changed, 77 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-doc/Mapper.cpp 
b/clang-tools-extra/clang-doc/Mapper.cpp
index 6c90db03424c6..98698f9151280 100644
--- a/clang-tools-extra/clang-doc/Mapper.cpp
+++ b/clang-tools-extra/clang-doc/Mapper.cpp
@@ -82,6 +82,10 @@ bool MapASTVisitor::VisitRecordDecl(const RecordDecl *D) {
   return mapDecl(D, D->isThisDeclarationADefinition());
 }
 
+bool MapASTVisitor::VisitVarDecl(const VarDecl *D) {
+  return mapDecl(D, D->isThisDeclarationADefinition());
+}
+
 bool MapASTVisitor::VisitEnumDecl(const EnumDecl *D) {
   return mapDecl(D, D->isThisDeclarationADefinition());
 }
diff --git a/clang-tools-extra/clang-doc/Mapper.h 
b/clang-tools-extra/clang-doc/Mapper.h
index 75c8e947c8f90..62fc5fbbdf3da 100644
--- a/clang-tools-extra/clang-doc/Mapper.h
+++ b/clang-tools-extra/clang-doc/Mapper.h
@@ -36,6 +36,7 @@ class MapASTVisitor : public 
clang::RecursiveASTVisitor,
   void HandleTranslationUnit(ASTContext &Context) override;
   bool VisitNamespaceDecl(const NamespaceDecl *D);
   bool VisitRecordDecl(const RecordDecl *D);
+  bool VisitVarDecl(const VarDecl *D);
   bool VisitEnumDecl(const EnumDecl *D);
   bool VisitCXXMethodDecl(const CXXMethodDecl *D);
   bool VisitFunctionDecl(const FunctionDecl *D);
diff --git a/clang-tools-extra/clang-doc/Serialize.cpp 
b/clang-tools-extra/clang-doc/Serialize.cpp
index f737fc75135a1..d34451cd10484 100644
--- a/clang-tools-extra/clang-doc/Serialize.cpp
+++ b/clang-tools-extra/clang-doc/Serialize.cpp
@@ -729,6 +729,62 @@ emitInfo(const RecordDecl *D, const FullComment *FC, int 
LineNumber,
   return {std::move(I), std::move(Parent)};
 }
 
+std::pair, std::unique_ptr>
+emitInfo(const VarDecl *D, const FullComment *FC, int LineNumber,
+ llvm::StringRef File, bool IsFileInRootDir, bool PublicOnly) {
+  auto I = std::make_unique();
+  bool IsInAnonymousNamespace = false;
+  populateSymbolInfo(*I, D, FC, LineNumber, File, IsFileInRootDir,
+ IsInAnonymousNamespace);
+  if (!shouldSerializeInfo(PublicOnly, IsInAnonymousNamespace, D))
+return {};
+
+  I->Path = getInfoRelativePath(I->Namespace);
+
+  PopulateTemplateParameters(I->Template, D);
+
+  // Full and partial specializations.
+  if (auto *CTSD = dyn_cast(D)) {
+if (!I->Template)
+  I->Template.emplace();
+I->Template->Specialization.emplace();
+auto &Specialization = *I->Template->Specialization;
+
+// What this is a specialization of.
+auto SpecOf = CTSD->getSpecializedTemplateOrPartial();
+if (auto *CTD = dyn_cast(SpecOf))
+  Specialization.SpecializationOf = getUSRForDecl(CTD);
+else if (auto *CTPSD =
+ dyn_cast(SpecOf))
+  Specialization.SpecializationOf = getUSRForDecl(CTPSD);
+
+// Parameters to the specilization. For partial specializations, get the
+// parameters "as written" from the ClassTemplatePartialSpecializationDecl
+// because the non-explicit template parameters will have generated 
internal
+// placeholder names rather than the names the user typed that match the
+// template parameters.
+if (const ClassTemplatePartialSpecializationDecl *CTPSD =
+dyn_cast(D)) {
+  if (const ASTTemplateArgumentListInfo *AsWritten =
+  CTPSD->getTemplateArgsAsWritten()) {
+for (unsigned i = 0; i < AsWritten->getNumTemplateArgs(); i++) {
+  Specialization.Params.emplace_back(
+  getSourceCode(D, (*AsWritten)[i].getSourceRange()));
+}
+  }
+} else {
+  for (const TemplateArgument &Arg : CTSD->getTemplateArgs().asArray()) {
+Specialization.Params.push_back(TemplateArgumentToInfo(D, Arg));
+  }
+}
+  }
+
+  // Records are inserted into the parent by reference, so we need to return
+  // both the parent and the record itself.
+  auto Parent = MakeAndInsertIntoParent(*I);
+  return {std::move(I), std::move(Parent)};
+}
+
 std::pair, std::unique_ptr>
 emitInfo(const FunctionDecl *D, const FullComment *FC, int LineNumber,
  llvm::StringRef File, bool IsFileInRootDir, bool PublicOnly) {
diff --git a/clang-tools-extra/clang-doc/Serialize.h 
b/clang-tools-extra/clang-doc/Serialize.h
index 4e203ca7891ac..41946796f39f6 100644
--- a/clang-tools-extra/clang-doc/Serialize.h
+

[clang-tools-extra] [clang-doc] Handle static members and functions (PR #135457)

2025-04-12 Thread Paul Kirth via cfe-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/135457

>From ca38d210bd3058575752ff9d21232e87a550a943 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Mon, 7 Apr 2025 08:37:40 -0700
Subject: [PATCH 01/13] [clang-doc] Handle static members and functions

clang-doc didn't visit VarDecl, and hence never collected info
from class statics members and functions.

Fixes #59813.
---
 clang-tools-extra/clang-doc/Mapper.cpp|  4 ++
 clang-tools-extra/clang-doc/Mapper.h  |  1 +
 clang-tools-extra/clang-doc/Serialize.cpp | 56 +++
 clang-tools-extra/clang-doc/Serialize.h   |  4 ++
 .../test/clang-doc/basic-project.test | 13 -
 5 files changed, 77 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-doc/Mapper.cpp 
b/clang-tools-extra/clang-doc/Mapper.cpp
index 6c90db03424c6..98698f9151280 100644
--- a/clang-tools-extra/clang-doc/Mapper.cpp
+++ b/clang-tools-extra/clang-doc/Mapper.cpp
@@ -82,6 +82,10 @@ bool MapASTVisitor::VisitRecordDecl(const RecordDecl *D) {
   return mapDecl(D, D->isThisDeclarationADefinition());
 }
 
+bool MapASTVisitor::VisitVarDecl(const VarDecl *D) {
+  return mapDecl(D, D->isThisDeclarationADefinition());
+}
+
 bool MapASTVisitor::VisitEnumDecl(const EnumDecl *D) {
   return mapDecl(D, D->isThisDeclarationADefinition());
 }
diff --git a/clang-tools-extra/clang-doc/Mapper.h 
b/clang-tools-extra/clang-doc/Mapper.h
index 75c8e947c8f90..62fc5fbbdf3da 100644
--- a/clang-tools-extra/clang-doc/Mapper.h
+++ b/clang-tools-extra/clang-doc/Mapper.h
@@ -36,6 +36,7 @@ class MapASTVisitor : public 
clang::RecursiveASTVisitor,
   void HandleTranslationUnit(ASTContext &Context) override;
   bool VisitNamespaceDecl(const NamespaceDecl *D);
   bool VisitRecordDecl(const RecordDecl *D);
+  bool VisitVarDecl(const VarDecl *D);
   bool VisitEnumDecl(const EnumDecl *D);
   bool VisitCXXMethodDecl(const CXXMethodDecl *D);
   bool VisitFunctionDecl(const FunctionDecl *D);
diff --git a/clang-tools-extra/clang-doc/Serialize.cpp 
b/clang-tools-extra/clang-doc/Serialize.cpp
index f737fc75135a1..d34451cd10484 100644
--- a/clang-tools-extra/clang-doc/Serialize.cpp
+++ b/clang-tools-extra/clang-doc/Serialize.cpp
@@ -729,6 +729,62 @@ emitInfo(const RecordDecl *D, const FullComment *FC, int 
LineNumber,
   return {std::move(I), std::move(Parent)};
 }
 
+std::pair, std::unique_ptr>
+emitInfo(const VarDecl *D, const FullComment *FC, int LineNumber,
+ llvm::StringRef File, bool IsFileInRootDir, bool PublicOnly) {
+  auto I = std::make_unique();
+  bool IsInAnonymousNamespace = false;
+  populateSymbolInfo(*I, D, FC, LineNumber, File, IsFileInRootDir,
+ IsInAnonymousNamespace);
+  if (!shouldSerializeInfo(PublicOnly, IsInAnonymousNamespace, D))
+return {};
+
+  I->Path = getInfoRelativePath(I->Namespace);
+
+  PopulateTemplateParameters(I->Template, D);
+
+  // Full and partial specializations.
+  if (auto *CTSD = dyn_cast(D)) {
+if (!I->Template)
+  I->Template.emplace();
+I->Template->Specialization.emplace();
+auto &Specialization = *I->Template->Specialization;
+
+// What this is a specialization of.
+auto SpecOf = CTSD->getSpecializedTemplateOrPartial();
+if (auto *CTD = dyn_cast(SpecOf))
+  Specialization.SpecializationOf = getUSRForDecl(CTD);
+else if (auto *CTPSD =
+ dyn_cast(SpecOf))
+  Specialization.SpecializationOf = getUSRForDecl(CTPSD);
+
+// Parameters to the specilization. For partial specializations, get the
+// parameters "as written" from the ClassTemplatePartialSpecializationDecl
+// because the non-explicit template parameters will have generated 
internal
+// placeholder names rather than the names the user typed that match the
+// template parameters.
+if (const ClassTemplatePartialSpecializationDecl *CTPSD =
+dyn_cast(D)) {
+  if (const ASTTemplateArgumentListInfo *AsWritten =
+  CTPSD->getTemplateArgsAsWritten()) {
+for (unsigned i = 0; i < AsWritten->getNumTemplateArgs(); i++) {
+  Specialization.Params.emplace_back(
+  getSourceCode(D, (*AsWritten)[i].getSourceRange()));
+}
+  }
+} else {
+  for (const TemplateArgument &Arg : CTSD->getTemplateArgs().asArray()) {
+Specialization.Params.push_back(TemplateArgumentToInfo(D, Arg));
+  }
+}
+  }
+
+  // Records are inserted into the parent by reference, so we need to return
+  // both the parent and the record itself.
+  auto Parent = MakeAndInsertIntoParent(*I);
+  return {std::move(I), std::move(Parent)};
+}
+
 std::pair, std::unique_ptr>
 emitInfo(const FunctionDecl *D, const FullComment *FC, int LineNumber,
  llvm::StringRef File, bool IsFileInRootDir, bool PublicOnly) {
diff --git a/clang-tools-extra/clang-doc/Serialize.h 
b/clang-tools-extra/clang-doc/Serialize.h
index 4e203ca7891ac..41946796f39f6 100644
--- a/clang-tools-extra/clang-doc/Serialize.h
+

[clang] [llvm] [HIP][HIPSTDPAR][NFC] Re-order & adapt `hipstdpar` specific passes (PR #134753)

2025-04-12 Thread Matt Arsenault via cfe-commits


@@ -0,0 +1,11 @@
+// Check that if we are compiling with fgpu-rdc amdgpu-enable-hipstdpar is not
+// passed to CC1, to avoid eager, per TU, removal of potentially accessible
+// functions.
+
+// RUN: %clang -### --hipstdpar --offload-arch=gfx906 %s -nogpulib -nogpuinc \
+// RUN:   2>&1 | FileCheck -check-prefix=NORDC %s
+// NORDC: {{.*}}"-mllvm" "-amdgpu-enable-hipstdpar"
+
+// RUN: %clang -### --hipstdpar --offload-arch=gfx906 %s -nogpulib -nogpuinc 
-fgpu-rdc \
+// RUN:   2>&1 | FileCheck -check-prefix=RDC %s
+// RDC-NOT: {{.*}}"-mllvm" "-amdgpu-enable-hipstdpar"

arsenm wrote:

```suggestion
// RDC-NOT: -amdgpu-enable-hipstdpar
```

-NOT checks are hazardous and should be as permissive as possible 
```suggestion
// RDC-NOT: {{.*}}"-mllvm" "-amdgpu-enable-hipstdpar"
```

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


[clang] [llvm] [HIP][HIPSTDPAR][NFC] Re-order & adapt `hipstdpar` specific passes (PR #134753)

2025-04-12 Thread Matt Arsenault via cfe-commits


@@ -0,0 +1,21 @@
+// Test that the accelerator code selection pass only gets invoked after 
linking
+
+// Ensure Pass HipStdParAcceleratorCodeSelectionPass is not invoked in PreLink.
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -mllvm -amdgpu-enable-hipstdpar 
-flto -emit-llvm-bc -fcuda-is-device -fdebug-pass-manager \
+// RUN:  %s -o - 2>&1 | FileCheck --check-prefix=HIPSTDPAR-PRE %s
+// HIPSTDPAR-PRE-NOT: Running pass: HipStdParAcceleratorCodeSelectionPass
+
+// Ensure Pass HipStdParAcceleratorCodeSelectionPass is invoked in PostLink.
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -mllvm -amdgpu-enable-hipstdpar 
-fcuda-is-device -fdebug-pass-manager -emit-llvm \
+// RUN:  %s -o - 2>&1 | FileCheck --check-prefix=HIPSTDPAR-POST %s

arsenm wrote:

```suggestion
// RUN:  %s -o /dev/null 2>&1 | FileCheck --check-prefix=HIPSTDPAR-POST %s
```

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


[clang] [llvm] [HIP][HIPSTDPAR][NFC] Re-order & adapt `hipstdpar` specific passes (PR #134753)

2025-04-12 Thread Matt Arsenault via cfe-commits


@@ -0,0 +1,21 @@
+// Test that the accelerator code selection pass only gets invoked after 
linking
+
+// Ensure Pass HipStdParAcceleratorCodeSelectionPass is not invoked in PreLink.
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -mllvm -amdgpu-enable-hipstdpar 
-flto -emit-llvm-bc -fcuda-is-device -fdebug-pass-manager \
+// RUN:  %s -o - 2>&1 | FileCheck --check-prefix=HIPSTDPAR-PRE %s
+// HIPSTDPAR-PRE-NOT: Running pass: HipStdParAcceleratorCodeSelectionPass

arsenm wrote:

Better to use -NEXT checks with the passes before and after it 

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


[clang] [llvm] [HIP][HIPSTDPAR][NFC] Re-order & adapt `hipstdpar` specific passes (PR #134753)

2025-04-12 Thread Matt Arsenault via cfe-commits


@@ -0,0 +1,21 @@
+// Test that the accelerator code selection pass only gets invoked after 
linking
+
+// Ensure Pass HipStdParAcceleratorCodeSelectionPass is not invoked in PreLink.
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -mllvm -amdgpu-enable-hipstdpar 
-flto -emit-llvm-bc -fcuda-is-device -fdebug-pass-manager \
+// RUN:  %s -o - 2>&1 | FileCheck --check-prefix=HIPSTDPAR-PRE %s

arsenm wrote:

```suggestion
// RUN:  %s -o /dev/null 2>&1 | FileCheck --check-prefix=HIPSTDPAR-PRE %s
```

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


[clang] Disable -fdollars-in-identifiers by default (PR #135407)

2025-04-12 Thread via cfe-commits

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

THANKS!

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


[libunwind] [libunwind][Haiku] Improve support (PR #115462)

2025-04-12 Thread Trung Nguyen via cfe-commits
=?utf-8?q?Jérôme?= Duval ,
=?utf-8?q?Jérôme?= Duval 
Message-ID:
In-Reply-To: 


trungnt2910 wrote:

This code has **not** been tested against `tests/signal_unwind.pass.cpp`, and 
this exact test has failed when tested against `libunwind` in LLVM 20 on Haiku.

See #135367 for an alternative implementation that works, and as a bonus, does 
not rely on private headers.



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


[libunwind] Fix signal frame unwinding (PR #135367)

2025-04-12 Thread Brad Smith via cfe-commits

brad0 wrote:

cc @korli @X547 

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


[clang] Suppress errors from well-formed-testing type traits in SFINAE contexts (PR #135390)

2025-04-12 Thread Aaron Puchert via cfe-commits

aaronpuchert wrote:

> (It should be noted that the standard doesn't always base this on the 
> immediate context being well-formed: for `std::common_type` it's based on 
> whether some expression "denotes a valid type." But I assume that's an 
> editorial issue and means the same thing.)

Filed cplusplus/draft#7827 to clarify this.

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


[clang] Suppress errors from well-formed-testing type traits in SFINAE contexts (PR #135390)

2025-04-12 Thread Aaron Puchert via cfe-commits

https://github.com/aaronpuchert updated 
https://github.com/llvm/llvm-project/pull/135390

>From 20219354f6a5a59cb36554fb26c5864b5d9be74e Mon Sep 17 00:00:00 2001
From: Aaron Puchert 
Date: Fri, 11 Apr 2025 13:47:02 +0200
Subject: [PATCH] Suppress errors from well-formed-testing type traits in
 SFINAE contexts

There are several type traits that produce a boolean value or type based
on the well-formedness of some expression (more precisely, the immediate
context, i.e. for example excluding nested template instantiation):
* `__is_constructible` and variants,
* `__is_convertible` and variants,
* `__is_assignable` and variants,
* `__reference_{binds_to,{constructs,converts}_from}_temporary`,
* `__is_trivially_equality_comparable`,
* `__builtin_common_type`.

(It should be noted that the standard doesn't always base this on the
immediate context being well-formed: for `std::common_type` it's based
on whether some expression "denotes a valid type." But I assume that's
an editorial issue and means the same thing.)

Errors in the immediate context are suppressed, instead the type traits
return another value or produce a different type if the expression is
not well-formed. This is achieved using an `SFINAETrap` with
`AccessCheckingSFINAE` set to true. If the type trait is used outside of
an SFINAE context, errors are discarded because in that case the
`SFINAETrap` sets `InNonInstantiationSFINAEContext`, which makes
`isSFINAEContext` return an `optional(nullptr)`, which causes the errors
to be discarded in `EmitDiagnostic`. However, in an SFINAE context this
doesn't happen, and errors are added to `SuppressedDiagnostics` in the
`TemplateDeductionInfo` returned by `isSFINAEContext`. Once we're done
with deducing template arguments and have decided which template is
going to be instantiated, the errors corresponding to the chosen
template are then emitted. At this point we get errors from those type
traits that we wouldn't have seen if used with the same arguments
outside of an SFINAE context. That doesn't seem right.

So what we want to do is always set `InNonInstantiationSFINAEContext`
when evaluating these well-formed-testing type traits, regardless of
whether we're in an SFINAE context or not. This should only affect the
immediate context, as nested contexts add a new `CodeSynthesisContext`
that resets `InNonInstantiationSFINAEContext` for the time it's active.

Going through uses of `SFINAETrap` with `AccessCheckingSFINAE` = `true`,
it occurred to me that all of them want this behavior and we can just
use this parameter to decide whether to use a non-instantiation context.
The uses are precisely the type traits mentioned above plus the
`TentativeAnalysisScope`, where I think it is also fine. (Though I think
we don't do tentative analysis in SFINAE contexts anyway.)

Because the parameter no longer just sets `AccessCheckingSFINAE` in Sema
but also `InNonInstantiationSFINAEContext`, I think it should be renamed
(along with uses, which also point the reviewer to the affected places).
Since we're testing for well-formedness of some expression, I think
`WellFormedSFINAE` is a good new name.

The added tests should more or less correspond to the users of
`SFINAETrap` with `AccessCheckingSFINAE` = `true`. I added a test for
errors outside of the immediate context for only one type trait, because
it requires some setup and is relatively noisy.

We put the `WellFormedSFINAE` condition first because it's constant in
all uses and would allow the compiler to prune the call to
`isSFINAEContext` when true.

Fixes #132044.
---
 clang/include/clang/Sema/Sema.h   |  8 ++---
 clang/lib/Sema/SemaConcept.cpp|  2 +-
 clang/lib/Sema/SemaExprCXX.cpp|  8 ++---
 clang/lib/Sema/SemaTemplate.cpp   |  4 +--
 clang/test/SemaCXX/type-trait-common-type.cpp | 34 +++
 clang/test/SemaCXX/type-traits.cpp| 34 +++
 6 files changed, 79 insertions(+), 11 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index f65dd0191c666..971339b84f08a 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -12240,16 +12240,16 @@ class Sema final : public SemaBase {
 bool PrevLastDiagnosticIgnored;
 
   public:
-explicit SFINAETrap(Sema &SemaRef, bool AccessCheckingSFINAE = false)
+explicit SFINAETrap(Sema &SemaRef, bool TestWellformedSFINAE = false)
 : SemaRef(SemaRef), PrevSFINAEErrors(SemaRef.NumSFINAEErrors),
   PrevInNonInstantiationSFINAEContext(
   SemaRef.InNonInstantiationSFINAEContext),
   PrevAccessCheckingSFINAE(SemaRef.AccessCheckingSFINAE),
   PrevLastDiagnosticIgnored(
   SemaRef.getDiagnostics().isLastDiagnosticIgnored()) {
-  if (!SemaRef.isSFINAEContext())
+  if (TestWellformedSFINAE || !SemaRef.isSFINAEContext())
 SemaRef.InNonInstantiationSFINAEContext = true;
-  SemaRef.AccessCheckingSFI

[clang] Suppress errors from well-formed-testing type traits in SFINAE contexts (PR #135390)

2025-04-12 Thread Aaron Puchert via cfe-commits

https://github.com/aaronpuchert updated 
https://github.com/llvm/llvm-project/pull/135390

>From ef1b40c0247205f8147fe6050c1303628833c247 Mon Sep 17 00:00:00 2001
From: Aaron Puchert 
Date: Fri, 11 Apr 2025 13:47:02 +0200
Subject: [PATCH] Suppress errors from well-formed-testing type traits in
 SFINAE contexts

There are several type traits that produce a boolean value or type based
on the well-formedness of some expression (more precisely, the immediate
context, i.e. for example excluding nested template instantiation):
* `__is_constructible` and variants,
* `__is_convertible` and variants,
* `__is_assignable` and variants,
* `__reference_{binds_to,{constructs,converts}_from}_temporary`,
* `__is_trivially_equality_comparable`,
* `__builtin_common_type`.

(It should be noted that the standard doesn't always base this on the
immediate context being well-formed: for `std::common_type` it's based
on whether some expression "denotes a valid type." But I assume that's
an editorial issue and means the same thing.)

Errors in the immediate context are suppressed, instead the type traits
return another value or produce a different type if the expression is
not well-formed. This is achieved using an `SFINAETrap` with
`AccessCheckingSFINAE` set to true. If the type trait is used outside of
an SFINAE context, errors are discarded because in that case the
`SFINAETrap` sets `InNonInstantiationSFINAEContext`, which makes
`isSFINAEContext` return an `optional(nullptr)`, which causes the errors
to be discarded in `EmitDiagnostic`. However, in an SFINAE context this
doesn't happen, and errors are added to `SuppressedDiagnostics` in the
`TemplateDeductionInfo` returned by `isSFINAEContext`. Once we're done
with deducing template arguments and have decided which template is
going to be instantiated, the errors corresponding to the chosen
template are then emitted. At this point we get errors from those type
traits that we wouldn't have seen if used with the same arguments
outside of an SFINAE context. That doesn't seem right.

So what we want to do is always set `InNonInstantiationSFINAEContext`
when evaluating these well-formed-testing type traits, regardless of
whether we're in an SFINAE context or not. This should only affect the
immediate context, as nested contexts add a new `CodeSynthesisContext`
that resets `InNonInstantiationSFINAEContext` for the time it's active.

Going through uses of `SFINAETrap` with `AccessCheckingSFINAE` = `true`,
it occurred to me that all of them want this behavior and we can just
use this parameter to decide whether to use a non-instantiation context.
The uses are precisely the type traits mentioned above plus the
`TentativeAnalysisScope`, where I think it is also fine. (Though I think
we don't do tentative analysis in SFINAE contexts anyway.)

Because the parameter no longer just sets `AccessCheckingSFINAE` in Sema
but also `InNonInstantiationSFINAEContext`, I think it should be renamed
(along with uses, which also point the reviewer to the affected places).
Since we're testing for well-formedness of some expression, I think
`WellFormedSFINAE` is a good new name.

The added tests should more or less correspond to the users of
`SFINAETrap` with `AccessCheckingSFINAE` = `true`. I added a test for
errors outside of the immediate context for only one type trait, because
it requires some setup and is relatively noisy.

We put the `WellFormedSFINAE` condition first because it's constant in
all uses and would allow the compiler to prune the call to
`isSFINAEContext` when true.

Fixes #132044.
---
 clang/include/clang/Sema/Sema.h   |  8 ++---
 clang/lib/Sema/SemaConcept.cpp|  2 +-
 clang/lib/Sema/SemaExprCXX.cpp|  8 ++---
 clang/lib/Sema/SemaTemplate.cpp   |  4 +--
 clang/test/SemaCXX/type-trait-common-type.cpp | 34 +++
 clang/test/SemaCXX/type-traits.cpp| 34 +++
 6 files changed, 79 insertions(+), 11 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index f65dd0191c666..971339b84f08a 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -12240,16 +12240,16 @@ class Sema final : public SemaBase {
 bool PrevLastDiagnosticIgnored;
 
   public:
-explicit SFINAETrap(Sema &SemaRef, bool AccessCheckingSFINAE = false)
+explicit SFINAETrap(Sema &SemaRef, bool TestWellformedSFINAE = false)
 : SemaRef(SemaRef), PrevSFINAEErrors(SemaRef.NumSFINAEErrors),
   PrevInNonInstantiationSFINAEContext(
   SemaRef.InNonInstantiationSFINAEContext),
   PrevAccessCheckingSFINAE(SemaRef.AccessCheckingSFINAE),
   PrevLastDiagnosticIgnored(
   SemaRef.getDiagnostics().isLastDiagnosticIgnored()) {
-  if (!SemaRef.isSFINAEContext())
+  if (TestWellformedSFINAE || !SemaRef.isSFINAEContext())
 SemaRef.InNonInstantiationSFINAEContext = true;
-  SemaRef.AccessCheckingSFI

[clang-tools-extra] [clang-tidy] Added Conflicting Global Accesses checker (PR #130421)

2025-04-12 Thread via cfe-commits


@@ -0,0 +1,748 @@
+//===--===//
+//
+// 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 "ConflictingGlobalAccesses.h"
+
+#include "clang/AST/RecursiveASTVisitor.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+// An AccesKind represents one access to a global variable.
+//
+// The unchecked versions represent reads/writes that are not handled by
+// -Wunsequenced. (e.g. accesses inside functions).
+using AccessKind = uint8_t;
+static constexpr AccessKind AkRead = 0;
+static constexpr AccessKind AkWrite = 1;
+static constexpr AccessKind AkUncheckedRead = 2;
+static constexpr AccessKind AkUncheckedWrite = 3;
+
+static constexpr uint8_t AkCount = 4;
+
+// The TraversalResultKind represents a set of accesses.
+// Bits are corresponding to the AccessKind enum values.
+using TraversalResultKind = uint8_t;
+static constexpr TraversalResultKind TrInvalid = 0;
+static constexpr TraversalResultKind TrRead = 1 << AkRead;
+static constexpr TraversalResultKind TrWrite = 1 << AkWrite;
+static constexpr TraversalResultKind TrUncheckedWrite = 1 << AkUncheckedWrite;
+
+// To represent fields in structs or unions we use numbered FieldIndices. The
+// FieldIndexArray represents one field inside a global struct/union system.
+// The FieldIndexArray can be thought of as a path inside a tree.
+using FieldIndex = uint16_t;
+static constexpr FieldIndex FiUnion = 0x8000;
+
+// Note: This bit signals whether the field is a *field of* a struct or a
+// union, not whether the type of the field itself is a struct or a union.
+using FieldIndexArray = SmallVector;
+
+/// One traversal recurses into one side of a binary expression or one
+/// parameter of a function call. At least two of these traversals are used to
+/// find conflicting accesses.
+///
+/// A TraversalResult represents one traversal.
+struct TraversalResult {
+  int IndexCreated; // We use indices to keep track of which
+// traversal we are in currently. The current
+// index is stored in GlobalRWVisitor with the
+// name TraversalIndex.
+  SourceLocation Loc[AkCount];
+  TraversalResultKind Kind;
+
+  TraversalResult();
+  TraversalResult(int Index, SourceLocation Loc, AccessKind Access);
+  void addNewAccess(SourceLocation Loc, AccessKind Access);
+};
+
+/// The result of a number of traversals.
+class TraversalAggregation {
+  DeclarationName DeclName; // The name of the global variable being checked.
+
+  // We only store the result of two traversals as two conflicting accesses
+  // are enough to detect undefined behavior. The two stored TraversalResults
+  // have different traversal indices.
+  //
+  // Note: Sometimes multiple traversals are merged into one
+  // TraversalResult.
+  TraversalResult MainPart, OtherPart;
+  // Pairings that are not reportable: Read-Read, Read-Write,
+  // Read-UncheckedRead, Write-Write, UncheckedRead-UncheckedRead.
+
+public:
+  TraversalAggregation();
+  TraversalAggregation(DeclarationName Name, SourceLocation Loc,
+   AccessKind Access, int Index);
+  void addGlobalRW(SourceLocation Loc, AccessKind Access, int Index);
+  DeclarationName getDeclName() const;
+
+  bool isValid() const;
+
+  // If there is a conflict and that conflict isn't reported by -Wunsequenced
+  // then we report the conflict.
+  bool shouldBeReported() const;
+  bool hasConflictingOperations() const;
+
+private:
+  bool hasTwoAccesses() const;
+  bool isReportedByWunsequenced() const;
+};
+
+/// The ObjectAccessTree stores the TraversalAggregations of one global
+/// struct/union. Because each field can be handled as a single variable, the
+/// tree stores one TraversalAggregation for every field.
+///
+/// Note: structs, classes, and unions are called objects in the code.
+struct ObjectAccessTree {
+  using FieldMap = llvm::DenseMap>;
+  TraversalAggregation OwnAccesses;
+
+  // In a union, new fields should inherit from UnionTemporalAccesses
+  // instead of OwnAccesses. That's because an access to a field of a union is
+  // also an access to every other field of the same union.
+  TraversalAggregation UnionTemporalAccesses;
+
+  // We try to be lazy and only store fields that are actually accessed.
+  FieldMap Fields;
+  bool IsUnion;
+
+  ObjectAccessTree(TraversalAggregation Own);
+
+  void addFieldToAll(SourceLocation Loc, AccessKind Access, int Index);
+  void addFieldToAllExcept(uint16_t ExceptIndex, SourceLocation Loc,
+   AccessKind Access, int Index);
+};
+
+/// This object is the root of all ObjectAccessTrees.
+class ObjectTraversalAggregation {
+  DeclarationName 

[clang-tools-extra] [clang-tidy] Added Conflicting Global Accesses checker (PR #130421)

2025-04-12 Thread via cfe-commits


@@ -0,0 +1,748 @@
+//===--===//
+//
+// 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 "ConflictingGlobalAccesses.h"
+
+#include "clang/AST/RecursiveASTVisitor.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+// An AccesKind represents one access to a global variable.
+//
+// The unchecked versions represent reads/writes that are not handled by
+// -Wunsequenced. (e.g. accesses inside functions).
+using AccessKind = uint8_t;
+static constexpr AccessKind AkRead = 0;
+static constexpr AccessKind AkWrite = 1;
+static constexpr AccessKind AkUncheckedRead = 2;
+static constexpr AccessKind AkUncheckedWrite = 3;
+
+static constexpr uint8_t AkCount = 4;
+
+// The TraversalResultKind represents a set of accesses.
+// Bits are corresponding to the AccessKind enum values.
+using TraversalResultKind = uint8_t;
+static constexpr TraversalResultKind TrInvalid = 0;
+static constexpr TraversalResultKind TrRead = 1 << AkRead;
+static constexpr TraversalResultKind TrWrite = 1 << AkWrite;
+static constexpr TraversalResultKind TrUncheckedWrite = 1 << AkUncheckedWrite;

ConcreteCactus wrote:

TraversalResultKind is supposed to be a flag field, so I think a uint8_t is 
more descriptive.

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


[clang-tools-extra] [clang-tidy] Added Conflicting Global Accesses checker (PR #130421)

2025-04-12 Thread via cfe-commits


@@ -0,0 +1,748 @@
+//===--===//
+//
+// 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 "ConflictingGlobalAccesses.h"
+
+#include "clang/AST/RecursiveASTVisitor.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+// An AccesKind represents one access to a global variable.
+//
+// The unchecked versions represent reads/writes that are not handled by
+// -Wunsequenced. (e.g. accesses inside functions).
+using AccessKind = uint8_t;
+static constexpr AccessKind AkRead = 0;
+static constexpr AccessKind AkWrite = 1;
+static constexpr AccessKind AkUncheckedRead = 2;
+static constexpr AccessKind AkUncheckedWrite = 3;
+
+static constexpr uint8_t AkCount = 4;
+
+// The TraversalResultKind represents a set of accesses.
+// Bits are corresponding to the AccessKind enum values.
+using TraversalResultKind = uint8_t;
+static constexpr TraversalResultKind TrInvalid = 0;
+static constexpr TraversalResultKind TrRead = 1 << AkRead;
+static constexpr TraversalResultKind TrWrite = 1 << AkWrite;
+static constexpr TraversalResultKind TrUncheckedWrite = 1 << AkUncheckedWrite;
+
+// To represent fields in structs or unions we use numbered FieldIndices. The
+// FieldIndexArray represents one field inside a global struct/union system.
+// The FieldIndexArray can be thought of as a path inside a tree.
+using FieldIndex = uint16_t;
+static constexpr FieldIndex FiUnion = 0x8000;
+
+// Note: This bit signals whether the field is a *field of* a struct or a
+// union, not whether the type of the field itself is a struct or a union.
+using FieldIndexArray = SmallVector;
+
+/// One traversal recurses into one side of a binary expression or one
+/// parameter of a function call. At least two of these traversals are used to
+/// find conflicting accesses.
+///
+/// A TraversalResult represents one traversal.
+struct TraversalResult {
+  int IndexCreated; // We use indices to keep track of which
+// traversal we are in currently. The current
+// index is stored in GlobalRWVisitor with the
+// name TraversalIndex.
+  SourceLocation Loc[AkCount];
+  TraversalResultKind Kind;
+
+  TraversalResult();
+  TraversalResult(int Index, SourceLocation Loc, AccessKind Access);
+  void addNewAccess(SourceLocation Loc, AccessKind Access);
+};
+
+/// The result of a number of traversals.
+class TraversalAggregation {
+  DeclarationName DeclName; // The name of the global variable being checked.
+
+  // We only store the result of two traversals as two conflicting accesses
+  // are enough to detect undefined behavior. The two stored TraversalResults
+  // have different traversal indices.
+  //
+  // Note: Sometimes multiple traversals are merged into one
+  // TraversalResult.
+  TraversalResult MainPart, OtherPart;
+  // Pairings that are not reportable: Read-Read, Read-Write,
+  // Read-UncheckedRead, Write-Write, UncheckedRead-UncheckedRead.
+
+public:
+  TraversalAggregation();
+  TraversalAggregation(DeclarationName Name, SourceLocation Loc,
+   AccessKind Access, int Index);
+  void addGlobalRW(SourceLocation Loc, AccessKind Access, int Index);
+  DeclarationName getDeclName() const;
+
+  bool isValid() const;
+
+  // If there is a conflict and that conflict isn't reported by -Wunsequenced
+  // then we report the conflict.
+  bool shouldBeReported() const;
+  bool hasConflictingOperations() const;
+
+private:
+  bool hasTwoAccesses() const;
+  bool isReportedByWunsequenced() const;
+};
+
+/// The ObjectAccessTree stores the TraversalAggregations of one global
+/// struct/union. Because each field can be handled as a single variable, the
+/// tree stores one TraversalAggregation for every field.
+///
+/// Note: structs, classes, and unions are called objects in the code.
+struct ObjectAccessTree {
+  using FieldMap = llvm::DenseMap>;
+  TraversalAggregation OwnAccesses;
+
+  // In a union, new fields should inherit from UnionTemporalAccesses
+  // instead of OwnAccesses. That's because an access to a field of a union is
+  // also an access to every other field of the same union.
+  TraversalAggregation UnionTemporalAccesses;
+
+  // We try to be lazy and only store fields that are actually accessed.
+  FieldMap Fields;
+  bool IsUnion;
+
+  ObjectAccessTree(TraversalAggregation Own);
+
+  void addFieldToAll(SourceLocation Loc, AccessKind Access, int Index);
+  void addFieldToAllExcept(uint16_t ExceptIndex, SourceLocation Loc,
+   AccessKind Access, int Index);
+};
+
+/// This object is the root of all ObjectAccessTrees.
+class ObjectTraversalAggregation {
+  DeclarationName 

[clang] [clang-format] Wrap and indent lambda braces in GNU style (PR #135479)

2025-04-12 Thread via cfe-commits

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


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


[clang] [Clang][CodeGen][UBSan] Remove redundant `EmitCheckValue` calls. NFCI (PR #135141)

2025-04-12 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`sanitizer-x86_64-linux-fast` running on `sanitizer-buildbot4` while building 
`clang` at step 2 "annotate".

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


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

```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using lld-link: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using ld64.lld: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using wasm-ld: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using ld.lld: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using lld-link: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using ld64.lld: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using wasm-ld: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/main.py:72:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 900 seconds was requested on the command line. Forcing 
timeout to be 900 seconds.
-- Testing: 90167 tests, 88 workers --
Testing: 
FAIL: Clang :: Interpreter/inline-virtual.cpp (1 of 90167)
 TEST 'Clang :: Interpreter/inline-virtual.cpp' FAILED 

Exit Code: 1

Command Output (stderr):
--
cat 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Interpreter/inline-virtual.cpp
 | 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/clang-repl 
-Xcc -fno-rtti -Xcc -fno-sized-deallocation  | 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/FileCheck 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Interpreter/inline-virtual.cpp
 # RUN: at line 6
+ /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/FileCheck 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Interpreter/inline-virtual.cpp
+ cat 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Interpreter/inline-virtual.cpp
+ 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/clang-repl 
-Xcc -fno-rtti -Xcc -fno-sized-deallocation
JIT session error: In graph incr_module_23-jitted-objectbuffer, section 
.text.startup: relocation target "_ZN1AD2Ev" at address 0x74bb196bf040 is out 
of range of Delta32 fixup at 0x70bb1820502d ( @ 0x70bb18205010 
+ 0x1d)
error: Failed to materialize symbols: { (main, { a2, 
$.incr_module_23.__inits.0, __orc_init_func.incr_module_23 }) }
error: Failed to materialize symbols: { (main, { __orc_init_func.incr_module_23 
}) }
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Interpreter/inline-virtual.cpp:26:11:
 error: CHECK: expected string not found in input
// CHECK: ~A(2)
  ^
:1:262: note: scanning from here
clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> 
clang-repl... clang-repl> clang-repl... clang-repl> clang-repl> clang-repl> 
clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> 
clang-repl> clang-repl> clang-repl> ~A(1)



 ^

Input file: 
Check file: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Interpreter/inline-virtual.cpp

-dump-input=help explains the following input dump.

Input was:
<<
  1: clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> 
clang-repl> clang-repl... clang-repl> clang-repl... clang-repl> clang-repl> 
clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> 
clang-repl> clang-repl> clang-repl> clang-repl> ~A(1) 
check:26 

[libunwind] [libunwind] Fix Haiku signal frame unwinding (PR #135367)

2025-04-12 Thread Brad Smith via cfe-commits

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


[libunwind] [libunwind] Fix Haiku signal frame unwinding (PR #135367)

2025-04-12 Thread Trung Nguyen via cfe-commits

https://github.com/trungnt2910 updated 
https://github.com/llvm/llvm-project/pull/135367

>From bc84623d87b606ff2af239170bd19c14cb4e2876 Mon Sep 17 00:00:00 2001
From: Trung Nguyen 
Date: Fri, 11 Apr 2025 23:53:14 +1000
Subject: [PATCH] [libunwind][Haiku] Fix signal frame unwinding

The current unwinding implementation on Haiku is messy and broken.
1. It searches weird paths for private headers, which is breaking builds
in consuming projects, such as dotnet/runtime.
2. It does not even work, due to relying on incorrect private offsets.

This commit strips all references to private headers and ports a
working signal frame implementation. It has been tested against
`tests/signal_unwind.pass.cpp` and can go pass the signal frame.
---
 libunwind/src/CMakeLists.txt   |  16 ---
 libunwind/src/UnwindCursor.hpp | 227 -
 2 files changed, 167 insertions(+), 76 deletions(-)

diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt
index d69013e5dace1..70bd3a017cda7 100644
--- a/libunwind/src/CMakeLists.txt
+++ b/libunwind/src/CMakeLists.txt
@@ -118,22 +118,6 @@ if (HAIKU)
 
   add_compile_flags("-D_DEFAULT_SOURCE")
   add_compile_flags("-DPT_GNU_EH_FRAME=PT_EH_FRAME")
-
-  find_path(LIBUNWIND_HAIKU_PRIVATE_HEADERS
-"commpage_defs.h"
-PATHS ${CMAKE_SYSTEM_INCLUDE_PATH}
-PATH_SUFFIXES "/private/system"
-NO_DEFAULT_PATH
-REQUIRED)
-
-  include_directories(SYSTEM "${LIBUNWIND_HAIKU_PRIVATE_HEADERS}")
-  if (LIBUNWIND_TARGET_TRIPLE)
-if (${LIBUNWIND_TARGET_TRIPLE} MATCHES "^x86_64")
-  include_directories(SYSTEM 
"${LIBUNWIND_HAIKU_PRIVATE_HEADERS}/arch/x86_64")
-endif()
-  else()
-include_directories(SYSTEM 
"${LIBUNWIND_HAIKU_PRIVATE_HEADERS}/arch/${CMAKE_SYSTEM_PROCESSOR}")
-  endif()
 endif ()
 
 string(REPLACE ";" " " LIBUNWIND_COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}")
diff --git a/libunwind/src/UnwindCursor.hpp b/libunwind/src/UnwindCursor.hpp
index ca9927edc9990..1c545978673b4 100644
--- a/libunwind/src/UnwindCursor.hpp
+++ b/libunwind/src/UnwindCursor.hpp
@@ -41,6 +41,14 @@
 #define _LIBUNWIND_CHECK_LINUX_SIGRETURN 1
 #endif
 
+#if defined(_LIBUNWIND_TARGET_HAIKU) && defined(_LIBUNWIND_TARGET_X86_64)
+#include 
+#include 
+#include 
+#include 
+#define _LIBUNWIND_CHECK_HAIKU_SIGRETURN 1
+#endif
+
 #include "AddressSpace.hpp"
 #include "CompactUnwinder.hpp"
 #include "config.h"
@@ -1015,7 +1023,7 @@ class UnwindCursor : public AbstractUnwindCursor{
   template  int stepThroughSigReturn(Registers &) {
 return UNW_STEP_END;
   }
-#elif defined(_LIBUNWIND_TARGET_HAIKU)
+#elif defined(_LIBUNWIND_CHECK_HAIKU_SIGRETURN)
   bool setInfoForSigReturn();
   int stepThroughSigReturn();
 #endif
@@ -2559,7 +2567,7 @@ int UnwindCursor::stepWithTBTable(pint_t pc, 
tbtable *TBTable,
 template 
 void UnwindCursor::setInfoBasedOnIPRegister(bool isReturnAddress) {
 #if defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN) ||   
\
-defined(_LIBUNWIND_TARGET_HAIKU)
+defined(_LIBUNWIND_CHECK_HAIKU_SIGRETURN)
   _isSigReturn = false;
 #endif
 
@@ -2684,7 +2692,7 @@ void UnwindCursor::setInfoBasedOnIPRegister(bool 
isReturnAddress) {
 #endif // #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
 
 #if defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN) ||   
\
-defined(_LIBUNWIND_TARGET_HAIKU)
+defined(_LIBUNWIND_CHECK_HAIKU_SIGRETURN)
   if (setInfoForSigReturn())
 return;
 #endif
@@ -2760,63 +2768,6 @@ int UnwindCursor::stepThroughSigReturn(Registers_arm64 &) {
   _isSignalFrame = true;
   return UNW_STEP_SUCCESS;
 }
-
-#elif defined(_LIBUNWIND_TARGET_HAIKU) && defined(_LIBUNWIND_TARGET_X86_64)
-#include 
-#include 
-
-extern "C" {
-extern void *__gCommPageAddress;
-}
-
-template 
-bool UnwindCursor::setInfoForSigReturn() {
-#if defined(_LIBUNWIND_TARGET_X86_64)
-  addr_t signal_handler =
-  (((addr_t *)__gCommPageAddress)[COMMPAGE_ENTRY_X86_SIGNAL_HANDLER] +
-   (addr_t)__gCommPageAddress);
-  addr_t signal_handler_ret = signal_handler + 45;
-#endif
-  pint_t pc = static_cast(this->getReg(UNW_REG_IP));
-  if (pc == signal_handler_ret) {
-_info = {};
-_info.start_ip = signal_handler;
-_info.end_ip = signal_handler_ret;
-_isSigReturn = true;
-return true;
-  }
-  return false;
-}
-
-template 
-int UnwindCursor::stepThroughSigReturn() {
-  _isSignalFrame = true;
-  pint_t sp = _registers.getSP();
-#if defined(_LIBUNWIND_TARGET_X86_64)
-  vregs *regs = (vregs *)(sp + 0x70);
-
-  _registers.setRegister(UNW_REG_IP, regs->rip);
-  _registers.setRegister(UNW_REG_SP, regs->rsp);
-  _registers.setRegister(UNW_X86_64_RAX, regs->rax);
-  _registers.setRegister(UNW_X86_64_RDX, regs->rdx);
-  _registers.setRegister(UNW_X86_64_RCX, regs->rcx);
-  _registers.setRegister(UNW_X86_64_RBX, regs->rbx);
-  _registers.setRegister(UNW_X86_64_RSI, regs->rsi);
-  _registers.setRegister(UNW_X86_64_RDI, regs->rdi);
-  _registers.setRegister(UNW_X86_64_RBP, reg

[clang] [CIR] Upstream ArraySubscriptExpr from function parameter with pointer base (PR #135493)

2025-04-12 Thread Amr Hesham via cfe-commits

https://github.com/AmrDeveloper created 
https://github.com/llvm/llvm-project/pull/135493

This change adds an ArraySubscriptExpr from the function parameter with base 
type as Pointer

Issue https://github.com/llvm/llvm-project/issues/130197

>From 650a2402bef4ef83abaaa2b5ae78a7bcdfb4b79f Mon Sep 17 00:00:00 2001
From: AmrDeveloper 
Date: Fri, 11 Apr 2025 23:39:10 +0200
Subject: [PATCH] [CIR] Upstream ArraySubscriptExpr for base type as pointer

---
 clang/lib/CIR/CodeGen/CIRGenExpr.cpp | 14 +++-
 clang/test/CIR/CodeGen/array.cpp | 95 
 2 files changed, 92 insertions(+), 17 deletions(-)

diff --git a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
index f0732a8ea60af..5179f732a4aa2 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
@@ -570,9 +570,17 @@ CIRGenFunction::emitArraySubscriptExpr(const 
clang::ArraySubscriptExpr *e) {
   }
 
   // The base must be a pointer; emit it with an estimate of its alignment.
-  cgm.errorNYI(e->getSourceRange(),
-   "emitArraySubscriptExpr: The base must be a pointer");
-  return {};
+  assert(e->getBase()->getType()->isPointerType() &&
+ "The base must be a pointer");
+
+  LValueBaseInfo eltBaseInfo;
+  const Address ptrAddr = emitPointerWithAlignment(e->getBase(), &eltBaseInfo);
+  // Propagate the alignment from the array itself to the result.
+  const Address addxr = emitArraySubscriptPtr(
+  *this, cgm.getLoc(e->getBeginLoc()), cgm.getLoc(e->getEndLoc()), ptrAddr,
+  e->getType(), idx, cgm.getLoc(e->getExprLoc()),
+  /*shouldDecay=*/false);
+  return LValue::makeAddr(addxr, e->getType(), eltBaseInfo);
 }
 
 LValue CIRGenFunction::emitBinaryOperatorLValue(const BinaryOperator *e) {
diff --git a/clang/test/CIR/CodeGen/array.cpp b/clang/test/CIR/CodeGen/array.cpp
index 5cda061cdbf12..f63ff79db59ae 100644
--- a/clang/test/CIR/CodeGen/array.cpp
+++ b/clang/test/CIR/CodeGen/array.cpp
@@ -350,20 +350,87 @@ void func7() {
 // OGCG: %[[ARR:.*]] = alloca [1 x ptr], align 8
 // OGCG: call void @llvm.memset.p0.i64(ptr align 8 %[[ARR]], i8 0, i64 8, i1 
false)
 
-void func8(int p[10]) {}
-// CIR: cir.func @func8(%arg0: !cir.ptr
-// CIR: cir.alloca !cir.ptr, !cir.ptr>, ["p", init]
-
-// LLVM: define void @func8(ptr {{%.*}})
-// LLVM-NEXT: alloca ptr, i64 1, align 8
-
-// OGCG: alloca ptr, align 8
+void func8(int arr[10]) {
+  int e = arr[0];
+  int e2 = arr[1];
+}
 
-void func9(int pp[10][5]) {}
-// CIR: cir.func @func9(%arg0: !cir.ptr>
-// CIR: cir.alloca !cir.ptr>, 
!cir.ptr>>
+// CIR: cir.func @func8(%[[ARG:.*]]: !cir.ptr
+// CIR:  %[[ARR:.*]] = cir.alloca !cir.ptr, !cir.ptr>, 
["arr", init]
+// CIR:  %[[INIT:.*]] = cir.alloca !s32i, !cir.ptr, ["e", init]
+// CIR:  %[[INIT_2:.*]] = cir.alloca !s32i, !cir.ptr, ["e2", init]
+// CIR:  cir.store %[[ARG]], %[[ARR]] : !cir.ptr, 
!cir.ptr>
+// CIR:  %[[IDX:.*]] = cir.const #cir.int<0> : !s32i
+// CIR:  %[[TMP_1:.*]] = cir.load %[[ARR]] : !cir.ptr>, 
!cir.ptr
+// CIR:  %[[ELE_0:.*]] = cir.ptr_stride(%[[TMP_1]] : !cir.ptr, %[[IDX]] 
: !s32i), !cir.ptr
+// CIR:  %[[TMP_2:.*]] = cir.load %[[ELE_0]] : !cir.ptr, !s32i
+// CIR:  cir.store %[[TMP_2]], %[[INIT]] : !s32i, !cir.ptr
+// CIR:  %[[IDX_1:.*]] = cir.const #cir.int<1> : !s32i
+// CIR:  %[[TMP_3:.*]] = cir.load %[[ARR]] : !cir.ptr>, 
!cir.ptr
+// CIR:  %[[ELE_1:.*]] = cir.ptr_stride(%[[TMP_3]] : !cir.ptr, 
%[[IDX_1]] : !s32i), !cir.ptr
+// CIR:  %[[TMP_4:.*]] = cir.load %[[ELE_1]] : !cir.ptr, !s32i
+// CIR:  cir.store %[[TMP_4]], %[[INIT_2]] : !s32i, !cir.ptr
+
+// LLVM: define void @func8(ptr %[[ARG:.*]])
+// LLVM:  %[[ARR:.*]] = alloca ptr, i64 1, align 8
+// LLVM:  %[[INIT:.*]] = alloca i32, i64 1, align 4
+// LLVM:  %[[INIT_2:.*]] = alloca i32, i64 1, align 4
+// LLVM:  store ptr %[[ARG]], ptr %[[ARR]], align 8
+// LLVM:  %[[TMP_1:.*]] = load ptr, ptr %[[ARR]], align 8
+// LLVM:  %[[ELE_0:.*]] = getelementptr i32, ptr %[[TMP_1]], i64 0
+// LLVM:  %[[TMP_2:.*]] = load i32, ptr %[[ELE_0]], align 4
+// LLVM:  store i32 %[[TMP_2]], ptr %[[INIT]], align 4
+// LLVM:  %[[TMP_3:.*]] = load ptr, ptr %[[ARR]], align 8
+// LLVM:  %[[ELE_1:.*]] = getelementptr i32, ptr %[[TMP_3]], i64 1
+// LLVM:  %[[TMP_4:.*]] = load i32, ptr %[[ELE_1]], align 4
+// LLVM:  store i32 %[[TMP_4]], ptr %[[INIT_2]], align 4
+
+// OGCG: %[[ARR:.*]] = alloca ptr, align 8
+// OGCG: %[[INIT:.*]] = alloca i32, align 4
+// OGCG: %[[INIT_2:.*]] = alloca i32, align 4
+// OGCG: store ptr {{%.*}}, ptr %[[ARR]], align 8
+// OGCG: %[[TMP_1:.*]] = load ptr, ptr %[[ARR]], align 8
+// OGCG: %[[ELE_0:.*]] = getelementptr inbounds i32, ptr %[[TMP_1]], i64 0
+// OGCG: %[[TMP_2:.*]] = load i32, ptr %[[ELE_0]], align 4
+// OGCG: store i32 %[[TMP_2]], ptr %[[INIT]], align 4
+// OGCG: %[[TMP_3:.*]] = load ptr, ptr %[[ARR]], align 8
+// OGCG: %[[ELE_1:.*]] = getelementptr inbounds i32, ptr %[[TMP_3]], i64 1
+// OGCG: %[[TMP_2:.*]] = load i32, ptr %[[ELE_1]], align 4
+// OGCG: store i32 %[[TMP_2]], ptr

[clang] [CIR] Upstream ArraySubscriptExpr from function parameter with pointer base (PR #135493)

2025-04-12 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Amr Hesham (AmrDeveloper)


Changes

This change adds an ArraySubscriptExpr from the function parameter with base 
type as Pointer

Issue https://github.com/llvm/llvm-project/issues/130197

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


2 Files Affected:

- (modified) clang/lib/CIR/CodeGen/CIRGenExpr.cpp (+11-3) 
- (modified) clang/test/CIR/CodeGen/array.cpp (+81-14) 


``diff
diff --git a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
index f0732a8ea60af..5179f732a4aa2 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
@@ -570,9 +570,17 @@ CIRGenFunction::emitArraySubscriptExpr(const 
clang::ArraySubscriptExpr *e) {
   }
 
   // The base must be a pointer; emit it with an estimate of its alignment.
-  cgm.errorNYI(e->getSourceRange(),
-   "emitArraySubscriptExpr: The base must be a pointer");
-  return {};
+  assert(e->getBase()->getType()->isPointerType() &&
+ "The base must be a pointer");
+
+  LValueBaseInfo eltBaseInfo;
+  const Address ptrAddr = emitPointerWithAlignment(e->getBase(), &eltBaseInfo);
+  // Propagate the alignment from the array itself to the result.
+  const Address addxr = emitArraySubscriptPtr(
+  *this, cgm.getLoc(e->getBeginLoc()), cgm.getLoc(e->getEndLoc()), ptrAddr,
+  e->getType(), idx, cgm.getLoc(e->getExprLoc()),
+  /*shouldDecay=*/false);
+  return LValue::makeAddr(addxr, e->getType(), eltBaseInfo);
 }
 
 LValue CIRGenFunction::emitBinaryOperatorLValue(const BinaryOperator *e) {
diff --git a/clang/test/CIR/CodeGen/array.cpp b/clang/test/CIR/CodeGen/array.cpp
index 5cda061cdbf12..f63ff79db59ae 100644
--- a/clang/test/CIR/CodeGen/array.cpp
+++ b/clang/test/CIR/CodeGen/array.cpp
@@ -350,20 +350,87 @@ void func7() {
 // OGCG: %[[ARR:.*]] = alloca [1 x ptr], align 8
 // OGCG: call void @llvm.memset.p0.i64(ptr align 8 %[[ARR]], i8 0, i64 8, i1 
false)
 
-void func8(int p[10]) {}
-// CIR: cir.func @func8(%arg0: !cir.ptr
-// CIR: cir.alloca !cir.ptr, !cir.ptr>, ["p", init]
-
-// LLVM: define void @func8(ptr {{%.*}})
-// LLVM-NEXT: alloca ptr, i64 1, align 8
-
-// OGCG: alloca ptr, align 8
+void func8(int arr[10]) {
+  int e = arr[0];
+  int e2 = arr[1];
+}
 
-void func9(int pp[10][5]) {}
-// CIR: cir.func @func9(%arg0: !cir.ptr>
-// CIR: cir.alloca !cir.ptr>, 
!cir.ptr>>
+// CIR: cir.func @func8(%[[ARG:.*]]: !cir.ptr
+// CIR:  %[[ARR:.*]] = cir.alloca !cir.ptr, !cir.ptr>, 
["arr", init]
+// CIR:  %[[INIT:.*]] = cir.alloca !s32i, !cir.ptr, ["e", init]
+// CIR:  %[[INIT_2:.*]] = cir.alloca !s32i, !cir.ptr, ["e2", init]
+// CIR:  cir.store %[[ARG]], %[[ARR]] : !cir.ptr, 
!cir.ptr>
+// CIR:  %[[IDX:.*]] = cir.const #cir.int<0> : !s32i
+// CIR:  %[[TMP_1:.*]] = cir.load %[[ARR]] : !cir.ptr>, 
!cir.ptr
+// CIR:  %[[ELE_0:.*]] = cir.ptr_stride(%[[TMP_1]] : !cir.ptr, %[[IDX]] 
: !s32i), !cir.ptr
+// CIR:  %[[TMP_2:.*]] = cir.load %[[ELE_0]] : !cir.ptr, !s32i
+// CIR:  cir.store %[[TMP_2]], %[[INIT]] : !s32i, !cir.ptr
+// CIR:  %[[IDX_1:.*]] = cir.const #cir.int<1> : !s32i
+// CIR:  %[[TMP_3:.*]] = cir.load %[[ARR]] : !cir.ptr>, 
!cir.ptr
+// CIR:  %[[ELE_1:.*]] = cir.ptr_stride(%[[TMP_3]] : !cir.ptr, 
%[[IDX_1]] : !s32i), !cir.ptr
+// CIR:  %[[TMP_4:.*]] = cir.load %[[ELE_1]] : !cir.ptr, !s32i
+// CIR:  cir.store %[[TMP_4]], %[[INIT_2]] : !s32i, !cir.ptr
+
+// LLVM: define void @func8(ptr %[[ARG:.*]])
+// LLVM:  %[[ARR:.*]] = alloca ptr, i64 1, align 8
+// LLVM:  %[[INIT:.*]] = alloca i32, i64 1, align 4
+// LLVM:  %[[INIT_2:.*]] = alloca i32, i64 1, align 4
+// LLVM:  store ptr %[[ARG]], ptr %[[ARR]], align 8
+// LLVM:  %[[TMP_1:.*]] = load ptr, ptr %[[ARR]], align 8
+// LLVM:  %[[ELE_0:.*]] = getelementptr i32, ptr %[[TMP_1]], i64 0
+// LLVM:  %[[TMP_2:.*]] = load i32, ptr %[[ELE_0]], align 4
+// LLVM:  store i32 %[[TMP_2]], ptr %[[INIT]], align 4
+// LLVM:  %[[TMP_3:.*]] = load ptr, ptr %[[ARR]], align 8
+// LLVM:  %[[ELE_1:.*]] = getelementptr i32, ptr %[[TMP_3]], i64 1
+// LLVM:  %[[TMP_4:.*]] = load i32, ptr %[[ELE_1]], align 4
+// LLVM:  store i32 %[[TMP_4]], ptr %[[INIT_2]], align 4
+
+// OGCG: %[[ARR:.*]] = alloca ptr, align 8
+// OGCG: %[[INIT:.*]] = alloca i32, align 4
+// OGCG: %[[INIT_2:.*]] = alloca i32, align 4
+// OGCG: store ptr {{%.*}}, ptr %[[ARR]], align 8
+// OGCG: %[[TMP_1:.*]] = load ptr, ptr %[[ARR]], align 8
+// OGCG: %[[ELE_0:.*]] = getelementptr inbounds i32, ptr %[[TMP_1]], i64 0
+// OGCG: %[[TMP_2:.*]] = load i32, ptr %[[ELE_0]], align 4
+// OGCG: store i32 %[[TMP_2]], ptr %[[INIT]], align 4
+// OGCG: %[[TMP_3:.*]] = load ptr, ptr %[[ARR]], align 8
+// OGCG: %[[ELE_1:.*]] = getelementptr inbounds i32, ptr %[[TMP_3]], i64 1
+// OGCG: %[[TMP_2:.*]] = load i32, ptr %[[ELE_1]], align 4
+// OGCG: store i32 %[[TMP_2]], ptr %[[INIT_2]], align 4
 
-// LLVM: define void @func9(ptr {{%.*}})
-// LLVM-NEXT: alloca ptr, i64 1, align 8
+void func9(int arr[10][5]) {
+  int e = arr[1][2];
+

[clang] [clang-tools-extra] Reland: [clang] Improved canonicalization for template specialization types (PR #135414)

2025-04-12 Thread Matheus Izvekov via cfe-commits

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


[clang-tools-extra] [clang-doc] Pre-commit tests for static members and functions (PR #135456)

2025-04-12 Thread Paul Kirth via cfe-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/135456

>From 07c9c8756b564198c2761e353b1b2b2031c9a4ee Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Wed, 2 Apr 2025 09:11:20 -0700
Subject: [PATCH 1/3] [clang-doc] Pre-commit tests for static members and
 functions

Issue #59813 mentions that static members are not included in
the documentation generated by clang-doc. This patch adds
some basic testing for that property, with the current incorrect
behavior. Follow up patches will address the missing documentation.
---
 .../Inputs/basic-project/include/Calculator.h | 23 ++-
 .../Inputs/basic-project/src/Calculator.cpp   |  1 +
 .../test/clang-doc/basic-project.test | 18 +++
 3 files changed, 41 insertions(+), 1 deletion(-)

diff --git 
a/clang-tools-extra/test/clang-doc/Inputs/basic-project/include/Calculator.h 
b/clang-tools-extra/test/clang-doc/Inputs/basic-project/include/Calculator.h
index 6811834bc0159..195721d56fff6 100644
--- a/clang-tools-extra/test/clang-doc/Inputs/basic-project/include/Calculator.h
+++ b/clang-tools-extra/test/clang-doc/Inputs/basic-project/include/Calculator.h
@@ -43,4 +43,25 @@ class Calculator {
  * @throw std::invalid_argument if b is zero.
  */
 double divide(int a, int b);
-};
\ No newline at end of file
+
+/**
+ * @brief Performs the mod operation on integers.
+ *
+ * @param a First integer.
+ * @param b Second integer.
+ * @return The result of a % b.
+ */
+static int mod(int a, int b) {
+  return a % b;
+}
+
+/**
+ * @brief A static value.
+ */
+static constexpr int static_val = 10;
+
+/**
+ * @brief Holds a public value.
+ */
+int public_val = -1;
+};
diff --git 
a/clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Calculator.cpp 
b/clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Calculator.cpp
index 258ea22e46184..483d050e3225a 100644
--- a/clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Calculator.cpp
+++ b/clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Calculator.cpp
@@ -15,3 +15,4 @@ int Calculator::multiply(int a, int b) {
 double Calculator::divide(int a, int b) {
   return static_cast(a) / b;
 }
+
diff --git a/clang-tools-extra/test/clang-doc/basic-project.test 
b/clang-tools-extra/test/clang-doc/basic-project.test
index ef26e5b8916b4..822c93a4b2fc0 100644
--- a/clang-tools-extra/test/clang-doc/basic-project.test
+++ b/clang-tools-extra/test/clang-doc/basic-project.test
@@ -129,6 +129,12 @@
 //  HTML-CALC: brief
 //  HTML-CALC:  A simple calculator class.
 //  HTML-CALC:  Provides basic arithmetic operations.
+
+//  HTML-CALC: Members
+//  HTML-CALC: brief
+//  HTML-CALC:  Holds a public value.
+//  HTML-CALC: public int public_val
+
 //  HTML-CALC: Functions
 //  HTML-CALC: add
 //  HTML-CALC: public int add(int a, int b)
@@ -185,6 +191,18 @@
 //  HTML-CALC: throw
 //  HTML-CALC: if b is zero.
 
+//  HTML-CALC: public int mod(int a, int b)
+//   CALC-NO-REPOSITORY: Defined at line 20 of file 
.{{.}}src{{.}}Calculator.cpp
+//  CALC-REPOSITORY: Defined at line 
+// CALC-REPOSITORY-NEXT: https://repository.com/./src/Calculator.cpp#20";>20
+// CALC-LINE-PREFIX: https://repository.com/./src/Calculator.cpp#L20";>20
+// CALC-REPOSITORY-NEXT: of file 
+// CALC-REPOSITORY-NEXT: https://repository.com/./src/Calculator.cpp";>Calculator.cpp
+//  HTML-CALC: brief
+//  HTML-CALC:  Performs the mod operation on integers.
+//  HTML-CALC: return
+//  HTML-CALC:  The result of a % b.
+
 //  HTML-RECTANGLE: class Rectangle
 // RECTANGLE-NO-REPOSITORY: Defined at line 10 of file 
.{{.}}include{{.}}Rectangle.h
 //  RECTANGLE-REPOSITORY: 

>From 512a49d370e353285c54a6ea441bd5394ac67f68 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Fri, 11 Apr 2025 22:02:20 -0700
Subject: [PATCH 2/3] Fix file location in test checks

---
 clang-tools-extra/test/clang-doc/basic-project.test | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang-tools-extra/test/clang-doc/basic-project.test 
b/clang-tools-extra/test/clang-doc/basic-project.test
index 822c93a4b2fc0..6b6d512329c30 100644
--- a/clang-tools-extra/test/clang-doc/basic-project.test
+++ b/clang-tools-extra/test/clang-doc/basic-project.test
@@ -192,12 +192,12 @@
 //  HTML-CALC: if b is zero.
 
 //  HTML-CALC: public int mod(int a, int b)
-//   CALC-NO-REPOSITORY: Defined at line 20 of file 
.{{.}}src{{.}}Calculator.cpp
+//   CALC-NO-REPOSITORY: Defined at line 54 of file 
.{{.}}include{{.}}Calculator.h
 //  CALC-REPOSITORY: Defined at line 
-// CALC-REPOSITORY-NEXT: https://repository.com/./src/Calculator.cpp#20";>20
-// CALC-LINE-PREFIX: https://repository.com/./src/Calculator.cpp#L20";>20
+// CALC-REPOSITORY-NEXT: https://repository.com/./include/Calculator.h#54";>54
+// CALC-LINE-PREFIX: https://repository.com/./include/Calc

[libunwind] [libunwind][Haiku] Fix signal frame unwinding (PR #135367)

2025-04-12 Thread Jérôme Duval via cfe-commits

korli wrote:

> Yes, tested on `x86_64` and only `x86_64` (though support for other archs can 
> be added by as easy as defining a few offsets and registers). Requires Haiku 
> `hrev58811` to fully work with `tests/signal_unwind.pass.cpp`.
> 
> This is also the same implementation used in my debugger ports for Haiku.

Does it build on r1beta5?

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


[clang] [clang-tools-extra] Reland: [clang] Improved canonicalization for template specialization types (PR #135414)

2025-04-12 Thread Matheus Izvekov via cfe-commits

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


[clang] 761787d - Reland: [clang] Improved canonicalization for template specialization types (#135414)

2025-04-12 Thread via cfe-commits

Author: Matheus Izvekov
Date: 2025-04-12T14:26:30-03:00
New Revision: 761787d42576751afbaaba5107233ee849f81b6f

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

LOG: Reland: [clang] Improved canonicalization for template specialization 
types (#135414)

This relands https://github.com/llvm/llvm-project/pull/135119, after
fixing crashes seen in LLDB CI reported here:
https://github.com/llvm/llvm-project/pull/135119#issuecomment-2794910840

Fixes https://github.com/llvm/llvm-project/pull/135119

This changes the TemplateArgument representation to hold a flag
indicating whether a tempalte argument of expression type is supposed to
be canonical or not.

This gets one step closer to solving
https://github.com/llvm/llvm-project/issues/92292

This still doesn't try to unique as-written TSTs. While this would
increase the amount of memory savings and make code dealing with the AST
more well-behaved, profiling template argument lists is still too
expensive for this to be worthwhile, at least for now.

This also fixes the context creation of TSTs, so that they don't in some
cases get incorrectly flagged as sugar over their own canonical form.
This is captured in the test expectation change of some AST dumps.

This fixes some places which were unnecessarily canonicalizing these
TSTs.

Added: 


Modified: 
clang-tools-extra/clangd/AST.cpp
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/ASTContext.h
clang/include/clang/AST/PropertiesBase.td
clang/include/clang/AST/TemplateBase.h
clang/include/clang/AST/Type.h
clang/include/clang/AST/TypeProperties.td
clang/lib/AST/ASTContext.cpp
clang/lib/AST/ASTDiagnostic.cpp
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/ASTStructuralEquivalence.cpp
clang/lib/AST/DeclTemplate.cpp
clang/lib/AST/QualTypeNames.cpp
clang/lib/AST/TemplateBase.cpp
clang/lib/AST/Type.cpp
clang/lib/Sema/SemaCXXScopeSpec.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaLookup.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/lib/Sema/SemaTemplateVariadic.cpp
clang/lib/Sema/TreeTransform.h
clang/test/CXX/class.derived/class.derived.general/p2.cpp
clang/test/CXX/temp/temp.decls/temp.class.spec/p6.cpp
clang/test/SemaCXX/undefined-partial-specialization.cpp
clang/test/SemaTemplate/make_integer_seq.cpp
clang/test/SemaTemplate/type_pack_element.cpp
clang/unittests/AST/TypePrinterTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/AST.cpp 
b/clang-tools-extra/clangd/AST.cpp
index 66b587f00ff4a..3b991e5e9013f 100644
--- a/clang-tools-extra/clangd/AST.cpp
+++ b/clang-tools-extra/clangd/AST.cpp
@@ -439,7 +439,8 @@ QualType declaredType(const TypeDecl *D) {
   if (const auto *CTSD = llvm::dyn_cast(D))
 if (const auto *Args = CTSD->getTemplateArgsAsWritten())
   return Context.getTemplateSpecializationType(
-  TemplateName(CTSD->getSpecializedTemplate()), Args->arguments());
+  TemplateName(CTSD->getSpecializedTemplate()), Args->arguments(),
+  /*CanonicalArgs=*/std::nullopt);
   return Context.getTypeDeclType(D);
 }
 

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9c45965dc4d82..11f62bc881b03 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -303,6 +303,8 @@ Improvements to Clang's diagnostics
 - Clang now better preserves the sugared types of pointers to member.
 - Clang now better preserves the presence of the template keyword with 
dependent
   prefixes.
+- Clang now in more cases avoids printing 'type-parameter-X-X' instead of the 
name of
+  the template parameter.
 - Clang now respects the current language mode when printing expressions in
   diagnostics. This fixes a bunch of `bool` being printed as `_Bool`, and also
   a bunch of HLSL types being printed as their C++ equivalents.

diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index b1e6344576eb5..0f6c727f6f9ca 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -243,8 +243,7 @@ class ASTContext : public RefCountedBase {
   mutable llvm::FoldingSet PackExpansionTypes;
   mutable llvm::FoldingSet ObjCObjectTypes;
   mutable llvm::FoldingSet ObjCObjectPointerTypes;
-  mutable llvm::FoldingSet
-DependentUnaryTransformTypes;
+  mutable llvm::FoldingSet UnaryTransformTypes;
   // An AutoType can have a dependency on another AutoType via its template
   // arguments. Since both dependent and dependency are on the same set,
   // we can end up in an infinite recursion when looking for a node if we used
@@ -367,9 +366,6 @@ class ASTContext : public RefCounted

[clang] [Clang] Consider preferred_type in bitfield warnings (#116760) (PR #116785)

2025-04-12 Thread Oliver Hunt via cfe-commits

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


[clang] [clang-tools-extra] Reland: [clang] Improved canonicalization for template specialization types (PR #135414)

2025-04-12 Thread Matheus Izvekov via cfe-commits

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


[clang-tools-extra] [clang-doc] Pre-commit tests for static members and functions (PR #135456)

2025-04-12 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`sanitizer-aarch64-linux-bootstrap-asan` running on `sanitizer-buildbot8` while 
building `clang-tools-extra` at step 2 "annotate".

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


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

```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using lld-link: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using ld64.lld: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using wasm-ld: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using ld.lld: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld.lld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using lld-link: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using ld64.lld: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using wasm-ld: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/main.py:72:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 900 seconds was requested on the command line. Forcing 
timeout to be 900 seconds.
-- Testing: 87683 tests, 72 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 
FAIL: LLVM :: ExecutionEngine/JITLink/x86-64/MachO_weak_references.s (53457 of 
87683)
 TEST 'LLVM :: 
ExecutionEngine/JITLink/x86-64/MachO_weak_references.s' FAILED 

Exit Code: 1

Command Output (stderr):
--
rm -rf 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp
 && mkdir -p 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp
 # RUN: at line 1
+ rm -rf 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp
+ mkdir -p 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/llvm-mc
 -triple=x86_64-apple-macosx10.9 -filetype=obj -o 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp/macho_weak_refs.o
 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/MachO_weak_references.s
 # RUN: at line 2
+ 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/llvm-mc
 -triple=x86_64-apple-macosx10.9 -filetype=obj -o 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp/macho_weak_refs.o
 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/MachO_weak_references.s
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/llvm-jitlink
 -noexec -check-name=jitlink-check-bar-present -abs bar=0x1 
-check=/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/MachO_weak_references.s
 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/test/ExecutionEngine/JITLink/x86-64/Output/MachO_weak_references.s.tmp/macho_weak_refs.o
 # RUN: at line 3
+ 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/llvm-jitlink
 -noexec -check-name=jitlink-check-bar-present -abs bar=0x1 
-check=/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/test/ExecutionEngine/JITLink/x86-64/MachO_weak_references.s
 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/test/ExecutionEngi

[libunwind] [libunwind][Haiku] Fix signal frame unwinding (PR #135367)

2025-04-12 Thread Jérôme Duval via cfe-commits

korli wrote:

Tested on x86_64? 

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


[clang] [clang-format][NFC] Add isJava() and isTextProto() in FormatStyle (PR #135466)

2025-04-12 Thread Björn Schäpers via cfe-commits

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


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


[clang] [clang-format] Wrap and indent lambda braces in GNU style (PR #135479)

2025-04-12 Thread Björn Schäpers via cfe-commits

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


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


[clang] [clang-tools-extra] Reland: [clang] Improved canonicalization for template specialization types (PR #135414)

2025-04-12 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`sanitizer-x86_64-linux-fast` running on `sanitizer-buildbot4` while building 
`clang-tools-extra,clang` at step 2 "annotate".

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


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

```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using lld-link: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using ld64.lld: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using wasm-ld: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using ld.lld: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using lld-link: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using ld64.lld: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using wasm-ld: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/lit/lit/main.py:72:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 900 seconds was requested on the command line. Forcing 
timeout to be 900 seconds.
-- Testing: 90177 tests, 88 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80
FAIL: Clang :: Interpreter/global-dtor.cpp (37396 of 90177)
 TEST 'Clang :: Interpreter/global-dtor.cpp' FAILED 

Exit Code: 1

Command Output (stderr):
--
cat 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Interpreter/global-dtor.cpp
 | 
/home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/clang-repl 
| /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/FileCheck 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Interpreter/global-dtor.cpp
 # RUN: at line 6
+ cat 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Interpreter/global-dtor.cpp
+ /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/clang-repl
+ /home/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan_ubsan/bin/FileCheck 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Interpreter/global-dtor.cpp
JIT session error: In graph incr_module_10-jitted-objectbuffer, section 
.text.startup: relocation target "__dso_handle" at address 0x7c63462ba000 is 
out of range of Delta32 fixup at 0x786344e0d02f ( @ 
0x786344e0d010 + 0x1f)
error: Failed to materialize symbols: { (main, { $.incr_module_10.__inits.0, 
_ZN1DC2Ev, __clang_call_terminate, DW.ref.__gxx_personality_v0, d, _ZN1DD2Ev, 
__orc_init_func.incr_module_10 }) }
error: Failed to materialize symbols: { (main, { __orc_init_func.incr_module_10 
}) }
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Interpreter/global-dtor.cpp:11:11:
 error: CHECK: expected string not found in input
// CHECK: D[f=1.00, m=0x0]
  ^
:1:1: note: scanning from here
clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> 
clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> 
clang-repl> 
^
:1:11: note: possible intended match here
clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> 
clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> 
clang-repl> 
  ^

Input file: 
Check file: 
/home/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/Interpreter/global-dtor.cpp

-dump-input=help explains the following input dump.

Input was:
<<
1: clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> 
clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> 
clang-repl> clang-repl>  
check:11'0 
X
 error: no match found
check:11'1   ?  
 

[clang] [Clang] Improve ``-Wtautological-overlap-compare`` diagnostics flag (PR #133653)

2025-04-12 Thread Yutong Zhu via cfe-commits

https://github.com/YutongZhuu updated 
https://github.com/llvm/llvm-project/pull/133653

>From ca795c3f27e37ad8a8f165a3b10e9415cbfd66a5 Mon Sep 17 00:00:00 2001
From: Yutong Zhu 
Date: Sat, 12 Apr 2025 15:32:46 -0400
Subject: [PATCH] Improved the -Wtautological-overlap-compare diagnostics to
 warn about overlapping and non-overlapping ranges involving character
 literals and floating-point literals.

---
 clang/docs/ReleaseNotes.rst   |   3 +
 .../clang/Basic/DiagnosticSemaKinds.td|   2 +-
 clang/lib/Analysis/CFG.cpp| 179 +++---
 clang/lib/Sema/AnalysisBasedWarnings.cpp  |   5 +-
 clang/test/Sema/warn-overlap.c| 119 ++--
 5 files changed, 211 insertions(+), 97 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 11f62bc881b03..de5c877cf996b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -352,6 +352,9 @@ Improvements to Clang's diagnostics
 - Now correctly diagnose a tentative definition of an array with static
   storage duration in pedantic mode in C. (#GH50661)
 
+- Improved the ``-Wtautological-overlap-compare`` diagnostics to warn about 
overlapping and non-overlapping ranges involving character literals and 
floating-point literals. 
+  The warning message for non-overlapping cases has also been improved 
(#GH13473).
+  
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 180ca39bc07e9..c8b5c94676d18 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10356,7 +10356,7 @@ def warn_tautological_negation_or_compare: Warning<
   "'||' of a value and its negation always evaluates to true">,
   InGroup, DefaultIgnore;
 def warn_tautological_overlap_comparison : Warning<
-  "overlapping comparisons always evaluate to %select{false|true}0">,
+  "%select{non-|}0overlapping comparisons always evaluate to 
%select{false|true}0">,
   InGroup, DefaultIgnore;
 def warn_depr_array_comparison : Warning<
   "comparison between two arrays is deprecated; "
diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index 9af1e915482da..ec7c1fbfc423a 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/lib/Analysis/CFG.cpp
@@ -70,19 +70,18 @@ static SourceLocation GetEndLoc(Decl *D) {
   return D->getLocation();
 }
 
-/// Returns true on constant values based around a single IntegerLiteral.
-/// Allow for use of parentheses, integer casts, and negative signs.
-/// FIXME: it would be good to unify this function with
-/// getIntegerLiteralSubexpressionValue at some point given the similarity
-/// between the functions.
+/// Returns true on constant values based around a single IntegerLiteral,
+/// CharacterLiteral, or FloatingLiteral. Allow for use of parentheses, integer
+/// casts, and negative signs.
 
-static bool IsIntegerLiteralConstantExpr(const Expr *E) {
+static bool IsLiteralConstantExpr(const Expr *E) {
   // Allow parentheses
   E = E->IgnoreParens();
 
   // Allow conversions to different integer kind.
   if (const auto *CE = dyn_cast(E)) {
-if (CE->getCastKind() != CK_IntegralCast)
+if (CE->getCastKind() != CK_IntegralCast &&
+CE->getCastKind() != CK_IntegralToFloating)
   return false;
 E = CE->getSubExpr();
   }
@@ -93,16 +92,16 @@ static bool IsIntegerLiteralConstantExpr(const Expr *E) {
   return false;
 E = UO->getSubExpr();
   }
-
-  return isa(E);
+  return isa(E) || isa(E) ||
+ isa(E);
 }
 
 /// Helper for tryNormalizeBinaryOperator. Attempts to extract an 
IntegerLiteral
-/// constant expression or EnumConstantDecl from the given Expr. If it fails,
-/// returns nullptr.
-static const Expr *tryTransformToIntOrEnumConstant(const Expr *E) {
+/// FloatingLiteral, CharacterLiteral or EnumConstantDecl from the given Expr.
+/// If it fails, returns nullptr.
+static const Expr *tryTransformToLiteralConstant(const Expr *E) {
   E = E->IgnoreParens();
-  if (IsIntegerLiteralConstantExpr(E))
+  if (IsLiteralConstantExpr(E))
 return E;
   if (auto *DR = dyn_cast(E->IgnoreParenImpCasts()))
 return isa(DR->getDecl()) ? DR : nullptr;
@@ -119,7 +118,7 @@ tryNormalizeBinaryOperator(const BinaryOperator *B) {
   BinaryOperatorKind Op = B->getOpcode();
 
   const Expr *MaybeDecl = B->getLHS();
-  const Expr *Constant = tryTransformToIntOrEnumConstant(B->getRHS());
+  const Expr *Constant = tryTransformToLiteralConstant(B->getRHS());
   // Expr looked like `0 == Foo` instead of `Foo == 0`
   if (Constant == nullptr) {
 // Flip the operator
@@ -133,7 +132,7 @@ tryNormalizeBinaryOperator(const BinaryOperator *B) {
   Op = BO_GE;
 
 MaybeDecl = B->getRHS();
-Constant = tryTransformToIntOrEnumConstant(B->getLHS());
+Constant = tryTransformToLiteralConstant(B->getLHS());
   }
 
   return std:

[clang] [Clang][P1061] Fix invalid pack binding crash (PR #135129)

2025-04-12 Thread Jason Rice via cfe-commits

ricejasonf wrote:

Sorry, I haven't had time to revisit this, but in that test we are only 
checking the validity of the decomposition declarations so I think the addition 
of `constexpr` to that variable should not affect the checks on the other 
declarations. There is plenty of coverage on decompositions in the other not 
"nontemplate" test file. Still, I probably did not need to step on the original 
test like that. I will consider adding more "invalid declaration" tests and 
address this when I get more time. Thank you.

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


[clang] [Serialization] Fix lazy template loading (PR #133057)

2025-04-12 Thread Jonas Hahnfeld via cfe-commits

hahnjo wrote:

> When I have time, I will need to see that I turn the reduced example into 
> actual valid code to understand what is going on...

I spent some time turning it into valid code, but then noticed that the `error: 
use of overloaded operator '=' is ambiguous` is gone. Going back, the piece 
that triggers the error is the token `bns` in `TR7.cc`, which leads to `error: 
unknown type name 'bns'` and then messes up parsing of `namespace sr` in 
`UL8.h`. I believe the reproducer is not useful in the current form, you will 
have to instruct the reduce process to keep somewhat valid code...

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


[clang] [flang] [driver] Generalize the code that adds the path of libflang_rt.runtime.a. (PR #134362)

2025-04-12 Thread Michał Górny via cfe-commits

mgorny wrote:

I find this change quite confusing. It seems that `-static-libflangrt` now 
expects entirely different install location than `-shared-libflangrt`. 
Furthermore, the location used seems inconsistent with clang, i.e.:


/usr/lib/llvm/21/bin/../../../../lib/clang/21/lib/x86_64-pc-linux-gnu/libflang_rt.runtime.a

whereas clang uses `lib/linux/libclang_rt.builtins-x86_64.a` and so on.

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


[clang] [flang] [driver] Generalize the code that adds the path of libflang_rt.runtime.a. (PR #134362)

2025-04-12 Thread Michał Górny via cfe-commits

mgorny wrote:

> I find this change quite confusing. It seems that `-static-libflangrt` now 
> expects entirely different install location than `-shared-libflangrt`.

Ah, sorry, now I see that 
`-L/usr/lib/llvm/21/bin/../../../../lib/clang/21/lib/x86_64-pc-linux-gnu` is 
also added, so the "resource dir" location should work for both options.

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


[clang] [Clang][CodeGen][UBSan] Remove redundant `EmitCheckValue` calls. NFCI (PR #135141)

2025-04-12 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`sanitizer-x86_64-linux-bootstrap-asan` running on `sanitizer-buildbot2` while 
building `clang` at step 2 "annotate".

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


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

```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using lld-link: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using ld64.lld: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using wasm-ld: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using ld.lld: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using lld-link: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using ld64.lld: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520:
 note: using wasm-ld: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/main.py:72:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 900 seconds was requested on the command line. Forcing 
timeout to be 900 seconds.
-- Testing: 90167 tests, 88 workers --
Testing:  0.. 10
FAIL: Clang :: Interpreter/inline-virtual.cpp (12964 of 90167)
 TEST 'Clang :: Interpreter/inline-virtual.cpp' FAILED 

Exit Code: 1

Command Output (stderr):
--
cat 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/clang/test/Interpreter/inline-virtual.cpp
 | 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/clang-repl
 -Xcc -fno-rtti -Xcc -fno-sized-deallocation  | 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/FileCheck
 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/clang/test/Interpreter/inline-virtual.cpp
 # RUN: at line 6
+ cat 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/clang/test/Interpreter/inline-virtual.cpp
+ 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/clang-repl
 -Xcc -fno-rtti -Xcc -fno-sized-deallocation
+ 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/FileCheck
 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/clang/test/Interpreter/inline-virtual.cpp
JIT session error: In graph incr_module_23-jitted-objectbuffer, section 
.text.startup: relocation target "_ZN1AD2Ev" at address 0x71842da4d040 is out 
of range of Delta32 fixup at 0x6d842c80d02d ( @ 0x6d842c80d010 
+ 0x1d)
error: Failed to materialize symbols: { (main, { a2, 
$.incr_module_23.__inits.0, __orc_init_func.incr_module_23 }) }
error: Failed to materialize symbols: { (main, { __orc_init_func.incr_module_23 
}) }
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/clang/test/Interpreter/inline-virtual.cpp:26:11:
 error: CHECK: expected string not found in input
// CHECK: ~A(2)
  ^
:1:262: note: scanning from here
clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> 
clang-repl... clang-repl> clang-repl... clang-repl> clang-repl> clang-repl> 
clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> 
clang-repl> clang-repl> clang-repl> ~A(1)



 ^

Input file: 
Check file: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/clang/test/Interpreter/inline-virtual.cpp

-dump-input=help explains the following input dump.

Input was:
<<
  1: clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> 
clang-repl> clang-repl... clang-repl> clang-repl... clang-repl> 

[clang] [clang-format] Wrap and indent lambda braces in GNU style (PR #135479)

2025-04-12 Thread Owen Pan via cfe-commits


@@ -1334,6 +1334,11 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState &State) {
Style.IndentWidth;
   }
 
+  if (Style.BraceWrapping.BeforeLambdaBody &&
+  Style.BraceWrapping.IndentBraces && Current.is(TT_LambdaLBrace)) {
+return CurrentState.Indent + Style.IndentWidth;
+  }

owenca wrote:

> It might also be worth extracting the handling for `TT_LambdaLBrace` from the 
> `if` just below and putting it here to keep it all together?

Not sure if it'd be worthwhile, but that can be done in another NFC patch.

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


[clang] [clang-format] Wrap and indent lambda braces in GNU style (PR #135479)

2025-04-12 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/135479

>From f041f9c3eac94b8f1322ebaa9dfd60d4287840d7 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Fri, 11 Apr 2025 23:36:37 -0700
Subject: [PATCH 1/2] [clang-format] Wrap and indent lambda braces in GNU style

Fix #133135
---
 clang/lib/Format/ContinuationIndenter.cpp | 5 +
 clang/lib/Format/Format.cpp   | 2 +-
 clang/unittests/Format/FormatTest.cpp | 9 +
 3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 1969f4297b211..9bebac1bed5c6 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1334,6 +1334,11 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState &State) {
Style.IndentWidth;
   }
 
+  if (Style.BraceWrapping.BeforeLambdaBody &&
+  Style.BraceWrapping.IndentBraces && Current.is(TT_LambdaLBrace)) {
+return CurrentState.Indent + Style.IndentWidth;
+  }
+
   if ((NextNonComment->is(tok::l_brace) && NextNonComment->is(BK_Block)) ||
   (Style.isVerilog() && Keywords.isVerilogBegin(*NextNonComment))) {
 if (Current.NestingLevel == 0 ||
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index b90bd8276e1e2..57175a0be1a6b 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1435,7 +1435,7 @@ static void expandPresetsBraceWrapping(FormatStyle 
&Expanded) {
 /*AfterExternBlock=*/true,
 /*BeforeCatch=*/true,
 /*BeforeElse=*/true,
-/*BeforeLambdaBody=*/false,
+/*BeforeLambdaBody=*/true,
 /*BeforeWhile=*/true,
 /*IndentBraces=*/true,
 /*SplitEmptyFunction=*/true,
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index f0e67c604cc4b..108d5b90e31f8 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -24268,6 +24268,15 @@ TEST_F(FormatTest, EmptyLinesInLambdas) {
"};");
 }
 
+TEST_F(FormatTest, LambdaBracesInGNU) {
+  verifyFormat("auto x = [&] ()\n"
+   "  {\n"
+   "for (int i = 0; i < y; ++i)\n"
+   "  return 97;\n"
+   "  };",
+   getGNUStyle());
+}
+
 TEST_F(FormatTest, FormatsBlocks) {
   FormatStyle ShortBlocks = getLLVMStyle();
   ShortBlocks.AllowShortBlocksOnASingleLine = FormatStyle::SBS_Always;

>From 5a9aa414c32d2b57e12e2c639e6385275ee91acd Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sat, 12 Apr 2025 03:51:23 -0700
Subject: [PATCH 2/2] Also handle LBI_OuterScope

---
 clang/lib/Format/ContinuationIndenter.cpp |  8 --
 clang/unittests/Format/FormatTest.cpp | 32 +++
 2 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 9bebac1bed5c6..1cf15ea65681d 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1336,7 +1336,10 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState &State) {
 
   if (Style.BraceWrapping.BeforeLambdaBody &&
   Style.BraceWrapping.IndentBraces && Current.is(TT_LambdaLBrace)) {
-return CurrentState.Indent + Style.IndentWidth;
+const auto From = Style.LambdaBodyIndentation == FormatStyle::LBI_Signature
+  ? CurrentState.Indent
+  : State.FirstIndent;
+return From + Style.IndentWidth;
   }
 
   if ((NextNonComment->is(tok::l_brace) && NextNonComment->is(BK_Block)) ||
@@ -2118,7 +2121,8 @@ void ContinuationIndenter::moveStateToNewBlock(LineState 
&State, bool NewLine) {
   if (Style.LambdaBodyIndentation == FormatStyle::LBI_OuterScope &&
   State.NextToken->is(TT_LambdaLBrace) &&
   !State.Line->MightBeFunctionDecl) {
-State.Stack.back().NestedBlockIndent = State.FirstIndent;
+const auto Indent = Style.IndentWidth * Style.BraceWrapping.IndentBraces;
+State.Stack.back().NestedBlockIndent = State.FirstIndent + Indent;
   }
   unsigned NestedBlockIndent = State.Stack.back().NestedBlockIndent;
   // ObjC block sometimes follow special indentation rules.
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 108d5b90e31f8..7163a49820ae2 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -24269,12 +24269,34 @@ TEST_F(FormatTest, EmptyLinesInLambdas) {
 }
 
 TEST_F(FormatTest, LambdaBracesInGNU) {
-  verifyFormat("auto x = [&] ()\n"
+  auto Style = getGNUStyle();
+  EXPECT_EQ(Style.LambdaBodyIndentation, FormatStyle::LBI_Signature);
+
+  constexpr StringRef Code("auto x = [&] ()\n"
+   "  {\n"
+   "for (int i = 0; i < y; ++i)\n"
+   "  return 97;\n"
+ 

[clang] [clang-tools-extra] [clang] implement printing of canonical expressions (PR #135133)

2025-04-12 Thread Matheus Izvekov via cfe-commits

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


[clang-tools-extra] [clang-tidy] Avoid diagnosing std::array initializations for modernize-use-designated-initializers (PR #134774)

2025-04-12 Thread David Rivera via cfe-commits

https://github.com/RiverDave updated 
https://github.com/llvm/llvm-project/pull/134774

>From bf1294a2be9da63717087f8940a7bad5b3c522f6 Mon Sep 17 00:00:00 2001
From: David Rivera 
Date: Mon, 7 Apr 2025 23:21:50 -0400
Subject: [PATCH 1/2] [clang-tidy] Avoid diagnosing std::array initializations
 for modernize-use-designated-initializers

---
 .../modernize/UseDesignatedInitializersCheck.cpp   | 7 ++-
 clang-tools-extra/docs/ReleaseNotes.rst| 4 
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
index 3132067f3d5ec..9e2ac149d0868 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
@@ -119,13 +119,18 @@ 
UseDesignatedInitializersCheck::UseDesignatedInitializersCheck(
 void UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
   const auto HasBaseWithFields =
   hasAnyBase(hasType(cxxRecordDecl(has(fieldDecl();
+
+  // see #133715
+  const auto IsSTLArray =
+  hasType(qualType(hasDeclaration(recordDecl(hasName("::std::array");
+
   Finder->addMatcher(
   initListExpr(
   hasType(cxxRecordDecl(RestrictToPODTypes ? isPOD() : isAggregate(),
 unless(HasBaseWithFields))
   .bind("type")),
   IgnoreSingleElementAggregates ? hasMoreThanOneElement() : anything(),
-  unless(isFullyDesignated()))
+  unless(anyOf(isFullyDesignated(), IsSTLArray)))
   .bind("init"),
   this);
 }
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 6c1f05009df98..44c348f453543 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -171,6 +171,10 @@ Changes in existing checks
   ``constexpr`` and ``static``` values on member initialization and by 
detecting
   explicit casting of built-in types within member list initialization.
 
+- Improved :doc:`modernize-use-designated-initializers
+  ` check by avoiding
+  diagnosing designated initializers for ``std::array`` initializations.
+
 - Improved :doc:`modernize-use-ranges
   ` check by updating suppress 
   warnings logic for ``nullptr`` in ``std::find``.

>From 9727ea1d3990f6612231cbd087532bc5a021c2d9 Mon Sep 17 00:00:00 2001
From: David Rivera 
Date: Sat, 12 Apr 2025 19:55:39 -0400
Subject: [PATCH 2/2] [clang-tidy] avoid diagnosing std::array initializations
 for modernize-use-designated-initializers when IgnoreSingleElementAggregates
 is false

---
 .../modernize/UseDesignatedInitializersCheck.cpp  | 11 +--
 clang-tools-extra/docs/ReleaseNotes.rst   |  3 ++-
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
index 9e2ac149d0868..296887119c310 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
@@ -120,17 +120,16 @@ void 
UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
   const auto HasBaseWithFields =
   hasAnyBase(hasType(cxxRecordDecl(has(fieldDecl();
 
-  // see #133715
-  const auto IsSTLArray =
-  hasType(qualType(hasDeclaration(recordDecl(hasName("::std::array");
-
   Finder->addMatcher(
   initListExpr(
   hasType(cxxRecordDecl(RestrictToPODTypes ? isPOD() : isAggregate(),
-unless(HasBaseWithFields))
+unless(anyOf(HasBaseWithFields,
+ IgnoreSingleElementAggregates
+ ? hasName("::std::array")
+ : anything(
   .bind("type")),
   IgnoreSingleElementAggregates ? hasMoreThanOneElement() : anything(),
-  unless(anyOf(isFullyDesignated(), IsSTLArray)))
+  unless(isFullyDesignated()))
   .bind("init"),
   this);
 }
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 44c348f453543..f6f1d27c1cff7 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -173,7 +173,8 @@ Changes in existing checks
 
 - Improved :doc:`modernize-use-designated-initializers
   ` check by avoiding
-  diagnosing designated initializers for ``std::array`` initializations.
+  diagnosing designated initializers for ``std::array`` initializations when
+  `IgnoreSingleElementAggregates` is false.
 
 - Improved :doc:`modernize-use-ranges
   ` check by updating suppress 

___

[clang-tools-extra] [clang-tidy] Avoid diagnosing std::array initializations for modernize-use-designated-initializers (PR #134774)

2025-04-12 Thread David Rivera via cfe-commits

https://github.com/RiverDave updated 
https://github.com/llvm/llvm-project/pull/134774

>From bf1294a2be9da63717087f8940a7bad5b3c522f6 Mon Sep 17 00:00:00 2001
From: David Rivera 
Date: Mon, 7 Apr 2025 23:21:50 -0400
Subject: [PATCH 1/2] [clang-tidy] Avoid diagnosing std::array initializations
 for modernize-use-designated-initializers

---
 .../modernize/UseDesignatedInitializersCheck.cpp   | 7 ++-
 clang-tools-extra/docs/ReleaseNotes.rst| 4 
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
index 3132067f3d5ec..9e2ac149d0868 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
@@ -119,13 +119,18 @@ 
UseDesignatedInitializersCheck::UseDesignatedInitializersCheck(
 void UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
   const auto HasBaseWithFields =
   hasAnyBase(hasType(cxxRecordDecl(has(fieldDecl();
+
+  // see #133715
+  const auto IsSTLArray =
+  hasType(qualType(hasDeclaration(recordDecl(hasName("::std::array");
+
   Finder->addMatcher(
   initListExpr(
   hasType(cxxRecordDecl(RestrictToPODTypes ? isPOD() : isAggregate(),
 unless(HasBaseWithFields))
   .bind("type")),
   IgnoreSingleElementAggregates ? hasMoreThanOneElement() : anything(),
-  unless(isFullyDesignated()))
+  unless(anyOf(isFullyDesignated(), IsSTLArray)))
   .bind("init"),
   this);
 }
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 6c1f05009df98..44c348f453543 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -171,6 +171,10 @@ Changes in existing checks
   ``constexpr`` and ``static``` values on member initialization and by 
detecting
   explicit casting of built-in types within member list initialization.
 
+- Improved :doc:`modernize-use-designated-initializers
+  ` check by avoiding
+  diagnosing designated initializers for ``std::array`` initializations.
+
 - Improved :doc:`modernize-use-ranges
   ` check by updating suppress 
   warnings logic for ``nullptr`` in ``std::find``.

>From 65fc264b7cdd33a6f8d8ad6d76a9c2f5e551955a Mon Sep 17 00:00:00 2001
From: David Rivera 
Date: Sat, 12 Apr 2025 19:55:39 -0400
Subject: [PATCH 2/2] [clang-tidy] avoid diagnosing std::array initializations
 for modernize-use-designated-initializers when IgnoreSingleElementAggregates
 is false

---
 .../modernize/UseDesignatedInitializersCheck.cpp | 12 +---
 clang-tools-extra/docs/ReleaseNotes.rst  |  3 ++-
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
index 9e2ac149d0868..508d9ed821cae 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
@@ -119,18 +119,16 @@ 
UseDesignatedInitializersCheck::UseDesignatedInitializersCheck(
 void UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
   const auto HasBaseWithFields =
   hasAnyBase(hasType(cxxRecordDecl(has(fieldDecl();
-
-  // see #133715
-  const auto IsSTLArray =
-  hasType(qualType(hasDeclaration(recordDecl(hasName("::std::array");
-
   Finder->addMatcher(
   initListExpr(
   hasType(cxxRecordDecl(RestrictToPODTypes ? isPOD() : isAggregate(),
-unless(HasBaseWithFields))
+unless(anyOf(HasBaseWithFields,
+ IgnoreSingleElementAggregates
+ ? hasName("::std::array")
+ : anything(
   .bind("type")),
   IgnoreSingleElementAggregates ? hasMoreThanOneElement() : anything(),
-  unless(anyOf(isFullyDesignated(), IsSTLArray)))
+  unless(isFullyDesignated()))
   .bind("init"),
   this);
 }
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 44c348f453543..f6f1d27c1cff7 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -173,7 +173,8 @@ Changes in existing checks
 
 - Improved :doc:`modernize-use-designated-initializers
   ` check by avoiding
-  diagnosing designated initializers for ``std::array`` initializations.
+  diagnosing designated initializers for ``std::array`` initializations when
+  `IgnoreSingleElementAggregates` is false.
 
 - Improved :doc:`mo

[clang-tools-extra] [clang-tidy] Improve integer comparison by matching valid expressions outside implicitCastExpr (PR #134188)

2025-04-12 Thread David Rivera via cfe-commits

https://github.com/RiverDave updated 
https://github.com/llvm/llvm-project/pull/134188

>From 56fc987f62fcc0ad74924bea0351efaebee23547 Mon Sep 17 00:00:00 2001
From: David Rivera 
Date: Wed, 2 Apr 2025 21:02:00 -0400
Subject: [PATCH] [clang-tidy] Improve integer comparison by matching valid
 expressions outside implicitCastExpr

---
 .../UseIntegerSignComparisonCheck.cpp | 17 +---
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 +++
 .../modernize/use-integer-sign-comparison.cpp | 26 +++
 3 files changed, 44 insertions(+), 3 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
index eeba5cce80da5..8f2bb4c4ba8f2 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
@@ -39,9 +39,11 @@ intCastExpression(bool IsSigned,
   // std::cmp_{} functions trigger a compile-time error if either LHS or RHS
   // is a non-integer type, char, enum or bool
   // (unsigned char/ signed char are Ok and can be used).
-  auto IntTypeExpr = expr(hasType(hasCanonicalType(qualType(
+  const auto HasIntegerType = hasType(hasCanonicalType(qualType(
   isInteger(), IsSigned ? isSignedInteger() : isUnsignedInteger(),
-  unless(isActualChar()), unless(booleanType()), unless(enumType());
+  unless(isActualChar()), unless(booleanType()), unless(enumType();
+
+  auto IntTypeExpr = expr(HasIntegerType);
 
   const auto ImplicitCastExpr =
   CastBindName.empty() ? implicitCastExpr(hasSourceExpression(IntTypeExpr))
@@ -52,8 +54,17 @@ intCastExpression(bool IsSigned,
   const auto StaticCastExpr = cxxStaticCastExpr(has(ImplicitCastExpr));
   const auto FunctionalCastExpr = cxxFunctionalCastExpr(has(ImplicitCastExpr));
 
+  // Match function calls or variable references not directly wrapped by an
+  // implicit cast
+  const auto CallIntExpr = CastBindName.empty()
+   ? callExpr(HasIntegerType)
+   : callExpr(HasIntegerType).bind(CastBindName);
+  const auto DeclRefIntExpr =
+  CastBindName.empty() ? declRefExpr(HasIntegerType)
+   : declRefExpr(HasIntegerType).bind(CastBindName);
+
   return expr(anyOf(ImplicitCastExpr, CStyleCastExpr, StaticCastExpr,
-FunctionalCastExpr));
+FunctionalCastExpr, CallIntExpr));
 }
 
 static StringRef parseOpCode(BinaryOperator::Opcode Code) {
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 761c1d3a80359..b39723cd99493 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -182,6 +182,10 @@ Changes in existing checks
   ``constexpr`` and ``static``` values on member initialization and by 
detecting
   explicit casting of built-in types within member list initialization.
 
+- Improved :doc:`modernize-use-integer-sign-comparison
+  ` check by matching
+  valid integer expressions not directly wrapped around an implicit cast.
+
 - Improved :doc:`modernize-use-ranges
   ` check by updating suppress 
   warnings logic for ``nullptr`` in ``std::find``.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-integer-sign-comparison.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-integer-sign-comparison.cpp
index e0a84ef5aed26..158861cc59486 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-integer-sign-comparison.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-integer-sign-comparison.cpp
@@ -121,3 +121,29 @@ int AllComparisons() {
 
 return 0;
 }
+
+namespace PR127471 {
+int getSignedValue();
+unsigned int getUnsignedValue();
+
+void callExprTest() {
+
+if (getSignedValue() < getUnsignedValue())
+return;
+// CHECK-MESSAGES: :[[@LINE-2]]:13: warning: comparison between 'signed' and 
'unsigned' integers [modernize-use-integer-sign-comparison]
+// CHECK-FIXES:  if (std::cmp_less(getSignedValue() , getUnsignedValue()))
+
+int sVar = 0;
+if (getUnsignedValue() > sVar)
+return;
+// CHECK-MESSAGES: :[[@LINE-2]]:13: warning: comparison between 'signed' and 
'unsigned' integers [modernize-use-integer-sign-comparison]
+// CHECK-FIXES: if (std::cmp_greater(getUnsignedValue() , sVar))
+
+unsigned int uVar = 0;
+if (getSignedValue() > uVar)
+return;
+// CHECK-MESSAGES: :[[@LINE-2]]:13: warning: comparison between 'signed' and 
'unsigned' integers [modernize-use-integer-sign-comparison]
+// CHECK-FIXES: if (std::cmp_greater(getSignedValue() , uVar))
+
+}
+} // namespace PR127471

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


[clang-tools-extra] [clang-tidy] Improve integer comparison by matching valid expressions outside implicitCastExpr (PR #134188)

2025-04-12 Thread David Rivera via cfe-commits

RiverDave wrote:

Ping

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


[clang-tools-extra] [clang-doc][NFC] clean unused variable in HTML generator (PR #135505)

2025-04-12 Thread Petr Hosek via cfe-commits

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


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


[libunwind] [libunwind][Haiku] Fix signal frame unwinding (PR #135367)

2025-04-12 Thread Trung Nguyen via cfe-commits

trungnt2910 wrote:

> Does it build on r1beta5?

Theoretically yes, since I did not require any new Haiku nightly feature for 
tge implementation.

The unwinding might not fully work due to missing CFE information in `libroot`, 
in this case for `_kern_send_signal`.



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


[clang] [clang-tools-extra] [clang] implement printing of canonical template arguments of expression kind (PR #135133)

2025-04-12 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/135133

>From 6876f4a602b44d587eb62163acd3e769b212b40b Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Thu, 10 Apr 2025 02:52:36 -0300
Subject: [PATCH] [clang] implement printing of canonical expressions

This patch extends the canonicalization printing policy to cover expressions
and template names, and wires that up to the template argument printer,
covering expressions, and to the expression within a dependent decltype.

This is helpful for debugging, or if these expressions somehow end up
in diagnostics, as without this patch they can print as completely unrelated
expressions, which can be quite confusing.

This is because expressions are not uniqued, unlike types, and
when a template specialization containing an expression is the first to be
canonicalized, the expression ends up appearing in the canonical type of
subsequent equivalent specializations.

Fixes https://github.com/llvm/llvm-project/issues/92292
---
 .../StaticAccessedThroughInstanceCheck.cpp|2 +-
 .../clang-tidy/utils/Matchers.cpp |2 +-
 clang/include/clang/AST/PrettyPrinter.h   |6 +-
 clang/lib/AST/DeclPrinter.cpp |4 +-
 clang/lib/AST/JSONNodeDumper.cpp  |2 +
 clang/lib/AST/StmtPrinter.cpp |6 +-
 clang/lib/AST/TemplateBase.cpp|7 +-
 clang/lib/AST/TemplateName.cpp|   10 +-
 clang/lib/AST/TextNodeDumper.cpp  |2 +
 clang/lib/AST/TypePrinter.cpp |   16 +-
 clang/lib/CodeGen/CGDebugInfo.cpp |2 +-
 clang/lib/Sema/SemaTemplate.cpp   |2 +-
 clang/test/AST/ast-dump-templates.cpp | 1022 +
 .../test/CXX/temp/temp.decls/temp.mem/p5.cpp  |   17 +
 clang/unittests/AST/TypePrinterTest.cpp   |2 +-
 15 files changed, 1080 insertions(+), 22 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
 
b/clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
index 08adc7134cfea..fffb136e5a332 100644
--- 
a/clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
@@ -69,7 +69,7 @@ void StaticAccessedThroughInstanceCheck::check(
   PrintingPolicyWithSuppressedTag.SuppressTagKeyword = true;
   PrintingPolicyWithSuppressedTag.SuppressUnwrittenScope = true;
 
-  PrintingPolicyWithSuppressedTag.PrintCanonicalTypes =
+  PrintingPolicyWithSuppressedTag.PrintAsCanonical =
   !BaseExpr->getType()->isTypedefNameType();
 
   std::string BaseTypeName =
diff --git a/clang-tools-extra/clang-tidy/utils/Matchers.cpp 
b/clang-tools-extra/clang-tidy/utils/Matchers.cpp
index 7e89cae1c3316..0721667fd0c41 100644
--- a/clang-tools-extra/clang-tidy/utils/Matchers.cpp
+++ b/clang-tools-extra/clang-tidy/utils/Matchers.cpp
@@ -32,7 +32,7 @@ bool MatchesAnyListedTypeNameMatcher::matches(
 
   PrintingPolicy PrintingPolicyWithSuppressedTag(
   Finder->getASTContext().getLangOpts());
-  PrintingPolicyWithSuppressedTag.PrintCanonicalTypes = true;
+  PrintingPolicyWithSuppressedTag.PrintAsCanonical = true;
   PrintingPolicyWithSuppressedTag.SuppressElaboration = true;
   PrintingPolicyWithSuppressedTag.SuppressScope = false;
   PrintingPolicyWithSuppressedTag.SuppressTagKeyword = true;
diff --git a/clang/include/clang/AST/PrettyPrinter.h 
b/clang/include/clang/AST/PrettyPrinter.h
index 91818776b770c..5a98ae1987b16 100644
--- a/clang/include/clang/AST/PrettyPrinter.h
+++ b/clang/include/clang/AST/PrettyPrinter.h
@@ -76,7 +76,7 @@ struct PrintingPolicy {
 MSWChar(LO.MicrosoftExt && !LO.WChar), IncludeNewlines(true),
 MSVCFormatting(false), ConstantsAsWritten(false),
 SuppressImplicitBase(false), FullyQualifiedName(false),
-PrintCanonicalTypes(false), PrintInjectedClassNameWithArguments(true),
+PrintAsCanonical(false), PrintInjectedClassNameWithArguments(true),
 UsePreferredNames(true), AlwaysIncludeTypeForTemplateArgument(false),
 CleanUglifiedParameters(false), EntireContentsOfLargeArray(true),
 UseEnumerators(true), UseHLSLTypes(LO.HLSL) {}
@@ -310,9 +310,9 @@ struct PrintingPolicy {
   LLVM_PREFERRED_TYPE(bool)
   unsigned FullyQualifiedName : 1;
 
-  /// Whether to print types as written or canonically.
+  /// Whether to print entities as written or canonically.
   LLVM_PREFERRED_TYPE(bool)
-  unsigned PrintCanonicalTypes : 1;
+  unsigned PrintAsCanonical : 1;
 
   /// Whether to print an InjectedClassNameType with template arguments or as
   /// written. When a template argument is unnamed, printing it results in
diff --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp
index 28098b242d494..22da5bf251ecd 100644
--- a/clang/lib/AST/DeclPrinter.cpp
+++ b/clang/lib/AST/DeclPrinter.cpp
@@ -735,7 +735,7 @@ void DeclPrinter

[clang-tools-extra] [clang-tidy] Avoid diagnosing std::array initializations for modernize-use-designated-initializers (PR #134774)

2025-04-12 Thread David Rivera via cfe-commits


@@ -119,13 +119,18 @@ 
UseDesignatedInitializersCheck::UseDesignatedInitializersCheck(
 void UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
   const auto HasBaseWithFields =
   hasAnyBase(hasType(cxxRecordDecl(has(fieldDecl();
+
+  // see #133715
+  const auto IsSTLArray =
+  hasType(qualType(hasDeclaration(recordDecl(hasName("::std::array");
+
   Finder->addMatcher(
   initListExpr(
   hasType(cxxRecordDecl(RestrictToPODTypes ? isPOD() : isAggregate(),
 unless(HasBaseWithFields))

RiverDave wrote:

Good catch, fixed.

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


[clang-tools-extra] [clang-tidy] Avoid diagnosing std::array initializations for modernize-use-designated-initializers (PR #134774)

2025-04-12 Thread David Rivera via cfe-commits

RiverDave wrote:

> Ok, I see, let's disable for ::std::array then, generalize in the future if 
> we come across a similar use case.

Thanks, your feedback has been addressed.

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


[clang-tools-extra] [clang-doc] Handle static members and functions (PR #135457)

2025-04-12 Thread Paul Kirth via cfe-commits

https://github.com/ilovepi updated 
https://github.com/llvm/llvm-project/pull/135457

>From ca38d210bd3058575752ff9d21232e87a550a943 Mon Sep 17 00:00:00 2001
From: Paul Kirth 
Date: Mon, 7 Apr 2025 08:37:40 -0700
Subject: [PATCH 01/14] [clang-doc] Handle static members and functions

clang-doc didn't visit VarDecl, and hence never collected info
from class statics members and functions.

Fixes #59813.
---
 clang-tools-extra/clang-doc/Mapper.cpp|  4 ++
 clang-tools-extra/clang-doc/Mapper.h  |  1 +
 clang-tools-extra/clang-doc/Serialize.cpp | 56 +++
 clang-tools-extra/clang-doc/Serialize.h   |  4 ++
 .../test/clang-doc/basic-project.test | 13 -
 5 files changed, 77 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-doc/Mapper.cpp 
b/clang-tools-extra/clang-doc/Mapper.cpp
index 6c90db03424c6..98698f9151280 100644
--- a/clang-tools-extra/clang-doc/Mapper.cpp
+++ b/clang-tools-extra/clang-doc/Mapper.cpp
@@ -82,6 +82,10 @@ bool MapASTVisitor::VisitRecordDecl(const RecordDecl *D) {
   return mapDecl(D, D->isThisDeclarationADefinition());
 }
 
+bool MapASTVisitor::VisitVarDecl(const VarDecl *D) {
+  return mapDecl(D, D->isThisDeclarationADefinition());
+}
+
 bool MapASTVisitor::VisitEnumDecl(const EnumDecl *D) {
   return mapDecl(D, D->isThisDeclarationADefinition());
 }
diff --git a/clang-tools-extra/clang-doc/Mapper.h 
b/clang-tools-extra/clang-doc/Mapper.h
index 75c8e947c8f90..62fc5fbbdf3da 100644
--- a/clang-tools-extra/clang-doc/Mapper.h
+++ b/clang-tools-extra/clang-doc/Mapper.h
@@ -36,6 +36,7 @@ class MapASTVisitor : public 
clang::RecursiveASTVisitor,
   void HandleTranslationUnit(ASTContext &Context) override;
   bool VisitNamespaceDecl(const NamespaceDecl *D);
   bool VisitRecordDecl(const RecordDecl *D);
+  bool VisitVarDecl(const VarDecl *D);
   bool VisitEnumDecl(const EnumDecl *D);
   bool VisitCXXMethodDecl(const CXXMethodDecl *D);
   bool VisitFunctionDecl(const FunctionDecl *D);
diff --git a/clang-tools-extra/clang-doc/Serialize.cpp 
b/clang-tools-extra/clang-doc/Serialize.cpp
index f737fc75135a1..d34451cd10484 100644
--- a/clang-tools-extra/clang-doc/Serialize.cpp
+++ b/clang-tools-extra/clang-doc/Serialize.cpp
@@ -729,6 +729,62 @@ emitInfo(const RecordDecl *D, const FullComment *FC, int 
LineNumber,
   return {std::move(I), std::move(Parent)};
 }
 
+std::pair, std::unique_ptr>
+emitInfo(const VarDecl *D, const FullComment *FC, int LineNumber,
+ llvm::StringRef File, bool IsFileInRootDir, bool PublicOnly) {
+  auto I = std::make_unique();
+  bool IsInAnonymousNamespace = false;
+  populateSymbolInfo(*I, D, FC, LineNumber, File, IsFileInRootDir,
+ IsInAnonymousNamespace);
+  if (!shouldSerializeInfo(PublicOnly, IsInAnonymousNamespace, D))
+return {};
+
+  I->Path = getInfoRelativePath(I->Namespace);
+
+  PopulateTemplateParameters(I->Template, D);
+
+  // Full and partial specializations.
+  if (auto *CTSD = dyn_cast(D)) {
+if (!I->Template)
+  I->Template.emplace();
+I->Template->Specialization.emplace();
+auto &Specialization = *I->Template->Specialization;
+
+// What this is a specialization of.
+auto SpecOf = CTSD->getSpecializedTemplateOrPartial();
+if (auto *CTD = dyn_cast(SpecOf))
+  Specialization.SpecializationOf = getUSRForDecl(CTD);
+else if (auto *CTPSD =
+ dyn_cast(SpecOf))
+  Specialization.SpecializationOf = getUSRForDecl(CTPSD);
+
+// Parameters to the specilization. For partial specializations, get the
+// parameters "as written" from the ClassTemplatePartialSpecializationDecl
+// because the non-explicit template parameters will have generated 
internal
+// placeholder names rather than the names the user typed that match the
+// template parameters.
+if (const ClassTemplatePartialSpecializationDecl *CTPSD =
+dyn_cast(D)) {
+  if (const ASTTemplateArgumentListInfo *AsWritten =
+  CTPSD->getTemplateArgsAsWritten()) {
+for (unsigned i = 0; i < AsWritten->getNumTemplateArgs(); i++) {
+  Specialization.Params.emplace_back(
+  getSourceCode(D, (*AsWritten)[i].getSourceRange()));
+}
+  }
+} else {
+  for (const TemplateArgument &Arg : CTSD->getTemplateArgs().asArray()) {
+Specialization.Params.push_back(TemplateArgumentToInfo(D, Arg));
+  }
+}
+  }
+
+  // Records are inserted into the parent by reference, so we need to return
+  // both the parent and the record itself.
+  auto Parent = MakeAndInsertIntoParent(*I);
+  return {std::move(I), std::move(Parent)};
+}
+
 std::pair, std::unique_ptr>
 emitInfo(const FunctionDecl *D, const FullComment *FC, int LineNumber,
  llvm::StringRef File, bool IsFileInRootDir, bool PublicOnly) {
diff --git a/clang-tools-extra/clang-doc/Serialize.h 
b/clang-tools-extra/clang-doc/Serialize.h
index 4e203ca7891ac..41946796f39f6 100644
--- a/clang-tools-extra/clang-doc/Serialize.h
+

[clang] [clang-tools-extra] [clang] implement printing of canonical expressions (PR #135133)

2025-04-12 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

I've added a few test cases showing the effects on diagnostics.
Which is likely to be short lived, as the underlying issue looks easy to solve.

I have updated the patch to cover printing of dependent decltype as well.

I have looked into also covering DependentSizedArrays, but the sugaring there 
is broken at the moment
and would need a separate and more involved fix before we can turn this on 
there.


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


[clang] [clang-tools-extra] [clang] implement printing of canonical expressions (PR #135133)

2025-04-12 Thread Matheus Izvekov via cfe-commits

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


[clang-tools-extra] [clang-tidy] detect arithmetic operations within member list initialization in modernize-use-default-member-init check (PR #129370)

2025-04-12 Thread David Rivera via cfe-commits

https://github.com/RiverDave updated 
https://github.com/llvm/llvm-project/pull/129370

>From cae6e099a40086bba0790783f4088058f5aead20 Mon Sep 17 00:00:00 2001
From: David Rivera 
Date: Sat, 1 Mar 2025 02:09:02 -0500
Subject: [PATCH] [clang-tidy] detect arithmetic operations within member list
 initialization in modernize-use-default-member-init

---
 .../modernize/UseDefaultMemberInitCheck.cpp   | 30 +--
 clang-tools-extra/docs/ReleaseNotes.rst   |  2 +-
 .../modernize/use-default-member-init.cpp | 23 ++
 3 files changed, 45 insertions(+), 10 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
index bf99c738da1a3..9ad6dcefbc1bb 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
@@ -159,6 +159,13 @@ static bool sameValue(const Expr *E1, const Expr *E2) {
   case Stmt::UnaryOperatorClass:
 return sameValue(cast(E1)->getSubExpr(),
  cast(E2)->getSubExpr());
+  case Stmt::BinaryOperatorClass: {
+const auto *BinOp1 = cast(E1);
+const auto *BinOp2 = cast(E2);
+return BinOp1->getOpcode() == BinOp2->getOpcode() &&
+   sameValue(BinOp1->getLHS(), BinOp2->getLHS()) &&
+   sameValue(BinOp1->getRHS(), BinOp2->getRHS());
+  }
   case Stmt::CharacterLiteralClass:
 return cast(E1)->getValue() ==
cast(E2)->getValue();
@@ -199,17 +206,22 @@ void UseDefaultMemberInitCheck::storeOptions(
 }
 
 void UseDefaultMemberInitCheck::registerMatchers(MatchFinder *Finder) {
-  auto ConstExpRef = varDecl(anyOf(isConstexpr(), isStaticStorageClass()));
+  auto NumericLiteral = anyOf(integerLiteral(), floatLiteral());
+  auto UnaryNumericLiteral = unaryOperator(hasAnyOperatorName("+", "-"),
+   hasUnaryOperand(NumericLiteral));
+
+  auto ConstExprRef = varDecl(anyOf(isConstexpr(), isStaticStorageClass()));
+  auto ImmutableRef =
+  declRefExpr(to(decl(anyOf(enumConstantDecl(), ConstExprRef;
+
+  auto BinaryNumericExpr = binaryOperator(
+  hasOperands(anyOf(NumericLiteral, ImmutableRef, binaryOperator()),
+  anyOf(NumericLiteral, ImmutableRef, binaryOperator(;
 
   auto InitBase =
-  anyOf(stringLiteral(), characterLiteral(), integerLiteral(),
-unaryOperator(hasAnyOperatorName("+", "-"),
-  hasUnaryOperand(integerLiteral())),
-floatLiteral(),
-unaryOperator(hasAnyOperatorName("+", "-"),
-  hasUnaryOperand(floatLiteral())),
-cxxBoolLiteral(), cxxNullPtrLiteralExpr(), implicitValueInitExpr(),
-declRefExpr(to(anyOf(enumConstantDecl(), ConstExpRef;
+  anyOf(stringLiteral(), characterLiteral(), NumericLiteral,
+UnaryNumericLiteral, cxxBoolLiteral(), cxxNullPtrLiteralExpr(),
+implicitValueInitExpr(), ImmutableRef, BinaryNumericExpr);
 
   auto ExplicitCastExpr = castExpr(hasSourceExpression(InitBase));
   auto InitMatcher = anyOf(InitBase, ExplicitCastExpr);
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 761c1d3a80359..fc40d525d7bb8 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -179,7 +179,7 @@ Changes in existing checks
 
 - Improved :doc:`modernize-use-default-member-init
   ` check by matching
-  ``constexpr`` and ``static``` values on member initialization and by 
detecting
+  arithmetic operations, ``constexpr`` and ``static`` values, and detecting
   explicit casting of built-in types within member list initialization.
 
 - Improved :doc:`modernize-use-ranges
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp
index cac50be9e4368..bb2a7388e75f1 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp
@@ -572,4 +572,27 @@ class FunctionalCastInit {
   // CHECK-FIXES: double c{double('C')};
 };
 
+#define ARITHMETIC_MACRO (44 - 2)
+
+class DefaultMemberInitWithArithmetic {
+  DefaultMemberInitWithArithmetic() : a{1 + 1},  b{1 + 11 + 123 + 1234},  c{2 
+ (4 / 2) + 3 + (7 / 11)},  d{ARITHMETIC_MACRO * 2}, e{1.2 + 3.4} {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:39: warning: member initializer for 'a' is 
redundant [modernize-use-default-member-init]
+  // CHECK-FIXES: DefaultMemberInitWithArithmetic()  {}
+
+  int a{1 + 1};
+  int b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer 
for 'b' [modernize-use-default-member-init]
+  // CHECK-FIXES:  int b{1 + 11 + 123 + 1234};
+  int c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning:

[clang-tools-extra] [clang-tidy] Avoid diagnosing std::array initializations for modernize-use-designated-initializers (PR #134774)

2025-04-12 Thread David Rivera via cfe-commits

https://github.com/RiverDave updated 
https://github.com/llvm/llvm-project/pull/134774

>From ee7ba0b76586c73aa83f156982953482345f9b92 Mon Sep 17 00:00:00 2001
From: David Rivera 
Date: Mon, 7 Apr 2025 23:21:50 -0400
Subject: [PATCH 1/2] [clang-tidy] Avoid diagnosing std::array initializations
 for modernize-use-designated-initializers

---
 .../modernize/UseDesignatedInitializersCheck.cpp   | 7 ++-
 clang-tools-extra/docs/ReleaseNotes.rst| 4 
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
index 3132067f3d5ec..9e2ac149d0868 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
@@ -119,13 +119,18 @@ 
UseDesignatedInitializersCheck::UseDesignatedInitializersCheck(
 void UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
   const auto HasBaseWithFields =
   hasAnyBase(hasType(cxxRecordDecl(has(fieldDecl();
+
+  // see #133715
+  const auto IsSTLArray =
+  hasType(qualType(hasDeclaration(recordDecl(hasName("::std::array");
+
   Finder->addMatcher(
   initListExpr(
   hasType(cxxRecordDecl(RestrictToPODTypes ? isPOD() : isAggregate(),
 unless(HasBaseWithFields))
   .bind("type")),
   IgnoreSingleElementAggregates ? hasMoreThanOneElement() : anything(),
-  unless(isFullyDesignated()))
+  unless(anyOf(isFullyDesignated(), IsSTLArray)))
   .bind("init"),
   this);
 }
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 761c1d3a80359..ba3774307e392 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -182,6 +182,10 @@ Changes in existing checks
   ``constexpr`` and ``static``` values on member initialization and by 
detecting
   explicit casting of built-in types within member list initialization.
 
+- Improved :doc:`modernize-use-designated-initializers
+  ` check by avoiding
+  diagnosing designated initializers for ``std::array`` initializations.
+
 - Improved :doc:`modernize-use-ranges
   ` check by updating suppress 
   warnings logic for ``nullptr`` in ``std::find``.

>From 05b4a2075f130cb0e82ca64b242da0e97440d823 Mon Sep 17 00:00:00 2001
From: David Rivera 
Date: Sat, 12 Apr 2025 19:55:39 -0400
Subject: [PATCH 2/2] [clang-tidy] avoid diagnosing std::array initializations
 for modernize-use-designated-initializers when IgnoreSingleElementAggregates
 is false

---
 .../modernize/UseDesignatedInitializersCheck.cpp | 12 +---
 clang-tools-extra/docs/ReleaseNotes.rst  |  3 ++-
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
index 9e2ac149d0868..6d71666b53963 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
@@ -119,18 +119,16 @@ 
UseDesignatedInitializersCheck::UseDesignatedInitializersCheck(
 void UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
   const auto HasBaseWithFields =
   hasAnyBase(hasType(cxxRecordDecl(has(fieldDecl();
-
-  // see #133715
-  const auto IsSTLArray =
-  hasType(qualType(hasDeclaration(recordDecl(hasName("::std::array");
-
   Finder->addMatcher(
   initListExpr(
   hasType(cxxRecordDecl(RestrictToPODTypes ? isPOD() : isAggregate(),
-unless(HasBaseWithFields))
+unless(anyOf(HasBaseWithFields,
+ IgnoreSingleElementAggregates
+ ? hasName("::std::array")
+ : unless(anything()
   .bind("type")),
   IgnoreSingleElementAggregates ? hasMoreThanOneElement() : anything(),
-  unless(anyOf(isFullyDesignated(), IsSTLArray)))
+  unless(isFullyDesignated()))
   .bind("init"),
   this);
 }
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index ba3774307e392..1d9177f17a255 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -184,7 +184,8 @@ Changes in existing checks
 
 - Improved :doc:`modernize-use-designated-initializers
   ` check by avoiding
-  diagnosing designated initializers for ``std::array`` initializations.
+  diagnosing designated initializers for ``std::array`` initializations when
+  `IgnoreSingleElementAggregates` is false.
 
 - Improved 

  1   2   >