[clang-tools-extra] [clangd][unittests] Limit paralelism for clangd unittests (PR #65444)

2023-09-06 Thread kadir çetinkaya via cfe-commits

https://github.com/kadircet created 
https://github.com/llvm/llvm-project/pull/65444:

None

From 0b33a1277beb1ec518cb000923d02d78365bfd82 Mon Sep 17 00:00:00 2001
From: Kadir Cetinkaya 
Date: Tue, 5 Sep 2023 19:19:47 +0200
Subject: [PATCH] [clangd][unittests] Limit paralelism for clangd unittests

We started seeing a lot of timeouts that align with the change in lit to
execute gtests in shards. The logic there assumes tests are
single-threaded, which is the case for most of the LLVM, hence they
pick #shards ~ #cores (by slightly overshooting).

There are enough unittests in clangd that rely on multi-threading, they
can create arbitrarily many threads but we limit amount of meaningful
work to ~4 thread per process.

This change ensures that we're accounting for that paralelism when
executing clangd tests and not overloading test executors.

In theory the change overestimates the requirements, not all tests are
multi-threaded, but it doesn't seem to be resulting in any regressions
on my local runs.

Fixes https://github.com/llvm/llvm-project/issues/64964.
Fixes https://github.com/clangd/clangd/issues/1712.
---
 clang-tools-extra/clangd/unittests/lit.cfg.py | 8 
 1 file changed, 8 insertions(+)

diff --git a/clang-tools-extra/clangd/unittests/lit.cfg.py 
b/clang-tools-extra/clangd/unittests/lit.cfg.py
index 48ee5f5d5ab9203..33aa9e61f4ce9dd 100644
--- a/clang-tools-extra/clangd/unittests/lit.cfg.py
+++ b/clang-tools-extra/clangd/unittests/lit.cfg.py
@@ -1,4 +1,5 @@
 import lit.formats
+import lit.util
 
 config.name = "Clangd Unit Tests"
 config.test_format = lit.formats.GoogleTest(".", "Tests")
@@ -9,6 +10,13 @@
 # FIXME: it seems every project has a copy of this logic. Move it somewhere.
 import platform
 
+# Clangd unittests uses ~4 threads per test. So make sure we don't over commit.
+core_count = lit.util.usable_core_count()
+# FIXME: Split unittests into groups that use threads, and groups that do not,
+# and only limit multi-threaded tests.
+lit_config.parallelism_groups["clangd"] = max(1, core_count // 4)
+config.parallelism_group = "clangd"
+
 if platform.system() == "Darwin":
 shlibpath_var = "DYLD_LIBRARY_PATH"
 elif platform.system() == "Windows":

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


[clang-tools-extra] [clangd][unittests] Limit paralelism for clangd unittests (PR #65444)

2023-09-06 Thread kadir çetinkaya via cfe-commits

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


[clang-tools-extra] [clangd][unittests] Limit paralelism for clangd unittests (PR #65444)

2023-09-06 Thread kadir çetinkaya via cfe-commits

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


[clang-tools-extra] [clangd][unittests] Limit paralelism for clangd unittests (PR #65444)

2023-09-06 Thread via cfe-commits

https://github.com/github-actions[bot] labeled 
https://github.com/llvm/llvm-project/pull/65444
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd][unittests] Limit paralelism for clangd unittests (PR #65444)

2023-09-06 Thread kadir çetinkaya via cfe-commits

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


[clang-tools-extra] [clangd][unittests] Limit paralelism for clangd unittests (PR #65444)

2023-09-06 Thread kadir çetinkaya via cfe-commits

kadircet wrote:

@HighCommander4 @AaronBallman FYI

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


[PATCH] D155610: [Clang][Sema] Fix display of characters on static assertion failure

2023-09-06 Thread Takuya Shimizu via Phabricator via cfe-commits
hazohelet added a comment.

@cor3ntin Gentle ping


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155610/new/

https://reviews.llvm.org/D155610

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


[clang] [AArch64]: Refactor target parser to use BitVector. (PR #65423)

2023-09-06 Thread David Green via cfe-commits

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


[PATCH] D159126: [Clang] Add captures to the instantiation scope of lambda call operators

2023-09-06 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 555973.
cor3ntin added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159126/new/

https://reviews.llvm.org/D159126

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/SemaCXX/lambda-capture-type-deduction.cpp

Index: clang/test/SemaCXX/lambda-capture-type-deduction.cpp
===
--- clang/test/SemaCXX/lambda-capture-type-deduction.cpp
+++ clang/test/SemaCXX/lambda-capture-type-deduction.cpp
@@ -260,3 +260,40 @@
 void test() { f(0);  }
 
 }
+
+namespace GH65067 {
+
+template  class a {
+public:
+  template  void c(b f) { d(f)(0); }
+  template  auto d(b f) {
+return [f = f](auto arg) -> a { return {}; };
+  }
+};
+a e;
+auto fn1() {
+  e.c([](int) {});
+}
+
+}
+
+namespace GH63675 {
+
+template  _Tp __declval();
+struct __get_tag {
+  template  void operator()(_Tag);
+};
+template  struct __basic_sender {
+  using __tag_t = decltype(__declval<_ImplFn>()(__declval<__get_tag>()));
+  _ImplFn __impl_;
+};
+auto __make_basic_sender = [](
+   _Children... __children) {
+  return __basic_sender{[... __children = __children](
+ _Fun __fun) -> decltype(__fun(__children...)) {}};
+};
+void __trans_tmp_1() {
+  __make_basic_sender(__trans_tmp_1);
+}
+
+}
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -28,6 +28,7 @@
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtObjC.h"
 #include "clang/AST/StmtOpenMP.h"
+#include "clang/AST/Type.h"
 #include "clang/Basic/DiagnosticParse.h"
 #include "clang/Basic/OpenMPKinds.h"
 #include "clang/Sema/Designator.h"
@@ -12325,7 +12326,8 @@
 template
 ExprResult
 TreeTransform::TransformCXXThisExpr(CXXThisExpr *E) {
-  QualType T = getSema().getCurrentThisType();
+
+  QualType T = getDerived().TransformType(E->getType());
 
   if (!getDerived().AlwaysRebuild() && T == E->getType()) {
 // Mark it referenced in the new context regardless.
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -12,7 +12,9 @@
 #include "TreeTransform.h"
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/ASTLambda.h"
 #include "clang/AST/ASTMutationListener.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/DeclVisitor.h"
 #include "clang/AST/DependentDiagnostic.h"
@@ -2426,6 +2428,9 @@
   cast(Owner)->isDefinedOutsideFunctionOrMethod());
   LocalInstantiationScope Scope(SemaRef, MergeWithParentScope);
 
+  Sema::LambdaScopeForCallOperatorInstantiationRAII LambdaScope(
+  SemaRef, const_cast(D), TemplateArgs, Scope);
+
   // Instantiate enclosing template arguments for friends.
   SmallVector TempParamLists;
   unsigned NumTempParamLists = 0;
Index: clang/lib/Sema/SemaLambda.cpp
===
--- clang/lib/Sema/SemaLambda.cpp
+++ clang/lib/Sema/SemaLambda.cpp
@@ -9,17 +9,19 @@
 //  This file implements semantic analysis for C++ lambda expressions.
 //
 //===--===//
-#include "clang/Sema/DeclSpec.h"
+#include "clang/Sema/SemaLambda.h"
 #include "TypeLocBuilder.h"
 #include "clang/AST/ASTLambda.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/Basic/TargetInfo.h"
+#include "clang/Sema/DeclSpec.h"
 #include "clang/Sema/Initialization.h"
 #include "clang/Sema/Lookup.h"
 #include "clang/Sema/Scope.h"
 #include "clang/Sema/ScopeInfo.h"
 #include "clang/Sema/SemaInternal.h"
-#include "clang/Sema/SemaLambda.h"
+#include "clang/Sema/Template.h"
 #include "llvm/ADT/STLExtras.h"
 #include 
 using namespace clang;
@@ -2254,3 +2256,34 @@
 
   return BuildBlock;
 }
+
+Sema::LambdaScopeForCallOperatorInstantiationRAII::
+LambdaScopeForCallOperatorInstantiationRAII(
+Sema &SemasRef, FunctionDecl *FD, MultiLevelTemplateArgumentList MLTAL,
+LocalInstantiationScope &Scope)
+: FunctionScope(SemasRef) {
+  if (!isLambdaCallOperator(FD)) {
+FunctionScope.disable();
+return;
+  }
+
+  if (FD->isTemplateInstantiation() && FD->getPrimaryTemplate()) {
+FunctionTemplateDecl *PrimaryTemplate = FD->getPrimaryTemplate();
+if (const auto *FromMemTempl =
+PrimaryTemplate->getInstantiatedFromMemberTemplate()) {
+  SemasRef.addInstantiatedCapturesToScope(
+  FD, FromMemTempl->getTemplatedDecl(), Scope, MLTAL);
+}
+  }
+
+  else if (F

[PATCH] D159126: [Clang] Add captures to the instantiation scope of lambda call operators

2023-09-06 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 555974.
cor3ntin added a comment.

Rebase and cleanups


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159126/new/

https://reviews.llvm.org/D159126

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/SemaCXX/lambda-capture-type-deduction.cpp

Index: clang/test/SemaCXX/lambda-capture-type-deduction.cpp
===
--- clang/test/SemaCXX/lambda-capture-type-deduction.cpp
+++ clang/test/SemaCXX/lambda-capture-type-deduction.cpp
@@ -260,3 +260,40 @@
 void test() { f(0);  }
 
 }
+
+namespace GH65067 {
+
+template  class a {
+public:
+  template  void c(b f) { d(f)(0); }
+  template  auto d(b f) {
+return [f = f](auto arg) -> a { return {}; };
+  }
+};
+a e;
+auto fn1() {
+  e.c([](int) {});
+}
+
+}
+
+namespace GH63675 {
+
+template  _Tp __declval();
+struct __get_tag {
+  template  void operator()(_Tag);
+};
+template  struct __basic_sender {
+  using __tag_t = decltype(__declval<_ImplFn>()(__declval<__get_tag>()));
+  _ImplFn __impl_;
+};
+auto __make_basic_sender = [](
+   _Children... __children) {
+  return __basic_sender{[... __children = __children](
+ _Fun __fun) -> decltype(__fun(__children...)) {}};
+};
+void __trans_tmp_1() {
+  __make_basic_sender(__trans_tmp_1);
+}
+
+}
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -12325,7 +12325,7 @@
 template
 ExprResult
 TreeTransform::TransformCXXThisExpr(CXXThisExpr *E) {
-  QualType T = getSema().getCurrentThisType();
+  QualType T = getDerived().TransformType(E->getType());
 
   if (!getDerived().AlwaysRebuild() && T == E->getType()) {
 // Mark it referenced in the new context regardless.
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -2426,6 +2426,9 @@
   cast(Owner)->isDefinedOutsideFunctionOrMethod());
   LocalInstantiationScope Scope(SemaRef, MergeWithParentScope);
 
+  Sema::LambdaScopeForCallOperatorInstantiationRAII LambdaScope(
+  SemaRef, const_cast(D), TemplateArgs, Scope);
+
   // Instantiate enclosing template arguments for friends.
   SmallVector TempParamLists;
   unsigned NumTempParamLists = 0;
Index: clang/lib/Sema/SemaLambda.cpp
===
--- clang/lib/Sema/SemaLambda.cpp
+++ clang/lib/Sema/SemaLambda.cpp
@@ -20,6 +20,7 @@
 #include "clang/Sema/ScopeInfo.h"
 #include "clang/Sema/SemaInternal.h"
 #include "clang/Sema/SemaLambda.h"
+#include "clang/Sema/Template.h"
 #include "llvm/ADT/STLExtras.h"
 #include 
 using namespace clang;
@@ -2254,3 +2255,34 @@
 
   return BuildBlock;
 }
+
+Sema::LambdaScopeForCallOperatorInstantiationRAII::
+LambdaScopeForCallOperatorInstantiationRAII(
+Sema &SemasRef, FunctionDecl *FD, MultiLevelTemplateArgumentList MLTAL,
+LocalInstantiationScope &Scope)
+: FunctionScope(SemasRef) {
+  if (!isLambdaCallOperator(FD)) {
+FunctionScope.disable();
+return;
+  }
+
+  if (FD->isTemplateInstantiation() && FD->getPrimaryTemplate()) {
+FunctionTemplateDecl *PrimaryTemplate = FD->getPrimaryTemplate();
+if (const auto *FromMemTempl =
+PrimaryTemplate->getInstantiatedFromMemberTemplate()) {
+  SemasRef.addInstantiatedCapturesToScope(
+  FD, FromMemTempl->getTemplatedDecl(), Scope, MLTAL);
+}
+  }
+
+  else if (FD->getTemplatedKind() == FunctionDecl::TK_MemberSpecialization ||
+   FD->getTemplatedKind() == FunctionDecl::TK_DependentNonTemplate) {
+FunctionDecl *InstantiatedFrom =
+FD->getTemplatedKind() == FunctionDecl::TK_MemberSpecialization
+? FD->getInstantiatedFromMemberFunction()
+: FD->getInstantiatedFromDecl();
+SemasRef.addInstantiatedCapturesToScope(FD, InstantiatedFrom, Scope, MLTAL);
+  }
+
+  SemasRef.RebuildLambdaScopeInfo(cast(FD));
+}
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -15380,6 +15380,10 @@
   LSI->CallOperator = CallOperator;
   LSI->Lambda = LambdaClass;
   LSI->ReturnType = CallOperator->getReturnType();
+  // This function in calls in situation where the context of the call operator
+  // is not entered, so we set AfterParameterList to false, so that
+  // `tryCaptureVariable` finds explicit captures in the appropriate context.
+  LSI->AfterParameterList = false;
   const LambdaCaptureDe

[PATCH] D159126: [Clang] Add captures to the instantiation scope of lambda call operators

2023-09-06 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

@erichkeane @aaron.ballman  This now pass the tests and is ready for review :)
Thanks to @beanz for the quick turnaround on the HLSL issue


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159126/new/

https://reviews.llvm.org/D159126

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


[clang-tools-extra] [clang-tidy][misc-include-cleaner]Avoid to insert same include header multiple times (PR #65431)

2023-09-06 Thread kadir çetinkaya via cfe-commits

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


[clang-tools-extra] [clang-tidy][misc-include-cleaner]Avoid to insert same include header multiple times (PR #65431)

2023-09-06 Thread kadir çetinkaya via cfe-commits

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

thanks!

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


[clang-tools-extra] [clang-tidy][misc-include-cleaner]Avoid to insert same include header multiple times (PR #65431)

2023-09-06 Thread kadir çetinkaya via cfe-commits


@@ -199,6 +200,9 @@ void IncludeCleanerCheck::check(const 
MatchFinder::MatchResult &Result) {
 
   tooling::HeaderIncludes HeaderIncludes(getCurrentMainFile(), Code,
  FileStyle->IncludeStyle);
+  // `tooling::HeaderIncludes::insert` will not modify `ExistingIncludes`. We
+  // should handle repeat include here

kadircet wrote:

```suggestion
  // Deduplicate insertions when running in bulk fix mode.
```

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


[clang-tools-extra] [clang-tidy][misc-include-cleaner]Avoid to insert same include header multiple times (PR #65431)

2023-09-06 Thread kadir çetinkaya via cfe-commits


@@ -224,7 +224,8 @@ Changes in existing checks
 
 - Improved :doc:`misc-include-cleaner
   ` check by adding option
-  `DeduplicateFindings` to output one finding per symbol occurrence.
+  `DeduplicateFindings` to output one finding per symbol occurrence 
+  and avoid fixes insert same include header multiple times.

kadircet wrote:

rather than `and` can you add a separate sentence?

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


[clang-tools-extra] [clang-tidy][misc-include-cleaner]Avoid to insert same include header multiple times (PR #65431)

2023-09-06 Thread kadir çetinkaya via cfe-commits


@@ -209,14 +213,17 @@ void IncludeCleanerCheck::check(const 
MatchFinder::MatchResult &Result) {
 // main file.
 if (auto Replacement =
 HeaderIncludes.insert(llvm::StringRef{Spelling}.trim("\"<>"),
-  Angled, tooling::IncludeDirective::Include))
-  diag(SM->getSpellingLoc(Inc.SymRef.RefLocation),
-   "no header providing \"%0\" is directly included")
-  << Inc.SymRef.Target.name()
-  << FixItHint::CreateInsertion(
- SM->getComposedLoc(SM->getMainFileID(),
-Replacement->getOffset()),
- Replacement->getReplacementText());
+  Angled, tooling::IncludeDirective::Include)) 
{
+  DiagnosticBuilder DB =
+  diag(SM->getSpellingLoc(Inc.SymRef.RefLocation),
+   "no header providing \"%0\" is directly included")
+  << Inc.SymRef.Target.name();
+  if (areDiagsSelfContained() ||
+  InsertedHeaders.insert(Replacement->getReplacementText()).second)

kadircet wrote:

nit: since we have multiple lines (despite being a single statement) can you 
wrap the body in `{}` ?

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


[clang] [analyzer] Reduce constraint on modulo with small concrete range (PR #65448)

2023-09-06 Thread Ding Fei via cfe-commits

https://github.com/danix800 created 
https://github.com/llvm/llvm-project/pull/65448:

Fixes #54377

>From 2b04f714f1e1985546ff7ed00c131591316782b8 Mon Sep 17 00:00:00 2001
From: dingfei 
Date: Wed, 6 Sep 2023 10:03:21 +0800
Subject: [PATCH] [analyzer] Reduce constraint on modulo with small concrete
 range

---
 .../PathSensitive/RangedConstraintManager.h   |  1 +
 clang/lib/StaticAnalyzer/Core/ExprEngine.cpp  |  3 +
 .../Core/RangeConstraintManager.cpp   | 48 +++
 .../Core/RangedConstraintManager.cpp  | 14 +
 clang/test/Analysis/constraint-assignor.c | 60 +++
 5 files changed, 126 insertions(+)

diff --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h
 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h
index 49ea006e27aa54..f350cfa1cd011c 100644
--- 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h
+++ 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h
@@ -476,6 +476,7 @@ class RangedConstraintManager : public 
SimpleConstraintManager {
   //===--===//
 private:
   static void computeAdjustment(SymbolRef &Sym, llvm::APSInt &Adjustment);
+  static void computeScaling(SymbolRef &Sym, llvm::APSInt &ConvertedInt);
 };
 
 /// Try to simplify a given symbolic expression based on the constraints in
diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp 
b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
index 0e2ac78f7089c5..670de6795f1c2d 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1702,6 +1702,9 @@ ProgramStateRef ExprEngine::escapeValues(ProgramStateRef 
State,
 
 void ExprEngine::Visit(const Stmt *S, ExplodedNode *Pred,
ExplodedNodeSet &DstTop) {
+  //  static int Count = 0;
+  //  llvm::errs() << "Count: " << Count++ << "\n";
+  //  S->dump();
   PrettyStackTraceLoc CrashInfo(getContext().getSourceManager(),
 S->getBeginLoc(), "Error evaluating 
statement");
   ExplodedNodeSet Dst;
diff --git a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
index 5de99384449a4c..9bda29c87f3c0f 100644
--- a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -2073,6 +2073,14 @@ class ConstraintAssignor : public 
ConstraintAssignorBase {
 if (Sym->getOpcode() != BO_Rem)
   return true;
 // a % b != 0 implies that a != 0.
+// Z3 verification:
+//   (declare-const a Int)
+//   (declare-const m Int)
+//   (assert (not (= m 0)))
+//   (assert (not (= (mod a m) 0)))
+//   (assert (= a 0))
+//   (check-sat)
+//   ; unsat
 if (!Constraint.containsZero()) {
   SVal SymSVal = Builder.makeSymbolVal(Sym->getLHS());
   if (auto NonLocSymSVal = SymSVal.getAs()) {
@@ -2080,6 +2088,46 @@ class ConstraintAssignor : public 
ConstraintAssignorBase {
 if (!State)
   return false;
   }
+} else if (auto *SIE = dyn_cast(Sym);
+   SIE && Constraint.encodesFalseRange()) {
+  // a % m == 0 && a in [x, y] && y - x < m implies that
+  // a = (y < 0 ? x : y) / m * m which is a 'ConcreteInt'
+  // where x and m are 'ConcreteInt'.
+  //
+  // Z3 verification:
+  //   (declare-const a Int)
+  //   (declare-const m Int)
+  //   (declare-const x Int)
+  //   (declare-const y Int)
+  //   (assert (= (mod a m) 0))
+  //   (assert (< (- y x) m))
+  //   (assert (and (>= a x) (<= a y)))
+  //   (assert (not (= a (* (div y m) m
+  //   (check-sat)
+  //   ; unsat
+  llvm::APSInt Modulo = SIE->getRHS();
+  Modulo = llvm::APSInt(Modulo.abs(), Modulo.isUnsigned());
+  RangeSet RS =
+  SymbolicRangeInferrer::inferRange(RangeFactory, State, 
SIE->getLHS());
+  if (RS.size() == 1) {
+auto R = RS.begin();
+if ((R->To() - R->From()).getExtValue() < Modulo.getExtValue()) {
+  SVal SymSVal = Builder.makeSymbolVal(SIE->getLHS());
+  if (auto NonLocSymSVal = SymSVal.getAs()) {
+auto NewConstConstraint = Builder.makeIntVal(
+(R->To() > 0 ? R->To() : R->From()) / Modulo * Modulo);
+if (auto Cond = Builder
+.evalBinOp(State, BO_EQ, *NonLocSymSVal,
+   NewConstConstraint,
+   Builder.getConditionType())
+.template getAs()) {
+  State = State->assume(*Cond, true);
+  if (!State)
+return false;
+}
+  }
+}
+  }
 }
 return true;
   }
diff --git a/clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp 
b/cla

[clang] [analyzer] Reduce constraint on modulo with small concrete range (PR #65448)

2023-09-06 Thread via cfe-commits

https://github.com/github-actions[bot] labeled 
https://github.com/llvm/llvm-project/pull/65448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Reduce constraint on modulo with small concrete range (PR #65448)

2023-09-06 Thread via cfe-commits

https://github.com/github-actions[bot] labeled 
https://github.com/llvm/llvm-project/pull/65448
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][misc-include-cleaner]Avoid to insert same include header multiple times (PR #65431)

2023-09-06 Thread kadir çetinkaya via cfe-commits

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


[clang] [AArch64]: Refactor target parser to use BitVector. (PR #65423)

2023-09-06 Thread David Spickett via cfe-commits

DavidSpickett wrote:

With just the bitvector change this is fine.

I don't disagree with splitting the test files but it should be in its own 
commit/PR.

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


[clang] [analyzer] Reduce constraint on modulo with small concrete range (PR #65448)

2023-09-06 Thread Ding Fei via cfe-commits

https://github.com/danix800 updated 
https://github.com/llvm/llvm-project/pull/65448:

>From 235f39a6a5137e53239105727798d4540e5dd563 Mon Sep 17 00:00:00 2001
From: dingfei 
Date: Wed, 6 Sep 2023 10:03:21 +0800
Subject: [PATCH] [analyzer] Reduce constraint on modulo with small concrete
 range

---
 .../Core/RangeConstraintManager.cpp   | 48 +++
 clang/test/Analysis/constraint-assignor.c | 60 +++
 2 files changed, 108 insertions(+)

diff --git a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
index 5de99384449a4c..9bda29c87f3c0f 100644
--- a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -2073,6 +2073,14 @@ class ConstraintAssignor : public 
ConstraintAssignorBase {
 if (Sym->getOpcode() != BO_Rem)
   return true;
 // a % b != 0 implies that a != 0.
+// Z3 verification:
+//   (declare-const a Int)
+//   (declare-const m Int)
+//   (assert (not (= m 0)))
+//   (assert (not (= (mod a m) 0)))
+//   (assert (= a 0))
+//   (check-sat)
+//   ; unsat
 if (!Constraint.containsZero()) {
   SVal SymSVal = Builder.makeSymbolVal(Sym->getLHS());
   if (auto NonLocSymSVal = SymSVal.getAs()) {
@@ -2080,6 +2088,46 @@ class ConstraintAssignor : public 
ConstraintAssignorBase {
 if (!State)
   return false;
   }
+} else if (auto *SIE = dyn_cast(Sym);
+   SIE && Constraint.encodesFalseRange()) {
+  // a % m == 0 && a in [x, y] && y - x < m implies that
+  // a = (y < 0 ? x : y) / m * m which is a 'ConcreteInt'
+  // where x and m are 'ConcreteInt'.
+  //
+  // Z3 verification:
+  //   (declare-const a Int)
+  //   (declare-const m Int)
+  //   (declare-const x Int)
+  //   (declare-const y Int)
+  //   (assert (= (mod a m) 0))
+  //   (assert (< (- y x) m))
+  //   (assert (and (>= a x) (<= a y)))
+  //   (assert (not (= a (* (div y m) m
+  //   (check-sat)
+  //   ; unsat
+  llvm::APSInt Modulo = SIE->getRHS();
+  Modulo = llvm::APSInt(Modulo.abs(), Modulo.isUnsigned());
+  RangeSet RS =
+  SymbolicRangeInferrer::inferRange(RangeFactory, State, 
SIE->getLHS());
+  if (RS.size() == 1) {
+auto R = RS.begin();
+if ((R->To() - R->From()).getExtValue() < Modulo.getExtValue()) {
+  SVal SymSVal = Builder.makeSymbolVal(SIE->getLHS());
+  if (auto NonLocSymSVal = SymSVal.getAs()) {
+auto NewConstConstraint = Builder.makeIntVal(
+(R->To() > 0 ? R->To() : R->From()) / Modulo * Modulo);
+if (auto Cond = Builder
+.evalBinOp(State, BO_EQ, *NonLocSymSVal,
+   NewConstConstraint,
+   Builder.getConditionType())
+.template getAs()) {
+  State = State->assume(*Cond, true);
+  if (!State)
+return false;
+}
+  }
+}
+  }
 }
 return true;
   }
diff --git a/clang/test/Analysis/constraint-assignor.c 
b/clang/test/Analysis/constraint-assignor.c
index 8210e576c98bd2..150fe20c9f37a0 100644
--- a/clang/test/Analysis/constraint-assignor.c
+++ b/clang/test/Analysis/constraint-assignor.c
@@ -5,6 +5,7 @@
 
 void clang_analyzer_warnIfReached(void);
 void clang_analyzer_eval(int);
+void clang_analyzer_dump(int);
 
 void rem_constant_rhs_ne_zero(int x, int y) {
   if (x % 3 == 0) // x % 3 != 0 -> x != 0
@@ -82,3 +83,62 @@ void remainder_with_adjustment_of_composit_lhs(int x, int y) 
{
   clang_analyzer_eval(x + y != -1);// expected-warning{{TRUE}}
   (void)(x * y); // keep the constraints alive.
 }
+
+void remainder_infeasible(int x, int y) {
+  if (x <= 2 || x >= 5)
+return;
+  if (x % 5 != 0)
+return;
+  clang_analyzer_warnIfReached(); // no-warning
+  (void)x; // keep the constraints alive.
+}
+
+void remainder_within_modulo_positive_range_unsigned(unsigned x) {
+  if (x <= 2 || x > 6)
+return;
+  clang_analyzer_dump(x); // expected-warning{{reg_$0}}
+  if (x % 5 != 0)
+return;
+  clang_analyzer_dump(x);  // expected-warning{{5 S32b}}
+  (void)x; // keep the constraints alive.
+}
+
+void remainder_within_modulo_positive_range(int x) {
+  if (x <= 2 || x > 6)
+return;
+  clang_analyzer_dump(x); // expected-warning{{reg_$0}}
+  if (x % 5 != 0)
+return;
+  clang_analyzer_dump(x);  // expected-warning{{5 S32b}}
+  (void)x; // keep the constraints alive.
+}
+
+void remainder_within_modulo_range_spans_zero(int x) {
+  if (x <= -2 || x > 2)
+return;
+  clang_analyzer_dump(x); // expected-warning{{reg_$0}}
+  if (x % 5 != 0)
+return;
+  clang_analyzer_dump(x);  // expected-warning{{0 S32b}}
+  (void)x; // keep the constraints alive.
+}
+
+void remainder_w

[PATCH] D159441: [include-cleaner] Weaken signal for boosting preferred headers

2023-09-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

see also https://github.com/llvm/llvm-project/issues/62172


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159441/new/

https://reviews.llvm.org/D159441

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


[clang] f470c36 - [clang][dataflow] Eliminate uses of `RecordValue::getChild()`. (#65329)

2023-09-06 Thread via cfe-commits

Author: martinboehme
Date: 2023-09-06T09:43:05+02:00
New Revision: f470c361d959ec21dee51f65b53412ff8a63c946

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

LOG: [clang][dataflow] Eliminate uses of `RecordValue::getChild()`. (#65329)

We want to work towards eliminating the `RecordStorageLocation` from
`RecordValue`. These particular uses of `RecordValue::getChild()` can
simply
be replaced with `RecordStorageLocation::getChild()`.

Added: 


Modified: 
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Removed: 




diff  --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index 0a5cf62e5ea2332..ff3618e999f004a 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -2860,11 +2860,11 @@ TEST(TransferTest, AggregateInitialization) {
 
   // Check that fields initialized in an initializer list are always
   // modeled in other instances of the same type.
-  const auto &OtherBVal =
-  getValueForDecl(ASTCtx, Env, "OtherB");
-  EXPECT_THAT(OtherBVal.getChild(*BarDecl), NotNull());
-  EXPECT_THAT(OtherBVal.getChild(*BazDecl), NotNull());
-  EXPECT_THAT(OtherBVal.getChild(*QuxDecl), NotNull());
+  const auto &OtherBLoc =
+  getLocForDecl(ASTCtx, Env, "OtherB");
+  EXPECT_THAT(OtherBLoc.getChild(*BarDecl), NotNull());
+  EXPECT_THAT(OtherBLoc.getChild(*BazDecl), NotNull());
+  EXPECT_THAT(OtherBLoc.getChild(*QuxDecl), NotNull());
 });
   }
 }



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


[clang] [clang][dataflow] Eliminate uses of `RecordValue::getChild()`. (PR #65329)

2023-09-06 Thread via cfe-commits

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


[clang-tools-extra] [lit] Are all RUN lines skipped in windows cmd? (PR #65242)

2023-09-06 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

Whatever we do, I consider it important for us to understand how widely `cmd` 
is used.

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


[clang] be12f26 - [clang][dataflow][NFC] Remove stale comment. (#65322)

2023-09-06 Thread via cfe-commits

Author: martinboehme
Date: 2023-09-06T09:52:30+02:00
New Revision: be12f26dc00cad8bcd575b176a453a1c7c4fdff5

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

LOG: [clang][dataflow][NFC] Remove stale comment. (#65322)

Added: 


Modified: 
clang/unittests/Analysis/FlowSensitive/TestingSupport.h

Removed: 




diff  --git a/clang/unittests/Analysis/FlowSensitive/TestingSupport.h 
b/clang/unittests/Analysis/FlowSensitive/TestingSupport.h
index 44dbf27a7458677..c61e9f26beff40b 100644
--- a/clang/unittests/Analysis/FlowSensitive/TestingSupport.h
+++ b/clang/unittests/Analysis/FlowSensitive/TestingSupport.h
@@ -465,10 +465,6 @@ inline Value *getFieldValue(const RecordStorageLocation 
*Loc,
 
 /// Returns the value of a `Field` on a `Struct.
 /// Returns null if `Struct` is null.
-///
-/// Note: This function currently does not use the `Env` parameter, but it will
-/// soon be needed to look up the `Value` when `setChild()` changes to return a
-/// `StorageLocation *`.
 inline Value *getFieldValue(const RecordValue *Struct, const ValueDecl &Field,
 const Environment &Env) {
   if (Struct == nullptr)



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


[clang] [clang][dataflow][NFC] Remove stale comment. (PR #65322)

2023-09-06 Thread via cfe-commits

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


[PATCH] D159284: [clang][dataflow] Fix Record initialization with InitListExpr and inheritances

2023-09-06 Thread Martin Böhme via Phabricator via cfe-commits
mboehme accepted this revision.
mboehme added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp:2498
+TEST(TransferTest, ReturnStructWithInheritance) {
+  // This is a crash repro. (Returning a struct involves copy/move constructor)
+  std::string Code = R"(

kinu wrote:
> mboehme wrote:
> > kinu wrote:
> > > mboehme wrote:
> > > > I don't think this is true -- the `return S1` in `target()` will use 
> > > > NRVO.
> > > > 
> > > > But I also don't think it's relevant -- I believe the crash this is 
> > > > reproducing was triggered by the `InitListExpr`, not the return 
> > > > statement?
> > > > 
> > > > Given the other tests added in this patch, do we need this test?
> > > It will use NRVO but in AST this still seems to generate CXXConstructExpr 
> > > with isCopyOrMoveConstructor() == true because omitting the ctor is not 
> > > mandatory in compilers.
> > > 
> > > I can drop this one, but I'm also a bit torn because this was the 
> > > original crash repro that puzzled me a bit.
> > > 
> > > I refined the comment to explain it a bit better; how does it look now?
> > > It will use NRVO but in AST this still seems to generate CXXConstructExpr 
> > > with isCopyOrMoveConstructor() == true
> > 
> > Ah, true, I see this now:
> > 
> > https://godbolt.org/z/z9enG8cW7
> > 
> > > because omitting the ctor is not mandatory in compilers.
> > 
> > TIL that NRVO [isn't 
> > guaranteed](https://en.cppreference.com/w/cpp/language/copy_elision). (I 
> > always thought it was!)
> > 
> > I'm still pretty sure though that the `CXXConstructExpr` will have 
> > `isElidable() == true`, and in this case we [don't call 
> > `copyRecord()`](https://github.com/llvm/llvm-project/blob/6c6a2d3445671ada6a58b9ab5ce4a1e11e3dd610/clang/lib/Analysis/FlowSensitive/Transfer.cpp#L474):
> > 
> > ```
> >   if (S->isElidable()) {
> > if (Value *Val = Env.getValue(*ArgLoc))
> >   Env.setValue(*S, *Val);
> >   } else {
> > auto &Val = *cast(Env.createValue(S->getType()));
> > Env.setValue(*S, Val);
> > copyRecord(*ArgLoc, Val.getLoc(), Env);
> >   }
> > ```
> > 
> > So I'm not sure that this repro actually triggers the crash? (Can you 
> > verify? If it does trigger the crash, where am I going wrong in my thinking 
> > above?)
> > 
> > > I can drop this one, but I'm also a bit torn because this was the 
> > > original crash repro that puzzled me a bit.
> > 
> > OK, good to know that this is the original scenario that triggered the 
> > crash.
> > 
> > I still think it would be OK to keep only 
> > AssignmentOperatorWithInitAndInheritance because it also triggers a call to 
> > `copyRecord()` but does so in a more obvious fashion. And I think for a 
> > test it's actually useful if it's obvious what is happening.
> 
> > I'm still pretty sure though that the `CXXConstructExpr` will have 
> > `isElidable() == true`, and in this case we [don't call 
> > `copyRecord()`](https://github.com/llvm/llvm-project/blob/6c6a2d3445671ada6a58b9ab5ce4a1e11e3dd610/clang/lib/Analysis/FlowSensitive/Transfer.cpp#L474):
> 
> Interesting, so I looked into it:
> 
> Looks like after C++17 isElidable is no longer used in AST:
> https://github.com/llvm/llvm-project/blob/2a603deec49cb6a27f3a29480ed8a133eef31cee/clang/include/clang/ASTMatchers/ASTMatchers.h#L8351
> 
> (So this test code doesn't take the branch)
> 
> NRVO seems to be handled around ReturnStmt, not in each Expr:
> https://github.com/llvm/llvm-project/blob/2a603deec49cb6a27f3a29480ed8a133eef31cee/clang/lib/AST/Stmt.cpp#L1202
> 
> > [...] because it also triggers a call to `copyRecord()` but does so in a 
> > more obvious fashion. And I think for a test it's actually useful if it's 
> > obvious what is happening.
> 
> Makes sense, now I dropped this.
> 
> > I'm still pretty sure though that the `CXXConstructExpr` will have 
> > `isElidable() == true`, and in this case we [don't call 
> > `copyRecord()`](https://github.com/llvm/llvm-project/blob/6c6a2d3445671ada6a58b9ab5ce4a1e11e3dd610/clang/lib/Analysis/FlowSensitive/Transfer.cpp#L474):
> 
> Interesting, so I looked into it:
> 
> Looks like after C++17 isElidable is no longer used in AST:
> https://github.com/llvm/llvm-project/blob/2a603deec49cb6a27f3a29480ed8a133eef31cee/clang/include/clang/ASTMatchers/ASTMatchers.h#L8351
> 
> (So this test code doesn't take the branch)

Interesting -- wasn't aware!

> NRVO seems to be handled around ReturnStmt, not in each Expr:
> https://github.com/llvm/llvm-project/blob/2a603deec49cb6a27f3a29480ed8a133eef31cee/clang/lib/AST/Stmt.cpp#L1202

Thanks for the pointer, makes sese!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159284/new/

https://reviews.llvm.org/D159284

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

[clang] [clang][dataflow] Emit an error if source code is not compiled as C++. (PR #65301)

2023-09-06 Thread via cfe-commits

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


[clang] c0703ea - [clang][dataflow] Emit an error if source code is not compiled as C++. (#65301)

2023-09-06 Thread via cfe-commits

Author: martinboehme
Date: 2023-09-06T10:02:21+02:00
New Revision: c0703eaec1df4cde861f15e244507ef79f2d3d82

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

LOG: [clang][dataflow] Emit an error if source code is not compiled as C++. 
(#65301)

The shape of certain elements of the AST can vary depending on the
langugage.
We currently only support C++.

Added: 


Modified: 
clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Removed: 




diff  --git a/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp 
b/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
index 7f9bc31bd41f2dd..004b7711a869d17 100644
--- a/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
+++ b/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
@@ -84,6 +84,13 @@ ControlFlowContext::build(const Decl &D, Stmt &S, ASTContext 
&C) {
 std::make_error_code(std::errc::invalid_argument),
 "Cannot analyze templated declarations");
 
+  // The shape of certain elements of the AST can vary depending on the
+  // language. We currently only support C++.
+  if (!C.getLangOpts().CPlusPlus)
+return llvm::createStringError(
+std::make_error_code(std::errc::invalid_argument),
+"Can only analyze C++");
+
   CFG::BuildOptions Options;
   Options.PruneTriviallyFalseEdges = true;
   Options.AddImplicitDtors = true;

diff  --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index ff3618e999f004a..28d062196cb07bf 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -70,6 +70,16 @@ const Formula &getFormula(const ValueDecl &D, const 
Environment &Env) {
   return cast(Env.getValue(D))->formula();
 }
 
+TEST(TransferTest, CNotSupported) {
+  std::string Code = R"(
+void target() {}
+  )";
+  ASSERT_THAT_ERROR(checkDataflowWithNoopAnalysis(
+Code, [](const auto &, auto &) {}, {BuiltinOptions{}},
+LangStandard::lang_c89),
+llvm::FailedWithMessage("Can only analyze C++"));
+}
+
 TEST(TransferTest, IntVarDeclNotTrackedWhenTransferDisabled) {
   std::string Code = R"(
 void target() {



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


[clang] [clang][dataflow] Merge `RecordValue`s with different locations correctly. (PR #65319)

2023-09-06 Thread via cfe-commits


@@ -121,18 +121,18 @@ static Value *mergeDistinctValues(QualType Type, Value 
&Val1,
 
   Value *MergedVal = nullptr;
   if (auto *RecordVal1 = dyn_cast(&Val1)) {
-[[maybe_unused]] auto *RecordVal2 = cast(&Val2);
-
-// Values to be merged are always associated with the same location in
-// `LocToVal`. The location stored in `RecordVal` should therefore also
-// be the same.
-assert(&RecordVal1->getLoc() == &RecordVal2->getLoc());
-
-// `RecordVal1` and `RecordVal2` may have different properties associated
-// with them. Create a new `RecordValue` without any properties so that we
-// soundly approximate both values. If a particular analysis needs to merge
-// properties, it should do so in `DataflowAnalysis::merge()`.
-MergedVal = &MergedEnv.create(RecordVal1->getLoc());
+auto *RecordVal2 = cast(&Val2);
+
+if (&RecordVal1->getLoc() == &RecordVal2->getLoc())
+  // `RecordVal1` and `RecordVal2` may have different properties associated
+  // with them. Create a new `RecordValue` without any properties so that 
we
+  // soundly approximate both values. If a particular analysis needs to
+  // merge properties, it should do so in `DataflowAnalysis::merge()`.
+  MergedVal = &MergedEnv.create(RecordVal1->getLoc());
+else
+  // If the locations for the two records are different, need to create a
+  // completely new value.

martinboehme wrote:

Not sure exactly what you mean...

Whether the locations are the same or not doesn't really depend on the order in 
which we process CFG blocks. Instead, locations are guaranteed to be the same 
if the `RecordValue` is stored in `ExprToLoc`, and they are usually (but not 
always) different if the `RecordValue` is stored in `ExprToVal`.

The order in which we process CFG blocks affects whether we actually see 
different `RecordValue`s or not when the merge happens -- which makes merges 
difficult to trigger reliably from an integration test 
([example](https://github.com/google/crubit/blob/3ab9d49fde5a59262903c589bb6963b8db4c0541/nullability/test/merge.cc#L342)).
 But I'm not sure how relevant that is to the situation here?

Anyway, my hope is that all of this will go away relatively soon because we're 
now working on eliminating the `RecordStorageLocation` from `RecordValue`.

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


[clang] [clang][dataflow] Merge `RecordValue`s with different locations correctly. (PR #65319)

2023-09-06 Thread via cfe-commits


@@ -121,18 +121,18 @@ static Value *mergeDistinctValues(QualType Type, Value 
&Val1,
 
   Value *MergedVal = nullptr;
   if (auto *RecordVal1 = dyn_cast(&Val1)) {
-[[maybe_unused]] auto *RecordVal2 = cast(&Val2);
-
-// Values to be merged are always associated with the same location in
-// `LocToVal`. The location stored in `RecordVal` should therefore also
-// be the same.
-assert(&RecordVal1->getLoc() == &RecordVal2->getLoc());
-
-// `RecordVal1` and `RecordVal2` may have different properties associated
-// with them. Create a new `RecordValue` without any properties so that we
-// soundly approximate both values. If a particular analysis needs to merge
-// properties, it should do so in `DataflowAnalysis::merge()`.
-MergedVal = &MergedEnv.create(RecordVal1->getLoc());
+auto *RecordVal2 = cast(&Val2);
+
+if (&RecordVal1->getLoc() == &RecordVal2->getLoc())
+  // `RecordVal1` and `RecordVal2` may have different properties associated
+  // with them. Create a new `RecordValue` without any properties so that 
we
+  // soundly approximate both values. If a particular analysis needs to
+  // merge properties, it should do so in `DataflowAnalysis::merge()`.

martinboehme wrote:

I see what you're saying. However, if I put this part of the comment ("If a 
particular analysis needs to merge properties...") above the if statement, it 
would read a bit strangely -- because in the case where the locations aren't 
the same, it's clear we need to create a new `RecordValue` anyway, and this 
will of course remove any properties.

What I'm trying to explain here is that we need to create a new `RecordValue` 
even if the location is the same, because the properties may be different -- 
and that therefore the analysis needs to merge properties even in this case. 
Does that make sense?

Open to suggestions on how I could clarify this.

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


[PATCH] D158804: [Clang] Fix crash in Parser::ParseDirectDeclarator by adding check that token is not an annotation token

2023-09-06 Thread Nathan Ridge via Phabricator via cfe-commits
nridge accepted this revision.
nridge added a subscriber: rjmccall.
nridge added a comment.
This revision is now accepted and ready to land.

I'm not well versed in the parser code, but the fix clearly avoids the 
assertion in `getIdentifierInfo()`, and both @aaron.ballman and @rjmccall 
indicated in the issue discussion that this fix is appropriate, so I will take 
the liberty of approving this.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158804/new/

https://reviews.llvm.org/D158804

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


[clang] [AArch64]: Refactor target parser to use BitVector. (PR #65423)

2023-09-06 Thread via cfe-commits

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


[clang] [AArch64]: Refactor target parser to use BitVector. (PR #65423)

2023-09-06 Thread via cfe-commits




sdesmalen-arm wrote:

Would it have been possible to change ARMCPUTestParams to give it two 
constructors, one taking a uint64_t mask (for the ARM features), and the other 
constructor taking a BitVector (for the AArch64 features), and then to have the 
classes work on a BitVector under the hood?

For example, it's possible to convert a bitmask -> BitVector with a simple loop:
```uint64_t Mask = ... // the mask you want to convert to a BitVector
BitVector V(64);
for (unsigned I=0; I<64; ++I) {
  if ((Mask >> I) & 1)
V.set(I);
}
```

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


[clang] [AArch64]: Refactor target parser to use BitVector. (PR #65423)

2023-09-06 Thread via cfe-commits


@@ -260,7 +262,7 @@ inline constexpr ExtensionInfo Extensions[] = {
 {"tme", AArch64::AEK_TME, "+tme", "-tme", FEAT_MAX, "", 0},
 {"wfxt", AArch64::AEK_NONE, {}, {}, FEAT_WFXT, "+wfxt", 550},
 {"gcs", AArch64::AEK_GCS, "+gcs", "-gcs", FEAT_MAX, "", 0},
-// Special cases
+// Special cases

sdesmalen-arm wrote:

nit: unrelated change

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


[clang] [AArch64]: Refactor target parser to use BitVector. (PR #65423)

2023-09-06 Thread via cfe-commits


@@ -315,23 +317,23 @@ struct ArchInfo {
 };
 
 // clang-format off
-inline constexpr ArchInfo ARMV8A= { VersionTuple{8, 0}, AProfile, 
"armv8-a", "+v8a", (AArch64::AEK_FP | AArch64::AEK_SIMD), };
-inline constexpr ArchInfo ARMV8_1A  = { VersionTuple{8, 1}, AProfile, 
"armv8.1-a", "+v8.1a", (ARMV8A.DefaultExts | AArch64::AEK_CRC | 
AArch64::AEK_LSE | AArch64::AEK_RDM)};
-inline constexpr ArchInfo ARMV8_2A  = { VersionTuple{8, 2}, AProfile, 
"armv8.2-a", "+v8.2a", (ARMV8_1A.DefaultExts | AArch64::AEK_RAS)};
-inline constexpr ArchInfo ARMV8_3A  = { VersionTuple{8, 3}, AProfile, 
"armv8.3-a", "+v8.3a", (ARMV8_2A.DefaultExts | AArch64::AEK_RCPC)};
-inline constexpr ArchInfo ARMV8_4A  = { VersionTuple{8, 4}, AProfile, 
"armv8.4-a", "+v8.4a", (ARMV8_3A.DefaultExts | AArch64::AEK_DOTPROD)};
-inline constexpr ArchInfo ARMV8_5A  = { VersionTuple{8, 5}, AProfile, 
"armv8.5-a", "+v8.5a", (ARMV8_4A.DefaultExts)};
-inline constexpr ArchInfo ARMV8_6A  = { VersionTuple{8, 6}, AProfile, 
"armv8.6-a", "+v8.6a", (ARMV8_5A.DefaultExts | AArch64::AEK_BF16 | 
AArch64::AEK_I8MM)};
-inline constexpr ArchInfo ARMV8_7A  = { VersionTuple{8, 7}, AProfile, 
"armv8.7-a", "+v8.7a", (ARMV8_6A.DefaultExts)};
-inline constexpr ArchInfo ARMV8_8A  = { VersionTuple{8, 8}, AProfile, 
"armv8.8-a", "+v8.8a", (ARMV8_7A.DefaultExts | AArch64::AEK_MOPS | 
AArch64::AEK_HBC)};
-inline constexpr ArchInfo ARMV8_9A  = { VersionTuple{8, 9}, AProfile, 
"armv8.9-a", "+v8.9a", (ARMV8_8A.DefaultExts | AArch64::AEK_SPECRES2 | 
AArch64::AEK_CSSC | AArch64::AEK_RASv2)};
-inline constexpr ArchInfo ARMV9A= { VersionTuple{9, 0}, AProfile, 
"armv9-a", "+v9a", (ARMV8_5A.DefaultExts | AArch64::AEK_FP16 | AArch64::AEK_SVE 
| AArch64::AEK_SVE2)};
-inline constexpr ArchInfo ARMV9_1A  = { VersionTuple{9, 1}, AProfile, 
"armv9.1-a", "+v9.1a", (ARMV9A.DefaultExts | AArch64::AEK_BF16 | 
AArch64::AEK_I8MM)};
-inline constexpr ArchInfo ARMV9_2A  = { VersionTuple{9, 2}, AProfile, 
"armv9.2-a", "+v9.2a", (ARMV9_1A.DefaultExts)};
-inline constexpr ArchInfo ARMV9_3A  = { VersionTuple{9, 3}, AProfile, 
"armv9.3-a", "+v9.3a", (ARMV9_2A.DefaultExts | AArch64::AEK_MOPS | 
AArch64::AEK_HBC)};
-inline constexpr ArchInfo ARMV9_4A  = { VersionTuple{9, 4}, AProfile, 
"armv9.4-a", "+v9.4a", (ARMV9_3A.DefaultExts | AArch64::AEK_SPECRES2 | 
AArch64::AEK_CSSC | AArch64::AEK_RASv2)};
+inline ArchInfo ARMV8A= { VersionTuple{8, 0}, AProfile, "armv8-a", "+v8a", 
(BitVector(AEK_EXTENTIONS_NUM).set(AArch64::AEK_FP).set(AArch64::AEK_SIMD)), };
+inline ArchInfo ARMV8_1A  = { VersionTuple{8, 1}, AProfile, "armv8.1-a", 
"+v8.1a", 
(BitVector(ARMV8A.DefaultExts).set(AArch64::AEK_CRC).set(AArch64::AEK_LSE).set(AArch64::AEK_RDM))};

sdesmalen-arm wrote:

This line looks like it exceeds the 80char limit, please run clang-format on 
this file.

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


[clang] [AArch64]: Refactor target parser to use BitVector. (PR #65423)

2023-09-06 Thread via cfe-commits

https://github.com/sdesmalen-arm commented:

Seems like a sensible refactor, we're going to run out of bits eventually.

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


[clang] [AArch64]: Refactor target parser to use BitVector. (PR #65423)

2023-09-06 Thread Lucas Duarte Prates via cfe-commits


@@ -315,23 +317,23 @@ struct ArchInfo {
 };
 
 // clang-format off
-inline constexpr ArchInfo ARMV8A= { VersionTuple{8, 0}, AProfile, 
"armv8-a", "+v8a", (AArch64::AEK_FP | AArch64::AEK_SIMD), };
-inline constexpr ArchInfo ARMV8_1A  = { VersionTuple{8, 1}, AProfile, 
"armv8.1-a", "+v8.1a", (ARMV8A.DefaultExts | AArch64::AEK_CRC | 
AArch64::AEK_LSE | AArch64::AEK_RDM)};
-inline constexpr ArchInfo ARMV8_2A  = { VersionTuple{8, 2}, AProfile, 
"armv8.2-a", "+v8.2a", (ARMV8_1A.DefaultExts | AArch64::AEK_RAS)};
-inline constexpr ArchInfo ARMV8_3A  = { VersionTuple{8, 3}, AProfile, 
"armv8.3-a", "+v8.3a", (ARMV8_2A.DefaultExts | AArch64::AEK_RCPC)};
-inline constexpr ArchInfo ARMV8_4A  = { VersionTuple{8, 4}, AProfile, 
"armv8.4-a", "+v8.4a", (ARMV8_3A.DefaultExts | AArch64::AEK_DOTPROD)};
-inline constexpr ArchInfo ARMV8_5A  = { VersionTuple{8, 5}, AProfile, 
"armv8.5-a", "+v8.5a", (ARMV8_4A.DefaultExts)};
-inline constexpr ArchInfo ARMV8_6A  = { VersionTuple{8, 6}, AProfile, 
"armv8.6-a", "+v8.6a", (ARMV8_5A.DefaultExts | AArch64::AEK_BF16 | 
AArch64::AEK_I8MM)};
-inline constexpr ArchInfo ARMV8_7A  = { VersionTuple{8, 7}, AProfile, 
"armv8.7-a", "+v8.7a", (ARMV8_6A.DefaultExts)};
-inline constexpr ArchInfo ARMV8_8A  = { VersionTuple{8, 8}, AProfile, 
"armv8.8-a", "+v8.8a", (ARMV8_7A.DefaultExts | AArch64::AEK_MOPS | 
AArch64::AEK_HBC)};
-inline constexpr ArchInfo ARMV8_9A  = { VersionTuple{8, 9}, AProfile, 
"armv8.9-a", "+v8.9a", (ARMV8_8A.DefaultExts | AArch64::AEK_SPECRES2 | 
AArch64::AEK_CSSC | AArch64::AEK_RASv2)};
-inline constexpr ArchInfo ARMV9A= { VersionTuple{9, 0}, AProfile, 
"armv9-a", "+v9a", (ARMV8_5A.DefaultExts | AArch64::AEK_FP16 | AArch64::AEK_SVE 
| AArch64::AEK_SVE2)};
-inline constexpr ArchInfo ARMV9_1A  = { VersionTuple{9, 1}, AProfile, 
"armv9.1-a", "+v9.1a", (ARMV9A.DefaultExts | AArch64::AEK_BF16 | 
AArch64::AEK_I8MM)};
-inline constexpr ArchInfo ARMV9_2A  = { VersionTuple{9, 2}, AProfile, 
"armv9.2-a", "+v9.2a", (ARMV9_1A.DefaultExts)};
-inline constexpr ArchInfo ARMV9_3A  = { VersionTuple{9, 3}, AProfile, 
"armv9.3-a", "+v9.3a", (ARMV9_2A.DefaultExts | AArch64::AEK_MOPS | 
AArch64::AEK_HBC)};
-inline constexpr ArchInfo ARMV9_4A  = { VersionTuple{9, 4}, AProfile, 
"armv9.4-a", "+v9.4a", (ARMV9_3A.DefaultExts | AArch64::AEK_SPECRES2 | 
AArch64::AEK_CSSC | AArch64::AEK_RASv2)};
+inline ArchInfo ARMV8A= { VersionTuple{8, 0}, AProfile, "armv8-a", "+v8a", 
(BitVector(AEK_EXTENTIONS_NUM).set(AArch64::AEK_FP).set(AArch64::AEK_SIMD)), };

pratlucas wrote:

Could we have a constructor for `ArchInfo` that takes a list of `ArchExtKind`s 
as an argument (e.g. an initialiser_list)? This would make these lines less 
verbose and a bit more readable.

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


[clang] [AArch64]: Refactor target parser to use BitVector. (PR #65423)

2023-09-06 Thread Lucas Duarte Prates via cfe-commits


@@ -96,64 +97,65 @@ static_assert(FEAT_MAX <= 64,
 // Arch extension modifiers for CPUs. These are labelled with their Arm ARM
 // feature name (though the canonical reference for those is AArch64.td)
 // clang-format off
-enum ArchExtKind : uint64_t {
-  AEK_NONE =1,
-  AEK_CRC = 1 << 1,  // FEAT_CRC32
-  AEK_CRYPTO =  1 << 2,
-  AEK_FP =  1 << 3,  // FEAT_FP
-  AEK_SIMD =1 << 4,  // FEAT_AdvSIMD
-  AEK_FP16 =1 << 5,  // FEAT_FP16
-  AEK_PROFILE = 1 << 6,  // FEAT_SPE
-  AEK_RAS = 1 << 7,  // FEAT_RAS, FEAT_RASv1p1
-  AEK_LSE = 1 << 8,  // FEAT_LSE
-  AEK_SVE = 1 << 9,  // FEAT_SVE
-  AEK_DOTPROD = 1 << 10, // FEAT_DotProd
-  AEK_RCPC =1 << 11, // FEAT_LRCPC
-  AEK_RDM = 1 << 12, // FEAT_RDM
-  AEK_SM4 = 1 << 13, // FEAT_SM4, FEAT_SM3
-  AEK_SHA3 =1 << 14, // FEAT_SHA3, FEAT_SHA512
-  AEK_SHA2 =1 << 15, // FEAT_SHA1, FEAT_SHA256
-  AEK_AES = 1 << 16, // FEAT_AES, FEAT_PMULL
-  AEK_FP16FML = 1 << 17, // FEAT_FHM
-  AEK_RAND =1 << 18, // FEAT_RNG
-  AEK_MTE = 1 << 19, // FEAT_MTE, FEAT_MTE2
-  AEK_SSBS =1 << 20, // FEAT_SSBS, FEAT_SSBS2
-  AEK_SB =  1 << 21, // FEAT_SB
-  AEK_PREDRES = 1 << 22, // FEAT_SPECRES
-  AEK_SVE2 =1 << 23, // FEAT_SVE2
-  AEK_SVE2AES = 1 << 24, // FEAT_SVE_AES, FEAT_SVE_PMULL128
-  AEK_SVE2SM4 = 1 << 25, // FEAT_SVE_SM4
-  AEK_SVE2SHA3 =1 << 26, // FEAT_SVE_SHA3
-  AEK_SVE2BITPERM = 1 << 27, // FEAT_SVE_BitPerm
-  AEK_TME = 1 << 28, // FEAT_TME
-  AEK_BF16 =1 << 29, // FEAT_BF16
-  AEK_I8MM =1 << 30, // FEAT_I8MM
-  AEK_F32MM =   1ULL << 31, // FEAT_F32MM
-  AEK_F64MM =   1ULL << 32, // FEAT_F64MM
-  AEK_LS64 =1ULL << 33, // FEAT_LS64, FEAT_LS64_V, FEAT_LS64_ACCDATA
-  AEK_BRBE =1ULL << 34, // FEAT_BRBE
-  AEK_PAUTH =   1ULL << 35, // FEAT_PAuth
-  AEK_FLAGM =   1ULL << 36, // FEAT_FlagM
-  AEK_SME = 1ULL << 37, // FEAT_SME
-  AEK_SMEF64F64 =   1ULL << 38, // FEAT_SME_F64F64
-  AEK_SMEI16I64 =   1ULL << 39, // FEAT_SME_I16I64
-  AEK_HBC = 1ULL << 40, // FEAT_HBC
-  AEK_MOPS =1ULL << 41, // FEAT_MOPS
-  AEK_PERFMON = 1ULL << 42, // FEAT_PMUv3
-  AEK_SME2 =1ULL << 43, // FEAT_SME2
-  AEK_SVE2p1 =  1ULL << 44, // FEAT_SVE2p1
-  AEK_SME2p1 =  1ULL << 45, // FEAT_SME2p1
-  AEK_B16B16 =  1ULL << 46, // FEAT_B16B16
-  AEK_SMEF16F16 =   1ULL << 47, // FEAT_SMEF16F16
-  AEK_CSSC =1ULL << 48, // FEAT_CSSC
-  AEK_RCPC3 =   1ULL << 49, // FEAT_LRCPC3
-  AEK_THE = 1ULL << 50, // FEAT_THE
-  AEK_D128 =1ULL << 51, // FEAT_D128
-  AEK_LSE128 =  1ULL << 52, // FEAT_LSE128
-  AEK_SPECRES2 =1ULL << 53, // FEAT_SPECRES2
-  AEK_RASv2 =   1ULL << 54, // FEAT_RASv2
-  AEK_ITE = 1ULL << 55, // FEAT_ITE
-  AEK_GCS = 1ULL << 56, // FEAT_GCS
+enum ArchExtKind : int {

pratlucas wrote:

Since the enum will no longer represent a bit map, can it be made an `enum 
class`?

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


[PATCH] D157610: [include-cleaner][clangd][clang-tidy] Ignore resource dir during include-cleaner analysis.

2023-09-06 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 555985.
VitaNuo added a comment.

Fix analysis test to properly recognize the resource directory.
Use HeaderSearch->getModuleMap().BuiltinDir to find out the resource directory.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157610/new/

https://reviews.llvm.org/D157610

Files:
  clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -273,6 +273,32 @@
   EXPECT_THAT(Results.Unused, testing::IsEmpty());
 }
 
+TEST_F(AnalyzeTest, ResourceDirIsIgnored) {
+  Inputs.ExtraArgs.push_back("-resource-dir");
+  Inputs.ExtraArgs.push_back("resources");
+  Inputs.ExtraArgs.push_back("-internal-isystem");
+  Inputs.ExtraArgs.push_back("resources/include");
+  Inputs.Code = R"cpp(
+#include 
+#include 
+void baz() {
+  bar();
+}
+  )cpp";
+  Inputs.ExtraFiles["resources/include/amintrin.h"] = "";
+  Inputs.ExtraFiles["resources/include/emintrin.h"] = guard(R"cpp(
+void bar();
+  )cpp");
+  Inputs.ExtraFiles["resources/include/imintrin.h"] = guard(R"cpp(
+#include 
+  )cpp");
+  TestAST AST(Inputs);
+  auto Results = analyze({}, {}, PP.Includes, &PI, AST.sourceManager(),
+ AST.preprocessor().getHeaderSearchInfo());
+  EXPECT_THAT(Results.Unused, testing::IsEmpty());
+  EXPECT_THAT(Results.Missing, testing::IsEmpty());
+}
+
 TEST(FixIncludes, Basic) {
   llvm::StringRef Code = R"cpp(#include "d.h"
 #include "a.h"
Index: clang-tools-extra/include-cleaner/lib/Analysis.cpp
===
--- clang-tools-extra/include-cleaner/lib/Analysis.cpp
+++ clang-tools-extra/include-cleaner/lib/Analysis.cpp
@@ -13,6 +13,7 @@
 #include "clang-include-cleaner/Types.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
+#include "clang/Basic/DirectoryEntry.h"
 #include "clang/Basic/FileEntry.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Format/Format.h"
@@ -68,12 +69,17 @@
   llvm::StringSet<> Missing;
   if (!HeaderFilter)
 HeaderFilter = [](llvm::StringRef) { return false; };
+  const DirectoryEntry *ResourceDir = HS.getModuleMap().getBuiltinDir();
   walkUsed(ASTRoots, MacroRefs, PI, SM,
[&](const SymbolReference &Ref, llvm::ArrayRef Providers) {
  bool Satisfied = false;
  for (const Header &H : Providers) {
-   if (H.kind() == Header::Physical && H.physical() == MainFile)
+   if (H.kind() == Header::Physical &&
+   (H.physical() == MainFile ||
+H.physical()->getDir() == ResourceDir)) {
  Satisfied = true;
+ continue;
+   }
for (const Include *I : Inc.match(H)) {
  Used.insert(I);
  Satisfied = true;
@@ -88,7 +94,8 @@
   AnalysisResults Results;
   for (const Include &I : Inc.all()) {
 if (Used.contains(&I) || !I.Resolved ||
-HeaderFilter(I.Resolved->getFileEntry().tryGetRealPathName()))
+HeaderFilter(I.Resolved->getFileEntry().tryGetRealPathName()) ||
+I.Resolved->getFileEntry().getDir() == ResourceDir)
   continue;
 if (PI) {
   if (PI->shouldKeep(*I.Resolved))
Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -574,6 +574,29 @@
   EXPECT_THAT(Findings.UnusedIncludes, IsEmpty());
 }
 
+TEST(IncludeCleaner, ResourceDirIsIgnored) {
+  auto TU = TestTU::withCode(R"cpp(
+#include 
+#include 
+void baz() {
+  bar();
+}
+  )cpp");
+  TU.ExtraArgs.push_back("-resource-dir");
+  TU.ExtraArgs.push_back(testPath("resources"));
+  TU.AdditionalFiles["resources/include/amintrin.h"] = "";
+  TU.AdditionalFiles["resources/include/imintrin.h"] = guard(R"cpp(
+#include 
+  )cpp");
+  TU.AdditionalFiles["resources/include/emintrin.h"] = guard(R"cpp(
+void bar();
+  )cpp");
+  auto AST = TU.build();
+  auto Findings = computeIncludeCleanerFindings(AST);
+  EXPECT_THAT(Findings.UnusedIncludes, IsEmpty());
+  EXPECT_THAT(Findings.MissingIncludes, IsEmpty());
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
=

[PATCH] D152793: [RISCV] Add MC layer support for Zicfiss.

2023-09-06 Thread Su Hsien Ho via Phabricator via cfe-commits
SuH added inline comments.



Comment at: llvm/lib/Target/RISCV/RISCVInstrInfoZicfiss.td:76
+let Uses = [SSP], Defs = [SSP], hasSideEffects = 0, mayLoad = 0, mayStore = 1 
in {
+def SSPUSH : RVInstR<0b1000101, 0b100, OPC_SYSTEM, (outs), (ins GPRRA:$rs2),
+ "sspush", "$rs2"> {

After v0.2 SSPUSH encoding already changed from 0b1000101 to 0b101


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152793/new/

https://reviews.llvm.org/D152793

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


[PATCH] D157610: [include-cleaner][clangd][clang-tidy] Ignore resource dir during include-cleaner analysis.

2023-09-06 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo marked an inline comment as done.
VitaNuo added a comment.

Thanks for the help in resolving the resource dir issues!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157610/new/

https://reviews.llvm.org/D157610

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


[PATCH] D159206: [Clang] Propagate target-features if compatible when using mlink-builtin-bitcode

2023-09-06 Thread Juan Manuel Martinez Caamaño via Phabricator via cfe-commits
jmmartinez updated this revision to Diff 555986.
jmmartinez marked an inline comment as done.
jmmartinez added a comment.

- Review


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159206/new/

https://reviews.llvm.org/D159206

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CodeGen/link-builtin-bitcode.c
  clang/test/CodeGenCUDA/link-builtin-bitcode-gpu-attrs-preserved.cu

Index: clang/test/CodeGenCUDA/link-builtin-bitcode-gpu-attrs-preserved.cu
===
--- clang/test/CodeGenCUDA/link-builtin-bitcode-gpu-attrs-preserved.cu
+++ clang/test/CodeGenCUDA/link-builtin-bitcode-gpu-attrs-preserved.cu
@@ -31,7 +31,7 @@
 
 
 // CHECK: define {{.*}} i64 @do_intrin_stuff() #[[ATTR:[0-9]+]]
-// INTERNALIZE: attributes #[[ATTR]] = {{.*}} "target-cpu"="gfx{{.*}}" "target-features"="+gfx11-insts"
+// INTERNALIZE: attributes #[[ATTR]] = {{.*}} "target-cpu"="gfx{{.*}}" "target-features"="{{.*}}+gfx11-insts{{.*}}"
 // NOINTERNALIZE: attributes #[[ATTR]] = {{.*}} "target-features"="+gfx11-insts"
 
 #define __device__ __attribute__((device))
Index: clang/test/CodeGen/link-builtin-bitcode.c
===
--- clang/test/CodeGen/link-builtin-bitcode.c
+++ clang/test/CodeGen/link-builtin-bitcode.c
@@ -1,42 +1,49 @@
-// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-attributes --check-globals --include-generated-funcs --version 2
+// Build two version of the bitcode library, one with a target-cpu set and one without
 // RUN: %clang_cc1 -triple amdgcn-- -target-cpu gfx803 -DBITCODE -emit-llvm-bc -o %t-lib.bc %s
+// RUN: %clang_cc1 -triple amdgcn-- -DBITCODE -emit-llvm-bc -o %t-lib.no-cpu.bc %s
+
 // RUN: %clang_cc1 -triple amdgcn-- -target-cpu gfx90a -emit-llvm-bc -o %t.bc %s
 // RUN: %clang_cc1 -triple amdgcn-- -target-cpu gfx90a -emit-llvm \
 // RUN:   -mlink-builtin-bitcode %t-lib.bc -o - %t.bc | FileCheck %s
 
+// RUN: %clang_cc1 -triple amdgcn-- -target-cpu gfx90a -emit-llvm-bc -o %t.bc %s
+// RUN: %clang_cc1 -triple amdgcn-- -target-cpu gfx90a -emit-llvm \
+// RUN:   -mlink-builtin-bitcode %t-lib.no-cpu.bc -o - %t.bc | FileCheck %s
+
 #ifdef BITCODE
-int foo(void) { return 42; }
+int no_attr(void) { return 42; }
+int __attribute__((target("gfx8-insts"))) attr_in_target(void) { return 42; }
+int __attribute__((target("extended-image-insts"))) attr_not_in_target(void) { return 42; }
+int __attribute__((target("no-gfx9-insts"))) attr_incompatible(void) { return 42; }
 int x = 12;
 #endif
 
-extern int foo(void);
+extern int no_attr(void);
+extern int attr_in_target(void);
+extern int attr_not_in_target(void);
+extern int attr_incompatible(void);
 extern int x;
 
-int bar() { return foo() + x; }
-//.
+int bar() { return no_attr() + attr_in_target() + attr_not_in_target() + attr_incompatible() + x; }
+
 // CHECK: @x = internal addrspace(1) global i32 12, align 4
-//.
-// CHECK: Function Attrs: noinline nounwind optnone
+
 // CHECK-LABEL: define dso_local i32 @bar
-// CHECK-SAME: () #[[ATTR0:[0-9]+]] {
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[RETVAL:%.*]] = alloca i32, align 4, addrspace(5)
-// CHECK-NEXT:[[RETVAL_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[RETVAL]] to ptr
-// CHECK-NEXT:[[CALL:%.*]] = call i32 @foo()
-// CHECK-NEXT:[[TMP0:%.*]] = load i32, ptr addrspacecast (ptr addrspace(1) @x to ptr), align 4
-// CHECK-NEXT:[[ADD:%.*]] = add nsw i32 [[CALL]], [[TMP0]]
-// CHECK-NEXT:ret i32 [[ADD]]
+// CHECK-SAME: () #[[ATTR_BAR:[0-9]+]] {
 //
-//
-// CHECK: Function Attrs: convergent noinline nounwind optnone
-// CHECK-LABEL: define internal i32 @foo
-// CHECK-SAME: () #[[ATTR1:[0-9]+]] {
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[RETVAL:%.*]] = alloca i32, align 4, addrspace(5)
-// CHECK-NEXT:[[RETVAL_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[RETVAL]] to ptr
-// CHECK-NEXT:ret i32 42
-//
-//.
-// CHECK: attributes #0 = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="gfx90a" "target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-fadd-rtn-insts,+ci-insts,+dl-insts,+dot1-insts,+dot10-insts,+dot2-insts,+dot3-insts,+dot4-insts,+dot5-insts,+dot6-insts,+dot7-insts,+dpp,+gfx8-insts,+gfx9-insts,+gfx90a-insts,+mai-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64" }
-// CHECK: attributes #1 = { convergent noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="gfx90a" "target-features"="+16-bit-insts,+ci-insts,+dpp,+gfx8-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64" }
-//.
+// CHECK-LABEL: define internal i32 @no_attr
+// CHECK-SAME: () #[[ATTR_COMPATIBLE:[0-9]+]] {
+
+// CHECK-LABEL: define internal i32 @attr_in_target
+// CHECK-SAME: () #[[ATTR_COMPATIBLE:[0-9]+]] {
+
+// CHECK-LABEL: define internal i32 @attr_not_in_target
+// CHECK-SAME: () #[[ATTR_EX

[clang-tools-extra] [clangd][unittests] Limit paralelism for clangd unittests (PR #65444)

2023-09-06 Thread Sam McCall via cfe-commits

https://github.com/sam-mccall approved this pull request.


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


[PATCH] D159206: [Clang] Propagate target-features if compatible when using mlink-builtin-bitcode

2023-09-06 Thread Juan Manuel Martinez Caamaño via Phabricator via cfe-commits
jmmartinez updated this revision to Diff 555987.
jmmartinez marked 2 inline comments as done.
jmmartinez added a comment.

- Capitalize comment


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159206/new/

https://reviews.llvm.org/D159206

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CodeGen/link-builtin-bitcode.c
  clang/test/CodeGenCUDA/link-builtin-bitcode-gpu-attrs-preserved.cu

Index: clang/test/CodeGenCUDA/link-builtin-bitcode-gpu-attrs-preserved.cu
===
--- clang/test/CodeGenCUDA/link-builtin-bitcode-gpu-attrs-preserved.cu
+++ clang/test/CodeGenCUDA/link-builtin-bitcode-gpu-attrs-preserved.cu
@@ -31,7 +31,7 @@
 
 
 // CHECK: define {{.*}} i64 @do_intrin_stuff() #[[ATTR:[0-9]+]]
-// INTERNALIZE: attributes #[[ATTR]] = {{.*}} "target-cpu"="gfx{{.*}}" "target-features"="+gfx11-insts"
+// INTERNALIZE: attributes #[[ATTR]] = {{.*}} "target-cpu"="gfx{{.*}}" "target-features"="{{.*}}+gfx11-insts{{.*}}"
 // NOINTERNALIZE: attributes #[[ATTR]] = {{.*}} "target-features"="+gfx11-insts"
 
 #define __device__ __attribute__((device))
Index: clang/test/CodeGen/link-builtin-bitcode.c
===
--- clang/test/CodeGen/link-builtin-bitcode.c
+++ clang/test/CodeGen/link-builtin-bitcode.c
@@ -1,42 +1,49 @@
-// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-attributes --check-globals --include-generated-funcs --version 2
+// Build two version of the bitcode library, one with a target-cpu set and one without
 // RUN: %clang_cc1 -triple amdgcn-- -target-cpu gfx803 -DBITCODE -emit-llvm-bc -o %t-lib.bc %s
+// RUN: %clang_cc1 -triple amdgcn-- -DBITCODE -emit-llvm-bc -o %t-lib.no-cpu.bc %s
+
 // RUN: %clang_cc1 -triple amdgcn-- -target-cpu gfx90a -emit-llvm-bc -o %t.bc %s
 // RUN: %clang_cc1 -triple amdgcn-- -target-cpu gfx90a -emit-llvm \
 // RUN:   -mlink-builtin-bitcode %t-lib.bc -o - %t.bc | FileCheck %s
 
+// RUN: %clang_cc1 -triple amdgcn-- -target-cpu gfx90a -emit-llvm-bc -o %t.bc %s
+// RUN: %clang_cc1 -triple amdgcn-- -target-cpu gfx90a -emit-llvm \
+// RUN:   -mlink-builtin-bitcode %t-lib.no-cpu.bc -o - %t.bc | FileCheck %s
+
 #ifdef BITCODE
-int foo(void) { return 42; }
+int no_attr(void) { return 42; }
+int __attribute__((target("gfx8-insts"))) attr_in_target(void) { return 42; }
+int __attribute__((target("extended-image-insts"))) attr_not_in_target(void) { return 42; }
+int __attribute__((target("no-gfx9-insts"))) attr_incompatible(void) { return 42; }
 int x = 12;
 #endif
 
-extern int foo(void);
+extern int no_attr(void);
+extern int attr_in_target(void);
+extern int attr_not_in_target(void);
+extern int attr_incompatible(void);
 extern int x;
 
-int bar() { return foo() + x; }
-//.
+int bar() { return no_attr() + attr_in_target() + attr_not_in_target() + attr_incompatible() + x; }
+
 // CHECK: @x = internal addrspace(1) global i32 12, align 4
-//.
-// CHECK: Function Attrs: noinline nounwind optnone
+
 // CHECK-LABEL: define dso_local i32 @bar
-// CHECK-SAME: () #[[ATTR0:[0-9]+]] {
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[RETVAL:%.*]] = alloca i32, align 4, addrspace(5)
-// CHECK-NEXT:[[RETVAL_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[RETVAL]] to ptr
-// CHECK-NEXT:[[CALL:%.*]] = call i32 @foo()
-// CHECK-NEXT:[[TMP0:%.*]] = load i32, ptr addrspacecast (ptr addrspace(1) @x to ptr), align 4
-// CHECK-NEXT:[[ADD:%.*]] = add nsw i32 [[CALL]], [[TMP0]]
-// CHECK-NEXT:ret i32 [[ADD]]
+// CHECK-SAME: () #[[ATTR_BAR:[0-9]+]] {
 //
-//
-// CHECK: Function Attrs: convergent noinline nounwind optnone
-// CHECK-LABEL: define internal i32 @foo
-// CHECK-SAME: () #[[ATTR1:[0-9]+]] {
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[RETVAL:%.*]] = alloca i32, align 4, addrspace(5)
-// CHECK-NEXT:[[RETVAL_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[RETVAL]] to ptr
-// CHECK-NEXT:ret i32 42
-//
-//.
-// CHECK: attributes #0 = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="gfx90a" "target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-fadd-rtn-insts,+ci-insts,+dl-insts,+dot1-insts,+dot10-insts,+dot2-insts,+dot3-insts,+dot4-insts,+dot5-insts,+dot6-insts,+dot7-insts,+dpp,+gfx8-insts,+gfx9-insts,+gfx90a-insts,+mai-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64" }
-// CHECK: attributes #1 = { convergent noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="gfx90a" "target-features"="+16-bit-insts,+ci-insts,+dpp,+gfx8-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64" }
-//.
+// CHECK-LABEL: define internal i32 @no_attr
+// CHECK-SAME: () #[[ATTR_COMPATIBLE:[0-9]+]] {
+
+// CHECK-LABEL: define internal i32 @attr_in_target
+// CHECK-SAME: () #[[ATTR_COMPATIBLE:[0-9]+]] {
+
+// CHECK-LABEL: define internal i32 @attr_not_in_target
+// CHECK-SAME: (

[PATCH] D159206: [Clang] Propagate target-features if compatible when using mlink-builtin-bitcode

2023-09-06 Thread Juan Manuel Martinez Caamaño via Phabricator via cfe-commits
jmmartinez added inline comments.



Comment at: clang/lib/CodeGen/CGCall.cpp:2030-2031
+  bool EnabledForTarget = TEntry->second;
+  if (EnabledForTarget != EnabledForFunc)
+return;
+}

arsenm wrote:
> jmmartinez wrote:
> > arsenm wrote:
> > > Early return breaks the other features
> > I did not understand this remark.
> > 
> > If the features are not compatible, we do not add a "target-features" entry 
> > in the new "FuncAttrs". Then, the old "target-features" entry is kept in 
> > the Function coming from the builtin.
> > 
> > If you think it would be better to set the target-features in FuncAttrs to 
> > the old value in any case. If that's the case I've added the following code:
> > 
> > if (EnabledForTarget != EnabledForFunc) {
> > FuncAttr.addAttribute(FFeatures);
> > return;
> > }
> You find an incompatible feature and then discontinue processing any further 
> features by early exiting. I expect this to act like an append to any 
> features already present. The incompatibility is at an individual feature 
> level, not the group 
I see. I changed it to match that behaviour.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159206/new/

https://reviews.llvm.org/D159206

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


[clang-tools-extra] [clang-tidy][misc-include-cleaner]Avoid to insert same include header multiple times (PR #65431)

2023-09-06 Thread Congcong Cai via cfe-commits

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


[clang-tools-extra] [clang-tidy][misc-include-cleaner]Avoid to insert same include header multiple times (PR #65431)

2023-09-06 Thread Congcong Cai via cfe-commits

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


[clang-tools-extra] [clang-tidy][misc-include-cleaner]Avoid to insert same include header multiple times (PR #65431)

2023-09-06 Thread Congcong Cai via cfe-commits

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


[clang-tools-extra] [clang-tidy][misc-include-cleaner]Avoid to insert same include header multiple times (PR #65431)

2023-09-06 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/65431:

>From 2b727285edb91a4a88add118745eabc08da9c6fd Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Wed, 6 Sep 2023 09:55:20 +0800
Subject: [PATCH 1/2] [clang-tidy][misc-include-cleaner]Avoid fixes insert same
 include header multiple times

Fixed: #65285
---
 .../clang-tidy/misc/IncludeCleanerCheck.cpp   | 21 +++-
 clang-tools-extra/docs/ReleaseNotes.rst   |  3 +-
 .../clang-tidy/IncludeCleanerTest.cpp | 32 +++
 3 files changed, 47 insertions(+), 9 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
index 2658c4b38702ca..d8afe451c99bb7 100644
--- a/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
@@ -199,6 +199,9 @@ void IncludeCleanerCheck::check(const 
MatchFinder::MatchResult &Result) {
 
   tooling::HeaderIncludes HeaderIncludes(getCurrentMainFile(), Code,
  FileStyle->IncludeStyle);
+  // `tooling::HeaderIncludes::insert` will not modify `ExistingIncludes`. We
+  // should handle repeat include here
+  std::set InsertedHeader{};
   for (const auto &Inc : Missing) {
 std::string Spelling = include_cleaner::spellHeader(
 {Inc.Missing, PP->getHeaderSearchInfo(), MainFile});
@@ -209,14 +212,16 @@ void IncludeCleanerCheck::check(const 
MatchFinder::MatchResult &Result) {
 // main file.
 if (auto Replacement =
 HeaderIncludes.insert(llvm::StringRef{Spelling}.trim("\"<>"),
-  Angled, tooling::IncludeDirective::Include))
-  diag(SM->getSpellingLoc(Inc.SymRef.RefLocation),
-   "no header providing \"%0\" is directly included")
-  << Inc.SymRef.Target.name()
-  << FixItHint::CreateInsertion(
- SM->getComposedLoc(SM->getMainFileID(),
-Replacement->getOffset()),
- Replacement->getReplacementText());
+  Angled, tooling::IncludeDirective::Include)) 
{
+  DiagnosticBuilder DB =
+  diag(SM->getSpellingLoc(Inc.SymRef.RefLocation),
+   "no header providing \"%0\" is directly included")
+  << Inc.SymRef.Target.name();
+  if 
(InsertedHeader.insert(Replacement->getReplacementText().str()).second)
+DB << FixItHint::CreateInsertion(
+SM->getComposedLoc(SM->getMainFileID(), Replacement->getOffset()),
+Replacement->getReplacementText());
+}
   }
 }
 
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 5dfda9928aca20..571a50e75bc9b0 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -224,7 +224,8 @@ Changes in existing checks
 
 - Improved :doc:`misc-include-cleaner
   ` check by adding option
-  `DeduplicateFindings` to output one finding per symbol occurrence.
+  `DeduplicateFindings` to output one finding per symbol occurrence 
+  and avoid fixes insert same include header multiple times.
 
 - Improved :doc:`misc-redundant-expression
   ` check to ignore
diff --git a/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp 
b/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
index fe3e38958f8985..f84133b01a3a49 100644
--- a/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
+++ b/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
@@ -184,6 +184,38 @@ int QuxResult = qux();
)"}}));
 }
 
+
+TEST(IncludeCleanerCheckTest, MultipleTimeMissingInclude) {
+  const char *PreCode = R"(
+#include "bar.h"
+
+int BarResult = bar();
+int BazResult_0 = baz_0();
+int BazResult_1 = baz_1();
+)";
+  const char *PostCode = R"(
+#include "bar.h"
+#include "baz.h"
+
+int BarResult = bar();
+int BazResult_0 = baz_0();
+int BazResult_1 = baz_1();
+)";
+
+  std::vector Errors;
+  EXPECT_EQ(PostCode,
+runCheckOnCode(
+PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(),
+{{"bar.h", R"(#pragma once
+  #include "baz.h"
+  int bar();
+   )"},
+ {"baz.h", R"(#pragma once
+  int baz_0();
+  int baz_1();
+   )"}}));
+}
+
 TEST(IncludeCleanerCheckTest, SystemMissingIncludes) {
   const char *PreCode = R"(
 #include 

>From 403b03e2ced5b70fc10aa003b9f72e269ed61dad Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Wed, 6 Sep 2023 13:38:24 +0800
Subject: [PATCH 2/2] add areDiagsSelfContained check

---
 clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/misc/IncludeCleane

[clang] [clang-tidy][misc-include-cleaner]Avoid to insert same include header multiple times (PR #65431)

2023-09-06 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/65431:

>From 2b727285edb91a4a88add118745eabc08da9c6fd Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Wed, 6 Sep 2023 09:55:20 +0800
Subject: [PATCH 1/2] [clang-tidy][misc-include-cleaner]Avoid fixes insert same
 include header multiple times

Fixed: #65285
---
 .../clang-tidy/misc/IncludeCleanerCheck.cpp   | 21 +++-
 clang-tools-extra/docs/ReleaseNotes.rst   |  3 +-
 .../clang-tidy/IncludeCleanerTest.cpp | 32 +++
 3 files changed, 47 insertions(+), 9 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
index 2658c4b38702ca..d8afe451c99bb7 100644
--- a/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
@@ -199,6 +199,9 @@ void IncludeCleanerCheck::check(const 
MatchFinder::MatchResult &Result) {
 
   tooling::HeaderIncludes HeaderIncludes(getCurrentMainFile(), Code,
  FileStyle->IncludeStyle);
+  // `tooling::HeaderIncludes::insert` will not modify `ExistingIncludes`. We
+  // should handle repeat include here
+  std::set InsertedHeader{};
   for (const auto &Inc : Missing) {
 std::string Spelling = include_cleaner::spellHeader(
 {Inc.Missing, PP->getHeaderSearchInfo(), MainFile});
@@ -209,14 +212,16 @@ void IncludeCleanerCheck::check(const 
MatchFinder::MatchResult &Result) {
 // main file.
 if (auto Replacement =
 HeaderIncludes.insert(llvm::StringRef{Spelling}.trim("\"<>"),
-  Angled, tooling::IncludeDirective::Include))
-  diag(SM->getSpellingLoc(Inc.SymRef.RefLocation),
-   "no header providing \"%0\" is directly included")
-  << Inc.SymRef.Target.name()
-  << FixItHint::CreateInsertion(
- SM->getComposedLoc(SM->getMainFileID(),
-Replacement->getOffset()),
- Replacement->getReplacementText());
+  Angled, tooling::IncludeDirective::Include)) 
{
+  DiagnosticBuilder DB =
+  diag(SM->getSpellingLoc(Inc.SymRef.RefLocation),
+   "no header providing \"%0\" is directly included")
+  << Inc.SymRef.Target.name();
+  if 
(InsertedHeader.insert(Replacement->getReplacementText().str()).second)
+DB << FixItHint::CreateInsertion(
+SM->getComposedLoc(SM->getMainFileID(), Replacement->getOffset()),
+Replacement->getReplacementText());
+}
   }
 }
 
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 5dfda9928aca20..571a50e75bc9b0 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -224,7 +224,8 @@ Changes in existing checks
 
 - Improved :doc:`misc-include-cleaner
   ` check by adding option
-  `DeduplicateFindings` to output one finding per symbol occurrence.
+  `DeduplicateFindings` to output one finding per symbol occurrence 
+  and avoid fixes insert same include header multiple times.
 
 - Improved :doc:`misc-redundant-expression
   ` check to ignore
diff --git a/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp 
b/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
index fe3e38958f8985..f84133b01a3a49 100644
--- a/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
+++ b/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
@@ -184,6 +184,38 @@ int QuxResult = qux();
)"}}));
 }
 
+
+TEST(IncludeCleanerCheckTest, MultipleTimeMissingInclude) {
+  const char *PreCode = R"(
+#include "bar.h"
+
+int BarResult = bar();
+int BazResult_0 = baz_0();
+int BazResult_1 = baz_1();
+)";
+  const char *PostCode = R"(
+#include "bar.h"
+#include "baz.h"
+
+int BarResult = bar();
+int BazResult_0 = baz_0();
+int BazResult_1 = baz_1();
+)";
+
+  std::vector Errors;
+  EXPECT_EQ(PostCode,
+runCheckOnCode(
+PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(),
+{{"bar.h", R"(#pragma once
+  #include "baz.h"
+  int bar();
+   )"},
+ {"baz.h", R"(#pragma once
+  int baz_0();
+  int baz_1();
+   )"}}));
+}
+
 TEST(IncludeCleanerCheckTest, SystemMissingIncludes) {
   const char *PreCode = R"(
 #include 

>From 403b03e2ced5b70fc10aa003b9f72e269ed61dad Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Wed, 6 Sep 2023 13:38:24 +0800
Subject: [PATCH 2/2] add areDiagsSelfContained check

---
 clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/misc/IncludeCleane

[libunwind] [clang-tidy][misc-include-cleaner]Avoid to insert same include header multiple times (PR #65431)

2023-09-06 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/65431:

>From 2b727285edb91a4a88add118745eabc08da9c6fd Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Wed, 6 Sep 2023 09:55:20 +0800
Subject: [PATCH 1/2] [clang-tidy][misc-include-cleaner]Avoid fixes insert same
 include header multiple times

Fixed: #65285
---
 .../clang-tidy/misc/IncludeCleanerCheck.cpp   | 21 +++-
 clang-tools-extra/docs/ReleaseNotes.rst   |  3 +-
 .../clang-tidy/IncludeCleanerTest.cpp | 32 +++
 3 files changed, 47 insertions(+), 9 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
index 2658c4b38702ca..d8afe451c99bb7 100644
--- a/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
@@ -199,6 +199,9 @@ void IncludeCleanerCheck::check(const 
MatchFinder::MatchResult &Result) {
 
   tooling::HeaderIncludes HeaderIncludes(getCurrentMainFile(), Code,
  FileStyle->IncludeStyle);
+  // `tooling::HeaderIncludes::insert` will not modify `ExistingIncludes`. We
+  // should handle repeat include here
+  std::set InsertedHeader{};
   for (const auto &Inc : Missing) {
 std::string Spelling = include_cleaner::spellHeader(
 {Inc.Missing, PP->getHeaderSearchInfo(), MainFile});
@@ -209,14 +212,16 @@ void IncludeCleanerCheck::check(const 
MatchFinder::MatchResult &Result) {
 // main file.
 if (auto Replacement =
 HeaderIncludes.insert(llvm::StringRef{Spelling}.trim("\"<>"),
-  Angled, tooling::IncludeDirective::Include))
-  diag(SM->getSpellingLoc(Inc.SymRef.RefLocation),
-   "no header providing \"%0\" is directly included")
-  << Inc.SymRef.Target.name()
-  << FixItHint::CreateInsertion(
- SM->getComposedLoc(SM->getMainFileID(),
-Replacement->getOffset()),
- Replacement->getReplacementText());
+  Angled, tooling::IncludeDirective::Include)) 
{
+  DiagnosticBuilder DB =
+  diag(SM->getSpellingLoc(Inc.SymRef.RefLocation),
+   "no header providing \"%0\" is directly included")
+  << Inc.SymRef.Target.name();
+  if 
(InsertedHeader.insert(Replacement->getReplacementText().str()).second)
+DB << FixItHint::CreateInsertion(
+SM->getComposedLoc(SM->getMainFileID(), Replacement->getOffset()),
+Replacement->getReplacementText());
+}
   }
 }
 
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 5dfda9928aca20..571a50e75bc9b0 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -224,7 +224,8 @@ Changes in existing checks
 
 - Improved :doc:`misc-include-cleaner
   ` check by adding option
-  `DeduplicateFindings` to output one finding per symbol occurrence.
+  `DeduplicateFindings` to output one finding per symbol occurrence 
+  and avoid fixes insert same include header multiple times.
 
 - Improved :doc:`misc-redundant-expression
   ` check to ignore
diff --git a/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp 
b/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
index fe3e38958f8985..f84133b01a3a49 100644
--- a/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
+++ b/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
@@ -184,6 +184,38 @@ int QuxResult = qux();
)"}}));
 }
 
+
+TEST(IncludeCleanerCheckTest, MultipleTimeMissingInclude) {
+  const char *PreCode = R"(
+#include "bar.h"
+
+int BarResult = bar();
+int BazResult_0 = baz_0();
+int BazResult_1 = baz_1();
+)";
+  const char *PostCode = R"(
+#include "bar.h"
+#include "baz.h"
+
+int BarResult = bar();
+int BazResult_0 = baz_0();
+int BazResult_1 = baz_1();
+)";
+
+  std::vector Errors;
+  EXPECT_EQ(PostCode,
+runCheckOnCode(
+PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(),
+{{"bar.h", R"(#pragma once
+  #include "baz.h"
+  int bar();
+   )"},
+ {"baz.h", R"(#pragma once
+  int baz_0();
+  int baz_1();
+   )"}}));
+}
+
 TEST(IncludeCleanerCheckTest, SystemMissingIncludes) {
   const char *PreCode = R"(
 #include 

>From 403b03e2ced5b70fc10aa003b9f72e269ed61dad Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Wed, 6 Sep 2023 13:38:24 +0800
Subject: [PATCH 2/2] add areDiagsSelfContained check

---
 clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/misc/IncludeCleane

[PATCH] D150867: [AArch64][FMV] Prevent target attribute using for multiversioning.

2023-09-06 Thread Allen zhong via Phabricator via cfe-commits
Allen added inline comments.



Comment at: clang/lib/Sema/SemaDecl.cpp:11544
+  // Target attribute on AArch64 is not used for multiversioning
+  if (NewTA && S.getASTContext().getTargetInfo().getTriple().isAArch64())
+return false;

I find the attribute **target_clones/target_version** also not be used to 
generate multiversioning function? https://godbolt.org/z/cYWsbrPn9
so it is not support on AArch64 ?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150867/new/

https://reviews.llvm.org/D150867

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


[clang-tools-extra] 9a26d2c - [clangd][unittests] Limit paralelism for clangd unittests

2023-09-06 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2023-09-06T10:53:18+02:00
New Revision: 9a26d2c6d35f574d7a4b06a5a22f8a1c063cb664

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

LOG: [clangd][unittests] Limit paralelism for clangd unittests

We started seeing a lot of timeouts that align with the change in lit to
execute gtests in shards. The logic there assumes tests are
single-threaded, which is the case for most of the LLVM, hence they
pick #shards ~ #cores (by slightly overshooting).

There are enough unittests in clangd that rely on multi-threading, they
can create arbitrarily many threads but we limit amount of meaningful
work to ~4 thread per process.

This change ensures that we're accounting for that paralelism when
executing clangd tests and not overloading test executors.

In theory the change overestimates the requirements, not all tests are
multi-threaded, but it doesn't seem to be resulting in any regressions
on my local runs.

Fixes https://github.com/llvm/llvm-project/issues/64964.
Fixes https://github.com/clangd/clangd/issues/1712.

Added: 


Modified: 
clang-tools-extra/clangd/unittests/lit.cfg.py

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/lit.cfg.py 
b/clang-tools-extra/clangd/unittests/lit.cfg.py
index 48ee5f5d5ab920..33aa9e61f4ce9d 100644
--- a/clang-tools-extra/clangd/unittests/lit.cfg.py
+++ b/clang-tools-extra/clangd/unittests/lit.cfg.py
@@ -1,4 +1,5 @@
 import lit.formats
+import lit.util
 
 config.name = "Clangd Unit Tests"
 config.test_format = lit.formats.GoogleTest(".", "Tests")
@@ -9,6 +10,13 @@
 # FIXME: it seems every project has a copy of this logic. Move it somewhere.
 import platform
 
+# Clangd unittests uses ~4 threads per test. So make sure we don't over commit.
+core_count = lit.util.usable_core_count()
+# FIXME: Split unittests into groups that use threads, and groups that do not,
+# and only limit multi-threaded tests.
+lit_config.parallelism_groups["clangd"] = max(1, core_count // 4)
+config.parallelism_group = "clangd"
+
 if platform.system() == "Darwin":
 shlibpath_var = "DYLD_LIBRARY_PATH"
 elif platform.system() == "Windows":



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


[clang] [Clang] Fix missing diagnostic for non-standard layout type in `offsetof` (PR #65246)

2023-09-06 Thread via cfe-commits

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


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


[clang-tools-extra] [clang-tidy][misc-include-cleaner]Avoid to insert same include header multiple times (PR #65431)

2023-09-06 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/65431:

>From 2b727285edb91a4a88add118745eabc08da9c6fd Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Wed, 6 Sep 2023 09:55:20 +0800
Subject: [PATCH 1/3] [clang-tidy][misc-include-cleaner]Avoid fixes insert same
 include header multiple times

Fixed: #65285
---
 .../clang-tidy/misc/IncludeCleanerCheck.cpp   | 21 +++-
 clang-tools-extra/docs/ReleaseNotes.rst   |  3 +-
 .../clang-tidy/IncludeCleanerTest.cpp | 32 +++
 3 files changed, 47 insertions(+), 9 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
index 2658c4b38702ca..d8afe451c99bb7 100644
--- a/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
@@ -199,6 +199,9 @@ void IncludeCleanerCheck::check(const 
MatchFinder::MatchResult &Result) {
 
   tooling::HeaderIncludes HeaderIncludes(getCurrentMainFile(), Code,
  FileStyle->IncludeStyle);
+  // `tooling::HeaderIncludes::insert` will not modify `ExistingIncludes`. We
+  // should handle repeat include here
+  std::set InsertedHeader{};
   for (const auto &Inc : Missing) {
 std::string Spelling = include_cleaner::spellHeader(
 {Inc.Missing, PP->getHeaderSearchInfo(), MainFile});
@@ -209,14 +212,16 @@ void IncludeCleanerCheck::check(const 
MatchFinder::MatchResult &Result) {
 // main file.
 if (auto Replacement =
 HeaderIncludes.insert(llvm::StringRef{Spelling}.trim("\"<>"),
-  Angled, tooling::IncludeDirective::Include))
-  diag(SM->getSpellingLoc(Inc.SymRef.RefLocation),
-   "no header providing \"%0\" is directly included")
-  << Inc.SymRef.Target.name()
-  << FixItHint::CreateInsertion(
- SM->getComposedLoc(SM->getMainFileID(),
-Replacement->getOffset()),
- Replacement->getReplacementText());
+  Angled, tooling::IncludeDirective::Include)) 
{
+  DiagnosticBuilder DB =
+  diag(SM->getSpellingLoc(Inc.SymRef.RefLocation),
+   "no header providing \"%0\" is directly included")
+  << Inc.SymRef.Target.name();
+  if 
(InsertedHeader.insert(Replacement->getReplacementText().str()).second)
+DB << FixItHint::CreateInsertion(
+SM->getComposedLoc(SM->getMainFileID(), Replacement->getOffset()),
+Replacement->getReplacementText());
+}
   }
 }
 
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 5dfda9928aca20..571a50e75bc9b0 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -224,7 +224,8 @@ Changes in existing checks
 
 - Improved :doc:`misc-include-cleaner
   ` check by adding option
-  `DeduplicateFindings` to output one finding per symbol occurrence.
+  `DeduplicateFindings` to output one finding per symbol occurrence 
+  and avoid fixes insert same include header multiple times.
 
 - Improved :doc:`misc-redundant-expression
   ` check to ignore
diff --git a/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp 
b/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
index fe3e38958f8985..f84133b01a3a49 100644
--- a/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
+++ b/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
@@ -184,6 +184,38 @@ int QuxResult = qux();
)"}}));
 }
 
+
+TEST(IncludeCleanerCheckTest, MultipleTimeMissingInclude) {
+  const char *PreCode = R"(
+#include "bar.h"
+
+int BarResult = bar();
+int BazResult_0 = baz_0();
+int BazResult_1 = baz_1();
+)";
+  const char *PostCode = R"(
+#include "bar.h"
+#include "baz.h"
+
+int BarResult = bar();
+int BazResult_0 = baz_0();
+int BazResult_1 = baz_1();
+)";
+
+  std::vector Errors;
+  EXPECT_EQ(PostCode,
+runCheckOnCode(
+PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(),
+{{"bar.h", R"(#pragma once
+  #include "baz.h"
+  int bar();
+   )"},
+ {"baz.h", R"(#pragma once
+  int baz_0();
+  int baz_1();
+   )"}}));
+}
+
 TEST(IncludeCleanerCheckTest, SystemMissingIncludes) {
   const char *PreCode = R"(
 #include 

>From 403b03e2ced5b70fc10aa003b9f72e269ed61dad Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Wed, 6 Sep 2023 13:38:24 +0800
Subject: [PATCH 2/3] add areDiagsSelfContained check

---
 clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/misc/IncludeCleane

[PATCH] D158715: [Driver] Cleanup last vestiges of Minix / Contiki support

2023-09-06 Thread Mikael Holmén via Phabricator via cfe-commits
uabelho added inline comments.



Comment at: clang/lib/Lex/InitHeaderSearch.cpp:336
-  case llvm::Triple::Minix:
-AddGnuCPlusPlusIncludePaths("/usr/gnu/include/c++/4.4.3",
-"", "", "", triple);

@brad :
I think this was the last use of the AddGnuCPlusPlusIncludePaths method, should 
we remove it now or is it likely it will be used again?



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158715/new/

https://reviews.llvm.org/D158715

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


[clang] [X86][Driver] Move mno-gather/mno-scatter from m_x86_Features_Group yo m_Group. NFCI (PR #65457)

2023-09-06 Thread Phoebe Wang via cfe-commits

https://github.com/phoebewang created 
https://github.com/llvm/llvm-project/pull/65457:

m_x86_Features_Group always turn `mno-` into `-target-feature-`. In 
this case, we don't have `-gather/-scatter` but `+prefer-no-gather/scatter`.

>From be58af68f221bb65788e74f8cfe4952c1038ae70 Mon Sep 17 00:00:00 2001
From: Phoebe Wang 
Date: Wed, 6 Sep 2023 17:10:01 +0800
Subject: [PATCH] [X86][Driver] Move mno-gather/mno-scatter from
 m_x86_Features_Group to m_Group. NFCI

m_x86_Features_Group always turn `mno-` into `-target-feature-`.
In this case, we don't have `-gather/-scatter` but `+prefer-no-gather/scatter`.
---
 clang/include/clang/Driver/Options.td | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index e6d8aed6aefc8d9..9a6e7e9929f5f2f 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5846,9 +5846,9 @@ def mretpoline_external_thunk : Flag<["-"], 
"mretpoline-external-thunk">, Group<
 def mno_retpoline_external_thunk : Flag<["-"], 
"mno-retpoline-external-thunk">, Group;
 def mvzeroupper : Flag<["-"], "mvzeroupper">, Group;
 def mno_vzeroupper : Flag<["-"], "mno-vzeroupper">, 
Group;
-def mno_gather : Flag<["-"], "mno-gather">, Group,
+def mno_gather : Flag<["-"], "mno-gather">, Group,
  HelpText<"Disable generation of gather instructions in 
auto-vectorization(x86 only)">;
-def mno_scatter : Flag<["-"], "mno-scatter">, Group,
+def mno_scatter : Flag<["-"], "mno-scatter">, Group,
   HelpText<"Disable generation of scatter instructions in 
auto-vectorization(x86 only)">;
 } // let Flags = [TargetSpecific]
 

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


[clang] [X86][Driver] Move mno-gather/mno-scatter from m_x86_Features_Group yo m_Group. NFCI (PR #65457)

2023-09-06 Thread Phoebe Wang via cfe-commits

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


[clang] [X86][Driver] Move mno-gather/mno-scatter from m_x86_Features_Group yo m_Group. NFCI (PR #65457)

2023-09-06 Thread via cfe-commits

https://github.com/github-actions[bot] labeled 
https://github.com/llvm/llvm-project/pull/65457
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][AArch64] Define x86_64 macros for ARM64EC targets (PR #65420)

2023-09-06 Thread Martin Storsjö via cfe-commits

mstorsjo wrote:

CC @cjacek @efriedma-quic 

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


[clang] [X86][Driver] Move mno-gather/mno-scatter from m_x86_Features_Group yo m_Group. NFCI (PR #65457)

2023-09-06 Thread Phoebe Wang via cfe-commits

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


[clang] [X86][Driver] Move mno-gather/mno-scatter from m_x86_Features_Group yo m_Group. NFCI (PR #65457)

2023-09-06 Thread Phoebe Wang via cfe-commits

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


[clang] [X86][Driver] Move mno-gather/mno-scatter from m_x86_Features_Group yo m_Group. NFCI (PR #65457)

2023-09-06 Thread Phoebe Wang via cfe-commits

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


[clang-tools-extra] b0831c3 - [clang-tidy][misc-include-cleaner]Avoid to insert same include header multiple times (#65431)

2023-09-06 Thread via cfe-commits

Author: Congcong Cai
Date: 2023-09-06T17:37:14+08:00
New Revision: b0831c3996752038c375796d8ebb4f471f1ea251

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

LOG: [clang-tidy][misc-include-cleaner]Avoid to insert same include header 
multiple times (#65431)

`HeaderIncludes` won't update `ExistingIncludes` during inserting.
We need to manage it in tidy check.

Fixed: #65285

Added: 


Modified: 
clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
index 2658c4b38702ca8..8d5f400acfef8bc 100644
--- a/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
@@ -33,6 +33,7 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSet.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Regex.h"
@@ -199,6 +200,8 @@ void IncludeCleanerCheck::check(const 
MatchFinder::MatchResult &Result) {
 
   tooling::HeaderIncludes HeaderIncludes(getCurrentMainFile(), Code,
  FileStyle->IncludeStyle);
+  // Deduplicate insertions when running in bulk fix mode.
+  llvm::StringSet<> InsertedHeaders{};
   for (const auto &Inc : Missing) {
 std::string Spelling = include_cleaner::spellHeader(
 {Inc.Missing, PP->getHeaderSearchInfo(), MainFile});
@@ -209,14 +212,18 @@ void IncludeCleanerCheck::check(const 
MatchFinder::MatchResult &Result) {
 // main file.
 if (auto Replacement =
 HeaderIncludes.insert(llvm::StringRef{Spelling}.trim("\"<>"),
-  Angled, tooling::IncludeDirective::Include))
-  diag(SM->getSpellingLoc(Inc.SymRef.RefLocation),
-   "no header providing \"%0\" is directly included")
-  << Inc.SymRef.Target.name()
-  << FixItHint::CreateInsertion(
- SM->getComposedLoc(SM->getMainFileID(),
-Replacement->getOffset()),
- Replacement->getReplacementText());
+  Angled, tooling::IncludeDirective::Include)) 
{
+  DiagnosticBuilder DB =
+  diag(SM->getSpellingLoc(Inc.SymRef.RefLocation),
+   "no header providing \"%0\" is directly included")
+  << Inc.SymRef.Target.name();
+  if (areDiagsSelfContained() ||
+  InsertedHeaders.insert(Replacement->getReplacementText()).second) {
+DB << FixItHint::CreateInsertion(
+SM->getComposedLoc(SM->getMainFileID(), Replacement->getOffset()),
+Replacement->getReplacementText());
+  }
+}
   }
 }
 

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 5dfda9928aca20b..a2cde526a8c04d9 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -226,6 +226,10 @@ Changes in existing checks
   ` check by adding option
   `DeduplicateFindings` to output one finding per symbol occurrence.
 
+- Improved :doc:`misc-include-cleaner
+  ` check to avoid fixes insert 
+  same include header multiple times.
+
 - Improved :doc:`misc-redundant-expression
   ` check to ignore
   false-positives in unevaluated context (e.g., ``decltype``).

diff  --git a/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp 
b/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
index fe3e38958f8985a..f84133b01a3a49f 100644
--- a/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
+++ b/clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
@@ -184,6 +184,38 @@ int QuxResult = qux();
)"}}));
 }
 
+
+TEST(IncludeCleanerCheckTest, MultipleTimeMissingInclude) {
+  const char *PreCode = R"(
+#include "bar.h"
+
+int BarResult = bar();
+int BazResult_0 = baz_0();
+int BazResult_1 = baz_1();
+)";
+  const char *PostCode = R"(
+#include "bar.h"
+#include "baz.h"
+
+int BarResult = bar();
+int BazResult_0 = baz_0();
+int BazResult_1 = baz_1();
+)";
+
+  std::vector Errors;
+  EXPECT_EQ(PostCode,
+runCheckOnCode(
+PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(),
+{{"bar.h", R"(#pragma once
+  #include "baz.h"
+  int bar();
+   )"},
+ {"baz.h", R"(#pragma once
+  int baz_0();
+  int baz_1();
+ 

[clang-tools-extra] [clang-tidy][misc-include-cleaner]Avoid to insert same include header multiple times (PR #65431)

2023-09-06 Thread Congcong Cai via cfe-commits

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


[PATCH] D157610: [include-cleaner][clangd][clang-tidy] Ignore resource dir during include-cleaner analysis.

2023-09-06 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 555995.
VitaNuo added a comment.

Rebase to current main.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157610/new/

https://reviews.llvm.org/D157610

Files:
  clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -271,6 +271,31 @@
   EXPECT_THAT(Results.Unused, testing::IsEmpty());
 }
 
+TEST_F(AnalyzeTest, ResourceDirIsIgnored) {
+  Inputs.ExtraArgs.push_back("-resource-dir");
+  Inputs.ExtraArgs.push_back("resources");
+  Inputs.ExtraArgs.push_back("-internal-isystem");
+  Inputs.ExtraArgs.push_back("resources/include");
+  Inputs.Code = R"cpp(
+#include 
+#include 
+void baz() {
+  bar();
+}
+  )cpp";
+  Inputs.ExtraFiles["resources/include/amintrin.h"] = "";
+  Inputs.ExtraFiles["resources/include/emintrin.h"] = guard(R"cpp(
+void bar();
+  )cpp");
+  Inputs.ExtraFiles["resources/include/imintrin.h"] = guard(R"cpp(
+#include 
+  )cpp");
+  TestAST AST(Inputs);
+  auto Results = analyze({}, {}, PP.Includes, &PI, AST.preprocessor());
+  EXPECT_THAT(Results.Unused, testing::IsEmpty());
+  EXPECT_THAT(Results.Missing, testing::IsEmpty());
+}
+
 TEST(FixIncludes, Basic) {
   llvm::StringRef Code = R"cpp(#include "d.h"
 #include "a.h"
Index: clang-tools-extra/include-cleaner/lib/Analysis.cpp
===
--- clang-tools-extra/include-cleaner/lib/Analysis.cpp
+++ clang-tools-extra/include-cleaner/lib/Analysis.cpp
@@ -13,6 +13,7 @@
 #include "clang-include-cleaner/Types.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
+#include "clang/Basic/DirectoryEntry.h"
 #include "clang/Basic/FileEntry.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Format/Format.h"
@@ -86,12 +87,18 @@
   llvm::StringSet<> Missing;
   if (!HeaderFilter)
 HeaderFilter = [](llvm::StringRef) { return false; };
+  const DirectoryEntry *ResourceDir =
+  PP.getHeaderSearchInfo().getModuleMap().getBuiltinDir();
   walkUsed(ASTRoots, MacroRefs, PI, PP,
[&](const SymbolReference &Ref, llvm::ArrayRef Providers) {
  bool Satisfied = false;
  for (const Header &H : Providers) {
-   if (H.kind() == Header::Physical && H.physical() == MainFile)
+   if (H.kind() == Header::Physical &&
+   (H.physical() == MainFile ||
+H.physical()->getDir() == ResourceDir)) {
  Satisfied = true;
+ continue;
+   }
for (const Include *I : Inc.match(H)) {
  Used.insert(I);
  Satisfied = true;
@@ -107,7 +114,8 @@
   AnalysisResults Results;
   for (const Include &I : Inc.all()) {
 if (Used.contains(&I) || !I.Resolved ||
-HeaderFilter(I.Resolved->getFileEntry().tryGetRealPathName()))
+HeaderFilter(I.Resolved->getFileEntry().tryGetRealPathName()) ||
+I.Resolved->getFileEntry().getDir() == ResourceDir)
   continue;
 if (PI) {
   if (PI->shouldKeep(*I.Resolved))
Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -574,6 +574,29 @@
   EXPECT_THAT(Findings.UnusedIncludes, IsEmpty());
 }
 
+TEST(IncludeCleaner, ResourceDirIsIgnored) {
+  auto TU = TestTU::withCode(R"cpp(
+#include 
+#include 
+void baz() {
+  bar();
+}
+  )cpp");
+  TU.ExtraArgs.push_back("-resource-dir");
+  TU.ExtraArgs.push_back(testPath("resources"));
+  TU.AdditionalFiles["resources/include/amintrin.h"] = "";
+  TU.AdditionalFiles["resources/include/imintrin.h"] = guard(R"cpp(
+#include 
+  )cpp");
+  TU.AdditionalFiles["resources/include/emintrin.h"] = guard(R"cpp(
+void bar();
+  )cpp");
+  auto AST = TU.build();
+  auto Findings = computeIncludeCleanerFindings(AST);
+  EXPECT_THAT(Findings.UnusedIncludes, IsEmpty());
+  EXPECT_THAT(Findings.MissingIncludes, IsEmpty());
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
===
--- clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
+++ clang-tools-extra/clangd/test/include-cleaner-batch-fix.test
@

[PATCH] D159462: [clangd][clang-tidy] Add missing symbols to the symbol map.

2023-09-06 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo created this revision.
Herald added subscribers: kadircet, arphaman, xazax.hun.
Herald added a project: All.
VitaNuo requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159462

Files:
  clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc


Index: clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
===
--- clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
+++ clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
@@ -364,6 +364,8 @@
 // Remove when the generator starts producing them.
 SYMBOL(make_any, std::, )
 SYMBOL(any_cast, std::, )
+SYMBOL(div, std::, )
+SYMBOL(abort, std::, )
 
 // The std::placeholder symbols (_1, ..., _N) are listed in the cppreference
 // placeholder.html, but the index only contains a single entry with "_1, _2, 
..., _N"


Index: clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
===
--- clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
+++ clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
@@ -364,6 +364,8 @@
 // Remove when the generator starts producing them.
 SYMBOL(make_any, std::, )
 SYMBOL(any_cast, std::, )
+SYMBOL(div, std::, )
+SYMBOL(abort, std::, )
 
 // The std::placeholder symbols (_1, ..., _N) are listed in the cppreference
 // placeholder.html, but the index only contains a single entry with "_1, _2, ..., _N"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [X86][Driver] Move mno-gather/mno-scatter from m_x86_Features_Group yo m_Group. NFCI (PR #65457)

2023-09-06 Thread via cfe-commits

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

LGTM, could work on my side.

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


[clang] [X86][Driver] Move mno-gather/mno-scatter from m_x86_Features_Group to m_Group. NFCI (PR #65457)

2023-09-06 Thread Phoebe Wang via cfe-commits

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


[clang] c5fabac - [X86][Driver] Move mno-gather/mno-scatter from m_x86_Features_Group to m_Group. NFCI (#65457)

2023-09-06 Thread via cfe-commits

Author: Phoebe Wang
Date: 2023-09-06T18:08:29+08:00
New Revision: c5fabaccef5a8566bd65a6f242be65d75096bea8

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

LOG: [X86][Driver] Move mno-gather/mno-scatter from m_x86_Features_Group to 
m_Group. NFCI (#65457)

m_x86_Features_Group always turn `mno-` into `-target-feature
-`. In this case, we don't have `-gather/-scatter` but
`+prefer-no-gather/scatter`.

This patch solves unexpected warning when using
`mno-gather/mno-scatter`:
```
'-gather' is not a recognized feature for this target (ignoring feature)
'-scatter' is not a recognized feature for this target (ignoring feature)
```

Added: 


Modified: 
clang/include/clang/Driver/Options.td

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index e6d8aed6aefc8d9..9a6e7e9929f5f2f 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5846,9 +5846,9 @@ def mretpoline_external_thunk : Flag<["-"], 
"mretpoline-external-thunk">, Group<
 def mno_retpoline_external_thunk : Flag<["-"], 
"mno-retpoline-external-thunk">, Group;
 def mvzeroupper : Flag<["-"], "mvzeroupper">, Group;
 def mno_vzeroupper : Flag<["-"], "mno-vzeroupper">, 
Group;
-def mno_gather : Flag<["-"], "mno-gather">, Group,
+def mno_gather : Flag<["-"], "mno-gather">, Group,
  HelpText<"Disable generation of gather instructions in 
auto-vectorization(x86 only)">;
-def mno_scatter : Flag<["-"], "mno-scatter">, Group,
+def mno_scatter : Flag<["-"], "mno-scatter">, Group,
   HelpText<"Disable generation of scatter instructions in 
auto-vectorization(x86 only)">;
 } // let Flags = [TargetSpecific]
 



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


[clang] [X86][Driver] Move mno-gather/mno-scatter from m_x86_Features_Group to m_Group. NFCI (PR #65457)

2023-09-06 Thread Phoebe Wang via cfe-commits

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


[PATCH] D148131: Avoid unnecessarily aggressive line-breaking when using "LambdaBodyIndentation: OuterScope" with argument bin-packing.

2023-09-06 Thread Owen Pan via Phabricator via cfe-commits
owenpan accepted this revision.
owenpan added a comment.

LG with a couple of minor comments.




Comment at: clang/lib/Format/ContinuationIndenter.cpp:334
+  // enabled.
+  !(Current.is(TT_LambdaLBrace) && Style.BraceWrapping.BeforeLambdaBody) &&
   CurrentState.NoLineBreakInOperand) {

To be consistent with line 1116 below.



Comment at: clang/unittests/Format/FormatTest.cpp:22789
+  // doesn't force an initial line break, even if lambdas span multiple lines.
+  // This should probably be considered a bug.
+  verifyFormat("void foo() {\n"

If so, we should put the test case below in a `#if 0`-`#endif` block with a 
`FIXME` comment?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148131/new/

https://reviews.llvm.org/D148131

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


[PATCH] D148381: [Clang] Add counted_by attribute

2023-09-06 Thread Bill Wendling via Phabricator via cfe-commits
void added a comment.

This is now ready for a non-WIP review. PTAL. :-)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148381/new/

https://reviews.llvm.org/D148381

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


[PATCH] D150867: [AArch64][FMV] Prevent target attribute using for multiversioning.

2023-09-06 Thread Pavel Iliin via Phabricator via cfe-commits
ilinpv added inline comments.



Comment at: clang/lib/Sema/SemaDecl.cpp:11544
+  // Target attribute on AArch64 is not used for multiversioning
+  if (NewTA && S.getASTContext().getTargetInfo().getTriple().isAArch64())
+return false;

Allen wrote:
> I find the attribute **target_clones/target_version** also not be used to 
> generate multiversioning function? https://godbolt.org/z/cYWsbrPn9
> so it is not support on AArch64 ?
Function multiversioning depends on compiler-rt library, specify 
--rtlib=compiler-rt to make it work.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150867/new/

https://reviews.llvm.org/D150867

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


[clang] [clang][TSA] (PR #65462)

2023-09-06 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= 


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


[clang] [clang][TSA] (PR #65462)

2023-09-06 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= 


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


[clang] [clang][TSA] (PR #65462)

2023-09-06 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= 


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


[clang] [clang][TSA] (PR #65462)

2023-09-06 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= 


https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/65462:

None

>From 20aa3e3225f6ea48df00ea05bcbfcc5cc2278af5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Tue, 8 Aug 2023 14:11:33 +0200
Subject: [PATCH 1/2] [clang][CFG] Cleanup functions

---
 clang/include/clang/Analysis/CFG.h   | 38 +++-
 clang/lib/Analysis/CFG.cpp   | 40 
 clang/lib/Analysis/PathDiagnostic.cpp|  1 +
 clang/lib/StaticAnalyzer/Core/ExprEngine.cpp |  1 +
 clang/test/Analysis/scopes-cfg-output.cpp| 65 
 5 files changed, 131 insertions(+), 14 deletions(-)

diff --git a/clang/include/clang/Analysis/CFG.h 
b/clang/include/clang/Analysis/CFG.h
index cf4fa2da2a358e..67383bb316d318 100644
--- a/clang/include/clang/Analysis/CFG.h
+++ b/clang/include/clang/Analysis/CFG.h
@@ -14,10 +14,11 @@
 #ifndef LLVM_CLANG_ANALYSIS_CFG_H
 #define LLVM_CLANG_ANALYSIS_CFG_H
 
-#include "clang/Analysis/Support/BumpVector.h"
-#include "clang/Analysis/ConstructionContext.h"
+#include "clang/AST/Attr.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/ExprObjC.h"
+#include "clang/Analysis/ConstructionContext.h"
+#include "clang/Analysis/Support/BumpVector.h"
 #include "clang/Basic/LLVM.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/GraphTraits.h"
@@ -74,7 +75,8 @@ class CFGElement {
 MemberDtor,
 TemporaryDtor,
 DTOR_BEGIN = AutomaticObjectDtor,
-DTOR_END = TemporaryDtor
+DTOR_END = TemporaryDtor,
+CleanupFunction,
   };
 
 protected:
@@ -383,6 +385,32 @@ class CFGImplicitDtor : public CFGElement {
   }
 };
 
+class CFGCleanupFunction final : public CFGElement {
+public:
+  CFGCleanupFunction() = default;
+  CFGCleanupFunction(const VarDecl *VD)
+  : CFGElement(Kind::CleanupFunction, VD) {
+assert(VD->hasAttr());
+  }
+
+  const VarDecl *getVarDecl() const {
+return static_cast(Data1.getPointer());
+  }
+
+  /// Returns the function to be called when cleaning up the var decl.
+  const FunctionDecl *getFunctionDecl() const {
+const CleanupAttr *A = getVarDecl()->getAttr();
+return A->getFunctionDecl();
+  }
+
+private:
+  friend class CFGElement;
+
+  static bool isKind(const CFGElement E) {
+return E.getKind() == Kind::CleanupFunction;
+  }
+};
+
 /// Represents C++ object destructor implicitly generated for automatic object
 /// or temporary bound to const reference at the point of leaving its local
 /// scope.
@@ -1142,6 +1170,10 @@ class CFGBlock {
 Elements.push_back(CFGAutomaticObjDtor(VD, S), C);
   }
 
+  void appendCleanupFunction(const VarDecl *VD, BumpVectorContext &C) {
+Elements.push_back(CFGCleanupFunction(VD), C);
+  }
+
   void appendLifetimeEnds(VarDecl *VD, Stmt *S, BumpVectorContext &C) {
 Elements.push_back(CFGLifetimeEnds(VD, S), C);
   }
diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index b82f9010a83f77..03ab4c6fdf29ca 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/lib/Analysis/CFG.cpp
@@ -881,6 +881,10 @@ class CFGBuilder {
 B->appendAutomaticObjDtor(VD, S, cfg->getBumpVectorContext());
   }
 
+  void appendCleanupFunction(CFGBlock *B, VarDecl *VD) {
+B->appendCleanupFunction(VD, cfg->getBumpVectorContext());
+  }
+
   void appendLifetimeEnds(CFGBlock *B, VarDecl *VD, Stmt *S) {
 B->appendLifetimeEnds(VD, S, cfg->getBumpVectorContext());
   }
@@ -1346,7 +1350,8 @@ class CFGBuilder {
 return {};
   }
 
-  bool hasTrivialDestructor(VarDecl *VD);
+  bool hasTrivialDestructor(const VarDecl *VD) const;
+  bool needsAutomaticDestruction(const VarDecl *VD) const;
 };
 
 } // namespace
@@ -1861,14 +1866,14 @@ void 
CFGBuilder::addAutomaticObjDestruction(LocalScope::const_iterator B,
   if (B == E)
 return;
 
-  SmallVector DeclsNonTrivial;
-  DeclsNonTrivial.reserve(B.distance(E));
+  SmallVector DeclsNeedDestruction;
+  DeclsNeedDestruction.reserve(B.distance(E));
 
   for (VarDecl* D : llvm::make_range(B, E))
-if (!hasTrivialDestructor(D))
-  DeclsNonTrivial.push_back(D);
+if (needsAutomaticDestruction(D))
+  DeclsNeedDestruction.push_back(D);
 
-  for (VarDecl *VD : llvm::reverse(DeclsNonTrivial)) {
+  for (VarDecl *VD : llvm::reverse(DeclsNeedDestruction)) {
 if (BuildOpts.AddImplicitDtors) {
   // If this destructor is marked as a no-return destructor, we need to
   // create a new block for the destructor which does not have as a
@@ -1879,7 +1884,8 @@ void 
CFGBuilder::addAutomaticObjDestruction(LocalScope::const_iterator B,
 Ty = getReferenceInitTemporaryType(VD->getInit());
   Ty = Context->getBaseElementType(Ty);
 
-  if (Ty->getAsCXXRecordDecl()->isAnyDestructorNoReturn())
+  const CXXRecordDecl *CRD = Ty->getAsCXXRecordDecl();
+  if (CRD && CRD->isAnyDestructorNoReturn())
 Block = createNoReturnBlock();
 }
 
@@ -1890,8 +1896,10 @@ void 
CFGBuilder::addAutomaticObjDestruction(LocalScope::const_iterator B,
 

[clang] [clang][TSA] (PR #65462)

2023-09-06 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= 


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


[clang] [clang][TSA] (PR #65462)

2023-09-06 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= 


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


[clang] [clang][TSA] (PR #65462)

2023-09-06 Thread via cfe-commits
Timm =?utf-8?q?Bäder?= 


https://github.com/github-actions[bot] labeled 
https://github.com/llvm/llvm-project/pull/65462
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][TSA] (PR #65462)

2023-09-06 Thread via cfe-commits
Timm =?utf-8?q?Bäder?= 


https://github.com/github-actions[bot] labeled 
https://github.com/llvm/llvm-project/pull/65462
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][TSA] Consider cleanup functions for thread safety analysis (PR #65462)

2023-09-06 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= 


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


[PATCH] D158259: [clang][RISCV] Support operators for RVV sizeless vector types

2023-09-06 Thread Jianjian Guan via Phabricator via cfe-commits
jacquesguan marked an inline comment as done.
jacquesguan added a comment.

ping.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158259/new/

https://reviews.llvm.org/D158259

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


[clang] [Clang] Allow mixed scalar type constraints for inline asm (PR #65465)

2023-09-06 Thread Dávid Ferenc Szabó via cfe-commits

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


[clang] [Clang] Allow mixed scalar type constraints for inline asm (PR #65465)

2023-09-06 Thread Dávid Ferenc Szabó via cfe-commits

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


[clang] [Clang] Allow mixed scalar type constraints for inline asm (PR #65465)

2023-09-06 Thread Dávid Ferenc Szabó via cfe-commits

https://github.com/dfszabo created 
https://github.com/llvm/llvm-project/pull/65465:

GCC supports code like "asm volatile ("" : "=r" (i) : "0" (f))" where i is 
integer type and f is floating point type. Currently this code produces an 
error with Clang. The change allows mixed scalar types between input and output 
constraints.

From 69e13118b0669b3e54c5fffc1f5ac60d8b6b2d62 Mon Sep 17 00:00:00 2001
From: dfszabo 
Date: Wed, 6 Sep 2023 13:07:19 +0200
Subject: [PATCH] [Clang] Allow mixed scalar type constraints for inline asm

GCC supports code like "asm volatile ("" : "=r" (i) : "0" (f))" where i is 
integer type and f is floating point type. Currently this code produces an 
error with Clang. The change allows mixed scalar types between input and output 
constraints.
---
 clang/test/CodeGen/inline-asm-fp-to-int.c| 8 
 llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp | 7 +--
 2 files changed, 13 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/CodeGen/inline-asm-fp-to-int.c

diff --git a/clang/test/CodeGen/inline-asm-fp-to-int.c 
b/clang/test/CodeGen/inline-asm-fp-to-int.c
new file mode 100644
index 00..cdcdb4c90516a4
--- /dev/null
+++ b/clang/test/CodeGen/inline-asm-fp-to-int.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 %s -emit-llvm -o /dev/null
+
+unsigned test(float f)
+{
+   unsigned i;
+   asm volatile ("" : "=r" (i) : "0" (f));
+   return i;
+}
diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp 
b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
index bd1940994a87f0..50aec396c78b80 100644
--- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -5687,8 +5687,11 @@ TargetLowering::ParseConstraints(const DataLayout &DL,
 std::pair InputRC =
 getRegForInlineAsmConstraint(TRI, Input.ConstraintCode,
  Input.ConstraintVT);
-if ((OpInfo.ConstraintVT.isInteger() !=
- Input.ConstraintVT.isInteger()) ||
+const bool OpInfoIsScalar = OpInfo.ConstraintVT.isInteger() ||
+OpInfo.ConstraintVT.isFloatingPoint();
+const bool InputIsScalar = Input.ConstraintVT.isInteger() ||
+   Input.ConstraintVT.isFloatingPoint();
+if ((!OpInfoIsScalar && !InputIsScalar) ||
 (MatchRC.second != InputRC.second)) {
   report_fatal_error("Unsupported asm: input constraint"
  " with a matching output constraint of"

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


[clang] [Clang] Allow mixed scalar type constraints for inline asm (PR #65465)

2023-09-06 Thread via cfe-commits

https://github.com/github-actions[bot] labeled 
https://github.com/llvm/llvm-project/pull/65465
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-repl] Emit const variables only once (PR #65257)

2023-09-06 Thread Jonas Hahnfeld via cfe-commits

https://github.com/hahnjo updated 
https://github.com/llvm/llvm-project/pull/65257:

>From 7b52d2ad531286ca3e14c3f05da51c91fd71bd0d Mon Sep 17 00:00:00 2001
From: Jonas Hahnfeld 
Date: Wed, 6 Sep 2023 13:11:57 +0200
Subject: [PATCH] [clang-repl] Emit const variables only once

Disable internal linkage for const variables if IncrementalExtensions
are enabled. Otherwise the variables are emitted multiple times, with
multiple constructions at unique memory locations, during every PTU.
---
 clang/lib/AST/ASTContext.cpp | 10 ++
 clang/test/Interpreter/const.cpp | 29 +
 2 files changed, 39 insertions(+)
 create mode 100644 clang/test/Interpreter/const.cpp

diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 4b1d9e86797b77..f7438e9be19ee1 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -11764,6 +11764,16 @@ GVALinkage ASTContext::GetGVALinkageForFunction(const 
FunctionDecl *FD) const {
 
 static GVALinkage basicGVALinkageForVariable(const ASTContext &Context,
  const VarDecl *VD) {
+  // As an extension for interactive REPLs, make sure constant variables are
+  // only emitted once instead of LinkageComputer::getLVForNamespaceScopeDecl
+  // marking them as internal.
+  if (Context.getLangOpts().CPlusPlus &&
+  Context.getLangOpts().IncrementalExtensions &&
+  VD->getType().isConstQualified() &&
+  !VD->getType().isVolatileQualified() && !VD->isInline() &&
+  !isa(VD) && 
!VD->getDescribedVarTemplate())
+return GVA_DiscardableODR;
+
   if (!VD->isExternallyVisible())
 return GVA_Internal;
 
diff --git a/clang/test/Interpreter/const.cpp b/clang/test/Interpreter/const.cpp
new file mode 100644
index 00..a4b610f1a19d84
--- /dev/null
+++ b/clang/test/Interpreter/const.cpp
@@ -0,0 +1,29 @@
+// UNSUPPORTED: system-aix
+// RUN: cat %s | clang-repl | FileCheck %s
+// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
+
+extern "C" int printf(const char*, ...);
+
+struct A { int val; A(int v); ~A(); void f() const; };
+A::A(int v) : val(v) { printf("A(%d), this = %p\n", val, this); }
+A::~A() { printf("~A, this = %p, val = %d\n", this, val); }
+void A::f() const { printf("f: this = %p, val = %d\n", this, val); }
+
+const A a(1);
+// CHECK: A(1), this = [[THIS:0x[0-9a-f]+]]
+// The constructor must only be called once!
+// CHECK-NOT: A(1)
+
+a.f();
+// CHECK-NEXT: f: this = [[THIS]], val = 1
+a.f();
+// CHECK-NEXT: f: this = [[THIS]], val = 1
+
+%quit
+// There must still be no other constructor!
+// CHECK-NOT: A(1)
+
+// At the end, we expect exactly one destructor call
+// CHECK: ~A
+// CHECK-SAME: this = [[THIS]], val = 1
+// CHECK-NOT: ~A

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


[clang] [clang][AArch64] Add --print-supported-extensions support (PR #65466)

2023-09-06 Thread David Spickett via cfe-commits

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


[clang] [clang][AArch64] Add --print-supported-extensions support (PR #65466)

2023-09-06 Thread David Spickett via cfe-commits

https://github.com/DavidSpickett created 
https://github.com/llvm/llvm-project/pull/65466:

This follows the RISC-V work done in 4b40ced4e5ba10b841516b3970e7699ba8ded572.

This uses AArch64's target parser instead. We just list the names, without the 
"+" on them, which matches RISC-V's format.

```
$ ./bin/clang -target aarch64-linux-gnu --print-supported-extensions
clang version 18.0.0 (https://github.com/llvm/llvm-project.git 
154da8aec20719c82235a6957aa6e461f5a5e030)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: <...>
All available -march extensions for AArch64

aes
b16b16
bf16
brbe
crc
crypto
cssc
<...>
```

Since our extensions don't have versions in the same way there's just one 
column with the name in.

Any extension without a feature name (including the special "none") is not 
listed as those cannot be passed to -march, they're just for the backend. For 
example the MTE extension can be added with "+memtag" but MTE2 and MTE3 do not 
have feature names so they cannot be added to -march.

This does not attempt to tackle the fact that clang allows invalid combinations 
of AArch64 extensions, it simply lists the possible options. It's still up to 
the user to ask for something sensible.

Equally, this has no context of what CPU is being selected. Neither does the 
RISC-V option, the user has to be aware of that.

I've added a target parser test, and a high level clang test that checks RISC-V 
and AArch64 work and that Intel, that doesn't support this, shows the correct 
error.

>From f0157ffb412fd2d6d4aa4a294b631f74e5638878 Mon Sep 17 00:00:00 2001
From: David Spickett 
Date: Wed, 6 Sep 2023 10:15:27 +
Subject: [PATCH] [clang][AArch64] Add --print-supported-extensions support

This follows the RISC-V work done in 4b40ced4e5ba10b841516b3970e7699ba8ded572.

This uses AArch64's target parser instead. We just list the names,
without the "+" on them, which matches RISC-V's format.

```
$ ./bin/clang -target aarch64-linux-gnu --print-supported-extensions
clang version 18.0.0 (https://github.com/llvm/llvm-project.git 
154da8aec20719c82235a6957aa6e461f5a5e030)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: <...>
All available -march extensions for AArch64

aes
b16b16
bf16
brbe
crc
crypto
cssc
<...>
```

Since our extensions don't have versions in the same way there's
just one column with the name in.

Any extension without a feature name (including the special "none")
is not listed as those cannot be passed to -march, they're just
for the backend. For example the MTE extension can be added with
"+memtag" but MTE2 and MTE3 do not have feature names so they
cannot be added to -march.

This does not attempt to tackle the fact that clang allows
invalid combinations of AArch64 extensions, it simply lists the
possible options. It's still up to the user to ask for something
sensible.

Equally, this has no context of what CPU is being selected.
Neither does the RISC-V option, the user has to be aware of that.

I've added a target parser test, and a high level clang test
that checks RISC-V and AArch64 work and that Intel, that doesn't
support this, shows the correct error.
---
 clang/include/clang/Driver/Options.td |  2 +-
 clang/lib/Driver/Driver.cpp   |  3 +-
 .../test/Driver/print-supported-extensions.c  | 14 +
 clang/tools/driver/cc1_main.cpp   | 31 ++-
 .../llvm/TargetParser/AArch64TargetParser.h   |  2 ++
 llvm/lib/TargetParser/AArch64TargetParser.cpp | 10 ++
 .../TargetParser/TargetParserTest.cpp | 22 +
 7 files changed, 81 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/Driver/print-supported-extensions.c

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index e6d8aed6aefc8d9..5840368d6876622 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5260,7 +5260,7 @@ def print_supported_cpus : Flag<["-", "--"], 
"print-supported-cpus">,
   MarshallingInfoFlag>;
 def print_supported_extensions : Flag<["-", "--"], 
"print-supported-extensions">,
   Visibility<[ClangOption, CC1Option, CLOption]>,
-  HelpText<"Print supported extensions for RISC-V">,
+  HelpText<"Print supported -march extensions (RISC-V and AArch64 only)">,
   MarshallingInfoFlag>;
 def : Flag<["-"], "mcpu=help">, Alias;
 def : Flag<["-"], "mtune=help">, Alias;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 9d05549f671e29d..ba723eac2a7ee74 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4284,7 +4284,8 @@ void Driver::BuildActions(Compilation &C, DerivedArgList 
&Args,
 // and quits.
 if (Arg *A = Args.getLastArg(Opt)) {
   if (Opt == options::OPT_print_supported_extensions &&
-  !C.getDefaultToolChain().getTriple().

[clang] [clang][AArch64] Add --print-supported-extensions support (PR #65466)

2023-09-06 Thread David Spickett via cfe-commits

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


[clang] [clang][AArch64] Add --print-supported-extensions support (PR #65466)

2023-09-06 Thread David Spickett via cfe-commits

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


[clang] [clang][AArch64] Add --print-supported-extensions support (PR #65466)

2023-09-06 Thread via cfe-commits

https://github.com/github-actions[bot] labeled 
https://github.com/llvm/llvm-project/pull/65466
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][AArch64] Add --print-supported-extensions support (PR #65466)

2023-09-06 Thread David Spickett via cfe-commits

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


[clang] [clang][AArch64] Add --print-supported-extensions support (PR #65466)

2023-09-06 Thread David Spickett via cfe-commits

DavidSpickett wrote:

I've generalised this a bit but mostly kept to what RISC-V did. If we think 
it's time to completely generalise it then I'll figure that out.

Mostly want to know people are on board with supporting this for AArch64 first.

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


[clang] [clang-repl] Emit const variables only once (PR #65257)

2023-09-06 Thread Jonas Hahnfeld via cfe-commits

hahnjo wrote:

The original patch worked for `clang-repl` but results in strong linkage which 
I found to cause problems with modules downstream in ROOT. Instead the latest 
push moves the special case one level higher to `basicGVALinkageForVariable` 
and returns `GVA_DiscardableODR` which fixes that problem as well.

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


  1   2   3   4   5   >