[clang] Implement resource binding type prefix mismatch flag setting logic (PR #97103)

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

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

>From c784272b3f66ca06be4ab8e72a0963e5ebb6a869 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Fri, 28 Jun 2024 12:40:56 -0700
Subject: [PATCH 01/13] update tests, update code

---
 clang/include/clang/Basic/Attr.td |   2 +-
 .../clang/Basic/DiagnosticSemaKinds.td|   5 +-
 clang/include/clang/Sema/SemaHLSL.h   |   2 +
 clang/lib/Sema/HLSLExternalSemaSource.cpp |  26 +-
 clang/lib/Sema/SemaHLSL.cpp   | 232 +-
 .../ast-dump-comment-cbuffe-tbufferr.hlsl |   2 +
 clang/test/AST/HLSL/cbuffer_tbuffer.hlsl  |   6 +-
 clang/test/AST/HLSL/packoffset.hlsl   |   1 +
 clang/test/AST/HLSL/pch_hlsl_buffer.hlsl  |   2 +
 .../test/AST/HLSL/resource_binding_attr.hlsl  |   6 +-
 .../SemaHLSL/resource_binding_attr_error.hlsl |  21 +-
 .../resource_binding_attr_error_mismatch.hlsl |  74 ++
 12 files changed, 346 insertions(+), 33 deletions(-)
 create mode 100644 
clang/test/SemaHLSL/resource_binding_attr_error_mismatch.hlsl

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 452cd1810f653..c3d67e19656da 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4467,7 +4467,7 @@ def HLSLSV_GroupIndex: HLSLAnnotationAttr {
 
 def HLSLResourceBinding: InheritableAttr {
   let Spellings = [HLSLAnnotation<"register">];
-  let Subjects = SubjectList<[HLSLBufferObj, ExternalGlobalVar]>;
+  let Subjects = SubjectList<[HLSLBufferObj, ExternalGlobalVar], ErrorDiag>;
   let LangOpts = [HLSL];
   let Args = [StringArgument<"Slot">, StringArgument<"Space", 1>];
   let Documentation = [HLSLResourceBindingDocs];
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 96f0c0f0205c2..3bf15ff5f2657 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12303,7 +12303,10 @@ def err_hlsl_missing_semantic_annotation : Error<
 def err_hlsl_init_priority_unsupported : Error<
   "initializer priorities are not supported in HLSL">;
 
-def err_hlsl_unsupported_register_type : Error<"invalid resource class 
specifier '%0' used; expected 'b', 's', 't', or 'u'">;
+def err_hlsl_mismatching_register_resource_type_and_name: Error<"invalid 
register name prefix '%0' for register resource type '%1' (expected 
%select{'t'|'u'|'b'|'s'}2)">;
+def err_hlsl_mismatching_register_builtin_type_and_name: Error<"invalid 
register name prefix '%0' for '%1' (expected %2)">;
+def err_hlsl_unsupported_register_prefix : Error<"invalid resource class 
specifier '%0' used; expected 't', 'u', 'b', or 's'">;
+def err_hlsl_unsupported_register_resource_type : Error<"invalid resource '%0' 
used">;
 def err_hlsl_unsupported_register_number : Error<"register number should be an 
integer">;
 def err_hlsl_expected_space : Error<"invalid space specifier '%0' used; 
expected 'space' followed by an integer, like space1">;
 def warn_hlsl_packoffset_mix : Warning<"cannot mix packoffset elements with 
nonpackoffset elements in a cbuffer">,
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index 4d6958a1be3e5..d3d36d04d1019 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -22,6 +22,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Sema/Scope.h"
 #include "clang/Sema/SemaBase.h"
+#include "clang/Sema/Sema.h"
 #include 
 
 namespace clang {
@@ -31,6 +32,7 @@ class SemaHLSL : public SemaBase {
 public:
   SemaHLSL(Sema &S);
 
+  HLSLResourceAttr *mergeHLSLResourceAttr(bool CBuffer);
   Decl *ActOnStartBuffer(Scope *BufferScope, bool CBuffer, SourceLocation 
KwLoc,
  IdentifierInfo *Ident, SourceLocation IdentLoc,
  SourceLocation LBrace);
diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp 
b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index a2b29a7bdf505..b82cd8373403a 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -490,23 +490,24 @@ void HLSLExternalSemaSource::defineTrivialHLSLTypes() {
 }
 
 /// Set up common members and attributes for buffer types
-static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S,
-  ResourceClass RC, ResourceKind 
RK,
-  bool IsROV) {
+static BuiltinTypeDeclBuilder setupBufferHandle(CXXRecordDecl *Decl, Sema &S,
+ResourceClass RC) {
   return BuiltinTypeDeclBuilder(Decl)
   .addHandleMember()
-  .addDefaultHandleConstructor(S, RC)
-  .annotateResourceClass(RC, RK, IsROV);
+  .addDefaultHandleConstructor(S, RC);
 }
 
 void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
   CXXRecordDecl *Decl;
-  Decl = 

[clang-tools-extra] Add checks to convert std library iterator algorithms into c++20 or boost ranges (PR #97764)

2024-07-07 Thread Nathan James via cfe-commits

https://github.com/njames93 updated 
https://github.com/llvm/llvm-project/pull/97764

>From 065d343d5ab1706475fe5a1bc3a43e5368d1142b Mon Sep 17 00:00:00 2001
From: Nathan James 
Date: Tue, 2 Jul 2024 14:25:44 +0100
Subject: [PATCH 1/2] Add a modernize-use-ranges check

---
 .../clang-tidy/modernize/CMakeLists.txt   |   1 +
 .../modernize/ModernizeTidyModule.cpp |   2 +
 .../clang-tidy/modernize/UseRangesCheck.cpp   | 204 ++
 .../clang-tidy/modernize/UseRangesCheck.h |  33 +++
 .../clang-tidy/utils/CMakeLists.txt   |   1 +
 .../clang-tidy/utils/UseRangesCheck.cpp   | 263 ++
 .../clang-tidy/utils/UseRangesCheck.h |  84 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |   6 +
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../checks/modernize/use-ranges.rst   |  61 
 .../checkers/modernize/use-ranges.cpp | 191 +
 11 files changed, 847 insertions(+)
 create mode 100644 clang-tools-extra/clang-tidy/modernize/UseRangesCheck.cpp
 create mode 100644 clang-tools-extra/clang-tidy/modernize/UseRangesCheck.h
 create mode 100644 clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
 create mode 100644 clang-tools-extra/clang-tidy/utils/UseRangesCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-ranges.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp

diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 576805c4c7f18..4f68c487cac9d 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -40,6 +40,7 @@ add_clang_library(clangTidyModernizeModule
   UseNoexceptCheck.cpp
   UseNullptrCheck.cpp
   UseOverrideCheck.cpp
+  UseRangesCheck.cpp
   UseStartsEndsWithCheck.cpp
   UseStdFormatCheck.cpp
   UseStdNumbersCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index b9c7a2dc383e8..1860759332063 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -41,6 +41,7 @@
 #include "UseNoexceptCheck.h"
 #include "UseNullptrCheck.h"
 #include "UseOverrideCheck.h"
+#include "UseRangesCheck.h"
 #include "UseStartsEndsWithCheck.h"
 #include "UseStdFormatCheck.h"
 #include "UseStdNumbersCheck.h"
@@ -75,6 +76,7 @@ class ModernizeModule : public ClangTidyModule {
 CheckFactories.registerCheck("modernize-pass-by-value");
 CheckFactories.registerCheck(
 "modernize-use-designated-initializers");
+CheckFactories.registerCheck("modernize-use-ranges");
 CheckFactories.registerCheck(
 "modernize-use-starts-ends-with");
 
CheckFactories.registerCheck("modernize-use-std-format");
diff --git a/clang-tools-extra/clang-tidy/modernize/UseRangesCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseRangesCheck.cpp
new file mode 100644
index 0..f4fe6d04e239d
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UseRangesCheck.cpp
@@ -0,0 +1,204 @@
+//===--- UseRangesCheck.cpp - clang-tidy 
--===//
+//
+// 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 "UseRangesCheck.h"
+#include "clang/AST/Decl.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include 
+
+// FixItHint - Let the docs script know that this class does provide fixits
+
+namespace clang::tidy::modernize {
+
+static constexpr const char *SingleRangeNames[] = {
+"all_of",
+"any_of",
+"none_of",
+"for_each",
+"find",
+"find_if",
+"find_if_not",
+"adjacent_find",
+"copy",
+"copy_if",
+"copy_backward",
+"move",
+"move_backward",
+"fill",
+"transform",
+"replace",
+"replace_if",
+"generate",
+"remove",
+"remove_if",
+"remove_copy",
+"remove_copy_if",
+"unique",
+"unique_copy",
+"sample",
+"partition_point",
+"lower_bound",
+"upper_bound",
+"equal_range",
+"binary_search",
+"push_heap",
+"pop_heap",
+"make_heap",
+"sort_heap",
+"next_permutation",
+"prev_permutation",
+};
+
+static constexpr const char *SingleRangeWithExecNames[] = {
+"reverse",
+"reverse_copy",
+"shift_left",
+"shift_right",
+"is_partitioned",
+"partition",
+"partition_copy",
+"stable_partition",
+"sort",
+"stable_sort",
+"is_sorted",
+"is_sorted_until",
+"is_heap",
+"is_heap_until",
+   

[clang-tools-extra] Add checks to convert std library iterator algorithms into c++20 or boost ranges (PR #97764)

2024-07-07 Thread Nathan James via cfe-commits

https://github.com/njames93 updated 
https://github.com/llvm/llvm-project/pull/97764

>From 56d452478fb2b002898e6b3dfc5e251b42894ca3 Mon Sep 17 00:00:00 2001
From: Nathan James 
Date: Tue, 2 Jul 2024 14:25:44 +0100
Subject: [PATCH 1/2] Add a modernize-use-ranges check

---
 .../clang-tidy/modernize/CMakeLists.txt   |   1 +
 .../modernize/ModernizeTidyModule.cpp |   2 +
 .../clang-tidy/modernize/UseRangesCheck.cpp   | 204 ++
 .../clang-tidy/modernize/UseRangesCheck.h |  33 +++
 .../clang-tidy/utils/CMakeLists.txt   |   1 +
 .../clang-tidy/utils/UseRangesCheck.cpp   | 260 ++
 .../clang-tidy/utils/UseRangesCheck.h |  84 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |   6 +
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../checks/modernize/use-ranges.rst   |  61 
 .../checkers/modernize/use-ranges.cpp | 191 +
 11 files changed, 844 insertions(+)
 create mode 100644 clang-tools-extra/clang-tidy/modernize/UseRangesCheck.cpp
 create mode 100644 clang-tools-extra/clang-tidy/modernize/UseRangesCheck.h
 create mode 100644 clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
 create mode 100644 clang-tools-extra/clang-tidy/utils/UseRangesCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-ranges.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp

diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 576805c4c7f181..4f68c487cac9d4 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -40,6 +40,7 @@ add_clang_library(clangTidyModernizeModule
   UseNoexceptCheck.cpp
   UseNullptrCheck.cpp
   UseOverrideCheck.cpp
+  UseRangesCheck.cpp
   UseStartsEndsWithCheck.cpp
   UseStdFormatCheck.cpp
   UseStdNumbersCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index b9c7a2dc383e88..18607593320635 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -41,6 +41,7 @@
 #include "UseNoexceptCheck.h"
 #include "UseNullptrCheck.h"
 #include "UseOverrideCheck.h"
+#include "UseRangesCheck.h"
 #include "UseStartsEndsWithCheck.h"
 #include "UseStdFormatCheck.h"
 #include "UseStdNumbersCheck.h"
@@ -75,6 +76,7 @@ class ModernizeModule : public ClangTidyModule {
 CheckFactories.registerCheck("modernize-pass-by-value");
 CheckFactories.registerCheck(
 "modernize-use-designated-initializers");
+CheckFactories.registerCheck("modernize-use-ranges");
 CheckFactories.registerCheck(
 "modernize-use-starts-ends-with");
 
CheckFactories.registerCheck("modernize-use-std-format");
diff --git a/clang-tools-extra/clang-tidy/modernize/UseRangesCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseRangesCheck.cpp
new file mode 100644
index 00..f4fe6d04e239dd
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UseRangesCheck.cpp
@@ -0,0 +1,204 @@
+//===--- UseRangesCheck.cpp - clang-tidy 
--===//
+//
+// 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 "UseRangesCheck.h"
+#include "clang/AST/Decl.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include 
+
+// FixItHint - Let the docs script know that this class does provide fixits
+
+namespace clang::tidy::modernize {
+
+static constexpr const char *SingleRangeNames[] = {
+"all_of",
+"any_of",
+"none_of",
+"for_each",
+"find",
+"find_if",
+"find_if_not",
+"adjacent_find",
+"copy",
+"copy_if",
+"copy_backward",
+"move",
+"move_backward",
+"fill",
+"transform",
+"replace",
+"replace_if",
+"generate",
+"remove",
+"remove_if",
+"remove_copy",
+"remove_copy_if",
+"unique",
+"unique_copy",
+"sample",
+"partition_point",
+"lower_bound",
+"upper_bound",
+"equal_range",
+"binary_search",
+"push_heap",
+"pop_heap",
+"make_heap",
+"sort_heap",
+"next_permutation",
+"prev_permutation",
+};
+
+static constexpr const char *SingleRangeWithExecNames[] = {
+"reverse",
+"reverse_copy",
+"shift_left",
+"shift_right",
+"is_partitioned",
+"partition",
+"partition_copy",
+"stable_partition",
+"sort",
+"stable_sort",
+"is_sorted",
+"is_sorted_until",
+"is_heap",
+"is_heap_until"

[clang] [Clang][Sema] Add a test for move ctor calling for a base class. NFC (PR #97164)

2024-07-07 Thread Pavel Samolysov via cfe-commits

https://github.com/samolisov updated 
https://github.com/llvm/llvm-project/pull/97164

>From edf0d10b41099068ef49a2d2fe0ce60356d2f2fd Mon Sep 17 00:00:00 2001
From: Pavel Samolysov 
Date: Sat, 29 Jun 2024 15:18:11 +0300
Subject: [PATCH 1/2] [Clang][Sema] Add a test for move ctor calling for a base
 class. NFC

When clang compiles the following expression:

```c++
  return A{B{"Move Ctor"}};
```
(where `B` is a base class for `A`), it adds a call to the move
constructor of `B`. When the code is changed to...

```c++
  return A{{"No Move Ctor"}};
```
... a move constructor is invoked neither for `A` nor for `B`.

The lit test demonstrates the difference in the generated AST.

Issue: #92495
---
 .../AST/explicit-base-class-move-cntr.cpp | 43 +++
 1 file changed, 43 insertions(+)
 create mode 100644 clang/test/AST/explicit-base-class-move-cntr.cpp

diff --git a/clang/test/AST/explicit-base-class-move-cntr.cpp 
b/clang/test/AST/explicit-base-class-move-cntr.cpp
new file mode 100644
index 00..b9b591ebc79d7e
--- /dev/null
+++ b/clang/test/AST/explicit-base-class-move-cntr.cpp
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -ast-dump -fblocks %s | FileCheck -strict-whitespace %s
+
+struct ExplicitBase {
+  explicit ExplicitBase(const char *) { }
+  ExplicitBase(const ExplicitBase &) {}
+  ExplicitBase(ExplicitBase &&) {}
+  ExplicitBase &operator=(const ExplicitBase &) { return *this; }
+  ExplicitBase &operator=(ExplicitBase &&) { return *this; }
+  ~ExplicitBase() { }
+};
+
+struct Derived1 : ExplicitBase {};
+
+Derived1 makeDerived1() {
+  // CHECK:  FunctionDecl 0x{{[^ ]*}}  line:[[@LINE-1]]:10 makeDerived1 'Derived1 ()'
+  // CHECK-NEXT: CompoundStmt 0x{{[^ ]*}} 
+  // CHECK-DAG:  MaterializeTemporaryExpr 0x{{[^ ]*}}  'ExplicitBase' xvalue
+  // CHECK-NEXT: CXXBindTemporaryExpr 0x[[TEMP:[^ ]*]]  'ExplicitBase' (CXXTemporary 0x[[TEMP]])
+  // CHECK-NEXT: CXXTemporaryObjectExpr 0x{{[^ ]*}}  'ExplicitBase' 'void (const char *)' list
+  // CHECK-NEXT: ImplicitCastExpr 0x{{[^ ]*}}  'const char *' 

+  // CHECK-NEXT: StringLiteral 0x{{[^ ]*}}  'const char[10]' 
lvalue "Move Ctor"
+  return Derived1{ExplicitBase{"Move Ctor"}};
+}
+
+struct ImplicitBase {
+  ImplicitBase(const char *) { }
+  ImplicitBase(const ImplicitBase &) {}
+  ImplicitBase(ImplicitBase &&) {}
+  ImplicitBase &operator=(const ImplicitBase &) { return *this; }
+  ImplicitBase &operator=(ImplicitBase &&) { return *this; }
+  ~ImplicitBase() { }
+};
+
+struct Derived2 : ImplicitBase {};
+
+Derived2 makeDerived2() {
+  // CHECK:  FunctionDecl 0x{{[^ ]*}}  line:[[@LINE-1]]:10 makeDerived2 'Derived2 ()'
+  // CHECK-NEXT: CompoundStmt 0x{{[^ ]*}} 
+  // CHECK-NOT:  MaterializeTemporaryExpr 0x{{[^ ]*}}  'ImplicitBase' xvalue
+  return Derived2{{"No Ctor"}};
+}

>From a29869ad88f546563404f7f1d60ca9ca2c3a255b Mon Sep 17 00:00:00 2001
From: Pavel Samolysov 
Date: Sun, 7 Jul 2024 13:29:06 +0300
Subject: [PATCH 2/2] Regenerate the test using the
 llvm-project/clang/test/AST/gen_ast_dump_json_test.py tool

---
 .../AST/explicit-base-class-move-cntr.cpp | 154 --
 1 file changed, 141 insertions(+), 13 deletions(-)

diff --git a/clang/test/AST/explicit-base-class-move-cntr.cpp 
b/clang/test/AST/explicit-base-class-move-cntr.cpp
index b9b591ebc79d7e..808af2fc94336f 100644
--- a/clang/test/AST/explicit-base-class-move-cntr.cpp
+++ b/clang/test/AST/explicit-base-class-move-cntr.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -ast-dump -fblocks %s | FileCheck -strict-whitespace %s
+// RUN: %clang_cc1 -ast-dump=json %s | FileCheck -strict-whitespace %s
 
 struct ExplicitBase {
   explicit ExplicitBase(const char *) { }
@@ -12,14 +12,85 @@ struct ExplicitBase {
 struct Derived1 : ExplicitBase {};
 
 Derived1 makeDerived1() {
-  // CHECK:  FunctionDecl 0x{{[^ ]*}}  line:[[@LINE-1]]:10 makeDerived1 'Derived1 ()'
-  // CHECK-NEXT: CompoundStmt 0x{{[^ ]*}} 
-  // CHECK-DAG:  MaterializeTemporaryExpr 0x{{[^ ]*}}  'ExplicitBase' xvalue
-  // CHECK-NEXT: CXXBindTemporaryExpr 0x[[TEMP:[^ ]*]]  'ExplicitBase' (CXXTemporary 0x[[TEMP]])
-  // CHECK-NEXT: CXXTemporaryObjectExpr 0x{{[^ ]*}}  'ExplicitBase' 'void (const char *)' list
-  // CHECK-NEXT: ImplicitCastExpr 0x{{[^ ]*}}  'const char *' 

-  // CHECK-NEXT: StringLiteral 0x{{[^ ]*}}  'const char[10]' 
lvalue "Move Ctor"
+// CHECK:  "kind": "FunctionDecl",
+// CHECK:  "name": "makeDerived1",
+
+// CHECK:"kind": "CompoundStmt",
+
+// CHECK:  "kind": "ReturnStmt",
+// CHECK:"kind": "ExprWithCleanups",
+// CHECK:"type": {
+// CHECK-NEXT: "qualType": "Derived1"
+// CHECK-NEXT:   },
+
+// CHECK:  "kind": "CXXFunctionalCastExpr",
+// CHECK:  "type": {
+// CHECK-NEXT:   "qualType": "Derived1"
+// CHECK-NEXT: },
+// CHECK-NEXT: "valueCategory": "prvalue",
+// CHECK-NEXT: "castKind": "NoOp",
+
+// CHECK:"kind": "CXXBindTemporaryExpr",
+// CHECK:"type": {
+// CHECK-NEXT: "qualType": "Derived1"
+// CH

[clang] [Clang][Sema] Add a test for move ctor calling for a base class. NFC (PR #97164)

2024-07-07 Thread Pavel Samolysov via cfe-commits


@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -ast-dump -fblocks %s | FileCheck -strict-whitespace %s

samolisov wrote:

@vitalybuka Thank you for the suggestion. I've regenerated the test using the 
tool and cut the dump to make it a bit shorter.

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


[clang-tools-extra] Add checks to convert std library iterator algorithms into c++20 or boost ranges (PR #97764)

2024-07-07 Thread via cfe-commits


@@ -131,6 +131,12 @@ Improvements to clang-tidy
 New checks
 ^^
 
+- New :doc:`boost-use-ranges
+  ` check.
+
+  Detects calls to standard library iterator algorithms that could be replaced
+  with a boost ranges version instead

EugeneZelenko wrote:

```suggestion
  with a Boost ranges version instead.
```

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


[clang-tools-extra] Add checks to convert std library iterator algorithms into c++20 or boost ranges (PR #97764)

2024-07-07 Thread via cfe-commits


@@ -169,6 +175,12 @@ New checks
   Finds initializer lists for aggregate types that could be
   written as designated initializers instead.
 
+- New :doc:`modernize-use-ranges
+  ` check.
+
+  Detects calls to standard library iterator algorithms that could be replaced
+  with a ranges version instead

EugeneZelenko wrote:

```suggestion
  with a ranges version instead.
```

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


[clang-tools-extra] Add checks to convert std library iterator algorithms into c++20 or boost ranges (PR #97764)

2024-07-07 Thread via cfe-commits


@@ -0,0 +1,54 @@
+.. title:: clang-tidy - boost-use-ranges
+
+boost-use-ranges
+
+
+Detects calls to standard library iterator algorithms that could be replaced
+with a boost ranges version instead.
+
+Example
+---
+
+.. code-block:: c++
+
+  auto Iter1 = std::find(Items.begin(), Items.end(), 0);
+  auto AreSame = std::equal(Items1.cbegin(), Items1.cend(), std::begin(Items2),
+std::end(Items2));
+
+
+transforms to:
+
+.. code-block:: c++
+
+  auto Iter1 = boost::range::find(Items, 0);
+  auto AreSame = boost::range::equal(Items1, Items2);
+
+Calls to the following std library algorithms are checked:
+``includes``,``set_union``,``set_intersection``,``set_difference``,
+``set_symmetric_difference``,``unique``,``lower_bound``,``stable_sort``,
+``equal_range``,``remove_if``,``sort``,``random_shuffle``,``remove_copy``,
+``stable_partition``,``remove_copy_if``,``count``,``copy_backward``,
+``reverse_copy``,``adjacent_find``,``remove``,``upper_bound``,``binary_search``,
+``replace_copy_if``,``for_each``,``generate``,``count_if``,``min_element``,
+``reverse``,``replace_copy``,``fill``,``unique_copy``,``transform``,``copy``,
+``replace``,``find``,``replace_if``,``find_if``,``partition``,``max_element``,
+``find_end``,``merge``,``partial_sort_copy``,``find_first_of``,``search``,
+``lexicographical_compare``,``equal``,``mismatch``,``next_permutation``,
+``prev_permutation``,``push_heap``,``pop_heap``,``make_heap``,``sort_heap``,
+``copy_if``,``is_permutation``,``is_partitioned``,``find_if_not``,
+``partition_copy``,``any_of``,``iota``,``all_of``,``partition_point``,
+``is_sorted``,``none_of``,``is_sorted_until``,``reduce``.
+
+Options
+---
+
+.. option:: IncludeStyle
+
+   A string specifying which include-style is used, `llvm` or `google`. Default
+   is `llvm`.
+
+.. option:: IncludeBoostSystem
+   
+   If `true` the boost headers are included as system headers with angle
+   brackets (`#include `), otherwise quotes are used
+   (`#include "boost.hpp"`).

EugeneZelenko wrote:

Missing default value.

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


[clang-tools-extra] Add checks to convert std library iterator algorithms into c++20 or boost ranges (PR #97764)

2024-07-07 Thread via cfe-commits


@@ -0,0 +1,54 @@
+.. title:: clang-tidy - boost-use-ranges
+
+boost-use-ranges
+
+
+Detects calls to standard library iterator algorithms that could be replaced
+with a boost ranges version instead.

EugeneZelenko wrote:

```suggestion
with a Boost ranges version instead.
```

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


[clang] [clang-format][NFC] Annotate function decl l_paren (PR #97938)

2024-07-07 Thread Björn Schäpers via cfe-commits

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


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


[clang-tools-extra] Add checks to convert std library iterator algorithms into c++20 or boost ranges (PR #97764)

2024-07-07 Thread Nathan James via cfe-commits

https://github.com/njames93 updated 
https://github.com/llvm/llvm-project/pull/97764

>From ecde6109c040741f6425d3c42464ffaa02f237f9 Mon Sep 17 00:00:00 2001
From: Nathan James 
Date: Tue, 2 Jul 2024 14:25:44 +0100
Subject: [PATCH 1/2] Add a modernize-use-ranges check

---
 .../clang-tidy/modernize/CMakeLists.txt   |   1 +
 .../modernize/ModernizeTidyModule.cpp |   2 +
 .../clang-tidy/modernize/UseRangesCheck.cpp   | 185 +++
 .../clang-tidy/modernize/UseRangesCheck.h |  39 +++
 .../clang-tidy/utils/CMakeLists.txt   |   1 +
 .../clang-tidy/utils/UseRangesCheck.cpp   | 306 ++
 .../clang-tidy/utils/UseRangesCheck.h |  95 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |   6 +
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../checks/modernize/use-ranges.rst   |  79 +
 .../checkers/modernize/use-ranges.cpp | 208 
 11 files changed, 923 insertions(+)
 create mode 100644 clang-tools-extra/clang-tidy/modernize/UseRangesCheck.cpp
 create mode 100644 clang-tools-extra/clang-tidy/modernize/UseRangesCheck.h
 create mode 100644 clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
 create mode 100644 clang-tools-extra/clang-tidy/utils/UseRangesCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-ranges.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp

diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 576805c4c7f18..4f68c487cac9d 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -40,6 +40,7 @@ add_clang_library(clangTidyModernizeModule
   UseNoexceptCheck.cpp
   UseNullptrCheck.cpp
   UseOverrideCheck.cpp
+  UseRangesCheck.cpp
   UseStartsEndsWithCheck.cpp
   UseStdFormatCheck.cpp
   UseStdNumbersCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index b9c7a2dc383e8..1860759332063 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -41,6 +41,7 @@
 #include "UseNoexceptCheck.h"
 #include "UseNullptrCheck.h"
 #include "UseOverrideCheck.h"
+#include "UseRangesCheck.h"
 #include "UseStartsEndsWithCheck.h"
 #include "UseStdFormatCheck.h"
 #include "UseStdNumbersCheck.h"
@@ -75,6 +76,7 @@ class ModernizeModule : public ClangTidyModule {
 CheckFactories.registerCheck("modernize-pass-by-value");
 CheckFactories.registerCheck(
 "modernize-use-designated-initializers");
+CheckFactories.registerCheck("modernize-use-ranges");
 CheckFactories.registerCheck(
 "modernize-use-starts-ends-with");
 
CheckFactories.registerCheck("modernize-use-std-format");
diff --git a/clang-tools-extra/clang-tidy/modernize/UseRangesCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseRangesCheck.cpp
new file mode 100644
index 0..5c7b315f43173
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UseRangesCheck.cpp
@@ -0,0 +1,185 @@
+//===--- UseRangesCheck.cpp - clang-tidy 
--===//
+//
+// 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 "UseRangesCheck.h"
+#include "clang/AST/Decl.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include 
+
+// FixItHint - Let the docs script know that this class does provide fixits
+
+namespace clang::tidy::modernize {
+
+static constexpr const char *SingleRangeNames[] = {
+"all_of",
+"any_of",
+"none_of",
+"for_each",
+"find",
+"find_if",
+"find_if_not",
+"adjacent_find",
+"copy",
+"copy_if",
+"copy_backward",
+"move",
+"move_backward",
+"fill",
+"transform",
+"replace",
+"replace_if",
+"generate",
+"remove",
+"remove_if",
+"remove_copy",
+"remove_copy_if",
+"unique",
+"unique_copy",
+"sample",
+"partition_point",
+"lower_bound",
+"upper_bound",
+"equal_range",
+"binary_search",
+"push_heap",
+"pop_heap",
+"make_heap",
+"sort_heap",
+"next_permutation",
+"prev_permutation",
+"reverse",
+"reverse_copy",
+"shift_left",
+"shift_right",
+"is_partitioned",
+"partition",
+"partition_copy",
+"stable_partition",
+"sort",
+"stable_sort",
+"is_sorted",
+"is_sorted_until",
+"is_heap",
+"is_heap_until",
+"max_element",
+"min_element",
+"minmax_element",
+"unini

[clang-tools-extra] Add checks to convert std library iterator algorithms into c++20 or boost ranges (PR #97764)

2024-07-07 Thread Nathan James via cfe-commits

njames93 wrote:

- Added some more functions for boost/range/numeric
- Added support for Reverse range iteration 

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


[clang-tools-extra] [clang-tidy] Only expand macros in modernize-use-std-format/print (PR #97911)

2024-07-07 Thread via cfe-commits


@@ -208,11 +208,22 @@ FormatStringConverter::FormatStringConverter(ASTContext 
*ContextIn,
   assert(ArgsOffset <= NumArgs);
   FormatExpr = llvm::dyn_cast(
   Args[FormatArgOffset]->IgnoreImplicitAsWritten());
+
   if (!FormatExpr || !FormatExpr->isOrdinary()) {
 // Function must have a narrow string literal as its first argument.
 conversionNotPossible("first argument is not a narrow string literal");
 return;
   }
+
+  if (const auto MaybeMacroName =

EugeneZelenko wrote:

Please do not use `auto` unless type is explicitly stated in same statement or 
iterator.

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


[clang-tools-extra] Add checks to convert std library iterator algorithms into c++20 or boost ranges (PR #97764)

2024-07-07 Thread Nathan James via cfe-commits

https://github.com/njames93 updated 
https://github.com/llvm/llvm-project/pull/97764

>From 7bb1c44fb23a1ec0c90c5ce694cbd7d2245a00a6 Mon Sep 17 00:00:00 2001
From: Nathan James 
Date: Tue, 2 Jul 2024 14:25:44 +0100
Subject: [PATCH 1/2] Add a modernize-use-ranges check

---
 .../clang-tidy/modernize/CMakeLists.txt   |   1 +
 .../modernize/ModernizeTidyModule.cpp |   2 +
 .../clang-tidy/modernize/UseRangesCheck.cpp   | 185 +++
 .../clang-tidy/modernize/UseRangesCheck.h |  39 +++
 .../clang-tidy/utils/CMakeLists.txt   |   1 +
 .../clang-tidy/utils/UseRangesCheck.cpp   | 306 ++
 .../clang-tidy/utils/UseRangesCheck.h |  95 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |   6 +
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../checks/modernize/use-ranges.rst   |  79 +
 .../checkers/modernize/use-ranges.cpp | 208 
 11 files changed, 923 insertions(+)
 create mode 100644 clang-tools-extra/clang-tidy/modernize/UseRangesCheck.cpp
 create mode 100644 clang-tools-extra/clang-tidy/modernize/UseRangesCheck.h
 create mode 100644 clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
 create mode 100644 clang-tools-extra/clang-tidy/utils/UseRangesCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-ranges.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp

diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 576805c4c7f18..4f68c487cac9d 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -40,6 +40,7 @@ add_clang_library(clangTidyModernizeModule
   UseNoexceptCheck.cpp
   UseNullptrCheck.cpp
   UseOverrideCheck.cpp
+  UseRangesCheck.cpp
   UseStartsEndsWithCheck.cpp
   UseStdFormatCheck.cpp
   UseStdNumbersCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index b9c7a2dc383e8..1860759332063 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -41,6 +41,7 @@
 #include "UseNoexceptCheck.h"
 #include "UseNullptrCheck.h"
 #include "UseOverrideCheck.h"
+#include "UseRangesCheck.h"
 #include "UseStartsEndsWithCheck.h"
 #include "UseStdFormatCheck.h"
 #include "UseStdNumbersCheck.h"
@@ -75,6 +76,7 @@ class ModernizeModule : public ClangTidyModule {
 CheckFactories.registerCheck("modernize-pass-by-value");
 CheckFactories.registerCheck(
 "modernize-use-designated-initializers");
+CheckFactories.registerCheck("modernize-use-ranges");
 CheckFactories.registerCheck(
 "modernize-use-starts-ends-with");
 
CheckFactories.registerCheck("modernize-use-std-format");
diff --git a/clang-tools-extra/clang-tidy/modernize/UseRangesCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseRangesCheck.cpp
new file mode 100644
index 0..5c7b315f43173
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UseRangesCheck.cpp
@@ -0,0 +1,185 @@
+//===--- UseRangesCheck.cpp - clang-tidy 
--===//
+//
+// 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 "UseRangesCheck.h"
+#include "clang/AST/Decl.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include 
+
+// FixItHint - Let the docs script know that this class does provide fixits
+
+namespace clang::tidy::modernize {
+
+static constexpr const char *SingleRangeNames[] = {
+"all_of",
+"any_of",
+"none_of",
+"for_each",
+"find",
+"find_if",
+"find_if_not",
+"adjacent_find",
+"copy",
+"copy_if",
+"copy_backward",
+"move",
+"move_backward",
+"fill",
+"transform",
+"replace",
+"replace_if",
+"generate",
+"remove",
+"remove_if",
+"remove_copy",
+"remove_copy_if",
+"unique",
+"unique_copy",
+"sample",
+"partition_point",
+"lower_bound",
+"upper_bound",
+"equal_range",
+"binary_search",
+"push_heap",
+"pop_heap",
+"make_heap",
+"sort_heap",
+"next_permutation",
+"prev_permutation",
+"reverse",
+"reverse_copy",
+"shift_left",
+"shift_right",
+"is_partitioned",
+"partition",
+"partition_copy",
+"stable_partition",
+"sort",
+"stable_sort",
+"is_sorted",
+"is_sorted_until",
+"is_heap",
+"is_heap_until",
+"max_element",
+"min_element",
+"minmax_element",
+"unini

[clang-tools-extra] Add checks to convert std library iterator algorithms into c++20 or boost ranges (PR #97764)

2024-07-07 Thread Nathan James via cfe-commits

https://github.com/njames93 updated 
https://github.com/llvm/llvm-project/pull/97764

>From 4bb4d8258c7d68864b4c01c8f982fa1339e5006b Mon Sep 17 00:00:00 2001
From: Nathan James 
Date: Tue, 2 Jul 2024 14:25:44 +0100
Subject: [PATCH 1/2] Add a modernize-use-ranges check

---
 .../clang-tidy/modernize/CMakeLists.txt   |   1 +
 .../modernize/ModernizeTidyModule.cpp |   2 +
 .../clang-tidy/modernize/UseRangesCheck.cpp   | 185 +++
 .../clang-tidy/modernize/UseRangesCheck.h |  38 +++
 .../clang-tidy/utils/CMakeLists.txt   |   1 +
 .../clang-tidy/utils/UseRangesCheck.cpp   | 306 ++
 .../clang-tidy/utils/UseRangesCheck.h |  94 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |   6 +
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../checks/modernize/use-ranges.rst   |  79 +
 .../checkers/modernize/use-ranges.cpp | 208 
 11 files changed, 921 insertions(+)
 create mode 100644 clang-tools-extra/clang-tidy/modernize/UseRangesCheck.cpp
 create mode 100644 clang-tools-extra/clang-tidy/modernize/UseRangesCheck.h
 create mode 100644 clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
 create mode 100644 clang-tools-extra/clang-tidy/utils/UseRangesCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-ranges.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp

diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 576805c4c7f18..4f68c487cac9d 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -40,6 +40,7 @@ add_clang_library(clangTidyModernizeModule
   UseNoexceptCheck.cpp
   UseNullptrCheck.cpp
   UseOverrideCheck.cpp
+  UseRangesCheck.cpp
   UseStartsEndsWithCheck.cpp
   UseStdFormatCheck.cpp
   UseStdNumbersCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index b9c7a2dc383e8..1860759332063 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -41,6 +41,7 @@
 #include "UseNoexceptCheck.h"
 #include "UseNullptrCheck.h"
 #include "UseOverrideCheck.h"
+#include "UseRangesCheck.h"
 #include "UseStartsEndsWithCheck.h"
 #include "UseStdFormatCheck.h"
 #include "UseStdNumbersCheck.h"
@@ -75,6 +76,7 @@ class ModernizeModule : public ClangTidyModule {
 CheckFactories.registerCheck("modernize-pass-by-value");
 CheckFactories.registerCheck(
 "modernize-use-designated-initializers");
+CheckFactories.registerCheck("modernize-use-ranges");
 CheckFactories.registerCheck(
 "modernize-use-starts-ends-with");
 
CheckFactories.registerCheck("modernize-use-std-format");
diff --git a/clang-tools-extra/clang-tidy/modernize/UseRangesCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseRangesCheck.cpp
new file mode 100644
index 0..5c7b315f43173
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UseRangesCheck.cpp
@@ -0,0 +1,185 @@
+//===--- UseRangesCheck.cpp - clang-tidy 
--===//
+//
+// 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 "UseRangesCheck.h"
+#include "clang/AST/Decl.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include 
+
+// FixItHint - Let the docs script know that this class does provide fixits
+
+namespace clang::tidy::modernize {
+
+static constexpr const char *SingleRangeNames[] = {
+"all_of",
+"any_of",
+"none_of",
+"for_each",
+"find",
+"find_if",
+"find_if_not",
+"adjacent_find",
+"copy",
+"copy_if",
+"copy_backward",
+"move",
+"move_backward",
+"fill",
+"transform",
+"replace",
+"replace_if",
+"generate",
+"remove",
+"remove_if",
+"remove_copy",
+"remove_copy_if",
+"unique",
+"unique_copy",
+"sample",
+"partition_point",
+"lower_bound",
+"upper_bound",
+"equal_range",
+"binary_search",
+"push_heap",
+"pop_heap",
+"make_heap",
+"sort_heap",
+"next_permutation",
+"prev_permutation",
+"reverse",
+"reverse_copy",
+"shift_left",
+"shift_right",
+"is_partitioned",
+"partition",
+"partition_copy",
+"stable_partition",
+"sort",
+"stable_sort",
+"is_sorted",
+"is_sorted_until",
+"is_heap",
+"is_heap_until",
+"max_element",
+"min_element",
+"minmax_element",
+"unini

[clang-tools-extra] [clang-tidy] Only expand macros in modernize-use-std-format/print (PR #97911)

2024-07-07 Thread Mike Crowe via cfe-commits

https://github.com/mikecrowe updated 
https://github.com/llvm/llvm-project/pull/97911

>From f6c1a231681092189a621e2bc6af97300b2a7bfa Mon Sep 17 00:00:00 2001
From: Mike Crowe 
Date: Wed, 12 Jun 2024 21:06:26 +0100
Subject: [PATCH 1/2] [clang-tidy] Only expand  macros in
 modernize-use-std-format/print

Expanding all macros in the printf/absl::StrFormat format string before
conversion could easily break code if those macros are expended to
change their definition between builds. It's important for this check to
expand the  PRI macros though, so let's ensure that the
presence of any other macros in the format string causes the check to
emit a warning and not perform any conversion.
---
 .../modernize/UseStdFormatCheck.cpp   |  7 +--
 .../clang-tidy/modernize/UseStdFormatCheck.h  |  1 +
 .../clang-tidy/modernize/UseStdPrintCheck.cpp |  4 +-
 .../clang-tidy/modernize/UseStdPrintCheck.h   |  1 +
 .../utils/FormatStringConverter.cpp   | 52 --
 .../clang-tidy/utils/FormatStringConverter.h  |  6 ++-
 clang-tools-extra/docs/ReleaseNotes.rst   |  3 +-
 .../checks/modernize/use-std-print.rst| 22 
 .../checkers/Inputs/Headers/inttypes.h| 26 +
 .../checkers/modernize/use-std-format.cpp | 53 +++
 .../checkers/modernize/use-std-print.cpp  | 47 +++-
 11 files changed, 181 insertions(+), 41 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp
index d082faa786b375..7e8cbd40fe07ae 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp
@@ -44,6 +44,7 @@ void UseStdFormatCheck::registerPPCallbacks(const 
SourceManager &SM,
 Preprocessor *PP,
 Preprocessor *ModuleExpanderPP) {
   IncludeInserter.registerPreprocessor(PP);
+  this->PP = PP;
 }
 
 void UseStdFormatCheck::registerMatchers(MatchFinder *Finder) {
@@ -78,9 +79,9 @@ void UseStdFormatCheck::check(const MatchFinder::MatchResult 
&Result) {
 
   utils::FormatStringConverter::Configuration ConverterConfig;
   ConverterConfig.StrictMode = StrictMode;
-  utils::FormatStringConverter Converter(Result.Context, StrFormat,
- FormatArgOffset, ConverterConfig,
- getLangOpts());
+  utils::FormatStringConverter Converter(
+  Result.Context, StrFormat, FormatArgOffset, ConverterConfig,
+  getLangOpts(), *Result.SourceManager, *PP);
   const Expr *StrFormatCall = StrFormat->getCallee();
   if (!Converter.canApply()) {
 diag(StrFormat->getBeginLoc(),
diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.h 
b/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.h
index b59a4708c6e4bc..9ac2240212ebf6 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.h
@@ -44,6 +44,7 @@ class UseStdFormatCheck : public ClangTidyCheck {
   StringRef ReplacementFormatFunction;
   utils::IncludeInserter IncludeInserter;
   std::optional MaybeHeaderToInclude;
+  Preprocessor *PP = nullptr;
 };
 
 } // namespace clang::tidy::modernize
diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
index 1ea170c3cd3106..69136c10d927b2 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
@@ -68,6 +68,7 @@ void UseStdPrintCheck::registerPPCallbacks(const 
SourceManager &SM,
Preprocessor *PP,
Preprocessor *ModuleExpanderPP) {
   IncludeInserter.registerPreprocessor(PP);
+  this->PP = PP;
 }
 
 static clang::ast_matchers::StatementMatcher
@@ -137,7 +138,8 @@ void UseStdPrintCheck::check(const MatchFinder::MatchResult 
&Result) {
   ConverterConfig.StrictMode = StrictMode;
   ConverterConfig.AllowTrailingNewlineRemoval = true;
   utils::FormatStringConverter Converter(
-  Result.Context, Printf, FormatArgOffset, ConverterConfig, getLangOpts());
+  Result.Context, Printf, FormatArgOffset, ConverterConfig, getLangOpts(),
+  *Result.SourceManager, *PP);
   const Expr *PrintfCall = Printf->getCallee();
   const StringRef ReplacementFunction = Converter.usePrintNewlineFunction()
 ? ReplacementPrintlnFunction
diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.h 
b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.h
index 7a06cf38b4264f..995c740389e73b 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.h
@@ -36,6 +36,7 @@ class UseStdPrintCheck : public Clan

[clang] [Coverage] Suppress covmap and profdata for system headers. (PR #97952)

2024-07-07 Thread NAKAMURA Takumi via cfe-commits

https://github.com/chapuni created 
https://github.com/llvm/llvm-project/pull/97952

With `system-headers-coverage=false`, functions defined in system headers was 
not instrumented but corresponding covmap was emitted. It caused wasting covmap 
and profraw.

This change improves:

- Reduce object size (due to reduced covmap)
- Reduce size of profraw (uninstrumented system headers occupied counters)
- Smarter view of coverage report. Stubs of uninstrumented system headers will 
be no longer seen.

>From 0d87f3b0be84230e40025f221c501f9104fdc261 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi 
Date: Sun, 7 Jul 2024 22:48:20 +0900
Subject: [PATCH 1/3] Update clang/test/system_macro.cpp for both
 -system-headers-coverage=true/false

---
 clang/test/CoverageMapping/system_macro.cpp | 32 ++---
 1 file changed, 28 insertions(+), 4 deletions(-)

diff --git a/clang/test/CoverageMapping/system_macro.cpp 
b/clang/test/CoverageMapping/system_macro.cpp
index 725752553bcf7..3909c17a9b5c6 100644
--- a/clang/test/CoverageMapping/system_macro.cpp
+++ b/clang/test/CoverageMapping/system_macro.cpp
@@ -1,4 +1,15 @@
-// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -mllvm 
-system-headers-coverage -std=c++11 -fprofile-instrument=clang 
-fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name 
system_macro.cpp -o - %s | FileCheck %s
+// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -mllvm 
-system-headers-coverage=true -std=c++11 -fprofile-instrument=clang 
-fcoverage-mapping -dump-coverage-mapping -emit-llvm -main-file-name 
system_macro.cpp -o %t.w_sys.ll %s | FileCheck %s --check-prefixes=CHECK,W_SYS
+// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -mllvm 
-system-headers-coverage=false -std=c++11 -fprofile-instrument=clang 
-fcoverage-mapping -dump-coverage-mapping -emit-llvm -main-file-name 
system_macro.cpp -o %t.wosys.ll %s | FileCheck %s --check-prefixes=CHECK,WOSYS
+// RUN: FileCheck %s --check-prefixes=LL_CHECK,LL_W_SYS < %t.w_sys.ll
+// RUN: FileCheck %s --check-prefixes=LL_CHECK,LL_WOSYS < %t.wosys.ll
+
+// LL_CHECK: @__covrec_
+// LL_W_SYS: [[PROFC:@.*__profc_.*SysTmpl.*]] =
+// LL_WOSYS: [[PROFC:@.*__profc_.*SysTmpl.*]] =
+// LL_W_SYS: @{{.*}}__profd_{{.*}}SysTmpl{{.*}} =
+// LL_WOSYS: @{{.*}}__profd_{{.*}}SysTmpl{{.*}} =
+
+// LL_CHECK: @llvm.used =
 
 #ifdef IS_SYSHEADER
 
@@ -6,6 +17,12 @@
 #define Func(x) if (x) {}
 #define SomeType int
 
+// LL_CHECK: define {{.*}} i1 @{{.*}}SysTmpl
+template  bool SysTmpl() { return f; }
+// Check SysTmpl() is instrumented or not.
+// LL_W_SYS: load i64, ptr [[PROFC]],
+// LL_WOSYS: load i64, ptr [[PROFC]],
+
 #else
 
 #define IS_SYSHEADER
@@ -13,15 +30,22 @@
 
 // CHECK-LABEL: doSomething
 void doSomething(int x) { // CHECK: File 0, [[@LINE]]:25 -> {{[0-9:]+}} = #0
-  Func(x); // CHECK: Expansion,File 0, [[@LINE]]:3 -> [[@LINE]]:7
+  // WOSYS-NOT: Expansion,
+  // W_SYS: Expansion,File 0, [[@LINE+1]]:3 -> [[@LINE+1]]:7
+  Func(x);
+  // CHECK: Gap,File 0, [[@LINE+1]]:10
   return;
-  // CHECK: Expansion,File 0, [[@LINE+1]]:3 -> [[@LINE+1]]:11
+  // WOSYS-NOT: Expansion,
+  // W_SYS: Expansion,File 0, [[@LINE+1]]:3 -> [[@LINE+1]]:11
   SomeType *f; // CHECK: File 0, [[@LINE]]:11 -> {{[0-9:]+}} = 0
 }
 
 // CHECK-LABEL: main
 int main() { // CHECK: File 0, [[@LINE]]:12 -> [[@LINE+2]]:2 = #0
-  Func([] { return true; }());
+  Func([] { return SysTmpl(); }());
 }
 
+// W_SYS: SysTmpl
+// WOSYS-NOT: SysTmpl
+
 #endif

>From 4ca645447202fe08877d88bca630bd2fc1ac Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi 
Date: Sun, 7 Jul 2024 19:05:59 +0900
Subject: [PATCH 2/3] Move `SystemHeadersCoverage` into `llvm::coverage` in
 CoverageMappingGen.h

---
 clang/lib/CodeGen/CodeGenPGO.cpp | 4 +---
 clang/lib/CodeGen/CoverageMappingGen.cpp | 8 +---
 clang/lib/CodeGen/CoverageMappingGen.h   | 5 +
 3 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp
index ea726b5708a4a..6e6dfc4d5a642 100644
--- a/clang/lib/CodeGen/CodeGenPGO.cpp
+++ b/clang/lib/CodeGen/CodeGenPGO.cpp
@@ -32,8 +32,6 @@ static llvm::cl::opt
  llvm::cl::desc("Enable value profiling"),
  llvm::cl::Hidden, llvm::cl::init(false));
 
-extern llvm::cl::opt SystemHeadersCoverage;
-
 using namespace clang;
 using namespace CodeGen;
 
@@ -1118,7 +1116,7 @@ bool CodeGenPGO::skipRegionMappingForDecl(const Decl *D) {
   // Don't map the functions in system headers.
   const auto &SM = CGM.getContext().getSourceManager();
   auto Loc = D->getBody()->getBeginLoc();
-  return !SystemHeadersCoverage && SM.isInSystemHeader(Loc);
+  return !llvm::coverage::SystemHeadersCoverage && SM.isInSystemHeader(Loc);
 }
 
 void CodeGenPGO::emitCounterRegionMapping(const Decl *D) {
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index ba483d857d5f4..67a9caf8b4ec4 100644
--- a/clang/lib/CodeGen/Cover

[clang] [Coverage] Suppress covmap and profdata for system headers. (PR #97952)

2024-07-07 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-codegen

Author: NAKAMURA Takumi (chapuni)


Changes

With `system-headers-coverage=false`, functions defined in system headers was 
not instrumented but corresponding covmap was emitted. It caused wasting covmap 
and profraw.

This change improves:

- Reduce object size (due to reduced covmap)
- Reduce size of profraw (uninstrumented system headers occupied counters)
- Smarter view of coverage report. Stubs of uninstrumented system headers will 
be no longer seen.

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


5 Files Affected:

- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+3) 
- (modified) clang/lib/CodeGen/CodeGenPGO.cpp (+6-4) 
- (modified) clang/lib/CodeGen/CoverageMappingGen.cpp (+5-3) 
- (modified) clang/lib/CodeGen/CoverageMappingGen.h (+5) 
- (modified) clang/test/CoverageMapping/system_macro.cpp (+27-4) 


``diff
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 652f519d82488..b181342b37c3b 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -7127,6 +7127,9 @@ void CodeGenModule::AddDeferredUnusedCoverageMapping(Decl 
*D) {
 SourceManager &SM = getContext().getSourceManager();
 if (LimitedCoverage && SM.getMainFileID() != 
SM.getFileID(D->getBeginLoc()))
   break;
+if (!llvm::coverage::SystemHeadersCoverage &&
+SM.isInSystemHeader(D->getBeginLoc()))
+  break;
 DeferredEmptyCoverageMappingDecls.try_emplace(D, true);
 break;
   }
diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp
index ea726b5708a4a..cfcdb5911b581 100644
--- a/clang/lib/CodeGen/CodeGenPGO.cpp
+++ b/clang/lib/CodeGen/CodeGenPGO.cpp
@@ -32,8 +32,6 @@ static llvm::cl::opt
  llvm::cl::desc("Enable value profiling"),
  llvm::cl::Hidden, llvm::cl::init(false));
 
-extern llvm::cl::opt SystemHeadersCoverage;
-
 using namespace clang;
 using namespace CodeGen;
 
@@ -1046,13 +1044,17 @@ void CodeGenPGO::assignRegionCounters(GlobalDecl GD, 
llvm::Function *Fn) {
   if (Fn->hasFnAttribute(llvm::Attribute::SkipProfile))
 return;
 
+  SourceManager &SM = CGM.getContext().getSourceManager();
+  if (!llvm::coverage::SystemHeadersCoverage &&
+  SM.isInSystemHeader(D->getLocation()))
+return;
+
   setFuncName(Fn);
 
   mapRegionCounters(D);
   if (CGM.getCodeGenOpts().CoverageMapping)
 emitCounterRegionMapping(D);
   if (PGOReader) {
-SourceManager &SM = CGM.getContext().getSourceManager();
 loadRegionCounts(PGOReader, SM.isInMainFile(D->getLocation()));
 computeRegionCounts(D);
 applyFunctionAttributes(PGOReader, Fn);
@@ -1118,7 +1120,7 @@ bool CodeGenPGO::skipRegionMappingForDecl(const Decl *D) {
   // Don't map the functions in system headers.
   const auto &SM = CGM.getContext().getSourceManager();
   auto Loc = D->getBody()->getBeginLoc();
-  return !SystemHeadersCoverage && SM.isInSystemHeader(Loc);
+  return !llvm::coverage::SystemHeadersCoverage && SM.isInSystemHeader(Loc);
 }
 
 void CodeGenPGO::emitCounterRegionMapping(const Decl *D) {
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index ba483d857d5f4..67a9caf8b4ec4 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -46,10 +46,12 @@ static llvm::cl::opt EmptyLineCommentCoverage(
"disable it on test)"),
 llvm::cl::init(true), llvm::cl::Hidden);
 
-llvm::cl::opt SystemHeadersCoverage(
+namespace llvm::coverage {
+cl::opt SystemHeadersCoverage(
 "system-headers-coverage",
-llvm::cl::desc("Enable collecting coverage from system headers"),
-llvm::cl::init(false), llvm::cl::Hidden);
+cl::desc("Enable collecting coverage from system headers"), 
cl::init(false),
+cl::Hidden);
+}
 
 using namespace clang;
 using namespace CodeGen;
diff --git a/clang/lib/CodeGen/CoverageMappingGen.h 
b/clang/lib/CodeGen/CoverageMappingGen.h
index f7c59c48c1839..fe4b93f3af856 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.h
+++ b/clang/lib/CodeGen/CoverageMappingGen.h
@@ -19,8 +19,13 @@
 #include "clang/Lex/Preprocessor.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/IR/GlobalValue.h"
+#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/raw_ostream.h"
 
+namespace llvm::coverage {
+extern cl::opt SystemHeadersCoverage;
+}
+
 namespace clang {
 
 class LangOptions;
diff --git a/clang/test/CoverageMapping/system_macro.cpp 
b/clang/test/CoverageMapping/system_macro.cpp
index 725752553bcf7..38bbb2efb7075 100644
--- a/clang/test/CoverageMapping/system_macro.cpp
+++ b/clang/test/CoverageMapping/system_macro.cpp
@@ -1,4 +1,14 @@
-// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -mllvm 
-system-headers-coverage -std=c++11 -fprofile-instrument=clang 
-fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-fil

[libunwind] [libunwind] fix unwinding from signal handler (PR #92291)

2024-07-07 Thread Azat Khuzhin via cfe-commits


@@ -365,7 +365,12 @@ int DwarfInstructions::stepWithDwarf(A 
&addressSpace, pint_t pc,
 
   // Return address is address after call site instruction, so setting IP 
to
   // that does simulates a return.
-  newRegisters.setIP(returnAddress);
+  //
+  // In case of this is frame of signal handler, the IP should be
+  // incremented, because the IP saved in the signal handler points to
+  // first non-executed instruction, while FDE/CIE expects IP to be after
+  // the first non-executed instruction.
+  newRegisters.setIP(returnAddress + cieInfo.isSignalFrame);

azat wrote:

>Could the register state not being used for anything else in between and thus 
>be misleading?

Hm, I don't see how it is possible...

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


[clang] [llvm] [ValueTracking] use KnownBits to compute fpclass from bitcast (PR #97762)

2024-07-07 Thread Yingwei Zheng via cfe-commits

dtcxzyw wrote:

> This patch is motivated by an internal benchmark where there were some cases 
> where this helped, though even that case is in some sense artificial.

It is ok to optimize some pattern in proxy apps/benchmarks :)

> Is this a necessary criteria for landing this change?

As recursively computing known bits/fpclass is expensive, it is not worth 
adding additional complexity unless it is useful for real-world applications.

> I believe we already handle float to int in KnownBits

I posted https://github.com/llvm/llvm-project/pull/86409 because I found it 
enabled more optimizations in [my ir dataset] 
(https://github.com/dtcxzyw/llvm-opt-benchmark/pull/451/files).
 
> and adding the inverse in KnownFPClass seems like a correct and reasonable 
> extension of the logic, ***even if there are not many cases where it is 
> used.***

Don't do this. It is a trap of code coverage. We need to strike a balance 
between optimizations, compilation time and maintainability.

For more details, see 
https://llvm.org/docs/InstCombineContributorGuide.html#real-world-usefulness.


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


[clang-tools-extra] [clang-tidy] Only expand macros in modernize-use-std-format/print (PR #97911)

2024-07-07 Thread Mike Crowe via cfe-commits

mikecrowe wrote:

It looks like the tests are failing on Windows because the `%s` in the command 
line
```
// RUN: %check_clang_tidy \
// RUN:   -std=c++20 %s modernize-use-std-format %t -- \
// RUN:   -config="{CheckOptions: {StrictMode: true}}" \
// RUN:   -- -isystem %clang_tidy_headers \
// RUN:  -DPRI_CMDLINE_MACRO="\"%s\"" \
// RUN:  -D__PRI_CMDLINE_MACRO="\"%s\""
```
is being replaced by the filename for the LIT test:
```
| Running ['clang-tidy', 
'C:\\ws\\src\\build\\tools\\clang\\tools\\extra\\test\\clang-tidy\\checkers\\modernize\\Output\\use-std-format.cpp.tmp.cpp',
 '-fix', '--checks=-*,modernize-use-std-format', '-config={CheckOptions: 
{StrictMode: true}}', '--', '-isystem', 
'C:/ws/src/clang-tools-extra/test/../test\\clang-tidy\\checkers\\Inputs\\Headers',
 
'-DPRI_CMDLINE_MACRO="C:\\ws\\src\\clang-tools-extra\\test\\clang-tidy\\checkers\\modernize\\use-std-format.cpp"',
 
'-D__PRI_CMDLINE_MACRO="C:\\ws\\src\\clang-tools-extra\\test\\clang-tidy\\checkers\\modernize\\use-std-format.cpp"',
 '-std=c++20', '-nostdinc++']...
```
I can believe that this is being done by `TestRunner.py` (or some other part of 
llvm-lit) since that's expected for the first `%s` on the command line, but the 
surprise is that it doesn't also do this on Linux. Nevertheless, I'll modify 
the tests to avoid using `%` at all in the macros on the command line.

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


[clang-tools-extra] [clang-tidy] Only expand macros in modernize-use-std-format/print (PR #97911)

2024-07-07 Thread Mike Crowe via cfe-commits

https://github.com/mikecrowe updated 
https://github.com/llvm/llvm-project/pull/97911

>From f6c1a231681092189a621e2bc6af97300b2a7bfa Mon Sep 17 00:00:00 2001
From: Mike Crowe 
Date: Wed, 12 Jun 2024 21:06:26 +0100
Subject: [PATCH 1/3] [clang-tidy] Only expand  macros in
 modernize-use-std-format/print

Expanding all macros in the printf/absl::StrFormat format string before
conversion could easily break code if those macros are expended to
change their definition between builds. It's important for this check to
expand the  PRI macros though, so let's ensure that the
presence of any other macros in the format string causes the check to
emit a warning and not perform any conversion.
---
 .../modernize/UseStdFormatCheck.cpp   |  7 +--
 .../clang-tidy/modernize/UseStdFormatCheck.h  |  1 +
 .../clang-tidy/modernize/UseStdPrintCheck.cpp |  4 +-
 .../clang-tidy/modernize/UseStdPrintCheck.h   |  1 +
 .../utils/FormatStringConverter.cpp   | 52 --
 .../clang-tidy/utils/FormatStringConverter.h  |  6 ++-
 clang-tools-extra/docs/ReleaseNotes.rst   |  3 +-
 .../checks/modernize/use-std-print.rst| 22 
 .../checkers/Inputs/Headers/inttypes.h| 26 +
 .../checkers/modernize/use-std-format.cpp | 53 +++
 .../checkers/modernize/use-std-print.cpp  | 47 +++-
 11 files changed, 181 insertions(+), 41 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp
index d082faa786b37..7e8cbd40fe07a 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp
@@ -44,6 +44,7 @@ void UseStdFormatCheck::registerPPCallbacks(const 
SourceManager &SM,
 Preprocessor *PP,
 Preprocessor *ModuleExpanderPP) {
   IncludeInserter.registerPreprocessor(PP);
+  this->PP = PP;
 }
 
 void UseStdFormatCheck::registerMatchers(MatchFinder *Finder) {
@@ -78,9 +79,9 @@ void UseStdFormatCheck::check(const MatchFinder::MatchResult 
&Result) {
 
   utils::FormatStringConverter::Configuration ConverterConfig;
   ConverterConfig.StrictMode = StrictMode;
-  utils::FormatStringConverter Converter(Result.Context, StrFormat,
- FormatArgOffset, ConverterConfig,
- getLangOpts());
+  utils::FormatStringConverter Converter(
+  Result.Context, StrFormat, FormatArgOffset, ConverterConfig,
+  getLangOpts(), *Result.SourceManager, *PP);
   const Expr *StrFormatCall = StrFormat->getCallee();
   if (!Converter.canApply()) {
 diag(StrFormat->getBeginLoc(),
diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.h 
b/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.h
index b59a4708c6e4b..9ac2240212ebf 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.h
@@ -44,6 +44,7 @@ class UseStdFormatCheck : public ClangTidyCheck {
   StringRef ReplacementFormatFunction;
   utils::IncludeInserter IncludeInserter;
   std::optional MaybeHeaderToInclude;
+  Preprocessor *PP = nullptr;
 };
 
 } // namespace clang::tidy::modernize
diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
index 1ea170c3cd310..69136c10d927b 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
@@ -68,6 +68,7 @@ void UseStdPrintCheck::registerPPCallbacks(const 
SourceManager &SM,
Preprocessor *PP,
Preprocessor *ModuleExpanderPP) {
   IncludeInserter.registerPreprocessor(PP);
+  this->PP = PP;
 }
 
 static clang::ast_matchers::StatementMatcher
@@ -137,7 +138,8 @@ void UseStdPrintCheck::check(const MatchFinder::MatchResult 
&Result) {
   ConverterConfig.StrictMode = StrictMode;
   ConverterConfig.AllowTrailingNewlineRemoval = true;
   utils::FormatStringConverter Converter(
-  Result.Context, Printf, FormatArgOffset, ConverterConfig, getLangOpts());
+  Result.Context, Printf, FormatArgOffset, ConverterConfig, getLangOpts(),
+  *Result.SourceManager, *PP);
   const Expr *PrintfCall = Printf->getCallee();
   const StringRef ReplacementFunction = Converter.usePrintNewlineFunction()
 ? ReplacementPrintlnFunction
diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.h 
b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.h
index 7a06cf38b4264..995c740389e73 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.h
@@ -36,6 +36,7 @@ class UseStdPrintCheck : public ClangTidyChe

[clang-tools-extra] [clang-tidy] Only expand macros in modernize-use-std-format/print (PR #97911)

2024-07-07 Thread Mike Crowe via cfe-commits

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


[clang-tools-extra] [clangd] Support go-to-definition on type hints. The core part (PR #86629)

2024-07-07 Thread Younan Zhang via cfe-commits


@@ -372,6 +374,292 @@ maybeDropCxxExplicitObjectParameters(ArrayRef Params) {
   return Params;
 }
 
+class TypeInlayHintLabelPartBuilder
+: public TypeVisitor {
+  QualType CurrentType;
+  NestedNameSpecifier *CurrentNestedNameSpecifier;
+  ASTContext &Context;
+  StringRef MainFilePath;
+  const PrintingPolicy &PP;
+  SourceManager &SM;
+  std::vector &LabelChunks;
+
+  struct CurrentTypeRAII {
+TypeInlayHintLabelPartBuilder &Builder;
+QualType PreviousType;
+NestedNameSpecifier *PreviousNestedNameSpecifier;
+CurrentTypeRAII(TypeInlayHintLabelPartBuilder &Builder, QualType New,
+NestedNameSpecifier *NNS = nullptr)
+: Builder(Builder), PreviousType(Builder.CurrentType),
+  PreviousNestedNameSpecifier(Builder.CurrentNestedNameSpecifier) {
+  Builder.CurrentType = New;
+  if (NNS)
+Builder.CurrentNestedNameSpecifier = NNS;
+}
+~CurrentTypeRAII() {
+  Builder.CurrentType = PreviousType;
+  Builder.CurrentNestedNameSpecifier = PreviousNestedNameSpecifier;
+}
+  };
+
+  void addLabel(llvm::function_ref NamePrinter,
+llvm::function_ref SourceLocationGetter) {
+std::string Label;
+llvm::raw_string_ostream OS(Label);
+NamePrinter(OS);
+auto &Name = LabelChunks.emplace_back();
+Name.value = std::move(Label);
+Name.location = makeLocation(Context, SourceLocationGetter(), 
MainFilePath);
+  }
+
+  void addLabel(std::string Label) {
+if (LabelChunks.empty()) {
+  LabelChunks.emplace_back(std::move(Label));
+  return;
+}
+auto &Back = LabelChunks.back();
+if (Back.location) {
+  LabelChunks.emplace_back(std::move(Label));
+  return;
+}
+// Let's combine the "unclickable" pieces together.
+Back.value += std::move(Label);
+  }
+
+  void printTemplateArgumentList(llvm::ArrayRef Args) {
+unsigned Size = Args.size();
+for (unsigned I = 0; I < Size; ++I) {
+  auto &TA = Args[I];
+  if (PP.SuppressDefaultTemplateArgs && TA.getIsDefaulted())
+continue;
+  if (I)
+addLabel(", ");
+  printTemplateArgument(TA);
+}
+  }
+
+  void printTemplateArgument(const TemplateArgument &TA) {
+switch (TA.getKind()) {
+case TemplateArgument::Pack:
+  return printTemplateArgumentList(TA.pack_elements());
+case TemplateArgument::Type: {
+  CurrentTypeRAII Guard(*this, TA.getAsType());
+  return Visit(TA.getAsType().getTypePtr());
+}
+// TODO: Add support for NTTP arguments.
+case TemplateArgument::Expression:
+case TemplateArgument::StructuralValue:
+case TemplateArgument::Null:
+case TemplateArgument::Declaration:
+case TemplateArgument::NullPtr:
+case TemplateArgument::Integral:
+case TemplateArgument::Template:
+case TemplateArgument::TemplateExpansion:
+  break;
+}
+std::string Label;
+llvm::raw_string_ostream OS(Label);
+TA.print(PP, OS, /*IncludeType=*/true);
+addLabel(std::move(Label));
+  }
+
+  void handleTemplateSpecialization(
+  TemplateName TN, llvm::ArrayRef Args,
+  SourceLocation TemplateNameLocation = SourceLocation()) {
+SourceLocation Location;
+TemplateDecl *TD = nullptr;
+auto PrintType = TemplateName::Qualified::AsWritten;
+switch (TN.getKind()) {
+case TemplateName::Template:
+  TD = TN.getAsTemplateDecl();
+  Location = nameLocation(*TD, SM);
+  break;
+case TemplateName::QualifiedTemplate:
+  if (NestedNameSpecifier *NNS =
+  TN.getAsQualifiedTemplateName()->getQualifier();
+  NNS == CurrentNestedNameSpecifier) {
+// We have handled the NNS in VisitElaboratedType(). Avoid printing it
+// twice.
+TN = TN.getAsQualifiedTemplateName()->getUnderlyingTemplate();
+PrintType = TemplateName::Qualified::None;
+  }
+  break;
+case TemplateName::OverloadedTemplate:
+case TemplateName::AssumedTemplate:
+case TemplateName::DependentTemplate:
+case TemplateName::SubstTemplateTemplateParm:
+case TemplateName::SubstTemplateTemplateParmPack:
+case TemplateName::UsingTemplate:
+  break;
+}
+
+addLabel([&](llvm::raw_ostream &OS) { TN.print(OS, PP, PrintType); },
+ [&] {
+   if (TemplateNameLocation.isValid())
+ return TemplateNameLocation;
+   return Location;
+ });
+
+addLabel("<");
+printTemplateArgumentList(Args);
+addLabel(">");
+  }
+
+  void maybeAddQualifiers() {
+auto Quals = CurrentType.split().Quals;
+if (!Quals.empty()) {
+  addLabel(Quals.getAsString());
+  addLabel(" ");
+}
+  }
+
+  // When printing a reference, the referenced type might also be a reference.
+  // If so, we want to skip that before printing the inner type.
+  static QualType skipTopLevelReferences(QualType T) {
+if (auto *Ref = T->getAs())
+  return skipTopLevelReferences(Ref->getPointeeTypeAsWr

[clang-tools-extra] [clangd] Support go-to-definition on type hints. The core part (PR #86629)

2024-07-07 Thread Younan Zhang via cfe-commits


@@ -1005,14 +1332,22 @@ class InlayHintVisitor : public 
RecursiveASTVisitor {
 // The sugared type is more useful in some cases, and the canonical
 // type in other cases.
 auto Desugared = maybeDesugar(AST, T);
-std::string TypeName = Desugared.getAsString(TypeHintPolicy);
-if (T != Desugared && !shouldPrintTypeHint(TypeName)) {
+std::vector Chunks;
+TypeInlayHintLabelPartBuilder Builder(Desugared, AST, MainFilePath,
+  TypeHintPolicy, Prefix, Chunks);
+Builder.Visit(Desugared.getTypePtr());
+if (T != Desugared && !shouldPrintTypeHint(Chunks)) {
   // If the desugared type is too long to display, fallback to the sugared
   // type.
-  TypeName = T.getAsString(TypeHintPolicy);
+  Chunks.clear();
+  TypeInlayHintLabelPartBuilder Builder(T, AST, MainFilePath,
+TypeHintPolicy, Prefix, Chunks);
+  Builder.Visit(T.getTypePtr());
 }
-if (shouldPrintTypeHint(TypeName))
-  addInlayHint(R, HintSide::Right, InlayHintKind::Type, Prefix, TypeName,
+if (shouldPrintTypeHint(Chunks))
+  addInlayHint(R, HintSide::Right, InlayHintKind::Type,
+   /*Prefix=*/"", // We have handled prefixes in the builder.

zyn0217 wrote:

I'm trying to put these prefixes i.e. ": " together with those unclickable type 
hints. i.e. to emit `: S` instead of adding such prefixes outside of the 
builder - we would end up copying the whole vector otherwise.

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


[clang-tools-extra] [clangd] Support go-to-definition on type hints. The core part (PR #86629)

2024-07-07 Thread Younan Zhang via cfe-commits

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


[clang] [Coverage] Suppress covmap and profdata for system headers. (PR #97952)

2024-07-07 Thread Hana Dusíková via cfe-commits

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

LGTM

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


[clang] [clang][C23] N3006 Underspecified object declarations (PR #79845)

2024-07-07 Thread Guillot Tony via cfe-commits


@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -std=c2x -verify %s
+
+/* WG14 N3006: Full
+ * Underspecified object declarations
+ */
+
+struct S1 { int x, y; };// expected-note {{previous definition is 
here}}
+union U1 { int a; double b; };  // expected-note {{previous definition is 
here}}
+enum E1 { FOO, BAR };   // expected-note {{previous definition is 
here}}
+
+auto normal_struct = (struct S1){ 1, 2 };
+auto underspecified_struct = (struct S2 { int x, y; }){ 1, 2 };   // 
expected-error {{'struct S2' is defined as an underspecified object 
initializer}}
+auto underspecified_struct_redef = (struct S1 { char x, y; }){ 'A', 'B'}; // 
expected-error {{redefinition of 'S1'}}
+auto underspecified_empty_struct = (struct S3 { }){ };// 
expected-error {{'struct S3' is defined as an underspecified object 
initializer}}
+
+auto normal_union_int = (union U1){ .a = 12 };
+auto normal_union_double = (union U1){ .b = 2.4 };
+auto underspecified_union = (union U2 { int a; double b; }){ .a = 34 };
 // expected-error {{'union U2' is defined as an underspecified object 
initializer}}
+auto underspecified_union_redef = (union U1 { char a; double b; }){ .a = 'A' 
}; // expected-error {{redefinition of 'U1'}}
+auto underspecified_empty_union = (union U3 {  }){  }; 
 // expected-error {{'union U3' is defined as an underspecified object 
initializer}}
+
+auto normal_enum_foo = (enum E1){ FOO };
+auto normal_enum_bar = (enum E1){ BAR };
+auto underspecified_enum = (enum E2 { BAZ, QUX }){ BAZ };   // 
expected-error {{'enum E2' is defined as an underspecified object initializer}}
+auto underspecified_enum_redef = (enum E1 { ONE, TWO }){ ONE }; // 
expected-error {{redefinition of 'E1'}}
+auto underspecified_empty_enum = (enum E3 {  }){ }; // 
expected-error {{'enum E3' is defined as an underspecified object initializer}} 
\
+   
expected-error {{use of empty enum}}

to268 wrote:

I'm not sure if declaring a non ordinary identifier `t` of type `struct T` 
should be diagnosed as an invalid declaration, since the definition of the 
`struct T` type is actually a underspecified declaration.
Interestingly, if you remove the `constexpr` keyword, there is currently no 
change in behavior in this case.

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


[clang] [clang][C23] N3006 Underspecified object declarations (PR #79845)

2024-07-07 Thread Guillot Tony via cfe-commits


@@ -7813,6 +7813,32 @@ Sema::BuildCompoundLiteralExpr(SourceLocation LParenLoc, 
TypeSourceInfo *TInfo,
diag::err_variable_object_no_init))
 return ExprError();
 }
+  } else if (LangOpts.C23 &&

to268 wrote:

3 out of these 5 cases are not conforming curently:
```cpp
constexpr typeof(struct s *) x = 0;   // Wrong, no underspecifed 
diagnostics
constexpr struct S { int a, b; } y = { 0 };   // Wrong, no underspecifed 
diagnostics
constexpr int a = 0, b = 0;   // Ok, no underspecifed 
diagnostics
auto c = (struct T { int x, y; }){0, 0};  // Ok, `struct T` diagnosed 
as underspecifed
constexpr int (*fp)(struct X { int x; } val) = 0; // Wrong, no underspecifed 
diagnostics but dignoses warning: `declaration of 'struct X' will not be 
visible outside of this function`
```
I need to do more work outside of compound literals.

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


[clang] [clang][C23] N3006 Underspecified object declarations (PR #79845)

2024-07-07 Thread Guillot Tony via cfe-commits

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


[clang] [llvm] [RISCV] Add support for getHostCPUFeatures using hwprobe (PR #94352)

2024-07-07 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw updated 
https://github.com/llvm/llvm-project/pull/94352

>From ff839bef048a65760f4cd0e9abafe11cfebd9362 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Tue, 4 Jun 2024 21:08:27 +0800
Subject: [PATCH 01/14] [RISCV] Add support for getHostCPUFeatures using
 hwprobe

Co-authored-by: Yangyu Chen 
---
 llvm/lib/TargetParser/Host.cpp | 68 ++
 1 file changed, 68 insertions(+)

diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp
index 68155acd9e5bc..b4a13b38eb380 100644
--- a/llvm/lib/TargetParser/Host.cpp
+++ b/llvm/lib/TargetParser/Host.cpp
@@ -1998,6 +1998,74 @@ bool sys::getHostCPUFeatures(StringMap &Features) {
 
   return true;
 }
+#elif defined(__linux__) && defined(__riscv)
+#ifdef __has_include
+#if __has_include()
+#include 
+#endif
+#endif
+bool sys::getHostCPUFeatures(StringMap &Features) {
+#ifdef RISCV_HWPROBE_KEY_MVENDORID
+  riscv_hwprobe Query[2]{
+  {RISCV_HWPROBE_KEY_IMA_EXT_0, 0},
+  {RISCV_HWPROBE_KEY_CPUPERF_0, 0},
+  };
+  int Ret = syscall(/*__NR_riscv_hwprobe=*/258, /*pairs=*/&Query,
+/*pair_count=*/1, /*cpu_count=*/0, /*cpus=*/0, 
/*flags=*/0);
+  if (Ret != 0)
+return false;
+
+  uint64_t ExtMask = Query[0].value;
+  Features["f"] = ExtMask & RISCV_HWPROBE_IMA_FD;
+  Features["d"] = ExtMask & RISCV_HWPROBE_IMA_FD;
+  Features["c"] = ExtMask & RISCV_HWPROBE_IMA_C;
+  Features["v"] = ExtMask & RISCV_HWPROBE_IMA_V;
+  Features["zba"] = ExtMask & RISCV_HWPROBE_IMA_ZBA;
+  Features["zbb"] = ExtMask & RISCV_HWPROBE_IMA_ZBB;
+  Features["zbs"] = ExtMask & RISCV_HWPROBE_IMA_ZBS;
+  Features["zicboz"] = ExtMask & RISCV_HWPROBE_IMA_ZICBOZ;
+  Features["zbc"] = ExtMask & RISCV_HWPROBE_IMA_ZBC;
+  Features["zbkb"] = ExtMask & RISCV_HWPROBE_IMA_ZBKB;
+  Features["zbkc"] = ExtMask & RISCV_HWPROBE_IMA_ZBKC;
+  Features["zbkx"] = ExtMask & RISCV_HWPROBE_IMA_ZBKX;
+  Features["zknd"] = ExtMask & RISCV_HWPROBE_IMA_ZKND;
+  Features["zkne"] = ExtMask & RISCV_HWPROBE_IMA_ZKNE;
+  Features["zknh"] = ExtMask & RISCV_HWPROBE_IMA_ZKNH;
+  Features["zksed"] = ExtMask & RISCV_HWPROBE_IMA_ZKSED;
+  Features["zksh"] = ExtMask & RISCV_HWPROBE_IMA_ZKSH;
+  Features["zkt"] = ExtMask & RISCV_HWPROBE_IMA_ZKT;
+  Features["zvbb"] = ExtMask & RISCV_HWPROBE_IMA_ZVBB;
+  Features["zvbc"] = ExtMask & RISCV_HWPROBE_IMA_ZVBC;
+  Features["zvkb"] = ExtMask & RISCV_HWPROBE_IMA_ZVKB;
+  Features["zvkg"] = ExtMask & RISCV_HWPROBE_IMA_ZVKG;
+  Features["zvkned"] = ExtMask & RISCV_HWPROBE_IMA_ZVKNED;
+  Features["zvknha"] = ExtMask & RISCV_HWPROBE_IMA_ZVKNHA;
+  Features["zvknhb"] = ExtMask & RISCV_HWPROBE_IMA_ZVKNHB;
+  Features["zvksed"] = ExtMask & RISCV_HWPROBE_IMA_ZVKSED;
+  Features["zvksh"] = ExtMask & RISCV_HWPROBE_IMA_ZVKSH;
+  Features["zvkt"] = ExtMask & RISCV_HWPROBE_IMA_ZVKT;
+  Features["zfh"] = ExtMask & RISCV_HWPROBE_IMA_ZFH;
+  Features["zfhmin"] = ExtMask & RISCV_HWPROBE_IMA_ZFHMIN;
+  Features["zihintntl"] = ExtMask & RISCV_HWPROBE_IMA_ZIHINTNTL;
+  Features["zvfh"] = ExtMask & RISCV_HWPROBE_IMA_ZVFH;
+  Features["zvfhmin"] = ExtMask & RISCV_HWPROBE_IMA_ZVFHMIN;
+  Features["zfa"] = ExtMask & RISCV_HWPROBE_IMA_ZFA;
+  Features["ztso"] = ExtMask & RISCV_HWPROBE_IMA_ZTSO;
+  Features["zacas"] = ExtMask & RISCV_HWPROBE_IMA_ZACAS;
+  Features["zicond"] = ExtMask & RISCV_HWPROBE_IMA_ZICOND;
+  Features["zihintpause"] = ExtMask & RISCV_HWPROBE_IMA_ZIHINTPAUSE;
+
+  uint64_t MisalignedMask = Query[1].value;
+  if (MisalignedMask == RISCV_HWPROBE_MISALIGNED_FAST) {
+Features["unaligned-scalar-mem"] = true;
+Features["unaligned-vector-mem"] = true;
+  }
+
+  return true;
+#else
+  return false;
+#endif
+}
 #else
 bool sys::getHostCPUFeatures(StringMap &Features) { return false; }
 #endif

>From a2fa6e3d64d3a1e2a8e3a7af91068bdb1fda28b1 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Tue, 4 Jun 2024 22:10:55 +0800
Subject: [PATCH 02/14] [RISCV] Address review comments.

---
 llvm/lib/TargetParser/Host.cpp | 112 +++--
 1 file changed, 52 insertions(+), 60 deletions(-)

diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp
index b4a13b38eb380..ec275c0a7fded 100644
--- a/llvm/lib/TargetParser/Host.cpp
+++ b/llvm/lib/TargetParser/Host.cpp
@@ -1999,72 +1999,64 @@ bool sys::getHostCPUFeatures(StringMap &Features) 
{
   return true;
 }
 #elif defined(__linux__) && defined(__riscv)
-#ifdef __has_include
-#if __has_include()
-#include 
-#endif
-#endif
+// struct riscv_hwprobe
+struct RISCVHwProbe {
+  int64_t Key;
+  uint64_t Value;
+};
 bool sys::getHostCPUFeatures(StringMap &Features) {
-#ifdef RISCV_HWPROBE_KEY_MVENDORID
-  riscv_hwprobe Query[2]{
-  {RISCV_HWPROBE_KEY_IMA_EXT_0, 0},
-  {RISCV_HWPROBE_KEY_CPUPERF_0, 0},
-  };
-  int Ret = syscall(/*__NR_riscv_hwprobe=*/258, /*pairs=*/&Query,
-/*pair_count=*/1, /*cpu_count=*/0, /*cpus=*/0, 
/*flags=*/0);
+  RISCVHwProbe Query[]{{/*RISCV_HWPROBE_KEY_IMA_EXT_0=*/4, 0}};
+  i

[clang] [llvm] [RISCV] Add support for getHostCPUFeatures using hwprobe (PR #94352)

2024-07-07 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 902fb1b4653d5a23613492406cd5693446f06ab6 
6be7eea2a193ca3d92141f62286f779124647acd -- 
clang/lib/Driver/ToolChains/Arch/RISCV.cpp llvm/lib/TargetParser/Host.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp
index a6c848d180..7b13e68475 100644
--- a/llvm/lib/TargetParser/Host.cpp
+++ b/llvm/lib/TargetParser/Host.cpp
@@ -2063,8 +2063,8 @@ bool sys::getHostCPUFeatures(StringMap &Features) {
   Features["zfa"] = ExtMask & (1ULL << 32); // RISCV_HWPROBE_EXT_ZFA
   // TODO: set ztso when it is no longer experimental.
   // Features["ztso"] = ExtMask & (1ULL << 33);// RISCV_HWPROBE_EXT_ZTSO
-  Features["zacas"] = ExtMask & (1ULL << 34);   // RISCV_HWPROBE_EXT_ZACAS
-  Features["zicond"] = ExtMask & (1ULL << 35);  // RISCV_HWPROBE_EXT_ZICOND
+  Features["zacas"] = ExtMask & (1ULL << 34);  // RISCV_HWPROBE_EXT_ZACAS
+  Features["zicond"] = ExtMask & (1ULL << 35); // RISCV_HWPROBE_EXT_ZICOND
   Features["zihintpause"] =
   ExtMask & (1ULL << 36); // RISCV_HWPROBE_EXT_ZIHINTPAUSE
 

``




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


[clang] [llvm] [Clang][OpenMP] This is addition fix for #92210. (PR #94802)

2024-07-07 Thread via cfe-commits

jyu2-git wrote:

Hi Alexey,
Thank you take look!

> Missed one thing, the assignments for boolean flags must be |=, otherwise we 
> may miss some combinations.

Are you talking about assignment of following?
HasMapBasePtr = any_of(M, [](c..

Do I need to change to:
HasMapBasePtr |= any_of(M, [](c

Thanks.  
Jennifer

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


[clang] [RISCV][Driver] Refactor `riscv::getRISCVArch` to return `std::string`. NFC. (PR #97965)

2024-07-07 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw created 
https://github.com/llvm/llvm-project/pull/97965

See the discussion in 
https://github.com/llvm/llvm-project/pull/94352#discussion_r1657074801

>From 21a8c00e8276f0ea4fa5c52296b257b8d113b947 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Mon, 8 Jul 2024 02:06:34 +0800
Subject: [PATCH] [RISCV][Driver] Refactor `riscv::getRISCVArch` to return
 `std::string`. NFC.

---
 clang/lib/Driver/Driver.cpp|  2 +-
 clang/lib/Driver/ToolChains/Arch/RISCV.cpp | 10 +-
 clang/lib/Driver/ToolChains/Arch/RISCV.h   |  4 ++--
 clang/lib/Driver/ToolChains/BareMetal.cpp  |  2 +-
 clang/lib/Driver/ToolChains/Clang.cpp  |  2 +-
 clang/lib/Driver/ToolChains/Flang.cpp  |  2 +-
 clang/lib/Driver/ToolChains/Gnu.cpp|  7 ---
 7 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 221e222bdd47d..021c5b8a33dba 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -681,7 +681,7 @@ static llvm::Triple computeTargetTriple(const Driver &D,
   if (Target.isRISCV()) {
 if (Args.hasArg(options::OPT_march_EQ) ||
 Args.hasArg(options::OPT_mcpu_EQ)) {
-  StringRef ArchName = tools::riscv::getRISCVArch(Args, Target);
+  std::string ArchName = tools::riscv::getRISCVArch(Args, Target);
   auto ISAInfo = llvm::RISCVISAInfo::parseArchString(
   ArchName, /*EnableExperimentalExtensions=*/true);
   if (!llvm::errorToBool(ISAInfo.takeError())) {
diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index 26789b0ba6e09..1831a4113fcd0 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -72,7 +72,7 @@ static void getRISCFeaturesFromMcpu(const Driver &D, const 
Arg *A,
 void riscv::getRISCVTargetFeatures(const Driver &D, const llvm::Triple &Triple,
const ArgList &Args,
std::vector &Features) {
-  StringRef MArch = getRISCVArch(Args, Triple);
+  std::string MArch = getRISCVArch(Args, Triple);
 
   if (!getArchFeatures(D, MArch, Features, Args))
 return;
@@ -227,7 +227,7 @@ StringRef riscv::getRISCVABI(const ArgList &Args, const 
llvm::Triple &Triple) {
   // rv64g | rv64*d -> lp64d
   // rv64e -> lp64e
   // rv64* -> lp64
-  StringRef Arch = getRISCVArch(Args, Triple);
+  std::string Arch = getRISCVArch(Args, Triple);
 
   auto ParseResult = llvm::RISCVISAInfo::parseArchString(
   Arch, /* EnableExperimentalExtension */ true);
@@ -253,8 +253,8 @@ StringRef riscv::getRISCVABI(const ArgList &Args, const 
llvm::Triple &Triple) {
   }
 }
 
-StringRef riscv::getRISCVArch(const llvm::opt::ArgList &Args,
-  const llvm::Triple &Triple) {
+std::string riscv::getRISCVArch(const llvm::opt::ArgList &Args,
+const llvm::Triple &Triple) {
   assert(Triple.isRISCV() && "Unexpected triple");
 
   // GCC's logic around choosing a default `-march=` is complex. If GCC is not
@@ -295,7 +295,7 @@ StringRef riscv::getRISCVArch(const llvm::opt::ArgList 
&Args,
 StringRef MArch = llvm::RISCV::getMArchFromMcpu(CPU);
 // Bypass if target cpu's default march is empty.
 if (MArch != "")
-  return MArch;
+  return MArch.str();
   }
 
   // 3. Choose a default based on `-mabi=`
diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.h 
b/clang/lib/Driver/ToolChains/Arch/RISCV.h
index fcaf9d57ad13d..388786b9c4c1f 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.h
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.h
@@ -24,8 +24,8 @@ void getRISCVTargetFeatures(const Driver &D, const 
llvm::Triple &Triple,
 std::vector &Features);
 StringRef getRISCVABI(const llvm::opt::ArgList &Args,
   const llvm::Triple &Triple);
-StringRef getRISCVArch(const llvm::opt::ArgList &Args,
-   const llvm::Triple &Triple);
+std::string getRISCVArch(const llvm::opt::ArgList &Args,
+ const llvm::Triple &Triple);
 std::string getRISCVTargetCPU(const llvm::opt::ArgList &Args,
   const llvm::Triple &Triple);
 } // end namespace riscv
diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp 
b/clang/lib/Driver/ToolChains/BareMetal.cpp
index 11f94877a5cff..852e0442f50a2 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.cpp
+++ b/clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -37,7 +37,7 @@ static bool findRISCVMultilibs(const Driver &D,
const llvm::Triple &TargetTriple,
const ArgList &Args, DetectedMultilibs &Result) 
{
   Multilib::flags_list Flags;
-  StringRef Arch = riscv::getRISCVArch(Args, TargetTriple);
+  std::string Arch = riscv::getRISCVArch(Args, TargetTriple);
   StringRef Abi = tools::riscv::getRISCVABI(Args, TargetTriple);
 
   if (TargetTriple.isRISCV64()) {
d

[clang] [RISCV][Driver] Refactor `riscv::getRISCVArch` to return `std::string`. NFC. (PR #97965)

2024-07-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Yingwei Zheng (dtcxzyw)


Changes

See the discussion in 
https://github.com/llvm/llvm-project/pull/94352#discussion_r1657074801

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


7 Files Affected:

- (modified) clang/lib/Driver/Driver.cpp (+1-1) 
- (modified) clang/lib/Driver/ToolChains/Arch/RISCV.cpp (+5-5) 
- (modified) clang/lib/Driver/ToolChains/Arch/RISCV.h (+2-2) 
- (modified) clang/lib/Driver/ToolChains/BareMetal.cpp (+1-1) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+1-1) 
- (modified) clang/lib/Driver/ToolChains/Flang.cpp (+1-1) 
- (modified) clang/lib/Driver/ToolChains/Gnu.cpp (+4-3) 


``diff
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 221e222bdd47d9..021c5b8a33dba9 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -681,7 +681,7 @@ static llvm::Triple computeTargetTriple(const Driver &D,
   if (Target.isRISCV()) {
 if (Args.hasArg(options::OPT_march_EQ) ||
 Args.hasArg(options::OPT_mcpu_EQ)) {
-  StringRef ArchName = tools::riscv::getRISCVArch(Args, Target);
+  std::string ArchName = tools::riscv::getRISCVArch(Args, Target);
   auto ISAInfo = llvm::RISCVISAInfo::parseArchString(
   ArchName, /*EnableExperimentalExtensions=*/true);
   if (!llvm::errorToBool(ISAInfo.takeError())) {
diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index 26789b0ba6e098..1831a4113fcd08 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -72,7 +72,7 @@ static void getRISCFeaturesFromMcpu(const Driver &D, const 
Arg *A,
 void riscv::getRISCVTargetFeatures(const Driver &D, const llvm::Triple &Triple,
const ArgList &Args,
std::vector &Features) {
-  StringRef MArch = getRISCVArch(Args, Triple);
+  std::string MArch = getRISCVArch(Args, Triple);
 
   if (!getArchFeatures(D, MArch, Features, Args))
 return;
@@ -227,7 +227,7 @@ StringRef riscv::getRISCVABI(const ArgList &Args, const 
llvm::Triple &Triple) {
   // rv64g | rv64*d -> lp64d
   // rv64e -> lp64e
   // rv64* -> lp64
-  StringRef Arch = getRISCVArch(Args, Triple);
+  std::string Arch = getRISCVArch(Args, Triple);
 
   auto ParseResult = llvm::RISCVISAInfo::parseArchString(
   Arch, /* EnableExperimentalExtension */ true);
@@ -253,8 +253,8 @@ StringRef riscv::getRISCVABI(const ArgList &Args, const 
llvm::Triple &Triple) {
   }
 }
 
-StringRef riscv::getRISCVArch(const llvm::opt::ArgList &Args,
-  const llvm::Triple &Triple) {
+std::string riscv::getRISCVArch(const llvm::opt::ArgList &Args,
+const llvm::Triple &Triple) {
   assert(Triple.isRISCV() && "Unexpected triple");
 
   // GCC's logic around choosing a default `-march=` is complex. If GCC is not
@@ -295,7 +295,7 @@ StringRef riscv::getRISCVArch(const llvm::opt::ArgList 
&Args,
 StringRef MArch = llvm::RISCV::getMArchFromMcpu(CPU);
 // Bypass if target cpu's default march is empty.
 if (MArch != "")
-  return MArch;
+  return MArch.str();
   }
 
   // 3. Choose a default based on `-mabi=`
diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.h 
b/clang/lib/Driver/ToolChains/Arch/RISCV.h
index fcaf9d57ad13d6..388786b9c4c1f4 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.h
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.h
@@ -24,8 +24,8 @@ void getRISCVTargetFeatures(const Driver &D, const 
llvm::Triple &Triple,
 std::vector &Features);
 StringRef getRISCVABI(const llvm::opt::ArgList &Args,
   const llvm::Triple &Triple);
-StringRef getRISCVArch(const llvm::opt::ArgList &Args,
-   const llvm::Triple &Triple);
+std::string getRISCVArch(const llvm::opt::ArgList &Args,
+ const llvm::Triple &Triple);
 std::string getRISCVTargetCPU(const llvm::opt::ArgList &Args,
   const llvm::Triple &Triple);
 } // end namespace riscv
diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp 
b/clang/lib/Driver/ToolChains/BareMetal.cpp
index 11f94877a5cff2..852e0442f50a23 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.cpp
+++ b/clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -37,7 +37,7 @@ static bool findRISCVMultilibs(const Driver &D,
const llvm::Triple &TargetTriple,
const ArgList &Args, DetectedMultilibs &Result) 
{
   Multilib::flags_list Flags;
-  StringRef Arch = riscv::getRISCVArch(Args, TargetTriple);
+  std::string Arch = riscv::getRISCVArch(Args, TargetTriple);
   StringRef Abi = tools::riscv::getRISCVABI(Args, TargetTriple);
 
   if (TargetTriple.isRISCV64()) {
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index aa285c39f14b43..c43fd3def6

[clang] [X86][vectorcall] Do not consume register for indirect return value (PR #97939)

2024-07-07 Thread Eli Friedman via cfe-commits

https://github.com/efriedma-quic commented:

It looks like MSVC also applies this rule to fastcall.

Maybe put a boolean in the "state" to try to group together the code for 
specific conventions, instead of directly checking the CC.

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


[clang] [RISCV] Handle empty structs/unions passing in C++ (PR #97315)

2024-07-07 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

> gcc does ignore the empty array case for assigning argument registers in C++. 
> Compare the two cases here https://godbolt.org/z/j4WP89rE8

Oh, you're right, I didn't actually do any testing myself, I was just assuming 
@svs-quic did the right test.

So I guess the previous size==0 check was actually correct.

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


[clang] [TBAA] Emit int TBAA metadata on FP math libcall expf (PR #96025)

2024-07-07 Thread Eli Friedman via cfe-commits


@@ -0,0 +1,43 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// The test may fail as time out on windows
+// REQUIRES: system-linux
+
+// RUN:  %clang -S -O3 -emit-llvm -o - -x c++ %s | FileCheck %s 
-check-prefixes=CHECK,NoNewStructPathTBAA
+// RUN:  %clang -S -O3 -Xclang -new-struct-path-tbaa -emit-llvm -o - -x c++ %s 
| FileCheck %s -check-prefixes=CHECK,NewStructPathTBAA
+

efriedma-quic wrote:

Can you rewrite the test so you don't need to include math.h?  You don't need 
the whole header; you just need `extern "C" float expf(float);`.

We try to avoid including system headers in clang regression tests so the tests 
work consistently across platforms.  If we actually need to run something 
natively for some reason, we it in llvm-test-suite.

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


[clang] [llvm] [PowerPC] Diagnose musttail instead of crash inside backend (PR #93267)

2024-07-07 Thread Eli Friedman via cfe-commits

https://github.com/efriedma-quic approved this pull request.

LGTM

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


[clang-tools-extra] [clang-tidy] Do not warn on const variables in misc-use-internal-linkage (PR #97969)

2024-07-07 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp created 
https://github.com/llvm/llvm-project/pull/97969

Since in C++ they already have implicit internal linkage.

Fixes #97947

>From 07bd62f97d203bbdb865cd4b1e14cef3ead70c80 Mon Sep 17 00:00:00 2001
From: Carlos Galvez 
Date: Sun, 7 Jul 2024 21:11:54 +0200
Subject: [PATCH] [clang-tidy] Do not warn on const variables in
 misc-use-internal-linkage

Since in C++ they already have implicit internal linkage.

Fixes #97947
---
 .../clang-tidy/misc/UseInternalLinkageCheck.cpp | 6 ++
 .../clang-tidy/checkers/misc/use-internal-linkage-var.cpp   | 3 +++
 2 files changed, 9 insertions(+)

diff --git a/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp
index 44ccc2bc906a5..c086e7721e02b 100644
--- a/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp
@@ -121,6 +121,12 @@ void UseInternalLinkageCheck::check(const 
MatchFinder::MatchResult &Result) {
 return;
   }
   if (const auto *VD = Result.Nodes.getNodeAs("var")) {
+// In C++, const variables at file scope have implicit internal linkage,
+// so we should not warn there. This is not the case in C.
+// https://eel.is/c++draft/diff#basic-3
+if (getLangOpts().CPlusPlus && VD->getType().isConstQualified())
+  return;
+
 DiagnosticBuilder DB = diag(VD->getLocation(), Message) << "variable" << 
VD;
 SourceLocation FixLoc = VD->getTypeSpecStartLoc();
 if (FixLoc.isInvalid() || FixLoc.isMacroID())
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-var.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-var.cpp
index 01b8d28e61230..6777ce4bb0265 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-var.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-var.cpp
@@ -42,3 +42,6 @@ int global_in_extern_c_1;
 }
 
 extern "C" int global_in_extern_c_2;
+
+const int const_global = 123;
+constexpr int constexpr_global = 123;

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


[clang-tools-extra] [clang-tidy] Do not warn on const variables in misc-use-internal-linkage (PR #97969)

2024-07-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Carlos Galvez (carlosgalvezp)


Changes

Since in C++ they already have implicit internal linkage.

Fixes #97947

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


2 Files Affected:

- (modified) clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp (+6) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-var.cpp 
(+3) 


``diff
diff --git a/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp
index 44ccc2bc906a5b..c086e7721e02bd 100644
--- a/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UseInternalLinkageCheck.cpp
@@ -121,6 +121,12 @@ void UseInternalLinkageCheck::check(const 
MatchFinder::MatchResult &Result) {
 return;
   }
   if (const auto *VD = Result.Nodes.getNodeAs("var")) {
+// In C++, const variables at file scope have implicit internal linkage,
+// so we should not warn there. This is not the case in C.
+// https://eel.is/c++draft/diff#basic-3
+if (getLangOpts().CPlusPlus && VD->getType().isConstQualified())
+  return;
+
 DiagnosticBuilder DB = diag(VD->getLocation(), Message) << "variable" << 
VD;
 SourceLocation FixLoc = VD->getTypeSpecStartLoc();
 if (FixLoc.isInvalid() || FixLoc.isMacroID())
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-var.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-var.cpp
index 01b8d28e612301..6777ce4bb0265e 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-var.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/misc/use-internal-linkage-var.cpp
@@ -42,3 +42,6 @@ int global_in_extern_c_1;
 }
 
 extern "C" int global_in_extern_c_2;
+
+const int const_global = 123;
+constexpr int constexpr_global = 123;

``




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


[clang] [llvm] [Clang][OpenMP] This is addition fix for #92210. (PR #94802)

2024-07-07 Thread Alexey Bataev via cfe-commits

alexey-bataev wrote:

> Hi Alexey,
> 
> Thank you take look!
> 
> 
> 
> > Missed one thing, the assignments for boolean flags must be |=, otherwise 
> > we may miss some combinations.
> 
> 
> 
> Are you talking about assignment of following?
> 
> HasMapBasePtr = any_of(M, [](c..
> 
> 
> 
> Do I need to change to:
> 
> HasMapBasePtr |= any_of(M, [](c
> 
> 
> 
> Thanks.  
> 
> Jennifer

Yes, I thought it matches the original code behavior.

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


[clang] [lldb] [clang][RecordLayoutBuilder] Be stricter about inferring packed-ness in ExternalLayouts (PR #97443)

2024-07-07 Thread Eli Friedman via cfe-commits

https://github.com/efriedma-quic commented:

If I'm understanding correctly, the way this currently works is that you do 
normal field layout, then if you discover that the actual offset of a field is 
less than the offset normal field layout would produce, you assume the struct 
is packed.  This misses cases where a struct is packed, but the packing doesn't 
affect the offset of any of the fields.  But as you note, this can't be fixed 
without adjusting the overall architecture.

There's an issue with the current implementation: it skips fields which 
actually are packed, I think.  Consider the following:

```
struct Empty {};
struct __attribute((packed)) S {
  [[no_unique_address]] Empty a,b,c,d;
  char x;
  int y;
};
S s;
```

In this case, the field "y" is both overlapping, and at a packed offset.  
Really, you don't want to check for overlap; you want to ignore empty fields.  
(Non-empty fields can't overlap.)

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


[clang] [libcxx] [Clang] Implement CWG2137 (list-initialization from objects of the same type) (PR #94355)

2024-07-07 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok updated 
https://github.com/llvm/llvm-project/pull/94355

>From ac803f979f2779da35a006988d2d42cdabbad252 Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Sat, 22 Jul 2023 20:07:00 +0100
Subject: [PATCH 1/6] [SemaCXX] Implement CWG2137 (list-initialization from
 objects of the same type)

Differential Revision: https://reviews.llvm.org/D156032

---

This is a cherry-pick from 
https://github.com/llvm/llvm-project/pull/77768/commits/644ec10fc357f70ca8af94ae6544e9631021eb5e
---
 clang/docs/ReleaseNotes.rst   |  3 ++
 clang/lib/Sema/SemaInit.cpp   | 14 +++---
 clang/lib/Sema/SemaOverload.cpp   | 38 +++-
 clang/test/CXX/drs/cwg14xx.cpp| 10 -
 clang/test/CXX/drs/cwg21xx.cpp| 45 +++
 clang/www/cxx_dr_status.html  |  2 +-
 .../pairs.pair/ctor.pair_U_V_move.pass.cpp| 21 -
 7 files changed, 104 insertions(+), 29 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 99580c0d28a4fd..818fa160ef9848 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -254,6 +254,9 @@ Resolutions to C++ Defect Reports
 - Clang now requires a template argument list after a template keyword.
   (`CWG96: Syntactic disambiguation using the template keyword 
`_).
 
+- Implemented `CWG2137 `_ which allows
+  list-initialization from objects of the same type.
+
 C Language Changes
 --
 
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 79bdc8e9f87838..6aa0ebeeaa11fc 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -4231,7 +4231,7 @@ static OverloadingResult ResolveConstructorOverload(
 /// \param IsListInit Is this list-initialization?
 /// \param IsInitListCopy Is this non-list-initialization resulting from a
 ///   list-initialization from {x} where x is the same
-///   type as the entity?
+///   aggregate type as the entity?
 static void TryConstructorInitialization(Sema &S,
  const InitializedEntity &Entity,
  const InitializationKind &Kind,
@@ -4271,8 +4271,8 @@ static void TryConstructorInitialization(Sema &S,
   // ObjC++: Lambda captured by the block in the lambda to block conversion
   // should avoid copy elision.
   if (S.getLangOpts().CPlusPlus17 && !RequireActualConstructor &&
-  UnwrappedArgs.size() == 1 && UnwrappedArgs[0]->isPRValue() &&
-  S.Context.hasSameUnqualifiedType(UnwrappedArgs[0]->getType(), DestType)) 
{
+  Args.size() == 1 && Args[0]->isPRValue() &&
+  S.Context.hasSameUnqualifiedType(Args[0]->getType(), DestType)) {
 // Convert qualifications if necessary.
 Sequence.AddQualificationConversionStep(DestType, VK_PRValue);
 if (ILE)
@@ -4603,9 +4603,9 @@ static void TryListInitialization(Sema &S,
 return;
   }
 
-  // C++11 [dcl.init.list]p3, per DR1467:
-  // - If T is a class type and the initializer list has a single element of
-  //   type cv U, where U is T or a class derived from T, the object is
+  // C++11 [dcl.init.list]p3, per DR1467 and DR2137:
+  // - If T is an aggregate class and the initializer list has a single element
+  //   of type cv U, where U is T or a class derived from T, the object is
   //   initialized from that element (by copy-initialization for
   //   copy-list-initialization, or by direct-initialization for
   //   direct-list-initialization).
@@ -4616,7 +4616,7 @@ static void TryListInitialization(Sema &S,
   // - Otherwise, if T is an aggregate, [...] (continue below).
   if (S.getLangOpts().CPlusPlus11 && InitList->getNumInits() == 1 &&
   !IsDesignatedInit) {
-if (DestType->isRecordType()) {
+if (DestType->isRecordType() && DestType->isAggregateType()) {
   QualType InitType = InitList->getInit(0)->getType();
   if (S.Context.hasSameUnqualifiedType(InitType, DestType) ||
   S.IsDerivedFrom(InitList->getBeginLoc(), InitType, DestType)) {
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 6c4ce1022ae274..b6d6d9d1ef3af3 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -1628,19 +1628,37 @@ TryUserDefinedConversion(Sema &S, Expr *From, QualType 
ToType,
 //   called for those cases.
 if (CXXConstructorDecl *Constructor
   = dyn_cast(ICS.UserDefined.ConversionFunction)) {
-  QualType FromCanon
-= S.Context.getCanonicalType(From->getType().getUnqualifiedType());
+  QualType FromType;
+  SourceLocation FromLoc;
+  // C++11 [over.ics.list]p6, per DR2137:
+  // C++17 [over.ics.list]p6:
+  //   If C is not an initializer-list constructor and the initializer list
+  //   has a single element of type cv U,

[libunwind] [libunwind] fix unwinding from signal handler (PR #92291)

2024-07-07 Thread Saleem Abdulrasool via cfe-commits


@@ -365,7 +365,12 @@ int DwarfInstructions::stepWithDwarf(A 
&addressSpace, pint_t pc,
 
   // Return address is address after call site instruction, so setting IP 
to
   // that does simulates a return.
-  newRegisters.setIP(returnAddress);
+  //
+  // In case of this is frame of signal handler, the IP should be
+  // incremented, because the IP saved in the signal handler points to
+  // first non-executed instruction, while FDE/CIE expects IP to be after
+  // the first non-executed instruction.
+  newRegisters.setIP(returnAddress + cieInfo.isSignalFrame);

compnerd wrote:

I guess I'm thinking about someone using libunwind and manually walking the 
FDE. The single step alters the register state (`.setIP`). As long as you are 
just walking the FDE for unwinding as we do it is fine, but were someone to do 
something non-standard in between, it would just give you an unaligned IP.

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


[clang] [lldb] [HLSL] Implement intangible AST type (PR #97362)

2024-07-07 Thread Chris B via cfe-commits

https://github.com/llvm-beanz commented:

Few comments, but mostly I really like this direction!

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


[clang] [lldb] [HLSL] Implement intangible AST type (PR #97362)

2024-07-07 Thread Chris B via cfe-commits


@@ -3428,6 +3428,12 @@ void CXXNameMangler::mangleType(const BuiltinType *T) {
 Out << 'u' << type_name.size() << type_name;   
\
 break;
 #include "clang/Basic/AMDGPUTypes.def"
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId)
\
+  case BuiltinType::Id:
\
+type_name = #Name; 
\
+Out << type_name.size() << type_name;  
\

llvm-beanz wrote:

```suggestion
Out << 'u' << type_name.size() << type_name;   \
```

The `u` is significant here because it denotes a vendor-specific builtin type 
(see: https://itanium-cxx-abi.github.io/cxx-abi/abi-mangling.html).

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


[clang] [lldb] [HLSL] Implement intangible AST type (PR #97362)

2024-07-07 Thread Chris B via cfe-commits

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


[clang] [lldb] [HLSL] Implement intangible AST type (PR #97362)

2024-07-07 Thread Chris B via cfe-commits


@@ -8001,6 +8001,12 @@ NamedDecl *Sema::ActOnVariableDeclarator(
 }
   }
 
+  if (getLangOpts().HLSL) {
+if (R->isHLSLSpecificType() && !NewVD->isImplicit()) {
+  Diag(D.getBeginLoc(), diag::err_hlsl_intangible_type_cannot_be_declared);

llvm-beanz wrote:

Is the intent here to basically say that you can't create these types unless 
the declaration is implicit? I know we don't expose handle types in DXC, but do 
we really need to force these to be invalid in source?

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


[clang] [lldb] [HLSL] Implement intangible AST type (PR #97362)

2024-07-07 Thread Chris B via cfe-commits


@@ -12335,6 +12335,10 @@ def warn_hlsl_availability_unavailable :
   Warning,
   InGroup, DefaultError;
 
+def err_hlsl_intangible_type_cannot_be_declared : Error<
+"HLSL intangible type cannot be declared here">;
+def err_hlsl_intangible_type_as_function_arg_or_return : Error<
+"HLSL intangible type cannot be used as function %select{argument|return 
value}0">;

llvm-beanz wrote:

I don't think this is correct. We do allow resources as argument and return 
types.

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


[clang] [lldb] [HLSL] Implement intangible AST type (PR #97362)

2024-07-07 Thread Chris B via cfe-commits


@@ -0,0 +1,33 @@
+//===-- HLSLIntangibleTypes.def - HLSL standard intangible types *- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file defines HLSL standard intangible types. These are implementation-
+// defined types such as handle types that have no defined object 
+// representation or value representation and their size is unknown at compile
+// time.
+//
+// The macro is:
+//
+//HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId)
+//
+// where:
+//
+//  - Name is the name of the builtin type.
+//
+//  - BuiltinType::Id is the enumerator defining the type.
+//
+//  - Context.SingletonId is the global singleton of this type.
+//
+// To include this file, define HLSL_INTANGIBLE_TYPE.
+// The macro will be undefined after inclusion.
+//
+//===--===//
+
+HLSL_INTANGIBLE_TYPE(__builtin_hlsl_resource_t, HLSLResource, HLSLResourceTy)

llvm-beanz wrote:

I don't know if we have any cases where a type is prefixed by `__builtin`, 
usually types are `__clang` or  `__` (e.g. `__arm`, `__amdgpu`). Maybe 
we should just do `__hlsl`?

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


[clang] [clang][C23] N3006 Underspecified object declarations (PR #79845)

2024-07-07 Thread Guillot Tony via cfe-commits

https://github.com/to268 updated https://github.com/llvm/llvm-project/pull/79845

>From 5cd7ca393c35ea31f76ceae522d9cd480f9381f1 Mon Sep 17 00:00:00 2001
From: Guillot Tony 
Date: Mon, 29 Jan 2024 15:14:32 +0100
Subject: [PATCH 1/5] Implementation base of N3006 Underspecified object
 declarations

---
 clang/docs/ReleaseNotes.rst   |  5 +++-
 .../clang/Basic/DiagnosticSemaKinds.td|  2 ++
 clang/lib/Sema/SemaExpr.cpp   | 27 +++
 clang/test/C/C23/n3006.c  | 27 +++
 clang/test/Parser/c2x-underspecified-decls.c  | 12 +
 clang/www/c_status.html   |  2 +-
 6 files changed, 73 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/C/C23/n3006.c
 create mode 100644 clang/test/Parser/c2x-underspecified-decls.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 838cb69f647ee..56dcf5baf6b52 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -99,7 +99,7 @@ ABI Changes in This Version
   ifuncs. Its purpose was to preserve backwards compatibility when the ".ifunc"
   suffix got removed from the name mangling. The alias interacts badly with
   GlobalOpt (see the issue #96197).
-  
+
 - Fixed Microsoft name mangling for auto non-type template arguments of pointer
   type for MSVC 1920+. This change resolves incompatibilities with code 
compiled
   by MSVC 1920+ but will introduce incompatibilities with code compiled by
@@ -348,6 +348,9 @@ C23 Feature Support
   but C23 added them to  in
   `WG14 N2848 `_.
 
+- Clang now diagnoses `N3006 Underspecified object declarations
+  `_.
+
 Non-comprehensive list of changes in this release
 -
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 44fd51ec9abc9..618605a5b0f2e 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7779,6 +7779,8 @@ def err_attribute_arm_mve_polymorphism : Error<
   "'__clang_arm_mve_strict_polymorphism' attribute can only be applied to an 
MVE/NEON vector type">;
 def err_attribute_webassembly_funcref : Error<
   "'__funcref' attribute can only be applied to a function pointer type">;
+def err_c23_underspecified_object_declaration: Error<
+  "'%select{struct||union||enum}0 %1' is defined as an 
underspecified object initializer">;
 
 def warn_setter_getter_impl_required : Warning<
   "property %0 requires method %1 to be defined - "
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 852344d895ffd..c0616c3047015 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6978,6 +6978,33 @@ Sema::BuildCompoundLiteralExpr(SourceLocation LParenLoc, 
TypeSourceInfo *TInfo,
diagID))
 return ExprError();
 }
+  } else if (LangOpts.C23 &&
+ (literalType->isRecordType() || literalType->isEnumeralType())) {
+// C23 6.2.1p7: Structure, union, and enumeration tags have scope that
+// begins just after the appearance of the tag in a type specifier that
+// declares the tag.
+// [...]
+// An ordinary identifier that has an underspecified definition has scope
+// that starts when the definition is completed; if the same ordinary
+// identifier declares another entity with a scope that encloses the 
current
+// block, that declaration is hidden as soon as the inner declarator is
+// completed*.)
+// [...]
+// *) That means, that the outer declaration is not visible for the
+// initializer.
+auto Range = SourceRange(LParenLoc, RParenLoc);
+const auto *Tag = literalType->castAs();
+const auto &TagRange = Tag->getDecl()->getSourceRange();
+
+// We should diagnose underspecified declaration, unless the identifier has
+// been diagnosed as being a redefinition, since the tag is made anonymous.
+if (Range.fullyContains(TagRange) && Tag->getDecl()->getIdentifier()) {
+  Diag(TagRange.getBegin(),
+   diag::err_c23_underspecified_object_declaration)
+  << (unsigned)Tag->getDecl()->getTagKind()
+  << Tag->getDecl()->getName() << TagRange;
+  return ExprError();
+}
   } else if (!literalType->isDependentType() &&
  RequireCompleteType(LParenLoc, literalType,
diag::err_typecheck_decl_incomplete_type,
diff --git a/clang/test/C/C23/n3006.c b/clang/test/C/C23/n3006.c
new file mode 100644
index 0..15efc0ccd6d32
--- /dev/null
+++ b/clang/test/C/C23/n3006.c
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -std=c2x -verify %s
+
+/* WG14 N3006: Full
+ * Underspecified object declarations
+ */
+
+struct S1 { int x, y; };// expected-note {{previous definition

[clang] afd0e6d - [PowerPC] Diagnose musttail instead of crash inside backend (#93267)

2024-07-07 Thread via cfe-commits

Author: Chen Zheng
Date: 2024-07-08T09:30:01+08:00
New Revision: afd0e6d06ba05cf3cd8b0bb91b6506242de78a4d

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

LOG: [PowerPC] Diagnose musttail instead of crash inside backend (#93267)

musttail is not often possible to be generated on PPC targets as when
calling to a function defined in another module, PPC needs to restore
the TOC pointer. To restore the TOC pointer, compiler needs to emit a
nop after the call to let linker generate codes to restore TOC pointer.
Tail call cannot generate expected call sequence for this case.

To avoid the crash inside the compiler backend, a diagnosis is added in
the frontend.

Fixes #63214

Added: 
clang/test/CodeGen/PowerPC/musttail-forward-declaration-inline.c
clang/test/CodeGen/PowerPC/musttail-forward-declaration-weak.c
clang/test/CodeGen/PowerPC/musttail-forward-declaration.c
clang/test/CodeGen/PowerPC/musttail-indirect.cpp
clang/test/CodeGen/PowerPC/musttail-inline.c
clang/test/CodeGen/PowerPC/musttail-undefined.c
clang/test/CodeGen/PowerPC/musttail-weak.c
clang/test/CodeGen/PowerPC/musttail.c

Modified: 
clang/include/clang/Basic/DiagnosticCommonKinds.td
clang/lib/Basic/Targets/PPC.cpp
clang/lib/Basic/Targets/PPC.h
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenModule.h

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index de758cbe679dcf..33b1d58bb5b099 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -367,6 +367,15 @@ def warn_target_unrecognized_env : Warning<
 def err_target_unsupported_abi_with_fpu : Error<
   "'%0' ABI is not supported with FPU">;
 
+def err_ppc_impossible_musttail: Error<
+  "'musttail' attribute for this call is impossible because %select{"
+  "long calls can not be tail called on PPC|"
+  "indirect calls can not be tail called on PPC|"
+  "external calls can not be tail called on PPC}0"
+  >;
+def err_aix_musttail_unsupported: Error<
+  "'musttail' attribute is not supported on AIX">;
+
 // Source manager
 def err_cannot_open_file : Error<"cannot open file '%0': %1">, DefaultFatal;
 def err_file_modified : Error<

diff  --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index 89c5566f7ad091..4ba4a49311d36b 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -93,6 +93,8 @@ bool 
PPCTargetInfo::handleTargetFeatures(std::vector &Features,
   HasQuadwordAtomics = true;
 } else if (Feature == "+aix-shared-lib-tls-model-opt") {
   HasAIXShLibTLSModelOpt = true;
+} else if (Feature == "+longcall") {
+  UseLongCalls = true;
 }
 // TODO: Finish this list and add an assert that we've handled them
 // all.
@@ -728,6 +730,7 @@ bool PPCTargetInfo::hasFeature(StringRef Feature) const {
   .Case("isa-v31-instructions", IsISA3_1)
   .Case("quadword-atomics", HasQuadwordAtomics)
   .Case("aix-shared-lib-tls-model-opt", HasAIXShLibTLSModelOpt)
+  .Case("longcall", UseLongCalls)
   .Default(false);
 }
 

diff  --git a/clang/lib/Basic/Targets/PPC.h b/clang/lib/Basic/Targets/PPC.h
index e4d6a02386da58..b15ab6fbcf492f 100644
--- a/clang/lib/Basic/Targets/PPC.h
+++ b/clang/lib/Basic/Targets/PPC.h
@@ -82,6 +82,7 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public 
TargetInfo {
   bool IsISA3_1 = false;
   bool HasQuadwordAtomics = false;
   bool HasAIXShLibTLSModelOpt = false;
+  bool UseLongCalls = false;
 
 protected:
   std::string ABI;

diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 2b301130ef7b70..7e7b2b395f7d63 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -5751,8 +5751,35 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   if (llvm::CallInst *Call = dyn_cast(CI)) {
 if (TargetDecl && TargetDecl->hasAttr())
   Call->setTailCallKind(llvm::CallInst::TCK_NoTail);
-else if (IsMustTail)
+else if (IsMustTail) {
+  if (getTarget().getTriple().isPPC()) {
+if (getTarget().getTriple().isOSAIX())
+  CGM.getDiags().Report(Loc, diag::err_aix_musttail_unsupported);
+else if (!getTarget().hasFeature("pcrelative-memops")) {
+  if (getTarget().hasFeature("longcall"))
+CGM.getDiags().Report(Loc, diag::err_ppc_impossible_musttail) << 0;
+  else if (Call->isIndirectCall())
+CGM.getDiags().Report(Loc, diag::err_ppc_impossible_musttail) << 1;
+  else if (isa_and_nonnull(TargetDecl)) {
+if (!cast(TargetDecl)->isDefined())
+  // The undefined callee m

[clang] [llvm] [PowerPC] Diagnose musttail instead of crash inside backend (PR #93267)

2024-07-07 Thread Chen Zheng via cfe-commits

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


[clang] [Doc] Update documentation for no-transitive-change (PR #96453)

2024-07-07 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 updated 
https://github.com/llvm/llvm-project/pull/96453

>From a035ae25314f3168f73108988f2bb7671e7d9e7f Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Mon, 24 Jun 2024 11:41:23 +0800
Subject: [PATCH 1/5] [Doc] Update documentation for no-transitive-change

---
 clang/docs/ReleaseNotes.rst |   4 +
 clang/docs/StandardCPlusPlusModules.rst | 128 
 2 files changed, 132 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9c8f8c4a4fbaf..89e433870c9ff 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -229,6 +229,10 @@ C++20 Feature Support
   will now work.
   (#GH62925).
 
+- Clang refactored the BMI format to make it possible to support no transitive 
changes
+  mode for modules. See `StandardCPlusPlusModules 
`_ for
+  details.
+
 C++23 Feature Support
 ^
 
diff --git a/clang/docs/StandardCPlusPlusModules.rst 
b/clang/docs/StandardCPlusPlusModules.rst
index 1c3c4d319c0e1..68854636e617d 100644
--- a/clang/docs/StandardCPlusPlusModules.rst
+++ b/clang/docs/StandardCPlusPlusModules.rst
@@ -652,6 +652,134 @@ in the future. The expected roadmap for Reduced BMIs as 
of Clang 19.x is:
comes, the term BMI will refer to the Reduced BMI and the Full BMI will only
be meaningful to build systems which elect to support two-phase compilation.
 
+Experimental No Transitive Change
+-
+
+Starting with clang19.x, we introduced an experimental feature: the 
non-transitive
+change for modules, aimed at reducing unnecessary recompilations. For example,
+
+.. code-block:: c++
+
+  // m-partA.cppm
+  export module m:partA;
+
+  // m-partB.cppm
+  export module m:partB;
+  export int getB() { return 44; }
+
+  // m.cppm
+  export module m;
+  export import :partA;
+  export import :partB;
+
+  // useBOnly.cppm
+  export module useBOnly;
+  import m;
+  export int B() {
+return getB();
+  }
+
+  // Use.cc
+  import useBOnly;
+  int get() {
+return B();
+  }
+
+Now let's compile the project (For brevity, some commands are omitted.):
+
+.. code-block:: console
+
+  $ clang++ -std=c++20 m-partA.cppm --precompile -o m-partA.pcm
+  $ clang++ -std=c++20 m-partB.cppm --precompile -o m-partB.pcm
+  $ clang++ -std=c++20 m.cppm --precompile -o m.pcm -fprebuilt-module-path=.
+  $ clang++ -std=c++20 useBOnly.cppm --precompile -o useBOnly.pcm 
-fprebuilt-module-path=.
+  $ md5sum useBOnly.pcm
+  07656bf4a6908626795729295f9608da  useBOnly.pcm
+
+then let's change the interface of ``m-partA.cppm`` to:
+
+.. code-block:: c++
+
+  // m-partA.v1.cppm
+  export module m:partA;
+  export int getA() { return 43; }
+
+Let's compile the BMI for `useBOnly` again:
+
+.. code-block:: console
+
+  $ clang++ -std=c++20 m-partA.cppm --precompile -o m-partA.pcm
+  $ clang++ -std=c++20 m-partB.cppm --precompile -o m-partB.pcm
+  $ clang++ -std=c++20 m.cppm --precompile -o m.pcm -fprebuilt-module-path=.
+  $ clang++ -std=c++20 useBOnly.cppm --precompile -o useBOnly.pcm 
-fprebuilt-module-path=.
+  $ md5sum useBOnly.pcm
+  07656bf4a6908626795729295f9608da  useBOnly.pcm
+
+We observed that the contents of useBOnly.pcm remain unchanged.
+Consequently, if the build system bases recompilation decisions on directly 
imported modules only,
+it becomes possible to skip the recompilation of Use.cc.
+It should be fine because the altered interfaces do not affect Use.cc in any 
way.
+This concept is called as no transitive changes.
+
+When clang generates a BMI, it records the hash values of all potentially 
contributory BMIs
+into the currently written BMI. This ensures that build systems are not 
required to consider
+transitively imported modules when deciding on recompilations.
+
+The definition for potential contributory BMIs is implementation defined. We 
don't intend to
+display detailed rules for users. The contract is:
+
+1. It is a severe bug if a BMI remains unchanged erroneously following an 
observable change
+   that affects its users.
+2. It is an potential improvement opportunity if a BMI changes after an 
unobservable change
+   happens.
+
+We suggest build systems to support this feature as a configurable option for 
a long time.
+So that users can go back to the transitive change mode safely at any time.
+
+Interactions with Reduced BMI
+~
+
+With reduced BMI, the no transitive change feature can be more powerful if the 
change
+can be reduced. For example,
+
+.. code-block:: c++
+
+  // A.cppm
+  export module A;
+  export int a() { return 44; }
+
+  // B.cppm
+  export module B;
+  import A;
+  export int b() { return a(); }
+
+.. code-block:: console
+
+  $ clang++ -std=c++20 A.cppm -c -fmodule-output=A.pcm  
-fexperimental-modules-reduced-bmi -o A.o
+  $ clang++ -std=c++20 B.cppm -c -fmodule-output=B.pcm  
-fexperimental-modules-reduced-bmi -o B.o -fmodule-file=A=A.pcm
+  $md5sum B.pcm
+  6c2bd452ca32ab418bf35cd141b060b9  B.

[clang] [Doc] Update documentation for no-transitive-change (PR #96453)

2024-07-07 Thread Chuanqi Xu via cfe-commits


@@ -652,6 +652,141 @@ in the future. The expected roadmap for Reduced BMIs as 
of Clang 19.x is:
comes, the term BMI will refer to the Reduced BMI and the Full BMI will only
be meaningful to build systems which elect to support two-phase compilation.
 
+Experimental No Transitive Change
+-
+
+This section is primarily for build system vendors. For end compiler users,
+if you don't want to read it all, this is helpful to reduce recompilations
+We encourage build system vendors and end users try this out and bring 
feedbacks
+
+Before Clang 19, a change in BMI of any (transitive) dependency would case the
+outputs of the BMI to change. Starting with Clang 19, changes to non-direct
+dependencies should not directly affect the output BMI, unless they affect the
+results of the compilations. We expect that there are many more opportunities
+for this optimization than we currently have realized and would appreaciate 
+feedback about missed optimization opportunities. For example,
+
+.. code-block:: c++
+
+  // m-partA.cppm
+  export module m:partA;
+
+  // m-partB.cppm
+  export module m:partB;
+  export int getB() { return 44; }
+
+  // m.cppm
+  export module m;
+  export import :partA;
+  export import :partB;
+
+  // useBOnly.cppm
+  export module useBOnly;
+  import m;
+  export int B() {
+return getB();
+  }
+
+  // Use.cc
+  import useBOnly;
+  int get() {
+return B();
+  }
+
+To compile the project (for brevity, some commands are omitted.):
+
+.. code-block:: console
+
+  $ clang++ -std=c++20 m-partA.cppm --precompile -o m-partA.pcm
+  $ clang++ -std=c++20 m-partB.cppm --precompile -o m-partB.pcm
+  $ clang++ -std=c++20 m.cppm --precompile -o m.pcm -fprebuilt-module-path=.
+  $ clang++ -std=c++20 useBOnly.cppm --precompile -o useBOnly.pcm 
-fprebuilt-module-path=.
+  $ md5sum useBOnly.pcm
+  07656bf4a6908626795729295f9608da  useBOnly.pcm
+
+If the interface of ``m-partA.cppm`` is changed to:
+
+.. code-block:: c++
+
+  // m-partA.v1.cppm
+  export module m:partA;
+  export int getA() { return 43; }
+
+and the BMI for ``useBOnly`` is recompiled as in:
+
+.. code-block:: console
+
+  $ clang++ -std=c++20 m-partA.cppm --precompile -o m-partA.pcm
+  $ clang++ -std=c++20 m-partB.cppm --precompile -o m-partB.pcm
+  $ clang++ -std=c++20 m.cppm --precompile -o m.pcm -fprebuilt-module-path=.
+  $ clang++ -std=c++20 useBOnly.cppm --precompile -o useBOnly.pcm 
-fprebuilt-module-path=.
+  $ md5sum useBOnly.pcm
+  07656bf4a6908626795729295f9608da  useBOnly.pcm
+
+then the contents of ``useBOnly.pcm`` remain unchanged.
+Consequently, if the build system only bases recompilation decisions on 
directly imported modules,
+it becomes possible to skip the recompilation of ``Use.cc``.
+It should be fine because the altered interfaces do not affect ``Use.cc`` in 
any way;
+there are no transitive changes.
+
+When clang generates a BMI, it records the hash values of all potentially 
contributory BMIs
+for the BMI being produced. This ensures that build systems are not required 
to consider
+transitively imported modules when deciding whether to recompile.
+
+What is considered to be a potential contributory BMIs is currently 
unspecified.
+However, it is a severe bug for a BMI to remain unchanged following an 
observable change
+that affects its consumers.
+
+We recommend that build systems support this feature as a configurable option 
so that users
+can go back to the transitive change mode safely at any time.

ChuanqiXu9 wrote:

Suggestion Added

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


[clang] [X86][vectorcall] Do not consume register for indirect return value (PR #97939)

2024-07-07 Thread Phoebe Wang via cfe-commits

https://github.com/phoebewang updated 
https://github.com/llvm/llvm-project/pull/97939

>From cf19ec8d705434ca6d989a72069dba1040c360ca Mon Sep 17 00:00:00 2001
From: Phoebe Wang 
Date: Sun, 7 Jul 2024 13:14:59 +0800
Subject: [PATCH 1/2] [X86][vectorcall] Do not consume register for indirect
 return value

This is how MSVC handles it. https://godbolt.org/z/Eav3vx7cd
---
 clang/lib/CodeGen/Targets/X86.cpp | 2 +-
 clang/test/CodeGen/vectorcall.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index 3146caba1c615..3c0947589ce3d 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -469,7 +469,7 @@ bool X86_32ABIInfo::canExpandIndirectArgument(QualType Ty) 
const {
 ABIArgInfo X86_32ABIInfo::getIndirectReturnResult(QualType RetTy, CCState 
&State) const {
   // If the return value is indirect, then the hidden argument is consuming one
   // integer register.
-  if (State.FreeRegs) {
+  if (State.CC != llvm::CallingConv::X86_VectorCall && State.FreeRegs) {
 --State.FreeRegs;
 if (!IsMCUABI)
   return getNaturalAlignIndirectInReg(RetTy);
diff --git a/clang/test/CodeGen/vectorcall.c b/clang/test/CodeGen/vectorcall.c
index 71dc3b0b9585a..cab7fc0972d7b 100644
--- a/clang/test/CodeGen/vectorcall.c
+++ b/clang/test/CodeGen/vectorcall.c
@@ -90,7 +90,7 @@ struct HVA4 __vectorcall hva6(struct HVA4 a, struct HVA4 b) { 
return b;}
 // X64: define dso_local x86_vectorcallcc %struct.HVA4 
@"\01hva6@@128"(%struct.HVA4 inreg %a.coerce, ptr noundef %b)
 
 struct HVA5 __vectorcall hva7(void) {struct HVA5 a = {}; return a;}
-// X86: define dso_local x86_vectorcallcc void @"\01hva7@@0"(ptr 
dead_on_unwind inreg noalias writable sret(%struct.HVA5) align 16 %agg.result)
+// X86: define dso_local x86_vectorcallcc void @"\01hva7@@0"(ptr 
dead_on_unwind noalias writable sret(%struct.HVA5) align 16 %agg.result)
 // X64: define dso_local x86_vectorcallcc void @"\01hva7@@0"(ptr 
dead_on_unwind noalias writable sret(%struct.HVA5) align 16 %agg.result)
 
 v4f32 __vectorcall hva8(v4f32 a, v4f32 b, v4f32 c, v4f32 d, int e, v4f32 f) 
{return f;}

>From 48ef23c72544bd9f7a862ab9dc17d46945de1a59 Mon Sep 17 00:00:00 2001
From: Phoebe Wang 
Date: Mon, 8 Jul 2024 10:01:00 +0800
Subject: [PATCH 2/2] Change for fastcall too

---
 clang/lib/CodeGen/Targets/X86.cpp | 3 ++-
 clang/test/CodeGen/stdcall-fastcall.c | 6 ++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index 3c0947589ce3d..1dc3172a6bdf9 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -469,7 +469,8 @@ bool X86_32ABIInfo::canExpandIndirectArgument(QualType Ty) 
const {
 ABIArgInfo X86_32ABIInfo::getIndirectReturnResult(QualType RetTy, CCState 
&State) const {
   // If the return value is indirect, then the hidden argument is consuming one
   // integer register.
-  if (State.CC != llvm::CallingConv::X86_VectorCall && State.FreeRegs) {
+  if (State.CC != llvm::CallingConv::X86_FastCall &&
+  State.CC != llvm::CallingConv::X86_VectorCall && State.FreeRegs) {
 --State.FreeRegs;
 if (!IsMCUABI)
   return getNaturalAlignIndirectInReg(RetTy);
diff --git a/clang/test/CodeGen/stdcall-fastcall.c 
b/clang/test/CodeGen/stdcall-fastcall.c
index f6d86d24463f3..5014b7d48e5b9 100644
--- a/clang/test/CodeGen/stdcall-fastcall.c
+++ b/clang/test/CodeGen/stdcall-fastcall.c
@@ -151,3 +151,9 @@ void bar13(long long a, int b, int c) {
   // CHECK: call x86_fastcallcc void @foo13(i64 noundef %{{.*}}, i32 inreg 
noundef %{{.*}}, i32 inreg noundef %
   foo13(a, b, c);
 }
+
+struct S2 __attribute__((fastcall)) foo14(int a) {
+  // CHECK-LABEL: define dso_local x86_fastcallcc void @foo14(ptr 
dead_on_unwind noalias writable sret(%struct.S2) align 4 %agg.result, i32 inreg 
noundef %a)
+  struct S2 r = {a};
+  return r;
+}

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


[clang] [X86][vectorcall] Do not consume register for indirect return value (PR #97939)

2024-07-07 Thread Phoebe Wang via cfe-commits

phoebewang wrote:

> It looks like MSVC also applies this rule to fastcall.

Good catch, done!
 
> Maybe put a boolean in the "state" to try to group together the code for 
> specific conventions, instead of directly checking the CC.

There are 3 special conventions here: vectorcall, fastcall and regcall. We 
sometime check them all, sometime check one or two of them. I think it's 
impossible to use one boolean to group them.

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


[clang] [llvm] [PowerPC] Diagnose musttail instead of crash inside backend (PR #93267)

2024-07-07 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `sanitizer-x86_64-linux` 
running on `sanitizer-buildbot2` while building `clang` at step 2 "annotate".

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

Here is the relevant piece of the build log for the reference:
```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
llvm-lit: 
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-x86_64-linux/build/build_debug/lib/clang/19/lib/i386-unknown-linux-gnu".
 This path was found by running 
['/b/sanitizer-x86_64-linux/build/build_debug/./bin/clang', 
'--target=x86_64-unknown-linux-gnu', '-m32', '-print-runtime-dir'].
llvm-lit: 
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-x86_64-linux/build/build_debug/lib/clang/19/lib/x86_64-unknown-linux-gnu".
 This path was found by running 
['/b/sanitizer-x86_64-linux/build/build_debug/./bin/clang', 
'--target=x86_64-unknown-linux-gnu', '-m64', '-print-runtime-dir'].
llvm-lit: 
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-x86_64-linux/build/build_debug/lib/clang/19/lib/x86_64-unknown-linux-gnu".
 This path was found by running 
['/b/sanitizer-x86_64-linux/build/build_debug/./bin/clang', 
'--target=x86_64-unknown-linux-gnu', '-Wthread-safety', 
'-Wthread-safety-reference', '-Wthread-safety-beta', '-print-runtime-dir'].
llvm-lit: 
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-x86_64-linux/build/build_debug/lib/clang/19/lib/x86_64-unknown-linux-gnu".
 This path was found by running 
['/b/sanitizer-x86_64-linux/build/build_debug/./bin/clang', 
'--target=x86_64-unknown-linux-gnu', '-m64', '-print-runtime-dir'].
llvm-lit: 
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-x86_64-linux/build/build_debug/lib/clang/19/lib/x86_64-unknown-linux-gnu".
 This path was found by running 
['/b/sanitizer-x86_64-linux/build/build_debug/./bin/clang', 
'--target=x86_64-unknown-linux-gnu', '-m64', '-print-runtime-dir'].
llvm-lit: 
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-x86_64-linux/build/build_debug/lib/clang/19/lib/x86_64-unknown-linux-gnu".
 This path was found by running 
['/b/sanitizer-x86_64-linux/build/build_debug/./bin/clang', 
'--target=x86_64-unknown-linux-gnu', '-m64', '-print-runtime-dir'].
llvm-lit: 
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-x86_64-linux/build/build_debug/lib/clang/19/lib/x86_64-unknown-linux-gnu".
 This path was found by running 
['/b/sanitizer-x86_64-linux/build/build_debug/./bin/clang', 
'--target=x86_64-unknown-linux-gnu', '-m64', '-print-runtime-dir'].
llvm-lit: 
/b/sanitizer-x86_64-linux/build/llvm-project/llvm/utils/lit/lit/main.py:72: 
note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 900 seconds was requested on the command line. Forcing 
timeout to be 900 seconds.
-- Testing: 4348 of 9965 tests, 80 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70..
FAIL: libFuzzer-i386-libcxx-Linux :: fuzzer-finalstats.test (1362 of 4348)
 TEST 'libFuzzer-i386-libcxx-Linux :: 
fuzzer-finalstats.test' FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: /b/sanitizer-x86_64-linux/build/build_debug/./bin/clang
-Wthread-safety -Wthread-safety-reference -Wthread-safety-beta   
--driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer 
-I/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/lib/fuzzer -m32 
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/fuzzer/SimpleTest.cpp
 -o 
/b/sanitizer-x86_64-linux/build/build_debug/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386LibcxxLinuxConfig/Output/fuzzer-finalstats.test.tmp-SimpleTest
+ /b/sanitizer-x86_64-linux/build/build_debug/./bin/clang -Wthread-safety 
-Wthread-safety-reference -Wthread-safety-beta --driver-mode=g++ -O2 
-gline-tables-only -fsanitize=address,fuzzer 
-I/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/lib/fuzzer -m32 
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/fuzzer/SimpleTest.cpp
 -o 
/b/sanitizer-x86_64-linux/build/build_debug/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386LibcxxLinuxConfig/Output/fuzzer-finalstats.test.tmp-SimpleTest
RUN: at line 2: 
/b/sanitizer-x86_64-linux/build/b

[clang] [llvm] [PowerPC] Diagnose musttail instead of crash inside backend (PR #93267)

2024-07-07 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`clang-aarch64-sve-vls-2stage` running on `linaro-g3-04` while building `clang` 
at step 11 "build stage 2".

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

Here is the relevant piece of the build log for the reference:
```
Step 11 (build stage 2) failure: 'ninja' (failure)
...
[7764/8583] Building CXX object 
tools/flang/lib/Optimizer/Builder/CMakeFiles/obj.FIRBuilder.dir/Complex.cpp.o
[7765/8583] Building CXX object 
tools/flang/lib/Semantics/CMakeFiles/obj.FortranSemantics.dir/resolve-names.cpp.o
[7766/8583] Building CXX object 
tools/flang/lib/Frontend/CMakeFiles/obj.flangFrontend.dir/TextDiagnosticBuffer.cpp.o
[7767/8583] Building CXX object 
tools/flang/lib/Optimizer/Builder/CMakeFiles/obj.FIRBuilder.dir/Runtime/Allocatable.cpp.o
[7768/8583] Building CXX object 
tools/flang/lib/Optimizer/Builder/CMakeFiles/obj.FIRBuilder.dir/BoxValue.cpp.o
[7769/8583] Building CXX object 
tools/flang/lib/Frontend/CMakeFiles/obj.flangFrontend.dir/TextDiagnosticPrinter.cpp.o
[7770/8583] Building CXX object 
tools/flang/lib/Optimizer/Builder/CMakeFiles/obj.FIRBuilder.dir/MutableBox.cpp.o
[7771/8583] Building CXX object 
tools/flang/lib/Semantics/CMakeFiles/obj.FortranSemantics.dir/expression.cpp.o
[7772/8583] Linking CXX static library lib/libFortranEvaluate.a
[7773/8583] Building CXX object 
tools/flang/lib/Lower/CMakeFiles/obj.FortranLower.dir/OpenMP/Clauses.cpp.o
FAILED: 
tools/flang/lib/Lower/CMakeFiles/obj.FortranLower.dir/OpenMP/Clauses.cpp.o 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/stage1.install/bin/clang++
 -DFLANG_INCLUDE_TESTS=1 -DFLANG_LITTLE_ENDIAN=1 -DGTEST_HAS_RTTI=0 -D_DEBUG 
-D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-I/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/stage2/tools/flang/lib/Lower
 -I/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/llvm/flang/lib/Lower 
-I/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/llvm/flang/include 
-I/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/stage2/tools/flang/include
 -I/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/stage2/include 
-I/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/llvm/llvm/include 
-isystem 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/llvm/llvm/../mlir/include
 -isystem 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/stage2/tools/mlir/include
 -isystem 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/stage2/tools/clang/include
 -isystem 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/llvm/llvm/../clang/include
 -mcpu=neoverse-512tvb -msve-vector-bits=256 -mllvm 
-treat-scalable-fixed-error-as-warning=false -fPIC -fno-semantic-interposition 
-fvisibility-inlines-hidden -Werror=date-time 
-Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter 
-Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic 
-Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough 
-Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
-Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion 
-Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color 
-ffunction-sections -fdata-sections -Wno-deprecated-copy -Wno-string-conversion 
-Wno-ctad-maybe-unsupported -Wno-unused-command-line-argument 
-Wstring-conversion   -Wcovered-switch-default -Wno-nested-anon-types 
-O3 -DNDEBUG  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -std=c++17 -MD 
-MT tools/flang/lib/Lower/CMakeFiles/obj.FortranLower.dir/OpenMP/Clauses.cpp.o 
-MF 
tools/flang/lib/Lower/CMakeFiles/obj.FortranLower.dir/OpenMP/Clauses.cpp.o.d -o 
tools/flang/lib/Lower/CMakeFiles/obj.FortranLower.dir/OpenMP/Clauses.cpp.o -c 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/llvm/flang/lib/Lower/OpenMP/Clauses.cpp
Killed
[7774/8583] Building CXX object 
tools/flang/lib/Optimizer/Builder/CMakeFiles/obj.FIRBuilder.dir/HLFIRTools.cpp.o
[7775/8583] Building CXX object 
tools/flang/lib/Optimizer/Builder/CMakeFiles/obj.FIRBuilder.dir/Character.cpp.o
[7776/8583] Building CXX object 
tools/flang/lib/Lower/CMakeFiles/obj.FortranLower.dir/IterationSpace.cpp.o
FAILED: 
tools/flang/lib/Lower/CMakeFiles/obj.FortranLower.dir/IterationSpace.cpp.o 
/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/stage1.install/bin/clang++
 -DFLANG_INCLUDE_TESTS=1 -DFLANG_LITTLE_ENDIAN=1 -DGTEST_HAS_RTTI=0 -D_DEBUG 
-D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-I/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/stage2/tools/flang/lib/Lower
 -I/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/llvm/flang/lib/Lower 
-I/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/llvm/flang/include 
-I/home/tcwg-buildbot/worker/clang-aarch64-sve-vls-2stage/stage2/tools/flang/include
 -I/home/tcwg-buildbot/worker/cla

[clang] [Clang] Fix Microsoft ABI inheritance model when member pointer is used in a base specifier (PR #91990)

2024-07-07 Thread Max Winkler via cfe-commits

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

LGTM.

@MitalAshok I noticed in your commit messages you mentioned reworking 
-fcomplete-member-pointers. Will that include fixing clang incorrectly warning 
when an inheritance model is explicitly specified. Godbolt for reference: 
https://godbolt.org/z/rYaWz6sra.

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


[clang] [Clang] Fix Microsoft ABI inheritance model when member pointer is used in a base specifier (PR #91990)

2024-07-07 Thread Max Winkler via cfe-commits

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


[clang] [RISCV] Handle empty structs/unions passing in C++ (PR #97315)

2024-07-07 Thread Sudharsan Veeravalli via cfe-commits

svs-quic wrote:

> Thanks @efriedma-quic. I tried adding a test case for it locally and see that 
> the code produced is different for llvm and gcc: 
> https://godbolt.org/z/vdhGbvj6W
> 
> Test case:
> 
> ```
> struct s12 {int x[0];};
> struct s12 test_s12(struct s12 a) {
>   return a;
> }
> ```
> 
> For llvm this is an empty record of size zero and so it ignores it where as 
> gcc loads 0 into a0. Do we handle this case similar to what gcc does? Or do I 
> add a fixme for now?
> 
> @topperc @asb

What about the case I have mentioned in https://godbolt.org/z/vdhGbvj6W ?

Having a check for both Size==0 and LangOpts.CPlusPlus handles this as well.


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


[clang] [LoongArch][clang] Add support for option `-msimd` and macro ` loonga… (PR #97984)

2024-07-07 Thread Zhaoxin Yang via cfe-commits

https://github.com/ylzsx created https://github.com/llvm/llvm-project/pull/97984

…rch_simd_width`.

>From bd70e74419947c32265d698163722552e80df12f Mon Sep 17 00:00:00 2001
From: yangzhaoxin 
Date: Fri, 5 Jul 2024 10:40:07 +0800
Subject: [PATCH] [LoongArch][clang] Add support for option `-msimd` and macro
 ` loongarch_simd_width`.

---
 .../clang/Basic/DiagnosticDriverKinds.td  |   2 +
 clang/include/clang/Driver/Options.td |   3 +
 clang/lib/Basic/Targets/LoongArch.cpp |   8 +-
 .../lib/Driver/ToolChains/Arch/LoongArch.cpp  |  29 
 clang/test/Driver/loongarch-msimd.c   | 129 ++
 clang/test/Preprocessor/init-loongarch.c  |   3 +
 6 files changed, 172 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Driver/loongarch-msimd.c

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index a62bdc21298ee..243d88d53d664 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -791,6 +791,8 @@ def err_drv_loongarch_wrong_fpu_width : Error<
   "wrong fpu width; %select{LSX|LASX}0 depends on 64-bit FPU">;
 def err_drv_loongarch_invalid_simd_option_combination : Error<
   "invalid option combination; LASX depends on LSX">;
+def err_drv_loongarch_invalid_msimd_EQ : Error<
+  "invalid argument '%0' to -msimd=; must be one of: none, lsx, lasx">;
 
 def err_drv_expand_response_file : Error<
   "failed to expand response file: %0">;
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 58ca6f2bea9e4..707ce8ce78d0b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5252,6 +5252,9 @@ def mlasx : Flag<["-"], "mlasx">, 
Group,
   HelpText<"Enable Loongson Advanced SIMD Extension (LASX).">;
 def mno_lasx : Flag<["-"], "mno-lasx">, Group,
   HelpText<"Disable Loongson Advanced SIMD Extension (LASX).">;
+def msimd_EQ : Joined<["-"], "msimd=">, Group,
+  Flags<[TargetSpecific]>,
+  HelpText<"Select the SIMD extension(s) to be enabled in LoongArch either 
'none', 'lsx', 'lasx'.">;
 def mnop_mcount : Flag<["-"], "mnop-mcount">, HelpText<"Generate 
mcount/__fentry__ calls as nops. To activate they need to be patched in.">,
   Visibility<[ClangOption, CC1Option]>, Group,
   MarshallingInfoFlag>;
diff --git a/clang/lib/Basic/Targets/LoongArch.cpp 
b/clang/lib/Basic/Targets/LoongArch.cpp
index 280bd1d8033cc..75f71a337b7a4 100644
--- a/clang/lib/Basic/Targets/LoongArch.cpp
+++ b/clang/lib/Basic/Targets/LoongArch.cpp
@@ -208,10 +208,14 @@ void LoongArchTargetInfo::getTargetDefines(const 
LangOptions &Opts,
 TuneCPU = ArchName;
   Builder.defineMacro("__loongarch_tune", Twine('"') + TuneCPU + Twine('"'));
 
-  if (HasFeatureLSX)
+  if (HasFeatureLASX) {
+Builder.defineMacro("__loongarch_simd_width", "256");
 Builder.defineMacro("__loongarch_sx", Twine(1));
-  if (HasFeatureLASX)
 Builder.defineMacro("__loongarch_asx", Twine(1));
+  } else if (HasFeatureLSX) {
+Builder.defineMacro("__loongarch_simd_width", "128");
+Builder.defineMacro("__loongarch_sx", Twine(1));
+  }
 
   StringRef ABI = getABI();
   if (ABI == "lp64d" || ABI == "lp64f" || ABI == "lp64s")
diff --git a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp 
b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
index 9ea4cc3f7cb95..4a2b9efc9ffad 100644
--- a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
@@ -206,6 +206,35 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
 } else /*-mno-lasx*/
   Features.push_back("-lasx");
   }
+
+  // Select lsx/lasx feature determined by -msimd=.
+  // Option -msimd= has lower priority than -m[no-]lsx and -m[no-]lasx.
+  if (const Arg *A = Args.getLastArg(options::OPT_msimd_EQ)) {
+StringRef MSIMD = A->getValue();
+if (MSIMD == "lsx") {
+  // Option -msimd=lsx depends on 64-bit FPU.
+  // -m*-float and -mfpu=none/0/32 conflict with -mlsx.
+  if (llvm::find(Features, "-d") != Features.end())
+D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << /*LSX*/ 0;
+  // The previous option does not contain feature -lsx.
+  else if (llvm::find(Features, "-lsx") == Features.end())
+Features.push_back("+lsx");
+} else if (MSIMD == "lasx") {
+  // Option -msimd=lasx depends on 64-bit FPU and LSX.
+  // -m*-float and -mfpu=none/0/32 conflict with -mlsx.
+  if (llvm::find(Features, "-d") != Features.end())
+D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << /*LASX*/ 1;
+  else if (llvm::find(Features, "-lsx") != Features.end())
+D.Diag(diag::err_drv_loongarch_invalid_simd_option_combination);
+  // The previous option does not contain feature -lasx.
+  else if (llvm::find(Features, "-lasx") == Features.end()) {
+Features.push_back("+lsx");
+Features.push_back("+lasx");
+  }
+} else

[clang] [LoongArch][clang] Add support for option `-msimd` and macro ` loonga… (PR #97984)

2024-07-07 Thread via cfe-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from 
other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[clang] [LoongArch][clang] Add support for option `-msimd` and macro ` loonga… (PR #97984)

2024-07-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Zhaoxin Yang (ylzsx)


Changes

…rch_simd_width`.

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


6 Files Affected:

- (modified) clang/include/clang/Basic/DiagnosticDriverKinds.td (+2) 
- (modified) clang/include/clang/Driver/Options.td (+3) 
- (modified) clang/lib/Basic/Targets/LoongArch.cpp (+6-2) 
- (modified) clang/lib/Driver/ToolChains/Arch/LoongArch.cpp (+29) 
- (added) clang/test/Driver/loongarch-msimd.c (+129) 
- (modified) clang/test/Preprocessor/init-loongarch.c (+3) 


``diff
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index a62bdc21298eee..243d88d53d6647 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -791,6 +791,8 @@ def err_drv_loongarch_wrong_fpu_width : Error<
   "wrong fpu width; %select{LSX|LASX}0 depends on 64-bit FPU">;
 def err_drv_loongarch_invalid_simd_option_combination : Error<
   "invalid option combination; LASX depends on LSX">;
+def err_drv_loongarch_invalid_msimd_EQ : Error<
+  "invalid argument '%0' to -msimd=; must be one of: none, lsx, lasx">;
 
 def err_drv_expand_response_file : Error<
   "failed to expand response file: %0">;
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 58ca6f2bea9e44..707ce8ce78d0b0 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5252,6 +5252,9 @@ def mlasx : Flag<["-"], "mlasx">, 
Group,
   HelpText<"Enable Loongson Advanced SIMD Extension (LASX).">;
 def mno_lasx : Flag<["-"], "mno-lasx">, Group,
   HelpText<"Disable Loongson Advanced SIMD Extension (LASX).">;
+def msimd_EQ : Joined<["-"], "msimd=">, Group,
+  Flags<[TargetSpecific]>,
+  HelpText<"Select the SIMD extension(s) to be enabled in LoongArch either 
'none', 'lsx', 'lasx'.">;
 def mnop_mcount : Flag<["-"], "mnop-mcount">, HelpText<"Generate 
mcount/__fentry__ calls as nops. To activate they need to be patched in.">,
   Visibility<[ClangOption, CC1Option]>, Group,
   MarshallingInfoFlag>;
diff --git a/clang/lib/Basic/Targets/LoongArch.cpp 
b/clang/lib/Basic/Targets/LoongArch.cpp
index 280bd1d8033cc6..75f71a337b7a49 100644
--- a/clang/lib/Basic/Targets/LoongArch.cpp
+++ b/clang/lib/Basic/Targets/LoongArch.cpp
@@ -208,10 +208,14 @@ void LoongArchTargetInfo::getTargetDefines(const 
LangOptions &Opts,
 TuneCPU = ArchName;
   Builder.defineMacro("__loongarch_tune", Twine('"') + TuneCPU + Twine('"'));
 
-  if (HasFeatureLSX)
+  if (HasFeatureLASX) {
+Builder.defineMacro("__loongarch_simd_width", "256");
 Builder.defineMacro("__loongarch_sx", Twine(1));
-  if (HasFeatureLASX)
 Builder.defineMacro("__loongarch_asx", Twine(1));
+  } else if (HasFeatureLSX) {
+Builder.defineMacro("__loongarch_simd_width", "128");
+Builder.defineMacro("__loongarch_sx", Twine(1));
+  }
 
   StringRef ABI = getABI();
   if (ABI == "lp64d" || ABI == "lp64f" || ABI == "lp64s")
diff --git a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp 
b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
index 9ea4cc3f7cb95b..4a2b9efc9ffadb 100644
--- a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
@@ -206,6 +206,35 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
 } else /*-mno-lasx*/
   Features.push_back("-lasx");
   }
+
+  // Select lsx/lasx feature determined by -msimd=.
+  // Option -msimd= has lower priority than -m[no-]lsx and -m[no-]lasx.
+  if (const Arg *A = Args.getLastArg(options::OPT_msimd_EQ)) {
+StringRef MSIMD = A->getValue();
+if (MSIMD == "lsx") {
+  // Option -msimd=lsx depends on 64-bit FPU.
+  // -m*-float and -mfpu=none/0/32 conflict with -mlsx.
+  if (llvm::find(Features, "-d") != Features.end())
+D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << /*LSX*/ 0;
+  // The previous option does not contain feature -lsx.
+  else if (llvm::find(Features, "-lsx") == Features.end())
+Features.push_back("+lsx");
+} else if (MSIMD == "lasx") {
+  // Option -msimd=lasx depends on 64-bit FPU and LSX.
+  // -m*-float and -mfpu=none/0/32 conflict with -mlsx.
+  if (llvm::find(Features, "-d") != Features.end())
+D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << /*LASX*/ 1;
+  else if (llvm::find(Features, "-lsx") != Features.end())
+D.Diag(diag::err_drv_loongarch_invalid_simd_option_combination);
+  // The previous option does not contain feature -lasx.
+  else if (llvm::find(Features, "-lasx") == Features.end()) {
+Features.push_back("+lsx");
+Features.push_back("+lasx");
+  }
+} else if (MSIMD != "none") {
+  D.Diag(diag::err_drv_loongarch_invalid_msimd_EQ) << MSIMD;
+}
+  }
 }
 
 std::string loongarch::postProcessTargetCPUString(const std::string &CPU,
diff --git a/clang/test/Drive

[clang] [LoongArch][clang] Add support for option `-msimd` and macro ` loonga… (PR #97984)

2024-07-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Zhaoxin Yang (ylzsx)


Changes

…rch_simd_width`.

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


6 Files Affected:

- (modified) clang/include/clang/Basic/DiagnosticDriverKinds.td (+2) 
- (modified) clang/include/clang/Driver/Options.td (+3) 
- (modified) clang/lib/Basic/Targets/LoongArch.cpp (+6-2) 
- (modified) clang/lib/Driver/ToolChains/Arch/LoongArch.cpp (+29) 
- (added) clang/test/Driver/loongarch-msimd.c (+129) 
- (modified) clang/test/Preprocessor/init-loongarch.c (+3) 


``diff
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index a62bdc21298eee..243d88d53d6647 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -791,6 +791,8 @@ def err_drv_loongarch_wrong_fpu_width : Error<
   "wrong fpu width; %select{LSX|LASX}0 depends on 64-bit FPU">;
 def err_drv_loongarch_invalid_simd_option_combination : Error<
   "invalid option combination; LASX depends on LSX">;
+def err_drv_loongarch_invalid_msimd_EQ : Error<
+  "invalid argument '%0' to -msimd=; must be one of: none, lsx, lasx">;
 
 def err_drv_expand_response_file : Error<
   "failed to expand response file: %0">;
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 58ca6f2bea9e44..707ce8ce78d0b0 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5252,6 +5252,9 @@ def mlasx : Flag<["-"], "mlasx">, 
Group,
   HelpText<"Enable Loongson Advanced SIMD Extension (LASX).">;
 def mno_lasx : Flag<["-"], "mno-lasx">, Group,
   HelpText<"Disable Loongson Advanced SIMD Extension (LASX).">;
+def msimd_EQ : Joined<["-"], "msimd=">, Group,
+  Flags<[TargetSpecific]>,
+  HelpText<"Select the SIMD extension(s) to be enabled in LoongArch either 
'none', 'lsx', 'lasx'.">;
 def mnop_mcount : Flag<["-"], "mnop-mcount">, HelpText<"Generate 
mcount/__fentry__ calls as nops. To activate they need to be patched in.">,
   Visibility<[ClangOption, CC1Option]>, Group,
   MarshallingInfoFlag>;
diff --git a/clang/lib/Basic/Targets/LoongArch.cpp 
b/clang/lib/Basic/Targets/LoongArch.cpp
index 280bd1d8033cc6..75f71a337b7a49 100644
--- a/clang/lib/Basic/Targets/LoongArch.cpp
+++ b/clang/lib/Basic/Targets/LoongArch.cpp
@@ -208,10 +208,14 @@ void LoongArchTargetInfo::getTargetDefines(const 
LangOptions &Opts,
 TuneCPU = ArchName;
   Builder.defineMacro("__loongarch_tune", Twine('"') + TuneCPU + Twine('"'));
 
-  if (HasFeatureLSX)
+  if (HasFeatureLASX) {
+Builder.defineMacro("__loongarch_simd_width", "256");
 Builder.defineMacro("__loongarch_sx", Twine(1));
-  if (HasFeatureLASX)
 Builder.defineMacro("__loongarch_asx", Twine(1));
+  } else if (HasFeatureLSX) {
+Builder.defineMacro("__loongarch_simd_width", "128");
+Builder.defineMacro("__loongarch_sx", Twine(1));
+  }
 
   StringRef ABI = getABI();
   if (ABI == "lp64d" || ABI == "lp64f" || ABI == "lp64s")
diff --git a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp 
b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
index 9ea4cc3f7cb95b..4a2b9efc9ffadb 100644
--- a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
@@ -206,6 +206,35 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
 } else /*-mno-lasx*/
   Features.push_back("-lasx");
   }
+
+  // Select lsx/lasx feature determined by -msimd=.
+  // Option -msimd= has lower priority than -m[no-]lsx and -m[no-]lasx.
+  if (const Arg *A = Args.getLastArg(options::OPT_msimd_EQ)) {
+StringRef MSIMD = A->getValue();
+if (MSIMD == "lsx") {
+  // Option -msimd=lsx depends on 64-bit FPU.
+  // -m*-float and -mfpu=none/0/32 conflict with -mlsx.
+  if (llvm::find(Features, "-d") != Features.end())
+D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << /*LSX*/ 0;
+  // The previous option does not contain feature -lsx.
+  else if (llvm::find(Features, "-lsx") == Features.end())
+Features.push_back("+lsx");
+} else if (MSIMD == "lasx") {
+  // Option -msimd=lasx depends on 64-bit FPU and LSX.
+  // -m*-float and -mfpu=none/0/32 conflict with -mlsx.
+  if (llvm::find(Features, "-d") != Features.end())
+D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << /*LASX*/ 1;
+  else if (llvm::find(Features, "-lsx") != Features.end())
+D.Diag(diag::err_drv_loongarch_invalid_simd_option_combination);
+  // The previous option does not contain feature -lasx.
+  else if (llvm::find(Features, "-lasx") == Features.end()) {
+Features.push_back("+lsx");
+Features.push_back("+lasx");
+  }
+} else if (MSIMD != "none") {
+  D.Diag(diag::err_drv_loongarch_invalid_msimd_EQ) << MSIMD;
+}
+  }
 }
 
 std::string loongarch::postProcessTargetCPUString(const std::string &CPU,
diff --git a/clang/tes

[clang] [LoongArch][clang] Add support for option `-msimd` and macro `__loongarch_simd_width`. (PR #97984)

2024-07-07 Thread Zhaoxin Yang via cfe-commits

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


[clang] [LoongArch][clang] Add support for option `-msimd` and macro `__loongarch_simd_width`. (PR #97984)

2024-07-07 Thread Zhaoxin Yang via cfe-commits

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


[clang] [llvm] [X86] Support branch hint (PR #97721)

2024-07-07 Thread Shengchen Kan via cfe-commits

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


[clang] e603451 - [X86] Support branch hint (#97721)

2024-07-07 Thread via cfe-commits

Author: Feng Zou
Date: 2024-07-08T13:12:50+08:00
New Revision: e603451f3cb16792fb46ab5f2fa50b05f3e5d935

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

LOG: [X86] Support branch hint (#97721)

For more details about this feature, please refer to latest Intel 64 and
IA-32 Architectures Optimization Reference Manual Volume 1:
https://www.intel.com/content/www/us/en/content-details/821612/intel-64-and-ia-32-architectures-optimization-reference-manual-volume-1.html

Added: 
llvm/test/CodeGen/X86/branch-hint.ll

Modified: 
clang/lib/Basic/Targets/X86.cpp
clang/lib/Basic/Targets/X86.h
llvm/lib/Target/X86/X86.td
llvm/lib/Target/X86/X86MCInstLower.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 276d492955207..1f6fc842ddd95 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -457,6 +457,8 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector &Features,
   HasCF = true;
 } else if (Feature == "+zu") {
   HasZU = true;
+} else if (Feature == "+branch-hint") {
+  HasBranchHint = true;
 }
 
 X86SSEEnum Level = llvm::StringSwitch(Feature)
@@ -1292,6 +1294,7 @@ bool X86TargetInfo::hasFeature(StringRef Feature) const {
   .Case("nf", HasNF)
   .Case("cf", HasCF)
   .Case("zu", HasZU)
+  .Case("branch-hint", HasBranchHint)
   .Default(false);
 }
 

diff  --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index 5ce4953251bc3..a70711f4ae2bb 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -174,6 +174,7 @@ class LLVM_LIBRARY_VISIBILITY X86TargetInfo : public 
TargetInfo {
   bool HasCF = false;
   bool HasZU = false;
   bool HasInlineAsmUseGPR32 = false;
+  bool HasBranchHint = false;
 
 protected:
   llvm::X86::CPUKind CPU = llvm::X86::CK_None;

diff  --git a/llvm/lib/Target/X86/X86.td b/llvm/lib/Target/X86/X86.td
index 68b78c7c44771..fdd7d5f1ee0e7 100644
--- a/llvm/lib/Target/X86/X86.td
+++ b/llvm/lib/Target/X86/X86.td
@@ -749,6 +749,11 @@ def TuningUseGLMDivSqrtCosts
 : SubtargetFeature<"use-glm-div-sqrt-costs", "UseGLMDivSqrtCosts", "true",
 "Use Goldmont specific floating point div/sqrt costs">;
 
+// Starting with Redwood Cove architecture, the branch has branch taken hint
+// (i.e., instruction prefix 3EH).
+def TuningBranchHint: SubtargetFeature<"branch-hint", "HasBranchHint", "true",
+"Target has branch hint feature">;
+
 
//===--===//
 // X86 CPU Families
 // TODO: Remove these - use general tuning features to determine codegen.
@@ -1124,6 +1129,8 @@ def ProcessorFeatures {
   FeaturePREFETCHI];
   list GNRFeatures =
 !listconcat(SPRFeatures, GNRAdditionalFeatures);
+  list GNRAdditionalTuning = [TuningBranchHint];
+  list GNRTuning = !listconcat(SPRTuning, 
GNRAdditionalTuning);
 
   // Graniterapids D
   list GNRDAdditionalFeatures = [FeatureAMXCOMPLEX];
@@ -1815,12 +1822,12 @@ def : ProcModel<"pantherlake", AlderlakePModel,
 def : ProcModel<"clearwaterforest", AlderlakePModel,
 ProcessorFeatures.CWFFeatures, ProcessorFeatures.ADLTuning>;
 def : ProcModel<"graniterapids", SapphireRapidsModel,
-ProcessorFeatures.GNRFeatures, ProcessorFeatures.SPRTuning>;
+ProcessorFeatures.GNRFeatures, ProcessorFeatures.GNRTuning>;
 def : ProcModel<"emeraldrapids", SapphireRapidsModel,
-ProcessorFeatures.SPRFeatures, ProcessorFeatures.SPRTuning>;
+ProcessorFeatures.SPRFeatures, ProcessorFeatures.GNRTuning>;
 foreach P = ["graniterapids-d", "graniterapids_d"] in {
 def : ProcModel;
+ProcessorFeatures.GNRDFeatures, ProcessorFeatures.GNRTuning>;
 }
 
 // AMD CPUs.

diff  --git a/llvm/lib/Target/X86/X86MCInstLower.cpp 
b/llvm/lib/Target/X86/X86MCInstLower.cpp
index 00f58f9432e4d..df20ecd1b9b21 100644
--- a/llvm/lib/Target/X86/X86MCInstLower.cpp
+++ b/llvm/lib/Target/X86/X86MCInstLower.cpp
@@ -25,6 +25,7 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
 #include "llvm/CodeGen/MachineConstantPool.h"
 #include "llvm/CodeGen/MachineFunction.h"
 #include "llvm/CodeGen/MachineModuleInfoImpls.h"
@@ -54,6 +55,14 @@
 
 using namespace llvm;
 
+static cl::opt EnableBranchHint("enable-branch-hint",
+  cl::desc("Enable branch hint."),
+  cl::init(false), cl::Hidden);
+static cl::opt BranchHintProbabilityThreshold(
+"branch-hint-probability-threshold",
+cl::desc(

[clang] [llvm] [ValueTracking] use KnownBits to compute fpclass from bitcast (PR #97762)

2024-07-07 Thread via cfe-commits


@@ -5805,6 +5805,37 @@ void computeKnownFPClass(const Value *V, const APInt 
&DemandedElts,
 
 break;
   }
+  case Instruction::BitCast: {
+const Value *Src;
+if (!match(Op, m_ElementWiseBitCast(m_Value(Src))) ||
+!Src->getType()->isIntOrIntVectorTy())
+  break;
+
+const Type *Ty = Op->getType()->getScalarType();
+KnownBits Bits(Ty->getScalarSizeInBits());
+computeKnownBits(Src, DemandedElts, Bits, Depth + 1, Q);
+
+// Transfer information from the sign bit.
+if (Bits.isNonNegative())
+  Known.signBitMustBeZero();
+else if (Bits.isNegative())
+  Known.signBitMustBeOne();
+
+if (Ty->isIEEE()) {
+  // IEEE floats are NaN when all bits of the exponent plus at least one of
+  // the fraction bits are 1. This means:
+  //   - If we assume unknown bits are 0 and the value is NaN, it will
+  // always be NaN
+  //   - If we assume unknown bits are 1 and the value is not NaN, it can
+  // never be NaN
+  if (APFloat(Ty->getFltSemantics(), Bits.One).isNaN())
+Known.KnownFPClasses = fcNan;
+  else if (!APFloat(Ty->getFltSemantics(), ~Bits.Zero).isNaN())
+Known.knownNot(fcNan);

goldsteinn wrote:

Is there a reason you cant also do `inf`/`normal`/`subnormal`?

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


[clang-tools-extra] [clang-tidy] Do not warn on const variables in misc-use-internal-linkage (PR #97969)

2024-07-07 Thread Congcong Cai via cfe-commits

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

There are some other limitation for const variable to be internal linkage.
Please follow standard to exclude this case
https://eel.is/c++draft/basic.link#3.2.

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


[clang-tools-extra] [clang-tidy] Do not warn on const variables in misc-use-internal-linkage (PR #97969)

2024-07-07 Thread Congcong Cai via cfe-commits

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

re-think about this case. LGTM

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


[clang] [LoongArch][clang] Add support for option `-msimd=` and macro `__loongarch_simd_width`. (PR #97984)

2024-07-07 Thread Lu Weining via cfe-commits

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


[clang] [LoongArch][clang] Add support for option `-msimd=` and macro `__loongarch_simd_width`. (PR #97984)

2024-07-07 Thread Lu Weining via cfe-commits

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

LGTM

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


[libunwind] [libunwind] fix unwinding from signal handler (PR #92291)

2024-07-07 Thread Azat Khuzhin via cfe-commits


@@ -365,7 +365,12 @@ int DwarfInstructions::stepWithDwarf(A 
&addressSpace, pint_t pc,
 
   // Return address is address after call site instruction, so setting IP 
to
   // that does simulates a return.
-  newRegisters.setIP(returnAddress);
+  //
+  // In case of this is frame of signal handler, the IP should be
+  // incremented, because the IP saved in the signal handler points to
+  // first non-executed instruction, while FDE/CIE expects IP to be after
+  // the first non-executed instruction.
+  newRegisters.setIP(returnAddress + cieInfo.isSignalFrame);

azat wrote:

OK, I see, thanks.
I can move this logic into `DwarfInstructions::stepWithDwarf`, but still, 
the IP will be different in case of regular unwind (after first non executed 
instruction) and unwind from signal (before first non-executed instruction)

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


[clang-tools-extra] [clang-tidy] In C++17, callee is guaranteed to be sequenced before arguments. (PR #93623)

2024-07-07 Thread Congcong Cai via cfe-commits

HerrCai0907 wrote:

Normally PR can be merged if someone approved PR. You can merge it by yourself.
If you don't have access, I'm glad to help you.

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


[clang-tools-extra] [clang-tidy] In C++17, callee is guaranteed to be sequenced before arguments. (PR #93623)

2024-07-07 Thread Kefu Chai via cfe-commits

tchaikov wrote:

@HerrCai0907 Hello Congcong, thank you for your message. I appreciate your 
willingness to help. As I don't have write access to the repository, I would be 
grateful if you could review and merge this pull request for me. Please let me 
know if you need any additional information or if you have any questions about 
the changes.

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


[clang] [llvm] [SanitizerBinaryMetadata] Fix multi-version sanitizer metadata (PR #97848)

2024-07-07 Thread Dmitry Vyukov via cfe-commits

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


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


[clang] [X86][vectorcall] Do not consume register for indirect return value (PR #97939)

2024-07-07 Thread Eli Friedman via cfe-commits

https://github.com/efriedma-quic approved this pull request.

LGTM

I meant, at the beginning of X86_32ABIInfo::computeInfo there's a chain of if 
statements that set up the properties of different calling conventions, and 
maybe some bits could be set there.  If you don't think that makes sense, 
though, it's fine.

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