[clang] [llvm] [AVR] Handle flash RO data mapped to data space for newer devices (PR #146244)

2025-07-14 Thread Tom Vijlbrief via cfe-commits


@@ -651,8 +651,19 @@ void AVR::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   // This is almost always required because otherwise avr-ld
   // will assume 'avr2' and warn about the program being larger
   // than the bare minimum supports.
-  if (Linker.find("avr-ld") != std::string::npos && FamilyName)

tomtor wrote:

I can remove the new linker options. A user could use `-T` and additional 
linker options if needed.

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


[clang-tools-extra] [clang-tidy] Make `bugprone-unhandled-self-assignment` check more general (PR #147066)

2025-07-14 Thread Andrey Karlov via cfe-commits

https://github.com/negativ updated 
https://github.com/llvm/llvm-project/pull/147066

>From 950b6dce92eb2a831e7bd7e7ba44b3e8cc354dd4 Mon Sep 17 00:00:00 2001
From: Andrey Karlov 
Date: Fri, 4 Jul 2025 17:13:20 +0300
Subject: [PATCH 1/6] Checking that some kind of constructor is called and
 followed by a `swap`

---
 .../bugprone/UnhandledSelfAssignmentCheck.cpp | 19 ++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git 
a/clang-tools-extra/clang-tidy/bugprone/UnhandledSelfAssignmentCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/UnhandledSelfAssignmentCheck.cpp
index 1f432c4ccc5f0..8307e744a434c 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UnhandledSelfAssignmentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UnhandledSelfAssignmentCheck.cpp
@@ -68,7 +68,23 @@ void 
UnhandledSelfAssignmentCheck::registerMatchers(MatchFinder *Finder) {
   const auto HasNoNestedSelfAssign =
   
cxxMethodDecl(unless(hasDescendant(cxxMemberCallExpr(callee(cxxMethodDecl(
   hasName("operator="), ofClass(equalsBoundNode("class";
-
+  
+  // Checking that some kind of constructor is called and followed by a `swap`:
+  // T& operator=(const T& other) {
+  //T tmp{this->internal_data(), some, other, args};
+  //swap(tmp);
+  //return *this;
+  // }
+  const auto HasCopyAndSwap = cxxMethodDecl(
+  ofClass(cxxRecordDecl(unless(hasAncestor(classTemplateDecl(),
+  hasDescendant(
+  stmt(hasDescendant(
+   varDecl(hasType(cxxRecordDecl(equalsBoundNode("class"
+   .bind("tmp_var")),
+   hasDescendant(callExpr(callee(functionDecl(hasName("swap"))),
+  hasAnyArgument(declRefExpr(to(varDecl(
+  equalsBoundNode("tmp_var"));
+
   DeclarationMatcher AdditionalMatcher = cxxMethodDecl();
   if (WarnOnlyIfThisHasSuspiciousField) {
 // Matcher for standard smart pointers.
@@ -94,6 +110,7 @@ void 
UnhandledSelfAssignmentCheck::registerMatchers(MatchFinder *Finder) {
HasReferenceParam, HasNoSelfCheck,
unless(HasNonTemplateSelfCopy),
unless(HasTemplateSelfCopy),
+   unless(HasCopyAndSwap),
HasNoNestedSelfAssign, AdditionalMatcher)
  .bind("copyAssignmentOperator"),
  this);

>From 0cd33ec49693cfc6f5a72b72a9c50ba868634221 Mon Sep 17 00:00:00 2001
From: Andrey Karlov 
Date: Fri, 4 Jul 2025 17:19:02 +0300
Subject: [PATCH 2/6] Tests

---
 .../bugprone/unhandled-self-assignment.cpp| 90 +++
 1 file changed, 90 insertions(+)

diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unhandled-self-assignment.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unhandled-self-assignment.cpp
index 8610393449f97..f2f61062f883f 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unhandled-self-assignment.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unhandled-self-assignment.cpp
@@ -28,6 +28,13 @@ template 
 class auto_ptr {
 };
 
+namespace pmr {
+template 
+class allocator {};
+}
+
+struct allocator_arg_t {} allocator_arg;
+
 } // namespace std
 
 void assert(int expression){};
@@ -540,6 +547,89 @@ class NotACopyAssignmentOperator {
   Uy *getUy() const { return Ptr2; }
 };
 
+// Support "extended" copy/move constructors
+class AllocatorAwareClass {
+  // pointer member to trigger bugprone-unhandled-self-assignment
+  void *foo = nullptr;
+
+  public:
+using allocator_type = std::pmr::allocator<>;
+
+AllocatorAwareClass(const AllocatorAwareClass& other) {
+}
+
+AllocatorAwareClass(const AllocatorAwareClass& other, const 
allocator_type& alloc) {
+}
+
+AllocatorAwareClass& operator=(const AllocatorAwareClass& other) {
+AllocatorAwareClass tmp(other, get_allocator());
+swap(tmp);
+return *this;
+}
+
+void swap(AllocatorAwareClass& other) noexcept {
+}
+
+allocator_type get_allocator() const {
+return allocator_type();
+}
+};
+
+// Support "extended" copy/move constructors + std::swap
+class AllocatorAwareClassStdSwap {
+  // pointer member to trigger bugprone-unhandled-self-assignment
+  void *foo = nullptr;
+
+  public:
+using allocator_type = std::pmr::allocator<>;
+
+AllocatorAwareClassStdSwap(const AllocatorAwareClassStdSwap& other) {
+}
+
+AllocatorAwareClassStdSwap(const AllocatorAwareClassStdSwap& other, const 
allocator_type& alloc) {
+}
+
+AllocatorAwareClassStdSwap& operator=(const AllocatorAwareClassStdSwap& 
other) {
+using std::swap;
+
+AllocatorAwareClassStdSwap tmp(other, get_allocator());
+swap(*this, tmp);
+return *this;
+}
+
+allocator_type get_allocator() const {
+re

[clang] [KeyInstr] Add release note & update option (PR #148244)

2025-07-14 Thread Nikita Popov via cfe-commits

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

LGTM

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


[clang] [llvm] [clang] [OpenMP] New OpenMP 6.0 self_maps clause - CodeGen (PR #134131)

2025-07-14 Thread via cfe-commits

Ritanya-B-Bharadwaj wrote:

ping

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


[clang] [llvm] [openmp] [clang][OpenMP] New OpenMP 6.0 threadset clause (PR #135807)

2025-07-14 Thread via cfe-commits

https://github.com/Ritanya-B-Bharadwaj updated 
https://github.com/llvm/llvm-project/pull/135807

>From 9c56e59ba9984c14c15a8d5a95a02e7192a64e8f Mon Sep 17 00:00:00 2001
From: Ritanya B Bharadwaj 
Date: Sun, 6 Apr 2025 09:33:06 -0500
Subject: [PATCH 1/9] [OpenMP] Parsing Support of ThreadSets in Task

---
 clang/include/clang/AST/OpenMPClause.h| 80 +++
 clang/include/clang/AST/RecursiveASTVisitor.h |  6 ++
 clang/include/clang/Basic/OpenMPKinds.def |  8 +-
 clang/include/clang/Basic/OpenMPKinds.h   |  7 ++
 clang/include/clang/Sema/SemaOpenMP.h |  6 ++
 clang/lib/AST/OpenMPClause.cpp|  7 ++
 clang/lib/AST/StmtProfile.cpp |  2 +
 clang/lib/Basic/OpenMPKinds.cpp   |  9 +++
 clang/lib/Parse/ParseOpenMP.cpp   |  1 +
 clang/lib/Sema/SemaOpenMP.cpp | 21 +
 clang/lib/Sema/TreeTransform.h|  7 ++
 clang/lib/Serialization/ASTReader.cpp | 11 +++
 clang/lib/Serialization/ASTWriter.cpp |  6 ++
 clang/tools/libclang/CIndex.cpp   |  2 +
 llvm/include/llvm/Frontend/OpenMP/OMP.td  |  4 +
 15 files changed, 176 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/AST/OpenMPClause.h 
b/clang/include/clang/AST/OpenMPClause.h
index 572e62249b46f..81420384f885c 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -1332,6 +1332,86 @@ class OMPDefaultClause : public OMPClause {
   }
 };
 
+/// This represents 'threadset' clause in the '#pragma omp ...' directive.
+///
+/// \code
+/// #pragma omp parallel threadset(shared)
+/// \endcode
+/// In this example directive '#pragma omp parallel' has simple 'threadset'
+/// clause with kind 'shared'.
+class OMPThreadsetClause : public OMPClause {
+  friend class OMPClauseReader;
+
+  /// Location of '('.
+  SourceLocation LParenLoc;
+
+  /// A kind of the 'threadset' clause.
+  OpenMPThreadsetKind Kind = OMPC_THREADSET_unknown;
+
+  /// Start location of the kind in source code.
+  SourceLocation KindLoc;
+
+  /// Set kind of the clauses.
+  ///
+  /// \param K Argument of clause.
+  void setThreadsetKind(OpenMPThreadsetKind K) { Kind = K; }
+
+  /// Set argument location.
+  ///
+  /// \param KLoc Argument location.
+  void setThreadsetKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
+
+public:
+  /// Build 'threadset' clause with argument \a A ('none' or 'shared').
+  ///
+  /// \param A Argument of the clause ('none' or 'shared').
+  /// \param ALoc Starting location of the argument.
+  /// \param StartLoc Starting location of the clause.
+  /// \param LParenLoc Location of '('.
+  /// \param EndLoc Ending location of the clause.
+  OMPThreadsetClause(OpenMPThreadsetKind A, SourceLocation ALoc,
+ SourceLocation StartLoc, SourceLocation LParenLoc,
+ SourceLocation EndLoc)
+  : OMPClause(llvm::omp::OMPC_threadset, StartLoc, EndLoc),
+LParenLoc(LParenLoc), Kind(A), KindLoc(ALoc) {}
+
+  /// Build an empty clause.
+  OMPThreadsetClause()
+  : OMPClause(llvm::omp::OMPC_threadset, SourceLocation(),
+  SourceLocation()) {}
+
+  /// Sets the location of '('.
+  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
+
+  /// Returns the location of '('.
+  SourceLocation getLParenLoc() const { return LParenLoc; }
+
+  /// Returns kind of the clause.
+  OpenMPThreadsetKind getThreadsetKind() const { return Kind; }
+
+  /// Returns location of clause kind.
+  SourceLocation getThreadsetKindLoc() const { return KindLoc; }
+
+  child_range children() {
+return child_range(child_iterator(), child_iterator());
+  }
+
+  const_child_range children() const {
+return const_child_range(const_child_iterator(), const_child_iterator());
+  }
+
+  child_range used_children() {
+return child_range(child_iterator(), child_iterator());
+  }
+  const_child_range used_children() const {
+return const_child_range(const_child_iterator(), const_child_iterator());
+  }
+
+  static bool classof(const OMPClause *T) {
+return T->getClauseKind() == llvm::omp::OMPC_threadset;
+  }
+};
+
 /// This represents 'proc_bind' clause in the '#pragma omp ...'
 /// directive.
 ///
diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index 0530996ed20d3..d86c7d4577ac6 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -3410,6 +3410,12 @@ bool 
RecursiveASTVisitor::VisitOMPDefaultClause(OMPDefaultClause *) {
   return true;
 }
 
+template 
+bool RecursiveASTVisitor::VisitOMPThreadsetClause(
+OMPThreadsetClause *) {
+  return true;
+}
+
 template 
 bool RecursiveASTVisitor::VisitOMPProcBindClause(OMPProcBindClause *) 
{
   return true;
diff --git a/clang/include/clang/Basic/OpenMPKinds.def 
b/clang/include/clang/Basic/OpenMPKinds.def
index b0de65df7e397..5b8889b8f7a34 100644
--- a/clang/include/clang/B

[clang] [KeyInstr] Add release note & update option (PR #148244)

2025-07-14 Thread Nikita Popov via cfe-commits

nikic wrote:

Needs a rebase though, otherwise CI won't run :)

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


[clang] [llvm] [DTLTO][Clang] Add support for Integrated Distributed ThinLTO (PR #147265)

2025-07-14 Thread via cfe-commits

https://github.com/bd1976bris updated 
https://github.com/llvm/llvm-project/pull/147265

>From 737bb8c03620d668299a9b85d34eb659a30eebfb Mon Sep 17 00:00:00 2001
From: Dunbobbin 
Date: Thu, 5 Jun 2025 17:10:31 +0100
Subject: [PATCH 01/15] [DTLTO][Clang] Add support for Integrated Distributed
 ThinLTO

This patch introduces support for Integrated Distributed ThinLTO
(DTLTO) in Clang.

DTLTO enables the distribution of ThinLTO backend compilations via
external distribution systems, such as Incredibuild, during the
traditional link step: https://llvm.org/docs/DTLTO.html.

Testing:
- `lit` test coverage has been added to Clang's Driver tests.
- The DTLTO cross-project tests will use this Clang support.

For the design discussion of the DTLTO feature, see:
https://github.com/llvm/llvm-project/pull/126654

Note that I have removed the forwarding of -mllvm options to the
backend compilations which was discussed in the design review from
this patch. LTO configuration for DTLTO will be addressed in a
follow-up patch. In the meantime -mllvm options can be forwarded
manually if required.
---
 clang/docs/ThinLTO.rst| 32 
 clang/include/clang/Driver/Options.td | 14 -
 clang/lib/Driver/ToolChains/Gnu.cpp   | 15 ++
 clang/test/Driver/DTLTO/dtlto.c   | 43 +++
 cross-project-tests/dtlto/ld-dtlto.c  | 31 ---
 5 files changed, 116 insertions(+), 19 deletions(-)
 create mode 100644 clang/test/Driver/DTLTO/dtlto.c

diff --git a/clang/docs/ThinLTO.rst b/clang/docs/ThinLTO.rst
index c042547678919..687795ac655a7 100644
--- a/clang/docs/ThinLTO.rst
+++ b/clang/docs/ThinLTO.rst
@@ -240,6 +240,38 @@ The ``BOOTSTRAP_LLVM_ENABLE_LTO=Thin`` will enable ThinLTO 
for stage 2 and
 stage 3 in case the compiler used for stage 1 does not support the ThinLTO
 option.
 
+Integrated Distributed ThinLTO (DTLTO)
+--
+
+Integrated Distributed ThinLTO (DTLTO) enables the distribution of backend
+ThinLTO compilations via external distribution systems, such as Incredibuild,
+during the traditional link step.
+
+The implementation is documented here: https://llvm.org/docs/DTLTO.html.
+
+DTLTO requires the LLD linker (``-fuse-ld=lld``).
+
+``-fthinlto-distributor=``
+   - Specifies the  to the distributor process executable for DTLTO.
+   - If specified, ThinLTO backend compilations will be distributed by LLD.
+
+``-Xthinlto-distributor=``
+   - Passes  to the distributor process (see 
``-fthinlto-distributor=``).
+   - Can be specified multiple times to pass multiple options.
+   - Multiple options can also be specified by separating them with commas.
+
+Examples:
+   - ``clang -flto=thin -fthinlto-distributor=incredibuild.exe 
-Xthinlto-distributor=--verbose,--j10 -fuse-ld=lld``
+   - ``clang -flto=thin -fthinlto-distributor=$(which python) 
-Xthinlto-distributor=incredibuild.py -fuse-ld=lld``
+
+If ``-fthinlto-distributor=`` is specified, Clang supplies the path to a
+compiler to be executed remotely to perform the ThinLTO backend
+compilations. Currently, this is Clang itself.
+
+Note that currently, DTLTO is only supported in some LLD flavors. Support will
+be added to other LLD flavours in the future.
+See `DTLTO `_ for more information.
+
 More Information
 
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 0c8a219b19bf4..9c6f77af97be0 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -990,6 +990,13 @@ def Xlinker : Separate<["-"], "Xlinker">, 
Flags<[LinkerInput, RenderAsInput]>,
   Visibility<[ClangOption, CLOption, FlangOption]>,
   HelpText<"Pass  to the linker">, MetaVarName<"">,
   Group;
+def Xthinlto_distributor_EQ : CommaJoined<["-"], "Xthinlto-distributor=">,
+  Flags<[LinkOption]>,
+  Visibility<[ClangOption, CLOption]>,
+  HelpText<"Pass  to the ThinLTO distributor process. Can be specified "
+   "multiple times or with comma-separated values.">,
+  MetaVarName<"">,
+  Group;
 def Xoffload_linker : JoinedAndSeparate<["-"], "Xoffload-linker">,
   Visibility<[ClangOption, FlangOption]>,
   HelpText<"Pass  to the offload linkers or the ones identified by 
-">,
@@ -4233,7 +4240,12 @@ def ffinite_loops: Flag<["-"],  "ffinite-loops">, 
Group,
 def fno_finite_loops: Flag<["-"], "fno-finite-loops">, Group,
   HelpText<"Do not assume that any loop is finite.">,
   Visibility<[ClangOption, CC1Option]>;
-
+def fthinlto_distributor_EQ : Joined<["-"], "fthinlto-distributor=">,
+  Group,
+  HelpText<"Path to the ThinLTO distributor process. If specified, "
+   "ThinLTO backend compilations will be distributed by LLD">,
+  MetaVarName<"">,
+  Visibility<[ClangOption, CLOption]>;
 def ftrigraphs : Flag<["-"], "ftrigraphs">, Group,
   HelpText<"Process trigraph sequences">, Visibility<[ClangOption, CC1Option]>;
 def fno_trigraphs : Flag<["-"], "fno-trig

[clang] [clang][CodeGen] Set `dead_on_return` on indirect pointer arguments (PR #148159)

2025-07-14 Thread Antonio Frighetto via cfe-commits

antoniofrighetto wrote:

Updated, thanks, not sure how I overlooked that; hopefully should be on track.

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


[clang] [clang] Update diagnostics for type aware allocators (PR #148576)

2025-07-14 Thread Oliver Hunt via cfe-commits

https://github.com/ojhunt updated 
https://github.com/llvm/llvm-project/pull/148576

>From d86fea4e16dc9962f87a8969e74b62767476ec30 Mon Sep 17 00:00:00 2001
From: Oliver Hunt 
Date: Mon, 14 Jul 2025 00:26:08 -0700
Subject: [PATCH 1/2] [clang] Update diagnostics for type aware allocators

Alas reflection pushed p2719 out of C++26, so this PR changes
the diagnostics to reflect that for now type aware allocation
is functionally a clang extension.
---
 .../clang/Basic/DiagnosticSemaKinds.td|  7 +-
 clang/lib/Sema/SemaDeclCXX.cpp|  8 +--
 ...re-class-scoped-mismatched-constraints.cpp |  8 +--
 clang/test/SemaCXX/type-aware-coroutines.cpp  |  2 +-
 .../test/SemaCXX/type-aware-new-constexpr.cpp | 16 ++---
 .../SemaCXX/type-aware-new-delete-arrays.cpp  |  8 +--
 ...are-new-delete-basic-free-declarations.cpp |  8 +--
 ...new-delete-basic-in-class-declarations.cpp | 70 +--
 ...type-aware-new-delete-basic-resolution.cpp |  8 +--
 .../type-aware-new-delete-qualifiers.cpp  |  8 +--
 ...-aware-new-delete-transparent-contexts.cpp |  6 +-
 .../type-aware-new-invalid-type-identity.cpp  | 12 ++--
 .../type-aware-placement-operators.cpp|  8 +--
 13 files changed, 81 insertions(+), 88 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 577adc30ba2fa..2ea9e46dadcdf 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10081,11 +10081,8 @@ def err_destroying_operator_delete_not_usual : Error<
 def err_type_aware_destroying_operator_delete : Error<
   "destroying delete is not permitted to be type aware">;
 
-def ext_cxx26_type_aware_allocators : ExtWarn<
-  "type aware allocators are a C++2c extension">, InGroup;
-def warn_cxx26_type_aware_allocators : Warning<
-  "type aware allocators are incompatible with C++ standards before C++2c">,
-  DefaultIgnore, InGroup;
+def warn_ext_type_aware_allocators : ExtWarn<
+  "type aware allocators are a clang extension">, 
InGroup>;
 def err_type_aware_allocator_missing_matching_operator : Error<
   "declaration of type aware %0 in %1 must have matching type aware %2"
 >;
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 5cc92ebb0171f..f60ab4f0da7a0 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -16541,12 +16541,8 @@ static inline bool CheckOperatorNewDeleteTypes(
   if (IsPotentiallyTypeAware) {
 // We don't emit this diagnosis for template instantiations as we will
 // have already emitted it for the original template declaration.
-if (!FnDecl->isTemplateInstantiation()) {
-  unsigned DiagID = SemaRef.getLangOpts().CPlusPlus26
-? diag::warn_cxx26_type_aware_allocators
-: diag::ext_cxx26_type_aware_allocators;
-  SemaRef.Diag(FnDecl->getLocation(), DiagID);
-}
+if (!FnDecl->isTemplateInstantiation())
+  SemaRef.Diag(FnDecl->getLocation(), 
diag::warn_ext_type_aware_allocators);
 
 if (OperatorKind == AllocationOperatorKind::New) {
   SizeParameterIndex = 1;
diff --git 
a/clang/test/SemaCXX/type-aware-class-scoped-mismatched-constraints.cpp 
b/clang/test/SemaCXX/type-aware-class-scoped-mismatched-constraints.cpp
index 57e6d953c2ad6..709635a1948ff 100644
--- a/clang/test/SemaCXX/type-aware-class-scoped-mismatched-constraints.cpp
+++ b/clang/test/SemaCXX/type-aware-class-scoped-mismatched-constraints.cpp
@@ -1,7 +1,7 @@
-// RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s 
-std=c++26 -fexceptions -fcxx-exceptions-fsized-deallocation
-faligned-allocation -Wno-non-c-typedef-for-linkage -DDEFAULT_DELETE=1
-// RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s 
-std=c++26 -fexceptions -fcxx-exceptions -fno-sized-deallocation
-faligned-allocation -Wno-non-c-typedef-for-linkage -DDEFAULT_DELETE=0
-// RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s 
-std=c++26 -fexceptions -fcxx-exceptions-fsized-deallocation 
-fno-aligned-allocation -Wno-non-c-typedef-for-linkage -DDEFAULT_DELETE=1
-// RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s 
-std=c++26 -fexceptions -fcxx-exceptions -fno-sized-deallocation 
-fno-aligned-allocation -Wno-non-c-typedef-for-linkage -DDEFAULT_DELETE=0
+// RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s 
-std=c++26 -Wno-cxx-type-aware-allocators -fexceptions -fcxx-exceptions
-fsized-deallocation-faligned-allocation -Wno-non-c-typedef-for-linkage 
-DDEFAULT_DELETE=1
+// RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s 
-std=c++26 -Wno-cxx-type-aware-allocators -fexceptions -fcxx-exceptions 
-fno-sized-deallocation-faligned-allocation -Wno-non-c-typedef-for-linkage 
-DDEFAULT_DELETE=0
+// RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s 
-std=c++26 -Wno-cxx-typ

[clang-tools-extra] [clang-tidy] fix `bugprone-narrowing-conversions` false positive for conditional expression (PR #139474)

2025-07-14 Thread via cfe-commits

https://github.com/AndreyG updated 
https://github.com/llvm/llvm-project/pull/139474

>From b4814ba942266c5d4f4f070cbdef7b721738f33e Mon Sep 17 00:00:00 2001
From: Andrey Davydov 
Date: Sun, 11 May 2025 22:23:38 +0200
Subject: [PATCH 1/2] [clang-tidy] false positive narrowing conversion

Let's consider the following code from the issue #139467:

void test(int cond, char c) {
char ret = cond > 0 ? ':' : c;
}

Initializer of 'ret' looks the following:

-ImplicitCastExpr 'char' 
 `-ConditionalOperator 'int'
   |-BinaryOperator 'int' '>'
   | |-ImplicitCastExpr 'int' 
   | | `-DeclRefExpr 'int' lvalue ParmVar 'cond' 'int'
   | `-IntegerLiteral 'int' 0
   |-CharacterLiteral 'int' 58
   `-ImplicitCastExpr 'int' 
 `-ImplicitCastExpr 'char' 
   `-DeclRefExpr 'char' lvalue ParmVar 'c' 'char'

So it could be seen that 'RHS' of the conditional operator is
DeclRefExpr 'c' which is casted to 'int' and then the whole conditional 
expression is casted to 'char'.
But this last conversion is not narrowing, because 'RHS' was 'char' _initially_.
We should just remove the cast from 'char' to 'int' before the narrowing 
conversion check.
---
 .../bugprone/NarrowingConversionsCheck.cpp| 16 ++
 .../bugprone/NarrowingConversionsCheck.h  |  2 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 
 ...wing-conversions-conditional-expressions.c | 22 +++
 ...ng-conversions-conditional-expressions.cpp | 22 +++
 5 files changed, 62 insertions(+), 4 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/narrowing-conversions-conditional-expressions.c
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/narrowing-conversions-conditional-expressions.cpp

diff --git 
a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
index 8b2ca6968ea75..6b9e24b3e2d26 100644
--- a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
@@ -553,15 +553,23 @@ bool NarrowingConversionsCheck::handleConditionalOperator(
 // We have an expression like so: `output = cond ? lhs : rhs`
 // From the point of view of narrowing conversion we treat it as two
 // expressions `output = lhs` and `output = rhs`.
-handleBinaryOperator(Context, CO->getLHS()->getExprLoc(), Lhs,
- *CO->getLHS());
-handleBinaryOperator(Context, CO->getRHS()->getExprLoc(), Lhs,
- *CO->getRHS());
+handleConditionalOperatorArgument(Context, Lhs, CO->getLHS());
+handleConditionalOperatorArgument(Context, Lhs, CO->getRHS());
 return true;
   }
   return false;
 }
 
+void NarrowingConversionsCheck::handleConditionalOperatorArgument(
+const ASTContext &Context, const Expr &Lhs, const Expr *Arg) {
+  if (const auto *ICE = llvm::dyn_cast(Arg)) {
+if (!Arg->getIntegerConstantExpr(Context)) {
+  Arg = ICE->getSubExpr();
+}
+  }
+  handleBinaryOperator(Context, Arg->getExprLoc(), Lhs, *Arg);
+}
+
 void NarrowingConversionsCheck::handleImplicitCast(
 const ASTContext &Context, const ImplicitCastExpr &Cast) {
   if (Cast.getExprLoc().isMacroID())
diff --git a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.h 
b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.h
index 20403f920b925..ebddbc2869675 100644
--- a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.h
@@ -85,6 +85,8 @@ class NarrowingConversionsCheck : public ClangTidyCheck {
   bool handleConditionalOperator(const ASTContext &Context, const Expr &Lhs,
  const Expr &Rhs);
 
+  void handleConditionalOperatorArgument(const ASTContext &Context, const Expr 
&Lhs,
+ const Expr *Arg);
   void handleImplicitCast(const ASTContext &Context,
   const ImplicitCastExpr &Cast);
 
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 36a41b4bdf42d..43282bb52d9c1 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -182,6 +182,10 @@ New check aliases
 Changes in existing checks
 ^^
 
+- Improved :doc:`bugprone-narrowing-conversions
+  ` check by fixing
+  false positive from analysis of a conditional expression in C.
+
 - Improved :doc:`bugprone-crtp-constructor-accessibility
   ` check by fixing
   false positives on deleted constructors that cannot be used to construct
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/narrowing-conversions-conditional-expressions.c
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/narrowing-conversions-conditional-expressions.c
new file mode 100644
index 0..474842b7b905e
--- /dev

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

2025-07-14 Thread Owen Pan via cfe-commits


@@ -1180,16 +1183,47 @@ TEST_F(FormatTestJS, InliningFunctionLiterals) {
"}",
Style);
 
-  Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Empty;
+  Style.AllowShortFunctionsOnASingleLine =
+  FormatStyle::ShortFunctionStyle::setEmptyOnly();
   verifyFormat("var func = function() {\n"
"  return 1;\n"
"};",
Style);
 }
 
+TEST_F(FormatTestJS, InliningFunctionLiteralsNew) {

owenca wrote:

Can you also move this test for `Other` to a future patch?

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


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

2025-07-14 Thread Owen Pan via cfe-commits


@@ -622,15 +622,26 @@ template <> struct 
ScalarEnumerationTraits {
   }
 };
 
-template <> struct ScalarEnumerationTraits {
-  static void enumeration(IO &IO, FormatStyle::ShortFunctionStyle &Value) {
-IO.enumCase(Value, "None", FormatStyle::SFS_None);
-IO.enumCase(Value, "false", FormatStyle::SFS_None);
-IO.enumCase(Value, "All", FormatStyle::SFS_All);
-IO.enumCase(Value, "true", FormatStyle::SFS_All);
-IO.enumCase(Value, "Inline", FormatStyle::SFS_Inline);
-IO.enumCase(Value, "InlineOnly", FormatStyle::SFS_InlineOnly);
-IO.enumCase(Value, "Empty", FormatStyle::SFS_Empty);
+template <> struct MappingTraits {
+  static void enumInput(IO &IO, FormatStyle::ShortFunctionStyle &Value) {
+IO.enumCase(Value, "None", FormatStyle::ShortFunctionStyle({}));

owenca wrote:

```suggestion
IO.enumCase(Value, "None", FormatStyle::ShortFunctionStyle());
```
Ditto below and in other files as well.

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


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

2025-07-14 Thread Owen Pan via cfe-commits


@@ -623,20 +623,29 @@ TEST(ConfigParseTest, ParsesConfiguration) {
   CHECK_PARSE("AllowShortBlocksOnASingleLine: true",
   AllowShortBlocksOnASingleLine, FormatStyle::SBS_Always);
 
-  Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline;
   CHECK_PARSE("AllowShortFunctionsOnASingleLine: None",
-  AllowShortFunctionsOnASingleLine, FormatStyle::SFS_None);
+  AllowShortFunctionsOnASingleLine,
+  FormatStyle::ShortFunctionStyle({}));
   CHECK_PARSE("AllowShortFunctionsOnASingleLine: Inline",

owenca wrote:

Please add `CHECK_PARSE_NESTED_BOOL` tests for `Empty`, `Inline`, and `Other` 
before `BraceWrapping` in `TEST(ConfigParseTest, ParsesConfigurationBools)`.

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


[clang] d64938b - [RISCV] Split the intrinsic test for vector crypto to seperate directory. NFC.

2025-07-14 Thread Jim Lin via cfe-commits

Author: Jim Lin
Date: 2025-07-14T16:03:09+08:00
New Revision: d64938b2baa826e749220c8a9cd1c5d03f28a2a5

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

LOG: [RISCV] Split the intrinsic test for vector crypto to seperate directory. 
NFC.

Added: 

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/non-overloaded/vaesdf.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/non-overloaded/vaesdm.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/non-overloaded/vaesef.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/non-overloaded/vaesem.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/non-overloaded/vaeskf1.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/non-overloaded/vaeskf2.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/non-overloaded/vaesz.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/non-overloaded/vandn.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/non-overloaded/vbrev.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/non-overloaded/vbrev8.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/non-overloaded/vclmul.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/non-overloaded/vclmulh.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/non-overloaded/vclz.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/non-overloaded/vcpopv.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/non-overloaded/vctz.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/non-overloaded/vghsh.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/non-overloaded/vgmul.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/non-overloaded/vrev8.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/non-overloaded/vrol.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/non-overloaded/vror.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/non-overloaded/vsha2ch.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/non-overloaded/vsha2cl.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/non-overloaded/vsha2ms.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/non-overloaded/vsm3c.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/non-overloaded/vsm3me.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/non-overloaded/vsm4k.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/non-overloaded/vsm4r.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/non-overloaded/vwsll.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/overloaded/vaesdf.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/overloaded/vaesdm.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/overloaded/vaesef.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/overloaded/vaesem.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/overloaded/vaeskf1.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/overloaded/vaeskf2.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/overloaded/vaesz.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/overloaded/vandn.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/overloaded/vbrev.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/overloaded/vbrev8.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/overloaded/vclmul.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/overloaded/vclmulh.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/overloaded/vclz.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/overloaded/vcpopv.c

clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/vector-crypto/non-policy/overloaded/vctz.c

clang/test/CodeGen/RISCV/rvv-intrinsic

[clang] [Clang][OpenMP] Fixing Clang error for metadirective with multiple when clauses and no otherwise (PR #148583)

2025-07-14 Thread via cfe-commits

https://github.com/Ritanya-B-Bharadwaj created 
https://github.com/llvm/llvm-project/pull/148583

Fixing - https://github.com/llvm/llvm-project/issues/147336

>From cc247bc1eb330dd2d3ccebabc7c1d3b524073627 Mon Sep 17 00:00:00 2001
From: Ritanya B Bharadwaj 
Date: Mon, 14 Jul 2025 03:18:25 -0500
Subject: [PATCH] [Clang][OpenMP] Fixing error - 147336

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

diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index aa6a0c61a2c17..5db2f2e2ccf86 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2704,7 +2704,7 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
 // If no match is found and no otherwise clause is present, skip
 // OMP5.2 Chapter 7.4: If no otherwise clause is specified the effect is as
 // if one was specified without an associated directive variant.
-if (BestIdx == -1 && Idx == 1) {
+if (BestIdx == -1 && Idx > 0) {
   assert(Tok.is(tok::annot_pragma_openmp_end) &&
  "Expecting the end of the pragma here");
   ConsumeAnnotationToken();

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


[clang] [Clang][OpenMP] Fixing Clang error for metadirective with multiple when clauses and no otherwise (PR #148583)

2025-07-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (Ritanya-B-Bharadwaj)


Changes

Fixing - https://github.com/llvm/llvm-project/issues/147336

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


1 Files Affected:

- (modified) clang/lib/Parse/ParseOpenMP.cpp (+1-1) 


``diff
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index aa6a0c61a2c17..5db2f2e2ccf86 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -2704,7 +2704,7 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
 // If no match is found and no otherwise clause is present, skip
 // OMP5.2 Chapter 7.4: If no otherwise clause is specified the effect is as
 // if one was specified without an associated directive variant.
-if (BestIdx == -1 && Idx == 1) {
+if (BestIdx == -1 && Idx > 0) {
   assert(Tok.is(tok::annot_pragma_openmp_end) &&
  "Expecting the end of the pragma here");
   ConsumeAnnotationToken();

``




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


[clang] [clang] Update diagnostics for type aware allocators (PR #148576)

2025-07-14 Thread Corentin Jabot via cfe-commits


@@ -133,7 +133,8 @@ C++2c Feature Support
 
 - Implemented `P0963R3 Structured binding declaration as a condition 
`_.
 
-- Implemented `P2719R4 Type-aware allocation and deallocation functions 
`_.
+- Implemented `P2719R5 Type-aware allocation and deallocation functions 
`_
+  as an extension in all C++ language modes.

cor3ntin wrote:

Still in the wrong section :)

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


[clang] [clang] Update diagnostics for type aware allocators (PR #148576)

2025-07-14 Thread Oliver Hunt via cfe-commits

https://github.com/ojhunt updated 
https://github.com/llvm/llvm-project/pull/148576

>From d86fea4e16dc9962f87a8969e74b62767476ec30 Mon Sep 17 00:00:00 2001
From: Oliver Hunt 
Date: Mon, 14 Jul 2025 00:26:08 -0700
Subject: [PATCH 1/3] [clang] Update diagnostics for type aware allocators

Alas reflection pushed p2719 out of C++26, so this PR changes
the diagnostics to reflect that for now type aware allocation
is functionally a clang extension.
---
 .../clang/Basic/DiagnosticSemaKinds.td|  7 +-
 clang/lib/Sema/SemaDeclCXX.cpp|  8 +--
 ...re-class-scoped-mismatched-constraints.cpp |  8 +--
 clang/test/SemaCXX/type-aware-coroutines.cpp  |  2 +-
 .../test/SemaCXX/type-aware-new-constexpr.cpp | 16 ++---
 .../SemaCXX/type-aware-new-delete-arrays.cpp  |  8 +--
 ...are-new-delete-basic-free-declarations.cpp |  8 +--
 ...new-delete-basic-in-class-declarations.cpp | 70 +--
 ...type-aware-new-delete-basic-resolution.cpp |  8 +--
 .../type-aware-new-delete-qualifiers.cpp  |  8 +--
 ...-aware-new-delete-transparent-contexts.cpp |  6 +-
 .../type-aware-new-invalid-type-identity.cpp  | 12 ++--
 .../type-aware-placement-operators.cpp|  8 +--
 13 files changed, 81 insertions(+), 88 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 577adc30ba2fa..2ea9e46dadcdf 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10081,11 +10081,8 @@ def err_destroying_operator_delete_not_usual : Error<
 def err_type_aware_destroying_operator_delete : Error<
   "destroying delete is not permitted to be type aware">;
 
-def ext_cxx26_type_aware_allocators : ExtWarn<
-  "type aware allocators are a C++2c extension">, InGroup;
-def warn_cxx26_type_aware_allocators : Warning<
-  "type aware allocators are incompatible with C++ standards before C++2c">,
-  DefaultIgnore, InGroup;
+def warn_ext_type_aware_allocators : ExtWarn<
+  "type aware allocators are a clang extension">, 
InGroup>;
 def err_type_aware_allocator_missing_matching_operator : Error<
   "declaration of type aware %0 in %1 must have matching type aware %2"
 >;
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 5cc92ebb0171f..f60ab4f0da7a0 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -16541,12 +16541,8 @@ static inline bool CheckOperatorNewDeleteTypes(
   if (IsPotentiallyTypeAware) {
 // We don't emit this diagnosis for template instantiations as we will
 // have already emitted it for the original template declaration.
-if (!FnDecl->isTemplateInstantiation()) {
-  unsigned DiagID = SemaRef.getLangOpts().CPlusPlus26
-? diag::warn_cxx26_type_aware_allocators
-: diag::ext_cxx26_type_aware_allocators;
-  SemaRef.Diag(FnDecl->getLocation(), DiagID);
-}
+if (!FnDecl->isTemplateInstantiation())
+  SemaRef.Diag(FnDecl->getLocation(), 
diag::warn_ext_type_aware_allocators);
 
 if (OperatorKind == AllocationOperatorKind::New) {
   SizeParameterIndex = 1;
diff --git 
a/clang/test/SemaCXX/type-aware-class-scoped-mismatched-constraints.cpp 
b/clang/test/SemaCXX/type-aware-class-scoped-mismatched-constraints.cpp
index 57e6d953c2ad6..709635a1948ff 100644
--- a/clang/test/SemaCXX/type-aware-class-scoped-mismatched-constraints.cpp
+++ b/clang/test/SemaCXX/type-aware-class-scoped-mismatched-constraints.cpp
@@ -1,7 +1,7 @@
-// RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s 
-std=c++26 -fexceptions -fcxx-exceptions-fsized-deallocation
-faligned-allocation -Wno-non-c-typedef-for-linkage -DDEFAULT_DELETE=1
-// RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s 
-std=c++26 -fexceptions -fcxx-exceptions -fno-sized-deallocation
-faligned-allocation -Wno-non-c-typedef-for-linkage -DDEFAULT_DELETE=0
-// RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s 
-std=c++26 -fexceptions -fcxx-exceptions-fsized-deallocation 
-fno-aligned-allocation -Wno-non-c-typedef-for-linkage -DDEFAULT_DELETE=1
-// RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s 
-std=c++26 -fexceptions -fcxx-exceptions -fno-sized-deallocation 
-fno-aligned-allocation -Wno-non-c-typedef-for-linkage -DDEFAULT_DELETE=0
+// RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s 
-std=c++26 -Wno-cxx-type-aware-allocators -fexceptions -fcxx-exceptions
-fsized-deallocation-faligned-allocation -Wno-non-c-typedef-for-linkage 
-DDEFAULT_DELETE=1
+// RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s 
-std=c++26 -Wno-cxx-type-aware-allocators -fexceptions -fcxx-exceptions 
-fno-sized-deallocation-faligned-allocation -Wno-non-c-typedef-for-linkage 
-DDEFAULT_DELETE=0
+// RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s 
-std=c++26 -Wno-cxx-typ

[clang] [clang-tools-extra] [clang-tidy] `bugprone-unchecked-optional-access`: handle `BloombergLP::bdlb:NullableValue::makeValue` to prevent false-positives (PR #144313)

2025-07-14 Thread Gábor Horváth via cfe-commits


@@ -985,6 +985,20 @@ auto buildTransferMatchSwitch() {
   isOptionalMemberCallWithNameMatcher(hasName("isNull")),
   transferOptionalIsNullCall)
 
+  // NullableValue::makeValue, NullableValue::makeValueInplace
+  // Only NullableValue has these methods, but this
+  // will also pass for other types
+  .CaseOfCFGStmt(
+  isOptionalMemberCallWithNameMatcher(
+  hasAnyName("makeValue", "makeValueInplace")),
+  [](const CXXMemberCallExpr *E, const MatchFinder::MatchResult &,
+ LatticeTransferState &State) {
+if (RecordStorageLocation *Loc =
+getImplicitObjectLocation(*E, State.Env)) {
+  setHasValue(*Loc, State.Env.getBoolLiteralValue(true), 
State.Env);
+}
+  })
+

Xazax-hun wrote:

I'll defer to @ymand on the final decision what is the best way to do this. But 
in my opinion, this make a strong argument that the analysis instance should 
always be created by the client (e.g., we should pass the analysis instance to 
`diagnoseFunction` and similar) as all analyses might need different 
configuration options and we definitely don't want to deal with all that in a 
generic way in the framework. 

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


[clang] [clang] Update diagnostics for type aware allocators (PR #148576)

2025-07-14 Thread Corentin Jabot via cfe-commits

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

Thanks!

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


[clang] [KeyInstr] Add release note & update option (PR #148244)

2025-07-14 Thread Orlando Cazalet-Hyams via cfe-commits

https://github.com/OCHyams updated 
https://github.com/llvm/llvm-project/pull/148244

>From e31f415c4a1ba18f771a6119bee2bc11f4f705bb Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams 
Date: Fri, 11 Jul 2025 14:35:12 +0100
Subject: [PATCH 1/3] notes and helptext

---
 clang/docs/ReleaseNotes.rst   | 2 ++
 clang/include/clang/Driver/Options.td | 4 ++--
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index bee71cf296ac3..9fa0d182ead25 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -354,6 +354,8 @@ New Compiler Flags
 
 - New option ``-ignore-pch`` added to disable precompiled headers. It 
overrides ``-emit-pch`` and ``-include-pch``. (#GH142409, `PCHDocs 
`_).
 
+- New options ``-g[no-]key-instructions`` added, disabled by default. Reduces 
jumpiness of debug stepping for optimized code in some debuggers (not LLDB at 
this time). Not recommended for use without optimizations. DWARF only. Note 
both the positive and negative flags imply ``-g``.
+
 Deprecated Compiler Flags
 -
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 9911d752966e3..cc21e73e43fe6 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4705,8 +4705,8 @@ defm key_instructions : BoolGOption<"key-instructions",
 CodeGenOpts<"DebugKeyInstructions">, DefaultFalse,
 NegFlag, PosFlag,
-BothFlags<[HelpHidden], [ClangOption, CLOption, CC1Option]>>;
+" Implies -g.">,
+BothFlags<[], [ClangOption, CLOption, CC1Option]>>;
 def headerpad__max__install__names : Joined<["-"], 
"headerpad_max_install_names">;
 def help : Flag<["-", "--"], "help">,
 Visibility<[ClangOption, CC1Option, CC1AsOption,

>From 2474a23890da2f49670bec4e32bd07169aa40720 Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams 
Date: Fri, 11 Jul 2025 14:39:19 +0100
Subject: [PATCH 2/3] better help text

---
 clang/include/clang/Driver/Options.td | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index cc21e73e43fe6..a6ff105d1b6a4 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4704,8 +4704,8 @@ def gno_embed_source : Flag<["-"], "gno-embed-source">, 
Group,
 defm key_instructions : BoolGOption<"key-instructions",
 CodeGenOpts<"DebugKeyInstructions">, DefaultFalse,
 NegFlag, PosFlag,
+"Enable Key Instructions, which reduces the jumpiness of debug 
stepping in optimized C/C++ code"
+" in some debuggers. DWARF only. Implies -g.">,
 BothFlags<[], [ClangOption, CLOption, CC1Option]>>;
 def headerpad__max__install__names : Joined<["-"], 
"headerpad_max_install_names">;
 def help : Flag<["-", "--"], "help">,

>From 40097d68a0af4afad16c7c9d28e7da527189aa6c Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams 
Date: Mon, 14 Jul 2025 09:57:05 +0100
Subject: [PATCH 3/3] check help is visible

---
 clang/test/DebugInfo/KeyInstructions/flag.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/test/DebugInfo/KeyInstructions/flag.cpp 
b/clang/test/DebugInfo/KeyInstructions/flag.cpp
index 93503dd4bdb4c..f5f438ac683ea 100644
--- a/clang/test/DebugInfo/KeyInstructions/flag.cpp
+++ b/clang/test/DebugInfo/KeyInstructions/flag.cpp
@@ -3,9 +3,9 @@
  Default: Off.
 // RUN: %clang -### -target x86_64 -c -gdwarf %s 2>&1 | FileCheck %s 
--check-prefixes=NO-KEY-INSTRUCTIONS
 
- Help hidden.
+ Help.
 // RUN %clang --help | FileCheck %s --check-prefix=HELP
-// HELP-NOT: key-instructions
+// HELP: -gkey-instructions  Enable Key Instructions, which reduces the 
jumpiness of debug stepping in optimized C/C++ code in some debuggers. DWARF 
only. Implies -g.
 
 // KEY-INSTRUCTIONS: "-gkey-instructions"
 // KEY-INSTRUCTIONS: "-mllvm" "-dwarf-use-key-instructions"

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


[clang] [KeyInstr] Add release note & update option (PR #148244)

2025-07-14 Thread Orlando Cazalet-Hyams via cfe-commits

OCHyams wrote:

So it is. Fixed!

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


[clang] 34bb38f - [KeyInstr] Add release note & update option (#148244)

2025-07-14 Thread via cfe-commits

Author: Orlando Cazalet-Hyams
Date: 2025-07-14T11:21:20+01:00
New Revision: 34bb38ffbf12539bd403794ac2f7c29e50094d5f

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

LOG: [KeyInstr] Add release note & update option (#148244)

Make the option visible, improve the help text, and add a release note.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Driver/Options.td
clang/test/DebugInfo/KeyInstructions/flag.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6996066826cbc..9f745e8e0dca3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -376,6 +376,8 @@ New Compiler Flags
 
 - New option ``-ignore-pch`` added to disable precompiled headers. It 
overrides ``-emit-pch`` and ``-include-pch``. (#GH142409, `PCHDocs 
`_).
 
+- New options ``-g[no-]key-instructions`` added, disabled by default. Reduces 
jumpiness of debug stepping for optimized code in some debuggers (not LLDB at 
this time). Not recommended for use without optimizations. DWARF only. Note 
both the positive and negative flags imply ``-g``.
+
 Deprecated Compiler Flags
 -
 

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index b1314f2c53a79..2e070d6d64508 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4720,9 +4720,9 @@ def gno_embed_source : Flag<["-"], "gno-embed-source">, 
Group,
 defm key_instructions : BoolGOption<"key-instructions",
 CodeGenOpts<"DebugKeyInstructions">, DefaultFalse,
 NegFlag, PosFlag,
-BothFlags<[HelpHidden], [ClangOption, CLOption, CC1Option]>>;
+"Enable Key Instructions, which reduces the jumpiness of debug 
stepping in optimized C/C++ code"
+" in some debuggers. DWARF only. Implies -g.">,
+BothFlags<[], [ClangOption, CLOption, CC1Option]>>;
 def headerpad__max__install__names : Joined<["-"], 
"headerpad_max_install_names">;
 def help : Flag<["-", "--"], "help">,
 Visibility<[ClangOption, CC1Option, CC1AsOption,

diff  --git a/clang/test/DebugInfo/KeyInstructions/flag.cpp 
b/clang/test/DebugInfo/KeyInstructions/flag.cpp
index 813f7e908011c..e34faa6cbb347 100644
--- a/clang/test/DebugInfo/KeyInstructions/flag.cpp
+++ b/clang/test/DebugInfo/KeyInstructions/flag.cpp
@@ -3,6 +3,10 @@
  Default: Off.
 // RUN: %clang -### -target x86_64 -c -gdwarf %s 2>&1 | FileCheck %s 
--check-prefixes=NO-KEY-INSTRUCTIONS
 
+ Help.
+// RUN %clang --help | FileCheck %s --check-prefix=HELP
+// HELP: -gkey-instructions  Enable Key Instructions, which reduces the 
jumpiness of debug stepping in optimized C/C++ code in some debuggers. DWARF 
only. Implies -g.
+
 // KEY-INSTRUCTIONS: "-gkey-instructions"
 // NO-KEY-INSTRUCTIONS-NOT: key-instructions
 



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


[clang] [KeyInstr] Add release note & update option (PR #148244)

2025-07-14 Thread Orlando Cazalet-Hyams via cfe-commits

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


[clang] [KeyInstr] Add release note & update option (PR #148244)

2025-07-14 Thread Orlando Cazalet-Hyams via cfe-commits

https://github.com/OCHyams updated 
https://github.com/llvm/llvm-project/pull/148244

>From 8c3d449f4398c9dbc40c4be3f19f51bb2eadfc6d Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams 
Date: Fri, 11 Jul 2025 14:35:12 +0100
Subject: [PATCH 1/3] notes and helptext

---
 clang/docs/ReleaseNotes.rst   | 2 ++
 clang/include/clang/Driver/Options.td | 4 ++--
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6996066826cbc..9f745e8e0dca3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -376,6 +376,8 @@ New Compiler Flags
 
 - New option ``-ignore-pch`` added to disable precompiled headers. It 
overrides ``-emit-pch`` and ``-include-pch``. (#GH142409, `PCHDocs 
`_).
 
+- New options ``-g[no-]key-instructions`` added, disabled by default. Reduces 
jumpiness of debug stepping for optimized code in some debuggers (not LLDB at 
this time). Not recommended for use without optimizations. DWARF only. Note 
both the positive and negative flags imply ``-g``.
+
 Deprecated Compiler Flags
 -
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index b1314f2c53a79..6cc68615fd105 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4721,8 +4721,8 @@ defm key_instructions : BoolGOption<"key-instructions",
 CodeGenOpts<"DebugKeyInstructions">, DefaultFalse,
 NegFlag, PosFlag,
-BothFlags<[HelpHidden], [ClangOption, CLOption, CC1Option]>>;
+" Implies -g.">,
+BothFlags<[], [ClangOption, CLOption, CC1Option]>>;
 def headerpad__max__install__names : Joined<["-"], 
"headerpad_max_install_names">;
 def help : Flag<["-", "--"], "help">,
 Visibility<[ClangOption, CC1Option, CC1AsOption,

>From 14409b6a69a7a146487eb4ffd9b1469d57af47af Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams 
Date: Fri, 11 Jul 2025 14:39:19 +0100
Subject: [PATCH 2/3] better help text

---
 clang/include/clang/Driver/Options.td | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 6cc68615fd105..2e070d6d64508 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4720,8 +4720,8 @@ def gno_embed_source : Flag<["-"], "gno-embed-source">, 
Group,
 defm key_instructions : BoolGOption<"key-instructions",
 CodeGenOpts<"DebugKeyInstructions">, DefaultFalse,
 NegFlag, PosFlag,
+"Enable Key Instructions, which reduces the jumpiness of debug 
stepping in optimized C/C++ code"
+" in some debuggers. DWARF only. Implies -g.">,
 BothFlags<[], [ClangOption, CLOption, CC1Option]>>;
 def headerpad__max__install__names : Joined<["-"], 
"headerpad_max_install_names">;
 def help : Flag<["-", "--"], "help">,

>From 6dbedfd87a5fbe25a307c16c30edcb85135b8e3b Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams 
Date: Mon, 14 Jul 2025 09:57:05 +0100
Subject: [PATCH 3/3] check help is visible

---
 clang/test/DebugInfo/KeyInstructions/flag.cpp | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang/test/DebugInfo/KeyInstructions/flag.cpp 
b/clang/test/DebugInfo/KeyInstructions/flag.cpp
index 813f7e908011c..e34faa6cbb347 100644
--- a/clang/test/DebugInfo/KeyInstructions/flag.cpp
+++ b/clang/test/DebugInfo/KeyInstructions/flag.cpp
@@ -3,6 +3,10 @@
  Default: Off.
 // RUN: %clang -### -target x86_64 -c -gdwarf %s 2>&1 | FileCheck %s 
--check-prefixes=NO-KEY-INSTRUCTIONS
 
+ Help.
+// RUN %clang --help | FileCheck %s --check-prefix=HELP
+// HELP: -gkey-instructions  Enable Key Instructions, which reduces the 
jumpiness of debug stepping in optimized C/C++ code in some debuggers. DWARF 
only. Implies -g.
+
 // KEY-INSTRUCTIONS: "-gkey-instructions"
 // NO-KEY-INSTRUCTIONS-NOT: key-instructions
 

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


[clang] [KeyInstr] Add release note & update option (PR #148244)

2025-07-14 Thread Orlando Cazalet-Hyams via cfe-commits

OCHyams wrote:

ty
(rebased & fixed conflict)

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


[clang] [llvm] [HIPSTDPAR] Add support for globals (PR #146813)

2025-07-14 Thread Alex Voicu via cfe-commits

https://github.com/AlexVlx updated 
https://github.com/llvm/llvm-project/pull/146813

>From d98e3785a144ada9881cdbe24c86f273850eca20 Mon Sep 17 00:00:00 2001
From: Alex Voicu 
Date: Thu, 3 Jul 2025 02:02:04 +0100
Subject: [PATCH 1/6] Add support for true globals.

---
 llvm/lib/Transforms/HipStdPar/HipStdPar.cpp   | 220 +-
 ...al-var-indirection-wrong-table-member-0.ll |  15 ++
 ...al-var-indirection-wrong-table-member-1.ll |  15 ++
 ...al-var-indirection-wrong-table-member-2.ll |  15 ++
 ...ar-indirection-wrong-table-member-count.ll |  14 ++
 ...global-var-indirection-wrong-table-type.ll |  13 ++
 .../HipStdPar/global-var-indirection.ll   |  87 +++
 llvm/test/Transforms/HipStdPar/global-var.ll  |   4 +-
 8 files changed, 371 insertions(+), 12 deletions(-)
 create mode 100644 
llvm/test/Transforms/HipStdPar/global-var-indirection-wrong-table-member-0.ll
 create mode 100644 
llvm/test/Transforms/HipStdPar/global-var-indirection-wrong-table-member-1.ll
 create mode 100644 
llvm/test/Transforms/HipStdPar/global-var-indirection-wrong-table-member-2.ll
 create mode 100644 
llvm/test/Transforms/HipStdPar/global-var-indirection-wrong-table-member-count.ll
 create mode 100644 
llvm/test/Transforms/HipStdPar/global-var-indirection-wrong-table-type.ll
 create mode 100644 llvm/test/Transforms/HipStdPar/global-var-indirection.ll

diff --git a/llvm/lib/Transforms/HipStdPar/HipStdPar.cpp 
b/llvm/lib/Transforms/HipStdPar/HipStdPar.cpp
index 5a87cf8c83d79..87fbcd40be431 100644
--- a/llvm/lib/Transforms/HipStdPar/HipStdPar.cpp
+++ b/llvm/lib/Transforms/HipStdPar/HipStdPar.cpp
@@ -48,6 +48,7 @@
 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/Function.h"
+#include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/Module.h"
 #include "llvm/Transforms/Utils/ModuleUtils.h"
 
@@ -114,24 +115,223 @@ static inline void clearModule(Module &M) { // TODO: 
simplify.
 eraseFromModule(*M.ifuncs().begin());
 }
 
+static inline SmallVector> collectIndirectableUses(
+  GlobalVariable *G) {
+  // We are interested only in use chains that end in an Instruction.
+  SmallVector> Uses;
+
+  SmallVector> Tmp(G->use_begin(), G->use_end());
+  while (!Tmp.empty()) {
+Use &U = Tmp.back();
+Tmp.pop_back();
+if (isa(U.getUser()))
+  Uses.emplace_back(U);
+else
+  transform(U.getUser()->uses(), std::back_inserter(Tmp), [](auto &&U) {
+return std::ref(U);
+  });
+  }
+
+  return Uses;
+}
+
+static inline GlobalVariable *getGlobalForName(GlobalVariable *G) {
+  // Create an anonymous global which stores the variable's name, which will be
+  // used by the HIPSTDPAR runtime to look up the program-wide symbol.
+  LLVMContext &Ctx = G->getContext();
+  auto *CDS = ConstantDataArray::getString(Ctx, G->getName());
+
+  GlobalVariable *N = G->getParent()->getOrInsertGlobal("", CDS->getType());
+  N->setInitializer(CDS);
+  N->setLinkage(GlobalValue::LinkageTypes::PrivateLinkage);
+  N->setConstant(true);
+
+  return N;
+}
+
+static inline GlobalVariable *getIndirectionGlobal(Module *M) {
+  // Create an anonymous global which stores a pointer to a pointer, which will
+  // be externally initialised by the HIPSTDPAR runtime with the address of the
+  // program-wide symbol.
+  Type *PtrTy =
+  PointerType::get(M->getContext(),
+   M->getDataLayout().getDefaultGlobalsAddressSpace());
+  GlobalVariable *NewG = M->getOrInsertGlobal("", PtrTy);
+
+  NewG->setInitializer(PoisonValue::get(NewG->getValueType()));
+  NewG->setLinkage(GlobalValue::LinkageTypes::PrivateLinkage);
+  NewG->setConstant(true);
+  NewG->setExternallyInitialized(true);
+
+  return NewG;
+}
+
+static inline Constant *appendIndirectedGlobal(
+const GlobalVariable *IndirectionTable,
+SmallVector &SymbolIndirections,
+GlobalVariable *ToIndirect) {
+  Module *M = ToIndirect->getParent();
+
+  auto *InitTy = cast(IndirectionTable->getValueType());
+  auto *SymbolListTy = cast(InitTy->getStructElementType(2));
+  Type *NameTy = SymbolListTy->getElementType(0);
+  Type *IndirectTy = SymbolListTy->getElementType(1);
+
+  Constant *NameG = getGlobalForName(ToIndirect);
+  Constant *IndirectG = getIndirectionGlobal(M);
+  Constant *Entry = ConstantStruct::get(
+  SymbolListTy, {ConstantExpr::getAddrSpaceCast(NameG, NameTy),
+ ConstantExpr::getAddrSpaceCast(IndirectG, IndirectTy)});
+  SymbolIndirections.push_back(Entry);
+
+  return IndirectG;
+}
+
+static void fillIndirectionTable(GlobalVariable *IndirectionTable,
+ SmallVector Indirections) {
+  Module *M = IndirectionTable->getParent();
+  size_t SymCnt = Indirections.size();
+
+  auto *InitTy = cast(IndirectionTable->getValueType());
+  Type *SymbolListTy = InitTy->getStructElementType(1);
+  auto *SymbolTy = cast(InitTy->getStructElementType(2));
+
+  Constant *Count = ConstantInt::get(InitTy->getStructElementType(0), SymCnt);
+  M->removeGlobalV

[clang] 65d20bb - [KeyInstr] Disable key-instructions for coroutine scopes (#147551)

2025-07-14 Thread via cfe-commits

Author: Jeremy Morse
Date: 2025-07-14T11:28:07+01:00
New Revision: 65d20bb0ab27f1b0078cc8811d02f7b47eb779bf

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

LOG: [KeyInstr] Disable key-instructions for coroutine scopes (#147551)

At this time (immediately prior to llvm21 branching) we haven't
instrumented coroutine generation to identify the "key" instructions of
things like co_return and similar. This will lead to worse stepping
behaviours, as there won't be any key instruction for those lines.

This patch removes the key-instructions flag from the DISubprograms for
coroutines, which will cause AsmPrinter to use the "old" / existing
linetable stepping behaviour, avoiding a regression until we can
instrument these constructs.

(I'm going to post on discourse about whether this is a good idea or not
in a moment)

Added: 
clang/test/DebugInfo/KeyInstructions/coro-dwarf-key-instrs.cpp

Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 8bf7d24d8551d..5240853199c11 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -4629,6 +4629,7 @@ void CGDebugInfo::emitFunctionStart(GlobalDecl GD, 
SourceLocation Loc,
   llvm::DIFile *Unit = getOrCreateFile(Loc);
   llvm::DIScope *FDContext = Unit;
   llvm::DINodeArray TParamsArray;
+  bool KeyInstructions = CGM.getCodeGenOpts().DebugKeyInstructions;
   if (!HasDecl) {
 // Use llvm function name.
 LinkageName = Fn->getName();
@@ -4645,6 +4646,9 @@ void CGDebugInfo::emitFunctionStart(GlobalDecl GD, 
SourceLocation Loc,
 }
 collectFunctionDeclProps(GD, Unit, Name, LinkageName, FDContext,
  TParamsArray, Flags);
+// Disable KIs if this is a coroutine.
+KeyInstructions =
+KeyInstructions && !isa_and_present(FD->getBody());
   } else if (const auto *OMD = dyn_cast(D)) {
 Name = getObjCMethodName(OMD);
 Flags |= llvm::DINode::FlagPrototyped;
@@ -4706,7 +4710,7 @@ void CGDebugInfo::emitFunctionStart(GlobalDecl GD, 
SourceLocation Loc,
   llvm::DISubprogram *SP = DBuilder.createFunction(
   FDContext, Name, LinkageName, Unit, LineNo, DIFnType, ScopeLine,
   FlagsForDef, SPFlagsForDef, TParamsArray.get(), Decl, nullptr,
-  Annotations, "", CGM.getCodeGenOpts().DebugKeyInstructions);
+  Annotations, "", KeyInstructions);
   Fn->setSubprogram(SP);
 
   // We might get here with a VarDecl in the case we're generating

diff  --git a/clang/test/DebugInfo/KeyInstructions/coro-dwarf-key-instrs.cpp 
b/clang/test/DebugInfo/KeyInstructions/coro-dwarf-key-instrs.cpp
new file mode 100644
index 0..66537db88155d
--- /dev/null
+++ b/clang/test/DebugInfo/KeyInstructions/coro-dwarf-key-instrs.cpp
@@ -0,0 +1,81 @@
+// RUN: %clang_cc1 -disable-llvm-optzns -std=c++20 \
+// RUN:-triple=x86_64 -dwarf-version=4 -debug-info-kind=limited \
+// RUN:-emit-llvm -o - %s -gkey-instructions | \
+// RUN:FileCheck %s
+
+// Check that for the coroutine below, we mark the created DISubprogram as
+// not having key instructions. This will prevent AsmPrinter from trying to
+// instrument the linetable with key-instructions for source-locations in
+// the coroutine scope.
+//
+// This is a temporary workaround for key instructions: we can instrument
+// coroutine code in the future, but it hasn't been done yet.
+//
+// File contents copied from coro-dwarf.cpp.
+
+namespace std {
+template  struct coroutine_traits;
+
+template  struct coroutine_handle {
+  coroutine_handle() = default;
+  static coroutine_handle from_address(void *) noexcept;
+};
+template <> struct coroutine_handle {
+  static coroutine_handle from_address(void *) noexcept;
+  coroutine_handle() = default;
+  template 
+  coroutine_handle(coroutine_handle) noexcept;
+};
+} // namespace std
+
+struct suspend_always {
+  bool await_ready() noexcept;
+  void await_suspend(std::coroutine_handle<>) noexcept;
+  void await_resume() noexcept;
+};
+
+template  struct std::coroutine_traits {
+  struct promise_type {
+void get_return_object() noexcept;
+suspend_always initial_suspend() noexcept;
+suspend_always final_suspend() noexcept;
+void return_void() noexcept;
+promise_type();
+~promise_type() noexcept;
+void unhandled_exception() noexcept;
+  };
+};
+
+// TODO: Not supported yet
+struct CopyOnly {
+  int val;
+  CopyOnly(const CopyOnly &) noexcept;
+  CopyOnly(CopyOnly &&) = delete;
+  ~CopyOnly();
+};
+
+struct MoveOnly {
+  int val;
+  MoveOnly(const MoveOnly &) = delete;
+  MoveOnly(MoveOnly &&) noexcept;
+  ~MoveOnly();
+};
+
+struct MoveAndCopy {
+  int val;
+  MoveAndCopy(const MoveAndCopy &) noexcept;
+  MoveAndCopy(MoveAndCop

[clang] [Clang][CodeGen] Emit “trap reasons” on UBSan traps (PR #145967)

2025-07-14 Thread Michael Buch via cfe-commits

Michael137 wrote:

> What is debug info size impact?

Realistically this will add a few more abbreviations into `.debug_abbrev` and 
only a few extra bytes per-UBSAN trap (abbreviation code + 1 ULEB128 for the 
index into the string offset table) into `.debug_info`. The rest of the 
`DW_TAG_subprogram` is encoded in the abbreviation for that fake frame. But I 
don't have a good intuition for how many UBSAN traps get emitted for a large 
codebase. So @anthonyhatran try this on a bootstrapped Clang build

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


[clang] [KeyInstr] Disable key-instructions for coroutine scopes (PR #147551)

2025-07-14 Thread Jeremy Morse via cfe-commits

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


[clang] [WIP][DO NOT MERGE][Clang][Driver] Emit warning when -fsanitize-trap=<...> is passed without associated -fsanitize=<...> (PR #147997)

2025-07-14 Thread Anthony Tran via cfe-commits

https://github.com/anthonyhatran updated 
https://github.com/llvm/llvm-project/pull/147997

>From eadf3e52072fbae01e8de8f7f59883aec1b2c9bc Mon Sep 17 00:00:00 2001
From: Anthony Tran 
Date: Thu, 10 Jul 2025 09:18:50 -0700
Subject: [PATCH 1/3] Added warning and warning group for sanitizer argument
 mismatch

---
 clang/include/clang/Basic/DiagnosticDriverKinds.td | 5 +
 clang/include/clang/Basic/DiagnosticGroups.td  | 3 +++
 2 files changed, 8 insertions(+)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 34b6c0d7a8acd..49a8bdf06bda4 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -874,4 +874,9 @@ def warn_drv_openacc_without_cir
 : Warning<"OpenACC directives will result in no runtime behavior; use "
   "-fclangir to enable runtime effect">,
   InGroup;
+
+def warn_drv_sanitize_trap_mismatch : Warning<
+  "-fsanitize-trap=%0 has no effect because the matching sanitizer is not 
enabled; "
+  "did you mean to pass \"-fsanitize=%0\" as well?">,
+  InGroup;
 }
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index f54a830b0103e..a79562cd9c2e0 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1752,3 +1752,6 @@ def ExplicitSpecializationStorageClass : 
DiagGroup<"explicit-specialization-stor
 
 // A warning for options that enable a feature that is not yet complete
 def ExperimentalOption : DiagGroup<"experimental-option">;
+
+// Warnings for sanitizer arguments
+def SanitizeTrapMismatch : DiagGroup<"sanitize-trap-mismatch">;

>From f1bf9b34daca5d23d1a3f518847f3ccbc8f069a7 Mon Sep 17 00:00:00 2001
From: Anthony Tran 
Date: Thu, 10 Jul 2025 13:35:52 -0700
Subject: [PATCH 2/3] Emit warning and parse mismatched arguments

---
 clang/lib/Driver/SanitizerArgs.cpp | 36 ++
 1 file changed, 36 insertions(+)

diff --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index 4bd61c2f8deef..8b78d850e0018 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -348,6 +348,30 @@ parseSanitizeSkipHotCutoffArgs(const Driver &D, const 
llvm::opt::ArgList &Args,
   return Cutoffs;
 }
 
+// Given a set of mismatched bits, TrapOnly (bits the user asked to trap but
+// that aren’t actually enabled), emit a warning based on -fsanitize-trap=NAME
+static void diagnoseTrapOnly(const Driver &D, SanitizerMask &TrapOnly) {
+// Double pass: one for sanitizer groupings, one for leaves (ex: undefined vs.
+// signed-integer-overflow)
+#define SANITIZER(NAME, ID)
+#define SANITIZER_GROUP(NAME, ID, ALIAS)   
\
+  if (TrapOnly & SanitizerKind::ID##Group) {   
\
+D.Diag(diag::warn_drv_sanitize_trap_mismatch) << NAME; 
\
+TrapOnly &= ~SanitizerKind::ID##Group; 
\
+TrapOnly &= ~SanitizerKind::ID;
\
+  }
+#include "clang/Basic/Sanitizers.def"
+
+#undef SANITIZER_GROUP
+#define SANITIZER_GROUP(NAME, ID, ALIAS)
+#define SANITIZER(NAME, ID)
\
+  if (TrapOnly & SanitizerKind::ID) {  
\
+D.Diag(diag::warn_drv_sanitize_trap_mismatch) << NAME; 
\
+TrapOnly &= ~SanitizerKind::ID;
\
+  }
+#include "clang/Basic/Sanitizers.def"
+}
+
 bool SanitizerArgs::needsFuzzerInterceptors() const {
   return needsFuzzer() && !needsAsanRt() && !needsTsanRt() && !needsMsanRt();
 }
@@ -730,6 +754,18 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
   options::OPT_fno_sanitize_recover_EQ);
   RecoverableKinds &= Kinds;
 
+  // Parse any -fsanitize-trap=<...> flags the user provided, then
+  // diagnose any which do not have a matching -fsanitize=<...>
+  if (DiagnoseErrors) {
+SanitizerMask ExplicitTrap = parseSanitizeArgs(
+D, Args, false, {}, {}, {}, options::OPT_fsanitize_trap_EQ,
+options::OPT_fno_sanitize_trap_EQ);
+SanitizerMask TrapOnly = ExplicitTrap & ~Kinds;
+
+if (TrapOnly)
+  diagnoseTrapOnly(D, TrapOnly);
+  }
+
   TrappingKinds &= Kinds;
   RecoverableKinds &= ~TrappingKinds;
 

>From c7b44099357ee78329f6e289ef6feb321b9b121c Mon Sep 17 00:00:00 2001
From: Anthony Tran 
Date: Mon, 14 Jul 2025 03:36:11 -0700
Subject: [PATCH 3/3] Modify warning message

---
 clang/include/clang/Basic/DiagnosticDriverKinds.td | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 49a8bdf06bda4..f2a0582a364bf 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/cl

[clang-tools-extra] [clang-tidy] Add new check: `readability-use-concise-preprocessor-directives` (PR #146830)

2025-07-14 Thread Jan Patrick Lehr via cfe-commits

jplehr wrote:

A LLVM syncbot commit turned our buildbot red: 
https://lab.llvm.org/buildbot/#/builders/123/builds/23254

The syncbot commit links to this PR. 

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


[clang-tools-extra] [clang-tidy] Make `bugprone-unhandled-self-assignment` check more general (PR #147066)

2025-07-14 Thread Andrey Karlov via cfe-commits

https://github.com/negativ updated 
https://github.com/llvm/llvm-project/pull/147066

>From 950b6dce92eb2a831e7bd7e7ba44b3e8cc354dd4 Mon Sep 17 00:00:00 2001
From: Andrey Karlov 
Date: Fri, 4 Jul 2025 17:13:20 +0300
Subject: [PATCH 1/7] Checking that some kind of constructor is called and
 followed by a `swap`

---
 .../bugprone/UnhandledSelfAssignmentCheck.cpp | 19 ++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git 
a/clang-tools-extra/clang-tidy/bugprone/UnhandledSelfAssignmentCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/UnhandledSelfAssignmentCheck.cpp
index 1f432c4ccc5f0..8307e744a434c 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UnhandledSelfAssignmentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UnhandledSelfAssignmentCheck.cpp
@@ -68,7 +68,23 @@ void 
UnhandledSelfAssignmentCheck::registerMatchers(MatchFinder *Finder) {
   const auto HasNoNestedSelfAssign =
   
cxxMethodDecl(unless(hasDescendant(cxxMemberCallExpr(callee(cxxMethodDecl(
   hasName("operator="), ofClass(equalsBoundNode("class";
-
+  
+  // Checking that some kind of constructor is called and followed by a `swap`:
+  // T& operator=(const T& other) {
+  //T tmp{this->internal_data(), some, other, args};
+  //swap(tmp);
+  //return *this;
+  // }
+  const auto HasCopyAndSwap = cxxMethodDecl(
+  ofClass(cxxRecordDecl(unless(hasAncestor(classTemplateDecl(),
+  hasDescendant(
+  stmt(hasDescendant(
+   varDecl(hasType(cxxRecordDecl(equalsBoundNode("class"
+   .bind("tmp_var")),
+   hasDescendant(callExpr(callee(functionDecl(hasName("swap"))),
+  hasAnyArgument(declRefExpr(to(varDecl(
+  equalsBoundNode("tmp_var"));
+
   DeclarationMatcher AdditionalMatcher = cxxMethodDecl();
   if (WarnOnlyIfThisHasSuspiciousField) {
 // Matcher for standard smart pointers.
@@ -94,6 +110,7 @@ void 
UnhandledSelfAssignmentCheck::registerMatchers(MatchFinder *Finder) {
HasReferenceParam, HasNoSelfCheck,
unless(HasNonTemplateSelfCopy),
unless(HasTemplateSelfCopy),
+   unless(HasCopyAndSwap),
HasNoNestedSelfAssign, AdditionalMatcher)
  .bind("copyAssignmentOperator"),
  this);

>From 0cd33ec49693cfc6f5a72b72a9c50ba868634221 Mon Sep 17 00:00:00 2001
From: Andrey Karlov 
Date: Fri, 4 Jul 2025 17:19:02 +0300
Subject: [PATCH 2/7] Tests

---
 .../bugprone/unhandled-self-assignment.cpp| 90 +++
 1 file changed, 90 insertions(+)

diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unhandled-self-assignment.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unhandled-self-assignment.cpp
index 8610393449f97..f2f61062f883f 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unhandled-self-assignment.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unhandled-self-assignment.cpp
@@ -28,6 +28,13 @@ template 
 class auto_ptr {
 };
 
+namespace pmr {
+template 
+class allocator {};
+}
+
+struct allocator_arg_t {} allocator_arg;
+
 } // namespace std
 
 void assert(int expression){};
@@ -540,6 +547,89 @@ class NotACopyAssignmentOperator {
   Uy *getUy() const { return Ptr2; }
 };
 
+// Support "extended" copy/move constructors
+class AllocatorAwareClass {
+  // pointer member to trigger bugprone-unhandled-self-assignment
+  void *foo = nullptr;
+
+  public:
+using allocator_type = std::pmr::allocator<>;
+
+AllocatorAwareClass(const AllocatorAwareClass& other) {
+}
+
+AllocatorAwareClass(const AllocatorAwareClass& other, const 
allocator_type& alloc) {
+}
+
+AllocatorAwareClass& operator=(const AllocatorAwareClass& other) {
+AllocatorAwareClass tmp(other, get_allocator());
+swap(tmp);
+return *this;
+}
+
+void swap(AllocatorAwareClass& other) noexcept {
+}
+
+allocator_type get_allocator() const {
+return allocator_type();
+}
+};
+
+// Support "extended" copy/move constructors + std::swap
+class AllocatorAwareClassStdSwap {
+  // pointer member to trigger bugprone-unhandled-self-assignment
+  void *foo = nullptr;
+
+  public:
+using allocator_type = std::pmr::allocator<>;
+
+AllocatorAwareClassStdSwap(const AllocatorAwareClassStdSwap& other) {
+}
+
+AllocatorAwareClassStdSwap(const AllocatorAwareClassStdSwap& other, const 
allocator_type& alloc) {
+}
+
+AllocatorAwareClassStdSwap& operator=(const AllocatorAwareClassStdSwap& 
other) {
+using std::swap;
+
+AllocatorAwareClassStdSwap tmp(other, get_allocator());
+swap(*this, tmp);
+return *this;
+}
+
+allocator_type get_allocator() const {
+re

[clang] [LifetimeSafety] Implement dataflow analysis for loan propagation (PR #148065)

2025-07-14 Thread Gábor Horváth via cfe-commits


@@ -493,7 +496,247 @@ class FactGenerator : public 
ConstStmtVisitor {
 };
 
 // = //
-//  TODO: Run dataflow analysis to propagate loans, analyse and error 
reporting.
+//  The Dataflow Lattice
+// = //
+
+// Using LLVM's immutable collections is efficient for dataflow analysis
+// as it avoids deep copies during state transitions.
+// TODO(opt): Consider using a bitset to represent the set of loans.
+using LoanSet = llvm::ImmutableSet;
+using OriginLoanMap = llvm::ImmutableMap;
+
+/// An object to hold the factories for immutable collections, ensuring
+/// that all created states share the same underlying memory management.
+struct LifetimeFactory {
+  OriginLoanMap::Factory OriginMapFact;
+  LoanSet::Factory LoanSetFact;
+
+  LoanSet createLoanSet(LoanID LID) {
+return LoanSetFact.add(LoanSetFact.getEmptySet(), LID);
+  }
+};
+
+/// LifetimeLattice represents the state of our analysis at a given program
+/// point. It is an immutable object, and all operations produce a new
+/// instance rather than modifying the existing one.
+struct LifetimeLattice {
+  /// The map from an origin to the set of loans it contains.
+  /// TODO(opt): To reduce the lattice size, propagate origins of declarations,
+  /// not expressions, because expressions are not visible across blocks.
+  OriginLoanMap Origins = OriginLoanMap(nullptr);
+
+  explicit LifetimeLattice(const OriginLoanMap &S) : Origins(S) {}
+  LifetimeLattice() = default;
+
+  bool operator==(const LifetimeLattice &Other) const {
+return Origins == Other.Origins;
+  }
+  bool operator!=(const LifetimeLattice &Other) const {
+return !(*this == Other);
+  }
+
+  LoanSet getLoans(OriginID OID, LifetimeFactory &Factory) const {
+if (auto *Loans = Origins.lookup(OID))
+  return *Loans;
+return Factory.LoanSetFact.getEmptySet();
+  }
+
+  /// Computes the union of two lattices by performing a key-wise join of
+  /// their OriginLoanMaps.
+  // TODO(opt): This key-wise join is a performance bottleneck. A more
+  // efficient merge could be implemented using a Patricia Trie or HAMT
+  // instead of the current AVL-tree-based ImmutableMap.
+  LifetimeLattice join(const LifetimeLattice &Other,
+   LifetimeFactory &Factory) const {
+/// Merge the smaller map into the larger one ensuring we iterate over the
+/// smaller map.
+if (Origins.getHeight() < Other.Origins.getHeight())
+  return Other.join(*this, Factory);
+
+OriginLoanMap JoinedState = Origins;
+// For each origin in the other map, union its loan set with ours.
+for (const auto &Entry : Other.Origins) {
+  OriginID OID = Entry.first;
+  LoanSet OtherLoanSet = Entry.second;
+  JoinedState = Factory.OriginMapFact.add(
+  JoinedState, OID,
+  join(getLoans(OID, Factory), OtherLoanSet, Factory));
+}
+return LifetimeLattice(JoinedState);
+  }
+
+  LoanSet join(LoanSet a, LoanSet b, LifetimeFactory &Factory) const {
+/// Merge the smaller set into the larger one ensuring we iterate over the
+/// smaller set.
+if (a.getHeight() < b.getHeight())
+  std::swap(a, b);
+LoanSet Result = a;
+for (LoanID LID : b) {
+  /// TODO(opt): Profiling shows that this loop is a major performance
+  /// bottleneck. Investigate using a BitVector to represent the set of
+  /// loans for improved join performance.
+  Result = Factory.LoanSetFact.add(Result, LID);
+}
+return Result;
+  }
+
+  void dump(llvm::raw_ostream &OS) const {
+OS << "LifetimeLattice State:\n";
+if (Origins.isEmpty())
+  OS << "  \n";
+for (const auto &Entry : Origins) {
+  if (Entry.second.isEmpty())
+OS << "  Origin " << Entry.first << " contains no loans\n";
+  for (const LoanID &LID : Entry.second)
+OS << "  Origin " << Entry.first << " contains Loan " << LID << "\n";
+}
+  }
+};
+
+// = //
+//  The Transfer Function
+// = //
+class Transferer {
+  FactManager &AllFacts;
+  LifetimeFactory &Factory;
+
+public:
+  explicit Transferer(FactManager &F, LifetimeFactory &Factory)
+  : AllFacts(F), Factory(Factory) {}
+
+  /// Computes the exit state of a block by applying all its facts sequentially
+  /// to a given entry state.
+  /// TODO: We might need to store intermediate states per-fact in the block 
for
+  /// later analysis.
+  LifetimeLattice transferBlock(const CFGBlock *Block,
+LifetimeLattice EntryState) {
+LifetimeLattice BlockState = EntryState;
+llvm::ArrayRef Facts = AllFacts.getFacts(Block);
+
+for (const Fact *F : Facts) {
+  BlockState = transferF

[clang] [LifetimeSafety] Implement dataflow analysis for loan propagation (PR #148065)

2025-07-14 Thread Gábor Horváth via cfe-commits


@@ -493,7 +496,247 @@ class FactGenerator : public 
ConstStmtVisitor {
 };
 
 // = //
-//  TODO: Run dataflow analysis to propagate loans, analyse and error 
reporting.
+//  The Dataflow Lattice
+// = //
+
+// Using LLVM's immutable collections is efficient for dataflow analysis
+// as it avoids deep copies during state transitions.
+// TODO(opt): Consider using a bitset to represent the set of loans.
+using LoanSet = llvm::ImmutableSet;
+using OriginLoanMap = llvm::ImmutableMap;
+
+/// An object to hold the factories for immutable collections, ensuring
+/// that all created states share the same underlying memory management.
+struct LifetimeFactory {
+  OriginLoanMap::Factory OriginMapFact;
+  LoanSet::Factory LoanSetFact;
+
+  LoanSet createLoanSet(LoanID LID) {
+return LoanSetFact.add(LoanSetFact.getEmptySet(), LID);
+  }
+};
+
+/// LifetimeLattice represents the state of our analysis at a given program
+/// point. It is an immutable object, and all operations produce a new
+/// instance rather than modifying the existing one.
+struct LifetimeLattice {
+  /// The map from an origin to the set of loans it contains.
+  /// TODO(opt): To reduce the lattice size, propagate origins of declarations,
+  /// not expressions, because expressions are not visible across blocks.
+  OriginLoanMap Origins = OriginLoanMap(nullptr);
+
+  explicit LifetimeLattice(const OriginLoanMap &S) : Origins(S) {}
+  LifetimeLattice() = default;
+
+  bool operator==(const LifetimeLattice &Other) const {
+return Origins == Other.Origins;
+  }
+  bool operator!=(const LifetimeLattice &Other) const {
+return !(*this == Other);
+  }
+
+  LoanSet getLoans(OriginID OID, LifetimeFactory &Factory) const {
+if (auto *Loans = Origins.lookup(OID))
+  return *Loans;
+return Factory.LoanSetFact.getEmptySet();
+  }
+
+  /// Computes the union of two lattices by performing a key-wise join of
+  /// their OriginLoanMaps.
+  // TODO(opt): This key-wise join is a performance bottleneck. A more
+  // efficient merge could be implemented using a Patricia Trie or HAMT
+  // instead of the current AVL-tree-based ImmutableMap.
+  LifetimeLattice join(const LifetimeLattice &Other,
+   LifetimeFactory &Factory) const {
+/// Merge the smaller map into the larger one ensuring we iterate over the
+/// smaller map.
+if (Origins.getHeight() < Other.Origins.getHeight())
+  return Other.join(*this, Factory);
+
+OriginLoanMap JoinedState = Origins;
+// For each origin in the other map, union its loan set with ours.
+for (const auto &Entry : Other.Origins) {
+  OriginID OID = Entry.first;
+  LoanSet OtherLoanSet = Entry.second;
+  JoinedState = Factory.OriginMapFact.add(
+  JoinedState, OID,
+  join(getLoans(OID, Factory), OtherLoanSet, Factory));
+}
+return LifetimeLattice(JoinedState);
+  }
+
+  LoanSet join(LoanSet a, LoanSet b, LifetimeFactory &Factory) const {
+/// Merge the smaller set into the larger one ensuring we iterate over the
+/// smaller set.
+if (a.getHeight() < b.getHeight())
+  std::swap(a, b);
+LoanSet Result = a;
+for (LoanID LID : b) {
+  /// TODO(opt): Profiling shows that this loop is a major performance
+  /// bottleneck. Investigate using a BitVector to represent the set of
+  /// loans for improved join performance.
+  Result = Factory.LoanSetFact.add(Result, LID);
+}
+return Result;
+  }
+
+  void dump(llvm::raw_ostream &OS) const {
+OS << "LifetimeLattice State:\n";
+if (Origins.isEmpty())
+  OS << "  \n";
+for (const auto &Entry : Origins) {
+  if (Entry.second.isEmpty())
+OS << "  Origin " << Entry.first << " contains no loans\n";
+  for (const LoanID &LID : Entry.second)
+OS << "  Origin " << Entry.first << " contains Loan " << LID << "\n";
+}
+  }
+};
+
+// = //
+//  The Transfer Function
+// = //
+class Transferer {
+  FactManager &AllFacts;
+  LifetimeFactory &Factory;
+
+public:
+  explicit Transferer(FactManager &F, LifetimeFactory &Factory)
+  : AllFacts(F), Factory(Factory) {}
+
+  /// Computes the exit state of a block by applying all its facts sequentially
+  /// to a given entry state.
+  /// TODO: We might need to store intermediate states per-fact in the block 
for
+  /// later analysis.
+  LifetimeLattice transferBlock(const CFGBlock *Block,
+LifetimeLattice EntryState) {
+LifetimeLattice BlockState = EntryState;
+llvm::ArrayRef Facts = AllFacts.getFacts(Block);
+
+for (const Fact *F : Facts) {
+  BlockState = transferF

[clang-tools-extra] [clang-tidy] Add new check: `readability-use-concise-preprocessor-directives` (PR #146830)

2025-07-14 Thread Jan Patrick Lehr via cfe-commits

jplehr wrote:

Hi, I don't know why, but it seems that on those machines, some git issue 
creped up with some stale refs. I think I resolved them.

Nothing to worry about with this PR ,and apologies for the noise!

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


[clang] [LifetimeSafety] Implement dataflow analysis for loan propagation (PR #148065)

2025-07-14 Thread Gábor Horváth via cfe-commits


@@ -493,7 +496,247 @@ class FactGenerator : public 
ConstStmtVisitor {
 };
 
 // = //
-//  TODO: Run dataflow analysis to propagate loans, analyse and error 
reporting.
+//  The Dataflow Lattice
+// = //
+
+// Using LLVM's immutable collections is efficient for dataflow analysis
+// as it avoids deep copies during state transitions.
+// TODO(opt): Consider using a bitset to represent the set of loans.
+using LoanSet = llvm::ImmutableSet;
+using OriginLoanMap = llvm::ImmutableMap;
+
+/// An object to hold the factories for immutable collections, ensuring
+/// that all created states share the same underlying memory management.
+struct LifetimeFactory {
+  OriginLoanMap::Factory OriginMapFact;
+  LoanSet::Factory LoanSetFact;
+
+  LoanSet createLoanSet(LoanID LID) {
+return LoanSetFact.add(LoanSetFact.getEmptySet(), LID);
+  }
+};
+
+/// LifetimeLattice represents the state of our analysis at a given program
+/// point. It is an immutable object, and all operations produce a new
+/// instance rather than modifying the existing one.
+struct LifetimeLattice {
+  /// The map from an origin to the set of loans it contains.
+  /// TODO(opt): To reduce the lattice size, propagate origins of declarations,
+  /// not expressions, because expressions are not visible across blocks.
+  OriginLoanMap Origins = OriginLoanMap(nullptr);
+
+  explicit LifetimeLattice(const OriginLoanMap &S) : Origins(S) {}
+  LifetimeLattice() = default;
+
+  bool operator==(const LifetimeLattice &Other) const {
+return Origins == Other.Origins;
+  }
+  bool operator!=(const LifetimeLattice &Other) const {
+return !(*this == Other);
+  }
+
+  LoanSet getLoans(OriginID OID, LifetimeFactory &Factory) const {
+if (auto *Loans = Origins.lookup(OID))
+  return *Loans;
+return Factory.LoanSetFact.getEmptySet();
+  }
+
+  /// Computes the union of two lattices by performing a key-wise join of
+  /// their OriginLoanMaps.
+  // TODO(opt): This key-wise join is a performance bottleneck. A more
+  // efficient merge could be implemented using a Patricia Trie or HAMT
+  // instead of the current AVL-tree-based ImmutableMap.
+  LifetimeLattice join(const LifetimeLattice &Other,
+   LifetimeFactory &Factory) const {
+/// Merge the smaller map into the larger one ensuring we iterate over the
+/// smaller map.
+if (Origins.getHeight() < Other.Origins.getHeight())
+  return Other.join(*this, Factory);
+
+OriginLoanMap JoinedState = Origins;
+// For each origin in the other map, union its loan set with ours.
+for (const auto &Entry : Other.Origins) {
+  OriginID OID = Entry.first;
+  LoanSet OtherLoanSet = Entry.second;
+  JoinedState = Factory.OriginMapFact.add(
+  JoinedState, OID,
+  join(getLoans(OID, Factory), OtherLoanSet, Factory));
+}
+return LifetimeLattice(JoinedState);
+  }
+
+  LoanSet join(LoanSet a, LoanSet b, LifetimeFactory &Factory) const {
+/// Merge the smaller set into the larger one ensuring we iterate over the
+/// smaller set.
+if (a.getHeight() < b.getHeight())
+  std::swap(a, b);
+LoanSet Result = a;
+for (LoanID LID : b) {
+  /// TODO(opt): Profiling shows that this loop is a major performance

Xazax-hun wrote:

Another way to potentially speed this up is to try to keep the state small. If 
an origin is dead, we might be able to remove it from the state. 

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


[clang-tools-extra] [clang-tidy] Make `bugprone-unhandled-self-assignment` check more general (PR #147066)

2025-07-14 Thread Andrey Karlov via cfe-commits


@@ -69,6 +69,22 @@ void 
UnhandledSelfAssignmentCheck::registerMatchers(MatchFinder *Finder) {
   
cxxMethodDecl(unless(hasDescendant(cxxMemberCallExpr(callee(cxxMethodDecl(
   hasName("operator="), ofClass(equalsBoundNode("class";
 
+  // Checking that some kind of constructor is called and followed by a `swap`:
+  // T& operator=(const T& other) {
+  //T tmp{this->internal_data(), some, other, args};
+  //swap(tmp);
+  //return *this;
+  // }
+  const auto HasCopyAndSwap = cxxMethodDecl(
+  ofClass(cxxRecordDecl(unless(hasAncestor(classTemplateDecl(),

negativ wrote:

@5chmidti since I'm just getting started with AST-matchers, I went with the 
safe approach :D Stripped out the extra restrictions - it's simply 
`ofClass(cxxRecordDecl())` now

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


[clang-tools-extra] [clang-tidy] Make `bugprone-unhandled-self-assignment` check more general (PR #147066)

2025-07-14 Thread Andrey Karlov via cfe-commits


@@ -189,6 +189,12 @@ Changes in existing checks
   calls of ``std::string`` constructor with char pointer, start position and
   length parameters.
 
+- Improved :doc:`bugprone-unhandled-self-assignment
+  ` check by adding
+  an additional matcher that generalizes the copy-and-swap idiom pattern
+  detection. The checker now properly recognizes copy-and-swap implementations
+  that use "extended" copy/move constructors.

negativ wrote:

Fixed

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


[clang] [llvm] [llvm-objcopy][libObject] Add RISC-V big-endian support (PR #146913)

2025-07-14 Thread James Henderson via cfe-commits


@@ -48,62 +48,64 @@ class Triple {
   enum ArchType {
 UnknownArch,
 
-arm,// ARM (little endian): arm, armv.*, xscale
-armeb,  // ARM (big endian): armeb
-aarch64,// AArch64 (little endian): aarch64
-aarch64_be, // AArch64 (big endian): aarch64_be
-aarch64_32, // AArch64 (little endian) ILP32: aarch64_32
-arc,// ARC: Synopsys ARC
-avr,// AVR: Atmel AVR microcontroller
-bpfel,  // eBPF or extended BPF or 64-bit BPF (little endian)
-bpfeb,  // eBPF or extended BPF or 64-bit BPF (big endian)
-csky,   // CSKY: csky
-dxil,   // DXIL 32-bit DirectX bytecode
-hexagon,// Hexagon: hexagon
-loongarch32,// LoongArch (32-bit): loongarch32
-loongarch64,// LoongArch (64-bit): loongarch64
-m68k,   // M68k: Motorola 680x0 family
-mips,   // MIPS: mips, mipsallegrex, mipsr6
-mipsel, // MIPSEL: mipsel, mipsallegrexe, mipsr6el
-mips64, // MIPS64: mips64, mips64r6, mipsn32, mipsn32r6
-mips64el,   // MIPS64EL: mips64el, mips64r6el, mipsn32el, mipsn32r6el
-msp430, // MSP430: msp430
-ppc,// PPC: powerpc
-ppcle,  // PPCLE: powerpc (little endian)
-ppc64,  // PPC64: powerpc64, ppu
-ppc64le,// PPC64LE: powerpc64le
-r600,   // R600: AMD GPUs HD2XXX - HD6XXX
-amdgcn, // AMDGCN: AMD GCN GPUs
-riscv32,// RISC-V (32-bit): riscv32
-riscv64,// RISC-V (64-bit): riscv64
-sparc,  // Sparc: sparc
-sparcv9,// Sparcv9: Sparcv9
-sparcel,// Sparc: (endianness = little). NB: 'Sparcle' is a CPU 
variant
-systemz,// SystemZ: s390x
-tce,// TCE (http://tce.cs.tut.fi/): tce
-tcele,  // TCE little endian (http://tce.cs.tut.fi/): tcele
-thumb,  // Thumb (little endian): thumb, thumbv.*
-thumbeb,// Thumb (big endian): thumbeb
-x86,// X86: i[3-9]86
-x86_64, // X86-64: amd64, x86_64
-xcore,  // XCore: xcore
-xtensa, // Tensilica: Xtensa
-nvptx,  // NVPTX: 32-bit
-nvptx64,// NVPTX: 64-bit
-amdil,  // AMDIL
-amdil64,// AMDIL with 64-bit pointers
-hsail,  // AMD HSAIL
-hsail64,// AMD HSAIL with 64-bit pointers
-spir,   // SPIR: standard portable IR for OpenCL 32-bit version
-spir64, // SPIR: standard portable IR for OpenCL 64-bit version
-spirv,  // SPIR-V with logical memory layout.
-spirv32,// SPIR-V with 32-bit pointers
-spirv64,// SPIR-V with 64-bit pointers
-kalimba,// Kalimba: generic kalimba
-shave,  // SHAVE: Movidius vector VLIW processors
-lanai,  // Lanai: Lanai 32-bit
-wasm32, // WebAssembly with 32-bit pointers
-wasm64, // WebAssembly with 64-bit pointers
+arm, // ARM (little endian): arm, armv.*, xscale
+armeb,   // ARM (big endian): armeb
+aarch64, // AArch64 (little endian): aarch64
+aarch64_be,  // AArch64 (big endian): aarch64_be
+aarch64_32,  // AArch64 (little endian) ILP32: aarch64_32
+arc, // ARC: Synopsys ARC
+avr, // AVR: Atmel AVR microcontroller
+bpfel,   // eBPF or extended BPF or 64-bit BPF (little endian)
+bpfeb,   // eBPF or extended BPF or 64-bit BPF (big endian)
+csky,// CSKY: csky
+dxil,// DXIL 32-bit DirectX bytecode
+hexagon, // Hexagon: hexagon
+loongarch32, // LoongArch (32-bit): loongarch32
+loongarch64, // LoongArch (64-bit): loongarch64
+m68k,// M68k: Motorola 680x0 family
+mips,// MIPS: mips, mipsallegrex, mipsr6
+mipsel,  // MIPSEL: mipsel, mipsallegrexe, mipsr6el
+mips64,  // MIPS64: mips64, mips64r6, mipsn32, mipsn32r6
+mips64el,// MIPS64EL: mips64el, mips64r6el, mipsn32el, mipsn32r6el
+msp430,  // MSP430: msp430
+ppc, // PPC: powerpc
+ppcle,   // PPCLE: powerpc (little endian)
+ppc64,   // PPC64: powerpc64, ppu
+ppc64le, // PPC64LE: powerpc64le
+r600,// R600: AMD GPUs HD2XXX - HD6XXX
+amdgcn,  // AMDGCN: AMD GCN GPUs
+riscv32, // RISC-V (32-bit, little endian): riscv32
+riscv64, // RISC-V (64-bit, little endian): riscv64
+riscv32be,   // RISC-V (32-bit, big endian): riscv32be
+riscv64be,   // RISC-V (64-bit, big endian): riscv64be
+sparc,   // Sparc: sparc
+sparcv9, // Sparcv9: Sparcv9
+sparcel, // Sparc: (endianness = little). NB: 'Sparcle' is a CPU 
variant
+systemz, // SystemZ: s390x
+tce, // TCE (http://tce.cs.tut.fi/): tce
+tcele,   // TCE little endian (http://tce.cs.tut.fi/): tcele
+thumb,   // Thumb (little endian): 

[clang] [LifetimeSafety] Implement dataflow analysis for loan propagation (PR #148065)

2025-07-14 Thread Gábor Horváth via cfe-commits

https://github.com/Xazax-hun approved this pull request.

Some minor things inline, overall looks good to me. 

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


[clang] [LifetimeSafety] Implement dataflow analysis for loan propagation (PR #148065)

2025-07-14 Thread Gábor Horváth via cfe-commits

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


[clang-tools-extra] [clang-tidy] Make `bugprone-unhandled-self-assignment` check more general (PR #147066)

2025-07-14 Thread Andrey Karlov via cfe-commits


@@ -189,6 +189,12 @@ Changes in existing checks
   calls of ``std::string`` constructor with char pointer, start position and
   length parameters.
 
+- Improved :doc:`bugprone-unhandled-self-assignment

negativ wrote:

@EugeneZelenko fixed

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


[clang-tools-extra] [clang-tidy] Make `bugprone-unhandled-self-assignment` check more general (PR #147066)

2025-07-14 Thread Andrey Karlov via cfe-commits

https://github.com/negativ updated 
https://github.com/llvm/llvm-project/pull/147066

>From 950b6dce92eb2a831e7bd7e7ba44b3e8cc354dd4 Mon Sep 17 00:00:00 2001
From: Andrey Karlov 
Date: Fri, 4 Jul 2025 17:13:20 +0300
Subject: [PATCH 1/7] Checking that some kind of constructor is called and
 followed by a `swap`

---
 .../bugprone/UnhandledSelfAssignmentCheck.cpp | 19 ++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git 
a/clang-tools-extra/clang-tidy/bugprone/UnhandledSelfAssignmentCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/UnhandledSelfAssignmentCheck.cpp
index 1f432c4ccc5f0..8307e744a434c 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UnhandledSelfAssignmentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UnhandledSelfAssignmentCheck.cpp
@@ -68,7 +68,23 @@ void 
UnhandledSelfAssignmentCheck::registerMatchers(MatchFinder *Finder) {
   const auto HasNoNestedSelfAssign =
   
cxxMethodDecl(unless(hasDescendant(cxxMemberCallExpr(callee(cxxMethodDecl(
   hasName("operator="), ofClass(equalsBoundNode("class";
-
+  
+  // Checking that some kind of constructor is called and followed by a `swap`:
+  // T& operator=(const T& other) {
+  //T tmp{this->internal_data(), some, other, args};
+  //swap(tmp);
+  //return *this;
+  // }
+  const auto HasCopyAndSwap = cxxMethodDecl(
+  ofClass(cxxRecordDecl(unless(hasAncestor(classTemplateDecl(),
+  hasDescendant(
+  stmt(hasDescendant(
+   varDecl(hasType(cxxRecordDecl(equalsBoundNode("class"
+   .bind("tmp_var")),
+   hasDescendant(callExpr(callee(functionDecl(hasName("swap"))),
+  hasAnyArgument(declRefExpr(to(varDecl(
+  equalsBoundNode("tmp_var"));
+
   DeclarationMatcher AdditionalMatcher = cxxMethodDecl();
   if (WarnOnlyIfThisHasSuspiciousField) {
 // Matcher for standard smart pointers.
@@ -94,6 +110,7 @@ void 
UnhandledSelfAssignmentCheck::registerMatchers(MatchFinder *Finder) {
HasReferenceParam, HasNoSelfCheck,
unless(HasNonTemplateSelfCopy),
unless(HasTemplateSelfCopy),
+   unless(HasCopyAndSwap),
HasNoNestedSelfAssign, AdditionalMatcher)
  .bind("copyAssignmentOperator"),
  this);

>From 0cd33ec49693cfc6f5a72b72a9c50ba868634221 Mon Sep 17 00:00:00 2001
From: Andrey Karlov 
Date: Fri, 4 Jul 2025 17:19:02 +0300
Subject: [PATCH 2/7] Tests

---
 .../bugprone/unhandled-self-assignment.cpp| 90 +++
 1 file changed, 90 insertions(+)

diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unhandled-self-assignment.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unhandled-self-assignment.cpp
index 8610393449f97..f2f61062f883f 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unhandled-self-assignment.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unhandled-self-assignment.cpp
@@ -28,6 +28,13 @@ template 
 class auto_ptr {
 };
 
+namespace pmr {
+template 
+class allocator {};
+}
+
+struct allocator_arg_t {} allocator_arg;
+
 } // namespace std
 
 void assert(int expression){};
@@ -540,6 +547,89 @@ class NotACopyAssignmentOperator {
   Uy *getUy() const { return Ptr2; }
 };
 
+// Support "extended" copy/move constructors
+class AllocatorAwareClass {
+  // pointer member to trigger bugprone-unhandled-self-assignment
+  void *foo = nullptr;
+
+  public:
+using allocator_type = std::pmr::allocator<>;
+
+AllocatorAwareClass(const AllocatorAwareClass& other) {
+}
+
+AllocatorAwareClass(const AllocatorAwareClass& other, const 
allocator_type& alloc) {
+}
+
+AllocatorAwareClass& operator=(const AllocatorAwareClass& other) {
+AllocatorAwareClass tmp(other, get_allocator());
+swap(tmp);
+return *this;
+}
+
+void swap(AllocatorAwareClass& other) noexcept {
+}
+
+allocator_type get_allocator() const {
+return allocator_type();
+}
+};
+
+// Support "extended" copy/move constructors + std::swap
+class AllocatorAwareClassStdSwap {
+  // pointer member to trigger bugprone-unhandled-self-assignment
+  void *foo = nullptr;
+
+  public:
+using allocator_type = std::pmr::allocator<>;
+
+AllocatorAwareClassStdSwap(const AllocatorAwareClassStdSwap& other) {
+}
+
+AllocatorAwareClassStdSwap(const AllocatorAwareClassStdSwap& other, const 
allocator_type& alloc) {
+}
+
+AllocatorAwareClassStdSwap& operator=(const AllocatorAwareClassStdSwap& 
other) {
+using std::swap;
+
+AllocatorAwareClassStdSwap tmp(other, get_allocator());
+swap(*this, tmp);
+return *this;
+}
+
+allocator_type get_allocator() const {
+re

[clang] [win][clang] Align scalar deleting destructors with MSABI (PR #139566)

2025-07-14 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

ping @tahonermann 

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


[clang] [llvm] [AVR] Handle flash RO data mapped to data space for newer devices (PR #146244)

2025-07-14 Thread Tom Vijlbrief via cfe-commits

tomtor wrote:

I removed the new flags, these can be simulated with `-T` and other linker 
flags by a user.

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


[clang] [Clang] Do not emit -Wmissing-noreturn when [[noreturn]] is present (PR #148552)

2025-07-14 Thread Aaron Ballman via cfe-commits

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

LGTM! Thank you for the fix!

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


[clang] [llvm] [RISCV] Add Andes XAndesBFHCvt (Andes Scalar BFLOAT16) extension (PR #148563)

2025-07-14 Thread Pengcheng Wang via cfe-commits

https://github.com/wangpc-pp approved this pull request.

LGTM.

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


[clang] [llvm] [AVR] Handle flash RO data mapped to data space for newer devices (PR #146244)

2025-07-14 Thread Tom Vijlbrief via cfe-commits

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


[clang] [WIP][DO NOT MERGE][Clang][Driver] Emit warning when -fsanitize-trap=<...> is passed without associated -fsanitize=<...> (PR #147997)

2025-07-14 Thread Anthony Tran via cfe-commits

https://github.com/anthonyhatran updated 
https://github.com/llvm/llvm-project/pull/147997

>From eadf3e52072fbae01e8de8f7f59883aec1b2c9bc Mon Sep 17 00:00:00 2001
From: Anthony Tran 
Date: Thu, 10 Jul 2025 09:18:50 -0700
Subject: [PATCH 1/6] Added warning and warning group for sanitizer argument
 mismatch

---
 clang/include/clang/Basic/DiagnosticDriverKinds.td | 5 +
 clang/include/clang/Basic/DiagnosticGroups.td  | 3 +++
 2 files changed, 8 insertions(+)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 34b6c0d7a8acd..49a8bdf06bda4 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -874,4 +874,9 @@ def warn_drv_openacc_without_cir
 : Warning<"OpenACC directives will result in no runtime behavior; use "
   "-fclangir to enable runtime effect">,
   InGroup;
+
+def warn_drv_sanitize_trap_mismatch : Warning<
+  "-fsanitize-trap=%0 has no effect because the matching sanitizer is not 
enabled; "
+  "did you mean to pass \"-fsanitize=%0\" as well?">,
+  InGroup;
 }
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index f54a830b0103e..a79562cd9c2e0 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1752,3 +1752,6 @@ def ExplicitSpecializationStorageClass : 
DiagGroup<"explicit-specialization-stor
 
 // A warning for options that enable a feature that is not yet complete
 def ExperimentalOption : DiagGroup<"experimental-option">;
+
+// Warnings for sanitizer arguments
+def SanitizeTrapMismatch : DiagGroup<"sanitize-trap-mismatch">;

>From f1bf9b34daca5d23d1a3f518847f3ccbc8f069a7 Mon Sep 17 00:00:00 2001
From: Anthony Tran 
Date: Thu, 10 Jul 2025 13:35:52 -0700
Subject: [PATCH 2/6] Emit warning and parse mismatched arguments

---
 clang/lib/Driver/SanitizerArgs.cpp | 36 ++
 1 file changed, 36 insertions(+)

diff --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index 4bd61c2f8deef..8b78d850e0018 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -348,6 +348,30 @@ parseSanitizeSkipHotCutoffArgs(const Driver &D, const 
llvm::opt::ArgList &Args,
   return Cutoffs;
 }
 
+// Given a set of mismatched bits, TrapOnly (bits the user asked to trap but
+// that aren’t actually enabled), emit a warning based on -fsanitize-trap=NAME
+static void diagnoseTrapOnly(const Driver &D, SanitizerMask &TrapOnly) {
+// Double pass: one for sanitizer groupings, one for leaves (ex: undefined vs.
+// signed-integer-overflow)
+#define SANITIZER(NAME, ID)
+#define SANITIZER_GROUP(NAME, ID, ALIAS)   
\
+  if (TrapOnly & SanitizerKind::ID##Group) {   
\
+D.Diag(diag::warn_drv_sanitize_trap_mismatch) << NAME; 
\
+TrapOnly &= ~SanitizerKind::ID##Group; 
\
+TrapOnly &= ~SanitizerKind::ID;
\
+  }
+#include "clang/Basic/Sanitizers.def"
+
+#undef SANITIZER_GROUP
+#define SANITIZER_GROUP(NAME, ID, ALIAS)
+#define SANITIZER(NAME, ID)
\
+  if (TrapOnly & SanitizerKind::ID) {  
\
+D.Diag(diag::warn_drv_sanitize_trap_mismatch) << NAME; 
\
+TrapOnly &= ~SanitizerKind::ID;
\
+  }
+#include "clang/Basic/Sanitizers.def"
+}
+
 bool SanitizerArgs::needsFuzzerInterceptors() const {
   return needsFuzzer() && !needsAsanRt() && !needsTsanRt() && !needsMsanRt();
 }
@@ -730,6 +754,18 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
   options::OPT_fno_sanitize_recover_EQ);
   RecoverableKinds &= Kinds;
 
+  // Parse any -fsanitize-trap=<...> flags the user provided, then
+  // diagnose any which do not have a matching -fsanitize=<...>
+  if (DiagnoseErrors) {
+SanitizerMask ExplicitTrap = parseSanitizeArgs(
+D, Args, false, {}, {}, {}, options::OPT_fsanitize_trap_EQ,
+options::OPT_fno_sanitize_trap_EQ);
+SanitizerMask TrapOnly = ExplicitTrap & ~Kinds;
+
+if (TrapOnly)
+  diagnoseTrapOnly(D, TrapOnly);
+  }
+
   TrappingKinds &= Kinds;
   RecoverableKinds &= ~TrappingKinds;
 

>From c7b44099357ee78329f6e289ef6feb321b9b121c Mon Sep 17 00:00:00 2001
From: Anthony Tran 
Date: Mon, 14 Jul 2025 03:36:11 -0700
Subject: [PATCH 3/6] Modify warning message

---
 clang/include/clang/Basic/DiagnosticDriverKinds.td | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 49a8bdf06bda4..f2a0582a364bf 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/cl

[clang] [clang][CodeGen] Fix metadata when vectorization is disabled by pragma (PR #135163)

2025-07-14 Thread Michael Kruse via cfe-commits

Meinersbur wrote:

> I think there are two possible interpretations of `vectorize(disable) 
> vectorize_width(scalable)`, as follows:
> 
> * It is equivalent to `vectorize(disable)` so vectorization is disabled, as 
> the document says:
>   > Pragmas setting transformation options imply the transformation is 
> enabled, as if it was enabled via the corresponding transformation pragma 
> (e.g. `vectorize(enable)`). If the transformation is disabled (e.g. 
> `vectorize(disable)`), that takes precedence over transformations option 
> pragmas implying that transformation..

This seems to be the more logical interpretation. Like `unroll(disable) 
unroll_count(5)` which wold also not unroll loops.

> * Since `vectorize(disable)` is equivalent to `vectorize_width(1)`, it is 
> equivalent to `vectorize_width(1, scalable)` so that vectorization should be 
> performed [as previously 
> commented](https://github.com/llvm/llvm-project/pull/135163#discussion_r2037236948).

That `llvm.loop.vectorize.width==1` disables vectorization is just a quirk of 
how the metadata evolved. It should not leak into the user-visible semantics.

If you prefer, you can also clean up the metata and introduce a separate 
`llvm.loop.interleave.enable`. 

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


[clang] [clang] Build argument string for clang::warn_unused_result (PR #148090)

2025-07-14 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> Thanks for the suggestions Aaron, applied them both and refreshed the branch 
> (it doesn't stay fresh for long it seems 😄)
> 
> When it comes to `[[gnu::`, options seems to be
> 
> * Leave as-is, no change: no error, no warning but string is dropped
> 
> * Align with GCC and error on passing a string: we would break existing 
> code as they pass just fine now with a string in, it's just ignored.
> 
> * Keep and display the string (with or without additional warning): 
> Decent user experience, and does not introduce breakage
> 
> 
> Let me know where you stand

I think we're good with the current behavior in your patch. I'll land the 
changes when CI comes back green. We can decide later if we want to do 
something about the `gnu` spelling.

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


[clang] [clang-tools-extra] [Clang] [Diagnostics] Simplify filenames that contain '..' (PR #143520)

2025-07-14 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

I think the new plan forward makes sense. But also: thank you to everyone on 
this thread for the excellent collaboration on identifying an issue, getting 
the previous incarnation reverted, and discussing a good path forward. :-)

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


[clang] [clang] Build argument string for clang::warn_unused_result (PR #148090)

2025-07-14 Thread via cfe-commits

https://github.com/zebullax updated 
https://github.com/llvm/llvm-project/pull/148090

>From 11909560ed6cb4e56192fbbfe4d8b1cdf58e1cb1 Mon Sep 17 00:00:00 2001
From: zebullax 
Date: Fri, 11 Jul 2025 09:12:44 +0900
Subject: [PATCH 1/9] Build argument string for clang::warn_unused_result

Preserve the argument-clause for `warn-unused-result` when under clang:: scope.
We are not touching gnu:: scope for now as it's an error for GCC to have that 
string. Personally I think it would be ok to relax it here too as we are not 
introducing breakage to currently passing code, but feedback is to go slowly 
about it.
---
 clang/lib/Sema/SemaDeclAttr.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 7ebb53318702c..221197b3849e0 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -2902,7 +2902,8 @@ static void handleWarnUnusedResult(Sema &S, Decl *D, 
const ParsedAttr &AL) {
 }
 
   StringRef Str;
-  if (AL.isStandardAttributeSyntax() && !AL.getScopeName()) {
+  if (AL.isStandardAttributeSyntax()
+  && (!AL.getScopeName() || AL.isClangScope())) {
 // The standard attribute cannot be applied to variable declarations such
 // as a function pointer.
 if (isa(D))

>From 7d1b223472514fa09574fb4ee49518f912353494 Mon Sep 17 00:00:00 2001
From: zebullax 
Date: Fri, 11 Jul 2025 15:51:22 +0900
Subject: [PATCH 2/9] Add unit test to check reason string on clang scope

Signed-off-by: zebullax 

Fix scope in UT

Signed-off-by: zebullax 

Fix UT

Signed-off-by: zebullax 

Remove warn on attaching clang scoped to var decl

Signed-off-by: zebullax 

Fix EOL

Signed-off-by: zebullax 
---
 clang/lib/Sema/SemaDeclAttr.cpp   |  2 +-
 clang/test/SemaCXX/warn-unused-result.cpp | 18 ++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 221197b3849e0..c9822369e8652 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -2906,7 +2906,7 @@ static void handleWarnUnusedResult(Sema &S, Decl *D, 
const ParsedAttr &AL) {
   && (!AL.getScopeName() || AL.isClangScope())) {
 // The standard attribute cannot be applied to variable declarations such
 // as a function pointer.
-if (isa(D))
+if (!AL.isClangScope() && isa(D))
   S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type)
   << AL << AL.isRegularKeywordAttribute()
   << ExpectedFunctionOrClassOrEnum;
diff --git a/clang/test/SemaCXX/warn-unused-result.cpp 
b/clang/test/SemaCXX/warn-unused-result.cpp
index fa7540c116e67..fe7d5ea79e9a7 100644
--- a/clang/test/SemaCXX/warn-unused-result.cpp
+++ b/clang/test/SemaCXX/warn-unused-result.cpp
@@ -364,3 +364,21 @@ void id_print_name() {
 ((int(*)())f)();
 }
 } // namespace GH117975
+
+namespace BuildStringOnClangScope {
+
+[[clang::warn_unused_result("Discarded result")]]
+bool makeClangTrue() { return true; }
+
+[[gnu::warn_unused_result("Discarded result")]]
+bool makeGccTrue() { return true; }
+
+void doClangThings() {
+  makeClangTrue(); // expected-warning {{ignoring return value of function 
declared with 'clang::warn_unused_result' attribute: Discarded result}}
+}
+
+void doGccThings() {
+  makeGccTrue(); // expected-warning {{ignoring return value of function 
declared with 'gnu::warn_unused_result' attribute}}
+}
+
+}

>From b110d634b6b64b8d96d63e0a43e3283809e46af0 Mon Sep 17 00:00:00 2001
From: zebullax 
Date: Fri, 11 Jul 2025 18:02:53 +0900
Subject: [PATCH 3/9] Update release notes

Signed-off-by: zebullax 
---
 clang/docs/ReleaseNotes.rst | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9e16613826a77..7797b14e49f55 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -464,6 +464,9 @@ related warnings within the method body.
 - Clang now disallows the use of attributes applied before an
   ``extern template`` declaration (#GH79893).
 
+- Clang will print the "reason" string argument passed on to
+  `[[clang::warn_unused_result("reason")]]` as part of the warning diagnostic
+
 Improvements to Clang's diagnostics
 ---
 

>From 0cbcc955ccc9d9be8e15cbc094a8eaa3235e0bfd Mon Sep 17 00:00:00 2001
From: zebullax 
Date: Fri, 11 Jul 2025 20:36:53 +0900
Subject: [PATCH 4/9] Update clang/docs/ReleaseNotes.rst

Co-authored-by: Aaron Ballman 
---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7797b14e49f55..edad96c15ca9f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -465,7 +465,7 @@ related warnings within the method body.
   ``extern template`` declaration (#GH79893).
 
 - Clang will print the "reason" string argument passed on to
-  `[[clang::warn_unused_result

[clang] [clang] Build argument string for clang::warn_unused_result (PR #148090)

2025-07-14 Thread via cfe-commits

https://github.com/zebullax updated 
https://github.com/llvm/llvm-project/pull/148090

>From 11909560ed6cb4e56192fbbfe4d8b1cdf58e1cb1 Mon Sep 17 00:00:00 2001
From: zebullax 
Date: Fri, 11 Jul 2025 09:12:44 +0900
Subject: [PATCH 1/9] Build argument string for clang::warn_unused_result

Preserve the argument-clause for `warn-unused-result` when under clang:: scope.
We are not touching gnu:: scope for now as it's an error for GCC to have that 
string. Personally I think it would be ok to relax it here too as we are not 
introducing breakage to currently passing code, but feedback is to go slowly 
about it.
---
 clang/lib/Sema/SemaDeclAttr.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 7ebb53318702c..221197b3849e0 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -2902,7 +2902,8 @@ static void handleWarnUnusedResult(Sema &S, Decl *D, 
const ParsedAttr &AL) {
 }
 
   StringRef Str;
-  if (AL.isStandardAttributeSyntax() && !AL.getScopeName()) {
+  if (AL.isStandardAttributeSyntax()
+  && (!AL.getScopeName() || AL.isClangScope())) {
 // The standard attribute cannot be applied to variable declarations such
 // as a function pointer.
 if (isa(D))

>From 7d1b223472514fa09574fb4ee49518f912353494 Mon Sep 17 00:00:00 2001
From: zebullax 
Date: Fri, 11 Jul 2025 15:51:22 +0900
Subject: [PATCH 2/9] Add unit test to check reason string on clang scope

Signed-off-by: zebullax 

Fix scope in UT

Signed-off-by: zebullax 

Fix UT

Signed-off-by: zebullax 

Remove warn on attaching clang scoped to var decl

Signed-off-by: zebullax 

Fix EOL

Signed-off-by: zebullax 
---
 clang/lib/Sema/SemaDeclAttr.cpp   |  2 +-
 clang/test/SemaCXX/warn-unused-result.cpp | 18 ++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 221197b3849e0..c9822369e8652 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -2906,7 +2906,7 @@ static void handleWarnUnusedResult(Sema &S, Decl *D, 
const ParsedAttr &AL) {
   && (!AL.getScopeName() || AL.isClangScope())) {
 // The standard attribute cannot be applied to variable declarations such
 // as a function pointer.
-if (isa(D))
+if (!AL.isClangScope() && isa(D))
   S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type)
   << AL << AL.isRegularKeywordAttribute()
   << ExpectedFunctionOrClassOrEnum;
diff --git a/clang/test/SemaCXX/warn-unused-result.cpp 
b/clang/test/SemaCXX/warn-unused-result.cpp
index fa7540c116e67..fe7d5ea79e9a7 100644
--- a/clang/test/SemaCXX/warn-unused-result.cpp
+++ b/clang/test/SemaCXX/warn-unused-result.cpp
@@ -364,3 +364,21 @@ void id_print_name() {
 ((int(*)())f)();
 }
 } // namespace GH117975
+
+namespace BuildStringOnClangScope {
+
+[[clang::warn_unused_result("Discarded result")]]
+bool makeClangTrue() { return true; }
+
+[[gnu::warn_unused_result("Discarded result")]]
+bool makeGccTrue() { return true; }
+
+void doClangThings() {
+  makeClangTrue(); // expected-warning {{ignoring return value of function 
declared with 'clang::warn_unused_result' attribute: Discarded result}}
+}
+
+void doGccThings() {
+  makeGccTrue(); // expected-warning {{ignoring return value of function 
declared with 'gnu::warn_unused_result' attribute}}
+}
+
+}

>From b110d634b6b64b8d96d63e0a43e3283809e46af0 Mon Sep 17 00:00:00 2001
From: zebullax 
Date: Fri, 11 Jul 2025 18:02:53 +0900
Subject: [PATCH 3/9] Update release notes

Signed-off-by: zebullax 
---
 clang/docs/ReleaseNotes.rst | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9e16613826a77..7797b14e49f55 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -464,6 +464,9 @@ related warnings within the method body.
 - Clang now disallows the use of attributes applied before an
   ``extern template`` declaration (#GH79893).
 
+- Clang will print the "reason" string argument passed on to
+  `[[clang::warn_unused_result("reason")]]` as part of the warning diagnostic
+
 Improvements to Clang's diagnostics
 ---
 

>From 0cbcc955ccc9d9be8e15cbc094a8eaa3235e0bfd Mon Sep 17 00:00:00 2001
From: zebullax 
Date: Fri, 11 Jul 2025 20:36:53 +0900
Subject: [PATCH 4/9] Update clang/docs/ReleaseNotes.rst

Co-authored-by: Aaron Ballman 
---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7797b14e49f55..edad96c15ca9f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -465,7 +465,7 @@ related warnings within the method body.
   ``extern template`` declaration (#GH79893).
 
 - Clang will print the "reason" string argument passed on to
-  `[[clang::warn_unused_result

[clang] [llvm] [AVR] Handle flash RO data mapped to data space for newer devices (PR #146244)

2025-07-14 Thread Tom Vijlbrief via cfe-commits

tomtor wrote:

I did not request a review from code owners? Did I hit a button by accident?

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


[clang] afffa0d - [Clang] Do not emit -Wmissing-noreturn when [[noreturn]] is present (#148552)

2025-07-14 Thread via cfe-commits

Author: Corentin Jabot
Date: 2025-07-14T14:20:00+02:00
New Revision: afffa0d334bf33c89f1f921ef950e14744e0f0e4

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

LOG: [Clang] Do not emit -Wmissing-noreturn when [[noreturn]] is present 
(#148552)

Fix a false positve warning which was introduced by #146234.

Added: 


Modified: 
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/SemaCXX/wmissing-noreturn-suggestion.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 099207727c8c8..60a9aee2d41e7 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -1976,7 +1976,7 @@ void clang::inferNoReturnAttr(Sema &S, const Decl *D) {
   Diags.isIgnored(diag::warn_suggest_noreturn_function, FD->getLocation()))
 return;
 
-  if (!FD->hasAttr() && !FD->hasAttr() &&
+  if (!FD->isNoReturn() && !FD->hasAttr() &&
   isKnownToAlwaysThrow(FD)) {
 NonConstFD->addAttr(InferredNoReturnAttr::CreateImplicit(S.Context));
 

diff  --git a/clang/test/SemaCXX/wmissing-noreturn-suggestion.cpp 
b/clang/test/SemaCXX/wmissing-noreturn-suggestion.cpp
index 7548ba8904a71..8beffcd39e85c 100644
--- a/clang/test/SemaCXX/wmissing-noreturn-suggestion.cpp
+++ b/clang/test/SemaCXX/wmissing-noreturn-suggestion.cpp
@@ -21,3 +21,25 @@ int ensureZero(int i) {
   if (i == 0) return 0;
   throwError("ERROR"); // no-warning
 }
+
+
+template 
+[[noreturn]]
+void tpl_throws(Ex const& e) {
+throw e;
+}
+
+[[noreturn]]
+void tpl_throws_test() {
+tpl_throws(0);
+}
+
+[[gnu::noreturn]]
+int gnu_throws() {
+throw 0;
+}
+
+[[noreturn]]
+int cxx11_throws() {
+throw 0;
+}



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


[clang] [Clang] Do not emit -Wmissing-noreturn when [[noreturn]] is present (PR #148552)

2025-07-14 Thread Corentin Jabot via cfe-commits

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


[clang] [clang] Build argument string for clang::warn_unused_result (PR #148090)

2025-07-14 Thread via cfe-commits

zebullax wrote:

Ok, fixed the formatting issues from a suggestion, and rebased.
GTG

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


[clang-tools-extra] [clang-tidy] Add new check: `readability-use-concise-preprocessor-directives` (PR #146830)

2025-07-14 Thread Baranov Victor via cfe-commits

vbvictor wrote:

> A LLVM syncbot commit turned our buildbot red: 
> https://lab.llvm.org/buildbot/#/builders/123/builds/23254
> 
> The syncbot commit links to this PR. [edit] On a second look it looks more 
> like an infra issue on our end, I'll investigate. [/edit]

Hi! Any logs/errors that are related to this PR should have `clang-tidy` in 
them at some point. Whether it's a file path or some command-run.


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


[clang] [llvm] [llvm-objcopy][libObject] Add RISC-V big-endian support (PR #146913)

2025-07-14 Thread Djordje Todorovic via cfe-commits


@@ -48,62 +48,64 @@ class Triple {
   enum ArchType {
 UnknownArch,
 
-arm,// ARM (little endian): arm, armv.*, xscale
-armeb,  // ARM (big endian): armeb
-aarch64,// AArch64 (little endian): aarch64
-aarch64_be, // AArch64 (big endian): aarch64_be
-aarch64_32, // AArch64 (little endian) ILP32: aarch64_32
-arc,// ARC: Synopsys ARC
-avr,// AVR: Atmel AVR microcontroller
-bpfel,  // eBPF or extended BPF or 64-bit BPF (little endian)
-bpfeb,  // eBPF or extended BPF or 64-bit BPF (big endian)
-csky,   // CSKY: csky
-dxil,   // DXIL 32-bit DirectX bytecode
-hexagon,// Hexagon: hexagon
-loongarch32,// LoongArch (32-bit): loongarch32
-loongarch64,// LoongArch (64-bit): loongarch64
-m68k,   // M68k: Motorola 680x0 family
-mips,   // MIPS: mips, mipsallegrex, mipsr6
-mipsel, // MIPSEL: mipsel, mipsallegrexe, mipsr6el
-mips64, // MIPS64: mips64, mips64r6, mipsn32, mipsn32r6
-mips64el,   // MIPS64EL: mips64el, mips64r6el, mipsn32el, mipsn32r6el
-msp430, // MSP430: msp430
-ppc,// PPC: powerpc
-ppcle,  // PPCLE: powerpc (little endian)
-ppc64,  // PPC64: powerpc64, ppu
-ppc64le,// PPC64LE: powerpc64le
-r600,   // R600: AMD GPUs HD2XXX - HD6XXX
-amdgcn, // AMDGCN: AMD GCN GPUs
-riscv32,// RISC-V (32-bit): riscv32
-riscv64,// RISC-V (64-bit): riscv64
-sparc,  // Sparc: sparc
-sparcv9,// Sparcv9: Sparcv9
-sparcel,// Sparc: (endianness = little). NB: 'Sparcle' is a CPU 
variant
-systemz,// SystemZ: s390x
-tce,// TCE (http://tce.cs.tut.fi/): tce
-tcele,  // TCE little endian (http://tce.cs.tut.fi/): tcele
-thumb,  // Thumb (little endian): thumb, thumbv.*
-thumbeb,// Thumb (big endian): thumbeb
-x86,// X86: i[3-9]86
-x86_64, // X86-64: amd64, x86_64
-xcore,  // XCore: xcore
-xtensa, // Tensilica: Xtensa
-nvptx,  // NVPTX: 32-bit
-nvptx64,// NVPTX: 64-bit
-amdil,  // AMDIL
-amdil64,// AMDIL with 64-bit pointers
-hsail,  // AMD HSAIL
-hsail64,// AMD HSAIL with 64-bit pointers
-spir,   // SPIR: standard portable IR for OpenCL 32-bit version
-spir64, // SPIR: standard portable IR for OpenCL 64-bit version
-spirv,  // SPIR-V with logical memory layout.
-spirv32,// SPIR-V with 32-bit pointers
-spirv64,// SPIR-V with 64-bit pointers
-kalimba,// Kalimba: generic kalimba
-shave,  // SHAVE: Movidius vector VLIW processors
-lanai,  // Lanai: Lanai 32-bit
-wasm32, // WebAssembly with 32-bit pointers
-wasm64, // WebAssembly with 64-bit pointers
+arm, // ARM (little endian): arm, armv.*, xscale
+armeb,   // ARM (big endian): armeb
+aarch64, // AArch64 (little endian): aarch64
+aarch64_be,  // AArch64 (big endian): aarch64_be
+aarch64_32,  // AArch64 (little endian) ILP32: aarch64_32
+arc, // ARC: Synopsys ARC
+avr, // AVR: Atmel AVR microcontroller
+bpfel,   // eBPF or extended BPF or 64-bit BPF (little endian)
+bpfeb,   // eBPF or extended BPF or 64-bit BPF (big endian)
+csky,// CSKY: csky
+dxil,// DXIL 32-bit DirectX bytecode
+hexagon, // Hexagon: hexagon
+loongarch32, // LoongArch (32-bit): loongarch32
+loongarch64, // LoongArch (64-bit): loongarch64
+m68k,// M68k: Motorola 680x0 family
+mips,// MIPS: mips, mipsallegrex, mipsr6
+mipsel,  // MIPSEL: mipsel, mipsallegrexe, mipsr6el
+mips64,  // MIPS64: mips64, mips64r6, mipsn32, mipsn32r6
+mips64el,// MIPS64EL: mips64el, mips64r6el, mipsn32el, mipsn32r6el
+msp430,  // MSP430: msp430
+ppc, // PPC: powerpc
+ppcle,   // PPCLE: powerpc (little endian)
+ppc64,   // PPC64: powerpc64, ppu
+ppc64le, // PPC64LE: powerpc64le
+r600,// R600: AMD GPUs HD2XXX - HD6XXX
+amdgcn,  // AMDGCN: AMD GCN GPUs
+riscv32, // RISC-V (32-bit, little endian): riscv32
+riscv64, // RISC-V (64-bit, little endian): riscv64
+riscv32be,   // RISC-V (32-bit, big endian): riscv32be
+riscv64be,   // RISC-V (64-bit, big endian): riscv64be
+sparc,   // Sparc: sparc
+sparcv9, // Sparcv9: Sparcv9
+sparcel, // Sparc: (endianness = little). NB: 'Sparcle' is a CPU 
variant
+systemz, // SystemZ: s390x
+tce, // TCE (http://tce.cs.tut.fi/): tce
+tcele,   // TCE little endian (http://tce.cs.tut.fi/): tcele
+thumb,   // Thumb (little endian): 

[clang-tools-extra] [clang-tidy][NFC] Enable 'performance-move-const-arg' in '.clang-tidy' config (PR #148549)

2025-07-14 Thread Carlos Galvez via cfe-commits

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

LGTM!

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


[clang] [CIR][NFC] Resolve various nits for builtin bit operations (PR #148378)

2025-07-14 Thread Henrich Lauko via cfe-commits

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

lgtm, please apply these changes to incubator as well

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


[clang] [CIR][NFC] Resolve various nits for builtin bit operations (PR #148378)

2025-07-14 Thread Henrich Lauko via cfe-commits

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


[clang] [llvm] [AVR] Handle flash RO data mapped to data space for newer devices (PR #146244)

2025-07-14 Thread Tom Vijlbrief via cfe-commits

https://github.com/tomtor updated 
https://github.com/llvm/llvm-project/pull/146244

>From 137c1824febc34b1e34b5b35fc7eefc073eec6fa Mon Sep 17 00:00:00 2001
From: Tom Vijlbrief 
Date: Fri, 27 Jun 2025 17:16:35 +0200
Subject: [PATCH 01/11] [AVR] Handle mapped RO data for newer devices

---
 clang/include/clang/Driver/Options.td |  4 ++
 clang/lib/Basic/Targets/AVR.cpp   |  6 +++
 clang/lib/Driver/ToolChains/AVR.cpp   | 15 ++-
 llvm/lib/Target/AVR/AVRAsmPrinter.cpp | 14 +--
 llvm/lib/Target/AVR/AVRDevices.td | 56 ---
 5 files changed, 67 insertions(+), 28 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2e070d6d64508..95ccdeadf5bfd 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4930,6 +4930,10 @@ def mguard_EQ : Joined<["-"], "mguard=">, Group,
   HelpText<"Enable or disable Control Flow Guard checks and guard tables 
emission">,
   Values<"none,cf,cf-nochecks">;
 def mmcu_EQ : Joined<["-"], "mmcu=">, Group;
+def mflmap : Flag<["-"], "mflmap">, Group,
+  HelpText<"Use AVR mapped memory for RO data">;
+def mrodata_in_ram : Flag<["-"], "mrodata-in-ram">, Group,
+  HelpText<"Copy RO data to ram">;
 def msim : Flag<["-"], "msim">, Group;
 def mfix_and_continue : Flag<["-"], "mfix-and-continue">, 
Group;
 def mieee_fp : Flag<["-"], "mieee-fp">, Group;
diff --git a/clang/lib/Basic/Targets/AVR.cpp b/clang/lib/Basic/Targets/AVR.cpp
index bbe7b01ca036d..4a36bf9cdb132 100644
--- a/clang/lib/Basic/Targets/AVR.cpp
+++ b/clang/lib/Basic/Targets/AVR.cpp
@@ -418,6 +418,10 @@ static MCUInfo AVRMcus[] = {
 } // namespace targets
 } // namespace clang
 
+static bool ArchHasFLMAP(StringRef Name) {
+  return Name.starts_with("avr64") || Name.starts_with("avr128");
+}
+
 static bool ArchHasELPM(StringRef Arch) {
   return llvm::StringSwitch(Arch)
 .Cases("31", "51", "6", true)
@@ -529,6 +533,8 @@ void AVRTargetInfo::getTargetDefines(const LangOptions 
&Opts,
   Builder.defineMacro("__AVR_ARCH__", Arch);
 
   // TODO: perhaps we should use the information from AVRDevices.td instead?
+  if (ArchHasFLMAP(DefineName))
+Builder.defineMacro("__AVR_HAVE_FLMAP__");
   if (ArchHasELPM(Arch))
 Builder.defineMacro("__AVR_HAVE_ELPM__");
   if (ArchHasELPMX(Arch))
diff --git a/clang/lib/Driver/ToolChains/AVR.cpp 
b/clang/lib/Driver/ToolChains/AVR.cpp
index 731076d9754a9..645f9214f091f 100644
--- a/clang/lib/Driver/ToolChains/AVR.cpp
+++ b/clang/lib/Driver/ToolChains/AVR.cpp
@@ -651,8 +651,19 @@ void AVR::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   // This is almost always required because otherwise avr-ld
   // will assume 'avr2' and warn about the program being larger
   // than the bare minimum supports.
-  if (Linker.find("avr-ld") != std::string::npos && FamilyName)
-CmdArgs.push_back(Args.MakeArgString(std::string("-m") + *FamilyName));
+  if (Linker.find("avr-ld") != std::string::npos && FamilyName) {
+// Option to use mapped memory for modern devices with >32kB flash.
+// This is the only option for modern devices with <= 32kB flash,
+// but the larger default to a copy from flash to RAM (avr-ld version < 14)
+// or map the highest 32kB to RAM (avr-ld version >= 14).
+if (Args.hasFlag(options::OPT_mflmap, options::OPT_mrodata_in_ram, false)) 
{
+  CmdArgs.push_back(
+  Args.MakeArgString(std::string("-m") + *FamilyName + "_flmap"));
+  CmdArgs.push_back(Args.MakeArgString(std::string("-u")));
+  CmdArgs.push_back(Args.MakeArgString(std::string("__do_flmap_init")));
+} else
+  CmdArgs.push_back(Args.MakeArgString(std::string("-m") + *FamilyName));
+  }
 
   C.addCommand(std::make_unique(
   JA, *this, ResponseFileSupport::AtFileCurCP(), 
Args.MakeArgString(Linker),
diff --git a/llvm/lib/Target/AVR/AVRAsmPrinter.cpp 
b/llvm/lib/Target/AVR/AVRAsmPrinter.cpp
index ad8aa5717fb42..decfcc4b67f5d 100644
--- a/llvm/lib/Target/AVR/AVRAsmPrinter.cpp
+++ b/llvm/lib/Target/AVR/AVRAsmPrinter.cpp
@@ -263,11 +263,17 @@ bool AVRAsmPrinter::doFinalization(Module &M) {
 auto *Section = cast(TLOF.SectionForGlobal(&GO, TM));
 if (Section->getName().starts_with(".data"))
   NeedsCopyData = true;
-else if (Section->getName().starts_with(".rodata") && SubTM->hasLPM())
+else if (Section->getName().starts_with(".rodata") && SubTM->hasLPM()) {
   // AVRs that have a separate program memory (that's most AVRs) store
-  // .rodata sections in RAM.
-  NeedsCopyData = true;
-else if (Section->getName().starts_with(".bss"))
+  // .rodata sections in RAM,
+  // but XMEGA3 family maps all flash in the data space.
+  // Invoking __do_copy_data with 0 bytes to copy will crash,
+  // so we let the loader handle this for newer devices.
+  if (!(SubTM->hasFeatureSetFamilyXMEGA2() ||
+SubTM->hasFeatureSetFamilyXMEGA3() ||
+SubTM->hasFeatureSetFamilyXMEGA4()))

[clang] [flang] [llvm] [openmp] [Clang][OpenMP][LoopTransformations] Add support for "#pragma omp fuse" loop transformation directive and "looprange" clause (PR #139293)

2025-07-14 Thread Roger Ferrer Ibáñez via cfe-commits

rofirrim wrote:

Hi all, @eZWALT is changing jobs and kindly asked me if I could finish on his 
behalf. I plan to go through all the items of feedback and then rebase against 
main.

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


[clang] [Clang] Do not treat Foo -> const Foo conversion sequences as perfect (PR #148613)

2025-07-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Corentin Jabot (cor3ntin)


Changes

For implicit object arguments.
This fixes a regression introduced by the "perfect match" overload resolusion 
mechanism introduced in #8c5a307.

Note that GCC allows the ambiguity between a const and non-const candidate to 
be resolved. But this patch focuses on restoring the Clang 20 behavior, and to 
fix the cases which we did resolve incorrectly.

Fixes #147374

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


3 Files Affected:

- (modified) clang/include/clang/Sema/Overload.h (+9-3) 
- (modified) clang/lib/Sema/SemaOverload.cpp (+17-5) 
- (modified) clang/test/SemaCXX/overload-resolution-deferred-templates.cpp 
(+28) 


``diff
diff --git a/clang/include/clang/Sema/Overload.h 
b/clang/include/clang/Sema/Overload.h
index a70335bef9dd4..bc42e1684ba99 100644
--- a/clang/include/clang/Sema/Overload.h
+++ b/clang/include/clang/Sema/Overload.h
@@ -350,6 +350,11 @@ class Sema;
 LLVM_PREFERRED_TYPE(bool)
 unsigned BindsToRvalue : 1;
 
+/// Whether this was an identity conversion with qualification
+/// conversion for the implicit object argument.
+LLVM_PREFERRED_TYPE(bool)
+unsigned IsImplicitObjectArgumentQualificationConversion : 1;
+
 /// Whether this binds an implicit object argument to a
 /// non-static member function without a ref-qualifier.
 LLVM_PREFERRED_TYPE(bool)
@@ -448,11 +453,12 @@ class Sema;
 #endif
 return true;
   }
-  if (!C.hasSameType(getFromType(), getToType(2)))
-return false;
   if (BindsToRvalue && IsLvalueReference)
 return false;
-  return true;
+  if (IsImplicitObjectArgumentQualificationConversion) {
+return C.hasSameUnqualifiedType(getFromType(), getToType(2));
+  }
+  return C.hasSameType(getFromType(), getToType(2));
 }
 
 ImplicitConversionRank getRank() const;
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 7af3acacb5ba6..cf6e7ed15a46a 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -245,6 +245,7 @@ void StandardConversionSequence::setAsIdentityConversion() {
   IsLvalueReference = true;
   BindsToFunctionLvalue = false;
   BindsToRvalue = false;
+  IsImplicitObjectArgumentQualificationConversion = false;
   BindsImplicitObjectArgumentWithoutRefQualifier = false;
   ObjCLifetimeConversionBinding = false;
   FromBracedInitList = false;
@@ -5305,10 +5306,10 @@ TryReferenceInit(Sema &S, Expr *Init, QualType DeclType,
 // FIXME: As a speculative fix to a defect introduced by CWG2352, we rank
 // a reference binding that performs a non-top-level qualification
 // conversion as a qualification conversion, not as an identity conversion.
-ICS.Standard.Third = (RefConv &
-  Sema::ReferenceConversions::NestedQualification)
- ? ICK_Qualification
- : ICK_Identity;
+ICS.Standard.Third =
+(RefConv & Sema::ReferenceConversions::NestedQualification)
+? ICK_Qualification
+: ICK_Identity;
 ICS.Standard.setFromType(T2);
 ICS.Standard.setToType(0, T2);
 ICS.Standard.setToType(1, T1);
@@ -5317,6 +5318,7 @@ TryReferenceInit(Sema &S, Expr *Init, QualType DeclType,
 ICS.Standard.DirectBinding = BindsDirectly;
 ICS.Standard.IsLvalueReference = !isRValRef;
 ICS.Standard.BindsToFunctionLvalue = T2->isFunctionType();
+ICS.Standard.IsImplicitObjectArgumentQualificationConversion = false;
 ICS.Standard.BindsToRvalue = InitCategory.isRValue();
 ICS.Standard.BindsImplicitObjectArgumentWithoutRefQualifier = false;
 ICS.Standard.ObjCLifetimeConversionBinding =
@@ -5496,6 +5498,7 @@ TryReferenceInit(Sema &S, Expr *Init, QualType DeclType,
 ICS.Standard.IsLvalueReference = !isRValRef;
 ICS.Standard.BindsToFunctionLvalue = false;
 ICS.Standard.BindsToRvalue = true;
+ICS.Standard.IsImplicitObjectArgumentQualificationConversion = false;
 ICS.Standard.BindsImplicitObjectArgumentWithoutRefQualifier = false;
 ICS.Standard.ObjCLifetimeConversionBinding = false;
   } else if (ICS.isUserDefined()) {
@@ -5518,6 +5521,8 @@ TryReferenceInit(Sema &S, Expr *Init, QualType DeclType,
 ICS.UserDefined.After.IsLvalueReference = !isRValRef;
 ICS.UserDefined.After.BindsToFunctionLvalue = false;
 ICS.UserDefined.After.BindsToRvalue = !LValRefType;
+ICS.UserDefined.After.IsImplicitObjectArgumentQualificationConversion =
+false;
 ICS.UserDefined.After.BindsImplicitObjectArgumentWithoutRefQualifier = 
false;
 ICS.UserDefined.After.ObjCLifetimeConversionBinding = false;
 ICS.UserDefined.After.FromBracedInitList = false;
@@ -5802,6 +5807,7 @@ TryListConversion(Sema &S, InitListExpr *From, QualType 
ToType,
   StandardConversionSequence &SCS = Result.isStandard() ? Result.Standard :

[clang] [Clang] Do not treat Foo -> const Foo conversion sequences as perfect (PR #148613)

2025-07-14 Thread Timm Baeder via cfe-commits

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


[clang] [Clang] Do not treat Foo -> const Foo conversion sequences as perfect (PR #148613)

2025-07-14 Thread Corentin Jabot via cfe-commits

https://github.com/cor3ntin created 
https://github.com/llvm/llvm-project/pull/148613

For implicit object arguments.
This fixes a regression introduced by the "perfect match" overload resolusion 
mechanism introduced in #8c5a307.

Note that GCC allows the ambiguity between a const and non-const candidate to 
be resolved. But this patch focuses on restoring the Clang 20 behavior, and to 
fix the cases which we did resolve incorrectly.

Fixes #147374

>From 18eaff999a03ff969b0feb127be9b8cae5bc93ff Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Mon, 14 Jul 2025 13:34:26 +0200
Subject: [PATCH] [Clang] Do not treat Foo -> const Foo conversion sequences as
 perfect

For implicit object arguments.
This fixes a regression introduced by the "perfect match"
overload resolusion mechanism introduced in #8c5a307.

Note that GCC allows the ambiguity between a const and non-const
candidate to be resolved. But this patch focuses on restoring the
Clang 20 behavior, and to fix the cases which we did resolve
incorrectly.

Fixes #147374
---
 clang/include/clang/Sema/Overload.h   | 12 ++--
 clang/lib/Sema/SemaOverload.cpp   | 22 +++
 ...overload-resolution-deferred-templates.cpp | 28 +++
 3 files changed, 54 insertions(+), 8 deletions(-)

diff --git a/clang/include/clang/Sema/Overload.h 
b/clang/include/clang/Sema/Overload.h
index a70335bef9dd4..bc42e1684ba99 100644
--- a/clang/include/clang/Sema/Overload.h
+++ b/clang/include/clang/Sema/Overload.h
@@ -350,6 +350,11 @@ class Sema;
 LLVM_PREFERRED_TYPE(bool)
 unsigned BindsToRvalue : 1;
 
+/// Whether this was an identity conversion with qualification
+/// conversion for the implicit object argument.
+LLVM_PREFERRED_TYPE(bool)
+unsigned IsImplicitObjectArgumentQualificationConversion : 1;
+
 /// Whether this binds an implicit object argument to a
 /// non-static member function without a ref-qualifier.
 LLVM_PREFERRED_TYPE(bool)
@@ -448,11 +453,12 @@ class Sema;
 #endif
 return true;
   }
-  if (!C.hasSameType(getFromType(), getToType(2)))
-return false;
   if (BindsToRvalue && IsLvalueReference)
 return false;
-  return true;
+  if (IsImplicitObjectArgumentQualificationConversion) {
+return C.hasSameUnqualifiedType(getFromType(), getToType(2));
+  }
+  return C.hasSameType(getFromType(), getToType(2));
 }
 
 ImplicitConversionRank getRank() const;
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 7af3acacb5ba6..cf6e7ed15a46a 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -245,6 +245,7 @@ void StandardConversionSequence::setAsIdentityConversion() {
   IsLvalueReference = true;
   BindsToFunctionLvalue = false;
   BindsToRvalue = false;
+  IsImplicitObjectArgumentQualificationConversion = false;
   BindsImplicitObjectArgumentWithoutRefQualifier = false;
   ObjCLifetimeConversionBinding = false;
   FromBracedInitList = false;
@@ -5305,10 +5306,10 @@ TryReferenceInit(Sema &S, Expr *Init, QualType DeclType,
 // FIXME: As a speculative fix to a defect introduced by CWG2352, we rank
 // a reference binding that performs a non-top-level qualification
 // conversion as a qualification conversion, not as an identity conversion.
-ICS.Standard.Third = (RefConv &
-  Sema::ReferenceConversions::NestedQualification)
- ? ICK_Qualification
- : ICK_Identity;
+ICS.Standard.Third =
+(RefConv & Sema::ReferenceConversions::NestedQualification)
+? ICK_Qualification
+: ICK_Identity;
 ICS.Standard.setFromType(T2);
 ICS.Standard.setToType(0, T2);
 ICS.Standard.setToType(1, T1);
@@ -5317,6 +5318,7 @@ TryReferenceInit(Sema &S, Expr *Init, QualType DeclType,
 ICS.Standard.DirectBinding = BindsDirectly;
 ICS.Standard.IsLvalueReference = !isRValRef;
 ICS.Standard.BindsToFunctionLvalue = T2->isFunctionType();
+ICS.Standard.IsImplicitObjectArgumentQualificationConversion = false;
 ICS.Standard.BindsToRvalue = InitCategory.isRValue();
 ICS.Standard.BindsImplicitObjectArgumentWithoutRefQualifier = false;
 ICS.Standard.ObjCLifetimeConversionBinding =
@@ -5496,6 +5498,7 @@ TryReferenceInit(Sema &S, Expr *Init, QualType DeclType,
 ICS.Standard.IsLvalueReference = !isRValRef;
 ICS.Standard.BindsToFunctionLvalue = false;
 ICS.Standard.BindsToRvalue = true;
+ICS.Standard.IsImplicitObjectArgumentQualificationConversion = false;
 ICS.Standard.BindsImplicitObjectArgumentWithoutRefQualifier = false;
 ICS.Standard.ObjCLifetimeConversionBinding = false;
   } else if (ICS.isUserDefined()) {
@@ -5518,6 +5521,8 @@ TryReferenceInit(Sema &S, Expr *Init, QualType DeclType,
 ICS.UserDefined.After.IsLvalueReference = !isRValRef;
 ICS.UserDefined.After.BindsToFunctionLvalue = false;
 ICS.Us

[clang] [llvm] [AVR] Handle flash RO data mapped to data space for newer devices (PR #146244)

2025-07-14 Thread Tom Vijlbrief via cfe-commits

https://github.com/tomtor updated 
https://github.com/llvm/llvm-project/pull/146244

>From 137c1824febc34b1e34b5b35fc7eefc073eec6fa Mon Sep 17 00:00:00 2001
From: Tom Vijlbrief 
Date: Fri, 27 Jun 2025 17:16:35 +0200
Subject: [PATCH 1/2] [AVR] Handle mapped RO data for newer devices

---
 clang/include/clang/Driver/Options.td |  4 ++
 clang/lib/Basic/Targets/AVR.cpp   |  6 +++
 clang/lib/Driver/ToolChains/AVR.cpp   | 15 ++-
 llvm/lib/Target/AVR/AVRAsmPrinter.cpp | 14 +--
 llvm/lib/Target/AVR/AVRDevices.td | 56 ---
 5 files changed, 67 insertions(+), 28 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2e070d6d64508..95ccdeadf5bfd 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4930,6 +4930,10 @@ def mguard_EQ : Joined<["-"], "mguard=">, Group,
   HelpText<"Enable or disable Control Flow Guard checks and guard tables 
emission">,
   Values<"none,cf,cf-nochecks">;
 def mmcu_EQ : Joined<["-"], "mmcu=">, Group;
+def mflmap : Flag<["-"], "mflmap">, Group,
+  HelpText<"Use AVR mapped memory for RO data">;
+def mrodata_in_ram : Flag<["-"], "mrodata-in-ram">, Group,
+  HelpText<"Copy RO data to ram">;
 def msim : Flag<["-"], "msim">, Group;
 def mfix_and_continue : Flag<["-"], "mfix-and-continue">, 
Group;
 def mieee_fp : Flag<["-"], "mieee-fp">, Group;
diff --git a/clang/lib/Basic/Targets/AVR.cpp b/clang/lib/Basic/Targets/AVR.cpp
index bbe7b01ca036d..4a36bf9cdb132 100644
--- a/clang/lib/Basic/Targets/AVR.cpp
+++ b/clang/lib/Basic/Targets/AVR.cpp
@@ -418,6 +418,10 @@ static MCUInfo AVRMcus[] = {
 } // namespace targets
 } // namespace clang
 
+static bool ArchHasFLMAP(StringRef Name) {
+  return Name.starts_with("avr64") || Name.starts_with("avr128");
+}
+
 static bool ArchHasELPM(StringRef Arch) {
   return llvm::StringSwitch(Arch)
 .Cases("31", "51", "6", true)
@@ -529,6 +533,8 @@ void AVRTargetInfo::getTargetDefines(const LangOptions 
&Opts,
   Builder.defineMacro("__AVR_ARCH__", Arch);
 
   // TODO: perhaps we should use the information from AVRDevices.td instead?
+  if (ArchHasFLMAP(DefineName))
+Builder.defineMacro("__AVR_HAVE_FLMAP__");
   if (ArchHasELPM(Arch))
 Builder.defineMacro("__AVR_HAVE_ELPM__");
   if (ArchHasELPMX(Arch))
diff --git a/clang/lib/Driver/ToolChains/AVR.cpp 
b/clang/lib/Driver/ToolChains/AVR.cpp
index 731076d9754a9..645f9214f091f 100644
--- a/clang/lib/Driver/ToolChains/AVR.cpp
+++ b/clang/lib/Driver/ToolChains/AVR.cpp
@@ -651,8 +651,19 @@ void AVR::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   // This is almost always required because otherwise avr-ld
   // will assume 'avr2' and warn about the program being larger
   // than the bare minimum supports.
-  if (Linker.find("avr-ld") != std::string::npos && FamilyName)
-CmdArgs.push_back(Args.MakeArgString(std::string("-m") + *FamilyName));
+  if (Linker.find("avr-ld") != std::string::npos && FamilyName) {
+// Option to use mapped memory for modern devices with >32kB flash.
+// This is the only option for modern devices with <= 32kB flash,
+// but the larger default to a copy from flash to RAM (avr-ld version < 14)
+// or map the highest 32kB to RAM (avr-ld version >= 14).
+if (Args.hasFlag(options::OPT_mflmap, options::OPT_mrodata_in_ram, false)) 
{
+  CmdArgs.push_back(
+  Args.MakeArgString(std::string("-m") + *FamilyName + "_flmap"));
+  CmdArgs.push_back(Args.MakeArgString(std::string("-u")));
+  CmdArgs.push_back(Args.MakeArgString(std::string("__do_flmap_init")));
+} else
+  CmdArgs.push_back(Args.MakeArgString(std::string("-m") + *FamilyName));
+  }
 
   C.addCommand(std::make_unique(
   JA, *this, ResponseFileSupport::AtFileCurCP(), 
Args.MakeArgString(Linker),
diff --git a/llvm/lib/Target/AVR/AVRAsmPrinter.cpp 
b/llvm/lib/Target/AVR/AVRAsmPrinter.cpp
index ad8aa5717fb42..decfcc4b67f5d 100644
--- a/llvm/lib/Target/AVR/AVRAsmPrinter.cpp
+++ b/llvm/lib/Target/AVR/AVRAsmPrinter.cpp
@@ -263,11 +263,17 @@ bool AVRAsmPrinter::doFinalization(Module &M) {
 auto *Section = cast(TLOF.SectionForGlobal(&GO, TM));
 if (Section->getName().starts_with(".data"))
   NeedsCopyData = true;
-else if (Section->getName().starts_with(".rodata") && SubTM->hasLPM())
+else if (Section->getName().starts_with(".rodata") && SubTM->hasLPM()) {
   // AVRs that have a separate program memory (that's most AVRs) store
-  // .rodata sections in RAM.
-  NeedsCopyData = true;
-else if (Section->getName().starts_with(".bss"))
+  // .rodata sections in RAM,
+  // but XMEGA3 family maps all flash in the data space.
+  // Invoking __do_copy_data with 0 bytes to copy will crash,
+  // so we let the loader handle this for newer devices.
+  if (!(SubTM->hasFeatureSetFamilyXMEGA2() ||
+SubTM->hasFeatureSetFamilyXMEGA3() ||
+SubTM->hasFeatureSetFamilyXMEGA4()))
+

[clang] [WIP][DO NOT MERGE][Clang][Driver] Emit warning when -fsanitize-trap=<...> is passed without associated -fsanitize=<...> (PR #147997)

2025-07-14 Thread Anthony Tran via cfe-commits

https://github.com/anthonyhatran updated 
https://github.com/llvm/llvm-project/pull/147997

>From eadf3e52072fbae01e8de8f7f59883aec1b2c9bc Mon Sep 17 00:00:00 2001
From: Anthony Tran 
Date: Thu, 10 Jul 2025 09:18:50 -0700
Subject: [PATCH 1/4] Added warning and warning group for sanitizer argument
 mismatch

---
 clang/include/clang/Basic/DiagnosticDriverKinds.td | 5 +
 clang/include/clang/Basic/DiagnosticGroups.td  | 3 +++
 2 files changed, 8 insertions(+)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 34b6c0d7a8acd..49a8bdf06bda4 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -874,4 +874,9 @@ def warn_drv_openacc_without_cir
 : Warning<"OpenACC directives will result in no runtime behavior; use "
   "-fclangir to enable runtime effect">,
   InGroup;
+
+def warn_drv_sanitize_trap_mismatch : Warning<
+  "-fsanitize-trap=%0 has no effect because the matching sanitizer is not 
enabled; "
+  "did you mean to pass \"-fsanitize=%0\" as well?">,
+  InGroup;
 }
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index f54a830b0103e..a79562cd9c2e0 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1752,3 +1752,6 @@ def ExplicitSpecializationStorageClass : 
DiagGroup<"explicit-specialization-stor
 
 // A warning for options that enable a feature that is not yet complete
 def ExperimentalOption : DiagGroup<"experimental-option">;
+
+// Warnings for sanitizer arguments
+def SanitizeTrapMismatch : DiagGroup<"sanitize-trap-mismatch">;

>From f1bf9b34daca5d23d1a3f518847f3ccbc8f069a7 Mon Sep 17 00:00:00 2001
From: Anthony Tran 
Date: Thu, 10 Jul 2025 13:35:52 -0700
Subject: [PATCH 2/4] Emit warning and parse mismatched arguments

---
 clang/lib/Driver/SanitizerArgs.cpp | 36 ++
 1 file changed, 36 insertions(+)

diff --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index 4bd61c2f8deef..8b78d850e0018 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -348,6 +348,30 @@ parseSanitizeSkipHotCutoffArgs(const Driver &D, const 
llvm::opt::ArgList &Args,
   return Cutoffs;
 }
 
+// Given a set of mismatched bits, TrapOnly (bits the user asked to trap but
+// that aren’t actually enabled), emit a warning based on -fsanitize-trap=NAME
+static void diagnoseTrapOnly(const Driver &D, SanitizerMask &TrapOnly) {
+// Double pass: one for sanitizer groupings, one for leaves (ex: undefined vs.
+// signed-integer-overflow)
+#define SANITIZER(NAME, ID)
+#define SANITIZER_GROUP(NAME, ID, ALIAS)   
\
+  if (TrapOnly & SanitizerKind::ID##Group) {   
\
+D.Diag(diag::warn_drv_sanitize_trap_mismatch) << NAME; 
\
+TrapOnly &= ~SanitizerKind::ID##Group; 
\
+TrapOnly &= ~SanitizerKind::ID;
\
+  }
+#include "clang/Basic/Sanitizers.def"
+
+#undef SANITIZER_GROUP
+#define SANITIZER_GROUP(NAME, ID, ALIAS)
+#define SANITIZER(NAME, ID)
\
+  if (TrapOnly & SanitizerKind::ID) {  
\
+D.Diag(diag::warn_drv_sanitize_trap_mismatch) << NAME; 
\
+TrapOnly &= ~SanitizerKind::ID;
\
+  }
+#include "clang/Basic/Sanitizers.def"
+}
+
 bool SanitizerArgs::needsFuzzerInterceptors() const {
   return needsFuzzer() && !needsAsanRt() && !needsTsanRt() && !needsMsanRt();
 }
@@ -730,6 +754,18 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
   options::OPT_fno_sanitize_recover_EQ);
   RecoverableKinds &= Kinds;
 
+  // Parse any -fsanitize-trap=<...> flags the user provided, then
+  // diagnose any which do not have a matching -fsanitize=<...>
+  if (DiagnoseErrors) {
+SanitizerMask ExplicitTrap = parseSanitizeArgs(
+D, Args, false, {}, {}, {}, options::OPT_fsanitize_trap_EQ,
+options::OPT_fno_sanitize_trap_EQ);
+SanitizerMask TrapOnly = ExplicitTrap & ~Kinds;
+
+if (TrapOnly)
+  diagnoseTrapOnly(D, TrapOnly);
+  }
+
   TrappingKinds &= Kinds;
   RecoverableKinds &= ~TrappingKinds;
 

>From c7b44099357ee78329f6e289ef6feb321b9b121c Mon Sep 17 00:00:00 2001
From: Anthony Tran 
Date: Mon, 14 Jul 2025 03:36:11 -0700
Subject: [PATCH 3/4] Modify warning message

---
 clang/include/clang/Basic/DiagnosticDriverKinds.td | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 49a8bdf06bda4..f2a0582a364bf 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/cl

[clang] [RISCV] Add -march=unset to cancel and ignore a previous -march. (PR #148321)

2025-07-14 Thread Pengcheng Wang via cfe-commits

https://github.com/wangpc-pp approved this pull request.

LGTM and I totally support this!

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


[clang] [CIR] Add rotate operation (PR #148426)

2025-07-14 Thread Henrich Lauko via cfe-commits


@@ -219,6 +233,28 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl 
&gd, unsigned builtinID,
 mlir::Value arg = emitScalarExpr(e->getArg(0));
 return RValue::get(builder.create(loc, arg));
   }
+
+  case Builtin::BI__builtin_rotateleft8:
+  case Builtin::BI__builtin_rotateleft16:
+  case Builtin::BI__builtin_rotateleft32:
+  case Builtin::BI__builtin_rotateleft64:
+  case Builtin::BI_rotl8:
+  case Builtin::BI_rotl16:
+  case Builtin::BI_rotl:
+  case Builtin::BI_lrotl:
+  case Builtin::BI_rotl64:
+return emitRotate(e, /*isRotateLeft=*/true);
+
+  case Builtin::BI__builtin_rotateright8:
+  case Builtin::BI__builtin_rotateright16:
+  case Builtin::BI__builtin_rotateright32:
+  case Builtin::BI__builtin_rotateright64:
+  case Builtin::BI_rotr8:
+  case Builtin::BI_rotr16:
+  case Builtin::BI_rotr:
+  case Builtin::BI_lrotr:
+  case Builtin::BI_rotr64:

xlauko wrote:

These are not tested. Please add tests.

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


[clang] [CIR] Add rotate operation (PR #148426)

2025-07-14 Thread Henrich Lauko via cfe-commits


@@ -57,6 +57,20 @@ static RValue emitBuiltinBitOp(CIRGenFunction &cgf, const 
CallExpr *e,
   return RValue::get(result);
 }
 
+RValue CIRGenFunction::emitRotate(const CallExpr *e, bool isRotateLeft) {
+  mlir::Value input = emitScalarExpr(e->getArg(0));
+  mlir::Value amount = emitScalarExpr(e->getArg(1));
+
+  // The builtin's amount parameter may have a different type than the input
+  // argument, but the CIR op uses the same type for all values.

xlauko wrote:

why? This just creates unnecessary int cast. 

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


[clang] [CIR] Add rotate operation (PR #148426)

2025-07-14 Thread Henrich Lauko via cfe-commits


@@ -219,6 +233,28 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl 
&gd, unsigned builtinID,
 mlir::Value arg = emitScalarExpr(e->getArg(0));
 return RValue::get(builder.create(loc, arg));
   }
+
+  case Builtin::BI__builtin_rotateleft8:
+  case Builtin::BI__builtin_rotateleft16:
+  case Builtin::BI__builtin_rotateleft32:
+  case Builtin::BI__builtin_rotateleft64:
+  case Builtin::BI_rotl8:
+  case Builtin::BI_rotl16:
+  case Builtin::BI_rotl:
+  case Builtin::BI_lrotl:
+  case Builtin::BI_rotl64:

xlauko wrote:

These are not tested. Please add tests.

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


[clang] [CIR] Add rotate operation (PR #148426)

2025-07-14 Thread Henrich Lauko via cfe-commits


@@ -872,6 +872,21 @@ mlir::LogicalResult 
CIRToLLVMReturnOpLowering::matchAndRewrite(
   return mlir::LogicalResult::success();
 }
 
+mlir::LogicalResult CIRToLLVMRotateOpLowering::matchAndRewrite(
+cir::RotateOp op, OpAdaptor adaptor,
+mlir::ConversionPatternRewriter &rewriter) const {
+  // Note that LLVM intrinsic calls to @llvm.fsh{r,l}.i* have the same type as
+  // the operand.
+  auto input = adaptor.getInput();
+  if (op.getIsRotateLeft())

xlauko wrote:

```suggestion
  if (op.isRotateLeft())
```

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


[clang] [CIR] Add rotate operation (PR #148426)

2025-07-14 Thread Henrich Lauko via cfe-commits


@@ -2847,6 +2847,37 @@ def ByteSwapOp : CIR_BitOpBase<"byte_swap", 
CIR_UIntOfWidths<[16, 32, 64]>> {
   }];
 }
 
+//===--===//
+// RotateOp
+//===--===//
+
+def RotateOp : CIR_Op<"rotate", [Pure, SameOperandsAndResultType]> {
+  let summary = "Rotate the bits in the operand integer";
+  let description = [{
+The `cir.rotate` rotates the bits in `input` by the given amount `amount`.
+The rotate direction is specified by the `left` and `right` keyword.
+
+The width of the input integer must be either 8, 16, 32, or 64. `input`,
+`amount`, and `result` must be of the same type.
+
+Example:
+
+```mlir
+%r = cir.rotate left %0, %1 -> !u32i
+%r = cir.rotate right %0, %1 -> !u32i
+```
+  }];
+
+  let results = (outs CIR_IntType:$result);
+  let arguments = (ins CIR_IntType:$input, CIR_IntType:$amount,
+   UnitAttr:$isRotateLeft);
+
+  let assemblyFormat = [{
+(`left` $isRotateLeft^) : (`right`)?
+$input `,` $amount `:` type($result) attr-dict
+  }];
+}

xlauko wrote:

```suggestion
  }];

  let extraClassDeclaration = [{
bool isRotateLeft() const { return getRotateLeft(); }
bool isRotateRight() const { return !isRotateLeft(); }
  }];
}
```

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


[clang] [CIR] Add rotate operation (PR #148426)

2025-07-14 Thread Henrich Lauko via cfe-commits


@@ -2847,6 +2847,37 @@ def ByteSwapOp : CIR_BitOpBase<"byte_swap", 
CIR_UIntOfWidths<[16, 32, 64]>> {
   }];
 }
 
+//===--===//
+// RotateOp
+//===--===//
+
+def RotateOp : CIR_Op<"rotate", [Pure, SameOperandsAndResultType]> {
+  let summary = "Rotate the bits in the operand integer";
+  let description = [{
+The `cir.rotate` rotates the bits in `input` by the given amount `amount`.
+The rotate direction is specified by the `left` and `right` keyword.
+
+The width of the input integer must be either 8, 16, 32, or 64. `input`,
+`amount`, and `result` must be of the same type.
+
+Example:
+
+```mlir
+%r = cir.rotate left %0, %1 -> !u32i
+%r = cir.rotate right %0, %1 -> !u32i
+```
+  }];
+
+  let results = (outs CIR_IntType:$result);
+  let arguments = (ins CIR_IntType:$input, CIR_IntType:$amount,
+   UnitAttr:$isRotateLeft);

xlauko wrote:

```suggestion
 
  let arguments = (ins 
CIR_UIntOfWidths<[8, 16, 32, 64]>:$input, 
CIR_IntType:$amount,
UnitAttr:$rotateLeft
  );

  let results = (outs CIR_IntType:$result);
```

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


[clang] [CIR] Add rotate operation (PR #148426)

2025-07-14 Thread Henrich Lauko via cfe-commits


@@ -2847,6 +2847,37 @@ def ByteSwapOp : CIR_BitOpBase<"byte_swap", 
CIR_UIntOfWidths<[16, 32, 64]>> {
   }];
 }
 
+//===--===//
+// RotateOp
+//===--===//
+
+def RotateOp : CIR_Op<"rotate", [Pure, SameOperandsAndResultType]> {
+  let summary = "Rotate the bits in the operand integer";
+  let description = [{
+The `cir.rotate` rotates the bits in `input` by the given amount `amount`.
+The rotate direction is specified by the `left` and `right` keyword.
+
+The width of the input integer must be either 8, 16, 32, or 64. `input`,
+`amount`, and `result` must be of the same type.
+
+Example:
+
+```mlir
+%r = cir.rotate left %0, %1 -> !u32i
+%r = cir.rotate right %0, %1 -> !u32i
+```
+  }];
+
+  let results = (outs CIR_IntType:$result);
+  let arguments = (ins CIR_IntType:$input, CIR_IntType:$amount,
+   UnitAttr:$isRotateLeft);
+
+  let assemblyFormat = [{
+(`left` $isRotateLeft^) : (`right`)?

xlauko wrote:

```suggestion
(`left` $rotateLeft^) : (`right`)?
```

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


[clang] [WIP][DO NOT MERGE][Clang][Driver] Emit warning when -fsanitize-trap=<...> is passed without associated -fsanitize=<...> (PR #147997)

2025-07-14 Thread Anthony Tran via cfe-commits

https://github.com/anthonyhatran updated 
https://github.com/llvm/llvm-project/pull/147997

>From eadf3e52072fbae01e8de8f7f59883aec1b2c9bc Mon Sep 17 00:00:00 2001
From: Anthony Tran 
Date: Thu, 10 Jul 2025 09:18:50 -0700
Subject: [PATCH 1/5] Added warning and warning group for sanitizer argument
 mismatch

---
 clang/include/clang/Basic/DiagnosticDriverKinds.td | 5 +
 clang/include/clang/Basic/DiagnosticGroups.td  | 3 +++
 2 files changed, 8 insertions(+)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 34b6c0d7a8acd..49a8bdf06bda4 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -874,4 +874,9 @@ def warn_drv_openacc_without_cir
 : Warning<"OpenACC directives will result in no runtime behavior; use "
   "-fclangir to enable runtime effect">,
   InGroup;
+
+def warn_drv_sanitize_trap_mismatch : Warning<
+  "-fsanitize-trap=%0 has no effect because the matching sanitizer is not 
enabled; "
+  "did you mean to pass \"-fsanitize=%0\" as well?">,
+  InGroup;
 }
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index f54a830b0103e..a79562cd9c2e0 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1752,3 +1752,6 @@ def ExplicitSpecializationStorageClass : 
DiagGroup<"explicit-specialization-stor
 
 // A warning for options that enable a feature that is not yet complete
 def ExperimentalOption : DiagGroup<"experimental-option">;
+
+// Warnings for sanitizer arguments
+def SanitizeTrapMismatch : DiagGroup<"sanitize-trap-mismatch">;

>From f1bf9b34daca5d23d1a3f518847f3ccbc8f069a7 Mon Sep 17 00:00:00 2001
From: Anthony Tran 
Date: Thu, 10 Jul 2025 13:35:52 -0700
Subject: [PATCH 2/5] Emit warning and parse mismatched arguments

---
 clang/lib/Driver/SanitizerArgs.cpp | 36 ++
 1 file changed, 36 insertions(+)

diff --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index 4bd61c2f8deef..8b78d850e0018 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -348,6 +348,30 @@ parseSanitizeSkipHotCutoffArgs(const Driver &D, const 
llvm::opt::ArgList &Args,
   return Cutoffs;
 }
 
+// Given a set of mismatched bits, TrapOnly (bits the user asked to trap but
+// that aren’t actually enabled), emit a warning based on -fsanitize-trap=NAME
+static void diagnoseTrapOnly(const Driver &D, SanitizerMask &TrapOnly) {
+// Double pass: one for sanitizer groupings, one for leaves (ex: undefined vs.
+// signed-integer-overflow)
+#define SANITIZER(NAME, ID)
+#define SANITIZER_GROUP(NAME, ID, ALIAS)   
\
+  if (TrapOnly & SanitizerKind::ID##Group) {   
\
+D.Diag(diag::warn_drv_sanitize_trap_mismatch) << NAME; 
\
+TrapOnly &= ~SanitizerKind::ID##Group; 
\
+TrapOnly &= ~SanitizerKind::ID;
\
+  }
+#include "clang/Basic/Sanitizers.def"
+
+#undef SANITIZER_GROUP
+#define SANITIZER_GROUP(NAME, ID, ALIAS)
+#define SANITIZER(NAME, ID)
\
+  if (TrapOnly & SanitizerKind::ID) {  
\
+D.Diag(diag::warn_drv_sanitize_trap_mismatch) << NAME; 
\
+TrapOnly &= ~SanitizerKind::ID;
\
+  }
+#include "clang/Basic/Sanitizers.def"
+}
+
 bool SanitizerArgs::needsFuzzerInterceptors() const {
   return needsFuzzer() && !needsAsanRt() && !needsTsanRt() && !needsMsanRt();
 }
@@ -730,6 +754,18 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
   options::OPT_fno_sanitize_recover_EQ);
   RecoverableKinds &= Kinds;
 
+  // Parse any -fsanitize-trap=<...> flags the user provided, then
+  // diagnose any which do not have a matching -fsanitize=<...>
+  if (DiagnoseErrors) {
+SanitizerMask ExplicitTrap = parseSanitizeArgs(
+D, Args, false, {}, {}, {}, options::OPT_fsanitize_trap_EQ,
+options::OPT_fno_sanitize_trap_EQ);
+SanitizerMask TrapOnly = ExplicitTrap & ~Kinds;
+
+if (TrapOnly)
+  diagnoseTrapOnly(D, TrapOnly);
+  }
+
   TrappingKinds &= Kinds;
   RecoverableKinds &= ~TrappingKinds;
 

>From c7b44099357ee78329f6e289ef6feb321b9b121c Mon Sep 17 00:00:00 2001
From: Anthony Tran 
Date: Mon, 14 Jul 2025 03:36:11 -0700
Subject: [PATCH 3/5] Modify warning message

---
 clang/include/clang/Basic/DiagnosticDriverKinds.td | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 49a8bdf06bda4..f2a0582a364bf 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/cl

[clang] [llvm] [AVR] Handle flash RO data mapped to data space for newer devices (PR #146244)

2025-07-14 Thread Tom Vijlbrief via cfe-commits

https://github.com/tomtor updated 
https://github.com/llvm/llvm-project/pull/146244

>From 137c1824febc34b1e34b5b35fc7eefc073eec6fa Mon Sep 17 00:00:00 2001
From: Tom Vijlbrief 
Date: Fri, 27 Jun 2025 17:16:35 +0200
Subject: [PATCH 1/3] [AVR] Handle mapped RO data for newer devices

---
 clang/include/clang/Driver/Options.td |  4 ++
 clang/lib/Basic/Targets/AVR.cpp   |  6 +++
 clang/lib/Driver/ToolChains/AVR.cpp   | 15 ++-
 llvm/lib/Target/AVR/AVRAsmPrinter.cpp | 14 +--
 llvm/lib/Target/AVR/AVRDevices.td | 56 ---
 5 files changed, 67 insertions(+), 28 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2e070d6d64508..95ccdeadf5bfd 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4930,6 +4930,10 @@ def mguard_EQ : Joined<["-"], "mguard=">, Group,
   HelpText<"Enable or disable Control Flow Guard checks and guard tables 
emission">,
   Values<"none,cf,cf-nochecks">;
 def mmcu_EQ : Joined<["-"], "mmcu=">, Group;
+def mflmap : Flag<["-"], "mflmap">, Group,
+  HelpText<"Use AVR mapped memory for RO data">;
+def mrodata_in_ram : Flag<["-"], "mrodata-in-ram">, Group,
+  HelpText<"Copy RO data to ram">;
 def msim : Flag<["-"], "msim">, Group;
 def mfix_and_continue : Flag<["-"], "mfix-and-continue">, 
Group;
 def mieee_fp : Flag<["-"], "mieee-fp">, Group;
diff --git a/clang/lib/Basic/Targets/AVR.cpp b/clang/lib/Basic/Targets/AVR.cpp
index bbe7b01ca036d..4a36bf9cdb132 100644
--- a/clang/lib/Basic/Targets/AVR.cpp
+++ b/clang/lib/Basic/Targets/AVR.cpp
@@ -418,6 +418,10 @@ static MCUInfo AVRMcus[] = {
 } // namespace targets
 } // namespace clang
 
+static bool ArchHasFLMAP(StringRef Name) {
+  return Name.starts_with("avr64") || Name.starts_with("avr128");
+}
+
 static bool ArchHasELPM(StringRef Arch) {
   return llvm::StringSwitch(Arch)
 .Cases("31", "51", "6", true)
@@ -529,6 +533,8 @@ void AVRTargetInfo::getTargetDefines(const LangOptions 
&Opts,
   Builder.defineMacro("__AVR_ARCH__", Arch);
 
   // TODO: perhaps we should use the information from AVRDevices.td instead?
+  if (ArchHasFLMAP(DefineName))
+Builder.defineMacro("__AVR_HAVE_FLMAP__");
   if (ArchHasELPM(Arch))
 Builder.defineMacro("__AVR_HAVE_ELPM__");
   if (ArchHasELPMX(Arch))
diff --git a/clang/lib/Driver/ToolChains/AVR.cpp 
b/clang/lib/Driver/ToolChains/AVR.cpp
index 731076d9754a9..645f9214f091f 100644
--- a/clang/lib/Driver/ToolChains/AVR.cpp
+++ b/clang/lib/Driver/ToolChains/AVR.cpp
@@ -651,8 +651,19 @@ void AVR::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   // This is almost always required because otherwise avr-ld
   // will assume 'avr2' and warn about the program being larger
   // than the bare minimum supports.
-  if (Linker.find("avr-ld") != std::string::npos && FamilyName)
-CmdArgs.push_back(Args.MakeArgString(std::string("-m") + *FamilyName));
+  if (Linker.find("avr-ld") != std::string::npos && FamilyName) {
+// Option to use mapped memory for modern devices with >32kB flash.
+// This is the only option for modern devices with <= 32kB flash,
+// but the larger default to a copy from flash to RAM (avr-ld version < 14)
+// or map the highest 32kB to RAM (avr-ld version >= 14).
+if (Args.hasFlag(options::OPT_mflmap, options::OPT_mrodata_in_ram, false)) 
{
+  CmdArgs.push_back(
+  Args.MakeArgString(std::string("-m") + *FamilyName + "_flmap"));
+  CmdArgs.push_back(Args.MakeArgString(std::string("-u")));
+  CmdArgs.push_back(Args.MakeArgString(std::string("__do_flmap_init")));
+} else
+  CmdArgs.push_back(Args.MakeArgString(std::string("-m") + *FamilyName));
+  }
 
   C.addCommand(std::make_unique(
   JA, *this, ResponseFileSupport::AtFileCurCP(), 
Args.MakeArgString(Linker),
diff --git a/llvm/lib/Target/AVR/AVRAsmPrinter.cpp 
b/llvm/lib/Target/AVR/AVRAsmPrinter.cpp
index ad8aa5717fb42..decfcc4b67f5d 100644
--- a/llvm/lib/Target/AVR/AVRAsmPrinter.cpp
+++ b/llvm/lib/Target/AVR/AVRAsmPrinter.cpp
@@ -263,11 +263,17 @@ bool AVRAsmPrinter::doFinalization(Module &M) {
 auto *Section = cast(TLOF.SectionForGlobal(&GO, TM));
 if (Section->getName().starts_with(".data"))
   NeedsCopyData = true;
-else if (Section->getName().starts_with(".rodata") && SubTM->hasLPM())
+else if (Section->getName().starts_with(".rodata") && SubTM->hasLPM()) {
   // AVRs that have a separate program memory (that's most AVRs) store
-  // .rodata sections in RAM.
-  NeedsCopyData = true;
-else if (Section->getName().starts_with(".bss"))
+  // .rodata sections in RAM,
+  // but XMEGA3 family maps all flash in the data space.
+  // Invoking __do_copy_data with 0 bytes to copy will crash,
+  // so we let the loader handle this for newer devices.
+  if (!(SubTM->hasFeatureSetFamilyXMEGA2() ||
+SubTM->hasFeatureSetFamilyXMEGA3() ||
+SubTM->hasFeatureSetFamilyXMEGA4()))
+

[clang] [llvm] [DTLTO][Clang] Add support for Integrated Distributed ThinLTO (PR #147265)

2025-07-14 Thread via cfe-commits


@@ -0,0 +1,43 @@
+// REQUIRES: lld
+
+/// Check DTLTO options are forwarded to the linker.
+
+// RUN: echo "--target=x86_64-linux-gnu \
+// RUN:   -Xthinlto-distributor=distarg1 \
+// RUN:   -Xthinlto-distributor=distarg2,distarg3 \
+// RUN:   -fuse-ld=lld" > %t.rsp
+
+/// Check that options are forwarded as expected with --thinlto-distributor=.
+// RUN: %clang -### @%t.rsp -fthinlto-distributor=dist.exe %s 2>&1 | \
+// RUN:   FileCheck %s --implicit-check-not=warning
+
+// CHECK: ld.lld
+// CHECK-SAME: "--thinlto-distributor=dist.exe"
+// CHECK-SAME: "--thinlto-remote-compiler={{.*}}clang
+// CHECK-SAME: "--thinlto-distributor-arg=distarg1"
+// CHECK-SAME: "--thinlto-distributor-arg=distarg2"
+// CHECK-SAME: "--thinlto-distributor-arg=distarg3"
+
+
+/// Check that options are not added without --thinlto-distributor= and
+/// that there is an unused option warning issued for -Xthinlto-distributor=
+/// options. We specify -flto here as these options should be unaffected by it.
+// RUN: %clang -### @%t.rsp -flto=thin %s 2>&1 | \
+// RUN:   FileCheck %s --check-prefixes=NONE,NOMORE 
--implicit-check-not=warning

bd1976bris wrote:

@MaskRay done. Thanks.

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


[clang] [llvm] [DTLTO][Clang] Add support for Integrated Distributed ThinLTO (PR #147265)

2025-07-14 Thread via cfe-commits


@@ -0,0 +1,43 @@
+// REQUIRES: lld
+
+/// Check DTLTO options are forwarded to the linker.
+
+// RUN: echo "--target=x86_64-linux-gnu \
+// RUN:   -Xthinlto-distributor=distarg1 \
+// RUN:   -Xthinlto-distributor=distarg2,distarg3 \
+// RUN:   -fuse-ld=lld" > %t.rsp
+
+/// Check that options are forwarded as expected with --thinlto-distributor=.
+// RUN: %clang -### @%t.rsp -fthinlto-distributor=dist.exe %s 2>&1 | \
+// RUN:   FileCheck %s --implicit-check-not=warning
+
+// CHECK: ld.lld
+// CHECK-SAME: "--thinlto-distributor=dist.exe"
+// CHECK-SAME: "--thinlto-remote-compiler={{.*}}clang
+// CHECK-SAME: "--thinlto-distributor-arg=distarg1"
+// CHECK-SAME: "--thinlto-distributor-arg=distarg2"
+// CHECK-SAME: "--thinlto-distributor-arg=distarg3"
+
+
+/// Check that options are not added without --thinlto-distributor= and
+/// that there is an unused option warning issued for -Xthinlto-distributor=
+/// options. We specify -flto here as these options should be unaffected by it.
+// RUN: %clang -### @%t.rsp -flto=thin %s 2>&1 | \
+// RUN:   FileCheck %s --check-prefixes=NONE,NOMORE 
--implicit-check-not=warning
+
+// NONE: warning: argument unused during compilation: 
'-Xthinlto-distributor=distarg1'
+// NONE: warning: argument unused during compilation: 
'-Xthinlto-distributor=distarg2,distarg3'
+// NONE: ld.lld
+// NOMORE-NOT: distributor

bd1976bris wrote:

@teresajohnson I have now removed the use of response files and implemented 
(judiciously) @MaskRay's suggestion of using `-Werror`.

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


[clang] [llvm] [DTLTO][Clang] Add support for Integrated Distributed ThinLTO (PR #147265)

2025-07-14 Thread via cfe-commits


@@ -0,0 +1,43 @@
+// REQUIRES: lld
+
+/// Check DTLTO options are forwarded to the linker.
+
+// RUN: echo "--target=x86_64-linux-gnu \
+// RUN:   -Xthinlto-distributor=distarg1 \
+// RUN:   -Xthinlto-distributor=distarg2,distarg3 \
+// RUN:   -fuse-ld=lld" > %t.rsp

bd1976bris wrote:

@ilovepi - I concede that using response files has caused some issues already. 
I have removed their use from the test now.

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


[clang] [llvm] [DTLTO][Clang] Add support for Integrated Distributed ThinLTO (PR #147265)

2025-07-14 Thread via cfe-commits


@@ -0,0 +1,57 @@
+// REQUIRES: lld
+
+/// Check DTLTO options are forwarded to the linker.
+
+/// Create a response file for all FileCheck invocations to share. These 
implicit
+/// checks ensure that all lines which mention DTLTO options are checked,
+/// and that no unexpected warnings appear.
+// RUN: echo " \"%/s\" --implicit-check-not=distributor \
+// RUN:   --implicit-check-not=remote-compiler \
+// RUN:   --implicit-check-not=warning:" > %t_f.rsp
+
+/// Create a response file to check that explicitly specified 
-Xthinlto-distributor
+/// options are forwarded correctly.
+// RUN: echo "-flto=thin \"%/s\" -### -fuse-ld=lld --target=x86_64-linux-gnu \

bd1976bris wrote:

This is no longer relevant as I have removed the use of response files from the 
test.

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


[clang] [llvm] [KeyInstr] Add docs (PR #137991)

2025-07-14 Thread J. Ryan Stinnett via cfe-commits


@@ -0,0 +1,114 @@
+# Key Instructions debug info in LLVM
+
+Key Instructions reduces the jumpiness of optimized code debug stepping. This 
document explains the feature and how it is implemented in LLVM. For Clang 
support please see the [Clang docs](../../clang/docs/KeyInstructionsClang.md)
+
+## Status
+
+In development, but mostly complete. The feature is currently disabled for 
coroutines.
+
+Tell Clang [not] to produce Key Instructions metadata with 
`-g[no-]key-instructions`. See the Clang docs for implementation info.
+
+The feature improves optimized code stepping; it's intended for the feature to 
be used with optimisations enabled. Although the feature works at O0 it is not 
recommended because in some cases the effect of editing variables may not 
always be immediately realised. (This is a quirk of the current implementation, 
rather than fundemental limitation, covered in more detail later).
+
+This is a DWARF-based feature. There is currently no plan to support CodeView.
+
+Set LLVM flag `-dwarf-use-key-instructions` to `false` to ignore Key 
Instructions metadata when emitting DWARF.
+
+## Problem statement
+
+A lot of the noise in stepping comes from code motion and instruction 
scheduling. Consider a long expression on a single line. It may involve 
multiple operations that optimisations move, re-order, and interleave with 
other instructions that have different line numbers.
+
+DWARF provides a helpful tool the compiler can employ to mitigate this 
jumpiness, the `is_stmt` flag, which indicates that an instruction is a 
recommended breakpoint location. However, LLVM's current approach to deciding 
`is_stmt` placement essentially reduces down to "is the associated line number 
different to the previous instruction's?".
+
+(Note: It's up to the debugger if it wants to interpret `is_stmt` or not, and 
at time of writing LLDB doesn't; possibly because until now LLVM's is_stmts 
convey no information that can't already be deduced from the rest of the line 
table.)
+
+## Solution overview
+
+Taking ideas from two papers [1][2] that explore the issue, especially C. 
Tice's:
+
+From the perspective of a source-level debugger user:
+
+* Source code is made up of interesting constructs; the level of granularity 
for “interesting” while stepping is typically assignments, calls, control flow. 
We’ll call these interesting constructs Atoms.
+
+* Atoms usually have one instruction that implements the functionality that a 
user can observe; once they step “off” that instruction, the atom is finalised. 
We’ll call that a Key Instruction.
+
+* Communicating where the key instructions are to the debugger (using DWARF’s 
is_stmt) avoids jumpiness introduced by scheduling non-key instructions without 
losing source attribution (because non-key instructions retain an associated 
source location, they’re just ignored for stepping).
+
+## Solution implementation
+
+1. `DILocation` has 2 new fields, `atomGroup` and `atomRank`. `DISubprogram` 
has a new field `keyInstructions`.
+2. Clang creates `DILocations` using the new fields to communicate which 
instructions are "interesting", and sets `keyInstructions` true in 
`DISubprogram`s to tell LLVM to interpret the new metadata in those functions.
+3. There’s some bookkeeping required by optimisations that duplicate control 
flow.
+4. During DWARF emission, the new metadata is collected (linear scan over 
instructions) to decide `is_stmt` placements.
+
+1. *The metadata* - The two new `DILocation` fields are `atomGroup` and 
`atomRank` and are both are unsigned integers. `atomGroup` is 61 bits and 
`atomRank` 3 bits. Instructions in the same function with the same `(atomGroup, 
inlinedAt)` pair are part of the same source atom. `atomRank` determines 
`is_stmt` preference within that group, where a lower number is higher 
precedence. Higher rank instructions act as "backup" `is_stmt` locations, 
providing good fallback locations if/when the primary candidate gets optimized 
away. The default values of 0 indicate the instruction isn’t interesting - it's 
not an `is_stmt` candidate. If `keyInstructions` in `DISubprogram` is false 
(default) then the new `DILocation` metadata is ignored for the function 
(including inlined instances) when emitting DWARF.
+
+2. *Clang annotates key instructions* with the new metadata. Variable 
assignments (stores, memory intrinsics), control flow (branches and their 
conditions, some unconditional branches), and exception handling instructions 
are annotated. Calls are ignored as they're unconditionally marked is_stmt.
+
+3. *Throughout optimisation*, the `DILocation` is propagated normally. Cloned 
instructions get the original’s `DILocation`, the new fields get merged in 
`getMergedLocation`, etc. However, pass writers need to intercede in cases 
where a code path is duplicated, e.g. unrolling, jump-threading. In these cases 
we want to emit key instructions in both the original and duplicated code, so 
the duplicate

[clang] [llvm] [KeyInstr] Add docs (PR #137991)

2025-07-14 Thread J. Ryan Stinnett via cfe-commits


@@ -102,6 +103,10 @@ Clang
 :doc:`CFIVerify`
   A description of the verification tool for Control Flow Integrity.
 
+:doc: `KeyInstructionsClang`

jryans wrote:

Does this render correctly as a link to your page...? None of the other lines 
have a space between `:doc:` and the page name, but maybe it works...?

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


[clang] [llvm] [KeyInstr] Add docs (PR #137991)

2025-07-14 Thread J. Ryan Stinnett via cfe-commits


@@ -0,0 +1,114 @@
+# Key Instructions debug info in LLVM
+
+Key Instructions reduces the jumpiness of optimized code debug stepping. This 
document explains the feature and how it is implemented in LLVM. For Clang 
support please see the [Clang docs](../../clang/docs/KeyInstructionsClang.md)
+
+## Status
+
+In development, but mostly complete. The feature is currently disabled for 
coroutines.
+
+Tell Clang [not] to produce Key Instructions metadata with 
`-g[no-]key-instructions`. See the Clang docs for implementation info.
+
+The feature improves optimized code stepping; it's intended for the feature to 
be used with optimisations enabled. Although the feature works at O0 it is not 
recommended because in some cases the effect of editing variables may not 
always be immediately realised. (This is a quirk of the current implementation, 
rather than fundemental limitation, covered in more detail later).
+
+This is a DWARF-based feature. There is currently no plan to support CodeView.
+
+Set LLVM flag `-dwarf-use-key-instructions` to `false` to ignore Key 
Instructions metadata when emitting DWARF.
+
+## Problem statement
+
+A lot of the noise in stepping comes from code motion and instruction 
scheduling. Consider a long expression on a single line. It may involve 
multiple operations that optimisations move, re-order, and interleave with 
other instructions that have different line numbers.
+
+DWARF provides a helpful tool the compiler can employ to mitigate this 
jumpiness, the `is_stmt` flag, which indicates that an instruction is a 
recommended breakpoint location. However, LLVM's current approach to deciding 
`is_stmt` placement essentially reduces down to "is the associated line number 
different to the previous instruction's?".
+
+(Note: It's up to the debugger if it wants to interpret `is_stmt` or not, and 
at time of writing LLDB doesn't; possibly because until now LLVM's is_stmts 
convey no information that can't already be deduced from the rest of the line 
table.)
+
+## Solution overview
+
+Taking ideas from two papers [1][2] that explore the issue, especially C. 
Tice's:
+
+From the perspective of a source-level debugger user:
+
+* Source code is made up of interesting constructs; the level of granularity 
for “interesting” while stepping is typically assignments, calls, control flow. 
We’ll call these interesting constructs Atoms.
+
+* Atoms usually have one instruction that implements the functionality that a 
user can observe; once they step “off” that instruction, the atom is finalised. 
We’ll call that a Key Instruction.
+
+* Communicating where the key instructions are to the debugger (using DWARF’s 
is_stmt) avoids jumpiness introduced by scheduling non-key instructions without 
losing source attribution (because non-key instructions retain an associated 
source location, they’re just ignored for stepping).
+
+## Solution implementation
+
+1. `DILocation` has 2 new fields, `atomGroup` and `atomRank`. `DISubprogram` 
has a new field `keyInstructions`.
+2. Clang creates `DILocations` using the new fields to communicate which 
instructions are "interesting", and sets `keyInstructions` true in 
`DISubprogram`s to tell LLVM to interpret the new metadata in those functions.
+3. There’s some bookkeeping required by optimisations that duplicate control 
flow.
+4. During DWARF emission, the new metadata is collected (linear scan over 
instructions) to decide `is_stmt` placements.
+
+1. *The metadata* - The two new `DILocation` fields are `atomGroup` and 
`atomRank` and are both are unsigned integers. `atomGroup` is 61 bits and 
`atomRank` 3 bits. Instructions in the same function with the same `(atomGroup, 
inlinedAt)` pair are part of the same source atom. `atomRank` determines 
`is_stmt` preference within that group, where a lower number is higher 
precedence. Higher rank instructions act as "backup" `is_stmt` locations, 
providing good fallback locations if/when the primary candidate gets optimized 
away. The default values of 0 indicate the instruction isn’t interesting - it's 
not an `is_stmt` candidate. If `keyInstructions` in `DISubprogram` is false 
(default) then the new `DILocation` metadata is ignored for the function 
(including inlined instances) when emitting DWARF.

jryans wrote:

GitHub's Markdown preview joins this two lists together, so this becomes item 
number 5... Perhaps best to run a local docs build and check exactly how this 
displayed, then tweak if needed.

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


[clang] [llvm] [KeyInstr] Add docs (PR #137991)

2025-07-14 Thread J. Ryan Stinnett via cfe-commits


@@ -0,0 +1,114 @@
+# Key Instructions debug info in LLVM
+
+Key Instructions reduces the jumpiness of optimized code debug stepping. This 
document explains the feature and how it is implemented in LLVM. For Clang 
support please see the [Clang docs](../../clang/docs/KeyInstructionsClang.md)
+
+## Status
+
+In development, but mostly complete. The feature is currently disabled for 
coroutines.
+
+Tell Clang [not] to produce Key Instructions metadata with 
`-g[no-]key-instructions`. See the Clang docs for implementation info.
+
+The feature improves optimized code stepping; it's intended for the feature to 
be used with optimisations enabled. Although the feature works at O0 it is not 
recommended because in some cases the effect of editing variables may not 
always be immediately realised. (This is a quirk of the current implementation, 
rather than fundemental limitation, covered in more detail later).
+
+This is a DWARF-based feature. There is currently no plan to support CodeView.
+
+Set LLVM flag `-dwarf-use-key-instructions` to `false` to ignore Key 
Instructions metadata when emitting DWARF.
+
+## Problem statement
+
+A lot of the noise in stepping comes from code motion and instruction 
scheduling. Consider a long expression on a single line. It may involve 
multiple operations that optimisations move, re-order, and interleave with 
other instructions that have different line numbers.
+
+DWARF provides a helpful tool the compiler can employ to mitigate this 
jumpiness, the `is_stmt` flag, which indicates that an instruction is a 
recommended breakpoint location. However, LLVM's current approach to deciding 
`is_stmt` placement essentially reduces down to "is the associated line number 
different to the previous instruction's?".
+
+(Note: It's up to the debugger if it wants to interpret `is_stmt` or not, and 
at time of writing LLDB doesn't; possibly because until now LLVM's is_stmts 
convey no information that can't already be deduced from the rest of the line 
table.)
+
+## Solution overview
+
+Taking ideas from two papers [1][2] that explore the issue, especially C. 
Tice's:
+
+From the perspective of a source-level debugger user:
+
+* Source code is made up of interesting constructs; the level of granularity 
for “interesting” while stepping is typically assignments, calls, control flow. 
We’ll call these interesting constructs Atoms.
+
+* Atoms usually have one instruction that implements the functionality that a 
user can observe; once they step “off” that instruction, the atom is finalised. 
We’ll call that a Key Instruction.
+
+* Communicating where the key instructions are to the debugger (using DWARF’s 
is_stmt) avoids jumpiness introduced by scheduling non-key instructions without 
losing source attribution (because non-key instructions retain an associated 
source location, they’re just ignored for stepping).
+
+## Solution implementation
+
+1. `DILocation` has 2 new fields, `atomGroup` and `atomRank`. `DISubprogram` 
has a new field `keyInstructions`.
+2. Clang creates `DILocations` using the new fields to communicate which 
instructions are "interesting", and sets `keyInstructions` true in 
`DISubprogram`s to tell LLVM to interpret the new metadata in those functions.
+3. There’s some bookkeeping required by optimisations that duplicate control 
flow.
+4. During DWARF emission, the new metadata is collected (linear scan over 
instructions) to decide `is_stmt` placements.
+
+1. *The metadata* - The two new `DILocation` fields are `atomGroup` and 
`atomRank` and are both are unsigned integers. `atomGroup` is 61 bits and 
`atomRank` 3 bits. Instructions in the same function with the same `(atomGroup, 
inlinedAt)` pair are part of the same source atom. `atomRank` determines 
`is_stmt` preference within that group, where a lower number is higher 
precedence. Higher rank instructions act as "backup" `is_stmt` locations, 
providing good fallback locations if/when the primary candidate gets optimized 
away. The default values of 0 indicate the instruction isn’t interesting - it's 
not an `is_stmt` candidate. If `keyInstructions` in `DISubprogram` is false 
(default) then the new `DILocation` metadata is ignored for the function 
(including inlined instances) when emitting DWARF.
+
+2. *Clang annotates key instructions* with the new metadata. Variable 
assignments (stores, memory intrinsics), control flow (branches and their 
conditions, some unconditional branches), and exception handling instructions 
are annotated. Calls are ignored as they're unconditionally marked is_stmt.
+
+3. *Throughout optimisation*, the `DILocation` is propagated normally. Cloned 
instructions get the original’s `DILocation`, the new fields get merged in 
`getMergedLocation`, etc. However, pass writers need to intercede in cases 
where a code path is duplicated, e.g. unrolling, jump-threading. In these cases 
we want to emit key instructions in both the original and duplicated code, so 
the duplicate

[clang] [llvm] [KeyInstr] Add docs (PR #137991)

2025-07-14 Thread J. Ryan Stinnett via cfe-commits


@@ -0,0 +1,46 @@
+# Key Instructions in Clang
+
+Key Instructions is an LLVM feature that reduces the jumpiness of optimized 
code debug stepping. This document explains how Clang applies the necessary 
metadata.
+
+## Implementation
+
+See the [LLVM docs](../../llvm/docs/KeyInstructionsDebugInfo.md) for general 
info about the feature (and LLVM implementation details).
+
+Clang needs to annotate key instructions with the new metadata. Variable 
assignments (stores, memory intrinsics), control flow (branches and their 
conditions, some unconditional branches), and exception handling instructions 
are annotated. Calls are ignored as they're unconditionally marked `is_stmt`. 
This is achieved with a few simple constructs:
+
+Class `ApplyAtomGroup` - This is a scoped helper similar to 
`ApplyDebugLocation` that creates a new source atom group which instructions 
can be added to. It's used during CodeGen to declare that a new source atom has 
started, e.g. in `CodeGenFunction::EmitBinaryOperatorLValue`.
+
+`CodeGenFunction::addInstToCurrentSourceAtom(llvm::Instruction 
*KeyInstruction, llvm::Value *Backup)` adds an instruction (and a backup 
instruction if non-null) to the current "atom group" defined with 
`ApplyAtomGroup`. The Key Instruction gets rank 1, and backup instructions get 
higher ranks (the function looks through casts, applying increasing rank as it 
goes). There are a lot of sites in Clang that need to call this (mostly stores 
and store-like instructions). FIXME?: Currently it's called at the CGBuilderTy 
callsites; it could instead make sense to always call the function inside the 
CGBuilderTy calls, with some calls opting out.

jryans wrote:

```suggestion
`CodeGenFunction::addInstToCurrentSourceAtom(llvm::Instruction *KeyInstruction, 
llvm::Value *Backup)` adds an instruction (and a backup instruction if 
non-null) to the current "atom group" defined with `ApplyAtomGroup`. The Key 
Instruction gets rank 1, and backup instructions get higher ranks (the function 
looks through casts, applying increasing rank as it goes). There are a lot of 
sites in Clang that need to call this (mostly stores and store-like 
instructions). FIXME?: Currently it's called at the `CGBuilderTy` callsites; it 
could instead make sense to always call the function inside the `CGBuilderTy` 
calls, with some calls opting out.
```

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


[clang] [llvm] [KeyInstr] Add docs (PR #137991)

2025-07-14 Thread J. Ryan Stinnett via cfe-commits


@@ -0,0 +1,114 @@
+# Key Instructions debug info in LLVM
+
+Key Instructions reduces the jumpiness of optimized code debug stepping. This 
document explains the feature and how it is implemented in LLVM. For Clang 
support please see the [Clang docs](../../clang/docs/KeyInstructionsClang.md)
+
+## Status
+
+In development, but mostly complete. The feature is currently disabled for 
coroutines.
+
+Tell Clang [not] to produce Key Instructions metadata with 
`-g[no-]key-instructions`. See the Clang docs for implementation info.
+
+The feature improves optimized code stepping; it's intended for the feature to 
be used with optimisations enabled. Although the feature works at O0 it is not 
recommended because in some cases the effect of editing variables may not 
always be immediately realised. (This is a quirk of the current implementation, 
rather than fundemental limitation, covered in more detail later).
+
+This is a DWARF-based feature. There is currently no plan to support CodeView.
+
+Set LLVM flag `-dwarf-use-key-instructions` to `false` to ignore Key 
Instructions metadata when emitting DWARF.
+
+## Problem statement
+
+A lot of the noise in stepping comes from code motion and instruction 
scheduling. Consider a long expression on a single line. It may involve 
multiple operations that optimisations move, re-order, and interleave with 
other instructions that have different line numbers.
+
+DWARF provides a helpful tool the compiler can employ to mitigate this 
jumpiness, the `is_stmt` flag, which indicates that an instruction is a 
recommended breakpoint location. However, LLVM's current approach to deciding 
`is_stmt` placement essentially reduces down to "is the associated line number 
different to the previous instruction's?".
+
+(Note: It's up to the debugger if it wants to interpret `is_stmt` or not, and 
at time of writing LLDB doesn't; possibly because until now LLVM's is_stmts 
convey no information that can't already be deduced from the rest of the line 
table.)

jryans wrote:

```suggestion
(Note: It's up to the debugger if it wants to interpret `is_stmt` or not, and 
at time of writing LLDB doesn't; possibly because until now LLVM's `is_stmt`s 
convey no information that can't already be deduced from the rest of the line 
table.)
```

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


[clang] [llvm] [KeyInstr] Add docs (PR #137991)

2025-07-14 Thread J. Ryan Stinnett via cfe-commits


@@ -0,0 +1,114 @@
+# Key Instructions debug info in LLVM
+
+Key Instructions reduces the jumpiness of optimized code debug stepping. This 
document explains the feature and how it is implemented in LLVM. For Clang 
support please see the [Clang docs](../../clang/docs/KeyInstructionsClang.md)
+
+## Status
+
+In development, but mostly complete. The feature is currently disabled for 
coroutines.
+
+Tell Clang [not] to produce Key Instructions metadata with 
`-g[no-]key-instructions`. See the Clang docs for implementation info.
+
+The feature improves optimized code stepping; it's intended for the feature to 
be used with optimisations enabled. Although the feature works at O0 it is not 
recommended because in some cases the effect of editing variables may not 
always be immediately realised. (This is a quirk of the current implementation, 
rather than fundemental limitation, covered in more detail later).
+
+This is a DWARF-based feature. There is currently no plan to support CodeView.
+
+Set LLVM flag `-dwarf-use-key-instructions` to `false` to ignore Key 
Instructions metadata when emitting DWARF.
+
+## Problem statement
+
+A lot of the noise in stepping comes from code motion and instruction 
scheduling. Consider a long expression on a single line. It may involve 
multiple operations that optimisations move, re-order, and interleave with 
other instructions that have different line numbers.
+
+DWARF provides a helpful tool the compiler can employ to mitigate this 
jumpiness, the `is_stmt` flag, which indicates that an instruction is a 
recommended breakpoint location. However, LLVM's current approach to deciding 
`is_stmt` placement essentially reduces down to "is the associated line number 
different to the previous instruction's?".
+
+(Note: It's up to the debugger if it wants to interpret `is_stmt` or not, and 
at time of writing LLDB doesn't; possibly because until now LLVM's is_stmts 
convey no information that can't already be deduced from the rest of the line 
table.)
+
+## Solution overview
+
+Taking ideas from two papers [1][2] that explore the issue, especially C. 
Tice's:
+
+From the perspective of a source-level debugger user:
+
+* Source code is made up of interesting constructs; the level of granularity 
for “interesting” while stepping is typically assignments, calls, control flow. 
We’ll call these interesting constructs Atoms.
+
+* Atoms usually have one instruction that implements the functionality that a 
user can observe; once they step “off” that instruction, the atom is finalised. 
We’ll call that a Key Instruction.
+
+* Communicating where the key instructions are to the debugger (using DWARF’s 
is_stmt) avoids jumpiness introduced by scheduling non-key instructions without 
losing source attribution (because non-key instructions retain an associated 
source location, they’re just ignored for stepping).
+
+## Solution implementation
+
+1. `DILocation` has 2 new fields, `atomGroup` and `atomRank`. `DISubprogram` 
has a new field `keyInstructions`.
+2. Clang creates `DILocations` using the new fields to communicate which 
instructions are "interesting", and sets `keyInstructions` true in 
`DISubprogram`s to tell LLVM to interpret the new metadata in those functions.
+3. There’s some bookkeeping required by optimisations that duplicate control 
flow.
+4. During DWARF emission, the new metadata is collected (linear scan over 
instructions) to decide `is_stmt` placements.
+
+1. *The metadata* - The two new `DILocation` fields are `atomGroup` and 
`atomRank` and are both are unsigned integers. `atomGroup` is 61 bits and 
`atomRank` 3 bits. Instructions in the same function with the same `(atomGroup, 
inlinedAt)` pair are part of the same source atom. `atomRank` determines 
`is_stmt` preference within that group, where a lower number is higher 
precedence. Higher rank instructions act as "backup" `is_stmt` locations, 
providing good fallback locations if/when the primary candidate gets optimized 
away. The default values of 0 indicate the instruction isn’t interesting - it's 
not an `is_stmt` candidate. If `keyInstructions` in `DISubprogram` is false 
(default) then the new `DILocation` metadata is ignored for the function 
(including inlined instances) when emitting DWARF.
+
+2. *Clang annotates key instructions* with the new metadata. Variable 
assignments (stores, memory intrinsics), control flow (branches and their 
conditions, some unconditional branches), and exception handling instructions 
are annotated. Calls are ignored as they're unconditionally marked is_stmt.

jryans wrote:

```suggestion
2. *Clang annotates key instructions* with the new metadata. Variable 
assignments (stores, memory intrinsics), control flow (branches and their 
conditions, some unconditional branches), and exception handling instructions 
are annotated. Calls are ignored as they're unconditionally marked `is_stmt`.
```

https://github.com/llvm/llvm-project/pull/137991

[clang] [llvm] [KeyInstr] Add docs (PR #137991)

2025-07-14 Thread J. Ryan Stinnett via cfe-commits


@@ -0,0 +1,114 @@
+# Key Instructions debug info in LLVM
+
+Key Instructions reduces the jumpiness of optimized code debug stepping. This 
document explains the feature and how it is implemented in LLVM. For Clang 
support please see the [Clang docs](../../clang/docs/KeyInstructionsClang.md)
+
+## Status
+
+In development, but mostly complete. The feature is currently disabled for 
coroutines.
+
+Tell Clang [not] to produce Key Instructions metadata with 
`-g[no-]key-instructions`. See the Clang docs for implementation info.
+
+The feature improves optimized code stepping; it's intended for the feature to 
be used with optimisations enabled. Although the feature works at O0 it is not 
recommended because in some cases the effect of editing variables may not 
always be immediately realised. (This is a quirk of the current implementation, 
rather than fundemental limitation, covered in more detail later).

jryans wrote:

Maybe move full stop inside parens...?

```suggestion
The feature improves optimized code stepping; it's intended for the feature to 
be used with optimisations enabled. Although the feature works at O0 it is not 
recommended because in some cases the effect of editing variables may not 
always be immediately realised. (This is a quirk of the current implementation, 
rather than fundemental limitation, covered in more detail later.)
```

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


[clang] [llvm] [KeyInstr] Add docs (PR #137991)

2025-07-14 Thread J. Ryan Stinnett via cfe-commits


@@ -0,0 +1,114 @@
+# Key Instructions debug info in LLVM
+
+Key Instructions reduces the jumpiness of optimized code debug stepping. This 
document explains the feature and how it is implemented in LLVM. For Clang 
support please see the [Clang docs](../../clang/docs/KeyInstructionsClang.md)
+
+## Status
+
+In development, but mostly complete. The feature is currently disabled for 
coroutines.

jryans wrote:

Perhaps briefly explain why it's disabled for coroutines...? Seems a bit random 
without any explanation.

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


[clang] [llvm] [KeyInstr] Add docs (PR #137991)

2025-07-14 Thread J. Ryan Stinnett via cfe-commits


@@ -0,0 +1,114 @@
+# Key Instructions debug info in LLVM
+
+Key Instructions reduces the jumpiness of optimized code debug stepping. This 
document explains the feature and how it is implemented in LLVM. For Clang 
support please see the [Clang docs](../../clang/docs/KeyInstructionsClang.md)
+
+## Status
+
+In development, but mostly complete. The feature is currently disabled for 
coroutines.
+
+Tell Clang [not] to produce Key Instructions metadata with 
`-g[no-]key-instructions`. See the Clang docs for implementation info.
+
+The feature improves optimized code stepping; it's intended for the feature to 
be used with optimisations enabled. Although the feature works at O0 it is not 
recommended because in some cases the effect of editing variables may not 
always be immediately realised. (This is a quirk of the current implementation, 
rather than fundemental limitation, covered in more detail later).
+
+This is a DWARF-based feature. There is currently no plan to support CodeView.
+
+Set LLVM flag `-dwarf-use-key-instructions` to `false` to ignore Key 
Instructions metadata when emitting DWARF.
+
+## Problem statement
+
+A lot of the noise in stepping comes from code motion and instruction 
scheduling. Consider a long expression on a single line. It may involve 
multiple operations that optimisations move, re-order, and interleave with 
other instructions that have different line numbers.
+
+DWARF provides a helpful tool the compiler can employ to mitigate this 
jumpiness, the `is_stmt` flag, which indicates that an instruction is a 
recommended breakpoint location. However, LLVM's current approach to deciding 
`is_stmt` placement essentially reduces down to "is the associated line number 
different to the previous instruction's?".
+
+(Note: It's up to the debugger if it wants to interpret `is_stmt` or not, and 
at time of writing LLDB doesn't; possibly because until now LLVM's is_stmts 
convey no information that can't already be deduced from the rest of the line 
table.)
+
+## Solution overview
+
+Taking ideas from two papers [1][2] that explore the issue, especially C. 
Tice's:
+
+From the perspective of a source-level debugger user:
+
+* Source code is made up of interesting constructs; the level of granularity 
for “interesting” while stepping is typically assignments, calls, control flow. 
We’ll call these interesting constructs Atoms.
+
+* Atoms usually have one instruction that implements the functionality that a 
user can observe; once they step “off” that instruction, the atom is finalised. 
We’ll call that a Key Instruction.
+
+* Communicating where the key instructions are to the debugger (using DWARF’s 
is_stmt) avoids jumpiness introduced by scheduling non-key instructions without 
losing source attribution (because non-key instructions retain an associated 
source location, they’re just ignored for stepping).
+
+## Solution implementation
+
+1. `DILocation` has 2 new fields, `atomGroup` and `atomRank`. `DISubprogram` 
has a new field `keyInstructions`.
+2. Clang creates `DILocations` using the new fields to communicate which 
instructions are "interesting", and sets `keyInstructions` true in 
`DISubprogram`s to tell LLVM to interpret the new metadata in those functions.
+3. There’s some bookkeeping required by optimisations that duplicate control 
flow.
+4. During DWARF emission, the new metadata is collected (linear scan over 
instructions) to decide `is_stmt` placements.
+
+1. *The metadata* - The two new `DILocation` fields are `atomGroup` and 
`atomRank` and are both are unsigned integers. `atomGroup` is 61 bits and 
`atomRank` 3 bits. Instructions in the same function with the same `(atomGroup, 
inlinedAt)` pair are part of the same source atom. `atomRank` determines 
`is_stmt` preference within that group, where a lower number is higher 
precedence. Higher rank instructions act as "backup" `is_stmt` locations, 
providing good fallback locations if/when the primary candidate gets optimized 
away. The default values of 0 indicate the instruction isn’t interesting - it's 
not an `is_stmt` candidate. If `keyInstructions` in `DISubprogram` is false 
(default) then the new `DILocation` metadata is ignored for the function 
(including inlined instances) when emitting DWARF.
+
+2. *Clang annotates key instructions* with the new metadata. Variable 
assignments (stores, memory intrinsics), control flow (branches and their 
conditions, some unconditional branches), and exception handling instructions 
are annotated. Calls are ignored as they're unconditionally marked is_stmt.
+
+3. *Throughout optimisation*, the `DILocation` is propagated normally. Cloned 
instructions get the original’s `DILocation`, the new fields get merged in 
`getMergedLocation`, etc. However, pass writers need to intercede in cases 
where a code path is duplicated, e.g. unrolling, jump-threading. In these cases 
we want to emit key instructions in both the original and duplicated code, so 
the duplicate

[clang] [llvm] [KeyInstr] Add docs (PR #137991)

2025-07-14 Thread J. Ryan Stinnett via cfe-commits

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


[clang] [llvm] [KeyInstr] Add docs (PR #137991)

2025-07-14 Thread J. Ryan Stinnett via cfe-commits

https://github.com/jryans commented:

Overall, looks good. Most of my comments are stylistic nits.

I do think it's important to link to this new feature from the "how to updated 
debug info" page, as without that, pass writers (esp. in the future) are quite 
unlikely to know they need to do some work for this feature.

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


[clang] [llvm] [KeyInstr] Add docs (PR #137991)

2025-07-14 Thread J. Ryan Stinnett via cfe-commits


@@ -187,6 +192,10 @@ Optimizations
This is a migration guide describing how to move from debug info using
intrinsics such as dbg.value to using the non-instruction DbgRecord object.
 
+:doc: `KeyInstructionsDebugInfo`

jryans wrote:

Same question about the space here as well.

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


[clang-tools-extra] [clang-tidy] Make `bugprone-unhandled-self-assignment` check more general (PR #147066)

2025-07-14 Thread Andrey Karlov via cfe-commits


@@ -69,6 +69,22 @@ void 
UnhandledSelfAssignmentCheck::registerMatchers(MatchFinder *Finder) {
   
cxxMethodDecl(unless(hasDescendant(cxxMemberCallExpr(callee(cxxMethodDecl(
   hasName("operator="), ofClass(equalsBoundNode("class";
 
+  // Checking that some kind of constructor is called and followed by a `swap`:
+  // T& operator=(const T& other) {
+  //T tmp{this->internal_data(), some, other, args};
+  //swap(tmp);
+  //return *this;
+  // }
+  const auto HasCopyAndSwap = cxxMethodDecl(
+  ofClass(cxxRecordDecl(unless(hasAncestor(classTemplateDecl(),
+  hasDescendant(
+  stmt(hasDescendant(
+   varDecl(hasType(cxxRecordDecl(equalsBoundNode("class"
+   .bind("tmp_var")),
+   hasDescendant(callExpr(callee(functionDecl(hasName("swap"))),
+  hasAnyArgument(declRefExpr(to(varDecl(
+  equalsBoundNode("tmp_var"));

negativ wrote:

@5chmidti fixed as suggested. thank you!

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


[clang] [Clang] Do not emit -Wmissing-noreturn when [[noreturn]] is present (PR #148552)

2025-07-14 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`openmp-gcc-x86_64-linux-debian` running on `gribozavr4` while building `clang` 
at step 6 "test-openmp".

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


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

```
Step 6 (test-openmp) failure: test (failure)
 TEST 'libomp :: tasking/issue-94260-2.c' FAILED 

Exit Code: -11

Command Output (stdout):
--
# RUN: at line 1
/b/1/openmp-gcc-x86_64-linux-debian/llvm.build/./bin/clang -fopenmp   -I 
/b/1/openmp-gcc-x86_64-linux-debian/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -I /b/1/openmp-gcc-x86_64-linux-debian/llvm.src/openmp/runtime/test -L 
/b/1/openmp-gcc-x86_64-linux-debian/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
  -fno-omit-frame-pointer -I 
/b/1/openmp-gcc-x86_64-linux-debian/llvm.src/openmp/runtime/test/ompt 
/b/1/openmp-gcc-x86_64-linux-debian/llvm.src/openmp/runtime/test/tasking/issue-94260-2.c
 -o 
/b/1/openmp-gcc-x86_64-linux-debian/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
 -lm -latomic && 
/b/1/openmp-gcc-x86_64-linux-debian/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
# executed command: /b/1/openmp-gcc-x86_64-linux-debian/llvm.build/./bin/clang 
-fopenmp -I 
/b/1/openmp-gcc-x86_64-linux-debian/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -I /b/1/openmp-gcc-x86_64-linux-debian/llvm.src/openmp/runtime/test -L 
/b/1/openmp-gcc-x86_64-linux-debian/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -fno-omit-frame-pointer -I 
/b/1/openmp-gcc-x86_64-linux-debian/llvm.src/openmp/runtime/test/ompt 
/b/1/openmp-gcc-x86_64-linux-debian/llvm.src/openmp/runtime/test/tasking/issue-94260-2.c
 -o 
/b/1/openmp-gcc-x86_64-linux-debian/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
 -lm -latomic
# executed command: 
/b/1/openmp-gcc-x86_64-linux-debian/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
# note: command had no output on stdout or stderr
# error: command failed with exit status: -11

--




```



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


  1   2   3   4   5   >