[clang] [Serialization] Load Specializations Lazily (PR #76774)

2024-01-29 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

> The newest version of this patch still doesn't work correctly. Switching the 
> new `LoadExternalSpecializationsLazily` to disabled by default (somehow the 
> argument didn't work on its own) instead crashes, most of the cases involving 
> `MultiOnDiskHashTable`. I suspect some kind of memory error maybe? Sorry to 
> not be more helpful at the moment...

Thanks for testing it. It shows it is really complex. Maybe I am missing some 
points.

> How about taking a step at a time with this patch. Perhaps we should 
> introduce the on-disk hash table infrastructure and always deserialize 
> everything. Then we can verify that part works on our build infrastructure 
> and then move on with the deferring the template loading. I believe that 
> should be relatively easy to achieve with the current version of the patch.
> 
> Essentially I am proposing making `-fno-load-external-specializations-lazily` 
> default so that we can test it without having to modify build 
> infrastructure...

Good suggestion. It sounds good to me. Then we can test it and improve it step 
by step. I've made it. Now anything in the patch shouldn't be accessed without 
`-fload-external-specializations-lazily`.

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


[clang] [Sema] Fix c23 not checking CheckBoolLikeConversion (PR #79588)

2024-01-29 Thread Pil Eghoff via cfe-commits

https://github.com/pileghoff updated 
https://github.com/llvm/llvm-project/pull/79588

>From 38d96aba5818091d48c40a46738f5adbf881b2a8 Mon Sep 17 00:00:00 2001
From: Pil Eghoff 
Date: Fri, 26 Jan 2024 13:30:17 +0100
Subject: [PATCH] [Sema] Fix c23 not checking CheckBoolLikeConversion

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaChecking.cpp|  2 +-
 clang/test/C/C2x/n3042.c   | 36 --
 clang/test/Sema/warn-int-in-bool-context.c |  7 +
 4 files changed, 29 insertions(+), 18 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9d68be469dac39..df502b50a9536a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -117,6 +117,8 @@ Improvements to Clang's time-trace
 Bug Fixes in This Version
 -
 
+- Fixed missing warnings when doing bool-like conversions in C23 (`#79435 
`_).
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 502b24bcdf8b42..3e08f44a5b84b7 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -16134,7 +16134,7 @@ static void CheckConditionalOperator(Sema &S, 
AbstractConditionalOperator *E,
 /// Check conversion of given expression to boolean.
 /// Input argument E is a logical expression.
 static void CheckBoolLikeConversion(Sema &S, Expr *E, SourceLocation CC) {
-  if (S.getLangOpts().Bool)
+  if (S.getLangOpts().Bool && !S.getLangOpts().C23)
 return;
   if (E->IgnoreParenImpCasts()->getType()->isAtomicType())
 return;
diff --git a/clang/test/C/C2x/n3042.c b/clang/test/C/C2x/n3042.c
index 3f869013af4807..99661b1fb39eba 100644
--- a/clang/test/C/C2x/n3042.c
+++ b/clang/test/C/C2x/n3042.c
@@ -65,13 +65,15 @@ void test() {
   void *other_ptr = null_val;
 
   // Can it be used in all the places a scalar can be used?
-  if (null_val) {}
-  if (!null_val) {}
-  for (;null_val;) {}
-  while (nullptr) {}
-  null_val && nullptr;
-  nullptr || null_val;
-  null_val ? 0 : 1;
+  if (null_val) {} // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  if (!null_val) {}// expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  for (;null_val;) {}  // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  while (nullptr) {}   // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  null_val && nullptr; // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}} \
+  expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  nullptr || null_val; // expected-warning {{implicit conversion of nullptr 
constant to 'bool'}} \
+  expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
+  null_val ? 0 : 1;// expected-warning {{implicit conversion of nullptr 
constant to 'bool'}}
   sizeof(null_val);
   alignas(nullptr_t) int aligned;
 
@@ -95,12 +97,12 @@ void test() {
   // Can it be converted to bool with the result false (this relies on Clang
   // accepting additional kinds of constant expressions where an ICE is
   // required)?
-  static_assert(!nullptr);
-  static_assert(!null_val);
-  static_assert(nullptr);  // expected-error {{static assertion failed due to 
requirement 'nullptr'}} \
-  expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
-  static_assert(null_val); // expected-error {{static assertion failed due to 
requirement 'null_val'}} \
-  expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
+  static_assert(!nullptr);  // expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
+  static_assert(!null_val); // expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
+  static_assert(nullptr);   // expected-error {{static assertion failed due to 
requirement 'nullptr'}} \
+   expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
+  static_assert(null_val);  // expected-error {{static assertion failed due to 
requirement 'null_val'}} \
+   expected-warning {{implicit conversion of 
nullptr constant to 'bool'}}
 
   // Do equality operators work as expected with it?
   static_assert(nullptr == nullptr);
@@ -142,11 +144,11 @@ void test() {
   _Generic(1 ? typed_ptr : nullptr, typeof(typed_ptr) : 0);
 
   // Same for GNU conditional operators?
-  _Generic(nullptr ?: nullptr, nullptr_t : 0);
-  _Generic(null_val ?: null_val, nullptr_t : 0);
+  _Generic(nullptr ?: nullptr, nullptr_t : 0);// expected-warning 
{{implicit conversion of nullptr constant to 'bool'}}
+  _Generic(null_val ?: null_val, nullptr_t : 0);  // expected-warning 
{{implicit conversion

[clang] [clang] WIP: Implement CTAD for type alias template. (PR #77890)

2024-01-29 Thread Haojian Wu via cfe-commits

https://github.com/hokein updated 
https://github.com/llvm/llvm-project/pull/77890

>From 8f7d83aed173688ff1413b7c4445d4576efee872 Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Wed, 24 Jan 2024 14:55:03 +0100
Subject: [PATCH] [clang] Implement Class Template Argument Deduction (CTAD)
 for type alias templates P1814R0.

This patch implements the C++20 feature -- CTAD for alias templates.
This is an initial patch, which covers most of pieces, the major missing
piece is to implement the associated constraints (over.match.class.deduct#3.3)
for the synthesized deduction guides (we can address in a followup).

This patch also refactors the existing 
`ConvertConstructorToDeductionGuideTransform`
to allow code reuse.
---
 clang/include/clang/Sema/Sema.h   |  16 +-
 clang/lib/Sema/CMakeLists.txt |   1 +
 clang/lib/Sema/CTAD.cpp   | 209 ++
 clang/lib/Sema/CTAD.h |  64 +++
 clang/lib/Sema/SemaInit.cpp   | 379 +-
 clang/lib/Sema/SemaTemplate.cpp   | 167 +---
 clang/lib/Sema/SemaTemplateDeduction.cpp  |   9 +
 clang/lib/Sema/SemaTemplateInstantiate.cpp|  22 +-
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  18 +-
 clang/test/SemaCXX/cxx20-ctad-type-alias.cpp  | 133 ++
 10 files changed, 858 insertions(+), 160 deletions(-)
 create mode 100644 clang/lib/Sema/CTAD.cpp
 create mode 100644 clang/lib/Sema/CTAD.h
 create mode 100644 clang/test/SemaCXX/cxx20-ctad-type-alias.cpp

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 1f1cbd11ff7358..24d7809ee17db3 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9280,6 +9280,14 @@ class Sema final {
   const TemplateArgumentList &TemplateArgs,
   sema::TemplateDeductionInfo &Info);
 
+  TemplateDeductionResult
+  DeduceTemplateArguments(TemplateParameterList *TemplateParams,
+  ArrayRef Ps,
+  ArrayRef As,
+  sema::TemplateDeductionInfo &Info,
+  SmallVectorImpl &Deduced,
+  bool NumberOfArgumentsMustMatch);
+
   TemplateDeductionResult SubstituteExplicitTemplateArguments(
   FunctionTemplateDecl *FunctionTemplate,
   TemplateArgumentListInfo &ExplicitTemplateArgs,
@@ -10432,9 +10440,11 @@ class Sema final {
   SourceLocation PointOfInstantiation, FunctionDecl *Decl,
   ArrayRef TemplateArgs,
   ConstraintSatisfaction &Satisfaction);
-  FunctionDecl *InstantiateFunctionDeclaration(FunctionTemplateDecl *FTD,
-   const TemplateArgumentList 
*Args,
-   SourceLocation Loc);
+  FunctionDecl *InstantiateFunctionDeclaration(
+  FunctionTemplateDecl *FTD, const TemplateArgumentList *Args,
+  SourceLocation Loc,
+  CodeSynthesisContext::SynthesisKind CSC =
+  CodeSynthesisContext::ExplicitTemplateArgumentSubstitution);
   void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
  FunctionDecl *Function,
  bool Recursive = false,
diff --git a/clang/lib/Sema/CMakeLists.txt b/clang/lib/Sema/CMakeLists.txt
index 1856a88e9a3271..7a55406171ac74 100644
--- a/clang/lib/Sema/CMakeLists.txt
+++ b/clang/lib/Sema/CMakeLists.txt
@@ -14,6 +14,7 @@ clang_tablegen(OpenCLBuiltins.inc -gen-clang-opencl-builtins
 
 add_clang_library(clangSema
   AnalysisBasedWarnings.cpp
+  CTAD.cpp
   CodeCompleteConsumer.cpp
   DeclSpec.cpp
   DelayedDiagnostic.cpp
diff --git a/clang/lib/Sema/CTAD.cpp b/clang/lib/Sema/CTAD.cpp
new file mode 100644
index 00..f21e4c45df2fea
--- /dev/null
+++ b/clang/lib/Sema/CTAD.cpp
@@ -0,0 +1,209 @@
+//===--- CTAD.cpp - 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "CTAD.h"
+#include "TreeTransform.h"
+#include "TypeLocBuilder.h"
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/ASTMutationListener.h"
+#include "clang/AST/ASTStructuralEquivalence.h"
+#include "clang/AST/CXXInheritance.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclObjC.h"
+#include "clang/AST/DeclTemplate.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Type.h"
+#include "clang/AST/TypeLoc.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/Specifiers.h"
+#include "clang/Sema/DeclSpec.h"
+#include "clang/Sema/ScopeInfo.h"
+#include "clang/Sema/Template.h"
+#include "llvm/ADT/ArrayRef.h"
+#include 
+
+namespace clang {
+
+namespace {
+//

[clang] [clang-tools-extra] [clangd] Prevent printing huge initializer lists in hover definitions (PR #79746)

2024-01-29 Thread kadir çetinkaya via cfe-commits

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


[clang-tools-extra] [clang] [clangd] Prevent printing huge initializer lists in hover definitions (PR #79746)

2024-01-29 Thread kadir çetinkaya via cfe-commits

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


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


[clang] [clang-tools-extra] [clangd] Prevent printing huge initializer lists in hover definitions (PR #79746)

2024-01-29 Thread kadir çetinkaya via cfe-commits


@@ -138,15 +138,9 @@ std::string getNamespaceScope(const Decl *D) {
 
 std::string printDefinition(const Decl *D, PrintingPolicy PP,
 const syntax::TokenBuffer &TB) {
-  if (auto *VD = llvm::dyn_cast(D)) {
-if (auto *IE = VD->getInit()) {
-  // Initializers might be huge and result in lots of memory allocations in
-  // some catostrophic cases. Such long lists are not useful in hover cards
-  // anyway.
-  if (200 < TB.expandedTokens(IE->getSourceRange()).size())
-PP.SuppressInitializers = true;
-}
-  }
+  // Initializers might be huge and result in lots of memory allocations in 
some
+  // catostrophic cases. Such long lists are not useful in hover cards anyway.
+  PP.EntireContentsOfLargeArray = false;

kadircet wrote:

i am not sure if this completely addresses the previous implementation. e.g. we 
can have a nested initializer list, which never has more than N elements 
directly, but the overall initalizer list might be huge. in such a scenario, 
we'll still end up allocating lots of strings.

so can we keep the old filtering while also setting this flag here? note that 
it'll still be ~incomplete. a more concrete approach could be based on counting 
number of "total" elements in the initializer list, and setting the suppression 
flag based on that. i'd actually lean towards such a solution, WDYT?

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


[clang-tools-extra] [clang] [clangd] Prevent printing huge initializer lists in hover definitions (PR #79746)

2024-01-29 Thread kadir çetinkaya via cfe-commits


@@ -1720,6 +1720,12 @@ void StmtPrinter::VisitInitListExpr(InitListExpr* Node) {
   OS << "{";
   for (unsigned i = 0, e = Node->getNumInits(); i != e; ++i) {
 if (i) OS << ", ";
+// TODO: There is duplicated functionality in APValue::printPretty.
+// Would be good to consolidate the two.
+if (!Policy.EntireContentsOfLargeArray && i == 10) {

kadircet wrote:

i am not sure if usage of this flag is actually appropriate here. it 
specifically says "contents of large arrays" but here we have an initializer 
list, not necessarily an array.

moreover this fix is in clang, independent of clangd, so I think it deserves 
its own patch, with relevant owners from clang. can you separate it out? i'd 
like to hear their opinion on using this flag.

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


[clang] [clang] WIP: Implement CTAD for type alias template. (PR #77890)

2024-01-29 Thread Haojian Wu via cfe-commits

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


[clang] [clang] Implement CTAD for type alias template. (PR #77890)

2024-01-29 Thread Haojian Wu via cfe-commits

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


[clang-tools-extra] [compiler-rt] [libc] [flang] [mlir] [libcxx] [lldb] [llvm] [clang] [AArch64] add intrinsic to generate a bfi instruction (PR #79672)

2024-01-29 Thread David Green via cfe-commits

davemgreen wrote:

OK. We would not usually add intrinsics like this without a strong motivating 
case, that could not be optimized in some other way. It is better to use target 
independent options when available, and inline assembly is available as a 
fallback if it is really needed. But I would recommend that they use normal 
and/or/shift operations and let us know about places the compiler isn't 
optimizing them as well as it could be.

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


[clang-tools-extra] [clangd] forward clang-tidy's readability-identifier-naming fix to textDocument/rename (PR #78454)

2024-01-29 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

Linking to the issue this is seeking to address for reference: 
https://github.com/clangd/clangd/issues/1589

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


[clang] [clang-format] Simplify the AfterPlacementOperator option (PR #79796)

2024-01-29 Thread Owen Pan via cfe-commits

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

Change AfterPlacementOperator to a boolean. Also add SBPO_None for never 
inserting a space before a left parenthesis and deprecate SBPO_Never, which 
meant never inserting a space except when after new/delete.

Fixes #78892.

>From 46f4a74f1bdb90751b6b2beb7c0e49c6ee83d2e3 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Mon, 29 Jan 2024 00:43:19 -0800
Subject: [PATCH] [clang-format] Simplify the AfterPlacementOperator option

Change AfterPlacementOperator to a boolean. Also add SBPO_None for never
inserting a space before a left parenthesis and deprecate SBPO_Never, which
meant never inserting a space except when after new/delete.

Fixes #78892.
---
 clang/docs/ClangFormatStyleOptions.rst | 37 +++---
 clang/include/clang/Format/Format.h| 36 -
 clang/lib/Format/Format.cpp| 28 
 clang/lib/Format/TokenAnnotator.cpp|  9 +-
 clang/unittests/Format/ConfigParseTest.cpp | 21 ++--
 clang/unittests/Format/FormatTest.cpp  | 32 ---
 6 files changed, 49 insertions(+), 114 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 4dc0de3a90f265..ce4bf867b26195 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -5276,7 +5276,7 @@ the configuration (without a prefix: ``Auto``).
 
   Possible values:
 
-  * ``SBPO_Never`` (in configuration: ``Never``)
+  * ``SBPO_None`` (in configuration: ``None``)
 Never put a space before opening parentheses.
 
 .. code-block:: c++
@@ -5287,6 +5287,11 @@ the configuration (without a prefix: ``Auto``).
  }
}
 
+  * ``SBPO_Never`` (in configuration: ``Never``)
+This is **deprecated** and replaced by ``Custom`` below, with all
+``SpaceBeforeParensOptions`` but ``AfterPlacementOperator`` set to
+``false``.
+
   * ``SBPO_ControlStatements`` (in configuration: ``ControlStatements``)
 Put a space before opening parentheses only after control statement
 keywords (``for/if/while...``).
@@ -5425,32 +5430,14 @@ the configuration (without a prefix: ``Auto``).
void operator++ (int a);vs.void operator++(int a);
object.operator++ (10);object.operator++(10);
 
-  * ``AfterPlacementOperatorStyle AfterPlacementOperator`` 
:versionbadge:`clang-format 18`
-
-Defines in which cases to put a space between ``new/delete`` operators
-and opening parentheses.
+  * ``bool AfterPlacementOperator`` If ``true``, put a space between operator 
``new``/``delete`` and opening
+parenthesis.
 
-Possible values:
-
-* ``APO_Never`` (in configuration: ``Never``)
-  Remove space after ``new/delete`` operators and before ``(``.
-
-  .. code-block:: c++
-
- new(buf) T;
- delete(buf) T;
-
-* ``APO_Always`` (in configuration: ``Always``)
-  Always add space after ``new/delete`` operators and before ``(``.
-
-  .. code-block:: c++
-
- new (buf) T;
- delete (buf) T;
-
-* ``APO_Leave`` (in configuration: ``Leave``)
-  Leave placement ``new/delete`` expressions as they are.
+.. code-block:: c++
 
+   true:  false:
+   new (buf) T;vs.new(buf) T;
+   delete (buf) T;delete(buf) T;
 
   * ``bool AfterRequiresInClause`` If ``true``, put space between requires 
keyword in a requires clause and
 opening parentheses, if there is one.
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index bc9eecd42f9ebf..5c536bc3f381fa 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4165,6 +4165,10 @@ struct FormatStyle {
 ///  }
 ///}
 /// \endcode
+SBPO_None,
+/// This is **deprecated** and replaced by ``Custom`` below, with all
+/// ``SpaceBeforeParensOptions`` but ``AfterPlacementOperator`` set to
+/// ``false``.
 SBPO_Never,
 /// Put a space before opening parentheses only after control statement
 /// keywords (``for/if/while...``).
@@ -4273,28 +4277,14 @@ struct FormatStyle {
 ///object.operator++ (10);object.operator++(10);
 /// \endcode
 bool AfterOverloadedOperator;
-/// Styles for adding spacing between ``new/delete`` operators and opening
-/// parentheses.
-enum AfterPlacementOperatorStyle : int8_t {
-  /// Remove space after ``new/delete`` operators and before ``(``.
-  /// \code
-  ///new(buf) T;
-  ///delete(buf) T;
-  /// \endcode
-  APO_Never,
-  /// Always add space after ``new/delete`` operators and before ``(``.
-  /// \code
-  ///new (buf) T;
-  ///delete (buf) T;
-  /// \endcode
-  APO_Always,
-  /// Leave placement ``new/delete`` e

[clang] [clang-format] Simplify the AfterPlacementOperator option (PR #79796)

2024-01-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)


Changes

Change AfterPlacementOperator to a boolean. Also add SBPO_None for never 
inserting a space before a left parenthesis and deprecate SBPO_Never, which 
meant never inserting a space except when after new/delete.

Fixes #78892.

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


6 Files Affected:

- (modified) clang/docs/ClangFormatStyleOptions.rst (+12-25) 
- (modified) clang/include/clang/Format/Format.h (+13-23) 
- (modified) clang/lib/Format/Format.cpp (+6-22) 
- (modified) clang/lib/Format/TokenAnnotator.cpp (+1-8) 
- (modified) clang/unittests/Format/ConfigParseTest.cpp (+3-18) 
- (modified) clang/unittests/Format/FormatTest.cpp (+14-18) 


``diff
diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 4dc0de3a90f2650..ce4bf867b26195f 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -5276,7 +5276,7 @@ the configuration (without a prefix: ``Auto``).
 
   Possible values:
 
-  * ``SBPO_Never`` (in configuration: ``Never``)
+  * ``SBPO_None`` (in configuration: ``None``)
 Never put a space before opening parentheses.
 
 .. code-block:: c++
@@ -5287,6 +5287,11 @@ the configuration (without a prefix: ``Auto``).
  }
}
 
+  * ``SBPO_Never`` (in configuration: ``Never``)
+This is **deprecated** and replaced by ``Custom`` below, with all
+``SpaceBeforeParensOptions`` but ``AfterPlacementOperator`` set to
+``false``.
+
   * ``SBPO_ControlStatements`` (in configuration: ``ControlStatements``)
 Put a space before opening parentheses only after control statement
 keywords (``for/if/while...``).
@@ -5425,32 +5430,14 @@ the configuration (without a prefix: ``Auto``).
void operator++ (int a);vs.void operator++(int a);
object.operator++ (10);object.operator++(10);
 
-  * ``AfterPlacementOperatorStyle AfterPlacementOperator`` 
:versionbadge:`clang-format 18`
-
-Defines in which cases to put a space between ``new/delete`` operators
-and opening parentheses.
+  * ``bool AfterPlacementOperator`` If ``true``, put a space between operator 
``new``/``delete`` and opening
+parenthesis.
 
-Possible values:
-
-* ``APO_Never`` (in configuration: ``Never``)
-  Remove space after ``new/delete`` operators and before ``(``.
-
-  .. code-block:: c++
-
- new(buf) T;
- delete(buf) T;
-
-* ``APO_Always`` (in configuration: ``Always``)
-  Always add space after ``new/delete`` operators and before ``(``.
-
-  .. code-block:: c++
-
- new (buf) T;
- delete (buf) T;
-
-* ``APO_Leave`` (in configuration: ``Leave``)
-  Leave placement ``new/delete`` expressions as they are.
+.. code-block:: c++
 
+   true:  false:
+   new (buf) T;vs.new(buf) T;
+   delete (buf) T;delete(buf) T;
 
   * ``bool AfterRequiresInClause`` If ``true``, put space between requires 
keyword in a requires clause and
 opening parentheses, if there is one.
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index bc9eecd42f9ebfd..5c536bc3f381fab 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4165,6 +4165,10 @@ struct FormatStyle {
 ///  }
 ///}
 /// \endcode
+SBPO_None,
+/// This is **deprecated** and replaced by ``Custom`` below, with all
+/// ``SpaceBeforeParensOptions`` but ``AfterPlacementOperator`` set to
+/// ``false``.
 SBPO_Never,
 /// Put a space before opening parentheses only after control statement
 /// keywords (``for/if/while...``).
@@ -4273,28 +4277,14 @@ struct FormatStyle {
 ///object.operator++ (10);object.operator++(10);
 /// \endcode
 bool AfterOverloadedOperator;
-/// Styles for adding spacing between ``new/delete`` operators and opening
-/// parentheses.
-enum AfterPlacementOperatorStyle : int8_t {
-  /// Remove space after ``new/delete`` operators and before ``(``.
-  /// \code
-  ///new(buf) T;
-  ///delete(buf) T;
-  /// \endcode
-  APO_Never,
-  /// Always add space after ``new/delete`` operators and before ``(``.
-  /// \code
-  ///new (buf) T;
-  ///delete (buf) T;
-  /// \endcode
-  APO_Always,
-  /// Leave placement ``new/delete`` expressions as they are.
-  APO_Leave,
-};
-/// Defines in which cases to put a space between ``new/delete`` operators
-/// and opening parentheses.
-/// \version 18
-AfterPlacementOperatorStyle AfterPlacementOperator;
+/// If ``true``, put a space between operator ``new``/``delete`` and 
opening
+/// parenthesis.
+/// \code
+///true:  

[llvm] [clang-tools-extra] [clang] Reapply "InstCombine: Introduce SimplifyDemandedUseFPClass"" (PR #74056)

2024-01-29 Thread Matt Arsenault via cfe-commits

https://github.com/arsenm updated 
https://github.com/llvm/llvm-project/pull/74056

>From 9be777d5b39852cf3c0b2538fd5f712922672caa Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Fri, 1 Dec 2023 18:00:13 +0900
Subject: [PATCH 1/2] Reapply "InstCombine: Introduce
 SimplifyDemandedUseFPClass""

This reverts commit ef388334ee5a3584255b9ef5b3fefdb244fa3fd7.

The referenced issue violates the spec for finite-only math only by
using a return value for a constant infinity.
---
 clang/test/Headers/__clang_hip_math.hip   |  56 +++--
 llvm/include/llvm/Analysis/ValueTracking.h|   4 +
 .../InstCombine/InstCombineInternal.h |   9 +
 .../InstCombineSimplifyDemanded.cpp   | 140 +++-
 .../InstCombine/InstructionCombining.cpp  |  18 +-
 .../InstCombine/simplify-demanded-fpclass.ll  | 203 +++---
 6 files changed, 286 insertions(+), 144 deletions(-)

diff --git a/clang/test/Headers/__clang_hip_math.hip 
b/clang/test/Headers/__clang_hip_math.hip
index c0f4a06acbb8e3..9e15aec94dc28a 100644
--- a/clang/test/Headers/__clang_hip_math.hip
+++ b/clang/test/Headers/__clang_hip_math.hip
@@ -2557,33 +2557,65 @@ extern "C" __device__ double test_nan(const char *tag) {
   return nan(tag);
 }
 
-// CHECK-LABEL: @test_nanf_emptystr(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:ret float 0x7FF8
+// DEFAULT-LABEL: @test_nanf_emptystr(
+// DEFAULT-NEXT:  entry:
+// DEFAULT-NEXT:ret float 0x7FF8
+//
+// FINITEONLY-LABEL: @test_nanf_emptystr(
+// FINITEONLY-NEXT:  entry:
+// FINITEONLY-NEXT:ret float poison
+//
+// APPROX-LABEL: @test_nanf_emptystr(
+// APPROX-NEXT:  entry:
+// APPROX-NEXT:ret float 0x7FF8
 //
 extern "C" __device__ float test_nanf_emptystr() {
   return nanf("");
 }
 
-// CHECK-LABEL: @test_nan_emptystr(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:ret double 0x7FF8
+// DEFAULT-LABEL: @test_nan_emptystr(
+// DEFAULT-NEXT:  entry:
+// DEFAULT-NEXT:ret double 0x7FF8
+//
+// FINITEONLY-LABEL: @test_nan_emptystr(
+// FINITEONLY-NEXT:  entry:
+// FINITEONLY-NEXT:ret double poison
+//
+// APPROX-LABEL: @test_nan_emptystr(
+// APPROX-NEXT:  entry:
+// APPROX-NEXT:ret double 0x7FF8
 //
 extern "C" __device__ double test_nan_emptystr() {
   return nan("");
 }
 
-// CHECK-LABEL: @test_nanf_fill(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:ret float 0x7FF8
+// DEFAULT-LABEL: @test_nanf_fill(
+// DEFAULT-NEXT:  entry:
+// DEFAULT-NEXT:ret float 0x7FF8
+//
+// FINITEONLY-LABEL: @test_nanf_fill(
+// FINITEONLY-NEXT:  entry:
+// FINITEONLY-NEXT:ret float poison
+//
+// APPROX-LABEL: @test_nanf_fill(
+// APPROX-NEXT:  entry:
+// APPROX-NEXT:ret float 0x7FF8
 //
 extern "C" __device__ float test_nanf_fill() {
   return nanf("0x456");
 }
 
-// CHECK-LABEL: @test_nan_fill(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:ret double 0x7FF8
+// DEFAULT-LABEL: @test_nan_fill(
+// DEFAULT-NEXT:  entry:
+// DEFAULT-NEXT:ret double 0x7FF8
+//
+// FINITEONLY-LABEL: @test_nan_fill(
+// FINITEONLY-NEXT:  entry:
+// FINITEONLY-NEXT:ret double poison
+//
+// APPROX-LABEL: @test_nan_fill(
+// APPROX-NEXT:  entry:
+// APPROX-NEXT:ret double 0x7FF8
 //
 extern "C" __device__ double test_nan_fill() {
   return nan("0x123");
diff --git a/llvm/include/llvm/Analysis/ValueTracking.h 
b/llvm/include/llvm/Analysis/ValueTracking.h
index 82c87edd6297cd..f9ce679bc74268 100644
--- a/llvm/include/llvm/Analysis/ValueTracking.h
+++ b/llvm/include/llvm/Analysis/ValueTracking.h
@@ -243,6 +243,10 @@ struct KnownFPClass {
   /// definitely set or false if the sign bit is definitely unset.
   std::optional SignBit;
 
+  bool operator==(KnownFPClass Other) const {
+return KnownFPClasses == Other.KnownFPClasses && SignBit == Other.SignBit;
+  }
+
   /// Return true if it's known this can never be one of the mask entries.
   bool isKnownNever(FPClassTest Mask) const {
 return (KnownFPClasses & Mask) == fcNone;
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h 
b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
index 0bbb22be71569f..9a66fb8f456f95 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
+++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
@@ -551,6 +551,15 @@ class LLVM_LIBRARY_VISIBILITY InstCombinerImpl final
 APInt &UndefElts, unsigned Depth = 0,
 bool AllowMultipleUsers = false) override;
 
+  /// Attempts to replace V with a simpler value based on the demanded
+  /// floating-point classes
+  Value *SimplifyDemandedUseFPClass(Value *V, FPClassTest DemandedMask,
+KnownFPClass &Known, unsigned Depth,
+Instruction *CxtI);
+  bool SimplifyDemandedFPClass(Instruction *I, unsigned Op,
+   FPClassTest DemandedMask, Know

[clang] [llvm] [AMDGPU] Emit a waitcnt instruction after each memory instruction (PR #79236)

2024-01-29 Thread Matt Arsenault via cfe-commits


@@ -2561,6 +2567,70 @@ bool SIMemoryLegalizer::expandAtomicCmpxchgOrRmw(const 
SIMemOpInfo &MOI,
   return Changed;
 }
 
+bool SIMemoryLegalizer::GFX9InsertWaitcntForPreciseMem(MachineFunction &MF) {

arsenm wrote:

can you just make this happen as a consequence of the existing flow rather than 
using an entirely separate pass over the function?

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


[clang] [llvm] [AMDGPU] Emit a waitcnt instruction after each memory instruction (PR #79236)

2024-01-29 Thread Matt Arsenault via cfe-commits


@@ -2561,6 +2567,70 @@ bool SIMemoryLegalizer::expandAtomicCmpxchgOrRmw(const 
SIMemOpInfo &MOI,
   return Changed;
 }
 
+bool SIMemoryLegalizer::GFX9InsertWaitcntForPreciseMem(MachineFunction &MF) {
+  const GCNSubtarget &ST = MF.getSubtarget();
+  const SIInstrInfo *TII = ST.getInstrInfo();
+  IsaVersion IV = getIsaVersion(ST.getCPU());
+
+  bool Changed = false;
+
+  for (auto &MBB : MF) {
+for (auto MI = MBB.begin(); MI != MBB.end();) {
+  MachineInstr &Inst = *MI;
+  ++MI;
+  if (Inst.mayLoadOrStore() == false)

arsenm wrote:

Don't use == false 

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


[clang] [clang] Implement CTAD for type alias template. (PR #77890)

2024-01-29 Thread Haojian Wu via cfe-commits

https://github.com/hokein updated 
https://github.com/llvm/llvm-project/pull/77890

>From becb1bdebc8d10296a5c9f1af64ebae5ca9b68b7 Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Wed, 24 Jan 2024 14:55:03 +0100
Subject: [PATCH] [clang] Implement Class Template Argument Deduction (CTAD)
 for type alias templates P1814R0.

This patch implements the C++20 feature -- CTAD for alias templates.
This is an initial patch, which covers most of pieces, the major missing
piece is to implement the associated constraints (over.match.class.deduct#3.3)
for the synthesized deduction guides (we can address in a followup).

This patch also refactors the existing 
`ConvertConstructorToDeductionGuideTransform`
to allow code reuse.
---
 clang/include/clang/Sema/Sema.h   |  14 +-
 clang/lib/Sema/CMakeLists.txt |   1 +
 clang/lib/Sema/CTAD.cpp   | 209 ++
 clang/lib/Sema/CTAD.h |  65 +++
 clang/lib/Sema/SemaInit.cpp   | 374 +-
 clang/lib/Sema/SemaTemplate.cpp   | 168 ++--
 clang/lib/Sema/SemaTemplateDeduction.cpp  |   9 +
 clang/lib/Sema/SemaTemplateInstantiate.cpp|  25 +-
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  25 +-
 clang/test/SemaCXX/cxx20-ctad-type-alias.cpp  | 133 +++
 10 files changed, 856 insertions(+), 167 deletions(-)
 create mode 100644 clang/lib/Sema/CTAD.cpp
 create mode 100644 clang/lib/Sema/CTAD.h
 create mode 100644 clang/test/SemaCXX/cxx20-ctad-type-alias.cpp

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index b5946e3f3178ff2..c3fba8add4b660f 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9305,6 +9305,12 @@ class Sema final {
   const TemplateArgumentList &TemplateArgs,
   sema::TemplateDeductionInfo &Info);
 
+  TemplateDeductionResult DeduceTemplateArguments(
+  TemplateParameterList *TemplateParams, ArrayRef Ps,
+  ArrayRef As, sema::TemplateDeductionInfo &Info,
+  SmallVectorImpl &Deduced,
+  bool NumberOfArgumentsMustMatch);
+
   TemplateDeductionResult SubstituteExplicitTemplateArguments(
   FunctionTemplateDecl *FunctionTemplate,
   TemplateArgumentListInfo &ExplicitTemplateArgs,
@@ -10457,9 +10463,11 @@ class Sema final {
   SourceLocation PointOfInstantiation, FunctionDecl *Decl,
   ArrayRef TemplateArgs,
   ConstraintSatisfaction &Satisfaction);
-  FunctionDecl *InstantiateFunctionDeclaration(FunctionTemplateDecl *FTD,
-   const TemplateArgumentList 
*Args,
-   SourceLocation Loc);
+  FunctionDecl *InstantiateFunctionDeclaration(
+  FunctionTemplateDecl *FTD, const TemplateArgumentList *Args,
+  SourceLocation Loc,
+  CodeSynthesisContext::SynthesisKind CSC =
+  CodeSynthesisContext::ExplicitTemplateArgumentSubstitution);
   void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
  FunctionDecl *Function,
  bool Recursive = false,
diff --git a/clang/lib/Sema/CMakeLists.txt b/clang/lib/Sema/CMakeLists.txt
index 1856a88e9a3271a..7a55406171ac74a 100644
--- a/clang/lib/Sema/CMakeLists.txt
+++ b/clang/lib/Sema/CMakeLists.txt
@@ -14,6 +14,7 @@ clang_tablegen(OpenCLBuiltins.inc -gen-clang-opencl-builtins
 
 add_clang_library(clangSema
   AnalysisBasedWarnings.cpp
+  CTAD.cpp
   CodeCompleteConsumer.cpp
   DeclSpec.cpp
   DelayedDiagnostic.cpp
diff --git a/clang/lib/Sema/CTAD.cpp b/clang/lib/Sema/CTAD.cpp
new file mode 100644
index 000..745878c717fc4c5
--- /dev/null
+++ b/clang/lib/Sema/CTAD.cpp
@@ -0,0 +1,209 @@
+//===--- CTAD.cpp - 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "CTAD.h"
+#include "TreeTransform.h"
+#include "TypeLocBuilder.h"
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/ASTMutationListener.h"
+#include "clang/AST/ASTStructuralEquivalence.h"
+#include "clang/AST/CXXInheritance.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclObjC.h"
+#include "clang/AST/DeclTemplate.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Type.h"
+#include "clang/AST/TypeLoc.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/Specifiers.h"
+#include "clang/Sema/DeclSpec.h"
+#include "clang/Sema/ScopeInfo.h"
+#include "clang/Sema/Template.h"
+#include "llvm/ADT/ArrayRef.h"
+#include 
+
+namespace clang {
+
+namespace {
+/// Tree transform to "extract" a transformed type from a class template's
+/// constructor to a deducti

[clang] [Clang][Sema] Fix crash when type used in return statement contains errors (PR #79788)

2024-01-29 Thread via cfe-commits

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

Missing changelog, otherwise LGTM

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


[clang-tools-extra] [clangd] forward clang-tidy's readability-identifier-naming fix to textDocument/rename (PR #78454)

2024-01-29 Thread Nathan Ridge via cfe-commits

https://github.com/HighCommander4 commented:

Thanks, the approach in this patch looks pretty good to me.

My only feedback is to encapsulate the "hard coding" into a function like:

```
Option TryConvertToRename(const Diag *D, const Fix *F)
```

because I can imagine in the future coming across other diagnostics that are 
conceptually renames that we may want to handle this way.

Regarding testing: I find lit-tests pretty hard to read and maintain; a nicer 
alternative might be a gtest in `ClangdLSPServerTests` (e.g. see [this 
one](https://searchfox.org/llvm/rev/23b233c8adad5b81e185e50d04356fab64c2f870/clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp#198)
 for testing call hierarchy incoming calls).

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


[clang] [clang] Implement CTAD for type alias template. (PR #77890)

2024-01-29 Thread Haojian Wu via cfe-commits

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


[clang] [clang] Implement CTAD for type alias template. (PR #77890)

2024-01-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Haojian Wu (hokein)


Changes

Fixes #54051

This patch implements the C++20 feature -- CTAD for alias templates.
It is an initial patch, which covers most of pieces, the major missing piece is 
to implement the associated constraints (over.match.class.deduct#3.3) 
for the synthesized deduction guides (we can address it in a followup).

This patch also refactors the existing 
`ConvertConstructorToDeductionGuideTransform` to allow code reuse.

CC @ilya-biryukov, @sam-mccall , @usx95 

---

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


10 Files Affected:

- (modified) clang/include/clang/Sema/Sema.h (+11-3) 
- (modified) clang/lib/Sema/CMakeLists.txt (+1) 
- (added) clang/lib/Sema/CTAD.cpp (+209) 
- (added) clang/lib/Sema/CTAD.h (+65) 
- (modified) clang/lib/Sema/SemaInit.cpp (+367-7) 
- (modified) clang/lib/Sema/SemaTemplate.cpp (+23-145) 
- (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+9) 
- (modified) clang/lib/Sema/SemaTemplateInstantiate.cpp (+22-3) 
- (modified) clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (+16-9) 
- (added) clang/test/SemaCXX/cxx20-ctad-type-alias.cpp (+133) 


``diff
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index b5946e3f3178ff..c3fba8add4b660 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9305,6 +9305,12 @@ class Sema final {
   const TemplateArgumentList &TemplateArgs,
   sema::TemplateDeductionInfo &Info);
 
+  TemplateDeductionResult DeduceTemplateArguments(
+  TemplateParameterList *TemplateParams, ArrayRef Ps,
+  ArrayRef As, sema::TemplateDeductionInfo &Info,
+  SmallVectorImpl &Deduced,
+  bool NumberOfArgumentsMustMatch);
+
   TemplateDeductionResult SubstituteExplicitTemplateArguments(
   FunctionTemplateDecl *FunctionTemplate,
   TemplateArgumentListInfo &ExplicitTemplateArgs,
@@ -10457,9 +10463,11 @@ class Sema final {
   SourceLocation PointOfInstantiation, FunctionDecl *Decl,
   ArrayRef TemplateArgs,
   ConstraintSatisfaction &Satisfaction);
-  FunctionDecl *InstantiateFunctionDeclaration(FunctionTemplateDecl *FTD,
-   const TemplateArgumentList 
*Args,
-   SourceLocation Loc);
+  FunctionDecl *InstantiateFunctionDeclaration(
+  FunctionTemplateDecl *FTD, const TemplateArgumentList *Args,
+  SourceLocation Loc,
+  CodeSynthesisContext::SynthesisKind CSC =
+  CodeSynthesisContext::ExplicitTemplateArgumentSubstitution);
   void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
  FunctionDecl *Function,
  bool Recursive = false,
diff --git a/clang/lib/Sema/CMakeLists.txt b/clang/lib/Sema/CMakeLists.txt
index 1856a88e9a3271..7a55406171ac74 100644
--- a/clang/lib/Sema/CMakeLists.txt
+++ b/clang/lib/Sema/CMakeLists.txt
@@ -14,6 +14,7 @@ clang_tablegen(OpenCLBuiltins.inc -gen-clang-opencl-builtins
 
 add_clang_library(clangSema
   AnalysisBasedWarnings.cpp
+  CTAD.cpp
   CodeCompleteConsumer.cpp
   DeclSpec.cpp
   DelayedDiagnostic.cpp
diff --git a/clang/lib/Sema/CTAD.cpp b/clang/lib/Sema/CTAD.cpp
new file mode 100644
index 00..745878c717fc4c
--- /dev/null
+++ b/clang/lib/Sema/CTAD.cpp
@@ -0,0 +1,209 @@
+//===--- CTAD.cpp - 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "CTAD.h"
+#include "TreeTransform.h"
+#include "TypeLocBuilder.h"
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/ASTMutationListener.h"
+#include "clang/AST/ASTStructuralEquivalence.h"
+#include "clang/AST/CXXInheritance.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclObjC.h"
+#include "clang/AST/DeclTemplate.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Type.h"
+#include "clang/AST/TypeLoc.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/Specifiers.h"
+#include "clang/Sema/DeclSpec.h"
+#include "clang/Sema/ScopeInfo.h"
+#include "clang/Sema/Template.h"
+#include "llvm/ADT/ArrayRef.h"
+#include 
+
+namespace clang {
+
+namespace {
+/// Tree transform to "extract" a transformed type from a class template's
+/// constructor to a deduction guide.
+class ExtractTypeForDeductionGuide
+: public TreeTransform {
+  llvm::SmallVectorImpl &MaterializedTypedefs;
+
+public:
+  typedef TreeTransform Base;
+  ExtractTypeForDeductionGuide(
+  Sema &SemaRef,
+  llvm::SmallVectorImpl &MaterializedTypedefs)
+ 

[clang] [clang][ASTImporter] Improve import of variable template specializations. (PR #78284)

2024-01-29 Thread Balázs Kéri via cfe-commits

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


[clang] 9f80ecb - [clang][ASTImporter] Improve import of variable template specializations. (#78284)

2024-01-29 Thread via cfe-commits

Author: Balázs Kéri
Date: 2024-01-29T10:04:17+01:00
New Revision: 9f80ecb308c989523cc32d4256f7ab61c5b788d7

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

LOG: [clang][ASTImporter] Improve import of variable template specializations. 
(#78284)

Code of `VisitVarTemplateSpecializationDecl` was rewritten based on code
of `VisitVarDecl`. Additional changes (in structural equivalence) were
made to make tests pass.

Added: 


Modified: 
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/ASTStructuralEquivalence.cpp
clang/unittests/AST/ASTImporterGenericRedeclTest.cpp
clang/unittests/AST/ASTImporterTest.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 30567aa1163c4a8..023aaa7f0572b43 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -6385,16 +6385,19 @@ ExpectedDecl 
ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) {
 
 ExpectedDecl ASTNodeImporter::VisitVarTemplateSpecializationDecl(
 VarTemplateSpecializationDecl *D) {
-  // If this record has a definition in the translation unit we're coming from,
-  // but this particular declaration is not that definition, import the
-  // definition and map to that.
-  VarDecl *Definition = D->getDefinition();
-  if (Definition && Definition != D) {
-if (ExpectedDecl ImportedDefOrErr = import(Definition))
-  return Importer.MapImported(D, *ImportedDefOrErr);
-else
-  return ImportedDefOrErr.takeError();
+  // A VarTemplateSpecializationDecl inherits from VarDecl, the import is done
+  // in an analog way (but specialized for this case).
+
+  SmallVector Redecls = getCanonicalForwardRedeclChain(D);
+  auto RedeclIt = Redecls.begin();
+  // Import the first part of the decl chain. I.e. import all previous
+  // declarations starting from the canonical decl.
+  for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
+ExpectedDecl RedeclOrErr = import(*RedeclIt);
+if (!RedeclOrErr)
+  return RedeclOrErr.takeError();
   }
+  assert(*RedeclIt == D);
 
   VarTemplateDecl *VarTemplate = nullptr;
   if (Error Err = importInto(VarTemplate, D->getSpecializedTemplate()))
@@ -6422,116 +6425,132 @@ ExpectedDecl 
ASTNodeImporter::VisitVarTemplateSpecializationDecl(
 
   // Try to find an existing specialization with these template arguments.
   void *InsertPos = nullptr;
-  VarTemplateSpecializationDecl *D2 = VarTemplate->findSpecialization(
-  TemplateArgs, InsertPos);
-  if (D2) {
-// We already have a variable template specialization with these template
-// arguments.
-
-// FIXME: Check for specialization vs. instantiation errors.
-
-if (VarDecl *FoundDef = D2->getDefinition()) {
-  if (!D->isThisDeclarationADefinition() ||
-  IsStructuralMatch(D, FoundDef)) {
-// The record types structurally match, or the "from" translation
-// unit only had a forward declaration anyway; call it the same
-// variable.
-return Importer.MapImported(D, FoundDef);
+  VarTemplateSpecializationDecl *FoundSpecialization =
+  VarTemplate->findSpecialization(TemplateArgs, InsertPos);
+  if (FoundSpecialization) {
+if (IsStructuralMatch(D, FoundSpecialization)) {
+  VarDecl *FoundDef = FoundSpecialization->getDefinition();
+  if (D->getDeclContext()->isRecord()) {
+// In a record, it is allowed only to have one optional declaration and
+// one definition of the (static or constexpr) variable template.
+assert(
+FoundSpecialization->getDeclContext()->isRecord() &&
+"Member variable template specialization imported as non-member, "
+"inconsistent imported AST?");
+if (FoundDef)
+  return Importer.MapImported(D, FoundDef);
+if (!D->isThisDeclarationADefinition())
+  return Importer.MapImported(D, FoundSpecialization);
+  } else {
+// If definition is imported and there is already one, map to it.
+// Otherwise create a new variable and link it to the existing.
+if (FoundDef && D->isThisDeclarationADefinition())
+  return Importer.MapImported(D, FoundDef);
   }
+} else {
+  return make_error(ASTImportError::NameConflict);
 }
-  } else {
-TemplateArgumentListInfo ToTAInfo;
-if (const ASTTemplateArgumentListInfo *Args = D->getTemplateArgsInfo()) {
-  if (Error Err = ImportTemplateArgumentListInfo(*Args, ToTAInfo))
-return std::move(Err);
-}
+  }
 
-using PartVarSpecDecl = VarTemplatePartialSpecializationDecl;
-// Create a new specialization.
-if (auto *FromPartial = dyn_cast(D)) {
-  // Import TemplateArgumentListInfo
-  TemplateArgumentListInfo ArgInfos;
-  const auto *FromTAArgsA

[clang-tools-extra] [clangd] Support outgoing calls in call hierarchy (PR #77556)

2024-01-29 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

@sam-mccall review ping :)

I would particularly appreciate feedback on whether I should plan to set aside 
some time to implement the "deep lookup optimization" (from [this 
comment](https://reviews.llvm.org/D93829#4258101)), or whether the 2.5% 
increase in index memory usage (which I've achieved by implementing everything 
_except_ the deep lookup optimization from that comment) is acceptable.

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


[clang] [Serialization] Load Specializations Lazily (PR #76774)

2024-01-29 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

> > The newest version of this patch still doesn't work correctly. Switching 
> > the new `LoadExternalSpecializationsLazily` to disabled by default (somehow 
> > the argument didn't work on its own) instead crashes, most of the cases 
> > involving `MultiOnDiskHashTable`. I suspect some kind of memory error 
> > maybe? Sorry to not be more helpful at the moment...
> 
> Thanks for testing it. It shows it is really complex. Maybe I am missing some 
> points.
> 
> > How about taking a step at a time with this patch. Perhaps we should 
> > introduce the on-disk hash table infrastructure and always deserialize 
> > everything. Then we can verify that part works on our build infrastructure 
> > and then move on with the deferring the template loading. I believe that 
> > should be relatively easy to achieve with the current version of the patch.
> > Essentially I am proposing making 
> > `-fno-load-external-specializations-lazily` default so that we can test it 
> > without having to modify build infrastructure...
> 
> Good suggestion. It sounds good to me. Then we can test it and improve it 
> step by step. I've made it. Now anything in the patch shouldn't be accessed 
> without `-fload-external-specializations-lazily`.
> 
> Introducing a new flag will require a change in the document. I'll do that 
> later after this get landed.

@hahnjo, could you test again?

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


[clang] [Serialization] Load Specializations Lazily (PR #76774)

2024-01-29 Thread Jonas Hahnfeld via cfe-commits

hahnjo wrote:

As far as I can tell from 
https://github.com/llvm/llvm-project/pull/76774#issuecomment-1914177330 above, 
the last push only changed the default value of 
`LoadExternalSpecializationsLazily`. In that case, my test results from 
https://github.com/llvm/llvm-project/pull/76774#issuecomment-1912182171 remain 
fully valid, especially

> Switching the new `LoadExternalSpecializationsLazily` to disabled by default 
> (somehow the argument didn't work on its own) instead crashes, most of the 
> cases involving `MultiOnDiskHashTable`. I suspect some kind of memory error 
> maybe?

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


[clang] [Serialization] Load Specializations Lazily (PR #76774)

2024-01-29 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

Ok, so it sounds it fails earlier than I expected. We might be missing 
something in the implementation of the on-disk hashtable. Have you had a chance 
to run valgrind?

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


[clang] [Serialization] Load Specializations Lazily (PR #76774)

2024-01-29 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

> As far as I can tell from [#76774 
> (comment)](https://github.com/llvm/llvm-project/pull/76774#issuecomment-1914177330)
>  above, the last push only changed the default value of 
> `LoadExternalSpecializationsLazily`. In that case, my test results from 
> [#76774 
> (comment)](https://github.com/llvm/llvm-project/pull/76774#issuecomment-1912182171)
>  remain fully valid, especially
> 
> > Switching the new `LoadExternalSpecializationsLazily` to disabled by 
> > default (somehow the argument didn't work on its own) instead crashes, most 
> > of the cases involving `MultiOnDiskHashTable`. I suspect some kind of 
> > memory error maybe?

No, this newest patch changes  besides changing the default value. For example, 
https://github.com/llvm/llvm-project/pull/76774/commits/22c9d1145eb57d9c2cb2ef490b7c474598dd5d12#diff-125f472e690aa3d973bc42aa3c5d580226c5c47661551aca2889f960681aa64dR232-R237
 now we won't write specializations into the hash table, while the original 
patch tries to load all the decls from the consumers' side only. This patch 
touches the producer's side.

Maybe I shouldn't push force to make the history clear..

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


[clang] [flang] [libcxx] [compiler-rt] [libc] [llvm] [clang-tools-extra] [mlir] [VPlan] Replace VPRecipeOrVPValue with VP2VP recipe simplification. (PR #76090)

2024-01-29 Thread Florian Hahn via cfe-commits

https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/76090

>From 7c31c8bc2acf60bd50cb6d63944ee8d4946b9638 Mon Sep 17 00:00:00 2001
From: Florian Hahn 
Date: Thu, 4 May 2023 21:33:24 +0100
Subject: [PATCH 1/4] [VPlan] Replace VPRecieOrVPValue with VP2VP recipe
 simplification.

Move simplification of VPBlendRecipes from early VPlan construction to
VPlan-to-VPlan based recipe simplification. This simplifies initial
construction.

Note that some in-loop reduction tests are failing at the moment, due to
the reduction predicate being created after the reduction recipe. I will
provide a patch for that soon.
---
 .../Transforms/Vectorize/LoopVectorize.cpp| 99 +++
 .../Transforms/Vectorize/VPRecipeBuilder.h| 23 ++---
 .../Transforms/Vectorize/VPlanTransforms.cpp  | 34 ++-
 .../Transforms/Vectorize/VPlanTransforms.h|  1 -
 4 files changed, 74 insertions(+), 83 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp 
b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index f82e161fb846d18..609a927d23754b3 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -8256,31 +8256,10 @@ VPWidenIntOrFpInductionRecipe 
*VPRecipeBuilder::tryToOptimizeInductionTruncate(
   return nullptr;
 }
 
-VPRecipeOrVPValueTy VPRecipeBuilder::tryToBlend(PHINode *Phi,
-ArrayRef Operands,
-VPlanPtr &Plan) {
-  // If all incoming values are equal, the incoming VPValue can be used 
directly
-  // instead of creating a new VPBlendRecipe.
-  if (llvm::all_equal(Operands))
-return Operands[0];
-
+VPBlendRecipe *VPRecipeBuilder::tryToBlend(PHINode *Phi,
+   ArrayRef Operands,
+   VPlanPtr &Plan) {
   unsigned NumIncoming = Phi->getNumIncomingValues();
-  // For in-loop reductions, we do not need to create an additional select.
-  VPValue *InLoopVal = nullptr;
-  for (unsigned In = 0; In < NumIncoming; In++) {
-PHINode *PhiOp =
-dyn_cast_or_null(Operands[In]->getUnderlyingValue());
-if (PhiOp && CM.isInLoopReduction(PhiOp)) {
-  assert(!InLoopVal && "Found more than one in-loop reduction!");
-  InLoopVal = Operands[In];
-}
-  }
-
-  assert((!InLoopVal || NumIncoming == 2) &&
- "Found an in-loop reduction for PHI with unexpected number of "
- "incoming values");
-  if (InLoopVal)
-return Operands[Operands[0] == InLoopVal ? 1 : 0];
 
   // We know that all PHIs in non-header blocks are converted into selects, so
   // we don't have to worry about the insertion order and we can just use the
@@ -8292,13 +8271,13 @@ VPRecipeOrVPValueTy VPRecipeBuilder::tryToBlend(PHINode 
*Phi,
   for (unsigned In = 0; In < NumIncoming; In++) {
 VPValue *EdgeMask =
 createEdgeMask(Phi->getIncomingBlock(In), Phi->getParent(), *Plan);
-assert((EdgeMask || NumIncoming == 1) &&
+assert((EdgeMask || NumIncoming == 1 || Operands[In] == Operands[0]) &&
"Multiple predecessors with one having a full mask");
 OperandsWithMask.push_back(Operands[In]);
 if (EdgeMask)
   OperandsWithMask.push_back(EdgeMask);
   }
-  return toVPRecipeResult(new VPBlendRecipe(Phi, OperandsWithMask));
+  return new VPBlendRecipe(Phi, OperandsWithMask);
 }
 
 VPWidenCallRecipe *VPRecipeBuilder::tryToWidenCall(CallInst *CI,
@@ -8464,9 +8443,8 @@ void VPRecipeBuilder::fixHeaderPhis() {
   }
 }
 
-VPRecipeOrVPValueTy VPRecipeBuilder::handleReplication(Instruction *I,
-   VFRange &Range,
-   VPlan &Plan) {
+VPRecipeBase *VPRecipeBuilder::handleReplication(Instruction *I, VFRange 
&Range,
+ VPlan &Plan) {
   bool IsUniform = LoopVectorizationPlanner::getDecisionAndClampRange(
   [&](ElementCount VF) { return CM.isUniformAfterVectorization(I, VF); },
   Range);
@@ -8518,14 +8496,12 @@ VPRecipeOrVPValueTy 
VPRecipeBuilder::handleReplication(Instruction *I,
 
   auto *Recipe = new VPReplicateRecipe(I, Plan.mapToVPValues(I->operands()),
IsUniform, BlockInMask);
-  return toVPRecipeResult(Recipe);
+  return Recipe;
 }
 
-VPRecipeOrVPValueTy
-VPRecipeBuilder::tryToCreateWidenRecipe(Instruction *Instr,
-ArrayRef Operands,
-VFRange &Range, VPBasicBlock *VPBB,
-VPlanPtr &Plan) {
+VPRecipeBase *VPRecipeBuilder::tryToCreateWidenRecipe(
+Instruction *Instr, ArrayRef Operands, VFRange &Range,
+VPBasicBlock *VPBB, VPlanPtr &Plan) {
   // First, check for specific widening recipes that deal with inductions, Phi
   // nodes, calls and memory operations.
   VPRecipeBase *Recipe;
@@ -8538,7 +8514,7 @@ 

[clang] [llvm] [clang-tools-extra] [PowerPC] Check value uses in ValueBit tracking (PR #66040)

2024-01-29 Thread Kai Luo via cfe-commits

bzEq wrote:

Though I do see some codegen improvement, I don't think we should check uses 
inside `getValueBits`, since `getValueBits` is for analysis and is gathering as 
much information as it can. Can you post your motivation code?

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


[clang-tools-extra] [clang] [llvm] [Clang] Fix : More Detailed "No expected directives found" (PR #78338)

2024-01-29 Thread Shourya Goel via cfe-commits

Sh0g0-1758 wrote:

gentle ping @reviewers

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


[llvm] [libcxxabi] [libcxx] [clang-tools-extra] [libunwind] [compiler-rt] [lld] [libc] [clang] [flang] [lldb] [PowerPC] Combine sub within setcc back to sext (PR #66978)

2024-01-29 Thread Kai Luo via cfe-commits

bzEq wrote:

Please provide more description in PR summary.

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


[clang-tools-extra] [libcxx] [clang] [llvm] [lld] [lldb] [libc] intrinsic to generate a bfi instruction (PR #79655)

2024-01-29 Thread David Spickett via cfe-commits

DavidSpickett wrote:

If you're referring to the CI that runs here, we've been having capacity issues 
lately. Another way to "resubmit" is to rebase the PR.

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


[clang] [clang] Implement CTAD for type alias template. (PR #77890)

2024-01-29 Thread via cfe-commits

cor3ntin wrote:

@hokein @sam-mccall to repeat what was said in the language group last week.

We do not think a feature flag is a good fit. 

 - Until clang 19 ships (in 6 months) we do not need to stabilize the feature 
(but ofc we should avoid regressions, which we would not find if hidden behind 
a flag), and the flag does not guarantee existing features are not impacted.
 
And if we break trunk, we revert, you get extra test cases... it's perfectly 
fine

 - The feature should be behind a -std=C++20 flag.
 - We should not update __cpp_deduction_guides until the feature is battle 
tested

We do that for about every feature that is not concept/module scale (and then 
again, these things were tses), and this isn't big enough to warrant a novel 
approach.
  
I still think we should land this soon and we can start a review whenever you 
are ready.
If you want to land it in an incomplete state, we just need to make sure we 
have a good collective understanding of the remaining work that would need to 
be done to bring the feature to completion (tests with fix me, issues, etc)

Does that make sense to you?





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


[libcxx] [compiler-rt] [clang-tools-extra] [flang] [mlir] [clang] [libc] [llvm] [VPlan] Replace VPRecipeOrVPValue with VP2VP recipe simplification. (PR #76090)

2024-01-29 Thread Florian Hahn via cfe-commits


@@ -9027,7 +8994,8 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
 // the phi until LoopExitValue. We keep track of the previous item
 // (PreviousLink) to tell which of the two operands of a Link will remain
 // scalar and which will be reduced. For minmax by select(cmp), Link will 
be
-// the select instructions.
+// the select instructions. Blend recipes will get folded to their non-phi

fhahn wrote:

Done, thanks!

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


[clang-tools-extra] [flang] [libc] [compiler-rt] [libcxx] [clang] [llvm] [mlir] [VPlan] Replace VPRecipeOrVPValue with VP2VP recipe simplification. (PR #76090)

2024-01-29 Thread Florian Hahn via cfe-commits


@@ -9058,6 +9026,20 @@ void 
LoopVectorizationPlanner::adjustRecipesForReductions(
 LinkVPBB->insert(FMulRecipe, CurrentLink->getIterator());
 VecOp = FMulRecipe;
   } else {
+auto *Blend = dyn_cast(CurrentLink);
+if (PhiR->isInLoop() && Blend) {
+  assert(Blend->getNumIncomingValues() == 2 &&
+ "Blend must have 2 incoming values");
+  if (Blend->getIncomingValue(0) == PhiR)
+Blend->replaceAllUsesWith(Blend->getIncomingValue(1));
+  else {
+Blend->replaceAllUsesWith(Blend->getIncomingValue(0));
+assert(Blend->getIncomingValue(1) == PhiR &&
+   "PhiR must be an operand of the blend");

fhahn wrote:

Done, thanks!

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


[clang-tools-extra] [mlir] [libcxx] [compiler-rt] [clang] [llvm] [libc] [flang] [VPlan] Replace VPRecipeOrVPValue with VP2VP recipe simplification. (PR #76090)

2024-01-29 Thread Florian Hahn via cfe-commits


@@ -827,6 +827,16 @@ static unsigned getOpcodeForRecipe(VPRecipeBase &R) {
 
 /// Try to simplify recipe \p R.
 static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
+  // Try to remove redundant blend recipes.
+  if (auto *Blend = dyn_cast(&R)) {

fhahn wrote:

Done, thanks!

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


[clang-tools-extra] [libunwind] [libcxx] [compiler-rt] [clang] [llvm] [lld] [libcxxabi] [lldb] [libc] [flang] [PowerPC] Combine sub within setcc back to sext (PR #66978)

2024-01-29 Thread Kai Luo via cfe-commits


@@ -14428,15 +14431,52 @@ SDValue PPCTargetLowering::combineSetCC(SDNode *N,
 // x != 0-y --> x+y != 0
 if (RHS.getOpcode() == ISD::SUB && isNullConstant(RHS.getOperand(0)) &&
 RHS.hasOneUse()) {
-  SDLoc DL(N);
-  SelectionDAG &DAG = DCI.DAG;
-  EVT VT = N->getValueType(0);
-  EVT OpVT = LHS.getValueType();
   SDValue Add = DAG.getNode(ISD::ADD, DL, OpVT, LHS, RHS.getOperand(1));
   return DAG.getSetCC(DL, VT, Add, DAG.getConstant(0, DL, OpVT), CC);
 }
   }
 
+  if (CC == ISD::SETULT && isa(RHS)) {
+uint64_t RHSVal = cast(RHS)->getZExtValue();
+if (LHS.getOpcode() == ISD::ADD && isa(LHS.getOperand(1))) 
{
+  uint64_t Addend = 
cast(LHS.getOperand(1))->getZExtValue();
+  if (OpVT == MVT::i64) {
+uint64_t ShiftVal = ~Addend + 1;

bzEq wrote:

```suggestion
uint64_t ShiftVal = -Addend;
```

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


[libcxx] [lldb] [compiler-rt] [clang-tools-extra] [flang] [clang] [libcxxabi] [libc] [libunwind] [lld] [llvm] [PowerPC] Combine sub within setcc back to sext (PR #66978)

2024-01-29 Thread Kai Luo via cfe-commits


@@ -14428,15 +14431,52 @@ SDValue PPCTargetLowering::combineSetCC(SDNode *N,
 // x != 0-y --> x+y != 0
 if (RHS.getOpcode() == ISD::SUB && isNullConstant(RHS.getOperand(0)) &&
 RHS.hasOneUse()) {
-  SDLoc DL(N);
-  SelectionDAG &DAG = DCI.DAG;
-  EVT VT = N->getValueType(0);
-  EVT OpVT = LHS.getValueType();
   SDValue Add = DAG.getNode(ISD::ADD, DL, OpVT, LHS, RHS.getOperand(1));
   return DAG.getSetCC(DL, VT, Add, DAG.getConstant(0, DL, OpVT), CC);
 }
   }
 
+  if (CC == ISD::SETULT && isa(RHS)) {
+uint64_t RHSVal = cast(RHS)->getZExtValue();
+if (LHS.getOpcode() == ISD::ADD && isa(LHS.getOperand(1))) 
{
+  uint64_t Addend = 
cast(LHS.getOperand(1))->getZExtValue();
+  if (OpVT == MVT::i64) {
+uint64_t ShiftVal = ~Addend + 1;
+uint64_t CmpVal = ~RHSVal + 1;

bzEq wrote:

```suggestion
uint64_t CmpVal = -RHSVal;
```

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


[libunwind] [clang-tools-extra] [lld] [flang] [libc] [compiler-rt] [libcxx] [clang] [libcxxabi] [lldb] [llvm] [PowerPC] Combine sub within setcc back to sext (PR #66978)

2024-01-29 Thread Kai Luo via cfe-commits


@@ -14428,15 +14431,52 @@ SDValue PPCTargetLowering::combineSetCC(SDNode *N,
 // x != 0-y --> x+y != 0
 if (RHS.getOpcode() == ISD::SUB && isNullConstant(RHS.getOperand(0)) &&
 RHS.hasOneUse()) {
-  SDLoc DL(N);
-  SelectionDAG &DAG = DCI.DAG;
-  EVT VT = N->getValueType(0);
-  EVT OpVT = LHS.getValueType();
   SDValue Add = DAG.getNode(ISD::ADD, DL, OpVT, LHS, RHS.getOperand(1));
   return DAG.getSetCC(DL, VT, Add, DAG.getConstant(0, DL, OpVT), CC);
 }
   }
 
+  if (CC == ISD::SETULT && isa(RHS)) {
+uint64_t RHSVal = cast(RHS)->getZExtValue();
+if (LHS.getOpcode() == ISD::ADD && isa(LHS.getOperand(1))) 
{
+  uint64_t Addend = 
cast(LHS.getOperand(1))->getZExtValue();
+  if (OpVT == MVT::i64) {
+uint64_t ShiftVal = ~Addend + 1;
+uint64_t CmpVal = ~RHSVal + 1;
+if (isPowerOf2_64(ShiftVal) && ShiftVal << 1 == CmpVal) {

bzEq wrote:

Add comment for the DAG pattern found. Better provide alive2 prove in the PR 
summary.

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


[clang-tools-extra] [flang] [libc] [compiler-rt] [libcxx] [clang] [llvm] [mlir] [VPlan] Replace VPRecipeOrVPValue with VP2VP recipe simplification. (PR #76090)

2024-01-29 Thread Florian Hahn via cfe-commits

https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/76090

>From 7c31c8bc2acf60bd50cb6d63944ee8d4946b9638 Mon Sep 17 00:00:00 2001
From: Florian Hahn 
Date: Thu, 4 May 2023 21:33:24 +0100
Subject: [PATCH 1/5] [VPlan] Replace VPRecieOrVPValue with VP2VP recipe
 simplification.

Move simplification of VPBlendRecipes from early VPlan construction to
VPlan-to-VPlan based recipe simplification. This simplifies initial
construction.

Note that some in-loop reduction tests are failing at the moment, due to
the reduction predicate being created after the reduction recipe. I will
provide a patch for that soon.
---
 .../Transforms/Vectorize/LoopVectorize.cpp| 99 +++
 .../Transforms/Vectorize/VPRecipeBuilder.h| 23 ++---
 .../Transforms/Vectorize/VPlanTransforms.cpp  | 34 ++-
 .../Transforms/Vectorize/VPlanTransforms.h|  1 -
 4 files changed, 74 insertions(+), 83 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp 
b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index f82e161fb846d18..609a927d23754b3 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -8256,31 +8256,10 @@ VPWidenIntOrFpInductionRecipe 
*VPRecipeBuilder::tryToOptimizeInductionTruncate(
   return nullptr;
 }
 
-VPRecipeOrVPValueTy VPRecipeBuilder::tryToBlend(PHINode *Phi,
-ArrayRef Operands,
-VPlanPtr &Plan) {
-  // If all incoming values are equal, the incoming VPValue can be used 
directly
-  // instead of creating a new VPBlendRecipe.
-  if (llvm::all_equal(Operands))
-return Operands[0];
-
+VPBlendRecipe *VPRecipeBuilder::tryToBlend(PHINode *Phi,
+   ArrayRef Operands,
+   VPlanPtr &Plan) {
   unsigned NumIncoming = Phi->getNumIncomingValues();
-  // For in-loop reductions, we do not need to create an additional select.
-  VPValue *InLoopVal = nullptr;
-  for (unsigned In = 0; In < NumIncoming; In++) {
-PHINode *PhiOp =
-dyn_cast_or_null(Operands[In]->getUnderlyingValue());
-if (PhiOp && CM.isInLoopReduction(PhiOp)) {
-  assert(!InLoopVal && "Found more than one in-loop reduction!");
-  InLoopVal = Operands[In];
-}
-  }
-
-  assert((!InLoopVal || NumIncoming == 2) &&
- "Found an in-loop reduction for PHI with unexpected number of "
- "incoming values");
-  if (InLoopVal)
-return Operands[Operands[0] == InLoopVal ? 1 : 0];
 
   // We know that all PHIs in non-header blocks are converted into selects, so
   // we don't have to worry about the insertion order and we can just use the
@@ -8292,13 +8271,13 @@ VPRecipeOrVPValueTy VPRecipeBuilder::tryToBlend(PHINode 
*Phi,
   for (unsigned In = 0; In < NumIncoming; In++) {
 VPValue *EdgeMask =
 createEdgeMask(Phi->getIncomingBlock(In), Phi->getParent(), *Plan);
-assert((EdgeMask || NumIncoming == 1) &&
+assert((EdgeMask || NumIncoming == 1 || Operands[In] == Operands[0]) &&
"Multiple predecessors with one having a full mask");
 OperandsWithMask.push_back(Operands[In]);
 if (EdgeMask)
   OperandsWithMask.push_back(EdgeMask);
   }
-  return toVPRecipeResult(new VPBlendRecipe(Phi, OperandsWithMask));
+  return new VPBlendRecipe(Phi, OperandsWithMask);
 }
 
 VPWidenCallRecipe *VPRecipeBuilder::tryToWidenCall(CallInst *CI,
@@ -8464,9 +8443,8 @@ void VPRecipeBuilder::fixHeaderPhis() {
   }
 }
 
-VPRecipeOrVPValueTy VPRecipeBuilder::handleReplication(Instruction *I,
-   VFRange &Range,
-   VPlan &Plan) {
+VPRecipeBase *VPRecipeBuilder::handleReplication(Instruction *I, VFRange 
&Range,
+ VPlan &Plan) {
   bool IsUniform = LoopVectorizationPlanner::getDecisionAndClampRange(
   [&](ElementCount VF) { return CM.isUniformAfterVectorization(I, VF); },
   Range);
@@ -8518,14 +8496,12 @@ VPRecipeOrVPValueTy 
VPRecipeBuilder::handleReplication(Instruction *I,
 
   auto *Recipe = new VPReplicateRecipe(I, Plan.mapToVPValues(I->operands()),
IsUniform, BlockInMask);
-  return toVPRecipeResult(Recipe);
+  return Recipe;
 }
 
-VPRecipeOrVPValueTy
-VPRecipeBuilder::tryToCreateWidenRecipe(Instruction *Instr,
-ArrayRef Operands,
-VFRange &Range, VPBasicBlock *VPBB,
-VPlanPtr &Plan) {
+VPRecipeBase *VPRecipeBuilder::tryToCreateWidenRecipe(
+Instruction *Instr, ArrayRef Operands, VFRange &Range,
+VPBasicBlock *VPBB, VPlanPtr &Plan) {
   // First, check for specific widening recipes that deal with inductions, Phi
   // nodes, calls and memory operations.
   VPRecipeBase *Recipe;
@@ -8538,7 +8514,7 @@ 

[clang] [llvm] [AArch64][TargetParser] Add mcpu alias for Microsoft Azure Cobalt 100. (PR #79614)

2024-01-29 Thread David Spickett via cfe-commits

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

```
/var/lib/buildkite-agent/builds/linux-56-59b8f5d88-r6v66-1/llvm-project/github-pull-requests/llvm/unittests/TargetParser/TargetParserTest.cpp:1662:
 Failure
Expected equality of these values:
  List.size()
Which is: 68
  NumAArch64CPUArchs
Which is: 67
```
Needs fixing, but otherwise LGTM.

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


[clang-tools-extra] [llvm] [clang] [PowerPC] Check value uses in ValueBit tracking (PR #66040)

2024-01-29 Thread Qiu Chaofan via cfe-commits

ecnelises wrote:

The motivating case:

```llvm
define i64 @splatByte(i64 %a) {
entry:
  %x0 = shl i64 %a, 8
  %x1 = and i64 %a, 255
  %x2 = or i64 %x0, %x1
  %x3 = shl i64 %x2, 16
  %x4 = and i64 %x2, 65535
  %x5 = or i64 %x3, %x4
  %x6 = shl i64 %x5, 32
  %x7 = and i64 %x5, 4294967295
  %x8 = or i64 %x6, %x7
  ret i64 %x8
}
```

```
; before patch
rotldi 4, 3, 32
rlwimi 4, 3, 0, 24, 31
rlwimi 4, 3, 8, 16, 23
rlwimi 4, 3, 16, 8, 15
rlwimi 4, 3, 24, 0, 7
rldimi 4, 3, 40, 16
rldimi 4, 3, 48, 8
rldimi 4, 3, 56, 0
mr 3, 4

; after patch
rldimi 3, 3, 8, 0
rldimi 3, 3, 16, 0
rlwinm 3, 3, 0, 1, 0
```

Bit permutation is not good at selecting globally optimized result. This is the 
limitation until a better selector respecting rotate operations is introduced.

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


[clang] [clang][Interp] Add inline descriptor to global variables (PR #72892)

2024-01-29 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Ping

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


[libcxx] [compiler-rt] [clang-tools-extra] [flang] [mlir] [clang] [libc] [llvm] [VPlan] Replace VPRecipeOrVPValue with VP2VP recipe simplification. (PR #76090)

2024-01-29 Thread Florian Hahn via cfe-commits

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


[libcxx] [clang-tools-extra] [flang] [mlir] [clang] [llvm] [LV] Improve AnyOf reduction codegen. (PR #78304)

2024-01-29 Thread Florian Hahn via cfe-commits

https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/78304

>From 9846f970b6b394ccc3af25b92f238377a8ae7807 Mon Sep 17 00:00:00 2001
From: Florian Hahn 
Date: Sun, 14 Jan 2024 18:06:36 +
Subject: [PATCH] [LV] Improve AnyOf reduction codegen.

Update AnyOf reduction code generation to only keep track of the AnyOf
property in a boolean vector in the loop, only selecting either the new
or start value in the middle block.

This fixes the #62565, as now there aren't multiple uses of the
start/new values.

Fixes https://github.com/llvm/llvm-project/issues/62565
---
 .../include/llvm/Transforms/Utils/LoopUtils.h |   9 --
 llvm/lib/Transforms/Utils/LoopUtils.cpp   |  24 +--
 .../Vectorize/LoopVectorizationPlanner.h  |   1 +
 .../Transforms/Vectorize/LoopVectorize.cpp|  44 +-
 .../lib/Transforms/Vectorize/VPlanRecipes.cpp |   7 +-
 .../LoopVectorize/AArch64/sve-select-cmp.ll   |  38 ++---
 .../RISCV/select-cmp-reduction.ll | 120 ++
 .../LoopVectorize/select-cmp-predicated.ll|  29 ++--
 .../Transforms/LoopVectorize/select-cmp.ll| 146 +-
 ...tion-start-value-may-be-undef-or-poison.ll |  43 +++---
 10 files changed, 218 insertions(+), 243 deletions(-)

diff --git a/llvm/include/llvm/Transforms/Utils/LoopUtils.h 
b/llvm/include/llvm/Transforms/Utils/LoopUtils.h
index 5a1385d01d8e44d..3bad7b616d9d756 100644
--- a/llvm/include/llvm/Transforms/Utils/LoopUtils.h
+++ b/llvm/include/llvm/Transforms/Utils/LoopUtils.h
@@ -363,15 +363,6 @@ Intrinsic::ID getMinMaxReductionIntrinsicOp(RecurKind RK);
 /// Returns the comparison predicate used when expanding a min/max reduction.
 CmpInst::Predicate getMinMaxReductionPredicate(RecurKind RK);
 
-/// See RecurrenceDescriptor::isAnyOfPattern for a description of the pattern 
we
-/// are trying to match. In this pattern, we are only ever selecting between 
two
-/// values: 1) an initial start value \p StartVal of the reduction PHI, and 2) 
a
-/// loop invariant value. If any of lane value in \p Left, \p Right is not 
equal
-/// to \p StartVal, select the loop invariant value. This is done by selecting
-/// \p Right iff \p Left is equal to \p StartVal.
-Value *createAnyOfOp(IRBuilderBase &Builder, Value *StartVal, RecurKind RK,
- Value *Left, Value *Right);
-
 /// Returns a Min/Max operation corresponding to MinMaxRecurrenceKind.
 /// The Builder's fast-math-flags must be set to propagate the expected values.
 Value *createMinMaxOp(IRBuilderBase &Builder, RecurKind RK, Value *Left,
diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp 
b/llvm/lib/Transforms/Utils/LoopUtils.cpp
index 59485126b280abf..c0582fb7d7e1505 100644
--- a/llvm/lib/Transforms/Utils/LoopUtils.cpp
+++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp
@@ -962,15 +962,6 @@ CmpInst::Predicate 
llvm::getMinMaxReductionPredicate(RecurKind RK) {
   }
 }
 
-Value *llvm::createAnyOfOp(IRBuilderBase &Builder, Value *StartVal,
-   RecurKind RK, Value *Left, Value *Right) {
-  if (auto VTy = dyn_cast(Left->getType()))
-StartVal = Builder.CreateVectorSplat(VTy->getElementCount(), StartVal);
-  Value *Cmp =
-  Builder.CreateCmp(CmpInst::ICMP_NE, Left, StartVal, "rdx.select.cmp");
-  return Builder.CreateSelect(Cmp, Left, Right, "rdx.select");
-}
-
 Value *llvm::createMinMaxOp(IRBuilderBase &Builder, RecurKind RK, Value *Left,
 Value *Right) {
   Type *Ty = Left->getType();
@@ -1079,16 +1070,13 @@ Value *llvm::createAnyOfTargetReduction(IRBuilderBase 
&Builder, Value *Src,
 NewVal = SI->getTrueValue();
   }
 
-  // Create a splat vector with the new value and compare this to the vector
-  // we want to reduce.
-  ElementCount EC = cast(Src->getType())->getElementCount();
-  Value *Right = Builder.CreateVectorSplat(EC, InitVal);
-  Value *Cmp =
-  Builder.CreateCmp(CmpInst::ICMP_NE, Src, Right, "rdx.select.cmp");
-
   // If any predicate is true it means that we want to select the new value.
-  Cmp = Builder.CreateOrReduce(Cmp);
-  return Builder.CreateSelect(Cmp, NewVal, InitVal, "rdx.select");
+  Value *AnyOf =
+  Src->getType()->isVectorTy() ? Builder.CreateOrReduce(Src) : Src;
+  // The compares in the loop may yield poison, which propagates through the
+  // bitwise ORs. Freeze it here before the condition is used.
+  AnyOf = Builder.CreateFreeze(AnyOf);
+  return Builder.CreateSelect(AnyOf, NewVal, InitVal, "rdx.select");
 }
 
 Value *llvm::createSimpleTargetReduction(IRBuilderBase &Builder, Value *Src,
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h 
b/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h
index a7ebf78e54ceb61..9d3ef5b96c72fbe 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h
@@ -68,6 +68,7 @@ class VPBuilder {
 public:
   VPBuilder() = default;
   VPBuilder(VPBasicBlock *InsertBB) { setInsertPoint(InsertBB); }
+  VPBuilder(VPRecipeB

[llvm] [clang] [coroutine] Implement llvm.coro.await.suspend intrinsic (PR #79712)

2024-01-29 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 commented:

Thanks for looking into this. I haven't looked it in details. Given this is 
complex, it should take a relative longer time.

Here is some quick feedbacks:
- Every time we change the non-static data members of AST nodes, we need to 
update the serializations. Otherwise, modules won't work.
- Every time we change the LLVM intrinsics, we need to change the documentation.
- Every time we change the LLVM with a functional change, we need a test in the 
LLVM part.

And there is something I haven't fully understand:
- I feel odd about `helperFunction`. I don't understand the necessity and I 
feel we should make it in the middle end.
- I feel odd about `IsSuspendNoThrow`. Can't we make it simply during the 
CodeGen time by the attribute of `await_suspend`?.
- I am wondering if we can get rid of the introduction of `OpaqueFramePtr` from 
`CoroutineSuspendExpr` either in CodeGen part or in Sema part.

But I am not sure if my feelings are correct. I need more time looking into it.

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


[clang] [Clang][Sema] Fix crash when type used in return statement contains errors (PR #79788)

2024-01-29 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

NIT: `eligable ` -> `eligible` in the description.

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


[llvm] [clang] [RISCV] Relax march string order constraint (PR #78120)

2024-01-29 Thread Piyou Chen via cfe-commits

https://github.com/BeMg updated https://github.com/llvm/llvm-project/pull/78120

>From 8f7b429d2f7fe791a2a469e3d232d33abba1bef8 Mon Sep 17 00:00:00 2001
From: Piyou Chen 
Date: Sun, 14 Jan 2024 19:41:59 -0800
Subject: [PATCH 1/9] [RISCV] Relax march string order constraint

---
 clang/test/Driver/riscv-arch.c  |  14 +-
 llvm/lib/Support/RISCVISAInfo.cpp   | 295 ++--
 llvm/unittests/Support/RISCVISAInfoTest.cpp |  91 --
 3 files changed, 226 insertions(+), 174 deletions(-)

diff --git a/clang/test/Driver/riscv-arch.c b/clang/test/Driver/riscv-arch.c
index 0ac81ea982f1b61..38de95e4fbf7aa4 100644
--- a/clang/test/Driver/riscv-arch.c
+++ b/clang/test/Driver/riscv-arch.c
@@ -156,9 +156,8 @@
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32L %s
 // RV32L: error: invalid arch name 'rv32l'
 
-// RUN: not %clang --target=riscv32-unknown-elf -march=rv32imadf -### %s \
-// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32IMADF %s
-// RV32IMADF: error: invalid arch name 'rv32imadf'
+// RUN: %clang --target=riscv32-unknown-elf -march=rv32imadf -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck %s
 
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32imm -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32IMM %s
@@ -184,9 +183,8 @@
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64L %s
 // RV64L: error: invalid arch name 'rv64l'
 
-// RUN: not %clang --target=riscv64-unknown-elf -march=rv64imadf -### %s \
-// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64IMADF %s
-// RV64IMADF: error: invalid arch name 'rv64imadf'
+// RUN: %clang --target=riscv64-unknown-elf -march=rv64imadf -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck %s
 
 // RUN: not %clang --target=riscv64-unknown-elf -march=rv64imm -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64IMM %s
@@ -216,7 +214,7 @@
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32imcq -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-ORDER %s
 // RV32-ORDER: error: invalid arch name 'rv32imcq',
-// RV32-ORDER: standard user-level extension not given in canonical order 'q'
+// RV32-ORDER: unsupported standard user-level extension 'q'
 
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32izvl64b -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-ZVL64B-ER %s
@@ -318,7 +316,7 @@
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32ixabc_a -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-PREFIX %s
 // RV32-PREFIX: error: invalid arch name 'rv32ixabc_a',
-// RV32-PREFIX: invalid extension prefix 'a'
+// RV32-PREFIX: unsupported non-standard user-level extension 'xabc'
 
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32ixdef_sabc -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-X-ORDER %s
diff --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index 9a716f7aff1cc94..5674de804f6bb58 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -704,6 +704,106 @@ RISCVISAInfo::parseNormalizedArchString(StringRef Arch) {
   return std::move(ISAInfo);
 }
 
+static Error splitExtsByUnderscore(StringRef Exts,
+   std::vector &SplitedExts) {
+  SmallVector Split;
+  if (Exts.empty())
+return Error::success();
+
+  Exts.split(Split, "_");
+
+  for (auto Ext : Split) {
+if (Ext.empty())
+  return createStringError(errc::invalid_argument,
+   "extension name missing after separator '_'");
+
+SplitedExts.push_back(Ext.str());
+  }
+  return Error::success();
+}
+
+static Error processMultiLetterExtension(
+StringRef RawExt, SmallVector &SeenExts,
+SmallVector &ExtsVersion,
+bool IgnoreUnknown, bool EnableExperimentalExtension,
+bool ExperimentalExtensionVersionCheck) {
+  StringRef Type = getExtensionType(RawExt);
+  StringRef Desc = getExtensionTypeDesc(RawExt);
+  auto Pos = findLastNonVersionCharacter(RawExt) + 1;
+  StringRef Name(RawExt.substr(0, Pos));
+  StringRef Vers(RawExt.substr(Pos));
+
+  if (Type.empty()) {
+if (IgnoreUnknown)
+  return Error::success();
+return createStringError(errc::invalid_argument,
+ "invalid extension prefix '" + RawExt + "'");
+  }
+
+  if (!IgnoreUnknown && Name.size() == Type.size())
+return createStringError(errc::invalid_argument,
+ "%s name missing after '%s'", Desc.str().c_str(),
+ Type.str().c_str());
+
+  unsigned Major, Minor, ConsumeLength;
+  if (auto E = getExtensionVersion(Name, Vers, Major, Minor, ConsumeLength,
+   EnableExperimentalExtension,
+   ExperimentalExtensionVersionCheck)) {
+if (IgnoreUnknown) {
+  consumeError(std::move(E));
+  return Error::success();
+}
+return E;
+  }
+
+  // Check if du

[clang] [llvm] [AArch64][SME] Implement inline-asm clobbers for za/zt0 (PR #79276)

2024-01-29 Thread Matthew Devereau via cfe-commits

https://github.com/MDevereau updated 
https://github.com/llvm/llvm-project/pull/79276

>From e98987ebb48839ea652d63dfaa62ed841b426e46 Mon Sep 17 00:00:00 2001
From: Matt Devereau 
Date: Thu, 18 Jan 2024 15:41:25 +
Subject: [PATCH 1/2] [AArch64][SME] Implement inline-asm clobbers for za/zt0

This enables specifing "za" or "zt0" to the clobber list
for inline asm. This complies with the acle SME addition to the
asm extension here:
https://github.com/ARM-software/acle/pull/276
---
 clang/lib/Basic/Targets/AArch64.cpp |  5 -
 clang/test/CodeGen/aarch64-inline-asm.c |  8 
 llvm/lib/Target/AArch64/AArch64ISelLowering.cpp |  8 
 llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp |  4 
 llvm/test/CodeGen/AArch64/aarch64-za-clobber.ll | 16 
 5 files changed, 40 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/CodeGen/AArch64/aarch64-za-clobber.ll

diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index d47181bfca4fc8..781118c9358987 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -1200,7 +1200,10 @@ const char *const AArch64TargetInfo::GCCRegNames[] = {
 
 // SVE predicate-as-counter registers
 "pn0",  "pn1",  "pn2",  "pn3",  "pn4",  "pn5",  "pn6",  "pn7",  "pn8",
-"pn9",  "pn10", "pn11", "pn12", "pn13", "pn14", "pn15"
+"pn9",  "pn10", "pn11", "pn12", "pn13", "pn14", "pn15",
+
+// SME registers
+"za", "zt0",
 };
 
 ArrayRef AArch64TargetInfo::getGCCRegNames() const {
diff --git a/clang/test/CodeGen/aarch64-inline-asm.c 
b/clang/test/CodeGen/aarch64-inline-asm.c
index 75e9a8c46b8769..8ddee560b11da4 100644
--- a/clang/test/CodeGen/aarch64-inline-asm.c
+++ b/clang/test/CodeGen/aarch64-inline-asm.c
@@ -95,3 +95,11 @@ void test_reduced_gpr_constraints(int var32, long var64) {
 // CHECK: [[ARG2:%.+]] = load i64, ptr
 // CHECK: call void asm sideeffect "add x0, x0, $0", "@3Ucj,~{x0}"(i64 
[[ARG2]])
 }
+
+void test_sme_constraints(){
+  asm("movt zt0[3, mul vl], z0" : : : "za");
+// CHECK: call void asm sideeffect "movt zt0[3, mul vl], z0", "~{za}"()
+
+  asm("movt zt0[3, mul vl], z0" : : : "zt0");
+// CHECK: call void asm sideeffect "movt zt0[3, mul vl], z0", "~{zt0}"()
+}
\ No newline at end of file
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp 
b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index 332fb37655288c..6a210846cf4dff 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -10702,6 +10702,14 @@ AArch64TargetLowering::getRegForInlineAsmConstraint(
   parseConstraintCode(Constraint) != AArch64CC::Invalid)
 return std::make_pair(unsigned(AArch64::NZCV), &AArch64::CCRRegClass);
 
+  if (StringRef("{za}").equals_insensitive(Constraint)){
+return std::make_pair(unsigned(AArch64::ZA), &AArch64::MPRRegClass);
+  }
+
+  if (StringRef("{zt0}").equals_insensitive(Constraint)){
+return std::make_pair(unsigned(AArch64::ZT0), &AArch64::ZTRRegClass);
+  }
+
   // Use the default implementation in TargetLowering to convert the register
   // constraint into a member of a register class.
   std::pair Res;
diff --git a/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp 
b/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
index ea9882160d6fb2..7d6b86ab8a3e95 100644
--- a/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
@@ -507,6 +507,10 @@ bool AArch64RegisterInfo::isAsmClobberable(const 
MachineFunction &MF,
 MCRegisterInfo::regsOverlap(PhysReg, AArch64::X16))
 return true;
 
+  // ZA/ZT0 registers are reserved but may be permitted in the clobber list.
+  if (PhysReg.id() == AArch64::ZA || PhysReg.id() == AArch64::ZT0)
+return true;
+
   return !isReservedReg(MF, PhysReg);
 }
 
diff --git a/llvm/test/CodeGen/AArch64/aarch64-za-clobber.ll 
b/llvm/test/CodeGen/AArch64/aarch64-za-clobber.ll
new file mode 100644
index 00..a8cba7dc9a91e9
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/aarch64-za-clobber.ll
@@ -0,0 +1,16 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=aarch64-none-linux-gnu -stop-after=aarch64-isel < %s -o - 
| FileCheck %s
+
+define void @alpha( %x) local_unnamed_addr {
+entry:
+; CHECK: INLINEASM &"movt zt0[3, mul vl], z0", 1 /* sideeffect attdialect */, 
12 /* clobber */, implicit-def early-clobber $za
+  tail call void asm sideeffect "movt zt0[3, mul vl], z0", "~{za}"()
+  ret void
+}
+
+define void @beta( %x) local_unnamed_addr {
+entry:
+; CHECK: INLINEASM &"movt zt0[3, mul vl], z0", 1 /* sideeffect attdialect */, 
12 /* clobber */, implicit-def early-clobber $zt0
+  tail call void asm sideeffect "movt zt0[3, mul vl], z0", "~{zt0}"()
+  ret void
+}

>From 6391def8b7cfd88b12544766c94b75cb2a5bd385 Mon Sep 17 00:00:00 2001
From: Matt Devereau 
Date: Mon, 29 Jan 2024 09:59:47 +
Subject: [PATCH 2/2] run clang-format

[lldb] [clang-tools-extra] [clang] [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. (PR #78041)

2024-01-29 Thread via cfe-commits

zmodem wrote:

We're hitting a "dyn_cast on a non-existent value" assert in Chromium after 
this change. I've attached a reproducer here: 
https://bugs.chromium.org/p/chromium/issues/detail?id=1522775#c2

Based on the stack, this doesn't look the same as the analyzer issue (#79575) 
but there are similarities: "clang::IgnoreParensSingleStep" vs. 
"ignoreTransparentExprs".

Maybe the fix in #79764 can be expanded to cover also this case?

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


[clang] Fix analyzer crash on 'StructuralValue' (PR #79764)

2024-01-29 Thread via cfe-commits

zmodem wrote:

I think a similar fix may be needed in `clang::IgnoreParensSingleStep`, see my 
comment here: 
https://github.com/llvm/llvm-project/pull/78041#issuecomment-1914407300

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


[clang-tools-extra] [clang] [clangd] Prevent printing huge initializer lists in hover definitions (PR #79746)

2024-01-29 Thread Raoul Wols via cfe-commits


@@ -1720,6 +1720,12 @@ void StmtPrinter::VisitInitListExpr(InitListExpr* Node) {
   OS << "{";
   for (unsigned i = 0, e = Node->getNumInits(); i != e; ++i) {
 if (i) OS << ", ";
+// TODO: There is duplicated functionality in APValue::printPretty.
+// Would be good to consolidate the two.
+if (!Policy.EntireContentsOfLargeArray && i == 10) {

rwols wrote:

I was also kind of unsure about the usage of `EntirecontentsOfLargeArray` here. 
I feel like StmtPrinter should always output valid C++ code  but that's not 
possible using `EntireContentsOfLargeArray`.

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


[clang] [Coverage] Map regions from system headers (PR #76950)

2024-01-29 Thread via cfe-commits

mhaehnel wrote:

Your revert just masks the underlying issue. What you do now is that you *can* 
specify `-system-headers-coverage` but the compiler will not actually provide 
coverage data for system headers because the flag is ignored.  So specifying 
the switch becomes meaningless. 

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


[clang] [clang-format] Explicitly open DOC_FILE with utf-8 in dump_format_style.py (PR #79805)

2024-01-29 Thread via cfe-commits

https://github.com/rmarker created 
https://github.com/llvm/llvm-project/pull/79805

The dump_format_style.py script generates the clang-format style options 
documentation.
There was an issue where the script could include spurious characters in the 
output when run in windows. It appears that it wasn't defaulting to the correct 
encoding when reading the input.
This has been addressed by explicitly setting the encoding when opening the 
file.

>From 7e639edc339b3f09d8e67860b32b2c4bff3237d9 Mon Sep 17 00:00:00 2001
From: rmarker 
Date: Mon, 29 Jan 2024 21:13:45 +1030
Subject: [PATCH] [clang-format] Explicitly open DOC_FILE with utf-8 in
 dump_format_style.py.

The dump_format_style script generates the clang-format style options 
documentation.
There was an issue where the script could include spurious characters in the 
output when run in windows.
It appears that it wasn't defaulting to the correct encoding when reading the 
input.
This has been addressed by explicitly setting the encoding when opening the 
file.
---
 clang/docs/tools/dump_format_style.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/tools/dump_format_style.py 
b/clang/docs/tools/dump_format_style.py
index 75d4a044ef19f68..e41891f07de2e32 100755
--- a/clang/docs/tools/dump_format_style.py
+++ b/clang/docs/tools/dump_format_style.py
@@ -474,7 +474,7 @@ class State:
 opts = sorted(opts, key=lambda x: x.name)
 options_text = "\n\n".join(map(str, opts))
 
-with open(DOC_FILE) as f:
+with open(DOC_FILE, encoding="utf-8") as f:
 contents = f.read()
 
 contents = substitute(contents, "FORMAT_STYLE_OPTIONS", options_text)

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


[clang] [clang-format] Explicitly open DOC_FILE with utf-8 in dump_format_style.py (PR #79805)

2024-01-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (rmarker)


Changes

The dump_format_style.py script generates the clang-format style options 
documentation.
There was an issue where the script could include spurious characters in the 
output when run in windows. It appears that it wasn't defaulting to the correct 
encoding when reading the input.
This has been addressed by explicitly setting the encoding when opening the 
file.

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


1 Files Affected:

- (modified) clang/docs/tools/dump_format_style.py (+1-1) 


``diff
diff --git a/clang/docs/tools/dump_format_style.py 
b/clang/docs/tools/dump_format_style.py
index 75d4a044ef19f68..e41891f07de2e32 100755
--- a/clang/docs/tools/dump_format_style.py
+++ b/clang/docs/tools/dump_format_style.py
@@ -474,7 +474,7 @@ class State:
 opts = sorted(opts, key=lambda x: x.name)
 options_text = "\n\n".join(map(str, opts))
 
-with open(DOC_FILE) as f:
+with open(DOC_FILE, encoding="utf-8") as f:
 contents = f.read()
 
 contents = substitute(contents, "FORMAT_STYLE_OPTIONS", options_text)

``




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


[clang] [polly] [clang-format] Add AllowShortType option for AlwaysBreakAfterReturnType. (PR #78011)

2024-01-29 Thread via cfe-commits

https://github.com/rmarker updated 
https://github.com/llvm/llvm-project/pull/78011

>From a1312a0a463bb946f336977b5b01ef7afbede678 Mon Sep 17 00:00:00 2001
From: rmarker 
Date: Thu, 11 Jan 2024 15:01:18 +1030
Subject: [PATCH 1/9] [clang-format] Add ShortReturnTypeColumn option.

---
 clang/docs/ClangFormatStyleOptions.rst | 13 +++
 clang/docs/ReleaseNotes.rst|  1 +
 clang/include/clang/Format/Format.h| 12 ++
 clang/lib/Format/ContinuationIndenter.cpp  |  3 +-
 clang/lib/Format/Format.cpp|  2 +
 clang/unittests/Format/ConfigParseTest.cpp |  1 +
 clang/unittests/Format/FormatTest.cpp  | 44 ++
 7 files changed, 75 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 4dc0de3a90f2650..7836cc8f1c9bb5b 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -4999,6 +4999,19 @@ the configuration (without a prefix: ``Auto``).
int bar;   int bar;
  } // namespace b   } // namespace b
 
+.. _ShortReturnTypeColumn:
+
+**ShortReturnTypeColumn** (``Unsigned``) :versionbadge:`clang-format 19` 
:ref:`¶ `
+  When ``AlwaysBreakAfterReturnType`` is ``None``, line breaks are prevented
+  after short return types. This configures the column limit for a type
+  to be regarded as short.
+
+
+  .. note::
+
+   This isn't the length of the type itself, but the column where it
+   finishes. I.e. it includes indentation, etc.
+
 .. _SkipMacroDefinitionBody:
 
 **SkipMacroDefinitionBody** (``Boolean``) :versionbadge:`clang-format 18` 
:ref:`¶ `
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5330cd9caad8011..669b420fe21ec15 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -184,6 +184,7 @@ AST Matchers
 
 clang-format
 
+- Add ``ShortReturnTypeColumn`` option.
 
 libclang
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index bc9eecd42f9ebfd..7fd574c98a3944f 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -3932,6 +3932,17 @@ struct FormatStyle {
   /// \version 13
   unsigned ShortNamespaceLines;
 
+  /// When ``AlwaysBreakAfterReturnType`` is ``None``, line breaks are 
prevented
+  /// after short return types. This configures the column limit for a type
+  /// to be regarded as short.
+  ///
+  /// \note
+  ///  This isn't the length of the type itself, but the column where it
+  ///  finishes. I.e. it includes indentation, etc.
+  /// \endnote
+  /// \version 19
+  unsigned ShortReturnTypeColumn;
+
   /// Do not format macro definition body.
   /// \version 18
   bool SkipMacroDefinitionBody;
@@ -4899,6 +4910,7 @@ struct FormatStyle {
RequiresExpressionIndentation == R.RequiresExpressionIndentation &&
SeparateDefinitionBlocks == R.SeparateDefinitionBlocks &&
ShortNamespaceLines == R.ShortNamespaceLines &&
+   ShortReturnTypeColumn == R.ShortReturnTypeColumn &&
SkipMacroDefinitionBody == R.SkipMacroDefinitionBody &&
SortIncludes == R.SortIncludes &&
SortJavaStaticImport == R.SortJavaStaticImport &&
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index a3eb9138b218335..3f9c0cc815745c3 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -328,7 +328,8 @@ bool ContinuationIndenter::canBreak(const LineState &State) 
{
 
   // Don't break after very short return types (e.g. "void") as that is often
   // unexpected.
-  if (Current.is(TT_FunctionDeclarationName) && State.Column < 6) {
+  if (Current.is(TT_FunctionDeclarationName) &&
+  State.Column <= Style.ShortReturnTypeColumn) {
 if (Style.AlwaysBreakAfterReturnType == FormatStyle::RTBS_None)
   return false;
   }
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index ff326dc784783b2..35478fac7b49629 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1085,6 +1085,7 @@ template <> struct MappingTraits {
Style.RequiresExpressionIndentation);
 IO.mapOptional("SeparateDefinitionBlocks", Style.SeparateDefinitionBlocks);
 IO.mapOptional("ShortNamespaceLines", Style.ShortNamespaceLines);
+IO.mapOptional("ShortReturnTypeColumn", Style.ShortReturnTypeColumn);
 IO.mapOptional("SkipMacroDefinitionBody", Style.SkipMacroDefinitionBody);
 IO.mapOptional("SortIncludes", Style.SortIncludes);
 IO.mapOptional("SortJavaStaticImport", Style.SortJavaStaticImport);
@@ -1557,6 +1558,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   LLVMStyle.RequiresExpressionIndentation = FormatStyle::REI_OuterScope;
   LLVMStyle.SeparateDefinitionBlocks = FormatStyle::SDS_Leave;
   LLVMStyle.ShortNamespaceLi

[polly] [clang] [clang-format] Add AllowShortType option for AlwaysBreakAfterReturnType. (PR #78011)

2024-01-29 Thread via cfe-commits


@@ -474,7 +474,7 @@ class State:
 opts = sorted(opts, key=lambda x: x.name)
 options_text = "\n\n".join(map(str, opts))
 
-with open(DOC_FILE) as f:
+with open(DOC_FILE, encoding="utf-8") as f:

rmarker wrote:

Moved change to its own PR. #79805

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


[clang] [clang-format] Explicitly open DOC_FILE with utf-8 in dump_format_style.py (PR #79805)

2024-01-29 Thread via cfe-commits

rmarker wrote:

@HazardyKnusperkeks, @owenca, extracted this change from #78011.

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


[clang-tools-extra] [flang] [clang] [llvm] [flang] add SYSTEM runtime and lowering intrinsics support (PR #74309)

2024-01-29 Thread Yi Wu via cfe-commits


@@ -5934,6 +5938,40 @@ IntrinsicLibrary::genSum(mlir::Type resultType,
   resultType, args);
 }
 
+// SYSTEM
+void IntrinsicLibrary::genSystem(llvm::ArrayRef args) {
+  assert(args.size() == 2);
+  mlir::Value command = fir::getBase(args[0]);
+  const fir::ExtendedValue &exitstat = args[1];
+
+  if (!command)
+fir::emitFatalError(loc, "expected COMMAND parameter");
+
+  mlir::Type boxNoneTy = fir::BoxType::get(builder.getNoneType());
+
+  mlir::Value waitBool = builder.createBool(loc, true);
+  mlir::Value exitstatBox =
+  isStaticallyPresent(exitstat)
+  ? fir::getBase(exitstat)
+  : builder.create(loc, boxNoneTy).getResult();

yi-wu-arm wrote:

If I understand correctly, it will pass a null descriptor, which will be handle 
by an `if(exitstat)` here: 
https://github.com/llvm/llvm-project/blob/ba5d92eb9c18a9037dd06a74f90ceba3f4e3ace9/flang/runtime/execute.cpp#L123

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


[flang] [llvm] [clang-tools-extra] [clang] [flang] add SYSTEM runtime and lowering intrinsics support (PR #74309)

2024-01-29 Thread Yi Wu via cfe-commits


@@ -5934,6 +5938,40 @@ IntrinsicLibrary::genSum(mlir::Type resultType,
   resultType, args);
 }
 
+// SYSTEM
+void IntrinsicLibrary::genSystem(llvm::ArrayRef args) {
+  assert(args.size() == 2);
+  mlir::Value command = fir::getBase(args[0]);
+  const fir::ExtendedValue &exitstat = args[1];
+
+  if (!command)
+fir::emitFatalError(loc, "expected COMMAND parameter");
+
+  mlir::Type boxNoneTy = fir::BoxType::get(builder.getNoneType());
+
+  mlir::Value waitBool = builder.createBool(loc, true);
+  mlir::Value exitstatBox =
+  isStaticallyPresent(exitstat)
+  ? fir::getBase(exitstat)
+  : builder.create(loc, boxNoneTy).getResult();
+
+  // Create a dummmy cmdstat to prevent EXECUTE_COMMAND_LINE terminate itself
+  // when cmdstat is assigned with a non-zero value but not present
+  mlir::Value tempValue =
+  builder.createIntegerConstant(loc, builder.getI2Type(), 0);
+  mlir::Value temp = builder.createTemporary(loc, builder.getI2Type());

yi-wu-arm wrote:

True, I thought an I2Type is an integer with kind 2, in fact it is a 2bit int, 
the correct type I need to use here is an int16(int kind 2): 
https://github.com/llvm/llvm-project/blob/743946e8ef0d164cbaa3409d11b218e299ccd35e/mlir/lib/IR/Builders.cpp#L81

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


[clang] [clang-tools-extra] [llvm] [flang] [flang] add SYSTEM runtime and lowering intrinsics support (PR #74309)

2024-01-29 Thread Yi Wu via cfe-commits


@@ -5934,6 +5938,40 @@ IntrinsicLibrary::genSum(mlir::Type resultType,
   resultType, args);
 }
 
+// SYSTEM
+void IntrinsicLibrary::genSystem(llvm::ArrayRef args) {
+  assert(args.size() == 2);
+  mlir::Value command = fir::getBase(args[0]);
+  const fir::ExtendedValue &exitstat = args[1];
+
+  if (!command)
+fir::emitFatalError(loc, "expected COMMAND parameter");
+
+  mlir::Type boxNoneTy = fir::BoxType::get(builder.getNoneType());
+
+  mlir::Value waitBool = builder.createBool(loc, true);
+  mlir::Value exitstatBox =
+  isStaticallyPresent(exitstat)
+  ? fir::getBase(exitstat)
+  : builder.create(loc, boxNoneTy).getResult();
+
+  // Create a dummmy cmdstat to prevent EXECUTE_COMMAND_LINE terminate itself
+  // when cmdstat is assigned with a non-zero value but not present
+  mlir::Value tempValue =
+  builder.createIntegerConstant(loc, builder.getI2Type(), 0);
+  mlir::Value temp = builder.createTemporary(loc, builder.getI2Type());
+  mlir::Value castVal =
+  builder.createConvert(loc, builder.getI2Type(), tempValue);

yi-wu-arm wrote:

it should be an int16, (integer with kind code 2), the minimum accepted kind 
code for `cmdstst` in `execute_command_line`. (Although `execute_comman_line` 
runtime function doesn't check for kind, it was checked in 
`flang/lib/Evaluate/intrinsics.cpp`.
Changed to getI16Type().

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


[clang] [clang-tools-extra] [llvm] [flang] [flang] add SYSTEM runtime and lowering intrinsics support (PR #74309)

2024-01-29 Thread Yi Wu via cfe-commits


@@ -1393,6 +1393,11 @@ static const IntrinsicInterface intrinsicSubroutine[]{
 {"get", DefaultInt, Rank::vector, Optionality::optional,
 common::Intent::Out}},
 {}, Rank::elemental, IntrinsicClass::impureSubroutine},
+{"system",
+{{"command", DefaultChar, Rank::scalar},
+{"exitstat", DefaultInt, Rank::scalar, Optionality::optional,
+common::Intent::InOut}},

yi-wu-arm wrote:

Correct, it doesn't read. Done

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


[clang] Fix analyzer crash on 'StructuralValue' (PR #79764)

2024-01-29 Thread Balazs Benics via cfe-commits

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


[clang] Fix analyzer crash on 'StructuralValue' (PR #79764)

2024-01-29 Thread Balazs Benics via cfe-commits


@@ -40,8 +40,12 @@ static const Expr *ignoreTransparentExprs(const Expr *E) {
 
   switch (E->getStmtClass()) {
   case Stmt::OpaqueValueExprClass:
-E = cast(E)->getSourceExpr();
-break;
+if (const clang::Expr *SE = cast(E)->getSourceExpr()) {
+  E = SE;
+  break;
+} else {
+  return E;
+}

steakhal wrote:

```suggestion
if (const auto *SE = cast(E)->getSourceExpr()) {
  E = SE;
  break;
}
return E;
```
Fix `else-after-break`.
Use `auto` after `cast<>`.

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


[clang] Fix analyzer crash on 'StructuralValue' (PR #79764)

2024-01-29 Thread Balazs Benics via cfe-commits

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

Approved with nits. This works around the crash.

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


[compiler-rt] [llvm] [flang] [clang] [clang-tools-extra] [AArch64][compiler-rt] Avoid use of libc header in sme-libc-routines (PR #79454)

2024-01-29 Thread Peter Waller via cfe-commits

https://github.com/peterwaller-arm updated 
https://github.com/llvm/llvm-project/pull/79454

>From 18fbfe3d757372fc904146a9156e8af466c9f013 Mon Sep 17 00:00:00 2001
From: Peter Waller 
Date: Thu, 25 Jan 2024 14:29:45 +
Subject: [PATCH] [AArch64][compiler-rt] Avoid use of libc header in
 sme-libc-routines

The use of `#include ` introduces a libc dependency. In many
build environments such a file can be found under e.g. /usr/include, but this
does not correspond to the libc in use, which may not be available until
after the builtins have been built.

So far as I understand, it's not valid to have a dependency on libc from
builtins; there are a handful of such includes in builtins, but they are
protected by ifdefs.

Instead, use  which is provided by the compiler's resource
headers and so should always be available.
---
 compiler-rt/lib/builtins/aarch64/sme-libc-routines.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/compiler-rt/lib/builtins/aarch64/sme-libc-routines.c 
b/compiler-rt/lib/builtins/aarch64/sme-libc-routines.c
index cd73025a19cc1ac..89b52b0d1a8805c 100644
--- a/compiler-rt/lib/builtins/aarch64/sme-libc-routines.c
+++ b/compiler-rt/lib/builtins/aarch64/sme-libc-routines.c
@@ -1,4 +1,4 @@
-#include 
+#include 
 
 // WARNING: When building the scalar versions of these functions you need to
 // use the compiler flag "-mllvm -disable-loop-idiom-all" to prevent clang

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


[flang] [llvm] [clang-tools-extra] [clang] [flang] add SYSTEM runtime and lowering intrinsics support (PR #74309)

2024-01-29 Thread Yi Wu via cfe-commits


@@ -5934,6 +5938,40 @@ IntrinsicLibrary::genSum(mlir::Type resultType,
   resultType, args);
 }
 
+// SYSTEM
+void IntrinsicLibrary::genSystem(llvm::ArrayRef args) {
+  assert(args.size() == 2);
+  mlir::Value command = fir::getBase(args[0]);
+  const fir::ExtendedValue &exitstat = args[1];
+
+  if (!command)
+fir::emitFatalError(loc, "expected COMMAND parameter");

yi-wu-arm wrote:

Done

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


[libc] [lld] [llvm] [clang-tools-extra] [libcxx] [lldb] [clang] intrinsic to generate a bfi instruction (PR #79655)

2024-01-29 Thread Rama Malladi via cfe-commits

RamaMalladiAWS wrote:

Thank you @DavidSpickett 

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


[flang] [llvm] [clang-tools-extra] [clang] [flang] add SYSTEM runtime and lowering intrinsics support (PR #74309)

2024-01-29 Thread Yi Wu via cfe-commits

https://github.com/yi-wu-arm updated 
https://github.com/llvm/llvm-project/pull/74309

>From 14f8c3e38791cc6b06455b8beffe37a6f7105e03 Mon Sep 17 00:00:00 2001
From: Yi Wu 
Date: Mon, 4 Dec 2023 10:32:03 +
Subject: [PATCH 01/19] Add SYSTEM runtime and lowering intrinsic support

Calls std::system() function and pass the command,
cmd on Windows or shell on Linux.
Command parameter is required, exitstatus is optional.
call system(command)
call system(command, exitstatus)
---
 flang/docs/Intrinsics.md  |  2 +-
 .../flang/Optimizer/Builder/IntrinsicCall.h   |  1 +
 .../flang/Optimizer/Builder/Runtime/Command.h |  5 +++
 flang/include/flang/Runtime/command.h |  5 +++
 flang/lib/Evaluate/intrinsics.cpp | 16 +---
 flang/lib/Optimizer/Builder/IntrinsicCall.cpp | 22 ++
 .../lib/Optimizer/Builder/Runtime/Command.cpp | 13 ++
 flang/runtime/command.cpp | 19 +
 flang/test/Lower/Intrinsics/system.f90| 39 ++
 flang/unittests/Runtime/CommandTest.cpp   | 41 +++
 10 files changed, 157 insertions(+), 6 deletions(-)
 create mode 100644 flang/test/Lower/Intrinsics/system.f90

diff --git a/flang/docs/Intrinsics.md b/flang/docs/Intrinsics.md
index fef2b4ea4dd8c8..871332399628e9 100644
--- a/flang/docs/Intrinsics.md
+++ b/flang/docs/Intrinsics.md
@@ -751,7 +751,7 @@ This phase currently supports all the intrinsic procedures 
listed above but the
 | Object characteristic inquiry functions | ALLOCATED, ASSOCIATED, 
EXTENDS_TYPE_OF, IS_CONTIGUOUS, PRESENT, RANK, SAME_TYPE, STORAGE_SIZE |
 | Type inquiry intrinsic functions | BIT_SIZE, DIGITS, EPSILON, HUGE, KIND, 
MAXEXPONENT, MINEXPONENT, NEW_LINE, PRECISION, RADIX, RANGE, TINY|
 | Non-standard intrinsic functions | AND, OR, XOR, SHIFT, ZEXT, IZEXT, COSD, 
SIND, TAND, ACOSD, ASIND, ATAND, ATAN2D, COMPL, EQV, NEQV, INT8, JINT, JNINT, 
KNINT, QCMPLX, DREAL, DFLOAT, QEXT, QFLOAT, QREAL, DNUM, NUM, JNUM, KNUM, QNUM, 
RNUM, RAN, RANF, ILEN, SIZEOF, MCLOCK, SECNDS, COTAN, IBCHNG, ISHA, ISHC, ISHL, 
IXOR, IARG, IARGC, NARGS, GETPID, NUMARG, BADDRESS, IADDR, CACHESIZE, EOF, 
FP_CLASS, INT_PTR_KIND, ISNAN, MALLOC |
-| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, RANDOM_SEED, 
SYSTEM_CLOCK |
+| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, RANDOM_SEED, 
SYSTEM, SYSTEM_CLOCK |
 | Atomic intrinsic subroutines | ATOMIC_ADD |
 | Collective intrinsic subroutines | CO_REDUCE |
 
diff --git a/flang/include/flang/Optimizer/Builder/IntrinsicCall.h 
b/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
index 5065f11ae9e726..669d076c3e0e7d 100644
--- a/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
+++ b/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
@@ -321,6 +321,7 @@ struct IntrinsicLibrary {
   fir::ExtendedValue genStorageSize(mlir::Type,
 llvm::ArrayRef);
   fir::ExtendedValue genSum(mlir::Type, llvm::ArrayRef);
+  void genSystem(mlir::ArrayRef args);
   void genSystemClock(llvm::ArrayRef);
   mlir::Value genTand(mlir::Type, llvm::ArrayRef);
   mlir::Value genTrailz(mlir::Type, llvm::ArrayRef);
diff --git a/flang/include/flang/Optimizer/Builder/Runtime/Command.h 
b/flang/include/flang/Optimizer/Builder/Runtime/Command.h
index 976fb3aa0b6fbb..9d6a39639844fc 100644
--- a/flang/include/flang/Optimizer/Builder/Runtime/Command.h
+++ b/flang/include/flang/Optimizer/Builder/Runtime/Command.h
@@ -53,5 +53,10 @@ mlir::Value genGetEnvVariable(fir::FirOpBuilder &, 
mlir::Location,
   mlir::Value length, mlir::Value trimName,
   mlir::Value errmsg);
 
+/// Generate a call to System runtime function which implements
+/// the non-standard System GNU extension.
+void genSystem(fir::FirOpBuilder &, mlir::Location, mlir::Value command,
+   mlir::Value exitstat);
+
 } // namespace fir::runtime
 #endif // FORTRAN_OPTIMIZER_BUILDER_RUNTIME_COMMAND_H
diff --git a/flang/include/flang/Runtime/command.h 
b/flang/include/flang/Runtime/command.h
index c67d171c8e2f1b..f325faa7bd09fa 100644
--- a/flang/include/flang/Runtime/command.h
+++ b/flang/include/flang/Runtime/command.h
@@ -55,6 +55,11 @@ std::int32_t RTNAME(GetEnvVariable)(const Descriptor &name,
 const Descriptor *value = nullptr, const Descriptor *length = nullptr,
 bool trim_name = true, const Descriptor *errmsg = nullptr,
 const char *sourceFile = nullptr, int line = 0);
+
+// Calls std::system()
+void RTNAME(System)(const Descriptor *command = nullptr,
+const Descriptor *exitstat = nullptr, const char *sourceFile = nullptr,
+int line = 0);
 }
 } // namespace Fortran::runtime
 
di

[compiler-rt] [llvm] [libc] [flang] [clang] [clang-tools-extra] [lldb] [libcxx] [mlir] [AArch64] add intrinsic to generate a bfi instruction (PR #79672)

2024-01-29 Thread Rama Malladi via cfe-commits

RamaMalladiAWS wrote:

> OK. We would not usually add intrinsics like this without a strong motivating 
> case, that could not be optimized in some other way. It is better to use 
> target independent options when available, and inline assembly is available 
> as a fallback if it is really needed. But I would recommend that they use 
> normal and/or/shift operations and let us know about places the compiler 
> isn't optimizing them as well as it could be.

I completely agree with the approach @davemgreen. In this case, the IR sequence 
wasn't optimized to a `bfi`. I can try to get a test-case and create an issue 
for better sequence if feasible. Thanks again.

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


[compiler-rt] [llvm] [libc] [flang] [clang] [clang-tools-extra] Apply kind code check on exitstat and cmdstat (PR #78286)

2024-01-29 Thread Yi Wu via cfe-commits

yi-wu-arm wrote:

build and pass all test on Windows on Arm MSVC native.

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


[clang] [clang-tools-extra] [llvm] [flang] [flang] add SYSTEM runtime and lowering intrinsics support (PR #74309)

2024-01-29 Thread Tom Eccles via cfe-commits


@@ -5934,6 +5938,40 @@ IntrinsicLibrary::genSum(mlir::Type resultType,
   resultType, args);
 }
 
+// SYSTEM
+void IntrinsicLibrary::genSystem(llvm::ArrayRef args) {
+  assert(args.size() == 2);
+  mlir::Value command = fir::getBase(args[0]);
+  const fir::ExtendedValue &exitstat = args[1];
+
+  if (!command)
+fir::emitFatalError(loc, "expected COMMAND parameter");
+
+  mlir::Type boxNoneTy = fir::BoxType::get(builder.getNoneType());
+
+  mlir::Value waitBool = builder.createBool(loc, true);
+  mlir::Value exitstatBox =
+  isStaticallyPresent(exitstat)
+  ? fir::getBase(exitstat)
+  : builder.create(loc, boxNoneTy).getResult();

tblah wrote:

As I understand it, RUNTIME_CHECK is more like an assertion, so the runtime 
would crash when given a null existstat:

https://github.com/llvm/llvm-project/blob/main/flang/runtime/terminator.h#L103

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


[clang] [Serialization] Load Specializations Lazily (PR #76774)

2024-01-29 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

> > As far as I can tell from [#76774 
> > (comment)](https://github.com/llvm/llvm-project/pull/76774#issuecomment-1914177330)
> >  above, the last push only changed the default value of 
> > `LoadExternalSpecializationsLazily`. In that case, my test results from 
> > [#76774 
> > (comment)](https://github.com/llvm/llvm-project/pull/76774#issuecomment-1912182171)
> >  remain fully valid, especially
> > > Switching the new `LoadExternalSpecializationsLazily` to disabled by 
> > > default (somehow the argument didn't work on its own) instead crashes, 
> > > most of the cases involving `MultiOnDiskHashTable`. I suspect some kind 
> > > of memory error maybe?
> 
> No, this newest patch changes besides changing the default value. For 
> example, 
> [22c9d11#diff-125f472e690aa3d973bc42aa3c5d580226c5c47661551aca2889f960681aa64dR232-R237](https://github.com/llvm/llvm-project/commit/22c9d1145eb57d9c2cb2ef490b7c474598dd5d12#diff-125f472e690aa3d973bc42aa3c5d580226c5c47661551aca2889f960681aa64dR232-R237)
>  now we won't write specializations into the hash table, while the original 
> patch tries to load all the decls from the consumers' side only. This patch 
> touches the producer's side.
> 
> Maybe I shouldn't push force to make the history clear..

If you want I can set you up with the ROOT project so that you can debug the 
failures easier.

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


[clang] [llvm] [clang-tools-extra] [compiler-rt] [flang] [AArch64][compiler-rt] Avoid use of libc header in sme-libc-routines (PR #79454)

2024-01-29 Thread Peter Waller via cfe-commits

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


[clang] [llvm] [clang-tools-extra] [Clang][AST] Fix a crash on attaching doc comments (PR #78716)

2024-01-29 Thread via cfe-commits

https://github.com/chenshanzhi updated 
https://github.com/llvm/llvm-project/pull/78716

>From dcdf4a5825a402ab1392f61354c604a9cf965bdd Mon Sep 17 00:00:00 2001
From: Shanzhi Chen 
Date: Thu, 18 Jan 2024 11:40:09 +
Subject: [PATCH] [Clang][AST] Fix a crash on attaching doc comments

This crash is basically caused by calling
`ASTContext::getRawCommentForDeclNoCacheImp` with its input arguments
`RepresentativeLocForDecl` and `CommentsInTheFile` refering to different files.
A reduced reproducer is provided in this patch.

After the source locations for instantiations of funtion template are corrected
in the commit 256a0b298c68b89688b80350b034daf2f7785b67, the variable
`CommitsInThisFile` in the function
`ASTContext::attachCommentsToJustParsedDecls` would refer to the source file
rather than the header file for implicit function template instantiation.
Therefore, in the first loop in `ASTContext::attachCommentsToJustParsedDecls`,
`D` should also be adjusted for relevant scenarios like the second loop.

Fixes #67979 #68524 #70550
---
 clang/lib/AST/ASTContext.cpp  |  6 +++-
 .../AST/ast-crash-doc-function-template.cpp   | 30 +++
 2 files changed, 35 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/AST/ast-crash-doc-function-template.cpp

diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 5eb7aa3664569dd..9a0ede2010596ec 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -498,7 +498,11 @@ void 
ASTContext::attachCommentsToJustParsedDecls(ArrayRef Decls,
 return;
 
   FileID File;
-  for (Decl *D : Decls) {
+  for (const Decl *D : Decls) {
+if (D->isInvalidDecl())
+  continue;
+
+D = &adjustDeclToTemplate(*D);
 SourceLocation Loc = D->getLocation();
 if (Loc.isValid()) {
   // See if there are any new comments that are not attached to a decl.
diff --git a/clang/test/AST/ast-crash-doc-function-template.cpp 
b/clang/test/AST/ast-crash-doc-function-template.cpp
new file mode 100644
index 000..d48eb0dbe02f011
--- /dev/null
+++ b/clang/test/AST/ast-crash-doc-function-template.cpp
@@ -0,0 +1,30 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -x c++ -Wdocumentation -fsyntax-only -ast-dump-all %t/t.cpp
+
+//--- t.h
+/// MyClass in the header file
+class MyClass {
+public:
+  template 
+  void Foo() const;
+
+  /// Bar
+  void Bar() const;
+};
+
+//--- t.cpp
+#include "t.h"
+
+/// MyClass::Bar: Foo() is implicitly instantiated and called here.
+void MyClass::Bar() const {
+  Foo();
+}
+
+/// MyClass::Foo
+template 
+void MyClass::Foo() const {
+}
+
+// CHECK: TranslationUnitDecl

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


[clang] [lldb] [libc] [llvm] [libcxx] [lld] [compiler-rt] [flang] [hwasan] Use ErrorAction::Recover in interceptors (PR #74000)

2024-01-29 Thread Tamar Christina via cfe-commits

TamarChristinaArm wrote:

@vitalybuka I'm trying to backport the fixes to the GCC branches. Do I just 
need to backport these 4 commits?

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


[libcxx] [llvm] [libc] [compiler-rt] [lldb] [clang-tools-extra] [mlir] [clang] [flang] [AArch64] add intrinsic to generate a bfi instruction (PR #79672)

2024-01-29 Thread Simon Pilgrim via cfe-commits

RKSimon wrote:

@RamaMalladiAWS Do you have examples of the IR that fails to lower to BFI? 
These things often turn out to be either a missing middle-end canonicalization 
or maybe a case that could be added to existing pattern matching in the 
back-end.

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


[clang-tools-extra] [flang] [llvm] [clang] [compiler-rt] [libc] Apply kind code check on exitstat and cmdstat (PR #78286)

2024-01-29 Thread Yi Wu via cfe-commits

https://github.com/yi-wu-arm closed 
https://github.com/llvm/llvm-project/pull/78286
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang, SystemZ] Split test into Driver and CodeGen parts (NFC) (PR #79808)

2024-01-29 Thread Nikita Popov via cfe-commits

https://github.com/nikic created https://github.com/llvm/llvm-project/pull/79808

The test added in #73511 currently fails in
CLANG_DEFAULT_PIE_ON_LINUX=OFF configuration, because it uses the clang driver 
in a codegen test.

Split the test into two, a driver test that checks that the appropriate target 
feature is passed, and a codegen test that uses cc1.

>From c44059be08fa08ef09498bfd7193ac7d52680e18 Mon Sep 17 00:00:00 2001
From: Nikita Popov 
Date: Mon, 29 Jan 2024 12:12:41 +0100
Subject: [PATCH] [Clang, SystemZ] Split test into Driver and CodeGen parts
 (NFC)

The test added in #73511 currently fails in
CLANG_DEFAULT_PIE_ON_LINUX=OFF configuration, because it uses the
clang driver in a codegen test.

Split the tests into two, a driver test that checks that the
appropriate target feature is passed, and a codegen test that uses
cc1.
---
 clang/test/CodeGen/SystemZ/unaligned-symbols.c | 11 ---
 clang/test/Driver/s390x-unaligned-symbols.c|  7 +++
 2 files changed, 11 insertions(+), 7 deletions(-)
 create mode 100644 clang/test/Driver/s390x-unaligned-symbols.c

diff --git a/clang/test/CodeGen/SystemZ/unaligned-symbols.c 
b/clang/test/CodeGen/SystemZ/unaligned-symbols.c
index 31fc211393dd719..b19f30338857992 100644
--- a/clang/test/CodeGen/SystemZ/unaligned-symbols.c
+++ b/clang/test/CodeGen/SystemZ/unaligned-symbols.c
@@ -1,13 +1,10 @@
-// RUN: %clang -target s390x-linux-gnu %s -o - -emit-llvm -S \
+// RUN: %clang_cc1 -triple s390x-linux-gnu %s -o - -emit-llvm \
 // RUN:| FileCheck %s -check-prefixes=CHECK,ALIGNED
 
-// RUN: %clang -target s390x-linux-gnu %s -o - -emit-llvm -S \
-// RUN:-mno-unaligned-symbols | FileCheck %s -check-prefixes=CHECK,ALIGNED
+// RUN: %clang_cc1 -triple s390x-linux-gnu %s -o - -emit-llvm \
+// RUN:-target-feature -unaligned-symbols | FileCheck %s 
-check-prefixes=CHECK,ALIGNED
 
-// RUN: %clang -target s390x-linux-gnu %s -o - -emit-llvm -S \
-// RUN:-munaligned-symbols | FileCheck %s -check-prefixes=CHECK,UNALIGN
-
-// RUN: %clang -cc1 -triple s390x-linux-gnu %s -o - -emit-llvm \
+// RUN: %clang_cc1 -triple s390x-linux-gnu %s -o - -emit-llvm \
 // RUN:-target-feature +unaligned-symbols | FileCheck %s 
-check-prefixes=CHECK,UNALIGN
 
 
diff --git a/clang/test/Driver/s390x-unaligned-symbols.c 
b/clang/test/Driver/s390x-unaligned-symbols.c
new file mode 100644
index 000..1dff5b737fff776
--- /dev/null
+++ b/clang/test/Driver/s390x-unaligned-symbols.c
@@ -0,0 +1,7 @@
+// RUN: %clang -target s390x-linux-gnu -### -c %s 2>&1 | FileCheck 
-check-prefix=DEFAULT %s
+// RUN: %clang -target s390x-linux-gnu -mno-unaligned-symbols -### -c %s 2>&1 
| FileCheck -check-prefix=ALIGNED %s
+// RUN: %clang -target s390x-linux-gnu -munaligned-symbols -### -c %s 2>&1 | 
FileCheck -check-prefix=UNALIGN %s
+
+// DEFAULT-NOT: unaligned-symbols"
+// ALIGNED: "-target-feature" "-unaligned-symbols"
+// UNALIGN: "-target-feature" "+unaligned-symbols"

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


[clang] [Serialization] Load Specializations Lazily (PR #76774)

2024-01-29 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

> > > As far as I can tell from [#76774 
> > > (comment)](https://github.com/llvm/llvm-project/pull/76774#issuecomment-1914177330)
> > >  above, the last push only changed the default value of 
> > > `LoadExternalSpecializationsLazily`. In that case, my test results from 
> > > [#76774 
> > > (comment)](https://github.com/llvm/llvm-project/pull/76774#issuecomment-1912182171)
> > >  remain fully valid, especially
> > > > Switching the new `LoadExternalSpecializationsLazily` to disabled by 
> > > > default (somehow the argument didn't work on its own) instead crashes, 
> > > > most of the cases involving `MultiOnDiskHashTable`. I suspect some kind 
> > > > of memory error maybe?
> > 
> > 
> > No, this newest patch changes besides changing the default value. For 
> > example, 
> > [22c9d11#diff-125f472e690aa3d973bc42aa3c5d580226c5c47661551aca2889f960681aa64dR232-R237](https://github.com/llvm/llvm-project/commit/22c9d1145eb57d9c2cb2ef490b7c474598dd5d12#diff-125f472e690aa3d973bc42aa3c5d580226c5c47661551aca2889f960681aa64dR232-R237)
> >  now we won't write specializations into the hash table, while the original 
> > patch tries to load all the decls from the consumers' side only. This patch 
> > touches the producer's side.
> > Maybe I shouldn't push force to make the history clear..
> 
> If you want I can set you up with the ROOT project so that you can debug the 
> failures easier.

Thanks. Although I don't understand how can it be, it will be better if things 
can be easier.

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


[clang] [Clang, SystemZ] Split test into Driver and CodeGen parts (NFC) (PR #79808)

2024-01-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Nikita Popov (nikic)


Changes

The test added in #73511 currently fails in
CLANG_DEFAULT_PIE_ON_LINUX=OFF configuration, because it uses the clang driver 
in a codegen test.

Split the test into two, a driver test that checks that the appropriate target 
feature is passed, and a codegen test that uses cc1.

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


2 Files Affected:

- (modified) clang/test/CodeGen/SystemZ/unaligned-symbols.c (+4-7) 
- (added) clang/test/Driver/s390x-unaligned-symbols.c (+7) 


``diff
diff --git a/clang/test/CodeGen/SystemZ/unaligned-symbols.c 
b/clang/test/CodeGen/SystemZ/unaligned-symbols.c
index 31fc211393dd719..b19f30338857992 100644
--- a/clang/test/CodeGen/SystemZ/unaligned-symbols.c
+++ b/clang/test/CodeGen/SystemZ/unaligned-symbols.c
@@ -1,13 +1,10 @@
-// RUN: %clang -target s390x-linux-gnu %s -o - -emit-llvm -S \
+// RUN: %clang_cc1 -triple s390x-linux-gnu %s -o - -emit-llvm \
 // RUN:| FileCheck %s -check-prefixes=CHECK,ALIGNED
 
-// RUN: %clang -target s390x-linux-gnu %s -o - -emit-llvm -S \
-// RUN:-mno-unaligned-symbols | FileCheck %s -check-prefixes=CHECK,ALIGNED
+// RUN: %clang_cc1 -triple s390x-linux-gnu %s -o - -emit-llvm \
+// RUN:-target-feature -unaligned-symbols | FileCheck %s 
-check-prefixes=CHECK,ALIGNED
 
-// RUN: %clang -target s390x-linux-gnu %s -o - -emit-llvm -S \
-// RUN:-munaligned-symbols | FileCheck %s -check-prefixes=CHECK,UNALIGN
-
-// RUN: %clang -cc1 -triple s390x-linux-gnu %s -o - -emit-llvm \
+// RUN: %clang_cc1 -triple s390x-linux-gnu %s -o - -emit-llvm \
 // RUN:-target-feature +unaligned-symbols | FileCheck %s 
-check-prefixes=CHECK,UNALIGN
 
 
diff --git a/clang/test/Driver/s390x-unaligned-symbols.c 
b/clang/test/Driver/s390x-unaligned-symbols.c
new file mode 100644
index 000..1dff5b737fff776
--- /dev/null
+++ b/clang/test/Driver/s390x-unaligned-symbols.c
@@ -0,0 +1,7 @@
+// RUN: %clang -target s390x-linux-gnu -### -c %s 2>&1 | FileCheck 
-check-prefix=DEFAULT %s
+// RUN: %clang -target s390x-linux-gnu -mno-unaligned-symbols -### -c %s 2>&1 
| FileCheck -check-prefix=ALIGNED %s
+// RUN: %clang -target s390x-linux-gnu -munaligned-symbols -### -c %s 2>&1 | 
FileCheck -check-prefix=UNALIGN %s
+
+// DEFAULT-NOT: unaligned-symbols"
+// ALIGNED: "-target-feature" "-unaligned-symbols"
+// UNALIGN: "-target-feature" "+unaligned-symbols"

``




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


[clang] [Clang, SystemZ] Split test into Driver and CodeGen parts (NFC) (PR #79808)

2024-01-29 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Nikita Popov (nikic)


Changes

The test added in #73511 currently fails in
CLANG_DEFAULT_PIE_ON_LINUX=OFF configuration, because it uses the clang driver 
in a codegen test.

Split the test into two, a driver test that checks that the appropriate target 
feature is passed, and a codegen test that uses cc1.

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


2 Files Affected:

- (modified) clang/test/CodeGen/SystemZ/unaligned-symbols.c (+4-7) 
- (added) clang/test/Driver/s390x-unaligned-symbols.c (+7) 


``diff
diff --git a/clang/test/CodeGen/SystemZ/unaligned-symbols.c 
b/clang/test/CodeGen/SystemZ/unaligned-symbols.c
index 31fc211393dd719..b19f30338857992 100644
--- a/clang/test/CodeGen/SystemZ/unaligned-symbols.c
+++ b/clang/test/CodeGen/SystemZ/unaligned-symbols.c
@@ -1,13 +1,10 @@
-// RUN: %clang -target s390x-linux-gnu %s -o - -emit-llvm -S \
+// RUN: %clang_cc1 -triple s390x-linux-gnu %s -o - -emit-llvm \
 // RUN:| FileCheck %s -check-prefixes=CHECK,ALIGNED
 
-// RUN: %clang -target s390x-linux-gnu %s -o - -emit-llvm -S \
-// RUN:-mno-unaligned-symbols | FileCheck %s -check-prefixes=CHECK,ALIGNED
+// RUN: %clang_cc1 -triple s390x-linux-gnu %s -o - -emit-llvm \
+// RUN:-target-feature -unaligned-symbols | FileCheck %s 
-check-prefixes=CHECK,ALIGNED
 
-// RUN: %clang -target s390x-linux-gnu %s -o - -emit-llvm -S \
-// RUN:-munaligned-symbols | FileCheck %s -check-prefixes=CHECK,UNALIGN
-
-// RUN: %clang -cc1 -triple s390x-linux-gnu %s -o - -emit-llvm \
+// RUN: %clang_cc1 -triple s390x-linux-gnu %s -o - -emit-llvm \
 // RUN:-target-feature +unaligned-symbols | FileCheck %s 
-check-prefixes=CHECK,UNALIGN
 
 
diff --git a/clang/test/Driver/s390x-unaligned-symbols.c 
b/clang/test/Driver/s390x-unaligned-symbols.c
new file mode 100644
index 000..1dff5b737fff776
--- /dev/null
+++ b/clang/test/Driver/s390x-unaligned-symbols.c
@@ -0,0 +1,7 @@
+// RUN: %clang -target s390x-linux-gnu -### -c %s 2>&1 | FileCheck 
-check-prefix=DEFAULT %s
+// RUN: %clang -target s390x-linux-gnu -mno-unaligned-symbols -### -c %s 2>&1 
| FileCheck -check-prefix=ALIGNED %s
+// RUN: %clang -target s390x-linux-gnu -munaligned-symbols -### -c %s 2>&1 | 
FileCheck -check-prefix=UNALIGN %s
+
+// DEFAULT-NOT: unaligned-symbols"
+// ALIGNED: "-target-feature" "-unaligned-symbols"
+// UNALIGN: "-target-feature" "+unaligned-symbols"

``




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


[clang] 5f4ee5a - [Clang][AST] Fix a crash on attaching doc comments (#78716)

2024-01-29 Thread via cfe-commits

Author: Shanzhi
Date: 2024-01-29T19:17:13+08:00
New Revision: 5f4ee5a2dfa97fe32ee62d1d67aa1413d5a059e6

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

LOG: [Clang][AST] Fix a crash on attaching doc comments (#78716)

This crash is basically caused by calling
`ASTContext::getRawCommentForDeclNoCacheImp` with its input arguments
`RepresentativeLocForDecl` and `CommentsInTheFile` refering to different
files. A reduced reproducer is provided in this patch.

After the source locations for instantiations of funtion template are
corrected in the commit 256a0b298c68b89688b80350b034daf2f7785b67, the
variable `CommitsInThisFile` in the function
`ASTContext::attachCommentsToJustParsedDecls` would refer to the source
file rather than the header file for implicit function template
instantiation. Therefore, in the first loop in
`ASTContext::attachCommentsToJustParsedDecls`, `D` should also be
adjusted for relevant scenarios like the second loop.

Fixes #67979 
Fixes #68524
Fixes #70550

Added: 
clang/test/AST/ast-crash-doc-function-template.cpp

Modified: 
clang/lib/AST/ASTContext.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index f7c9e4521b5f16..71c9c0003d18c0 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -498,7 +498,11 @@ void 
ASTContext::attachCommentsToJustParsedDecls(ArrayRef Decls,
 return;
 
   FileID File;
-  for (Decl *D : Decls) {
+  for (const Decl *D : Decls) {
+if (D->isInvalidDecl())
+  continue;
+
+D = &adjustDeclToTemplate(*D);
 SourceLocation Loc = D->getLocation();
 if (Loc.isValid()) {
   // See if there are any new comments that are not attached to a decl.

diff  --git a/clang/test/AST/ast-crash-doc-function-template.cpp 
b/clang/test/AST/ast-crash-doc-function-template.cpp
new file mode 100644
index 00..d48eb0dbe02f01
--- /dev/null
+++ b/clang/test/AST/ast-crash-doc-function-template.cpp
@@ -0,0 +1,30 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -x c++ -Wdocumentation -fsyntax-only -ast-dump-all %t/t.cpp
+
+//--- t.h
+/// MyClass in the header file
+class MyClass {
+public:
+  template 
+  void Foo() const;
+
+  /// Bar
+  void Bar() const;
+};
+
+//--- t.cpp
+#include "t.h"
+
+/// MyClass::Bar: Foo() is implicitly instantiated and called here.
+void MyClass::Bar() const {
+  Foo();
+}
+
+/// MyClass::Foo
+template 
+void MyClass::Foo() const {
+}
+
+// CHECK: TranslationUnitDecl



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


[llvm] [clang-tools-extra] [clang] [Clang][AST] Fix a crash on attaching doc comments (PR #78716)

2024-01-29 Thread via cfe-commits

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


[clang-tools-extra] [flang] [llvm] [clang] [compiler-rt] [AMDGPU] Fold operand after shrinking instruction in SIFoldOperands (PR #68426)

2024-01-29 Thread Jay Foad via cfe-commits

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


[llvm] [clang-tools-extra] [clang] [AMDGPU] Update SITargetLowering::getAddrModeArguments (PR #78740)

2024-01-29 Thread Jay Foad via cfe-commits

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


[clang] [clang] Implement CTAD for type alias template. (PR #77890)

2024-01-29 Thread Haojian Wu via cfe-commits

hokein wrote:

Thanks for the summary.

> We do not think a feature flag is a good fit.
> 
> * Until clang 19 ships (in 6 months) we do not need to stabilize the feature 
> (but ofc we should avoid regressions, which we would not find if hidden 
> behind a flag), and the flag does not guarantee existing features are not 
> impacted.
> 

I think this works fine with clang open-source release cycles (18 release was 
just cut, we have 6 months from now to polish this feature). However, this is 
not applicable for our internal case. At Google, we have used C++20 in 
production, and we have our own toolchain release cycles (which stay close to 
upstream main). Checking in an in-development C++20 feature without a proper 
safeguard poses risks to users (clang crashes, incorrect compilations, and 
other issues).

So having a temporary flag is useful, it enables us to incrementally test and 
experiment it without compromising the experience for most users. 

> And if we break trunk, we revert, you get extra test cases... it's perfectly 
> fine

We could revert the whole patch when things are broken (and it is what we 
usually do). But I'm not sure revert/reland a big patch back and forth is a 
good idea.

This also brings a general question: what level of quality should we require 
from experimental features in HEAD?

> We do that for about every feature that is not concept/module scale (and then 
> again, these things were tses), and this isn't big enough to warrant a novel 
> approach.

Yeah, I agree that this is a narrow feature. Given that this feature is very 
late to the party, and C++20 has been used in some productions, I think it is 
probably reasonable to have a flag.

> I still think we should land this soon and we can start a review whenever you 
> are ready.
If you want to land it in an incomplete state, we just need to make sure we 
have a good collective understanding of the remaining work that would need to 
be done to bring the feature to completion (tests with fix me, issues, etc)

+1, I think the current state should be good enough and ready for review. The 
remaining big piece (see the FIXME) is to implement the associated constraints 
(over.match.class.deduct#3.3).


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


[polly] [clang] [clang-format] Add AllowShortType option for AlwaysBreakAfterReturnType. (PR #78011)

2024-01-29 Thread via cfe-commits

https://github.com/rmarker updated 
https://github.com/llvm/llvm-project/pull/78011

>From a1312a0a463bb946f336977b5b01ef7afbede678 Mon Sep 17 00:00:00 2001
From: rmarker 
Date: Thu, 11 Jan 2024 15:01:18 +1030
Subject: [PATCH 01/10] [clang-format] Add ShortReturnTypeColumn option.

---
 clang/docs/ClangFormatStyleOptions.rst | 13 +++
 clang/docs/ReleaseNotes.rst|  1 +
 clang/include/clang/Format/Format.h| 12 ++
 clang/lib/Format/ContinuationIndenter.cpp  |  3 +-
 clang/lib/Format/Format.cpp|  2 +
 clang/unittests/Format/ConfigParseTest.cpp |  1 +
 clang/unittests/Format/FormatTest.cpp  | 44 ++
 7 files changed, 75 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 4dc0de3a90f2650..7836cc8f1c9bb5b 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -4999,6 +4999,19 @@ the configuration (without a prefix: ``Auto``).
int bar;   int bar;
  } // namespace b   } // namespace b
 
+.. _ShortReturnTypeColumn:
+
+**ShortReturnTypeColumn** (``Unsigned``) :versionbadge:`clang-format 19` 
:ref:`¶ `
+  When ``AlwaysBreakAfterReturnType`` is ``None``, line breaks are prevented
+  after short return types. This configures the column limit for a type
+  to be regarded as short.
+
+
+  .. note::
+
+   This isn't the length of the type itself, but the column where it
+   finishes. I.e. it includes indentation, etc.
+
 .. _SkipMacroDefinitionBody:
 
 **SkipMacroDefinitionBody** (``Boolean``) :versionbadge:`clang-format 18` 
:ref:`¶ `
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5330cd9caad8011..669b420fe21ec15 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -184,6 +184,7 @@ AST Matchers
 
 clang-format
 
+- Add ``ShortReturnTypeColumn`` option.
 
 libclang
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index bc9eecd42f9ebfd..7fd574c98a3944f 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -3932,6 +3932,17 @@ struct FormatStyle {
   /// \version 13
   unsigned ShortNamespaceLines;
 
+  /// When ``AlwaysBreakAfterReturnType`` is ``None``, line breaks are 
prevented
+  /// after short return types. This configures the column limit for a type
+  /// to be regarded as short.
+  ///
+  /// \note
+  ///  This isn't the length of the type itself, but the column where it
+  ///  finishes. I.e. it includes indentation, etc.
+  /// \endnote
+  /// \version 19
+  unsigned ShortReturnTypeColumn;
+
   /// Do not format macro definition body.
   /// \version 18
   bool SkipMacroDefinitionBody;
@@ -4899,6 +4910,7 @@ struct FormatStyle {
RequiresExpressionIndentation == R.RequiresExpressionIndentation &&
SeparateDefinitionBlocks == R.SeparateDefinitionBlocks &&
ShortNamespaceLines == R.ShortNamespaceLines &&
+   ShortReturnTypeColumn == R.ShortReturnTypeColumn &&
SkipMacroDefinitionBody == R.SkipMacroDefinitionBody &&
SortIncludes == R.SortIncludes &&
SortJavaStaticImport == R.SortJavaStaticImport &&
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index a3eb9138b218335..3f9c0cc815745c3 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -328,7 +328,8 @@ bool ContinuationIndenter::canBreak(const LineState &State) 
{
 
   // Don't break after very short return types (e.g. "void") as that is often
   // unexpected.
-  if (Current.is(TT_FunctionDeclarationName) && State.Column < 6) {
+  if (Current.is(TT_FunctionDeclarationName) &&
+  State.Column <= Style.ShortReturnTypeColumn) {
 if (Style.AlwaysBreakAfterReturnType == FormatStyle::RTBS_None)
   return false;
   }
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index ff326dc784783b2..35478fac7b49629 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1085,6 +1085,7 @@ template <> struct MappingTraits {
Style.RequiresExpressionIndentation);
 IO.mapOptional("SeparateDefinitionBlocks", Style.SeparateDefinitionBlocks);
 IO.mapOptional("ShortNamespaceLines", Style.ShortNamespaceLines);
+IO.mapOptional("ShortReturnTypeColumn", Style.ShortReturnTypeColumn);
 IO.mapOptional("SkipMacroDefinitionBody", Style.SkipMacroDefinitionBody);
 IO.mapOptional("SortIncludes", Style.SortIncludes);
 IO.mapOptional("SortJavaStaticImport", Style.SortJavaStaticImport);
@@ -1557,6 +1558,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   LLVMStyle.RequiresExpressionIndentation = FormatStyle::REI_OuterScope;
   LLVMStyle.SeparateDefinitionBlocks = FormatStyle::SDS_Leave;
   LLVMStyle.ShortNamespace

[clang] [clang] Use getDefaultArgRange instead of getDefaultArg to retrieve the (PR #79296)

2024-01-29 Thread Haojian Wu via cfe-commits

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


[polly] [clang] [clang-format] Add AllowShortType option for AlwaysBreakAfterReturnType. (PR #78011)

2024-01-29 Thread via cfe-commits


@@ -922,8 +922,23 @@ struct FormatStyle {
 ///   };
 ///   int f();
 ///   int f() { return 1; }
+///   int f::
+///   bar();
 /// \endcode
 RTBS_None,
+/// Break after return type automatically, while allowing a break after
+/// short return types.
+/// ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
+/// \code
+///   class A {
+/// int f() { return 0; };
+///   };
+///   int f();
+///   int f() { return 1; }
+///   int
+///   
f::bar();
+/// \endcode
+RTBS_AllowShortType,
 /// Always break after the return type.
 /// \code
 ///   class A {

rmarker wrote:

Yes, it should indeed be added.

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


[llvm] [flang] [clang-tools-extra] [mlir] [libcxx] [clang] [LV] Improve AnyOf reduction codegen. (PR #78304)

2024-01-29 Thread Florian Hahn via cfe-commits

https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/78304

>From 9846f970b6b394ccc3af25b92f238377a8ae7807 Mon Sep 17 00:00:00 2001
From: Florian Hahn 
Date: Sun, 14 Jan 2024 18:06:36 +
Subject: [PATCH 1/2] [LV] Improve AnyOf reduction codegen.

Update AnyOf reduction code generation to only keep track of the AnyOf
property in a boolean vector in the loop, only selecting either the new
or start value in the middle block.

This fixes the #62565, as now there aren't multiple uses of the
start/new values.

Fixes https://github.com/llvm/llvm-project/issues/62565
---
 .../include/llvm/Transforms/Utils/LoopUtils.h |   9 --
 llvm/lib/Transforms/Utils/LoopUtils.cpp   |  24 +--
 .../Vectorize/LoopVectorizationPlanner.h  |   1 +
 .../Transforms/Vectorize/LoopVectorize.cpp|  44 +-
 .../lib/Transforms/Vectorize/VPlanRecipes.cpp |   7 +-
 .../LoopVectorize/AArch64/sve-select-cmp.ll   |  38 ++---
 .../RISCV/select-cmp-reduction.ll | 120 ++
 .../LoopVectorize/select-cmp-predicated.ll|  29 ++--
 .../Transforms/LoopVectorize/select-cmp.ll| 146 +-
 ...tion-start-value-may-be-undef-or-poison.ll |  43 +++---
 10 files changed, 218 insertions(+), 243 deletions(-)

diff --git a/llvm/include/llvm/Transforms/Utils/LoopUtils.h 
b/llvm/include/llvm/Transforms/Utils/LoopUtils.h
index 5a1385d01d8e44d..3bad7b616d9d756 100644
--- a/llvm/include/llvm/Transforms/Utils/LoopUtils.h
+++ b/llvm/include/llvm/Transforms/Utils/LoopUtils.h
@@ -363,15 +363,6 @@ Intrinsic::ID getMinMaxReductionIntrinsicOp(RecurKind RK);
 /// Returns the comparison predicate used when expanding a min/max reduction.
 CmpInst::Predicate getMinMaxReductionPredicate(RecurKind RK);
 
-/// See RecurrenceDescriptor::isAnyOfPattern for a description of the pattern 
we
-/// are trying to match. In this pattern, we are only ever selecting between 
two
-/// values: 1) an initial start value \p StartVal of the reduction PHI, and 2) 
a
-/// loop invariant value. If any of lane value in \p Left, \p Right is not 
equal
-/// to \p StartVal, select the loop invariant value. This is done by selecting
-/// \p Right iff \p Left is equal to \p StartVal.
-Value *createAnyOfOp(IRBuilderBase &Builder, Value *StartVal, RecurKind RK,
- Value *Left, Value *Right);
-
 /// Returns a Min/Max operation corresponding to MinMaxRecurrenceKind.
 /// The Builder's fast-math-flags must be set to propagate the expected values.
 Value *createMinMaxOp(IRBuilderBase &Builder, RecurKind RK, Value *Left,
diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp 
b/llvm/lib/Transforms/Utils/LoopUtils.cpp
index 59485126b280abf..c0582fb7d7e1505 100644
--- a/llvm/lib/Transforms/Utils/LoopUtils.cpp
+++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp
@@ -962,15 +962,6 @@ CmpInst::Predicate 
llvm::getMinMaxReductionPredicate(RecurKind RK) {
   }
 }
 
-Value *llvm::createAnyOfOp(IRBuilderBase &Builder, Value *StartVal,
-   RecurKind RK, Value *Left, Value *Right) {
-  if (auto VTy = dyn_cast(Left->getType()))
-StartVal = Builder.CreateVectorSplat(VTy->getElementCount(), StartVal);
-  Value *Cmp =
-  Builder.CreateCmp(CmpInst::ICMP_NE, Left, StartVal, "rdx.select.cmp");
-  return Builder.CreateSelect(Cmp, Left, Right, "rdx.select");
-}
-
 Value *llvm::createMinMaxOp(IRBuilderBase &Builder, RecurKind RK, Value *Left,
 Value *Right) {
   Type *Ty = Left->getType();
@@ -1079,16 +1070,13 @@ Value *llvm::createAnyOfTargetReduction(IRBuilderBase 
&Builder, Value *Src,
 NewVal = SI->getTrueValue();
   }
 
-  // Create a splat vector with the new value and compare this to the vector
-  // we want to reduce.
-  ElementCount EC = cast(Src->getType())->getElementCount();
-  Value *Right = Builder.CreateVectorSplat(EC, InitVal);
-  Value *Cmp =
-  Builder.CreateCmp(CmpInst::ICMP_NE, Src, Right, "rdx.select.cmp");
-
   // If any predicate is true it means that we want to select the new value.
-  Cmp = Builder.CreateOrReduce(Cmp);
-  return Builder.CreateSelect(Cmp, NewVal, InitVal, "rdx.select");
+  Value *AnyOf =
+  Src->getType()->isVectorTy() ? Builder.CreateOrReduce(Src) : Src;
+  // The compares in the loop may yield poison, which propagates through the
+  // bitwise ORs. Freeze it here before the condition is used.
+  AnyOf = Builder.CreateFreeze(AnyOf);
+  return Builder.CreateSelect(AnyOf, NewVal, InitVal, "rdx.select");
 }
 
 Value *llvm::createSimpleTargetReduction(IRBuilderBase &Builder, Value *Src,
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h 
b/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h
index a7ebf78e54ceb61..9d3ef5b96c72fbe 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h
@@ -68,6 +68,7 @@ class VPBuilder {
 public:
   VPBuilder() = default;
   VPBuilder(VPBasicBlock *InsertBB) { setInsertPoint(InsertBB); }
+  VPBuilder(VPRec

[lldb] [flang] [llvm] [compiler-rt] [clang-tools-extra] [mlir] [libcxx] [clang] [libc] [AArch64] add intrinsic to generate a bfi instruction (PR #79672)

2024-01-29 Thread Rama Malladi via cfe-commits

RamaMalladiAWS wrote:

> @RamaMalladiAWS Do you have examples of the IR that fails to lower to BFI? 
> These things often turn out to be either a missing middle-end 
> canonicalization or maybe a case that could be added to existing pattern 
> matching in the back-end.

Yes, @RKSimon, I will try to get some test-cases in the next couple of days and 
we can evaluate the issues if any. Thank you.

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


[polly] [clang] [clang-format] Add AllowShortType option for AlwaysBreakAfterReturnType. (PR #78011)

2024-01-29 Thread via cfe-commits


@@ -922,8 +922,23 @@ struct FormatStyle {
 ///   };
 ///   int f();
 ///   int f() { return 1; }
+///   int f::

rmarker wrote:

Ah, that is nice.
The long names required to get the behaviour naturally didn't seem very 
pleasant.

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


[polly] [clang] [clang-format] Add AllowShortType option for AlwaysBreakAfterReturnType. (PR #78011)

2024-01-29 Thread via cfe-commits


@@ -922,8 +922,23 @@ struct FormatStyle {
 ///   };
 ///   int f();
 ///   int f() { return 1; }
+///   int f::
+///   bar();
 /// \endcode
 RTBS_None,
+/// Break after return type automatically, while allowing a break after
+/// short return types.

rmarker wrote:

I made another attempt at being clearer.
What do you think?

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


[clang] [clang] Improved isSimpleTypeSpecifier (PR #79037)

2024-01-29 Thread Carl Peto via cfe-commits

https://github.com/carlos4242 updated 
https://github.com/llvm/llvm-project/pull/79037

>From a78545315baf3d920f7101f44c6dba05238dbcf7 Mon Sep 17 00:00:00 2001
From: Carl Peto 
Date: Fri, 26 Jan 2024 14:20:48 +
Subject: [PATCH] [clang] - Sema::isSimpleTypeSpecifier return true for
 _Bool in c99 (currently returns false for _Bool, regardless of C dialect).
 (Fixes #72203) - replace the logic with a check for simple types and a
 proper check for a valid keyword in the appropriate dialect - PR feedback
 fixes for owenca

---
 clang/include/clang/Sema/Sema.h |  2 +-
 clang/lib/Parse/ParseExpr.cpp   |  2 +-
 clang/lib/Parse/ParseObjc.cpp   |  2 +-
 clang/lib/Sema/SemaDecl.cpp | 25 ++---
 4 files changed, 13 insertions(+), 18 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index b5946e3f3178ff2..31ee05ec99a43c8 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2644,7 +2644,7 @@ class Sema final {
 
   void DiagnoseUseOfUnimplementedSelectors();
 
-  bool isSimpleTypeSpecifier(tok::TokenKind Kind) const;
+  bool isSimpleTypeSpecifier(const Token &Tok) const;
 
   ParsedType getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
  Scope *S, CXXScopeSpec *SS = nullptr,
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 68dc1bc4a40a074..e5d4285b991831e 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -1609,7 +1609,7 @@ ExprResult Parser::ParseCastExpression(CastParseKind 
ParseKind,
   if (TryAnnotateTypeOrScopeToken())
 return ExprError();
 
-  if (!Actions.isSimpleTypeSpecifier(Tok.getKind()))
+  if (!Actions.isSimpleTypeSpecifier(Tok))
 // We are trying to parse a simple-type-specifier but might not get 
such
 // a token after error recovery.
 return ExprError();
diff --git a/clang/lib/Parse/ParseObjc.cpp b/clang/lib/Parse/ParseObjc.cpp
index 849fd1ac95a442e..4771b69eadb34b9 100644
--- a/clang/lib/Parse/ParseObjc.cpp
+++ b/clang/lib/Parse/ParseObjc.cpp
@@ -2971,7 +2971,7 @@ bool Parser::ParseObjCXXMessageReceiver(bool &IsExpr, 
void *&TypeOrExpr) {
   tok::annot_cxxscope))
 TryAnnotateTypeOrScopeToken();
 
-  if (!Actions.isSimpleTypeSpecifier(Tok.getKind())) {
+  if (!Actions.isSimpleTypeSpecifier(Tok)) {
 //   objc-receiver:
 // expression
 // Make sure any typos in the receiver are corrected or diagnosed, so that
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index e725e187fc9ea08..c31b07d46cf5301 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -128,10 +128,13 @@ class TypeNameValidatorCCC final : public 
CorrectionCandidateCallback {
 } // end anonymous namespace
 
 /// Determine whether the token kind starts a simple-type-specifier.
-bool Sema::isSimpleTypeSpecifier(tok::TokenKind Kind) const {
-  switch (Kind) {
-  // FIXME: Take into account the current language when deciding whether a
-  // token kind is a valid type specifier
+bool Sema::isSimpleTypeSpecifier(const Token &Tok) const {
+  switch (Tok.getKind()) {
+  case tok::annot_typename:
+  case tok::annot_decltype:
+  case tok::annot_pack_indexing_type:
+return true;
+
   case tok::kw_short:
   case tok::kw_long:
   case tok::kw___int64:
@@ -150,31 +153,23 @@ bool Sema::isSimpleTypeSpecifier(tok::TokenKind Kind) 
const {
   case tok::kw___ibm128:
   case tok::kw_wchar_t:
   case tok::kw_bool:
+  case tok::kw__Bool:
   case tok::kw__Accum:
   case tok::kw__Fract:
   case tok::kw__Sat:
 #define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
 #include "clang/Basic/TransformTypeTraits.def"
   case tok::kw___auto_type:
-return true;
-
-  case tok::annot_typename:
   case tok::kw_char16_t:
   case tok::kw_char32_t:
   case tok::kw_typeof:
-  case tok::annot_decltype:
-  case tok::annot_pack_indexing_type:
   case tok::kw_decltype:
-return getLangOpts().CPlusPlus;
-
   case tok::kw_char8_t:
-return getLangOpts().Char8;
+return Tok.getIdentifierInfo()->isKeyword(getLangOpts());
 
   default:
-break;
+return false;
   }
-
-  return false;
 }
 
 namespace {

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


[clang] [llvm] [RISCV] Graduate Zicond to non-experimental (PR #79811)

2024-01-29 Thread Alex Bradbury via cfe-commits

https://github.com/asb created https://github.com/llvm/llvm-project/pull/79811

The Zicond extension was ratified in the last few months, with no changes that 
affect the LLVM implementation. Although there's surely more tuning that could 
be done about when to select Zicond or not, there are no known correctness 
issues. Therefore, we should mark support as non-experimental.

>From cf5c3432f66b36db0b8283a967b24686433cdf63 Mon Sep 17 00:00:00 2001
From: Alex Bradbury 
Date: Sun, 28 Jan 2024 08:50:35 +
Subject: [PATCH] [RISCV] Graduate Zicond to non-experimental

The Zicond extension was ratified in the last few months, with no
changes that affect the LLVM implementation. Although there's surely
more tuning that could be done about when to select Zicond or not, there
are no known correctness issues. Therefore, we should mark support as
non-experimental.
---
 .../CodeGen/RISCV/riscv-func-attr-target.c|  2 +-
 .../test/Preprocessor/riscv-target-features.c | 18 
 llvm/docs/RISCVUsage.rst  |  4 +-
 llvm/docs/ReleaseNotes.rst|  2 +
 llvm/lib/Support/RISCVISAInfo.cpp |  3 +-
 llvm/lib/Target/RISCV/RISCVFeatures.td|  2 +-
 llvm/lib/Target/RISCV/RISCVInstrInfoZicond.td |  2 -
 llvm/test/CodeGen/RISCV/attributes.ll |  4 +-
 llvm/test/CodeGen/RISCV/cmov-branch-opt.ll|  4 +-
 llvm/test/CodeGen/RISCV/condbinops.ll |  4 +-
 llvm/test/CodeGen/RISCV/condops.ll|  4 +-
 .../CodeGen/RISCV/select-binop-identity.ll|  4 +-
 llvm/test/CodeGen/RISCV/select.ll |  4 +-
 .../CodeGen/RISCV/short-forward-branch-opt.ll |  2 +-
 llvm/test/CodeGen/RISCV/xaluo.ll  |  4 +-
 llvm/test/MC/RISCV/rv32zicond-invalid.s   |  4 +-
 llvm/test/MC/RISCV/rv32zicond-valid.s | 12 ++---
 llvm/unittests/Support/RISCVISAInfoTest.cpp   | 46 +--
 18 files changed, 61 insertions(+), 64 deletions(-)

diff --git a/clang/test/CodeGen/RISCV/riscv-func-attr-target.c 
b/clang/test/CodeGen/RISCV/riscv-func-attr-target.c
index 7d3362e84e75888..f216eaf735b4a85 100644
--- a/clang/test/CodeGen/RISCV/riscv-func-attr-target.c
+++ b/clang/test/CodeGen/RISCV/riscv-func-attr-target.c
@@ -39,7 +39,7 @@ __attribute__((target("cpu=sifive-u54"))) void 
testAttrCpuOnly() {}
 // CHECK: attributes #0 = { 
{{.*}}"target-features"="+64bit,+a,+m,+save-restore,+zifencei,-relax,-zbb,-zfa" 
}
 // CHECK: attributes #1 = { {{.*}}"target-cpu"="rocket-rv64" 
"target-features"="+64bit,+a,+d,+f,+m,+save-restore,+v,+zicsr,+zifencei,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-relax,-zbb,-zfa"
 "tune-cpu"="generic-rv64" }
 // CHECK: attributes #2 = { 
{{.*}}"target-features"="+64bit,+a,+m,+save-restore,+zbb,+zifencei,-relax,-zfa" 
}
-// CHECK: attributes #3 = { 
{{.*}}"target-features"="+64bit,+a,+d,+experimental-zicond,+f,+m,+save-restore,+v,+zbb,+zicsr,+zifencei,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-relax,-zfa"
 }
+// CHECK: attributes #3 = { 
{{.*}}"target-features"="+64bit,+a,+d,+f,+m,+save-restore,+v,+zbb,+zicond,+zicsr,+zifencei,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-relax,-zfa"
 }
 // Make sure we append negative features if we override the arch
 // CHECK: attributes #4 = { 
{{.*}}"target-features"="+64bit,+a,+c,+d,+f,+m,+save-restore,+zbb,+zicsr,+zifencei,{{(-[[:alnum:]-]+)(,-[[:alnum:]-]+)*}}"
 }
 // CHECK: attributes #5 = { 
{{.*}}"target-features"="+64bit,+m,+save-restore,{{(-[[:alnum:]-]+)(,-[[:alnum:]-]+)*}}"
 }
diff --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 8f50126f1b36285..2361c83a5a6102d 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -88,6 +88,7 @@
 // CHECK-NOT: __riscv_zicclsm {{.*$}}
 // CHECK-NOT: __riscv_ziccrse {{.*$}}
 // CHECK-NOT: __riscv_zicntr {{.*$}}
+// CHECK-NOT: __riscv_zicond {{.*$}}
 // CHECK-NOT: __riscv_zicsr {{.*$}}
 // CHECK-NOT: __riscv_zifencei {{.*$}}
 // CHECK-NOT: __riscv_zihintntl {{.*$}}
@@ -148,7 +149,6 @@
 // CHECK-NOT: __riscv_zfbfmin {{.*$}}
 // CHECK-NOT: __riscv_zicfilp {{.*$}}
 // CHECK-NOT: __riscv_zicfiss {{.*$}}
-// CHECK-NOT: __riscv_zicond {{.*$}}
 // CHECK-NOT: __riscv_zimop {{.*$}}
 // CHECK-NOT: __riscv_ztso {{.*$}}
 // CHECK-NOT: __riscv_zvfbfmin {{.*$}}
@@ -766,6 +766,14 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZICNTR-EXT %s
 // CHECK-ZICNTR-EXT: __riscv_zicntr 200{{$}}
 
+// RUN: %clang --target=riscv32 \
+// RUN:   -march=rv32i_zicond -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-ZICOND-EXT %s
+// RUN: %clang --target=riscv64 \
+// RUN:   -march=rv64i_zicond -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-ZICOND-EXT %s
+// CHECK-ZICOND-EXT: __riscv_zicond  100{{$}}
+
 // RUN: %clang --target=riscv32-unknown-linux-gnu \
 // RUN:   -march=rv32izicsr2p0 -E -dM %s \
 // RUN:   -o - | FileCheck --check-prefix=CHECK-Z

[clang] [llvm] [RISCV] Graduate Zicond to non-experimental (PR #79811)

2024-01-29 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-llvm-support

@llvm/pr-subscribers-clang

Author: Alex Bradbury (asb)


Changes

The Zicond extension was ratified in the last few months, with no changes that 
affect the LLVM implementation. Although there's surely more tuning that could 
be done about when to select Zicond or not, there are no known correctness 
issues. Therefore, we should mark support as non-experimental.

---

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


18 Files Affected:

- (modified) clang/test/CodeGen/RISCV/riscv-func-attr-target.c (+1-1) 
- (modified) clang/test/Preprocessor/riscv-target-features.c (+9-9) 
- (modified) llvm/docs/RISCVUsage.rst (+1-3) 
- (modified) llvm/docs/ReleaseNotes.rst (+2) 
- (modified) llvm/lib/Support/RISCVISAInfo.cpp (+1-2) 
- (modified) llvm/lib/Target/RISCV/RISCVFeatures.td (+1-1) 
- (modified) llvm/lib/Target/RISCV/RISCVInstrInfoZicond.td (-2) 
- (modified) llvm/test/CodeGen/RISCV/attributes.ll (+2-2) 
- (modified) llvm/test/CodeGen/RISCV/cmov-branch-opt.ll (+2-2) 
- (modified) llvm/test/CodeGen/RISCV/condbinops.ll (+2-2) 
- (modified) llvm/test/CodeGen/RISCV/condops.ll (+2-2) 
- (modified) llvm/test/CodeGen/RISCV/select-binop-identity.ll (+2-2) 
- (modified) llvm/test/CodeGen/RISCV/select.ll (+2-2) 
- (modified) llvm/test/CodeGen/RISCV/short-forward-branch-opt.ll (+1-1) 
- (modified) llvm/test/CodeGen/RISCV/xaluo.ll (+2-2) 
- (modified) llvm/test/MC/RISCV/rv32zicond-invalid.s (+2-2) 
- (modified) llvm/test/MC/RISCV/rv32zicond-valid.s (+6-6) 
- (modified) llvm/unittests/Support/RISCVISAInfoTest.cpp (+23-23) 


``diff
diff --git a/clang/test/CodeGen/RISCV/riscv-func-attr-target.c 
b/clang/test/CodeGen/RISCV/riscv-func-attr-target.c
index 7d3362e84e75888..f216eaf735b4a85 100644
--- a/clang/test/CodeGen/RISCV/riscv-func-attr-target.c
+++ b/clang/test/CodeGen/RISCV/riscv-func-attr-target.c
@@ -39,7 +39,7 @@ __attribute__((target("cpu=sifive-u54"))) void 
testAttrCpuOnly() {}
 // CHECK: attributes #0 = { 
{{.*}}"target-features"="+64bit,+a,+m,+save-restore,+zifencei,-relax,-zbb,-zfa" 
}
 // CHECK: attributes #1 = { {{.*}}"target-cpu"="rocket-rv64" 
"target-features"="+64bit,+a,+d,+f,+m,+save-restore,+v,+zicsr,+zifencei,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-relax,-zbb,-zfa"
 "tune-cpu"="generic-rv64" }
 // CHECK: attributes #2 = { 
{{.*}}"target-features"="+64bit,+a,+m,+save-restore,+zbb,+zifencei,-relax,-zfa" 
}
-// CHECK: attributes #3 = { 
{{.*}}"target-features"="+64bit,+a,+d,+experimental-zicond,+f,+m,+save-restore,+v,+zbb,+zicsr,+zifencei,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-relax,-zfa"
 }
+// CHECK: attributes #3 = { 
{{.*}}"target-features"="+64bit,+a,+d,+f,+m,+save-restore,+v,+zbb,+zicond,+zicsr,+zifencei,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-relax,-zfa"
 }
 // Make sure we append negative features if we override the arch
 // CHECK: attributes #4 = { 
{{.*}}"target-features"="+64bit,+a,+c,+d,+f,+m,+save-restore,+zbb,+zicsr,+zifencei,{{(-[[:alnum:]-]+)(,-[[:alnum:]-]+)*}}"
 }
 // CHECK: attributes #5 = { 
{{.*}}"target-features"="+64bit,+m,+save-restore,{{(-[[:alnum:]-]+)(,-[[:alnum:]-]+)*}}"
 }
diff --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 8f50126f1b36285..2361c83a5a6102d 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -88,6 +88,7 @@
 // CHECK-NOT: __riscv_zicclsm {{.*$}}
 // CHECK-NOT: __riscv_ziccrse {{.*$}}
 // CHECK-NOT: __riscv_zicntr {{.*$}}
+// CHECK-NOT: __riscv_zicond {{.*$}}
 // CHECK-NOT: __riscv_zicsr {{.*$}}
 // CHECK-NOT: __riscv_zifencei {{.*$}}
 // CHECK-NOT: __riscv_zihintntl {{.*$}}
@@ -148,7 +149,6 @@
 // CHECK-NOT: __riscv_zfbfmin {{.*$}}
 // CHECK-NOT: __riscv_zicfilp {{.*$}}
 // CHECK-NOT: __riscv_zicfiss {{.*$}}
-// CHECK-NOT: __riscv_zicond {{.*$}}
 // CHECK-NOT: __riscv_zimop {{.*$}}
 // CHECK-NOT: __riscv_ztso {{.*$}}
 // CHECK-NOT: __riscv_zvfbfmin {{.*$}}
@@ -766,6 +766,14 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZICNTR-EXT %s
 // CHECK-ZICNTR-EXT: __riscv_zicntr 200{{$}}
 
+// RUN: %clang --target=riscv32 \
+// RUN:   -march=rv32i_zicond -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-ZICOND-EXT %s
+// RUN: %clang --target=riscv64 \
+// RUN:   -march=rv64i_zicond -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-ZICOND-EXT %s
+// CHECK-ZICOND-EXT: __riscv_zicond  100{{$}}
+
 // RUN: %clang --target=riscv32-unknown-linux-gnu \
 // RUN:   -march=rv32izicsr2p0 -E -dM %s \
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZICSR-EXT %s
@@ -1349,14 +1357,6 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZICFILP-EXT %s
 // CHECK-ZICFILP-EXT: __riscv_zicfilp 4000{{$}}
 
-// RUN: %clang --target=riscv32 -menable-experimental-extensions \
-// RUN:   -march=rv32i_zicond1p0 -E -dM %s \
-// RU

[clang] [llvm] [RISCV] Graduate Zicond to non-experimental (PR #79811)

2024-01-29 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 23b233c8adad5b81e185e50d04356fab64c2f870 
cf5c3432f66b36db0b8283a967b24686433cdf63 -- 
clang/test/CodeGen/RISCV/riscv-func-attr-target.c 
clang/test/Preprocessor/riscv-target-features.c 
llvm/lib/Support/RISCVISAInfo.cpp llvm/unittests/Support/RISCVISAInfoTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/unittests/Support/RISCVISAInfoTest.cpp 
b/llvm/unittests/Support/RISCVISAInfoTest.cpp
index ba040492c0..f03ccecfae 100644
--- a/llvm/unittests/Support/RISCVISAInfoTest.cpp
+++ b/llvm/unittests/Support/RISCVISAInfoTest.cpp
@@ -366,8 +366,7 @@ TEST(ParseArchString, RejectsDuplicateExtensionNames) {
 TEST(ParseArchString,
  RejectsExperimentalExtensionsIfNotEnableExperimentalExtension) {
   EXPECT_EQ(
-  toString(
-  RISCVISAInfo::parseArchString("rv64iztso", false).takeError()),
+  toString(RISCVISAInfo::parseArchString("rv64iztso", false).takeError()),
   "requires '-menable-experimental-extensions' for experimental extension "
   "'ztso'");
 }
@@ -378,8 +377,7 @@ TEST(ParseArchString,
   // updating (and unfortunately, it will still pass). The failure of
   // RejectsExperimentalExtensionsIfNotEnableExperimentalExtension will
   // hopefully serve as a reminder to update.
-  auto MaybeISAInfo =
-  RISCVISAInfo::parseArchString("rv64iztso", true, false);
+  auto MaybeISAInfo = RISCVISAInfo::parseArchString("rv64iztso", true, false);
   ASSERT_THAT_EXPECTED(MaybeISAInfo, Succeeded());
   RISCVISAInfo::OrderedExtensionMap Exts = (*MaybeISAInfo)->getExtensions();
   EXPECT_EQ(Exts.size(), 2UL);
@@ -394,8 +392,7 @@ TEST(ParseArchString,
 TEST(ParseArchString,
  RequiresExplicitVersionNumberForExperimentalExtensionByDefault) {
   EXPECT_EQ(
-  toString(
-  RISCVISAInfo::parseArchString("rv64iztso", true).takeError()),
+  toString(RISCVISAInfo::parseArchString("rv64iztso", true).takeError()),
   "experimental extension requires explicit version number `ztso`");
 }
 
@@ -411,8 +408,7 @@ TEST(ParseArchString,
 
 TEST(ParseArchString, RejectsUnrecognizedVersionForExperimentalExtension) {
   EXPECT_EQ(
-  toString(
-  RISCVISAInfo::parseArchString("rv64iztso9p9", true).takeError()),
+  toString(RISCVISAInfo::parseArchString("rv64iztso9p9", 
true).takeError()),
   "unsupported version number 9.9 for experimental extension 'ztso' "
   "(this compiler supports 0.1)");
 }
@@ -494,8 +490,8 @@ TEST(ToFeatures, 
IIsDroppedAndExperimentalExtensionsArePrefixed) {
   EXPECT_THAT((*MaybeISAInfo1)->toFeatures(),
   ElementsAre("+m", "+experimental-ztso"));
 
-  auto MaybeISAInfo2 = RISCVISAInfo::parseArchString(
-  "rv32e_ztso_xventanacondops", true, false);
+  auto MaybeISAInfo2 =
+  RISCVISAInfo::parseArchString("rv32e_ztso_xventanacondops", true, false);
   ASSERT_THAT_EXPECTED(MaybeISAInfo2, Succeeded());
   EXPECT_THAT((*MaybeISAInfo2)->toFeatures(),
   ElementsAre("+e", "+experimental-ztso", "+xventanacondops"));

``




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


[clang] [llvm] [RISCV] Graduate Zicond to non-experimental (PR #79811)

2024-01-29 Thread Alex Bradbury via cfe-commits

https://github.com/asb updated https://github.com/llvm/llvm-project/pull/79811

>From cf5c3432f66b36db0b8283a967b24686433cdf63 Mon Sep 17 00:00:00 2001
From: Alex Bradbury 
Date: Sun, 28 Jan 2024 08:50:35 +
Subject: [PATCH 1/2] [RISCV] Graduate Zicond to non-experimental

The Zicond extension was ratified in the last few months, with no
changes that affect the LLVM implementation. Although there's surely
more tuning that could be done about when to select Zicond or not, there
are no known correctness issues. Therefore, we should mark support as
non-experimental.
---
 .../CodeGen/RISCV/riscv-func-attr-target.c|  2 +-
 .../test/Preprocessor/riscv-target-features.c | 18 
 llvm/docs/RISCVUsage.rst  |  4 +-
 llvm/docs/ReleaseNotes.rst|  2 +
 llvm/lib/Support/RISCVISAInfo.cpp |  3 +-
 llvm/lib/Target/RISCV/RISCVFeatures.td|  2 +-
 llvm/lib/Target/RISCV/RISCVInstrInfoZicond.td |  2 -
 llvm/test/CodeGen/RISCV/attributes.ll |  4 +-
 llvm/test/CodeGen/RISCV/cmov-branch-opt.ll|  4 +-
 llvm/test/CodeGen/RISCV/condbinops.ll |  4 +-
 llvm/test/CodeGen/RISCV/condops.ll|  4 +-
 .../CodeGen/RISCV/select-binop-identity.ll|  4 +-
 llvm/test/CodeGen/RISCV/select.ll |  4 +-
 .../CodeGen/RISCV/short-forward-branch-opt.ll |  2 +-
 llvm/test/CodeGen/RISCV/xaluo.ll  |  4 +-
 llvm/test/MC/RISCV/rv32zicond-invalid.s   |  4 +-
 llvm/test/MC/RISCV/rv32zicond-valid.s | 12 ++---
 llvm/unittests/Support/RISCVISAInfoTest.cpp   | 46 +--
 18 files changed, 61 insertions(+), 64 deletions(-)

diff --git a/clang/test/CodeGen/RISCV/riscv-func-attr-target.c 
b/clang/test/CodeGen/RISCV/riscv-func-attr-target.c
index 7d3362e84e7588..f216eaf735b4a8 100644
--- a/clang/test/CodeGen/RISCV/riscv-func-attr-target.c
+++ b/clang/test/CodeGen/RISCV/riscv-func-attr-target.c
@@ -39,7 +39,7 @@ __attribute__((target("cpu=sifive-u54"))) void 
testAttrCpuOnly() {}
 // CHECK: attributes #0 = { 
{{.*}}"target-features"="+64bit,+a,+m,+save-restore,+zifencei,-relax,-zbb,-zfa" 
}
 // CHECK: attributes #1 = { {{.*}}"target-cpu"="rocket-rv64" 
"target-features"="+64bit,+a,+d,+f,+m,+save-restore,+v,+zicsr,+zifencei,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-relax,-zbb,-zfa"
 "tune-cpu"="generic-rv64" }
 // CHECK: attributes #2 = { 
{{.*}}"target-features"="+64bit,+a,+m,+save-restore,+zbb,+zifencei,-relax,-zfa" 
}
-// CHECK: attributes #3 = { 
{{.*}}"target-features"="+64bit,+a,+d,+experimental-zicond,+f,+m,+save-restore,+v,+zbb,+zicsr,+zifencei,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-relax,-zfa"
 }
+// CHECK: attributes #3 = { 
{{.*}}"target-features"="+64bit,+a,+d,+f,+m,+save-restore,+v,+zbb,+zicond,+zicsr,+zifencei,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-relax,-zfa"
 }
 // Make sure we append negative features if we override the arch
 // CHECK: attributes #4 = { 
{{.*}}"target-features"="+64bit,+a,+c,+d,+f,+m,+save-restore,+zbb,+zicsr,+zifencei,{{(-[[:alnum:]-]+)(,-[[:alnum:]-]+)*}}"
 }
 // CHECK: attributes #5 = { 
{{.*}}"target-features"="+64bit,+m,+save-restore,{{(-[[:alnum:]-]+)(,-[[:alnum:]-]+)*}}"
 }
diff --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 8f50126f1b3628..2361c83a5a6102 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -88,6 +88,7 @@
 // CHECK-NOT: __riscv_zicclsm {{.*$}}
 // CHECK-NOT: __riscv_ziccrse {{.*$}}
 // CHECK-NOT: __riscv_zicntr {{.*$}}
+// CHECK-NOT: __riscv_zicond {{.*$}}
 // CHECK-NOT: __riscv_zicsr {{.*$}}
 // CHECK-NOT: __riscv_zifencei {{.*$}}
 // CHECK-NOT: __riscv_zihintntl {{.*$}}
@@ -148,7 +149,6 @@
 // CHECK-NOT: __riscv_zfbfmin {{.*$}}
 // CHECK-NOT: __riscv_zicfilp {{.*$}}
 // CHECK-NOT: __riscv_zicfiss {{.*$}}
-// CHECK-NOT: __riscv_zicond {{.*$}}
 // CHECK-NOT: __riscv_zimop {{.*$}}
 // CHECK-NOT: __riscv_ztso {{.*$}}
 // CHECK-NOT: __riscv_zvfbfmin {{.*$}}
@@ -766,6 +766,14 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZICNTR-EXT %s
 // CHECK-ZICNTR-EXT: __riscv_zicntr 200{{$}}
 
+// RUN: %clang --target=riscv32 \
+// RUN:   -march=rv32i_zicond -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-ZICOND-EXT %s
+// RUN: %clang --target=riscv64 \
+// RUN:   -march=rv64i_zicond -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-ZICOND-EXT %s
+// CHECK-ZICOND-EXT: __riscv_zicond  100{{$}}
+
 // RUN: %clang --target=riscv32-unknown-linux-gnu \
 // RUN:   -march=rv32izicsr2p0 -E -dM %s \
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZICSR-EXT %s
@@ -1349,14 +1357,6 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZICFILP-EXT %s
 // CHECK-ZICFILP-EXT: __riscv_zicfilp 4000{{$}}
 
-// RUN: %clang --target=riscv32 -menable-experimental-extensions \
-// RUN:   -march=rv32i_zicond1p0 -E -dM %s \
-// RUN:   -o - | FileCheck --check-

  1   2   3   4   5   6   >