[clang] [flang] [mlir] [flang] Add support for -mprefer-vector-width= (PR #141380)

2025-05-26 Thread via cfe-commits


@@ -2636,6 +2636,10 @@ void 
ModuleImport::processFunctionAttributes(llvm::Function *func,
 funcOp.setTargetFeaturesAttr(
 LLVM::TargetFeaturesAttr::get(context, attr.getValueAsString()));
 
+  if (llvm::Attribute attr = func->getFnAttribute("prefer-vector-width");
+  attr.isStringAttribute())
+funcOp.setPreferVectorWidth(attr.getValueAsString());

jeanPerier wrote:

Can you add an import test in mlir/test/Target/LLVMIR/Import and an export one 
in ‎mlir/test/Target/LLVMIR (just like the ones for tune-cpu)?

Even though the export is tested indirectly in flang, it is best to add an 
explicit test here.

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


[clang] [flang] [mlir] [flang] Add support for -mprefer-vector-width= (PR #141380)

2025-05-26 Thread via cfe-commits

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


[clang-tools-extra] [NFC][clangd][test] add clang-tidy config to ensure test cases sandbox (PR #141410)

2025-05-26 Thread kadir çetinkaya via cfe-commits


@@ -0,0 +1 @@
+InheritParentConfig: false

kadircet wrote:

are we running any tests in this directory? these inputs are usually copied to 
temp test directories, since you're not copying this over in any of the tests, 
is this really needed? (or do we have some tests that recursively copy 
everything?)

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


[clang-tools-extra] [NFC][clangd][test] add clang-tidy config to ensure test cases sandbox (PR #141410)

2025-05-26 Thread kadir çetinkaya via cfe-commits


@@ -32,6 +32,9 @@
 # RUN: echo 'printf "End of search list.\r\n" >&2' >> %t.dir/bin/my_driver.sh
 # RUN: chmod +x %t.dir/bin/my_driver.sh
 
+# Create fake clang-tidy config to ensure sandbox
+# RUN: echo 'InheritParentConfig: false' >> %t.dir/.clang-tidy

kadircet wrote:

instead of this can you just pass `-clang-tidy=0` to `clangd` invocations in 
this file? we shouldn't be testing/relying on any clang-tidy behavior in this 
test file.

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


[clang] [Analysis] Use llvm::erase_if (NFC) (PR #141446)

2025-05-26 Thread Matt Arsenault via cfe-commits

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


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


[clang] [Driver] Remove unused includes (NFC) (PR #141448)

2025-05-26 Thread Matt Arsenault via cfe-commits

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


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


[clang-tools-extra] [NFC][clangd][test] add clang-tidy config to ensure test cases sandbox (PR #141410)

2025-05-26 Thread kadir çetinkaya via cfe-commits

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


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


[clang] [AST] Use llvm::none_of (NFC) (PR #141447)

2025-05-26 Thread Matt Arsenault via cfe-commits

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


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


[clang] [Clang] Reapply CWG2369 "Ordering between constraints and substitution" (PR #122423)

2025-05-26 Thread Younan Zhang via cfe-commits

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

>From 56bacf47c53aca276ae4fa6aa2972b7eda152ddd Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Fri, 10 Jan 2025 09:46:24 +0800
Subject: [PATCH 01/15] Reapply "[Clang] Implement CWG2369 "Ordering between
 constraints and substitution"" (#122130)

This reverts commit 3972ed57088f6515b787d7d38dec03dc74e51827.
---
 clang/include/clang/Sema/Sema.h   |  22 +++-
 clang/include/clang/Sema/Template.h   |   6 +
 clang/lib/Sema/SemaConcept.cpp|  47 ++-
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  49 +---
 clang/lib/Sema/SemaTemplateDeductionGuide.cpp |   8 +-
 clang/lib/Sema/SemaTemplateInstantiate.cpp| 115 --
 clang/lib/Sema/TreeTransform.h|   2 +-
 clang/test/CXX/drs/cwg23xx.cpp|  29 +
 clang/test/CXX/drs/cwg26xx.cpp|   2 +-
 clang/test/CXX/drs/cwg27xx.cpp|  20 +++
 .../expr.prim.req/nested-requirement.cpp  |   2 +-
 .../constrant-satisfaction-conversions.cpp|   6 +-
 .../SemaCXX/concept-crash-on-diagnostic.cpp   |   2 +-
 clang/test/SemaCXX/cxx20-ctad-type-alias.cpp  |   2 +-
 clang/test/SemaCXX/cxx23-assume.cpp   |   6 +-
 clang/test/SemaCXX/cxx2c-fold-exprs.cpp   |   2 +-
 clang/test/SemaCXX/lambda-unevaluated.cpp |   4 +-
 .../SemaTemplate/concepts-recursive-inst.cpp  |   4 +-
 .../SemaTemplate/cxx2a-constraint-exprs.cpp   |   2 +-
 .../nested-implicit-deduction-guides.cpp  |   8 +-
 clang/www/cxx_dr_status.html  |   8 +-
 21 files changed, 289 insertions(+), 57 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 96d81e618494a..3b1f4d3234ea9 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -13303,6 +13303,7 @@ class Sema final : public SemaBase {
   ///
   /// \param SkipForSpecialization when specified, any template specializations
   /// in a traversal would be ignored.
+  ///
   /// \param ForDefaultArgumentSubstitution indicates we should continue 
looking
   /// when encountering a specialized member function template, rather than
   /// returning immediately.
@@ -13314,6 +13315,17 @@ class Sema final : public SemaBase {
   bool SkipForSpecialization = false,
   bool ForDefaultArgumentSubstitution = false);
 
+  /// Apart from storing the result to \p Result, this behaves the same as
+  /// another overload.
+  void getTemplateInstantiationArgs(
+  MultiLevelTemplateArgumentList &Result, const NamedDecl *D,
+  const DeclContext *DC = nullptr, bool Final = false,
+  std::optional> Innermost = std::nullopt,
+  bool RelativeToPrimary = false, const FunctionDecl *Pattern = nullptr,
+  bool ForConstraintInstantiation = false,
+  bool SkipForSpecialization = false,
+  bool ForDefaultArgumentSubstitution = false);
+
   /// RAII object to handle the state changes required to synthesize
   /// a function body.
   class SynthesizedFunctionScope {
@@ -13590,7 +13602,7 @@ class Sema final : public SemaBase {
   ExprResult
   SubstConstraintExpr(Expr *E,
   const MultiLevelTemplateArgumentList &TemplateArgs);
-  // Unlike the above, this does not evaluates constraints.
+  // Unlike the above, this does not evaluate constraints.
   ExprResult SubstConstraintExprWithoutSatisfaction(
   Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs);
 
@@ -14732,10 +14744,10 @@ class Sema final : public SemaBase {
   const MultiLevelTemplateArgumentList &TemplateArgs,
   SourceRange TemplateIDRange);
 
-  bool CheckInstantiatedFunctionTemplateConstraints(
-  SourceLocation PointOfInstantiation, FunctionDecl *Decl,
-  ArrayRef TemplateArgs,
-  ConstraintSatisfaction &Satisfaction);
+  bool CheckFunctionTemplateConstraints(SourceLocation PointOfInstantiation,
+FunctionDecl *Decl,
+ArrayRef 
TemplateArgs,
+ConstraintSatisfaction &Satisfaction);
 
   /// \brief Emit diagnostics explaining why a constraint expression was deemed
   /// unsatisfied.
diff --git a/clang/include/clang/Sema/Template.h 
b/clang/include/clang/Sema/Template.h
index f9a10cfafb1f7..39f0cf225e673 100644
--- a/clang/include/clang/Sema/Template.h
+++ b/clang/include/clang/Sema/Template.h
@@ -522,6 +522,12 @@ enum class TemplateSubstitutionKind : char {
 llvm::PointerUnion *
 findInstantiationOf(const Decl *D);
 
+/// Similar to \p findInstantiationOf(), but it wouldn't assert if the
+/// instantiation was not found within the current instantiation scope. 
This
+/// is helpful for on-demand declaration instantiation.
+llvm::PointerUnion *
+findInstantiationUnsafe(const Decl *D);
+
 void InstantiatedLocal(const Decl *D, Decl *Inst);
 void InstantiatedLocalPackArg(const Decl *D, VarD

[clang] Allow changes to language options across modules (PR #141459)

2025-05-26 Thread via cfe-commits

https://github.com/matts1 created 
https://github.com/llvm/llvm-project/pull/141459

See #141165 for details on why to do this

>From d410b2f6e804697b0903936afb0681889bcb95ef Mon Sep 17 00:00:00 2001
From: Matt Stark 
Date: Mon, 26 May 2025 14:06:00 +1000
Subject: [PATCH] Allow a user to decide whether changes in various language
 options are allowed across modules.

---
 .../Basic/DiagnosticSerializationKinds.td |  4 +-
 .../include/clang/Basic/LangOptionsOptions.h  | 38 +++
 clang/include/clang/Driver/Options.td |  4 ++
 .../include/clang/Frontend/CompilerInstance.h |  1 +
 .../include/clang/Frontend/FrontendOptions.h  |  7 
 clang/include/clang/Serialization/ASTReader.h | 10 -
 clang/lib/Frontend/ASTUnit.cpp|  5 ++-
 clang/lib/Frontend/ChainedIncludesSource.cpp  |  1 +
 clang/lib/Frontend/CompilerInstance.cpp   | 11 --
 clang/lib/Frontend/CompilerInvocation.cpp |  9 +
 clang/lib/Frontend/FrontendAction.cpp |  1 +
 clang/lib/Frontend/FrontendActions.cpp|  1 +
 clang/lib/Serialization/ASTReader.cpp | 32 ++--
 13 files changed, 107 insertions(+), 17 deletions(-)
 create mode 100644 clang/include/clang/Basic/LangOptionsOptions.h

diff --git a/clang/include/clang/Basic/DiagnosticSerializationKinds.td 
b/clang/include/clang/Basic/DiagnosticSerializationKinds.td
index 7965da593f218..b66338955d3e3 100644
--- a/clang/include/clang/Basic/DiagnosticSerializationKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSerializationKinds.td
@@ -37,8 +37,10 @@ def err_ast_file_targetopt_feature_mismatch : Error<
 "feature '%2' but the %select{current translation unit is|AST file '%1' 
was}0 "
 "not">;
 def err_ast_file_langopt_mismatch : Error<"%0 was %select{disabled|enabled}1 
in "
-"AST file '%3' but is currently %select{disabled|enabled}2">;
+"AST file '%3' but is currently %select{disabled|enabled}2. To ignore 
this, add -fmodule-config-mismatch-ignore=%4">;
 def err_ast_file_langopt_value_mismatch : Error<
+  "%0 differs in AST file '%1' vs. current file. To ignore this, add 
-fmodule-config-mismatch-ignore=%4">;
+def err_ast_file_langopt_value_nameless_mismatch : Error<
   "%0 differs in AST file '%1' vs. current file">;
 def err_ast_file_diagopt_mismatch : Error<"%0 is currently enabled, but was 
not in "
   "the AST file '%1'">;
diff --git a/clang/include/clang/Basic/LangOptionsOptions.h 
b/clang/include/clang/Basic/LangOptionsOptions.h
new file mode 100644
index 0..861af1df0b04e
--- /dev/null
+++ b/clang/include/clang/Basic/LangOptionsOptions.h
@@ -0,0 +1,38 @@
+#ifndef LLVM_CLANG_INCLUDE_BASIC_LANGOPTIONSOPTIONS_H
+#define LLVM_CLANG_INCLUDE_BASIC_LANGOPTIONSOPTIONS_H
+
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/DiagnosticDriver.h"
+#include 
+#include 
+#include 
+
+using namespace clang;
+
+struct LangOptionsOption {
+// Completely ignores this option when it comes to 
+bool ignore_mismatch;
+};
+
+// Options that can be applied arbitrarily to any langopt
+struct LangOptionsOptions {
+
+#define LANGOPT(Name, Bits, Default, Description) LangOptionsOption Name;
+#include "clang/Basic/LangOptions.def"
+
+LangOptionsOption* get(const std::string& OptName) {
+#define LANGOPT(Name, Bits, Default, Description) \
+  {std::string(#Name), offsetof(LangOptionsOptions, Name)},
+static const std::unordered_map Offsets = {
+#include "clang/Basic/LangOptions.def"
+};
+if (auto it = Offsets.find(OptName); it != Offsets.end()) {
+auto Offset = it->second;
+return 
reinterpret_cast(reinterpret_cast(this) + 
Offset);
+} else {
+return nullptr;
+}
+}
+};
+
+#endif // LLVM_CLANG_INCLUDE_BASIC_LANGOPTIONSOPTIONS_H
\ No newline at end of file
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 22261621df092..fea227360078d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8026,6 +8026,10 @@ def fmodules_embed_file_EQ : Joined<["-"], 
"fmodules-embed-file=">,
   HelpText<"Embed the contents of the specified file into the module file "
"being compiled.">,
   MarshallingInfoStringVector>;
+def fmodule_config_mismatch_ignores: CommaJoined<["-"], 
"fmodule-config-mismatch-ignores=">,
+  Visibility<[ClangOption, CC1Option]>,
+HelpText<"Comma separated list of options to ignore for the purposes of a 
config mismatch">,
+
MarshallingInfoStringVector>;
 defm fimplicit_modules_use_lock : BoolOption<"f", "implicit-modules-use-lock",
   FrontendOpts<"BuildingImplicitModuleUsesLock">, DefaultTrue,
   NegFlag,
diff --git a/clang/include/clang/Frontend/CompilerInstance.h 
b/clang/include/clang/Frontend/CompilerInstance.h
index 5f25a932c5052..c60720a21ad21 100644
--- a/clang/include/clang/Frontend/CompilerInstance.h
+++ b/clang/include/clang/Frontend/CompilerInstance.h
@@

[clang] [Driver][X86] Add -m[no-]apxf to m_x86_Features_Group (PR #140874)

2025-05-26 Thread Rainer Orth via cfe-commits

rorth wrote:

This patch broke the [Solaris/amd64 
buildbot](https://lab.llvm.org/staging/#/builders/120/builds/8977).  I suspect 
the test should use `--target=i386-pc-windows` instead of just `i386`?

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


[clang] [Clang] Clean up the fix for deferred access checking (PR #141340)

2025-05-26 Thread via cfe-commits

cor3ntin wrote:

Thanks for this PR.
I'd like CWG to weigh in on the core issue I submitted here  
https://github.com/cplusplus/CWG/issues/709
Several people have expressed that they expect Clang's (non-conforming) 
behavior. WDYT?

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


[clang-tools-extra] 926c201 - [clangd] Add support for textDocument/rangesFormatting (#141208)

2025-05-26 Thread via cfe-commits

Author: Tom Praschan
Date: 2025-05-26T10:08:18+02:00
New Revision: 926c2013231a030a52037528bac0ba124c35ac32

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

LOG: [clangd] Add support for textDocument/rangesFormatting (#141208)



Uses the protocol changes proposed in
https://github.com/microsoft/language-server-protocol/pull/1556 and
https://github.com/microsoft/vscode/pull/163190

Related issue: https://github.com/clangd/clangd/issues/1635

Old Phabricator review: https://reviews.llvm.org/D150852

Relevant LSP 3.18 spec:
https://microsoft.github.io/language-server-protocol/specifications/lsp/3.18/specification/#documentRangesFormattingParams

Old PR: https://github.com/llvm/llvm-project/pull/80180,
https://github.com/llvm/llvm-project/pull/141052

Added: 


Modified: 
clang-tools-extra/clangd/ClangdLSPServer.cpp
clang-tools-extra/clangd/ClangdLSPServer.h
clang-tools-extra/clangd/ClangdServer.cpp
clang-tools-extra/clangd/ClangdServer.h
clang-tools-extra/clangd/Protocol.cpp
clang-tools-extra/clangd/Protocol.h
clang-tools-extra/clangd/test/formatting.test
clang-tools-extra/clangd/test/initialize-params.test
clang-tools-extra/clangd/unittests/ClangdTests.cpp
clang-tools-extra/clangd/unittests/SyncAPI.cpp
clang-tools-extra/clangd/unittests/SyncAPI.h

Removed: 




diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index 1e981825c7c15..29321f7cd3fa2 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -591,7 +591,10 @@ void ClangdLSPServer::onInitialize(const InitializeParams 
&Params,
{"save", true},
}},
   {"documentFormattingProvider", true},
-  {"documentRangeFormattingProvider", true},
+  {"documentRangeFormattingProvider",
+   llvm::json::Object{
+   {"rangesSupport", true},
+   }},
   {"documentOnTypeFormattingProvider",
llvm::json::Object{
{"firstTriggerCharacter", "\n"},
@@ -952,9 +955,17 @@ void ClangdLSPServer::onDocumentOnTypeFormatting(
 void ClangdLSPServer::onDocumentRangeFormatting(
 const DocumentRangeFormattingParams &Params,
 Callback> Reply) {
+  onDocumentRangesFormatting(
+  DocumentRangesFormattingParams{Params.textDocument, {Params.range}},
+  std::move(Reply));
+}
+
+void ClangdLSPServer::onDocumentRangesFormatting(
+const DocumentRangesFormattingParams &Params,
+Callback> Reply) {
   auto File = Params.textDocument.uri.file();
   auto Code = Server->getDraft(File);
-  Server->formatFile(File, Params.range,
+  Server->formatFile(File, Params.ranges,
  [Code = std::move(Code), Reply = std::move(Reply)](
  llvm::Expected Result) mutable 
{
if (Result)
@@ -970,7 +981,7 @@ void ClangdLSPServer::onDocumentFormatting(
   auto File = Params.textDocument.uri.file();
   auto Code = Server->getDraft(File);
   Server->formatFile(File,
- /*Rng=*/std::nullopt,
+ /*Rngs=*/{},
  [Code = std::move(Code), Reply = std::move(Reply)](
  llvm::Expected Result) mutable 
{
if (Result)
@@ -1666,6 +1677,7 @@ void ClangdLSPServer::bindMethods(LSPBinder &Bind,
   Bind.method("shutdown", this, &ClangdLSPServer::onShutdown);
   Bind.method("sync", this, &ClangdLSPServer::onSync);
   Bind.method("textDocument/rangeFormatting", this, 
&ClangdLSPServer::onDocumentRangeFormatting);
+  Bind.method("textDocument/rangesFormatting", this, 
&ClangdLSPServer::onDocumentRangesFormatting);
   Bind.method("textDocument/onTypeFormatting", this, 
&ClangdLSPServer::onDocumentOnTypeFormatting);
   Bind.method("textDocument/formatting", this, 
&ClangdLSPServer::onDocumentFormatting);
   Bind.method("textDocument/codeAction", this, &ClangdLSPServer::onCodeAction);

diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.h 
b/clang-tools-extra/clangd/ClangdLSPServer.h
index f43734ec1ede3..6ada3fd9e6e47 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.h
+++ b/clang-tools-extra/clangd/ClangdLSPServer.h
@@ -110,6 +110,8 @@ class ClangdLSPServer : private ClangdServer::Callbacks,
   Callback>);
   void onDocumentRangeFormatting(const DocumentRangeFormattingParams &,
  Callback>);
+  void onDocumentRangesFormatting(const DocumentRangesFormattingParams &,
+  Callback>);
   void onDocumentFormatting(const DocumentFormattingParams &,
 Callback>);
   // The results are serialized 'vector' if

diff  --git a/clang-tools-extra/clangd/ClangdServer.cpp 
b/clang-tools-extra/c

[clang] [flang] [mlir] [flang] Add support for -mprefer-vector-width= (PR #141380)

2025-05-26 Thread via cfe-commits

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

Nit about the need for MLIR tests, LGTM otherwise!

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


[clang] [Clang] Reapply CWG2369 "Ordering between constraints and substitution" (PR #122423)

2025-05-26 Thread Younan Zhang via cfe-commits

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

>From 56bacf47c53aca276ae4fa6aa2972b7eda152ddd Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Fri, 10 Jan 2025 09:46:24 +0800
Subject: [PATCH 01/18] Reapply "[Clang] Implement CWG2369 "Ordering between
 constraints and substitution"" (#122130)

This reverts commit 3972ed57088f6515b787d7d38dec03dc74e51827.
---
 clang/include/clang/Sema/Sema.h   |  22 +++-
 clang/include/clang/Sema/Template.h   |   6 +
 clang/lib/Sema/SemaConcept.cpp|  47 ++-
 clang/lib/Sema/SemaTemplateDeduction.cpp  |  49 +---
 clang/lib/Sema/SemaTemplateDeductionGuide.cpp |   8 +-
 clang/lib/Sema/SemaTemplateInstantiate.cpp| 115 --
 clang/lib/Sema/TreeTransform.h|   2 +-
 clang/test/CXX/drs/cwg23xx.cpp|  29 +
 clang/test/CXX/drs/cwg26xx.cpp|   2 +-
 clang/test/CXX/drs/cwg27xx.cpp|  20 +++
 .../expr.prim.req/nested-requirement.cpp  |   2 +-
 .../constrant-satisfaction-conversions.cpp|   6 +-
 .../SemaCXX/concept-crash-on-diagnostic.cpp   |   2 +-
 clang/test/SemaCXX/cxx20-ctad-type-alias.cpp  |   2 +-
 clang/test/SemaCXX/cxx23-assume.cpp   |   6 +-
 clang/test/SemaCXX/cxx2c-fold-exprs.cpp   |   2 +-
 clang/test/SemaCXX/lambda-unevaluated.cpp |   4 +-
 .../SemaTemplate/concepts-recursive-inst.cpp  |   4 +-
 .../SemaTemplate/cxx2a-constraint-exprs.cpp   |   2 +-
 .../nested-implicit-deduction-guides.cpp  |   8 +-
 clang/www/cxx_dr_status.html  |   8 +-
 21 files changed, 289 insertions(+), 57 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 96d81e618494a..3b1f4d3234ea9 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -13303,6 +13303,7 @@ class Sema final : public SemaBase {
   ///
   /// \param SkipForSpecialization when specified, any template specializations
   /// in a traversal would be ignored.
+  ///
   /// \param ForDefaultArgumentSubstitution indicates we should continue 
looking
   /// when encountering a specialized member function template, rather than
   /// returning immediately.
@@ -13314,6 +13315,17 @@ class Sema final : public SemaBase {
   bool SkipForSpecialization = false,
   bool ForDefaultArgumentSubstitution = false);
 
+  /// Apart from storing the result to \p Result, this behaves the same as
+  /// another overload.
+  void getTemplateInstantiationArgs(
+  MultiLevelTemplateArgumentList &Result, const NamedDecl *D,
+  const DeclContext *DC = nullptr, bool Final = false,
+  std::optional> Innermost = std::nullopt,
+  bool RelativeToPrimary = false, const FunctionDecl *Pattern = nullptr,
+  bool ForConstraintInstantiation = false,
+  bool SkipForSpecialization = false,
+  bool ForDefaultArgumentSubstitution = false);
+
   /// RAII object to handle the state changes required to synthesize
   /// a function body.
   class SynthesizedFunctionScope {
@@ -13590,7 +13602,7 @@ class Sema final : public SemaBase {
   ExprResult
   SubstConstraintExpr(Expr *E,
   const MultiLevelTemplateArgumentList &TemplateArgs);
-  // Unlike the above, this does not evaluates constraints.
+  // Unlike the above, this does not evaluate constraints.
   ExprResult SubstConstraintExprWithoutSatisfaction(
   Expr *E, const MultiLevelTemplateArgumentList &TemplateArgs);
 
@@ -14732,10 +14744,10 @@ class Sema final : public SemaBase {
   const MultiLevelTemplateArgumentList &TemplateArgs,
   SourceRange TemplateIDRange);
 
-  bool CheckInstantiatedFunctionTemplateConstraints(
-  SourceLocation PointOfInstantiation, FunctionDecl *Decl,
-  ArrayRef TemplateArgs,
-  ConstraintSatisfaction &Satisfaction);
+  bool CheckFunctionTemplateConstraints(SourceLocation PointOfInstantiation,
+FunctionDecl *Decl,
+ArrayRef 
TemplateArgs,
+ConstraintSatisfaction &Satisfaction);
 
   /// \brief Emit diagnostics explaining why a constraint expression was deemed
   /// unsatisfied.
diff --git a/clang/include/clang/Sema/Template.h 
b/clang/include/clang/Sema/Template.h
index f9a10cfafb1f7..39f0cf225e673 100644
--- a/clang/include/clang/Sema/Template.h
+++ b/clang/include/clang/Sema/Template.h
@@ -522,6 +522,12 @@ enum class TemplateSubstitutionKind : char {
 llvm::PointerUnion *
 findInstantiationOf(const Decl *D);
 
+/// Similar to \p findInstantiationOf(), but it wouldn't assert if the
+/// instantiation was not found within the current instantiation scope. 
This
+/// is helpful for on-demand declaration instantiation.
+llvm::PointerUnion *
+findInstantiationUnsafe(const Decl *D);
+
 void InstantiatedLocal(const Decl *D, Decl *Inst);
 void InstantiatedLocalPackArg(const Decl *D, VarD

[clang] [Clang] Remap paths in OpenMP runtime calls (#82541) (PR #141250)

2025-05-26 Thread Dan McGregor via cfe-commits

dankm wrote:

Neat, the original was good, and apparently some tests don't run on my system. 
Going back to to that version :/

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


[clang] [Clang] Remap paths in OpenMP runtime calls (#82541) (PR #141250)

2025-05-26 Thread Dan McGregor via cfe-commits

https://github.com/dankm updated 
https://github.com/llvm/llvm-project/pull/141250

>From e4fc23b1486180ec01a68f0d2c367d8d15aa8203 Mon Sep 17 00:00:00 2001
From: Dan McGregor 
Date: Fri, 23 May 2025 10:19:22 -0600
Subject: [PATCH] [Clang] Remap paths in OpenMP runtime calls

Apply the debug prefix mapping to the OpenMP location strings.

Fixes https://github.com/llvm/llvm-project/issues/82541
---
 clang/lib/CodeGen/CGOpenMPRuntime.cpp  | 23 ++-
 clang/test/CodeGen/openmp-prefix-map.c | 21 +
 2 files changed, 39 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/CodeGen/openmp-prefix-map.c

diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index e458d437d085a..d77e624c5edbe 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -1352,7 +1352,12 @@ static StringRef 
getIdentStringFromSourceLocation(CodeGenFunction &CGF,
   llvm::raw_svector_ostream OS(Buffer);
   // Build debug location
   PresumedLoc PLoc = CGF.getContext().getSourceManager().getPresumedLoc(Loc);
-  OS << ";" << PLoc.getFilename() << ";";
+  OS << ";";
+  if (CGF.getDebugInfo())
+OS << CGF.getDebugInfo()->remapDIPath(PLoc.getFilename());
+  else
+OS << PLoc.getFilename();
+  OS << ";";
   if (const auto *FD = dyn_cast_or_null(CGF.CurFuncDecl))
 OS << FD->getQualifiedNameAsString();
   OS << ";" << PLoc.getLine() << ";" << PLoc.getColumn() << ";;";
@@ -1370,10 +1375,14 @@ llvm::Value 
*CGOpenMPRuntime::emitUpdateLocation(CodeGenFunction &CGF,
 SrcLocStr = OMPBuilder.getOrCreateDefaultSrcLocStr(SrcLocStrSize);
   } else {
 std::string FunctionName;
+std::string FileName;
 if (const auto *FD = dyn_cast_or_null(CGF.CurFuncDecl))
   FunctionName = FD->getQualifiedNameAsString();
 PresumedLoc PLoc = CGF.getContext().getSourceManager().getPresumedLoc(Loc);
-const char *FileName = PLoc.getFilename();
+if (CGF.getDebugInfo())
+  FileName = CGF.getDebugInfo()->remapDIPath(PLoc.getFilename());
+else
+  FileName = PLoc.getFilename();
 unsigned Line = PLoc.getLine();
 unsigned Column = PLoc.getColumn();
 SrcLocStr = OMPBuilder.getOrCreateSrcLocStr(FunctionName, FileName, Line,
@@ -8840,10 +8849,14 @@ emitMappingInformation(CodeGenFunction &CGF, 
llvm::OpenMPIRBuilder &OMPBuilder,
 ExprName = MapExprs.getMapDecl()->getNameAsString();
   }
 
+  std::string FileName;
   PresumedLoc PLoc = CGF.getContext().getSourceManager().getPresumedLoc(Loc);
-  return OMPBuilder.getOrCreateSrcLocStr(PLoc.getFilename(), ExprName,
- PLoc.getLine(), PLoc.getColumn(),
- SrcLocStrSize);
+  if (CGF.getDebugInfo())
+FileName = CGF.getDebugInfo()->remapDIPath(PLoc.getFilename());
+  else
+FileName = PLoc.getFilename();
+  return OMPBuilder.getOrCreateSrcLocStr(FileName, ExprName, PLoc.getLine(),
+ PLoc.getColumn(), SrcLocStrSize);
 }
 /// Emit the arrays used to pass the captures and map information to the
 /// offloading runtime library. If there is no map or capture information,
diff --git a/clang/test/CodeGen/openmp-prefix-map.c 
b/clang/test/CodeGen/openmp-prefix-map.c
new file mode 100644
index 0..be3429c267215
--- /dev/null
+++ b/clang/test/CodeGen/openmp-prefix-map.c
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -triple i386-unknown-unknown -debug-info-kind=standalone 
-fopenmp %s -emit-llvm -o - -disable-llvm-optzns -fdebug-prefix-map=%S=.| 
FileCheck -DPREFIX=%S %s
+
+// CHECK-NOT: @{{[0-9]+}} = private unnamed_addr constant [{{[0-9]+}} x i8] 
c";[[PREFIX]]{{.*}}.c;foo;{{[0-9]+}};{{[0-9]+}};;\00"
+
+void work1(int, int);
+void work2(int, int);
+void work12(int, int);
+
+void foo(int q) {
+  int p = 2;
+
+  #pragma omp parallel firstprivate(q, p)
+  work1(p, q);
+
+  #pragma omp parallel for firstprivate(p, q)
+  for (int i = 0; i < q; i++)
+work2(i, p);
+
+  #pragma omp target teams firstprivate(p)
+  work12(p, p);
+}

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


[clang] [llvm] [HLSL][RootSignature] Add parsing infastructure for StaticSampler (PR #140180)

2025-05-26 Thread Finn Plummer via cfe-commits

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


[clang] [Format] Use llvm::count_if (NFC) (PR #141518)

2025-05-26 Thread Owen Pan via cfe-commits

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


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


[clang] 23c2f88 - [Format] Use llvm::count_if (NFC) (#141518)

2025-05-26 Thread via cfe-commits

Author: Kazu Hirata
Date: 2025-05-26T19:43:28-07:00
New Revision: 23c2f8827b13ef8c72f09f931a70e088c35ccc77

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

LOG: [Format] Use llvm::count_if (NFC) (#141518)

Added: 


Modified: 
clang/lib/Format/MacroCallReconstructor.cpp

Removed: 




diff  --git a/clang/lib/Format/MacroCallReconstructor.cpp 
b/clang/lib/Format/MacroCallReconstructor.cpp
index c9b618c6cb5b0..116bbad320e1f 100644
--- a/clang/lib/Format/MacroCallReconstructor.cpp
+++ b/clang/lib/Format/MacroCallReconstructor.cpp
@@ -511,9 +511,8 @@ MacroCallReconstructor::createUnwrappedLine(const 
ReconstructedLine &Line,
   for (const auto &N : Line.Tokens) {
 Result.Tokens.push_back(N->Tok);
 UnwrappedLineNode &Current = Result.Tokens.back();
-auto NumChildren =
-std::count_if(N->Children.begin(), N->Children.end(),
-  [](const auto &Child) { return !Child->Tokens.empty(); 
});
+auto NumChildren = llvm::count_if(
+N->Children, [](const auto &Child) { return !Child->Tokens.empty(); });
 if (NumChildren == 1 && Current.Tok->isOneOf(tok::l_paren, tok::comma)) {
   // If we only have one child, and the child is due to a macro expansion
   // (either attached to a left parenthesis or comma), merge the child into



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


[clang] [Format] Use llvm::count_if (NFC) (PR #141518)

2025-05-26 Thread Kazu Hirata via cfe-commits

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


[clang] [Driver][X86] Fix LIT test failure on Solaris OS + AMD64 CPU. (PR #141486)

2025-05-26 Thread Feng Zou via cfe-commits

https://github.com/fzou1 updated 
https://github.com/llvm/llvm-project/pull/141486

>From 5f839ebc0d21f393b30821b1df44d066e4b11d2b Mon Sep 17 00:00:00 2001
From: Feng Zou 
Date: Mon, 26 May 2025 20:16:34 +0800
Subject: [PATCH 1/2] [Driver][X86] Fix LIT test failure on Solaris OS + AMD64
 CPU.

The LIT test is introduced by https://github.com/llvm/llvm-project/pull/140874.
---
 clang/test/Driver/cl-x86-flags.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/test/Driver/cl-x86-flags.c b/clang/test/Driver/cl-x86-flags.c
index 0210b5f3cd3f1..fc9a3befe7164 100644
--- a/clang/test/Driver/cl-x86-flags.c
+++ b/clang/test/Driver/cl-x86-flags.c
@@ -137,10 +137,10 @@ void f(void) {
 }
 
 
-// RUN: not %clang_cl -### --target=i386 -mapx-features=ndd %s 2>&1 | 
FileCheck --check-prefix=NON-APX %s
-// RUN: not %clang_cl -### --target=i386 -mapxf %s 2>&1 | FileCheck 
--check-prefix=NON-APX %s
-// RUN: %clang_cl -### --target=i386 -mno-apxf %s 2>&1 > /dev/null
-// NON-APX:  error: unsupported option '-mapx-features=|-mapxf' for target 
'i386'
+// RUN: not %clang_cl -### --target=i386-pc-windows -mapx-features=ndd %s 2>&1 
| FileCheck --check-prefix=NON-APX %s
+// RUN: not %clang_cl -### --target=i386-pc-windows -mapxf %s 2>&1 | FileCheck 
--check-prefix=NON-APX %s
+// RUN: %clang_cl -### --target=i386-pc-windows -mno-apxf %s 2>&1 > /dev/null
+// NON-APX:  error: unsupported option '-mapx-features=|-mapxf' for target 
'i386-pc-windows{{.*}}'
 // NON-APX-NOT:  error: {{.*}} -mapx-features=
 
 // RUN: %clang_cl --target=x86_64-pc-windows -mapxf %s -### 2>&1 | FileCheck 
-check-prefix=APXF %s

>From 9b16c4cc21fc0f593248a47d7625f3d1640571c7 Mon Sep 17 00:00:00 2001
From: Feng Zou 
Date: Tue, 27 May 2025 10:42:56 +0800
Subject: [PATCH 2/2] Fix the issue by using "--" to separate options from
 input file names.

---
 clang/test/Driver/cl-x86-flags.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/clang/test/Driver/cl-x86-flags.c b/clang/test/Driver/cl-x86-flags.c
index fc9a3befe7164..1e6418207e642 100644
--- a/clang/test/Driver/cl-x86-flags.c
+++ b/clang/test/Driver/cl-x86-flags.c
@@ -137,14 +137,14 @@ void f(void) {
 }
 
 
-// RUN: not %clang_cl -### --target=i386-pc-windows -mapx-features=ndd %s 2>&1 
| FileCheck --check-prefix=NON-APX %s
-// RUN: not %clang_cl -### --target=i386-pc-windows -mapxf %s 2>&1 | FileCheck 
--check-prefix=NON-APX %s
-// RUN: %clang_cl -### --target=i386-pc-windows -mno-apxf %s 2>&1 > /dev/null
+// RUN: not %clang_cl -### --target=i386-pc-windows -mapx-features=ndd -- 2>&1 
%s | FileCheck --check-prefix=NON-APX %s
+// RUN: not %clang_cl -### --target=i386-pc-windows -mapxf -- 2>&1 %s | 
FileCheck --check-prefix=NON-APX %s
+// RUN: %clang_cl -### --target=i386-pc-windows -mno-apxf -- 2>&1 %s > 
/dev/null
 // NON-APX:  error: unsupported option '-mapx-features=|-mapxf' for target 
'i386-pc-windows{{.*}}'
 // NON-APX-NOT:  error: {{.*}} -mapx-features=
 
-// RUN: %clang_cl --target=x86_64-pc-windows -mapxf %s -### 2>&1 | FileCheck 
-check-prefix=APXF %s
-// RUN: %clang_cl --target=x86_64-pc-windows -mapxf -mno-apxf %s -### 2>&1 | 
FileCheck -check-prefix=NO-APXF %s
-// RUN: %clang_cl --target=x86_64-pc-windows 
-mapx-features=egpr,push2pop2,ppx,ndd,ccmp,nf,cf,zu %s -### 2>&1 | FileCheck 
-check-prefix=APXF %s
+// RUN: %clang_cl --target=x86_64-pc-windows -mapxf -### -- 2>&1 %s | 
FileCheck -check-prefix=APXF %s
+// RUN: %clang_cl --target=x86_64-pc-windows -mapxf -mno-apxf -### -- 2>&1 %s 
| FileCheck -check-prefix=NO-APXF %s
+// RUN: %clang_cl --target=x86_64-pc-windows 
-mapx-features=egpr,push2pop2,ppx,ndd,ccmp,nf,cf,zu -### -- 2>&1 %s | FileCheck 
-check-prefix=APXF %s
 // APXF: "-target-feature" "+egpr" "-target-feature" "+push2pop2" 
"-target-feature" "+ppx" "-target-feature" "+ndd" "-target-feature" "+ccmp" 
"-target-feature" "+nf" "-target-feature" "+cf" "-target-feature" "+zu"
 // NO-APXF: "-target-feature" "-egpr" "-target-feature" "-push2pop2" 
"-target-feature" "-ppx" "-target-feature" "-ndd" "-target-feature" "-ccmp" 
"-target-feature" "-nf" "-target-feature" "-cf" "-target-feature" "-zu"

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


[clang] [Driver][X86] Fix LIT test failure on Solaris/MacOS (PR #141486)

2025-05-26 Thread Feng Zou via cfe-commits

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


[clang] [Clang] Add resource_dir_EQ flag to CC1Option group (PR #140870)

2025-05-26 Thread kadir çetinkaya via cfe-commits

kadircet wrote:

LGTM, but cc @llvm/clang-area-team, in case they have any concerns here

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


[clang] Fix tests of lookup table generator (PR #139463)

2025-05-26 Thread kadir çetinkaya via cfe-commits

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


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


[clang-tools-extra] [clang-doc] Update serializer for improved template handling (PR #138065)

2025-05-26 Thread Petr Hosek via cfe-commits


@@ -35,6 +35,169 @@ static void populateMemberTypeInfo(RecordInfo &I, 
AccessSpecifier &Access,
const DeclaratorDecl *D,
bool IsStatic = false);
 
+static void getTemplateParameters(const TemplateParameterList *TemplateParams,
+  llvm::raw_ostream &Stream) {
+  Stream << "template <";
+
+  for (unsigned i = 0; i < TemplateParams->size(); ++i) {
+if (i > 0)
+  Stream << ", ";
+
+const NamedDecl *Param = TemplateParams->getParam(i);
+if (const auto *TTP = llvm::dyn_cast(Param)) {
+  if (TTP->wasDeclaredWithTypename())
+Stream << "typename";
+  else
+Stream << "class";

petrhosek wrote:

We also need to handle type constraints, see `TTP->hasTypeConstraint()`, for 
example:
```
template 
class C {};
```

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


[clang] [clang][OpenCL] Only evaluate initializer once to check for zero init (PR #141474)

2025-05-26 Thread Timm Baeder via cfe-commits

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


[clang] [Clang] Fix a pack expansion bug in template argument deduction (PR #141547)

2025-05-26 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 created 
https://github.com/llvm/llvm-project/pull/141547

I think the intent of df18ee96206 was to substitute only those non-packs into a 
pack expansion type (e.g. `T` in `T::pack`...), so let's hold off pack 
expansions explicitly, in case there are calls coming from a substitution of 
pack expansion.

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

>From e20d9aec39ea1360c7233bca397cada640a8c36f Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Tue, 27 May 2025 14:07:00 +0800
Subject: [PATCH] [Clang] Fix a pack expansion bug in template argument
 deduction

I think the intent of df18ee96206 was to substitute only those non-packs
into a pack expansion type (e.g. `T` in `T::pack`...), so let's hold off
pack expansions explicitly, in case there are calls coming from a
substitution of pack expansion.
---
 clang/docs/ReleaseNotes.rst |  1 +
 clang/lib/Sema/SemaTemplateDeduction.cpp|  1 +
 .../CXX/temp/temp.fct.spec/temp.deduct/p7.cpp   | 17 +
 3 files changed, 19 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b93fa33acc2a0..2c46a8f8ac86d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -795,6 +795,7 @@ Bug Fixes to C++ Support
 - Fix instantiation of default-initialized variable template specialization. 
(#GH140632) (#GH140622)
 - Clang modules now allow a module and its user to differ on 
TrivialAutoVarInit*
 - Fixed an access checking bug when initializing non-aggregates in default 
arguments (#GH62444), (#GH83608)
+- Fixed a pack substitution bug in deducing class template partial 
specializations. (#GH53609)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 217d57d67f067..75ae04b27d06a 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -2946,6 +2946,7 @@ ConvertDeducedTemplateArgument(Sema &S, NamedDecl *Param,
   LocalInstantiationScope Scope(S);
   MultiLevelTemplateArgumentList Args(Template, CTAI.SugaredConverted,
   /*Final=*/true);
+  Sema::ArgPackSubstIndexRAII OnlySubstNonPackExpansion(S, std::nullopt);
 
   if (auto *NTTP = dyn_cast(Param)) {
 Sema::InstantiatingTemplate Inst(S, Template->getLocation(), Template,
diff --git a/clang/test/CXX/temp/temp.fct.spec/temp.deduct/p7.cpp 
b/clang/test/CXX/temp/temp.fct.spec/temp.deduct/p7.cpp
index f0ab7b8ea7612..de6fa0c837e2a 100644
--- a/clang/test/CXX/temp/temp.fct.spec/temp.deduct/p7.cpp
+++ b/clang/test/CXX/temp/temp.fct.spec/temp.deduct/p7.cpp
@@ -54,3 +54,20 @@ namespace reversed_operator_substitution_order {
   float &s = no_adl::f(true);
 }
 #endif
+
+namespace GH53609 {
+
+template 
+struct a;
+
+template 
+struct b;
+
+template 
+struct b...> {};
+
+template  struct c: b...  {};
+
+c d;
+
+}

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


[clang-tools-extra] [clang-doc] Update serializer for improved template handling (PR #138065)

2025-05-26 Thread Petr Hosek via cfe-commits


@@ -35,6 +35,169 @@ static void populateMemberTypeInfo(RecordInfo &I, 
AccessSpecifier &Access,
const DeclaratorDecl *D,
bool IsStatic = false);
 
+static void getTemplateParameters(const TemplateParameterList *TemplateParams,
+  llvm::raw_ostream &Stream) {
+  Stream << "template <";
+
+  for (unsigned i = 0; i < TemplateParams->size(); ++i) {
+if (i > 0)
+  Stream << ", ";
+
+const NamedDecl *Param = TemplateParams->getParam(i);
+if (const auto *TTP = llvm::dyn_cast(Param)) {
+  if (TTP->wasDeclaredWithTypename())
+Stream << "typename";
+  else
+Stream << "class";
+  if (TTP->isParameterPack())
+Stream << "...";
+  Stream << " " << TTP->getNameAsString();
+} else if (const auto *NTTP =
+   llvm::dyn_cast(Param)) {
+  NTTP->getType().print(Stream, NTTP->getASTContext().getPrintingPolicy());
+  if (NTTP->isParameterPack())
+Stream << "...";
+  Stream << " " << NTTP->getNameAsString();
+} else if (const auto *TTPD =
+   llvm::dyn_cast(Param)) {
+  Stream << "template <";
+  getTemplateParameters(TTPD->getTemplateParameters(), Stream);
+  Stream << "> class " << TTPD->getNameAsString();
+}
+  }
+
+  Stream << "> ";
+}
+
+// Extract the full function prototype from a FunctionDecl including
+// Full Decl
+static llvm::SmallString<256>
+getFunctionPrototype(const FunctionDecl *FuncDecl) {
+  llvm::SmallString<256> Result;
+  llvm::raw_svector_ostream Stream(Result);
+  const ASTContext &Ctx = FuncDecl->getASTContext();
+  const auto *Method = llvm::dyn_cast(FuncDecl);
+  // If it's a templated function, handle the template parameters
+  if (const auto *TmplDecl = FuncDecl->getDescribedTemplate())
+getTemplateParameters(TmplDecl->getTemplateParameters(), Stream);
+
+  // If it's a virtual method
+  if (Method && Method->isVirtual())
+Stream << "virtual ";
+
+  // Print return type
+  FuncDecl->getReturnType().print(Stream, Ctx.getPrintingPolicy());
+
+  // Print function name
+  Stream << " " << FuncDecl->getNameAsString() << "(";
+
+  // Print parameter list with types, names, and default values
+  for (unsigned I = 0; I < FuncDecl->getNumParams(); ++I) {
+if (I > 0)
+  Stream << ", ";
+const ParmVarDecl *ParamDecl = FuncDecl->getParamDecl(I);
+QualType ParamType = ParamDecl->getType();
+ParamType.print(Stream, Ctx.getPrintingPolicy());
+
+// Print parameter name if it has one
+if (!ParamDecl->getName().empty())
+  Stream << " " << ParamDecl->getNameAsString();
+
+// Print default argument if it exists
+if (ParamDecl->hasDefaultArg()) {
+  const Expr *DefaultArg = ParamDecl->getDefaultArg();
+  if (DefaultArg) {
+Stream << " = ";
+DefaultArg->printPretty(Stream, nullptr, Ctx.getPrintingPolicy());
+  }
+}
+  }
+
+  // If it is a variadic function, add '...'
+  if (FuncDecl->isVariadic()) {
+if (FuncDecl->getNumParams() > 0)
+  Stream << ", ";
+Stream << "...";
+  }
+
+  Stream << ")";
+
+  // If it's a const method, add 'const' qualifier
+  if (Method) {

petrhosek wrote:

This also needs to handle `= delete`.

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


[clang] [Clang] Fix a pack expansion bug in template argument deduction (PR #141547)

2025-05-26 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Younan Zhang (zyn0217)


Changes

I think the intent of df18ee96206 was to substitute only those non-packs into a 
pack expansion type (e.g. `T` in `T::pack...`), so let's hold off pack 
expansions explicitly, in case there are calls coming from a substitution of 
pack expansion.

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

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+1) 
- (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+1) 
- (modified) clang/test/CXX/temp/temp.fct.spec/temp.deduct/p7.cpp (+17) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b93fa33acc2a0..2c46a8f8ac86d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -795,6 +795,7 @@ Bug Fixes to C++ Support
 - Fix instantiation of default-initialized variable template specialization. 
(#GH140632) (#GH140622)
 - Clang modules now allow a module and its user to differ on 
TrivialAutoVarInit*
 - Fixed an access checking bug when initializing non-aggregates in default 
arguments (#GH62444), (#GH83608)
+- Fixed a pack substitution bug in deducing class template partial 
specializations. (#GH53609)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 217d57d67f067..75ae04b27d06a 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -2946,6 +2946,7 @@ ConvertDeducedTemplateArgument(Sema &S, NamedDecl *Param,
   LocalInstantiationScope Scope(S);
   MultiLevelTemplateArgumentList Args(Template, CTAI.SugaredConverted,
   /*Final=*/true);
+  Sema::ArgPackSubstIndexRAII OnlySubstNonPackExpansion(S, std::nullopt);
 
   if (auto *NTTP = dyn_cast(Param)) {
 Sema::InstantiatingTemplate Inst(S, Template->getLocation(), Template,
diff --git a/clang/test/CXX/temp/temp.fct.spec/temp.deduct/p7.cpp 
b/clang/test/CXX/temp/temp.fct.spec/temp.deduct/p7.cpp
index f0ab7b8ea7612..de6fa0c837e2a 100644
--- a/clang/test/CXX/temp/temp.fct.spec/temp.deduct/p7.cpp
+++ b/clang/test/CXX/temp/temp.fct.spec/temp.deduct/p7.cpp
@@ -54,3 +54,20 @@ namespace reversed_operator_substitution_order {
   float &s = no_adl::f(true);
 }
 #endif
+
+namespace GH53609 {
+
+template 
+struct a;
+
+template 
+struct b;
+
+template 
+struct b...> {};
+
+template  struct c: b...  {};
+
+c d;
+
+}

``




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


[clang] [Clang] Fix a pack expansion bug in template argument deduction (PR #141547)

2025-05-26 Thread Younan Zhang via cfe-commits

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


[clang-tools-extra] [clang-doc] Update serializer for improved template handling (PR #138065)

2025-05-26 Thread Petr Hosek via cfe-commits

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


[clang-tools-extra] [clang-doc] Update serializer for improved template handling (PR #138065)

2025-05-26 Thread Petr Hosek via cfe-commits

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


[clang-tools-extra] [clang-doc] Update serializer for improved template handling (PR #138065)

2025-05-26 Thread Petr Hosek via cfe-commits


@@ -35,6 +35,169 @@ static void populateMemberTypeInfo(RecordInfo &I, 
AccessSpecifier &Access,
const DeclaratorDecl *D,
bool IsStatic = false);
 
+static void getTemplateParameters(const TemplateParameterList *TemplateParams,
+  llvm::raw_ostream &Stream) {
+  Stream << "template <";
+
+  for (unsigned i = 0; i < TemplateParams->size(); ++i) {
+if (i > 0)
+  Stream << ", ";
+
+const NamedDecl *Param = TemplateParams->getParam(i);
+if (const auto *TTP = llvm::dyn_cast(Param)) {
+  if (TTP->wasDeclaredWithTypename())
+Stream << "typename";
+  else
+Stream << "class";
+  if (TTP->isParameterPack())
+Stream << "...";
+  Stream << " " << TTP->getNameAsString();

petrhosek wrote:

We also need to handle type constraints, see `TTP->hasTypeConstraint()`, for 
example:
```
template 
class C {};
```

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


[clang-tools-extra] [clang-doc] Update serializer for improved template handling (PR #138065)

2025-05-26 Thread Petr Hosek via cfe-commits


@@ -35,6 +35,169 @@ static void populateMemberTypeInfo(RecordInfo &I, 
AccessSpecifier &Access,
const DeclaratorDecl *D,
bool IsStatic = false);
 
+static void getTemplateParameters(const TemplateParameterList *TemplateParams,
+  llvm::raw_ostream &Stream) {
+  Stream << "template <";
+
+  for (unsigned i = 0; i < TemplateParams->size(); ++i) {
+if (i > 0)
+  Stream << ", ";
+
+const NamedDecl *Param = TemplateParams->getParam(i);
+if (const auto *TTP = llvm::dyn_cast(Param)) {
+  if (TTP->wasDeclaredWithTypename())
+Stream << "typename";
+  else
+Stream << "class";
+  if (TTP->isParameterPack())
+Stream << "...";
+  Stream << " " << TTP->getNameAsString();
+} else if (const auto *NTTP =
+   llvm::dyn_cast(Param)) {
+  NTTP->getType().print(Stream, NTTP->getASTContext().getPrintingPolicy());
+  if (NTTP->isParameterPack())
+Stream << "...";
+  Stream << " " << NTTP->getNameAsString();
+} else if (const auto *TTPD =
+   llvm::dyn_cast(Param)) {
+  Stream << "template <";
+  getTemplateParameters(TTPD->getTemplateParameters(), Stream);
+  Stream << "> class " << TTPD->getNameAsString();
+}
+  }
+
+  Stream << "> ";
+}
+
+// Extract the full function prototype from a FunctionDecl including
+// Full Decl
+static llvm::SmallString<256>
+getFunctionPrototype(const FunctionDecl *FuncDecl) {
+  llvm::SmallString<256> Result;
+  llvm::raw_svector_ostream Stream(Result);
+  const ASTContext &Ctx = FuncDecl->getASTContext();
+  const auto *Method = llvm::dyn_cast(FuncDecl);
+  // If it's a templated function, handle the template parameters
+  if (const auto *TmplDecl = FuncDecl->getDescribedTemplate())
+getTemplateParameters(TmplDecl->getTemplateParameters(), Stream);
+
+  // If it's a virtual method
+  if (Method && Method->isVirtual())
+Stream << "virtual ";
+
+  // Print return type
+  FuncDecl->getReturnType().print(Stream, Ctx.getPrintingPolicy());
+
+  // Print function name
+  Stream << " " << FuncDecl->getNameAsString() << "(";
+
+  // Print parameter list with types, names, and default values
+  for (unsigned I = 0; I < FuncDecl->getNumParams(); ++I) {
+if (I > 0)
+  Stream << ", ";
+const ParmVarDecl *ParamDecl = FuncDecl->getParamDecl(I);
+QualType ParamType = ParamDecl->getType();
+ParamType.print(Stream, Ctx.getPrintingPolicy());
+
+// Print parameter name if it has one
+if (!ParamDecl->getName().empty())
+  Stream << " " << ParamDecl->getNameAsString();
+
+// Print default argument if it exists
+if (ParamDecl->hasDefaultArg()) {
+  const Expr *DefaultArg = ParamDecl->getDefaultArg();
+  if (DefaultArg) {
+Stream << " = ";
+DefaultArg->printPretty(Stream, nullptr, Ctx.getPrintingPolicy());
+  }
+}
+  }
+
+  // If it is a variadic function, add '...'
+  if (FuncDecl->isVariadic()) {
+if (FuncDecl->getNumParams() > 0)
+  Stream << ", ";
+Stream << "...";
+  }
+
+  Stream << ")";
+
+  // If it's a const method, add 'const' qualifier
+  if (Method) {
+if (Method->size_overridden_methods())
+  Stream << " override";
+if (Method->hasAttr())
+  Stream << " final";
+if (Method->isConst())
+  Stream << " const";
+if (Method->isPureVirtual())
+  Stream << " = 0";
+  }
+  return Result; // Convert SmallString to std::string for return

petrhosek wrote:

We also need to handle `noexcept`  and in pre-C++20 `throw()`.

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


[clang] [Clang] Fix a pack expansion bug in template argument deduction (PR #141547)

2025-05-26 Thread via cfe-commits

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


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


[clang] 9e6fc8d - [Driver][X86] Fix LIT test failure on Solaris/MacOS (#141486)

2025-05-26 Thread via cfe-commits

Author: Feng Zou
Date: 2025-05-27T14:58:32+08:00
New Revision: 9e6fc8dedd75bcb9a389921bee12d18eecbd9908

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

LOG: [Driver][X86] Fix LIT test failure on Solaris/MacOS (#141486)

The LIT test is introduced by
https://github.com/llvm/llvm-project/pull/140874. Fixed by using "--" to
separate options from input file names.

Added: 


Modified: 
clang/test/Driver/cl-x86-flags.c

Removed: 




diff  --git a/clang/test/Driver/cl-x86-flags.c 
b/clang/test/Driver/cl-x86-flags.c
index 0210b5f3cd3f1..1e6418207e642 100644
--- a/clang/test/Driver/cl-x86-flags.c
+++ b/clang/test/Driver/cl-x86-flags.c
@@ -137,14 +137,14 @@ void f(void) {
 }
 
 
-// RUN: not %clang_cl -### --target=i386 -mapx-features=ndd %s 2>&1 | 
FileCheck --check-prefix=NON-APX %s
-// RUN: not %clang_cl -### --target=i386 -mapxf %s 2>&1 | FileCheck 
--check-prefix=NON-APX %s
-// RUN: %clang_cl -### --target=i386 -mno-apxf %s 2>&1 > /dev/null
-// NON-APX:  error: unsupported option '-mapx-features=|-mapxf' for target 
'i386'
+// RUN: not %clang_cl -### --target=i386-pc-windows -mapx-features=ndd -- 2>&1 
%s | FileCheck --check-prefix=NON-APX %s
+// RUN: not %clang_cl -### --target=i386-pc-windows -mapxf -- 2>&1 %s | 
FileCheck --check-prefix=NON-APX %s
+// RUN: %clang_cl -### --target=i386-pc-windows -mno-apxf -- 2>&1 %s > 
/dev/null
+// NON-APX:  error: unsupported option '-mapx-features=|-mapxf' for target 
'i386-pc-windows{{.*}}'
 // NON-APX-NOT:  error: {{.*}} -mapx-features=
 
-// RUN: %clang_cl --target=x86_64-pc-windows -mapxf %s -### 2>&1 | FileCheck 
-check-prefix=APXF %s
-// RUN: %clang_cl --target=x86_64-pc-windows -mapxf -mno-apxf %s -### 2>&1 | 
FileCheck -check-prefix=NO-APXF %s
-// RUN: %clang_cl --target=x86_64-pc-windows 
-mapx-features=egpr,push2pop2,ppx,ndd,ccmp,nf,cf,zu %s -### 2>&1 | FileCheck 
-check-prefix=APXF %s
+// RUN: %clang_cl --target=x86_64-pc-windows -mapxf -### -- 2>&1 %s | 
FileCheck -check-prefix=APXF %s
+// RUN: %clang_cl --target=x86_64-pc-windows -mapxf -mno-apxf -### -- 2>&1 %s 
| FileCheck -check-prefix=NO-APXF %s
+// RUN: %clang_cl --target=x86_64-pc-windows 
-mapx-features=egpr,push2pop2,ppx,ndd,ccmp,nf,cf,zu -### -- 2>&1 %s | FileCheck 
-check-prefix=APXF %s
 // APXF: "-target-feature" "+egpr" "-target-feature" "+push2pop2" 
"-target-feature" "+ppx" "-target-feature" "+ndd" "-target-feature" "+ccmp" 
"-target-feature" "+nf" "-target-feature" "+cf" "-target-feature" "+zu"
 // NO-APXF: "-target-feature" "-egpr" "-target-feature" "-push2pop2" 
"-target-feature" "-ppx" "-target-feature" "-ndd" "-target-feature" "-ccmp" 
"-target-feature" "-nf" "-target-feature" "-cf" "-target-feature" "-zu"



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


[clang] [flang] [flang] add -floop-interchange and enable it with opt levels (PR #140182)

2025-05-26 Thread KAWASHIMA Takahiro via cfe-commits

kawashima-fj wrote:

I've confirmed the result of Fujitsu Compiler Test Suite. The only correctness 
issue affected by this commit is 
https://github.com/fujitsu/compiler-test-suite/blob/main/Fortran/0347/0347_0240.f,
 which will be resolved by #140709.

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


[clang] [clang][RISCV] Handle target features correctly in CheckBuiltinFunctionCall (PR #141548)

2025-05-26 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-risc-v

Author: Brandon Wu (4vtomat)


Changes

Currently we only check the required features passed by command line arguments.
We also need to check the features passed by using target features.


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


2 Files Affected:

- (modified) clang/lib/Sema/SemaRISCV.cpp (+29-20) 
- (added) clang/test/Sema/zvk-target-attributes.c (+11) 


``diff
diff --git a/clang/lib/Sema/SemaRISCV.cpp b/clang/lib/Sema/SemaRISCV.cpp
index 481bf8bd22cc1..ca8d849b40a2a 100644
--- a/clang/lib/Sema/SemaRISCV.cpp
+++ b/clang/lib/Sema/SemaRISCV.cpp
@@ -544,8 +544,10 @@ bool SemaRISCV::CheckLMUL(CallExpr *TheCall, unsigned 
ArgNum) {
  << Arg->getSourceRange();
 }
 
-static bool CheckInvalidVLENandLMUL(const TargetInfo &TI, CallExpr *TheCall,
-Sema &S, QualType Type, int EGW) {
+static bool CheckInvalidVLENandLMUL(const TargetInfo &TI,
+llvm::StringMap &FunctionFeatureMap,
+CallExpr *TheCall, Sema &S, QualType Type,
+int EGW) {
   assert((EGW == 128 || EGW == 256) && "EGW can only be 128 or 256 bits");
 
   // LMUL * VLEN >= EGW
@@ -566,7 +568,7 @@ static bool CheckInvalidVLENandLMUL(const TargetInfo &TI, 
CallExpr *TheCall,
   // Vscale is VLEN/RVVBitsPerBlock.
   unsigned MinRequiredVLEN = VScaleFactor * llvm::RISCV::RVVBitsPerBlock;
   std::string RequiredExt = "zvl" + std::to_string(MinRequiredVLEN) + "b";
-  if (!TI.hasFeature(RequiredExt))
+  if (!TI.hasFeature(RequiredExt) && !FunctionFeatureMap.lookup(RequiredExt))
 return S.Diag(TheCall->getBeginLoc(),
   diag::err_riscv_type_requires_extension)
<< Type << RequiredExt;
@@ -578,6 +580,10 @@ bool SemaRISCV::CheckBuiltinFunctionCall(const TargetInfo 
&TI,
  unsigned BuiltinID,
  CallExpr *TheCall) {
   ASTContext &Context = getASTContext();
+  const FunctionDecl *FD = SemaRef.getCurFunctionDecl();
+  llvm::StringMap FunctionFeatureMap;
+  Context.getFunctionFeatureMap(FunctionFeatureMap, FD);
+
   // vmulh.vv, vmulh.vx, vmulhu.vv, vmulhu.vx, vmulhsu.vv, vmulhsu.vx,
   // vsmul.vv, vsmul.vx are not included for EEW=64 in Zve64*.
   switch (BuiltinID) {
@@ -634,10 +640,6 @@ bool SemaRISCV::CheckBuiltinFunctionCall(const TargetInfo 
&TI,
 ASTContext::BuiltinVectorTypeInfo Info = Context.getBuiltinVectorTypeInfo(
 TheCall->getType()->castAs());
 
-const FunctionDecl *FD = SemaRef.getCurFunctionDecl();
-llvm::StringMap FunctionFeatureMap;
-Context.getFunctionFeatureMap(FunctionFeatureMap, FD);
-
 if (Context.getTypeSize(Info.ElementType) == 64 && !TI.hasFeature("v") &&
 !FunctionFeatureMap.lookup("v"))
   return Diag(TheCall->getBeginLoc(),
@@ -713,20 +715,24 @@ bool SemaRISCV::CheckBuiltinFunctionCall(const TargetInfo 
&TI,
   case RISCVVector::BI__builtin_rvv_vsm4k_vi_tu: {
 QualType Arg0Type = TheCall->getArg(0)->getType();
 QualType Arg1Type = TheCall->getArg(1)->getType();
-return CheckInvalidVLENandLMUL(TI, TheCall, SemaRef, Arg0Type, 128) ||
-   CheckInvalidVLENandLMUL(TI, TheCall, SemaRef, Arg1Type, 128) ||
+return CheckInvalidVLENandLMUL(TI, FunctionFeatureMap, TheCall, SemaRef,
+   Arg0Type, 128) ||
+   CheckInvalidVLENandLMUL(TI, FunctionFeatureMap, TheCall, SemaRef,
+   Arg1Type, 128) ||
SemaRef.BuiltinConstantArgRange(TheCall, 2, 0, 31);
   }
   case RISCVVector::BI__builtin_rvv_vsm3c_vi_tu:
   case RISCVVector::BI__builtin_rvv_vsm3c_vi: {
 QualType Arg0Type = TheCall->getArg(0)->getType();
-return CheckInvalidVLENandLMUL(TI, TheCall, SemaRef, Arg0Type, 256) ||
+return CheckInvalidVLENandLMUL(TI, FunctionFeatureMap, TheCall, SemaRef,
+   Arg0Type, 256) ||
SemaRef.BuiltinConstantArgRange(TheCall, 2, 0, 31);
   }
   case RISCVVector::BI__builtin_rvv_vaeskf1_vi:
   case RISCVVector::BI__builtin_rvv_vsm4k_vi: {
 QualType Arg0Type = TheCall->getArg(0)->getType();
-return CheckInvalidVLENandLMUL(TI, TheCall, SemaRef, Arg0Type, 128) ||
+return CheckInvalidVLENandLMUL(TI, FunctionFeatureMap, TheCall, SemaRef,
+   Arg0Type, 128) ||
SemaRef.BuiltinConstantArgRange(TheCall, 1, 0, 31);
   }
   case RISCVVector::BI__builtin_rvv_vaesdf_vv:
@@ -753,8 +759,10 @@ bool SemaRISCV::CheckBuiltinFunctionCall(const TargetInfo 
&TI,
   case RISCVVector::BI__builtin_rvv_vsm4r_vs_tu: {
 QualType Arg0Type = TheCall->getArg(0)->getType();
 QualType Arg1Type = TheCall->getArg(1)->getType();
-return CheckInvalidVLENandLMUL(TI, TheCall, SemaRef, Arg0Type, 128) ||
-   CheckInvalidVLENandLMUL(TI, TheCall, SemaRef, Arg1Type, 128);
+return CheckInva

[clang] [clang][RISCV] Handle target features correctly in CheckBuiltinFunctionCall (PR #141548)

2025-05-26 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Brandon Wu (4vtomat)


Changes

Currently we only check the required features passed by command line arguments.
We also need to check the features passed by using target features.


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


2 Files Affected:

- (modified) clang/lib/Sema/SemaRISCV.cpp (+29-20) 
- (added) clang/test/Sema/zvk-target-attributes.c (+11) 


``diff
diff --git a/clang/lib/Sema/SemaRISCV.cpp b/clang/lib/Sema/SemaRISCV.cpp
index 481bf8bd22cc1..ca8d849b40a2a 100644
--- a/clang/lib/Sema/SemaRISCV.cpp
+++ b/clang/lib/Sema/SemaRISCV.cpp
@@ -544,8 +544,10 @@ bool SemaRISCV::CheckLMUL(CallExpr *TheCall, unsigned 
ArgNum) {
  << Arg->getSourceRange();
 }
 
-static bool CheckInvalidVLENandLMUL(const TargetInfo &TI, CallExpr *TheCall,
-Sema &S, QualType Type, int EGW) {
+static bool CheckInvalidVLENandLMUL(const TargetInfo &TI,
+llvm::StringMap &FunctionFeatureMap,
+CallExpr *TheCall, Sema &S, QualType Type,
+int EGW) {
   assert((EGW == 128 || EGW == 256) && "EGW can only be 128 or 256 bits");
 
   // LMUL * VLEN >= EGW
@@ -566,7 +568,7 @@ static bool CheckInvalidVLENandLMUL(const TargetInfo &TI, 
CallExpr *TheCall,
   // Vscale is VLEN/RVVBitsPerBlock.
   unsigned MinRequiredVLEN = VScaleFactor * llvm::RISCV::RVVBitsPerBlock;
   std::string RequiredExt = "zvl" + std::to_string(MinRequiredVLEN) + "b";
-  if (!TI.hasFeature(RequiredExt))
+  if (!TI.hasFeature(RequiredExt) && !FunctionFeatureMap.lookup(RequiredExt))
 return S.Diag(TheCall->getBeginLoc(),
   diag::err_riscv_type_requires_extension)
<< Type << RequiredExt;
@@ -578,6 +580,10 @@ bool SemaRISCV::CheckBuiltinFunctionCall(const TargetInfo 
&TI,
  unsigned BuiltinID,
  CallExpr *TheCall) {
   ASTContext &Context = getASTContext();
+  const FunctionDecl *FD = SemaRef.getCurFunctionDecl();
+  llvm::StringMap FunctionFeatureMap;
+  Context.getFunctionFeatureMap(FunctionFeatureMap, FD);
+
   // vmulh.vv, vmulh.vx, vmulhu.vv, vmulhu.vx, vmulhsu.vv, vmulhsu.vx,
   // vsmul.vv, vsmul.vx are not included for EEW=64 in Zve64*.
   switch (BuiltinID) {
@@ -634,10 +640,6 @@ bool SemaRISCV::CheckBuiltinFunctionCall(const TargetInfo 
&TI,
 ASTContext::BuiltinVectorTypeInfo Info = Context.getBuiltinVectorTypeInfo(
 TheCall->getType()->castAs());
 
-const FunctionDecl *FD = SemaRef.getCurFunctionDecl();
-llvm::StringMap FunctionFeatureMap;
-Context.getFunctionFeatureMap(FunctionFeatureMap, FD);
-
 if (Context.getTypeSize(Info.ElementType) == 64 && !TI.hasFeature("v") &&
 !FunctionFeatureMap.lookup("v"))
   return Diag(TheCall->getBeginLoc(),
@@ -713,20 +715,24 @@ bool SemaRISCV::CheckBuiltinFunctionCall(const TargetInfo 
&TI,
   case RISCVVector::BI__builtin_rvv_vsm4k_vi_tu: {
 QualType Arg0Type = TheCall->getArg(0)->getType();
 QualType Arg1Type = TheCall->getArg(1)->getType();
-return CheckInvalidVLENandLMUL(TI, TheCall, SemaRef, Arg0Type, 128) ||
-   CheckInvalidVLENandLMUL(TI, TheCall, SemaRef, Arg1Type, 128) ||
+return CheckInvalidVLENandLMUL(TI, FunctionFeatureMap, TheCall, SemaRef,
+   Arg0Type, 128) ||
+   CheckInvalidVLENandLMUL(TI, FunctionFeatureMap, TheCall, SemaRef,
+   Arg1Type, 128) ||
SemaRef.BuiltinConstantArgRange(TheCall, 2, 0, 31);
   }
   case RISCVVector::BI__builtin_rvv_vsm3c_vi_tu:
   case RISCVVector::BI__builtin_rvv_vsm3c_vi: {
 QualType Arg0Type = TheCall->getArg(0)->getType();
-return CheckInvalidVLENandLMUL(TI, TheCall, SemaRef, Arg0Type, 256) ||
+return CheckInvalidVLENandLMUL(TI, FunctionFeatureMap, TheCall, SemaRef,
+   Arg0Type, 256) ||
SemaRef.BuiltinConstantArgRange(TheCall, 2, 0, 31);
   }
   case RISCVVector::BI__builtin_rvv_vaeskf1_vi:
   case RISCVVector::BI__builtin_rvv_vsm4k_vi: {
 QualType Arg0Type = TheCall->getArg(0)->getType();
-return CheckInvalidVLENandLMUL(TI, TheCall, SemaRef, Arg0Type, 128) ||
+return CheckInvalidVLENandLMUL(TI, FunctionFeatureMap, TheCall, SemaRef,
+   Arg0Type, 128) ||
SemaRef.BuiltinConstantArgRange(TheCall, 1, 0, 31);
   }
   case RISCVVector::BI__builtin_rvv_vaesdf_vv:
@@ -753,8 +759,10 @@ bool SemaRISCV::CheckBuiltinFunctionCall(const TargetInfo 
&TI,
   case RISCVVector::BI__builtin_rvv_vsm4r_vs_tu: {
 QualType Arg0Type = TheCall->getArg(0)->getType();
 QualType Arg1Type = TheCall->getArg(1)->getType();
-return CheckInvalidVLENandLMUL(TI, TheCall, SemaRef, Arg0Type, 128) ||
-   CheckInvalidVLENandLMUL(TI, TheCall, SemaRef, Arg1Type, 128);
+return CheckInvalidVLENan

[clang-tools-extra] [clang-doc] Update serializer for improved template handling (PR #138065)

2025-05-26 Thread Petr Hosek via cfe-commits

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


[clang] [clang][RISCV] Handle target features correctly in CheckBuiltinFunctionCall (PR #141548)

2025-05-26 Thread Brandon Wu via cfe-commits

https://github.com/4vtomat created 
https://github.com/llvm/llvm-project/pull/141548

Currently we only check the required features passed by command line arguments.
We also need to check the features passed by using target features.


>From a125a7137fcfb05418e97d2823d5b0a7f099645d Mon Sep 17 00:00:00 2001
From: Brandon Wu 
Date: Mon, 26 May 2025 22:39:28 -0700
Subject: [PATCH] [clang][RISCV] Handle target features correctly in
 CheckBuiltinFunctionCall

Currently we only check the required features passed by command line arguments.
We also need to check the features passed by using target features.
---
 clang/lib/Sema/SemaRISCV.cpp| 49 +++--
 clang/test/Sema/zvk-target-attributes.c | 11 ++
 2 files changed, 40 insertions(+), 20 deletions(-)
 create mode 100644 clang/test/Sema/zvk-target-attributes.c

diff --git a/clang/lib/Sema/SemaRISCV.cpp b/clang/lib/Sema/SemaRISCV.cpp
index 481bf8bd22cc1..ca8d849b40a2a 100644
--- a/clang/lib/Sema/SemaRISCV.cpp
+++ b/clang/lib/Sema/SemaRISCV.cpp
@@ -544,8 +544,10 @@ bool SemaRISCV::CheckLMUL(CallExpr *TheCall, unsigned 
ArgNum) {
  << Arg->getSourceRange();
 }
 
-static bool CheckInvalidVLENandLMUL(const TargetInfo &TI, CallExpr *TheCall,
-Sema &S, QualType Type, int EGW) {
+static bool CheckInvalidVLENandLMUL(const TargetInfo &TI,
+llvm::StringMap &FunctionFeatureMap,
+CallExpr *TheCall, Sema &S, QualType Type,
+int EGW) {
   assert((EGW == 128 || EGW == 256) && "EGW can only be 128 or 256 bits");
 
   // LMUL * VLEN >= EGW
@@ -566,7 +568,7 @@ static bool CheckInvalidVLENandLMUL(const TargetInfo &TI, 
CallExpr *TheCall,
   // Vscale is VLEN/RVVBitsPerBlock.
   unsigned MinRequiredVLEN = VScaleFactor * llvm::RISCV::RVVBitsPerBlock;
   std::string RequiredExt = "zvl" + std::to_string(MinRequiredVLEN) + "b";
-  if (!TI.hasFeature(RequiredExt))
+  if (!TI.hasFeature(RequiredExt) && !FunctionFeatureMap.lookup(RequiredExt))
 return S.Diag(TheCall->getBeginLoc(),
   diag::err_riscv_type_requires_extension)
<< Type << RequiredExt;
@@ -578,6 +580,10 @@ bool SemaRISCV::CheckBuiltinFunctionCall(const TargetInfo 
&TI,
  unsigned BuiltinID,
  CallExpr *TheCall) {
   ASTContext &Context = getASTContext();
+  const FunctionDecl *FD = SemaRef.getCurFunctionDecl();
+  llvm::StringMap FunctionFeatureMap;
+  Context.getFunctionFeatureMap(FunctionFeatureMap, FD);
+
   // vmulh.vv, vmulh.vx, vmulhu.vv, vmulhu.vx, vmulhsu.vv, vmulhsu.vx,
   // vsmul.vv, vsmul.vx are not included for EEW=64 in Zve64*.
   switch (BuiltinID) {
@@ -634,10 +640,6 @@ bool SemaRISCV::CheckBuiltinFunctionCall(const TargetInfo 
&TI,
 ASTContext::BuiltinVectorTypeInfo Info = Context.getBuiltinVectorTypeInfo(
 TheCall->getType()->castAs());
 
-const FunctionDecl *FD = SemaRef.getCurFunctionDecl();
-llvm::StringMap FunctionFeatureMap;
-Context.getFunctionFeatureMap(FunctionFeatureMap, FD);
-
 if (Context.getTypeSize(Info.ElementType) == 64 && !TI.hasFeature("v") &&
 !FunctionFeatureMap.lookup("v"))
   return Diag(TheCall->getBeginLoc(),
@@ -713,20 +715,24 @@ bool SemaRISCV::CheckBuiltinFunctionCall(const TargetInfo 
&TI,
   case RISCVVector::BI__builtin_rvv_vsm4k_vi_tu: {
 QualType Arg0Type = TheCall->getArg(0)->getType();
 QualType Arg1Type = TheCall->getArg(1)->getType();
-return CheckInvalidVLENandLMUL(TI, TheCall, SemaRef, Arg0Type, 128) ||
-   CheckInvalidVLENandLMUL(TI, TheCall, SemaRef, Arg1Type, 128) ||
+return CheckInvalidVLENandLMUL(TI, FunctionFeatureMap, TheCall, SemaRef,
+   Arg0Type, 128) ||
+   CheckInvalidVLENandLMUL(TI, FunctionFeatureMap, TheCall, SemaRef,
+   Arg1Type, 128) ||
SemaRef.BuiltinConstantArgRange(TheCall, 2, 0, 31);
   }
   case RISCVVector::BI__builtin_rvv_vsm3c_vi_tu:
   case RISCVVector::BI__builtin_rvv_vsm3c_vi: {
 QualType Arg0Type = TheCall->getArg(0)->getType();
-return CheckInvalidVLENandLMUL(TI, TheCall, SemaRef, Arg0Type, 256) ||
+return CheckInvalidVLENandLMUL(TI, FunctionFeatureMap, TheCall, SemaRef,
+   Arg0Type, 256) ||
SemaRef.BuiltinConstantArgRange(TheCall, 2, 0, 31);
   }
   case RISCVVector::BI__builtin_rvv_vaeskf1_vi:
   case RISCVVector::BI__builtin_rvv_vsm4k_vi: {
 QualType Arg0Type = TheCall->getArg(0)->getType();
-return CheckInvalidVLENandLMUL(TI, TheCall, SemaRef, Arg0Type, 128) ||
+return CheckInvalidVLENandLMUL(TI, FunctionFeatureMap, TheCall, SemaRef,
+   Arg0Type, 128) ||
SemaRef.BuiltinConstantArgRange(TheCall, 1, 0, 31);
   }
   case RISCVVector::BI__builtin_rvv_vaesdf_vv:
@@ -753,8 +759,10 @@ bool SemaRIS

[clang] [analyzer] Introduce the check::BlockEntrance checker callback (PR #140924)

2025-05-26 Thread Balázs Benics via cfe-commits

https://github.com/balazs-benics-sonarsource updated 
https://github.com/llvm/llvm-project/pull/140924

From 084d821b62d5de473d32d3506da95fdd7bad1cfe Mon Sep 17 00:00:00 2001
From: Balazs Benics 
Date: Thu, 15 May 2025 17:20:29 +0200
Subject: [PATCH 1/7] [analyzer] Introduce the check::BlockEntrance

Tranersing the CFG blocks of a function is a fundamental operation.
Many C++ constructs can create splits in the control-flow, such as
`if`, `for`, and similar control structures or ternary expressions,
gnu conditionals, gotos, switches and possibly more.

Checkers should be able to get notifications about entering or leaving a
CFG block of interest.

Note that in the ExplodedGraph there is always a BlockEntrance
ProgramPoint right after the BlockEdge ProgramPoint.
I considered naming this callback check::BlockEdge, but then that may
leave the observer of the graph puzzled to see BlockEdge points followed
more BlockEdge nodes describing the same CFG transition.
This confusion could also apply to Bug Report Visitors too.

Because of this, I decided to hook BlockEntrance ProgramPoints instead.
The same confusion applies here, but I find this still a better place
TBH. There would only appear only one BlockEntrance ProgramPoint in the
graph if no checkers modify the state or emit a bug report.
Otherwise they modify some GDM (aka. State) thus create a new
ExplodedNode with the same BlockEntrance ProgramPoint in the graph.

CPP-6484
---
 .../clang/StaticAnalyzer/Core/Checker.h   |  20 ++
 .../StaticAnalyzer/Core/CheckerManager.h  |  13 +
 .../Core/PathSensitive/ExprEngine.h   |   4 +
 .../Checkers/CheckerDocumentation.cpp |  15 +-
 .../StaticAnalyzer/Core/CheckerManager.cpp|  50 +++-
 clang/lib/StaticAnalyzer/Core/CoreEngine.cpp  |  25 +-
 clang/lib/StaticAnalyzer/Core/ExprEngine.cpp  |  13 +
 clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp |   6 +-
 .../BlockEntranceCallbackTest.cpp | 283 ++
 clang/unittests/StaticAnalyzer/CMakeLists.txt |   1 +
 10 files changed, 414 insertions(+), 16 deletions(-)
 create mode 100644 clang/unittests/StaticAnalyzer/BlockEntranceCallbackTest.cpp

diff --git a/clang/include/clang/StaticAnalyzer/Core/Checker.h 
b/clang/include/clang/StaticAnalyzer/Core/Checker.h
index a54c5bee612f6..1b348dcce5ea7 100644
--- a/clang/include/clang/StaticAnalyzer/Core/Checker.h
+++ b/clang/include/clang/StaticAnalyzer/Core/Checker.h
@@ -221,6 +221,22 @@ class Bind {
   }
 };
 
+class BlockEntrance {
+  template 
+  static void _checkBlockEntrance(void *Checker,
+  const clang::BlockEntrance &Entrance,
+  CheckerContext &C) {
+((const CHECKER *)Checker)->checkBlockEntrance(Entrance, C);
+  }
+
+public:
+  template 
+  static void _register(CHECKER *checker, CheckerManager &mgr) {
+mgr._registerForBlockEntrance(CheckerManager::CheckBlockEntranceFunc(
+checker, _checkBlockEntrance));
+  }
+};
+
 class EndAnalysis {
   template 
   static void _checkEndAnalysis(void *checker, ExplodedGraph &G,
@@ -548,6 +564,8 @@ class CheckerProgramPointTag : public SimpleProgramPointTag 
{
 template 
 class Checker : public CHECK1, public CHECKs..., public CheckerBase {
 public:
+  using BlockEntrance = clang::BlockEntrance;
+
   template 
   static void _register(CHECKER *checker, CheckerManager &mgr) {
 CHECK1::_register(checker, mgr);
@@ -558,6 +576,8 @@ class Checker : public CHECK1, public CHECKs..., public 
CheckerBase {
 template 
 class Checker : public CHECK1, public CheckerBase {
 public:
+  using BlockEntrance = clang::BlockEntrance;
+
   template 
   static void _register(CHECKER *checker, CheckerManager &mgr) {
 CHECK1::_register(checker, mgr);
diff --git a/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h 
b/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
index 03ffadd346d0b..b5fefdb75401d 100644
--- a/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
+++ b/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
@@ -376,6 +376,12 @@ class CheckerManager {
   const Stmt *S, ExprEngine &Eng,
   const ProgramPoint &PP);
 
+  /// Run checkers after taking a control flow edge.
+  void runCheckersForBlockEntrance(ExplodedNodeSet &Dst,
+   const ExplodedNodeSet &Src,
+   const BlockEntrance &Entrance,
+   ExprEngine &Eng) const;
+
   /// Run checkers for end of analysis.
   void runCheckersForEndAnalysis(ExplodedGraph &G, BugReporter &BR,
  ExprEngine &Eng);
@@ -528,6 +534,9 @@ class CheckerManager {
   using CheckBindFunc =
   CheckerFn;
 
+  using CheckBlockEntranceFunc =
+  CheckerFn;
+
   using CheckEndAnalysisFunc =
   CheckerFn;
 
@@ -589,6 +598,8 @@ class CheckerManager {
 
   void _registerForBind(CheckBindFunc checkfn);
 
+  void _registerForBlockEntrance(Che

[clang] [analyzer] Introduce the check::BlockEntrance checker callback (PR #140924)

2025-05-26 Thread Balázs Benics via cfe-commits


@@ -166,6 +179,23 @@ class CheckerDocumentation
   /// check::Bind
   void checkBind(SVal Loc, SVal Val, const Stmt *S, CheckerContext &) const {}
 
+  /// Called after a CFG edge is taken within a function.
+  ///
+  /// This callback can be used to obtain information about potential branching
+  /// points or any other constructs that involve traversing a CFG edge.
+  /// Note that when inlining a call, there is no CFG edge between the caller
+  /// and the callee. One will only see the edge between the entry block and
+  /// the body of the function once inlined.

balazs-benics-sonarsource wrote:

Refined the comments in 700cd9380800c9e9105787c258ff63452fd97e15

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


[clang] [Driver][X86] Fix LIT test failure on Solaris/MacOS (PR #141486)

2025-05-26 Thread Feng Zou via cfe-commits

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


[clang] [Driver][X86] Add -m[no-]apxf to m_x86_Features_Group (PR #140874)

2025-05-26 Thread Feng Zou via cfe-commits

fzou1 wrote:

> Looks like this breaks tests on macOS: 
> http://45.33.8.238/macm1/107398/step_6.txt
> 
> Please take a look and revert for now if it takes a while to fix.

Thank you. I've reproduced this issue on MacOS and updated PR #141486 to fix it.

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


[clang] [Driver][X86] Fix LIT test failure on Solaris/MacOS (PR #141486)

2025-05-26 Thread Feng Zou via cfe-commits

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


[clang] [clang][OpenCL] Only evaluate initializer once to check for zero init (PR #141474)

2025-05-26 Thread Andrew Savonichev via cfe-commits

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

Good catch, LGTM.

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


[clang] HIPSPV: Unbundle SDL (PR #136412)

2025-05-26 Thread Paulius Velesko via cfe-commits

pvelesko wrote:

ping

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


[clang] [llvm] [UBSan] Implement src:*=sanitize for UBSan (PR #140529)

2025-05-26 Thread Qinkun Bao via cfe-commits

https://github.com/qinkunbao updated 
https://github.com/llvm/llvm-project/pull/140529

>From b83755d2aa0c5417ab8f359aa842449213437a7a Mon Sep 17 00:00:00 2001
From: Qinkun Bao 
Date: Mon, 19 May 2025 11:14:01 +
Subject: [PATCH 01/16] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20?=
 =?UTF-8?q?initial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.6
---
 .../clang/Basic/SanitizerSpecialCaseList.h|  7 +++-
 clang/lib/Basic/NoSanitizeList.cpp|  7 
 clang/lib/Basic/SanitizerSpecialCaseList.cpp  | 16 
 .../ubsan-src-ignorelist-category.test| 37 +++
 4 files changed, 66 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGen/ubsan-src-ignorelist-category.test

diff --git a/clang/include/clang/Basic/SanitizerSpecialCaseList.h 
b/clang/include/clang/Basic/SanitizerSpecialCaseList.h
index d024b7dfc2e85..25d518e7128cf 100644
--- a/clang/include/clang/Basic/SanitizerSpecialCaseList.h
+++ b/clang/include/clang/Basic/SanitizerSpecialCaseList.h
@@ -43,13 +43,18 @@ class SanitizerSpecialCaseList : public 
llvm::SpecialCaseList {
   bool inSection(SanitizerMask Mask, StringRef Prefix, StringRef Query,
  StringRef Category = StringRef()) const;
 
+  // Query ignorelisted entries if any bit in Mask matches the entry's section.
+  // Return 0 if not found. If found, return the line number (starts with 1).
+  unsigned inSectionBlame(SanitizerMask Mask, StringRef Prefix, StringRef 
Query,
+  StringRef Category = StringRef()) const;
+
 protected:
   // Initialize SanitizerSections.
   void createSanitizerSections();
 
   struct SanitizerSection {
 SanitizerSection(SanitizerMask SM, SectionEntries &E)
-: Mask(SM), Entries(E){};
+: Mask(SM), Entries(E) {};
 
 SanitizerMask Mask;
 SectionEntries &Entries;
diff --git a/clang/lib/Basic/NoSanitizeList.cpp 
b/clang/lib/Basic/NoSanitizeList.cpp
index e7e63c1f419e6..811480f914ec5 100644
--- a/clang/lib/Basic/NoSanitizeList.cpp
+++ b/clang/lib/Basic/NoSanitizeList.cpp
@@ -44,6 +44,13 @@ bool NoSanitizeList::containsFunction(SanitizerMask Mask,
 
 bool NoSanitizeList::containsFile(SanitizerMask Mask, StringRef FileName,
   StringRef Category) const {
+  unsigned nosanline = SSCL->inSectionBlame(Mask, "src", FileName, Category);
+  unsigned sanline = SSCL->inSectionBlame(Mask, "src", FileName, "sanitize");
+  // If we have two cases such as `src:a.cpp=sanitize` and `src:a.cpp`, the
+  // current entry override the previous entry.
+  if (nosanline > 0 && sanline > 0) {
+return nosanline > sanline;
+  }
   return SSCL->inSection(Mask, "src", FileName, Category);
 }
 
diff --git a/clang/lib/Basic/SanitizerSpecialCaseList.cpp 
b/clang/lib/Basic/SanitizerSpecialCaseList.cpp
index 2dbf04c6ede97..7da36f3801453 100644
--- a/clang/lib/Basic/SanitizerSpecialCaseList.cpp
+++ b/clang/lib/Basic/SanitizerSpecialCaseList.cpp
@@ -63,3 +63,19 @@ bool SanitizerSpecialCaseList::inSection(SanitizerMask Mask, 
StringRef Prefix,
 
   return false;
 }
+
+unsigned SanitizerSpecialCaseList::inSectionBlame(SanitizerMask Mask,
+  StringRef Prefix,
+  StringRef Query,
+  StringRef Category) const {
+  for (auto &S : SanitizerSections) {
+if (S.Mask & Mask) {
+  unsigned lineNum =
+  SpecialCaseList::inSectionBlame(S.Entries, Prefix, Query, Category);
+  if (lineNum > 0) {
+return lineNum;
+  }
+}
+  }
+  return 0;
+}
diff --git a/clang/test/CodeGen/ubsan-src-ignorelist-category.test 
b/clang/test/CodeGen/ubsan-src-ignorelist-category.test
new file mode 100644
index 0..e0efd65df8652
--- /dev/null
+++ b/clang/test/CodeGen/ubsan-src-ignorelist-category.test
@@ -0,0 +1,37 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow 
-fsanitize-ignorelist=%t/src.ignorelist -emit-llvm %t/test1.c -o - | FileCheck 
%s -check-prefix=CHECK-ALLOWLIST
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow 
-fsanitize-ignorelist=%t/src.ignorelist -emit-llvm %t/test2.c -o - | FileCheck 
%s -check-prefix=CHECK-IGNORELIST
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow 
-fsanitize-ignorelist=%t/src.ignorelist.contradict1 -emit-llvm %t/test1.c -o - 
| FileCheck %s -check-prefix=CHECK-ALLOWLISTOVERIDE1
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow 
-fsanitize-ignorelist=%t/src.ignorelist.contradict2 -emit-llvm %t/test1.c -o - 
| FileCheck %s -check-prefix=CHECK-ALLOWLISTOVERIDE2
+
+
+// Verify ubsan only emits checks for files in the allowlist
+
+//--- src.ignorelist
+src:*
+src:*/test1.c=sanitize
+
+//--- src.ignorelist.contradict1
+src:*

[clang] Add sycl_external attribute (PR #140282)

2025-05-26 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff HEAD~1 HEAD --extensions h,cpp -- 
clang/test/SemaSYCL/sycl-external-attribute.cpp 
clang/include/clang/Sema/SemaSYCL.h clang/lib/AST/ASTContext.cpp 
clang/lib/Sema/SemaDeclAttr.cpp clang/lib/Sema/SemaSYCL.cpp 
clang/test/CodeGenSYCL/kernel-caller-entry-point.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index a17df019a..9076c8ced 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -12907,8 +12907,8 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) {
   if (D->hasAttr())
 return false;
 
-  if (LangOpts.SYCLIsDevice &&
-   (!D->hasAttr() || 
!D->hasAttr()))
+  if (LangOpts.SYCLIsDevice && (!D->hasAttr() ||
+!D->hasAttr()))
 return false;
 
   // Aliases and used decls are required.

``




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


[clang] Add sycl_external attribute (PR #140282)

2025-05-26 Thread via cfe-commits

https://github.com/schittir updated 
https://github.com/llvm/llvm-project/pull/140282

>From abdbf8905d324f9b935b34bbc97c508ede5ac028 Mon Sep 17 00:00:00 2001
From: "Chittireddy, Sindhu" 
Date: Fri, 16 May 2025 08:51:06 -0700
Subject: [PATCH 1/3] Add sycl_external attribute

---
 clang/include/clang/Basic/Attr.td | 20 ++-
 clang/include/clang/Basic/AttrDocs.td | 11 
 .../clang/Basic/DiagnosticSemaKinds.td|  5 ++
 clang/include/clang/Sema/SemaSYCL.h   |  1 +
 clang/lib/AST/ASTContext.cpp  |  7 +++
 clang/lib/Sema/SemaDeclAttr.cpp   |  3 ++
 clang/lib/Sema/SemaSYCL.cpp   | 11 
 .../test/SemaSYCL/sycl-external-attribute.cpp | 52 +++
 8 files changed, 109 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaSYCL/sycl-external-attribute.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index ccd13a4cca4dd..1c13d0eb23f3b 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -143,6 +143,7 @@ def SharedVar : SubsetSubjecthasGlobalStorage()}], "global variables">;
 
+
 def ExternalGlobalVar : SubsetSubjecthasGlobalStorage() &&
S->getStorageClass()!=StorageClass::SC_Static &&
@@ -408,10 +409,14 @@ class SubjectList subjects, SubjectDiag 
diag = WarnDiag,
   string CustomDiag = customDiag;
 }
 
-class LangOpt {
+class LangOpt {
   // The language option to test; ignored when custom code is supplied.
   string Name = name;
 
+  // If set to 1, the attribute is accepted but is silently ignored. This is
+  // useful in multi-compilation situations like SYCL.
+  bit SilentlyIgnore = silentlyIgnore;
+
   // A custom predicate, written as an expression evaluated in a context with
   // "LangOpts" bound.
   code CustomCode = customCode;
@@ -422,6 +427,7 @@ def CUDA : LangOpt<"CUDA">;
 def HIP : LangOpt<"HIP">;
 def SYCLHost : LangOpt<"SYCLIsHost">;
 def SYCLDevice : LangOpt<"SYCLIsDevice">;
+def SilentlyIgnoreSYCLHost : LangOpt<"SYCLIsHost", "", 1>;
 def COnly : LangOpt<"", "!LangOpts.CPlusPlus">;
 def CPlusPlus : LangOpt<"CPlusPlus">;
 def OpenCL : LangOpt<"OpenCL">;
@@ -1545,6 +1551,18 @@ def SYCLKernel : InheritableAttr {
   let Documentation = [SYCLKernelDocs];
 }
 
+def GlobalStorageNonLocalVar : SubsetSubjecthasGlobalStorage() &&
+   !S->isLocalVarDeclOrParm()}],
+ "global variables">;
+
+def SYCLExternal : InheritableAttr {
+  let Spellings = [GNU<"sycl_external">];
+  let Subjects = SubjectList<[Function, GlobalStorageNonLocalVar]>;
+  let LangOpts = [SYCLDevice, SilentlyIgnoreSYCLHost];
+  let Documentation = [SYCLExternalDocs];
+}
+
 def SYCLKernelEntryPoint : InheritableAttr {
   let Spellings = [Clang<"sycl_kernel_entry_point">];
   let Args = [
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 5fb5f16680b41..2eef46a1348f3 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -472,6 +472,17 @@ The SYCL kernel in the previous code sample meets these 
expectations.
   }];
 }
 
+def SYCLExternalDocs : Documentation {
+  let Category = DocCatFunction;
+  let Heading = "sycl_external";
+  let Content = [{
+The ``sycl_external`` attribute (or the ``SYCL_EXTERNAL`` macro) can only be 
applied to
+functions, and indicates that the function must be treated as a device 
function and
+must be emitted even if it has no direct uses from other device functions.
+All ``sycl_external`` function callees implicitly inherit this attribute.
+  }];
+}
+
 def SYCLKernelEntryPointDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 3efe9593b8633..9228d388bc10b 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12746,6 +12746,11 @@ def err_sycl_special_type_num_init_method : Error<
   "types with 'sycl_special_class' attribute must have one and only one 
'__init' "
   "method defined">;
 
+//SYCL external attribute diagnostics
+def err_sycl_attribute_internal_decl
+: Error<"%0 attribute cannot be applied to a %select{function|variable}1"
+" without external linkage">;
+
 // SYCL kernel entry point diagnostics
 def err_sycl_entry_point_invalid : Error<
   "'sycl_kernel_entry_point' attribute cannot be applied to a"
diff --git a/clang/include/clang/Sema/SemaSYCL.h 
b/clang/include/clang/Sema/SemaSYCL.h
index b47b2f155ef93..099cc56b0ef92 100644
--- a/clang/include/clang/Sema/SemaSYCL.h
+++ b/clang/include/clang/Sema/SemaSYCL.h
@@ -62,6 +62,7 @@ class SemaSYCL : public SemaBase {
ParsedType ParsedTy);
 
   void handleKernelAttr(Decl *D, const ParsedAttr &AL);
+  void handleSY

[clang] 0259541 - [HLSL][RootSignature] Add parsing infastructure for StaticSampler (#140180)

2025-05-26 Thread via cfe-commits

Author: Finn Plummer
Date: 2025-05-26T18:40:59-07:00
New Revision: 02595417cef525cf1eeeb66e4719a3f9e9dc88b0

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

LOG: [HLSL][RootSignature] Add parsing infastructure for StaticSampler (#140180)

- define StaticSampler in-memory representation
- implement the infastructure for parsing parameters of StaticSampler
- define and implement parsing of the `s` reg to demonstrate
functionality
- add unit tests

First part of https://github.com/llvm/llvm-project/issues/126574

Added: 


Modified: 
clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def
clang/include/clang/Parse/ParseHLSLRootSignature.h
clang/lib/Parse/ParseHLSLRootSignature.cpp
clang/unittests/Lex/LexHLSLRootSignatureTest.cpp
clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp
llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h

Removed: 




diff  --git a/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def 
b/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def
index c6f7f8928bc91..ddebe82987197 100644
--- a/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def
+++ b/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def
@@ -80,6 +80,7 @@ KEYWORD(RootSignature) // used only for diagnostic messaging
 KEYWORD(RootFlags)
 KEYWORD(DescriptorTable)
 KEYWORD(RootConstants)
+KEYWORD(StaticSampler)
 
 // RootConstants Keywords:
 KEYWORD(num32BitConstants)

diff  --git a/clang/include/clang/Parse/ParseHLSLRootSignature.h 
b/clang/include/clang/Parse/ParseHLSLRootSignature.h
index 3754b4a7b595f..da17388a2aea5 100644
--- a/clang/include/clang/Parse/ParseHLSLRootSignature.h
+++ b/clang/include/clang/Parse/ParseHLSLRootSignature.h
@@ -77,6 +77,7 @@ class RootSignatureParser {
   std::optional parseDescriptorTable();
   std::optional
   parseDescriptorTableClause();
+  std::optional parseStaticSampler();
 
   /// Parameter arguments (eg. `bReg`, `space`, ...) can be specified in any
   /// order and only exactly once. The following methods define a
@@ -108,6 +109,11 @@ class RootSignatureParser {
   std::optional
   parseDescriptorTableClauseParams(RootSignatureToken::Kind RegType);
 
+  struct ParsedStaticSamplerParams {
+std::optional Reg;
+  };
+  std::optional parseStaticSamplerParams();
+
   // Common parsing methods
   std::optional parseUIntParam();
   std::optional parseRegister();

diff  --git a/clang/lib/Parse/ParseHLSLRootSignature.cpp 
b/clang/lib/Parse/ParseHLSLRootSignature.cpp
index 3d793fe5b84ad..a37505e360fc0 100644
--- a/clang/lib/Parse/ParseHLSLRootSignature.cpp
+++ b/clang/lib/Parse/ParseHLSLRootSignature.cpp
@@ -53,6 +53,13 @@ bool RootSignatureParser::parse() {
 return true;
   Elements.push_back(*Descriptor);
 }
+
+if (tryConsumeExpectedToken(TokenKind::kw_StaticSampler)) {
+  auto Sampler = parseStaticSampler();
+  if (!Sampler.has_value())
+return true;
+  Elements.push_back(*Sampler);
+}
   } while (tryConsumeExpectedToken(TokenKind::pu_comma));
 
   return consumeExpectedToken(TokenKind::end_of_stream,
@@ -346,6 +353,37 @@ RootSignatureParser::parseDescriptorTableClause() {
   return Clause;
 }
 
+std::optional RootSignatureParser::parseStaticSampler() {
+  assert(CurToken.TokKind == TokenKind::kw_StaticSampler &&
+ "Expects to only be invoked starting at given keyword");
+
+  if (consumeExpectedToken(TokenKind::pu_l_paren, diag::err_expected_after,
+   CurToken.TokKind))
+return std::nullopt;
+
+  StaticSampler Sampler;
+
+  auto Params = parseStaticSamplerParams();
+  if (!Params.has_value())
+return std::nullopt;
+
+  // Check mandatory parameters were provided
+  if (!Params->Reg.has_value()) {
+getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_missing_param)
+<< TokenKind::sReg;
+return std::nullopt;
+  }
+
+  Sampler.Reg = Params->Reg.value();
+
+  if (consumeExpectedToken(TokenKind::pu_r_paren,
+   diag::err_hlsl_unexpected_end_of_params,
+   /*param of=*/TokenKind::kw_StaticSampler))
+return std::nullopt;
+
+  return Sampler;
+}
+
 // Parameter arguments (eg. `bReg`, `space`, ...) can be specified in any
 // order and only exactly once. The following methods will parse through as
 // many arguments as possible reporting an error if a duplicate is seen.
@@ -604,6 +642,30 @@ 
RootSignatureParser::parseDescriptorTableClauseParams(TokenKind RegType) {
   return Params;
 }
 
+std::optional
+RootSignatureParser::parseStaticSamplerParams() {
+  assert(CurToken.TokKind == TokenKind::pu_l_paren &&
+ "Expects to only be invoked starting at given token");
+
+  ParsedStaticSamplerParams Params;
+  do {
+// `s` POS_INT
+if (tryConsumeExpectedToken(TokenKind::sR

[clang] [Clang][Driver] Override complex number calculation method by -fno-fa… (PR #132680)

2025-05-26 Thread via cfe-commits

s-watanabe314 wrote:

Thank you for confirming.

@MaskRay, do you have any comments regarding the handling of warning messages?

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


[clang] Thread Safety Analysis: Support reentrant capabilities (PR #137133)

2025-05-26 Thread Aaron Puchert via cfe-commits


@@ -271,26 +271,32 @@ class CFGWalker {
 // translateAttrExpr needs it, but that should be moved too.
 class CapabilityExpr {
 private:
-  /// The capability expression and whether it's negated.
-  llvm::PointerIntPair CapExpr;
+  /// The capability expression and flags.
+  llvm::PointerIntPair CapExpr;
 
   /// The kind of capability as specified by @ref CapabilityAttr::getName.
   StringRef CapKind;
 
 public:
-  CapabilityExpr() : CapExpr(nullptr, false) {}
-  CapabilityExpr(const til::SExpr *E, StringRef Kind, bool Neg)
-  : CapExpr(E, Neg), CapKind(Kind) {}
+  static constexpr unsigned FlagNegative = 1u << 0;
+  static constexpr unsigned FlagReentrant = 1u << 1;

aaronpuchert wrote:

While I see your point, this is all a bit vague. The purpose of negative 
capabilities is 
[documented](https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#negative) as 
helping to prevent double locking, which is not an issue for reentrant mutexes.

> I've been on the receiving end of such forced restrictions, and it's rather 
> annoying

The other side of the coin is that it is very hard to make the analysis more 
strict after we've released a feature, while making it more permissive is not a 
problem. Having done a few breaking changes myself, it's something that I'd 
like to avoid as much as possible.

That's why I tend to err on the side of making the analysis as strict as it can 
be while still being useful, and if that causes too much friction relax it 
later.

In this case, the restriction doesn't seem arbitrary at all. The combination 
simply doesn't make sense by the documented purpose of negative capabilities.

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


[clang] [ClangTool] Use CC1Option flag resource-dir in injectResourceDir (PR #140870)

2025-05-26 Thread Wenju He via cfe-commits

https://github.com/wenju-he updated 
https://github.com/llvm/llvm-project/pull/140870

>From f5e675f17ea737b0668e626f34d013153368425e Mon Sep 17 00:00:00 2001
From: Wenju He 
Date: Wed, 21 May 2025 02:08:34 -0700
Subject: [PATCH 1/3] [ClangTool] Use CC1Option flag resource-dir in
 injectResourceDir

This PR fixes ClangTool error in -cc1 mode:
error: unknown argument: '-resource-dir=
---
 clang/lib/Tooling/Tooling.cpp   |  8 +---
 clang/unittests/Tooling/ToolingTest.cpp | 19 +++
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp
index 3c72f52040142..87a984672662b 100644
--- a/clang/lib/Tooling/Tooling.cpp
+++ b/clang/lib/Tooling/Tooling.cpp
@@ -510,9 +510,11 @@ static void injectResourceDir(CommandLineArguments &Args, 
const char *Argv0,
   return;
 
   // If there's no override in place add our resource dir.
-  Args = getInsertArgumentAdjuster(
-  ("-resource-dir=" + CompilerInvocation::GetResourcesPath(Argv0, 
MainAddr))
-  .c_str())(Args, "");
+  CommandLineArguments Extra = {
+  "-resource-dir", CompilerInvocation::GetResourcesPath(Argv0, MainAddr)};
+
+  Args =
+  getInsertArgumentAdjuster(Extra, ArgumentInsertPosition::END)(Args, "");
 }
 
 int ClangTool::run(ToolAction *Action) {
diff --git a/clang/unittests/Tooling/ToolingTest.cpp 
b/clang/unittests/Tooling/ToolingTest.cpp
index 8cdfffb54390e..07104ccf9835f 100644
--- a/clang/unittests/Tooling/ToolingTest.cpp
+++ b/clang/unittests/Tooling/ToolingTest.cpp
@@ -771,6 +771,25 @@ TEST(ClangToolTest, BaseVirtualFileSystemUsage) {
   EXPECT_EQ(0, Tool.run(Action.get()));
 }
 
+// Check -cc1 command doesn't crash.
+TEST(ClangToolTest, CC1Arg) {
+  FixedCompilationDatabase Compilations("/", {"-cc1"});
+  llvm::IntrusiveRefCntPtr OverlayFileSystem(
+  new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem()));
+  llvm::IntrusiveRefCntPtr InMemoryFileSystem(
+  new llvm::vfs::InMemoryFileSystem);
+  OverlayFileSystem->pushOverlay(InMemoryFileSystem);
+
+  InMemoryFileSystem->addFile(
+  "a.cpp", 0, llvm::MemoryBuffer::getMemBuffer("int main() {}"));
+
+  ClangTool Tool(Compilations, std::vector(1, "a.cpp"),
+ std::make_shared(), 
OverlayFileSystem);
+  std::unique_ptr Action(
+  newFrontendActionFactory());
+  EXPECT_EQ(0, Tool.run(Action.get()));
+}
+
 // Check getClangStripDependencyFileAdjuster doesn't strip args after -MD/-MMD.
 TEST(ClangToolTest, StripDependencyFileAdjuster) {
   FixedCompilationDatabase Compilations("/", {"-MD", "-c", "-MMD", "-w"});

>From 9d8ce5cf034a9ff7bf427fb76126c1f7b1af300c Mon Sep 17 00:00:00 2001
From: Wenju He 
Date: Wed, 21 May 2025 02:12:23 -0700
Subject: [PATCH 2/3] update comment

---
 clang/unittests/Tooling/ToolingTest.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/unittests/Tooling/ToolingTest.cpp 
b/clang/unittests/Tooling/ToolingTest.cpp
index 07104ccf9835f..9969656b00956 100644
--- a/clang/unittests/Tooling/ToolingTest.cpp
+++ b/clang/unittests/Tooling/ToolingTest.cpp
@@ -771,7 +771,7 @@ TEST(ClangToolTest, BaseVirtualFileSystemUsage) {
   EXPECT_EQ(0, Tool.run(Action.get()));
 }
 
-// Check -cc1 command doesn't crash.
+// Check -cc1 command doesn't fail.
 TEST(ClangToolTest, CC1Arg) {
   FixedCompilationDatabase Compilations("/", {"-cc1"});
   llvm::IntrusiveRefCntPtr OverlayFileSystem(

>From 73377dd0d87c6b03397d461377f88068378c23bd Mon Sep 17 00:00:00 2001
From: Wenju He 
Date: Mon, 26 May 2025 16:11:35 -0700
Subject: [PATCH 3/3] add CC1Option to resource_dir_EQ

---
 clang/include/clang/Driver/Options.td | 2 +-
 clang/lib/Tooling/Tooling.cpp | 8 +++-
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 9a4253113488d..e4ac2ddc93073 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5897,7 +5897,7 @@ def resource_dir : Separate<["-"], "resource-dir">,
   HelpText<"The directory which holds the compiler resource files">,
   MarshallingInfoString>;
 def resource_dir_EQ : Joined<["-"], "resource-dir=">, Flags<[NoXarchOption]>,
-  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>,
+  Visibility<[ClangOption, CC1Option, CLOption, DXCOption, FlangOption]>,
   Alias;
 def rpath : Separate<["-"], "rpath">, Flags<[LinkerInput]>, Group,
   Visibility<[ClangOption, FlangOption]>;
diff --git a/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp
index 87a984672662b..3c72f52040142 100644
--- a/clang/lib/Tooling/Tooling.cpp
+++ b/clang/lib/Tooling/Tooling.cpp
@@ -510,11 +510,9 @@ static void injectResourceDir(CommandLineArguments &Args, 
const char *Argv0,
   return;
 
   // If there's no override in place add our resource dir.
-  CommandLineArguments Extra = {
-  "-resource-dir", CompilerInvocation::GetResourcesPath(Argv0, MainAddr)};
-
-  Args =
- 

[clang] [Clang] Add resource_dir_EQ flag to CC1Option group (PR #140870)

2025-05-26 Thread Wenju He via cfe-commits

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


[clang] [Clang] Add resource_dir_EQ flag to CC1Option group (PR #140870)

2025-05-26 Thread Wenju He via cfe-commits

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


[clang] [Clang] Add resource_dir_EQ flag to CC1Option group (PR #140870)

2025-05-26 Thread Wenju He via cfe-commits

wenju-he wrote:

> do we know why 
> https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Driver/Options.td#L5894-L5901
>  doesn't declare _EQ version for cc1?

Git history shows the earliest commit 
https://github.com/llvm/llvm-project/commit/f3e624ca73b007552554b31358f4abde9eb2d3b7
 already have the difference. I don't see obvious reason why resource_dir_EQ 
should not be cc1 option.

> i think instead of working around this in various places, we should unify the 
> two if possible.

done, thanks for the suggestion.

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


[clang] [llvm] [UBSan] Implement src:*=sanitize for UBSan (PR #140529)

2025-05-26 Thread Qinkun Bao via cfe-commits

https://github.com/qinkunbao updated 
https://github.com/llvm/llvm-project/pull/140529

>From b83755d2aa0c5417ab8f359aa842449213437a7a Mon Sep 17 00:00:00 2001
From: Qinkun Bao 
Date: Mon, 19 May 2025 11:14:01 +
Subject: [PATCH 01/16] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20?=
 =?UTF-8?q?initial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.6
---
 .../clang/Basic/SanitizerSpecialCaseList.h|  7 +++-
 clang/lib/Basic/NoSanitizeList.cpp|  7 
 clang/lib/Basic/SanitizerSpecialCaseList.cpp  | 16 
 .../ubsan-src-ignorelist-category.test| 37 +++
 4 files changed, 66 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGen/ubsan-src-ignorelist-category.test

diff --git a/clang/include/clang/Basic/SanitizerSpecialCaseList.h 
b/clang/include/clang/Basic/SanitizerSpecialCaseList.h
index d024b7dfc2e85..25d518e7128cf 100644
--- a/clang/include/clang/Basic/SanitizerSpecialCaseList.h
+++ b/clang/include/clang/Basic/SanitizerSpecialCaseList.h
@@ -43,13 +43,18 @@ class SanitizerSpecialCaseList : public 
llvm::SpecialCaseList {
   bool inSection(SanitizerMask Mask, StringRef Prefix, StringRef Query,
  StringRef Category = StringRef()) const;
 
+  // Query ignorelisted entries if any bit in Mask matches the entry's section.
+  // Return 0 if not found. If found, return the line number (starts with 1).
+  unsigned inSectionBlame(SanitizerMask Mask, StringRef Prefix, StringRef 
Query,
+  StringRef Category = StringRef()) const;
+
 protected:
   // Initialize SanitizerSections.
   void createSanitizerSections();
 
   struct SanitizerSection {
 SanitizerSection(SanitizerMask SM, SectionEntries &E)
-: Mask(SM), Entries(E){};
+: Mask(SM), Entries(E) {};
 
 SanitizerMask Mask;
 SectionEntries &Entries;
diff --git a/clang/lib/Basic/NoSanitizeList.cpp 
b/clang/lib/Basic/NoSanitizeList.cpp
index e7e63c1f419e6..811480f914ec5 100644
--- a/clang/lib/Basic/NoSanitizeList.cpp
+++ b/clang/lib/Basic/NoSanitizeList.cpp
@@ -44,6 +44,13 @@ bool NoSanitizeList::containsFunction(SanitizerMask Mask,
 
 bool NoSanitizeList::containsFile(SanitizerMask Mask, StringRef FileName,
   StringRef Category) const {
+  unsigned nosanline = SSCL->inSectionBlame(Mask, "src", FileName, Category);
+  unsigned sanline = SSCL->inSectionBlame(Mask, "src", FileName, "sanitize");
+  // If we have two cases such as `src:a.cpp=sanitize` and `src:a.cpp`, the
+  // current entry override the previous entry.
+  if (nosanline > 0 && sanline > 0) {
+return nosanline > sanline;
+  }
   return SSCL->inSection(Mask, "src", FileName, Category);
 }
 
diff --git a/clang/lib/Basic/SanitizerSpecialCaseList.cpp 
b/clang/lib/Basic/SanitizerSpecialCaseList.cpp
index 2dbf04c6ede97..7da36f3801453 100644
--- a/clang/lib/Basic/SanitizerSpecialCaseList.cpp
+++ b/clang/lib/Basic/SanitizerSpecialCaseList.cpp
@@ -63,3 +63,19 @@ bool SanitizerSpecialCaseList::inSection(SanitizerMask Mask, 
StringRef Prefix,
 
   return false;
 }
+
+unsigned SanitizerSpecialCaseList::inSectionBlame(SanitizerMask Mask,
+  StringRef Prefix,
+  StringRef Query,
+  StringRef Category) const {
+  for (auto &S : SanitizerSections) {
+if (S.Mask & Mask) {
+  unsigned lineNum =
+  SpecialCaseList::inSectionBlame(S.Entries, Prefix, Query, Category);
+  if (lineNum > 0) {
+return lineNum;
+  }
+}
+  }
+  return 0;
+}
diff --git a/clang/test/CodeGen/ubsan-src-ignorelist-category.test 
b/clang/test/CodeGen/ubsan-src-ignorelist-category.test
new file mode 100644
index 0..e0efd65df8652
--- /dev/null
+++ b/clang/test/CodeGen/ubsan-src-ignorelist-category.test
@@ -0,0 +1,37 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow 
-fsanitize-ignorelist=%t/src.ignorelist -emit-llvm %t/test1.c -o - | FileCheck 
%s -check-prefix=CHECK-ALLOWLIST
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow 
-fsanitize-ignorelist=%t/src.ignorelist -emit-llvm %t/test2.c -o - | FileCheck 
%s -check-prefix=CHECK-IGNORELIST
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow 
-fsanitize-ignorelist=%t/src.ignorelist.contradict1 -emit-llvm %t/test1.c -o - 
| FileCheck %s -check-prefix=CHECK-ALLOWLISTOVERIDE1
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow 
-fsanitize-ignorelist=%t/src.ignorelist.contradict2 -emit-llvm %t/test1.c -o - 
| FileCheck %s -check-prefix=CHECK-ALLOWLISTOVERIDE2
+
+
+// Verify ubsan only emits checks for files in the allowlist
+
+//--- src.ignorelist
+src:*
+src:*/test1.c=sanitize
+
+//--- src.ignorelist.contradict1
+src:*

[clang] [llvm] [HLSL][RootSignature] Add parsing infastructure for StaticSampler (PR #140180)

2025-05-26 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`clang-riscv-rva23-evl-vec-2stage` running on 
`rise-clang-riscv-rva23-evl-vec-2stage` while building `clang,llvm` at step 4 
"annotate".

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


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

```
Step 4 (annotate) failure: 
'../llvm-zorg/zorg/buildbot/builders/annotated/rise-riscv-build.sh --jobs=16' 
(failure)
...
PASS: lit :: test-data.py (81373 of 84500)
PASS: lit :: unit/TestRunner.py (81374 of 84500)
PASS: lit :: shtest-format.py (81375 of 84500)
PASS: LLVM-Unit :: Support/./SupportTests/10/48 (81376 of 84500)
PASS: lit :: test-output-micro-resultdb.py (81377 of 84500)
PASS: lit :: unittest-adaptor.py (81378 of 84500)
PASS: lit :: test-output-micro.py (81379 of 84500)
PASS: lit :: test-output.py (81380 of 84500)
PASS: LLVM :: tools/llvm-reduce/reduce-distinct-metadata.ll (81381 of 84500)
PASS: lit :: show-result-codes.py (81382 of 84500)
FAIL: lit :: timeout-hang.py (81383 of 84500)
 TEST 'lit :: timeout-hang.py' FAILED 
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 13
not env -u FILECHECK_OPTS "/usr/bin/python3" 
/home/buildbot-worker/bbroot/clang-riscv-rva23-evl-vec-2stage/llvm/llvm/utils/lit/lit.py
 -j1 --order=lexical Inputs/timeout-hang/run-nonexistent.txt  --timeout=1 
--param external=0 | "/usr/bin/python3" 
/home/buildbot-worker/bbroot/clang-riscv-rva23-evl-vec-2stage/stage2/utils/lit/tests/timeout-hang.py
 1
# executed command: not env -u FILECHECK_OPTS /usr/bin/python3 
/home/buildbot-worker/bbroot/clang-riscv-rva23-evl-vec-2stage/llvm/llvm/utils/lit/lit.py
 -j1 --order=lexical Inputs/timeout-hang/run-nonexistent.txt --timeout=1 
--param external=0
# .---command stderr
# | lit.py: 
/home/buildbot-worker/bbroot/clang-riscv-rva23-evl-vec-2stage/llvm/llvm/utils/lit/lit/main.py:72:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 1 seconds was requested on the command line. Forcing 
timeout to be 1 seconds.
# `-
# executed command: /usr/bin/python3 
/home/buildbot-worker/bbroot/clang-riscv-rva23-evl-vec-2stage/stage2/utils/lit/tests/timeout-hang.py
 1
# .---command stdout
# | Testing took as long or longer than timeout
# `-
# error: command failed with exit status: 1

--


PASS: lld :: COFF/alias-implib.s (81384 of 84500)
PASS: lld :: COFF/ar-comdat.test (81385 of 84500)
PASS: lld :: COFF/arm-thumb-branch20-error.s (81386 of 84500)
PASS: lld :: COFF/arm-thumb-thunks-multipass.s (81387 of 84500)
PASS: lld :: COFF/arm64-localimport-align.s (81388 of 84500)
PASS: lld :: COFF/allow-unknown-debug-info.test (81389 of 84500)
PASS: lld :: COFF/arm64-delayimport.yaml (81390 of 84500)
PASS: lld :: COFF/arm-thumb-thunks.s (81391 of 84500)
PASS: lld :: COFF/arm64-import2.test (81392 of 84500)
PASS: lld :: COFF/alternatename.test (81393 of 84500)
PASS: lld :: COFF/arm-thumb-thunks-pdb.s (81394 of 84500)
PASS: lld :: COFF/arm64-magic.yaml (81395 of 84500)
PASS: lld :: COFF/arm64-dynamicbase.s (81396 of 84500)
PASS: lld :: COFF/align.s (81397 of 84500)
PASS: lit :: xunit-output-report-failures-only.py (81398 of 84500)
PASS: lld :: COFF/arm64-relocs-imports.test (81399 of 84500)
PASS: lld :: COFF/arm64-thunks.s (81400 of 84500)
PASS: lit :: xunit-output.py (81401 of 84500)
Step 11 (llvm-project check-all) failure: llvm-project check-all (failure)
...
PASS: lit :: test-data.py (81373 of 84500)
PASS: lit :: unit/TestRunner.py (81374 of 84500)
PASS: lit :: shtest-format.py (81375 of 84500)
PASS: LLVM-Unit :: Support/./SupportTests/10/48 (81376 of 84500)
PASS: lit :: test-output-micro-resultdb.py (81377 of 84500)
PASS: lit :: unittest-adaptor.py (81378 of 84500)
PASS: lit :: test-output-micro.py (81379 of 84500)
PASS: lit :: test-output.py (81380 of 84500)
PASS: LLVM :: tools/llvm-reduce/reduce-distinct-metadata.ll (81381 of 84500)
PASS: lit :: show-result-codes.py (81382 of 84500)
FAIL: lit :: timeout-hang.py (81383 of 84500)
 TEST 'lit :: timeout-hang.py' FAILED 
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 13
not env -u FILECHECK_OPTS "/usr/bin/python3" 
/home/buildbot-worker/bbroot/clang-riscv-rva23-evl-vec-2stage/llvm/llvm/utils/lit/lit.py
 -j1 --order=lexical Inputs/timeout-hang/run-nonexistent.txt  --timeout=1 
--param external=0 | "/usr/bin/python3" 
/home/buildbot-worker/bbroot/clang-riscv-rva23-evl-vec-2stage/stage2/utils/lit/tests/timeout-hang.py
 1
# executed command: not env -u FILECHECK_OPTS /usr/bin/python3 
/home/buildbot-worker/bbroot/clang-riscv-rva23-evl-vec-2stage/llvm/llvm/utils/lit/lit.py
 -j1 --order=lexical Inputs/timeout-hang/run-nonexistent.txt --timeout=1 
--param external=0
# .---command stderr
# | lit.py: 
/home/buildbot-worker/bbroot/clang-riscv-rva23-e

[clang] [Modules] Don't fail when an unused textual header is missing. (PR #138227)

2025-05-26 Thread Volodymyr Sapsai via cfe-commits

vsapsai wrote:

Do you include proto headers directly or through the wrapper headers?

Are there any important macros in proto headers?

Do you need to abuse macros to get something out of proto headers? Kinda like 
`#define private public` but more realistic.

My initial reaction is to offer a solution by not using private headers 
(especially that it is so easily subverted by textual headers) and to rely on 
`-fmodules-embed-all-files` (which you already do). I believe you have 
constraints that make this "simple" solution not feasible. So I'm curious to 
know what about this solution doesn't work.

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


[clang] [Driver] Teach Barmetal toolchain about GCC installation (PR #121829)

2025-05-26 Thread Garvit Gupta via cfe-commits

https://github.com/quic-garvgupt updated 
https://github.com/llvm/llvm-project/pull/121829

>From 8d6d2e0f1eaa0b81613a786dbe003ddf7d0a2983 Mon Sep 17 00:00:00 2001
From: Garvit Gupta 
Date: Fri, 13 Dec 2024 05:31:56 -0800
Subject: [PATCH] [Driver] Teach Barmetal toolchain about GCC installation

This patch introduces the baretmetal toolchain object about GCC Installation.
Currently, if `--gcc-installation` ot `--gcc-install-dir` options are passed on
commandline, then sysroot will be formed from there if paths will be valid.
Otherwise, it will be fallback to as it already existed in the Baremetal
toolchaibn object. Moreover, support for adding include paths for libstd
C++ library is added as well.

Additionally, the restriction to always use integrated assembler is removed
because with valid gcc installation, gnu assembler can be invoked as well.

This patch currently adds and modifies arm related test only. The riscv specific
test will be added in the last PR when driver code related to calling of
RISCVToolchain object will be removed. Currently in this PR, there is no way to
test riscv target.

RFC:
https://discourse.llvm.org/t/merging-riscvtoolchain-and-baremetal-toolchains/75524

Change-Id: Ibaeb569cf7e2cee03c022aa9ecd1abe29d5c30d4
---
 clang/docs/Toolchain.rst  |   5 +
 .../clang/Basic/DiagnosticDriverKinds.td  |   2 +
 clang/lib/Driver/ToolChains/BareMetal.cpp | 207 +-
 clang/lib/Driver/ToolChains/BareMetal.h   |  14 +-
 .../aarch64-none-elf/include/c++/8.2.1/.keep  |   0
 .../aarch64-none-elf/lib/.keep|   0
 .../aarch64-none-elf/lib/crt0.o   |   0
 .../bin/aarch64-none-elf-ld   |   1 +
 .../lib/gcc/aarch64-none-elf/8.2.1/crtbegin.o |   0
 .../lib/gcc/aarch64-none-elf/8.2.1/crtend.o   |   0
 .../aarch64-none-elf/lib/crt0.o   |   0
 .../aarch64-none-elf/lib/crtbegin.o   |   0
 .../aarch64-none-elf/lib/crtend.o |   0
 .../bin/aarch64-none-elf-ld   |   1 +
 .../armv6m-none-eabi/include/c++/8.2.1/.keep  |   0
 .../armv6m-none-eabi/lib/.keep|   0
 .../armv6m-none-eabi/lib/crt0.o   |   0
 .../bin/armv6m-none-eabi-ld   |   1 +
 .../lib/gcc/armv6m-none-eabi/8.2.1/crtbegin.o |   0
 .../lib/gcc/armv6m-none-eabi/8.2.1/crtend.o   |   0
 .../armv6m-none-eabi/lib/crt0.o   |   0
 .../armv6m-none-eabi/lib/crtbegin.o   |   0
 .../armv6m-none-eabi/lib/crtend.o |   0
 .../bin/armv6m-none-eabi-ld   |   1 +
 clang/test/Driver/aarch64-gnutools.c  |   4 +
 clang/test/Driver/aarch64-toolchain-extra.c   |  28 +++
 clang/test/Driver/aarch64-toolchain.c |  61 ++
 clang/test/Driver/arm-gnutools.c  |   6 +
 clang/test/Driver/arm-toolchain-extra.c   |  29 +++
 clang/test/Driver/arm-toolchain.c |  62 ++
 clang/test/Driver/baremetal.cpp   |  16 ++
 clang/test/Driver/check-no-multlib-warning.c  |  10 +
 32 files changed, 386 insertions(+), 62 deletions(-)
 create mode 100644 
clang/test/Driver/Inputs/basic_aarch64_gcc_tree/aarch64-none-elf/include/c++/8.2.1/.keep
 create mode 100644 
clang/test/Driver/Inputs/basic_aarch64_gcc_tree/aarch64-none-elf/lib/.keep
 create mode 100644 
clang/test/Driver/Inputs/basic_aarch64_gcc_tree/aarch64-none-elf/lib/crt0.o
 create mode 100755 
clang/test/Driver/Inputs/basic_aarch64_gcc_tree/bin/aarch64-none-elf-ld
 create mode 100644 
clang/test/Driver/Inputs/basic_aarch64_gcc_tree/lib/gcc/aarch64-none-elf/8.2.1/crtbegin.o
 create mode 100644 
clang/test/Driver/Inputs/basic_aarch64_gcc_tree/lib/gcc/aarch64-none-elf/8.2.1/crtend.o
 create mode 100644 
clang/test/Driver/Inputs/basic_aarch64_nogcc_tree/aarch64-none-elf/lib/crt0.o
 create mode 100644 
clang/test/Driver/Inputs/basic_aarch64_nogcc_tree/aarch64-none-elf/lib/crtbegin.o
 create mode 100644 
clang/test/Driver/Inputs/basic_aarch64_nogcc_tree/aarch64-none-elf/lib/crtend.o
 create mode 100755 
clang/test/Driver/Inputs/basic_aarch64_nogcc_tree/bin/aarch64-none-elf-ld
 create mode 100644 
clang/test/Driver/Inputs/basic_arm_gcc_tree/armv6m-none-eabi/include/c++/8.2.1/.keep
 create mode 100644 
clang/test/Driver/Inputs/basic_arm_gcc_tree/armv6m-none-eabi/lib/.keep
 create mode 100644 
clang/test/Driver/Inputs/basic_arm_gcc_tree/armv6m-none-eabi/lib/crt0.o
 create mode 100755 
clang/test/Driver/Inputs/basic_arm_gcc_tree/bin/armv6m-none-eabi-ld
 create mode 100644 
clang/test/Driver/Inputs/basic_arm_gcc_tree/lib/gcc/armv6m-none-eabi/8.2.1/crtbegin.o
 create mode 100644 
clang/test/Driver/Inputs/basic_arm_gcc_tree/lib/gcc/armv6m-none-eabi/8.2.1/crtend.o
 create mode 100644 
clang/test/Driver/Inputs/basic_arm_nogcc_tree/armv6m-none-eabi/lib/crt0.o
 create mode 100644 
clang/test/Driver/Inputs/basic_arm_nogcc_tree/armv6m-none-eabi/lib/crtbegin.o
 create mode 100644 
clang/test/Driver/Inputs/basic_arm_nogcc_tree/armv6m-none-eabi/lib/crtend.o
 create mode 100755 
clang

[clang] [Driver] Teach Barmetal toolchain about GCC installation (PR #121829)

2025-05-26 Thread Garvit Gupta via cfe-commits


@@ -110,20 +110,81 @@ static std::string computeBaseSysRoot(const Driver &D, 
bool IncludeTriple) {
   return std::string(SysRootDir);
 }
 
+static bool hasGCCToolChainAlongSideClang(const Driver &D) {
+  SmallString<128> GCCDir;
+  llvm::sys::path::append(GCCDir, D.Dir, "..", D.getTargetTriple(),
+  "lib/crt0.o");
+  return llvm::sys::fs::exists(GCCDir);
+}
+
+std::string BareMetal::computeSysRoot() const {
+  if (!SysRoot.empty())
+return SysRoot;
+
+  const Driver &D = getDriver();
+  if (!D.SysRoot.empty())
+return D.SysRoot;
+
+  // Verify the GCC installation from -gcc-install-dir, --gcc-toolchain, or
+  // alongside clang. If valid, form the sysroot. Otherwise, check
+  // lib/clang-runtimes above the driver.
+  SmallString<128> SysRootDir;
+  if (GCCInstallation.isValid()) {
+StringRef LibDir = GCCInstallation.getParentLibPath();
+StringRef TripleStr = GCCInstallation.getTriple().str();
+llvm::sys::path::append(SysRootDir, LibDir, "..", TripleStr);
+  } else if (hasGCCToolChainAlongSideClang(D)) {
+// Use the triple as provided to the driver. Unlike the parsed triple
+// this has not been normalized to always contain every field.
+llvm::sys::path::append(SysRootDir, D.Dir, "..", D.getTargetTriple());
+  }
+
+  if (llvm::sys::fs::exists(SysRootDir))
+return std::string(SysRootDir);
+  return computeBaseSysRoot(D, /*IncludeTriple*/ true);
+}
+
+static void addMultilibsFilePaths(const Driver &D, const MultilibSet 
&Multilibs,
+  const Multilib &Multilib,
+  StringRef InstallPath,
+  ToolChain::path_list &Paths) {
+  if (const auto &PathsCallback = Multilibs.filePathsCallback())
+for (const auto &Path : PathsCallback(Multilib))
+  addPathIfExists(D, InstallPath + Path, Paths);
+}
+
 BareMetal::BareMetal(const Driver &D, const llvm::Triple &Triple,
  const ArgList &Args)
-: ToolChain(D, Triple, Args),
-  SysRoot(computeBaseSysRoot(D, /*IncludeTriple=*/true)) {
-  getProgramPaths().push_back(getDriver().Dir);
-
-  findMultilibs(D, Triple, Args);
-  SmallString<128> SysRoot(computeSysRoot());
-  if (!SysRoot.empty()) {
-for (const Multilib &M : getOrderedMultilibs()) {
-  SmallString<128> Dir(SysRoot);
-  llvm::sys::path::append(Dir, M.osSuffix(), "lib");
-  getFilePaths().push_back(std::string(Dir));
-  getLibraryPaths().push_back(std::string(Dir));
+: Generic_ELF(D, Triple, Args) {
+  GCCInstallation.init(Triple, Args);
+  SysRoot = computeSysRoot();
+  if (GCCInstallation.isValid()) {
+Multilibs = GCCInstallation.getMultilibs();
+SelectedMultilibs.assign({GCCInstallation.getMultilib()});
+path_list &Paths = getFilePaths();
+// Add toolchain/multilib specific file paths.
+addMultilibsFilePaths(D, Multilibs, SelectedMultilibs.back(),
+  GCCInstallation.getInstallPath(), Paths);
+getFilePaths().push_back(GCCInstallation.getInstallPath().str());
+ToolChain::path_list &PPaths = getProgramPaths();
+// Multilib cross-compiler GCC installations put ld in a triple-prefixed
+// directory off of the parent of the GCC installation.
+PPaths.push_back(Twine(GCCInstallation.getParentLibPath() + "/../" +
+   GCCInstallation.getTriple().str() + "/bin")
+ .str());
+PPaths.push_back((GCCInstallation.getParentLibPath() + "/../bin").str());
+getFilePaths().push_back(SysRoot + "/lib");
+  } else {

quic-garvgupt wrote:

> Stepping back a bit, there's a bit of the logic/use-case in computeSysRoot 
> that I don't understand. When we find a GCC ToolChain alongside clang, I 
> don't see any logic to validate it.
 
There is no code to validate it in the constructor. However, it's use was 
needed in the linker job (see `Linker::ConstructJob`). This was done to 
preserve the behavior of RISCVToolChain Object. I am not sure why it was 
decided there that the mere presence of `lib/crt0.o` file alongside clang in 
target triple prefixed directory will indicate a GCC toolchain, however in 
RISCVToolchain object, toolchain found along clang  isn't considered a valid 
GCCInstallation and the same has been implemented here to preserve that 
behavior. 
One needs to look at `hasGCCToolchain`, `computeSysRoot` and constructor in 
RISCVToolChain.cpp for the same
 
>Is the intention here to find a valid GCC installation equivalent to the 
>-gcc-install-dir or --gcc-toolchain, or something else?
 
Yes it is trying to find a  toolchain that is equivalent to `--gcc-toolchain`. 
The same is also mentioned in the comments for the function `hasGCCToolChain` 
in RISCVToolChain.cpp. You can also look at tests 
"clang/test/Driver/riscv64-toolchain-extra.c` and 
"clang/test/Driver/riscv32-toolchain-extra.c" to see how it works.
 
> The logic in this block is the same as if clang-runtimes w

[clang-tools-extra] [clang-tidy] Improve `bugprone-exception-escape`: add stacktrace of escaped exception (PR #134375)

2025-05-26 Thread Congcong Cai via cfe-commits

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


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


[clang-tools-extra] Follow style configuration in clangd when inserting missing includes (PR #140594)

2025-05-26 Thread kadir çetinkaya via cfe-commits

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


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


[clang-tools-extra] Follow style configuration in clangd when inserting missing includes (PR #140594)

2025-05-26 Thread kadir çetinkaya via cfe-commits


@@ -141,16 +143,41 @@ std::vector generateMissingIncludeDiagnostics(
  AST.getPreprocessor().getHeaderSearchInfo(), MainFile});
 
 llvm::StringRef HeaderRef{Spelling};
-bool Angled = HeaderRef.starts_with("<");
+
+bool IsAngled = false;

kadircet wrote:

we shouldn't be matching against `HeaderRef`, but instead matching against 
`ResolvedPath` and only when `SymbolWithMissingInclude.Providers.front().kind() 
== Physical`

nit:
```cpp
bool Angled = HeaderRef.starts_with("<");
if (SymbolWithMissingInclude.Providers.front().kind() == ..Physical) {
for (auto &Filter : Angled ? QuotedHeaders : AngledHeaders) {
  if (Filter(ResolvedPath)) {
Angled = !Angled;
break;
  }
}
}

std::optional Replacement = HeaderIncludes.insert(
HeaderRef.trim("\"<>"), Angled, tooling::IncludeDirective::Include);
```

[logic in the include 
inserter](https://github.com/llvm/llvm-project/blob/3033f202f6707937cd28c2473479db134993f96f/clang-tools-extra/clangd/Headers.cpp#L307)
 seem to have the same bug (we should match against paths, not spellings).

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


[clang] 17ef0fe - [clang][OpenCL] Only evaluate initializer once to check for zero init (#141474)

2025-05-26 Thread via cfe-commits

Author: Timm Baeder
Date: 2025-05-27T08:12:18+02:00
New Revision: 17ef0fe59437f107e8f1cf7edb2fe109de4e332f

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

LOG: [clang][OpenCL] Only evaluate initializer once to check for zero init 
(#141474)

Both Expr::isIntegerConstantExpr() and Expr::EvaluateKnownConstInt()
evaluate the expression. Just do it once and check the integer result.

Added: 


Modified: 
clang/lib/Sema/SemaInit.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 2f682dbc1f000..776cb022e6925 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -6410,9 +6410,9 @@ static bool TryOCLSamplerInitialization(Sema &S,
   return true;
 }
 
-static bool IsZeroInitializer(Expr *Initializer, Sema &S) {
-  return Initializer->isIntegerConstantExpr(S.getASTContext()) &&
-(Initializer->EvaluateKnownConstInt(S.getASTContext()) == 0);
+static bool IsZeroInitializer(const Expr *Init, ASTContext &Ctx) {
+  std::optional Value = Init->getIntegerConstantExpr(Ctx);
+  return Value && Value->isZero();
 }
 
 static bool TryOCLZeroOpaqueTypeInitialization(Sema &S,
@@ -6431,7 +6431,7 @@ static bool TryOCLZeroOpaqueTypeInitialization(Sema &S,
   // event should be zero.
   //
   if (DestType->isEventT() || DestType->isQueueT()) {
-if (!IsZeroInitializer(Initializer, S))
+if (!IsZeroInitializer(Initializer, S.getASTContext()))
   return false;
 
 Sequence.AddOCLZeroOpaqueTypeStep(DestType);
@@ -6447,7 +6447,7 @@ static bool TryOCLZeroOpaqueTypeInitialization(Sema &S,
 if (DestType->isOCLIntelSubgroupAVCMcePayloadType() ||
 DestType->isOCLIntelSubgroupAVCMceResultType())
   return false;
-if (!IsZeroInitializer(Initializer, S))
+if (!IsZeroInitializer(Initializer, S.getASTContext()))
   return false;
 
 Sequence.AddOCLZeroOpaqueTypeStep(DestType);



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


[clang] [llvm] [UBSan] Implement src:*=sanitize for UBSan (PR #140529)

2025-05-26 Thread Qinkun Bao via cfe-commits

https://github.com/qinkunbao updated 
https://github.com/llvm/llvm-project/pull/140529

>From b83755d2aa0c5417ab8f359aa842449213437a7a Mon Sep 17 00:00:00 2001
From: Qinkun Bao 
Date: Mon, 19 May 2025 11:14:01 +
Subject: [PATCH 01/16] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20?=
 =?UTF-8?q?initial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.6
---
 .../clang/Basic/SanitizerSpecialCaseList.h|  7 +++-
 clang/lib/Basic/NoSanitizeList.cpp|  7 
 clang/lib/Basic/SanitizerSpecialCaseList.cpp  | 16 
 .../ubsan-src-ignorelist-category.test| 37 +++
 4 files changed, 66 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGen/ubsan-src-ignorelist-category.test

diff --git a/clang/include/clang/Basic/SanitizerSpecialCaseList.h 
b/clang/include/clang/Basic/SanitizerSpecialCaseList.h
index d024b7dfc2e85..25d518e7128cf 100644
--- a/clang/include/clang/Basic/SanitizerSpecialCaseList.h
+++ b/clang/include/clang/Basic/SanitizerSpecialCaseList.h
@@ -43,13 +43,18 @@ class SanitizerSpecialCaseList : public 
llvm::SpecialCaseList {
   bool inSection(SanitizerMask Mask, StringRef Prefix, StringRef Query,
  StringRef Category = StringRef()) const;
 
+  // Query ignorelisted entries if any bit in Mask matches the entry's section.
+  // Return 0 if not found. If found, return the line number (starts with 1).
+  unsigned inSectionBlame(SanitizerMask Mask, StringRef Prefix, StringRef 
Query,
+  StringRef Category = StringRef()) const;
+
 protected:
   // Initialize SanitizerSections.
   void createSanitizerSections();
 
   struct SanitizerSection {
 SanitizerSection(SanitizerMask SM, SectionEntries &E)
-: Mask(SM), Entries(E){};
+: Mask(SM), Entries(E) {};
 
 SanitizerMask Mask;
 SectionEntries &Entries;
diff --git a/clang/lib/Basic/NoSanitizeList.cpp 
b/clang/lib/Basic/NoSanitizeList.cpp
index e7e63c1f419e6..811480f914ec5 100644
--- a/clang/lib/Basic/NoSanitizeList.cpp
+++ b/clang/lib/Basic/NoSanitizeList.cpp
@@ -44,6 +44,13 @@ bool NoSanitizeList::containsFunction(SanitizerMask Mask,
 
 bool NoSanitizeList::containsFile(SanitizerMask Mask, StringRef FileName,
   StringRef Category) const {
+  unsigned nosanline = SSCL->inSectionBlame(Mask, "src", FileName, Category);
+  unsigned sanline = SSCL->inSectionBlame(Mask, "src", FileName, "sanitize");
+  // If we have two cases such as `src:a.cpp=sanitize` and `src:a.cpp`, the
+  // current entry override the previous entry.
+  if (nosanline > 0 && sanline > 0) {
+return nosanline > sanline;
+  }
   return SSCL->inSection(Mask, "src", FileName, Category);
 }
 
diff --git a/clang/lib/Basic/SanitizerSpecialCaseList.cpp 
b/clang/lib/Basic/SanitizerSpecialCaseList.cpp
index 2dbf04c6ede97..7da36f3801453 100644
--- a/clang/lib/Basic/SanitizerSpecialCaseList.cpp
+++ b/clang/lib/Basic/SanitizerSpecialCaseList.cpp
@@ -63,3 +63,19 @@ bool SanitizerSpecialCaseList::inSection(SanitizerMask Mask, 
StringRef Prefix,
 
   return false;
 }
+
+unsigned SanitizerSpecialCaseList::inSectionBlame(SanitizerMask Mask,
+  StringRef Prefix,
+  StringRef Query,
+  StringRef Category) const {
+  for (auto &S : SanitizerSections) {
+if (S.Mask & Mask) {
+  unsigned lineNum =
+  SpecialCaseList::inSectionBlame(S.Entries, Prefix, Query, Category);
+  if (lineNum > 0) {
+return lineNum;
+  }
+}
+  }
+  return 0;
+}
diff --git a/clang/test/CodeGen/ubsan-src-ignorelist-category.test 
b/clang/test/CodeGen/ubsan-src-ignorelist-category.test
new file mode 100644
index 0..e0efd65df8652
--- /dev/null
+++ b/clang/test/CodeGen/ubsan-src-ignorelist-category.test
@@ -0,0 +1,37 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow 
-fsanitize-ignorelist=%t/src.ignorelist -emit-llvm %t/test1.c -o - | FileCheck 
%s -check-prefix=CHECK-ALLOWLIST
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow 
-fsanitize-ignorelist=%t/src.ignorelist -emit-llvm %t/test2.c -o - | FileCheck 
%s -check-prefix=CHECK-IGNORELIST
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow 
-fsanitize-ignorelist=%t/src.ignorelist.contradict1 -emit-llvm %t/test1.c -o - 
| FileCheck %s -check-prefix=CHECK-ALLOWLISTOVERIDE1
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-integer-overflow 
-fsanitize-ignorelist=%t/src.ignorelist.contradict2 -emit-llvm %t/test1.c -o - 
| FileCheck %s -check-prefix=CHECK-ALLOWLISTOVERIDE2
+
+
+// Verify ubsan only emits checks for files in the allowlist
+
+//--- src.ignorelist
+src:*
+src:*/test1.c=sanitize
+
+//--- src.ignorelist.contradict1
+src:*

[clang] [Driver][X86] Fix LIT test failure on Solaris OS + AMD64 CPU. (PR #141486)

2025-05-26 Thread Shengchen Kan via cfe-commits

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


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


[clang] [Driver] Teach Barmetal toolchain about GCC installation (PR #121829)

2025-05-26 Thread Garvit Gupta via cfe-commits


@@ -110,20 +110,81 @@ static std::string computeBaseSysRoot(const Driver &D, 
bool IncludeTriple) {
   return std::string(SysRootDir);
 }
 
+static bool hasGCCToolChainAlongSideClang(const Driver &D) {
+  SmallString<128> GCCDir;
+  llvm::sys::path::append(GCCDir, D.Dir, "..", D.getTargetTriple(),
+  "lib/crt0.o");
+  return llvm::sys::fs::exists(GCCDir);
+}
+
+std::string BareMetal::computeSysRoot() const {
+  if (!SysRoot.empty())
+return SysRoot;
+
+  const Driver &D = getDriver();
+  if (!D.SysRoot.empty())
+return D.SysRoot;
+
+  // Verify the GCC installation from -gcc-install-dir, --gcc-toolchain, or
+  // alongside clang. If valid, form the sysroot. Otherwise, check
+  // lib/clang-runtimes above the driver.
+  SmallString<128> SysRootDir;
+  if (GCCInstallation.isValid()) {
+StringRef LibDir = GCCInstallation.getParentLibPath();
+StringRef TripleStr = GCCInstallation.getTriple().str();
+llvm::sys::path::append(SysRootDir, LibDir, "..", TripleStr);
+  } else if (hasGCCToolChainAlongSideClang(D)) {
+// Use the triple as provided to the driver. Unlike the parsed triple
+// this has not been normalized to always contain every field.
+llvm::sys::path::append(SysRootDir, D.Dir, "..", D.getTargetTriple());
+  }
+
+  if (llvm::sys::fs::exists(SysRootDir))
+return std::string(SysRootDir);
+  return computeBaseSysRoot(D, /*IncludeTriple*/ true);
+}
+
+static void addMultilibsFilePaths(const Driver &D, const MultilibSet 
&Multilibs,
+  const Multilib &Multilib,
+  StringRef InstallPath,
+  ToolChain::path_list &Paths) {
+  if (const auto &PathsCallback = Multilibs.filePathsCallback())
+for (const auto &Path : PathsCallback(Multilib))
+  addPathIfExists(D, InstallPath + Path, Paths);
+}
+
 BareMetal::BareMetal(const Driver &D, const llvm::Triple &Triple,
  const ArgList &Args)
-: ToolChain(D, Triple, Args),
-  SysRoot(computeBaseSysRoot(D, /*IncludeTriple=*/true)) {
-  getProgramPaths().push_back(getDriver().Dir);
-
-  findMultilibs(D, Triple, Args);
-  SmallString<128> SysRoot(computeSysRoot());
-  if (!SysRoot.empty()) {
-for (const Multilib &M : getOrderedMultilibs()) {
-  SmallString<128> Dir(SysRoot);
-  llvm::sys::path::append(Dir, M.osSuffix(), "lib");
-  getFilePaths().push_back(std::string(Dir));
-  getLibraryPaths().push_back(std::string(Dir));
+: Generic_ELF(D, Triple, Args) {
+  GCCInstallation.init(Triple, Args);
+  SysRoot = computeSysRoot();
+  if (GCCInstallation.isValid()) {
+Multilibs = GCCInstallation.getMultilibs();
+SelectedMultilibs.assign({GCCInstallation.getMultilib()});

quic-garvgupt wrote:

Yes, I have added a warning in the latest patchset.

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


[clang] [analyzer][NFC] Introduce framework for checker families (PR #139256)

2025-05-26 Thread Donát Nagy via cfe-commits

NagyDonat wrote:

I reverted this PR to an earlier stage and added a more verbose explanation for 
the (current) requirement that classes derived from `CheckerFamily` need to 
override `getTagDescription`.

@steakhal  In addition to the other changes, I also reverted commit 
https://github.com/llvm/llvm-project/pull/139256/commits/7da3862e87c3e6e94b80e04bddbfd04848f6ce04
 where you renamed `getTagDescription` to `getDebugName`, because although I 
completely agree with that change, I think it would be nicer to merge it as a 
separate commit (because e.g. this relatively large commit would be easier to 
understand without the name change). Do you want to create the PR for it (after 
this is merged) or should I create it?

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


[clang-tools-extra] [clang-tidy] Add check for assignment or comparision operators' operand in `readability-math-missing-parentheses` (PR #141345)

2025-05-26 Thread via cfe-commits

EugeneZelenko wrote:

Please rebase from `main`. Release Notes were changed recently and there will 
be merge conflict.

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


[clang] 365dcf4 - Thread Safety Analysis: Convert CapabilityExpr::CapExpr to hold flags

2025-05-26 Thread Marco Elver via cfe-commits

Author: Marco Elver
Date: 2025-05-26T16:59:51+02:00
New Revision: 365dcf48b8aa726fb6a9ace4b37eb1f1cf121941

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

LOG: Thread Safety Analysis: Convert CapabilityExpr::CapExpr to hold flags

Rather than holding a single bool, switch it to contain flags, which is
both more descriptive and simplifies adding more flags in subsequent
changes.

NFC.

Pull Request: https://github.com/llvm/llvm-project/pull/137133

Added: 


Modified: 
clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h

Removed: 




diff  --git a/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h 
b/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
index e99c5b2466334..6e46a2d721463 100644
--- a/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
+++ b/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
@@ -271,26 +271,28 @@ class CFGWalker {
 // translateAttrExpr needs it, but that should be moved too.
 class CapabilityExpr {
 private:
-  /// The capability expression and whether it's negated.
-  llvm::PointerIntPair CapExpr;
+  static constexpr unsigned FlagNegative = 1u << 0;
+
+  /// The capability expression and flags.
+  llvm::PointerIntPair CapExpr;
 
   /// The kind of capability as specified by @ref CapabilityAttr::getName.
   StringRef CapKind;
 
 public:
-  CapabilityExpr() : CapExpr(nullptr, false) {}
+  CapabilityExpr() : CapExpr(nullptr, 0) {}
   CapabilityExpr(const til::SExpr *E, StringRef Kind, bool Neg)
-  : CapExpr(E, Neg), CapKind(Kind) {}
+  : CapExpr(E, Neg ? FlagNegative : 0), CapKind(Kind) {}
 
   // Don't allow implicitly-constructed StringRefs since we'll capture them.
   template  CapabilityExpr(const til::SExpr *, T, bool) = delete;
 
   const til::SExpr *sexpr() const { return CapExpr.getPointer(); }
   StringRef getKind() const { return CapKind; }
-  bool negative() const { return CapExpr.getInt(); }
+  bool negative() const { return CapExpr.getInt() & FlagNegative; }
 
   CapabilityExpr operator!() const {
-return CapabilityExpr(CapExpr.getPointer(), CapKind, !CapExpr.getInt());
+return CapabilityExpr(CapExpr.getPointer(), CapKind, !negative());
   }
 
   bool equals(const CapabilityExpr &other) const {



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


[clang] Thread Safety Analysis: Support reentrant capabilities (PR #137133)

2025-05-26 Thread Marco Elver via cfe-commits

https://github.com/melver updated 
https://github.com/llvm/llvm-project/pull/137133

>From b8754a894e8822c43dfce62b7d13d5169ea4a215 Mon Sep 17 00:00:00 2001
From: Marco Elver 
Date: Thu, 24 Apr 2025 09:02:08 +0200
Subject: [PATCH] Thread Safety Analysis: Support reentrant capabilities

Introduce the `reentrant_capability` attribute, which may be specified
alongside the `capability(..)` attribute to denote that the defined
capability type is reentrant. Marking a capability as reentrant means
that acquiring the same capability multiple times is safe, and does not
produce warnings on attempted re-acquisition.

The most significant changes required are plumbing to propagate if the
attribute is present to a CapabilityExpr, and then introducing a
ReentrancyCount to FactEntry that can be incremented while a fact
remains in the FactSet.
---
 clang/docs/ReleaseNotes.rst   |   1 +
 clang/docs/ThreadSafetyAnalysis.rst   |  18 +
 .../clang/Analysis/Analyses/ThreadSafety.h|   4 +-
 .../Analysis/Analyses/ThreadSafetyCommon.h|  22 +-
 clang/include/clang/Basic/Attr.td |   7 +
 .../clang/Basic/DiagnosticSemaKinds.td|   7 +-
 clang/lib/Analysis/ThreadSafety.cpp   | 133 +--
 clang/lib/Analysis/ThreadSafetyCommon.cpp |  76 ++--
 clang/lib/Sema/AnalysisBasedWarnings.cpp  |   8 +-
 clang/lib/Sema/SemaDeclAttr.cpp   |  18 +
 ...a-attribute-supported-attributes-list.test |   1 +
 clang/test/Sema/warn-thread-safety-analysis.c |  20 +
 .../test/SemaCXX/thread-safety-annotations.h  |   1 +
 .../SemaCXX/warn-thread-safety-analysis.cpp   | 364 ++
 .../SemaCXX/warn-thread-safety-parsing.cpp|  12 +
 clang/unittests/AST/ASTImporterTest.cpp   |   9 +
 16 files changed, 624 insertions(+), 77 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 75f529db7260e..780716b089e41 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -447,6 +447,7 @@ Improvements to Clang's diagnostics
   as function arguments or return value respectively. Note that
   :doc:`ThreadSafetyAnalysis` still does not perform alias analysis. The
   feature will be default-enabled with ``-Wthread-safety`` in a future release.
+- The :doc:`ThreadSafetyAnalysis` now supports reentrant capabilities.
 - Clang will now do a better job producing common nested names, when producing
   common types for ternary operator, template argument deduction and multiple 
return auto deduction.
 - The ``-Wsign-compare`` warning now treats expressions with bitwise not(~) 
and minus(-) as signed integers
diff --git a/clang/docs/ThreadSafetyAnalysis.rst 
b/clang/docs/ThreadSafetyAnalysis.rst
index 130069c5659d6..4fc7ff28e9931 100644
--- a/clang/docs/ThreadSafetyAnalysis.rst
+++ b/clang/docs/ThreadSafetyAnalysis.rst
@@ -434,6 +434,21 @@ class can be used as a capability.  The string argument 
specifies the kind of
 capability in error messages, e.g. ``"mutex"``.  See the ``Container`` example
 given above, or the ``Mutex`` class in :ref:`mutexheader`.
 
+REENTRANT_CAPABILITY
+
+
+``REENTRANT_CAPABILITY`` is an attribute on capability classes, denoting that
+they are reentrant. Marking a capability as reentrant means that acquiring the
+same capability multiple times is safe. Acquiring the same capability with
+different access privileges (exclusive vs. shared) again is not considered
+reentrant by the analysis.
+
+Note: In many cases this attribute is only required where a capability is
+acquired reentrant within the same function, such as via macros or other
+helpers. Otherwise, best practice is to avoid explicitly acquiring a capability
+multiple times within the same function, and letting the analysis produce
+warnings on double-acquisition attempts.
+
 .. _scoped_capability:
 
 SCOPED_CAPABILITY
@@ -846,6 +861,9 @@ implementation.
   #define CAPABILITY(x) \
 THREAD_ANNOTATION_ATTRIBUTE__(capability(x))
 
+  #define REENTRANT_CAPABILITY \
+THREAD_ANNOTATION_ATTRIBUTE__(reentrant_capability)
+
   #define SCOPED_CAPABILITY \
 THREAD_ANNOTATION_ATTRIBUTE__(scoped_lockable)
 
diff --git a/clang/include/clang/Analysis/Analyses/ThreadSafety.h 
b/clang/include/clang/Analysis/Analyses/ThreadSafety.h
index 65a91483562e0..9fb23212aaf97 100644
--- a/clang/include/clang/Analysis/Analyses/ThreadSafety.h
+++ b/clang/include/clang/Analysis/Analyses/ThreadSafety.h
@@ -166,10 +166,12 @@ class ThreadSafetyHandler {
   /// \param LocEndOfScope -- The location of the end of the scope where the
   ///   mutex is no longer held
   /// \param LEK -- which of the three above cases we should warn for
+  /// \param ReentrancyMismatch -- mismatching reentrancy depth
   virtual void handleMutexHeldEndOfScope(StringRef Kind, Name LockName,
  SourceLocation LocLocked,
  SourceLocation LocEndOfScope,
-   

[clang] [llvm] [NVPTX] Add pm_event intrinsics (PR #141278)

2025-05-26 Thread Durgadoss R via cfe-commits

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


[clang] [analyzer][NFC] Introduce framework for checker families (PR #139256)

2025-05-26 Thread Balazs Benics via cfe-commits
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,Balazs Benics
 ,Balazs Benics ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy 
Message-ID:
In-Reply-To: 


steakhal wrote:

> @steakhal In addition to the other changes, I also reverted commit 
> https://github.com/llvm/llvm-project/commit/7da3862e87c3e6e94b80e04bddbfd04848f6ce04
>  where you renamed getTagDescription to getDebugName, because although I 
> completely agree with that change, I think it would be nicer to merge it as a 
> separate commit (because e.g. this relatively large commit would be easier to 
> understand without the name change). Do you want to create the PR for it 
> (after this is merged) or should I create it?

I don't want to work on this, nor to propose a PR in this area.

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


[clang] Thread Safety Analysis: Use replaceLock instead of removeLock+addLock (PR #141500)

2025-05-26 Thread Marco Elver via cfe-commits

https://github.com/melver created 
https://github.com/llvm/llvm-project/pull/141500

In ScopedLockableFactEntry::unlock(), we can avoid a second search, pop_back(), 
and push_back() if we use the already obtained iterator into the FactSet to 
replace the old FactEntry and take its position in the vector.

>From b77f2a1ebf98bde647ee535dbd1ab0c24dbdfdb3 Mon Sep 17 00:00:00 2001
From: Marco Elver 
Date: Fri, 25 Apr 2025 18:51:16 +0200
Subject: [PATCH] Thread Safety Analysis: Use replaceLock instead of
 removeLock+addLock

In ScopedLockableFactEntry::unlock(), we can avoid a second search,
pop_back(), and push_back() if we use the already obtained iterator into
the FactSet to replace the old FactEntry and take its position in the
vector.
---
 clang/lib/Analysis/ThreadSafety.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Analysis/ThreadSafety.cpp 
b/clang/lib/Analysis/ThreadSafety.cpp
index 198e324414be9..9dffb8fcd2204 100644
--- a/clang/lib/Analysis/ThreadSafety.cpp
+++ b/clang/lib/Analysis/ThreadSafety.cpp
@@ -1071,9 +1071,9 @@ class ScopedLockableFactEntry : public FactEntry {
 return;
   }
 
-  FSet.removeLock(FactMan, Cp);
-  FSet.addLock(FactMan,
-   std::make_unique(!Cp, LK_Exclusive, 
loc));
+  FSet.replaceLock(
+  FactMan, It,
+  std::make_unique(!Cp, LK_Exclusive, loc));
 } else if (Handler) {
   SourceLocation PrevLoc;
   if (const FactEntry *Neg = FSet.findLock(FactMan, !Cp))

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


[clang] Thread Safety Analysis: Use replaceLock instead of removeLock+addLock (PR #141500)

2025-05-26 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-analysis

Author: Marco Elver (melver)


Changes

In ScopedLockableFactEntry::unlock(), we can avoid a second search, pop_back(), 
and push_back() if we use the already obtained iterator into the FactSet to 
replace the old FactEntry and take its position in the vector.

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


1 Files Affected:

- (modified) clang/lib/Analysis/ThreadSafety.cpp (+3-3) 


``diff
diff --git a/clang/lib/Analysis/ThreadSafety.cpp 
b/clang/lib/Analysis/ThreadSafety.cpp
index 198e324414be9..9dffb8fcd2204 100644
--- a/clang/lib/Analysis/ThreadSafety.cpp
+++ b/clang/lib/Analysis/ThreadSafety.cpp
@@ -1071,9 +1071,9 @@ class ScopedLockableFactEntry : public FactEntry {
 return;
   }
 
-  FSet.removeLock(FactMan, Cp);
-  FSet.addLock(FactMan,
-   std::make_unique(!Cp, LK_Exclusive, 
loc));
+  FSet.replaceLock(
+  FactMan, It,
+  std::make_unique(!Cp, LK_Exclusive, loc));
 } else if (Handler) {
   SourceLocation PrevLoc;
   if (const FactEntry *Neg = FSet.findLock(FactMan, !Cp))

``




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


[clang] Thread Safety Analysis: Use replaceLock instead of removeLock+addLock (PR #141500)

2025-05-26 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Marco Elver (melver)


Changes

In ScopedLockableFactEntry::unlock(), we can avoid a second search, pop_back(), 
and push_back() if we use the already obtained iterator into the FactSet to 
replace the old FactEntry and take its position in the vector.

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


1 Files Affected:

- (modified) clang/lib/Analysis/ThreadSafety.cpp (+3-3) 


``diff
diff --git a/clang/lib/Analysis/ThreadSafety.cpp 
b/clang/lib/Analysis/ThreadSafety.cpp
index 198e324414be9..9dffb8fcd2204 100644
--- a/clang/lib/Analysis/ThreadSafety.cpp
+++ b/clang/lib/Analysis/ThreadSafety.cpp
@@ -1071,9 +1071,9 @@ class ScopedLockableFactEntry : public FactEntry {
 return;
   }
 
-  FSet.removeLock(FactMan, Cp);
-  FSet.addLock(FactMan,
-   std::make_unique(!Cp, LK_Exclusive, 
loc));
+  FSet.replaceLock(
+  FactMan, It,
+  std::make_unique(!Cp, LK_Exclusive, loc));
 } else if (Handler) {
   SourceLocation PrevLoc;
   if (const FactEntry *Neg = FSet.findLock(FactMan, !Cp))

``




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


[clang] Thread Safety Analysis: Support reentrant capabilities (PR #137133)

2025-05-26 Thread Marco Elver via cfe-commits

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


[clang] [clang] Implement address sanitizer on AIX (PR #129925)

2025-05-26 Thread Jake Egan via cfe-commits

https://github.com/jakeegan updated 
https://github.com/llvm/llvm-project/pull/129925

>From 072f4eca3825729d69d423d774c8a3298cb624a8 Mon Sep 17 00:00:00 2001
From: Jake Egan 
Date: Wed, 5 Mar 2025 01:57:38 -0500
Subject: [PATCH 1/5] [clang] Implement address sanitizer on AIX (1/3)

The PR includes clang changes needed for the address sanitizer on AIX. Will 
also post llvm and
compiler-rt PRs following this.
---
 .../clang/Basic/DiagnosticDriverKinds.td  |   2 +
 clang/include/clang/Driver/Options.td |   2 +-
 clang/lib/CodeGen/BackendUtil.cpp |   5 +-
 clang/lib/Driver/ToolChain.cpp|   2 +-
 clang/lib/Driver/ToolChains/AIX.cpp   |  45 
 clang/lib/Driver/ToolChains/AIX.h |   2 +
 clang/lib/Driver/ToolChains/CommonArgs.cpp|  36 +-
 .../lib/aix/asan.link_with_main_exec.txt  |   0
 .../lib/aix/asan_cxx.link_with_main_exec.txt  |   0
 clang/test/Driver/sanitizer-ld.c  | 104 ++
 10 files changed, 189 insertions(+), 9 deletions(-)
 create mode 100644 
clang/test/Driver/Inputs/resource_dir/lib/aix/asan.link_with_main_exec.txt
 create mode 100644 
clang/test/Driver/Inputs/resource_dir/lib/aix/asan_cxx.link_with_main_exec.txt

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 8d599c96eb4fb..c44d364d244bc 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -257,6 +257,8 @@ def err_drv_malformed_sanitizer_metadata_ignorelist : Error<
   "malformed sanitizer metadata ignorelist: '%0'">;
 def err_drv_unsupported_static_sanitizer_darwin : Error<
   "static %0 runtime is not supported on darwin">;
+def err_drv_unsupported_shared_sanitizer_aix : Error<
+  "shared %0 runtime is not supported on AIX">;
 def err_drv_duplicate_config : Error<
   "no more than one option '--config' is allowed">;
 def err_drv_cannot_open_config_file : Error<
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 0ab923fcdd583..66959279d3fcf 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1542,7 +1542,7 @@ defm xl_pragma_pack : BoolFOption<"xl-pragma-pack",
   "Enable IBM XL #pragma pack handling">,
   NegFlag>;
 def shared_libsan : Flag<["-"], "shared-libsan">,
-  HelpText<"Dynamically link the sanitizer runtime">;
+  HelpText<"Dynamically link the sanitizer runtime (Not supported for ASan on 
AIX)">;
 def static_libsan : Flag<["-"], "static-libsan">,
   HelpText<"Statically link the sanitizer runtime (Not supported for ASan, 
TSan or UBSan on darwin)">;
 def : Flag<["-"], "shared-libasan">, Alias;
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 97e9bbccd61ef..b47aff95f2430 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -275,13 +275,14 @@ static bool asanUseGlobalsGC(const Triple &T, const 
CodeGenOptions &CGOpts) {
 return !CGOpts.DisableIntegratedAS;
   case Triple::GOFF:
 llvm::report_fatal_error("ASan not implemented for GOFF");
-  case Triple::XCOFF:
-llvm::report_fatal_error("ASan not implemented for XCOFF.");
   case Triple::Wasm:
   case Triple::DXContainer:
   case Triple::SPIRV:
   case Triple::UnknownObjectFormat:
 break;
+  case Triple::XCOFF:
+// FIXME: try to enable GC-friendly instrumentation for globals on AIX.
+return false;
   }
   return false;
 }
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index ebc982096595e..d4aa71d031ba9 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -749,7 +749,7 @@ std::string ToolChain::buildCompilerRTBasename(const 
llvm::opt::ArgList &Args,
   case ToolChain::FT_Shared:
 Suffix = TT.isOSWindows()
  ? (TT.isWindowsGNUEnvironment() ? ".dll.a" : ".lib")
- : ".so";
+ : (TT.isOSAIX() ? ".a" : ".so");
 break;
   }
 
diff --git a/clang/lib/Driver/ToolChains/AIX.cpp 
b/clang/lib/Driver/ToolChains/AIX.cpp
index 09a8dc2f4fa5d..30db6f45c7e81 100644
--- a/clang/lib/Driver/ToolChains/AIX.cpp
+++ b/clang/lib/Driver/ToolChains/AIX.cpp
@@ -20,6 +20,7 @@
 #include 
 
 using AIX = clang::driver::toolchains::AIX;
+using namespace clang;
 using namespace clang::driver;
 using namespace clang::driver::tools;
 using namespace clang::driver::toolchains;
@@ -233,6 +234,44 @@ void aix::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   // Specify linker input file(s).
   AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
 
+  // Add sanitizer libraries.
+  const SanitizerArgs &Sanitize = ToolChain.getSanitizerArgs(Args);
+  const char *sanitizer = nullptr;
+  bool NeedsSanitizerDeps = false;
+  // For now, only support address sanitizer.
+  if (Sanitize.needsAsanRt())
+sanitizer = "AddressSanitizer";
+
+  if (sanitizer) {
+  

[clang] [clang][ASTImporter] try fix missing Visit functions for issue #129393 (PR #138845)

2025-05-26 Thread Balázs Kéri via cfe-commits

balazske wrote:

After #141104 clang should be buildable with dynamic linking too with this 
change included. Only tests should be added for the new node types, but I can 
do it only later.

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


[clang] [clang] Implement address sanitizer on AIX (PR #129925)

2025-05-26 Thread Jake Egan via cfe-commits

jakeegan wrote:

> clang/test/Driver/Inputs/resource_dir/lib/aix/libclang_rt.asan-powerpc.a is 
> the old runtime path.
Does $triple/libclang_rt.asan.a work? If yes, the new hierarchy is preferred

per target runtime dir is enabled on AIX now, so I updated the PR accordingly 

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


[clang] [clang] Implement address sanitizer on AIX (PR #129925)

2025-05-26 Thread Jake Egan via cfe-commits

https://github.com/jakeegan updated 
https://github.com/llvm/llvm-project/pull/129925

>From 072f4eca3825729d69d423d774c8a3298cb624a8 Mon Sep 17 00:00:00 2001
From: Jake Egan 
Date: Wed, 5 Mar 2025 01:57:38 -0500
Subject: [PATCH 1/5] [clang] Implement address sanitizer on AIX (1/3)

The PR includes clang changes needed for the address sanitizer on AIX. Will 
also post llvm and
compiler-rt PRs following this.
---
 .../clang/Basic/DiagnosticDriverKinds.td  |   2 +
 clang/include/clang/Driver/Options.td |   2 +-
 clang/lib/CodeGen/BackendUtil.cpp |   5 +-
 clang/lib/Driver/ToolChain.cpp|   2 +-
 clang/lib/Driver/ToolChains/AIX.cpp   |  45 
 clang/lib/Driver/ToolChains/AIX.h |   2 +
 clang/lib/Driver/ToolChains/CommonArgs.cpp|  36 +-
 .../lib/aix/asan.link_with_main_exec.txt  |   0
 .../lib/aix/asan_cxx.link_with_main_exec.txt  |   0
 clang/test/Driver/sanitizer-ld.c  | 104 ++
 10 files changed, 189 insertions(+), 9 deletions(-)
 create mode 100644 
clang/test/Driver/Inputs/resource_dir/lib/aix/asan.link_with_main_exec.txt
 create mode 100644 
clang/test/Driver/Inputs/resource_dir/lib/aix/asan_cxx.link_with_main_exec.txt

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 8d599c96eb4fb..c44d364d244bc 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -257,6 +257,8 @@ def err_drv_malformed_sanitizer_metadata_ignorelist : Error<
   "malformed sanitizer metadata ignorelist: '%0'">;
 def err_drv_unsupported_static_sanitizer_darwin : Error<
   "static %0 runtime is not supported on darwin">;
+def err_drv_unsupported_shared_sanitizer_aix : Error<
+  "shared %0 runtime is not supported on AIX">;
 def err_drv_duplicate_config : Error<
   "no more than one option '--config' is allowed">;
 def err_drv_cannot_open_config_file : Error<
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 0ab923fcdd583..66959279d3fcf 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1542,7 +1542,7 @@ defm xl_pragma_pack : BoolFOption<"xl-pragma-pack",
   "Enable IBM XL #pragma pack handling">,
   NegFlag>;
 def shared_libsan : Flag<["-"], "shared-libsan">,
-  HelpText<"Dynamically link the sanitizer runtime">;
+  HelpText<"Dynamically link the sanitizer runtime (Not supported for ASan on 
AIX)">;
 def static_libsan : Flag<["-"], "static-libsan">,
   HelpText<"Statically link the sanitizer runtime (Not supported for ASan, 
TSan or UBSan on darwin)">;
 def : Flag<["-"], "shared-libasan">, Alias;
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 97e9bbccd61ef..b47aff95f2430 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -275,13 +275,14 @@ static bool asanUseGlobalsGC(const Triple &T, const 
CodeGenOptions &CGOpts) {
 return !CGOpts.DisableIntegratedAS;
   case Triple::GOFF:
 llvm::report_fatal_error("ASan not implemented for GOFF");
-  case Triple::XCOFF:
-llvm::report_fatal_error("ASan not implemented for XCOFF.");
   case Triple::Wasm:
   case Triple::DXContainer:
   case Triple::SPIRV:
   case Triple::UnknownObjectFormat:
 break;
+  case Triple::XCOFF:
+// FIXME: try to enable GC-friendly instrumentation for globals on AIX.
+return false;
   }
   return false;
 }
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index ebc982096595e..d4aa71d031ba9 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -749,7 +749,7 @@ std::string ToolChain::buildCompilerRTBasename(const 
llvm::opt::ArgList &Args,
   case ToolChain::FT_Shared:
 Suffix = TT.isOSWindows()
  ? (TT.isWindowsGNUEnvironment() ? ".dll.a" : ".lib")
- : ".so";
+ : (TT.isOSAIX() ? ".a" : ".so");
 break;
   }
 
diff --git a/clang/lib/Driver/ToolChains/AIX.cpp 
b/clang/lib/Driver/ToolChains/AIX.cpp
index 09a8dc2f4fa5d..30db6f45c7e81 100644
--- a/clang/lib/Driver/ToolChains/AIX.cpp
+++ b/clang/lib/Driver/ToolChains/AIX.cpp
@@ -20,6 +20,7 @@
 #include 
 
 using AIX = clang::driver::toolchains::AIX;
+using namespace clang;
 using namespace clang::driver;
 using namespace clang::driver::tools;
 using namespace clang::driver::toolchains;
@@ -233,6 +234,44 @@ void aix::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   // Specify linker input file(s).
   AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
 
+  // Add sanitizer libraries.
+  const SanitizerArgs &Sanitize = ToolChain.getSanitizerArgs(Args);
+  const char *sanitizer = nullptr;
+  bool NeedsSanitizerDeps = false;
+  // For now, only support address sanitizer.
+  if (Sanitize.needsAsanRt())
+sanitizer = "AddressSanitizer";
+
+  if (sanitizer) {
+  

[clang] [clang][AIX] Fix -print-runtime-dir fallback on AIX (PR #141439)

2025-05-26 Thread Daniel Chen via cfe-commits

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

LGTM with a minor nit comment.

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


[clang] [analyzer] Introduce the check::BlockEntrance checker callback (PR #140924)

2025-05-26 Thread Balázs Benics via cfe-commits

https://github.com/balazs-benics-sonarsource updated 
https://github.com/llvm/llvm-project/pull/140924

From 084d821b62d5de473d32d3506da95fdd7bad1cfe Mon Sep 17 00:00:00 2001
From: Balazs Benics 
Date: Thu, 15 May 2025 17:20:29 +0200
Subject: [PATCH 1/4] [analyzer] Introduce the check::BlockEntrance

Tranersing the CFG blocks of a function is a fundamental operation.
Many C++ constructs can create splits in the control-flow, such as
`if`, `for`, and similar control structures or ternary expressions,
gnu conditionals, gotos, switches and possibly more.

Checkers should be able to get notifications about entering or leaving a
CFG block of interest.

Note that in the ExplodedGraph there is always a BlockEntrance
ProgramPoint right after the BlockEdge ProgramPoint.
I considered naming this callback check::BlockEdge, but then that may
leave the observer of the graph puzzled to see BlockEdge points followed
more BlockEdge nodes describing the same CFG transition.
This confusion could also apply to Bug Report Visitors too.

Because of this, I decided to hook BlockEntrance ProgramPoints instead.
The same confusion applies here, but I find this still a better place
TBH. There would only appear only one BlockEntrance ProgramPoint in the
graph if no checkers modify the state or emit a bug report.
Otherwise they modify some GDM (aka. State) thus create a new
ExplodedNode with the same BlockEntrance ProgramPoint in the graph.

CPP-6484
---
 .../clang/StaticAnalyzer/Core/Checker.h   |  20 ++
 .../StaticAnalyzer/Core/CheckerManager.h  |  13 +
 .../Core/PathSensitive/ExprEngine.h   |   4 +
 .../Checkers/CheckerDocumentation.cpp |  15 +-
 .../StaticAnalyzer/Core/CheckerManager.cpp|  50 +++-
 clang/lib/StaticAnalyzer/Core/CoreEngine.cpp  |  25 +-
 clang/lib/StaticAnalyzer/Core/ExprEngine.cpp  |  13 +
 clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp |   6 +-
 .../BlockEntranceCallbackTest.cpp | 283 ++
 clang/unittests/StaticAnalyzer/CMakeLists.txt |   1 +
 10 files changed, 414 insertions(+), 16 deletions(-)
 create mode 100644 clang/unittests/StaticAnalyzer/BlockEntranceCallbackTest.cpp

diff --git a/clang/include/clang/StaticAnalyzer/Core/Checker.h 
b/clang/include/clang/StaticAnalyzer/Core/Checker.h
index a54c5bee612f6..1b348dcce5ea7 100644
--- a/clang/include/clang/StaticAnalyzer/Core/Checker.h
+++ b/clang/include/clang/StaticAnalyzer/Core/Checker.h
@@ -221,6 +221,22 @@ class Bind {
   }
 };
 
+class BlockEntrance {
+  template 
+  static void _checkBlockEntrance(void *Checker,
+  const clang::BlockEntrance &Entrance,
+  CheckerContext &C) {
+((const CHECKER *)Checker)->checkBlockEntrance(Entrance, C);
+  }
+
+public:
+  template 
+  static void _register(CHECKER *checker, CheckerManager &mgr) {
+mgr._registerForBlockEntrance(CheckerManager::CheckBlockEntranceFunc(
+checker, _checkBlockEntrance));
+  }
+};
+
 class EndAnalysis {
   template 
   static void _checkEndAnalysis(void *checker, ExplodedGraph &G,
@@ -548,6 +564,8 @@ class CheckerProgramPointTag : public SimpleProgramPointTag 
{
 template 
 class Checker : public CHECK1, public CHECKs..., public CheckerBase {
 public:
+  using BlockEntrance = clang::BlockEntrance;
+
   template 
   static void _register(CHECKER *checker, CheckerManager &mgr) {
 CHECK1::_register(checker, mgr);
@@ -558,6 +576,8 @@ class Checker : public CHECK1, public CHECKs..., public 
CheckerBase {
 template 
 class Checker : public CHECK1, public CheckerBase {
 public:
+  using BlockEntrance = clang::BlockEntrance;
+
   template 
   static void _register(CHECKER *checker, CheckerManager &mgr) {
 CHECK1::_register(checker, mgr);
diff --git a/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h 
b/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
index 03ffadd346d0b..b5fefdb75401d 100644
--- a/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
+++ b/clang/include/clang/StaticAnalyzer/Core/CheckerManager.h
@@ -376,6 +376,12 @@ class CheckerManager {
   const Stmt *S, ExprEngine &Eng,
   const ProgramPoint &PP);
 
+  /// Run checkers after taking a control flow edge.
+  void runCheckersForBlockEntrance(ExplodedNodeSet &Dst,
+   const ExplodedNodeSet &Src,
+   const BlockEntrance &Entrance,
+   ExprEngine &Eng) const;
+
   /// Run checkers for end of analysis.
   void runCheckersForEndAnalysis(ExplodedGraph &G, BugReporter &BR,
  ExprEngine &Eng);
@@ -528,6 +534,9 @@ class CheckerManager {
   using CheckBindFunc =
   CheckerFn;
 
+  using CheckBlockEntranceFunc =
+  CheckerFn;
+
   using CheckEndAnalysisFunc =
   CheckerFn;
 
@@ -589,6 +598,8 @@ class CheckerManager {
 
   void _registerForBind(CheckBindFunc checkfn);
 
+  void _registerForBlockEntrance(Che

[clang] [clang] Implement address sanitizer on AIX (PR #129925)

2025-05-26 Thread Jake Egan via cfe-commits


@@ -259,6 +260,45 @@ void aix::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   // Specify linker input file(s).
   AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
 
+  // Add sanitizer libraries.
+  const SanitizerArgs &Sanitize = ToolChain.getSanitizerArgs(Args);
+  const char *sanitizer = nullptr;
+  bool NeedsSanitizerDeps = false;
+  // For now, only support address sanitizer.
+  if (Sanitize.needsAsanRt())
+sanitizer = "AddressSanitizer";
+
+  if (sanitizer) {
+if (Sanitize.needsSharedRt()) {
+  
ToolChain.getDriver().Diag(diag::err_drv_unsupported_shared_sanitizer_aix)
+  << sanitizer;
+  return;
+}
+NeedsSanitizerDeps = addSanitizerRuntimes(ToolChain, Args, CmdArgs);
+  }
+
+  // Add sanitizer runtime dependencies.
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
+   options::OPT_shared, options::OPT_r)) {
+if (NeedsSanitizerDeps)
+  linkSanitizerRuntimeDeps(ToolChain, Args, CmdArgs);
+  }
+
+  // We won't add the static sanitizer libraries to the DSO, but we will
+  // introduce the undefined sanitizer symbols like __asan_init to the DSO. On
+  // AIX, this undefined sanitizer symbol cannot pass final link. Add the
+  // import file to make these undefined symbols be resolved at runtime.
+  if (Args.hasArg(options::OPT_shared) &&
+  ToolChain.getSanitizerArgs(Args).needsAsanRt()) {
+CmdArgs.push_back(Args.MakeArgString(Twine("-bI:") +
+ ToolChain.getCompilerRTPath() +
+ "/asan.link_with_main_exec.txt"));

jakeegan wrote:

The lists are added here: https://github.com/llvm/llvm-project/pull/139583

The file extension is to be consistent with other asan files like 
`compiler-rt/lib/asan/weak_symbols.txt`

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


[clang] [flang] [mlir] [flang] Add support for -mprefer-vector-width= (PR #141380)

2025-05-26 Thread Tarun Prabhu via cfe-commits

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

Thanks for this. I second @jeanPerier's request for an MLIR test

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


[clang] [flang] [mlir] [flang] Add support for -mprefer-vector-width= (PR #141380)

2025-05-26 Thread Tarun Prabhu via cfe-commits

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


[clang] [Preprocessor] Do not expand macros if the input is already preprocessed (PR #137665)

2025-05-26 Thread Juan Manuel Martinez Caamaño via cfe-commits

https://github.com/jmmartinez updated 
https://github.com/llvm/llvm-project/pull/137665

From 002795597e3c1c887e5099f0efa7e6b23eefad8e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Juan=20Manuel=20Martinez=20Caama=C3=B1o?= 
Date: Mon, 28 Apr 2025 17:05:46 +0200
Subject: [PATCH 1/6] Pre-commit test: [Preprocessor] Do not expand macros if
 the input is already preprocessed

---
 clang/test/Preprocessor/preprocess-cpp-output.c | 9 +
 1 file changed, 9 insertions(+)
 create mode 100644 clang/test/Preprocessor/preprocess-cpp-output.c

diff --git a/clang/test/Preprocessor/preprocess-cpp-output.c 
b/clang/test/Preprocessor/preprocess-cpp-output.c
new file mode 100644
index 0..59ff057e9b871
--- /dev/null
+++ b/clang/test/Preprocessor/preprocess-cpp-output.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -E -x c %s | FileCheck %s --check-prefixes=EXPANDED
+// RUN: %clang_cc1 -E -x cpp-output %s | FileCheck %s --check-prefixes=EXPANDED
+
+// EXPANDED: void __attribute__((__attribute__((always_inline foo()
+
+#define always_inline __attribute__((always_inline))
+void __attribute__((always_inline)) foo() {
+return 4;
+}

From 8d81c9f884dfcd35d993707847338528e11febc1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Juan=20Manuel=20Martinez=20Caama=C3=B1o?= 
Date: Tue, 13 May 2025 15:03:46 +0200
Subject: [PATCH 2/6] [Modules] initializers.cpp test fix

The module contents should not contain preprocessor directives. The
contents should be already preprocessed.

Duplicate the modules instead to propose 2 versions: one with the
namespace ns and one without.
---
 clang/test/Modules/initializers.cpp | 59 +++--
 1 file changed, 55 insertions(+), 4 deletions(-)

diff --git a/clang/test/Modules/initializers.cpp 
b/clang/test/Modules/initializers.cpp
index dcd9b08ec6f7a..e1f826fbc09f3 100644
--- a/clang/test/Modules/initializers.cpp
+++ b/clang/test/Modules/initializers.cpp
@@ -48,6 +48,7 @@
 // instantiation for v in one of the two headers, because we will only
 // parse one of the two get() functions.
 
+#ifdef NS
 #pragma clang module build m
 module m {
   module a {
@@ -60,9 +61,7 @@ module m {
 #pragma clang module begin m.a
 inline int non_trivial() { return 3; }
 
-#ifdef NS
 namespace ns {
-#endif
 
 int a = non_trivial();
 inline int b = non_trivial();
@@ -102,12 +101,64 @@ inline void use(bool b, ...) {
   X::e, X::f, X::g, X::h);
 }
 
-#ifdef NS
 }
-#endif
 
 #pragma clang module end
 #pragma clang module endbuild
+#else
+#pragma clang module build m
+module m {
+  module a {
+header "foo.h" { size 123 mtime 456789 }
+  }
+  module b {}
+}
+
+#pragma clang module contents
+#pragma clang module begin m.a
+inline int non_trivial() { return 3; }
+
+int a = non_trivial();
+inline int b = non_trivial();
+thread_local int c = non_trivial();
+inline thread_local int d = non_trivial();
+
+template int e = non_trivial();
+template inline int f = non_trivial();
+template thread_local int g = non_trivial();
+template inline thread_local int h = non_trivial();
+
+inline int unused = 123; // should not be emitted
+
+template struct X {
+  static int a;
+  static inline int b = non_trivial();
+  static thread_local int c;
+  static inline thread_local int d = non_trivial();
+
+  template static int e;
+  template static inline int f = non_trivial();
+  template static thread_local int g;
+  template static inline thread_local int h = non_trivial();
+
+  static inline int unused = 123; // should not be emitted
+};
+
+template int X::a = non_trivial();
+template thread_local int X::c = non_trivial();
+template template int X::e = non_trivial();
+template template thread_local int X::g = 
non_trivial();
+
+inline void use(bool b, ...) {
+  if (b) return;
+  use(true, e, f, g, h,
+  X::a, X::b, X::c, X::d,
+  X::e, X::f, X::g, X::h);
+}
+
+#pragma clang module end
+#pragma clang module endbuild
+#endif
 
 #if IMPORT == 1
 // Import the module and the m.a submodule; runs the ordered initializers and

From ec7595173f31f53be934b9abf5a3d29bee20c7ef Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Juan=20Manuel=20Martinez=20Caama=C3=B1o?= 
Date: Tue, 22 Apr 2025 18:40:37 +0200
Subject: [PATCH 3/6] [Preprocessor] Do not expand macros if the input is
 already preprocessed

---
 clang/include/clang/Lex/Preprocessor.h  | 5 +
 clang/lib/Frontend/InitPreprocessor.cpp | 7 +++
 clang/test/Preprocessor/preprocess-cpp-output.c | 3 ++-
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index f2dfd3a349b8b..63774e48a468b 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -1831,6 +1831,11 @@ class Preprocessor {
 MacroExpansionInDirectivesOverride = true;
   }
 
+  void SetDisableMacroExpansion() {
+DisableMacroExpansion = true;
+MacroExpansionInDirectivesOverride = false;
+  }
+
   /// Peeks ahead N tokens and returns that token without co

[clang] [Preprocessor] Do not expand macros if the input is already preprocessed (PR #137665)

2025-05-26 Thread Juan Manuel Martinez Caamaño via cfe-commits


@@ -84,6 +84,8 @@ class FrontendAction {
   /// \return True on success; on failure ExecutionAction() and
   /// EndSourceFileAction() will not be called.
   virtual bool BeginSourceFileAction(CompilerInstance &CI) {
+if (CurrentInput.isPreprocessed())
+  CI.getPreprocessor().SetDisableMacroExpansion();

jmmartinez wrote:

It was quite shortsighted from me, sorry. There were some subclasses that were 
missing the call to the base-class method.

I should add the calls to the base class in a separate NFC patch.

I've added a `SetEnableMacroExpansion(true/false)` method to set/reset the 
macro expansion; but I'm not convinced by it (I'm worried about interactions 
with `SetMacroExpansionOnlyInDirectives`, but these interactions also seem 
unlikely).

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


[clang] [Preprocessor] Do not expand macros if the input is already preprocessed (PR #137665)

2025-05-26 Thread Juan Manuel Martinez Caamaño via cfe-commits


@@ -1558,6 +1558,7 @@ void clang::InitializePreprocessor(Preprocessor &PP,
const PCHContainerReader &PCHContainerRdr,
const FrontendOptions &FEOpts,
const CodeGenOptions &CodeGenOpts) {
+

jmmartinez wrote:

This slipped in, remove this change.

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


[clang] Include [[clang::require_explicit_initialization]] warnings in system headers (PR #141133)

2025-05-26 Thread via cfe-commits

higher-performance wrote:

What do folks think?

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


[clang] [Analysis] Use llvm::erase_if (NFC) (PR #141446)

2025-05-26 Thread Kazu Hirata via cfe-commits

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


[clang] 6c37341 - [Driver] Remove unused includes (NFC) (#141448)

2025-05-26 Thread via cfe-commits

Author: Kazu Hirata
Date: 2025-05-26T09:13:36-07:00
New Revision: 6c37341943eb2a8ba2a34e35a2c699c763b001fb

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

LOG: [Driver] Remove unused includes (NFC) (#141448)

These are identified by misc-include-cleaner.  I've filtered out those
that break builds.  Also, I'm staying away from llvm-config.h,
config.h, and Compiler.h, which likely cause platform- or
compiler-specific build failures.

Added: 


Modified: 
clang/lib/Driver/ToolChains/AIX.cpp
clang/lib/Driver/ToolChains/AMDGPU.cpp
clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
clang/lib/Driver/ToolChains/AVR.cpp
clang/lib/Driver/ToolChains/Arch/AArch64.cpp
clang/lib/Driver/ToolChains/Arch/ARM.cpp
clang/lib/Driver/ToolChains/Arch/CSKY.cpp
clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
clang/lib/Driver/ToolChains/Arch/M68k.cpp
clang/lib/Driver/ToolChains/Arch/Mips.cpp
clang/lib/Driver/ToolChains/Arch/PPC.cpp
clang/lib/Driver/ToolChains/Arch/RISCV.cpp
clang/lib/Driver/ToolChains/Arch/Sparc.cpp
clang/lib/Driver/ToolChains/Arch/SystemZ.cpp
clang/lib/Driver/ToolChains/Arch/VE.cpp
clang/lib/Driver/ToolChains/Arch/X86.cpp
clang/lib/Driver/ToolChains/BareMetal.cpp
clang/lib/Driver/ToolChains/CSKYToolChain.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/lib/Driver/ToolChains/Cuda.cpp
clang/lib/Driver/ToolChains/Darwin.cpp
clang/lib/Driver/ToolChains/Flang.cpp
clang/lib/Driver/ToolChains/FreeBSD.cpp
clang/lib/Driver/ToolChains/Fuchsia.cpp
clang/lib/Driver/ToolChains/Gnu.cpp
clang/lib/Driver/ToolChains/HIPAMD.cpp
clang/lib/Driver/ToolChains/HIPSPV.cpp
clang/lib/Driver/ToolChains/HIPUtility.cpp
clang/lib/Driver/ToolChains/HLSL.cpp
clang/lib/Driver/ToolChains/Hexagon.cpp
clang/lib/Driver/ToolChains/Linux.cpp
clang/lib/Driver/ToolChains/MSP430.cpp
clang/lib/Driver/ToolChains/MSVC.cpp
clang/lib/Driver/ToolChains/MinGW.cpp
clang/lib/Driver/ToolChains/MipsLinux.cpp
clang/lib/Driver/ToolChains/NaCl.cpp
clang/lib/Driver/ToolChains/OHOS.cpp
clang/lib/Driver/ToolChains/PPCLinux.cpp
clang/lib/Driver/ToolChains/PS4CPU.cpp
clang/lib/Driver/ToolChains/RISCVToolchain.cpp
clang/lib/Driver/ToolChains/SPIRV.cpp
clang/lib/Driver/ToolChains/SYCL.cpp
clang/lib/Driver/ToolChains/Solaris.cpp
clang/lib/Driver/ToolChains/TCE.cpp
clang/lib/Driver/ToolChains/UEFI.cpp
clang/lib/Driver/ToolChains/VEToolchain.cpp
clang/lib/Driver/ToolChains/WebAssembly.cpp
clang/lib/Driver/ToolChains/ZOS.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/AIX.cpp 
b/clang/lib/Driver/ToolChains/AIX.cpp
index e44b0a76b3eb9..a1a94e37116ce 100644
--- a/clang/lib/Driver/ToolChains/AIX.cpp
+++ b/clang/lib/Driver/ToolChains/AIX.cpp
@@ -7,7 +7,6 @@
 
//===--===//
 
 #include "AIX.h"
-#include "Arch/PPC.h"
 #include "CommonArgs.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Options.h"

diff  --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp 
b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index 4ecb01d0f0bea..dfbe936d5a5d3 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -11,7 +11,6 @@
 #include "clang/Basic/TargetID.h"
 #include "clang/Config/config.h"
 #include "clang/Driver/Compilation.h"
-#include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/InputInfo.h"
 #include "clang/Driver/Options.h"
 #include "clang/Driver/SanitizerArgs.h"

diff  --git a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp 
b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
index fe8bfb361e5a6..7ffa3f0f558f3 100644
--- a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
@@ -8,20 +8,11 @@
 
 #include "AMDGPUOpenMP.h"
 #include "AMDGPU.h"
-#include "CommonArgs.h"
-#include "ROCm.h"
-#include "clang/Basic/DiagnosticDriver.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
-#include "clang/Driver/DriverDiagnostic.h"
-#include "clang/Driver/InputInfo.h"
 #include "clang/Driver/Options.h"
 #include "clang/Driver/Tool.h"
 #include "llvm/ADT/STLExtras.h"
-#include "llvm/Support/FileSystem.h"
-#include "llvm/Support/FormatAdapters.h"
-#include "llvm/Support/FormatVariadic.h"
-#include "llvm/Support/Path.h"
 
 using namespace clang::driver;
 using namespace clang::driver::toolchains;

diff  --git a/clang/lib/Driver/ToolChains/AVR.cpp 
b/clang/lib/Driver/ToolChains/AVR.cpp
index 53e952a853005..f1529f857eef8 100644
--- a/clang/lib/Driver/ToolChains/AVR.cpp
+++ b/clang/lib/Driver/ToolChains/AVR.cpp
@@ -9,11 +9,8 @@
 #include "AVR.h"
 #include "Common

[clang] fe83587 - [AST] Use llvm::none_of (NFC) (#141447)

2025-05-26 Thread via cfe-commits

Author: Kazu Hirata
Date: 2025-05-26T09:13:32-07:00
New Revision: fe83587366350843af8ad415a91491b91fb2dfb2

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

LOG: [AST] Use llvm::none_of (NFC) (#141447)

Added: 


Modified: 
clang/unittests/AST/ASTImporterFixtures.cpp

Removed: 




diff  --git a/clang/unittests/AST/ASTImporterFixtures.cpp 
b/clang/unittests/AST/ASTImporterFixtures.cpp
index 897b370dd3cdc..e4e5a078262c3 100644
--- a/clang/unittests/AST/ASTImporterFixtures.cpp
+++ b/clang/unittests/AST/ASTImporterFixtures.cpp
@@ -173,9 +173,8 @@ std::tuple 
ASTImporterTestBase::getImportedDecl(
 TranslationUnitDecl *ASTImporterTestBase::getTuDecl(StringRef SrcCode,
 TestLanguage Lang,
 StringRef FileName) {
-  assert(llvm::find_if(FromTUs, [FileName](const TU &E) {
-   return E.FileName == FileName;
- }) == FromTUs.end());
+  assert(llvm::none_of(
+  FromTUs, [FileName](const TU &E) { return E.FileName == FileName; }));
 
   std::vector Args = getCommandLineArgsForLanguage(Lang);
   FromTUs.emplace_back(SrcCode, FileName, Args, Creator, ODRHandling);



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


[clang] [Driver] Remove unused includes (NFC) (PR #141448)

2025-05-26 Thread Kazu Hirata via cfe-commits

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


[clang] ecd248f - [Analysis] Use llvm::erase_if (NFC) (#141446)

2025-05-26 Thread via cfe-commits

Author: Kazu Hirata
Date: 2025-05-26T09:13:29-07:00
New Revision: ecd248f647831245f89ffc7b926133e75cd3225a

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

LOG: [Analysis] Use llvm::erase_if (NFC) (#141446)

Added: 


Modified: 
clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp

Removed: 




diff  --git a/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp 
b/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
index 720999207083d..4e97174c17d95 100644
--- a/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
+++ b/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
@@ -86,9 +86,7 @@ mutatedBy(const SmallVectorImpl &Results, ASTUnit 
*AST) {
 }
 
 std::string removeSpace(std::string s) {
-  s.erase(std::remove_if(s.begin(), s.end(),
- [](char c) { return llvm::isSpace(c); }),
-  s.end());
+  llvm::erase_if(s, llvm::isSpace);
   return s;
 }
 



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


[clang] [flang] [mlir] [flang] Add support for -mprefer-vector-width= (PR #141380)

2025-05-26 Thread Tarun Prabhu via cfe-commits


@@ -309,6 +309,20 @@ static void 
parseCodeGenArgs(Fortran::frontend::CodeGenOptions &opts,
   for (auto *a : args.filtered(clang::driver::options::OPT_fpass_plugin_EQ))
 opts.LLVMPassPlugins.push_back(a->getValue());
 
+  // -mprefer_vector_width option
+  if (const llvm::opt::Arg *a = args.getLastArg(
+  clang::driver::options::OPT_mprefer_vector_width_EQ)) {
+llvm::StringRef s = a->getValue();
+unsigned Width;

tarunprabhu wrote:

Flang's coding conventions are a bit different from clang. Variables names 
should start with a lowercase letter

```suggestion
unsigned width;
```

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


  1   2   3   >