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

2025-04-20 Thread via cfe-commits

https://github.com/Ritanya-B-Bharadwaj edited 
https://github.com/llvm/llvm-project/pull/135807
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-doc][NFC] Remove else after return (PR #136443)

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


@@ -261,7 +261,7 @@ static bool isPublic(const clang::AccessSpecifier AS,
  const clang::Linkage Link) {
   if (AS == clang::AccessSpecifier::AS_private)
 return false;
-  else if ((Link == clang::Linkage::Module) ||
+  if ((Link == clang::Linkage::Module) ||
(Link == clang::Linkage::External))

petrhosek wrote:

```suggestion
  if ((Link == clang::Linkage::Module) ||
  (Link == clang::Linkage::External))
```

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


[clang-tools-extra] [clang-doc][NFC] Remove else after return (PR #136443)

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

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


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


[clang-tools-extra] [clang-doc][NFC] Use isa<> over dyn_cast (PR #136445)

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

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


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


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

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

ojhunt wrote:

Waiting on review for https://github.com/llvm/llvm-project/pull/136515

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


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

2025-04-20 Thread via cfe-commits

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

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

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

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

[clang] [flang] Enable `-m32`, `-maix32` and `-maix64` for Flang on AIX. (PR #136202)

2025-04-20 Thread Daniel Chen via cfe-commits

https://github.com/DanielCChen updated 
https://github.com/llvm/llvm-project/pull/136202

>From ca318afb810504d248c8bedeb13e2f742a446c37 Mon Sep 17 00:00:00 2001
From: Daniel Chen 
Date: Thu, 17 Apr 2025 17:06:27 -0400
Subject: [PATCH 1/5] Enable -m32, -maix32 and -maix64 for Flang on AIX.

---
 clang/include/clang/Driver/Options.td |  8 +---
 clang/lib/Driver/Driver.cpp   | 15 ++-
 flang/test/Driver/m32-option.f90  | 14 ++
 3 files changed, 29 insertions(+), 8 deletions(-)
 create mode 100644 flang/test/Driver/m32-option.f90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index e9acb20348654..84254dfa43249 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4694,15 +4694,17 @@ def EB : Flag<["-"], "EB">, Alias;
 def m16 : Flag<["-"], "m16">, Group, Flags<[NoXarchOption]>,
   Visibility<[ClangOption, CLOption, DXCOption]>;
 def m32 : Flag<["-"], "m32">, Group, Flags<[NoXarchOption]>,
-  Visibility<[ClangOption, CLOption, DXCOption]>;
-def maix32 : Flag<["-"], "maix32">, Group, Flags<[NoXarchOption]>;
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
+def maix32 : Flag<["-"], "maix32">, Group, Flags<[NoXarchOption]>,
+  Visibility<[FlangOption]>;
 def mqdsp6_compat : Flag<["-"], "mqdsp6-compat">, Group,
   Flags<[NoXarchOption]>, Visibility<[ClangOption, CC1Option]>,
   HelpText<"Enable hexagon-qdsp6 backward compatibility">,
   MarshallingInfoFlag>;
 def m64 : Flag<["-"], "m64">, Group, Flags<[NoXarchOption]>,
   Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
-def maix64 : Flag<["-"], "maix64">, Group, Flags<[NoXarchOption]>;
+def maix64 : Flag<["-"], "maix64">, Group, Flags<[NoXarchOption]>,
+  Visibility<[FlangOption]>;
 def mx32 : Flag<["-"], "mx32">, Group, Flags<[NoXarchOption]>,
   Visibility<[ClangOption, CLOption, DXCOption]>;
 def miamcu : Flag<["-"], "miamcu">, Group, Flags<[NoXarchOption]>,
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 90d8e823d1d02..808a18883b079 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -733,11 +733,16 @@ static llvm::Triple computeTargetTriple(const Driver &D,
 Target.setEnvironment(llvm::Triple::GNUX32);
 } else if (A->getOption().matches(options::OPT_m32) ||
A->getOption().matches(options::OPT_maix32)) {
-  AT = Target.get32BitArchVariant().getArch();
-  if (Target.getEnvironment() == llvm::Triple::GNUX32)
-Target.setEnvironment(llvm::Triple::GNU);
-  else if (Target.getEnvironment() == llvm::Triple::MuslX32)
-Target.setEnvironment(llvm::Triple::Musl);
+  if (D.IsFlangMode() && !Target.isOSAIX() )
+D.Diag(diag::err_drv_unsupported_opt_for_target)
+   << A->getAsString(Args) << Target.str();
+  else {
+AT = Target.get32BitArchVariant().getArch();
+if (Target.getEnvironment() == llvm::Triple::GNUX32)
+  Target.setEnvironment(llvm::Triple::GNU);
+else if (Target.getEnvironment() == llvm::Triple::MuslX32)
+  Target.setEnvironment(llvm::Triple::Musl);
+  }
 } else if (A->getOption().matches(options::OPT_m16) &&
Target.get32BitArchVariant().getArch() == llvm::Triple::x86) {
   AT = llvm::Triple::x86;
diff --git a/flang/test/Driver/m32-option.f90 b/flang/test/Driver/m32-option.f90
new file mode 100644
index 0..722bddfa43739
--- /dev/null
+++ b/flang/test/Driver/m32-option.f90
@@ -0,0 +1,14 @@
+! Check support of -m32.
+! RUN: %flang -target powerpc-ibm-aix -m32 -### - %s 2>&1 | FileCheck 
-check-prefix=M32 %s
+! RUN: %flang -target powerpc64-ibm-aix -m32 -### - %s 2>&1 | FileCheck 
-check-prefix=M32 %s
+! RUN: %flang -target powerpc-ibm-aix -maix32 -### - %s 2>&1 | FileCheck 
-check-prefix=M32 %s
+! RUN: %flang -target powerpc64-ibm-aix -maix32 -### - %s 2>&1 | FileCheck 
-check-prefix=M32 %s
+! RUN: %flang -target powerpc-ibm-aix -maix64 -### - %s 2>&1 | FileCheck 
-check-prefix=M64 %s
+! RUN: %flang -target powerpc64-ibm-aix -maix64 -### - %s 2>&1 | FileCheck 
-check-prefix=M64 %s
+! RUN: not %flang -target powerpc64le-unknown-linux-gnu -m32 -### - %s 2>&1 | 
FileCheck -check-prefix=M32-ERROR %s
+! RUN: not %flang -target powerpc64le-unknown-linux-gnu -maix32 -### - %s 2>&1 
| FileCheck -check-prefix=MAIX32-ERROR %s
+
+! M32: "-triple" "powerpc-ibm-aix{{.*}}"
+! M64: "-triple" "powerpc64-ibm-aix{{.*}}"
+! M32-ERROR: error: unsupported option '-m32' for target 
'powerpc64le-unknown-linux-gnu'
+! MAIX32-ERROR: error: unsupported option '-maix32' for target 
'powerpc64le-unknown-linux-gnu'

>From 690158f872cc09024510c4916a31a672498b8c51 Mon Sep 17 00:00:00 2001
From: Daniel Chen 
Date: Thu, 17 Apr 2025 17:13:42 -0400
Subject: [PATCH 2/5] Minor format change.

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

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Dri

[clang] [llvm] Minimal support of floating-point operand bundles (PR #135658)

2025-04-20 Thread Serge Pavlov via cfe-commits

https://github.com/spavloff updated 
https://github.com/llvm/llvm-project/pull/135658

>From 287340535219cd5bc31de3a27cde1b279db0eb09 Mon Sep 17 00:00:00 2001
From: Serge Pavlov 
Date: Mon, 14 Apr 2025 12:51:43 +0700
Subject: [PATCH 1/6] Minimal support of floating-point operand bundles

This is a lite version of https://github.com/llvm/llvm-project/pull/109798,
where code changes are minimized to facilitate discussion about the
implementation. The motivations and ideas behind the new floating-point
operation support are described in that PR and in the discussion
https://discourse.llvm.org/t/rfc-change-of-strict-fp-operation-representation-in-ir/85021.
There are concerns that the proposed changes are too invasive and a new
approach is required to make the transition smoother.

This implementation is essentially a subset of PR109798, where
everything beyond the minimum is removed. It tries to build eventually
the same implementation as that PR but in different steps.

The patch does not attempt to modify the existing implementation based
on the constrained intrinsics. Instead it introduces a new one using
operand bundles. This new implementation initially has very limited
functionality, which latter will be extended and finally can replace the
existing one.

This PR introduces the notion of floating-point operation, this is an
intrinsic, that is listed in the file "FloatingPointOps.def". These have
two additional properties:

1. In the strict environment (a function with strictfp attribute) calls
   to these operations acquire side effect, now it is read/write access
   to inaccessible memory, just as constrained intrinsics do.

2. Calls to these operations may have floating-point operand bundles.
   There are two kinds of such bundles, tagged with "fp.control" and
   "fp.except", which are used to carry additional information about
   control modes and exception handling. Initially the set of control
   modes consists of rounding mode only.

The set of operations enlisted in "FloatingPointOps.def" and in
"ConstrainedOps.def" are completely independent, an intrinsic may be in
one list or in both. The set of floating-point operations is expected to
grow and finally all FP intrinsics will be available in the new
implementation. In this patch set of intrinsics in
"FloatingPointOps.def" is minimum necessary for tests.
---
 llvm/docs/LangRef.rst |  51 -
 llvm/docs/ReleaseNotes.md |   1 +
 llvm/include/llvm/IR/FPEnv.h  |  18 ++
 llvm/include/llvm/IR/FloatingPointOps.def |  24 +++
 llvm/include/llvm/IR/IRBuilder.h  |  45 ++--
 llvm/include/llvm/IR/InstrTypes.h |  16 ++
 llvm/include/llvm/IR/IntrinsicInst.h  |   8 +
 llvm/include/llvm/IR/LLVMContext.h|   2 +
 llvm/include/llvm/Support/ModRef.h|   5 +
 llvm/lib/IR/FPEnv.cpp |  64 ++
 llvm/lib/IR/IRBuilder.cpp |  75 +++
 llvm/lib/IR/Instructions.cpp  |  83 +++-
 llvm/lib/IR/IntrinsicInst.cpp |  10 +
 llvm/lib/IR/LLVMContext.cpp   |  14 ++
 llvm/lib/IR/Verifier.cpp  |  31 ++-
 .../Bitcode/operand-bundles-bc-analyzer.ll|   2 +
 llvm/test/Verifier/fp-intrinsics.ll   |  91 
 llvm/unittests/IR/IRBuilderTest.cpp   | 197 ++
 18 files changed, 716 insertions(+), 21 deletions(-)
 create mode 100644 llvm/include/llvm/IR/FloatingPointOps.def

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 769003a90f959..9145c4c9092f1 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -3071,6 +3071,51 @@ A "convergencectrl" operand bundle is only valid on a 
``convergent`` operation.
 When present, the operand bundle must contain exactly one value of token type.
 See the :doc:`ConvergentOperations` document for details.
 
+.. _ob_fp:
+
+Floating-point Operand Bundles
+^^
+
+These operand bundles are used for calls that involve floating-point
+operations and interact with :ref:`floating-point environment ` or
+depend on floating-point options, such as rounding mode, denormal modes, etc.
+There are two kinds of such operand bundles, which represent the value of
+floating-point control modes and the treatment of status bits respectively.
+
+An operand bundle tagged with "fp.control" contains information about the
+control modes used for the operation execution. Operands specified in this
+bundle represent particular options. Currently, only rounding mode is 
supported.
+It is represented by a metadata string value, which specifies the rounding mode
+to be used for the operation evaluation. Possible values are:
+
+::
+
+"rtz"  - toward zero
+"rte"  - to nearest, ties to even
+"rtp"  - toward positive infinity
+"rtn"  - toward negative infinity
+"rmm"  - to nearest, ties away from zero
+"dyn"  - rounding mode is taken from contro

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

2025-04-20 Thread Carlos Galvez via cfe-commits

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


[clang] [RawPtrRefMemberChecker] Member varible checker should allow T* in smart pointer classes (PR #136503)

2025-04-20 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa created 
https://github.com/llvm/llvm-project/pull/136503

This PR fixes member variable checker to allow the usage of T* in smart pointer 
classes. e.g. alpha.webkit.NoUncheckedPtrMemberChecker should allow T* to 
appear within RefPtr.

>From 441e1d80180549ff17eb74e3749bc6e5663c5c0f Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Sun, 20 Apr 2025 11:58:11 -0700
Subject: [PATCH] [RawPtrRefMemberChecker] Member varible checker should allow
 T* in smart pointer classes

This PR fixes member variable checker to allow the usage of T* in smart pointer 
classes.
e.g. alpha.webkit.NoUncheckedPtrMemberChecker should allow T* to appear within 
RefPtr.
---
 .../Checkers/WebKit/PtrTypesSemantics.cpp   |  7 +++
 .../Checkers/WebKit/PtrTypesSemantics.h |  4 
 .../Checkers/WebKit/RawPtrRefMemberChecker.cpp  | 17 ++---
 .../Checkers/WebKit/unchecked-members.cpp   |  9 +
 .../Checkers/WebKit/uncounted-members.cpp   | 15 ---
 5 files changed, 34 insertions(+), 18 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 811888e119449..ba0c7fd77b410 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -436,6 +436,13 @@ bool isRetainPtr(const CXXRecordDecl *R) {
   return false;
 }
 
+bool isSmartPtr(const CXXRecordDecl *R) {
+  assert(R);
+  if (auto *TmplR = R->getTemplateInstantiationPattern())
+return isSmartPtrClass(safeGetName(TmplR));
+  return false;
+}
+
 bool isPtrConversion(const FunctionDecl *F) {
   assert(F);
   if (isCtorOfRefCounted(F))
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
index 97c9d0510e67d..f9fcfe9878d54 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
@@ -58,6 +58,10 @@ bool isCheckedPtr(const clang::CXXRecordDecl *Class);
 /// \returns true if \p Class is a RetainPtr, false if not.
 bool isRetainPtr(const clang::CXXRecordDecl *Class);
 
+/// \returns true if \p Class is a smart pointer (RefPtr, WeakPtr, etc...),
+/// false if not.
+bool isSmartPtr(const clang::CXXRecordDecl *Class);
+
 /// \returns true if \p Class is ref-countable AND not ref-counted, false if
 /// not, std::nullopt if inconclusive.
 std::optional isUncounted(const clang::QualType T);
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp
index a003fc200727c..10b9749319a57 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp
@@ -41,7 +41,6 @@ class RawPtrRefMemberChecker
   virtual std::optional
   isPtrCompatible(const clang::QualType,
   const clang::CXXRecordDecl *R) const = 0;
-  virtual bool isPtrCls(const clang::CXXRecordDecl *) const = 0;
   virtual const char *typeName() const = 0;
   virtual const char *invariant() const = 0;
 
@@ -205,8 +204,8 @@ class RawPtrRefMemberChecker
 // Ref-counted smartpointers actually have raw-pointer to uncounted type as
 // a member but we trust them to handle it correctly.
 auto CXXRD = llvm::dyn_cast_or_null(RD);
-if (CXXRD)
-  return isPtrCls(CXXRD);
+if (CXXRD && isSmartPtr(CXXRD))
+  return true;
 
 return false;
   }
@@ -270,10 +269,6 @@ class NoUncountedMemberChecker final : public 
RawPtrRefMemberChecker {
 return R ? isRefCountable(R) : std::nullopt;
   }
 
-  bool isPtrCls(const clang::CXXRecordDecl *R) const final {
-return isRefCounted(R);
-  }
-
   const char *typeName() const final { return "ref-countable type"; }
 
   const char *invariant() const final {
@@ -293,10 +288,6 @@ class NoUncheckedPtrMemberChecker final : public 
RawPtrRefMemberChecker {
 return R ? isCheckedPtrCapable(R) : std::nullopt;
   }
 
-  bool isPtrCls(const clang::CXXRecordDecl *R) const final {
-return isCheckedPtr(R);
-  }
-
   const char *typeName() const final { return "CheckedPtr capable type"; }
 
   const char *invariant() const final {
@@ -319,10 +310,6 @@ class NoUnretainedMemberChecker final : public 
RawPtrRefMemberChecker {
 return RTC->isUnretained(QT);
   }
 
-  bool isPtrCls(const clang::CXXRecordDecl *R) const final {
-return isRetainPtr(R);
-  }
-
   const char *typeName() const final { return "retainable type"; }
 
   const char *invariant() const final {
diff --git a/clang/test/Analysis/Checkers/WebKit/unchecked-members.cpp 
b/clang/test/Analysis/Checkers/WebKit/unchecked-members.cpp
index 0189b0cd50fcc..048ffbffcdefb 100644
--- a/clang/test/Analysis/Checkers/WebKit/unchecked-members.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/unchecked-members.cp

[clang] [RawPtrRefMemberChecker] Member varible checker should allow T* in smart pointer classes (PR #136503)

2025-04-20 Thread via cfe-commits

llvmbot wrote:



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

@llvm/pr-subscribers-clang

Author: Ryosuke Niwa (rniwa)


Changes

This PR fixes member variable checker to allow the usage of T* in smart pointer 
classes. e.g. alpha.webkit.NoUncheckedPtrMemberChecker should allow T* to 
appear within RefPtr.

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


5 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
(+7) 
- (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h (+4) 
- (modified) 
clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp (+2-15) 
- (modified) clang/test/Analysis/Checkers/WebKit/unchecked-members.cpp (+9) 
- (modified) clang/test/Analysis/Checkers/WebKit/uncounted-members.cpp (+12-3) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 811888e119449..ba0c7fd77b410 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -436,6 +436,13 @@ bool isRetainPtr(const CXXRecordDecl *R) {
   return false;
 }
 
+bool isSmartPtr(const CXXRecordDecl *R) {
+  assert(R);
+  if (auto *TmplR = R->getTemplateInstantiationPattern())
+return isSmartPtrClass(safeGetName(TmplR));
+  return false;
+}
+
 bool isPtrConversion(const FunctionDecl *F) {
   assert(F);
   if (isCtorOfRefCounted(F))
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
index 97c9d0510e67d..f9fcfe9878d54 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
@@ -58,6 +58,10 @@ bool isCheckedPtr(const clang::CXXRecordDecl *Class);
 /// \returns true if \p Class is a RetainPtr, false if not.
 bool isRetainPtr(const clang::CXXRecordDecl *Class);
 
+/// \returns true if \p Class is a smart pointer (RefPtr, WeakPtr, etc...),
+/// false if not.
+bool isSmartPtr(const clang::CXXRecordDecl *Class);
+
 /// \returns true if \p Class is ref-countable AND not ref-counted, false if
 /// not, std::nullopt if inconclusive.
 std::optional isUncounted(const clang::QualType T);
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp
index a003fc200727c..10b9749319a57 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp
@@ -41,7 +41,6 @@ class RawPtrRefMemberChecker
   virtual std::optional
   isPtrCompatible(const clang::QualType,
   const clang::CXXRecordDecl *R) const = 0;
-  virtual bool isPtrCls(const clang::CXXRecordDecl *) const = 0;
   virtual const char *typeName() const = 0;
   virtual const char *invariant() const = 0;
 
@@ -205,8 +204,8 @@ class RawPtrRefMemberChecker
 // Ref-counted smartpointers actually have raw-pointer to uncounted type as
 // a member but we trust them to handle it correctly.
 auto CXXRD = llvm::dyn_cast_or_null(RD);
-if (CXXRD)
-  return isPtrCls(CXXRD);
+if (CXXRD && isSmartPtr(CXXRD))
+  return true;
 
 return false;
   }
@@ -270,10 +269,6 @@ class NoUncountedMemberChecker final : public 
RawPtrRefMemberChecker {
 return R ? isRefCountable(R) : std::nullopt;
   }
 
-  bool isPtrCls(const clang::CXXRecordDecl *R) const final {
-return isRefCounted(R);
-  }
-
   const char *typeName() const final { return "ref-countable type"; }
 
   const char *invariant() const final {
@@ -293,10 +288,6 @@ class NoUncheckedPtrMemberChecker final : public 
RawPtrRefMemberChecker {
 return R ? isCheckedPtrCapable(R) : std::nullopt;
   }
 
-  bool isPtrCls(const clang::CXXRecordDecl *R) const final {
-return isCheckedPtr(R);
-  }
-
   const char *typeName() const final { return "CheckedPtr capable type"; }
 
   const char *invariant() const final {
@@ -319,10 +310,6 @@ class NoUnretainedMemberChecker final : public 
RawPtrRefMemberChecker {
 return RTC->isUnretained(QT);
   }
 
-  bool isPtrCls(const clang::CXXRecordDecl *R) const final {
-return isRetainPtr(R);
-  }
-
   const char *typeName() const final { return "retainable type"; }
 
   const char *invariant() const final {
diff --git a/clang/test/Analysis/Checkers/WebKit/unchecked-members.cpp 
b/clang/test/Analysis/Checkers/WebKit/unchecked-members.cpp
index 0189b0cd50fcc..048ffbffcdefb 100644
--- a/clang/test/Analysis/Checkers/WebKit/unchecked-members.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/unchecked-members.cpp
@@ -50,3 +50,12 @@ namespace ignore_unions {
   void forceTmplToInstantiate(FooTmpl) { }
 
 } // namespace ignore_unions
+
+namespace checked_ptr_ref_ptr_capable {
+
+  RefCountableAndCheckable* provide();
+  void foo() {
+RefPt

[clang] [flang] Enable `-m32`, `-maix32` and `-maix64` for Flang on AIX. (PR #136202)

2025-04-20 Thread Kiran Chandramohan via cfe-commits

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

LG.

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


[clang] 0e3e0bf - [RISCV] Add processor definition for XiangShan-KunMingHu-V2R2 (#123193)

2025-04-20 Thread via cfe-commits

Author: Chyaka
Date: 2025-04-21T10:06:43+08:00
New Revision: 0e3e0bf42c25b280d8caa455c6ae7e4a04d3667a

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

LOG: [RISCV] Add processor definition for XiangShan-KunMingHu-V2R2 (#123193)

XiangShan-KunMingHu is the third generation of Open-source
high-performance RISC-V processor developed by Beijing Institute of Open
Source Chip (BOSC) , and its latest version is V2R2.

The KunMingHu manual is now available at
https://github.com/OpenXiangShan/XiangShan-User-Guide/releases.
It will be updated on the official XiangShan documentation site:
https://docs.xiangshan.cc/zh-cn/latest

You can find the corresponding ISA extension from the XiangShan Github
repository:
https://github.com/OpenXiangShan/XiangShan/blob/master/src/main/scala/xiangshan/Parameters.scala

If you want to track the latest performance data of KunMingHu, please
check XiangShan Biweekly: https://docs.xiangshan.cc/zh-cn/latest/blog

This PR adds the processor definition for KunMingHu V2R2, developed by
the XSCC team https://github.com/orgs/OpenXiangShan/teams/xscc.

The scheduling model for XiangShan-KunMingHu V2R2 will be submitted in a
subsequent PR.

-

Co-authored-by: Shenglin Tang 
Co-authored-by: Xu, Zefan 
Co-authored-by: Tang Haojin 

Added: 


Modified: 
clang/test/Driver/riscv-cpus.c
clang/test/Misc/target-invalid-cpu-note/riscv.c
llvm/docs/ReleaseNotes.md
llvm/lib/Target/RISCV/RISCVProcessors.td

Removed: 




diff  --git a/clang/test/Driver/riscv-cpus.c b/clang/test/Driver/riscv-cpus.c
index e97b6940662d9..c2314efd34aa6 100644
--- a/clang/test/Driver/riscv-cpus.c
+++ b/clang/test/Driver/riscv-cpus.c
@@ -31,6 +31,78 @@
 // MCPU-XIANGSHAN-NANHU-SAME: "-target-feature" "+zks" "-target-feature" 
"+zksed" "-target-feature" "+zksh" "-target-feature" "+svinval"
 // MCPU-XIANGSHAN-NANHU-SAME: "-target-abi" "lp64d"
 
+// RUN: %clang --target=riscv64 -### -c %s 2>&1 -mcpu=xiangshan-kunminghu | 
FileCheck -check-prefix=MCPU-XIANGSHAN-KUNMINGHU %s
+// MCPU-XIANGSHAN-KUNMINGHU: "-nostdsysteminc" "-target-cpu" 
"xiangshan-kunminghu"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+m"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+a"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+f"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+d"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+c"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+b"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+v"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+h"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zic64b" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zicbom" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zicbop" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zicboz" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+ziccamoa" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+ziccif" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zicclsm" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+ziccrse" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zicntr" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zicond" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zicsr" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zihintntl" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zacas" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zawrs" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zfa" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zfh" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zca" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zcb" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zcmop" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zba" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zbb" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zbc"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zbkb" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zbkc" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zbkx" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zbs"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zkn" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zks" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zvbb" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zve64d" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zve64f" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zve64x" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zvfh"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zvkb"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zvkt"
+// MCPU-XIANGSHAN-K

[clang] [llvm] [RISCV] Add processor definition for XiangShan-KunMingHu-V2R2 (PR #123193)

2025-04-20 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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


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


[clang] 27653bd - Ensure bit-fields storing FPEvalMethodKind are wide enough to do so (#136515)

2025-04-20 Thread via cfe-commits

Author: Oliver Hunt
Date: 2025-04-20T18:42:09-07:00
New Revision: 27653bdc49161b6d0e785185384a5c96a55e9e24

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

LOG: Ensure bit-fields storing FPEvalMethodKind are wide enough to do so 
(#136515)

After landing #116760 we hit build failures due to existing fields
storing FPEvalMethodKind not being wide enough.

Added: 


Modified: 
clang/include/clang/Basic/FPOptions.def
clang/include/clang/Basic/LangOptions.def

Removed: 




diff  --git a/clang/include/clang/Basic/FPOptions.def 
b/clang/include/clang/Basic/FPOptions.def
index 90428c3c73c8b..85986b4ff0b9c 100644
--- a/clang/include/clang/Basic/FPOptions.def
+++ b/clang/include/clang/Basic/FPOptions.def
@@ -24,7 +24,7 @@ OPTION(NoHonorInfs, bool, 1, NoHonorNaNs)
 OPTION(NoSignedZero, bool, 1, NoHonorInfs)
 OPTION(AllowReciprocal, bool, 1, NoSignedZero)
 OPTION(AllowApproxFunc, bool, 1, AllowReciprocal)
-OPTION(FPEvalMethod, LangOptions::FPEvalMethodKind, 2, AllowApproxFunc)
+OPTION(FPEvalMethod, LangOptions::FPEvalMethodKind, 3, AllowApproxFunc)
 OPTION(Float16ExcessPrecision, LangOptions::ExcessPrecisionKind, 2, 
FPEvalMethod)
 OPTION(BFloat16ExcessPrecision, LangOptions::ExcessPrecisionKind, 2, 
Float16ExcessPrecision)
 OPTION(MathErrno, bool, 1, BFloat16ExcessPrecision)

diff  --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 930c1c06d1a76..85ca523c44157 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -347,7 +347,7 @@ BENIGN_ENUM_LANGOPT(DefaultFPContractMode, FPModeKind, 2, 
FPM_Off, "FP contracti
 COMPATIBLE_LANGOPT(ExpStrictFP, 1, false, "Enable experimental strict floating 
point")
 BENIGN_LANGOPT(RoundingMath, 1, false, "Do not assume default floating-point 
rounding behavior")
 BENIGN_ENUM_LANGOPT(FPExceptionMode, FPExceptionModeKind, 2, FPE_Default, "FP 
Exception Behavior Mode type")
-BENIGN_ENUM_LANGOPT(FPEvalMethod, FPEvalMethodKind, 2, FEM_UnsetOnCommandLine, 
"FP type used for floating point arithmetic")
+BENIGN_ENUM_LANGOPT(FPEvalMethod, FPEvalMethodKind, 3, FEM_UnsetOnCommandLine, 
"FP type used for floating point arithmetic")
 ENUM_LANGOPT(Float16ExcessPrecision, ExcessPrecisionKind, 2, FPP_Standard, 
"Intermediate truncation behavior for Float16 arithmetic")
 ENUM_LANGOPT(BFloat16ExcessPrecision, ExcessPrecisionKind, 2, FPP_Standard, 
"Intermediate truncation behavior for BFloat16 arithmetic")
 LANGOPT(NoBitFieldTypeAlign , 1, 0, "bit-field type alignment")



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


[clang] [llvm] [RISCV] Add processor definition for XiangShan-KunMingHu-V2R2 (PR #123193)

2025-04-20 Thread Sirui Mu via cfe-commits

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


[clang] [clang][AVR] Improve compatibility of inline assembly with avr-gcc (PR #136534)

2025-04-20 Thread Sergei Barannikov via cfe-commits

s-barannikov wrote:

gcc doesn't seem to allow it?
https://godbolt.org/z/4zh8TTPac


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


[clang] [clang][analyzer] Handle CXXParenInitListExpr alongside InitListExpr (PR #136041)

2025-04-20 Thread Yanzuo Liu via cfe-commits

zwuis wrote:

> FYI we usually ping once a week.

Oh, I see. IIUC `@ llvm/pr-subscribers-clang-static-analyzer-1` is also a ping, 
which I didn't know.

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


[clang] [clang-tools-extra] [clangd] Support operators new and delete in textDocument/references (PR #135620)

2025-04-20 Thread Nathan Ridge via cfe-commits

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

Thanks!

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


[clang] [clang][AVR] Improve compatibility of inline assembly with avr-gcc (PR #136534)

2025-04-20 Thread Ben Shi via cfe-commits

benshi001 wrote:

> gcc doesn't seem to allow it? https://godbolt.org/z/4zh8TTPac

avr-gcc allow value 64 for constraint 'I' in very special case, such as 
https://github.com/avrdudes/avr-libc/issues/678.

And my solution is loosen that check in the frontend, but let the AVR backend 
to deny the illegal constraint value 64.

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


[clang] [AST] Call hash_combine_range with a range (NFC) (PR #136525)

2025-04-20 Thread Jakub Kuderski via cfe-commits

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


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


[clang] [AST] Call hash_combine_range with a range (NFC) (PR #136525)

2025-04-20 Thread Kazu Hirata via cfe-commits

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


[clang] 02b55d2 - [AST] Call hash_combine_range with a range (NFC) (#136525)

2025-04-20 Thread via cfe-commits

Author: Kazu Hirata
Date: 2025-04-20T19:59:19-07:00
New Revision: 02b55d2b78d318dad331a66ddac81c7318b0b87a

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

LOG: [AST] Call hash_combine_range with a range (NFC) (#136525)

Added: 


Modified: 
clang/lib/AST/ItaniumCXXABI.cpp

Removed: 




diff  --git a/clang/lib/AST/ItaniumCXXABI.cpp b/clang/lib/AST/ItaniumCXXABI.cpp
index a1b2551419f5e..6ceedd657fe7e 100644
--- a/clang/lib/AST/ItaniumCXXABI.cpp
+++ b/clang/lib/AST/ItaniumCXXABI.cpp
@@ -110,7 +110,7 @@ struct DenseMapInfo {
   }
   static unsigned getHashValue(DecompositionDeclName Key) {
 assert(!isEqual(Key, getEmptyKey()) && !isEqual(Key, getTombstoneKey()));
-return llvm::hash_combine_range(Key.begin(), Key.end());
+return llvm::hash_combine_range(Key);
   }
   static bool isEqual(DecompositionDeclName LHS, DecompositionDeclName RHS) {
 if (std::optional Result =



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


[clang-tools-extra] 6274442 - [clangd] Call hash_combine_range with a range (NFC) (#136526)

2025-04-20 Thread via cfe-commits

Author: Kazu Hirata
Date: 2025-04-20T19:59:28-07:00
New Revision: 6274442f8c657597233b9691298df7b5cd743e66

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

LOG: [clangd] Call hash_combine_range with a range (NFC) (#136526)

Added: 


Modified: 
clang-tools-extra/clangd/SystemIncludeExtractor.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/SystemIncludeExtractor.cpp 
b/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
index 9399b910025b6..d9642f1115a6d 100644
--- a/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
+++ b/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
@@ -239,8 +239,7 @@ template <> struct DenseMapInfo {
 Val.Stdlib,
 });
 
-unsigned SpecsHash =
-llvm::hash_combine_range(Val.Specs.begin(), Val.Specs.end());
+unsigned SpecsHash = llvm::hash_combine_range(Val.Specs);
 
 return llvm::hash_combine(FixedFieldsHash, SpecsHash);
   }



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


[clang-tools-extra] [clangd] Call hash_combine_range with a range (NFC) (PR #136526)

2025-04-20 Thread Kazu Hirata via cfe-commits

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


[clang-tools-extra] [clangd] Call hash_combine_range with a range (NFC) (PR #136526)

2025-04-20 Thread Jakub Kuderski via cfe-commits

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


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


[clang] [clang][AVR] Improve compatibility of inline assembly with avr-gcc (PR #136534)

2025-04-20 Thread Ben Shi via cfe-commits

https://github.com/benshi001 created 
https://github.com/llvm/llvm-project/pull/136534

Allow the value 64 to be round up to 0 for constraint 'I'.

>From 1dcd2d91c37a4e6afc137ff0ad54d25777a1f4b1 Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Mon, 21 Apr 2025 11:16:51 +0800
Subject: [PATCH] [clang][AVR] Improve compitability of inline assembly with
 avr-gcc

Allow the value 64 to be round up to 0 for constraint 'I'.
---
 clang/lib/Basic/Targets/AVR.h   | 2 +-
 clang/test/CodeGen/avr/avr-inline-asm-constraints.c | 2 ++
 clang/test/CodeGen/avr/avr-unsupported-inline-asm-constraints.c | 1 +
 3 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Basic/Targets/AVR.h b/clang/lib/Basic/Targets/AVR.h
index 2117ab58e6f30..b2f2711c35435 100644
--- a/clang/lib/Basic/Targets/AVR.h
+++ b/clang/lib/Basic/Targets/AVR.h
@@ -124,7 +124,7 @@ class LLVM_LIBRARY_VISIBILITY AVRTargetInfo : public 
TargetInfo {
   Info.setAllowsRegister();
   return true;
 case 'I': // 6-bit positive integer constant
-  Info.setRequiresImmediate(0, 63);
+  Info.setRequiresImmediate(0, 64);
   return true;
 case 'J': // 6-bit negative integer constant
   Info.setRequiresImmediate(-63, 0);
diff --git a/clang/test/CodeGen/avr/avr-inline-asm-constraints.c 
b/clang/test/CodeGen/avr/avr-inline-asm-constraints.c
index 3a956de8db48f..c8d83b4848312 100644
--- a/clang/test/CodeGen/avr/avr-inline-asm-constraints.c
+++ b/clang/test/CodeGen/avr/avr-inline-asm-constraints.c
@@ -71,6 +71,8 @@ void z() {
 void I() {
   // CHECK: call addrspace(0) void asm sideeffect "subi r30, $0", "I"(i16 50)
   asm("subi r30, %0" :: "I"(50));
+  // CHECK: call addrspace(0) void asm sideeffect "subi r30, $0", "I"(i16 64)
+  asm("subi r30, %0" :: "I"(64));
 }
 
 void J() {
diff --git a/clang/test/CodeGen/avr/avr-unsupported-inline-asm-constraints.c 
b/clang/test/CodeGen/avr/avr-unsupported-inline-asm-constraints.c
index 29f0b69285fa8..52b8d1cb044ca 100644
--- a/clang/test/CodeGen/avr/avr-unsupported-inline-asm-constraints.c
+++ b/clang/test/CodeGen/avr/avr-unsupported-inline-asm-constraints.c
@@ -6,4 +6,5 @@ int foo(void) {
   __asm__ volatile("foo %0, 1" : : "fo" (val)); // expected-error {{invalid 
input constraint 'fo' in asm}}
   __asm__ volatile("foo %0, 1" : : "Nd" (val)); // expected-error {{invalid 
input constraint 'Nd' in asm}}
   __asm__ volatile("subi r30, %0" : : "G" (1)); // expected-error {{value '1' 
out of range for constraint 'G'}}
+  __asm__ volatile("out %0, r20" : : "I" (65)); // expected-error {{value '65' 
out of range for constraint 'I'}}
 }

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


[clang] [clang][AVR] Improve compatibility of inline assembly with avr-gcc (PR #136534)

2025-04-20 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Ben Shi (benshi001)


Changes

Allow the value 64 to be round up to 0 for constraint 'I'.

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


3 Files Affected:

- (modified) clang/lib/Basic/Targets/AVR.h (+1-1) 
- (modified) clang/test/CodeGen/avr/avr-inline-asm-constraints.c (+2) 
- (modified) clang/test/CodeGen/avr/avr-unsupported-inline-asm-constraints.c 
(+1) 


``diff
diff --git a/clang/lib/Basic/Targets/AVR.h b/clang/lib/Basic/Targets/AVR.h
index 2117ab58e6f30..b2f2711c35435 100644
--- a/clang/lib/Basic/Targets/AVR.h
+++ b/clang/lib/Basic/Targets/AVR.h
@@ -124,7 +124,7 @@ class LLVM_LIBRARY_VISIBILITY AVRTargetInfo : public 
TargetInfo {
   Info.setAllowsRegister();
   return true;
 case 'I': // 6-bit positive integer constant
-  Info.setRequiresImmediate(0, 63);
+  Info.setRequiresImmediate(0, 64);
   return true;
 case 'J': // 6-bit negative integer constant
   Info.setRequiresImmediate(-63, 0);
diff --git a/clang/test/CodeGen/avr/avr-inline-asm-constraints.c 
b/clang/test/CodeGen/avr/avr-inline-asm-constraints.c
index 3a956de8db48f..c8d83b4848312 100644
--- a/clang/test/CodeGen/avr/avr-inline-asm-constraints.c
+++ b/clang/test/CodeGen/avr/avr-inline-asm-constraints.c
@@ -71,6 +71,8 @@ void z() {
 void I() {
   // CHECK: call addrspace(0) void asm sideeffect "subi r30, $0", "I"(i16 50)
   asm("subi r30, %0" :: "I"(50));
+  // CHECK: call addrspace(0) void asm sideeffect "subi r30, $0", "I"(i16 64)
+  asm("subi r30, %0" :: "I"(64));
 }
 
 void J() {
diff --git a/clang/test/CodeGen/avr/avr-unsupported-inline-asm-constraints.c 
b/clang/test/CodeGen/avr/avr-unsupported-inline-asm-constraints.c
index 29f0b69285fa8..52b8d1cb044ca 100644
--- a/clang/test/CodeGen/avr/avr-unsupported-inline-asm-constraints.c
+++ b/clang/test/CodeGen/avr/avr-unsupported-inline-asm-constraints.c
@@ -6,4 +6,5 @@ int foo(void) {
   __asm__ volatile("foo %0, 1" : : "fo" (val)); // expected-error {{invalid 
input constraint 'fo' in asm}}
   __asm__ volatile("foo %0, 1" : : "Nd" (val)); // expected-error {{invalid 
input constraint 'Nd' in asm}}
   __asm__ volatile("subi r30, %0" : : "G" (1)); // expected-error {{value '1' 
out of range for constraint 'G'}}
+  __asm__ volatile("out %0, r20" : : "I" (65)); // expected-error {{value '65' 
out of range for constraint 'I'}}
 }

``




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


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

2025-04-20 Thread via cfe-commits

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

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

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

This approach has limitations:

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

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

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

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

**Proposed Solution**

1. Introduce a new configuration option: AllowShortFunctionsOnSingleLineOptions.

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

3. **Backward Compatibility:**

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

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

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

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

2025-04-20 Thread via cfe-commits


@@ -5685,11 +5685,9 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine 
&Line,
 if (Right.is(tok::r_brace) && Left.is(tok::l_brace) &&
 !Left.Children.empty()) {
   // Support AllowShortFunctionsOnASingleLine for JavaScript.
-  return Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_None ||
- Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_Empty 
||
- (Left.NestingLevel == 0 && Line.Level == 0 &&
-  Style.AllowShortFunctionsOnASingleLine &
-  FormatStyle::SFS_InlineOnly);
+  return !(Left.NestingLevel == 0 && Line.Level == 0
+   ? Style.AllowShortFunctionsOnASingleLine.isAll()

irymarchyk wrote:

Thanks, I tried to add code to correctly handle this case. Also I added unit 
test (per my understanding). Please let me know if you want to add more cases 
(or if I made some mistake). Thanks.

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


[clang-tools-extra] [clangd] IncludeCleaner include not found error now contains path (PR #136237)

2025-04-20 Thread Nathan Ridge via cfe-commits

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

Thanks!

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


[clang-tools-extra] 8435de0 - [clangd] Print include spelling in IncludeCleaner error message (#136237)

2025-04-20 Thread via cfe-commits

Author: Tongsheng Wu
Date: 2025-04-21T02:09:51-04:00
New Revision: 8435de0916d9df5a3a9dd9eeb44d5bf4aba87ba3

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

LOG: [clangd] Print include spelling in IncludeCleaner error message (#136237)

Added: 


Modified: 
clang-tools-extra/clangd/IncludeCleaner.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/IncludeCleaner.cpp 
b/clang-tools-extra/clangd/IncludeCleaner.cpp
index e34706172f0bf..dc4c8fc498b1f 100644
--- a/clang-tools-extra/clangd/IncludeCleaner.cpp
+++ b/clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -345,8 +345,9 @@ include_cleaner::Includes convertIncludes(const ParsedAST 
&AST) {
 // which is based on FileManager::getCanonicalName(ParentDir).
 auto FE = SM.getFileManager().getFileRef(Inc.Resolved);
 if (!FE) {
-  elog("IncludeCleaner: Failed to get an entry for resolved path {0}: {1}",
-   Inc.Resolved, FE.takeError());
+  elog("IncludeCleaner: Failed to get an entry for resolved path '{0}' "
+   "from include {1} : {2}",
+   Inc.Resolved, Inc.Written, FE.takeError());
   continue;
 }
 TransformedInc.Resolved = *FE;



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


[clang-tools-extra] [clangd] IncludeCleaner include not found error now contains path (PR #136237)

2025-04-20 Thread Nathan Ridge via cfe-commits

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


[clang-tools-extra] [clangd] IncludeCleaner include not found error now contains path (PR #136237)

2025-04-20 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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


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


[clang] [clang][AVR] Improve compatibility of inline assembly with avr-gcc (PR #136534)

2025-04-20 Thread Patryk Wychowaniec via cfe-commits

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


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


[clang-tools-extra] [clangd] Improve `BlockEnd` inlayhint presentation (PR #136106)

2025-04-20 Thread Nathan Ridge via cfe-commits


@@ -2305,7 +2335,45 @@ TEST(BlockEndHints, PointerToMemberFunction) {
   $ptrmem[[}]]
 } // suppress
   )cpp",
-  ExpectedHint{" // if", "ptrmem"});
+  ExpectedHint{" // if ()", "ptrmem"});
+}
+
+TEST(BlockEndHints, MinLineLimit) {
+  assertBlockEndHintsWithOpts(
+  R"cpp(
+namespace ns {
+  int Var;
+  int func1();
+  int func2(int, int);
+  struct S {
+int Field;
+int method1() const;
+int method2(int, int) const;
+  $struct[[}]];
+$namespace[[}]]
+void foo() {
+  int int_a {};
+  while (ns::Var) {
+  $var[[}]]
+
+  while (ns::func1()) {
+  $func1[[}]]
+
+  while (ns::func2(int_a, int_a)) {
+  $func2[[}]]
+
+  while (ns::S{}.Field) {
+  $field[[}]]
+
+  while (ns::S{}.method1()) {
+  $method1[[}]]
+  
+  while (ns::S{}.method2(int_a, int_a)) {
+  $method2[[}]]
+$foo[[}]]
+  )cpp",
+  InlayHintOptions{10}, ExpectedHint{" // namespace ns", "namespace"},

HighCommander4 wrote:

I'd rather we be a bit more explicit:

```c++
InlayhintOptions Opts;
Opts.HintMinLineLimit = 10;
...
assertBlockEndHintsWithOpts(..., Opts, ...);
```

as there may be more options in the future and it's not obvious which is first.

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


[clang-tools-extra] [clangd] Improve `BlockEnd` inlayhint presentation (PR #136106)

2025-04-20 Thread Nathan Ridge via cfe-commits


@@ -22,10 +22,16 @@ namespace clang {
 namespace clangd {
 class ParsedAST;
 
+struct InlayHintOptions {
+  // Minimum lines for BlockEnd inlay-hints to be shown
+  int HintMinLineLimit{2};

HighCommander4 wrote:

What we discussed in the original issue was that the default should remain 2 
**for tests**, so that we don't have to change a lot of tests / artificially 
make the blocks long in test code, but that the limit used in production should 
be increased to 10.

That requires either:
 * passing an options struct with the limit set to 10 in the [production call 
site](https://searchfox.org/llvm/rev/bb21a6819b3fb9d689de776f7ee768030dfbacea/clang-tools-extra/clangd/ClangdServer.cpp#921);
 or
 * setting the default to 10 here and adjusting test code accordingly (i.e. 
explicitly passing `2` to `DefaultInlayHintOpts`)

My preference is the latter, as that ensures that any new call sites use the 
production value by default (and it seems to be what we do for other options).

(Also, small code style nit: the convention in clangd code seems to be [equals 
initialization](https://searchfox.org/llvm/rev/bb21a6819b3fb9d689de776f7ee768030dfbacea/clang-tools-extra/clangd/CodeComplete.h#50)
 for members.)

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


[clang-tools-extra] [clangd] Improve `BlockEnd` inlayhint presentation (PR #136106)

2025-04-20 Thread Nathan Ridge via cfe-commits


@@ -2305,7 +2335,45 @@ TEST(BlockEndHints, PointerToMemberFunction) {
   $ptrmem[[}]]
 } // suppress
   )cpp",
-  ExpectedHint{" // if", "ptrmem"});
+  ExpectedHint{" // if ()", "ptrmem"});
+}
+
+TEST(BlockEndHints, MinLineLimit) {
+  assertBlockEndHintsWithOpts(
+  R"cpp(
+namespace ns {
+  int Var;
+  int func1();
+  int func2(int, int);
+  struct S {
+int Field;
+int method1() const;
+int method2(int, int) const;
+  $struct[[}]];

HighCommander4 wrote:

this and other unused annotations can be removed

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


[clang-tools-extra] [clangd] Improve `BlockEnd` inlayhint presentation (PR #136106)

2025-04-20 Thread Nathan Ridge via cfe-commits


@@ -22,10 +22,16 @@ namespace clang {
 namespace clangd {
 class ParsedAST;
 
+struct InlayHintOptions {
+  // Minimum lines for BlockEnd inlay-hints to be shown

HighCommander4 wrote:

Let's make this comment a bit more specific:

```
// Minimum height of a code block in lines for a BlockEnd hint to be shown
// Includes the lines containing the braces
```

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


[clang-tools-extra] [clangd] Improve `BlockEnd` inlayhint presentation (PR #136106)

2025-04-20 Thread Nathan Ridge via cfe-commits


@@ -147,6 +149,9 @@ std::string summarizeExpr(const Expr *E) {
 }
 
 // Literals are just printed
+std::string VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E) {
+  return "nullptr";

HighCommander4 wrote:

Could you add a small test case (or extend an existing one) that exercises this 
change? e.g. something like:

```c++
void foo(char *s) {
  if (s != nullptr) {
  }  // if s != nullptr
}

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


[clang-tools-extra] [clangd] Improve `BlockEnd` inlayhint presentation (PR #136106)

2025-04-20 Thread Nathan Ridge via cfe-commits

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

Thanks for picking up this patch!

Looks fairly good, just a few comments:

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


[clang-tools-extra] [clangd] Improve `BlockEnd` inlayhint presentation (PR #136106)

2025-04-20 Thread Nathan Ridge via cfe-commits


@@ -36,9 +36,12 @@ namespace {
 using ::testing::ElementsAre;
 using ::testing::IsEmpty;
 
-std::vector hintsOfKind(ParsedAST &AST, InlayHintKind Kind) {
+constexpr InlayHintOptions DefaultInlayHintOpts{};

HighCommander4 wrote:

nit: let's call this `DefaultInlayHintOptsForTests` (or just 
`DefaultOptsForTests`)

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


[clang] [clang][analyzer] Handle CXXParenInitListExpr alongside InitListExpr (PR #136041)

2025-04-20 Thread Balazs Benics via cfe-commits

steakhal wrote:

Ah, I see now your perspective.
Yes, any PRs tagged with the CSA tag will hit our inboxes.

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


[clang-tools-extra] [clangd] Improve `BlockEnd` inlayhint presentation (PR #136106)

2025-04-20 Thread Nathan Ridge via cfe-commits

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


[clang] [clang][AVR] Improve compatibility of inline assembly with avr-gcc (PR #136534)

2025-04-20 Thread Jianjian Guan via cfe-commits

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


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


[clang] [Clang] Make the result type of sizeof/pointer subtraction/size_t lit… (PR #136542)

2025-04-20 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: YexuanXiao (YexuanXiao)


Changes

…erals be typedefs instead of built-in types

Includeing the results of `sizeof`, `sizeof...`, `__datasizeof`, `__alignof`, 
`_Alignof`, `alignof`, `_Countof`, `size_t` literals, and signed `size_t` 
literals, as well as the results of pointer-pointer subtraction. It does not 
affect any program output except for debugging information. The goal is to 
enable clang and downstream tools such as clangd and clang-tidy to provide more 
portable hints and diagnostics.

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


5 Files Affected:

- (modified) clang/include/clang/AST/ASTContext.h (+4) 
- (modified) clang/lib/AST/ASTContext.cpp (+29) 
- (modified) clang/lib/AST/ComparisonCategories.cpp (+5-25) 
- (modified) clang/lib/AST/ExprCXX.cpp (+4-2) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+26-8) 


``diff
diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 3c78833a3f069..0c133d45d3f5e 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -2442,6 +2442,10 @@ class ASTContext : public RefCountedBase {
   QualType GetBuiltinType(unsigned ID, GetBuiltinTypeError &Error,
   unsigned *IntegerConstantArgs = nullptr) const;
 
+  QualType getCGlobalCXXStdNSTypedef(const NamespaceDecl *StdNS,
+ StringRef DefName,
+ QualType FallBack = {}) const;
+
   /// Types and expressions required to build C++2a three-way comparisons
   /// using operator<=>, including the values return by builtin <=> operators.
   ComparisonCategories CompCategories;
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 2836d68b05ff6..aa8ce0078d4d3 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -12556,6 +12556,35 @@ QualType ASTContext::GetBuiltinType(unsigned Id,
   return getFunctionType(ResType, ArgTypes, EPI);
 }
 
+QualType ASTContext::getCGlobalCXXStdNSTypedef(const NamespaceDecl *StdNS,
+   StringRef DefName,
+   QualType FallBack) const {
+  DeclContextLookupResult Lookup;
+  if (getLangOpts().C99) {
+Lookup = getTranslationUnitDecl()->lookup(&Idents.get(DefName));
+  } else if (getLangOpts().CPlusPlus) {
+if (StdNS == nullptr) {
+  auto LookupStdNS = getTranslationUnitDecl()->lookup(&Idents.get("std"));
+  if (!LookupStdNS.empty()) {
+StdNS = dyn_cast(LookupStdNS.front());
+  }
+}
+if (StdNS) {
+  Lookup = StdNS->lookup(&Idents.get(DefName));
+} else {
+  Lookup = getTranslationUnitDecl()->lookup(&Idents.get(DefName));
+}
+  }
+  if (!Lookup.empty()) {
+if (auto *TD = dyn_cast(Lookup.front())) {
+  if (auto Result = getTypeDeclType(TD); !Result.isNull()) {
+return Result;
+  }
+}
+  }
+  return FallBack;
+}
+
 static GVALinkage basicGVALinkageForFunction(const ASTContext &Context,
  const FunctionDecl *FD) {
   if (!FD->isExternallyVisible())
diff --git a/clang/lib/AST/ComparisonCategories.cpp 
b/clang/lib/AST/ComparisonCategories.cpp
index 28244104d6636..46dcd6ac4261d 100644
--- a/clang/lib/AST/ComparisonCategories.cpp
+++ b/clang/lib/AST/ComparisonCategories.cpp
@@ -87,37 +87,17 @@ ComparisonCategoryInfo::ValueInfo 
*ComparisonCategoryInfo::lookupValueInfo(
   return &Objects.back();
 }
 
-static const NamespaceDecl *lookupStdNamespace(const ASTContext &Ctx,
-   NamespaceDecl *&StdNS) {
-  if (!StdNS) {
-DeclContextLookupResult Lookup =
-Ctx.getTranslationUnitDecl()->lookup(&Ctx.Idents.get("std"));
-if (!Lookup.empty())
-  StdNS = dyn_cast(Lookup.front());
-  }
-  return StdNS;
-}
-
-static const CXXRecordDecl *lookupCXXRecordDecl(const ASTContext &Ctx,
-const NamespaceDecl *StdNS,
-ComparisonCategoryType Kind) {
-  StringRef Name = ComparisonCategories::getCategoryString(Kind);
-  DeclContextLookupResult Lookup = StdNS->lookup(&Ctx.Idents.get(Name));
-  if (!Lookup.empty())
-if (const CXXRecordDecl *RD = dyn_cast(Lookup.front()))
-  return RD;
-  return nullptr;
-}
-
 const ComparisonCategoryInfo *
 ComparisonCategories::lookupInfo(ComparisonCategoryType Kind) const {
   auto It = Data.find(static_cast(Kind));
   if (It != Data.end())
 return &It->second;
-
-  if (const NamespaceDecl *NS = lookupStdNamespace(Ctx, StdNS))
-if (const CXXRecordDecl *RD = lookupCXXRecordDecl(Ctx, NS, Kind))
+  if (auto QT = Ctx.getCGlobalCXXStdNSTypedef(
+  nullptr, ComparisonCategories::getCategoryString(Kind));
+  !QT.isNull()) {
+if (const auto *RD = QT->getAsCXXRecordDecl())
   return &Data.try_emplace((char

[clang] [Clang] Make the result type of sizeof/pointer subtraction/size_t lit… (PR #136542)

2025-04-20 Thread via cfe-commits

https://github.com/YexuanXiao created 
https://github.com/llvm/llvm-project/pull/136542

…erals be typedefs instead of built-in types

Includeing the results of `sizeof`, `sizeof...`, `__datasizeof`, `__alignof`, 
`_Alignof`, `alignof`, `_Countof`, `size_t` literals, and signed `size_t` 
literals, as well as the results of pointer-pointer subtraction. It does not 
affect any program output except for debugging information. The goal is to 
enable clang and downstream tools such as clangd and clang-tidy to provide more 
portable hints and diagnostics.

>From b9cc91971469dcf19bb926f6f53ae5a57d1109c3 Mon Sep 17 00:00:00 2001
From: YexuanXiao 
Date: Mon, 21 Apr 2025 14:28:33 +0800
Subject: [PATCH] [Clang] Make the result type of sizeof/pointer
 subtraction/size_t literals be typedefs instead of built-in types Includeing
 the results of `sizeof`, `sizeof...`, `__datasizeof`, `__alignof`,
 `_Alignof`, `alignof`, `_Countof`, `size_t` literals, and signed `size_t`
 literals, as well as the results of pointer-pointer subtraction. It does not
 affect any program output except for debugging information. The goal is to
 enable clang and downstream tools such as clangd and clang-tidy to provide
 more portable hints and diagnostics.

---
 clang/include/clang/AST/ASTContext.h   |  4 +++
 clang/lib/AST/ASTContext.cpp   | 29 ++
 clang/lib/AST/ComparisonCategories.cpp | 30 ---
 clang/lib/AST/ExprCXX.cpp  |  6 +++--
 clang/lib/Sema/SemaExpr.cpp| 34 --
 5 files changed, 68 insertions(+), 35 deletions(-)

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 3c78833a3f069..0c133d45d3f5e 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -2442,6 +2442,10 @@ class ASTContext : public RefCountedBase {
   QualType GetBuiltinType(unsigned ID, GetBuiltinTypeError &Error,
   unsigned *IntegerConstantArgs = nullptr) const;
 
+  QualType getCGlobalCXXStdNSTypedef(const NamespaceDecl *StdNS,
+ StringRef DefName,
+ QualType FallBack = {}) const;
+
   /// Types and expressions required to build C++2a three-way comparisons
   /// using operator<=>, including the values return by builtin <=> operators.
   ComparisonCategories CompCategories;
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 2836d68b05ff6..aa8ce0078d4d3 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -12556,6 +12556,35 @@ QualType ASTContext::GetBuiltinType(unsigned Id,
   return getFunctionType(ResType, ArgTypes, EPI);
 }
 
+QualType ASTContext::getCGlobalCXXStdNSTypedef(const NamespaceDecl *StdNS,
+   StringRef DefName,
+   QualType FallBack) const {
+  DeclContextLookupResult Lookup;
+  if (getLangOpts().C99) {
+Lookup = getTranslationUnitDecl()->lookup(&Idents.get(DefName));
+  } else if (getLangOpts().CPlusPlus) {
+if (StdNS == nullptr) {
+  auto LookupStdNS = getTranslationUnitDecl()->lookup(&Idents.get("std"));
+  if (!LookupStdNS.empty()) {
+StdNS = dyn_cast(LookupStdNS.front());
+  }
+}
+if (StdNS) {
+  Lookup = StdNS->lookup(&Idents.get(DefName));
+} else {
+  Lookup = getTranslationUnitDecl()->lookup(&Idents.get(DefName));
+}
+  }
+  if (!Lookup.empty()) {
+if (auto *TD = dyn_cast(Lookup.front())) {
+  if (auto Result = getTypeDeclType(TD); !Result.isNull()) {
+return Result;
+  }
+}
+  }
+  return FallBack;
+}
+
 static GVALinkage basicGVALinkageForFunction(const ASTContext &Context,
  const FunctionDecl *FD) {
   if (!FD->isExternallyVisible())
diff --git a/clang/lib/AST/ComparisonCategories.cpp 
b/clang/lib/AST/ComparisonCategories.cpp
index 28244104d6636..46dcd6ac4261d 100644
--- a/clang/lib/AST/ComparisonCategories.cpp
+++ b/clang/lib/AST/ComparisonCategories.cpp
@@ -87,37 +87,17 @@ ComparisonCategoryInfo::ValueInfo 
*ComparisonCategoryInfo::lookupValueInfo(
   return &Objects.back();
 }
 
-static const NamespaceDecl *lookupStdNamespace(const ASTContext &Ctx,
-   NamespaceDecl *&StdNS) {
-  if (!StdNS) {
-DeclContextLookupResult Lookup =
-Ctx.getTranslationUnitDecl()->lookup(&Ctx.Idents.get("std"));
-if (!Lookup.empty())
-  StdNS = dyn_cast(Lookup.front());
-  }
-  return StdNS;
-}
-
-static const CXXRecordDecl *lookupCXXRecordDecl(const ASTContext &Ctx,
-const NamespaceDecl *StdNS,
-ComparisonCategoryType Kind) {
-  StringRef Name = ComparisonCategories::getCategoryString(Kind);
-  DeclContextLookupResult Lookup = StdNS->lookup(&Ctx.Idents.get(Name));
-  if (!Look

[clang] [Clang] Make the result type of sizeof/pointer subtraction/size_t lit… (PR #136542)

2025-04-20 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/136542
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][AVR] Improve compatibility of inline assembly with avr-gcc (PR #136534)

2025-04-20 Thread Sergei Barannikov via cfe-commits

s-barannikov wrote:

> > gcc doesn't seem to allow it? https://godbolt.org/z/4zh8TTPac
> 
> avr-gcc allow value 64 for constraint 'I' in very special case, such as 
> #51513.

I guess the test needs to be updated to be representative?

> And my solution is loosen that check in the frontend, but let the AVR backend 
> to deny the illegal constraint value 64.

This deserves a comment in code so that other people don't get confused about 
this and don't try to change it back to 63.


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


[clang-tools-extra] [clangd] Improve `BlockEnd` inlayhint presentation (PR #136106)

2025-04-20 Thread via cfe-commits


@@ -2305,7 +2335,45 @@ TEST(BlockEndHints, PointerToMemberFunction) {
   $ptrmem[[}]]
 } // suppress
   )cpp",
-  ExpectedHint{" // if", "ptrmem"});
+  ExpectedHint{" // if ()", "ptrmem"});
+}
+
+TEST(BlockEndHints, MinLineLimit) {
+  assertBlockEndHintsWithOpts(
+  R"cpp(
+namespace ns {
+  int Var;
+  int func1();
+  int func2(int, int);
+  struct S {
+int Field;
+int method1() const;
+int method2(int, int) const;
+  $struct[[}]];

MythreyaK wrote:

I left them in because I thought that this would ensure the test fails when 
these annotations (unexpectedly) generate hints. Do I remove them? 

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


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

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`ppc64le-lld-multistage-test` running on `ppc64le-lld-multistage-test` while 
building `clang` at step 12 "build-stage2-unified-tree".

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


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

```
Step 12 (build-stage2-unified-tree) failure: build (failure)
...
388.063 [2086/1154/3313] Building CXX object 
tools/llvm-debuginfod-find/CMakeFiles/llvm-debuginfod-find.dir/llvm-debuginfod-find-driver.cpp.o
388.078 [2085/1154/3314] Building CXX object 
lib/Target/PowerPC/MCTargetDesc/CMakeFiles/LLVMPowerPCDesc.dir/PPCPredicates.cpp.o
388.085 [2084/1154/3315] Building RISCVGenSearchableTables.inc...
388.094 [2083/1154/3316] Building X86GenFoldTables.inc...
388.100 [2082/1154/3317] Building CXX object 
tools/clang/lib/Tooling/CMakeFiles/obj.clangTooling.dir/ArgumentsAdjusters.cpp.o
388.112 [2081/1154/3318] Building CXX object 
tools/clang/lib/Tooling/DependencyScanning/CMakeFiles/obj.clangDependencyScanning.dir/DependencyScanningService.cpp.o
388.122 [2080/1154/3319] Building CXX object 
tools/llvm-exegesis/lib/CMakeFiles/LLVMExegesis.dir/Error.cpp.o
388.133 [2079/1154/3320] Building CXX object 
lib/Target/Hexagon/MCTargetDesc/CMakeFiles/LLVMHexagonDesc.dir/HexagonMCAsmInfo.cpp.o
388.142 [2078/1154/3321] Building CXX object 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/ExpressionTraits.cpp.o
388.175 [2077/1154/3322] Building CXX object 
tools/clang/lib/Edit/CMakeFiles/obj.clangEdit.dir/Commit.cpp.o
FAILED: tools/clang/lib/Edit/CMakeFiles/obj.clangEdit.dir/Commit.cpp.o 
ccache 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/install/stage1/bin/clang++
 -DCLANG_EXPORTS -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS 
-D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS 
-D__STDC_LIMIT_MACROS 
-I/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/build/stage2/tools/clang/lib/Edit
 
-I/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/lib/Edit
 
-I/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/include
 
-I/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/build/stage2/tools/clang/include
 
-I/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/build/stage2/include
 
-I/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/llvm/include
 -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror 
-Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra 
-Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers 
-pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough 
-Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
-Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion 
-Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color 
-ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual 
-Wno-nested-anon-types -O3 -DNDEBUG -std=c++17  -fno-exceptions -funwind-tables 
-fno-rtti -UNDEBUG -MD -MT 
tools/clang/lib/Edit/CMakeFiles/obj.clangEdit.dir/Commit.cpp.o -MF 
tools/clang/lib/Edit/CMakeFiles/obj.clangEdit.dir/Commit.cpp.o.d -o 
tools/clang/lib/Edit/CMakeFiles/obj.clangEdit.dir/Commit.cpp.o -c 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/lib/Edit/Commit.cpp
In file included from 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/lib/Edit/Commit.cpp:15:
In file included from 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/include/clang/Lex/Lexer.h:16:
In file included from 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/include/clang/Basic/LangOptions.h:663:
/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/include/clang/Basic/LangOptions.def:350:1:
 error: assigning value of preferred signed enum type 'FPEvalMethodKind' to 
unsigned bit-field 'FPEvalMethod'; negative enumerators of enum 
'FPEvalMethodKind' will be converted to positive values 
[-Werror,-Wpreferred-type-bitfield-enum-conversion]
  350 | BENIGN_ENUM_LANGOPT(FPEvalMethod, FPEvalMethodKind, 2, 
FEM_UnsetOnCommandLine, "FP type used for floating point arithmetic")
  | ^
/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project

[clang-tools-extra] [clang-tools-extra] Use llvm::unique (NFC) (PR #136514)

2025-04-20 Thread Kazu Hirata via cfe-commits

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

None

>From 0682a632e741dde6737e488daf8fbc01d6b2a58b Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Sat, 19 Apr 2025 20:36:04 -0700
Subject: [PATCH] [clang-tools-extra] Use llvm::unique (NFC)

---
 clang-tools-extra/clang-doc/Representation.cpp |  4 ++--
 .../IncludeFixerContext.cpp| 18 +-
 .../clang-tidy/ClangTidyDiagnosticConsumer.cpp |  3 +--
 3 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/clang-tools-extra/clang-doc/Representation.cpp 
b/clang-tools-extra/clang-doc/Representation.cpp
index 54d2cb58ea2d9..9ab2f342d969a 100644
--- a/clang-tools-extra/clang-doc/Representation.cpp
+++ b/clang-tools-extra/clang-doc/Representation.cpp
@@ -200,7 +200,7 @@ void Info::mergeBase(Info &&Other) {
   std::move(Other.Description.begin(), Other.Description.end(),
 std::back_inserter(Description));
   llvm::sort(Description);
-  auto Last = std::unique(Description.begin(), Description.end());
+  auto Last = llvm::unique(Description);
   Description.erase(Last, Description.end());
 }
 
@@ -215,7 +215,7 @@ void SymbolInfo::merge(SymbolInfo &&Other) {
   // Unconditionally extend the list of locations, since we want all of them.
   std::move(Other.Loc.begin(), Other.Loc.end(), std::back_inserter(Loc));
   llvm::sort(Loc);
-  auto *Last = std::unique(Loc.begin(), Loc.end());
+  auto *Last = llvm::unique(Loc);
   Loc.erase(Last, Loc.end());
   mergeBase(std::move(Other));
 }
diff --git a/clang-tools-extra/clang-include-fixer/IncludeFixerContext.cpp 
b/clang-tools-extra/clang-include-fixer/IncludeFixerContext.cpp
index d7369b162dc10..4eac0617ed4a9 100644
--- a/clang-tools-extra/clang-include-fixer/IncludeFixerContext.cpp
+++ b/clang-tools-extra/clang-include-fixer/IncludeFixerContext.cpp
@@ -90,10 +90,10 @@ IncludeFixerContext::IncludeFixerContext(
   std::make_pair(B.Range.getOffset(), B.Range.getLength());
  });
   QuerySymbolInfos.erase(
-  std::unique(QuerySymbolInfos.begin(), QuerySymbolInfos.end(),
-  [](const QuerySymbolInfo &A, const QuerySymbolInfo &B) {
-return A.Range == B.Range;
-  }),
+  llvm::unique(QuerySymbolInfos,
+   [](const QuerySymbolInfo &A, const QuerySymbolInfo &B) {
+ return A.Range == B.Range;
+   }),
   QuerySymbolInfos.end());
   for (const auto &Symbol : MatchedSymbols) {
 HeaderInfos.push_back(
@@ -103,11 +103,11 @@ IncludeFixerContext::IncludeFixerContext(
  QuerySymbolInfos.front().ScopedQualifiers, Symbol)});
   }
   // Deduplicate header infos.
-  HeaderInfos.erase(std::unique(HeaderInfos.begin(), HeaderInfos.end(),
-[](const HeaderInfo &A, const HeaderInfo &B) {
-  return A.Header == B.Header &&
- A.QualifiedName == B.QualifiedName;
-}),
+  HeaderInfos.erase(llvm::unique(HeaderInfos,
+ [](const HeaderInfo &A, const HeaderInfo &B) {
+   return A.Header == B.Header &&
+  A.QualifiedName == B.QualifiedName;
+ }),
 HeaderInfos.end());
 }
 
diff --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
index 731141a545a48..b216970bfbd8c 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -754,8 +754,7 @@ std::vector 
ClangTidyDiagnosticConsumer::take() {
   finalizeLastError();
 
   llvm::stable_sort(Errors, LessClangTidyError());
-  Errors.erase(std::unique(Errors.begin(), Errors.end(), 
EqualClangTidyError()),
-   Errors.end());
+  Errors.erase(llvm::unique(Errors, EqualClangTidyError()), Errors.end());
   if (RemoveIncompatibleErrors)
 removeIncompatibleErrors();
   return std::move(Errors);

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


[clang-tools-extra] [clang-tools-extra] Use llvm::unique (NFC) (PR #136514)

2025-04-20 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Kazu Hirata (kazutakahirata)


Changes



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


3 Files Affected:

- (modified) clang-tools-extra/clang-doc/Representation.cpp (+2-2) 
- (modified) clang-tools-extra/clang-include-fixer/IncludeFixerContext.cpp 
(+9-9) 
- (modified) clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp 
(+1-2) 


``diff
diff --git a/clang-tools-extra/clang-doc/Representation.cpp 
b/clang-tools-extra/clang-doc/Representation.cpp
index 54d2cb58ea2d9..9ab2f342d969a 100644
--- a/clang-tools-extra/clang-doc/Representation.cpp
+++ b/clang-tools-extra/clang-doc/Representation.cpp
@@ -200,7 +200,7 @@ void Info::mergeBase(Info &&Other) {
   std::move(Other.Description.begin(), Other.Description.end(),
 std::back_inserter(Description));
   llvm::sort(Description);
-  auto Last = std::unique(Description.begin(), Description.end());
+  auto Last = llvm::unique(Description);
   Description.erase(Last, Description.end());
 }
 
@@ -215,7 +215,7 @@ void SymbolInfo::merge(SymbolInfo &&Other) {
   // Unconditionally extend the list of locations, since we want all of them.
   std::move(Other.Loc.begin(), Other.Loc.end(), std::back_inserter(Loc));
   llvm::sort(Loc);
-  auto *Last = std::unique(Loc.begin(), Loc.end());
+  auto *Last = llvm::unique(Loc);
   Loc.erase(Last, Loc.end());
   mergeBase(std::move(Other));
 }
diff --git a/clang-tools-extra/clang-include-fixer/IncludeFixerContext.cpp 
b/clang-tools-extra/clang-include-fixer/IncludeFixerContext.cpp
index d7369b162dc10..4eac0617ed4a9 100644
--- a/clang-tools-extra/clang-include-fixer/IncludeFixerContext.cpp
+++ b/clang-tools-extra/clang-include-fixer/IncludeFixerContext.cpp
@@ -90,10 +90,10 @@ IncludeFixerContext::IncludeFixerContext(
   std::make_pair(B.Range.getOffset(), B.Range.getLength());
  });
   QuerySymbolInfos.erase(
-  std::unique(QuerySymbolInfos.begin(), QuerySymbolInfos.end(),
-  [](const QuerySymbolInfo &A, const QuerySymbolInfo &B) {
-return A.Range == B.Range;
-  }),
+  llvm::unique(QuerySymbolInfos,
+   [](const QuerySymbolInfo &A, const QuerySymbolInfo &B) {
+ return A.Range == B.Range;
+   }),
   QuerySymbolInfos.end());
   for (const auto &Symbol : MatchedSymbols) {
 HeaderInfos.push_back(
@@ -103,11 +103,11 @@ IncludeFixerContext::IncludeFixerContext(
  QuerySymbolInfos.front().ScopedQualifiers, Symbol)});
   }
   // Deduplicate header infos.
-  HeaderInfos.erase(std::unique(HeaderInfos.begin(), HeaderInfos.end(),
-[](const HeaderInfo &A, const HeaderInfo &B) {
-  return A.Header == B.Header &&
- A.QualifiedName == B.QualifiedName;
-}),
+  HeaderInfos.erase(llvm::unique(HeaderInfos,
+ [](const HeaderInfo &A, const HeaderInfo &B) {
+   return A.Header == B.Header &&
+  A.QualifiedName == B.QualifiedName;
+ }),
 HeaderInfos.end());
 }
 
diff --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
index 731141a545a48..b216970bfbd8c 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -754,8 +754,7 @@ std::vector 
ClangTidyDiagnosticConsumer::take() {
   finalizeLastError();
 
   llvm::stable_sort(Errors, LessClangTidyError());
-  Errors.erase(std::unique(Errors.begin(), Errors.end(), 
EqualClangTidyError()),
-   Errors.end());
+  Errors.erase(llvm::unique(Errors, EqualClangTidyError()), Errors.end());
   if (RemoveIncompatibleErrors)
 removeIncompatibleErrors();
   return std::move(Errors);

``




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


[clang] Ensure bit-fields storing FPEvalMethodKind are wide enough to do so (PR #136515)

2025-04-20 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Oliver Hunt (ojhunt)


Changes

After landing #116760 we hit build failures due to existing fields 
storing FPEvalMethodKind not being wide enough.

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


2 Files Affected:

- (modified) clang/include/clang/Basic/FPOptions.def (+1-1) 
- (modified) clang/include/clang/Basic/LangOptions.def (+1-1) 


``diff
diff --git a/clang/include/clang/Basic/FPOptions.def 
b/clang/include/clang/Basic/FPOptions.def
index 90428c3c73c8b..85986b4ff0b9c 100644
--- a/clang/include/clang/Basic/FPOptions.def
+++ b/clang/include/clang/Basic/FPOptions.def
@@ -24,7 +24,7 @@ OPTION(NoHonorInfs, bool, 1, NoHonorNaNs)
 OPTION(NoSignedZero, bool, 1, NoHonorInfs)
 OPTION(AllowReciprocal, bool, 1, NoSignedZero)
 OPTION(AllowApproxFunc, bool, 1, AllowReciprocal)
-OPTION(FPEvalMethod, LangOptions::FPEvalMethodKind, 2, AllowApproxFunc)
+OPTION(FPEvalMethod, LangOptions::FPEvalMethodKind, 3, AllowApproxFunc)
 OPTION(Float16ExcessPrecision, LangOptions::ExcessPrecisionKind, 2, 
FPEvalMethod)
 OPTION(BFloat16ExcessPrecision, LangOptions::ExcessPrecisionKind, 2, 
Float16ExcessPrecision)
 OPTION(MathErrno, bool, 1, BFloat16ExcessPrecision)
diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 930c1c06d1a76..85ca523c44157 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -347,7 +347,7 @@ BENIGN_ENUM_LANGOPT(DefaultFPContractMode, FPModeKind, 2, 
FPM_Off, "FP contracti
 COMPATIBLE_LANGOPT(ExpStrictFP, 1, false, "Enable experimental strict floating 
point")
 BENIGN_LANGOPT(RoundingMath, 1, false, "Do not assume default floating-point 
rounding behavior")
 BENIGN_ENUM_LANGOPT(FPExceptionMode, FPExceptionModeKind, 2, FPE_Default, "FP 
Exception Behavior Mode type")
-BENIGN_ENUM_LANGOPT(FPEvalMethod, FPEvalMethodKind, 2, FEM_UnsetOnCommandLine, 
"FP type used for floating point arithmetic")
+BENIGN_ENUM_LANGOPT(FPEvalMethod, FPEvalMethodKind, 3, FEM_UnsetOnCommandLine, 
"FP type used for floating point arithmetic")
 ENUM_LANGOPT(Float16ExcessPrecision, ExcessPrecisionKind, 2, FPP_Standard, 
"Intermediate truncation behavior for Float16 arithmetic")
 ENUM_LANGOPT(BFloat16ExcessPrecision, ExcessPrecisionKind, 2, FPP_Standard, 
"Intermediate truncation behavior for BFloat16 arithmetic")
 LANGOPT(NoBitFieldTypeAlign , 1, 0, "bit-field type alignment")

``




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


[clang] Ensure bit-fields storing FPEvalMethodKind are wide enough to do so (PR #136515)

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

https://github.com/ojhunt created 
https://github.com/llvm/llvm-project/pull/136515

After landing #116760 we hit build failures due to existing fields storing 
FPEvalMethodKind not being wide enough.

>From 535e11400ea11461fa8e0cc98f9b481b045805c4 Mon Sep 17 00:00:00 2001
From: Oliver Hunt 
Date: Sun, 20 Apr 2025 15:29:39 -0700
Subject: [PATCH] Ensure bit-fields storing FPEvalMethodKind are wide enough to
 do so

---
 clang/include/clang/Basic/FPOptions.def   | 2 +-
 clang/include/clang/Basic/LangOptions.def | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/FPOptions.def 
b/clang/include/clang/Basic/FPOptions.def
index 90428c3c73c8b..85986b4ff0b9c 100644
--- a/clang/include/clang/Basic/FPOptions.def
+++ b/clang/include/clang/Basic/FPOptions.def
@@ -24,7 +24,7 @@ OPTION(NoHonorInfs, bool, 1, NoHonorNaNs)
 OPTION(NoSignedZero, bool, 1, NoHonorInfs)
 OPTION(AllowReciprocal, bool, 1, NoSignedZero)
 OPTION(AllowApproxFunc, bool, 1, AllowReciprocal)
-OPTION(FPEvalMethod, LangOptions::FPEvalMethodKind, 2, AllowApproxFunc)
+OPTION(FPEvalMethod, LangOptions::FPEvalMethodKind, 3, AllowApproxFunc)
 OPTION(Float16ExcessPrecision, LangOptions::ExcessPrecisionKind, 2, 
FPEvalMethod)
 OPTION(BFloat16ExcessPrecision, LangOptions::ExcessPrecisionKind, 2, 
Float16ExcessPrecision)
 OPTION(MathErrno, bool, 1, BFloat16ExcessPrecision)
diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 930c1c06d1a76..85ca523c44157 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -347,7 +347,7 @@ BENIGN_ENUM_LANGOPT(DefaultFPContractMode, FPModeKind, 2, 
FPM_Off, "FP contracti
 COMPATIBLE_LANGOPT(ExpStrictFP, 1, false, "Enable experimental strict floating 
point")
 BENIGN_LANGOPT(RoundingMath, 1, false, "Do not assume default floating-point 
rounding behavior")
 BENIGN_ENUM_LANGOPT(FPExceptionMode, FPExceptionModeKind, 2, FPE_Default, "FP 
Exception Behavior Mode type")
-BENIGN_ENUM_LANGOPT(FPEvalMethod, FPEvalMethodKind, 2, FEM_UnsetOnCommandLine, 
"FP type used for floating point arithmetic")
+BENIGN_ENUM_LANGOPT(FPEvalMethod, FPEvalMethodKind, 3, FEM_UnsetOnCommandLine, 
"FP type used for floating point arithmetic")
 ENUM_LANGOPT(Float16ExcessPrecision, ExcessPrecisionKind, 2, FPP_Standard, 
"Intermediate truncation behavior for Float16 arithmetic")
 ENUM_LANGOPT(BFloat16ExcessPrecision, ExcessPrecisionKind, 2, FPP_Standard, 
"Intermediate truncation behavior for BFloat16 arithmetic")
 LANGOPT(NoBitFieldTypeAlign , 1, 0, "bit-field type alignment")

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


[clang] [llvm] [clang][OpenMP][SPIR-V] Fix addrspace of global constants (PR #134399)

2025-04-20 Thread Shangwu Yao via cfe-commits

ShangwuYao wrote:

This test reproduces the issue above:

```
// RUN: %clang_cc1 -fcuda-is-device -triple spirv32 -o - -emit-llvm -x cuda %s  
| FileCheck %s
// RUN: %clang_cc1 -fcuda-is-device -triple spirv64 -o - -emit-llvm -x cuda %s  
| FileCheck %s

// CHECK: @.str = private unnamed_addr addrspace(4) constant [13 x i8] c"Hello 
World\0A\00", align 1 

extern "C" __attribute__((device)) int printf(const char* format, ...);

__attribute__((global)) void printf_kernel() {
  printf("Hello World\n");
}
```

Could you also add the test case as test/CodeGenCUDASPIRV/printf.cu or 
something? Thanks!!


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


[clang] [RawPtrRefMemberChecker] Member varible checker should allow T* in smart pointer classes (PR #136503)

2025-04-20 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa updated 
https://github.com/llvm/llvm-project/pull/136503

>From 01a0a5544010a605e828a28c04ba56d37658c6b0 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Sun, 20 Apr 2025 11:58:11 -0700
Subject: [PATCH] [RawPtrRefMemberChecker] Member variable checker should allow
 T* in smart pointer classes

This PR fixes member variable checker to allow the usage of T* in smart pointer 
classes.
e.g. alpha.webkit.NoUncheckedPtrMemberChecker should allow T* to appear within 
RefPtr.
---
 .../Checkers/WebKit/PtrTypesSemantics.cpp   |  7 +++
 .../Checkers/WebKit/PtrTypesSemantics.h |  4 
 .../Checkers/WebKit/RawPtrRefMemberChecker.cpp  | 17 ++---
 .../Checkers/WebKit/unchecked-members.cpp   |  9 +
 .../Checkers/WebKit/uncounted-members.cpp   | 15 ---
 5 files changed, 34 insertions(+), 18 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 811888e119449..ba0c7fd77b410 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -436,6 +436,13 @@ bool isRetainPtr(const CXXRecordDecl *R) {
   return false;
 }
 
+bool isSmartPtr(const CXXRecordDecl *R) {
+  assert(R);
+  if (auto *TmplR = R->getTemplateInstantiationPattern())
+return isSmartPtrClass(safeGetName(TmplR));
+  return false;
+}
+
 bool isPtrConversion(const FunctionDecl *F) {
   assert(F);
   if (isCtorOfRefCounted(F))
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
index 97c9d0510e67d..f9fcfe9878d54 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
@@ -58,6 +58,10 @@ bool isCheckedPtr(const clang::CXXRecordDecl *Class);
 /// \returns true if \p Class is a RetainPtr, false if not.
 bool isRetainPtr(const clang::CXXRecordDecl *Class);
 
+/// \returns true if \p Class is a smart pointer (RefPtr, WeakPtr, etc...),
+/// false if not.
+bool isSmartPtr(const clang::CXXRecordDecl *Class);
+
 /// \returns true if \p Class is ref-countable AND not ref-counted, false if
 /// not, std::nullopt if inconclusive.
 std::optional isUncounted(const clang::QualType T);
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp
index a003fc200727c..10b9749319a57 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp
@@ -41,7 +41,6 @@ class RawPtrRefMemberChecker
   virtual std::optional
   isPtrCompatible(const clang::QualType,
   const clang::CXXRecordDecl *R) const = 0;
-  virtual bool isPtrCls(const clang::CXXRecordDecl *) const = 0;
   virtual const char *typeName() const = 0;
   virtual const char *invariant() const = 0;
 
@@ -205,8 +204,8 @@ class RawPtrRefMemberChecker
 // Ref-counted smartpointers actually have raw-pointer to uncounted type as
 // a member but we trust them to handle it correctly.
 auto CXXRD = llvm::dyn_cast_or_null(RD);
-if (CXXRD)
-  return isPtrCls(CXXRD);
+if (CXXRD && isSmartPtr(CXXRD))
+  return true;
 
 return false;
   }
@@ -270,10 +269,6 @@ class NoUncountedMemberChecker final : public 
RawPtrRefMemberChecker {
 return R ? isRefCountable(R) : std::nullopt;
   }
 
-  bool isPtrCls(const clang::CXXRecordDecl *R) const final {
-return isRefCounted(R);
-  }
-
   const char *typeName() const final { return "ref-countable type"; }
 
   const char *invariant() const final {
@@ -293,10 +288,6 @@ class NoUncheckedPtrMemberChecker final : public 
RawPtrRefMemberChecker {
 return R ? isCheckedPtrCapable(R) : std::nullopt;
   }
 
-  bool isPtrCls(const clang::CXXRecordDecl *R) const final {
-return isCheckedPtr(R);
-  }
-
   const char *typeName() const final { return "CheckedPtr capable type"; }
 
   const char *invariant() const final {
@@ -319,10 +310,6 @@ class NoUnretainedMemberChecker final : public 
RawPtrRefMemberChecker {
 return RTC->isUnretained(QT);
   }
 
-  bool isPtrCls(const clang::CXXRecordDecl *R) const final {
-return isRetainPtr(R);
-  }
-
   const char *typeName() const final { return "retainable type"; }
 
   const char *invariant() const final {
diff --git a/clang/test/Analysis/Checkers/WebKit/unchecked-members.cpp 
b/clang/test/Analysis/Checkers/WebKit/unchecked-members.cpp
index 0189b0cd50fcc..048ffbffcdefb 100644
--- a/clang/test/Analysis/Checkers/WebKit/unchecked-members.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/unchecked-members.cpp
@@ -50,3 +50,12 @@ namespace ignore_unions {
   void forceTmplToInstantiate(FooTmpl) { }
 
 } // namespace ignore_unions
+
+namespace checked_ptr_ref_ptr_capable {
+
+  RefCoun

[clang-tools-extra] [clangd] Improve `BlockEnd` inlayhint presentation (PR #136106)

2025-04-20 Thread via cfe-commits

https://github.com/MythreyaK updated 
https://github.com/llvm/llvm-project/pull/136106

>From a0e3a33eda624bbebd436d6ac97a18348be39e7c Mon Sep 17 00:00:00 2001
From: daiyousei-qz 
Date: Tue, 14 Nov 2023 20:42:10 -0800
Subject: [PATCH 1/5] Improve BlockEnd presentation including: 1. Explicitly
 state a function call 2. Print literal nullptr 3. Escape for abbreviated
 string 4. Adjust min line limit to 10

---
 clang-tools-extra/clangd/InlayHints.cpp | 19 +--
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/clang-tools-extra/clangd/InlayHints.cpp 
b/clang-tools-extra/clangd/InlayHints.cpp
index 1b1bcf78c9855..b1e3bd97d4fd9 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -112,7 +112,9 @@ std::string summarizeExpr(const Expr *E) {
   return getSimpleName(*E->getFoundDecl()).str();
 }
 std::string VisitCallExpr(const CallExpr *E) {
-  return Visit(E->getCallee());
+  std::string Result = Visit(E->getCallee());
+  Result += E->getNumArgs() == 0 ? "()" : "(...)";
+  return Result;
 }
 std::string
 VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *E) {
@@ -147,6 +149,9 @@ std::string summarizeExpr(const Expr *E) {
 }
 
 // Literals are just printed
+std::string VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E) {
+  return "nullptr";
+}
 std::string VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E) {
   return E->getValue() ? "true" : "false";
 }
@@ -165,12 +170,14 @@ std::string summarizeExpr(const Expr *E) {
   std::string Result = "\"";
   if (E->containsNonAscii()) {
 Result += "...";
-  } else if (E->getLength() > 10) {
-Result += E->getString().take_front(7);
-Result += "...";
   } else {
 llvm::raw_string_ostream OS(Result);
-llvm::printEscapedString(E->getString(), OS);
+if (E->getLength() > 10) {
+  llvm::printEscapedString(E->getString().take_front(7), OS);
+  Result += "...";
+} else {
+  llvm::printEscapedString(E->getString(), OS);
+}
   }
   Result.push_back('"');
   return Result;
@@ -1120,7 +1127,7 @@ class InlayHintVisitor : public 
RecursiveASTVisitor {
   // Otherwise, the hint shouldn't be shown.
   std::optional computeBlockEndHintRange(SourceRange BraceRange,
 StringRef OptionalPunctuation) 
{
-constexpr unsigned HintMinLineLimit = 2;
+constexpr unsigned HintMinLineLimit = 10;
 
 auto &SM = AST.getSourceManager();
 auto [BlockBeginFileId, BlockBeginOffset] =

>From 729be505b882f34a29b2e9fc2c1b1adfaf31cc42 Mon Sep 17 00:00:00 2001
From: Mythreya 
Date: Thu, 17 Apr 2025 01:28:53 -0700
Subject: [PATCH 2/5] Add `InlayHintOptions`

---
 clang-tools-extra/clangd/InlayHints.cpp | 16 ++--
 clang-tools-extra/clangd/InlayHints.h   |  8 +++-
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/clang-tools-extra/clangd/InlayHints.cpp 
b/clang-tools-extra/clangd/InlayHints.cpp
index b1e3bd97d4fd9..298e19d7fe41d 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -415,12 +415,14 @@ struct Callee {
 class InlayHintVisitor : public RecursiveASTVisitor {
 public:
   InlayHintVisitor(std::vector &Results, ParsedAST &AST,
-   const Config &Cfg, std::optional RestrictRange)
+   const Config &Cfg, std::optional RestrictRange,
+   InlayHintOptions HintOptions)
   : Results(Results), AST(AST.getASTContext()), Tokens(AST.getTokens()),
 Cfg(Cfg), RestrictRange(std::move(RestrictRange)),
 MainFileID(AST.getSourceManager().getMainFileID()),
 Resolver(AST.getHeuristicResolver()),
-TypeHintPolicy(this->AST.getPrintingPolicy()) {
+TypeHintPolicy(this->AST.getPrintingPolicy()),
+HintOptions(HintOptions) {
 bool Invalid = false;
 llvm::StringRef Buf =
 AST.getSourceManager().getBufferData(MainFileID, &Invalid);
@@ -1127,7 +1129,6 @@ class InlayHintVisitor : public 
RecursiveASTVisitor {
   // Otherwise, the hint shouldn't be shown.
   std::optional computeBlockEndHintRange(SourceRange BraceRange,
 StringRef OptionalPunctuation) 
{
-constexpr unsigned HintMinLineLimit = 10;
 
 auto &SM = AST.getSourceManager();
 auto [BlockBeginFileId, BlockBeginOffset] =
@@ -1155,7 +1156,7 @@ class InlayHintVisitor : public 
RecursiveASTVisitor {
 auto RBraceLine = SM.getLineNumber(RBraceFileId, RBraceOffset);
 
 // Don't show hint on trivial blocks like `class X {};`
-if (BlockBeginLine + HintMinLineLimit - 1 > RBraceLine)
+if (BlockBeginLine + HintOptions.HintMinLineLimit - 1 > RBraceLine)
   return std::nullopt;
 
 // This is what we attach the hint to, usually "}" or "};".
@@ -1185,17 +1186,20 @@ class I

[clang-tools-extra] [clangd] Improve `BlockEnd` inlayhint presentation (PR #136106)

2025-04-20 Thread via cfe-commits

llvmbot wrote:




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

Author: Mythreya (MythreyaK)


Changes

Previous iteration of this PR was 
[here](https://github.com/llvm/llvm-project/pull/72345). I retained their first 
commit as-is, rebased it, and added my changes based on the comments in the 
thread 
[here](https://github.com/llvm/llvm-project/pull/72345#issuecomment-1826997798).

[Related issue](https://github.com/clangd/clangd/issues/1807). 

I am working on adding tests, but wanted to get an initial review to make sure 
I am on the right track. 

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


3 Files Affected:

- (modified) clang-tools-extra/clangd/InlayHints.cpp (+22-11) 
- (modified) clang-tools-extra/clangd/InlayHints.h (+7-1) 
- (modified) clang-tools-extra/clangd/unittests/InlayHintTests.cpp (+99-31) 


``diff
diff --git a/clang-tools-extra/clangd/InlayHints.cpp 
b/clang-tools-extra/clangd/InlayHints.cpp
index 40a824618f782..bdab2b8a9f377 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -112,7 +112,9 @@ std::string summarizeExpr(const Expr *E) {
   return getSimpleName(*E->getFoundDecl()).str();
 }
 std::string VisitCallExpr(const CallExpr *E) {
-  return Visit(E->getCallee());
+  std::string Result = Visit(E->getCallee());
+  Result += E->getNumArgs() == 0 ? "()" : "(...)";
+  return Result;
 }
 std::string
 VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *E) {
@@ -147,6 +149,9 @@ std::string summarizeExpr(const Expr *E) {
 }
 
 // Literals are just printed
+std::string VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E) {
+  return "nullptr";
+}
 std::string VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E) {
   return E->getValue() ? "true" : "false";
 }
@@ -165,12 +170,14 @@ std::string summarizeExpr(const Expr *E) {
   std::string Result = "\"";
   if (E->containsNonAscii()) {
 Result += "...";
-  } else if (E->getLength() > 10) {
-Result += E->getString().take_front(7);
-Result += "...";
   } else {
 llvm::raw_string_ostream OS(Result);
-llvm::printEscapedString(E->getString(), OS);
+if (E->getLength() > 10) {
+  llvm::printEscapedString(E->getString().take_front(7), OS);
+  Result += "...";
+} else {
+  llvm::printEscapedString(E->getString(), OS);
+}
   }
   Result.push_back('"');
   return Result;
@@ -408,12 +415,14 @@ struct Callee {
 class InlayHintVisitor : public RecursiveASTVisitor {
 public:
   InlayHintVisitor(std::vector &Results, ParsedAST &AST,
-   const Config &Cfg, std::optional RestrictRange)
+   const Config &Cfg, std::optional RestrictRange,
+   InlayHintOptions HintOptions)
   : Results(Results), AST(AST.getASTContext()), Tokens(AST.getTokens()),
 Cfg(Cfg), RestrictRange(std::move(RestrictRange)),
 MainFileID(AST.getSourceManager().getMainFileID()),
 Resolver(AST.getHeuristicResolver()),
-TypeHintPolicy(this->AST.getPrintingPolicy()) {
+TypeHintPolicy(this->AST.getPrintingPolicy()),
+HintOptions(HintOptions) {
 bool Invalid = false;
 llvm::StringRef Buf =
 AST.getSourceManager().getBufferData(MainFileID, &Invalid);
@@ -1120,7 +1129,6 @@ class InlayHintVisitor : public 
RecursiveASTVisitor {
   // Otherwise, the hint shouldn't be shown.
   std::optional computeBlockEndHintRange(SourceRange BraceRange,
 StringRef OptionalPunctuation) 
{
-constexpr unsigned HintMinLineLimit = 2;
 
 auto &SM = AST.getSourceManager();
 auto [BlockBeginFileId, BlockBeginOffset] =
@@ -1148,7 +1156,7 @@ class InlayHintVisitor : public 
RecursiveASTVisitor {
 auto RBraceLine = SM.getLineNumber(RBraceFileId, RBraceOffset);
 
 // Don't show hint on trivial blocks like `class X {};`
-if (BlockBeginLine + HintMinLineLimit - 1 > RBraceLine)
+if (BlockBeginLine + HintOptions.HintMinLineLimit - 1 > RBraceLine)
   return std::nullopt;
 
 // This is what we attach the hint to, usually "}" or "};".
@@ -1178,17 +1186,20 @@ class InlayHintVisitor : public 
RecursiveASTVisitor {
   StringRef MainFileBuf;
   const HeuristicResolver *Resolver;
   PrintingPolicy TypeHintPolicy;
+  InlayHintOptions HintOptions;
 };
 
 } // namespace
 
 std::vector inlayHints(ParsedAST &AST,
-  std::optional RestrictRange) {
+  std::optional RestrictRange,
+  InlayHintOptions HintOptions) {
   std::vector Results;
   const auto &Cfg = Config::current();
   if (!Cfg.InlayHints.Enabled)
 return Results;
-  InlayHintVisitor Visitor(Results, AST, Cfg, std::move(RestrictRange));
+  InlayHintVisitor Visitor(Results, AST, Cfg, std::move(RestrictRange)

[clang-tools-extra] [clangd] Improve `BlockEnd` inlayhint presentation (PR #136106)

2025-04-20 Thread via cfe-commits

https://github.com/MythreyaK updated 
https://github.com/llvm/llvm-project/pull/136106

>From 64410e0c5bbdc3f631e2efecef475768d48ef233 Mon Sep 17 00:00:00 2001
From: daiyousei-qz 
Date: Tue, 14 Nov 2023 20:42:10 -0800
Subject: [PATCH 1/4] Improve BlockEnd presentation including: 1. Explicitly
 state a function call 2. Print literal nullptr 3. Escape for abbreviated
 string 4. Adjust min line limit to 10

---
 clang-tools-extra/clangd/InlayHints.cpp | 19 +--
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/clang-tools-extra/clangd/InlayHints.cpp 
b/clang-tools-extra/clangd/InlayHints.cpp
index 40a824618f782..a1bc9956ec628 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -112,7 +112,9 @@ std::string summarizeExpr(const Expr *E) {
   return getSimpleName(*E->getFoundDecl()).str();
 }
 std::string VisitCallExpr(const CallExpr *E) {
-  return Visit(E->getCallee());
+  std::string Result = Visit(E->getCallee());
+  Result += E->getNumArgs() == 0 ? "()" : "(...)";
+  return Result;
 }
 std::string
 VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *E) {
@@ -147,6 +149,9 @@ std::string summarizeExpr(const Expr *E) {
 }
 
 // Literals are just printed
+std::string VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E) {
+  return "nullptr";
+}
 std::string VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E) {
   return E->getValue() ? "true" : "false";
 }
@@ -165,12 +170,14 @@ std::string summarizeExpr(const Expr *E) {
   std::string Result = "\"";
   if (E->containsNonAscii()) {
 Result += "...";
-  } else if (E->getLength() > 10) {
-Result += E->getString().take_front(7);
-Result += "...";
   } else {
 llvm::raw_string_ostream OS(Result);
-llvm::printEscapedString(E->getString(), OS);
+if (E->getLength() > 10) {
+  llvm::printEscapedString(E->getString().take_front(7), OS);
+  Result += "...";
+} else {
+  llvm::printEscapedString(E->getString(), OS);
+}
   }
   Result.push_back('"');
   return Result;
@@ -1120,7 +1127,7 @@ class InlayHintVisitor : public 
RecursiveASTVisitor {
   // Otherwise, the hint shouldn't be shown.
   std::optional computeBlockEndHintRange(SourceRange BraceRange,
 StringRef OptionalPunctuation) 
{
-constexpr unsigned HintMinLineLimit = 2;
+constexpr unsigned HintMinLineLimit = 10;
 
 auto &SM = AST.getSourceManager();
 auto [BlockBeginFileId, BlockBeginOffset] =

>From fe79c934873f5df8c13ef130adf96a05cc48364f Mon Sep 17 00:00:00 2001
From: Mythreya 
Date: Thu, 17 Apr 2025 01:28:53 -0700
Subject: [PATCH 2/4] Add `InlayHintOptions`

---
 clang-tools-extra/clangd/InlayHints.cpp | 16 ++--
 clang-tools-extra/clangd/InlayHints.h   |  8 +++-
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/clang-tools-extra/clangd/InlayHints.cpp 
b/clang-tools-extra/clangd/InlayHints.cpp
index a1bc9956ec628..bdab2b8a9f377 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -415,12 +415,14 @@ struct Callee {
 class InlayHintVisitor : public RecursiveASTVisitor {
 public:
   InlayHintVisitor(std::vector &Results, ParsedAST &AST,
-   const Config &Cfg, std::optional RestrictRange)
+   const Config &Cfg, std::optional RestrictRange,
+   InlayHintOptions HintOptions)
   : Results(Results), AST(AST.getASTContext()), Tokens(AST.getTokens()),
 Cfg(Cfg), RestrictRange(std::move(RestrictRange)),
 MainFileID(AST.getSourceManager().getMainFileID()),
 Resolver(AST.getHeuristicResolver()),
-TypeHintPolicy(this->AST.getPrintingPolicy()) {
+TypeHintPolicy(this->AST.getPrintingPolicy()),
+HintOptions(HintOptions) {
 bool Invalid = false;
 llvm::StringRef Buf =
 AST.getSourceManager().getBufferData(MainFileID, &Invalid);
@@ -1127,7 +1129,6 @@ class InlayHintVisitor : public 
RecursiveASTVisitor {
   // Otherwise, the hint shouldn't be shown.
   std::optional computeBlockEndHintRange(SourceRange BraceRange,
 StringRef OptionalPunctuation) 
{
-constexpr unsigned HintMinLineLimit = 10;
 
 auto &SM = AST.getSourceManager();
 auto [BlockBeginFileId, BlockBeginOffset] =
@@ -1155,7 +1156,7 @@ class InlayHintVisitor : public 
RecursiveASTVisitor {
 auto RBraceLine = SM.getLineNumber(RBraceFileId, RBraceOffset);
 
 // Don't show hint on trivial blocks like `class X {};`
-if (BlockBeginLine + HintMinLineLimit - 1 > RBraceLine)
+if (BlockBeginLine + HintOptions.HintMinLineLimit - 1 > RBraceLine)
   return std::nullopt;
 
 // This is what we attach the hint to, usually "}" or "};".
@@ -1185,17 +1186,20 @@ class I

[clang-tools-extra] [clangd] Improve `BlockEnd` inlayhint presentation (PR #136106)

2025-04-20 Thread via cfe-commits

https://github.com/MythreyaK updated 
https://github.com/llvm/llvm-project/pull/136106

>From a0e3a33eda624bbebd436d6ac97a18348be39e7c Mon Sep 17 00:00:00 2001
From: daiyousei-qz 
Date: Tue, 14 Nov 2023 20:42:10 -0800
Subject: [PATCH 1/4] Improve BlockEnd presentation including: 1. Explicitly
 state a function call 2. Print literal nullptr 3. Escape for abbreviated
 string 4. Adjust min line limit to 10

---
 clang-tools-extra/clangd/InlayHints.cpp | 19 +--
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/clang-tools-extra/clangd/InlayHints.cpp 
b/clang-tools-extra/clangd/InlayHints.cpp
index 1b1bcf78c9855..b1e3bd97d4fd9 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -112,7 +112,9 @@ std::string summarizeExpr(const Expr *E) {
   return getSimpleName(*E->getFoundDecl()).str();
 }
 std::string VisitCallExpr(const CallExpr *E) {
-  return Visit(E->getCallee());
+  std::string Result = Visit(E->getCallee());
+  Result += E->getNumArgs() == 0 ? "()" : "(...)";
+  return Result;
 }
 std::string
 VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *E) {
@@ -147,6 +149,9 @@ std::string summarizeExpr(const Expr *E) {
 }
 
 // Literals are just printed
+std::string VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E) {
+  return "nullptr";
+}
 std::string VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E) {
   return E->getValue() ? "true" : "false";
 }
@@ -165,12 +170,14 @@ std::string summarizeExpr(const Expr *E) {
   std::string Result = "\"";
   if (E->containsNonAscii()) {
 Result += "...";
-  } else if (E->getLength() > 10) {
-Result += E->getString().take_front(7);
-Result += "...";
   } else {
 llvm::raw_string_ostream OS(Result);
-llvm::printEscapedString(E->getString(), OS);
+if (E->getLength() > 10) {
+  llvm::printEscapedString(E->getString().take_front(7), OS);
+  Result += "...";
+} else {
+  llvm::printEscapedString(E->getString(), OS);
+}
   }
   Result.push_back('"');
   return Result;
@@ -1120,7 +1127,7 @@ class InlayHintVisitor : public 
RecursiveASTVisitor {
   // Otherwise, the hint shouldn't be shown.
   std::optional computeBlockEndHintRange(SourceRange BraceRange,
 StringRef OptionalPunctuation) 
{
-constexpr unsigned HintMinLineLimit = 2;
+constexpr unsigned HintMinLineLimit = 10;
 
 auto &SM = AST.getSourceManager();
 auto [BlockBeginFileId, BlockBeginOffset] =

>From 729be505b882f34a29b2e9fc2c1b1adfaf31cc42 Mon Sep 17 00:00:00 2001
From: Mythreya 
Date: Thu, 17 Apr 2025 01:28:53 -0700
Subject: [PATCH 2/4] Add `InlayHintOptions`

---
 clang-tools-extra/clangd/InlayHints.cpp | 16 ++--
 clang-tools-extra/clangd/InlayHints.h   |  8 +++-
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/clang-tools-extra/clangd/InlayHints.cpp 
b/clang-tools-extra/clangd/InlayHints.cpp
index b1e3bd97d4fd9..298e19d7fe41d 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -415,12 +415,14 @@ struct Callee {
 class InlayHintVisitor : public RecursiveASTVisitor {
 public:
   InlayHintVisitor(std::vector &Results, ParsedAST &AST,
-   const Config &Cfg, std::optional RestrictRange)
+   const Config &Cfg, std::optional RestrictRange,
+   InlayHintOptions HintOptions)
   : Results(Results), AST(AST.getASTContext()), Tokens(AST.getTokens()),
 Cfg(Cfg), RestrictRange(std::move(RestrictRange)),
 MainFileID(AST.getSourceManager().getMainFileID()),
 Resolver(AST.getHeuristicResolver()),
-TypeHintPolicy(this->AST.getPrintingPolicy()) {
+TypeHintPolicy(this->AST.getPrintingPolicy()),
+HintOptions(HintOptions) {
 bool Invalid = false;
 llvm::StringRef Buf =
 AST.getSourceManager().getBufferData(MainFileID, &Invalid);
@@ -1127,7 +1129,6 @@ class InlayHintVisitor : public 
RecursiveASTVisitor {
   // Otherwise, the hint shouldn't be shown.
   std::optional computeBlockEndHintRange(SourceRange BraceRange,
 StringRef OptionalPunctuation) 
{
-constexpr unsigned HintMinLineLimit = 10;
 
 auto &SM = AST.getSourceManager();
 auto [BlockBeginFileId, BlockBeginOffset] =
@@ -1155,7 +1156,7 @@ class InlayHintVisitor : public 
RecursiveASTVisitor {
 auto RBraceLine = SM.getLineNumber(RBraceFileId, RBraceOffset);
 
 // Don't show hint on trivial blocks like `class X {};`
-if (BlockBeginLine + HintMinLineLimit - 1 > RBraceLine)
+if (BlockBeginLine + HintOptions.HintMinLineLimit - 1 > RBraceLine)
   return std::nullopt;
 
 // This is what we attach the hint to, usually "}" or "};".
@@ -1185,17 +1186,20 @@ class I

[clang] [RawPtrRefMemberChecker] Member variable checker should allow T* in smart pointer classes (PR #136503)

2025-04-20 Thread Ryosuke Niwa via cfe-commits

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


[clang-tools-extra] [clangd] Improve `BlockEnd` inlayhint presentation (PR #136106)

2025-04-20 Thread via cfe-commits

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


[clang-tools-extra] be48727 - [clang-tools-extra] Use llvm::unique (NFC) (#136514)

2025-04-20 Thread via cfe-commits

Author: Kazu Hirata
Date: 2025-04-20T18:30:05-07:00
New Revision: be48727b95bf9075e4290cc8938ab87db8b7410c

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

LOG: [clang-tools-extra] Use llvm::unique (NFC) (#136514)

Added: 


Modified: 
clang-tools-extra/clang-doc/Representation.cpp
clang-tools-extra/clang-include-fixer/IncludeFixerContext.cpp
clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-doc/Representation.cpp 
b/clang-tools-extra/clang-doc/Representation.cpp
index 54d2cb58ea2d9..9ab2f342d969a 100644
--- a/clang-tools-extra/clang-doc/Representation.cpp
+++ b/clang-tools-extra/clang-doc/Representation.cpp
@@ -200,7 +200,7 @@ void Info::mergeBase(Info &&Other) {
   std::move(Other.Description.begin(), Other.Description.end(),
 std::back_inserter(Description));
   llvm::sort(Description);
-  auto Last = std::unique(Description.begin(), Description.end());
+  auto Last = llvm::unique(Description);
   Description.erase(Last, Description.end());
 }
 
@@ -215,7 +215,7 @@ void SymbolInfo::merge(SymbolInfo &&Other) {
   // Unconditionally extend the list of locations, since we want all of them.
   std::move(Other.Loc.begin(), Other.Loc.end(), std::back_inserter(Loc));
   llvm::sort(Loc);
-  auto *Last = std::unique(Loc.begin(), Loc.end());
+  auto *Last = llvm::unique(Loc);
   Loc.erase(Last, Loc.end());
   mergeBase(std::move(Other));
 }

diff  --git a/clang-tools-extra/clang-include-fixer/IncludeFixerContext.cpp 
b/clang-tools-extra/clang-include-fixer/IncludeFixerContext.cpp
index d7369b162dc10..4eac0617ed4a9 100644
--- a/clang-tools-extra/clang-include-fixer/IncludeFixerContext.cpp
+++ b/clang-tools-extra/clang-include-fixer/IncludeFixerContext.cpp
@@ -90,10 +90,10 @@ IncludeFixerContext::IncludeFixerContext(
   std::make_pair(B.Range.getOffset(), B.Range.getLength());
  });
   QuerySymbolInfos.erase(
-  std::unique(QuerySymbolInfos.begin(), QuerySymbolInfos.end(),
-  [](const QuerySymbolInfo &A, const QuerySymbolInfo &B) {
-return A.Range == B.Range;
-  }),
+  llvm::unique(QuerySymbolInfos,
+   [](const QuerySymbolInfo &A, const QuerySymbolInfo &B) {
+ return A.Range == B.Range;
+   }),
   QuerySymbolInfos.end());
   for (const auto &Symbol : MatchedSymbols) {
 HeaderInfos.push_back(
@@ -103,11 +103,11 @@ IncludeFixerContext::IncludeFixerContext(
  QuerySymbolInfos.front().ScopedQualifiers, Symbol)});
   }
   // Deduplicate header infos.
-  HeaderInfos.erase(std::unique(HeaderInfos.begin(), HeaderInfos.end(),
-[](const HeaderInfo &A, const HeaderInfo &B) {
-  return A.Header == B.Header &&
- A.QualifiedName == B.QualifiedName;
-}),
+  HeaderInfos.erase(llvm::unique(HeaderInfos,
+ [](const HeaderInfo &A, const HeaderInfo &B) {
+   return A.Header == B.Header &&
+  A.QualifiedName == B.QualifiedName;
+ }),
 HeaderInfos.end());
 }
 

diff  --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
index 731141a545a48..b216970bfbd8c 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -754,8 +754,7 @@ std::vector 
ClangTidyDiagnosticConsumer::take() {
   finalizeLastError();
 
   llvm::stable_sort(Errors, LessClangTidyError());
-  Errors.erase(std::unique(Errors.begin(), Errors.end(), 
EqualClangTidyError()),
-   Errors.end());
+  Errors.erase(llvm::unique(Errors, EqualClangTidyError()), Errors.end());
   if (RemoveIncompatibleErrors)
 removeIncompatibleErrors();
   return std::move(Errors);



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


[clang-tools-extra] [clang-tools-extra] Use llvm::unique (NFC) (PR #136514)

2025-04-20 Thread Kazu Hirata via cfe-commits

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


[clang-tools-extra] [clangd] Improve `BlockEnd` inlayhint presentation (PR #136106)

2025-04-20 Thread via cfe-commits

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


[clang] Ensure bit-fields storing FPEvalMethodKind are wide enough to do so (PR #136515)

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

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


[clang] Ensure bit-fields storing FPEvalMethodKind are wide enough to do so (PR #136515)

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

ojhunt wrote:

This is a blind build fix, so I'll merge

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


[clang] [AST] Call hash_combine_range with a range (NFC) (PR #136525)

2025-04-20 Thread Kazu Hirata via cfe-commits

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

None

>From 237474372f11d744737d9890308e7f687a1953ed Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Sun, 20 Apr 2025 15:11:01 -0700
Subject: [PATCH] [AST] Call hash_combine_range with a range (NFC)

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

diff --git a/clang/lib/AST/ItaniumCXXABI.cpp b/clang/lib/AST/ItaniumCXXABI.cpp
index a1b2551419f5e..6ceedd657fe7e 100644
--- a/clang/lib/AST/ItaniumCXXABI.cpp
+++ b/clang/lib/AST/ItaniumCXXABI.cpp
@@ -110,7 +110,7 @@ struct DenseMapInfo {
   }
   static unsigned getHashValue(DecompositionDeclName Key) {
 assert(!isEqual(Key, getEmptyKey()) && !isEqual(Key, getTombstoneKey()));
-return llvm::hash_combine_range(Key.begin(), Key.end());
+return llvm::hash_combine_range(Key);
   }
   static bool isEqual(DecompositionDeclName LHS, DecompositionDeclName RHS) {
 if (std::optional Result =

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


[clang-tools-extra] [clangd] Call hash_combine_range with a range (NFC) (PR #136526)

2025-04-20 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clangd

Author: Kazu Hirata (kazutakahirata)


Changes



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


1 Files Affected:

- (modified) clang-tools-extra/clangd/SystemIncludeExtractor.cpp (+1-2) 


``diff
diff --git a/clang-tools-extra/clangd/SystemIncludeExtractor.cpp 
b/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
index 9399b910025b6..d9642f1115a6d 100644
--- a/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
+++ b/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
@@ -239,8 +239,7 @@ template <> struct DenseMapInfo {
 Val.Stdlib,
 });
 
-unsigned SpecsHash =
-llvm::hash_combine_range(Val.Specs.begin(), Val.Specs.end());
+unsigned SpecsHash = llvm::hash_combine_range(Val.Specs);
 
 return llvm::hash_combine(FixedFieldsHash, SpecsHash);
   }

``




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


[clang-tools-extra] [clangd] Call hash_combine_range with a range (NFC) (PR #136526)

2025-04-20 Thread Kazu Hirata via cfe-commits

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

None

>From b5fba39de08101596f33dbec85f8541dbd7912de Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Sun, 20 Apr 2025 15:11:09 -0700
Subject: [PATCH] [clangd] Call hash_combine_range with a range (NFC)

---
 clang-tools-extra/clangd/SystemIncludeExtractor.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/clang-tools-extra/clangd/SystemIncludeExtractor.cpp 
b/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
index 9399b910025b6..d9642f1115a6d 100644
--- a/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
+++ b/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
@@ -239,8 +239,7 @@ template <> struct DenseMapInfo {
 Val.Stdlib,
 });
 
-unsigned SpecsHash =
-llvm::hash_combine_range(Val.Specs.begin(), Val.Specs.end());
+unsigned SpecsHash = llvm::hash_combine_range(Val.Specs);
 
 return llvm::hash_combine(FixedFieldsHash, SpecsHash);
   }

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


[clang] [AST] Call hash_combine_range with a range (NFC) (PR #136525)

2025-04-20 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)


Changes



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


1 Files Affected:

- (modified) clang/lib/AST/ItaniumCXXABI.cpp (+1-1) 


``diff
diff --git a/clang/lib/AST/ItaniumCXXABI.cpp b/clang/lib/AST/ItaniumCXXABI.cpp
index a1b2551419f5e..6ceedd657fe7e 100644
--- a/clang/lib/AST/ItaniumCXXABI.cpp
+++ b/clang/lib/AST/ItaniumCXXABI.cpp
@@ -110,7 +110,7 @@ struct DenseMapInfo {
   }
   static unsigned getHashValue(DecompositionDeclName Key) {
 assert(!isEqual(Key, getEmptyKey()) && !isEqual(Key, getTombstoneKey()));
-return llvm::hash_combine_range(Key.begin(), Key.end());
+return llvm::hash_combine_range(Key);
   }
   static bool isEqual(DecompositionDeclName LHS, DecompositionDeclName RHS) {
 if (std::optional Result =

``




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


[clang-tools-extra] [clangd] Call hash_combine_range with a range (NFC) (PR #136526)

2025-04-20 Thread via cfe-commits

llvmbot wrote:




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

Author: Kazu Hirata (kazutakahirata)


Changes



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


1 Files Affected:

- (modified) clang-tools-extra/clangd/SystemIncludeExtractor.cpp (+1-2) 


``diff
diff --git a/clang-tools-extra/clangd/SystemIncludeExtractor.cpp 
b/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
index 9399b910025b6..d9642f1115a6d 100644
--- a/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
+++ b/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
@@ -239,8 +239,7 @@ template <> struct DenseMapInfo {
 Val.Stdlib,
 });
 
-unsigned SpecsHash =
-llvm::hash_combine_range(Val.Specs.begin(), Val.Specs.end());
+unsigned SpecsHash = llvm::hash_combine_range(Val.Specs);
 
 return llvm::hash_combine(FixedFieldsHash, SpecsHash);
   }

``




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


[clang-tools-extra] [clangd] Store documentation when indexing standard library (PR #133681)

2025-04-20 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

> I was talking about a change like 
> [kadircet@ff0c31d](https://github.com/kadircet/llvm-project/commit/ff0c31d232b2aed9e95d69d16a9dfbb9babea711)

Thanks for the more fleshed-out suggestion.

As written, this would also have the following effects:

 1. we no longer use `SymbolOrigin::StdLib` for collected symbols
 2. we run the symbol collector with `CollectMainFileSymbols = true`
 3. we use the indexing option `SystemSymbolFilterKind::DeclarationsOnly`
 4. we no longer use 
[this](https://searchfox.org/llvm/rev/bb21a6819b3fb9d689de776f7ee768030dfbacea/clang-tools-extra/clangd/index/IndexAction.cpp#143-148)
 "deeply nested" optimization
 5. (maybe others, I haven't compared `clangd::IndexAction` to 
`SyntaxOnlyAction` + `indexTopLevelDecls()` in great depth)

Would I be right to say that (1) and (2) are undesirable? ((3) may actually be 
an improvement, and (4) may not make any difference as I'm guessing standard 
library implementations are unlikely to contain symbols with nesting depth 10 
or more.)

To fix (1) and (2), I think we would need to add a new parameter to the 
`indexHeaderSymbols` interface. If that seems preferable to you over adding a 
parameter to `createStaticIndexingAction`, I'm happy to revise the patch along 
these lines.

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


[clang] 3ac1aa4 - [Clang] Consider preferred_type in bitfield warnings (#116760) (#116785)

2025-04-20 Thread via cfe-commits

Author: Oliver Hunt
Date: 2025-04-20T14:16:51-07:00
New Revision: 3ac1aa4c88d4fe40166209cad616f4ae867c20a2

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

LOG: [Clang] Consider preferred_type in bitfield warnings (#116760) (#116785)

Very simply extends the bitfield sema checks for assignment to fields
with a preferred type specified to consider the preferred type if the
decl storage type is not explicitly an enum type.

This does mean that if the preferred and explicit types have different
storage requirements we may not warn in all possible cases, but that's a
scenario for which the warnings are much more complex and confusing.

Added: 
clang/test/SemaCXX/bitfield-preferred-type-sizing.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaChecking.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 25302764778d1..7417fdd71a392 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -395,6 +395,14 @@ Improvements to Clang's diagnostics
   constructors to initialize their non-modifiable members. The diagnostic is
   not new; being controlled via a warning group is what's new. Fixes #GH41104
 
+- Improved bit-field diagnostics to consider the type specified by the
+  ``preferred_type`` attribute. These diagnostics are controlled by the flags
+  ``-Wpreferred-type-bitfield-enum-conversion`` and
+  ``-Wpreferred-type-bitfield-width``. These warnings are on by default as they
+  they're only triggered if the authors are already making the choice to use
+  ``preferred_type`` attribute.
+
+
 Improvements to Clang's time-trace
 --
 

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index b234d60fee8fc..b29fe40b05c6f 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -49,6 +49,9 @@ def SingleBitBitFieldConstantConversion :
   DiagGroup<"single-bit-bitfield-constant-conversion">;
 def BitFieldConstantConversion : DiagGroup<"bitfield-constant-conversion",

[SingleBitBitFieldConstantConversion]>;
+def PreferredTypeBitFieldEnumConversion
+: DiagGroup<"preferred-type-bitfield-enum-conversion">;
+def PreferredTypeBitFieldWidth : DiagGroup<"preferred-type-bitfield-width">;
 def BitFieldEnumConversion : DiagGroup<"bitfield-enum-conversion">;
 def BitFieldWidth : DiagGroup<"bitfield-width">;
 def CompoundTokenSplitByMacro : DiagGroup<"compound-token-split-by-macro">;

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8b8d3d7f6903b..45b6e1dc29980 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6492,8 +6492,25 @@ def warn_signed_bitfield_enum_conversion : Warning<
   "signed bit-field %0 needs an extra bit to represent the largest positive "
   "enumerators of %1">,
   InGroup, DefaultIgnore;
+def warn_preferred_type_bitfield_too_small_for_enum
+: Warning<"bit-field %0 is not wide enough to store all enumerators of "
+  "preferred type %1">,
+  InGroup;
+def warn_preferred_type_unsigned_bitfield_assigned_signed_enum
+: Warning<"assigning value of preferred signed enum type %1 to unsigned "
+  "bit-field %0; "
+  "negative enumerators of enum %1 will be converted to positive "
+  "values">,
+  InGroup;
+def warn_preferred_type_signed_bitfield_enum_conversion
+: Warning<"signed bit-field %0 needs an extra bit to represent the largest 
"
+  "positive "
+  "enumerators of preferred type %1">,
+  InGroup;
 def note_change_bitfield_sign : Note<
   "consider making the bit-field type %select{unsigned|signed}0">;
+def note_bitfield_preferred_type
+: Note<"preferred type for bit-field %0 specified here">;
 
 def warn_missing_braces : Warning<
   "suggest braces around initialization of subobject">,

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index c48e009fd7242..b2b26a2c39cf2 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -11293,9 +11293,16 @@ static bool AnalyzeBitFieldAssignment(Sema &S, 
FieldDecl *Bitfield, Expr *Init,
 // The RHS is not constant.  If the RHS has an enum type, make sure the
 // bitfield is wide enough to hold all the values of the enum without
 // truncation.
-if (const auto *EnumTy = OriginalInit->getType()->getAs()) {
+const auto *EnumTy = OriginalInit->getType()->getA

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

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

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


[clang] [alpha.webkit.UncheckedCallArgsChecker] Checker fails to recognize CanMakeCheckedPtrBase (PR #136500)

2025-04-20 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

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

Author: Ryosuke Niwa (rniwa)


Changes

This PR fixes the bug that alpha.webkit.UncheckedCallArgsChecker did not 
recognize CanMakeCheckedPtrBase due to getAsCXXRecordDecl returning nullptr for 
it in hasPublicMethodInBase. Manually grab getTemplatedDecl out of 
TemplateSpecializationType then CXXRecordDecl to workaround this bug in clang 
frontend.

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


2 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
(+12-2) 
- (added) clang/test/Analysis/Checkers/WebKit/unchecked-call-arg.cpp (+34) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 811888e119449..25b77ef989388 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -46,8 +46,18 @@ hasPublicMethodInBase(const CXXBaseSpecifier *Base, 
StringRef NameToMatch) {
 return std::nullopt;
 
   const CXXRecordDecl *R = T->getAsCXXRecordDecl();
-  if (!R)
-return std::nullopt;
+  if (!R) {
+auto CT = Base->getType().getCanonicalType();
+if (auto *TST = dyn_cast(CT)) {
+  auto TmplName = TST->getTemplateName();
+  if (!TmplName.isNull()) {
+if (auto *TD = TmplName.getAsTemplateDecl())
+  R = dyn_cast_or_null(TD->getTemplatedDecl());
+  }
+}
+if (!R)
+  return std::nullopt;
+  }
   if (!R->hasDefinition())
 return std::nullopt;
 
diff --git a/clang/test/Analysis/Checkers/WebKit/unchecked-call-arg.cpp 
b/clang/test/Analysis/Checkers/WebKit/unchecked-call-arg.cpp
new file mode 100644
index 0..8685978ebf1ac
--- /dev/null
+++ b/clang/test/Analysis/Checkers/WebKit/unchecked-call-arg.cpp
@@ -0,0 +1,34 @@
+// RUN: %clang_analyze_cc1 
-analyzer-checker=alpha.webkit.UncheckedCallArgsChecker -verify %s
+
+void WTFCrash(void);
+
+enum class Tag : bool { Value };
+
+template  class CanMakeCheckedPtrBase {
+public:
+  void incrementCheckedPtrCount() const { ++m_checkedPtrCount; }
+  inline void decrementCheckedPtrCount() const
+  {
+  if (!m_checkedPtrCount)
+WTFCrash();
+  --m_checkedPtrCount;
+  }
+
+private:
+  mutable StorageType m_checkedPtrCount { 0 };
+};
+
+template
+class CanMakeCheckedPtr : public CanMakeCheckedPtrBase {
+};
+
+class CheckedObject : public CanMakeCheckedPtr {
+public:
+  void doWork();
+};
+
+CheckedObject* provide();
+void foo() {
+  provide()->doWork();
+  // expected-warning@-1{{Call argument for 'this' parameter is unchecked and 
unsafe}}
+}

``




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


[clang] [clang][bytecode] Fix bos/bdos with non-zero offset applied (PR #136482)

2025-04-20 Thread Timm Baeder via cfe-commits

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


[clang] ea3eb8d - [clang][bytecode] Fix bos/bdos with non-zero offset applied (#136482)

2025-04-20 Thread via cfe-commits

Author: Timm Baeder
Date: 2025-04-20T20:12:47+02:00
New Revision: ea3eb8d6258a018f118b5d41057ca333d1c8d4a0

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

LOG: [clang][bytecode] Fix bos/bdos with non-zero offset applied (#136482)

Compute the offset from the record layout.
Unfortunately, not all the test cases from the current interpreter work.

Added: 


Modified: 
clang/lib/AST/ByteCode/InterpBuiltin.cpp
clang/test/AST/ByteCode/builtin-object-size.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index aaf0f3f019b94..523e471d3c82c 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -2196,6 +2196,53 @@ static unsigned computeFullDescSize(const ASTContext 
&ASTCtx,
   return 0;
 }
 
+static unsigned computePointerOffset(const ASTContext &ASTCtx,
+ const Pointer &Ptr) {
+  unsigned Result = 0;
+
+  Pointer P = Ptr;
+  while (P.isArrayElement() || P.isField()) {
+P = P.expand();
+const Descriptor *D = P.getFieldDesc();
+
+if (P.isArrayElement()) {
+  unsigned ElemSize =
+  ASTCtx.getTypeSizeInChars(D->getElemQualType()).getQuantity();
+  if (P.isOnePastEnd())
+Result += ElemSize * P.getNumElems();
+  else
+Result += ElemSize * P.getIndex();
+  P = P.expand().getArray();
+} else if (P.isBaseClass()) {
+
+  const auto *RD = cast(D->asDecl());
+  bool IsVirtual = Ptr.isVirtualBaseClass();
+  P = P.getBase();
+  const Record *BaseRecord = P.getRecord();
+
+  const ASTRecordLayout &Layout =
+  
ASTCtx.getASTRecordLayout(cast(BaseRecord->getDecl()));
+  if (IsVirtual)
+Result += Layout.getVBaseClassOffset(RD).getQuantity();
+  else
+Result += Layout.getBaseClassOffset(RD).getQuantity();
+} else if (P.isField()) {
+  const FieldDecl *FD = P.getField();
+  const ASTRecordLayout &Layout =
+  ASTCtx.getASTRecordLayout(FD->getParent());
+  unsigned FieldIndex = FD->getFieldIndex();
+  uint64_t FieldOffset =
+  ASTCtx.toCharUnitsFromBits(Layout.getFieldOffset(FieldIndex))
+  .getQuantity();
+  Result += FieldOffset;
+  P = P.getBase();
+} else
+  llvm_unreachable("Unhandled descriptor type");
+  }
+
+  return Result;
+}
+
 static bool interp__builtin_object_size(InterpState &S, CodePtr OpPC,
 const InterpFrame *Frame,
 const Function *Func,
@@ -2217,7 +2264,7 @@ static bool interp__builtin_object_size(InterpState &S, 
CodePtr OpPC,
 
   const ASTContext &ASTCtx = S.getASTContext();
 
-  unsigned ByteOffset = 0;
+  unsigned ByteOffset = computePointerOffset(ASTCtx, Ptr);
   unsigned FullSize = computeFullDescSize(ASTCtx, DeclDesc);
 
   pushInteger(S, FullSize - ByteOffset, Call->getType());

diff  --git a/clang/test/AST/ByteCode/builtin-object-size.cpp 
b/clang/test/AST/ByteCode/builtin-object-size.cpp
index 62bb1642c5301..6f4ef54bcbafa 100644
--- a/clang/test/AST/ByteCode/builtin-object-size.cpp
+++ b/clang/test/AST/ByteCode/builtin-object-size.cpp
@@ -1,7 +1,9 @@
 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter 
-verify=both,expected %s
 // RUN: %clang_cc1 -verify=both,ref
  %s
 
-// both-no-diagnostics
+// ref-no-diagnostics
+
+typedef __SIZE_TYPE__ size_t;
 
 int a;
 static_assert(__builtin_object_size(&a, 0) == sizeof(int), "");
@@ -12,3 +14,43 @@ static_assert(__builtin_object_size(&arr, 0) == 
(sizeof(int)*2), "");
 
 float arrf[2];
 static_assert(__builtin_object_size(&arrf, 0) == (sizeof(float)*2), "");
+static_assert(__builtin_object_size(&arrf[1], 0) == sizeof(float), "");
+static_assert(__builtin_object_size(&arrf[2], 0) == 0, "");
+
+
+
+struct S {
+  int a;
+  char c;
+};
+
+S s;
+static_assert(__builtin_object_size(&s, 0) == sizeof(s), "");
+
+S ss[2];
+static_assert(__builtin_object_size(&ss[1], 0) == sizeof(s), "");
+static_assert(__builtin_object_size(&ss[1].c, 0) == sizeof(int), "");
+
+struct A { char buf[16]; };
+struct B : A {};
+struct C { int i; B bs[1]; } c;
+static_assert(__builtin_object_size(&c.bs[0], 3) == 16);
+static_assert(__builtin_object_size(&c.bs[1], 3) == 0);
+
+/// These are from test/SemaCXX/builtin-object-size-cxx14.
+/// They all don't work since they are rejected when evaluating the first
+/// parameter of the __builtin_object_size call.
+///
+/// GCC rejects them as well.
+namespace InvalidBase {
+  // Ensure this doesn't crash.
+  struct S { const char *name; };
+  S invalid_base(); // expected-note {{declared here}}
+  constexpr size_t bos_name = __builtin_object_size(invalid_base().name

[clang] [alpha.webkit.UncheckedCallArgsChecker] Checker fails to recognize CanMakeCheckedPtrBase (PR #136500)

2025-04-20 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa created 
https://github.com/llvm/llvm-project/pull/136500

This PR fixes the bug that alpha.webkit.UncheckedCallArgsChecker did not 
recognize CanMakeCheckedPtrBase due to getAsCXXRecordDecl returning nullptr for 
it in hasPublicMethodInBase. Manually grab getTemplatedDecl out of 
TemplateSpecializationType then CXXRecordDecl to workaround this bug in clang 
frontend.

>From 3cdf1565993030a56003c37e14e024e07ca75da1 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Sun, 20 Apr 2025 11:00:13 -0700
Subject: [PATCH] [alpha.webkit.UncheckedCallArgsChecker] Checker fails to
 recognize CanMakeCheckedPtrBase

This PR fixes the bug that alpha.webkit.UncheckedCallArgsChecker did not 
recognize
CanMakeCheckedPtrBase due to getAsCXXRecordDecl returning nullptr for it in
hasPublicMethodInBase. Manually grab getTemplatedDecl out of 
TemplateSpecializationType
then CXXRecordDecl to workaround this bug in clang frontend.
---
 .../Checkers/WebKit/PtrTypesSemantics.cpp | 14 ++--
 .../Checkers/WebKit/unchecked-call-arg.cpp| 34 +++
 2 files changed, 46 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Analysis/Checkers/WebKit/unchecked-call-arg.cpp

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 811888e119449..25b77ef989388 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -46,8 +46,18 @@ hasPublicMethodInBase(const CXXBaseSpecifier *Base, 
StringRef NameToMatch) {
 return std::nullopt;
 
   const CXXRecordDecl *R = T->getAsCXXRecordDecl();
-  if (!R)
-return std::nullopt;
+  if (!R) {
+auto CT = Base->getType().getCanonicalType();
+if (auto *TST = dyn_cast(CT)) {
+  auto TmplName = TST->getTemplateName();
+  if (!TmplName.isNull()) {
+if (auto *TD = TmplName.getAsTemplateDecl())
+  R = dyn_cast_or_null(TD->getTemplatedDecl());
+  }
+}
+if (!R)
+  return std::nullopt;
+  }
   if (!R->hasDefinition())
 return std::nullopt;
 
diff --git a/clang/test/Analysis/Checkers/WebKit/unchecked-call-arg.cpp 
b/clang/test/Analysis/Checkers/WebKit/unchecked-call-arg.cpp
new file mode 100644
index 0..8685978ebf1ac
--- /dev/null
+++ b/clang/test/Analysis/Checkers/WebKit/unchecked-call-arg.cpp
@@ -0,0 +1,34 @@
+// RUN: %clang_analyze_cc1 
-analyzer-checker=alpha.webkit.UncheckedCallArgsChecker -verify %s
+
+void WTFCrash(void);
+
+enum class Tag : bool { Value };
+
+template  class CanMakeCheckedPtrBase {
+public:
+  void incrementCheckedPtrCount() const { ++m_checkedPtrCount; }
+  inline void decrementCheckedPtrCount() const
+  {
+  if (!m_checkedPtrCount)
+WTFCrash();
+  --m_checkedPtrCount;
+  }
+
+private:
+  mutable StorageType m_checkedPtrCount { 0 };
+};
+
+template
+class CanMakeCheckedPtr : public CanMakeCheckedPtrBase {
+};
+
+class CheckedObject : public CanMakeCheckedPtr {
+public:
+  void doWork();
+};
+
+CheckedObject* provide();
+void foo() {
+  provide()->doWork();
+  // expected-warning@-1{{Call argument for 'this' parameter is unchecked and 
unsafe}}
+}

___
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] fix `clang-tidy` warnings in `clang-tools-extra/clang-tidy` directory (PR #136097)

2025-04-20 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp closed 
https://github.com/llvm/llvm-project/pull/136097
___
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] fix `clang-tidy` warnings in `clang-tools-extra/clang-tidy` directory (PR #136097)

2025-04-20 Thread Carlos Galvez via cfe-commits


@@ -209,12 +209,14 @@ bool isQualificationConvertiblePointer(QualType From, 
QualType To,
   // cv-decomposition of T, that is, cv_1, cv_2, ... , cv_n, is called the
   // cv-qualification signature of T.
 
-  auto isValidP_i = [](QualType P) {
+  // NOLINTNEXTLINE (readability-identifier-naming): Preserve original notation

carlosgalvezp wrote:

Ah yes, you are right! I agree.

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


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

2025-04-20 Thread Carlos Galvez via cfe-commits


@@ -122,7 +122,10 @@ void 
UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
   initListExpr(
   hasType(cxxRecordDecl(RestrictToPODTypes ? isPOD() : isAggregate(),
-unless(HasBaseWithFields))
+unless(anyOf(HasBaseWithFields,
+ IgnoreSingleElementAggregates
+ ? hasName("::std::array")

carlosgalvezp wrote:

The condition seem wrong? "If `IgnoreSingleElementAggregates` is true, then 
ignore `std::array`. Shouldn't it be the other way around?

Regardless, I believe we want to always ignore `std::array`, regardless of 
`IgnoreSingleElementAggregates`, since the private member is never intended to 
be used by the caller. 

So I would just simplify to `unless(anyOf(HasBaseWithFields, 
hasName("::std::array")))

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


[clang-tools-extra] 842e591 - [clang-tidy][NFC] fix `clang-tidy` warnings in `clang-tools-extra/clang-tidy` directory (#136097)

2025-04-20 Thread via cfe-commits

Author: Baranov Victor
Date: 2025-04-20T20:41:13+02:00
New Revision: 842e5915778a820c63cf38b75bec932a6ea8c18b

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

LOG: [clang-tidy][NFC] fix `clang-tidy` warnings in 
`clang-tools-extra/clang-tidy` directory (#136097)

Mostly stylistic changes to `clang-tidy` source code.

Command run:
`python3 clang-tools-extra/clang-tidy/tool/run-clang-tidy.py -p build/
-j $(nproc) clang-tools-extra/clang-tidy`

Added: 


Modified: 
clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.cpp
clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp
clang-tools-extra/clang-tidy/bugprone/StringviewNullptrCheck.cpp
clang-tools-extra/clang-tidy/bugprone/TaggedUnionMemberCountCheck.cpp
clang-tools-extra/clang-tidy/hicpp/NoAssemblerCheck.cpp
clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp
clang-tools-extra/clang-tidy/misc/ConfusableTable/BuildConfusableTable.cpp
clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
clang-tools-extra/clang-tidy/objc/AssertEquals.cpp
clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
clang-tools-extra/clang-tidy/portability/StdAllocatorConstCheck.cpp
clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
clang-tools-extra/clang-tidy/utils/ExprSequence.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.cpp 
b/clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.cpp
index 06f98c76269b5..664ec59997b59 100644
--- a/clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/CleanupCtadCheck.cpp
@@ -21,9 +21,9 @@ using namespace ::clang::transformer;
 
 namespace clang::tidy::abseil {
 
-RewriteRuleWith CleanupCtadCheckImpl() {
-  auto warning_message = cat("prefer absl::Cleanup's class template argument "
- "deduction pattern in C++17 and higher");
+RewriteRuleWith cleanupCtadCheckImpl() {
+  auto WarningMessage = cat("prefer absl::Cleanup's class template argument "
+"deduction pattern in C++17 and higher");
 
   return makeRule(
   declStmt(hasSingleDecl(varDecl(
@@ -34,10 +34,10 @@ RewriteRuleWith CleanupCtadCheckImpl() {
   .bind("make_cleanup_call")),
   {changeTo(node("auto_type_loc"), cat("absl::Cleanup")),
changeTo(node("make_cleanup_call"), 
cat(callArgs("make_cleanup_call")))},
-  warning_message);
+  WarningMessage);
 }
 
 CleanupCtadCheck::CleanupCtadCheck(StringRef Name, ClangTidyContext *Context)
-: utils::TransformerClangTidyCheck(CleanupCtadCheckImpl(), Name, Context) 
{}
+: utils::TransformerClangTidyCheck(cleanupCtadCheckImpl(), Name, Context) 
{}
 
 } // namespace clang::tidy::abseil

diff  --git a/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
index a7e25141b3fe2..a544ef0d9dd04 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
@@ -250,10 +250,10 @@ static bool isIdenticalStmt(const ASTContext &Ctx, const 
Stmt *Stmt1,
 
 if (!llvm::all_of(llvm::zip(CompStmt1->body(), CompStmt2->body()),
   [&Ctx, IgnoreSideEffects](
-  std::tuple stmtPair) {
-const Stmt *stmt0 = std::get<0>(stmtPair);
-const Stmt *stmt1 = std::get<1>(stmtPair);
-return isIdenticalStmt(Ctx, stmt0, stmt1,
+  std::tuple StmtPair) {
+const Stmt *Stmt0 = std::get<0>(StmtPair);
+const Stmt *Stmt1 = std::get<1>(StmtPair);
+return isIdenticalStmt(Ctx, Stmt0, Stmt1,
IgnoreSideEffects);
   })) {
   return false;
@@ -477,7 +477,7 @@ void BranchCloneCheck::check(const MatchFinder::MatchResult 
&Result) {
 
   if (const auto *IS = Result.Nodes.getNodeAs("ifWithDescendantIf")) {
 const Stmt *Then = IS->getThen();
-auto CS = dyn_cast(Then);
+const auto *CS = dyn_cast(Then);
 if (CS && (!CS->body_empty())) {
   const auto *InnerIf = dyn_cast(*CS->body_begin());
   if (InnerIf && isIdenticalStmt(Context, IS->getCond(), 
InnerIf->getCond(),

diff  --git a/clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
index 27045816a80d3..c066b3e7b19a5 100644
--- a/clang-tools-extra/clang-t

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

2025-04-20 Thread Carlos Galvez via cfe-commits

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

Please add a unit test demonstrating that the related issue is fixed.

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


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

2025-04-20 Thread Carlos Galvez via cfe-commits


@@ -182,6 +182,11 @@ Changes in existing checks
   ``constexpr`` and ``static``` values on member initialization and by 
detecting
   explicit casting of built-in types within member list initialization.
 
+- Improved :doc:`modernize-use-designated-initializers
+  ` check by avoiding
+  diagnosing designated initializers for ``std::array`` initializations when

carlosgalvezp wrote:

Please document this exception also in `IgnoreSingleElementAggregates`

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


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

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


@@ -5685,11 +5685,9 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine 
&Line,
 if (Right.is(tok::r_brace) && Left.is(tok::l_brace) &&
 !Left.Children.empty()) {
   // Support AllowShortFunctionsOnASingleLine for JavaScript.
-  return Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_None ||
- Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_Empty 
||
- (Left.NestingLevel == 0 && Line.Level == 0 &&
-  Style.AllowShortFunctionsOnASingleLine &
-  FormatStyle::SFS_InlineOnly);
+  return !(Left.NestingLevel == 0 && Line.Level == 0
+   ? Style.AllowShortFunctionsOnASingleLine.isAll()

owenca wrote:

Looks like this is even worse than what @sstwcw suggested because it also seems 
incorrect if the following is true:
```
Left.NestingLevel == 0 && Line.Level == 0 && Other && !Inline
```

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


[clang-tools-extra] [clang-tools-extra] Use llvm::unique (NFC) (PR #136514)

2025-04-20 Thread Jakub Kuderski via cfe-commits

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


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


[clang] [clang][bytecode] Start implementing __builtin_{,dynamic}_object_size (PR #136478)

2025-04-20 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes



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


3 Files Affected:

- (modified) clang/lib/AST/ByteCode/Descriptor.h (+1-1) 
- (modified) clang/lib/AST/ByteCode/InterpBuiltin.cpp (+52) 
- (added) clang/test/AST/ByteCode/builtin-object-size.cpp (+14) 


``diff
diff --git a/clang/lib/AST/ByteCode/Descriptor.h 
b/clang/lib/AST/ByteCode/Descriptor.h
index a0705cc8c377f..532b407c2c788 100644
--- a/clang/lib/AST/ByteCode/Descriptor.h
+++ b/clang/lib/AST/ByteCode/Descriptor.h
@@ -265,7 +265,7 @@ struct Descriptor final {
   bool isUnknownSizeArray() const { return Size == UnknownSizeMark; }
 
   /// Checks if the descriptor is of a primitive.
-  bool isPrimitive() const { return !IsArray && !ElemRecord && !IsDummy; }
+  bool isPrimitive() const { return !IsArray && !ElemRecord && PrimT; }
 
   /// Checks if the descriptor is of an array.
   bool isArray() const { return IsArray; }
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 34553301ef630..1eb210c0cac4f 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -2179,6 +2179,52 @@ static bool interp__builtin_memchr(InterpState &S, 
CodePtr OpPC,
   return true;
 }
 
+static unsigned computeFullDescSize(const ASTContext &ASTCtx,
+const Descriptor *Desc) {
+
+  if (Desc->isPrimitive())
+return ASTCtx.getTypeSizeInChars(Desc->getType()).getQuantity();
+
+  if (Desc->isArray())
+return ASTCtx.getTypeSizeInChars(Desc->getElemQualType()).getQuantity() *
+   Desc->getNumElems();
+
+  if (Desc->isRecord())
+return ASTCtx.getTypeSizeInChars(Desc->getType()).getQuantity();
+
+  llvm_unreachable("Unhandled descriptor type");
+  return 0;
+}
+
+static bool interp__builtin_object_size(InterpState &S, CodePtr OpPC,
+const InterpFrame *Frame,
+const Function *Func,
+const CallExpr *Call) {
+  PrimType KindT = *S.getContext().classify(Call->getArg(1));
+  unsigned Kind = peekToAPSInt(S.Stk, KindT).getZExtValue();
+
+  assert(Kind <= 3 && "unexpected kind");
+
+  const Pointer &Ptr =
+  S.Stk.peek(align(primSize(KindT)) + align(primSize(PT_Ptr)));
+
+  if (Ptr.isZero())
+return false;
+
+  const Descriptor *DeclDesc = Ptr.getDeclDesc();
+  if (!DeclDesc)
+return false;
+
+  const ASTContext &ASTCtx = S.getASTContext();
+
+  unsigned ByteOffset = 0;
+  unsigned FullSize = computeFullDescSize(ASTCtx, DeclDesc);
+
+  pushInteger(S, FullSize - ByteOffset, Call->getType());
+
+  return true;
+}
+
 bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
   const CallExpr *Call, uint32_t BuiltinID) {
   if (!S.getASTContext().BuiltinInfo.isConstantEvaluated(BuiltinID))
@@ -2681,6 +2727,12 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, 
const Function *F,
   return false;
 break;
 
+  case Builtin::BI__builtin_object_size:
+  case Builtin::BI__builtin_dynamic_object_size:
+if (!interp__builtin_object_size(S, OpPC, Frame, F, Call))
+  return false;
+break;
+
   default:
 S.FFDiag(S.Current->getLocation(OpPC),
  diag::note_invalid_subexpr_in_const_expr)
diff --git a/clang/test/AST/ByteCode/builtin-object-size.cpp 
b/clang/test/AST/ByteCode/builtin-object-size.cpp
new file mode 100644
index 0..62bb1642c5301
--- /dev/null
+++ b/clang/test/AST/ByteCode/builtin-object-size.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter 
-verify=both,expected %s
+// RUN: %clang_cc1 -verify=both,ref
  %s
+
+// both-no-diagnostics
+
+int a;
+static_assert(__builtin_object_size(&a, 0) == sizeof(int), "");
+float f;
+static_assert(__builtin_object_size(&f, 0) == sizeof(float), "");
+int arr[2];
+static_assert(__builtin_object_size(&arr, 0) == (sizeof(int)*2), "");
+
+float arrf[2];
+static_assert(__builtin_object_size(&arrf, 0) == (sizeof(float)*2), "");

``




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


[clang] [clang][bytecode] Start implementing __builtin_{,dynamic}_object_size (PR #136478)

2025-04-20 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/136478

>From 8327fc0f0d06c39386b285b16902838b2dc0af0c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sat, 19 Apr 2025 17:29:16 +0200
Subject: [PATCH] [clang][bytecode] Start implementing
 __builtin_{,dynamic}_object_size

---
 clang/lib/AST/ByteCode/Descriptor.h   |  2 +-
 clang/lib/AST/ByteCode/InterpBuiltin.cpp  | 52 +++
 .../test/AST/ByteCode/builtin-object-size.cpp | 14 +
 3 files changed, 67 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/AST/ByteCode/builtin-object-size.cpp

diff --git a/clang/lib/AST/ByteCode/Descriptor.h 
b/clang/lib/AST/ByteCode/Descriptor.h
index a0705cc8c377f..532b407c2c788 100644
--- a/clang/lib/AST/ByteCode/Descriptor.h
+++ b/clang/lib/AST/ByteCode/Descriptor.h
@@ -265,7 +265,7 @@ struct Descriptor final {
   bool isUnknownSizeArray() const { return Size == UnknownSizeMark; }
 
   /// Checks if the descriptor is of a primitive.
-  bool isPrimitive() const { return !IsArray && !ElemRecord && !IsDummy; }
+  bool isPrimitive() const { return !IsArray && !ElemRecord && PrimT; }
 
   /// Checks if the descriptor is of an array.
   bool isArray() const { return IsArray; }
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 34553301ef630..aaf0f3f019b94 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -2179,6 +2179,52 @@ static bool interp__builtin_memchr(InterpState &S, 
CodePtr OpPC,
   return true;
 }
 
+static unsigned computeFullDescSize(const ASTContext &ASTCtx,
+const Descriptor *Desc) {
+
+  if (Desc->isPrimitive())
+return ASTCtx.getTypeSizeInChars(Desc->getType()).getQuantity();
+
+  if (Desc->isArray())
+return ASTCtx.getTypeSizeInChars(Desc->getElemQualType()).getQuantity() *
+   Desc->getNumElems();
+
+  if (Desc->isRecord())
+return ASTCtx.getTypeSizeInChars(Desc->getType()).getQuantity();
+
+  llvm_unreachable("Unhandled descriptor type");
+  return 0;
+}
+
+static bool interp__builtin_object_size(InterpState &S, CodePtr OpPC,
+const InterpFrame *Frame,
+const Function *Func,
+const CallExpr *Call) {
+  PrimType KindT = *S.getContext().classify(Call->getArg(1));
+  [[maybe_unused]] unsigned Kind = peekToAPSInt(S.Stk, KindT).getZExtValue();
+
+  assert(Kind <= 3 && "unexpected kind");
+
+  const Pointer &Ptr =
+  S.Stk.peek(align(primSize(KindT)) + align(primSize(PT_Ptr)));
+
+  if (Ptr.isZero())
+return false;
+
+  const Descriptor *DeclDesc = Ptr.getDeclDesc();
+  if (!DeclDesc)
+return false;
+
+  const ASTContext &ASTCtx = S.getASTContext();
+
+  unsigned ByteOffset = 0;
+  unsigned FullSize = computeFullDescSize(ASTCtx, DeclDesc);
+
+  pushInteger(S, FullSize - ByteOffset, Call->getType());
+
+  return true;
+}
+
 bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
   const CallExpr *Call, uint32_t BuiltinID) {
   if (!S.getASTContext().BuiltinInfo.isConstantEvaluated(BuiltinID))
@@ -2681,6 +2727,12 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, 
const Function *F,
   return false;
 break;
 
+  case Builtin::BI__builtin_object_size:
+  case Builtin::BI__builtin_dynamic_object_size:
+if (!interp__builtin_object_size(S, OpPC, Frame, F, Call))
+  return false;
+break;
+
   default:
 S.FFDiag(S.Current->getLocation(OpPC),
  diag::note_invalid_subexpr_in_const_expr)
diff --git a/clang/test/AST/ByteCode/builtin-object-size.cpp 
b/clang/test/AST/ByteCode/builtin-object-size.cpp
new file mode 100644
index 0..62bb1642c5301
--- /dev/null
+++ b/clang/test/AST/ByteCode/builtin-object-size.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter 
-verify=both,expected %s
+// RUN: %clang_cc1 -verify=both,ref
  %s
+
+// both-no-diagnostics
+
+int a;
+static_assert(__builtin_object_size(&a, 0) == sizeof(int), "");
+float f;
+static_assert(__builtin_object_size(&f, 0) == sizeof(float), "");
+int arr[2];
+static_assert(__builtin_object_size(&arr, 0) == (sizeof(int)*2), "");
+
+float arrf[2];
+static_assert(__builtin_object_size(&arrf, 0) == (sizeof(float)*2), "");

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


[clang] 90c845f - [clang][bytecode] Start implementing __builtin_{,dynamic}_object_size (#136478)

2025-04-20 Thread via cfe-commits

Author: Timm Baeder
Date: 2025-04-20T12:20:21+02:00
New Revision: 90c845fb3babac387688dfa6d560d3ba8ed8e340

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

LOG: [clang][bytecode] Start implementing __builtin_{,dynamic}_object_size 
(#136478)

Added: 
clang/test/AST/ByteCode/builtin-object-size.cpp

Modified: 
clang/lib/AST/ByteCode/Descriptor.h
clang/lib/AST/ByteCode/InterpBuiltin.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/Descriptor.h 
b/clang/lib/AST/ByteCode/Descriptor.h
index a0705cc8c377f..532b407c2c788 100644
--- a/clang/lib/AST/ByteCode/Descriptor.h
+++ b/clang/lib/AST/ByteCode/Descriptor.h
@@ -265,7 +265,7 @@ struct Descriptor final {
   bool isUnknownSizeArray() const { return Size == UnknownSizeMark; }
 
   /// Checks if the descriptor is of a primitive.
-  bool isPrimitive() const { return !IsArray && !ElemRecord && !IsDummy; }
+  bool isPrimitive() const { return !IsArray && !ElemRecord && PrimT; }
 
   /// Checks if the descriptor is of an array.
   bool isArray() const { return IsArray; }

diff  --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 34553301ef630..aaf0f3f019b94 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -2179,6 +2179,52 @@ static bool interp__builtin_memchr(InterpState &S, 
CodePtr OpPC,
   return true;
 }
 
+static unsigned computeFullDescSize(const ASTContext &ASTCtx,
+const Descriptor *Desc) {
+
+  if (Desc->isPrimitive())
+return ASTCtx.getTypeSizeInChars(Desc->getType()).getQuantity();
+
+  if (Desc->isArray())
+return ASTCtx.getTypeSizeInChars(Desc->getElemQualType()).getQuantity() *
+   Desc->getNumElems();
+
+  if (Desc->isRecord())
+return ASTCtx.getTypeSizeInChars(Desc->getType()).getQuantity();
+
+  llvm_unreachable("Unhandled descriptor type");
+  return 0;
+}
+
+static bool interp__builtin_object_size(InterpState &S, CodePtr OpPC,
+const InterpFrame *Frame,
+const Function *Func,
+const CallExpr *Call) {
+  PrimType KindT = *S.getContext().classify(Call->getArg(1));
+  [[maybe_unused]] unsigned Kind = peekToAPSInt(S.Stk, KindT).getZExtValue();
+
+  assert(Kind <= 3 && "unexpected kind");
+
+  const Pointer &Ptr =
+  S.Stk.peek(align(primSize(KindT)) + align(primSize(PT_Ptr)));
+
+  if (Ptr.isZero())
+return false;
+
+  const Descriptor *DeclDesc = Ptr.getDeclDesc();
+  if (!DeclDesc)
+return false;
+
+  const ASTContext &ASTCtx = S.getASTContext();
+
+  unsigned ByteOffset = 0;
+  unsigned FullSize = computeFullDescSize(ASTCtx, DeclDesc);
+
+  pushInteger(S, FullSize - ByteOffset, Call->getType());
+
+  return true;
+}
+
 bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
   const CallExpr *Call, uint32_t BuiltinID) {
   if (!S.getASTContext().BuiltinInfo.isConstantEvaluated(BuiltinID))
@@ -2681,6 +2727,12 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, 
const Function *F,
   return false;
 break;
 
+  case Builtin::BI__builtin_object_size:
+  case Builtin::BI__builtin_dynamic_object_size:
+if (!interp__builtin_object_size(S, OpPC, Frame, F, Call))
+  return false;
+break;
+
   default:
 S.FFDiag(S.Current->getLocation(OpPC),
  diag::note_invalid_subexpr_in_const_expr)

diff  --git a/clang/test/AST/ByteCode/builtin-object-size.cpp 
b/clang/test/AST/ByteCode/builtin-object-size.cpp
new file mode 100644
index 0..62bb1642c5301
--- /dev/null
+++ b/clang/test/AST/ByteCode/builtin-object-size.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter 
-verify=both,expected %s
+// RUN: %clang_cc1 -verify=both,ref
  %s
+
+// both-no-diagnostics
+
+int a;
+static_assert(__builtin_object_size(&a, 0) == sizeof(int), "");
+float f;
+static_assert(__builtin_object_size(&f, 0) == sizeof(float), "");
+int arr[2];
+static_assert(__builtin_object_size(&arr, 0) == (sizeof(int)*2), "");
+
+float arrf[2];
+static_assert(__builtin_object_size(&arrf, 0) == (sizeof(float)*2), "");



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


[clang] [clang][bytecode] Start implementing __builtin_{,dynamic}_object_size (PR #136478)

2025-04-20 Thread Timm Baeder via cfe-commits

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


[clang] [clang] Implement P2582R1: CTAD from inherited constructors (PR #98788)

2025-04-20 Thread via cfe-commits

cor3ntin wrote:

@antangelo @erichkeane @hokein Should we try to land this now?

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


[clang] [llvm] [Clang][C++23] Core language changes from P1467R9 extended floating-point types and standard names. (PR #78503)

2025-04-20 Thread via cfe-commits

cor3ntin wrote:

@codemzs I want to make sure you saw the pending feedback. I think it would be 
great if we could land this for clang 21 :)

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


[clang] [clang] add `-fimplicit-constexpr` flag (PR #136436)

2025-04-20 Thread via cfe-commits
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= 
Message-ID:
In-Reply-To: 


cor3ntin wrote:

@Sirraide we could do the check at the point of call - and cache the result, 
which would require storing some state in FunctionDecl. Or just not care. GCC 
is explicit about not supporting this scenario 
https://compiler-explorer.com/z/Mdva4f1a1 - and i don't see the value in 
diverging from GCC

We also should be careful about the whole consteval propagation thing, which 
would be affected by this feature.
I think @philnik777, this probably needs an RFC, but it does seem reasonable to 
me to follow in GCC's footsteps here.


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


[clang] [clang][bytecode] Start implementing __builtin_{,dynamic}_object_size (PR #136478)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `fuchsia-x86_64-linux` 
running on `fuchsia-debian-64-us-central1-a-1` while building `clang` at step 4 
"annotate".

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


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

```
Step 4 (annotate) failure: 'python 
../llvm-zorg/zorg/buildbot/builders/annotated/fuchsia-linux.py ...' (failure)
...
[193/2494] Copying CXX header __type_traits/alignment_of.h
[194/2494] Copying CXX header __type_traits/can_extract_key.h
[195/2494] Copying CXX header __type_traits/common_reference.h
[196/2494] Generating header assert.h from 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/runtimes/../libc/include/assert.yaml
[197/2494] Generating header errno.h from 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/runtimes/../libc/include/errno.yaml
[198/2494] Generating header features.h from 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/runtimes/../libc/include/features.yaml
[199/2494] Generating header limits.h from 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/runtimes/../libc/include/limits.yaml
[200/2494] Generating header stdint.h from 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/runtimes/../libc/include/stdint.yaml
[201/2494] Generating header float.h from 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/runtimes/../libc/include/float.yaml
[202/2494] Building CXX object 
libc/src/stdlib/CMakeFiles/libc.src.stdlib.a64l.dir/a64l.cpp.obj
FAILED: libc/src/stdlib/CMakeFiles/libc.src.stdlib.a64l.dir/a64l.cpp.obj 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-_n9qsms1/./bin/clang++ 
--target=armv7em-none-eabi -DLIBC_NAMESPACE=__llvm_libc_21_0_0_git 
-I/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc -isystem 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-_n9qsms1/include/armv7em-unknown-none-eabi
 --target=armv7em-none-eabi -Wno-atomic-alignment "-Dvfprintf(stream, format, 
vlist)=vprintf(format, vlist)" "-Dfprintf(stream, format, ...)=printf(format)" 
-D_LIBCPP_PRINT=1 -mthumb -fPIC -fno-semantic-interposition 
-fvisibility-inlines-hidden -Werror=date-time 
-Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter 
-Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough 
-Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
-Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion 
-Wmisleading-indentation -Wctad-maybe-unsupported -ffunction-sections 
-fdata-sections 
-ffile-prefix-map=/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-_n9qsms1/runtimes/runtimes-armv7em-none-eabi-bins=../../../../llvm-project
 -ffile-prefix-map=/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/= 
-no-canonical-prefixes -Os -DNDEBUG --target=armv7em-none-eabi 
-DLIBC_QSORT_IMPL=LIBC_QSORT_HEAP_SORT -DLIBC_TYPES_TIME_T_IS_32_BIT 
-DLIBC_ADD_NULL_CHECKS "-DLIBC_MATH=(LIBC_MATH_SKIP_ACCURATE_PASS | 
LIBC_MATH_SMALL_TABLES)" -fpie -ffreestanding -DLIBC_FULL_BUILD -nostdlibinc 
-ffixed-point -fno-builtin -fno-exceptions -fno-lax-vector-conversions 
-fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti 
-ftrivial-auto-var-init=pattern -fno-omit-frame-pointer -Wall -Wextra -Werror 
-Wconversion -Wno-sign-conversion -Wdeprecated -Wno-c99-extensions 
-Wno-gnu-imaginary-constant -Wno-pedantic -Wimplicit-fallthrough 
-Wwrite-strings -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path 
-Wstrict-prototypes -Wthread-safety -Wglobal-constructors 
-DLIBC_COPT_PUBLIC_PACKAGING -MD -MT 
libc/src/stdlib/CMakeFiles/libc.src.stdlib.a64l.dir/a64l.cpp.obj -MF 
libc/src/stdlib/CMakeFiles/libc.src.stdlib.a64l.dir/a64l.cpp.obj.d -o 
libc/src/stdlib/CMakeFiles/libc.src.stdlib.a64l.dir/a64l.cpp.obj -c 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/stdlib/a64l.cpp
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/stdlib/a64l.cpp:22:18:
 error: unknown type name 'int32_t'
   22 | constexpr static int32_t b64_char_to_int(char ch) {
  |  ^
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/stdlib/a64l.cpp:47:3:
 error: unknown type name 'int32_t'
   47 |   int32_t result = 0;
  |   ^
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/stdlib/a64l.cpp:50:5:
 error: unknown type name 'int32_t'
   50 | int32_t cur_val = b64_char_to_int(s[i]);
  | ^
3 errors generated.
[203/2494] Generating header setjmp.h from 
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/runtimes/../libc/include/setjmp.yaml
[204/2494] Building CXX object 
libc/src/stdlib/baremetal/CMakeFiles/libc.src.stdlib.baremetal.abort.dir/abort.cpp.obj
[205/2494] Building CXX object 
libc/src/string/CMakeFiles/libc.src.string.strcmp.dir/strcmp.cpp.obj
[206/2494] Building CXX object 
libc/src/string/CMakeFiles/libc.src.string.memccpy.dir/memccpy.cpp.obj
[207/2494] Building CXX object 
libc/src/string/CMakeFiles/libc.src.string.strcoll.dir

[clang] [clang] add `-fimplicit-constexpr` flag (PR #136436)

2025-04-20 Thread via cfe-commits
Hana =?utf-8?q?Dusíková?= ,
Hana =?utf-8?q?Dusíková?= 
Message-ID:
In-Reply-To: 



@@ -779,6 +779,9 @@ static void InitializeCPlusPlusFeatureTestMacros(const 
LangOptions &LangOpts,
 
   // TODO: Final number?
   Builder.defineMacro("__cpp_type_aware_allocators", "202500L");
+
+  if (LangOpts.ImplicitConstexpr) // same value as GCC
+Builder.defineMacro("__cpp_implicit_constexpr", "2021");

cor3ntin wrote:

We don't usually define macros for non-standard feature. Instead users should 
use `__has_extension(cxx_implicit_constexpr)`

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


[clang] [clang][Analyzer] Fix error path of builtin overflow (PR #136345)

2025-04-20 Thread Balazs Benics via cfe-commits


@@ -194,30 +187,28 @@ void BuiltinFunctionChecker::handleOverflowBuiltin(const 
CallEvent &Call,
   SVal RetVal = SVB.evalBinOp(State, Op, Arg1, Arg2, ResultType);
 
   auto [Overflow, NotOverflow] = checkOverflow(C, RetValMax, ResultType);
-  if (NotOverflow) {
-ProgramStateRef StateNoOverflow = State->BindExpr(
-CE, C.getLocationContext(), SVB.makeTruthVal(false, BoolTy));
+  auto initializeState = [&](bool isOverflow) {
+ProgramStateRef NewState = State->BindExpr(
+CE, C.getLocationContext(), SVB.makeTruthVal(isOverflow, BoolTy));
 
 if (auto L = Call.getArgSVal(2).getAs()) {
-  StateNoOverflow =
-  StateNoOverflow->bindLoc(*L, RetVal, C.getLocationContext());
+  NewState = NewState->bindLoc(*L, RetVal, C.getLocationContext());
 
-  // Propagate taint if any of the argumets were tainted
+  // Propagate taint if any of the arguments were tainted
   if (isTainted(State, Arg1) || isTainted(State, Arg2))
-StateNoOverflow = addTaint(StateNoOverflow, *L);
+NewState = addTaint(NewState, *L);
 }
 
-C.addTransition(
-StateNoOverflow,
-createBuiltinNoOverflowNoteTag(
-C, /*BothFeasible=*/NotOverflow && Overflow, Arg1, Arg2, RetVal));
-  }
+C.addTransition(NewState,
+createBuiltinOverflowNoteTag(C, /*overflow=*/isOverflow,
+ Arg1, Arg2, RetVal));
+  };
 
-  if (Overflow) {
-C.addTransition(State->BindExpr(CE, C.getLocationContext(),
-SVB.makeTruthVal(true, BoolTy)),
-createBuiltinOverflowNoteTag(C));
-  }
+  if (NotOverflow)
+initializeState(false);

steakhal wrote:

I don't likr that this call has a side-effect. I eish we would be explicit 
about mutations. Pass whats needed, get the return value that it would produce.

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


[clang] [clang][Analyzer] Fix error path of builtin overflow (PR #136345)

2025-04-20 Thread Balazs Benics via cfe-commits

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


[clang] [clang][Analyzer] Fix error path of builtin overflow (PR #136345)

2025-04-20 Thread Balazs Benics via cfe-commits


@@ -121,30 +120,24 @@ class BuiltinFunctionChecker : public Checker 
{
 
 } // namespace
 
-const NoteTag *BuiltinFunctionChecker::createBuiltinNoOverflowNoteTag(
-CheckerContext &C, bool BothFeasible, SVal Arg1, SVal Arg2,
-SVal Result) const {
-  return C.getNoteTag([Result, Arg1, Arg2, BothFeasible](
-  PathSensitiveBugReport &BR, llvm::raw_ostream &OS) {
+const NoteTag *BuiltinFunctionChecker::createBuiltinOverflowNoteTag(
+CheckerContext &C, bool overflow, SVal Arg1, SVal Arg2, SVal Result) const 
{
+  return C.getNoteTag([Result, Arg1, Arg2, overflow](PathSensitiveBugReport 
&BR,
+ llvm::raw_ostream &OS) {
 if (!BR.isInteresting(Result))
   return;
 
-// Propagate interestingness to input argumets if result is interesting.
+// Propagate interestingness to input arguments if result is interesting.
 BR.markInteresting(Arg1);
 BR.markInteresting(Arg2);
 
-if (BothFeasible)
+if (overflow)

steakhal wrote:

You could have used a ternary expr here and save a couple of lines.

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


  1   2   >