[clang] [clang-format] Add an option for editing enum trailing commas (PR #133576)

2025-03-29 Thread Owen Pan via cfe-commits

owenca wrote:

> Should this get the same warning as the other non white space changes?

Absolutely!

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


[clang] [clang-format]: Add `StaticInlineOnly` and `StaticInline` options to `ShortFunctionStyle` (PR #133598)

2025-03-29 Thread Björn Schäpers via cfe-commits


@@ -335,6 +336,32 @@ class LineJoiner {
 }
   }
 
+  if (Style.AllowShortFunctionsOnASingleLine ==
+  FormatStyle::SFS_StaticInlineOnly ||
+  Style.AllowShortFunctionsOnASingleLine ==
+  FormatStyle::SFS_StaticInline) {
+// Check if the current line belongs to a static inline function
+const auto *FirstNonCommentToken =
+TheLine ? TheLine->getFirstNonComment() : nullptr;
+
+// Look for 'static' and 'inline' keywords in any order
+bool HasStatic = false;
+bool HasInline = false;
+const FormatToken *Tok = FirstNonCommentToken;
+
+while (Tok && !Tok->is(TT_FunctionLBrace)) {
+  if (Tok->is(tok::kw_static))
+HasStatic = true;
+  if (Tok->is(tok::kw_inline))
+HasInline = true;
+  Tok = Tok->Next;
+}
+
+// If we found both static and inline, allow merging

HazardyKnusperkeks wrote:

```suggestion
// If we found both static and inline, allow merging.
```

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


[clang] [clang-format] Add an option for editing enum trailing commas (PR #133576)

2025-03-29 Thread Björn Schäpers via cfe-commits

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

Should this get the same warning as the other non white space changes?

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


[clang] cuda clang: Add support for CUDA surfaces (PR #132883)

2025-03-29 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff HEAD~1 HEAD --extensions h -- 
clang/test/Headers/Inputs/include/surface_indirect_functions.h 
clang/lib/Headers/__clang_cuda_runtime_wrapper.h 
clang/lib/Headers/__clang_cuda_texture_intrinsics.h 
clang/test/Headers/Inputs/include/cuda.h
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Headers/__clang_cuda_runtime_wrapper.h 
b/clang/lib/Headers/__clang_cuda_runtime_wrapper.h
index 8182c961e..44934ba2c 100644
--- a/clang/lib/Headers/__clang_cuda_runtime_wrapper.h
+++ b/clang/lib/Headers/__clang_cuda_runtime_wrapper.h
@@ -384,9 +384,9 @@ __host__ __device__ void __nv_tex_surf_handler(const char 
*name, T *ptr,
 // will continue to fail as it does now.
 #endif // CUDA_VERSION
 #endif // __cplusplus >= 201103L && CUDA_VERSION >= 9000
+#include "surface_indirect_functions.h"
 #include "texture_fetch_functions.h"
 #include "texture_indirect_functions.h"
-#include "surface_indirect_functions.h"
 
 // Restore state of __CUDA_ARCH__ and __THROW we had on entry.
 #pragma pop_macro("__CUDA_ARCH__")
diff --git a/clang/lib/Headers/__clang_cuda_texture_intrinsics.h 
b/clang/lib/Headers/__clang_cuda_texture_intrinsics.h
index 618ac70ee..85db301e0 100644
--- a/clang/lib/Headers/__clang_cuda_texture_intrinsics.h
+++ b/clang/lib/Headers/__clang_cuda_texture_intrinsics.h
@@ -104,7 +104,6 @@
 #pragma push_macro("__3DV2");
 #pragma push_macro("__3DV4");
 
-
 // Put all functions into anonymous namespace so they have internal linkage.
 // The device-only function here must be internal in order to avoid ODR
 // violations in case they are used from the files compiled with
@@ -250,14 +249,15 @@ struct __texture_op_tag {};
 struct __surface_op_tag {};
 
 // Template specialization to determine operation type based on tag value
-template 
-struct __op_type_traits {
+template  struct __op_type_traits {
   using type = __texture_op_tag;
 };
 
 // Specialize for known surface operation tags
-#define __OP_TYPE_SURFACE(__op) \
-template <> struct __op_type_traits<__op> { using type = __surface_op_tag; 
};
+#define __OP_TYPE_SURFACE(__op)
\
+  template <> struct __op_type_traits<__op> {  
\
+using type = __surface_op_tag; 
\
+  };
 
 // Classes that implement specific texture ops.
 template  struct __tex_fetch_v4;
@@ -722,10 +722,11 @@ template  struct __convert {
   }
 };
 
-// There are a couple of layers here.  First, __op_type_traits is used to 
dispatch to either surface write calls, or to
-// the texture read calls.
+// There are a couple of layers here.  First, __op_type_traits is used to
+// dispatch to either surface write calls, or to the texture read calls.
 //
-// Then, that dispatches to __tex_fetch_impl below, which dispatches by both 
tag and datatype to the appropriate
+// Then, that dispatches to __tex_fetch_impl below, which dispatches by both 
tag
+// and datatype to the appropriate
 // __surf_read_write_v2.
 // TODO(austin): Do the reads too.
 
@@ -745,95 +746,105 @@ __OP_TYPE_SURFACE(__ID("__isurf2DLayeredwrite_v2"));
 __OP_TYPE_SURFACE(__ID("__isurfCubemapwrite_v2"));
 __OP_TYPE_SURFACE(__ID("__isurfCubemapLayeredwrite_v2"));
 
-template 
-struct __surf_read_write_v2;
-
-// For the various write calls, we need to be able to generate variations with 
different IDs, different numbers of
-// arguments, and different numbers of outputs.
-
-#define __SURF_WRITE_V2(__op, __asm_dim, __asmtype, __type, __index_op_args, 
__index_args, __index_asm_args,  \
-__asm_op_args, __asm_args) 
   \
-template <>
   \
-struct __surf_read_write_v2<__op, __type> {
   \
-static __device__ void __run(__type *__ptr, cudaSurfaceObject_t obj, 
__L(__index_args),   \
- cudaSurfaceBoundaryMode mode) {   
   \
-switch (mode) {
   \
-case cudaBoundaryModeZero: 
   \
-asm volatile("sust.b." __asm_dim "." __asmtype ".zero [%0, 
" __index_op_args "], " __asm_op_args  \
- ";"   
   \
- : 
  

[clang] [clang-format]: Add `StaticInlineOnly` and `StaticInline` options to `ShortFunctionStyle` (PR #133598)

2025-03-29 Thread via cfe-commits


@@ -335,6 +336,32 @@ class LineJoiner {
 }
   }
 
+  if (Style.AllowShortFunctionsOnASingleLine ==
+  FormatStyle::SFS_StaticInlineOnly ||
+  Style.AllowShortFunctionsOnASingleLine ==
+  FormatStyle::SFS_StaticInline) {
+// Check if the current line belongs to a static inline function
+const auto *FirstNonCommentToken =
+TheLine ? TheLine->getFirstNonComment() : nullptr;
+
+// Look for 'static' and 'inline' keywords in any order
+bool HasStatic = false;
+bool HasInline = false;
+const FormatToken *Tok = FirstNonCommentToken;
+
+while (Tok && !Tok->is(TT_FunctionLBrace)) {

irymarchyk wrote:

Seems like the name is sufficient. Thanks for idea. I've made a fix; please 
take a look.

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


[clang] [clang-format]: Add `StaticInlineOnly` and `StaticInline` options to `ShortFunctionStyle` (PR #133598)

2025-03-29 Thread via cfe-commits


@@ -335,6 +336,32 @@ class LineJoiner {
 }
   }
 
+  if (Style.AllowShortFunctionsOnASingleLine ==
+  FormatStyle::SFS_StaticInlineOnly ||
+  Style.AllowShortFunctionsOnASingleLine ==
+  FormatStyle::SFS_StaticInline) {
+// Check if the current line belongs to a static inline function
+const auto *FirstNonCommentToken =
+TheLine ? TheLine->getFirstNonComment() : nullptr;
+
+// Look for 'static' and 'inline' keywords in any order

irymarchyk wrote:

Thanks, fixed

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


[clang] [clang-format]: Add `StaticInlineOnly` and `StaticInline` options to `ShortFunctionStyle` (PR #133598)

2025-03-29 Thread Owen Pan via cfe-commits

owenca wrote:

If @mydeveloperday doesn't object to adding more choices to 
`AllowShortFunctionsOnASingleLine`, I'd like to see it extended to handle a 
custom `struct` first, similar to `SBPO_Custom` for example.

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


[clang] [clang-format] Add an option for editing enum trailing commas (PR #133576)

2025-03-29 Thread Owen Pan via cfe-commits

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

>From 3b352123c47cb382539fefc1bcd49228c17d994f Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sat, 29 Mar 2025 00:30:49 -0700
Subject: [PATCH 1/2] [clang-format] Add an option for editing enum trailing
 commas

---
 clang/docs/ClangFormatStyleOptions.rst | 34 ++
 clang/docs/ReleaseNotes.rst|  2 +
 clang/include/clang/Format/Format.h| 28 
 clang/lib/Format/Format.cpp| 76 ++
 clang/unittests/Format/ConfigParseTest.cpp |  8 +++
 clang/unittests/Format/FormatTest.cpp  | 32 +
 6 files changed, 180 insertions(+)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 9ecac68ae72bf..211bb3eeeb6e6 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -3976,6 +3976,40 @@ the configuration (without a prefix: ``Auto``).
 
 
 
+.. _EnumTrailingComma:
+
+**EnumTrailingComma** (``EnumTrailingCommaStyle``) :versionbadge:`clang-format 
21` :ref:`¶ `
+  Insert a comma (if missing) or remove the comma at the end of an ``enum``
+  enumerator list.
+
+  Possible values:
+
+  * ``ETC_Leave`` (in configuration: ``Leave``)
+Don't insert or remove trailing commas.
+
+.. code-block:: c++
+
+  enum { a, b, c, };
+  enum Color { red, green, blue };
+
+  * ``ETC_Insert`` (in configuration: ``Insert``)
+Insert trailing commas.
+
+.. code-block:: c++
+
+  enum { a, b, c, };
+  enum Color { red, green, blue, };
+
+  * ``ETC_Remove`` (in configuration: ``Remove``)
+Remove trailing commas.
+
+.. code-block:: c++
+
+  enum { a, b, c };
+  enum Color { red, green, blue };
+
+
+
 .. _ExperimentalAutoDetectBinPacking:
 
 **ExperimentalAutoDetectBinPacking** (``Boolean``) :versionbadge:`clang-format 
3.7` :ref:`¶ `
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 04ec2cfef679c..27f6a93e31643 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -480,6 +480,8 @@ clang-format
 - Allow specifying the language (C, C++, or Objective-C) for a ``.h`` file by
   adding a special comment (e.g. ``// clang-format Language: ObjC``) near the
   top of the file.
+- Add ``EnumTrailingComma`` option for inserting/removing commas at the end of
+  ``enum`` enumerator lists.
 
 libclang
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index fec47a248abb4..c39006c0d6361 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2704,6 +2704,33 @@ struct FormatStyle {
   /// \version 12
   EmptyLineBeforeAccessModifierStyle EmptyLineBeforeAccessModifier;
 
+  /// Styles for ``enum`` trailing commas.
+  enum EnumTrailingCommaStyle : int8_t {
+/// Don't insert or remove trailing commas.
+/// \code
+///   enum { a, b, c, };
+///   enum Color { red, green, blue };
+/// \endcode
+ETC_Leave,
+/// Insert trailing commas.
+/// \code
+///   enum { a, b, c, };
+///   enum Color { red, green, blue, };
+/// \endcode
+ETC_Insert,
+/// Remove trailing commas.
+/// \code
+///   enum { a, b, c };
+///   enum Color { red, green, blue };
+/// \endcode
+ETC_Remove,
+  };
+
+  /// Insert a comma (if missing) or remove the comma at the end of an ``enum``
+  /// enumerator list.
+  /// \version 21
+  EnumTrailingCommaStyle EnumTrailingComma;
+
   /// If ``true``, clang-format detects whether function calls and
   /// definitions are formatted with one parameter per line.
   ///
@@ -5323,6 +5350,7 @@ struct FormatStyle {
DisableFormat == R.DisableFormat &&
EmptyLineAfterAccessModifier == R.EmptyLineAfterAccessModifier &&
EmptyLineBeforeAccessModifier == R.EmptyLineBeforeAccessModifier &&
+   EnumTrailingComma == R.EnumTrailingComma &&
ExperimentalAutoDetectBinPacking ==
R.ExperimentalAutoDetectBinPacking &&
FixNamespaceComments == R.FixNamespaceComments &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 28aea86139e0d..5a875b8693574 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -361,6 +361,15 @@ struct ScalarEnumerationTraits<
   }
 };
 
+template <>
+struct ScalarEnumerationTraits {
+  static void enumeration(IO &IO, FormatStyle::EnumTrailingCommaStyle &Value) {
+IO.enumCase(Value, "Leave", FormatStyle::ETC_Leave);
+IO.enumCase(Value, "Insert", FormatStyle::ETC_Insert);
+IO.enumCase(Value, "Remove", FormatStyle::ETC_Remove);
+  }
+};
+
 template <>
 struct ScalarEnumerationTraits {
   static void enumeration(IO &IO, FormatStyle::IndentExternBlockStyle &Value) {
@@ -1042,6 +1051,7 @@ template <> struct MappingTraits {
Style.EmptyLineAfterAccessModifier);
 IO.mapOptional("EmptyLineBeforeAccessMo

[clang] [llvm] [Clang] [OpenMP] Support NOWAIT with optional argument (PR #128742)

2025-03-29 Thread via cfe-commits

https://github.com/jadhbeika updated 
https://github.com/llvm/llvm-project/pull/128742

>From fa3dd1423e4bf2209feb9713f1833e653ec43a74 Mon Sep 17 00:00:00 2001
From: Jad Hbeika 
Date: Wed, 19 Feb 2025 12:53:11 -0800
Subject: [PATCH 1/2] [Clang] [OpenMP] Support NOWAIT with optional argument

---
 clang/include/clang/AST/OpenMPClause.h| 58 ---
 clang/include/clang/AST/RecursiveASTVisitor.h |  3 +-
 clang/include/clang/Sema/SemaOpenMP.h |  6 +-
 clang/lib/AST/OpenMPClause.cpp| 11 +++-
 clang/lib/AST/StmtProfile.cpp |  5 +-
 clang/lib/Parse/ParseOpenMP.cpp   |  5 +-
 clang/lib/Sema/SemaOpenMP.cpp | 24 +++-
 clang/lib/Sema/TreeTransform.h| 21 ++-
 clang/lib/Serialization/ASTReader.cpp |  5 +-
 clang/lib/Serialization/ASTWriter.cpp |  5 +-
 clang/tools/libclang/CIndex.cpp   |  4 +-
 llvm/include/llvm/Frontend/OpenMP/OMP.td  |  2 +
 12 files changed, 127 insertions(+), 22 deletions(-)

diff --git a/clang/include/clang/AST/OpenMPClause.h 
b/clang/include/clang/AST/OpenMPClause.h
index 154ecfbaa4418..b29fce9bd9729 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -2173,18 +2173,62 @@ class OMPOrderedClause final
 /// This represents 'nowait' clause in the '#pragma omp ...' directive.
 ///
 /// \code
-/// #pragma omp for nowait
+/// #pragma omp for nowait (cond)
 /// \endcode
-/// In this example directive '#pragma omp for' has 'nowait' clause.
-class OMPNowaitClause final : public OMPNoChildClause {
+/// In this example directive '#pragma omp for' has simple 'nowait' clause with
+/// condition 'cond'.
+class OMPNowaitClause final : public OMPClause {
+  friend class OMPClauseReader;
+
+  /// Location of '('.
+  SourceLocation LParenLoc;
+
+  /// Condition of the 'nowait' clause.
+  Stmt *Condition = nullptr;
+
+  /// Set condition.
+  void setCondition(Expr *Cond) { Condition = Cond; }
+
 public:
-  /// Build 'nowait' clause.
+  /// Build 'nowait' clause with condition \a Cond.
   ///
+  /// \param Cond Condition of the clause.
   /// \param StartLoc Starting location of the clause.
+  /// \param LParenLoc Location of '('.
   /// \param EndLoc Ending location of the clause.
-  OMPNowaitClause(SourceLocation StartLoc = SourceLocation(),
-  SourceLocation EndLoc = SourceLocation())
-  : OMPNoChildClause(StartLoc, EndLoc) {}
+  OMPNowaitClause(Expr *Cond, SourceLocation StartLoc, SourceLocation 
LParenLoc,
+  SourceLocation EndLoc)
+  : OMPClause(llvm::omp::OMPC_nowait, StartLoc, EndLoc),
+LParenLoc(LParenLoc), Condition(Cond) {}
+
+  /// Build an empty clause.
+  OMPNowaitClause()
+  : OMPClause(llvm::omp::OMPC_nowait, SourceLocation(), SourceLocation()) 
{}
+
+  /// Sets the location of '('.
+  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
+
+  /// Returns the location of '('.
+  SourceLocation getLParenLoc() const { return LParenLoc; }
+
+  /// Returns condition.
+  Expr *getCondition() const { return cast_or_null(Condition); }
+
+  child_range children() { return child_range(&Condition, &Condition + 1); }
+
+  const_child_range children() const {
+return const_child_range(&Condition, &Condition + 1);
+  }
+
+  child_range used_children();
+  const_child_range used_children() const {
+auto Children = const_cast(this)->used_children();
+return const_child_range(Children.begin(), Children.end());
+  }
+
+  static bool classof(const OMPClause *T) {
+return T->getClauseKind() == llvm::omp::OMPC_nowait;
+  }
 };
 
 /// This represents 'untied' clause in the '#pragma omp ...' directive.
diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index 560de7da9913a..52b940e7f3c0a 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -3466,7 +3466,8 @@ bool 
RecursiveASTVisitor::VisitOMPOrderedClause(OMPOrderedClause *C) {
 }
 
 template 
-bool RecursiveASTVisitor::VisitOMPNowaitClause(OMPNowaitClause *) {
+bool RecursiveASTVisitor::VisitOMPNowaitClause(OMPNowaitClause *C) {
+  TRY_TO(TraverseStmt(C->getCondition()));
   return true;
 }
 
diff --git a/clang/include/clang/Sema/SemaOpenMP.h 
b/clang/include/clang/Sema/SemaOpenMP.h
index 64f0cfa0676af..8af56c087a896 100644
--- a/clang/include/clang/Sema/SemaOpenMP.h
+++ b/clang/include/clang/Sema/SemaOpenMP.h
@@ -1001,8 +1001,10 @@ class SemaOpenMP : public SemaBase {
   OMPClause *ActOnOpenMPClause(OpenMPClauseKind Kind, SourceLocation StartLoc,
SourceLocation EndLoc);
   /// Called on well-formed 'nowait' clause.
-  OMPClause *ActOnOpenMPNowaitClause(SourceLocation StartLoc,
- SourceLocation EndLoc);
+  OMPClause *
+  ActOnOpenMPNowaitClause(SourceLocation StartLoc, SourceLocation EndLoc,
+  SourceLoc

[clang] [RFC] Initial implementation of P2719 (PR #113510)

2025-03-29 Thread Oliver Hunt via cfe-commits


@@ -2533,9 +2533,43 @@ bool CXXMethodDecl::isUsualDeallocationFunction(
   getOverloadedOperator() != OO_Array_Delete)

ojhunt wrote:

I've adopted them in a few places, and I'm renaming them to isAnyOperatorNew, 
isAnyOperatorDelete so it's less confusable with a function that checks 
OO_New/OO_Delete

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


[clang] [WebKit checkers] Treat Objective-C message send return value as safe (PR #133605)

2025-03-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-static-analyzer-1

Author: Ryosuke Niwa (rniwa)


Changes

Objective-C selectors are supposed to return autoreleased object. Treat these 
return values as safe.

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


6 Files Affected:

- (modified) 
clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefCallArgsChecker.cpp (+8) 
- (modified) 
clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLocalVarsChecker.cpp (+8) 
- (modified) clang/test/Analysis/Checkers/WebKit/objc-mock-types.h (+5) 
- (modified) clang/test/Analysis/Checkers/WebKit/unretained-call-args-arc.mm 
(+9) 
- (modified) clang/test/Analysis/Checkers/WebKit/unretained-call-args.mm (+9) 
- (modified) clang/test/Analysis/Checkers/WebKit/unretained-local-vars.mm 
(+13-2) 


``diff
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefCallArgsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefCallArgsChecker.cpp
index ce8f0df697b06..13088920cfa19 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefCallArgsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefCallArgsChecker.cpp
@@ -47,6 +47,7 @@ class RawPtrRefCallArgsChecker
   virtual std::optional isUnsafePtr(QualType) const = 0;
   virtual bool isSafePtr(const CXXRecordDecl *Record) const = 0;
   virtual bool isSafePtrType(const QualType type) const = 0;
+  virtual bool isSafeExpr(const Expr *) const { return false; }
   virtual const char *ptrKind() const = 0;
 
   void checkASTDecl(const TranslationUnitDecl *TUD, AnalysisManager &MGR,
@@ -233,6 +234,8 @@ class RawPtrRefCallArgsChecker
 return true;
   if (EFA.isACallToEnsureFn(ArgOrigin))
 return true;
+  if (isSafeExpr(ArgOrigin))
+return true;
   return false;
 });
   }
@@ -469,6 +472,11 @@ class UnretainedCallArgsChecker final : public 
RawPtrRefCallArgsChecker {
 return isRetainPtrType(type);
   }
 
+  bool isSafeExpr(const Expr *E) const final {
+return ento::cocoa::isCocoaObjectRef(E->getType()) &&
+   isa(E);
+  }
+
   const char *ptrKind() const final { return "unretained"; }
 };
 
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLocalVarsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLocalVarsChecker.cpp
index d413e33a490c5..9975d1a91b681 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLocalVarsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLocalVarsChecker.cpp
@@ -179,6 +179,7 @@ class RawPtrRefLocalVarsChecker
   virtual std::optional isUnsafePtr(const QualType T) const = 0;
   virtual bool isSafePtr(const CXXRecordDecl *) const = 0;
   virtual bool isSafePtrType(const QualType) const = 0;
+  virtual bool isSafeExpr(const Expr *) const { return false; }
   virtual const char *ptrKind() const = 0;
 
   void checkASTDecl(const TranslationUnitDecl *TUD, AnalysisManager &MGR,
@@ -300,6 +301,9 @@ class RawPtrRefLocalVarsChecker
 if (EFA.isACallToEnsureFn(InitArgOrigin))
   return true;
 
+if (isSafeExpr(InitArgOrigin))
+  return true;
+
 if (auto *Ref = llvm::dyn_cast(InitArgOrigin)) {
   if (auto *MaybeGuardian =
   dyn_cast_or_null(Ref->getFoundDecl())) {
@@ -426,6 +430,10 @@ class UnretainedLocalVarsChecker final : public 
RawPtrRefLocalVarsChecker {
   bool isSafePtrType(const QualType type) const final {
 return isRetainPtrType(type);
   }
+  bool isSafeExpr(const Expr *E) const final {
+return ento::cocoa::isCocoaObjectRef(E->getType()) &&
+   isa(E);
+  }
   const char *ptrKind() const final { return "unretained"; }
 };
 
diff --git a/clang/test/Analysis/Checkers/WebKit/objc-mock-types.h 
b/clang/test/Analysis/Checkers/WebKit/objc-mock-types.h
index ef46a7c0a2925..059a203e3b0d1 100644
--- a/clang/test/Analysis/Checkers/WebKit/objc-mock-types.h
+++ b/clang/test/Analysis/Checkers/WebKit/objc-mock-types.h
@@ -71,6 +71,7 @@ __attribute__((objc_root_class))
 + (Class) superclass;
 - (instancetype) init;
 - (instancetype)retain;
+- (instancetype)autorelease;
 - (void)release;
 - (BOOL)isKindOfClass:(Class)aClass;
 @end
@@ -221,6 +222,10 @@ template  struct RetainPtr {
   operator PtrType() const { return t; }
   operator bool() const { return t; }
 
+#if !__has_feature(objc_arc)
+  PtrType autorelease() { [[clang::suppress]] return [t autorelease]; }
+#endif
+
 private:
   CFTypeRef toCFTypeRef(id ptr) { return (__bridge CFTypeRef)ptr; }
   CFTypeRef toCFTypeRef(const void* ptr) { return (CFTypeRef)ptr; }
diff --git a/clang/test/Analysis/Checkers/WebKit/unretained-call-args-arc.mm 
b/clang/test/Analysis/Checkers/WebKit/unretained-call-args-arc.mm
index eb4735da60a05..f1f4d912663aa 100644
--- a/clang/test/Analysis/Checkers/WebKit/unretained-call-args-arc.mm
+++ b/clang/test/Analysis/Checkers/WebKit/unretained-call-args-arc.mm
@@ -18,6 +18,

[clang] [clang-tools-extra] [lldb] Reland: [clang] preserve class type sugar when taking pointer to member (PR #132401)

2025-03-29 Thread Alexander Kornienko via cfe-commits

alexfh wrote:

I've found a new crash that's not fixed by 
https://github.com/llvm/llvm-project/pull/133343. Reducing...

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


[clang] [Clang] Check PP presence when printing stats (PR #131608)

2025-03-29 Thread Fangrui Song via cfe-commits

MaskRay wrote:

LGTM! Thanks for the fix

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


[clang] [RFC] Initial implementation of P2719 (PR #113510)

2025-03-29 Thread Oliver Hunt via cfe-commits


@@ -1829,10 +1829,18 @@ class DeclContext {
 // refers to an enclosing template for hte purposes of [temp.friend]p9.
 LLVM_PREFERRED_TYPE(bool)
 uint64_t FriendConstraintRefersToEnclosingTemplate : 1;
+
+// Indicates this function is type aware operator new or delete
+LLVM_PREFERRED_TYPE(bool)
+uint64_t IsDestroyingOperatorDelete : 1;
+
+// Indicates this function is type aware operator new or delete
+LLVM_PREFERRED_TYPE(bool)
+uint64_t IsTypeAwareOperatorNewOrDelete : 1;

ojhunt wrote:

I'm not convinced that the concern about the cost of these bits is really 
justified, however for the time being I've switched to a pair of `DenseSet`s on 
ASTContext which maintains the general design win of being able to do correct 
(and fast[er]) checks on the operator kind through the FunctionDecl without 
access to Sema. In the short term this also gives us the ability to track the 
existence of any type aware new or delete operators so we can short circuit 
type aware allocator lookup until we restructure operator lookup to be less 
like the spec language and much more efficient in general.

The DenseSet caches in ASTContext technically help performance, but the primary 
reason for this model is to help the overall design: it allows us to only have 
a single implementation of "is this type aware" and "is this destroying delete" 
semantics (that lives in Sema) rather than having the very subtle difference in 
semantics we get from Sema (that does fully correct type checks) and what are 
essentially just the type name check we were using before which technically 
makes it possible to have diverging definitions, though *in principle* the 
rules in Sema would mean that if there was divergence the sema checks would 
have failed and codegen would not be reached.

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


[clang] Disable alias template CTAD for C++17 (PR #133597)

2025-03-29 Thread via cfe-commits

GeorgeKA wrote:

Gotcha. Thanks for the feedback. I'll comment in the issue.

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


[clang] [Basic] Use SmallSet::insert_range (NFC) (PR #133594)

2025-03-29 Thread Kazu Hirata via cfe-commits

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


[clang] [clang-format]: Add `StaticInlineOnly` and `StaticInline` options to `ShortFunctionStyle` (PR #133598)

2025-03-29 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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

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

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


[clang] [Basic] Use SmallSet::insert_range (NFC) (PR #133594)

2025-03-29 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

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

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


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

```
Step 6 (test) failure: build (failure)
...
PASS: lldb-unit :: Language/CPlusPlus/./LanguageCPlusPlusTests/1/6 (2153 of 
2932)
PASS: lldb-unit :: Language/CPlusPlus/./LanguageCPlusPlusTests/2/6 (2154 of 
2932)
PASS: lldb-unit :: Language/CPlusPlus/./LanguageCPlusPlusTests/3/6 (2155 of 
2932)
PASS: lldb-unit :: Language/CPlusPlus/./LanguageCPlusPlusTests/4/6 (2156 of 
2932)
PASS: lldb-unit :: Language/CPlusPlus/./LanguageCPlusPlusTests/5/6 (2157 of 
2932)
PASS: lldb-unit :: Language/Highlighting/./HighlighterTests/0/29 (2158 of 2932)
PASS: lldb-unit :: Language/Highlighting/./HighlighterTests/1/29 (2159 of 2932)
PASS: lldb-unit :: Language/Highlighting/./HighlighterTests/10/29 (2160 of 2932)
PASS: lldb-unit :: Language/Highlighting/./HighlighterTests/11/29 (2161 of 2932)
PASS: lldb-unit :: Language/Highlighting/./HighlighterTests/12/29 (2162 of 2932)
FAIL: lldb-unit :: Host/./HostTests/33/96 (2163 of 2932)
 TEST 'lldb-unit :: Host/./HostTests/33/96' FAILED 

Script(shard):
--
GTEST_OUTPUT=json:/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/tools/lldb/unittests/Host/./HostTests-lldb-unit-1310901-33-96.json
 GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=96 GTEST_SHARD_INDEX=33 
/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/tools/lldb/unittests/Host/./HostTests
--

Script:
--
/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/tools/lldb/unittests/Host/./HostTests
 --gtest_filter=MainLoopTest.CallbackWithTimeout
--
../llvm-project/lldb/unittests/Host/MainLoopTest.cpp:227: Failure
Expected: (std::chrono::steady_clock::now() - start) >= 
(std::chrono::seconds(2)), actual: 8-byte object <91-1A 35-77 00-00 00-00> vs 
8-byte object <02-00 00-00 00-00 00-00>


../llvm-project/lldb/unittests/Host/MainLoopTest.cpp:227
Expected: (std::chrono::steady_clock::now() - start) >= 
(std::chrono::seconds(2)), actual: 8-byte object <91-1A 35-77 00-00 00-00> vs 
8-byte object <02-00 00-00 00-00 00-00>




PASS: lldb-unit :: Language/Highlighting/./HighlighterTests/13/29 (2164 of 2932)
PASS: lldb-unit :: Language/Highlighting/./HighlighterTests/14/29 (2165 of 2932)
PASS: lldb-unit :: Language/Highlighting/./HighlighterTests/15/29 (2166 of 2932)
PASS: lldb-unit :: Language/Highlighting/./HighlighterTests/16/29 (2167 of 2932)
PASS: lldb-unit :: Language/Highlighting/./HighlighterTests/17/29 (2168 of 2932)
PASS: lldb-unit :: Language/Highlighting/./HighlighterTests/18/29 (2169 of 2932)
PASS: lldb-unit :: Language/Highlighting/./HighlighterTests/19/29 (2170 of 2932)
PASS: lldb-unit :: Language/Highlighting/./HighlighterTests/21/29 (2171 of 2932)
PASS: lldb-unit :: Language/Highlighting/./HighlighterTests/2/29 (2172 of 2932)
PASS: lldb-unit :: Language/Highlighting/./HighlighterTests/20/29 (2173 of 2932)
PASS: lldb-unit :: Language/Highlighting/./HighlighterTests/22/29 (2174 of 2932)
PASS: lldb-unit :: Language/Highlighting/./HighlighterTests/23/29 (2175 of 2932)
PASS: lldb-unit :: Language/Highlighting/./HighlighterTests/24/29 (2176 of 2932)
PASS: lldb-unit :: Language/Highlighting/./HighlighterTests/25/29 (2177 of 2932)
PASS: lldb-unit :: Language/Highlighting/./HighlighterTests/26/29 (2178 of 2932)
PASS: lldb-unit :: Language/Highlighting/./HighlighterTests/27/29 (2179 of 2932)
PASS: lldb-unit :: Language/Highlighting/./HighlighterTests/28/29 (2180 of 2932)
PASS: lldb-unit :: Language/Highlighting/./HighlighterTests/3/29 (2181 of 2932)

```



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


[clang] 0cd8232 - Fix some typos (NFC) (#133558)

2025-03-29 Thread via cfe-commits

Author: Qinkun Bao
Date: 2025-03-29T20:54:15+01:00
New Revision: 0cd82327ff71282b2bfc51090074a3fd63e4842d

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

LOG: Fix some typos (NFC) (#133558)

Added: 


Modified: 
clang/docs/BoundsSafety.rst
clang/docs/ConstantInterpreter.rst
clang/docs/HIPSupport.rst
clang/docs/HLSL/AvailabilityDiagnostics.rst
clang/docs/MSVCCompatibility.rst
clang/docs/SanitizerCoverage.rst
clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
clang/unittests/StaticAnalyzer/CallEventTest.cpp
clang/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp
clang/unittests/Tooling/ExecutionTest.cpp

Removed: 




diff  --git a/clang/docs/BoundsSafety.rst b/clang/docs/BoundsSafety.rst
index cf5b0c75c0387..4b70b34eb4100 100644
--- a/clang/docs/BoundsSafety.rst
+++ b/clang/docs/BoundsSafety.rst
@@ -227,7 +227,7 @@ meaning they do not have ABI implications.
   annotated with ``__ended_by(Q)``. In this case, the end of the range extends
   to the pointer ``Q``. This is used for "iterator" support in C where you're
   iterating from one pointer value to another until a final pointer value is
-  reached (and the final pointer value is not dereferencable).
+  reached (and the final pointer value is not dereferenceable).
 
 Accessing a pointer outside the specified bounds causes a run-time trap or a
 compile-time error. Also, the model maintains correctness of bounds annotations
@@ -507,7 +507,7 @@ Default pointer types in ``typeof()``
 ^
 
 When ``typeof()`` takes an expression, it respects the bounds annotation on
-the expression type, including the bounds annotation is implcit. For example,
+the expression type, including the bounds annotation is implicit. For example,
 the global variable ``g`` in the following code is implicitly ``__single`` so
 ``typeof(g)`` gets ``char *__single``. The similar is true for the parameter
 ``p``, so ``typeof(p)`` returns ``void *__single``. The local variable ``l`` is

diff  --git a/clang/docs/ConstantInterpreter.rst 
b/clang/docs/ConstantInterpreter.rst
index b08cb1ce353be..a71ee4b430a6e 100644
--- a/clang/docs/ConstantInterpreter.rst
+++ b/clang/docs/ConstantInterpreter.rst
@@ -293,4 +293,4 @@ TypeInfoPointer
 
 ``TypeInfoPointer`` tracks two types: the type assigned to
 ``std::type_info`` and the type which was passed to ``typeinfo``.
-It is part of the taged union in ``Pointer``.
+It is part of the tagged union in ``Pointer``.

diff  --git a/clang/docs/HIPSupport.rst b/clang/docs/HIPSupport.rst
index 8f473c21e1918..b2ac53843aeed 100644
--- a/clang/docs/HIPSupport.rst
+++ b/clang/docs/HIPSupport.rst
@@ -704,7 +704,7 @@ Open Questions / Future Developments
 SPIR-V Support on HIPAMD ToolChain
 ==
 
-The HIPAMD ToolChain supports targetting
+The HIPAMD ToolChain supports targeting
 `AMDGCN Flavoured SPIR-V 
`_.
 The support for SPIR-V in the ROCm and HIPAMD ToolChain is under active
 development.

diff  --git a/clang/docs/HLSL/AvailabilityDiagnostics.rst 
b/clang/docs/HLSL/AvailabilityDiagnostics.rst
index c2f260f268e7b..0db94f4b15a86 100644
--- a/clang/docs/HLSL/AvailabilityDiagnostics.rst
+++ b/clang/docs/HLSL/AvailabilityDiagnostics.rst
@@ -48,7 +48,7 @@ Strict Diagnostic Mode
 
 When strict HLSL availability diagnostic mode is enabled the compiler must 
report all HLSL API availability issues regardless of code reachability. The 
implementation of this mode takes advantage of an existing diagnostic scan in 
``DiagnoseUnguardedAvailability`` class which is already traversing AST of each 
function as soon as the function body has been parsed. For HLSL, this pass was 
only slightly modified, such as making sure diagnostic messages are in the 
``hlsl-availability`` group and that availability checks based on shader stage 
are not included if the shader stage context is unknown.
 
-If the compilation target is a shader library, only availability based on 
shader model version can be diagnosed during this scan. To diagnose 
availability based on shader stage, the compiler needs to run the AST 
traversals implementated in ``DiagnoseHLSLAvailability`` at the end of the 
translation unit as described above.
+If the compilation target is a shader library, only availability based on 
shader model version can be diagnosed during this scan. To diagnose 
availability based on shader stage, the compiler needs to run the AST 
traversals implemented in ``DiagnoseHLSLAvailability`` at the end of the 
translation unit as described above.
 
 As a result, availability based on specific shader stage will only be 
diagn

[clang] Disable alias template CTAD for C++17 (PR #133597)

2025-03-29 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

It is generally ok, we only do not allow it when that would cause some 
significant backwards compatibility issues.

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


[clang-tools-extra] [clang-tidy] Fix broken HeaderFilterRegex when read from config file (PR #133582)

2025-03-29 Thread Carlos Galvez via cfe-commits

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


[clang] Disable alias template CTAD for C++17 (PR #133597)

2025-03-29 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov commented:

We do tend to offer newer features into older standards when that isn't a 
burden, as long as we have a warning advertising the incompatibility with the 
current standard, as we do.

What is the motivation for this change?

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


[clang] [RFC] Initial implementation of P2719 (PR #113510)

2025-03-29 Thread Oliver Hunt via cfe-commits


@@ -3134,6 +3134,31 @@ bool Type::isStdByteType() const {
   return false;
 }
 
+bool Type::isDestroyingDeleteT() const {
+  auto *RD = getAsCXXRecordDecl();
+  return RD && RD->isInStdNamespace() && RD->getIdentifier() &&
+ RD->getIdentifier()->isStr("destroying_delete_t");
+}
+
+TemplateDecl *Type::getSpecializedTemplateDecl() const {
+  auto UnderlyingType = getCanonicalTypeInternal();
+  if (auto *TST = UnderlyingType->getAs())
+return TST->getTemplateName().getAsTemplateDecl();
+  if (auto *RT = UnderlyingType->getAsCXXRecordDecl()) {
+if (auto *CTSD = dyn_cast(RT))
+  return CTSD->getSpecializedTemplate();
+  }
+  return nullptr;
+}
+
+bool Type::isTypeIdentitySpecialization() const {
+  const TemplateDecl *STDecl = getSpecializedTemplateDecl();
+  if (!STDecl)
+return false;
+  IdentifierInfo *II = STDecl->getIdentifier();
+  return STDecl->isInStdNamespace() && II->isStr("type_identity");
+}
+

ojhunt wrote:

With the various refactorings the need/use of these helpers is basically gone 
so I'm removing them (`getSpecializedTemplateDecl` might be useful, but now the 
only use of it is the function that I copied the code from so I'm removing it)

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


[clang] [Basic] Use SmallSet::insert_range (NFC) (PR #133594)

2025-03-29 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

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

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


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

```
Step 6 (test) failure: build (failure)
...
PASS: lldb-api :: lang/cpp/stl/TestSTL.py (864 of 2112)
XFAIL: lldb-api :: lang/cpp/trivial_abi/TestTrivialABI.py (865 of 2112)
PASS: lldb-api :: lang/cpp/type_lookup_duplicate/TestCppTypeLookupDuplicate.py 
(866 of 2112)
PASS: lldb-api :: lang/cpp/type_lookup/TestCppTypeLookup.py (867 of 2112)
PASS: lldb-api :: lang/cpp/typedef-to-outer-fwd/TestTypedefToOuterFwd.py (868 
of 2112)
PASS: lldb-api :: lang/cpp/typeof/TestTypeOfDeclTypeExpr.py (869 of 2112)
PASS: lldb-api :: lang/cpp/thunk/TestThunk.py (870 of 2112)
PASS: lldb-api :: lang/cpp/typedef/TestCppTypedef.py (871 of 2112)
PASS: lldb-api :: lang/cpp/template/TestTemplateArgs.py (872 of 2112)
PASS: lldb-api :: lang/cpp/unsigned_types/TestUnsignedTypes.py (873 of 2112)
FAIL: lldb-api :: lang/cpp/unique-types/TestUniqueTypes.py (874 of 2112)
 TEST 'lldb-api :: 
lang/cpp/unique-types/TestUniqueTypes.py' FAILED 
Script:
--
/usr/bin/python3.10 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/API/dotest.py
 -u CXXFLAGS -u CFLAGS --env 
LLVM_LIBS_DIR=/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./lib --env 
LLVM_INCLUDE_DIR=/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/include 
--env LLVM_TOOLS_DIR=/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin 
--arch aarch64 --build-dir 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex 
--lldb-module-cache-dir 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api
 --clang-module-cache-dir 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex/module-cache-clang/lldb-api
 --executable /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin/lldb 
--compiler /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin/clang 
--dsymutil /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin/dsymutil 
--make /usr/bin/gmake --llvm-tools-dir 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin --lldb-obj-root 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb --lldb-libs-dir 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./lib 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/API/lang/cpp/unique-types
 -p TestUniqueTypes.py
--
Exit Code: -11

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

--
Command Output (stderr):
--
UNSUPPORTED: LLDB 
(/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: 
test_dsym (TestUniqueTypes.UniqueTypesTestCase) (test case does not fall in any 
category of interest for this run) 
PASS: LLDB 
(/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: 
test_dwarf (TestUniqueTypes.UniqueTypesTestCase)
PASS: LLDB 
(/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: 
test_dwo (TestUniqueTypes.UniqueTypesTestCase)
--
Ran 3 tests in 1.006s

OK (skipped=1)

--


PASS: lldb-api :: lang/cpp/unique-types2/TestUniqueTypes2.py (875 of 2112)
PASS: lldb-api :: lang/cpp/unique-types4/TestUniqueTypes4.py (876 of 2112)
PASS: lldb-api :: lang/cpp/unique-types3/TestUniqueTypes3.py (877 of 2112)
PASS: lldb-api :: 
lang/cpp/union-static-data-members/TestCppUnionStaticMembers.py (878 of 2112)
PASS: lldb-api :: lang/cpp/unicode-literals/TestUnicodeLiterals.py (879 of 2112)
PASS: lldb-api :: lang/cpp/virtual-overload/TestVirtualOverload.py (880 of 2112)
PASS: lldb-api :: lang/cpp/wchar_t/TestCxxWCharT.py (881 of 2112)
UNSUPPORTED: lldb-api :: lang/objc/bitfield_ivars/TestBitfieldIvars.py (882 of 
2112)
UNSUPPORTED: lldb-api :: lang/objc/blocks/TestObjCIvarsInBlocks.py (883 of 2112)
UNSUPPORTED: lldb-api :: lang/objc/charstar_dyntype/TestCharStarDynType.py (884 
of 2112)

```



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


[clang] [clang] implement common-sugar for adjusted member-pointers (PR #133613)

2025-03-29 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clang-aarch64-sve-vls` 
running on `linaro-g3-03` while building `clang` at step 7 "ninja check 1".

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


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

```
Step 7 (ninja check 1) failure: stage 1 checked (failure)
...
llvm-lit: 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/llvm/utils/lit/lit/llvm/config.py:520:
 note: using ld64.lld: 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/bin/ld64.lld
llvm-lit: 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/llvm/utils/lit/lit/llvm/config.py:520:
 note: using wasm-ld: 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/bin/wasm-ld
llvm-lit: 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/llvm/utils/lit/lit/discovery.py:276:
 warning: input 
'/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/runtimes/runtimes-bins/compiler-rt/test/interception/Unit'
 contained no tests
llvm-lit: 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/llvm/utils/lit/lit/discovery.py:276:
 warning: input 
'/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/Unit'
 contained no tests
llvm-lit: 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/llvm/utils/lit/lit/llvm/config.py:520:
 note: using ld.lld: 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/bin/ld.lld
llvm-lit: 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/llvm/utils/lit/lit/llvm/config.py:520:
 note: using lld-link: 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/bin/lld-link
llvm-lit: 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/llvm/utils/lit/lit/llvm/config.py:520:
 note: using ld64.lld: 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/bin/ld64.lld
llvm-lit: 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/llvm/llvm/utils/lit/lit/llvm/config.py:520:
 note: using wasm-ld: 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls/stage1/bin/wasm-ld
-- Testing: 97483 tests, 64 workers --
UNRESOLVED: Flang :: Driver/slp-vectorize.ll (1 of 97483)
 TEST 'Flang :: Driver/slp-vectorize.ll' FAILED 

Test has no 'RUN:' line

PASS: Clang :: Driver/x86-target-features.c (2 of 97483)
PASS: ScudoStandalone-Unit :: ./ScudoUnitTest-aarch64-Test/53/71 (3 of 97483)
PASS: ThreadSanitizer-aarch64 :: signal_thread.cpp (4 of 97483)
PASS: Clang :: OpenMP/target_parallel_codegen_registration.cpp (5 of 97483)
PASS: Clang :: OpenMP/target_simd_codegen_registration.cpp (6 of 97483)
PASS: MemorySanitizer-AARCH64 :: release_origin.c (7 of 97483)
PASS: Clang :: Headers/arm-neon-header.c (8 of 97483)
PASS: HWAddressSanitizer-aarch64 :: TestCases/Linux/create-thread-stress.cpp (9 
of 97483)
PASS: lld :: COFF/arm64ec-import-range-ext.test (10 of 97483)
PASS: libFuzzer-aarch64-default-Linux :: merge-sigusr.test (11 of 97483)
PASS: Clang :: Analysis/runtime-regression.c (12 of 97483)
PASS: libFuzzer-aarch64-default-Linux :: large.test (13 of 97483)
PASS: UBSan-ThreadSanitizer-aarch64 :: 
TestCases/ImplicitConversion/signed-integer-truncation-ignorelist.c (14 of 
97483)
PASS: Clang :: CodeGen/X86/sse2-builtins.c (15 of 97483)
PASS: libFuzzer-aarch64-default-Linux :: msan.test (16 of 97483)
PASS: Clang :: OpenMP/target_parallel_for_codegen_registration.cpp (17 of 97483)
PASS: libFuzzer-aarch64-default-Linux :: value-profile-cmp.test (18 of 97483)
PASS: UBSan-ThreadSanitizer-aarch64 :: 
TestCases/ImplicitConversion/unsigned-integer-truncation-ignorelist.c (19 of 
97483)
PASS: Clang :: OpenMP/target_teams_distribute_codegen_registration.cpp (20 of 
97483)
PASS: Clang :: OpenMP/target_teams_distribute_simd_codegen_registration.cpp (21 
of 97483)
PASS: Clang :: Driver/linux-ld.c (22 of 97483)
PASS: Clang :: OpenMP/target_parallel_for_simd_codegen_registration.cpp (23 of 
97483)
PASS: LLVM :: CodeGen/RISCV/attributes.ll (24 of 97483)
PASS: Clang :: CodeGen/X86/rot-intrinsics.c (25 of 97483)
PASS: Clang :: Preprocessor/predefined-arch-macros.c (26 of 97483)
PASS: Clang :: CodeGen/X86/avx-builtins.c (27 of 97483)
PASS: Clang :: CodeGen/AArch64/sve-intrinsics/acle_sve_reinterpret-bfloat.c (28 
of 97483)
PASS: ThreadSanitizer-aarch64 :: deadlock_detector_stress_test.cpp (29 of 97483)
PASS: LLVM :: CodeGen/AMDGPU/sched-group-barrier-pipeline-solver.mir (30 of 
97483)
PASS: SanitizerCommon-lsan-aarch64-Linux :: Linux/signal_segv_handler.cpp (31 
of 97483)
PASS: SanitizerCommon-ubsan-aarch64-Linux :: Linux/signal_segv_handler.cpp (32 
of 97483)
PASS: Clang :: 
OpenMP/target_teams_distribute_parallel_for_simd_codegen_registration.cpp (33 
of 97483)
PASS: SanitizerCommon-hwasan-aarch64-Linux :: Linux/signal_segv_handler.cpp (34 
of 97483)
PASS: SanitizerCommon-msan-aarch64-Linux :: Linux/signal_segv_handler.cpp (35 
of 97483)
PASS: SanitizerCommon-tsan-aarch64-Linux :: Linux/signal_segv_handler.cpp (3

[clang] [Clang][Cmake] fix libtool duplicate member name warnings (PR #133619)

2025-03-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-amdgpu

Author: Farzon Lotfi (farzonl)


Changes

fixes #133199
 
PR #132252 Created a second file that shared `.cpp` 
in `clang/lib/CodeGen/CMakeLists.txt`

For example There were two `AMDGPU.cpp`'s one in `TargetBuiltins` and the other 
in `Targets`. Even though these were in different directories `libtool` warns 
that it might not distinguish them because they share the same base name.

There are two fixes. The easy fix is to rename one of them and keep one cmake 
file. That solution though doesn't future proof this problem in the event of a 
third `.cpp` and it seems teams want to just use the target 
name
https://github.com/llvm/llvm-project/pull/132252#issuecomment-2758178483.

The alternative fix is to seperate the cmake files into their own sub 
directories. I chose to create static libraries. It might of been possible to 
build an OBJECT, but I only saw examples of this in compiler-rt and test 
directories so assumed there was a reason it wasn't used.



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


4 Files Affected:

- (modified) clang/lib/CodeGen/CMakeLists.txt (+12-37) 
- (modified) clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp (+1-1) 
- (added) clang/lib/CodeGen/TargetBuiltins/CMakeLists.txt (+19) 
- (added) clang/lib/CodeGen/Targets/CMakeLists.txt (+35) 


``diff
diff --git a/clang/lib/CodeGen/CMakeLists.txt b/clang/lib/CodeGen/CMakeLists.txt
index ebe2fbd7db295..cdf9f909a3675 100644
--- a/clang/lib/CodeGen/CMakeLists.txt
+++ b/clang/lib/CodeGen/CMakeLists.txt
@@ -116,45 +116,8 @@ add_clang_library(clangCodeGen
   PatternInit.cpp
   SanitizerMetadata.cpp
   SwiftCallingConv.cpp
-  TargetBuiltins/ARM.cpp
-  TargetBuiltins/AMDGPU.cpp
-  TargetBuiltins/Hexagon.cpp
-  TargetBuiltins/NVPTX.cpp
-  TargetBuiltins/PPC.cpp
-  TargetBuiltins/RISCV.cpp
-  TargetBuiltins/SPIR.cpp
-  TargetBuiltins/SystemZ.cpp
-  TargetBuiltins/WebAssembly.cpp
-  TargetBuiltins/X86.cpp
   TargetInfo.cpp
-  Targets/AArch64.cpp
-  Targets/AMDGPU.cpp
-  Targets/ARC.cpp
-  Targets/ARM.cpp
-  Targets/AVR.cpp
-  Targets/BPF.cpp
-  Targets/CSKY.cpp
-  Targets/DirectX.cpp
-  Targets/Hexagon.cpp
-  Targets/Lanai.cpp
-  Targets/LoongArch.cpp
-  Targets/M68k.cpp
-  Targets/MSP430.cpp
-  Targets/Mips.cpp
-  Targets/NVPTX.cpp
-  Targets/PNaCl.cpp
-  Targets/PPC.cpp
-  Targets/RISCV.cpp
-  Targets/SPIR.cpp
-  Targets/Sparc.cpp
-  Targets/SystemZ.cpp
-  Targets/TCE.cpp
-  Targets/VE.cpp
-  Targets/WebAssembly.cpp
-  Targets/X86.cpp
-  Targets/XCore.cpp
   VarBypassDetector.cpp
-
   DEPENDS
   vt_gen
   intrinsics_gen
@@ -170,4 +133,16 @@ add_clang_library(clangCodeGen
   clangFrontend
   clangLex
   clangSerialization
+  clangCodeGenTargetBuiltins
+  clangCodeGenTargets
+  )
+
+  target_include_directories(clangCodeGen
+PUBLIC
+${CMAKE_CURRENT_SOURCE_DIR}
+${CMAKE_CURRENT_SOURCE_DIR}/TargetBuiltins
+${CMAKE_CURRENT_SOURCE_DIR}/Targets
   )
+  
+  add_subdirectory(TargetBuiltins)
+  add_subdirectory(Targets)
diff --git a/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp 
b/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
index b56b739094ff3..577fee05d4af6 100644
--- a/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
+++ b/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
@@ -1,4 +1,4 @@
-//===--- AMDCPU.cpp - Emit LLVM Code for builtins 
-===//
+//===--- AMDGPU.cpp - Emit LLVM Code for builtins 
-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/clang/lib/CodeGen/TargetBuiltins/CMakeLists.txt 
b/clang/lib/CodeGen/TargetBuiltins/CMakeLists.txt
new file mode 100644
index 0..8526c063b4593
--- /dev/null
+++ b/clang/lib/CodeGen/TargetBuiltins/CMakeLists.txt
@@ -0,0 +1,19 @@
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
+
+add_clang_library(clangCodeGenTargetBuiltins STATIC
+  ARM.cpp
+  AMDGPU.cpp
+  Hexagon.cpp
+  NVPTX.cpp
+  PPC.cpp
+  RISCV.cpp
+  SPIR.cpp
+  SystemZ.cpp
+  WebAssembly.cpp
+  X86.cpp
+)
+
+target_link_libraries(clangCodeGenTargetBuiltins
+  PRIVATE
+  clangCodeGen
+)
diff --git a/clang/lib/CodeGen/Targets/CMakeLists.txt 
b/clang/lib/CodeGen/Targets/CMakeLists.txt
new file mode 100644
index 0..fd79b6191b379
--- /dev/null
+++ b/clang/lib/CodeGen/Targets/CMakeLists.txt
@@ -0,0 +1,35 @@
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
+
+add_clang_library(clangCodeGenTargets STATIC
+  AArch64.cpp
+  AMDGPU.cpp
+  ARC.cpp
+  ARM.cpp
+  AVR.cpp
+  BPF.cpp
+  CSKY.cpp
+  DirectX.cpp
+  Hexagon.cpp
+  Lanai.cpp
+  LoongArch.cpp
+  M68k.cpp
+  MSP430.cpp
+  Mips.cpp
+  NVPTX.cpp
+  PNaCl.cpp
+  PPC.cpp
+  RISCV.cpp
+  SPIR.cpp
+  Sparc.cpp
+  SystemZ.cpp
+  TCE.cpp
+  VE.cpp
+  WebAssembly.cpp
+  X86.cpp
+  XCore.cpp
+)
+
+target_link_libraries(clangCodeGenTargets
+  PRIVATE
+  clangCodeGen
+)

``




https://github.com/llvm/llvm

[clang] [Clang][Cmake] fix libtool duplicate member name warnings (PR #133619)

2025-03-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Farzon Lotfi (farzonl)


Changes

fixes #133199
 
PR #132252 Created a second file that shared `.cpp` 
in `clang/lib/CodeGen/CMakeLists.txt`

For example There were two `AMDGPU.cpp`'s one in `TargetBuiltins` and the other 
in `Targets`. Even though these were in different directories `libtool` warns 
that it might not distinguish them because they share the same base name.

There are two fixes. The easy fix is to rename one of them and keep one cmake 
file. That solution though doesn't future proof this problem in the event of a 
third `.cpp` and it seems teams want to just use the target 
name
https://github.com/llvm/llvm-project/pull/132252#issuecomment-2758178483.

The alternative fix is to seperate the cmake files into their own sub 
directories. I chose to create static libraries. It might of been possible to 
build an OBJECT, but I only saw examples of this in compiler-rt and test 
directories so assumed there was a reason it wasn't used.



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


4 Files Affected:

- (modified) clang/lib/CodeGen/CMakeLists.txt (+12-37) 
- (modified) clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp (+1-1) 
- (added) clang/lib/CodeGen/TargetBuiltins/CMakeLists.txt (+19) 
- (added) clang/lib/CodeGen/Targets/CMakeLists.txt (+35) 


``diff
diff --git a/clang/lib/CodeGen/CMakeLists.txt b/clang/lib/CodeGen/CMakeLists.txt
index ebe2fbd7db295..cdf9f909a3675 100644
--- a/clang/lib/CodeGen/CMakeLists.txt
+++ b/clang/lib/CodeGen/CMakeLists.txt
@@ -116,45 +116,8 @@ add_clang_library(clangCodeGen
   PatternInit.cpp
   SanitizerMetadata.cpp
   SwiftCallingConv.cpp
-  TargetBuiltins/ARM.cpp
-  TargetBuiltins/AMDGPU.cpp
-  TargetBuiltins/Hexagon.cpp
-  TargetBuiltins/NVPTX.cpp
-  TargetBuiltins/PPC.cpp
-  TargetBuiltins/RISCV.cpp
-  TargetBuiltins/SPIR.cpp
-  TargetBuiltins/SystemZ.cpp
-  TargetBuiltins/WebAssembly.cpp
-  TargetBuiltins/X86.cpp
   TargetInfo.cpp
-  Targets/AArch64.cpp
-  Targets/AMDGPU.cpp
-  Targets/ARC.cpp
-  Targets/ARM.cpp
-  Targets/AVR.cpp
-  Targets/BPF.cpp
-  Targets/CSKY.cpp
-  Targets/DirectX.cpp
-  Targets/Hexagon.cpp
-  Targets/Lanai.cpp
-  Targets/LoongArch.cpp
-  Targets/M68k.cpp
-  Targets/MSP430.cpp
-  Targets/Mips.cpp
-  Targets/NVPTX.cpp
-  Targets/PNaCl.cpp
-  Targets/PPC.cpp
-  Targets/RISCV.cpp
-  Targets/SPIR.cpp
-  Targets/Sparc.cpp
-  Targets/SystemZ.cpp
-  Targets/TCE.cpp
-  Targets/VE.cpp
-  Targets/WebAssembly.cpp
-  Targets/X86.cpp
-  Targets/XCore.cpp
   VarBypassDetector.cpp
-
   DEPENDS
   vt_gen
   intrinsics_gen
@@ -170,4 +133,16 @@ add_clang_library(clangCodeGen
   clangFrontend
   clangLex
   clangSerialization
+  clangCodeGenTargetBuiltins
+  clangCodeGenTargets
+  )
+
+  target_include_directories(clangCodeGen
+PUBLIC
+${CMAKE_CURRENT_SOURCE_DIR}
+${CMAKE_CURRENT_SOURCE_DIR}/TargetBuiltins
+${CMAKE_CURRENT_SOURCE_DIR}/Targets
   )
+  
+  add_subdirectory(TargetBuiltins)
+  add_subdirectory(Targets)
diff --git a/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp 
b/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
index b56b739094ff3..577fee05d4af6 100644
--- a/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
+++ b/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
@@ -1,4 +1,4 @@
-//===--- AMDCPU.cpp - Emit LLVM Code for builtins 
-===//
+//===--- AMDGPU.cpp - Emit LLVM Code for builtins 
-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/clang/lib/CodeGen/TargetBuiltins/CMakeLists.txt 
b/clang/lib/CodeGen/TargetBuiltins/CMakeLists.txt
new file mode 100644
index 0..8526c063b4593
--- /dev/null
+++ b/clang/lib/CodeGen/TargetBuiltins/CMakeLists.txt
@@ -0,0 +1,19 @@
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
+
+add_clang_library(clangCodeGenTargetBuiltins STATIC
+  ARM.cpp
+  AMDGPU.cpp
+  Hexagon.cpp
+  NVPTX.cpp
+  PPC.cpp
+  RISCV.cpp
+  SPIR.cpp
+  SystemZ.cpp
+  WebAssembly.cpp
+  X86.cpp
+)
+
+target_link_libraries(clangCodeGenTargetBuiltins
+  PRIVATE
+  clangCodeGen
+)
diff --git a/clang/lib/CodeGen/Targets/CMakeLists.txt 
b/clang/lib/CodeGen/Targets/CMakeLists.txt
new file mode 100644
index 0..fd79b6191b379
--- /dev/null
+++ b/clang/lib/CodeGen/Targets/CMakeLists.txt
@@ -0,0 +1,35 @@
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
+
+add_clang_library(clangCodeGenTargets STATIC
+  AArch64.cpp
+  AMDGPU.cpp
+  ARC.cpp
+  ARM.cpp
+  AVR.cpp
+  BPF.cpp
+  CSKY.cpp
+  DirectX.cpp
+  Hexagon.cpp
+  Lanai.cpp
+  LoongArch.cpp
+  M68k.cpp
+  MSP430.cpp
+  Mips.cpp
+  NVPTX.cpp
+  PNaCl.cpp
+  PPC.cpp
+  RISCV.cpp
+  SPIR.cpp
+  Sparc.cpp
+  SystemZ.cpp
+  TCE.cpp
+  VE.cpp
+  WebAssembly.cpp
+  X86.cpp
+  XCore.cpp
+)
+
+target_link_libraries(clangCodeGenTargets
+  PRIVATE
+  clangCodeGen
+)

``




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

[clang] [Clang][Cmake] fix libtool duplicate member name warnings (PR #133619)

2025-03-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Farzon Lotfi (farzonl)


Changes

fixes #133199
 
PR #132252 Created a second file that shared `.cpp` 
in `clang/lib/CodeGen/CMakeLists.txt`

For example There were two `AMDGPU.cpp`'s one in `TargetBuiltins` and the other 
in `Targets`. Even though these were in different directories `libtool` warns 
that it might not distinguish them because they share the same base name.

There are two fixes. The easy fix is to rename one of them and keep one cmake 
file. That solution though doesn't future proof this problem in the event of a 
third `.cpp` and it seems teams want to just use the target 
name
https://github.com/llvm/llvm-project/pull/132252#issuecomment-2758178483.

The alternative fix is to seperate the cmake files into their own sub 
directories. I chose to create static libraries. It might of been possible to 
build an OBJECT, but I only saw examples of this in compiler-rt and test 
directories so assumed there was a reason it wasn't used.



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


4 Files Affected:

- (modified) clang/lib/CodeGen/CMakeLists.txt (+12-37) 
- (modified) clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp (+1-1) 
- (added) clang/lib/CodeGen/TargetBuiltins/CMakeLists.txt (+19) 
- (added) clang/lib/CodeGen/Targets/CMakeLists.txt (+35) 


``diff
diff --git a/clang/lib/CodeGen/CMakeLists.txt b/clang/lib/CodeGen/CMakeLists.txt
index ebe2fbd7db295..cdf9f909a3675 100644
--- a/clang/lib/CodeGen/CMakeLists.txt
+++ b/clang/lib/CodeGen/CMakeLists.txt
@@ -116,45 +116,8 @@ add_clang_library(clangCodeGen
   PatternInit.cpp
   SanitizerMetadata.cpp
   SwiftCallingConv.cpp
-  TargetBuiltins/ARM.cpp
-  TargetBuiltins/AMDGPU.cpp
-  TargetBuiltins/Hexagon.cpp
-  TargetBuiltins/NVPTX.cpp
-  TargetBuiltins/PPC.cpp
-  TargetBuiltins/RISCV.cpp
-  TargetBuiltins/SPIR.cpp
-  TargetBuiltins/SystemZ.cpp
-  TargetBuiltins/WebAssembly.cpp
-  TargetBuiltins/X86.cpp
   TargetInfo.cpp
-  Targets/AArch64.cpp
-  Targets/AMDGPU.cpp
-  Targets/ARC.cpp
-  Targets/ARM.cpp
-  Targets/AVR.cpp
-  Targets/BPF.cpp
-  Targets/CSKY.cpp
-  Targets/DirectX.cpp
-  Targets/Hexagon.cpp
-  Targets/Lanai.cpp
-  Targets/LoongArch.cpp
-  Targets/M68k.cpp
-  Targets/MSP430.cpp
-  Targets/Mips.cpp
-  Targets/NVPTX.cpp
-  Targets/PNaCl.cpp
-  Targets/PPC.cpp
-  Targets/RISCV.cpp
-  Targets/SPIR.cpp
-  Targets/Sparc.cpp
-  Targets/SystemZ.cpp
-  Targets/TCE.cpp
-  Targets/VE.cpp
-  Targets/WebAssembly.cpp
-  Targets/X86.cpp
-  Targets/XCore.cpp
   VarBypassDetector.cpp
-
   DEPENDS
   vt_gen
   intrinsics_gen
@@ -170,4 +133,16 @@ add_clang_library(clangCodeGen
   clangFrontend
   clangLex
   clangSerialization
+  clangCodeGenTargetBuiltins
+  clangCodeGenTargets
+  )
+
+  target_include_directories(clangCodeGen
+PUBLIC
+${CMAKE_CURRENT_SOURCE_DIR}
+${CMAKE_CURRENT_SOURCE_DIR}/TargetBuiltins
+${CMAKE_CURRENT_SOURCE_DIR}/Targets
   )
+  
+  add_subdirectory(TargetBuiltins)
+  add_subdirectory(Targets)
diff --git a/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp 
b/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
index b56b739094ff3..577fee05d4af6 100644
--- a/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
+++ b/clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
@@ -1,4 +1,4 @@
-//===--- AMDCPU.cpp - Emit LLVM Code for builtins 
-===//
+//===--- AMDGPU.cpp - Emit LLVM Code for builtins 
-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/clang/lib/CodeGen/TargetBuiltins/CMakeLists.txt 
b/clang/lib/CodeGen/TargetBuiltins/CMakeLists.txt
new file mode 100644
index 0..8526c063b4593
--- /dev/null
+++ b/clang/lib/CodeGen/TargetBuiltins/CMakeLists.txt
@@ -0,0 +1,19 @@
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
+
+add_clang_library(clangCodeGenTargetBuiltins STATIC
+  ARM.cpp
+  AMDGPU.cpp
+  Hexagon.cpp
+  NVPTX.cpp
+  PPC.cpp
+  RISCV.cpp
+  SPIR.cpp
+  SystemZ.cpp
+  WebAssembly.cpp
+  X86.cpp
+)
+
+target_link_libraries(clangCodeGenTargetBuiltins
+  PRIVATE
+  clangCodeGen
+)
diff --git a/clang/lib/CodeGen/Targets/CMakeLists.txt 
b/clang/lib/CodeGen/Targets/CMakeLists.txt
new file mode 100644
index 0..fd79b6191b379
--- /dev/null
+++ b/clang/lib/CodeGen/Targets/CMakeLists.txt
@@ -0,0 +1,35 @@
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
+
+add_clang_library(clangCodeGenTargets STATIC
+  AArch64.cpp
+  AMDGPU.cpp
+  ARC.cpp
+  ARM.cpp
+  AVR.cpp
+  BPF.cpp
+  CSKY.cpp
+  DirectX.cpp
+  Hexagon.cpp
+  Lanai.cpp
+  LoongArch.cpp
+  M68k.cpp
+  MSP430.cpp
+  Mips.cpp
+  NVPTX.cpp
+  PNaCl.cpp
+  PPC.cpp
+  RISCV.cpp
+  SPIR.cpp
+  Sparc.cpp
+  SystemZ.cpp
+  TCE.cpp
+  VE.cpp
+  WebAssembly.cpp
+  X86.cpp
+  XCore.cpp
+)
+
+target_link_libraries(clangCodeGenTargets
+  PRIVATE
+  clangCodeGen
+)

``




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

[clang] [C23] Implement WG14 N3037 (PR #132939)

2025-03-29 Thread Shafik Yaghmour via cfe-commits


@@ -1886,8 +1891,9 @@ TEST_F(StructuralEquivalenceCacheTest, 
VarDeclWithDifferentStorageClassNoEq) {
   Lang_CXX03);
 
   StructuralEquivalenceContext Ctx(
-  get<0>(TU)->getASTContext(), get<1>(TU)->getASTContext(),
-  NonEquivalentDecls, StructuralEquivalenceKind::Default, false, false);
+  get<0>(TU)->getASTContext().getLangOpts(), get<0>(TU)->getASTContext(),
+  get<1>(TU)->getASTContext(), NonEquivalentDecls,
+  StructuralEquivalenceKind::Default, false, false);

shafik wrote:

```suggestion
  StructuralEquivalenceKind::Default, /*StrictTypeSpelling=*/false, 
/*Complain=*/false);
```

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


[clang] [flang] [flang] Expose -m64 option (PR #132409)

2025-03-29 Thread Daniel Chen via cfe-commits

DanielCChen wrote:

@JDPailleux @kiranchandramohan 
We are planning to add support for flang to compile 32-bit application as well 
as building 32-bit flang-rt on AIX. The first thing would be to enable `-m32` 
for flang in the driver. I saw Kiran's comment. Would it be possible to make 
`-m32` available in the driver but disable it in front_end if desired?   

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


[clang] [llvm] [PowerPC] Enable indiviual crbits tracking at -O2 (PR #133617)

2025-03-29 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff HEAD~1 HEAD --extensions cpp,h -- 
clang/lib/Basic/Targets/PPC.cpp llvm/lib/Target/PowerPC/PPCSubtarget.cpp 
llvm/lib/Target/PowerPC/PPCSubtarget.h 
llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/Target/PowerPC/PPCSubtarget.h 
b/llvm/lib/Target/PowerPC/PPCSubtarget.h
index fcb17d71e..487937dfd 100644
--- a/llvm/lib/Target/PowerPC/PPCSubtarget.h
+++ b/llvm/lib/Target/PowerPC/PPCSubtarget.h
@@ -209,7 +209,7 @@ public:
   }
 
   POPCNTDKind hasPOPCNTD() const { return HasPOPCNTD; }
-  bool useCRBits() const; 
+  bool useCRBits() const;
 
   const Triple &getTargetTriple() const { return TargetTriple; }
 

``




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


[clang] [clang] implement common-sugar for adjusted member-pointers (PR #133613)

2025-03-29 Thread Younan Zhang via cfe-commits

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


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


[clang] [clang] implement common-sugar for adjusted member-pointers (PR #133613)

2025-03-29 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov created 
https://github.com/llvm/llvm-project/pull/133613

This implements a missing case for an adjusted member-pointer in 
getCommonSugaredType, when that was originally implemented here: 
https://github.com/llvm/llvm-project/pull/130537

This missing case could otherwise cause a crash, so this is a regression fix.

This should fix the crash reported here: 
https://github.com/llvm/llvm-project/pull/132401#issuecomment-2764331907

No release notes, since this regression and its underlying feature were never 
released.

>From ab52c7c3b2ec7e735966bd7f51da2ceb227b3fc5 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Sun, 30 Mar 2025 00:28:00 -0300
Subject: [PATCH] [clang] implement common-sugar for adjusted member-pointers

This implements a missing case for an adjusted member-pointer
in getCommonSugaredType, when that was originally implemented
here: https://github.com/llvm/llvm-project/pull/130537

This missing case could otherwise cause a crash, so this is a
regression fix.

This should fix the crash reported here: 
https://github.com/llvm/llvm-project/pull/132401#issuecomment-2764331907

No release notes, since this regression and the underlying feature
were never released.
---
 clang/lib/AST/ASTContext.cpp  | 10 +-
 clang/test/SemaCXX/sugar-common-types.cpp | 16 
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index c9d1bea4c623a..2d9480ebcf00c 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -14135,7 +14135,6 @@ static QualType getCommonSugarTypeNode(ASTContext &Ctx, 
const Type *X,
 CANONICAL_TYPE(IncompleteArray)
 CANONICAL_TYPE(HLSLAttributedResource)
 CANONICAL_TYPE(LValueReference)
-CANONICAL_TYPE(MemberPointer)
 CANONICAL_TYPE(ObjCInterface)
 CANONICAL_TYPE(ObjCObject)
 CANONICAL_TYPE(ObjCObjectPointer)
@@ -14313,6 +14312,15 @@ static QualType getCommonSugarTypeNode(ASTContext 
&Ctx, const Type *X,
   return QualType();
 return Ctx.getUsingType(CD, Ctx.getQualifiedType(Underlying));
   }
+  case Type::MemberPointer: {
+const auto *PX = cast(X),
+   *PY = cast(Y);
+CXXRecordDecl *Cls = PX->getMostRecentCXXRecordDecl();
+assert(Cls == PY->getMostRecentCXXRecordDecl());
+return Ctx.getMemberPointerType(
+::getCommonPointeeType(Ctx, PX, PY),
+::getCommonQualifier(Ctx, PX, PY, /*IsSame=*/false), Cls);
+  }
   case Type::CountAttributed: {
 const auto *DX = cast(X),
*DY = cast(Y);
diff --git a/clang/test/SemaCXX/sugar-common-types.cpp 
b/clang/test/SemaCXX/sugar-common-types.cpp
index a21032517b2ba..d58f6cdd900fc 100644
--- a/clang/test/SemaCXX/sugar-common-types.cpp
+++ b/clang/test/SemaCXX/sugar-common-types.cpp
@@ -186,3 +186,19 @@ namespace arrays {
 // expected-error@-1 {{lvalue of type 'const volatile volatile B1[1]' (aka 
'const volatile volatile int[1]')}}
   } // namespace balanced_qualifiers
 } // namespace arrays
+
+namespace member_pointers {
+  template  struct W {
+X1 a;
+Y1 b;
+  };
+  struct W1 : W {};
+  struct W2 : W {};
+
+  N t1 = 0 ? &W::a : &W::b;
+  // expected-error@-1 {{rvalue of type 'B1 W::*'}}
+
+  // FIXME: adjusted MemberPointer does not preserve qualifier
+  N t3 = 0 ? &W1::a : &W2::b;
+  // expected-error@-1 {{rvalue of type 'B1 W::*'}}
+} // namespace member_pointers

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


[clang] [llvm] [Clang] [OpenMP] Support NOWAIT with optional argument (PR #128742)

2025-03-29 Thread via cfe-commits

https://github.com/jadhbeika updated 
https://github.com/llvm/llvm-project/pull/128742

>From fa3dd1423e4bf2209feb9713f1833e653ec43a74 Mon Sep 17 00:00:00 2001
From: Jad Hbeika 
Date: Wed, 19 Feb 2025 12:53:11 -0800
Subject: [PATCH 1/3] [Clang] [OpenMP] Support NOWAIT with optional argument

---
 clang/include/clang/AST/OpenMPClause.h| 58 ---
 clang/include/clang/AST/RecursiveASTVisitor.h |  3 +-
 clang/include/clang/Sema/SemaOpenMP.h |  6 +-
 clang/lib/AST/OpenMPClause.cpp| 11 +++-
 clang/lib/AST/StmtProfile.cpp |  5 +-
 clang/lib/Parse/ParseOpenMP.cpp   |  5 +-
 clang/lib/Sema/SemaOpenMP.cpp | 24 +++-
 clang/lib/Sema/TreeTransform.h| 21 ++-
 clang/lib/Serialization/ASTReader.cpp |  5 +-
 clang/lib/Serialization/ASTWriter.cpp |  5 +-
 clang/tools/libclang/CIndex.cpp   |  4 +-
 llvm/include/llvm/Frontend/OpenMP/OMP.td  |  2 +
 12 files changed, 127 insertions(+), 22 deletions(-)

diff --git a/clang/include/clang/AST/OpenMPClause.h 
b/clang/include/clang/AST/OpenMPClause.h
index 154ecfbaa4418..b29fce9bd9729 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -2173,18 +2173,62 @@ class OMPOrderedClause final
 /// This represents 'nowait' clause in the '#pragma omp ...' directive.
 ///
 /// \code
-/// #pragma omp for nowait
+/// #pragma omp for nowait (cond)
 /// \endcode
-/// In this example directive '#pragma omp for' has 'nowait' clause.
-class OMPNowaitClause final : public OMPNoChildClause {
+/// In this example directive '#pragma omp for' has simple 'nowait' clause with
+/// condition 'cond'.
+class OMPNowaitClause final : public OMPClause {
+  friend class OMPClauseReader;
+
+  /// Location of '('.
+  SourceLocation LParenLoc;
+
+  /// Condition of the 'nowait' clause.
+  Stmt *Condition = nullptr;
+
+  /// Set condition.
+  void setCondition(Expr *Cond) { Condition = Cond; }
+
 public:
-  /// Build 'nowait' clause.
+  /// Build 'nowait' clause with condition \a Cond.
   ///
+  /// \param Cond Condition of the clause.
   /// \param StartLoc Starting location of the clause.
+  /// \param LParenLoc Location of '('.
   /// \param EndLoc Ending location of the clause.
-  OMPNowaitClause(SourceLocation StartLoc = SourceLocation(),
-  SourceLocation EndLoc = SourceLocation())
-  : OMPNoChildClause(StartLoc, EndLoc) {}
+  OMPNowaitClause(Expr *Cond, SourceLocation StartLoc, SourceLocation 
LParenLoc,
+  SourceLocation EndLoc)
+  : OMPClause(llvm::omp::OMPC_nowait, StartLoc, EndLoc),
+LParenLoc(LParenLoc), Condition(Cond) {}
+
+  /// Build an empty clause.
+  OMPNowaitClause()
+  : OMPClause(llvm::omp::OMPC_nowait, SourceLocation(), SourceLocation()) 
{}
+
+  /// Sets the location of '('.
+  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
+
+  /// Returns the location of '('.
+  SourceLocation getLParenLoc() const { return LParenLoc; }
+
+  /// Returns condition.
+  Expr *getCondition() const { return cast_or_null(Condition); }
+
+  child_range children() { return child_range(&Condition, &Condition + 1); }
+
+  const_child_range children() const {
+return const_child_range(&Condition, &Condition + 1);
+  }
+
+  child_range used_children();
+  const_child_range used_children() const {
+auto Children = const_cast(this)->used_children();
+return const_child_range(Children.begin(), Children.end());
+  }
+
+  static bool classof(const OMPClause *T) {
+return T->getClauseKind() == llvm::omp::OMPC_nowait;
+  }
 };
 
 /// This represents 'untied' clause in the '#pragma omp ...' directive.
diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index 560de7da9913a..52b940e7f3c0a 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -3466,7 +3466,8 @@ bool 
RecursiveASTVisitor::VisitOMPOrderedClause(OMPOrderedClause *C) {
 }
 
 template 
-bool RecursiveASTVisitor::VisitOMPNowaitClause(OMPNowaitClause *) {
+bool RecursiveASTVisitor::VisitOMPNowaitClause(OMPNowaitClause *C) {
+  TRY_TO(TraverseStmt(C->getCondition()));
   return true;
 }
 
diff --git a/clang/include/clang/Sema/SemaOpenMP.h 
b/clang/include/clang/Sema/SemaOpenMP.h
index 64f0cfa0676af..8af56c087a896 100644
--- a/clang/include/clang/Sema/SemaOpenMP.h
+++ b/clang/include/clang/Sema/SemaOpenMP.h
@@ -1001,8 +1001,10 @@ class SemaOpenMP : public SemaBase {
   OMPClause *ActOnOpenMPClause(OpenMPClauseKind Kind, SourceLocation StartLoc,
SourceLocation EndLoc);
   /// Called on well-formed 'nowait' clause.
-  OMPClause *ActOnOpenMPNowaitClause(SourceLocation StartLoc,
- SourceLocation EndLoc);
+  OMPClause *
+  ActOnOpenMPNowaitClause(SourceLocation StartLoc, SourceLocation EndLoc,
+  SourceLoc

[clang-tools-extra] [clang-tidy][NFC][doc] improve "options" sections of `bugprone-` and `modernize-` checks (PR #133525)

2025-03-29 Thread Baranov Victor via cfe-commits


@@ -53,4 +53,4 @@ Options
 
If set to non-zero, the check does not suggest edits that will transform

vbvictor wrote:

yes, thanks for the notice

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


[clang] Reland [HIP] fix host min/max in header (PR #133590)

2025-03-29 Thread Yaxun Liu via cfe-commits

https://github.com/yxsamliu updated 
https://github.com/llvm/llvm-project/pull/133590

>From 3f533ad3a54b199e96a14e91f01b9714c30f52c2 Mon Sep 17 00:00:00 2001
From: "Yaxun (Sam) Liu" 
Date: Sun, 25 Feb 2024 11:13:40 -0500
Subject: [PATCH] [HIP] fix host min/max in header

CUDA defines min/max functions for host in global namespace.
HIP header needs to define them too to be compatible.
Currently only min/max(int, int) is defined. This causes
wrong result for arguments that are out of range for int.
This patch defines host min/max functions to be compatible
with CUDA.

Since some HIP apps defined min/max functions by themselves, newly
added min/max function are under the control of macro
`__HIP_DEFINE_EXTENDED_HOST_MIN_MAX__`, which is 0 by
default. In the future, this will change to 1 by
default after most existing HIP apps adopt this change.

Also allows users to define
`__HIP_NO_HOST_MIN_MAX_IN_GLOBAL_NAMESPACE__` to disable
host max/min in global namespace.

min/max functions with mixed signed/unsigned integer
parameters are not defined unless
`__HIP_DEFINE_MIXED_HOST_MIN_MAX__` is defined.

Fixes: SWDEV-446564
---
 clang/lib/Headers/__clang_hip_math.h | 86 ++--
 1 file changed, 80 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Headers/__clang_hip_math.h 
b/clang/lib/Headers/__clang_hip_math.h
index f6c06eaf4afe0..759e742c9d012 100644
--- a/clang/lib/Headers/__clang_hip_math.h
+++ b/clang/lib/Headers/__clang_hip_math.h
@@ -1311,15 +1311,89 @@ float min(float __x, float __y) { return 
__builtin_fminf(__x, __y); }
 __DEVICE__
 double min(double __x, double __y) { return __builtin_fmin(__x, __y); }
 
-#if !defined(__HIPCC_RTC__) && !defined(__OPENMP_AMDGCN__)
-__host__ inline static int min(int __arg1, int __arg2) {
-  return __arg1 < __arg2 ? __arg1 : __arg2;
+// Define host min/max functions.
+#if !defined(__HIPCC_RTC__) && !defined(__OPENMP_AMDGCN__) &&  
\
+!defined(__HIP_NO_HOST_MIN_MAX_IN_GLOBAL_NAMESPACE__)
+
+// TODO: make this default to 1 after existing HIP apps adopting this change.
+#ifndef __HIP_DEFINE_EXTENDED_HOST_MIN_MAX__
+#define __HIP_DEFINE_EXTENDED_HOST_MIN_MAX__ 0
+#endif
+
+#ifndef __HIP_DEFINE_MIXED_HOST_MIN_MAX__
+#define __HIP_DEFINE_MIXED_HOST_MIN_MAX__ 0
+#endif
+
+#pragma push_macro("DEFINE_MIN_MAX_FUNCTIONS")
+#pragma push_macro("DEFINE_MIN_MAX_FUNCTIONS")
+#define DEFINE_MIN_MAX_FUNCTIONS(ret_type, type1, type2)   
\
+  inline ret_type min(const type1 __a, const type2 __b) {  
\
+return (__a < __b) ? __a : __b;
\
+  }
\
+  inline ret_type max(const type1 __a, const type2 __b) {  
\
+return (__a > __b) ? __a : __b;
\
+  }
+
+// Define min and max functions for same type comparisons
+DEFINE_MIN_MAX_FUNCTIONS(int, int, int)
+
+#if __HIP_DEFINE_EXTENDED_HOST_MIN_MAX__
+DEFINE_MIN_MAX_FUNCTIONS(unsigned int, unsigned int, unsigned int)
+DEFINE_MIN_MAX_FUNCTIONS(long, long, long)
+DEFINE_MIN_MAX_FUNCTIONS(unsigned long, unsigned long, unsigned long)
+DEFINE_MIN_MAX_FUNCTIONS(long long, long long, long long)
+DEFINE_MIN_MAX_FUNCTIONS(unsigned long long, unsigned long long,
+ unsigned long long)
+#endif // if __HIP_DEFINE_EXTENDED_HOST_MIN_MAX__
+
+// The host min/max functions below accept mixed signed/unsigned integer
+// parameters and perform unsigned comparisons, which may produce unexpected
+// results if a signed integer was passed unintentionally. To avoid this
+// happening silently, these overloaded functions are not defined by default.
+// However, for compatibility with CUDA, they will be defined if users define
+// __HIP_DEFINE_MIXED_HOST_MIN_MAX__.
+#if __HIP_DEFINE_MIXED_HOST_MIN_MAX__
+DEFINE_MIN_MAX_FUNCTIONS(unsigned int, int, unsigned int)
+DEFINE_MIN_MAX_FUNCTIONS(unsigned int, unsigned int, int)
+DEFINE_MIN_MAX_FUNCTIONS(unsigned long, long, unsigned long)
+DEFINE_MIN_MAX_FUNCTIONS(unsigned long, unsigned long, long)
+DEFINE_MIN_MAX_FUNCTIONS(unsigned long long, long long, unsigned long long)
+DEFINE_MIN_MAX_FUNCTIONS(unsigned long long, unsigned long long, long long)
+#endif // if __HIP_DEFINE_MIXED_HOST_MIN_MAX__
+
+// Floating-point comparisons using built-in functions
+#if __HIP_DEFINE_EXTENDED_HOST_MIN_MAX__
+inline float min(float const __a, float const __b) {
+  return __builtin_fminf(__a, __b);
+}
+inline double min(double const __a, double const __b) {
+  return __builtin_fmin(__a, __b);
+}
+inline double min(float const __a, double const __b) {
+  return __builtin_fmin(__a, __b);
+}
+inline double min(double const __a, float const __b) {
+  return __builtin_fmin(__a, __b);
 }
 
-__host__ inline static int max(int __arg1, int __arg2) {
-  return __arg1 > __arg2 ? __arg1 : __arg2;
+inline float max(float const __a, float const __b) {
+  return __builtin_

[clang] [Basic] Use SmallSet::insert_range (NFC) (PR #133594)

2025-03-29 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`clang-aarch64-sve2-vla-2stage` running on `linaro-g4-02` while building 
`clang` at step 12 "ninja check 2".

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


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

```
Step 12 (ninja check 2) failure: stage 2 checked (failure)
...
PASS: Flang :: Driver/print-resource-dir.F90 (24739 of 96438)
PASS: Flang :: Driver/parse-error.ll (24740 of 96438)
PASS: Flang :: Driver/predefined-macros-compiler-version.F90 (24741 of 96438)
PASS: Flang :: Driver/print-effective-triple.f90 (24742 of 96438)
PASS: Clangd Unit Tests :: ./ClangdTests/78/81 (24743 of 96438)
PASS: Flang :: Driver/phases.f90 (24744 of 96438)
PASS: Flang :: Driver/override-triple.ll (24745 of 96438)
PASS: Flang :: Driver/parse-fir-error.ll (24746 of 96438)
PASS: Flang :: Driver/missing-arg.f90 (24747 of 96438)
UNRESOLVED: Flang :: Driver/slp-vectorize.ll (24748 of 96438)
 TEST 'Flang :: Driver/slp-vectorize.ll' FAILED 

Test has no 'RUN:' line

PASS: Flang :: Driver/mlir-pass-pipeline.f90 (24749 of 96438)
PASS: Flang :: Driver/print-target-triple.f90 (24750 of 96438)
PASS: Flang :: Driver/print-pipeline-passes.f90 (24751 of 96438)
PASS: Flang :: Driver/parse-ir-error.f95 (24752 of 96438)
PASS: Flang :: Driver/include-header.f90 (24753 of 96438)
PASS: Flang :: Driver/pthread.f90 (24754 of 96438)
PASS: Flang :: Driver/mlink-builtin-bc.f90 (24755 of 96438)
PASS: Flang :: Driver/pp-fixed-form.f90 (24756 of 96438)
PASS: Flang :: Driver/pass-plugin-not-found.f90 (24757 of 96438)
PASS: Flang :: Driver/std2018-wrong.f90 (24758 of 96438)
PASS: Flang :: Driver/lto-bc.f90 (24759 of 96438)
PASS: Flang :: Driver/supported-suffices/f03-suffix.f03 (24760 of 96438)
PASS: Flang :: Driver/supported-suffices/f08-suffix.f08 (24761 of 96438)
PASS: Flang :: Driver/fixed-line-length.f90 (24762 of 96438)
PASS: Flang :: Driver/scanning-error.f95 (24763 of 96438)
PASS: Flang :: Driver/target-gpu-features.f90 (24764 of 96438)
PASS: Flang :: Driver/multiple-input-files.f90 (24765 of 96438)
PASS: Flang :: Driver/q-unused-arguments.f90 (24766 of 96438)
PASS: Flang :: Driver/target.f90 (24767 of 96438)
PASS: Flang :: Driver/tco-code-gen-llvm.fir (24768 of 96438)
PASS: Flang :: Driver/fsave-optimization-record.f90 (24769 of 96438)
PASS: Flang :: Driver/no-duplicate-main.f90 (24770 of 96438)
PASS: Flang :: Driver/mllvm.f90 (24771 of 96438)
PASS: Flang :: Driver/unsupported-vscale-max-min.f90 (24772 of 96438)
PASS: Flang :: Driver/input-from-stdin/input-from-stdin.f90 (24773 of 96438)
PASS: Flang :: Driver/unparse-with-modules.f90 (24774 of 96438)
PASS: Flang :: Driver/lto-flags.f90 (24775 of 96438)
PASS: Flang :: Driver/falias-analysis.f90 (24776 of 96438)
PASS: Flang :: Driver/target-machine-error.f90 (24777 of 96438)
PASS: Flang :: Driver/unparse-use-analyzed.f95 (24778 of 96438)
PASS: Flang :: Driver/std2018.f90 (24779 of 96438)
PASS: Flang :: Driver/optimization-remark-invalid.f90 (24780 of 96438)
PASS: Flang :: Driver/optimization-remark-backend.f90 (24781 of 96438)
PASS: Flang :: Driver/save-temps-use-module.f90 (24782 of 96438)
PASS: Flang :: Driver/prescanner-diag.f90 (24783 of 96438)
PASS: Flang :: Driver/save-temps.f90 (24784 of 96438)

```



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


[clang] Disable alias template CTAD for C++17 (PR #133597)

2025-03-29 Thread via cfe-commits

cor3ntin wrote:

I think the issue here is that there is no extension warning in C++17. There 
should probably be one. 
Search for `ExtWarn` in DiagnosticSemaKinds.td and how these `ext_` 
diagnostics are used 


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


[clang] [WebKit checkers] Treat Objective-C message send return value as safe (PR #133605)

2025-03-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Ryosuke Niwa (rniwa)


Changes

Objective-C selectors are supposed to return autoreleased object. Treat these 
return values as safe.

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


6 Files Affected:

- (modified) 
clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefCallArgsChecker.cpp (+8) 
- (modified) 
clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLocalVarsChecker.cpp (+8) 
- (modified) clang/test/Analysis/Checkers/WebKit/objc-mock-types.h (+5) 
- (modified) clang/test/Analysis/Checkers/WebKit/unretained-call-args-arc.mm 
(+9) 
- (modified) clang/test/Analysis/Checkers/WebKit/unretained-call-args.mm (+9) 
- (modified) clang/test/Analysis/Checkers/WebKit/unretained-local-vars.mm 
(+13-2) 


``diff
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefCallArgsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefCallArgsChecker.cpp
index ce8f0df697b06..13088920cfa19 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefCallArgsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefCallArgsChecker.cpp
@@ -47,6 +47,7 @@ class RawPtrRefCallArgsChecker
   virtual std::optional isUnsafePtr(QualType) const = 0;
   virtual bool isSafePtr(const CXXRecordDecl *Record) const = 0;
   virtual bool isSafePtrType(const QualType type) const = 0;
+  virtual bool isSafeExpr(const Expr *) const { return false; }
   virtual const char *ptrKind() const = 0;
 
   void checkASTDecl(const TranslationUnitDecl *TUD, AnalysisManager &MGR,
@@ -233,6 +234,8 @@ class RawPtrRefCallArgsChecker
 return true;
   if (EFA.isACallToEnsureFn(ArgOrigin))
 return true;
+  if (isSafeExpr(ArgOrigin))
+return true;
   return false;
 });
   }
@@ -469,6 +472,11 @@ class UnretainedCallArgsChecker final : public 
RawPtrRefCallArgsChecker {
 return isRetainPtrType(type);
   }
 
+  bool isSafeExpr(const Expr *E) const final {
+return ento::cocoa::isCocoaObjectRef(E->getType()) &&
+   isa(E);
+  }
+
   const char *ptrKind() const final { return "unretained"; }
 };
 
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLocalVarsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLocalVarsChecker.cpp
index d413e33a490c5..9975d1a91b681 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLocalVarsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLocalVarsChecker.cpp
@@ -179,6 +179,7 @@ class RawPtrRefLocalVarsChecker
   virtual std::optional isUnsafePtr(const QualType T) const = 0;
   virtual bool isSafePtr(const CXXRecordDecl *) const = 0;
   virtual bool isSafePtrType(const QualType) const = 0;
+  virtual bool isSafeExpr(const Expr *) const { return false; }
   virtual const char *ptrKind() const = 0;
 
   void checkASTDecl(const TranslationUnitDecl *TUD, AnalysisManager &MGR,
@@ -300,6 +301,9 @@ class RawPtrRefLocalVarsChecker
 if (EFA.isACallToEnsureFn(InitArgOrigin))
   return true;
 
+if (isSafeExpr(InitArgOrigin))
+  return true;
+
 if (auto *Ref = llvm::dyn_cast(InitArgOrigin)) {
   if (auto *MaybeGuardian =
   dyn_cast_or_null(Ref->getFoundDecl())) {
@@ -426,6 +430,10 @@ class UnretainedLocalVarsChecker final : public 
RawPtrRefLocalVarsChecker {
   bool isSafePtrType(const QualType type) const final {
 return isRetainPtrType(type);
   }
+  bool isSafeExpr(const Expr *E) const final {
+return ento::cocoa::isCocoaObjectRef(E->getType()) &&
+   isa(E);
+  }
   const char *ptrKind() const final { return "unretained"; }
 };
 
diff --git a/clang/test/Analysis/Checkers/WebKit/objc-mock-types.h 
b/clang/test/Analysis/Checkers/WebKit/objc-mock-types.h
index ef46a7c0a2925..059a203e3b0d1 100644
--- a/clang/test/Analysis/Checkers/WebKit/objc-mock-types.h
+++ b/clang/test/Analysis/Checkers/WebKit/objc-mock-types.h
@@ -71,6 +71,7 @@ __attribute__((objc_root_class))
 + (Class) superclass;
 - (instancetype) init;
 - (instancetype)retain;
+- (instancetype)autorelease;
 - (void)release;
 - (BOOL)isKindOfClass:(Class)aClass;
 @end
@@ -221,6 +222,10 @@ template  struct RetainPtr {
   operator PtrType() const { return t; }
   operator bool() const { return t; }
 
+#if !__has_feature(objc_arc)
+  PtrType autorelease() { [[clang::suppress]] return [t autorelease]; }
+#endif
+
 private:
   CFTypeRef toCFTypeRef(id ptr) { return (__bridge CFTypeRef)ptr; }
   CFTypeRef toCFTypeRef(const void* ptr) { return (CFTypeRef)ptr; }
diff --git a/clang/test/Analysis/Checkers/WebKit/unretained-call-args-arc.mm 
b/clang/test/Analysis/Checkers/WebKit/unretained-call-args-arc.mm
index eb4735da60a05..f1f4d912663aa 100644
--- a/clang/test/Analysis/Checkers/WebKit/unretained-call-args-arc.mm
+++ b/clang/test/Analysis/Checkers/WebKit/unretained-call-args-arc.mm
@@ -18,6 +18,7 @@ void foo() {

[clang] cuda clang: Add support for CUDA surfaces (PR #132883)

2025-03-29 Thread Austin Schuh via cfe-commits

AustinSchuh wrote:

> If the header is compileable without CUDA SDK (maybe with some stub headers 
> in tests Inputs), then a source file with a lot of builtin calls and 
> [autogenerated 
> checks](https://github.com/llvm/llvm-project/blob/d724bab8064685c98cdded88157b6e2245e0d7bc/llvm/utils/update_cc_test_checks.py#L2)
>  to verify produced instructions would do.

That wasn't too bad, done!

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


[clang] [clang-tools-extra] [libcxx] [clang] improved preservation of template keyword (PR #133610)

2025-03-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-modules

Author: Matheus Izvekov (mizvekov)


Changes

This makes it so clang can better represent the abscence of the template 
keyword for a template which cannot be resolved due to a dependent prefix.

The tracking of the template keyword is removed from the NestedNameSpecifier, 
and added to the last type node which had it missing, the 
DependentTemplateSpecializationType (DTST).

The DTST and the DependentTemplateName are refactored to share most of their 
implementation.

That refactoring along with the removal of the TypeSpecWithTemplate kind from 
the nested name specifiers amounts to a large amount of code removed, making 
this patch a small performance improvement overall.

![image](https://github.com/user-attachments/assets/e79d3b21-2f91-43e9-b89d-7f7ac0da6a6e)

This will also enable future further simplifications.

As a drive-by, this removes some special cases from the type printer, allowing 
template arguments within NestedNameSpecifiers to not have their nested names 
suppressed when printing.

---

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


66 Files Affected:

- (modified) clang-tools-extra/clangd/AST.cpp (+1-2) 
- (modified) clang-tools-extra/clangd/CodeComplete.cpp (-1) 
- (modified) clang-tools-extra/clangd/DumpAST.cpp (-1) 
- (modified) clang-tools-extra/clangd/FindTarget.cpp (-1) 
- (modified) clang-tools-extra/include-cleaner/lib/WalkAST.cpp (-1) 
- (modified) clang/docs/ReleaseNotes.rst (+4) 
- (modified) clang/include/clang/AST/ASTContext.h (+9-11) 
- (modified) clang/include/clang/AST/ASTImporter.h (+8) 
- (modified) clang/include/clang/AST/ASTNodeTraverser.h (+1-2) 
- (modified) clang/include/clang/AST/AbstractBasicReader.h (+1-3) 
- (modified) clang/include/clang/AST/AbstractBasicWriter.h (-1) 
- (modified) clang/include/clang/AST/NestedNameSpecifier.h (+5-15) 
- (modified) clang/include/clang/AST/ODRHash.h (+1) 
- (modified) clang/include/clang/AST/PropertiesBase.td (+8-7) 
- (modified) clang/include/clang/AST/RecursiveASTVisitor.h (+2-3) 
- (modified) clang/include/clang/AST/TemplateName.h (+56-77) 
- (modified) clang/include/clang/AST/Type.h (+8-14) 
- (modified) clang/include/clang/AST/TypeLoc.h (+5-4) 
- (modified) clang/include/clang/AST/TypeProperties.td (+25-22) 
- (modified) clang/include/clang/Sema/DeclSpec.h (+1-2) 
- (modified) clang/lib/AST/ASTContext.cpp (+81-133) 
- (modified) clang/lib/AST/ASTImporter.cpp (+22-41) 
- (modified) clang/lib/AST/ASTStructuralEquivalence.cpp (+19-18) 
- (modified) clang/lib/AST/ItaniumMangle.cpp (+22-13) 
- (modified) clang/lib/AST/NestedNameSpecifier.cpp (+23-79) 
- (modified) clang/lib/AST/ODRHash.cpp (+15-4) 
- (modified) clang/lib/AST/QualTypeNames.cpp (+3-5) 
- (modified) clang/lib/AST/TemplateName.cpp (+58-9) 
- (modified) clang/lib/AST/TextNodeDumper.cpp (-4) 
- (modified) clang/lib/AST/Type.cpp (+10-17) 
- (modified) clang/lib/AST/TypeLoc.cpp (+3-2) 
- (modified) clang/lib/AST/TypePrinter.cpp (+7-5) 
- (modified) clang/lib/ExtractAPI/DeclarationFragments.cpp (-7) 
- (modified) clang/lib/Index/IndexTypeSourceInfo.cpp (-1) 
- (modified) clang/lib/Parse/ParseExprCXX.cpp (+4-4) 
- (modified) clang/lib/Sema/DeclSpec.cpp (+3-3) 
- (modified) clang/lib/Sema/HeuristicResolver.cpp (+3-3) 
- (modified) clang/lib/Sema/SemaCXXScopeSpec.cpp (+12-19) 
- (modified) clang/lib/Sema/SemaCodeComplete.cpp (+3-3) 
- (modified) clang/lib/Sema/SemaCoroutine.cpp (+1-2) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+12-12) 
- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+1-2) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+1-1) 
- (modified) clang/lib/Sema/SemaExprCXX.cpp (-1) 
- (modified) clang/lib/Sema/SemaLookup.cpp (+1-3) 
- (modified) clang/lib/Sema/SemaTemplate.cpp (+19-22) 
- (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+2-1) 
- (modified) clang/lib/Sema/TreeTransform.h (+73-76) 
- (modified) clang/lib/Serialization/ASTReader.cpp (+2-8) 
- (modified) clang/lib/Serialization/ASTWriter.cpp (-2) 
- (modified) clang/lib/Tooling/Syntax/BuildTree.cpp (-2) 
- (modified) clang/test/AST/ast-dump-decl.cpp (+10-10) 
- (modified) clang/test/AST/ast-dump-expr.cpp (+1-2) 
- (modified) clang/test/AST/ast-dump-templates.cpp (+3-3) 
- (modified) clang/test/CXX/class.access/p6.cpp (+2-2) 
- (modified) clang/test/CXX/drs/cwg2xx.cpp (+2-2) 
- (modified) clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp 
(+1-1) 
- (modified) clang/test/SemaCXX/static-assert.cpp (+3-1) 
- (modified) clang/test/SemaTemplate/aggregate-deduction-candidate.cpp (+4-4) 
- (modified) clang/test/SemaTemplate/dependent-template-recover.cpp (+18) 
- (modified) clang/test/SemaTemplate/instantiate-requires-expr.cpp (+2-2) 
- (modified) clang/tools/libclang/CIndex.cpp (-2) 
- (modified) 
libcxx/test/std/containers/sequences/array/array.overview/nttp.verify.cpp 
(+1-1) 
- (modified) 
libcxx/test/std/utilities/smartptr/adapt/inout_ptr/inout_ptr.verify.cpp (+

[clang] [clang-tools-extra] [libcxx] [clang] improved preservation of template keyword (PR #133610)

2025-03-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-libcxx

Author: Matheus Izvekov (mizvekov)


Changes

This makes it so clang can better represent the abscence of the template 
keyword for a template which cannot be resolved due to a dependent prefix.

The tracking of the template keyword is removed from the NestedNameSpecifier, 
and added to the last type node which had it missing, the 
DependentTemplateSpecializationType (DTST).

The DTST and the DependentTemplateName are refactored to share most of their 
implementation.

That refactoring along with the removal of the TypeSpecWithTemplate kind from 
the nested name specifiers amounts to a large amount of code removed, making 
this patch a small performance improvement overall.

![image](https://github.com/user-attachments/assets/e79d3b21-2f91-43e9-b89d-7f7ac0da6a6e)

This will also enable future further simplifications.

As a drive-by, this removes some special cases from the type printer, allowing 
template arguments within NestedNameSpecifiers to not have their nested names 
suppressed when printing.

---

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


66 Files Affected:

- (modified) clang-tools-extra/clangd/AST.cpp (+1-2) 
- (modified) clang-tools-extra/clangd/CodeComplete.cpp (-1) 
- (modified) clang-tools-extra/clangd/DumpAST.cpp (-1) 
- (modified) clang-tools-extra/clangd/FindTarget.cpp (-1) 
- (modified) clang-tools-extra/include-cleaner/lib/WalkAST.cpp (-1) 
- (modified) clang/docs/ReleaseNotes.rst (+4) 
- (modified) clang/include/clang/AST/ASTContext.h (+9-11) 
- (modified) clang/include/clang/AST/ASTImporter.h (+8) 
- (modified) clang/include/clang/AST/ASTNodeTraverser.h (+1-2) 
- (modified) clang/include/clang/AST/AbstractBasicReader.h (+1-3) 
- (modified) clang/include/clang/AST/AbstractBasicWriter.h (-1) 
- (modified) clang/include/clang/AST/NestedNameSpecifier.h (+5-15) 
- (modified) clang/include/clang/AST/ODRHash.h (+1) 
- (modified) clang/include/clang/AST/PropertiesBase.td (+8-7) 
- (modified) clang/include/clang/AST/RecursiveASTVisitor.h (+2-3) 
- (modified) clang/include/clang/AST/TemplateName.h (+56-77) 
- (modified) clang/include/clang/AST/Type.h (+8-14) 
- (modified) clang/include/clang/AST/TypeLoc.h (+5-4) 
- (modified) clang/include/clang/AST/TypeProperties.td (+25-22) 
- (modified) clang/include/clang/Sema/DeclSpec.h (+1-2) 
- (modified) clang/lib/AST/ASTContext.cpp (+81-133) 
- (modified) clang/lib/AST/ASTImporter.cpp (+22-41) 
- (modified) clang/lib/AST/ASTStructuralEquivalence.cpp (+19-18) 
- (modified) clang/lib/AST/ItaniumMangle.cpp (+22-13) 
- (modified) clang/lib/AST/NestedNameSpecifier.cpp (+23-79) 
- (modified) clang/lib/AST/ODRHash.cpp (+15-4) 
- (modified) clang/lib/AST/QualTypeNames.cpp (+3-5) 
- (modified) clang/lib/AST/TemplateName.cpp (+58-9) 
- (modified) clang/lib/AST/TextNodeDumper.cpp (-4) 
- (modified) clang/lib/AST/Type.cpp (+10-17) 
- (modified) clang/lib/AST/TypeLoc.cpp (+3-2) 
- (modified) clang/lib/AST/TypePrinter.cpp (+7-5) 
- (modified) clang/lib/ExtractAPI/DeclarationFragments.cpp (-7) 
- (modified) clang/lib/Index/IndexTypeSourceInfo.cpp (-1) 
- (modified) clang/lib/Parse/ParseExprCXX.cpp (+4-4) 
- (modified) clang/lib/Sema/DeclSpec.cpp (+3-3) 
- (modified) clang/lib/Sema/HeuristicResolver.cpp (+3-3) 
- (modified) clang/lib/Sema/SemaCXXScopeSpec.cpp (+12-19) 
- (modified) clang/lib/Sema/SemaCodeComplete.cpp (+3-3) 
- (modified) clang/lib/Sema/SemaCoroutine.cpp (+1-2) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+12-12) 
- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+1-2) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+1-1) 
- (modified) clang/lib/Sema/SemaExprCXX.cpp (-1) 
- (modified) clang/lib/Sema/SemaLookup.cpp (+1-3) 
- (modified) clang/lib/Sema/SemaTemplate.cpp (+19-22) 
- (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+2-1) 
- (modified) clang/lib/Sema/TreeTransform.h (+73-76) 
- (modified) clang/lib/Serialization/ASTReader.cpp (+2-8) 
- (modified) clang/lib/Serialization/ASTWriter.cpp (-2) 
- (modified) clang/lib/Tooling/Syntax/BuildTree.cpp (-2) 
- (modified) clang/test/AST/ast-dump-decl.cpp (+10-10) 
- (modified) clang/test/AST/ast-dump-expr.cpp (+1-2) 
- (modified) clang/test/AST/ast-dump-templates.cpp (+3-3) 
- (modified) clang/test/CXX/class.access/p6.cpp (+2-2) 
- (modified) clang/test/CXX/drs/cwg2xx.cpp (+2-2) 
- (modified) clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp 
(+1-1) 
- (modified) clang/test/SemaCXX/static-assert.cpp (+3-1) 
- (modified) clang/test/SemaTemplate/aggregate-deduction-candidate.cpp (+4-4) 
- (modified) clang/test/SemaTemplate/dependent-template-recover.cpp (+18) 
- (modified) clang/test/SemaTemplate/instantiate-requires-expr.cpp (+2-2) 
- (modified) clang/tools/libclang/CIndex.cpp (-2) 
- (modified) 
libcxx/test/std/containers/sequences/array/array.overview/nttp.verify.cpp 
(+1-1) 
- (modified) 
libcxx/test/std/utilities/smartptr/adapt/inout_ptr/inout_ptr.verify.cpp (+1-1) 
-

[clang] [clang-tools-extra] [libcxx] [clang] improved preservation of template keyword (PR #133610)

2025-03-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-coroutines

Author: Matheus Izvekov (mizvekov)


Changes

This makes it so clang can better represent the abscence of the template 
keyword for a template which cannot be resolved due to a dependent prefix.

The tracking of the template keyword is removed from the NestedNameSpecifier, 
and added to the last type node which had it missing, the 
DependentTemplateSpecializationType (DTST).

The DTST and the DependentTemplateName are refactored to share most of their 
implementation.

That refactoring along with the removal of the TypeSpecWithTemplate kind from 
the nested name specifiers amounts to a large amount of code removed, making 
this patch a small performance improvement overall.

![image](https://github.com/user-attachments/assets/e79d3b21-2f91-43e9-b89d-7f7ac0da6a6e)

This will also enable future further simplifications.

As a drive-by, this removes some special cases from the type printer, allowing 
template arguments within NestedNameSpecifiers to not have their nested names 
suppressed when printing.

---

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


66 Files Affected:

- (modified) clang-tools-extra/clangd/AST.cpp (+1-2) 
- (modified) clang-tools-extra/clangd/CodeComplete.cpp (-1) 
- (modified) clang-tools-extra/clangd/DumpAST.cpp (-1) 
- (modified) clang-tools-extra/clangd/FindTarget.cpp (-1) 
- (modified) clang-tools-extra/include-cleaner/lib/WalkAST.cpp (-1) 
- (modified) clang/docs/ReleaseNotes.rst (+4) 
- (modified) clang/include/clang/AST/ASTContext.h (+9-11) 
- (modified) clang/include/clang/AST/ASTImporter.h (+8) 
- (modified) clang/include/clang/AST/ASTNodeTraverser.h (+1-2) 
- (modified) clang/include/clang/AST/AbstractBasicReader.h (+1-3) 
- (modified) clang/include/clang/AST/AbstractBasicWriter.h (-1) 
- (modified) clang/include/clang/AST/NestedNameSpecifier.h (+5-15) 
- (modified) clang/include/clang/AST/ODRHash.h (+1) 
- (modified) clang/include/clang/AST/PropertiesBase.td (+8-7) 
- (modified) clang/include/clang/AST/RecursiveASTVisitor.h (+2-3) 
- (modified) clang/include/clang/AST/TemplateName.h (+56-77) 
- (modified) clang/include/clang/AST/Type.h (+8-14) 
- (modified) clang/include/clang/AST/TypeLoc.h (+5-4) 
- (modified) clang/include/clang/AST/TypeProperties.td (+25-22) 
- (modified) clang/include/clang/Sema/DeclSpec.h (+1-2) 
- (modified) clang/lib/AST/ASTContext.cpp (+81-133) 
- (modified) clang/lib/AST/ASTImporter.cpp (+22-41) 
- (modified) clang/lib/AST/ASTStructuralEquivalence.cpp (+19-18) 
- (modified) clang/lib/AST/ItaniumMangle.cpp (+22-13) 
- (modified) clang/lib/AST/NestedNameSpecifier.cpp (+23-79) 
- (modified) clang/lib/AST/ODRHash.cpp (+15-4) 
- (modified) clang/lib/AST/QualTypeNames.cpp (+3-5) 
- (modified) clang/lib/AST/TemplateName.cpp (+58-9) 
- (modified) clang/lib/AST/TextNodeDumper.cpp (-4) 
- (modified) clang/lib/AST/Type.cpp (+10-17) 
- (modified) clang/lib/AST/TypeLoc.cpp (+3-2) 
- (modified) clang/lib/AST/TypePrinter.cpp (+7-5) 
- (modified) clang/lib/ExtractAPI/DeclarationFragments.cpp (-7) 
- (modified) clang/lib/Index/IndexTypeSourceInfo.cpp (-1) 
- (modified) clang/lib/Parse/ParseExprCXX.cpp (+4-4) 
- (modified) clang/lib/Sema/DeclSpec.cpp (+3-3) 
- (modified) clang/lib/Sema/HeuristicResolver.cpp (+3-3) 
- (modified) clang/lib/Sema/SemaCXXScopeSpec.cpp (+12-19) 
- (modified) clang/lib/Sema/SemaCodeComplete.cpp (+3-3) 
- (modified) clang/lib/Sema/SemaCoroutine.cpp (+1-2) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+12-12) 
- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+1-2) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+1-1) 
- (modified) clang/lib/Sema/SemaExprCXX.cpp (-1) 
- (modified) clang/lib/Sema/SemaLookup.cpp (+1-3) 
- (modified) clang/lib/Sema/SemaTemplate.cpp (+19-22) 
- (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+2-1) 
- (modified) clang/lib/Sema/TreeTransform.h (+73-76) 
- (modified) clang/lib/Serialization/ASTReader.cpp (+2-8) 
- (modified) clang/lib/Serialization/ASTWriter.cpp (-2) 
- (modified) clang/lib/Tooling/Syntax/BuildTree.cpp (-2) 
- (modified) clang/test/AST/ast-dump-decl.cpp (+10-10) 
- (modified) clang/test/AST/ast-dump-expr.cpp (+1-2) 
- (modified) clang/test/AST/ast-dump-templates.cpp (+3-3) 
- (modified) clang/test/CXX/class.access/p6.cpp (+2-2) 
- (modified) clang/test/CXX/drs/cwg2xx.cpp (+2-2) 
- (modified) clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp 
(+1-1) 
- (modified) clang/test/SemaCXX/static-assert.cpp (+3-1) 
- (modified) clang/test/SemaTemplate/aggregate-deduction-candidate.cpp (+4-4) 
- (modified) clang/test/SemaTemplate/dependent-template-recover.cpp (+18) 
- (modified) clang/test/SemaTemplate/instantiate-requires-expr.cpp (+2-2) 
- (modified) clang/tools/libclang/CIndex.cpp (-2) 
- (modified) 
libcxx/test/std/containers/sequences/array/array.overview/nttp.verify.cpp 
(+1-1) 
- (modified) 
libcxx/test/std/utilities/smartptr/adapt/inout_ptr/inout_ptr.verify.cpp (+1-1

[clang] [clang-tools-extra] [lldb] Reland: [clang] preserve class type sugar when taking pointer to member (PR #132401)

2025-03-29 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

@alexfh should be fixed by https://github.com/llvm/llvm-project/pull/133613

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


[clang] [clang-format]: Add `StaticInlineOnly` and `StaticInline` options to `ShortFunctionStyle` (PR #133598)

2025-03-29 Thread via cfe-commits


@@ -15120,6 +15120,85 @@ TEST_F(FormatTest, 
PullInlineFunctionDefinitionsIntoSingleLine) {
MergeInlineOnly);
 }
 
+TEST_F(FormatTest, PullStaticInlineFunctionDefinitionsIntoSingleLine) {
+  FormatStyle MergeStaticInlineOnly = getLLVMStyle();
+  MergeStaticInlineOnly.AllowShortFunctionsOnASingleLine =
+  FormatStyle::SFS_StaticInlineOnly;
+  verifyFormat("static inline int f() { return 42; }",
+   "static inline int f() {\n"
+   "  return 42; \n"
+   "}",
+   MergeStaticInlineOnly);
+  verifyFormat("inline static int f() { return 42; }",
+   "inline static int f() \n"
+   "{\n"
+   "  return 42; \n"
+   "}",
+   MergeStaticInlineOnly);
+  verifyNoChange("int f() {\n"
+ "  return 42;\n"
+ "}",
+ MergeStaticInlineOnly);
+
+  verifyFormat("void f1(void) {\n"
+   "}",
+   "void f1(void)\n"
+   "{\n"
+   "}",
+   MergeStaticInlineOnly);
+
+  verifyNoChange("int f2(int a, int b) {\n"
+ "  return a + b;\n"
+ "}",
+ MergeStaticInlineOnly);
+
+  verifyNoChange("static void f3(void) {\n"
+ "}\n",
+ MergeStaticInlineOnly);
+
+  verifyFormat("static int f4(int a, int b) {\n"
+   "  return a + b;\n"
+   "}\n",
+   MergeStaticInlineOnly);
+
+  verifyNoChange("static inline void f5(void) {}", MergeStaticInlineOnly);
+
+  verifyFormat("static inline int f6(int a, int b) { return a + b; }",
+   "static inline int f6(int a, int b) \n"
+   "{ return a + b; }",
+   MergeStaticInlineOnly);
+
+  verifyFormat("int f(int a, int b) {\n"
+   "  return a + b;\n"
+   "}",
+   "int f(int a, int b) { return a + b; }", MergeStaticInlineOnly);
+
+  FormatStyle MergeStaticInline = getLLVMStyle();
+  MergeStaticInline.AllowShortFunctionsOnASingleLine =
+  FormatStyle::SFS_StaticInline;
+  verifyFormat("static inline int f() { return 42; }",
+   "static inline int f() {\n"
+   "  return 42; \n"
+   "}",
+   MergeStaticInline);
+  verifyFormat("inline static int f() { return 42; }",
+   "inline static int f() \n"
+   "{\n"
+   "  return 42; \n"
+   "}",
+   MergeStaticInline);
+  verifyNoChange("int f() {\n"
+ "  return 42;\n"
+ "}",
+ MergeStaticInline);
+
+  verifyFormat("void f1(void) {}",
+   "void f1(void)\n"
+   "{\n"
+   "}",
+   MergeStaticInline);
+}

irymarchyk wrote:

I've added some tests with different attributes in different places. If you 
have any idea what should be added - small example (just code line) would be 
appreciated.

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


[clang] [clang-format]: Add `StaticInlineOnly` and `StaticInline` options to `ShortFunctionStyle` (PR #133598)

2025-03-29 Thread via cfe-commits


@@ -335,6 +336,32 @@ class LineJoiner {
 }
   }
 
+  if (Style.AllowShortFunctionsOnASingleLine ==
+  FormatStyle::SFS_StaticInlineOnly ||
+  Style.AllowShortFunctionsOnASingleLine ==
+  FormatStyle::SFS_StaticInline) {
+// Check if the current line belongs to a static inline function
+const auto *FirstNonCommentToken =
+TheLine ? TheLine->getFirstNonComment() : nullptr;
+
+// Look for 'static' and 'inline' keywords in any order
+bool HasStatic = false;
+bool HasInline = false;
+const FormatToken *Tok = FirstNonCommentToken;
+
+while (Tok && !Tok->is(TT_FunctionLBrace)) {
+  if (Tok->is(tok::kw_static))
+HasStatic = true;
+  if (Tok->is(tok::kw_inline))
+HasInline = true;
+  Tok = Tok->Next;
+}
+
+// If we found both static and inline, allow merging
+if (HasStatic && HasInline)

irymarchyk wrote:

Added additional check in while(). Please take a look.

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


[clang] [clang-format]: Add `StaticInlineOnly` and `StaticInline` options to `ShortFunctionStyle` (PR #133598)

2025-03-29 Thread via cfe-commits


@@ -15120,6 +15120,85 @@ TEST_F(FormatTest, 
PullInlineFunctionDefinitionsIntoSingleLine) {
MergeInlineOnly);
 }
 
+TEST_F(FormatTest, PullStaticInlineFunctionDefinitionsIntoSingleLine) {
+  FormatStyle MergeStaticInlineOnly = getLLVMStyle();
+  MergeStaticInlineOnly.AllowShortFunctionsOnASingleLine =
+  FormatStyle::SFS_StaticInlineOnly;
+  verifyFormat("static inline int f() { return 42; }",
+   "static inline int f() {\n"
+   "  return 42; \n"
+   "}",
+   MergeStaticInlineOnly);
+  verifyFormat("inline static int f() { return 42; }",
+   "inline static int f() \n"
+   "{\n"
+   "  return 42; \n"
+   "}",
+   MergeStaticInlineOnly);
+  verifyNoChange("int f() {\n"
+ "  return 42;\n"
+ "}",
+ MergeStaticInlineOnly);
+
+  verifyFormat("void f1(void) {\n"
+   "}",
+   "void f1(void)\n"
+   "{\n"
+   "}",
+   MergeStaticInlineOnly);
+
+  verifyNoChange("int f2(int a, int b) {\n"
+ "  return a + b;\n"
+ "}",
+ MergeStaticInlineOnly);
+
+  verifyNoChange("static void f3(void) {\n"
+ "}\n",
+ MergeStaticInlineOnly);
+
+  verifyFormat("static int f4(int a, int b) {\n"
+   "  return a + b;\n"
+   "}\n",
+   MergeStaticInlineOnly);
+
+  verifyNoChange("static inline void f5(void) {}", MergeStaticInlineOnly);
+
+  verifyFormat("static inline int f6(int a, int b) { return a + b; }",
+   "static inline int f6(int a, int b) \n"
+   "{ return a + b; }",
+   MergeStaticInlineOnly);
+
+  verifyFormat("int f(int a, int b) {\n"
+   "  return a + b;\n"
+   "}",
+   "int f(int a, int b) { return a + b; }", MergeStaticInlineOnly);
+
+  FormatStyle MergeStaticInline = getLLVMStyle();
+  MergeStaticInline.AllowShortFunctionsOnASingleLine =
+  FormatStyle::SFS_StaticInline;
+  verifyFormat("static inline int f() { return 42; }",
+   "static inline int f() {\n"
+   "  return 42; \n"
+   "}",
+   MergeStaticInline);
+  verifyFormat("inline static int f() { return 42; }",
+   "inline static int f() \n"
+   "{\n"
+   "  return 42; \n"
+   "}",
+   MergeStaticInline);
+  verifyNoChange("int f() {\n"
+ "  return 42;\n"
+ "}",
+ MergeStaticInline);
+
+  verifyFormat("void f1(void) {}",
+   "void f1(void)\n"
+   "{\n"
+   "}",
+   MergeStaticInline);
+}

irymarchyk wrote:

I have no preference regarding constexpr because it was not mentioned in 
'Inline' or 'InlineOnly' options before. Right now it won't be formatted if 
StaticInline is specified (I added unit test to show this). Please let me know 
if I need to change this.

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


[clang] [clang-format]: Add `StaticInlineOnly` and `StaticInline` options to `ShortFunctionStyle` (PR #133598)

2025-03-29 Thread via cfe-commits


@@ -863,6 +870,12 @@ struct FormatStyle {
 ///   void f() {}
 /// \endcode
 SFS_Inline,
+/// Only merge functions defined as static inline. Implies ``empty``.

irymarchyk wrote:

Thanks, fixed. Now it mention that empty function also merged.

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


[clang] [clang-format]: Add `StaticInlineOnly` and `StaticInline` options to `ShortFunctionStyle` (PR #133598)

2025-03-29 Thread via cfe-commits


@@ -335,6 +336,32 @@ class LineJoiner {
 }
   }
 
+  if (Style.AllowShortFunctionsOnASingleLine ==
+  FormatStyle::SFS_StaticInlineOnly ||
+  Style.AllowShortFunctionsOnASingleLine ==
+  FormatStyle::SFS_StaticInline) {
+// Check if the current line belongs to a static inline function
+const auto *FirstNonCommentToken =
+TheLine ? TheLine->getFirstNonComment() : nullptr;
+
+// Look for 'static' and 'inline' keywords in any order
+bool HasStatic = false;
+bool HasInline = false;
+const FormatToken *Tok = FirstNonCommentToken;
+
+while (Tok && !Tok->is(TT_FunctionLBrace)) {
+  if (Tok->is(tok::kw_static))
+HasStatic = true;
+  if (Tok->is(tok::kw_inline))
+HasInline = true;
+  Tok = Tok->Next;
+}
+
+// If we found both static and inline, allow merging

irymarchyk wrote:

Thanks, fixed

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


[clang] [clang] implement common-sugar for adjusted member-pointers (PR #133613)

2025-03-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Matheus Izvekov (mizvekov)


Changes

This implements a missing case for an adjusted member-pointer in 
getCommonSugaredType, when that was originally implemented here: 
https://github.com/llvm/llvm-project/pull/130537

This missing case could otherwise cause a crash, so this is a regression fix.

This should fix the crash reported here: 
https://github.com/llvm/llvm-project/pull/132401#issuecomment-2764331907

No release notes, since this regression and its underlying feature were never 
released.

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


2 Files Affected:

- (modified) clang/lib/AST/ASTContext.cpp (+9-1) 
- (modified) clang/test/SemaCXX/sugar-common-types.cpp (+16) 


``diff
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index c9d1bea4c623a..2d9480ebcf00c 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -14135,7 +14135,6 @@ static QualType getCommonSugarTypeNode(ASTContext &Ctx, 
const Type *X,
 CANONICAL_TYPE(IncompleteArray)
 CANONICAL_TYPE(HLSLAttributedResource)
 CANONICAL_TYPE(LValueReference)
-CANONICAL_TYPE(MemberPointer)
 CANONICAL_TYPE(ObjCInterface)
 CANONICAL_TYPE(ObjCObject)
 CANONICAL_TYPE(ObjCObjectPointer)
@@ -14313,6 +14312,15 @@ static QualType getCommonSugarTypeNode(ASTContext 
&Ctx, const Type *X,
   return QualType();
 return Ctx.getUsingType(CD, Ctx.getQualifiedType(Underlying));
   }
+  case Type::MemberPointer: {
+const auto *PX = cast(X),
+   *PY = cast(Y);
+CXXRecordDecl *Cls = PX->getMostRecentCXXRecordDecl();
+assert(Cls == PY->getMostRecentCXXRecordDecl());
+return Ctx.getMemberPointerType(
+::getCommonPointeeType(Ctx, PX, PY),
+::getCommonQualifier(Ctx, PX, PY, /*IsSame=*/false), Cls);
+  }
   case Type::CountAttributed: {
 const auto *DX = cast(X),
*DY = cast(Y);
diff --git a/clang/test/SemaCXX/sugar-common-types.cpp 
b/clang/test/SemaCXX/sugar-common-types.cpp
index a21032517b2ba..d58f6cdd900fc 100644
--- a/clang/test/SemaCXX/sugar-common-types.cpp
+++ b/clang/test/SemaCXX/sugar-common-types.cpp
@@ -186,3 +186,19 @@ namespace arrays {
 // expected-error@-1 {{lvalue of type 'const volatile volatile B1[1]' (aka 
'const volatile volatile int[1]')}}
   } // namespace balanced_qualifiers
 } // namespace arrays
+
+namespace member_pointers {
+  template  struct W {
+X1 a;
+Y1 b;
+  };
+  struct W1 : W {};
+  struct W2 : W {};
+
+  N t1 = 0 ? &W::a : &W::b;
+  // expected-error@-1 {{rvalue of type 'B1 W::*'}}
+
+  // FIXME: adjusted MemberPointer does not preserve qualifier
+  N t3 = 0 ? &W1::a : &W2::b;
+  // expected-error@-1 {{rvalue of type 'B1 W::*'}}
+} // namespace member_pointers

``




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


[clang] [Driver] Add linker options to support statical linking to shared flang-rt on AIX. (PR #131822)

2025-03-29 Thread Hubert Tong via cfe-commits


@@ -127,9 +127,19 @@ void aix::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   }
 
   // Force static linking when "-static" is present.
-  if (Args.hasArg(options::OPT_static))
+  if (Args.hasArg(options::OPT_static)) {
 CmdArgs.push_back("-bnso");
 
+if (D.IsFlangMode()) {
+  // The folllowing linker options are needed to statically link to the
+  // shared libflang_rt.runtime.a on AIX
+  CmdArgs.push_back("-bI:/usr/lib/syscalls.exp");
+  CmdArgs.push_back("-bI:/usr/lib/aio.exp");
+  CmdArgs.push_back("-bI:/usr/lib/threads.exp");
+  CmdArgs.push_back("-lcrypt");
+}

hubert-reinterpretcast wrote:

Does this add extra options even when `libflang_rt.runtime.a` is not being 
linked in?
See 
https://github.com/llvm/llvm-project/blob/main/clang/lib/Driver/ToolChains/AIX.cpp#L359-L365


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


[clang] Disable alias template CTAD for C++17 (PR #133597)

2025-03-29 Thread Matheus Izvekov via cfe-commits


@@ -9895,26 +9895,30 @@ QualType 
Sema::DeduceTemplateSpecializationFromInitializer(
   if (!Template) {
 if (auto *AliasTemplate = dyn_cast_or_null(
 TemplateName.getAsTemplateDecl())) {
-  Diag(Kind.getLocation(),
-   diag::warn_cxx17_compat_ctad_for_alias_templates);
-  LookupTemplateDecl = AliasTemplate;
-  auto UnderlyingType = AliasTemplate->getTemplatedDecl()
-->getUnderlyingType()
-.getCanonicalType();
-  // C++ [over.match.class.deduct#3]: ..., the defining-type-id of A must 
be
-  // of the form
-  //   [typename] [nested-name-specifier] [template] simple-template-id
-  if (const auto *TST =
-  UnderlyingType->getAs()) {
-Template = dyn_cast_or_null(
-TST->getTemplateName().getAsTemplateDecl());
-  } else if (const auto *RT = UnderlyingType->getAs()) {
-// Cases where template arguments in the RHS of the alias are not
-// dependent. e.g.
-//   using AliasFoo = Foo;
-if (const auto *CTSD = llvm::dyn_cast(
-RT->getAsCXXRecordDecl()))
-  Template = CTSD->getSpecializedTemplate();
+  if (getLangOpts().CPlusPlus20) {
+LookupTemplateDecl = AliasTemplate;
+auto UnderlyingType = AliasTemplate->getTemplatedDecl()
+  ->getUnderlyingType()
+  .getCanonicalType();
+// C++ [over.match.class.deduct#3]: ..., the defining-type-id of A must
+// be of the form
+//   [typename] [nested-name-specifier] [template] simple-template-id
+if (const auto *TST =
+UnderlyingType->getAs()) {
+  Template = dyn_cast_or_null(
+  TST->getTemplateName().getAsTemplateDecl());
+} else if (const auto *RT = UnderlyingType->getAs()) {
+  // Cases where template arguments in the RHS of the alias are not
+  // dependent. e.g.
+  //   using AliasFoo = Foo;
+  if (const auto *CTSD =
+  llvm::dyn_cast(
+  RT->getAsCXXRecordDecl()))
+Template = CTSD->getSpecializedTemplate();
+}
+  } else {
+Diag(Kind.getLocation(),
+ diag::warn_cxx17_compat_ctad_for_alias_templates);

mizvekov wrote:

This being still a warning is incompatible with the purpose of the change.

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


[clang] Disable alias template CTAD for C++17 (PR #133597)

2025-03-29 Thread Matheus Izvekov via cfe-commits


@@ -113,7 +113,7 @@ namespace dependent {
   };
   template void f() {
 typename T::X tx = 0;
-typename T::Y ty = 0;
+typename T::template Y ty = 0;

mizvekov wrote:

This is just removing the test. Ideally this would still be tested under C++20.

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


[clang] [clang-format]: Add `StaticInlineOnly` and `StaticInline` options to `ShortFunctionStyle` (PR #133598)

2025-03-29 Thread Björn Schäpers via cfe-commits


@@ -15120,6 +15120,85 @@ TEST_F(FormatTest, 
PullInlineFunctionDefinitionsIntoSingleLine) {
MergeInlineOnly);
 }
 
+TEST_F(FormatTest, PullStaticInlineFunctionDefinitionsIntoSingleLine) {
+  FormatStyle MergeStaticInlineOnly = getLLVMStyle();
+  MergeStaticInlineOnly.AllowShortFunctionsOnASingleLine =
+  FormatStyle::SFS_StaticInlineOnly;
+  verifyFormat("static inline int f() { return 42; }",
+   "static inline int f() {\n"
+   "  return 42; \n"
+   "}",
+   MergeStaticInlineOnly);
+  verifyFormat("inline static int f() { return 42; }",
+   "inline static int f() \n"
+   "{\n"
+   "  return 42; \n"
+   "}",
+   MergeStaticInlineOnly);
+  verifyNoChange("int f() {\n"
+ "  return 42;\n"
+ "}",
+ MergeStaticInlineOnly);
+
+  verifyFormat("void f1(void) {\n"
+   "}",
+   "void f1(void)\n"
+   "{\n"
+   "}",
+   MergeStaticInlineOnly);
+
+  verifyNoChange("int f2(int a, int b) {\n"
+ "  return a + b;\n"
+ "}",
+ MergeStaticInlineOnly);
+
+  verifyNoChange("static void f3(void) {\n"
+ "}\n",
+ MergeStaticInlineOnly);
+
+  verifyFormat("static int f4(int a, int b) {\n"
+   "  return a + b;\n"
+   "}\n",
+   MergeStaticInlineOnly);
+
+  verifyNoChange("static inline void f5(void) {}", MergeStaticInlineOnly);
+
+  verifyFormat("static inline int f6(int a, int b) { return a + b; }",
+   "static inline int f6(int a, int b) \n"
+   "{ return a + b; }",
+   MergeStaticInlineOnly);
+
+  verifyFormat("int f(int a, int b) {\n"
+   "  return a + b;\n"
+   "}",
+   "int f(int a, int b) { return a + b; }", MergeStaticInlineOnly);
+
+  FormatStyle MergeStaticInline = getLLVMStyle();
+  MergeStaticInline.AllowShortFunctionsOnASingleLine =
+  FormatStyle::SFS_StaticInline;
+  verifyFormat("static inline int f() { return 42; }",
+   "static inline int f() {\n"
+   "  return 42; \n"
+   "}",
+   MergeStaticInline);
+  verifyFormat("inline static int f() { return 42; }",
+   "inline static int f() \n"
+   "{\n"
+   "  return 42; \n"
+   "}",
+   MergeStaticInline);
+  verifyNoChange("int f() {\n"
+ "  return 42;\n"
+ "}",
+ MergeStaticInline);
+
+  verifyFormat("void f1(void) {}",
+   "void f1(void)\n"
+   "{\n"
+   "}",
+   MergeStaticInline);
+}

HazardyKnusperkeks wrote:

Please add some tests with attributes.

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


[clang] [clang-format]: Add `StaticInlineOnly` and `StaticInline` options to `ShortFunctionStyle` (PR #133598)

2025-03-29 Thread via cfe-commits

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

>From cc9c8d79396b6be64910eda59c4f7bd1a1d0a839 Mon Sep 17 00:00:00 2001
From: Ivan Rymarchyk <>
Date: Sat, 29 Mar 2025 13:54:32 -0700
Subject: [PATCH 1/2] [clang-format]: Add `StaticInlineOnly` and `StaticInline`
 options to `ShortFunctionStyle`

Currently, the `ShortFunctionStyle` option in clang-format lacks the 
granularity to specifically control the single-line formatting of `static 
inline` C functions independently from other function types like regular empty 
functions.

**Problem:**

Users may want to enforce a style where:

1.  **Only `static inline` functions** are allowed on a single line (if they 
fit), forcing all other functions (including empty ones) onto multiple lines. 
This is useful for keeping utility/helper functions concise while maintaining a 
consistent multi-line format for primary function definitions.
2.  **`static inline` functions *or* empty functions** are allowed on a single 
line (if they fit), while other non-empty, non-`static inline` functions are 
forced onto multiple lines. This is a slightly less strict variation.

The existing `ShortFunctionStyle` options do not cover these specific C use 
cases adequately:

*   `None`: Forces all functions multi-line.
*   `Empty`: Allows *any* empty function on one line, not just `static inline` 
ones.
*   `All`: Allows any short function on one line.
*   `Inline`/`InlineOnly`: Primarily target C++ member functions or C++ free 
inline functions, not specifically the C `static inline` pattern.

**Proposed Solution:**

Introduce two new values for the `ShortFunctionStyle` enum (currently named 
`ShortFunctionStyle` internally, likely `SFS_...` values):

1.  **`StaticInlineOnly`**
*   **Configuration Name:** `StaticInlineOnly`
*   **Internal Enum Value (Suggestion):** `SFS_StaticInlineOnly`
*   **Behavior:** Allows *only* functions declared with both `static` and 
`inline` specifiers to be formatted on a single line, provided they fit within 
the `ColumnLimit`. All other functions (regular, static non-inline, inline 
non-static, empty or not) must be formatted across multiple lines.

2.  **`StaticInline`**
*   **Configuration Name:** `StaticInline`
*   **Internal Enum Value (Suggestion):** `SFS_StaticInline`
*   **Behavior:** Allows functions declared with both `static` and `inline` 
specifiers *or* functions with an empty body (`{}`) to be formatted on a single 
line, provided they fit within the `ColumnLimit`. Non-empty functions that are 
*not* `static inline` must be formatted across multiple lines. This effectively 
combines the `SFS_Empty` behavior with allowing non-empty `static inline` 
functions.

**Expected Formatting:**

*   **With `ShortFunctionStyle: StaticInlineOnly`**
```c
void f1(void) // Multi-line (not static inline)
{
}
int f2(int a, int b) // Multi-line (not static inline)
{
return a + b;
}
static void f3(void) // Multi-line (not static inline)
{
}
static int f4(int a, int b) // Multi-line (not static inline)
{
return a + b;
}
static inline void f5(void) {} // Single-line allowed
static inline int f6(int a, int b) { return a + b; } // Single-line allowed 
(if fits)
inline void f7(void) // Multi-line (not static inline)
{
}
```

*   **With `ShortFunctionStyle: StaticInline`** (Implies Empty)
```c
void f1(void) {} // Single-line allowed (empty)
int f2(int a, int b) // Multi-line (non-empty, not static inline)
{
return a + b;
}
static void f3(void) {} // Single-line allowed (empty)
static int f4(int a, int b) // Multi-line (non-empty, not static inline)
{
return a + b;
}
static inline void f5(void) {} // Single-line allowed (static inline and 
empty)
static inline int f6(int a, int b) { return a + b; } // Single-line allowed 
(static inline, if fits)
inline void f7(void) {} // Single-line allowed (empty)
```
---
 clang/docs/ClangFormatStyleOptions.rst  | 17 +
 clang/include/clang/Format/Format.h | 13 
 clang/lib/Format/Format.cpp |  2 +
 clang/lib/Format/TokenAnnotator.cpp |  6 +-
 clang/lib/Format/UnwrappedLineFormatter.cpp | 31 +++-
 clang/unittests/Format/ConfigParseTest.cpp  |  6 ++
 clang/unittests/Format/FormatTest.cpp   | 79 +
 7 files changed, 150 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 9ecac68ae72bf..e5641fa5037ae 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -1926,6 +1926,15 @@ the configuration (without a prefix: ``Auto``).
   void f() {
   }
 
+  * ``SFS_StaticInlineOnly`` (in configuration: ``StaticInlineOnly``)
+Only merge functions defined as static inline.
+
+.. code-block:: c++
+
+  void f5(void) 

[clang] [alpha.webkit.RawPtrRefMemberChecker] The checker doesn't warn Objective-C types in ivars. (PR #132833)

2025-03-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-static-analyzer-1

Author: Ryosuke Niwa (rniwa)


Changes

This PR fixes the bug that we weren't generating warnings when a raw poiner is 
used to point to a NS type in Objective-C ivars. Also fix the bug that we 
weren't suppressing this warning in system headers.

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


3 Files Affected:

- (modified) 
clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp (+10) 
- (modified) clang/test/Analysis/Checkers/WebKit/mock-system-header.h (+11) 
- (modified) clang/test/Analysis/Checkers/WebKit/unretained-members.mm (+11-1) 


``diff
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp
index dc4e2c7d168fb..6d20869043358 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp
@@ -111,6 +111,8 @@ class RawPtrRefMemberChecker
   }
 
   void visitObjCDecl(const ObjCContainerDecl *CD) const {
+if (BR->getSourceManager().isInSystemHeader(CD->getLocation()))
+  return;
 if (auto *ID = dyn_cast(CD)) {
   for (auto *Ivar : ID->ivars())
 visitIvarDecl(CD, Ivar);
@@ -133,6 +135,14 @@ class RawPtrRefMemberChecker
   std::optional IsCompatible = isPtrCompatible(QT, IvarCXXRD);
   if (IsCompatible && *IsCompatible)
 reportBug(Ivar, IvarType, IvarCXXRD, CD);
+} else {
+  std::optional IsCompatible = isPtrCompatible(QT, nullptr);
+  auto *PointeeType = IvarType->getPointeeType().getTypePtrOrNull();
+  if (IsCompatible && *IsCompatible) {
+auto *Desugared = PointeeType->getUnqualifiedDesugaredType();
+if (auto *ObjCType = dyn_cast_or_null(Desugared))
+  reportBug(Ivar, IvarType, ObjCType->getDecl(), CD);
+  }
 }
   }
 
diff --git a/clang/test/Analysis/Checkers/WebKit/mock-system-header.h 
b/clang/test/Analysis/Checkers/WebKit/mock-system-header.h
index e993fd697ffab..b377f5098c002 100644
--- a/clang/test/Analysis/Checkers/WebKit/mock-system-header.h
+++ b/clang/test/Analysis/Checkers/WebKit/mock-system-header.h
@@ -29,3 +29,14 @@ enum os_log_type_t : uint8_t {
 typedef struct os_log_s *os_log_t;
 os_log_t os_log_create(const char *subsystem, const char *category);
 void os_log_msg(os_log_t oslog, os_log_type_t type, const char *msg, ...);
+
+typedef const struct __attribute__((objc_bridge(NSString))) __CFString * 
CFStringRef;
+
+#ifdef __OBJC__
+@class NSString;
+@interface SystemObject : NSObject {
+  NSString *ns_string;
+  CFStringRef cf_string;
+}
+@end
+#endif
diff --git a/clang/test/Analysis/Checkers/WebKit/unretained-members.mm 
b/clang/test/Analysis/Checkers/WebKit/unretained-members.mm
index e068a583c18c5..79f7a05caa1be 100644
--- a/clang/test/Analysis/Checkers/WebKit/unretained-members.mm
+++ b/clang/test/Analysis/Checkers/WebKit/unretained-members.mm
@@ -1,7 +1,8 @@
 // RUN: %clang_analyze_cc1 
-analyzer-checker=alpha.webkit.NoUnretainedMemberChecker -verify %s
 
 #include "objc-mock-types.h"
-
+#include "mock-system-header.h"
+#if 0
 namespace members {
 
   struct Foo {
@@ -58,3 +59,12 @@ void forceTmplToInstantiate(FooTmpl) {}
 
   void forceTmplToInstantiate(RefPtr) {}
 }
+#endif
+
+@interface AnotherObject : NSObject {
+  NSString *ns_string;
+  // expected-warning@-1{{Instance variable 'ns_string' in 'AnotherObject' is 
a raw pointer to retainable type 'NSString'; member variables must be a 
RetainPtr}}
+  CFStringRef cf_string;
+  // expected-warning@-1{{Instance variable 'cf_string' in 'AnotherObject' is 
a retainable type 'CFStringRef'; member variables must be a RetainPtr}}
+}
+@end

``




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


[clang] [clang] implement common-sugar for adjusted member-pointers (PR #133613)

2025-03-29 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`clang-aarch64-sve-vls-2stage` running on `linaro-g3-02` while building `clang` 
at step 12 "ninja check 2".

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


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

```
Step 12 (ninja check 2) failure: stage 2 checked (failure)
...
PASS: Flang :: Driver/misc-flags.f90 (25170 of 97483)
PASS: Flang :: Driver/predefined-macros-x86.f90 (25171 of 97483)
PASS: Flang :: Driver/mabi-riscv.f90 (25172 of 97483)
PASS: Flang :: Driver/print-resource-dir.F90 (25173 of 97483)
PASS: DataFlowSanitizer-aarch64 :: origin_ldst.c (25174 of 97483)
PASS: DataFlowSanitizer-aarch64 :: pair.cpp (25175 of 97483)
PASS: Flang :: Driver/input-output-file.f90 (25176 of 97483)
PASS: Flang :: Driver/implicit-none.f90 (25177 of 97483)
PASS: Flang :: Driver/parse-fir-error.ll (25178 of 97483)
UNRESOLVED: Flang :: Driver/slp-vectorize.ll (25179 of 97483)
 TEST 'Flang :: Driver/slp-vectorize.ll' FAILED 

Test has no 'RUN:' line

PASS: Flang :: Driver/override-triple.ll (25180 of 97483)
PASS: Flang :: Driver/parse-ir-error.f95 (25181 of 97483)
PASS: Flang :: Driver/predefined-macros-compiler-version.F90 (25182 of 97483)
PASS: Flang :: Driver/mlir-pass-pipeline.f90 (25183 of 97483)
PASS: Clangd Unit Tests :: ./ClangdTests/70/81 (25184 of 97483)
PASS: Flang :: Driver/macro-def-undef.F90 (25185 of 97483)
PASS: Flang :: Driver/lto-bc.f90 (25186 of 97483)
PASS: Flang :: Driver/phases.f90 (25187 of 97483)
PASS: Flang :: Driver/print-pipeline-passes.f90 (25188 of 97483)
PASS: Flang :: Driver/print-target-triple.f90 (25189 of 97483)
PASS: Flang :: Driver/mlink-builtin-bc.f90 (25190 of 97483)
PASS: Flang :: Driver/scanning-error.f95 (25191 of 97483)
PASS: Flang :: Driver/std2018-wrong.f90 (25192 of 97483)
PASS: Flang :: Driver/include-header.f90 (25193 of 97483)
PASS: Flang :: Driver/mllvm.f90 (25194 of 97483)
PASS: Flang :: Driver/supported-suffices/f03-suffix.f03 (25195 of 97483)
PASS: Flang :: Driver/pthread.f90 (25196 of 97483)
PASS: Flang :: Driver/supported-suffices/f08-suffix.f08 (25197 of 97483)
PASS: Clangd Unit Tests :: ./ClangdTests/80/81 (25198 of 97483)
PASS: Flang :: Driver/tco-code-gen-llvm.fir (25199 of 97483)
PASS: Flang :: Driver/parse-error.ll (25200 of 97483)
PASS: Flang :: Driver/q-unused-arguments.f90 (25201 of 97483)
PASS: Flang :: Driver/target.f90 (25202 of 97483)
PASS: Flang :: Driver/pass-plugin-not-found.f90 (25203 of 97483)
PASS: Flang :: Driver/pp-fixed-form.f90 (25204 of 97483)
PASS: Flang :: Driver/target-gpu-features.f90 (25205 of 97483)
PASS: Flang :: Driver/missing-arg.f90 (25206 of 97483)
PASS: Flang :: Driver/bbc-openmp-version-macro.f90 (25207 of 97483)
PASS: Flang :: Driver/no-duplicate-main.f90 (25208 of 97483)
PASS: Flang :: Driver/linker-flags.f90 (25209 of 97483)
PASS: Flang :: Driver/unsupported-vscale-max-min.f90 (25210 of 97483)
PASS: Flang :: Driver/optimization-remark-invalid.f90 (25211 of 97483)
PASS: Flang :: Driver/unparse-with-modules.f90 (25212 of 97483)
PASS: Flang :: Driver/multiple-input-files.f90 (25213 of 97483)
PASS: Flang :: Driver/optimization-remark-backend.f90 (25214 of 97483)
PASS: Flang :: Driver/save-temps.f90 (25215 of 97483)

```



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


[clang] [RFC] Initial implementation of P2719 (PR #113510)

2025-03-29 Thread Oliver Hunt via cfe-commits


@@ -9784,10 +9850,16 @@ bool Sema::ShouldDeleteSpecialMember(CXXMethodDecl *MD,
   //results in an ambiguity or in a function that is deleted or 
inaccessible
   if (CSM == CXXSpecialMemberKind::Destructor && MD->isVirtual()) {
 FunctionDecl *OperatorDelete = nullptr;
+QualType DeallocType = Context.getRecordType(RD);
 DeclarationName Name =
   Context.DeclarationNames.getCXXOperatorName(OO_Delete);
+ImplicitDeallocationParameters IDP = {
+DeallocType,
+typeAwareAllocationModeFromBool(getLangOpts().TypeAwareAllocators),
+AlignedAllocationMode::No, SizedDeallocationMode::No};
 if (FindDeallocationFunction(MD->getLocation(), MD->getParent(), Name,
- OperatorDelete, /*Diagnose*/false)) {
+ OperatorDelete, IDP,
+ /*Diagnose*/ false)) {

ojhunt wrote:

done

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


[clang] [RFC] Initial implementation of P2719 (PR #113510)

2025-03-29 Thread Oliver Hunt via cfe-commits


@@ -16147,6 +16169,108 @@ bool Sema::CompleteConstructorCall(CXXConstructorDecl 
*Constructor,
   return Invalid;
 }
 
+bool Sema::isTypeAwareOperatorNewOrDelete(const NamedDecl *ND) const {
+  const FunctionDecl *FnDecl = nullptr;
+  if (auto *FTD = dyn_cast(ND))
+FnDecl = FTD->getTemplatedDecl();
+  else if (auto *FD = dyn_cast(ND))
+FnDecl = FD;
+
+  return FnDecl->isTypeAwareOperatorNewOrDelete();
+}
+
+FunctionDecl *
+Sema::instantiateTypeAwareUsualDelete(FunctionTemplateDecl *FnTemplateDecl,
+  QualType DeallocType) {
+  if (!getLangOpts().TypeAwareAllocators)
+return nullptr;
+
+  TemplateParameterList *TemplateParameters =
+  FnTemplateDecl->getTemplateParameters();
+  if (TemplateParameters->hasParameterPack())
+return nullptr;
+
+  FunctionDecl *FnDecl = FnTemplateDecl->getTemplatedDecl();
+  if (!FnDecl->isTypeAwareOperatorNewOrDelete())
+return nullptr;
+
+  if (FnDecl->isVariadic())
+return nullptr;
+
+  unsigned NumParams = FnDecl->getNumParams();
+  if (NumParams < 2)
+return nullptr;
+
+  for (size_t Idx = 1; Idx < NumParams; ++Idx) {
+// A type aware allocation is only usual if the only dependent parameter is
+// the first parameter.
+const ParmVarDecl *ParamDecl = FnDecl->getParamDecl(Idx);
+if (ParamDecl->getType()->isDependentType())
+  return nullptr;
+  }

ojhunt wrote:

Done :D

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


[clang] [RFC] Initial implementation of P2719 (PR #113510)

2025-03-29 Thread Oliver Hunt via cfe-commits


@@ -1110,9 +1138,10 @@ static bool findDeleteForPromise(Sema &S, SourceLocation 
Loc, QualType PromiseTy
   // The deallocation function's name is looked up by searching for it in the
   // scope of the promise type. If nothing is found, a search is performed in
   // the global scope.
+  ImplicitDeallocationParameters IDP = {
+  alignedAllocationModeFromBool(Overaligned), SizedDeallocationMode::Yes};
   if (S.FindDeallocationFunction(Loc, PointeeRD, DeleteName, OperatorDelete,
- /*Diagnose*/ true, /*WantSize*/ true,
- /*WantAligned*/ Overaligned))
+ PromiseType, IDP, /*Diagnose*/ true))

ojhunt wrote:

searched the entire current diff and updated the style

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


[clang] [RFC] Initial implementation of P2719 (PR #113510)

2025-03-29 Thread Oliver Hunt via cfe-commits


@@ -307,6 +307,10 @@ EXTENSION(datasizeof, LangOpts.CPlusPlus)
 
 FEATURE(cxx_abi_relative_vtable, LangOpts.CPlusPlus && 
LangOpts.RelativeCXXABIVTables)
 
+// Type aware allocators
+FEATURE(cxx_type_aware_allocators, LangOpts.TypeAwareAllocators)

ojhunt wrote:

Removed the feature test

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


[clang] [RFC] Initial implementation of P2719 (PR #113510)

2025-03-29 Thread Oliver Hunt via cfe-commits


@@ -477,6 +477,44 @@ class DeclarationName {
 return OO_None;
   }
 
+  bool isOperatorNew() const {
+if (getNameKind() != DeclarationName::CXXOperatorName)
+  return false;
+switch (getCXXOverloadedOperator()) {
+case OO_New:
+case OO_Array_New:
+  return true;
+default:
+  return false;
+}
+  }
+
+  bool isOperatorDelete() const {
+if (getNameKind() != DeclarationName::CXXOperatorName)
+  return false;
+switch (getCXXOverloadedOperator()) {
+case OO_Delete:
+case OO_Array_Delete:
+  return true;
+default:
+  return false;
+}
+  }
+
+  bool isOperatorNewOrDelete() const {
+if (getNameKind() != DeclarationName::CXXOperatorName)
+  return false;
+switch (getCXXOverloadedOperator()) {
+case OO_New:
+case OO_Array_New:
+case OO_Delete:
+case OO_Array_Delete:
+  return true;
+default:
+  return false;
+}

ojhunt wrote:

done

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


[clang] [RFC] Initial implementation of P2719 (PR #113510)

2025-03-29 Thread Oliver Hunt via cfe-commits


@@ -3128,6 +3128,26 @@ bool Type::isStdByteType() const {
   return false;
 }
 
+static const TemplateDecl *getSpecializedTemplateType(const Type *T) {
+  const Type *DesugaredType = T->getUnqualifiedDesugaredType();
+  if (const auto *Specialization =
+  DesugaredType->getAs())
+return Specialization->getTemplateName().getAsTemplateDecl();
+  if (const auto *Record = DesugaredType->getAsCXXRecordDecl()) {
+if (const auto *CTS = dyn_cast(Record))
+  return CTS->getSpecializedTemplate();
+  }
+  return nullptr;
+}
+

ojhunt wrote:

As we've removed this logic entirely now I've reverted the addition of the 
method

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


[clang] [RFC] Initial implementation of P2719 (PR #113510)

2025-03-29 Thread Oliver Hunt via cfe-commits


@@ -0,0 +1,145 @@
+// RUN: %clang_cc1 -triple arm64-apple-macosx -fsyntax-only -verify %s 
-std=c++26 -fcoroutines -fexceptions -Wall -Wpedantic
+
+
+#include "Inputs/std-coroutine.h"
+
+namespace std {
+   template  struct type_identity {
+   typedef T type;
+   };
+   typedef __SIZE_TYPE__ size_t;
+   enum class align_val_t : size_t {};
+}
+
+struct Allocator {};
+
+struct resumable {
+  struct promise_type {
+void *operator new(std::type_identity, std::size_t sz, 
std::align_val_t, int); // #resumable_tan1
+void *operator new(std::type_identity, std::size_t sz, 
std::align_val_t, float); // #resumable_tan2
+void operator delete(std::type_identity, void *, std::size_t 
sz, std::align_val_t); // #resumable_tad1
+template  void operator delete(std::type_identity, void *, 
std::size_t sz, std::align_val_t) = delete; // #resumable_tad2
+
+resumable get_return_object() { return {}; }
+auto initial_suspend() { return std::suspend_always(); }
+auto final_suspend() noexcept { return std::suspend_always(); }
+void unhandled_exception() {}
+void return_void(){};
+std::suspend_always yield_value(int i);
+  };
+};
+
+struct resumable2 {
+  struct promise_type {
+template  void *operator 
new(std::type_identity, std::size_t sz, std::align_val_t, 
Args...); // #resumable2_tan1
+void operator delete(std::type_identity, void *, std::size_t 
sz, std::align_val_t); // #resumable2_tad2
+
+resumable2 get_return_object() { return {}; }
+auto initial_suspend() { return std::suspend_always(); }
+auto final_suspend() noexcept { return std::suspend_always(); }
+void unhandled_exception() {}
+void return_void(){};
+std::suspend_always yield_value(int i);
+  };
+};
+
+
+struct resumable3 {
+  struct promise_type {
+  // expected-error@-1 {{declaration of type aware 'operator new' in 
'resumable3::promise_type' must have matching type aware 'operator delete'}}
+  // expected-note@#resumable3_tan {{unmatched type aware 'operator new' 
declared here}}
+void *operator new(std::size_t sz, float);
+void *operator new(std::type_identity, std::size_t sz, 
std::align_val_t, float); // #resumable3_tan
+void operator delete(void *);
+
+resumable3 get_return_object() { return {}; }
+auto initial_suspend() { return std::suspend_always(); }
+auto final_suspend() noexcept { return std::suspend_always(); }
+void unhandled_exception() {}
+void return_void(){};
+std::suspend_always yield_value(int i);
+  };
+};
+struct resumable4 {
+  struct promise_type {
+// expected-error@-1 {{declaration of type aware 'operator delete' in 
'resumable4::promise_type' must have matching type aware 'operator new'}}
+// expected-note@#resumable4_tad {{unmatched type aware 'operator delete' 
declared here}}
+void *operator new(std::size_t sz, float);
+template  void operator delete(std::type_identity, void *, 
std::size_t, std::align_val_t); // #resumable4_tad
+
+resumable4 get_return_object() { return {}; }
+auto initial_suspend() { return std::suspend_always(); }
+auto final_suspend() noexcept { return std::suspend_always(); }
+void unhandled_exception() {}
+void return_void(){};
+std::suspend_always yield_value(int i);
+  };
+};
+struct resumable5 {
+  struct promise_type {
+// expected-error@-1 {{declaration of type aware 'operator delete' in 
'resumable5::promise_type' must have matching type aware 'operator new'}}
+// expected-note@#resumable5_tad {{unmatched type aware 'operator delete' 
declared here}}
+void *operator new(std::size_t sz, float);
+void operator delete(void *);
+template  void operator delete(std::type_identity, void *, 
std::size_t, std::align_val_t); // #resumable5_tad
+
+resumable5 get_return_object() { return {}; }
+auto initial_suspend() { return std::suspend_always(); }
+auto final_suspend() noexcept { return std::suspend_always(); }
+void unhandled_exception() {}
+void return_void(){};
+std::suspend_always yield_value(int i);
+  };
+};
+
+resumable f1(int) {
+  // expected-error@-1 {{'operator new' provided by 
'std::coroutine_traits::promise_type' (aka 
'resumable::promise_type') is not usable with the function signature of 'f1'}}
+  // expected-note@-2 {{type aware 'operator new' will not be used for 
coroutine allocation}}
+  // expected-note@#resumable_tan1 {{type aware 'operator new' declared here}}
+  // expected-note@#resumable_tan2 {{type aware 'operator new' declared here}}
+  co_return;
+}
+
+resumable f2(float) {
+  // expected-error@-1 {{'operator new' provided by 
'std::coroutine_traits::promise_type' (aka 
'resumable::promise_type') is not usable with the function signature of 'f2'}}
+  // expected-note@-2 {{type aware 'operator new' will not be used for 
coroutine allocation}}
+  // expected-note@#resumable_tan1 {{type aware 'operator new' declared here}}
+  // expected-note@#resumable_tan2 {{type aware 'operator ne

[clang] [clang] Clear `NeedsCleaning` flag after `ExpandBuiltinMacro` (PR #133574)

2025-03-29 Thread via cfe-commits

github-actions[bot] wrote:

⚠️ We detected that you are using a GitHub private e-mail address to contribute 
to the repo. Please turn off [Keep my email addresses 
private](https://github.com/settings/emails) setting in your account. See 
[LLVM 
Discourse](https://discourse.llvm.org/t/hidden-emails-on-github-should-we-do-something-about-it)
 for more information.

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


[clang] [lld] Add the type to target_link_libraries (PR #133596)

2025-03-29 Thread Theo Paris via cfe-commits

https://github.com/theoparis created 
https://github.com/llvm/llvm-project/pull/133596

This fixes building with LLVM_TOOL_LLVM_DRIVER_BUILD and LLVM_LINK_LLVM_DYLIB 
set to true. CMake requires that "all uses of target_link_libraries with a 
target must be either all-keyword or all-plain".


>From 183eac555a5aaf1ec0d2bd208506131351093a81 Mon Sep 17 00:00:00 2001
From: Theo Paris 
Date: Sat, 29 Mar 2025 13:15:58 -0700
Subject: [PATCH] [cmake] Add type to target_link_libraries

This fixes building with LLVM_TOOL_LLVM_DRIVER_BUILD and LLVM_LINK_LLVM_DYLIB 
set to true. Cmake requires that "all uses of target_link_libraries with a 
target must be either all-keyword or all-plain".
---
 clang/cmake/modules/AddClang.cmake | 2 +-
 lld/tools/lld/CMakeLists.txt   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/cmake/modules/AddClang.cmake 
b/clang/cmake/modules/AddClang.cmake
index cdc8bd5cd503b..45dd60206195d 100644
--- a/clang/cmake/modules/AddClang.cmake
+++ b/clang/cmake/modules/AddClang.cmake
@@ -213,7 +213,7 @@ endmacro()
 
 function(clang_target_link_libraries target type)
   if (TARGET obj.${target})
-target_link_libraries(obj.${target} ${ARGN})
+target_link_libraries(obj.${target} ${type} ${ARGN})
   endif()
 
   get_property(LLVM_DRIVER_TOOLS GLOBAL PROPERTY LLVM_DRIVER_TOOLS)
diff --git a/lld/tools/lld/CMakeLists.txt b/lld/tools/lld/CMakeLists.txt
index 8498a91597a93..1d1a7ff448b7c 100644
--- a/lld/tools/lld/CMakeLists.txt
+++ b/lld/tools/lld/CMakeLists.txt
@@ -13,7 +13,7 @@ export_executable_symbols_for_plugins(lld)
 
 function(lld_target_link_libraries target type)
   if (TARGET obj.${target})
-target_link_libraries(obj.${target} ${ARGN})
+target_link_libraries(obj.${target} ${type} ${ARGN})
   endif()
 
   get_property(LLVM_DRIVER_TOOLS GLOBAL PROPERTY LLVM_DRIVER_TOOLS)

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


[clang] [lld] Add the type to target_link_libraries (PR #133596)

2025-03-29 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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

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

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


[clang] [RFC] Initial implementation of P2719 (PR #113510)

2025-03-29 Thread Oliver Hunt via cfe-commits


@@ -16298,6 +16396,70 @@ bool Sema::CompleteConstructorCall(CXXConstructorDecl 
*Constructor,
   return Invalid;
 }
 
+bool Sema::isTypeAwareOperatorNewOrDelete(const NamedDecl *ND) const {
+  const FunctionDecl *FnDecl = nullptr;
+  if (auto *FTD = dyn_cast(ND))
+FnDecl = FTD->getTemplatedDecl();
+  else if (auto *FD = dyn_cast(ND))
+FnDecl = FD;
+

ojhunt wrote:

Now that I know about getAsFunction() I've just removed this helper method :D

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


[clang-tools-extra] [clang-tidy][NFC][doc] improve "options" sections of `bugprone-` and `modernize-` checks (PR #133525)

2025-03-29 Thread Baranov Victor via cfe-commits

https://github.com/vbvictor updated 
https://github.com/llvm/llvm-project/pull/133525

>From 9b88fc69e06d08fd06b60af24b5a9c12749185ef Mon Sep 17 00:00:00 2001
From: Victor Baranov 
Date: Sat, 29 Mar 2025 00:46:22 +0300
Subject: [PATCH 1/2] improve docs options of `bugprone-` and `modernize-`
 checks

---
 .../docs/clang-tidy/checks/bugprone/assert-side-effect.rst  | 1 +
 .../checks/bugprone/capturing-this-in-member-variable.rst   | 3 +++
 .../docs/clang-tidy/checks/bugprone/signed-char-misuse.rst  | 5 -
 .../clang-tidy/checks/bugprone/suspicious-enum-usage.rst| 1 +
 .../checks/bugprone/suspicious-stringview-data-usage.rst| 3 +++
 .../clang-tidy/checks/bugprone/too-small-loop-variable.rst  | 3 +++
 .../checks/bugprone/unhandled-self-assignment.rst   | 3 +++
 .../checks/bugprone/unintended-char-ostream-output.rst  | 3 +++
 .../docs/clang-tidy/checks/modernize/avoid-bind.rst | 3 ++-
 .../docs/clang-tidy/checks/modernize/avoid-c-arrays.rst | 3 +++
 .../docs/clang-tidy/checks/modernize/loop-convert.rst   | 3 +++
 .../docs/clang-tidy/checks/modernize/make-shared.rst| 2 +-
 .../docs/clang-tidy/checks/modernize/make-unique.rst| 2 +-
 .../docs/clang-tidy/checks/modernize/raw-string-literal.rst | 3 +++
 .../docs/clang-tidy/checks/modernize/use-emplace.rst| 6 +-
 15 files changed, 39 insertions(+), 5 deletions(-)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/assert-side-effect.rst 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/assert-side-effect.rst
index 1355afae92e4f..3ca712b958d04 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/assert-side-effect.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/assert-side-effect.rst
@@ -15,6 +15,7 @@ Options
 .. option:: AssertMacros
 
A comma-separated list of the names of assert macros to be checked.
+   Default is `assert,NSAssert,NSCAssert`.
 
 .. option:: CheckFunctionCalls
 
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/capturing-this-in-member-variable.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/capturing-this-in-member-variable.rst
index bb75e9239d9b5..b09d7d5fce959 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/capturing-this-in-member-variable.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/capturing-this-in-member-variable.rst
@@ -32,6 +32,9 @@ Possible fixes:
 object types.
   - passing ``this`` pointer as parameter 
 
+Options
+---
+
 .. option:: FunctionWrapperTypes
 
   A semicolon-separated list of names of types. Used to specify function
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/signed-char-misuse.rst 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/signed-char-misuse.rst
index 72860e8cf2a1d..4edbad5eac81b 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/signed-char-misuse.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/signed-char-misuse.rst
@@ -104,13 +104,16 @@ so both arguments will have the same type.
 return false;
   }
 
+Options
+---
+
 .. option:: CharTypdefsToIgnore
 
   A semicolon-separated list of typedef names. In this list, we can list
   typedefs for ``char`` or ``signed char``, which will be ignored by the
   check. This is useful when a typedef introduces an integer alias like
   ``sal_Int8`` or ``int8_t``. In this case, human misinterpretation is not
-  an issue.
+  an issue. Default is an empty string.
 
 .. option:: DiagnoseSignedUnsignedCharComparisons
 
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-enum-usage.rst 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-enum-usage.rst
index e87172414a23e..94f29ee11ee39 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-enum-usage.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-enum-usage.rst
@@ -71,6 +71,7 @@ Examples:
 
 Options
 ---
+
 .. option:: StrictMode
 
Default value: 0.
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-stringview-data-usage.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-stringview-data-usage.rst
index 9b38d83601810..de10da21e8442 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-stringview-data-usage.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-stringview-data-usage.rst
@@ -43,6 +43,9 @@ lead to a compilation error due to the explicit nature of the 
``std::string``
 constructor. Consequently, developers might opt for ``sv.data()`` to resolve 
the
 compilation error, albeit introducing potential hazards as discussed.
 
+Options
+---
+
 .. option:: StringViewTypes
 
   Option allows users to specify custom string view-like types for analysis. It
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/too-small-loop-variable.rst 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/too-small-loop-variable.rst
index 2c3de

[clang] [clang-format] Add an option for editing enum trailing commas (PR #133576)

2025-03-29 Thread Owen Pan via cfe-commits

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


[clang] Add range metadata for atomic load of boolean type. #131476 (PR #133546)

2025-03-29 Thread Jan Górski via cfe-commits

https://github.com/janagor created 
https://github.com/llvm/llvm-project/pull/133546

Addresses #131476.

For `x86_64` it folds
```
movzbl  t1(%rip), %eax
andb$1, %al
```
into
```
movzbl  t1(%rip), %eax
```
when run: `clang -S atomic-ops-load.c -o atomic-ops-load.s -O1 --target=x86_64`.

But for riscv replaces:
```
lb  a0, %lo(t1)(a0)
andia0, a0, 1
```
with
```
lb  a0, %lo(t1)(a0)
zext.b  a0, a0
``` 
when run: `when run `clang -S atomic-ops-load.c -o atomic-ops-load.s -O1 
--target=riscv64`.

 

From 4581169d6fbe72357bb83b95fe36c8cc606efa1e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20G=C3=B3rski?= 
Date: Fri, 28 Mar 2025 23:36:18 +0100
Subject: [PATCH 1/3] [clang][CodeGen] Added llvm ir pre-commit test.

---
 clang/test/CodeGen/atomic-ops-load.c | 11 +++
 1 file changed, 11 insertions(+)
 create mode 100644 clang/test/CodeGen/atomic-ops-load.c

diff --git a/clang/test/CodeGen/atomic-ops-load.c 
b/clang/test/CodeGen/atomic-ops-load.c
new file mode 100644
index 0..adcaf9a2112fa
--- /dev/null
+++ b/clang/test/CodeGen/atomic-ops-load.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple riscv64 -O1 -emit-llvm %s -o - | FileCheck %s
+#include 
+
+extern bool t1;
+bool test1(void) {
+// CHECK-LABEL: define{{.*}} i1 @test1
+// CHECK: load atomic i8, ptr @t1 monotonic, align 1
+// CHECK-NEXT: trunc i8 %{{.*}} to i1
+// CHECK-NEXT: ret i1 %{{.*}}
+  return __atomic_load_n(&t1, __ATOMIC_RELAXED);
+}

From 852b691fac487b3cef7b0df8875c26573bc58daa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20G=C3=B3rski?= 
Date: Sat, 29 Mar 2025 00:53:23 +0100
Subject: [PATCH 2/3] [clang][CodeGen] Added `!range` metadata to atomic load
 for `bool`.

---
 clang/lib/CodeGen/CGAtomic.cpp   | 23 +++
 clang/test/CodeGen/atomic-ops-load.c |  4 ++--
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CGAtomic.cpp b/clang/lib/CodeGen/CGAtomic.cpp
index 3adb2a7ad207f..70ae7180a9adc 100644
--- a/clang/lib/CodeGen/CGAtomic.cpp
+++ b/clang/lib/CodeGen/CGAtomic.cpp
@@ -590,6 +590,29 @@ static void EmitAtomicOp(CodeGenFunction &CGF, AtomicExpr 
*E, Address Dest,
 llvm::LoadInst *Load = CGF.Builder.CreateLoad(Ptr);
 Load->setAtomic(Order, Scope);
 Load->setVolatile(E->isVolatile());
+
+if (CGF.CGM.getCodeGenOpts().OptimizationLevel == 0) {
+  CGF.Builder.CreateStore(Load, Dest);
+  return;
+}
+
+QualType Ty = E->getValueType();
+if (!Ty->isBooleanType()) {
+  CGF.Builder.CreateStore(Load, Dest);
+  return;
+}
+
+llvm::MDBuilder MDHelper(CGF.getLLVMContext());
+llvm::APInt BooleanMin = llvm::APInt(CGF.getContext().getTypeSize(Ty), 0);
+llvm::APInt BooleanEnd = llvm::APInt(CGF.getContext().getTypeSize(Ty), 2);
+
+if (llvm::MDNode *RangeInfo =
+MDHelper.createRange(BooleanMin, BooleanEnd)) {
+  Load->setMetadata(llvm::LLVMContext::MD_range, RangeInfo);
+  Load->setMetadata(llvm::LLVMContext::MD_noundef,
+  llvm::MDNode::get(CGF.getLLVMContext(), {}));
+}
+
 CGF.Builder.CreateStore(Load, Dest);
 return;
   }
diff --git a/clang/test/CodeGen/atomic-ops-load.c 
b/clang/test/CodeGen/atomic-ops-load.c
index adcaf9a2112fa..778a7ebdc2618 100644
--- a/clang/test/CodeGen/atomic-ops-load.c
+++ b/clang/test/CodeGen/atomic-ops-load.c
@@ -4,8 +4,8 @@
 extern bool t1;
 bool test1(void) {
 // CHECK-LABEL: define{{.*}} i1 @test1
-// CHECK: load atomic i8, ptr @t1 monotonic, align 1
-// CHECK-NEXT: trunc i8 %{{.*}} to i1
+// CHECK: load atomic i8, ptr @t1 monotonic, align 1, !range 
![[$WS_RANGE:[0-9]*]], !noundef !{{[0-9]+}}
+// CHECK-NEXT: trunc nuw i8 %{{.*}} to i1
 // CHECK-NEXT: ret i1 %{{.*}}
   return __atomic_load_n(&t1, __ATOMIC_RELAXED);
 }

From e42772bbc0851696d73ded4abc3edf651f4e8b41 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20G=C3=B3rski?= 
Date: Sat, 29 Mar 2025 01:12:18 +0100
Subject: [PATCH 3/3] Updated codestyle.

---
 clang/lib/CodeGen/CGAtomic.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CGAtomic.cpp b/clang/lib/CodeGen/CGAtomic.cpp
index 70ae7180a9adc..2c9613deef744 100644
--- a/clang/lib/CodeGen/CGAtomic.cpp
+++ b/clang/lib/CodeGen/CGAtomic.cpp
@@ -607,10 +607,10 @@ static void EmitAtomicOp(CodeGenFunction &CGF, AtomicExpr 
*E, Address Dest,
 llvm::APInt BooleanEnd = llvm::APInt(CGF.getContext().getTypeSize(Ty), 2);
 
 if (llvm::MDNode *RangeInfo =
-MDHelper.createRange(BooleanMin, BooleanEnd)) {
+MDHelper.createRange(BooleanMin, BooleanEnd)) {
   Load->setMetadata(llvm::LLVMContext::MD_range, RangeInfo);
   Load->setMetadata(llvm::LLVMContext::MD_noundef,
-  llvm::MDNode::get(CGF.getLLVMContext(), {}));
+llvm::MDNode::get(CGF.getLLVMContext(), {}));
 }
 
 CGF.Builder.CreateStore(Load, Dest);

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

[clang] [CIR][Upstream] Local initialization for ArrayType (PR #132974)

2025-03-29 Thread Bruno Cardoso Lopes via cfe-commits

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


[clang] [clang][Modules] Fix the Size of `RecordDecl`'s `BitCodeAbbrevOp` (PR #133500)

2025-03-29 Thread via cfe-commits

https://github.com/higher-performance approved this pull request.

Thank you for spotting & fixing this! Approving, but I'm also quite unfamiliar 
with these so please wait for another approval.

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


[clang] [Clang] Ensure the instantiation of array initializers for decltype/_typeof operator (PR #133575)

2025-03-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Younan Zhang (zyn0217)


Changes

This is a follow-up to a9672515ce, per Richard's suggestion we should ensure 
the instantiation for these unevaluated operators as well.

No release entry because the issue being fixed was already claimed resolved in 
that patch (though not intended).

Fixes https://github.com/llvm/llvm-project/issues/79750

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaType.cpp (+3) 
- (modified) clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp (+12) 


``diff
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 776d6e55acc18..4b1a44d378f38 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -9544,6 +9544,7 @@ QualType Sema::BuildTypeofExprType(Expr *E, TypeOfKind 
Kind) {
 QualType T = E->getType();
 if (const TagType *TT = T->getAs())
   DiagnoseUseOfDecl(TT->getDecl(), E->getExprLoc());
+getCompletedType(E);
   }
   return Context.getTypeOfExprType(E, Kind);
 }
@@ -9589,6 +9590,8 @@ QualType Sema::getDecltypeForExpr(Expr *E) {
   if (E->isTypeDependent())
 return Context.DependentTy;
 
+  getCompletedType(IDExpr);
+
   // C++11 [dcl.type.simple]p4:
   //   The type denoted by decltype(e) is defined as follows:
 
diff --git a/clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp 
b/clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp
index 6fc2032ee7fb4..7fcc688d7fd1b 100644
--- a/clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp
+++ b/clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp
@@ -472,6 +472,18 @@ namespace VexingParse {
 
 namespace GH79750 {
 
+template 
+constexpr unsigned array[]{ values... };
+
+// Test if the unevaluated operators trigger instantiation of the array 
initializer.
+static_assert(__is_same(__typeof(array<1, 2, 3, 4, 5>),  const unsigned[5]), 
"");
+
+static_assert(__is_same(decltype(array<1, 2, 3, 4>),  const unsigned[4]), "");
+
+}
+
+namespace GH79750_2 {
+
 enum class Values { A };
 
 template

``




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


[clang] [clang-format] Add an option for editing enum trailing commas (PR #133576)

2025-03-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)


Changes



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


6 Files Affected:

- (modified) clang/docs/ClangFormatStyleOptions.rst (+34) 
- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/include/clang/Format/Format.h (+28) 
- (modified) clang/lib/Format/Format.cpp (+76) 
- (modified) clang/unittests/Format/ConfigParseTest.cpp (+8) 
- (modified) clang/unittests/Format/FormatTest.cpp (+32) 


``diff
diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 9ecac68ae72bf..211bb3eeeb6e6 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -3976,6 +3976,40 @@ the configuration (without a prefix: ``Auto``).
 
 
 
+.. _EnumTrailingComma:
+
+**EnumTrailingComma** (``EnumTrailingCommaStyle``) :versionbadge:`clang-format 
21` :ref:`¶ `
+  Insert a comma (if missing) or remove the comma at the end of an ``enum``
+  enumerator list.
+
+  Possible values:
+
+  * ``ETC_Leave`` (in configuration: ``Leave``)
+Don't insert or remove trailing commas.
+
+.. code-block:: c++
+
+  enum { a, b, c, };
+  enum Color { red, green, blue };
+
+  * ``ETC_Insert`` (in configuration: ``Insert``)
+Insert trailing commas.
+
+.. code-block:: c++
+
+  enum { a, b, c, };
+  enum Color { red, green, blue, };
+
+  * ``ETC_Remove`` (in configuration: ``Remove``)
+Remove trailing commas.
+
+.. code-block:: c++
+
+  enum { a, b, c };
+  enum Color { red, green, blue };
+
+
+
 .. _ExperimentalAutoDetectBinPacking:
 
 **ExperimentalAutoDetectBinPacking** (``Boolean``) :versionbadge:`clang-format 
3.7` :ref:`¶ `
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 04ec2cfef679c..27f6a93e31643 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -480,6 +480,8 @@ clang-format
 - Allow specifying the language (C, C++, or Objective-C) for a ``.h`` file by
   adding a special comment (e.g. ``// clang-format Language: ObjC``) near the
   top of the file.
+- Add ``EnumTrailingComma`` option for inserting/removing commas at the end of
+  ``enum`` enumerator lists.
 
 libclang
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index fec47a248abb4..c39006c0d6361 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2704,6 +2704,33 @@ struct FormatStyle {
   /// \version 12
   EmptyLineBeforeAccessModifierStyle EmptyLineBeforeAccessModifier;
 
+  /// Styles for ``enum`` trailing commas.
+  enum EnumTrailingCommaStyle : int8_t {
+/// Don't insert or remove trailing commas.
+/// \code
+///   enum { a, b, c, };
+///   enum Color { red, green, blue };
+/// \endcode
+ETC_Leave,
+/// Insert trailing commas.
+/// \code
+///   enum { a, b, c, };
+///   enum Color { red, green, blue, };
+/// \endcode
+ETC_Insert,
+/// Remove trailing commas.
+/// \code
+///   enum { a, b, c };
+///   enum Color { red, green, blue };
+/// \endcode
+ETC_Remove,
+  };
+
+  /// Insert a comma (if missing) or remove the comma at the end of an ``enum``
+  /// enumerator list.
+  /// \version 21
+  EnumTrailingCommaStyle EnumTrailingComma;
+
   /// If ``true``, clang-format detects whether function calls and
   /// definitions are formatted with one parameter per line.
   ///
@@ -5323,6 +5350,7 @@ struct FormatStyle {
DisableFormat == R.DisableFormat &&
EmptyLineAfterAccessModifier == R.EmptyLineAfterAccessModifier &&
EmptyLineBeforeAccessModifier == R.EmptyLineBeforeAccessModifier &&
+   EnumTrailingComma == R.EnumTrailingComma &&
ExperimentalAutoDetectBinPacking ==
R.ExperimentalAutoDetectBinPacking &&
FixNamespaceComments == R.FixNamespaceComments &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 28aea86139e0d..5a875b8693574 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -361,6 +361,15 @@ struct ScalarEnumerationTraits<
   }
 };
 
+template <>
+struct ScalarEnumerationTraits {
+  static void enumeration(IO &IO, FormatStyle::EnumTrailingCommaStyle &Value) {
+IO.enumCase(Value, "Leave", FormatStyle::ETC_Leave);
+IO.enumCase(Value, "Insert", FormatStyle::ETC_Insert);
+IO.enumCase(Value, "Remove", FormatStyle::ETC_Remove);
+  }
+};
+
 template <>
 struct ScalarEnumerationTraits {
   static void enumeration(IO &IO, FormatStyle::IndentExternBlockStyle &Value) {
@@ -1042,6 +1051,7 @@ template <> struct MappingTraits {
Style.EmptyLineAfterAccessModifier);
 IO.mapOptional("EmptyLineBeforeAccessModifier",
Style.EmptyLineBeforeAccessModifier);
+IO.mapOptional("EnumTrailingComma", Style.EnumTrailingComma);
 IO.mapOptional("Exper

[clang] [clang-format] Add an option for editing enum trailing commas (PR #133576)

2025-03-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Owen Pan (owenca)


Changes



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


6 Files Affected:

- (modified) clang/docs/ClangFormatStyleOptions.rst (+34) 
- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/include/clang/Format/Format.h (+28) 
- (modified) clang/lib/Format/Format.cpp (+76) 
- (modified) clang/unittests/Format/ConfigParseTest.cpp (+8) 
- (modified) clang/unittests/Format/FormatTest.cpp (+32) 


``diff
diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 9ecac68ae72bf..211bb3eeeb6e6 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -3976,6 +3976,40 @@ the configuration (without a prefix: ``Auto``).
 
 
 
+.. _EnumTrailingComma:
+
+**EnumTrailingComma** (``EnumTrailingCommaStyle``) :versionbadge:`clang-format 
21` :ref:`¶ `
+  Insert a comma (if missing) or remove the comma at the end of an ``enum``
+  enumerator list.
+
+  Possible values:
+
+  * ``ETC_Leave`` (in configuration: ``Leave``)
+Don't insert or remove trailing commas.
+
+.. code-block:: c++
+
+  enum { a, b, c, };
+  enum Color { red, green, blue };
+
+  * ``ETC_Insert`` (in configuration: ``Insert``)
+Insert trailing commas.
+
+.. code-block:: c++
+
+  enum { a, b, c, };
+  enum Color { red, green, blue, };
+
+  * ``ETC_Remove`` (in configuration: ``Remove``)
+Remove trailing commas.
+
+.. code-block:: c++
+
+  enum { a, b, c };
+  enum Color { red, green, blue };
+
+
+
 .. _ExperimentalAutoDetectBinPacking:
 
 **ExperimentalAutoDetectBinPacking** (``Boolean``) :versionbadge:`clang-format 
3.7` :ref:`¶ `
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 04ec2cfef679c..27f6a93e31643 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -480,6 +480,8 @@ clang-format
 - Allow specifying the language (C, C++, or Objective-C) for a ``.h`` file by
   adding a special comment (e.g. ``// clang-format Language: ObjC``) near the
   top of the file.
+- Add ``EnumTrailingComma`` option for inserting/removing commas at the end of
+  ``enum`` enumerator lists.
 
 libclang
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index fec47a248abb4..c39006c0d6361 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2704,6 +2704,33 @@ struct FormatStyle {
   /// \version 12
   EmptyLineBeforeAccessModifierStyle EmptyLineBeforeAccessModifier;
 
+  /// Styles for ``enum`` trailing commas.
+  enum EnumTrailingCommaStyle : int8_t {
+/// Don't insert or remove trailing commas.
+/// \code
+///   enum { a, b, c, };
+///   enum Color { red, green, blue };
+/// \endcode
+ETC_Leave,
+/// Insert trailing commas.
+/// \code
+///   enum { a, b, c, };
+///   enum Color { red, green, blue, };
+/// \endcode
+ETC_Insert,
+/// Remove trailing commas.
+/// \code
+///   enum { a, b, c };
+///   enum Color { red, green, blue };
+/// \endcode
+ETC_Remove,
+  };
+
+  /// Insert a comma (if missing) or remove the comma at the end of an ``enum``
+  /// enumerator list.
+  /// \version 21
+  EnumTrailingCommaStyle EnumTrailingComma;
+
   /// If ``true``, clang-format detects whether function calls and
   /// definitions are formatted with one parameter per line.
   ///
@@ -5323,6 +5350,7 @@ struct FormatStyle {
DisableFormat == R.DisableFormat &&
EmptyLineAfterAccessModifier == R.EmptyLineAfterAccessModifier &&
EmptyLineBeforeAccessModifier == R.EmptyLineBeforeAccessModifier &&
+   EnumTrailingComma == R.EnumTrailingComma &&
ExperimentalAutoDetectBinPacking ==
R.ExperimentalAutoDetectBinPacking &&
FixNamespaceComments == R.FixNamespaceComments &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 28aea86139e0d..5a875b8693574 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -361,6 +361,15 @@ struct ScalarEnumerationTraits<
   }
 };
 
+template <>
+struct ScalarEnumerationTraits {
+  static void enumeration(IO &IO, FormatStyle::EnumTrailingCommaStyle &Value) {
+IO.enumCase(Value, "Leave", FormatStyle::ETC_Leave);
+IO.enumCase(Value, "Insert", FormatStyle::ETC_Insert);
+IO.enumCase(Value, "Remove", FormatStyle::ETC_Remove);
+  }
+};
+
 template <>
 struct ScalarEnumerationTraits {
   static void enumeration(IO &IO, FormatStyle::IndentExternBlockStyle &Value) {
@@ -1042,6 +1051,7 @@ template <> struct MappingTraits {
Style.EmptyLineAfterAccessModifier);
 IO.mapOptional("EmptyLineBeforeAccessModifier",
Style.EmptyLineBeforeAccessModifier);
+IO.mapOptional("EnumTrailingComma", Style.EnumTrailingComma);
 IO.mapOptional("Experimental

[clang] [clang-format] Add an option for editing enum trailing commas (PR #133576)

2025-03-29 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/133576

None

>From 3b352123c47cb382539fefc1bcd49228c17d994f Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sat, 29 Mar 2025 00:30:49 -0700
Subject: [PATCH] [clang-format] Add an option for editing enum trailing commas

---
 clang/docs/ClangFormatStyleOptions.rst | 34 ++
 clang/docs/ReleaseNotes.rst|  2 +
 clang/include/clang/Format/Format.h| 28 
 clang/lib/Format/Format.cpp| 76 ++
 clang/unittests/Format/ConfigParseTest.cpp |  8 +++
 clang/unittests/Format/FormatTest.cpp  | 32 +
 6 files changed, 180 insertions(+)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 9ecac68ae72bf..211bb3eeeb6e6 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -3976,6 +3976,40 @@ the configuration (without a prefix: ``Auto``).
 
 
 
+.. _EnumTrailingComma:
+
+**EnumTrailingComma** (``EnumTrailingCommaStyle``) :versionbadge:`clang-format 
21` :ref:`¶ `
+  Insert a comma (if missing) or remove the comma at the end of an ``enum``
+  enumerator list.
+
+  Possible values:
+
+  * ``ETC_Leave`` (in configuration: ``Leave``)
+Don't insert or remove trailing commas.
+
+.. code-block:: c++
+
+  enum { a, b, c, };
+  enum Color { red, green, blue };
+
+  * ``ETC_Insert`` (in configuration: ``Insert``)
+Insert trailing commas.
+
+.. code-block:: c++
+
+  enum { a, b, c, };
+  enum Color { red, green, blue, };
+
+  * ``ETC_Remove`` (in configuration: ``Remove``)
+Remove trailing commas.
+
+.. code-block:: c++
+
+  enum { a, b, c };
+  enum Color { red, green, blue };
+
+
+
 .. _ExperimentalAutoDetectBinPacking:
 
 **ExperimentalAutoDetectBinPacking** (``Boolean``) :versionbadge:`clang-format 
3.7` :ref:`¶ `
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 04ec2cfef679c..27f6a93e31643 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -480,6 +480,8 @@ clang-format
 - Allow specifying the language (C, C++, or Objective-C) for a ``.h`` file by
   adding a special comment (e.g. ``// clang-format Language: ObjC``) near the
   top of the file.
+- Add ``EnumTrailingComma`` option for inserting/removing commas at the end of
+  ``enum`` enumerator lists.
 
 libclang
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index fec47a248abb4..c39006c0d6361 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2704,6 +2704,33 @@ struct FormatStyle {
   /// \version 12
   EmptyLineBeforeAccessModifierStyle EmptyLineBeforeAccessModifier;
 
+  /// Styles for ``enum`` trailing commas.
+  enum EnumTrailingCommaStyle : int8_t {
+/// Don't insert or remove trailing commas.
+/// \code
+///   enum { a, b, c, };
+///   enum Color { red, green, blue };
+/// \endcode
+ETC_Leave,
+/// Insert trailing commas.
+/// \code
+///   enum { a, b, c, };
+///   enum Color { red, green, blue, };
+/// \endcode
+ETC_Insert,
+/// Remove trailing commas.
+/// \code
+///   enum { a, b, c };
+///   enum Color { red, green, blue };
+/// \endcode
+ETC_Remove,
+  };
+
+  /// Insert a comma (if missing) or remove the comma at the end of an ``enum``
+  /// enumerator list.
+  /// \version 21
+  EnumTrailingCommaStyle EnumTrailingComma;
+
   /// If ``true``, clang-format detects whether function calls and
   /// definitions are formatted with one parameter per line.
   ///
@@ -5323,6 +5350,7 @@ struct FormatStyle {
DisableFormat == R.DisableFormat &&
EmptyLineAfterAccessModifier == R.EmptyLineAfterAccessModifier &&
EmptyLineBeforeAccessModifier == R.EmptyLineBeforeAccessModifier &&
+   EnumTrailingComma == R.EnumTrailingComma &&
ExperimentalAutoDetectBinPacking ==
R.ExperimentalAutoDetectBinPacking &&
FixNamespaceComments == R.FixNamespaceComments &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 28aea86139e0d..5a875b8693574 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -361,6 +361,15 @@ struct ScalarEnumerationTraits<
   }
 };
 
+template <>
+struct ScalarEnumerationTraits {
+  static void enumeration(IO &IO, FormatStyle::EnumTrailingCommaStyle &Value) {
+IO.enumCase(Value, "Leave", FormatStyle::ETC_Leave);
+IO.enumCase(Value, "Insert", FormatStyle::ETC_Insert);
+IO.enumCase(Value, "Remove", FormatStyle::ETC_Remove);
+  }
+};
+
 template <>
 struct ScalarEnumerationTraits {
   static void enumeration(IO &IO, FormatStyle::IndentExternBlockStyle &Value) {
@@ -1042,6 +1051,7 @@ template <> struct MappingTraits {
Style.EmptyLineAfterAccessModifier);
 IO.mapOptional("EmptyLineBeforeAccessM

[clang] [Clang] Ensure the instantiation of array initializers for decltype/_typeof operator (PR #133575)

2025-03-29 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

> I find myself wanting a `RequireCompleteType` (or just `CompletesType` - 
> maybe with asserts that check that the resulting types is indeed complete) 
> overload that does not take a diagnostic. `getCompletedType` does not make it 
> clear what it does. And comments would help

Humm, I didn't use RequireCompleteType because it is allowed to be incomplete:

https://godbolt.org/z/5s6s7hn7e

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


[clang] [libcxx] [Clang] Add __builtin_common_reference (PR #121199)

2025-03-29 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/121199

>From 3010ba7ab5392394b37261807fc7cf4cbb205e0c Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Fri, 27 Sep 2024 22:11:14 +0200
Subject: [PATCH] [Clang] Add __builtin_common_reference

---
 clang/docs/LanguageExtensions.rst |  17 +
 clang/include/clang/Basic/BuiltinTemplates.td |  30 +-
 clang/include/clang/Sema/Sema.h   |  19 +
 clang/lib/Sema/SemaExprCXX.cpp|  92 +
 clang/lib/Sema/SemaTemplate.cpp   | 355 +-
 clang/lib/Sema/SemaType.cpp   |  75 
 .../SemaCXX/type-trait-common-reference.cpp   | 123 ++
 .../include/__type_traits/common_reference.h  |  36 +-
 8 files changed, 629 insertions(+), 118 deletions(-)
 create mode 100644 clang/test/SemaCXX/type-trait-common-reference.cpp

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 3b8a9cac6587a..6fc86507ca423 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1677,6 +1677,23 @@ Builtin type aliases
 
 Clang provides a few builtin aliases to improve the throughput of certain 
metaprogramming facilities.
 
+__builtin_common_reference
+--
+
+.. code-block:: c++
+
+  template  class, template  
class> class BasicCommonReferenceT,
+template  CommonTypeT,
+template  HasTypeMember,
+class HasNoTypeMember,
+class... Ts>
+  using __builtin_common_reference = ...;
+
+This alias is used for implementing ``std::common_refernce``. If 
``std::common_reference`` should contain a ``type``
+member, it is an alias to ``HasTypeMember``. Otherwse it 
is an alias to ``HasNoTypeMember``. The
+``CommonTypeT`` is usually ``std::common_type_t``. ``BasicCommonReferenceT`` 
is usually an alias template to
+``basic_common_reference::type``.
+
 __builtin_common_type
 -
 
diff --git a/clang/include/clang/Basic/BuiltinTemplates.td 
b/clang/include/clang/Basic/BuiltinTemplates.td
index d46ce063d2f7e..5c79e89800829 100644
--- a/clang/include/clang/Basic/BuiltinTemplates.td
+++ b/clang/include/clang/Basic/BuiltinTemplates.td
@@ -10,11 +10,11 @@ class TemplateArg {
   string Name = name;
 }
 
-class Template args, string name> : TemplateArg {
+class Template args, string name = ""> : TemplateArg {
   list Args = args;
 }
 
-class Class : TemplateArg {
+class Class : TemplateArg {
   bit IsVariadic = is_variadic;
 }
 
@@ -50,3 +50,29 @@ def __builtin_common_type : BuiltinTemplate<
Template<[Class<"TypeMember">], "HasTypeMember">,
Class<"HasNoTypeMember">,
Class<"Ts", /*is_variadic=*/1>]>;
+
+// template  class,"
+// template  class> class BasicCommonReferenceT,"
+//   template  class CommonTypeT,"
+//   template  class HasTypeMember,"
+//   class HasNoTypeMember,"
+//   class... Ts>"
+def __builtin_common_reference : BuiltinTemplate<
+[Template<[Class<>,
+   Class<>,
+   Template<[Class<>]>,
+   Template<[Class<>]>], "BasicCommonReferenceT">,
+ Template<[Class<"Args", /*is_variadic=*/1>], "CommonTypeT">,
+ Template<[Class<>], "HasTypeMember">,
+ Class<"HasNoTypeMember">,
+ Class<"Ts", /*is_variadic=*/1>]>;
+
+foreach Ref = ["", "lvalue", "rvalue"] in {
+  foreach Const = ["", "const"] in {
+foreach Volatile = ["", "volatile"] in {
+  def __clang_internal_xref_#Ref#Const#Volatile : 
BuiltinTemplate<[Class<>]>;
+}
+  }
+}
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 066bce61c74c1..762cb851ee04f 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -15076,15 +15076,34 @@ class Sema final : public SemaBase {
   QualType BuiltinDecay(QualType BaseType, SourceLocation Loc);
   QualType BuiltinAddReference(QualType BaseType, UTTKind UKind,
SourceLocation Loc);
+
+  QualType BuiltinAddRValueReference(QualType BaseType, SourceLocation Loc) {
+return BuiltinAddReference(BaseType, 
UnaryTransformType::AddRvalueReference,
+   Loc);
+  }
+
+  QualType BuiltinAddLValueReference(QualType BaseType, SourceLocation Loc) {
+return BuiltinAddReference(BaseType, 
UnaryTransformType::AddLvalueReference,
+   Loc);
+  }
+
   QualType BuiltinRemoveExtent(QualType BaseType, UTTKind UKind,
SourceLocation Loc);
   QualType BuiltinRemoveReference(QualType BaseType, UTTKind UKind,
   SourceLocation Loc);
+
+  QualType BuiltinRemoveCVRef(QualType BaseType, SourceLocation Loc) {
+return BuiltinRemoveReference(BaseType, UTTKind::RemoveCVRef, Loc);
+  }
+
   QualType BuiltinChangeCVRQualifiers(QualType BaseType, UTTKind UKind,
   

[clang] [Clang] Ensure the instantiation of array initializers for decltype/_typeof operator (PR #133575)

2025-03-29 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/133575

>From 1100d56138a09a850aed4857ee69bffcff10fc6d Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Sat, 29 Mar 2025 16:42:12 +0800
Subject: [PATCH 1/2] [Clang] Ensure the instantiation of array initializers
 for decltype/__typeof operator

This is a follow-up to a9672515ce, per Richard's suggestion we should
ensure the instantiation for these unevaluated operators as well.

No release entry because the issue being fixed was already claimed
resolved in that patch (though not intended).
---
 clang/lib/Sema/SemaType.cpp  |  3 +++
 .../SemaCXX/cxx1y-variable-templates_top_level.cpp   | 12 
 2 files changed, 15 insertions(+)

diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 776d6e55acc18..4b1a44d378f38 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -9544,6 +9544,7 @@ QualType Sema::BuildTypeofExprType(Expr *E, TypeOfKind 
Kind) {
 QualType T = E->getType();
 if (const TagType *TT = T->getAs())
   DiagnoseUseOfDecl(TT->getDecl(), E->getExprLoc());
+getCompletedType(E);
   }
   return Context.getTypeOfExprType(E, Kind);
 }
@@ -9589,6 +9590,8 @@ QualType Sema::getDecltypeForExpr(Expr *E) {
   if (E->isTypeDependent())
 return Context.DependentTy;
 
+  getCompletedType(IDExpr);
+
   // C++11 [dcl.type.simple]p4:
   //   The type denoted by decltype(e) is defined as follows:
 
diff --git a/clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp 
b/clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp
index 6fc2032ee7fb4..7fcc688d7fd1b 100644
--- a/clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp
+++ b/clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp
@@ -472,6 +472,18 @@ namespace VexingParse {
 
 namespace GH79750 {
 
+template 
+constexpr unsigned array[]{ values... };
+
+// Test if the unevaluated operators trigger instantiation of the array 
initializer.
+static_assert(__is_same(__typeof(array<1, 2, 3, 4, 5>),  const unsigned[5]), 
"");
+
+static_assert(__is_same(decltype(array<1, 2, 3, 4>),  const unsigned[4]), "");
+
+}
+
+namespace GH79750_2 {
+
 enum class Values { A };
 
 template

>From b9fa41f87dae66e19c72ff02538abd3308bb3324 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Sat, 29 Mar 2025 17:22:56 +0800
Subject: [PATCH 2/2] Add comments

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

diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 4b1a44d378f38..ee7be5d11f717 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -9544,6 +9544,8 @@ QualType Sema::BuildTypeofExprType(Expr *E, TypeOfKind 
Kind) {
 QualType T = E->getType();
 if (const TagType *TT = T->getAs())
   DiagnoseUseOfDecl(TT->getDecl(), E->getExprLoc());
+// E might refer to an array whose initializer isn't instantiated yet.
+// Complete the type of E if possible.
 getCompletedType(E);
   }
   return Context.getTypeOfExprType(E, Kind);
@@ -9590,6 +9592,8 @@ QualType Sema::getDecltypeForExpr(Expr *E) {
   if (E->isTypeDependent())
 return Context.DependentTy;
 
+  // IDExpr might refer to an array whose initializer isn't instantiated yet.
+  // Complete the type of IDExpr if possible.
   getCompletedType(IDExpr);
 
   // C++11 [dcl.type.simple]p4:

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


[clang] Add range metadata for atomic load of boolean type. #131476 (PR #133546)

2025-03-29 Thread Jan Górski via cfe-commits

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


[clang] [CIR] Upstream SelectOp and ShiftOp (PR #133405)

2025-03-29 Thread Bruno Cardoso Lopes via cfe-commits

https://github.com/bcardosolopes requested changes to this pull request.

Looks reasonable to add vector support later for shifts. Because `SelectOp` is 
independent of `ShiftOp`, one possibility would have been to split it in two 
PRs to land them faster, but wouldn't bother changing for this round.

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


[clang] [flang] [libcxx] [llvm] [llvm-reduce]: print short form, actionable names in the log (PR #132813)

2025-03-29 Thread Matt Arsenault via cfe-commits

arsenm wrote:

Replaced with new PR 

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


[clang] [C23] Implement WG14 N3037 (PR #132939)

2025-03-29 Thread Martin Uecker via cfe-commits

uecker wrote:

> I now see there's two different parts of the problem to worry about:
> 
> First case: A redeclaration in a _different_ scope. This always defines a new 
> distinct type. This was valid before C23, and is still valid regardless of 
> whether the type is compatible. (In contrast with function decls, which must 
> be globally compatible across the entire TU in all scopes). This is the case 
> I was thinking about earlier. This part really feels pretty-much 
> straight-forward.
> 
> E.g. The following example defines two different `struct Foo` types. The 
> second does not inherit any semantics from the former, and the code is valid 
> before and after C23.
> 
> ```
> struct Foo { [[deprecated("hello")]] int x; };
> int test2() {
>   struct Foo { int x; };
>   struct Foo f = {0};
>   return f.x; // no deprecation
> }
> ```
> 
> Newly in C23, the inner `struct Foo` is compatible with the outer `Foo`. As 
> such, you can now implicitly cast between pointers to the two types, use them 
> to read/write the same memory, etc. The expected semantics seems to me to be 
> very clear here: we should determine whether it's a compatible type according 
> to the standard's rules, and we shouldn't inherit any attributes from the 
> other scope.
> 
> For determining compatibility of nonstandard attributes, we can do similarly 
> to how we handle functions: explicitly check a handful of properties, such as 
> calling convention, and assume compatibility if not otherwise specified. For 
> aggregates, we can also validate that the field offsets are the same, which 
> will handle most of the questionable cases.
> 
> But then there's the other case...
> 
> Where you have a redefinition of a struct in the _same scope_. This was 
> formerly invalid, and is now valid only when compatible. In this case, both 
> definitions define "the same type", so it seems reasonable to expect some 
> sort of decl merging semantics. But the standard doesn't appear to say 
> anything at all about what to do.
> 
> However, we do have some prior art -- we're not inventing the whole idea of 
> decl-merging from scratch right now. So maybe we can follow that prior art? 
> For example, top-level attributes on a struct's definition can be inherited 
> from a declaration in the same scope. It seems plausible that the same would 
> be true for redefinition, and then maybe we'd also extend that same 
> declaration-attribute-merging to fields within the struct.
> 
> Except, while investigating, I discovered that the pre-C23 behavior is 
> inconsistent between Clang and GCC, potentially resulting in ABI differences. 
> E.g.
> 
> ```
> struct __attribute__((packed)) Foo;
> struct Foo {
> char a;
> int b;
> };
> 
> _Static_assert(sizeof(struct Foo) == 8); // with GCC, because packed on the 
> decl was ignored
> _Static_assert(sizeof(struct Foo) == 5); // with Clang, because packed on 
> decl was inherited by the definition
> ```
> 
> Both GCC and Clang do inherit deprecation from the decl. E.g.:
> 
> ```
> struct [[deprecated("hello")]] Foo;
> struct Foo* test1; // Both GCC and Clang say: deprecated: hello
> 
> struct Foo { int x; };
> struct Foo* test2; // Both GCC and Clang say: deprecated: hello
> ```
> 
> Given that, I'd definitely expect that under the new C23 semantics, 
> _redefining_ the struct should obviously also preserve the deprecated 
> attribute. Except...apparently it doesn't in GCC's implementation. Gah. 
> Adding on to the previous test,
> 
> ```
> struct Foo { int x; };
> struct Foo* test3; // GCC: no deprecation warning.
> ```
> 
> So...yeah...

I think this is a bug in my implementation for GCC. Here, the wording in the 
standard for the attributes makes this clear that an entity can be redeclared 
with and without the attribute, but it is considered "marked" after the first 
declaration that has it.


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


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

2025-03-29 Thread David Rivera via cfe-commits

RiverDave wrote:

Ping

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


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

2025-03-29 Thread David Rivera via cfe-commits

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

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

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

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

[clang] [clang-format] Handle C++ keywords in other languages better (PR #132941)

2025-03-29 Thread Owen Pan via cfe-commits


@@ -1369,6 +1374,7 @@ TEST_F(FormatTestJS, 
WrapRespectsAutomaticSemicolonInsertion) {
getGoogleJSStyleWithColumns(10));
   verifyFormat("await theReckoning;", getGoogleJSStyleWithColumns(10));
   verifyFormat("some['a']['b']", getGoogleJSStyleWithColumns(10));
+  verifyFormat("union['a']['b']", getGoogleJSStyleWithColumns(10));

owenca wrote:

Ditto.

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


[clang] [clang-format] Handle C++ keywords in other languages better (PR #132941)

2025-03-29 Thread Owen Pan via cfe-commits


@@ -834,6 +834,11 @@ TEST_F(FormatTestJS, AsyncFunctions) {
"}",
"async function hello(myparamnameiswaytoolng) {}",
getGoogleJSStyleWithColumns(10));
+  verifyFormat("async function\n"
+   "union(\n"
+   "myparamnameiswaytoolng) {\n"
+   "}",
+   getGoogleJSStyleWithColumns(10));

owenca wrote:

Can you add something like `const auto Style = 
getGoogleJSStyleWithColumns(10);` and reuse it here and at line 849 below?

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


[clang-tools-extra] [clang-tidy][C++20] Add support for Initialization Forwarding in structs and Nested Objects within modernize-use-emplace (PR #131969)

2025-03-29 Thread David Rivera via cfe-commits

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


[clang] [clang] Clear `NeedsCleaning` flag after `ExpandBuiltinMacro` (PR #133574)

2025-03-29 Thread marius doerner via cfe-commits

https://github.com/mariusdr updated 
https://github.com/llvm/llvm-project/pull/133574

>From dd54aa59eabe9c3b7b110f46d82ff5c4d0b88c57 Mon Sep 17 00:00:00 2001
From: marius doerner 
Date: Sat, 29 Mar 2025 09:21:20 +0100
Subject: [PATCH] [clang] Clear `NeedsCleaning` flag after `ExpandBuiltinMacro`

After builtin macro expansion in `Preprocessor::ExpandBuiltinMacro`
the result token may have the `Token::NeedsCleaning` flag set
which causes an assertion failure later on when the lexer retrives
the spelling of the token in `getSpellingSlow` in Lexer.cpp.
---
 clang/lib/Lex/PPMacroExpansion.cpp  |  2 +-
 clang/test/Preprocessor/embed___has_embed.c | 19 
 clang/test/Preprocessor/has_attribute.c | 20 +
 clang/test/Preprocessor/has_attribute.cpp   | 20 +
 clang/test/Preprocessor/has_c_attribute.c   | 20 +
 clang/test/Preprocessor/has_include.c   | 49 +
 6 files changed, 129 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Lex/PPMacroExpansion.cpp 
b/clang/lib/Lex/PPMacroExpansion.cpp
index 8e35d56d3f1a6..107d5c31e039d 100644
--- a/clang/lib/Lex/PPMacroExpansion.cpp
+++ b/clang/lib/Lex/PPMacroExpansion.cpp
@@ -1646,7 +1646,6 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
 
   // Set up the return result.
   Tok.setIdentifierInfo(nullptr);
-  Tok.clearFlag(Token::NeedsCleaning);
   bool IsAtStartOfLine = Tok.isAtStartOfLine();
   bool HasLeadingSpace = Tok.hasLeadingSpace();
 
@@ -2089,6 +2088,7 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
   CreateString(OS.str(), Tok, Tok.getLocation(), Tok.getLocation());
   Tok.setFlagValue(Token::StartOfLine, IsAtStartOfLine);
   Tok.setFlagValue(Token::LeadingSpace, HasLeadingSpace);
+  Tok.clearFlag(Token::NeedsCleaning);
 }
 
 void Preprocessor::markMacroAsUsed(MacroInfo *MI) {
diff --git a/clang/test/Preprocessor/embed___has_embed.c 
b/clang/test/Preprocessor/embed___has_embed.c
index 43a3068b5f53a..2705b5ef6fd5b 100644
--- a/clang/test/Preprocessor/embed___has_embed.c
+++ b/clang/test/Preprocessor/embed___has_embed.c
@@ -58,3 +58,22 @@ unsigned char buffer[] = {
 #else
 #error 17
 #endif
+
+#if __has_embed(__FILE__\
+)
+#else
+#error 18
+#endif
+
+#define F __FI\
+LE__
+#if __has_embed(F)
+#else
+#error 19
+#endif
+
+#if __has_embed(F\
+)
+#else 
+#error 20
+#endif
diff --git a/clang/test/Preprocessor/has_attribute.c 
b/clang/test/Preprocessor/has_attribute.c
index 0ba664a53e649..6f6f519bd299d 100644
--- a/clang/test/Preprocessor/has_attribute.c
+++ b/clang/test/Preprocessor/has_attribute.c
@@ -68,3 +68,23 @@ int has_no_volatile_attribute();
 int has_fallthrough;
 #endif
 // CHECK: int has_fallthrough;
+
+#if __has_attribute(F\
+)
+int has_fallthrough_2;
+#endif
+// CHECK: int has_fallthrough_2;
+
+#define F_2 fall\
+through
+
+#if __has_attribute(F_2)
+int has_fallthrough_3;
+#endif
+// CHECK: int has_fallthrough_3;
+
+#if __has_attribute(F_2\
+)
+int has_fallthrough_4;
+#endif
+// CHECK: int has_fallthrough_4;
diff --git a/clang/test/Preprocessor/has_attribute.cpp 
b/clang/test/Preprocessor/has_attribute.cpp
index 00ec57615c84b..72af6de27e8bb 100644
--- a/clang/test/Preprocessor/has_attribute.cpp
+++ b/clang/test/Preprocessor/has_attribute.cpp
@@ -116,6 +116,26 @@ int funclike_1;
 int funclike_2;
 #endif
 // CHECK: int funclike_2;
+
+#if __has_cpp_attribute(CF\
+)
+int has_clang_falthrough_5;
+#endif
+// CHECK: int has_clang_falthrough_5;
+
+#define CF_2 clang::\
+fallthrough
+
+#if __has_cpp_attribute(CF_2)
+int has_clang_falthrough_6;
+#endif
+// CHECK: int has_clang_falthrough_6;
+
+#if __has_cpp_attribute(CF_2\
+)
+int has_clang_falthrough_7;
+#endif
+// CHECK: int has_clang_falthrough_7;
 }
 
 // Test for Microsoft __declspec attributes
diff --git a/clang/test/Preprocessor/has_c_attribute.c 
b/clang/test/Preprocessor/has_c_attribute.c
index 3332571d758c8..d8be13f5898a9 100644
--- a/clang/test/Preprocessor/has_c_attribute.c
+++ b/clang/test/Preprocessor/has_c_attribute.c
@@ -84,3 +84,23 @@ int funclike_1;
 int funclike_2;
 #endif
 // CHECK: int funclike_2;
+
+#if __has_c_attribute(CL\
+)
+int has_clang_likely_5;
+#endif
+// CHECK: int has_clang_likely_5;
+
+#define CL_2 clang::\
+likely
+
+#if __has_c_attribute(CL_2)
+int has_clang_likely_6;
+#endif
+// CHECK: int has_clang_likely_6;
+
+#if __has_c_attribute(CL_2\
+)
+int has_clang_likely_7;
+#endif
+// CHECK: int has_clang_likely_7;
diff --git a/clang/test/Preprocessor/has_include.c 
b/clang/test/Preprocessor/has_include.c
index c95025d83860a..ff199bf23063f 100644
--- a/clang/test/Preprocessor/has_include.c
+++ b/clang/test/Preprocessor/has_include.c
@@ -197,3 +197,52 @@ __has_include
 #ifdef FOO
 #elif __has_include()
 #endif
+
+#if __has_include(\
+)
+#else
+  #error "__has_include failed (10)."
+#endif
+
+#define MACRO6 
+#if __has_include(MACRO6\
+)
+#else
+  #error "__has_include failed (11)."
+#endif
+
+#if __has_include_next(/*expected-warning {{#include_next in primary 
source file}}*/\
+)
+#else
+  #error "__has_inclu

[clang] [OpenMP 6.0] Parse/Sema support for reduction over private variable with reduction clause. (PR #129938)

2025-03-29 Thread Alexey Bataev via cfe-commits

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


[clang] Fix some typos under clang (NFC) (PR #133558)

2025-03-29 Thread via cfe-commits


@@ -61,7 +61,7 @@ void addCXXDeallocatorChecker(AnalysisASTConsumer 
&AnalysisConsumer,
 }
 
 // TODO: What we should really be testing here is all the different varieties
-// of delete operators, and wether the retrieval of their arguments works as
+// of delete operators, and weather the retrieval of their arguments works as

cor3ntin wrote:

whether

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


[clang] [clang] Clear `NeedsCleaning` flag after `ExpandBuiltinMacro` (PR #133574)

2025-03-29 Thread marius doerner via cfe-commits

https://github.com/mariusdr created 
https://github.com/llvm/llvm-project/pull/133574

After builtin macro expansion in `Preprocessor::ExpandBuiltinMacro` the result 
token may have the `Token::NeedsCleaning` flag set which causes an assertion 
failure later on when the lexer retrieves the spelling of the token in 
`getSpellingSlow`.

This commit moves the `Tok.clearFlag(Token::NeedsCleaning)` call to the end of 
`ExpandBuiltinMacro`.

Closes #128384 

>From ae2279bb0fa44ff290a3305b90598caf60284066 Mon Sep 17 00:00:00 2001
From: marius doerner 
Date: Sat, 29 Mar 2025 09:21:20 +0100
Subject: [PATCH] [clang] Clear `NeedsCleaning` flag after `ExpandBuiltinMacro`

After builtin macro expansion in `Preprocessor::ExpandBuiltinMacro`
the result token may have the `Token::NeedsCleaning` flag set
which causes an assertion failure later on when the lexer retrives
the spelling of the token in `getSpellingSlow` in Lexer.cpp.
---
 clang/lib/Lex/PPMacroExpansion.cpp  |  2 +-
 clang/test/Preprocessor/embed___has_embed.c | 19 
 clang/test/Preprocessor/has_attribute.c | 20 +
 clang/test/Preprocessor/has_attribute.cpp   | 20 +
 clang/test/Preprocessor/has_c_attribute.c   | 20 +
 clang/test/Preprocessor/has_include.c   | 49 +
 6 files changed, 129 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Lex/PPMacroExpansion.cpp 
b/clang/lib/Lex/PPMacroExpansion.cpp
index 8e35d56d3f1a6..107d5c31e039d 100644
--- a/clang/lib/Lex/PPMacroExpansion.cpp
+++ b/clang/lib/Lex/PPMacroExpansion.cpp
@@ -1646,7 +1646,6 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
 
   // Set up the return result.
   Tok.setIdentifierInfo(nullptr);
-  Tok.clearFlag(Token::NeedsCleaning);
   bool IsAtStartOfLine = Tok.isAtStartOfLine();
   bool HasLeadingSpace = Tok.hasLeadingSpace();
 
@@ -2089,6 +2088,7 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
   CreateString(OS.str(), Tok, Tok.getLocation(), Tok.getLocation());
   Tok.setFlagValue(Token::StartOfLine, IsAtStartOfLine);
   Tok.setFlagValue(Token::LeadingSpace, HasLeadingSpace);
+  Tok.clearFlag(Token::NeedsCleaning);
 }
 
 void Preprocessor::markMacroAsUsed(MacroInfo *MI) {
diff --git a/clang/test/Preprocessor/embed___has_embed.c 
b/clang/test/Preprocessor/embed___has_embed.c
index 43a3068b5f53a..2705b5ef6fd5b 100644
--- a/clang/test/Preprocessor/embed___has_embed.c
+++ b/clang/test/Preprocessor/embed___has_embed.c
@@ -58,3 +58,22 @@ unsigned char buffer[] = {
 #else
 #error 17
 #endif
+
+#if __has_embed(__FILE__\
+)
+#else
+#error 18
+#endif
+
+#define F __FI\
+LE__
+#if __has_embed(F)
+#else
+#error 19
+#endif
+
+#if __has_embed(F\
+)
+#else 
+#error 20
+#endif
diff --git a/clang/test/Preprocessor/has_attribute.c 
b/clang/test/Preprocessor/has_attribute.c
index 0ba664a53e649..6f6f519bd299d 100644
--- a/clang/test/Preprocessor/has_attribute.c
+++ b/clang/test/Preprocessor/has_attribute.c
@@ -68,3 +68,23 @@ int has_no_volatile_attribute();
 int has_fallthrough;
 #endif
 // CHECK: int has_fallthrough;
+
+#if __has_attribute(F\
+)
+int has_fallthrough_2;
+#endif
+// CHECK: int has_fallthrough_2;
+
+#define F_2 fall\
+through
+
+#if __has_attribute(F_2)
+int has_fallthrough_3;
+#endif
+// CHECK: int has_fallthrough_3;
+
+#if __has_attribute(F_2\
+)
+int has_fallthrough_4;
+#endif
+// CHECK: int has_fallthrough_4;
diff --git a/clang/test/Preprocessor/has_attribute.cpp 
b/clang/test/Preprocessor/has_attribute.cpp
index 00ec57615c84b..72af6de27e8bb 100644
--- a/clang/test/Preprocessor/has_attribute.cpp
+++ b/clang/test/Preprocessor/has_attribute.cpp
@@ -116,6 +116,26 @@ int funclike_1;
 int funclike_2;
 #endif
 // CHECK: int funclike_2;
+
+#if __has_cpp_attribute(CF\
+)
+int has_clang_falthrough_5;
+#endif
+// CHECK: int has_clang_falthrough_5;
+
+#define CF_2 clang::\
+fallthrough
+
+#if __has_cpp_attribute(CF_2)
+int has_clang_falthrough_6;
+#endif
+// CHECK: int has_clang_falthrough_6;
+
+#if __has_cpp_attribute(CF_2\
+)
+int has_clang_falthrough_7;
+#endif
+// CHECK: int has_clang_falthrough_7;
 }
 
 // Test for Microsoft __declspec attributes
diff --git a/clang/test/Preprocessor/has_c_attribute.c 
b/clang/test/Preprocessor/has_c_attribute.c
index 3332571d758c8..d8be13f5898a9 100644
--- a/clang/test/Preprocessor/has_c_attribute.c
+++ b/clang/test/Preprocessor/has_c_attribute.c
@@ -84,3 +84,23 @@ int funclike_1;
 int funclike_2;
 #endif
 // CHECK: int funclike_2;
+
+#if __has_c_attribute(CL\
+)
+int has_clang_likely_5;
+#endif
+// CHECK: int has_clang_likely_5;
+
+#define CL_2 clang::\
+likely
+
+#if __has_c_attribute(CL_2)
+int has_clang_likely_6;
+#endif
+// CHECK: int has_clang_likely_6;
+
+#if __has_c_attribute(CL_2\
+)
+int has_clang_likely_7;
+#endif
+// CHECK: int has_clang_likely_7;
diff --git a/clang/test/Preprocessor/has_include.c 
b/clang/test/Preprocessor/has_include.c
index c95025d83860a..ff199bf23063f 100644
--- a/clang/test/Preprocessor/has_include.c
+++ b/clang/test/Preprocessor/has_include.c
@@ -197,3 +19

[clang] [clang] Clear `NeedsCleaning` flag after `ExpandBuiltinMacro` (PR #133574)

2025-03-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: marius doerner (mariusdr)


Changes

After builtin macro expansion in `Preprocessor::ExpandBuiltinMacro` the result 
token may have the `Token::NeedsCleaning` flag set which causes an assertion 
failure later on when the lexer retrieves the spelling of the token in 
`getSpellingSlow`.

This commit moves the `Tok.clearFlag(Token::NeedsCleaning)` call to the end of 
`ExpandBuiltinMacro`.

Closes #128384 

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


6 Files Affected:

- (modified) clang/lib/Lex/PPMacroExpansion.cpp (+1-1) 
- (modified) clang/test/Preprocessor/embed___has_embed.c (+19) 
- (modified) clang/test/Preprocessor/has_attribute.c (+20) 
- (modified) clang/test/Preprocessor/has_attribute.cpp (+20) 
- (modified) clang/test/Preprocessor/has_c_attribute.c (+20) 
- (modified) clang/test/Preprocessor/has_include.c (+49) 


``diff
diff --git a/clang/lib/Lex/PPMacroExpansion.cpp 
b/clang/lib/Lex/PPMacroExpansion.cpp
index 8e35d56d3f1a6..107d5c31e039d 100644
--- a/clang/lib/Lex/PPMacroExpansion.cpp
+++ b/clang/lib/Lex/PPMacroExpansion.cpp
@@ -1646,7 +1646,6 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
 
   // Set up the return result.
   Tok.setIdentifierInfo(nullptr);
-  Tok.clearFlag(Token::NeedsCleaning);
   bool IsAtStartOfLine = Tok.isAtStartOfLine();
   bool HasLeadingSpace = Tok.hasLeadingSpace();
 
@@ -2089,6 +2088,7 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
   CreateString(OS.str(), Tok, Tok.getLocation(), Tok.getLocation());
   Tok.setFlagValue(Token::StartOfLine, IsAtStartOfLine);
   Tok.setFlagValue(Token::LeadingSpace, HasLeadingSpace);
+  Tok.clearFlag(Token::NeedsCleaning);
 }
 
 void Preprocessor::markMacroAsUsed(MacroInfo *MI) {
diff --git a/clang/test/Preprocessor/embed___has_embed.c 
b/clang/test/Preprocessor/embed___has_embed.c
index 43a3068b5f53a..2705b5ef6fd5b 100644
--- a/clang/test/Preprocessor/embed___has_embed.c
+++ b/clang/test/Preprocessor/embed___has_embed.c
@@ -58,3 +58,22 @@ unsigned char buffer[] = {
 #else
 #error 17
 #endif
+
+#if __has_embed(__FILE__\
+)
+#else
+#error 18
+#endif
+
+#define F __FI\
+LE__
+#if __has_embed(F)
+#else
+#error 19
+#endif
+
+#if __has_embed(F\
+)
+#else 
+#error 20
+#endif
diff --git a/clang/test/Preprocessor/has_attribute.c 
b/clang/test/Preprocessor/has_attribute.c
index 0ba664a53e649..6f6f519bd299d 100644
--- a/clang/test/Preprocessor/has_attribute.c
+++ b/clang/test/Preprocessor/has_attribute.c
@@ -68,3 +68,23 @@ int has_no_volatile_attribute();
 int has_fallthrough;
 #endif
 // CHECK: int has_fallthrough;
+
+#if __has_attribute(F\
+)
+int has_fallthrough_2;
+#endif
+// CHECK: int has_fallthrough_2;
+
+#define F_2 fall\
+through
+
+#if __has_attribute(F_2)
+int has_fallthrough_3;
+#endif
+// CHECK: int has_fallthrough_3;
+
+#if __has_attribute(F_2\
+)
+int has_fallthrough_4;
+#endif
+// CHECK: int has_fallthrough_4;
diff --git a/clang/test/Preprocessor/has_attribute.cpp 
b/clang/test/Preprocessor/has_attribute.cpp
index 00ec57615c84b..72af6de27e8bb 100644
--- a/clang/test/Preprocessor/has_attribute.cpp
+++ b/clang/test/Preprocessor/has_attribute.cpp
@@ -116,6 +116,26 @@ int funclike_1;
 int funclike_2;
 #endif
 // CHECK: int funclike_2;
+
+#if __has_cpp_attribute(CF\
+)
+int has_clang_falthrough_5;
+#endif
+// CHECK: int has_clang_falthrough_5;
+
+#define CF_2 clang::\
+fallthrough
+
+#if __has_cpp_attribute(CF_2)
+int has_clang_falthrough_6;
+#endif
+// CHECK: int has_clang_falthrough_6;
+
+#if __has_cpp_attribute(CF_2\
+)
+int has_clang_falthrough_7;
+#endif
+// CHECK: int has_clang_falthrough_7;
 }
 
 // Test for Microsoft __declspec attributes
diff --git a/clang/test/Preprocessor/has_c_attribute.c 
b/clang/test/Preprocessor/has_c_attribute.c
index 3332571d758c8..d8be13f5898a9 100644
--- a/clang/test/Preprocessor/has_c_attribute.c
+++ b/clang/test/Preprocessor/has_c_attribute.c
@@ -84,3 +84,23 @@ int funclike_1;
 int funclike_2;
 #endif
 // CHECK: int funclike_2;
+
+#if __has_c_attribute(CL\
+)
+int has_clang_likely_5;
+#endif
+// CHECK: int has_clang_likely_5;
+
+#define CL_2 clang::\
+likely
+
+#if __has_c_attribute(CL_2)
+int has_clang_likely_6;
+#endif
+// CHECK: int has_clang_likely_6;
+
+#if __has_c_attribute(CL_2\
+)
+int has_clang_likely_7;
+#endif
+// CHECK: int has_clang_likely_7;
diff --git a/clang/test/Preprocessor/has_include.c 
b/clang/test/Preprocessor/has_include.c
index c95025d83860a..ff199bf23063f 100644
--- a/clang/test/Preprocessor/has_include.c
+++ b/clang/test/Preprocessor/has_include.c
@@ -197,3 +197,52 @@ __has_include
 #ifdef FOO
 #elif __has_include()
 #endif
+
+#if __has_include(\
+)
+#else
+  #error "__has_include failed (10)."
+#endif
+
+#define MACRO6 
+#if __has_include(MACRO6\
+)
+#else
+  #error "__has_include failed (11)."
+#endif
+
+#if __has_include_next(/*expected-warning {{#include_next in primary 
source file}}*/\
+)
+#else
+  #error "__has_include_next failed (9)."
+#endif
+
+#if __has_incl

[clang] [Clang] Ensure the instantiation of array initializers for decltype/_typeof operator (PR #133575)

2025-03-29 Thread via cfe-commits

cor3ntin wrote:

I find myself wanting a `RequireCompleteType` (or just `CompletesType` - maybe 
with asserts that check that the resulting types is indeed complete) overload 
that does not take a diagnostic. `getCompletedType` does not make it clear what 
it does. And comments would help

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


[clang] Fix some typos under clang (NFC) (PR #133558)

2025-03-29 Thread via cfe-commits

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


[clang] [llvm] [SROA] Vector promote some memsets (PR #133301)

2025-03-29 Thread via cfe-commits

https://github.com/macurtis-amd updated 
https://github.com/llvm/llvm-project/pull/133301

>From c0525fd7bd2c740b5b969e8e2913a878792a377c Mon Sep 17 00:00:00 2001
From: Matthew Curtis 
Date: Thu, 27 Mar 2025 14:04:40 -0500
Subject: [PATCH 1/2] [SROA] Vector promote some memsets

---
 clang/test/CodeGenOpenCL/amdgpu-nullptr.cl|  10 +-
 llvm/lib/Transforms/Scalar/SROA.cpp   |  67 +--
 .../assignment-tracking/sroa/user-memcpy.ll   |  12 +-
 llvm/test/DebugInfo/X86/sroasplit-5.ll|   5 +-
 llvm/test/Transforms/SROA/basictest.ll|  40 +++
 llvm/test/Transforms/SROA/slice-width.ll  |   5 +-
 .../SROA/sroa-common-type-fail-promotion.ll   | 104 ++
 7 files changed, 143 insertions(+), 100 deletions(-)

diff --git a/clang/test/CodeGenOpenCL/amdgpu-nullptr.cl 
b/clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
index a0c106bca83c9..927cb3f38fa9c 100644
--- a/clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
+++ b/clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
@@ -503,21 +503,19 @@ void cast_bool_generic(generic char* p) {
 *p = 0;
 }
 
-// Test initialize a struct using memset.
-// For large structures which is mostly zero, clang generats llvm.memset for
-// the zero part and store for non-zero members.
+// Test initialization of a struct with a private member.
 typedef struct {
   long a, b, c, d;
   private char *p;
 } StructTy3;
 
-// CHECK-LABEL: test_memset_private
-// CHECK: call void @llvm.memset.p5.i64(ptr addrspace(5) noundef align 8 
{{.*}}, i8 0, i64 32, i1 false)
+// CHECK-LABEL: test_struct_private_member
+// CHECK:  store <32 x i8> zeroinitializer, ptr addrspace(5) {{.*}}, align 8
 // CHECK: [[GEP:%.*]] = getelementptr inbounds nuw i8, ptr addrspace(5) %ptr, 
i32 32
 // CHECK: store ptr addrspace(5) addrspacecast (ptr null to ptr addrspace(5)), 
ptr addrspace(5) [[GEP]]
 // CHECK: [[GEP1:%.*]] = getelementptr inbounds nuw i8, ptr addrspace(5) 
{{.*}}, i32 36
 // CHECK: store i32 0, ptr addrspace(5) [[GEP1]], align 4
-void test_memset_private(private StructTy3 *ptr) {
+void test_struct_private_member(private StructTy3 *ptr) {
   StructTy3 S3 = {0, 0, 0, 0, 0};
   *ptr = S3;
 }
diff --git a/llvm/lib/Transforms/Scalar/SROA.cpp 
b/llvm/lib/Transforms/Scalar/SROA.cpp
index 86be20c799a68..3ded637a5c63b 100644
--- a/llvm/lib/Transforms/Scalar/SROA.cpp
+++ b/llvm/lib/Transforms/Scalar/SROA.cpp
@@ -1011,6 +1011,26 @@ static Value *foldPHINodeOrSelectInst(Instruction &I) {
   return foldSelectInst(cast(I));
 }
 
+/// Returns a fixed vector type equivalent to the memory set by II or nullptr 
if
+/// unable to do so.
+static FixedVectorType *getVectorTypeFor(const MemSetInst &II,
+ const DataLayout &DL) {
+  const ConstantInt *Length = dyn_cast(II.getLength());
+  if (!Length)
+return nullptr;
+
+  APInt Val = Length->getValue();
+  if (Val.ugt(std::numeric_limits::max()))
+return nullptr;
+
+  auto *VTy =
+  FixedVectorType::get(II.getValue()->getType(), Val.getZExtValue());
+  if (DL.getTypeStoreSizeInBits(VTy) != DL.getTypeAllocSizeInBits(VTy))
+return nullptr;
+
+  return VTy;
+}
+
 /// Builder for the alloca slices.
 ///
 /// This class builds a set of alloca slices by recursively visiting the uses
@@ -1099,15 +1119,16 @@ class AllocaSlices::SliceBuilder : public 
PtrUseVisitor {
 return Base::visitGetElementPtrInst(GEPI);
   }
 
+  bool isSplittableMemOp(Type *Ty, bool IsVolatile) {
+return Ty->isIntegerTy() && !IsVolatile && DL.typeSizeEqualsStoreSize(Ty);
+  }
+
   void handleLoadOrStore(Type *Ty, Instruction &I, const APInt &Offset,
  uint64_t Size, bool IsVolatile) {
 // We allow splitting of non-volatile loads and stores where the type is an
 // integer type. These may be used to implement 'memcpy' or other "transfer
 // of bits" patterns.
-bool IsSplittable =
-Ty->isIntegerTy() && !IsVolatile && DL.typeSizeEqualsStoreSize(Ty);
-
-insertUse(I, Offset, Size, IsSplittable);
+insertUse(I, Offset, Size, isSplittableMemOp(Ty, IsVolatile));
   }
 
   void visitLoadInst(LoadInst &LI) {
@@ -1170,10 +1191,23 @@ class AllocaSlices::SliceBuilder : public 
PtrUseVisitor {
 if (!IsOffsetKnown)
   return PI.setAborted(&II);
 
+auto IsSplittable = [&]() {
+  FixedVectorType *VTy = getVectorTypeFor(II, DL);
+  Type *ATy = AS.AI.getAllocatedType();
+
+  if (!Length)
+return false;
+  if (!VTy)
+return true;
+  if (DL.getTypeAllocSize(VTy) != DL.getTypeAllocSize(ATy))
+return true;
+  return isSplittableMemOp(ATy, II.isVolatile());
+};
+
 insertUse(II, Offset,
   Length ? Length->getLimitedValue()
  : AllocSize - Offset.getLimitedValue(),
-  (bool)Length);
+  IsSplittable());
   }
 
   void visitMemTransferInst(MemTransferInst &II) {
@@ -2072,8 +2106,20 @@ static bool isVectorPromotionViableForSlice(Partition 
&P, const Slice &S,
   if (M

[clang] [CIR] Emit allocas into the proper lexical scope (PR #132468)

2025-03-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Andy Kaylor (andykaylor)


Changes

Alloca operations were being emitted into the entry block of the current
function unconditionally, even if the variable they represented was
declared in a different scope. This change upstreams the code for handling
insertion of the alloca into the proper lexcial scope. It also adds a
CIR-to-CIR transformation to hoist allocas to the function entry block,
which is necessary to produce the expected LLVM IR during lowering.

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


13 Files Affected:

- (modified) clang/include/clang/CIR/Dialect/Passes.h (+1) 
- (modified) clang/include/clang/CIR/Dialect/Passes.td (+10) 
- (modified) clang/include/clang/CIR/MissingFeatures.h (+3) 
- (modified) clang/lib/CIR/CodeGen/CIRGenDecl.cpp (+2-1) 
- (modified) clang/lib/CIR/CodeGen/CIRGenExpr.cpp (+28-9) 
- (modified) clang/lib/CIR/CodeGen/CIRGenFunction.cpp (+4-2) 
- (modified) clang/lib/CIR/CodeGen/CIRGenFunction.h (+8-2) 
- (modified) clang/lib/CIR/Dialect/Transforms/CMakeLists.txt (+1) 
- (added) clang/lib/CIR/Dialect/Transforms/HoistAllocas.cpp (+81) 
- (modified) clang/lib/CIR/Lowering/CIRPasses.cpp (+1) 
- (modified) clang/test/CIR/CodeGen/loop.cpp (+97) 
- (added) clang/test/CIR/Transforms/hoist-allocas.cir (+113) 
- (modified) clang/tools/cir-opt/cir-opt.cpp (+4) 


``diff
diff --git a/clang/include/clang/CIR/Dialect/Passes.h 
b/clang/include/clang/CIR/Dialect/Passes.h
index aa84241bdecf0..133eb462dcf1f 100644
--- a/clang/include/clang/CIR/Dialect/Passes.h
+++ b/clang/include/clang/CIR/Dialect/Passes.h
@@ -22,6 +22,7 @@ namespace mlir {
 
 std::unique_ptr createCIRCanonicalizePass();
 std::unique_ptr createCIRFlattenCFGPass();
+std::unique_ptr createHoistAllocasPass();
 
 void populateCIRPreLoweringPasses(mlir::OpPassManager &pm);
 
diff --git a/clang/include/clang/CIR/Dialect/Passes.td 
b/clang/include/clang/CIR/Dialect/Passes.td
index 16133d020a7c8..74c255861c879 100644
--- a/clang/include/clang/CIR/Dialect/Passes.td
+++ b/clang/include/clang/CIR/Dialect/Passes.td
@@ -29,6 +29,16 @@ def CIRCanonicalize : Pass<"cir-canonicalize"> {
   let dependentDialects = ["cir::CIRDialect"];
 }
 
+def HoistAllocas : Pass<"cir-hoist-allocas"> {
+  let summary = "Hoist allocas to the entry of the function";
+  let description = [{
+This pass hoist all non-dynamic allocas to the entry of the function.
+This is helpful for later code generation.
+  }];
+  let constructor = "mlir::createHoistAllocasPass()";
+  let dependentDialects = ["cir::CIRDialect"];
+}
+
 def CIRFlattenCFG : Pass<"cir-flatten-cfg"> {
   let summary = "Produces flatten CFG";
   let description = [{
diff --git a/clang/include/clang/CIR/MissingFeatures.h 
b/clang/include/clang/CIR/MissingFeatures.h
index 3e33e5dc60194..3f2e56a43fbef 100644
--- a/clang/include/clang/CIR/MissingFeatures.h
+++ b/clang/include/clang/CIR/MissingFeatures.h
@@ -127,6 +127,9 @@ struct MissingFeatures {
   static bool ternaryOp() { return false; }
   static bool tryOp() { return false; }
   static bool zextOp() { return false; }
+
+  // Future CIR attributes
+  static bool optInfoAttr() { return false; }
 };
 
 } // namespace cir
diff --git a/clang/lib/CIR/CodeGen/CIRGenDecl.cpp 
b/clang/lib/CIR/CodeGen/CIRGenDecl.cpp
index a93e8dbcb42de..f2153c23ebb43 100644
--- a/clang/lib/CIR/CodeGen/CIRGenDecl.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenDecl.cpp
@@ -49,7 +49,8 @@ CIRGenFunction::emitAutoVarAlloca(const VarDecl &d) {
   // A normal fixed sized variable becomes an alloca in the entry block,
   mlir::Type allocaTy = convertTypeForMem(ty);
   // Create the temp alloca and declare variable using it.
-  address = createTempAlloca(allocaTy, alignment, loc, d.getName());
+  address = createTempAlloca(allocaTy, alignment, loc, d.getName(),
+ /*insertIntoFnEntryBlock=*/false);
   declare(address.getPointer(), &d, ty, getLoc(d.getSourceRange()), alignment);
 
   emission.Addr = address;
diff --git a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
index 306130b80d457..d16480143c47e 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
@@ -261,10 +261,27 @@ void CIRGenFunction::emitIgnoredExpr(const Expr *e) {
 }
 
 mlir::Value CIRGenFunction::emitAlloca(StringRef name, mlir::Type ty,
-   mlir::Location loc,
-   CharUnits alignment) {
-  mlir::Block *entryBlock = getCurFunctionEntryBlock();
+   mlir::Location loc, CharUnits alignment,
+   bool insertIntoFnEntryBlock,
+   mlir::Value arraySize) {
+  mlir::Block *entryBlock = insertIntoFnEntryBlock
+? getCurFunctionEntryBlock()
+: curLexScope->getEntryBlock();
+
+  // If this is an alloca in the e

[clang] [NFC][analyzer] Fix typo in VirtualCall checker docs (PR #133593)

2025-03-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (Alcaro)


Changes



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


1 Files Affected:

- (modified) clang/docs/analyzer/checkers.rst (+2-2) 


``diff
diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index 482a7ca3340c5..f91b2af1fd105 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -610,7 +610,7 @@ pure virtual – but may be still surprising for the 
programmer.)
void releaseResources() {
  // warn: This can call the pure virtual method A::getKind() when this is
  // called from the destructor.
- callSomeFunction(getKind())
+ callSomeFunction(getKind());
}
  };
 
@@ -936,7 +936,7 @@ checker does not report them**.
void releaseResources() {
  // warn: This can be called within ~A() and calls A::getKind() even if
  // we are destructing a class that is derived from A.
- callSomeFunction(getKind())
+ callSomeFunction(getKind());
}
  };
 

``




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


[clang] [NFC][analyzer] Fix typo in VirtualCall checker docs (PR #133593)

2025-03-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-static-analyzer-1

Author: None (Alcaro)


Changes



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


1 Files Affected:

- (modified) clang/docs/analyzer/checkers.rst (+2-2) 


``diff
diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index 482a7ca3340c5..f91b2af1fd105 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -610,7 +610,7 @@ pure virtual – but may be still surprising for the 
programmer.)
void releaseResources() {
  // warn: This can call the pure virtual method A::getKind() when this is
  // called from the destructor.
- callSomeFunction(getKind())
+ callSomeFunction(getKind());
}
  };
 
@@ -936,7 +936,7 @@ checker does not report them**.
void releaseResources() {
  // warn: This can be called within ~A() and calls A::getKind() even if
  // we are destructing a class that is derived from A.
- callSomeFunction(getKind())
+ callSomeFunction(getKind());
}
  };
 

``




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


  1   2   >