[clang] [clang] Dispatch default overloads of `TemplateArgumentVisitor` to the implementation (PR #115336)

2024-11-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Egor Zhdan (egorzhdan)


Changes

This fixes an issue where overriding 
`clang::ConstTemplateArgumentVisitor::VisitTemplateArgument` in an 
implementation visitor class did not have the desired effect: the overload was 
not invoked when one of the visitor methods (e.g. `VisitDeclarationArgument`) 
is not implemented, instead it dispatched to 
`clang::ConstTemplateArgumentVisitor::VisitTemplateArgument` itself and always 
returned a default-initialized result.

This makes `TemplateArgumentVisitor` and `ConstTemplateArgumentVisitor` follow 
the implicit convention that is followed elsewhere in Clang AST, in 
`RecursiveASTVisitor` and `TypeVisitor`.

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


1 Files Affected:

- (modified) clang/include/clang/AST/TemplateArgumentVisitor.h (+2-1) 


``diff
diff --git a/clang/include/clang/AST/TemplateArgumentVisitor.h 
b/clang/include/clang/AST/TemplateArgumentVisitor.h
index cf0d3220158063..923f045a995703 100644
--- a/clang/include/clang/AST/TemplateArgumentVisitor.h
+++ b/clang/include/clang/AST/TemplateArgumentVisitor.h
@@ -52,7 +52,8 @@ class Base {
 #define VISIT_METHOD(CATEGORY) 
\
   RetTy Visit##CATEGORY##TemplateArgument(REF(TemplateArgument) TA,
\
   ParamTys... P) { 
\
-return VisitTemplateArgument(TA, std::forward(P)...);
\
+return static_cast(this)->VisitTemplateArgument(  
\
+TA, std::forward(P)...); 
\
   }
 
   VISIT_METHOD(Null);

``




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


[clang] [Clang] Dispatch default overloads of `TemplateArgumentVisitor` to the implementation (PR #115336)

2024-11-07 Thread Gábor Horváth via cfe-commits

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


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


[clang] [flang] [clang][Driver] Add RPATH by default (PR #115286)

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

DavidTruby wrote:

I'd argue that this provides the least surprising behaviour to the end user: 
building a file with `clang -fopenmp` or `clang++ -stdlib=libc++` where 
openmp/libc++ were enabled on that LLVM build gives a binary that can just be 
run on that system, without setting any environment variables or playing with 
anything else. It seems to me that clang-built binaries should know where to 
look for the libraries from that toolchain. GCC does this with libstdc++ and 
libgcc_s as far as I know (I haven't checked in a while so I could be wrong 
here).

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


[clang] [clang-tools-extra] [llvm] [clang] Introduce diagnostics suppression mappings (PR #112517)

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


@@ -0,0 +1,90 @@
+
+Warning suppression mappings
+
+
+.. contents::
+   :local:
+
+Introduction
+
+
+Warning suppression mappings enable users to suppress Clang's diagnostics in a
+per-file granular manner. Enabling enforcement of diagnostics in specific parts
+of the project, even if there are violations in some headers.
+
+Goal and usage
+==
+
+Clang allows diagnostics to be configured at a translation-unit granularity.
+If a ``foo.cpp`` is compiled with ``-Wfoo``, all transitively included headers
+also need to be clean. Hence turning on new warnings in large codebases can be
+difficult today. Since it requires cleaning up all the existing warnings,
+which might not be possible when some dependencies aren't in the project 
owner's
+control or because new violations are creeping up quicker than the clean up.
+
+Warning suppression mappings aim to alleviate some of these concerns by making
+diagnostic configuration granularity finer, at a source file level.
+
+To achieve this, user can create a file that lists which diagnostic groups to
+suppress in which files or paths, and pass it as a command line argument to
+Clang with the ``--warning-suppression-mappings`` flag.
+
+Note that this mechanism won't enable any diagnostics on its own. Users should
+still turn on warnings in their compilations with explicit ``-Wfoo`` flags.
+
+Example
+===
+
+.. code-block:: bash
+
+  $ cat my/user/code.cpp
+  #include 
+  namespace { void unused_func1(); }
+
+  $ cat foo/bar.h
+  namespace { void unused_func2(); }
+
+  $ cat suppression_mappings.txt
+  # Suppress -Wunused warnings in all files, apart from the ones under `foo/`.
+  [unused]
+  src:*
+  src:*foo/*=emit
+  $ clang -Wunused --warning-suppression-mappings=suppression_mappings.txt 
my/user/code.cpp
+  # prints warning: unused function 'unused_func2', but no warnings for 
`unused_func1`.
+
+Format
+==
+
+Warning suppression mappings uses the same format as
+:doc:`SanitizerSpecialCaseList`.
+
+Users can mention sections to describe which diagnostic group behaviours to
+change. Sections are denoted as ``[unused]`` in this format. Each section name
+must match a diagnostic group.
+When a diagnostic is matched by multiple groups, the latest one takes
+precendence.
+
+Afterwards in each section, users can have multiple entities that match source
+files based on the globs. These entities look like ``src:*/my/dir/*``.
+Users can also use the ``emit`` category to exclude a subdirectory from
+suppression.
+Source files are matched against these globs either as paths relative to th
+current working directory, or as absolute paths.
+When a source file matches multiple globs, the longest one takes precendence.

kadircet wrote:

longest glob in the latest matching section. mentioned that matching still 
happens within a single section.

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


[clang] [Clang] Remove the wrong assumption when rebuilding SizeOfPackExprs for constraint normalization (PR #115120)

2024-11-07 Thread Matheus Izvekov via cfe-commits

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

LGTM, Thanks!

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


[clang] [Clang] SemaFunctionEffects: When verifying a function, ignore any conditional noexcept expression. (PR #115342)

2024-11-07 Thread Doug Wyatt via cfe-commits

https://github.com/dougsonos created 
https://github.com/llvm/llvm-project/pull/115342

Would have been part of my last PR (#142666) if I'd found it a few hours sooner.

>From a0b6093fcf24ade7ce9ee0c3d65f679a41751225 Mon Sep 17 00:00:00 2001
From: Doug Wyatt 
Date: Tue, 5 Nov 2024 13:35:50 -0800
Subject: [PATCH] [Clang] SemaFunctionEffects: When verifying a function,
 ignore any conditional noexcept expression.

---
 clang/lib/Sema/SemaFunctionEffects.cpp| 19 +--
 .../Sema/attr-nonblocking-constraints.cpp | 12 ++--
 2 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Sema/SemaFunctionEffects.cpp 
b/clang/lib/Sema/SemaFunctionEffects.cpp
index ab728f24d8a271..70f6f9b6784cd8 100644
--- a/clang/lib/Sema/SemaFunctionEffects.cpp
+++ b/clang/lib/Sema/SemaFunctionEffects.cpp
@@ -972,6 +972,7 @@ class Analyzer {
 CallableInfo &CurrentCaller;
 ViolationSite VSite;
 const Expr *TrailingRequiresClause = nullptr;
+const Expr *NoexceptExpr = nullptr;
 
 FunctionBodyASTVisitor(Analyzer &Outer,
PendingFunctionAnalysis &CurrentFunction,
@@ -986,9 +987,22 @@ class Analyzer {
   if (auto *Dtor = dyn_cast(CurrentCaller.CDecl))
 followDestructor(dyn_cast(Dtor->getParent()), Dtor);
 
-  if (auto *FD = dyn_cast(CurrentCaller.CDecl))
+  if (auto *FD = dyn_cast(CurrentCaller.CDecl)) {
 TrailingRequiresClause = FD->getTrailingRequiresClause();
 
+// Note that FD->getType->getAs() can yield a
+// noexcept Expr which has been boiled down to a constant expression.
+// Going through the TypeSourceInfo obtains the actual expression which
+// will be traversed as part of the function -- unless we capture it
+// here and have TraverseStmt skip it.
+if (TypeSourceInfo *TSI = FD->getTypeSourceInfo()) {
+  FunctionProtoTypeLoc TL =
+  TSI->getTypeLoc().getAs();
+  if (const FunctionProtoType *FPT = TL.getTypePtr())
+NoexceptExpr = FPT->getNoexceptExpr();
+}
+  }
+
   // Do an AST traversal of the function/block body
   TraverseDecl(const_cast(CurrentCaller.CDecl));
 }
@@ -1269,7 +1283,8 @@ class Analyzer {
   // We skip the traversal of lambdas (beyond their captures, see
   // TraverseLambdaExpr below), so just caching this from our constructor
   // should suffice.
-  if (Statement != TrailingRequiresClause)
+  // The exact same is true for a conditional `noexcept()` clause.
+  if (Statement != TrailingRequiresClause && Statement != NoexceptExpr)
 return Base::TraverseStmt(Statement);
   return true;
 }
diff --git a/clang/test/Sema/attr-nonblocking-constraints.cpp 
b/clang/test/Sema/attr-nonblocking-constraints.cpp
index 19a4c3b7942b12..169c42ee35fe83 100644
--- a/clang/test/Sema/attr-nonblocking-constraints.cpp
+++ b/clang/test/Sema/attr-nonblocking-constraints.cpp
@@ -388,7 +388,7 @@ void nb26() [[clang::nonblocking]] {
abort_wrapper(); // no diagnostic
 }
 
-// --- Make sure we don't traverse a requires clause. ---
+// --- Make sure we don't traverse requires and noexcept clauses. ---
 
 // Apparently some requires clauses are able to be collapsed into a constant 
before the nonblocking
 // analysis sees any function calls. This example (extracted from a real-world 
case where
@@ -420,7 +420,9 @@ class expected {
   constexpr expected()
 {}
 
+  // This is a deliberate corruption of the real implementation for simplicity.
   constexpr expected(const expected&)
+noexcept(is_copy_constructible_v<_Tp> && is_copy_constructible_v<_Err>)
 requires(is_copy_constructible_v<_Tp> && is_copy_constructible_v<_Err>)
   = default;
 };
@@ -428,11 +430,17 @@ class expected {
 void test() [[clang::nonblocking]]
 {
expected a;
-   auto b = a;
+   auto b = a;// Copy constructor.
 }
 
 } // namespace ExpectedTest
 
+// Make sure that simple type traits don't cause violations.
+
+void nb27() [[clang::nonblocking]] {
+   bool x = __is_constructible(int, const int&);
+}
+
 // --- nonblocking implies noexcept ---
 #pragma clang diagnostic warning "-Wperf-constraint-implies-noexcept"
 

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


[clang] [AMDGPU] Make `__GCC_DESTRUCTIVE_SIZE` 128 on AMDGPU (PR #115241)

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

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


[clang] Add `EvalASTMutator` interface (PR #115168)

2024-11-07 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll updated 
https://github.com/llvm/llvm-project/pull/115168

>From 5ca48e03412b1b8e9253f13356b9cc957f6fd9e5 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Wed, 6 Nov 2024 17:58:43 +0300
Subject: [PATCH 1/5] Add EvalASTMutator interface with
 `InstantiateFunctionDefinition` function

---
 clang/include/clang/AST/ASTContext.h  |  2 +-
 clang/include/clang/AST/Decl.h| 22 ++---
 clang/include/clang/AST/Expr.h|  3 +-
 clang/include/clang/Sema/Sema.h   | 17 ++
 clang/lib/AST/ASTContext.cpp  |  4 +--
 clang/lib/AST/Decl.cpp| 16 +-
 clang/lib/AST/ExprConstant.cpp| 24 +++---
 clang/lib/Sema/Sema.cpp   | 11 ++-
 clang/lib/Sema/SemaDecl.cpp   |  5 +--
 .../constexpr-function-instantiation.cpp  | 31 +++
 10 files changed, 113 insertions(+), 22 deletions(-)
 create mode 100644 clang/test/SemaCXX/constexpr-function-instantiation.cpp

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index a4d36f2eacd5d1..d143591de9f2cd 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -3258,7 +3258,7 @@ class ASTContext : public RefCountedBase {
   ///
   /// \returns true if the function/var must be CodeGen'ed/deserialized even if
   /// it is not used.
-  bool DeclMustBeEmitted(const Decl *D);
+  bool DeclMustBeEmitted(const Decl *D, EvalASTMutator *ASTMutator = nullptr);
 
   /// Visits all versions of a multiversioned function with the passed
   /// predicate.
diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 7ff35d73df5997..89a2833c82194d 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -78,6 +78,18 @@ class UnresolvedSetImpl;
 class VarTemplateDecl;
 enum class ImplicitParamKind;
 
+/// Interface that allows constant evaluator to mutate AST.
+/// When constant evaluation is triggered by Sema, it can supply a proper
+/// implementation of this interface.
+struct EvalASTMutator {
+  virtual ~EvalASTMutator() = default;
+
+  virtual void
+  InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
+FunctionDecl *Function, bool Recursive,
+bool DefinitionRequired, bool AtEndOfTU) = 0;
+};
+
 /// The top declaration context.
 class TranslationUnitDecl : public Decl,
 public DeclContext,
@@ -1355,11 +1367,12 @@ class VarDecl : public DeclaratorDecl, public 
Redeclarable {
   /// Attempt to evaluate the value of the initializer attached to this
   /// declaration, and produce notes explaining why it cannot be evaluated.
   /// Returns a pointer to the value if evaluation succeeded, 0 otherwise.
-  APValue *evaluateValue() const;
+  APValue *evaluateValue(EvalASTMutator *ASTMutator = nullptr) const;
 
 private:
   APValue *evaluateValueImpl(SmallVectorImpl &Notes,
- bool IsConstantInitialization) const;
+ bool IsConstantInitialization,
+ EvalASTMutator *ASTMutator = nullptr) const;
 
 public:
   /// Return the already-evaluated value of this variable's
@@ -1391,8 +1404,9 @@ class VarDecl : public DeclaratorDecl, public 
Redeclarable {
   /// Evaluate the initializer of this variable to determine whether it's a
   /// constant initializer. Should only be called once, after completing the
   /// definition of the variable.
-  bool checkForConstantInitialization(
-  SmallVectorImpl &Notes) const;
+  bool
+  checkForConstantInitialization(SmallVectorImpl &Notes,
+ EvalASTMutator *ASTMutator = nullptr) const;
 
   void setInitStyle(InitializationStyle Style) {
 VarDeclBits.InitStyle = Style;
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 466c65a9685ad3..ccf7fd226b5a8f 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -734,7 +734,8 @@ class Expr : public ValueStmt {
   bool EvaluateAsInitializer(APValue &Result, const ASTContext &Ctx,
  const VarDecl *VD,
  SmallVectorImpl &Notes,
- bool IsConstantInitializer) const;
+ bool IsConstantInitializer,
+ EvalASTMutator *ASTMutator = nullptr) const;
 
   /// EvaluateWithSubstitution - Evaluate an expression as if from the context
   /// of a call to the given function with the given arguments, inside an
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 93d98e1cbb9c81..1c0c6949573335 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -153,6 +153,7 @@ enum class OverloadCandidateParamOrder : char;
 enum OverloadCandidateRewri

[clang] [Clang] SemaFunctionEffects: When verifying a function, ignore any conditional noexcept expression. (PR #115342)

2024-11-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Doug Wyatt (dougsonos)


Changes

Would have been part of my last PR (#142666) if I'd found it a few 
hours sooner.

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaFunctionEffects.cpp (+17-2) 
- (modified) clang/test/Sema/attr-nonblocking-constraints.cpp (+10-2) 


``diff
diff --git a/clang/lib/Sema/SemaFunctionEffects.cpp 
b/clang/lib/Sema/SemaFunctionEffects.cpp
index ab728f24d8a271..70f6f9b6784cd8 100644
--- a/clang/lib/Sema/SemaFunctionEffects.cpp
+++ b/clang/lib/Sema/SemaFunctionEffects.cpp
@@ -972,6 +972,7 @@ class Analyzer {
 CallableInfo &CurrentCaller;
 ViolationSite VSite;
 const Expr *TrailingRequiresClause = nullptr;
+const Expr *NoexceptExpr = nullptr;
 
 FunctionBodyASTVisitor(Analyzer &Outer,
PendingFunctionAnalysis &CurrentFunction,
@@ -986,9 +987,22 @@ class Analyzer {
   if (auto *Dtor = dyn_cast(CurrentCaller.CDecl))
 followDestructor(dyn_cast(Dtor->getParent()), Dtor);
 
-  if (auto *FD = dyn_cast(CurrentCaller.CDecl))
+  if (auto *FD = dyn_cast(CurrentCaller.CDecl)) {
 TrailingRequiresClause = FD->getTrailingRequiresClause();
 
+// Note that FD->getType->getAs() can yield a
+// noexcept Expr which has been boiled down to a constant expression.
+// Going through the TypeSourceInfo obtains the actual expression which
+// will be traversed as part of the function -- unless we capture it
+// here and have TraverseStmt skip it.
+if (TypeSourceInfo *TSI = FD->getTypeSourceInfo()) {
+  FunctionProtoTypeLoc TL =
+  TSI->getTypeLoc().getAs();
+  if (const FunctionProtoType *FPT = TL.getTypePtr())
+NoexceptExpr = FPT->getNoexceptExpr();
+}
+  }
+
   // Do an AST traversal of the function/block body
   TraverseDecl(const_cast(CurrentCaller.CDecl));
 }
@@ -1269,7 +1283,8 @@ class Analyzer {
   // We skip the traversal of lambdas (beyond their captures, see
   // TraverseLambdaExpr below), so just caching this from our constructor
   // should suffice.
-  if (Statement != TrailingRequiresClause)
+  // The exact same is true for a conditional `noexcept()` clause.
+  if (Statement != TrailingRequiresClause && Statement != NoexceptExpr)
 return Base::TraverseStmt(Statement);
   return true;
 }
diff --git a/clang/test/Sema/attr-nonblocking-constraints.cpp 
b/clang/test/Sema/attr-nonblocking-constraints.cpp
index 19a4c3b7942b12..169c42ee35fe83 100644
--- a/clang/test/Sema/attr-nonblocking-constraints.cpp
+++ b/clang/test/Sema/attr-nonblocking-constraints.cpp
@@ -388,7 +388,7 @@ void nb26() [[clang::nonblocking]] {
abort_wrapper(); // no diagnostic
 }
 
-// --- Make sure we don't traverse a requires clause. ---
+// --- Make sure we don't traverse requires and noexcept clauses. ---
 
 // Apparently some requires clauses are able to be collapsed into a constant 
before the nonblocking
 // analysis sees any function calls. This example (extracted from a real-world 
case where
@@ -420,7 +420,9 @@ class expected {
   constexpr expected()
 {}
 
+  // This is a deliberate corruption of the real implementation for simplicity.
   constexpr expected(const expected&)
+noexcept(is_copy_constructible_v<_Tp> && is_copy_constructible_v<_Err>)
 requires(is_copy_constructible_v<_Tp> && is_copy_constructible_v<_Err>)
   = default;
 };
@@ -428,11 +430,17 @@ class expected {
 void test() [[clang::nonblocking]]
 {
expected a;
-   auto b = a;
+   auto b = a;// Copy constructor.
 }
 
 } // namespace ExpectedTest
 
+// Make sure that simple type traits don't cause violations.
+
+void nb27() [[clang::nonblocking]] {
+   bool x = __is_constructible(int, const int&);
+}
+
 // --- nonblocking implies noexcept ---
 #pragma clang diagnostic warning "-Wperf-constraint-implies-noexcept"
 

``




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


[clang] [clang] Introduce [[clang::lifetime_capture_by(X)]] (PR #111499)

2024-11-07 Thread Gábor Horváth via cfe-commits


@@ -12,6 +12,7 @@
 
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Attr.h"
+#include "clang/AST/Attrs.inc"

Xazax-hun wrote:

Is this include intended?

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


[clang] [clang][docs] Revise documentation for `__builtin_reduce_(max|min)`. (PR #114637)

2024-11-07 Thread via cfe-commits

https://github.com/c8ef updated https://github.com/llvm/llvm-project/pull/114637

>From 13d9d0771b666c5ba2262004f45dcbe34e6fd893 Mon Sep 17 00:00:00 2001
From: c8ef 
Date: Sat, 2 Nov 2024 11:53:54 +0800
Subject: [PATCH 1/3] Update LanguageExtensions.rst

---
 clang/docs/LanguageExtensions.rst | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 10232ff41da15a..b7676bab623ef8 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -745,12 +745,8 @@ Let ``VT`` be a vector type and ``ET`` the element type of 
``VT``.
 === 
== 
==
  NameOperation 
 Supported element types
 === 
== 
==
- ET __builtin_reduce_max(VT a)   return x or y, whichever is larger; 
If exactly one argument is integer and floating point types
- a NaN, return the other argument. If 
both arguments are NaNs,
- fmax() return a NaN.
- ET __builtin_reduce_min(VT a)   return x or y, whichever is smaller; 
If exactly one argument   integer and floating point types
- is a NaN, return the other argument. 
If both arguments are
- NaNs, fmax() return a NaN.
+ ET __builtin_reduce_max(VT a)   return the largest element of the 
vector.  integer and floating point types
+ ET __builtin_reduce_min(VT a)   return the smallest element of the 
vector. integer and floating point types
  ET __builtin_reduce_add(VT a)   \+
 integer types
  ET __builtin_reduce_mul(VT a)   \*
 integer types
  ET __builtin_reduce_and(VT a)   & 
 integer types

>From 2a7cb73cb24cc3c32a3fe14401b7051db8bad8a2 Mon Sep 17 00:00:00 2001
From: c8ef 
Date: Sun, 3 Nov 2024 20:28:01 +0800
Subject: [PATCH 2/3] Update LanguageExtensions.rst

---
 clang/docs/LanguageExtensions.rst | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index b7676bab623ef8..e4157d59e3892c 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -745,8 +745,12 @@ Let ``VT`` be a vector type and ``ET`` the element type of 
``VT``.
 === 
== 
==
  NameOperation 
 Supported element types
 === 
== 
==
- ET __builtin_reduce_max(VT a)   return the largest element of the 
vector.  integer and floating point types
- ET __builtin_reduce_min(VT a)   return the smallest element of the 
vector. integer and floating point types
+ ET __builtin_reduce_max(VT a)   return the largest element of the 
vector. If the element type is   integer and floating point types
+ floating point, this function has the 
same comparison semantics as 
+ ``__builtin_reduce_maximum``.
+ ET __builtin_reduce_min(VT a)   return the smallest element of the 
vector. If the element type is  integer and floating point types
+ floating point, this function has the 
same comparison semantics as 
+ ``__builtin_reduce_minimum``.
  ET __builtin_reduce_add(VT a)   \+
 integer types
  ET __builtin_reduce_mul(VT a)   \*
 integer types
  ET __builtin_reduce_and(VT a)   & 
 integer types

>From b4863a5e3ed5d759f169196d459227f8706c715e Mon Sep 17 00:00:00 2001
From: c8ef 
Date: Thu, 7 Nov 2024 23:35:30 +0800
Subject: [PATCH 3/3] Update LanguageExtensions.rst

---
 clang/docs/LanguageExtensions.rst | 10 --
 1 file changed, 4 in

[clang] [Clang] skip default argument instantiation for non-defining friend declarations without specialization info to meet [dcl.fct.default] p4 (PR #113777)

2024-11-07 Thread Matheus Izvekov via cfe-commits

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


[libclc] 6ca50a2 - [libclc] Correct use of CLC macro on two definitions

2024-11-07 Thread Fraser Cormack via cfe-commits

Author: Fraser Cormack
Date: 2024-11-07T17:47:52Z
New Revision: 6ca50a2593641f45b5310d907e6323f5eb367dfa

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

LOG: [libclc] Correct use of CLC macro on two definitions

_CLC_DECL is for declarations and _CLC_DEF for definitions, as the names
imply.

No change to any bitcode module.

Added: 


Modified: 
libclc/generic/lib/relational/binary_def.inc
libclc/generic/lib/relational/unary_def.inc

Removed: 




diff  --git a/libclc/generic/lib/relational/binary_def.inc 
b/libclc/generic/lib/relational/binary_def.inc
index 3ed68be142d005..e1ee9de7f84c2f 100644
--- a/libclc/generic/lib/relational/binary_def.inc
+++ b/libclc/generic/lib/relational/binary_def.inc
@@ -2,6 +2,6 @@
 
 #define __CLC_FUNCTION(x) __CLC_CONCAT(__clc_, x)
 
-_CLC_OVERLOAD _CLC_DECL __CLC_INTN FUNCTION(__CLC_FLOATN a, __CLC_FLOATN b) {
+_CLC_OVERLOAD _CLC_DEF __CLC_INTN FUNCTION(__CLC_FLOATN a, __CLC_FLOATN b) {
   return __CLC_FUNCTION(FUNCTION)(a, b);
 }

diff  --git a/libclc/generic/lib/relational/unary_def.inc 
b/libclc/generic/lib/relational/unary_def.inc
index dd9fe48731f969..0bec35804af9cd 100644
--- a/libclc/generic/lib/relational/unary_def.inc
+++ b/libclc/generic/lib/relational/unary_def.inc
@@ -2,6 +2,6 @@
 
 #define __CLC_FUNCTION(x) __CLC_CONCAT(__clc_, x)
 
-_CLC_OVERLOAD _CLC_DECL __CLC_INTN FUNCTION(__CLC_FLOATN a) {
+_CLC_OVERLOAD _CLC_DEF __CLC_INTN FUNCTION(__CLC_FLOATN a) {
   return __CLC_FUNCTION(FUNCTION)(a);
 }



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


[clang] 4fb953a - [AMDGPU] Make `__GCC_DESTRUCTIVE_SIZE` 128 on AMDGPU (#115241)

2024-11-07 Thread via cfe-commits

Author: Joseph Huber
Date: 2024-11-07T04:59:58-08:00
New Revision: 4fb953ac348d888541efe515439e0d844cdd7fbf

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

LOG: [AMDGPU] Make `__GCC_DESTRUCTIVE_SIZE` 128 on AMDGPU (#115241)

Summary:
The cache line size on AMDGPU varies between 64 and 128 (The lowest L2
cache also goes to 256 on some architectures.) This macro is intended to
present a size that will not cause destructive interference, so we
choose the larger of those values.

Added: 


Modified: 
clang/lib/Basic/Targets/AMDGPU.h
clang/test/Driver/amdgpu-macros.cl

Removed: 




diff  --git a/clang/lib/Basic/Targets/AMDGPU.h 
b/clang/lib/Basic/Targets/AMDGPU.h
index 6edd3474d4edae..fac46f215a3736 100644
--- a/clang/lib/Basic/Targets/AMDGPU.h
+++ b/clang/lib/Basic/Targets/AMDGPU.h
@@ -462,6 +462,14 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : 
public TargetInfo {
   }
 
   bool hasHIPImageSupport() const override { return HasImage; }
+
+  std::pair hardwareInterferenceSizes() const override {
+// This is imprecise as the value can vary between 64, 128 (even 256!) 
bytes
+// depending on the level of cache and the target architecture. We select
+// the size that corresponds to the largest L1 cache line for all
+// architectures.
+return std::make_pair(128, 128);
+  }
 };
 
 } // namespace targets

diff  --git a/clang/test/Driver/amdgpu-macros.cl 
b/clang/test/Driver/amdgpu-macros.cl
index dd5a4483e4d607..2fedd10bb53445 100644
--- a/clang/test/Driver/amdgpu-macros.cl
+++ b/clang/test/Driver/amdgpu-macros.cl
@@ -153,6 +153,8 @@
 // ARCH-GCN-DAG: #define __[[FAMILY]]__ 1
 // ARCH-GCN-DAG: #define __amdgcn_processor__ "[[CPU]]"
 // ARCH-GCN-DAG: #define __AMDGCN_WAVEFRONT_SIZE [[WAVEFRONT_SIZE]]
+// ARCH-GCN-DAG: #define __GCC_DESTRUCTIVE_SIZE 128
+// ARCH-GCN-DAG: #define __GCC_CONSTRUCTIVE_SIZE 128
 // UNSAFEFPATOMIC-DAG: #define __AMDGCN_UNSAFE_FP_ATOMICS__ 1
 
 // RUN: %clang -E -dM -target amdgcn -mcpu=gfx906 -mwavefrontsize64 \



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


[clang] [compiler-rt] [llvm] [FMV][AArch64] Remove features which expose non exploitable runtime behavior. (PR #114387)

2024-11-07 Thread Alexandros Lamprineas via cfe-commits


@@ -45,8 +45,6 @@ static void __init_cpu_features_constructor(unsigned long 
hwcap,
 setCPUFeature(FEAT_SSBS2);
   if (hwcap2 & HWCAP2_MTE)
 setCPUFeature(FEAT_MEMTAG2);
-  if (hwcap2 & HWCAP2_MTE3)

labrinea wrote:

There are no uses of the removed features in other targets.

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


[clang] [clang] Introduce [[clang::lifetime_capture_by(X)]] (PR #111499)

2024-11-07 Thread Gábor Horváth via cfe-commits


@@ -1199,6 +1213,17 @@ static void checkExprLifetimeImpl(Sema &SemaRef,
   break;
 }
 
+case LK_LifetimeCapture: {
+  if (!MTE)

Xazax-hun wrote:

Do we want to diagnose the following case:
```
std::set set;
void addToSet(std::string_view s [[clang::lifetime_capture_by()]]) {
   set.insert(s);
}
void f() {
  std::string local;
  addToSet(local);
}
```
?

I think we don't have an MTE here. It is OK to cover this in a follow-up. 

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


[clang] [clang] Introduce [[clang::lifetime_capture_by(X)]] (PR #111499)

2024-11-07 Thread Gábor Horváth via cfe-commits


@@ -45,10 +48,14 @@ enum LifetimeKind {
   /// a default member initializer), the program is ill-formed.
   LK_MemInitializer,
 
-  /// The lifetime of a temporary bound to this entity probably ends too soon,
+  /// The lifetime of a temporary bound to this entity may end too soon,
   /// because the entity is a pointer and we assign the address of a temporary
   /// object to it.
   LK_Assignment,
+
+  /// The lifetime of a temporary bound to this entity may end too soon,

Xazax-hun wrote:

Probably out of scope for this PR, but are these comments up to date given that 
we can also warn when the address of a local escapes the function (as opposed 
to just temporaries)?

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


[clang] [clang] Introduce [[clang::lifetime_capture_by(X)]] (PR #111499)

2024-11-07 Thread Gábor Horváth via cfe-commits


@@ -1873,6 +1873,46 @@ def LifetimeBound : DeclOrTypeAttr {
   let SimpleHandler = 1;
 }
 
+def LifetimeCaptureBy : DeclOrTypeAttr {
+  let Spellings = [Clang<"lifetime_capture_by", 0>];
+  let Subjects = SubjectList<[ParmVar, ImplicitObjectParameter], ErrorDiag>;
+  let Args = [VariadicParamOrParamIdxArgument<"Params">];
+  let Documentation = [LifetimeBoundDocs];
+  let LangOpts = [CPlusPlus];
+
+  // let SimpleHandler = 1;
+  // let LateParsed = LateAttrParseStandard;
+  // let HasCustomParsing = 1;
+  // let ParseArgumentsAsUnevaluated = 1;
+
+  let AdditionalMembers = [{
+private:
+  SmallVector ArgIdents;
+  SmallVector ArgLocs;
+
+public:
+  static constexpr int INVALID = -2;
+  static constexpr int UNKNOWN = -1;
+  static constexpr int GLOBAL = -1;
+  static constexpr int THIS = 0;

Xazax-hun wrote:

I wish we had one universal way of indexing parameters in Clang. I think 
probably most attributes start from 1, but there are APINotes that start from 
0. Not really an actionable comment here, more like a rant. 

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


[clang] bf30b6c - [HLSL][SPIRV][DXIL] Implement `dot4add_u8packed` intrinsic (#115068)

2024-11-07 Thread via cfe-commits

Author: Finn Plummer
Date: 2024-11-07T10:19:41-08:00
New Revision: bf30b6c33c17d43402d23f8cade450437fcff800

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

LOG: [HLSL][SPIRV][DXIL] Implement `dot4add_u8packed` intrinsic (#115068)

```- create a clang built-in in Builtins.td
- link dot4add_u8packed in hlsl_intrinsics.h
- add lowering to spirv backend through expansion of operation as OpUDot is 
missing up to SPIRV 1.6 in SPIRVInstructionSelector.cpp
- add lowering to spirv backend using OpUDot if applicable SPIRV version or 
SPV_KHR_integer_dot_product is enabled
- add dot4add_u8packed intrinsic to IntrinsicsDirectX.td and mapping to DXIL.td 
op Dot4AddU8Packed

- add tests for HLSL intrinsic lowering to dx/spv intrinsic in 
dot4add_u8packed.hlsl
- add tests for sema checks in dot4add_u8packed-errors.hlsl
- add test of spir-v lowering in SPIRV/dot4add_u8packed.ll
- add test to dxil lowering in DirectX/dot4add_u8packed.ll
```

Resolves #99219

Added: 
clang/test/CodeGenHLSL/builtins/dot4add_u8packed.hlsl
clang/test/SemaHLSL/BuiltIns/dot4add_u8packed-errors.hlsl
llvm/test/CodeGen/DirectX/dot4add_u8packed.ll
llvm/test/CodeGen/SPIRV/hlsl-intrinsics/dot4add_u8packed.ll

Modified: 
clang/include/clang/Basic/Builtins.td
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CGHLSLRuntime.h
clang/lib/Headers/hlsl/hlsl_intrinsics.h
llvm/include/llvm/IR/IntrinsicsDirectX.td
llvm/include/llvm/IR/IntrinsicsSPIRV.td
llvm/lib/Target/DirectX/DXIL.td
llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 87a798183d6e19..e484c3969fe228 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4798,6 +4798,12 @@ def HLSLDot4AddI8Packed : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "int(unsigned int, unsigned int, int)";
 }
 
+def HLSLDot4AddU8Packed : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_dot4add_u8packed"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "unsigned int(unsigned int, unsigned int, unsigned int)";
+}
+
 def HLSLFirstBitHigh : LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_elementwise_firstbithigh"];
   let Attributes = [NoThrow, Const];

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 5c3df5124517d6..0ef9058640db6a 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18881,6 +18881,16 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 /*ReturnType=*/C->getType(), ID, ArrayRef{A, B, C}, nullptr,
 "hlsl.dot4add.i8packed");
   }
+  case Builtin::BI__builtin_hlsl_dot4add_u8packed: {
+Value *A = EmitScalarExpr(E->getArg(0));
+Value *B = EmitScalarExpr(E->getArg(1));
+Value *C = EmitScalarExpr(E->getArg(2));
+
+Intrinsic::ID ID = CGM.getHLSLRuntime().getDot4AddU8PackedIntrinsic();
+return Builder.CreateIntrinsic(
+/*ReturnType=*/C->getType(), ID, ArrayRef{A, B, C}, nullptr,
+"hlsl.dot4add.u8packed");
+  }
   case Builtin::BI__builtin_hlsl_elementwise_firstbithigh: {
 
 Value *X = EmitScalarExpr(E->getArg(0));

diff  --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index ff810cc535c087..caf8777fd95a9f 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -90,6 +90,7 @@ class CGHLSLRuntime {
   GENERATE_HLSL_INTRINSIC_FUNCTION(SDot, sdot)
   GENERATE_HLSL_INTRINSIC_FUNCTION(UDot, udot)
   GENERATE_HLSL_INTRINSIC_FUNCTION(Dot4AddI8Packed, dot4add_i8packed)
+  GENERATE_HLSL_INTRINSIC_FUNCTION(Dot4AddU8Packed, dot4add_u8packed)
   GENERATE_HLSL_INTRINSIC_FUNCTION(WaveIsFirstLane, wave_is_first_lane)
   GENERATE_HLSL_INTRINSIC_FUNCTION(WaveReadLaneAt, wave_readlane)
   GENERATE_HLSL_INTRINSIC_FUNCTION(FirstBitUHigh, firstbituhigh)

diff  --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 12d3aa418449c0..2ee3827d720495 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -942,7 +942,13 @@ uint64_t dot(uint64_t4, uint64_t4);
 
 _HLSL_AVAILABILITY(shadermodel, 6.4)
 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot4add_i8packed)
-int dot4add_i8packed(unsigned int, unsigned int, int);
+int dot4add_i8packed(uint, uint, int);
+
+/// \fn uint dot4add_u8packed(uint A, uint B, uint C)
+
+_HLSL_AVAILABILITY(shadermodel, 6.4)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_dot4add_u8packed)
+uint dot4add_u8packed(uint, uint, uint);
 
 
//===--===//
 // exp builtins

diff  --git a/clang/test/CodeGenHLSL/builtins/dot4add_

[clang] [llvm] [HLSL][SPIRV][DXIL] Implement `dot4add_u8packed` intrinsic (PR #115068)

2024-11-07 Thread Finn Plummer via cfe-commits

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


[clang] [Webkit Checkers] Introduce a Webkit checker for memory unsafe casts (PR #114606)

2024-11-07 Thread Ryosuke Niwa via cfe-commits

rniwa wrote:

Hm... I'm still hitting a crash. In debug builds, we hit this assertion:
```
Assertion failed: (DD && "queried property of class with no definition"), 
function data, file DeclCXX.h, line 452.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and 
include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.  Program arguments: /Volumes/Data/llvm-project/build-debug/bin/clang-17 
-x c++ -target x86_64-apple-macos14.0 -fmessage-length=0 
-fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -std=c++2b 
-stdlib=libc++ -Wno-trigraphs -fno-exceptions -fno-rtti -fno-sanitize=vptr 
-fpascal-strings -O0 -fno-common -Werror -Wno-missing-field-initializers 
-Wno-missing-prototypes -Wno-non-virtual-dtor -Wno-overloaded-virtual 
-Wno-exit-time-destructors -Wno-missing-braces -Wparentheses -Wswitch 
-Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable 
-Wunused-value -Wempty-body -Wuninitialized -Wno-unknown-pragmas -Wno-shadow 
-Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion 
-Wbool-conversion -Wenum-conversion -Wno-float-conversion 
-Wnon-literal-null-conversion -Wobjc-literal-conversion -Wno-shorten-64-to-32 
-Wnewline-eof -Wno-c++11-extensions -Wno-implicit-fallthrough 
-DCLANG_WEBKIT_BRANCH=1 -DOPENSSL_NO_ASM -DABSL_ALLOCATOR_NOTHROW 
-DWEBRTC_WEBKIT_BUILD -isysroot 
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk
 -fasm-blocks -fstrict-aliasing -Wdeprecated-declarations -Winvalid-offsetof -g 
-fvisibility=hidden -fvisibility-inlines-hidden -Wno-sign-conversion 
-Winfinite-recursion -Wmove -Wno-comma -Wblock-capture-autoreleasing 
-Wstrict-prototypes -Wno-range-loop-analysis -Wno-semicolon-before-method-body 
-D__clang_analyzer__ -Xclang -analyzer-output=html -Xclang -analyzer-config 
-Xclang report-in-main-source-file=true -Xclang -analyzer-config -Xclang 
nullability:NoDiagnoseCallsToSystemHeaders=true -Xclang -analyzer-checker 
-Xclang optin.osx.cocoa.localizability.NonLocalizedStringChecker -Xclang 
-analyzer-checker -Xclang security.insecureAPI.UncheckedReturn -Xclang 
-analyzer-checker -Xclang security.insecureAPI.getpw -Xclang -analyzer-checker 
-Xclang security.insecureAPI.gets -Xclang -analyzer-checker -Xclang 
security.insecureAPI.mkstemp -Xclang -analyzer-checker -Xclang 
security.insecureAPI.mktemp -Xclang -analyzer-disable-checker -Xclang 
security.insecureAPI.rand -Xclang -analyzer-disable-checker -Xclang 
security.insecureAPI.strcpy -Xclang -analyzer-checker -Xclang 
security.insecureAPI.vfork -Xclang -analyzer-disable-checker -Xclang 
alpha,apiModeling,core,cplusplus,deadcode,debug,fuchsia,nullability,optin,osx,security,unix,webkit
 -Xclang -analyzer-checker -Xclang 
alpha.webkit.MemoryUnsafeCastChecker,alpha.webkit.NoUncheckedPtrMemberChecker,alpha.webkit.UncountedCallArgsChecker,alpha.webkit.UncountedLocalVarsChecker,webkit.NoUncountedMemberChecker,webkit.RefCntblBaseVirtualDtor
 -Xclang -analyzer-config -Xclang max-nodes=1000 -Xclang -analyzer-config 
-Xclang verbose-report-filename=true 
-I/Volumes/Data/safari-4/OpenSource/WebKitBuild/Debug/include 
-ISource/third_party/boringssl/src/include 
-I/Volumes/Data/safari-4/OpenSource/WebKitBuild/libwebrtc.build/Debug/boringssl.build/DerivedSources-normal/x86_64
 
-I/Volumes/Data/safari-4/OpenSource/WebKitBuild/libwebrtc.build/Debug/boringssl.build/DerivedSources/x86_64
 
-I/Volumes/Data/safari-4/OpenSource/WebKitBuild/libwebrtc.build/Debug/boringssl.build/DerivedSources
 -Wall -Wc99-designator -Wconditional-uninitialized -Wextra 
-Wdeprecated-enum-enum-conversion -Wdeprecated-enum-float-conversion 
-Wenum-float-conversion -Wfinal-dtor-non-final-class -Wformat=2 
-Wmisleading-indentation -Wreorder-init-list -Wundef -Wvla 
-Wno-elaborated-enum-base -Wthread-safety -Wno-conditional-uninitialized 
-Wno-missing-field-initializers -Wno-sign-compare -Wno-undef 
-Wno-unknown-warning-option -Wno-unused-but-set-parameter -Wno-unused-parameter 
-Wno-array-parameter -Wno-unused-but-set-variable 
-Wno-thread-safety-reference-return -Wno-vla -Wexit-time-destructors 
-Wglobal-constructors -F/Volumes/Data/safari-4/OpenSource/WebKitBuild/Debug 
-fvisibility=default -D_LIBCPP_ENABLE_ASSERTIONS=1 -isystem 
/Volumes/Data/safari-4/OpenSource/WebKitLibraries/SDKs/macosx14.0-additions.sdk/usr/local/include
 -MMD -MT dependencies -MF 
/Volumes/Data/safari-4/analyzer-output/StaticAnalyzer/libwebrtc/boringssl/normal/x86_64/tls_record.d
 --analyze 
/Volumes/Data/safari-4/OpenSource/Source/ThirdParty/libwebrtc/Source/third_party/boringssl/src/ssl/tls_record.cc
 -o 
/Volumes/Data/safari-4/analyzer-output/StaticAnalyzer/libwebrtc/boringssl/normal/x86_64/tls_record.plist
1.   parser at end of file
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH 
or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  clang-17 0x00011390

[clang] [Clang][RISCV] Remove forced-sw-shadow-stack (PR #115355)

2024-11-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jesse Huang (jaidTw)


Changes

This option was used to override the behavior of `-fsanitize=shadowcallstack` 
on RISC-V backend, which by default use a hardware implementation if possible, 
to use the software implementation instead. After 
https://github.com/llvm/llvm-project/pull/112477 and 
https://github.com/llvm/llvm-project/pull/112478, now two implementation is 
represented by independent options and we no longer need it.

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


3 Files Affected:

- (modified) clang/docs/ShadowCallStack.rst (+4-5) 
- (modified) clang/include/clang/Driver/Options.td (-4) 
- (modified) clang/test/Driver/riscv-features.c (-6) 


``diff
diff --git a/clang/docs/ShadowCallStack.rst b/clang/docs/ShadowCallStack.rst
index d7ece11b352606..fc8bea83e11452 100644
--- a/clang/docs/ShadowCallStack.rst
+++ b/clang/docs/ShadowCallStack.rst
@@ -59,11 +59,10 @@ and destruction would need to be intercepted by the 
application.
 
 The instrumentation makes use of the platform register ``x18`` on AArch64,
 ``x3`` (``gp``) on RISC-V with software shadow stack and ``ssp`` on RISC-V with
-hardware shadow stack, which needs `Zicfiss`_ and 
``-mno-forced-sw-shadow-stack``
-(default option). Note that with ``Zicfiss``_ the RISC-V backend will default 
to
-the hardware based shadow call stack. Users can force the RISC-V backend to
-generate the software shadow call stack with ``Zicfiss``_ by passing
-``-mforced-sw-shadow-stack``.
+hardware shadow stack, which needs `Zicfiss`_ and ``-fcf-protection=return``.
+Users can choose between the software and hardware based shadow stack
+implementation on RISC-V backend by passing ``-fsanitize=shadowcallstack``
+or ``Zicfiss`` with ``-fcf-protection=return``.
 For simplicity we will refer to this as the ``SCSReg``. On some platforms,
 ``SCSReg`` is reserved, and on others, it is designated as a scratch register.
 This generally means that any code that may run on the same thread as code
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 805b79491e6ea4..8887e0c1495d2a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4930,10 +4930,6 @@ def msave_restore : Flag<["-"], "msave-restore">, 
Group,
   HelpText<"Enable using library calls for save and restore">;
 def mno_save_restore : Flag<["-"], "mno-save-restore">, 
Group,
   HelpText<"Disable using library calls for save and restore">;
-def mforced_sw_shadow_stack : Flag<["-"], "mforced-sw-shadow-stack">, 
Group,
-  HelpText<"Force using software shadow stack when shadow-stack enabled">;
-def mno_forced_sw_shadow_stack : Flag<["-"], "mno-forced-sw-shadow-stack">, 
Group,
-  HelpText<"Not force using software shadow stack when shadow-stack enabled">;
 } // let Flags = [TargetSpecific]
 let Flags = [TargetSpecific] in {
 def menable_experimental_extensions : Flag<["-"], 
"menable-experimental-extensions">, Group,
diff --git a/clang/test/Driver/riscv-features.c 
b/clang/test/Driver/riscv-features.c
index b4fad5177c5f76..b58ec3b523e5c1 100644
--- a/clang/test/Driver/riscv-features.c
+++ b/clang/test/Driver/riscv-features.c
@@ -29,12 +29,6 @@
 // DEFAULT-NOT: "-target-feature" "-save-restore"
 // DEFAULT-NOT: "-target-feature" "+save-restore"
 
-// RUN: %clang --target=riscv32-unknown-elf -### %s -mforced-sw-shadow-stack 
2>&1 | FileCheck %s -check-prefix=FORCE-SW-SCS
-// RUN: %clang --target=riscv32-unknown-elf -### %s 
-mno-forced-sw-shadow-stack 2>&1 | FileCheck %s -check-prefix=NO-FORCE-SW-SCS
-// FORCE-SW-SCS: "-target-feature" "+forced-sw-shadow-stack"
-// NO-FORCE-SW-SCS: "-target-feature" "-forced-sw-shadow-stack"
-// DEFAULT-NOT: "-target-feature" "+forced-sw-shadow-stack"
-
 // RUN: %clang --target=riscv32-unknown-elf -### %s -mno-strict-align 2>&1 | 
FileCheck %s 
-check-prefixes=FAST-SCALAR-UNALIGNED-ACCESS,FAST-VECTOR-UNALIGNED-ACCESS
 // RUN: %clang --target=riscv32-unknown-elf -### %s -mstrict-align 2>&1 | 
FileCheck %s 
-check-prefixes=NO-FAST-SCALAR-UNALIGNED-ACCESS,NO-FAST-VECTOR-UNALIGNED-ACCESS
 // RUN: %clang --target=riscv32-unknown-elf -### %s -mno-scalar-strict-align 
2>&1 | FileCheck %s -check-prefix=FAST-SCALAR-UNALIGNED-ACCESS

``




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


[clang] [Clang][RISCV] Remove forced-sw-shadow-stack (PR #115355)

2024-11-07 Thread Jesse Huang via cfe-commits

https://github.com/jaidTw created 
https://github.com/llvm/llvm-project/pull/115355

This option was used to override the behavior of `-fsanitize=shadowcallstack` 
on RISC-V backend, which by default use a hardware implementation if possible, 
to use the software implementation instead. After 
https://github.com/llvm/llvm-project/pull/112477 and 
https://github.com/llvm/llvm-project/pull/112478, now two implementation is 
represented by independent options and we no longer need it.

>From d9203fbbcacf509defab5b7e8fb7816d2819f121 Mon Sep 17 00:00:00 2001
From: Jesse Huang 
Date: Fri, 8 Nov 2024 01:34:20 +0800
Subject: [PATCH] [Clang][RISCV] Remove forced-sw-shadow-stack After the
 separation of hardware and software shadow stack options, we no longer need
 this option.

---
 clang/docs/ShadowCallStack.rst| 9 -
 clang/include/clang/Driver/Options.td | 4 
 clang/test/Driver/riscv-features.c| 6 --
 3 files changed, 4 insertions(+), 15 deletions(-)

diff --git a/clang/docs/ShadowCallStack.rst b/clang/docs/ShadowCallStack.rst
index d7ece11b352606..fc8bea83e11452 100644
--- a/clang/docs/ShadowCallStack.rst
+++ b/clang/docs/ShadowCallStack.rst
@@ -59,11 +59,10 @@ and destruction would need to be intercepted by the 
application.
 
 The instrumentation makes use of the platform register ``x18`` on AArch64,
 ``x3`` (``gp``) on RISC-V with software shadow stack and ``ssp`` on RISC-V with
-hardware shadow stack, which needs `Zicfiss`_ and 
``-mno-forced-sw-shadow-stack``
-(default option). Note that with ``Zicfiss``_ the RISC-V backend will default 
to
-the hardware based shadow call stack. Users can force the RISC-V backend to
-generate the software shadow call stack with ``Zicfiss``_ by passing
-``-mforced-sw-shadow-stack``.
+hardware shadow stack, which needs `Zicfiss`_ and ``-fcf-protection=return``.
+Users can choose between the software and hardware based shadow stack
+implementation on RISC-V backend by passing ``-fsanitize=shadowcallstack``
+or ``Zicfiss`` with ``-fcf-protection=return``.
 For simplicity we will refer to this as the ``SCSReg``. On some platforms,
 ``SCSReg`` is reserved, and on others, it is designated as a scratch register.
 This generally means that any code that may run on the same thread as code
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 805b79491e6ea4..8887e0c1495d2a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4930,10 +4930,6 @@ def msave_restore : Flag<["-"], "msave-restore">, 
Group,
   HelpText<"Enable using library calls for save and restore">;
 def mno_save_restore : Flag<["-"], "mno-save-restore">, 
Group,
   HelpText<"Disable using library calls for save and restore">;
-def mforced_sw_shadow_stack : Flag<["-"], "mforced-sw-shadow-stack">, 
Group,
-  HelpText<"Force using software shadow stack when shadow-stack enabled">;
-def mno_forced_sw_shadow_stack : Flag<["-"], "mno-forced-sw-shadow-stack">, 
Group,
-  HelpText<"Not force using software shadow stack when shadow-stack enabled">;
 } // let Flags = [TargetSpecific]
 let Flags = [TargetSpecific] in {
 def menable_experimental_extensions : Flag<["-"], 
"menable-experimental-extensions">, Group,
diff --git a/clang/test/Driver/riscv-features.c 
b/clang/test/Driver/riscv-features.c
index b4fad5177c5f76..b58ec3b523e5c1 100644
--- a/clang/test/Driver/riscv-features.c
+++ b/clang/test/Driver/riscv-features.c
@@ -29,12 +29,6 @@
 // DEFAULT-NOT: "-target-feature" "-save-restore"
 // DEFAULT-NOT: "-target-feature" "+save-restore"
 
-// RUN: %clang --target=riscv32-unknown-elf -### %s -mforced-sw-shadow-stack 
2>&1 | FileCheck %s -check-prefix=FORCE-SW-SCS
-// RUN: %clang --target=riscv32-unknown-elf -### %s 
-mno-forced-sw-shadow-stack 2>&1 | FileCheck %s -check-prefix=NO-FORCE-SW-SCS
-// FORCE-SW-SCS: "-target-feature" "+forced-sw-shadow-stack"
-// NO-FORCE-SW-SCS: "-target-feature" "-forced-sw-shadow-stack"
-// DEFAULT-NOT: "-target-feature" "+forced-sw-shadow-stack"
-
 // RUN: %clang --target=riscv32-unknown-elf -### %s -mno-strict-align 2>&1 | 
FileCheck %s 
-check-prefixes=FAST-SCALAR-UNALIGNED-ACCESS,FAST-VECTOR-UNALIGNED-ACCESS
 // RUN: %clang --target=riscv32-unknown-elf -### %s -mstrict-align 2>&1 | 
FileCheck %s 
-check-prefixes=NO-FAST-SCALAR-UNALIGNED-ACCESS,NO-FAST-VECTOR-UNALIGNED-ACCESS
 // RUN: %clang --target=riscv32-unknown-elf -### %s -mno-scalar-strict-align 
2>&1 | FileCheck %s -check-prefix=FAST-SCALAR-UNALIGNED-ACCESS

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


[clang] [Clang][RISCV] Remove forced-sw-shadow-stack (PR #115355)

2024-11-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Jesse Huang (jaidTw)


Changes

This option was used to override the behavior of `-fsanitize=shadowcallstack` 
on RISC-V backend, which by default use a hardware implementation if possible, 
to use the software implementation instead. After 
https://github.com/llvm/llvm-project/pull/112477 and 
https://github.com/llvm/llvm-project/pull/112478, now two implementation is 
represented by independent options and we no longer need it.

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


3 Files Affected:

- (modified) clang/docs/ShadowCallStack.rst (+4-5) 
- (modified) clang/include/clang/Driver/Options.td (-4) 
- (modified) clang/test/Driver/riscv-features.c (-6) 


``diff
diff --git a/clang/docs/ShadowCallStack.rst b/clang/docs/ShadowCallStack.rst
index d7ece11b352606..fc8bea83e11452 100644
--- a/clang/docs/ShadowCallStack.rst
+++ b/clang/docs/ShadowCallStack.rst
@@ -59,11 +59,10 @@ and destruction would need to be intercepted by the 
application.
 
 The instrumentation makes use of the platform register ``x18`` on AArch64,
 ``x3`` (``gp``) on RISC-V with software shadow stack and ``ssp`` on RISC-V with
-hardware shadow stack, which needs `Zicfiss`_ and 
``-mno-forced-sw-shadow-stack``
-(default option). Note that with ``Zicfiss``_ the RISC-V backend will default 
to
-the hardware based shadow call stack. Users can force the RISC-V backend to
-generate the software shadow call stack with ``Zicfiss``_ by passing
-``-mforced-sw-shadow-stack``.
+hardware shadow stack, which needs `Zicfiss`_ and ``-fcf-protection=return``.
+Users can choose between the software and hardware based shadow stack
+implementation on RISC-V backend by passing ``-fsanitize=shadowcallstack``
+or ``Zicfiss`` with ``-fcf-protection=return``.
 For simplicity we will refer to this as the ``SCSReg``. On some platforms,
 ``SCSReg`` is reserved, and on others, it is designated as a scratch register.
 This generally means that any code that may run on the same thread as code
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 805b79491e6ea4..8887e0c1495d2a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4930,10 +4930,6 @@ def msave_restore : Flag<["-"], "msave-restore">, 
Group,
   HelpText<"Enable using library calls for save and restore">;
 def mno_save_restore : Flag<["-"], "mno-save-restore">, 
Group,
   HelpText<"Disable using library calls for save and restore">;
-def mforced_sw_shadow_stack : Flag<["-"], "mforced-sw-shadow-stack">, 
Group,
-  HelpText<"Force using software shadow stack when shadow-stack enabled">;
-def mno_forced_sw_shadow_stack : Flag<["-"], "mno-forced-sw-shadow-stack">, 
Group,
-  HelpText<"Not force using software shadow stack when shadow-stack enabled">;
 } // let Flags = [TargetSpecific]
 let Flags = [TargetSpecific] in {
 def menable_experimental_extensions : Flag<["-"], 
"menable-experimental-extensions">, Group,
diff --git a/clang/test/Driver/riscv-features.c 
b/clang/test/Driver/riscv-features.c
index b4fad5177c5f76..b58ec3b523e5c1 100644
--- a/clang/test/Driver/riscv-features.c
+++ b/clang/test/Driver/riscv-features.c
@@ -29,12 +29,6 @@
 // DEFAULT-NOT: "-target-feature" "-save-restore"
 // DEFAULT-NOT: "-target-feature" "+save-restore"
 
-// RUN: %clang --target=riscv32-unknown-elf -### %s -mforced-sw-shadow-stack 
2>&1 | FileCheck %s -check-prefix=FORCE-SW-SCS
-// RUN: %clang --target=riscv32-unknown-elf -### %s 
-mno-forced-sw-shadow-stack 2>&1 | FileCheck %s -check-prefix=NO-FORCE-SW-SCS
-// FORCE-SW-SCS: "-target-feature" "+forced-sw-shadow-stack"
-// NO-FORCE-SW-SCS: "-target-feature" "-forced-sw-shadow-stack"
-// DEFAULT-NOT: "-target-feature" "+forced-sw-shadow-stack"
-
 // RUN: %clang --target=riscv32-unknown-elf -### %s -mno-strict-align 2>&1 | 
FileCheck %s 
-check-prefixes=FAST-SCALAR-UNALIGNED-ACCESS,FAST-VECTOR-UNALIGNED-ACCESS
 // RUN: %clang --target=riscv32-unknown-elf -### %s -mstrict-align 2>&1 | 
FileCheck %s 
-check-prefixes=NO-FAST-SCALAR-UNALIGNED-ACCESS,NO-FAST-VECTOR-UNALIGNED-ACCESS
 // RUN: %clang --target=riscv32-unknown-elf -### %s -mno-scalar-strict-align 
2>&1 | FileCheck %s -check-prefix=FAST-SCALAR-UNALIGNED-ACCESS

``




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


[clang] [Webkit Checkers] Introduce a Webkit checker for memory unsafe casts (PR #114606)

2024-11-07 Thread Devin Coughlin via cfe-commits

https://github.com/devincoughlin commented:

This is great to see!

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


[clang] [Webkit Checkers] Introduce a Webkit checker for memory unsafe casts (PR #114606)

2024-11-07 Thread Devin Coughlin via cfe-commits

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


[clang] [Webkit Checkers] Introduce a Webkit checker for memory unsafe casts (PR #114606)

2024-11-07 Thread Devin Coughlin via cfe-commits


@@ -0,0 +1,117 @@
+//===- MemoryUnsafeCastChecker.cpp -*- C++ -*-==//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file defines MemoryUnsafeCast checker, which checks for casts from a
+// base type to a derived type.
+//===--===//
+
+#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
+#include "clang/AST/StmtVisitor.h"
+#include "clang/Analysis/AnalysisDeclContext.h"
+#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace clang;
+using namespace ento;
+
+namespace {
+class WalkAST : public StmtVisitor {
+  BugReporter &BR;
+  const CheckerBase *Checker;
+  AnalysisDeclContext* AC;
+  ASTContext &ASTC;
+
+public:
+  WalkAST(BugReporter &br, const CheckerBase *checker, AnalysisDeclContext *ac)
+  : BR(br), Checker(checker), AC(ac), ASTC(AC->getASTContext()) {}
+
+  // Statement visitor methods.
+  void VisitChildren(Stmt *S);
+  void VisitStmt(Stmt *S) { VisitChildren(S); }
+  void VisitCastExpr(CastExpr *CE);
+};
+} // end anonymous namespace
+
+void emitWarning(QualType FromType, QualType ToType,
+ AnalysisDeclContext *AC, BugReporter &BR,
+ const CheckerBase *Checker,
+ CastExpr *CE) {
+  std::string Diagnostics;
+  llvm::raw_string_ostream OS(Diagnostics);
+  OS << "Unsafe cast from base type '"
+ << FromType
+ << "' to derived type '"
+ << ToType
+ << "'",
+
+  BR.EmitBasicReport(
+AC->getDecl(),
+Checker,
+/*Name=*/"Memory unsafe cast",
+categories::SecurityError,
+Diagnostics,
+PathDiagnosticLocation::createBegin(CE, BR.getSourceManager(), AC),
+CE->getSourceRange());
+}
+
+namespace {
+class MemoryUnsafeCastChecker : public Checker {
+  BugType BT{this, ""};
+public:
+  void checkASTCodeBody(const Decl *D, AnalysisManager& Mgr,
+BugReporter &BR) const {
+WalkAST walker(BR, this, Mgr.getAnalysisDeclContext(D));

devincoughlin wrote:

Now that we can use ASTMatchers in static analyzer checkers, I would recommend 
using that rather than an explicit AST walker. For example, as Artem 
recommended, you can use `forEachDescendant()`. This saves the boilerplate of 
setting up a custom walker.

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


[clang] [NFC][Clang] Refactor ClangDiagnosticEmitter to use more StringRef (PR #115212)

2024-11-07 Thread Rahul Joshi via cfe-commits

https://github.com/jurahul updated 
https://github.com/llvm/llvm-project/pull/115212

>From c3df877042c59ca9c9303de0f1707359cd91e9bd Mon Sep 17 00:00:00 2001
From: Rahul Joshi 
Date: Wed, 6 Nov 2024 11:22:55 -0800
Subject: [PATCH] [Clang] Refactor ClangDiagnosticEmitter to use more StringRef

Refactor ClangDiagnosticEmitter to use more StringRefs. Also use
more range for loops.

Verified that .inc files generated by clang build are identical
with and without the change.
---
 .../TableGen/ClangDiagnosticsEmitter.cpp  | 295 +++---
 1 file changed, 115 insertions(+), 180 deletions(-)

diff --git a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp 
b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
index 34e2e8f47ae71a..5155ba7fcf21a5 100644
--- a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
+++ b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
@@ -18,6 +18,7 @@
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/StringSet.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/Support/Casting.h"
@@ -44,35 +45,28 @@ class DiagGroupParentMap {
 
 public:
   DiagGroupParentMap(const RecordKeeper &records) : Records(records) {
-ArrayRef DiagGroups =
-Records.getAllDerivedDefinitions("DiagGroup");
-for (unsigned i = 0, e = DiagGroups.size(); i != e; ++i) {
-  std::vector SubGroups =
-  DiagGroups[i]->getValueAsListOfDefs("SubGroups");
-  for (unsigned j = 0, e = SubGroups.size(); j != e; ++j)
-Mapping[SubGroups[j]].push_back(DiagGroups[i]);
-}
+for (const Record *Group : Records.getAllDerivedDefinitions("DiagGroup"))
+  for (const Record *SubGroup : Group->getValueAsListOfDefs("SubGroups"))
+Mapping[SubGroup].push_back(Group);
   }
 
-  const std::vector &getParents(const Record *Group) {
-return Mapping[Group];
+  ArrayRef getParents(const Record *SubGroup) {
+return Mapping[SubGroup];
   }
 };
 } // end anonymous namespace.
 
-static std::string
+static StringRef
 getCategoryFromDiagGroup(const Record *Group,
  DiagGroupParentMap &DiagGroupParents) {
   // If the DiagGroup has a category, return it.
-  std::string CatName = std::string(Group->getValueAsString("CategoryName"));
+  StringRef CatName = Group->getValueAsString("CategoryName");
   if (!CatName.empty()) return CatName;
 
   // The diag group may the subgroup of one or more other diagnostic groups,
   // check these for a category as well.
-  const std::vector &Parents =
-  DiagGroupParents.getParents(Group);
-  for (unsigned i = 0, e = Parents.size(); i != e; ++i) {
-CatName = getCategoryFromDiagGroup(Parents[i], DiagGroupParents);
+  for (const Record *Parent : DiagGroupParents.getParents(Group)) {
+CatName = getCategoryFromDiagGroup(Parent, DiagGroupParents);
 if (!CatName.empty()) return CatName;
   }
   return "";
@@ -80,25 +74,26 @@ getCategoryFromDiagGroup(const Record *Group,
 
 /// getDiagnosticCategory - Return the category that the specified diagnostic
 /// lives in.
-static std::string getDiagnosticCategory(const Record *R,
- DiagGroupParentMap &DiagGroupParents) 
{
+static StringRef getDiagnosticCategory(const Record *R,
+   DiagGroupParentMap &DiagGroupParents) {
   // If the diagnostic is in a group, and that group has a category, use it.
   if (const auto *Group = dyn_cast(R->getValueInit("Group"))) {
 // Check the diagnostic's diag group for a category.
-std::string CatName = getCategoryFromDiagGroup(Group->getDef(),
-   DiagGroupParents);
+StringRef CatName =
+getCategoryFromDiagGroup(Group->getDef(), DiagGroupParents);
 if (!CatName.empty()) return CatName;
   }
 
   // If the diagnostic itself has a category, get it.
-  return std::string(R->getValueAsString("CategoryName"));
+  return R->getValueAsString("CategoryName");
 }
 
 namespace {
   class DiagCategoryIDMap {
 const RecordKeeper &Records;
 StringMap CategoryIDs;
-std::vector CategoryStrings;
+std::vector CategoryStrings;
+
   public:
 DiagCategoryIDMap(const RecordKeeper &records) : Records(records) {
   DiagGroupParentMap ParentInfo(Records);
@@ -107,10 +102,9 @@ namespace {
   CategoryStrings.push_back("");
   CategoryIDs[""] = 0;
 
-  ArrayRef Diags =
-  Records.getAllDerivedDefinitions("Diagnostic");
-  for (unsigned i = 0, e = Diags.size(); i != e; ++i) {
-std::string Category = getDiagnosticCategory(Diags[i], ParentInfo);
+  for (const Record *Diag :
+   Records.getAllDerivedDefinitions("Diagnostic")) {
+StringRef Category = getDiagnosticCategory(Diag, ParentInfo);
 if (Category.empty()) continue;  // Skip diags with no category.
 
 unsigned &ID = CategoryIDs[Category];
@@ -125,7 +119,7 @@ namespace {
   

[clang] [llvm] [AArch64][SVE] Change the immediate argument in svextq (PR #115340)

2024-11-07 Thread via cfe-commits

https://github.com/SpencerAbson created 
https://github.com/llvm/llvm-project/pull/115340

In order to align with `svext` and NEON `vext`/`vextq`, this patch changes 
immediate argument in `svextq` such that it refers to elements of the size of 
those of the source vector, rather than bytes. The [spec for this 
intrinsic](https://github.com/ARM-software/acle/blob/main/main/acle.md#extq) is 
ambiguous about the meaning of this argument, this issue was raised after there 
was a differing interpretation for it from the implementers of the ACLE in GCC.

For example (with our current implementation):

`svextq_f64(zn_f64, zm_f64, 1)` would, for each 128-bit segment of `zn_f64,` 
concatenate the highest 15 bytes of this segment with the first byte of the 
corresponding segment of `zm_f64`.

After this patch, the behavior of `svextq_f64(zn_f64, zm_f64, 1)` would be, for 
each 128-bit vector segment of `zn_f64`, to concatenate the higher doubleword 
of this segment with the lower doubleword of the corresponding segment of 
`zm_f64`.

The range of the immediate argument in `svextq` would be modified such that it 
is:
- [0,15] for `svextq_{s8,u8}`
- [0,7] for `svextq_{s16,u16,f16,bf16}`
- [0,3] for `svextq_{s32,u32,f32}`
- [0,1] for `svextq_{s64,u64,f64}`

>From e5212d805bcd7db193255f02ea577420b9536e38 Mon Sep 17 00:00:00 2001
From: Spencer Abson 
Date: Thu, 7 Nov 2024 11:44:27 +
Subject: [PATCH] [AArch64][SVE] Fix the immediate argument in svextq

The meaning of the immediate argument in svextq should be tied to the element 
size of its operands.

For example:

svextq_f64(zn_f64, zm_f64, 1) would, for each 128-bit segment of zn_f64, 
concatenate the highest 15 bytes of this segment with
the first byte of the corresponding segment of zm_f64.

The intuitive behavior of svextq_f64(zn_f64, zm_f64, 1) is to concatenate the 
higher doubleword of zn_f64 with the lower doubleword of zm_f64.

The range of the immediate argument in svextq has been modified such that it is:
- [0,15] for svextq_{s8,u8}
- [0,7] for svextq_{s16,u16,f16,bf16}
- [0,3] for svextq_{s32,u32,f32}
- [0,1] for svextq_{s64,u64,f64}
---
 clang/include/clang/Basic/arm_sve.td  |  2 +-
 .../acle_sve2p1_extq.c| 42 +-
 .../acle_sve2p1_imm.cpp   | 44 +--
 .../lib/Target/AArch64/AArch64InstrFormats.td | 33 ++
 llvm/lib/Target/AArch64/SVEInstrFormats.td| 17 ---
 .../CodeGen/AArch64/sve2p1-intrinsics-extq.ll | 28 ++--
 6 files changed, 118 insertions(+), 48 deletions(-)

diff --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index 90b1ec242e6bae..f4f87323eef09f 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -2284,7 +2284,7 @@ let SVETargetGuard = "sve2p1", SMETargetGuard = 
InvalidMode in {
   def SVTBLQ : SInst<"svtblq[_{d}]", "ddu", "cUcsUsiUilUlbhfd", MergeNone, 
"aarch64_sve_tblq">;
   def SVTBXQ : SInst<"svtbxq[_{d}]", "dddu", "cUcsUsiUilUlbhfd", MergeNone, 
"aarch64_sve_tbxq">;
   // EXTQ
-  def EXTQ : SInst<"svextq[_{d}]", "dddk", "cUcsUsiUilUlbhfd", MergeNone, 
"aarch64_sve_extq", [], [ImmCheck<2, ImmCheck0_15>]>;
+  def EXTQ : SInst<"svextq[_{d}]", "dddk", "cUcsUsiUilUlbhfd", MergeNone, 
"aarch64_sve_extq", [], [ImmCheck<2, ImmCheckLaneIndex, 0>]>;
 
   // PMOV
   // Move to Pred
diff --git a/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_extq.c 
b/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_extq.c
index 5fbfa881500ba1..06eec1e00900cc 100644
--- a/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_extq.c
+++ b/clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_extq.c
@@ -103,111 +103,111 @@ svuint32_t test_svextq_u32(svuint32_t zn, svuint32_t 
zm) {
 // CHECK-LABEL: define dso_local  @test_svextq_s32
 // CHECK-SAME: ( [[ZN:%.*]],  [[ZM:%.*]]) 
#[[ATTR0]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.extq.nxv4i32( [[ZN]],  
[[ZM]], i32 6)
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.extq.nxv4i32( [[ZN]],  
[[ZM]], i32 3)
 // CHECK-NEXT:ret  [[TMP0]]
 //
 // CPP-CHECK-LABEL: define dso_local  
@_Z15test_svextq_s32u11__SVInt32_tS_
 // CPP-CHECK-SAME: ( [[ZN:%.*]],  
[[ZM:%.*]]) #[[ATTR0]] {
 // CPP-CHECK-NEXT:  entry:
-// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.extq.nxv4i32( [[ZN]],  
[[ZM]], i32 6)
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.extq.nxv4i32( [[ZN]],  
[[ZM]], i32 3)
 // CPP-CHECK-NEXT:ret  [[TMP0]]
 //
 svint32_t test_svextq_s32(svint32_t zn, svint32_t zm) {
-return SVE_ACLE_FUNC(svextq, _s32,,)(zn, zm, 6);
+return SVE_ACLE_FUNC(svextq, _s32,,)(zn, zm, 3);
 }
 
 // CHECK-LABEL: define dso_local  @test_svextq_u64
 // CHECK-SAME: ( [[ZN:%.*]],  [[ZM:%.*]]) 
#[[ATTR0]] {
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.extq.nxv2i64( [[ZN]],  
[[ZM]], i3

[libunwind] 5a8956e - [compiler-rt][libunwind] Support aarch64 without FPU (#111235)

2024-11-07 Thread via cfe-commits

Author: Keith Packard
Date: 2024-11-07T08:32:45-08:00
New Revision: 5a8956ea8b8ac1ef7b6c4e42553a55063ab699ea

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

LOG: [compiler-rt][libunwind] Support aarch64 without FPU (#111235)

These two libraries don't build for `-march=armv8-a+nofp
-mabi=aapcs-soft` as a couple of uses of floating point instructions and
registers have crept in.

In libunwind, skip save/restore of FPU registers on targets without them.
In compiler-rt, fall back to the old C implementation of __arm_sc_memset when
the target doesn't have an FPU.

-

Signed-off-by: Keith Packard 

Added: 


Modified: 
compiler-rt/lib/builtins/aarch64/sme-libc-mem-routines.S
compiler-rt/lib/builtins/aarch64/sme-libc-routines.c
libunwind/src/UnwindRegistersRestore.S
libunwind/src/UnwindRegistersSave.S

Removed: 




diff  --git a/compiler-rt/lib/builtins/aarch64/sme-libc-mem-routines.S 
b/compiler-rt/lib/builtins/aarch64/sme-libc-mem-routines.S
index 0318d9a6f1ebd2..6e13a03691cfd6 100644
--- a/compiler-rt/lib/builtins/aarch64/sme-libc-mem-routines.S
+++ b/compiler-rt/lib/builtins/aarch64/sme-libc-mem-routines.S
@@ -6,8 +6,6 @@
 
 #include "../assembly.h"
 
-#ifdef __aarch64__
-
 #define L(l) .L ## l
 
 //
@@ -238,7 +236,8 @@ END_COMPILERRT_OUTLINE_FUNCTION(__arm_sc_memcpy)
 
 DEFINE_COMPILERRT_FUNCTION_ALIAS(__arm_sc_memmove, __arm_sc_memcpy)
 
-
+// This version uses FP registers. Use this only on targets with them
+#if defined(__aarch64__) && __ARM_FP != 0
 //
 //  __arm_sc_memset
 //

diff  --git a/compiler-rt/lib/builtins/aarch64/sme-libc-routines.c 
b/compiler-rt/lib/builtins/aarch64/sme-libc-routines.c
index 315490e73ea2b1..07d6681485556b 100644
--- a/compiler-rt/lib/builtins/aarch64/sme-libc-routines.c
+++ b/compiler-rt/lib/builtins/aarch64/sme-libc-routines.c
@@ -1,5 +1,17 @@
 #include 
 
+/* The asm version uses FP registers. Use this on targets without them */
+#if __ARM_FP == 0
+void *__arm_sc_memset(void *dest, int c, size_t n) __arm_streaming_compatible {
+  unsigned char *destp = (unsigned char *)dest;
+  unsigned char c8 = (unsigned char)c;
+  for (size_t i = 0; i < n; ++i)
+destp[i] = c8;
+
+  return dest;
+}
+#endif
+
 const void *__arm_sc_memchr(const void *src, int c,
 size_t n) __arm_streaming_compatible {
   const unsigned char *srcp = (const unsigned char *)src;

diff  --git a/libunwind/src/UnwindRegistersRestore.S 
b/libunwind/src/UnwindRegistersRestore.S
index 180a66582f41b5..1702d016c368ba 100644
--- a/libunwind/src/UnwindRegistersRestore.S
+++ b/libunwind/src/UnwindRegistersRestore.S
@@ -658,7 +658,7 @@ 
DEFINE_LIBUNWIND_FUNCTION(__libunwind_Registers_arm64_jumpto)
   ldpx26,x27, [x0, #0x0D0]
   ldpx28,x29, [x0, #0x0E0]
   ldrx30, [x0, #0x100]  // restore pc into lr
-
+#if defined(__ARM_FP) && __ARM_FP != 0
   ldpd0, d1,  [x0, #0x110]
   ldpd2, d3,  [x0, #0x120]
   ldpd4, d5,  [x0, #0x130]
@@ -676,7 +676,7 @@ 
DEFINE_LIBUNWIND_FUNCTION(__libunwind_Registers_arm64_jumpto)
   ldpd28,d29, [x0, #0x1F0]
   ldrd30, [x0, #0x200]
   ldrd31, [x0, #0x208]
-
+#endif
   // Finally, restore sp. This must be done after the last read from the
   // context struct, because it is allocated on the stack, and an exception
   // could clobber the de-allocated portion of the stack after sp has been

diff  --git a/libunwind/src/UnwindRegistersSave.S 
b/libunwind/src/UnwindRegistersSave.S
index fab234fcd6f318..a489a8ba6df159 100644
--- a/libunwind/src/UnwindRegistersSave.S
+++ b/libunwind/src/UnwindRegistersSave.S
@@ -746,6 +746,7 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
   strx1,  [x0, #0x0F8]
   strx30, [x0, #0x100]// store return address as pc
   // skip cpsr
+#if defined(__ARM_FP) && __ARM_FP != 0
   stpd0, d1,  [x0, #0x110]
   stpd2, d3,  [x0, #0x120]
   stpd4, d5,  [x0, #0x130]
@@ -763,6 +764,7 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
   stpd28,d29, [x0, #0x1F0]
   strd30, [x0, #0x200]
   strd31, [x0, #0x208]
+#endif
   movx0, #0   // return UNW_ESUCCESS
   ret
 



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


[clang] [C2y] Implement WG14 N3344 (PR #115313)

2024-11-07 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> Paper doesn't say, but presumably based on this patch, 'alternative #1' is 
> what was accepted?

Correct, alternative #1 :-)

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


[clang] [clang] Introduce [[clang::lifetime_capture_by(X)]] (PR #111499)

2024-11-07 Thread Gábor Horváth via cfe-commits


@@ -1909,6 +1911,12 @@ void TypePrinter::printAttributedAfter(const 
AttributedType *T,
 OS << " [[clang::lifetimebound]]";
 return;
   }
+  if (T->getAttrKind() == attr::LifetimeCaptureBy) {
+// FIXME: Print the attribute arguments once we have a way to retrieve 
these

Xazax-hun wrote:

I think it should be possible since 
https://github.com/llvm/llvm-project/pull/108631 was merged. 

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


[clang] [llvm] Introduce a new WebKit checker for a unchecked call arguments (#113708) (PR #114522)

2024-11-07 Thread Ryosuke Niwa via cfe-commits


@@ -1,4 +1,4 @@
-//===- UncountedCallArgsChecker.cpp --*- C++ 
-*-==//
+//===- RawPtrRefCallArgsChecker.cpp --*- C++ 
-*-==//

rniwa wrote:

I don't think so. I could imagine `UncountedCallArgsChecker` and 
`UncheckedCallArgsChecker` getting merged in the future but I don't think we'd 
add a new checker using `RawPtrCallArgsChecker`.

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


[clang] [clang] Introduce [[clang::lifetime_capture_by(X)]] (PR #111499)

2024-11-07 Thread Gábor Horváth via cfe-commits


@@ -1873,6 +1873,46 @@ def LifetimeBound : DeclOrTypeAttr {
   let SimpleHandler = 1;
 }
 
+def LifetimeCaptureBy : DeclOrTypeAttr {
+  let Spellings = [Clang<"lifetime_capture_by", 0>];
+  let Subjects = SubjectList<[ParmVar, ImplicitObjectParameter], ErrorDiag>;
+  let Args = [VariadicParamOrParamIdxArgument<"Params">];
+  let Documentation = [LifetimeBoundDocs];
+  let LangOpts = [CPlusPlus];
+
+  // let SimpleHandler = 1;
+  // let LateParsed = LateAttrParseStandard;
+  // let HasCustomParsing = 1;
+  // let ParseArgumentsAsUnevaluated = 1;
+
+  let AdditionalMembers = [{
+private:
+  SmallVector ArgIdents;
+  SmallVector ArgLocs;
+
+public:
+  static constexpr int INVALID = -2;
+  static constexpr int UNKNOWN = -1;
+  static constexpr int GLOBAL = -1;
+  static constexpr int THIS = 0;
+
+  void setArgs(SmallVector Idents,

Xazax-hun wrote:

We often take `SmallVectorImpl&` or `SmallVectorImpl&&` as arguments, so we do 
not need to force the caller into a specific count for the inline buffer.

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


[clang] [clang] Introduce [[clang::lifetime_capture_by(X)]] (PR #111499)

2024-11-07 Thread Gábor Horváth via cfe-commits

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


[clang] ef353b0 - Introduce a new WebKit checker for a unchecked call arguments (#113708) (#114522)

2024-11-07 Thread via cfe-commits

Author: Ryosuke Niwa
Date: 2024-11-07T08:34:37-08:00
New Revision: ef353b02b0728f2328c3494c70dc426d58d23508

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

LOG: Introduce a new WebKit checker for a unchecked call arguments (#113708) 
(#114522)

This PR introduces alpha.webkit.UncheckedCallArgsChecker which detects a
function argument which is a raw reference or a raw pointer to a
CheckedPtr capable object.

Added: 
clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefCallArgsChecker.cpp
clang/test/Analysis/Checkers/WebKit/call-args-checked-ptr.cpp
clang/test/Analysis/Checkers/WebKit/call-args-checked-return-value.cpp

Modified: 
clang/docs/analyzer/checkers.rst
clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
llvm/utils/gn/secondary/clang/lib/StaticAnalyzer/Checkers/BUILD.gn

Removed: 
clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp



diff  --git a/clang/docs/analyzer/checkers.rst 
b/clang/docs/analyzer/checkers.rst
index 8a9e2076a875f3..f34b25cd04bd18 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -3560,6 +3560,12 @@ We also define a set of safe transformations which if 
passed a safe value as an
 - casts
 - unary operators like ``&`` or ``*``
 
+alpha.webkit.UncheckedCallArgsChecker
+"
+The goal of this rule is to make sure that lifetime of any dynamically 
allocated CheckedPtr capable object passed as a call argument keeps its memory 
region past the end of the call. This applies to call to any function, method, 
lambda, function pointer or functor. CheckedPtr capable objects aren't supposed 
to be allocated on stack so we check arguments for parameters of raw pointers 
and references to unchecked types.
+
+The rules of when to use and not to use CheckedPtr / CheckedRef are same as 
alpha.webkit.UncountedCallArgsChecker for ref-counted objects.
+
 alpha.webkit.UncountedLocalVarsChecker
 ""
 The goal of this rule is to make sure that any uncounted local variable is 
backed by a ref-counted object with lifetime that is strictly larger than the 
scope of the uncounted local variable. To be on the safe side we require the 
scope of an uncounted variable to be embedded in the scope of ref-counted 
object that backs it.

diff  --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index 86d62b58cac0fb..b03e707d638742 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -1760,6 +1760,10 @@ def UncountedCallArgsChecker : 
Checker<"UncountedCallArgsChecker">,
   HelpText<"Check uncounted call arguments.">,
   Documentation;
 
+def UncheckedCallArgsChecker : Checker<"UncheckedCallArgsChecker">,
+  HelpText<"Check unchecked call arguments.">,
+  Documentation;
+
 def UncountedLocalVarsChecker : Checker<"UncountedLocalVarsChecker">,
   HelpText<"Check uncounted local variables.">,
   Documentation;

diff  --git a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt 
b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
index c6e5afdc42424c..f40318f46dea1a 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
+++ b/clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
@@ -134,7 +134,7 @@ add_clang_library(clangStaticAnalyzerCheckers
   WebKit/ASTUtils.cpp
   WebKit/PtrTypesSemantics.cpp
   WebKit/RefCntblBaseVirtualDtorChecker.cpp
-  WebKit/UncountedCallArgsChecker.cpp
+  WebKit/RawPtrRefCallArgsChecker.cpp
   WebKit/UncountedLambdaCapturesChecker.cpp
   WebKit/RawPtrRefLocalVarsChecker.cpp
 

diff  --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 487cde26012e56..31bebdb07dbdc2 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -174,6 +174,16 @@ std::optional isUncounted(const QualType T) {
   return isUncounted(T->getAsCXXRecordDecl());
 }
 
+std::optional isUnchecked(const QualType T) {
+  if (auto *Subst = dyn_cast(T)) {
+if (auto *Decl = Subst->getAssociatedDecl()) {
+  if (isCheckedPtr(safeGetName(Decl)))
+return false;
+}
+  }
+  return isUnchecked(T->getAsCXXRecordDecl());
+}
+
 std::optional isUncounted(const CXXRecordDecl* Class)
 {
   // Keep isRefCounted first as it's cheaper.
@@ -188,7 +198,7 @@ std::optional isUncounted(const CXXRecordDecl* Class)
 }
 
 std::optional isUnchecked(const CXXR

[clang] [clang] Introduce [[clang::lifetime_capture_by(X)]] (PR #111499)

2024-11-07 Thread Gábor Horváth via cfe-commits

https://github.com/Xazax-hun commented:

I did not get to the end of this PR yet, but I was wondering if it would make 
sense to split it up. One PR could add the attribute with the semantic analysis 
(e.g., warnings for ill-formed arguments). The second PR could introduce the 
lifetime analysis part. WDYT?

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


[clang] [clang] Introduce [[clang::lifetime_capture_by(X)]] (PR #111499)

2024-11-07 Thread Gábor Horváth via cfe-commits


@@ -1873,6 +1873,46 @@ def LifetimeBound : DeclOrTypeAttr {
   let SimpleHandler = 1;
 }
 
+def LifetimeCaptureBy : DeclOrTypeAttr {
+  let Spellings = [Clang<"lifetime_capture_by", 0>];
+  let Subjects = SubjectList<[ParmVar, ImplicitObjectParameter], ErrorDiag>;
+  let Args = [VariadicParamOrParamIdxArgument<"Params">];
+  let Documentation = [LifetimeBoundDocs];
+  let LangOpts = [CPlusPlus];
+
+  // let SimpleHandler = 1;
+  // let LateParsed = LateAttrParseStandard;
+  // let HasCustomParsing = 1;
+  // let ParseArgumentsAsUnevaluated = 1;
+
+  let AdditionalMembers = [{
+private:
+  SmallVector ArgIdents;
+  SmallVector ArgLocs;
+
+public:
+  static constexpr int INVALID = -2;
+  static constexpr int UNKNOWN = -1;
+  static constexpr int GLOBAL = -1;
+  static constexpr int THIS = 0;
+
+  void setArgs(SmallVector Idents,
+   SmallVector Locs) { 
+assert(Idents.size() == Locs.size());
+assert(Idents.size() == params_Size);
+ArgIdents = std::move(Idents);
+ArgLocs = std::move(Locs);
+  }
+  
+  const SmallVector& getArgIdents() const { return 
ArgIdents; }

Xazax-hun wrote:

I think it might be better to return an `ArrayRef` here (and in the next 
getter). 

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


[clang] [flang] [clang][Driver] Add RPATH by default (PR #115286)

2024-11-07 Thread Paul Osmialowski via cfe-commits

pawosm-arm wrote:

> Some distributions (e.g. Fedora) have policies against DT_RUNPATH for system 
> packages.

For as long as I remember, distros (and Fedora is a good example of this 
phenomenon) were patching the software packages heavily, so adding one more to 
ensure their well established policies wouldn't make a huge difference.


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


[clang] [llvm] [llvm][AMDGPU] Fold `llvm.amdgcn.wavefrontsize` early (PR #114481)

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

JonChesterfield wrote:

Awesome! This is absolutely something that has been on my todo stack for ages 
and it's very good to see someone else writing the thing.

It looks like the implementation is contentious so I'll leave that for the 
moment. Under some time constraints so please forgive the length of the 
following - TLDR is I love this and definitely want the feature.

A magic intrinsic which can be summoned from clang and used in things like if 
statements is the right construct for all the stuff which we known by codegen 
time and don't really need to care about in the front end. The code object 
version should probably be reified as one. The number of compute units. All the 
things currently handled by magic global variables in the rocm device library 
and relying on O1 to constant fold them out of existence. We do this, throw 
away the magic globals, everything is better.

The magic intrinsic can have _guaranteed_ constant folding even at O0. That 
kills that class of O0 doesn't work bugs. This means it needs something that is 
certain to remove it ahead of a simplifycfg pass, or for the pass which removes 
it to _also_ do the trivial fold of a branch. So it's not just constant 
folding, though having instcombine also constant fold it is fine as an 
optimisation.

The real value here in my opinion is towards being able to write IR libraries 
that don't know or care what target they're going to run on. Either because 
they're associated with spir-v, or because they're the libc which currently 
handwaves that problem, or the rocm device libs which handwaves it in a 
slightly different way, or the openmp runtime which currently builds K 
identical copies of the bitcode with different names in the spirit of 
correctness and stashes them in an archive. Lots of that is on sketchy QoI 
ground at present. But if we have an wavesize intrinsic that turns into 32 or 
64 once the target is known, and hangs around in the IR until some later 
information about the target is revealed, we can have single IR and predictable 
correct semantics. Much better than the status quo.

Thanks Alex!

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


[clang] [Webkit Checkers] Introduce a Webkit checker for memory unsafe casts (PR #114606)

2024-11-07 Thread Ryosuke Niwa via cfe-commits

rniwa wrote:

I'm hitting this crash in the checker when I try to compile WebKit with this 
patch applied:
```
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH 
or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  clang-17 0x00010fb6c15d 
llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 61
1  clang-17 0x00010fb6c70b 
PrintStackTraceSignalHandler(void*) + 27
2  clang-17 0x00010fb6a4b6 llvm::sys::RunSignalHandlers() + 
134
3  clang-17 0x00010fb6b9de 
llvm::sys::CleanupOnSignal(unsigned long) + 110
4  clang-17 0x00010fa1d717 (anonymous 
namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) + 183
5  clang-17 0x00010fa1dabb CrashRecoverySignalHandler(int) 
+ 187
6  libsystem_platform.dylib 0x7ff802bc637d _sigtramp + 29
7  libsystem_platform.dylib 0x7ff7b4ce10c8 _sigtramp + 18446744072402087272
8  clang-17 0x0001163f26f1 
clang::CXXRecordDecl::isDerivedFrom(clang::CXXRecordDecl const*, 
clang::CXXBasePaths&) const + 33
9  clang-17 0x0001163f2681 
clang::CXXRecordDecl::isDerivedFrom(clang::CXXRecordDecl const*) const + 97
10 clang-17 0x000113a3768e (anonymous 
namespace)::WalkAST::VisitCastExpr(clang::CastExpr*) + 526
11 clang-17 0x000113a3746d 
clang::StmtVisitorBase::VisitExplicitCastExpr(clang::ExplicitCastExpr*) + 29
12 clang-17 0x000113a361ed 
clang::StmtVisitorBase::VisitCStyleCastExpr(clang::CStyleCastExpr*) + 29
13 clang-17 0x000113a3328a 
clang::StmtVisitorBase::Visit(clang::Stmt*) + 3770
14 clang-17 0x000113a372b2 (anonymous 
namespace)::WalkAST::VisitChildren(clang::Stmt*) + 146
15 clang-17 0x000113a3720d (anonymous 
namespace)::WalkAST::VisitStmt(clang::Stmt*) + 29
16 clang-17 0x000113a3477d 
clang::StmtVisitorBase::VisitCompoundStmt(clang::CompoundStmt*) + 29
17 clang-17 0x000113a328a0 
clang::StmtVisitorBase::Visit(clang::Stmt*) + 1232
18 clang-17 0x000113a3237f (anonymous 
namespace)::MemoryUnsafeCastChecker::checkASTCodeBody(clang::Decl const*, 
clang::ento::AnalysisManager&, clang::ento::BugReporter&) const + 95
19 clang-17 0x000113a3230d void 
clang::ento::check::ASTCodeBody::_checkBody<(anonymous 
namespace)::MemoryUnsafeCastChecker>(void*, clang::Decl const*, 
clang::ento::AnalysisManager&, clang::ento::BugReporter&) + 45
20 clang-17 0x000113df2901 clang::ento::CheckerFn::operator()(clang::Decl const*, 
clang::ento::AnalysisManager&, clang::ento::BugReporter&) const + 49
21 clang-17 0x000113df29e7 
clang::ento::CheckerManager::runCheckersOnASTBody(clang::Decl const*, 
clang::ento::AnalysisManager&, clang::ento::BugReporter&) + 215
22 clang-17 0x0001131f63fc (anonymous 
namespace)::AnalysisConsumer::HandleCode(clang::Decl*, unsigned int, 
clang::ento::ExprEngine::InliningModes, llvm::DenseSet>*) + 540
23 clang-17 0x0001131fc597 (anonymous 
namespace)::AnalysisConsumer::VisitFunctionDecl(clang::FunctionDecl*) + 311
24 clang-17 0x0001131fbced 
clang::RecursiveASTVisitor<(anonymous 
namespace)::AnalysisConsumer>::WalkUpFromFunctionDecl(clang::FunctionDecl*) + 93
25 clang-17 0x0001131829cf 
clang::RecursiveASTVisitor<(anonymous 
namespace)::AnalysisConsumer>::TraverseFunctionDecl(clang::FunctionDecl*) + 79
26 clang-17 0x0001131797e6 
clang::RecursiveASTVisitor<(anonymous 
namespace)::AnalysisConsumer>::TraverseDecl(clang::Decl*) + 2534
27 clang-17 0x0001131e0b18 
clang::RecursiveASTVisitor<(anonymous 
namespace)::AnalysisConsumer>::TraverseDeclContextHelper(clang::DeclContext*) + 
200
28 clang-17 0x00011317c495 
clang::RecursiveASTVisitor<(anonymous 
namespace)::AnalysisConsumer>::TraverseLinkageSpecDecl(clang::LinkageSpecDecl*) 
+ 165
29 clang-17 0x000113179103 
clang::RecursiveASTVisitor<(anonymous 
namespace)::AnalysisConsumer>::TraverseDecl(clang::Decl*) + 771
30 clang-17 0x000113178c0b (anonymous 
namespace)::AnalysisConsumer::runAnalysisOnTranslationUnit(clang::ASTContext&) 
+ 443
31 clang-17 0x0001131736fe (anonymous 
namespace)::AnalysisConsumer::HandleTranslationUnit(clang::ASTContext&) + 446
32 clang-17 0x0001141e1736 clang::ParseAST(clang::Sema&, 
bool, bool) + 870
33 clang-17 0x00011131e8b1 
clang::ASTFrontendAction::ExecuteAction() + 305
34 clang-17 0x00011131df8c clang::FrontendAction::Execute() 
+ 124
35 clang-17 0x0001112026df 
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 975
36 clang-17 0x00011144b193

[clang] [clang-tools-extra] [llvm] [clang] Introduce diagnostics suppression mappings (PR #112517)

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

https://github.com/kadircet commented:

> Note that there are a few open comments from previous iterations.

I tried to go over them, but github UI was ... suboptimal. So PLMK if you got 
some that aren't addressed in this revision as well.

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


[clang] [clang-tools-extra] [llvm] [clang] Introduce diagnostics suppression mappings (PR #112517)

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


@@ -167,4 +176,159 @@ TEST(DiagnosticTest, storedDiagEmptyWarning) {
   // Make sure an empty warning can round-trip with \c StoredDiagnostic.
   Diags.Report(CaptureConsumer.StoredDiags.front());
 }
+
+class SuppressionMappingTest : public testing::Test {
+public:
+  SuppressionMappingTest() {
+Diags.setClient(&CaptureConsumer, /*ShouldOwnClient=*/false);
+  }
+
+protected:
+  llvm::IntrusiveRefCntPtr FS =
+  llvm::makeIntrusiveRefCnt();
+  DiagnosticsEngine Diags{new DiagnosticIDs(), new DiagnosticOptions};
+
+  std::vector takeDiags() {
+return std::move(CaptureConsumer.StoredDiags);
+  }
+
+private:
+  class CaptureDiagnosticConsumer : public DiagnosticConsumer {
+  public:
+std::vector StoredDiags;
+
+void HandleDiagnostic(DiagnosticsEngine::Level level,
+  const Diagnostic &Info) override {
+  StoredDiags.push_back(StoredDiagnostic(level, Info));
+}
+  };
+  CaptureDiagnosticConsumer CaptureConsumer;
+};
+
+MATCHER_P(WithMessage, Msg, "has diagnostic message") {
+  return arg.getMessage() == Msg;
+}
+
+TEST_F(SuppressionMappingTest, MissingMappingFile) {
+  Diags.getDiagnosticOptions().DiagnosticSuppressionMappingsFile = "foo.txt";
+  clang::ProcessWarningOptions(Diags, Diags.getDiagnosticOptions(), *FS);
+  EXPECT_THAT(takeDiags(), testing::ElementsAre(WithMessage(
+   "no such file or directory: 'foo.txt'")));
+}
+
+TEST_F(SuppressionMappingTest, MalformedFile) {
+  Diags.getDiagnosticOptions().DiagnosticSuppressionMappingsFile = "foo.txt";
+  FS->addFile("foo.txt", /*ModificationTime=*/{},
+  llvm::MemoryBuffer::getMemBuffer("asdf", "foo.txt"));
+  clang::ProcessWarningOptions(Diags, Diags.getDiagnosticOptions(), *FS);
+  EXPECT_THAT(takeDiags(), testing::ElementsAre(WithMessage(
+   "failed to process suppression mapping file "
+   "'foo.txt': malformed line 1: 'asdf'")));
+}
+
+TEST_F(SuppressionMappingTest, UnknownDiagName) {
+  Diags.getDiagnosticOptions().DiagnosticSuppressionMappingsFile = "foo.txt";
+  FS->addFile("foo.txt", /*ModificationTime=*/{},
+  llvm::MemoryBuffer::getMemBuffer("[non-existing-warning]"));
+  clang::ProcessWarningOptions(Diags, Diags.getDiagnosticOptions(), *FS);
+  EXPECT_THAT(takeDiags(),
+  testing::ElementsAre(WithMessage(
+  "unknown warning option 'non-existing-warning'")));
+}
+
+TEST_F(SuppressionMappingTest, SuppressesGroup) {
+  llvm::StringLiteral SuppressionMappingFile = R"txt(
+  [unused]
+  src:*
+  )txt";
+  Diags.getDiagnosticOptions().DiagnosticSuppressionMappingsFile = "foo.txt";
+  FS->addFile("foo.txt", /*ModificationTime=*/{},
+  llvm::MemoryBuffer::getMemBuffer(SuppressionMappingFile));
+  clang::ProcessWarningOptions(Diags, Diags.getDiagnosticOptions(), *FS);
+  EXPECT_THAT(takeDiags(), testing::IsEmpty());
+
+  EXPECT_TRUE(
+  Diags.isSuppressedViaMapping(diag::warn_unused_function, "foo.cpp"));
+  EXPECT_FALSE(Diags.isSuppressedViaMapping(diag::warn_deprecated, "foo.cpp"));
+}
+
+TEST_F(SuppressionMappingTest, ExclusionsWork) {
+  llvm::StringLiteral SuppressionMappingFile = R"txt(
+  [unused]
+  src:*
+  src:*foo.cpp=emit
+  )txt";
+  Diags.getDiagnosticOptions().DiagnosticSuppressionMappingsFile = "foo.txt";
+  FS->addFile("foo.txt", /*ModificationTime=*/{},
+  llvm::MemoryBuffer::getMemBuffer(SuppressionMappingFile));
+  clang::ProcessWarningOptions(Diags, Diags.getDiagnosticOptions(), *FS);
+  EXPECT_THAT(takeDiags(), testing::IsEmpty());
+
+  EXPECT_TRUE(
+  Diags.isSuppressedViaMapping(diag::warn_unused_function, "bar.cpp"));
+  EXPECT_FALSE(
+  Diags.isSuppressedViaMapping(diag::warn_unused_function, "foo.cpp"));
+}
+
+TEST_F(SuppressionMappingTest, LongestMatchWins) {
+  llvm::StringLiteral SuppressionMappingFile = R"txt(
+  [unused]
+  src:*clang/*
+  src:*clang/lib/Sema/*=emit
+  src:*clang/lib/Sema/foo*
+  )txt";
+  Diags.getDiagnosticOptions().DiagnosticSuppressionMappingsFile = "foo.txt";
+  FS->addFile("foo.txt", /*ModificationTime=*/{},
+  llvm::MemoryBuffer::getMemBuffer(SuppressionMappingFile));
+  clang::ProcessWarningOptions(Diags, Diags.getDiagnosticOptions(), *FS);
+  EXPECT_THAT(takeDiags(), testing::IsEmpty());
+
+  EXPECT_TRUE(Diags.isSuppressedViaMapping(diag::warn_unused_function,
+   "clang/lib/Basic/foo.h"));
+  EXPECT_FALSE(Diags.isSuppressedViaMapping(diag::warn_unused_function,
+"clang/lib/Sema/bar.h"));
+  EXPECT_TRUE(Diags.isSuppressedViaMapping(diag::warn_unused_function,
+   "clang/lib/Sema/foo.h"));
+}
+
+TEST_F(SuppressionMappingTest, IsIgnored) {
+  llvm::StringLiteral SuppressionMappingFile = R"txt(
+  [unused]
+  src:*clang/*
+  )txt";
+  Diags.getDiagnosticOptions().DiagnosticSuppressionMappingsFile = "foo.txt";
+  Diags.getDiagnost

[clang] [Clang] skip default argument instantiation for non-defining friend declarations without specialization info to meet [dcl.fct.default] p4 (PR #113777)

2024-11-07 Thread Oleksandr T. via cfe-commits

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


[clang] [llvm] [AMDGPU] Introduce a new generic target `gfx9-4-generic` (PR #115190)

2024-11-07 Thread Konstantin Zhuravlyov via cfe-commits


@@ -576,6 +576,12 @@ Generic processor code objects are versioned. See 
:ref:`amdgpu-generic-processor

   - ``v_dot2_f32_f16``
 
 
+ ``gfx9-4-generic``   ``amdgcn`` - ``gfx940``  - xnack
- Absolute flat   FP8 and BF8 instructions,

kzhuravl wrote:

so should be added to target features supported column?

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


[clang] [llvm] Introduce a new WebKit checker for a unchecked call arguments (#113708) (PR #114522)

2024-11-07 Thread Ryosuke Niwa via cfe-commits

rniwa wrote:

Thanks for the review!

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


[clang] [Clang] skip default argument instantiation for non-defining friend declarations without specialization info to meet [dcl.fct.default] p4 (PR #113777)

2024-11-07 Thread Oleksandr T. via cfe-commits

a-tarasyuk wrote:

@zyn0217 done

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


[clang] Add `EvalASTMutator` interface (PR #115168)

2024-11-07 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll updated 
https://github.com/llvm/llvm-project/pull/115168

>From 5ca48e03412b1b8e9253f13356b9cc957f6fd9e5 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Wed, 6 Nov 2024 17:58:43 +0300
Subject: [PATCH 1/4] Add EvalASTMutator interface with
 `InstantiateFunctionDefinition` function

---
 clang/include/clang/AST/ASTContext.h  |  2 +-
 clang/include/clang/AST/Decl.h| 22 ++---
 clang/include/clang/AST/Expr.h|  3 +-
 clang/include/clang/Sema/Sema.h   | 17 ++
 clang/lib/AST/ASTContext.cpp  |  4 +--
 clang/lib/AST/Decl.cpp| 16 +-
 clang/lib/AST/ExprConstant.cpp| 24 +++---
 clang/lib/Sema/Sema.cpp   | 11 ++-
 clang/lib/Sema/SemaDecl.cpp   |  5 +--
 .../constexpr-function-instantiation.cpp  | 31 +++
 10 files changed, 113 insertions(+), 22 deletions(-)
 create mode 100644 clang/test/SemaCXX/constexpr-function-instantiation.cpp

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index a4d36f2eacd5d1..d143591de9f2cd 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -3258,7 +3258,7 @@ class ASTContext : public RefCountedBase {
   ///
   /// \returns true if the function/var must be CodeGen'ed/deserialized even if
   /// it is not used.
-  bool DeclMustBeEmitted(const Decl *D);
+  bool DeclMustBeEmitted(const Decl *D, EvalASTMutator *ASTMutator = nullptr);
 
   /// Visits all versions of a multiversioned function with the passed
   /// predicate.
diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 7ff35d73df5997..89a2833c82194d 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -78,6 +78,18 @@ class UnresolvedSetImpl;
 class VarTemplateDecl;
 enum class ImplicitParamKind;
 
+/// Interface that allows constant evaluator to mutate AST.
+/// When constant evaluation is triggered by Sema, it can supply a proper
+/// implementation of this interface.
+struct EvalASTMutator {
+  virtual ~EvalASTMutator() = default;
+
+  virtual void
+  InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
+FunctionDecl *Function, bool Recursive,
+bool DefinitionRequired, bool AtEndOfTU) = 0;
+};
+
 /// The top declaration context.
 class TranslationUnitDecl : public Decl,
 public DeclContext,
@@ -1355,11 +1367,12 @@ class VarDecl : public DeclaratorDecl, public 
Redeclarable {
   /// Attempt to evaluate the value of the initializer attached to this
   /// declaration, and produce notes explaining why it cannot be evaluated.
   /// Returns a pointer to the value if evaluation succeeded, 0 otherwise.
-  APValue *evaluateValue() const;
+  APValue *evaluateValue(EvalASTMutator *ASTMutator = nullptr) const;
 
 private:
   APValue *evaluateValueImpl(SmallVectorImpl &Notes,
- bool IsConstantInitialization) const;
+ bool IsConstantInitialization,
+ EvalASTMutator *ASTMutator = nullptr) const;
 
 public:
   /// Return the already-evaluated value of this variable's
@@ -1391,8 +1404,9 @@ class VarDecl : public DeclaratorDecl, public 
Redeclarable {
   /// Evaluate the initializer of this variable to determine whether it's a
   /// constant initializer. Should only be called once, after completing the
   /// definition of the variable.
-  bool checkForConstantInitialization(
-  SmallVectorImpl &Notes) const;
+  bool
+  checkForConstantInitialization(SmallVectorImpl &Notes,
+ EvalASTMutator *ASTMutator = nullptr) const;
 
   void setInitStyle(InitializationStyle Style) {
 VarDeclBits.InitStyle = Style;
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 466c65a9685ad3..ccf7fd226b5a8f 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -734,7 +734,8 @@ class Expr : public ValueStmt {
   bool EvaluateAsInitializer(APValue &Result, const ASTContext &Ctx,
  const VarDecl *VD,
  SmallVectorImpl &Notes,
- bool IsConstantInitializer) const;
+ bool IsConstantInitializer,
+ EvalASTMutator *ASTMutator = nullptr) const;
 
   /// EvaluateWithSubstitution - Evaluate an expression as if from the context
   /// of a call to the given function with the given arguments, inside an
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 93d98e1cbb9c81..1c0c6949573335 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -153,6 +153,7 @@ enum class OverloadCandidateParamOrder : char;
 enum OverloadCandidateRewri

[clang] [llvm] [Transforms][Utils][PromoteMem2Reg] Propagate nnan and ninf flags on par with the nsz flag (PR #114271)

2024-11-07 Thread Paul Walker via cfe-commits

https://github.com/paulwalker-arm approved this pull request.


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


[clang] [analyzer][NFC] Remove check::BranchCondition from debug.DumpTraversal (PR #113906)

2024-11-07 Thread Donát Nagy via cfe-commits

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


[clang] [clang-tools-extra] [llvm] [clang] Introduce diagnostics suppression mappings (PR #112517)

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


@@ -0,0 +1,90 @@
+
+Warning suppression mappings
+
+
+.. contents::
+   :local:
+
+Introduction
+
+
+Warning suppression mappings enable users to suppress Clang's diagnostics in a
+per-file granular manner. Enabling enforcement of diagnostics in specific parts
+of the project, even if there are violations in some headers.
+
+Goal and usage
+==
+
+Clang allows diagnostics to be configured at a translation-unit granularity.
+If a ``foo.cpp`` is compiled with ``-Wfoo``, all transitively included headers
+also need to be clean. Hence turning on new warnings in large codebases can be
+difficult today. Since it requires cleaning up all the existing warnings,
+which might not be possible when some dependencies aren't in the project 
owner's
+control or because new violations are creeping up quicker than the clean up.
+
+Warning suppression mappings aim to alleviate some of these concerns by making
+diagnostic configuration granularity finer, at a source file level.
+
+To achieve this, user can create a file that lists which diagnostic groups to
+suppress in which files or paths, and pass it as a command line argument to
+Clang with the ``--warning-suppression-mappings`` flag.
+
+Note that this mechanism won't enable any diagnostics on its own. Users should
+still turn on warnings in their compilations with explicit ``-Wfoo`` flags.
+
+Example
+===
+
+.. code-block:: bash
+
+  $ cat my/user/code.cpp
+  #include 
+  namespace { void unused_func1(); }
+
+  $ cat foo/bar.h
+  namespace { void unused_func2(); }
+
+  $ cat suppression_mappings.txt
+  # Suppress -Wunused warnings in all files, apart from the ones under `foo/`.
+  [unused]
+  src:*
+  src:*foo/*=emit
+  $ clang -Wunused --warning-suppression-mappings=suppression_mappings.txt 
my/user/code.cpp
+  # prints warning: unused function 'unused_func2', but no warnings for 
`unused_func1`.
+
+Format
+==
+
+Warning suppression mappings uses the same format as
+:doc:`SanitizerSpecialCaseList`.
+
+Users can mention sections to describe which diagnostic group behaviours to
+change. Sections are denoted as ``[unused]`` in this format. Each section name
+must match a diagnostic group.
+When a diagnostic is matched by multiple groups, the latest one takes

kadircet wrote:

but diagnostics usually belong to multiple groups. i think the poor choice was 
saying `groups` here rather than `sections`. reworded, ptal.

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


[clang] [C2y] Add conformance test for WG14 N3364 (PR #115332)

2024-11-07 Thread Aaron Ballman via cfe-commits

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


[clang] c1ead03 - [C2y] Add conformance test for WG14 N3364 (#115332)

2024-11-07 Thread via cfe-commits

Author: Aaron Ballman
Date: 2024-11-07T11:53:59-05:00
New Revision: c1ead03e01e47c797e32a3f981ace5ef21eebd18

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

LOG: [C2y] Add conformance test for WG14 N3364 (#115332)

This paper is defining the translation-time behavior of initialization
with a signaling NaN. Clang has always supported the correct behavior.

Added: 
clang/test/C/C2y/n3364.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/www/c_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 703422c9a6f0b3..bd0045a898b8e4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -293,6 +293,11 @@ C2y Feature Support
   language modes but is now rejected (all of the other qualifiers and storage
   class specifiers were previously rejected).
 
+- Updated conformance for `N3364 
`_
+  on floating-point translation-time initialization with signaling NaN. This
+  paper adopts Clang's existing practice, so there were no changes to compiler
+  behavior.
+
 C23 Feature Support
 ^^^
 

diff  --git a/clang/test/C/C2y/n3364.c b/clang/test/C/C2y/n3364.c
new file mode 100644
index 00..277b2643edd6bc
--- /dev/null
+++ b/clang/test/C/C2y/n3364.c
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -verify -std=c2y -Wall -pedantic -emit-llvm -o - %s
+// RUN: %clang_cc1 -verify -Wall -pedantic -emit-llvm -o - %s
+// expected-no-diagnostics
+
+/* WG14 N3364: Yes
+ * Give consistent wording for SNAN initialization v3
+ *
+ * Ensure that initializing from a signaling NAN (optionally with a unary + or
+ * -) at translation time behaves correctly at runtime.
+ */
+
+#define FLT_SNAN __builtin_nansf("1")
+#define DBL_SNAN __builtin_nans("1")
+#define LD_SNAN __builtin_nansl("1")
+
+float f1 = FLT_SNAN;
+float f2 = +FLT_SNAN;
+float f3 = -FLT_SNAN;
+// CHECK: @f1 = {{.*}}global float 0x7FF02000
+// CHECK: @f2 = {{.*}}global float 0x7FF02000
+// CHECK: @f3 = {{.*}}global float 0xFFF02000
+
+double d1 = DBL_SNAN;
+double d2 = +DBL_SNAN;
+double d3 = -DBL_SNAN;
+// CHECK: @d1 = {{.*}}global double 0x7FF1
+// CHECK: @d2 = {{.*}}global double 0x7FF1
+// CHECK: @d3 = {{.*}}global double 0xFFF1
+
+long double ld1 = LD_SNAN;
+long double ld2 = +LD_SNAN;
+long double ld3 = -LD_SNAN;
+// CHECK: @ld1 = {{.*}}global {{double 0x7FF1|x86_fp80 
0xK7FFF8001|fp128 0xL00017FFF}}
+// CHECK: @ld2 = {{.*}}global {{double 0x7FF1|x86_fp80 
0xK7FFF8001|fp128 0xL00017FFF}}
+// CHECK: @ld3 = {{.*}}global {{double 0xFFF1|x86_fp80 
0xK8001|fp128 0xL0001}}

diff  --git a/clang/www/c_status.html b/clang/www/c_status.html
index e66424290e6d50..989a572ae70fb6 100644
--- a/clang/www/c_status.html
+++ b/clang/www/c_status.html
@@ -231,7 +231,7 @@ C2y implementation status
 
   Give consistent wording for SNAN initialization v3
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3364.pdf";>N3364
-  Unknown
+  Yes
 
 
   Case range expressions v3.1



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


[clang] [clang-tools-extra] [llvm] [clang] Introduce diagnostics suppression mappings (PR #112517)

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

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


[clang] [clang-tools-extra] [llvm] [clang] Introduce diagnostics suppression mappings (PR #112517)

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


@@ -477,6 +486,136 @@ void DiagnosticsEngine::setSeverityForAll(diag::Flavor 
Flavor,
   setSeverity(Diag, Map, Loc);
 }
 
+namespace {
+// FIXME: We should isolate the parser from SpecialCaseList and just use it
+// here.
+class WarningsSpecialCaseList : public llvm::SpecialCaseList {
+public:
+  static std::unique_ptr
+  create(const llvm::MemoryBuffer &Input, std::string &Err);
+
+  // Section names refer to diagnostic groups, which cover multiple individual
+  // diagnostics. Expand diagnostic groups here to individual diagnostics.
+  // A diagnostic can have multiple diagnostic groups associated with it, we 
let
+  // the last section take precedence in such cases.
+  void processSections(DiagnosticsEngine &Diags);
+
+  bool isDiagSuppressed(diag::kind DiagId, llvm::StringRef FilePath) const;
+
+private:
+  // Find the longest glob pattern that matches FilePath amongst
+  // CategoriesToMatchers, return true iff the match exists and belongs to a
+  // positive category.
+  bool globsMatches(const llvm::StringMap &CategoriesToMatchers,
+llvm::StringRef FilePath) const;
+
+  llvm::DenseMap DiagToSection;
+};
+} // namespace
+
+std::unique_ptr
+WarningsSpecialCaseList::create(const llvm::MemoryBuffer &Input,
+std::string &Err) {
+  auto WarningSuppressionList = std::make_unique();
+  if (!WarningSuppressionList->createInternal(&Input, Err))
+return nullptr;
+  return WarningSuppressionList;
+}
+
+void WarningsSpecialCaseList::processSections(DiagnosticsEngine &Diags) {
+  // Drop the default section introduced by special case list, we only support
+  // exact diagnostic group names.
+  // FIXME: We should make this configurable in the parser instead.
+  Sections.erase("*");
+  // Make sure we iterate sections by their line numbers.
+  std::vector *>>
+  LineAndSectionEntry;
+  LineAndSectionEntry.reserve(Sections.size());
+  for (const auto &Entry : Sections) {
+llvm::StringRef DiagName = Entry.first();
+// Each section has a matcher with that section's name, attached to that
+// line.
+const auto &DiagSectionMatcher = Entry.second.SectionMatcher;
+unsigned DiagLine = DiagSectionMatcher->Globs.at(DiagName).second;
+LineAndSectionEntry.emplace_back(DiagLine, &Entry);
+  }
+  llvm::sort(LineAndSectionEntry);
+  static constexpr auto WarningFlavor = clang::diag::Flavor::WarningOrError;
+  for (const auto &[_, SectionEntry] : LineAndSectionEntry) {
+SmallVector GroupDiags;
+llvm::StringRef DiagGroup = SectionEntry->getKey();
+if (Diags.getDiagnosticIDs()->getDiagnosticsInGroup(
+WarningFlavor, DiagGroup, GroupDiags)) {
+  StringRef Suggestion =
+  DiagnosticIDs::getNearestOption(WarningFlavor, DiagGroup);
+  Diags.Report(diag::warn_unknown_diag_option)
+  << static_cast(WarningFlavor) << DiagGroup
+  << !Suggestion.empty() << Suggestion;
+  continue;
+}
+for (diag::kind Diag : GroupDiags)
+  // We're intentionally overwriting any previous mappings here to make 
sure
+  // latest one takes precedence.
+  DiagToSection[Diag] = &SectionEntry->getValue();
+  }
+}
+
+void DiagnosticsEngine::setDiagSuppressionMapping(llvm::MemoryBuffer &Input) {
+  std::string Err;
+  auto WarningSuppressionList = WarningsSpecialCaseList::create(Input, Err);
+  if (!WarningSuppressionList) {
+Report(diag::err_drv_malformed_warning_suppression_mapping)
+<< Input.getBufferIdentifier() << Err;
+return;
+  }
+  WarningSuppressionList->processSections(*this);
+  DiagSuppressionMapping =
+  [WarningSuppressionList(std::move(WarningSuppressionList))](
+  diag::kind DiagId, llvm::StringRef Path) {
+return WarningSuppressionList->isDiagSuppressed(DiagId, Path);
+  };
+}
+
+bool WarningsSpecialCaseList::isDiagSuppressed(diag::kind DiagId,
+   llvm::StringRef FilePath) const 
{
+  const Section *DiagSection = DiagToSection.lookup(DiagId);
+  if (!DiagSection)
+return false;
+  const SectionEntries &EntityTypeToCategories = DiagSection->Entries;
+  auto SrcEntriesIt = EntityTypeToCategories.find("src");
+  if (SrcEntriesIt == EntityTypeToCategories.end())
+return false;
+  const llvm::StringMap &CategoriesToMatchers =
+  SrcEntriesIt->second;

kadircet wrote:

lookup returns by value (because it needs to return a default-constructed 
object when key doesn't exist), hence can't bind it to a reference.

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


[clang] [Clang] Dispatch default overloads of `TemplateArgumentVisitor` to the implementation (PR #115336)

2024-11-07 Thread Egor Zhdan via cfe-commits

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


[clang] [llvm] [RFC][RISCV] Use the 'B' extension in RISC-V profile definitions (PR #113942)

2024-11-07 Thread Sam Elliott via cfe-commits

lenary wrote:

> > I think we shouldn't do this for RVA22, so as not to break existing users 
> > of that profile, who may have a toolchain that doesn't support B.
> > This change makes sense to me for the RV*23 profiles, especially since your 
> > change to RVM23 has been accepted.
> 
> For RVA22, I had a look at the commit history for extension support in 
> binutils. From what I can see (@kito-cheng please correct me if I'm wrong):
> 
> * zic64b support was only committed in 
> 25f05199bb7e35820c23e802424484accb7936b1 in July 2024
> * B support was committed in c144f638337944101131d9fe6de4ab908f6d4c2d in May 
> 2024
> 
> So given we emit zic64b anyway (as it has always been in the RVA22 spec), I 
> think we probably do have freedom to add in B here without breaking binutils 
> that would have previously successfully assembled our rva22u64 output.

Alright, then I don't have any worries about RVA22.

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


[clang] [clang-tools-extra] [llvm] [clang] Introduce diagnostics suppression mappings (PR #112517)

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


@@ -701,11 +702,10 @@ class CompilerInstance : public ModuleLoader {
   /// used by some diagnostics printers (for logging purposes only).
   ///
   /// \return The new object on success, or null on failure.
-  static IntrusiveRefCntPtr
-  createDiagnostics(DiagnosticOptions *Opts,
-DiagnosticConsumer *Client = nullptr,
-bool ShouldOwnClient = true,
-const CodeGenOptions *CodeGenOpts = nullptr);
+  static IntrusiveRefCntPtr createDiagnostics(
+  DiagnosticOptions *Opts, DiagnosticConsumer *Client = nullptr,
+  bool ShouldOwnClient = true, const CodeGenOptions *CodeGenOpts = nullptr,
+  IntrusiveRefCntPtr VFS = nullptr);

kadircet wrote:

i got that coming up in a future change, pending this one to land. 

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


[clang] [Clang] Remove the wrong assumption when rebuilding SizeOfPackExprs for constraint normalization (PR #115120)

2024-11-07 Thread Matheus Izvekov via cfe-commits


@@ -1731,31 +1731,21 @@ namespace {
   return inherited::TransformLambdaBody(E, Body);
 }
 
-ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
- NamedDecl *Pack, SourceLocation PackLoc,
- SourceLocation RParenLoc,
- std::optional Length,
- ArrayRef PartialArgs) {
-  if (SemaRef.CodeSynthesisContexts.back().Kind !=
-  Sema::CodeSynthesisContext::ConstraintNormalization)
-return inherited::RebuildSizeOfPackExpr(OperatorLoc, Pack, PackLoc,
-RParenLoc, Length, 
PartialArgs);
-
-#ifndef NDEBUG
-  for (auto *Iter = TemplateArgs.begin(); Iter != TemplateArgs.end();
-   ++Iter)
-for (const TemplateArgument &TA : Iter->Args)
-  assert(TA.getKind() != TemplateArgument::Pack || TA.pack_size() == 
1);
-#endif
-  Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
-  SemaRef, /*NewSubstitutionIndex=*/0);
-  Decl *NewPack = TransformDecl(PackLoc, Pack);
-  if (!NewPack)
-return ExprError();
-
-  return inherited::RebuildSizeOfPackExpr(OperatorLoc,
-  cast(NewPack), 
PackLoc,
-  RParenLoc, Length, PartialArgs);
+ExprResult TransformSizeOfPackExpr(SizeOfPackExpr *E) {
+  ExprResult Transformed = inherited::TransformSizeOfPackExpr(E);
+  if (!Transformed.isUsable())
+return Transformed;
+  auto *TransformedExpr = cast(Transformed.get());
+  if (SemaRef.CodeSynthesisContexts.back().Kind ==
+  Sema::CodeSynthesisContext::ConstraintNormalization &&
+  TransformedExpr->getPack() == E->getPack()) {
+Decl *NewPack =
+TransformDecl(E->getPackLoc(), TransformedExpr->getPack());
+if (!NewPack)
+  return ExprError();
+TransformedExpr->setPack(cast(NewPack));

mizvekov wrote:

It looks like there is some dance here that could be avoided if we moved this 
into the inherited transform function in TreeTransform.h instead.

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


[clang] [Clang] Improve EmitClangAttrSpellingListIndex (PR #114899)

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


@@ -3843,19 +3844,60 @@ void EmitClangAttrSpellingListIndex(const RecordKeeper 
&Records,
 const Record &R = *I.second;
 std::vector Spellings = GetFlattenedSpellings(R);
 OS << "  case AT_" << I.first << ": {\n";
-for (unsigned I = 0; I < Spellings.size(); ++ I) {
-  OS << "if (Name == \"" << Spellings[I].name() << "\" && "
- << "getSyntax() == AttributeCommonInfo::AS_" << Spellings[I].variety()
- << " && Scope == \"" << Spellings[I].nameSpace() << "\")\n"
- << "return " << I << ";\n";
+
+// If there are none or one spelling to check, resort to the default
+// behavior of returning index as 0.
+if (Spellings.size() <= 1) {
+  OS << "return 0;\n"
+ << "break;\n"
+ << "  }\n";
+  continue;
 }
 
-OS << "break;\n";
-OS << "  }\n";
+std::vector Names;
+llvm::transform(Spellings, std::back_inserter(Names),
+[](const FlattenedSpelling &FS) { return FS.name(); });
+llvm::sort(Names);
+Names.erase(llvm::unique(Names), Names.end());
+
+for (const auto &[Idx, FS] : enumerate(Spellings)) {
+  if (Names.size() == 1) {
+OS << "if (";

erichkeane wrote:

As a nit, I'd suggest printing this unconditionally above this 'if', then 
inverting it for the 'else' condition (since 3873 and 3879 are both printing 
this too).

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


[clang] [Clang] Remove the wrong assumption when rebuilding SizeOfPackExprs for constraint normalization (PR #115120)

2024-11-07 Thread Matheus Izvekov via cfe-commits

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


[clang] Add clang atomic control options and attribute (PR #114841)

2024-11-07 Thread Yaxun Liu via cfe-commits


@@ -0,0 +1,19 @@
+//===--- AtomicOptions.def - Atomic Options database -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+// This file defines the Atomic language options. Users of this file
+// must define the OPTION macro to make use of this information.
+#ifndef OPTION
+#  error Define the OPTION macro to handle atomic language options
+#endif
+
+// OPTION(name, type, width, previousName)
+OPTION(NoRemoteMemory, bool, 1, First)
+OPTION(NoFineGrainedMemory, bool, 1, NoRemoteMemory)
+OPTION(IgnoreDenormalMode, bool, 1, NoFineGrainedMemory)
+
+#undef OPTION

yxsamliu wrote:

will fix

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


[clang] [emacs][clang-format] Add elisp API for clang-format on git diffs (PR #112792)

2024-11-07 Thread via cfe-commits

https://github.com/goldsteinn updated 
https://github.com/llvm/llvm-project/pull/112792

>From 802764e879862541e205ba1a070824b71d2fef9a Mon Sep 17 00:00:00 2001
From: Noah Goldstein 
Date: Thu, 17 Oct 2024 17:31:24 -0500
Subject: [PATCH 01/12] [emacs][clang-format] Add elisp API for clang-format on
 git diffs

New proposed function `clang-format-git-diffs`.

It is the same as calling `clang-format-region` on all diffs between
the content of a buffer-file and the content of the file at git
revision HEAD. This is essentially the same thing as:
`git-clang-format -f {filename}`
If the current buffer is saved.

The motivation is many project (LLVM included) both have code that is
non-compliant with there clang-format style and disallow unrelated
format diffs in PRs. This means users can't just run
`clang-format-buffer` on the buffer they are working on, and need to
manually go through all the regions by hand to get them
formatted. This is both an error prone and annoying workflow.
---
 clang/tools/clang-format/clang-format.el | 159 ---
 1 file changed, 144 insertions(+), 15 deletions(-)

diff --git a/clang/tools/clang-format/clang-format.el 
b/clang/tools/clang-format/clang-format.el
index fb943b7b722f8a..d3f874de41c550 100644
--- a/clang/tools/clang-format/clang-format.el
+++ b/clang/tools/clang-format/clang-format.el
@@ -146,18 +146,97 @@ is a zero-based file offset, assuming ‘utf-8-unix’ 
coding."
 (lambda (byte &optional _quality _coding-system)
   (byte-to-position (1+ byte)
 
-;;;###autoload
-(defun clang-format-region (start end &optional style assume-file-name)
-  "Use clang-format to format the code between START and END according to 
STYLE.
-If called interactively uses the region or the current statement if there is no
-no active region. If no STYLE is given uses `clang-format-style'. Use
-ASSUME-FILE-NAME to locate a style config file, if no ASSUME-FILE-NAME is given
-uses the function `buffer-file-name'."
-  (interactive
-   (if (use-region-p)
-   (list (region-beginning) (region-end))
- (list (point) (point
-
+(defun clang-format--git-diffs-get-diff-lines (file-orig file-new)
+  "Return all line regions that contain diffs between FILE-ORIG and
+FILE-NEW.  If there is no diff 'nil' is returned. Otherwise the
+return is a 'list' of lines in the format '--lines=:'
+which can be passed directly to 'clang-format'"
+  ;; Temporary buffer for output of diff.
+  (with-temp-buffer
+(let ((status (call-process
+   "diff"
+   nil
+   (current-buffer)
+   nil
+   ;; Binary diff has different behaviors that we
+   ;; aren't interested in.
+   "-a"
+   ;; Printout changes as only the line groups.
+   "--changed-group-format=--lines=%dF:%dL "
+   ;; Ignore unchanged content.
+   "--unchanged-group-format="
+   file-orig
+   file-new
+   )
+  )
+  (stderr (concat (if (zerop (buffer-size)) "" ": ")
+  (buffer-substring-no-properties
+   (point-min) (line-end-position)
+  (when (stringp status)
+(error "(diff killed by signal %s%s)" status stderr))
+  (unless (= status 0)
+(unless (= status 1)
+  (error "(diff returned unsuccessfully %s%s)" status stderr)))
+
+
+  (if (= status 0)
+  ;; Status == 0 -> no Diff.
+  nil
+(progn
+  ;; Split "--lines=:... --lines=:" output to
+  ;; a list for return.
+  (s-split
+   " "
+   (string-trim
+(buffer-substring-no-properties
+ (point-min) (point-max)
+
+(defun clang-format--git-diffs-get-git-head-file ()
+  "Returns a temporary file with the content of 'buffer-file-name' at
+git revision HEAD. If the current buffer is either not a file or not
+in a git repo, this results in an error"
+  ;; Needs current buffer to be a file
+  (unless (buffer-file-name)
+(error "Buffer is not visiting a file"))
+  ;; Need to be able to find version control (git) root
+  (unless (vc-root-dir)
+(error "File not known to git"))
+  ;; Need version control to in fact be git
+  (unless (string-equal (vc-backend (buffer-file-name)) "Git")
+(error "Not using git"))
+
+  (let ((tmpfile-git-head (make-temp-file 
"clang-format-tmp-git-head-content")))
+;; Get filename relative to git root
+(let ((git-file-name (substring
+  (expand-file-name (buffer-file-name))
+  (string-width (expand-file-name (vc-root-dir)))
+  nil)))
+  (let ((status (call-process
+ "git"
+ nil
+ `(:file, tmpfile-git-head)
+ nil
+ "show" (concat "HEAD:" git-file-nam

[clang] Enable AST mutation in the constant evaluator (PR #115168)

2024-11-07 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [Clang] skip default argument instantiation for non-defining friend declarations without specialization info to meet [dcl.fct.default] p4 (PR #113777)

2024-11-07 Thread Oleksandr T. via cfe-commits

a-tarasyuk wrote:

@mizvekov thanks

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


[clang] [llvm] [Driver][SYCL] Add initial SYCL offload compilation support (PR #107493)

2024-11-07 Thread Michael Toguchi via cfe-commits

mdtoguchi wrote:

Ping

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


[clang] [Clang] Distinguish expanding-packs-in-place cases for SubstTemplateTypeParmTypes (PR #114220)

2024-11-07 Thread Matheus Izvekov via cfe-commits


@@ -3149,9 +3156,15 @@ struct ExpandPackedTypeConstraints
 
 assert(SemaRef.ArgumentPackSubstitutionIndex != -1);
 
+TemplateArgument Arg = TemplateArgs(T->getDepth(), T->getIndex());
+
+std::optional PackIndex;
+if (Arg.getKind() == TemplateArgument::Pack)
+  PackIndex = Arg.pack_size() - 1 - SemaRef.ArgumentPackSubstitutionIndex;

mizvekov wrote:

These index transformations also come up in other places, where some other 
index is used, instead of the current Sema pack subst index. That would be 
worth refactoring, also consolidating asserts.

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


[clang] [llvm] [HLSL][SPIRV] Added clamp intrinsic (PR #113394)

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

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


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


[clang] [clang][serialization] Pass `ASTContext` explicitly (PR #115235)

2024-11-07 Thread Ben Langmuir via cfe-commits


@@ -4753,15 +4755,12 @@ void ASTWriter::AddString(StringRef Str, RecordDataImpl 
&Record) {
 }
 
 bool ASTWriter::PreparePathForOutput(SmallVectorImpl &Path) {
-  assert(Context && "should have context when outputting path");
-
   // Leave special file names as they are.
   StringRef PathStr(Path.data(), Path.size());
   if (PathStr == "" || PathStr == "")
 return false;
 
-  bool Changed =
-  cleanPathForOutput(Context->getSourceManager().getFileManager(), Path);
+  bool Changed = cleanPathForOutput(PP->getFileManager(), Path);

benlangmuir wrote:

What's your opinion on the use of nullable `PP`? This seems like the same issue 
as `Context` where it's not obvious where it's mandatory and where it's not.

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


[clang] 7bd9be2 - [Driver] Use heterogenous lookups with std::set (NFC) (#115259)

2024-11-07 Thread via cfe-commits

Author: Kazu Hirata
Date: 2024-11-07T10:54:12-08:00
New Revision: 7bd9be2e0a74e6d17ec3f95ff364a4461dec4dbe

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

LOG: [Driver] Use heterogenous lookups with std::set (NFC) (#115259)

Heterogenous lookups allow us to call find with StringRef, avoiding a
temporary heap allocation of std::string.

Added: 


Modified: 
clang/lib/Driver/ToolChains/HIPUtility.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/HIPUtility.cpp 
b/clang/lib/Driver/ToolChains/HIPUtility.cpp
index c8075cbfe36b35..3f81c3cb0f80e8 100644
--- a/clang/lib/Driver/ToolChains/HIPUtility.cpp
+++ b/clang/lib/Driver/ToolChains/HIPUtility.cpp
@@ -148,8 +148,8 @@ class HIPUndefinedFatBinSymbols {
   bool Verbose;
   std::set FatBinSymbols;
   std::set GPUBinHandleSymbols;
-  std::set DefinedFatBinSymbols;
-  std::set DefinedGPUBinHandleSymbols;
+  std::set> DefinedFatBinSymbols;
+  std::set> DefinedGPUBinHandleSymbols;
   const std::string FatBinPrefix = "__hip_fatbin";
   const std::string GPUBinHandlePrefix = "__hip_gpubin_handle";
 
@@ -260,11 +260,10 @@ class HIPUndefinedFatBinSymbols {
 
   // Add undefined symbols if they are not in the defined sets
   if (isFatBinSymbol &&
-  DefinedFatBinSymbols.find(Name.str()) == DefinedFatBinSymbols.end())
+  DefinedFatBinSymbols.find(Name) == DefinedFatBinSymbols.end())
 FatBinSymbols.insert(Name.str());
-  else if (isGPUBinHandleSymbol &&
-   DefinedGPUBinHandleSymbols.find(Name.str()) ==
-   DefinedGPUBinHandleSymbols.end())
+  else if (isGPUBinHandleSymbol && DefinedGPUBinHandleSymbols.find(Name) ==
+   DefinedGPUBinHandleSymbols.end())
 GPUBinHandleSymbols.insert(Name.str());
 }
   }



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


[clang] c714f92 - [InstallAPI] Call DenseMap::find without constructing std::string (NFC) (#115260)

2024-11-07 Thread via cfe-commits

Author: Kazu Hirata
Date: 2024-11-07T10:54:35-08:00
New Revision: c714f928b2f9ab3dd481f272a2aa72b83fd0562e

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

LOG: [InstallAPI] Call DenseMap::find without constructing std::string (NFC) 
(#115260)

KnownIncludes is of DenseMap, so we don't need
to allocate a temporary instance of std::string.

Added: 


Modified: 
clang/lib/InstallAPI/Frontend.cpp

Removed: 




diff  --git a/clang/lib/InstallAPI/Frontend.cpp 
b/clang/lib/InstallAPI/Frontend.cpp
index 2ebe72bf021cf9..9e8c60fbda3d00 100644
--- a/clang/lib/InstallAPI/Frontend.cpp
+++ b/clang/lib/InstallAPI/Frontend.cpp
@@ -94,7 +94,7 @@ InstallAPIContext::findAndRecordFile(const FileEntry *FE,
   // included. This is primarily to resolve headers found
   // in a 
diff erent location than what passed directly as input.
   StringRef IncludeName = PP.getHeaderSearchInfo().getIncludeNameForHeader(FE);
-  auto BackupIt = KnownIncludes.find(IncludeName.str());
+  auto BackupIt = KnownIncludes.find(IncludeName);
   if (BackupIt != KnownIncludes.end()) {
 KnownFiles[FE] = BackupIt->second;
 return BackupIt->second;



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


[clang] [InstallAPI] Call DenseMap::find without constructing std::string (NFC) (PR #115260)

2024-11-07 Thread Kazu Hirata via cfe-commits

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


[clang] [Driver] Use heterogenous lookups with std::set (NFC) (PR #115259)

2024-11-07 Thread Kazu Hirata via cfe-commits

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


[clang] [Clang] Distinguish expanding-packs-in-place cases for SubstTemplateTypeParmTypes (PR #114220)

2024-11-07 Thread Shafik Yaghmour via cfe-commits


@@ -3149,9 +3156,15 @@ struct ExpandPackedTypeConstraints
 
 assert(SemaRef.ArgumentPackSubstitutionIndex != -1);
 
+TemplateArgument Arg = TemplateArgs(T->getDepth(), T->getIndex());
+
+std::optional PackIndex;
+if (Arg.getKind() == TemplateArgument::Pack)
+  PackIndex = Arg.pack_size() - 1 - SemaRef.ArgumentPackSubstitutionIndex;

shafik wrote:

Agreed, it seems like a valuable refactor to me.

When I see hand math like that it always raises my spidey senses and I look to 
see where else we are doing something like that.

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


[clang] [Webkit Checkers] Introduce a Webkit checker for memory unsafe casts (PR #114606)

2024-11-07 Thread Ryosuke Niwa via cfe-commits


@@ -0,0 +1,117 @@
+//===- MemoryUnsafeCastChecker.cpp -*- C++ -*-==//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file defines MemoryUnsafeCast checker, which checks for casts from a
+// base type to a derived type.
+//===--===//
+
+#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
+#include "clang/AST/StmtVisitor.h"
+#include "clang/Analysis/AnalysisDeclContext.h"
+#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace clang;
+using namespace ento;
+
+namespace {
+class WalkAST : public StmtVisitor {
+  BugReporter &BR;
+  const CheckerBase *Checker;
+  AnalysisDeclContext* AC;
+  ASTContext &ASTC;
+
+public:
+  WalkAST(BugReporter &br, const CheckerBase *checker, AnalysisDeclContext *ac)
+  : BR(br), Checker(checker), AC(ac), ASTC(AC->getASTContext()) {}
+
+  // Statement visitor methods.
+  void VisitChildren(Stmt *S);
+  void VisitStmt(Stmt *S) { VisitChildren(S); }
+  void VisitCastExpr(CastExpr *CE);
+};
+} // end anonymous namespace
+
+void emitWarning(QualType FromType, QualType ToType,
+ AnalysisDeclContext *AC, BugReporter &BR,
+ const CheckerBase *Checker,
+ CastExpr *CE) {
+  std::string Diagnostics;
+  llvm::raw_string_ostream OS(Diagnostics);
+  OS << "Unsafe cast from base type '"
+ << FromType
+ << "' to derived type '"
+ << ToType
+ << "'",
+
+  BR.EmitBasicReport(
+AC->getDecl(),
+Checker,
+/*Name=*/"Memory unsafe cast",
+categories::SecurityError,
+Diagnostics,
+PathDiagnosticLocation::createBegin(CE, BR.getSourceManager(), AC),
+CE->getSourceRange());
+}
+
+namespace {
+class MemoryUnsafeCastChecker : public Checker {
+  BugType BT{this, ""};
+public:
+  void checkASTCodeBody(const Decl *D, AnalysisManager& Mgr,
+BugReporter &BR) const {
+WalkAST walker(BR, this, Mgr.getAnalysisDeclContext(D));

rniwa wrote:

Hm... wouldn't it make it hard to cherry-pick this change to `stable/20230723` 
branch? We're still using that branch as a base so it would be ideal if this 
checker was written in such a way that it works with the branch.

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


[clang] Add clang atomic control options and attribute (PR #114841)

2024-11-07 Thread Yaxun Liu via cfe-commits


@@ -569,19 +569,21 @@ void AMDGPUTargetCodeGenInfo::setTargetAtomicMetadata(
 AtomicInst.setMetadata(llvm::LLVMContext::MD_noalias_addrspace, ASRange);
   }
 
-  if (!RMW || !CGF.getTarget().allowAMDGPUUnsafeFPAtomics())
+  if (!RMW)
 return;
 
-  // TODO: Introduce new, more controlled options that also work for integers,
-  // and deprecate allowAMDGPUUnsafeFPAtomics.
-  llvm::AtomicRMWInst::BinOp RMWOp = RMW->getOperation();
-  if (llvm::AtomicRMWInst::isFPOperation(RMWOp)) {
-llvm::MDNode *Empty = llvm::MDNode::get(CGF.getLLVMContext(), {});
+  AtomicOptions AO = CGF.CGM.getAtomicOpts();
+  llvm::MDNode *Empty = llvm::MDNode::get(CGF.getLLVMContext(), {});
+  if (AO.getNoFineGrainedMemory())
 RMW->setMetadata("amdgpu.no.fine.grained.memory", Empty);
-
-if (RMWOp == llvm::AtomicRMWInst::FAdd && RMW->getType()->isFloatTy())
-  RMW->setMetadata("amdgpu.ignore.denormal.mode", Empty);
-  }
+  if (AO.getNoRemoteMemory())
+RMW->setMetadata("amdgpu.no.remote.memory", Empty);
+
+  if ((AO.getIgnoreDenormalMode() ||
+   CGF.getTarget().allowAMDGPUUnsafeFPAtomics()) &&

yxsamliu wrote:

I will remove the use of CGF.getTarget().allowAMDGPUUnsafeFPAtomics() here 
since it should override the default value for IgnoreDenormalMode attribute, 
which I have done in Basic/Targets/AMDGPU.cpp.

amdgpu.no.fine.grained.memory is on by default, therefore does not need to be 
implied by allowAMDGPUUnsafeFPAtomics

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


[clang] Add clang atomic control options and attribute (PR #114841)

2024-11-07 Thread Yaxun Liu via cfe-commits


@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify -fcuda-is-device %s
+// RUN: %clang_cc1 -fsyntax-only -verify -fcuda-is-device %s \
+// RUN:   
-fatomic=no_fine_grained_memory:off,no_remote_memory:on,ignore_denormal_mode:on
+
+#include "Inputs/cuda.h"
+
+[[clang::atomic(!no_remote_memory)]] // expected-error {{'atomic' attribute 
cannot be applied to a declaration}}
+__device__ __host__ void test_location(float *a) {
+  __scoped_atomic_fetch_add(a, 1, __ATOMIC_RELAXED, __MEMORY_SCOPE_SYSTEM);
+  [[clang::atomic(!no_remote_memory)]] int x; // expected-error {{'atomic' 
attribute cannot be applied to a declaration}}
+}
+
+__device__ __host__ void test_invalid_option(float *a) {
+  [[clang::atomic(fast)]] { // expected-error {{invalid argument 'fast' to 
atomic attribute; valid options are: 'no_remote_memory', 
'no_fine_grained_memory', 'ignore_denormal_mode' (optionally prefixed with 
'!')}}
+__scoped_atomic_fetch_add(a, 1, __ATOMIC_RELAXED, __MEMORY_SCOPE_SYSTEM);
+  }
+}
+
+__device__ __host__ void test_invalid_value(float *a) {
+  [[clang::atomic(no_remote_memory(default))]] { // expected-error {{expected 
')'}} expected-note {{to match this '('}}
+__scoped_atomic_fetch_add(a, 1, __ATOMIC_RELAXED, __MEMORY_SCOPE_SYSTEM);
+  }
+}
+
+__device__ __host__ void test_invalid_format(float *a) {
+  [[clang::atomic(no_remote_memory=on)]] { // expected-error {{expected ')'}} 
expected-note {{to match this '('}}
+__scoped_atomic_fetch_add(a, 1, __ATOMIC_RELAXED, __MEMORY_SCOPE_SYSTEM);
+  }
+}

yxsamliu wrote:

will fix

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


[clang] [llvm] [Clang] Match MSVC handling of duplicate header search paths in Microsoft compatibility modes. (PR #105738)

2024-11-07 Thread Tom Honermann via cfe-commits

tahonermann wrote:

> Doesn't that impact whether a header is found via `""` or `<>` syntax? e.g., 
> if something went from a user header to a system header, I thought that meant 
> the search order would then change depending on which include syntax you used?

No, those are orthogonal concerns, but there is unfortunate terminology 
overlap. Options like `-isystem` nominate system include paths and headers 
found within those paths are treated as system headers. However, a header found 
via another include path can still be considered a system header. Consider a 
header file that contains `#pragma GCC system_header`; such a header file is 
considered a system header, but doesn't influence how header file inclusion is 
resolved.

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


[clang] [Webkit Checkers] Introduce a Webkit checker for memory unsafe casts (PR #114606)

2024-11-07 Thread Ryosuke Niwa via cfe-commits

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


[clang] 24e2e25 - [C2y] Implement WG14 N3344 (#115313)

2024-11-07 Thread via cfe-commits

Author: Aaron Ballman
Date: 2024-11-07T10:34:00-05:00
New Revision: 24e2e259a06d9aa67dc278ac24dcb98da9dd63f6

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

LOG: [C2y] Implement WG14 N3344 (#115313)

https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3344.pdf

This paper disallows a single `void` parameter from having qualifiers or
storage class specifiers. Clang has diagnosed most of these as an error
for a long time, but `register void` was previously accepted in all C
language modes and is now being rejected in all C language modes.

Added: 
clang/test/C/C2y/n3344.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDecl.cpp
clang/www/c_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 061a1fed3f7d48..3e7d8e15110f9d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -280,6 +280,12 @@ C2y Feature Support
   this is now a C2y extension in C. ``-Wgnu-case-range`` still applies in C++
   modes.
 
+- Clang implemented support for `N3344 
`_
+  which disallows a ``void`` parameter from having a qualifier or storage class
+  specifier. Note that ``register void`` was previously accepted in all C
+  language modes but is now rejected (all of the other qualifiers and storage
+  class specifiers were previously rejected).
+
 C23 Feature Support
 ^^^
 

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index aba6b555ff28f3..c9cd81a48fbe51 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -15002,6 +15002,12 @@ Decl *Sema::ActOnParamDeclarator(Scope *S, Declarator 
&D,
   const DeclSpec &DS = D.getDeclSpec();
 
   // Verify C99 6.7.5.3p2: The only SCS allowed is 'register'.
+  // C2y 6.7.7.4p4: A parameter declaration shall not specify a void type,
+  // except for the special case of a single unnamed parameter of type void
+  // with no storage class specifier, no type qualifier, and no following
+  // ellipsis terminator.
+  // Clang applies the C2y rules for 'register void' in all C language modes,
+  // same as GCC, because it's questionable what that could possibly mean.
 
   // C++03 [dcl.stc]p2 also permits 'auto'.
   StorageClass SC = SC_None;
@@ -15010,10 +15016,16 @@ Decl *Sema::ActOnParamDeclarator(Scope *S, Declarator 
&D,
 // In C++11, the 'register' storage class specifier is deprecated.
 // In C++17, it is not allowed, but we tolerate it as an extension.
 if (getLangOpts().CPlusPlus11) {
+  Diag(DS.getStorageClassSpecLoc(), getLangOpts().CPlusPlus17
+? diag::ext_register_storage_class
+: diag::warn_deprecated_register)
+  << FixItHint::CreateRemoval(DS.getStorageClassSpecLoc());
+} else if (!getLangOpts().CPlusPlus &&
+   DS.getTypeSpecType() == DeclSpec::TST_void) {
   Diag(DS.getStorageClassSpecLoc(),
-   getLangOpts().CPlusPlus17 ? diag::ext_register_storage_class
- : diag::warn_deprecated_register)
-<< FixItHint::CreateRemoval(DS.getStorageClassSpecLoc());
+   diag::err_invalid_storage_class_in_func_decl)
+  << FixItHint::CreateRemoval(DS.getStorageClassSpecLoc());
+  D.getMutableDeclSpec().ClearStorageClassSpecs();
 }
   } else if (getLangOpts().CPlusPlus &&
  DS.getStorageClassSpec() == DeclSpec::SCS_auto) {

diff  --git a/clang/test/C/C2y/n3344.c b/clang/test/C/C2y/n3344.c
new file mode 100644
index 00..bd3d440cb5d12a
--- /dev/null
+++ b/clang/test/C/C2y/n3344.c
@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -verify -std=c2y -Wall -pedantic %s
+// RUN: %clang_cc1 -verify -Wall -pedantic %s
+
+/* WG14 N3344: Yes
+ * Slay Some Earthly Demons VI
+ *
+ * A 'void' parameter cannot have any qualifiers, storage class specifiers, or
+ * be followed by an ellipsis.
+ *
+ * Note: Clang treats 'register void' as being a DR and rejects it in all
+ * language modes; there's no evidence that this will break users and it's not
+ * clear what the programmer intended if they wrote such code anyway. This
+ * matches GCC's behavior.
+ */
+
+void baz(volatile void); // expected-error {{'void' as parameter must 
not have type qualifiers}}
+void bar(const void);// expected-error {{'void' as parameter must 
not have type qualifiers}}
+void foo(register void); // expected-error {{invalid storage class 
specifier in function declarator}}
+void quux(static void);  // expected-error {{invalid storage class 
specifier in function declarator}}
+void quobble(auto void); // expected-error {{invalid storage class 
s

[clang] [clang][serialization] Pass `ASTContext` explicitly (PR #115235)

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


@@ -4753,15 +4755,12 @@ void ASTWriter::AddString(StringRef Str, RecordDataImpl 
&Record) {
 }
 
 bool ASTWriter::PreparePathForOutput(SmallVectorImpl &Path) {
-  assert(Context && "should have context when outputting path");
-
   // Leave special file names as they are.
   StringRef PathStr(Path.data(), Path.size());
   if (PathStr == "" || PathStr == "")
 return false;
 
-  bool Changed =
-  cleanPathForOutput(Context->getSourceManager().getFileManager(), Path);
+  bool Changed = cleanPathForOutput(PP->getFileManager(), Path);

jansvoboda11 wrote:

Yeah, I think `PP` has the same issues. Both `PP` and `Context` are null 
outside of `WriteAST()`, which is a foot gun.

However, `PP` is guaranteed to be non-null during the `WriteAST()` call, while 
`Context` may be null during that call (after 
https://github.com/llvm/llvm-project/pull/115239). So `Context` will have more 
complicated rules and they will only be exercised during scanning. I think that 
would make it easy to make changes that will work for regular module compiles, 
but break the scanner. That's why I see more value in doing this transformation 
to `Context`. 

To be clear I would like to do the same thing with `PP`, it's just that its 
simpler rules don't make it super important in my opinion. And any uses of null 
`PP` would be caught outside of the scanner, in normal module compiles.

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


[clang] [analyzer][NFC] Remove check::BranchCondition from debug.DumpTraversal (PR #113906)

2024-11-07 Thread Donát Nagy via cfe-commits

NagyDonat wrote:

Thanks for the information!

I'll merge this now and I might create a followup commit to remove the rest of 
`TraversalChecker.cpp` later.

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


[clang] [Clang] Improve EmitClangAttrSpellingListIndex (PR #114899)

2024-11-07 Thread Chinmay Deshpande via cfe-commits

https://github.com/chinmaydd updated 
https://github.com/llvm/llvm-project/pull/114899

>From cf4d70c23b2896483b452622300aa4c8c41c01e5 Mon Sep 17 00:00:00 2001
From: Chinmay Deshpande 
Date: Fri, 1 Nov 2024 19:49:52 -0400
Subject: [PATCH 1/5] [Clang] Improve EmitClangAttrSpellingListIndex

EmitClangAttrSpellingListIndex() performs a lot of
unnecessary string comparisons which is wasteful in time and space. This
commit attempts to refactor this method to be more performant.
---
 .../include/clang/Basic/AttributeCommonInfo.h | 10 ++
 clang/lib/Basic/Attributes.cpp| 28 +-
 clang/utils/TableGen/ClangAttrEmitter.cpp | 95 ++-
 3 files changed, 126 insertions(+), 7 deletions(-)

diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h 
b/clang/include/clang/Basic/AttributeCommonInfo.h
index 5f024b4b5fd782..834b3ca62adced 100644
--- a/clang/include/clang/Basic/AttributeCommonInfo.h
+++ b/clang/include/clang/Basic/AttributeCommonInfo.h
@@ -67,6 +67,16 @@ class AttributeCommonInfo {
 IgnoredAttribute,
 UnknownAttribute,
   };
+  enum Scope {
+SC_NONE,
+SC_CLANG,
+SC_GNU,
+SC_MSVC,
+SC_OMP,
+SC_HLSL,
+SC_GSL,
+SC_RISCV
+  };
 
 private:
   const IdentifierInfo *AttrName = nullptr;
diff --git a/clang/lib/Basic/Attributes.cpp b/clang/lib/Basic/Attributes.cpp
index 867d241a2cf847..6f5a70674cbd4b 100644
--- a/clang/lib/Basic/Attributes.cpp
+++ b/clang/lib/Basic/Attributes.cpp
@@ -16,6 +16,7 @@
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/ParsedAttrInfo.h"
 #include "clang/Basic/TargetInfo.h"
+#include "llvm/ADT/StringMap.h"
 
 using namespace clang;
 
@@ -153,12 +154,35 @@ std::string AttributeCommonInfo::getNormalizedFullName() 
const {
   normalizeName(getAttrName(), getScopeName(), getSyntax()));
 }
 
+static const llvm::StringMap ScopeMap = {
+{"", AttributeCommonInfo::SC_NONE},
+{"clang", AttributeCommonInfo::SC_CLANG},
+{"gnu", AttributeCommonInfo::SC_GNU},
+{"msvc", AttributeCommonInfo::SC_MSVC},
+{"omp", AttributeCommonInfo::SC_OMP},
+{"hlsl", AttributeCommonInfo::SC_HLSL},
+{"gsl", AttributeCommonInfo::SC_GSL},
+{"riscv", AttributeCommonInfo::SC_RISCV}};
+
+AttributeCommonInfo::Scope
+getScopeFromNormalizedScopeName(const StringRef ScopeName) {
+  auto It = ScopeMap.find(ScopeName);
+  if (It == ScopeMap.end()) {
+llvm_unreachable("Unknown normalized scope name. Shouldn't get here");
+  }
+
+  return It->second;
+}
+
 unsigned AttributeCommonInfo::calculateAttributeSpellingListIndex() const {
   // Both variables will be used in tablegen generated
   // attribute spell list index matching code.
   auto Syntax = static_cast(getSyntax());
-  StringRef Scope = normalizeAttrScopeName(getScopeName(), Syntax);
-  StringRef Name = normalizeAttrName(getAttrName(), Scope, Syntax);
+  StringRef ScopeName = normalizeAttrScopeName(getScopeName(), Syntax);
+  StringRef Name = normalizeAttrName(getAttrName(), ScopeName, Syntax);
+
+  AttributeCommonInfo::Scope ComputedScope =
+  getScopeFromNormalizedScopeName(ScopeName);
 
 #include "clang/Sema/AttrSpellingListIndex.inc"
 }
diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 5a80c8c0b7ad36..4db75a92639ad6 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -20,6 +20,7 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/ADT/StringSwitch.h"
@@ -3843,11 +3844,95 @@ void EmitClangAttrSpellingListIndex(const RecordKeeper 
&Records,
 const Record &R = *I.second;
 std::vector Spellings = GetFlattenedSpellings(R);
 OS << "  case AT_" << I.first << ": {\n";
-for (unsigned I = 0; I < Spellings.size(); ++ I) {
-  OS << "if (Name == \"" << Spellings[I].name() << "\" && "
- << "getSyntax() == AttributeCommonInfo::AS_" << Spellings[I].variety()
- << " && Scope == \"" << Spellings[I].nameSpace() << "\")\n"
- << "return " << I << ";\n";
+
+// If there are none or one spelling to check, resort to the default
+// behavior of returning index as 0.
+if (Spellings.size() <= 1) {
+  OS << "return 0;\n";
+  OS << "break;\n";
+  OS << "  }\n";
+  continue;
+}
+
+bool HasSingleUniqueSpellingName = true;
+StringMap> SpellingMap;
+
+StringRef FirstName = Spellings.front().name();
+for (const auto &S : Spellings) {
+  StringRef Name = S.name();
+  if (Name != FirstName)
+HasSingleUniqueSpellingName = false;
+  SpellingMap[Name].push_back(&S);
+}
+
+// If parsed attribute has only one possible spelling name, only compare
+// syntax and scope.
+if (HasSingleUniqueSpellingName) {
+  for (const auto &[Idx, S] : enumerate(SpellingMap[FirstName

[clang] [clang] Set FPOptions at the beginning of CompoundStmt (PR #111654)

2024-11-07 Thread Zahira Ammarguellat via cfe-commits

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


[clang] [clang] Set FPOptions at the beginning of CompoundStmt (PR #111654)

2024-11-07 Thread Zahira Ammarguellat via cfe-commits


@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -ffast-math -ffp-contract=fast -emit-llvm -o - %s | 
FileCheck %s
+// RUN: %clang_cc1 -ffast-math -ffp-contract=fast -emit-llvm -O2 -o - %s | 
FileCheck %s

zahiraam wrote:

It seems to me that this issue exists only at O2, right? 
https://godbolt.org/z/xGcWG1aM6
Shouldn't that be reflected in the code somewhere? 

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


[clang] [clang] Set FPOptions at the beginning of CompoundStmt (PR #111654)

2024-11-07 Thread Zahira Ammarguellat via cfe-commits


@@ -1684,6 +1684,15 @@ class CompoundStmt final
 return hasStoredFPFeatures() ? getStoredFPFeatures() : FPOptionsOverride();
   }
 
+  /// Get FPOptions inside this statement. They may differ from the outer
+  /// options due to pragmas.
+  /// \param CurFPOptions FPOptions outside this statement.
+  FPOptions getInsideFPOptions(FPOptions CurFPOptions) const {

zahiraam wrote:

How about giving another name to this function? Something like 
`getStoredFPFeaturesInStmt` or `getStoredFPFeaturesInCompoundStmt`.

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


[clang] [clang] Set FPOptions at the beginning of CompoundStmt (PR #111654)

2024-11-07 Thread Zahira Ammarguellat via cfe-commits

https://github.com/zahiraam commented:

You seem to have some fails in the CI.

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


[clang] [z/OS] Make sure __alignas_is_defined and __alignof_is_defined are defined on z/OS. (PR #115368)

2024-11-07 Thread Zibi Sarbinowski via cfe-commits

https://github.com/zibi2 created 
https://github.com/llvm/llvm-project/pull/115368

None

>From 34569fd0fbe6894d598d48e2088040ee730d308d Mon Sep 17 00:00:00 2001
From: Zbigniew Sarbinowski 
Date: Thu, 7 Nov 2024 20:27:52 +
Subject: [PATCH] Make sure __alignas_is_defined and __alignof_is_defined are
 defined on z/OS

---
 clang/lib/Headers/stdalign.h | 5 -
 1 file changed, 5 deletions(-)

diff --git a/clang/lib/Headers/stdalign.h b/clang/lib/Headers/stdalign.h
index 56cdfa52d4bafa..158508e65d2b34 100644
--- a/clang/lib/Headers/stdalign.h
+++ b/clang/lib/Headers/stdalign.h
@@ -10,10 +10,6 @@
 #ifndef __STDALIGN_H
 #define __STDALIGN_H
 
-#if defined(__MVS__) && __has_include_next()
-#include_next 
-#else
-
 #if defined(__cplusplus) ||
\
 (defined(__STDC_VERSION__) && __STDC_VERSION__ < 202311L)
 #ifndef __cplusplus
@@ -25,5 +21,4 @@
 #define __alignof_is_defined 1
 #endif /* __STDC_VERSION__ */
 
-#endif /* __MVS__ */
 #endif /* __STDALIGN_H */

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


[clang] [z/OS] Make sure __alignas_is_defined and __alignof_is_defined are defined on z/OS. (PR #115368)

2024-11-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Zibi Sarbinowski (zibi2)


Changes



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


1 Files Affected:

- (modified) clang/lib/Headers/stdalign.h (-5) 


``diff
diff --git a/clang/lib/Headers/stdalign.h b/clang/lib/Headers/stdalign.h
index 56cdfa52d4bafa..158508e65d2b34 100644
--- a/clang/lib/Headers/stdalign.h
+++ b/clang/lib/Headers/stdalign.h
@@ -10,10 +10,6 @@
 #ifndef __STDALIGN_H
 #define __STDALIGN_H
 
-#if defined(__MVS__) && __has_include_next()
-#include_next 
-#else
-
 #if defined(__cplusplus) ||
\
 (defined(__STDC_VERSION__) && __STDC_VERSION__ < 202311L)
 #ifndef __cplusplus
@@ -25,5 +21,4 @@
 #define __alignof_is_defined 1
 #endif /* __STDC_VERSION__ */
 
-#endif /* __MVS__ */
 #endif /* __STDALIGN_H */

``




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


[clang] [z/OS] Make sure __alignas_is_defined and __alignof_is_defined are defined on z/OS. (PR #115368)

2024-11-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-x86

Author: Zibi Sarbinowski (zibi2)


Changes



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


1 Files Affected:

- (modified) clang/lib/Headers/stdalign.h (-5) 


``diff
diff --git a/clang/lib/Headers/stdalign.h b/clang/lib/Headers/stdalign.h
index 56cdfa52d4bafa..158508e65d2b34 100644
--- a/clang/lib/Headers/stdalign.h
+++ b/clang/lib/Headers/stdalign.h
@@ -10,10 +10,6 @@
 #ifndef __STDALIGN_H
 #define __STDALIGN_H
 
-#if defined(__MVS__) && __has_include_next()
-#include_next 
-#else
-
 #if defined(__cplusplus) ||
\
 (defined(__STDC_VERSION__) && __STDC_VERSION__ < 202311L)
 #ifndef __cplusplus
@@ -25,5 +21,4 @@
 #define __alignof_is_defined 1
 #endif /* __STDC_VERSION__ */
 
-#endif /* __MVS__ */
 #endif /* __STDALIGN_H */

``




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


[clang] [z/OS] Make sure __alignas_is_defined and __alignof_is_defined are defined on z/OS. (PR #115368)

2024-11-07 Thread Abhina Sree via cfe-commits

https://github.com/abhina-sree approved this pull request.

LGTM

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


[clang] Fix for OpenMP offloading compilation error with GNU++20 option when using complex header (PR #115306)

2024-11-07 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/115306
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [C2y] Add test coverage for WG14 N3370 (PR #115054)

2024-11-07 Thread Aaron Ballman via cfe-commits

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


[clang] [clang] Support 'this' position for lifetimebound attribute (PR #115021)

2024-11-07 Thread Gábor Horváth via cfe-commits

https://github.com/Xazax-hun updated 
https://github.com/llvm/llvm-project/pull/115021

From 2c1b0358a5ebc65af8c4abc0720fc1febeb3109d Mon Sep 17 00:00:00 2001
From: Gabor Horvath 
Date: Tue, 5 Nov 2024 16:37:57 +
Subject: [PATCH] [clang] Support 'this' position for lifetimebound attribute

This patch makes the position -1 interpreted as the position for 'this'.
Adds some basic infrastructure and support for lifetimebound attribute.
---
 clang/include/clang/APINotes/Types.h  | 25 +++-
 clang/lib/APINotes/APINotesFormat.h   |  3 +-
 clang/lib/APINotes/APINotesReader.cpp | 18 
 clang/lib/APINotes/APINotesTypes.cpp  |  8 +
 clang/lib/APINotes/APINotesWriter.cpp | 29 +++
 clang/lib/APINotes/APINotesYAMLCompiler.cpp   | 28 +-
 clang/lib/Sema/SemaAPINotes.cpp   | 16 ++
 .../Inputs/Headers/Lifetimebound.apinotes |  4 +++
 .../APINotes/Inputs/Headers/Lifetimebound.h   |  1 -
 clang/test/APINotes/lifetimebound.cpp |  3 ++
 10 files changed, 114 insertions(+), 21 deletions(-)

diff --git a/clang/include/clang/APINotes/Types.h 
b/clang/include/clang/APINotes/Types.h
index 6327b7d75486fc..6ad1c850701146 100644
--- a/clang/include/clang/APINotes/Types.h
+++ b/clang/include/clang/APINotes/Types.h
@@ -445,9 +445,7 @@ class ParamInfo : public VariableInfo {
 RawRetainCountConvention() {}
 
   std::optional isNoEscape() const {
-if (!NoEscapeSpecified)
-  return std::nullopt;
-return NoEscape;
+return NoEscapeSpecified ? std::optional(NoEscape) : std::nullopt;
   }
   void setNoEscape(std::optional Value) {
 NoEscapeSpecified = Value.has_value();
@@ -455,9 +453,8 @@ class ParamInfo : public VariableInfo {
   }
 
   std::optional isLifetimebound() const {
-if (!LifetimeboundSpecified)
-  return std::nullopt;
-return Lifetimebound;
+return LifetimeboundSpecified ? std::optional(Lifetimebound)
+  : std::nullopt;
   }
   void setLifetimebound(std::optional Value) {
 LifetimeboundSpecified = Value.has_value();
@@ -643,6 +640,8 @@ class ObjCMethodInfo : public FunctionInfo {
   LLVM_PREFERRED_TYPE(bool)
   unsigned RequiredInit : 1;
 
+  std::optional Self;
+
   ObjCMethodInfo() : DesignatedInit(false), RequiredInit(false) {}
 
   friend bool operator==(const ObjCMethodInfo &, const ObjCMethodInfo &);
@@ -664,7 +663,7 @@ class ObjCMethodInfo : public FunctionInfo {
 inline bool operator==(const ObjCMethodInfo &LHS, const ObjCMethodInfo &RHS) {
   return static_cast(LHS) == RHS &&
  LHS.DesignatedInit == RHS.DesignatedInit &&
- LHS.RequiredInit == RHS.RequiredInit;
+ LHS.RequiredInit == RHS.RequiredInit && LHS.Self == RHS.Self;
 }
 
 inline bool operator!=(const ObjCMethodInfo &LHS, const ObjCMethodInfo &RHS) {
@@ -693,8 +692,20 @@ class FieldInfo : public VariableInfo {
 class CXXMethodInfo : public FunctionInfo {
 public:
   CXXMethodInfo() {}
+
+  std::optional This;
+
+  LLVM_DUMP_METHOD void dump(llvm::raw_ostream &OS);
 };
 
+inline bool operator==(const CXXMethodInfo &LHS, const CXXMethodInfo &RHS) {
+  return static_cast(LHS) == RHS && LHS.This == RHS.This;
+}
+
+inline bool operator!=(const CXXMethodInfo &LHS, const CXXMethodInfo &RHS) {
+  return !(LHS == RHS);
+}
+
 /// Describes API notes data for an enumerator.
 class EnumConstantInfo : public CommonEntityInfo {
 public:
diff --git a/clang/lib/APINotes/APINotesFormat.h 
b/clang/lib/APINotes/APINotesFormat.h
index 014ee7e2e3d397..4d1c698ae6310d 100644
--- a/clang/lib/APINotes/APINotesFormat.h
+++ b/clang/lib/APINotes/APINotesFormat.h
@@ -24,7 +24,8 @@ const uint16_t VERSION_MAJOR = 0;
 /// API notes file minor version number.
 ///
 /// When the format changes IN ANY WAY, this number should be incremented.
-const uint16_t VERSION_MINOR = 31; // lifetimebound
+const uint16_t VERSION_MINOR =
+32; // implicit parameter support (at position -1)
 
 const uint8_t kSwiftCopyable = 1;
 const uint8_t kSwiftNonCopyable = 2;
diff --git a/clang/lib/APINotes/APINotesReader.cpp 
b/clang/lib/APINotes/APINotesReader.cpp
index 1bde8482fce033..0f8fa1355bfb0a 100644
--- a/clang/lib/APINotes/APINotesReader.cpp
+++ b/clang/lib/APINotes/APINotesReader.cpp
@@ -14,6 +14,7 @@
 
//===--===//
 #include "clang/APINotes/APINotesReader.h"
 #include "APINotesFormat.h"
+#include "clang/APINotes/Types.h"
 #include "llvm/ADT/Hashing.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Bitstream/BitstreamReader.h"
@@ -396,12 +397,19 @@ class ObjCMethodTableInfo
 const uint8_t *&Data) {
 ObjCMethodInfo Info;
 uint8_t Payload = *Data++;
+bool HasSelf = Payload & 0x01;
+Payload >>= 1;
 Info.RequiredInit = Payload & 0x01;
 Payload >>= 1;
 Info.DesignatedInit = Payload & 0x01;
 Payload >>= 1;
+assert(Payload == 0 && "Unable t

[clang] [llvm] [HLSL] Adding HLSL `clip` function. (PR #114588)

2024-11-07 Thread Finn Plummer via cfe-commits


@@ -812,6 +821,34 @@ def SplitDouble :  DXILOp<102, splitDouble> {
   let attributes = [Attributes];
 }
 
+def WaveIsFirstLane :  DXILOp<110, waveIsFirstLane> {

inbelic wrote:

This reordering will be addressed as part of DXIL.td clean-up in #114461.

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


[clang] [llvm] [HLSL] Adding HLSL `clip` function. (PR #114588)

2024-11-07 Thread Finn Plummer via cfe-commits


@@ -75,7 +75,9 @@ static const std::map
 {"SPV_KHR_cooperative_matrix",
  SPIRV::Extension::Extension::SPV_KHR_cooperative_matrix},
 {"SPV_KHR_non_semantic_info",
- SPIRV::Extension::Extension::SPV_KHR_non_semantic_info}};
+ SPIRV::Extension::Extension::SPV_KHR_non_semantic_info},
+{"SPV_EXT_demote_to_helper_invocation",

inbelic wrote:

We could add a description of the extension in `llvm/docs/SPIRVUsage.rst`.

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


[clang] [HLSL] Add empty struct test cases to `__builtin_hlsl_is_typed_resource_element_compatible` test file (PR #115045)

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

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/115045

>From ef4a7eea3eacce4f77b628aebe7f2838733971d0 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Tue, 5 Nov 2024 10:35:59 -0800
Subject: [PATCH 1/4] add empty struct test cases

---
 .../SemaHLSL/Types/Traits/IsTypedResourceElementCompatible.hlsl | 2 ++
 1 file changed, 2 insertions(+)

diff --git 
a/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatible.hlsl 
b/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatible.hlsl
index acc1f281daddfc..08d75a0c23b228 100644
--- a/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatible.hlsl
+++ b/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatible.hlsl
@@ -107,3 +107,5 @@ struct TypeDefTest {
 };
 
 
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(TypeDefTest),
 "");
+
+

>From 0ed4809a4bb12618e885914c09ba83e44c9c83c9 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Tue, 5 Nov 2024 10:58:58 -0800
Subject: [PATCH 2/4] remove assert, return false instead

---
 clang/lib/Sema/SemaHLSL.cpp  | 6 --
 .../Types/Traits/IsTypedResourceElementCompatible.hlsl   | 9 +
 .../Traits/IsTypedResourceElementCompatibleErrors.hlsl   | 1 -
 3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 298b7ad4f9e687..4b5b5aa96d5c20 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -2210,8 +2210,10 @@ bool 
SemaHLSL::IsTypedResourceElementCompatible(clang::QualType QT) {
   llvm::SmallVector QTTypes;
   BuildFlattenedTypeList(QT, QTTypes);
 
-  assert(QTTypes.size() > 0 &&
- "expected at least one constituent type from non-null type");
+  // empty structs are not typed resource element compatible
+  if (QTTypes.size() == 0)
+return false;
+
   QualType FirstQT = SemaRef.Context.getCanonicalType(QTTypes[0]);
 
   // element count cannot exceed 4
diff --git 
a/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatible.hlsl 
b/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatible.hlsl
index 08d75a0c23b228..0a124be3e0aa60 100644
--- a/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatible.hlsl
+++ b/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatible.hlsl
@@ -108,4 +108,13 @@ struct TypeDefTest {
 
 
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(TypeDefTest),
 "");
 
+struct EmptyStruct {};
+_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(EmptyStruct),
 "");
 
+struct EmptyDerived : EmptyStruct {};
+_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(EmptyDerived),
 "");
+
+struct EmptyBase : EmptyStruct {
+  int4 V;
+};
+_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(EmptyBase), 
""); 
diff --git 
a/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatibleErrors.hlsl 
b/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatibleErrors.hlsl
index cb3e9ae7a61509..1cc9880e5b25f1 100644
--- 
a/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatibleErrors.hlsl
+++ 
b/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatibleErrors.hlsl
@@ -7,4 +7,3 @@ 
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(__hlsl_resour
 struct notComplete;
 // expected-error@+1{{incomplete type 'notComplete' where a complete type is 
required}}
 
_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(notComplete),
 "");
- 

>From 65c6e1a384dd529a749a2cc8e20aa5a70d17c60b Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Tue, 5 Nov 2024 16:26:23 -0800
Subject: [PATCH 3/4] address chris

---
 clang/lib/Sema/SemaHLSL.cpp   |  11 +-
 .../IsTypedResourceElementCompatible.hlsl | 116 ++
 2 files changed, 19 insertions(+), 108 deletions(-)

diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 4b5b5aa96d5c20..b0dd7369749619 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -2200,17 +2200,20 @@ static void BuildFlattenedTypeList(QualType BaseTy,
 }
 
 bool SemaHLSL::IsTypedResourceElementCompatible(clang::QualType QT) {
-  if (QT.isNull())
+  // null and array types are not allowed.
+  if (QT.isNull() || QT->isArrayType())
 return false;
 
-  // check if the outer type was an array type
-  if (QT->isArrayType())
+  // UDT types are not allowed
+  clang::QualType CanonicalType = QT.getCanonicalType();
+  if (CanonicalType->getAs()) {
 return false;
+  }
 
   llvm::SmallVector QTTypes;
   BuildFlattenedTypeList(QT, QTTypes);
 
-  // empty structs are not typed resource element compatible
+  // empty element type is not typed resource element compatible
   if (QTTypes.size() == 0)
 return false;
 
diff --git 
a/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatible.hlsl 
b/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatible.hl

[clang] [llvm] [HLSL] Adding HLSL `clip` function. (PR #114588)

2024-11-07 Thread Finn Plummer via cfe-commits


@@ -2120,6 +2123,32 @@ bool 
SPIRVInstructionSelector::selectSplatVector(Register ResVReg,
   return MIB.constrainAllUses(TII, TRI, RBI);
 }
 
+bool SPIRVInstructionSelector::selectClip(Register ResVReg,
+  const SPIRVType *ResType,
+  MachineInstr &I) const {
+
+  unsigned Opcode;
+
+  if (STI.isAtLeastSPIRVVer(VersionTuple(1, 6))) {
+if (!STI.canUseExtension(
+SPIRV::Extension::SPV_EXT_demote_to_helper_invocation))
+  report_fatal_error(
+  "llvm.spv.clip intrinsic: this instruction requires the following "
+  "SPIR-V extension: SPV_EXT_demote_to_helper_invocation",
+  false);

inbelic wrote:

```suggestion
  if (STI.isAtLeastSPIRVVer(VersionTuple(1, 6)) ||
  
STI.canUseExtension(SPIRV::Extension::SPV_EXT_demote_to_helper_invocation))) {
```

My understanding is that the extension is used to specify the capability is 
available when we don't have a spirv version that enables it by default. So we 
can use it if the minimum version is allowed or the extension is enabled.

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


[clang] [llvm] [HLSL] Adding HLSL `clip` function. (PR #114588)

2024-11-07 Thread Finn Plummer via cfe-commits


@@ -89,6 +89,7 @@ let TargetPrefix = "spv" in {
   def int_spv_sign : DefaultAttrsIntrinsic<[LLVMScalarOrSameVectorWidth<0, 
llvm_i32_ty>], [llvm_any_ty], [IntrNoMem]>;
   def int_spv_radians : DefaultAttrsIntrinsic<[LLVMMatchType<0>], 
[llvm_anyfloat_ty], [IntrNoMem]>;
   def int_spv_group_memory_barrier_with_group_sync : DefaultAttrsIntrinsic<[], 
[], []>;
+  def int_spv_clip : Intrinsic<[], [], []>;

inbelic wrote:

The attributes here don't match with the dx version.

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


[clang] [llvm] [HLSL] Adding HLSL `clip` function. (PR #114588)

2024-11-07 Thread Finn Plummer via cfe-commits


@@ -456,6 +456,7 @@ defm VulkanMemoryModelDeviceScopeKHR : 
CapabilityOperand<5346, 0, 0, [], []>;
 defm ImageFootprintNV : CapabilityOperand<5282, 0, 0, [], []>;
 defm FragmentBarycentricNV : CapabilityOperand<5284, 0, 0, [], []>;
 defm ComputeDerivativeGroupQuadsNV : CapabilityOperand<5288, 0, 0, [], []>;
+defm DemoteToHelperInvocation : CapabilityOperand<5379, 0, 0, 
[SPV_EXT_demote_to_helper_invocation], []>;

inbelic wrote:

```suggestion
defm DemoteToHelperInvocation : CapabilityOperand<5379, 0x00010600, 0, 
[SPV_EXT_demote_to_helper_invocation], []>;
```
We could specify the minimum version. Following format from here but I think 
you can remove some leading zeros: 
https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#_physical_layout_of_a_spir_v_module_and_instruction

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


  1   2   3   4   5   >