[clang] [clang][ASTImporter][StructuralEquivalence] improve StructuralEquivalence on recordType (PR #76226)

2023-12-22 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/76226

>From 27005dba5f7530143657c514250a362670e3d67d Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Fri, 22 Dec 2023 17:56:32 +0800
Subject: [PATCH] [clang][ASTImporter][StructuralEquivalence] improve
 StructuralEquivalence on recordType

---
 clang/lib/AST/ASTStructuralEquivalence.cpp| 13 ---
 .../AST/StructuralEquivalenceTest.cpp | 22 +++
 2 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp 
b/clang/lib/AST/ASTStructuralEquivalence.cpp
index 6bb4bf14b873d7..277532696305e3 100644
--- a/clang/lib/AST/ASTStructuralEquivalence.cpp
+++ b/clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -1463,8 +1463,9 @@ 
IsStructurallyEquivalentLambdas(StructuralEquivalenceContext ,
 }
 
 /// Determine if context of a class is equivalent.
-static bool IsRecordContextStructurallyEquivalent(RecordDecl *D1,
-  RecordDecl *D2) {
+static bool
+IsRecordContextStructurallyEquivalent(StructuralEquivalenceContext ,
+  RecordDecl *D1, RecordDecl *D2) {
   // The context should be completely equal, including anonymous and inline
   // namespaces.
   // We compare objects as part of full translation units, not subtrees of
@@ -1491,6 +1492,12 @@ static bool 
IsRecordContextStructurallyEquivalent(RecordDecl *D1,
 return false;
 }
 
+if (auto *D1Spec = dyn_cast(DC1)) {
+  auto *D2Spec = dyn_cast(DC2);
+  if (!IsStructurallyEquivalent(Context, D1Spec, D2Spec))
+return false;
+}
+
 DC1 = DC1->getParent()->getNonTransparentContext();
 DC2 = DC2->getParent()->getNonTransparentContext();
   }
@@ -1544,7 +1551,7 @@ static bool 
IsStructurallyEquivalent(StructuralEquivalenceContext ,
   // If the records occur in different context (namespace), these should be
   // different. This is specially important if the definition of one or both
   // records is missing.
-  if (!IsRecordContextStructurallyEquivalent(D1, D2))
+  if (!IsRecordContextStructurallyEquivalent(Context, D1, D2))
 return false;
 
   // If both declarations are class template specializations, we know
diff --git a/clang/unittests/AST/StructuralEquivalenceTest.cpp 
b/clang/unittests/AST/StructuralEquivalenceTest.cpp
index 44d950cfe758f1..b54d149152e105 100644
--- a/clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ b/clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -1024,6 +1024,28 @@ TEST_F(StructuralEquivalenceRecordContextTest, 
TransparentContextInNamespace) {
   EXPECT_TRUE(testStructuralMatch(Decls));
 }
 
+TEST_F(StructuralEquivalenceRecordContextTest, RecordWithinTemplateClass) {
+  std::string Code =
+  R"(
+  template  struct O {
+struct M {};
+  };
+  )";
+  auto t = makeDecls(Code + R"(
+  typedef O::M MT1;
+  MT1 A;
+  )",
+  Code + R"(
+  namespace {
+struct I {};
+  } // namespace
+  typedef O::M MT2;
+  MT2 A;
+  )",
+  Lang_CXX11, varDecl(hasName("A")));
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
 TEST_F(StructuralEquivalenceTest, NamespaceOfRecordMember) {
   auto Decls = makeNamedDecls(
   R"(

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


[compiler-rt] [clang] [llvm] [sanitizers] Optimize locking StackDepotBase for fork (PR #76280)

2023-12-22 Thread Vitaly Buka via cfe-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/76280

>From e0c1de414d58b844382db93e3b3f4ac8cd8cf5b6 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Fri, 22 Dec 2023 23:26:11 -0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20change?=
 =?UTF-8?q?s=20to=20main=20this=20commit=20is=20based=20on?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4

[skip ci]
---
 compiler-rt/lib/asan/asan_posix.cpp   | 48 ++-
 .../lib/dfsan/dfsan_chained_origin_depot.cpp  |  6 +++
 .../lib/dfsan/dfsan_chained_origin_depot.h|  3 ++
 compiler-rt/lib/dfsan/dfsan_custom.cpp| 12 ++---
 compiler-rt/lib/hwasan/hwasan_linux.cpp   | 46 ++
 compiler-rt/lib/lsan/lsan_posix.cpp   | 30 +++-
 .../lib/msan/msan_chained_origin_depot.cpp|  6 +--
 .../lib/msan/msan_chained_origin_depot.h  |  4 +-
 compiler-rt/lib/msan/msan_linux.cpp   | 32 +++--
 .../sanitizer_common/sanitizer_stackdepot.cpp |  4 +-
 .../sanitizer_common/sanitizer_stackdepot.h   |  4 +-
 11 files changed, 109 insertions(+), 86 deletions(-)

diff --git a/compiler-rt/lib/asan/asan_posix.cpp 
b/compiler-rt/lib/asan/asan_posix.cpp
index a5b87b7fbf1b5a..76564538bd5d77 100644
--- a/compiler-rt/lib/asan/asan_posix.cpp
+++ b/compiler-rt/lib/asan/asan_posix.cpp
@@ -146,33 +146,37 @@ void PlatformTSDDtor(void *tsd) {
 #endif
   AsanThread::TSDDtor(tsd);
 }
-#endif
+#  endif
+
+static void BeforeFork() {
+  if (CAN_SANITIZE_LEAKS) {
+__lsan::LockGlobal();
+  }
+  // `_lsan` functions defined regardless of `CAN_SANITIZE_LEAKS` and lock the
+  // stuff we need.
+  __lsan::LockThreads();
+  __lsan::LockAllocator();
+  StackDepotLockBeforeFork();
+}
+
+static void AfterFork(bool fork_child) {
+  StackDepotUnlockAfterFork(fork_child);
+  // `_lsan` functions defined regardless of `CAN_SANITIZE_LEAKS` and unlock
+  // the stuff we need.
+  __lsan::UnlockAllocator();
+  __lsan::UnlockThreads();
+  if (CAN_SANITIZE_LEAKS) {
+__lsan::UnlockGlobal();
+  }
+}
 
 void InstallAtForkHandler() {
 #  if SANITIZER_SOLARIS || SANITIZER_NETBSD || SANITIZER_APPLE
   return;  // FIXME: Implement FutexWait.
 #  endif
-  auto before = []() {
-if (CAN_SANITIZE_LEAKS) {
-  __lsan::LockGlobal();
-}
-// `_lsan` functions defined regardless of `CAN_SANITIZE_LEAKS` and lock 
the
-// stuff we need.
-__lsan::LockThreads();
-__lsan::LockAllocator();
-StackDepotLockAll();
-  };
-  auto after = []() {
-StackDepotUnlockAll();
-// `_lsan` functions defined regardless of `CAN_SANITIZE_LEAKS` and unlock
-// the stuff we need.
-__lsan::UnlockAllocator();
-__lsan::UnlockThreads();
-if (CAN_SANITIZE_LEAKS) {
-  __lsan::UnlockGlobal();
-}
-  };
-  pthread_atfork(before, after, after);
+  pthread_atfork(
+  , []() { AfterFork(/* fork_child= */ false); },
+  []() { AfterFork(/* fork_child= */ true); });
 }
 
 void InstallAtExitCheckLeaks() {
diff --git a/compiler-rt/lib/dfsan/dfsan_chained_origin_depot.cpp 
b/compiler-rt/lib/dfsan/dfsan_chained_origin_depot.cpp
index 9ec598bf2ce9e4..6644bd6a7c6c0c 100644
--- a/compiler-rt/lib/dfsan/dfsan_chained_origin_depot.cpp
+++ b/compiler-rt/lib/dfsan/dfsan_chained_origin_depot.cpp
@@ -19,4 +19,10 @@ static ChainedOriginDepot chainedOriginDepot;
 
 ChainedOriginDepot* GetChainedOriginDepot() { return  }
 
+void ChainedOriginDepotLockBeforeFork() { chainedOriginDepot.LockAll(); }
+
+void ChainedOriginDepotUnlockAfterFork(bool fork_child) {
+  chainedOriginDepot.UnlockAll();
+}
+
 }  // namespace __dfsan
diff --git a/compiler-rt/lib/dfsan/dfsan_chained_origin_depot.h 
b/compiler-rt/lib/dfsan/dfsan_chained_origin_depot.h
index d715ef707f41b7..83b9e29e1b710d 100644
--- a/compiler-rt/lib/dfsan/dfsan_chained_origin_depot.h
+++ b/compiler-rt/lib/dfsan/dfsan_chained_origin_depot.h
@@ -21,6 +21,9 @@ namespace __dfsan {
 
 ChainedOriginDepot* GetChainedOriginDepot();
 
+void ChainedOriginDepotLockBeforeFork();
+void ChainedOriginDepotUnlockAfterFork(bool fork_child);
+
 }  // namespace __dfsan
 
 #endif  // DFSAN_CHAINED_ORIGIN_DEPOT_H
diff --git a/compiler-rt/lib/dfsan/dfsan_custom.cpp 
b/compiler-rt/lib/dfsan/dfsan_custom.cpp
index 38371d35336818..05b48fd0525e33 100644
--- a/compiler-rt/lib/dfsan/dfsan_custom.cpp
+++ b/compiler-rt/lib/dfsan/dfsan_custom.cpp
@@ -2893,13 +2893,13 @@ int __dfso___isoc99_sscanf(char *str, const char 
*format, dfsan_label str_label,
 }
 
 static void BeforeFork() {
-  StackDepotLockAll();
-  GetChainedOriginDepot()->LockAll();
+  StackDepotLockBeforeFork();
+  ChainedOriginDepotLockBeforeFork();
 }
 
-static void AfterFork() {
-  GetChainedOriginDepot()->UnlockAll();
-  StackDepotUnlockAll();
+static void AfterFork(bool fork_child) {
+  ChainedOriginDepotUnlockAfterFork(fork_child);
+  StackDepotUnlockAfterFork(fork_child);
 }
 
 SANITIZER_INTERFACE_ATTRIBUTE
@@ -2913,7 

[clang] [clang-format] Fix operator overload inconsistency in `BreakAfterAttributes: Always` (PR #74943)

2023-12-22 Thread Owen Pan via cfe-commits

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


[clang] 8097a5d - [clang-format] Fix operator overload inconsistency in `BreakAfterAttributes: Always` (#74943)

2023-12-22 Thread via cfe-commits

Author: XDeme
Date: 2023-12-22T23:02:47-08:00
New Revision: 8097a5d37b70f483d9e441d78aa7f689618fa795

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

LOG: [clang-format] Fix operator overload inconsistency in 
`BreakAfterAttributes: Always` (#74943)

Fixes llvm/llvm-project#74901

Added: 


Modified: 
clang/lib/Format/ContinuationIndenter.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index bd319f21b05f86..8489a30dd34ab3 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -583,17 +583,15 @@ bool ContinuationIndenter::mustBreak(const LineState 
) {
   return true;
   }
 
-  // If the return type spans multiple lines, wrap before the function name.
-  if (((Current.is(TT_FunctionDeclarationName) &&
-!State.Line->ReturnTypeWrapped &&
-// Don't break before a C# function when no break after return type.
-(!Style.isCSharp() ||
- Style.AlwaysBreakAfterReturnType != FormatStyle::RTBS_None) &&
-// Don't always break between a JavaScript `function` and the function
-// name.
-!Style.isJavaScript()) ||
-   (Current.is(tok::kw_operator) && Previous.isNot(tok::coloncolon))) &&
-  Previous.isNot(tok::kw_template) && CurrentState.BreakBeforeParameter) {
+  if (Current.is(TT_FunctionDeclarationName) &&
+  !State.Line->ReturnTypeWrapped &&
+  // Don't break before a C# function when no break after return type.
+  (!Style.isCSharp() ||
+   Style.AlwaysBreakAfterReturnType != FormatStyle::RTBS_None) &&
+  // Don't always break between a JavaScript `function` and the function
+  // name.
+  !Style.isJavaScript() && Previous.isNot(tok::kw_template) &&
+  CurrentState.BreakBeforeParameter) {
 return true;
   }
 

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 9772c3be71877f..762fc8254bdfc9 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -26479,6 +26479,19 @@ TEST_F(FormatTest, BreakAfterAttributes) {
"{\n"
"}",
CtorDtorCode, Style);
+
+  verifyFormat("struct Foo {\n"
+   "  [[maybe_unused]]\n"
+   "  void operator+();\n"
+   "};\n"
+   "[[nodiscard]]\n"
+   "Foo (Foo &);",
+   Style);
+
+  Style.ReferenceAlignment = FormatStyle::ReferenceAlignmentStyle::RAS_Left;
+  verifyFormat("[[nodiscard]]\n"
+   "Foo& operator-(Foo&);",
+   Style);
 }
 
 TEST_F(FormatTest, InsertNewlineAtEOF) {



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


[clang] [clang-format] Add common attribute macros to Google style (PR #76239)

2023-12-22 Thread Emilia Kond via cfe-commits

rymiel wrote:

Who should have the final say on the Google code style if not Google?

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


[clang] [clang-format] Fix a bug in annotating function declaration names (PR #76206)

2023-12-22 Thread Owen Pan via cfe-commits

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


[clang] f8f8926 - [clang-format] Fix a bug in annotating function declaration names (#76206)

2023-12-22 Thread via cfe-commits

Author: Owen Pan
Date: 2023-12-22T22:51:00-08:00
New Revision: f8f8926054dcf47cb0f3166be8d6961afc979290

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

LOG: [clang-format] Fix a bug in annotating function declaration names (#76206)

Annotates function declaration names having unnamed parameters.

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index f3551af3424396..3ac3aa3c5e3a22 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3403,7 +3403,8 @@ static bool isFunctionDeclarationName(bool IsCpp, const 
FormatToken ,
   continue;
 }
 if (Tok->is(tok::kw_const) || Tok->isSimpleTypeSpecifier() ||
-Tok->isOneOf(TT_PointerOrReference, TT_StartOfName, tok::ellipsis)) {
+Tok->isOneOf(TT_PointerOrReference, TT_StartOfName, tok::ellipsis,
+ TT_TypeName)) {
   return true;
 }
 if (Tok->isOneOf(tok::l_brace, TT_ObjCMethodExpr) || Tok->Tok.isLiteral())

diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 8e6935319b2f3d..2cafc0438ffb46 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1718,6 +1718,13 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsFunctionDeclarationNames) {
   ASSERT_EQ(Tokens.size(), 14u) << Tokens;
   EXPECT_TOKEN(Tokens[3], tok::identifier, TT_Unknown);
   EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_FunctionTypeLParen);
+
+  auto Style = getLLVMStyle();
+  Style.TypeNames.push_back("time_t");
+  Tokens = annotate("int iso_time(time_t);", Style);
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::identifier, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[3], tok::identifier, TT_TypeName);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsCtorAndDtorDeclNames) {



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


[clang] [clang-format] Add common attribute macros to Google style (PR #76239)

2023-12-22 Thread Owen Pan via cfe-commits

owenca wrote:

> `GUARDED_BY` and `ABSL_GUARDED_BY` are very commoon in Google codebases so it 
> is reasonable to include them by default to avoid the need for extra 
> configuration in every Google repository.

I don't feel comfortable with this as it might impact users of the Google style 
with non-Google codebases. @mydeveloperday @HazardyKnusperkeks @rymiel can you 
chime in?

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


[clang] [clang-format] Fix operator overload inconsistency in `BreakAfterAttributes: Always` (PR #74943)

2023-12-22 Thread Owen Pan via cfe-commits

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


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


[clang] [clang-format] Fix operator overload inconsistency in `BreakAfterAttributes: Always` (PR #74943)

2023-12-22 Thread via cfe-commits

https://github.com/XDeme updated https://github.com/llvm/llvm-project/pull/74943

>From b80f8579dbc745ddfaa3d60770dd0d3e79e6c641 Mon Sep 17 00:00:00 2001
From: XDeme 
Date: Sat, 9 Dec 2023 14:31:12 -0300
Subject: [PATCH 1/9] Fixes overload operator in BreakAfterAttributes

---
 clang/lib/Format/ContinuationIndenter.cpp |  3 ++-
 clang/unittests/Format/FormatTest.cpp | 14 ++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 9e4e939503dfe4..de3768d475e7b2 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -593,7 +593,8 @@ bool ContinuationIndenter::mustBreak(const LineState 
) {
 // name.
 !Style.isJavaScript()) ||
(Current.is(tok::kw_operator) && Previous.isNot(tok::coloncolon))) &&
-  Previous.isNot(tok::kw_template) && CurrentState.BreakBeforeParameter) {
+  Previous.isNot(tok::kw_template) && CurrentState.BreakBeforeParameter &&
+  (Style.isCpp() && Current.Tok.isNot(tok::kw_operator))) {
 return true;
   }
 
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 24b2fd599dc397..a1f3beed475ff3 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -26417,6 +26417,20 @@ TEST_F(FormatTest, BreakAfterAttributes) {
"void g() {}",
CtorDtorCode, Style);
 
+  Style.ReferenceAlignment = FormatStyle::ReferenceAlignmentStyle::RAS_Left;
+  constexpr StringRef OperatorOverloadCode(
+  "struct Foo {\n"
+  "[[maybe_unused]] void operator+();\n"
+  "};\n"
+  "[[nodiscard]] Foo& operator-(Foo&);");
+  verifyFormat("struct Foo {\n"
+   "  [[maybe_unused]]\n"
+   "  void operator+();\n"
+   "};\n"
+   "[[nodiscard]]\n"
+   "Foo& operator-(Foo&);",
+   OperatorOverloadCode, Style);
+
   Style.BreakBeforeBraces = FormatStyle::BS_Linux;
   verifyFormat("struct Foo {\n"
"  [[deprecated]]\n"

>From 67a018f8c27f547fdea3443100ec7255e7aa4f2e Mon Sep 17 00:00:00 2001
From: XDeme 
Date: Sat, 9 Dec 2023 16:05:12 -0300
Subject: [PATCH 2/9] Addresses 1, 2 and 4 comments

---
 clang/lib/Format/ContinuationIndenter.cpp |  2 +-
 clang/unittests/Format/FormatTest.cpp | 20 
 2 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index de3768d475e7b2..d05a16f87038ce 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -594,7 +594,7 @@ bool ContinuationIndenter::mustBreak(const LineState 
) {
 !Style.isJavaScript()) ||
(Current.is(tok::kw_operator) && Previous.isNot(tok::coloncolon))) &&
   Previous.isNot(tok::kw_template) && CurrentState.BreakBeforeParameter &&
-  (Style.isCpp() && Current.Tok.isNot(tok::kw_operator))) {
+  Current.Tok.isNot(tok::kw_operator)) {
 return true;
   }
 
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index a1f3beed475ff3..bccc3162c34367 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -26418,18 +26418,14 @@ TEST_F(FormatTest, BreakAfterAttributes) {
CtorDtorCode, Style);
 
   Style.ReferenceAlignment = FormatStyle::ReferenceAlignmentStyle::RAS_Left;
-  constexpr StringRef OperatorOverloadCode(
-  "struct Foo {\n"
-  "[[maybe_unused]] void operator+();\n"
-  "};\n"
-  "[[nodiscard]] Foo& operator-(Foo&);");
-  verifyFormat("struct Foo {\n"
-   "  [[maybe_unused]]\n"
-   "  void operator+();\n"
-   "};\n"
-   "[[nodiscard]]\n"
-   "Foo& operator-(Foo&);",
-   OperatorOverloadCode, Style);
+  verifyNoChange("struct Foo {\n"
+ "  [[maybe_unused]]\n"
+ "  void operator+();\n"
+ "};\n"
+ "[[nodiscard]]\n"
+ "Foo& operator-(Foo&);",
+ Style);
+  Style.ReferenceAlignment = getLLVMStyle().ReferenceAlignment;
 
   Style.BreakBeforeBraces = FormatStyle::BS_Linux;
   verifyFormat("struct Foo {\n"

>From f9b8d8cee9cf1fd313497c72e7829114a5d4b083 Mon Sep 17 00:00:00 2001
From: XDeme 
Date: Sat, 9 Dec 2023 18:46:15 -0300
Subject: [PATCH 3/9] Addresses comment 3

---
 clang/lib/Format/ContinuationIndenter.cpp | 25 +--
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index d05a16f87038ce..a9ce3d20142984 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -584,20 +584,23 @@ bool ContinuationIndenter::mustBreak(const LineState 
) {
   

[clang] [clang-format] Fix operator overload inconsistency in `BreakAfterAttributes: Always` (PR #74943)

2023-12-22 Thread Owen Pan via cfe-commits


@@ -26451,6 +26451,20 @@ TEST_F(FormatTest, BreakAfterAttributes) {
"{\n"
"}",
CtorDtorCode, Style);
+
+  Style.BreakBeforeBraces = FormatStyle::BS_Attach;
+  Style.ReferenceAlignment = FormatStyle::ReferenceAlignmentStyle::RAS_Left;
+  verifyFormat("struct Foo {\n"
+   "  [[maybe_unused]]\n"
+   "  void operator+();\n"
+   "};\n"
+   "[[nodiscard]]\n"
+   "Foo& operator-(Foo&);",
+   "struct Foo {\n"
+   "[[maybe_unused]] void operator+();\n"
+   "};\n"
+   "[[nodiscard]] Foo (Foo&);",

owenca wrote:

Please split the test cases and use the single argument version of 
`verifyFormat`, e.g.:
```suggestion
  verifyFormat("struct Foo {\n"
   "  [[maybe_unused]]\n"
   "  void operator+();\n"
   "};\n"
   "[[nodiscard]]\n"
   "Foo (Foo &);",
   Style);

  Style.ReferenceAlignment = FormatStyle::ReferenceAlignmentStyle::RAS_Left;
  verifyFormat("[[nodiscard]]\n"
   "Foo& operator-(Foo&);",
```

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


[clang] [Clang][RISCV] Add missing support for `__builtin_riscv_cpop_32/64` (PR #76256)

2023-12-22 Thread Craig Topper via cfe-commits


@@ -82,3 +82,29 @@ unsigned int ctz_64(unsigned long a) {
   return __builtin_riscv_ctz_64(a);
 }
 #endif
+
+// RV32ZBB-LABEL: @cpop_32(
+// RV32ZBB-NEXT:  entry:
+// RV32ZBB-NEXT:[[TMP0:%.*]] = call i32 @llvm.ctpop.i32(i32 [[A:%.*]])
+// RV32ZBB-NEXT:ret i32 [[TMP0]]
+//
+// RV64ZBB-LABEL: @cpop_32(
+// RV64ZBB-NEXT:  entry:
+// RV64ZBB-NEXT:[[TMP0:%.*]] = call i32 @llvm.ctpop.i32(i32 [[A:%.*]])
+// RV64ZBB-NEXT:ret i32 [[TMP0]]
+//
+unsigned int cpop_32(unsigned int a) {

topperc wrote:

This should also be using the intrinsic from riscv_bitmanip.h

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


[clang] 31aa7d2 - [RISCV] Use riscv_bitmanip.h in zbb.c. NFC

2023-12-22 Thread Craig Topper via cfe-commits

Author: Craig Topper
Date: 2023-12-22T20:10:37-08:00
New Revision: 31aa7d2de018693a6b45c9056a67229c54461b8f

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

LOG: [RISCV] Use riscv_bitmanip.h in zbb.c. NFC

I missed this when converting other scalar bitmanip/crypto tests
to use intrinsics intead of builtins.

Added: 


Modified: 
clang/test/CodeGen/RISCV/rvb-intrinsics/zbb.c

Removed: 




diff  --git a/clang/test/CodeGen/RISCV/rvb-intrinsics/zbb.c 
b/clang/test/CodeGen/RISCV/rvb-intrinsics/zbb.c
index 3a421f8c6cd421..5edbc578e82e9a 100644
--- a/clang/test/CodeGen/RISCV/rvb-intrinsics/zbb.c
+++ b/clang/test/CodeGen/RISCV/rvb-intrinsics/zbb.c
@@ -6,6 +6,8 @@
 // RUN: -disable-O0-optnone | opt -S -passes=mem2reg \
 // RUN: | FileCheck %s  -check-prefix=RV64ZBB
 
+#include 
+
 // RV32ZBB-LABEL: @orc_b_32(
 // RV32ZBB-NEXT:  entry:
 // RV32ZBB-NEXT:[[TMP0:%.*]] = call i32 @llvm.riscv.orc.b.i32(i32 
[[A:%.*]])
@@ -16,8 +18,8 @@
 // RV64ZBB-NEXT:[[TMP0:%.*]] = call i32 @llvm.riscv.orc.b.i32(i32 
[[A:%.*]])
 // RV64ZBB-NEXT:ret i32 [[TMP0]]
 //
-unsigned int orc_b_32(unsigned int a) {
-  return __builtin_riscv_orc_b_32(a);
+uint32_t orc_b_32(uint32_t a) {
+  return __riscv_orc_b_32(a);
 }
 
 #if __riscv_xlen == 64
@@ -26,8 +28,8 @@ unsigned int orc_b_32(unsigned int a) {
 // RV64ZBB-NEXT:[[TMP0:%.*]] = call i64 @llvm.riscv.orc.b.i64(i64 
[[A:%.*]])
 // RV64ZBB-NEXT:ret i64 [[TMP0]]
 //
-unsigned long orc_b_64(unsigned long a) {
-  return __builtin_riscv_orc_b_64(a);
+uint64_t orc_b_64(uint64_t a) {
+  return __riscv_orc_b_64(a);
 }
 #endif
 
@@ -41,8 +43,8 @@ unsigned long orc_b_64(unsigned long a) {
 // RV64ZBB-NEXT:[[TMP0:%.*]] = call i32 @llvm.ctlz.i32(i32 [[A:%.*]], i1 
false)
 // RV64ZBB-NEXT:ret i32 [[TMP0]]
 //
-unsigned int clz_32(unsigned int a) {
-  return __builtin_riscv_clz_32(a);
+unsigned int clz_32(uint32_t a) {
+  return __riscv_clz_32(a);
 }
 
 #if __riscv_xlen == 64
@@ -52,8 +54,8 @@ unsigned int clz_32(unsigned int a) {
 // RV64ZBB-NEXT:[[CAST:%.*]] = trunc i64 [[TMP0]] to i32
 // RV64ZBB-NEXT:ret i32 [[CAST]]
 //
-unsigned int clz_64(unsigned long a) {
-  return __builtin_riscv_clz_64(a);
+unsigned int clz_64(uint64_t a) {
+  return __riscv_clz_64(a);
 }
 #endif
 
@@ -67,8 +69,8 @@ unsigned int clz_64(unsigned long a) {
 // RV64ZBB-NEXT:[[TMP0:%.*]] = call i32 @llvm.cttz.i32(i32 [[A:%.*]], i1 
false)
 // RV64ZBB-NEXT:ret i32 [[TMP0]]
 //
-unsigned int ctz_32(unsigned int a) {
-  return __builtin_riscv_ctz_32(a);
+unsigned int ctz_32(uint32_t a) {
+  return __riscv_ctz_32(a);
 }
 
 #if __riscv_xlen == 64
@@ -78,7 +80,7 @@ unsigned int ctz_32(unsigned int a) {
 // RV64ZBB-NEXT:[[CAST:%.*]] = trunc i64 [[TMP0]] to i32
 // RV64ZBB-NEXT:ret i32 [[CAST]]
 //
-unsigned int ctz_64(unsigned long a) {
-  return __builtin_riscv_ctz_64(a);
+unsigned int ctz_64(uint64_t a) {
+  return __riscv_ctz_64(a);
 }
 #endif



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


[llvm] [clang] [SPARC] Support reserving arbitrary general purpose registers (PR #74927)

2023-12-22 Thread via cfe-commits


@@ -1125,6 +1130,10 @@ Register SparcTargetLowering::getRegisterByName(const 
char* RegName, LLT VT,
 .Case("g4", SP::G4).Case("g5", SP::G5).Case("g6", SP::G6).Case("g7", 
SP::G7)
 .Default(0);
 
+  const SparcRegisterInfo *TRI = Subtarget->getRegisterInfo();
+  if (!TRI->isReservedReg(MF, Reg))
+Reg = 0;

koachan wrote:

Hmm, yeah, ideally we'd want to do that but I don't think we can do that easily?
Even if I turn off all the errors, stuff like this, for example:
```
register unsigned long r asm("l0");
void set(unsigned long x) { r = x; }
```
Becomes a nop function on clang unless `l0` is reserved.
Other LLVM backends also do this (and differ from GCC behavior) so I don't 
think the issue is localized to ours.

So I believe it is better for us to throw an error instead of silently 
miscompiling code?

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


[clang] [clang][ASTImporter][StructuralEquivalence] improve StructuralEquivalence on recordType (PR #76226)

2023-12-22 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/76226

>From 574fa37117614fc4e23c12a7ecd297304d5eb337 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Fri, 22 Dec 2023 17:56:32 +0800
Subject: [PATCH] [clang][ASTImporter][StructuralEquivalence] improve
 StructuralEquivalence on recordType

---
 clang/lib/AST/ASTStructuralEquivalence.cpp| 15 ++---
 .../AST/StructuralEquivalenceTest.cpp | 22 +++
 2 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp 
b/clang/lib/AST/ASTStructuralEquivalence.cpp
index 6bb4bf14b873d7..7c04c09bb80874 100644
--- a/clang/lib/AST/ASTStructuralEquivalence.cpp
+++ b/clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -1107,11 +1107,20 @@ static bool 
IsStructurallyEquivalent(StructuralEquivalenceContext ,
   }
 
   case Type::Record:
-  case Type::Enum:
-if (!IsStructurallyEquivalent(Context, cast(T1)->getDecl(),
-  cast(T2)->getDecl()))
+  case Type::Enum: {
+auto *D1 = cast(T1)->getDecl();
+auto *D2 = cast(T2)->getDecl();
+if (!IsStructurallyEquivalent(Context, D1, D2))
+  return false;
+auto *D1Spec =
+
dyn_cast_or_null(D1->getDeclContext());
+auto *D2Spec =
+
dyn_cast_or_null(D2->getDeclContext());
+if (nullptr != D1Spec && nullptr != D2Spec &&
+!IsStructurallyEquivalent(Context, D1Spec, D2Spec))
   return false;
 break;
+  }
 
   case Type::TemplateTypeParm: {
 const auto *Parm1 = cast(T1);
diff --git a/clang/unittests/AST/StructuralEquivalenceTest.cpp 
b/clang/unittests/AST/StructuralEquivalenceTest.cpp
index 44d950cfe758f1..b54d149152e105 100644
--- a/clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ b/clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -1024,6 +1024,28 @@ TEST_F(StructuralEquivalenceRecordContextTest, 
TransparentContextInNamespace) {
   EXPECT_TRUE(testStructuralMatch(Decls));
 }
 
+TEST_F(StructuralEquivalenceRecordContextTest, RecordWithinTemplateClass) {
+  std::string Code =
+  R"(
+  template  struct O {
+struct M {};
+  };
+  )";
+  auto t = makeDecls(Code + R"(
+  typedef O::M MT1;
+  MT1 A;
+  )",
+  Code + R"(
+  namespace {
+struct I {};
+  } // namespace
+  typedef O::M MT2;
+  MT2 A;
+  )",
+  Lang_CXX11, varDecl(hasName("A")));
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
 TEST_F(StructuralEquivalenceTest, NamespaceOfRecordMember) {
   auto Decls = makeNamedDecls(
   R"(

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


[clang] [NFC][Clang] Fix Static Code Analysis Concerns with copy without assign (PR #75091)

2023-12-22 Thread via cfe-commits

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


[clang] [NFC][Clang] Fix Static Code Analysis Concerns with copy without assign (PR #75091)

2023-12-22 Thread via cfe-commits

smanna12 wrote:

> I think the static analysis tool is confused here. The `SVEType` class 
> doesn't actually have a user-declared copy constructor. It does have a 
> constructor that delegates to the implicitly declared copy constructor 
> though. The class members are all scalar types, so the implicitly declared 
> copy constructor and assignment operator will both behave as expected.
> 
> I recommend triaging the static analysis report as a false positive and not 
> making a source code change.

Thanks @tahonermann for reviews and clarification. I will close it as FP.

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


[clang] [clang-format] Fix a bug in annotating function declaration names (PR #76206)

2023-12-22 Thread Matt Mundell via cfe-commits

mattmundell wrote:

> `clang-format` doesn't know what are types, except for the keywords. So there 
> is no way to decide if this is a function declaration without naming the 
> parameters, or a variable declaration with a constructor call.

This is C so I guess it can only be a function declaration. Anyway, it's minor 
to work around, thanks again.

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


[clang] [NFC][CLANG] Fix static analyzer bugs about unnecessary object copies with auto keyword (PR #75082)

2023-12-22 Thread via cfe-commits

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


[clang] bbe1b06 - [NFC][CLANG] Fix static analyzer bugs about unnecessary object copies with auto keyword (#75082)

2023-12-22 Thread via cfe-commits

Author: smanna12
Date: 2023-12-22T20:39:22-06:00
New Revision: bbe1b06fbb7127d613cb4958e06c737967878388

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

LOG: [NFC][CLANG] Fix static analyzer bugs about unnecessary object copies with 
auto keyword (#75082)

Reported by Static Analyzer Tool:

In ​EmitAssemblyHelper::​RunOptimizationPipeline(): Using the auto
keyword without an & causes the copy of an object of type function.

 /// List of pass builder callbacks ("CodeGenOptions.h").
std::vector>
PassBuilderCallbacks;

Added: 


Modified: 
clang/lib/CodeGen/BackendUtil.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 480410db1021b7..a6142d99f3b688 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -881,7 +881,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
   << PluginFN << toString(PassPlugin.takeError());
 }
   }
-  for (auto PassCallback : CodeGenOpts.PassBuilderCallbacks)
+  for (const auto  : CodeGenOpts.PassBuilderCallbacks)
 PassCallback(PB);
 #define HANDLE_EXTENSION(Ext)  
\
   get##Ext##PluginInfo().RegisterPassBuilderCallbacks(PB);



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


[clang] [NFC][CLANG] Fix static analyzer bugs about unnecessary object copies with auto keyword (PR #75082)

2023-12-22 Thread via cfe-commits


@@ -876,7 +876,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
   << PluginFN << toString(PassPlugin.takeError());
 }
   }
-  for (auto PassCallback : CodeGenOpts.PassBuilderCallbacks)
+  for (const auto  : CodeGenOpts.PassBuilderCallbacks)

smanna12 wrote:

Thank you @tahonermann for reviews and information!

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


[clang] [clang][ASTImporter][StructuralEquivalence] improve StructuralEquivalence on recordType (PR #76226)

2023-12-22 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/76226

>From be62fb62934052db668eea57a9ff241fcd06cd2c Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Fri, 22 Dec 2023 17:56:32 +0800
Subject: [PATCH] [clang][ASTImporter][StructuralEquivalence] improve
 StructuralEquivalence on recordType

---
 clang/lib/AST/ASTStructuralEquivalence.cpp| 15 ++---
 .../AST/StructuralEquivalenceTest.cpp | 22 +++
 2 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp 
b/clang/lib/AST/ASTStructuralEquivalence.cpp
index 6bb4bf14b873d7..7c04c09bb80874 100644
--- a/clang/lib/AST/ASTStructuralEquivalence.cpp
+++ b/clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -1107,11 +1107,20 @@ static bool 
IsStructurallyEquivalent(StructuralEquivalenceContext ,
   }
 
   case Type::Record:
-  case Type::Enum:
-if (!IsStructurallyEquivalent(Context, cast(T1)->getDecl(),
-  cast(T2)->getDecl()))
+  case Type::Enum: {
+auto *D1 = cast(T1)->getDecl();
+auto *D2 = cast(T2)->getDecl();
+if (!IsStructurallyEquivalent(Context, D1, D2))
+  return false;
+auto *D1Spec =
+
dyn_cast_or_null(D1->getDeclContext());
+auto *D2Spec =
+
dyn_cast_or_null(D2->getDeclContext());
+if (nullptr != D1Spec && nullptr != D2Spec &&
+!IsStructurallyEquivalent(Context, D1Spec, D2Spec))
   return false;
 break;
+  }
 
   case Type::TemplateTypeParm: {
 const auto *Parm1 = cast(T1);
diff --git a/clang/unittests/AST/StructuralEquivalenceTest.cpp 
b/clang/unittests/AST/StructuralEquivalenceTest.cpp
index 44d950cfe758f1..b54d149152e105 100644
--- a/clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ b/clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -1024,6 +1024,28 @@ TEST_F(StructuralEquivalenceRecordContextTest, 
TransparentContextInNamespace) {
   EXPECT_TRUE(testStructuralMatch(Decls));
 }
 
+TEST_F(StructuralEquivalenceRecordContextTest, RecordWithinTemplateClass) {
+  std::string Code =
+  R"(
+  template  struct O {
+struct M {};
+  };
+  )";
+  auto t = makeDecls(Code + R"(
+  typedef O::M MT1;
+  MT1 A;
+  )",
+  Code + R"(
+  namespace {
+struct I {};
+  } // namespace
+  typedef O::M MT2;
+  MT2 A;
+  )",
+  Lang_CXX11, varDecl(hasName("A")));
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
 TEST_F(StructuralEquivalenceTest, NamespaceOfRecordMember) {
   auto Decls = makeNamedDecls(
   R"(

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


[clang] [Clang][RISCV] Add missing support for `__builtin_riscv_cpop_32/64` (PR #76256)

2023-12-22 Thread Craig Topper via cfe-commits


@@ -82,3 +82,29 @@ unsigned int ctz_64(unsigned long a) {
   return __builtin_riscv_ctz_64(a);
 }
 #endif
+
+// RV32ZBB-LABEL: @cpop_32(
+// RV32ZBB-NEXT:  entry:
+// RV32ZBB-NEXT:[[TMP0:%.*]] = call i32 @llvm.ctpop.i32(i32 [[A:%.*]])
+// RV32ZBB-NEXT:ret i32 [[TMP0]]
+//
+// RV64ZBB-LABEL: @cpop_32(
+// RV64ZBB-NEXT:  entry:
+// RV64ZBB-NEXT:[[TMP0:%.*]] = call i32 @llvm.ctpop.i32(i32 [[A:%.*]])
+// RV64ZBB-NEXT:ret i32 [[TMP0]]
+//
+unsigned int cpop_32(unsigned int a) {

topperc wrote:

Use uint32_t and uint64_t. I already updated some of the tests to use those 
types but I somehow missed this one.

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


[clang] [Clang][RISCV] Add missing support for `__builtin_riscv_cpop_32/64` (PR #76256)

2023-12-22 Thread Craig Topper via cfe-commits

topperc wrote:

Can we just use __builtin_popcount and __builtin_popcountll directly in the 
header file?

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


[clang] [clang][ASTImporter][StructuralEquivalence] improve StructuralEquivalence on recordType (PR #76226)

2023-12-22 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/76226

>From 9a8cea81eba77eef914089e3cffd96e863aac36f Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Fri, 22 Dec 2023 17:56:32 +0800
Subject: [PATCH] [clang][ASTImporter][StructuralEquivalence] improve
 StructuralEquivalence on recordType

---
 clang/lib/AST/ASTStructuralEquivalence.cpp| 15 ++---
 .../AST/StructuralEquivalenceTest.cpp | 22 +++
 2 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp 
b/clang/lib/AST/ASTStructuralEquivalence.cpp
index 6bb4bf14b873d7..7c04c09bb80874 100644
--- a/clang/lib/AST/ASTStructuralEquivalence.cpp
+++ b/clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -1107,11 +1107,20 @@ static bool 
IsStructurallyEquivalent(StructuralEquivalenceContext ,
   }
 
   case Type::Record:
-  case Type::Enum:
-if (!IsStructurallyEquivalent(Context, cast(T1)->getDecl(),
-  cast(T2)->getDecl()))
+  case Type::Enum: {
+auto *D1 = cast(T1)->getDecl();
+auto *D2 = cast(T2)->getDecl();
+if (!IsStructurallyEquivalent(Context, D1, D2))
+  return false;
+auto *D1Spec =
+
dyn_cast_or_null(D1->getDeclContext());
+auto *D2Spec =
+
dyn_cast_or_null(D2->getDeclContext());
+if (nullptr != D1Spec && nullptr != D2Spec &&
+!IsStructurallyEquivalent(Context, D1Spec, D2Spec))
   return false;
 break;
+  }
 
   case Type::TemplateTypeParm: {
 const auto *Parm1 = cast(T1);
diff --git a/clang/unittests/AST/StructuralEquivalenceTest.cpp 
b/clang/unittests/AST/StructuralEquivalenceTest.cpp
index 44d950cfe758f1..b54d149152e105 100644
--- a/clang/unittests/AST/StructuralEquivalenceTest.cpp
+++ b/clang/unittests/AST/StructuralEquivalenceTest.cpp
@@ -1024,6 +1024,28 @@ TEST_F(StructuralEquivalenceRecordContextTest, 
TransparentContextInNamespace) {
   EXPECT_TRUE(testStructuralMatch(Decls));
 }
 
+TEST_F(StructuralEquivalenceRecordContextTest, RecordWithinTemplateClass) {
+  std::string Code =
+  R"(
+  template  struct O {
+struct M {};
+  };
+  )";
+  auto t = makeDecls(Code + R"(
+  typedef O::M MT1;
+  MT1 A;
+  )",
+  Code + R"(
+  namespace {
+struct I {};
+  } // namespace
+  typedef O::M MT2;
+  MT2 A;
+  )",
+  Lang_CXX11, varDecl(hasName("A")));
+  EXPECT_FALSE(testStructuralMatch(t));
+}
+
 TEST_F(StructuralEquivalenceTest, NamespaceOfRecordMember) {
   auto Decls = makeNamedDecls(
   R"(

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


[lldb] [flang] [clang-tools-extra] [libcxx] [compiler-rt] [clang] [libc] [llvm] [RegAllocFast] Refactor dominates algorithm for large basic block (PR #72250)

2023-12-22 Thread via cfe-commits

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


[lldb] [flang] [clang-tools-extra] [libcxx] [compiler-rt] [clang] [libc] [llvm] [RegAllocFast] Refactor dominates algorithm for large basic block (PR #72250)

2023-12-22 Thread via cfe-commits


@@ -62,6 +62,107 @@ static RegisterRegAlloc fastRegAlloc("fast", "fast register 
allocator",
 
 namespace {
 
+/// Assign ascending index for instructions in machine basic block. The index
+/// can be used to determine dominance between instructions in same MBB.
+class InstrPosIndexes {
+public:
+  void init(const MachineBasicBlock ) {
+CurMBB = 
+Instr2PosIndex.clear();
+uint64_t LastIndex = 0;
+for (const MachineInstr  : MBB) {
+  LastIndex += InstrDist;
+  Instr2PosIndex[] = LastIndex;
+}

HaohaiWen wrote:

#76275

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


[clang] Revert "[Sema] Fix crash on invalid code with parenthesized aggregate initialization" (PR #76272)

2023-12-22 Thread Vitaly Buka via cfe-commits

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


[clang] 2205d23 - Revert "[Sema] Fix crash on invalid code with parenthesized aggregate initialization" (#76272)

2023-12-22 Thread via cfe-commits

Author: Vitaly Buka
Date: 2023-12-22T15:20:00-08:00
New Revision: 2205d2334f3c859ad9f6c65ed950bfb3bb6f7cbe

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

LOG: Revert "[Sema] Fix crash on invalid code with parenthesized aggregate 
initialization" (#76272)

Reverts llvm/llvm-project#76232 and
7ab16fb5207fe187ab999f882069bd632d2e68e5 to recover build bots.

Breaks libc++ tests, details in #76232

#76228

Added: 


Modified: 
clang/lib/Sema/SemaInit.cpp
clang/test/SemaCXX/paren-list-agg-init.cpp

Removed: 
clang/test/SemaCXX/crash-GH76228.cpp



diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index cc9db5ded1149a0..61d244f3bb9798a 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -5512,14 +5512,6 @@ static void TryOrBuildParenListInitialization(
   } else if (auto *RT = Entity.getType()->getAs()) {
 bool IsUnion = RT->isUnionType();
 const CXXRecordDecl *RD = cast(RT->getDecl());
-if (RD->isInvalidDecl()) {
-  // Exit early to avoid confusion when processing members.
-  // We do the same for braced list initialization in
-  // `CheckStructUnionTypes`.
-  Sequence.SetFailed(
-  clang::InitializationSequence::FK_ParenthesizedListInitFailed);
-  return;
-}
 
 if (!IsUnion) {
   for (const CXXBaseSpecifier  : RD->bases()) {

diff  --git a/clang/test/SemaCXX/crash-GH76228.cpp 
b/clang/test/SemaCXX/crash-GH76228.cpp
deleted file mode 100644
index 33a9395823127ea..000
--- a/clang/test/SemaCXX/crash-GH76228.cpp
+++ /dev/null
@@ -1,28 +0,0 @@
-// RUN: %clang_cc1 -std=c++20 -verify %s
-// Check we don't crash on incomplete members and bases when handling 
parenthesized initialization.
-class incomplete; // expected-note@-0 3  {{forward declaration of 
'incomplete'}}
-struct foo {
-  int a;
-  incomplete b;
-  // expected-error@-1 {{incomplete type}}
-};
-foo a1(0);
-
-struct one_int {
-int a;
-};
-struct bar : one_int, incomplete {};
-// expected-error@-1 {{incomplete type}}
-bar a2(0);
-
-incomplete a3[3](1,2,3);
-// expected-error@-1 {{incomplete type}}
-
-struct qux : foo {
-};
-qux a4(0);
-
-struct fred {
-foo a[3];
-};
-fred a5(0);

diff  --git a/clang/test/SemaCXX/paren-list-agg-init.cpp 
b/clang/test/SemaCXX/paren-list-agg-init.cpp
index c1964a5a9eb0058..f60b20e0d465685 100644
--- a/clang/test/SemaCXX/paren-list-agg-init.cpp
+++ b/clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -289,7 +289,7 @@ int test() {
   // used to crash
   S a(0, 1);
   S b(0);
-  S c(0, 0, 1);
+  S c(0, 0, 1); // beforecxx20-warning {{aggregate initialization of type 'S' 
from a parenthesized list of values is a C++20 extension}}
 
   S d {0, 1};
   S e {0};



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


[clang] Revert "[Sema] Fix crash on invalid code with parenthesized aggregate initialization" (PR #76272)

2023-12-22 Thread Vitaly Buka via cfe-commits

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


[clang] Revert "[Sema] Fix crash on invalid code with parenthesized aggregate initialization" (PR #76272)

2023-12-22 Thread Vitaly Buka via cfe-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/76272

>From 543b621aae66c572776cf57ba338f2e4daae3382 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Fri, 22 Dec 2023 14:23:46 -0800
Subject: [PATCH] Revert "[Sema] Fix crash on invalid code with parenthesized
 aggregate initialization (#76232)"

This reverts commit 86dc6e15f22610bbb53eb4efda0a178ecefc933a and 
7ab16fb5207fe187ab999f882069bd632d2e68e5.
---
 clang/lib/Sema/SemaInit.cpp|  8 ---
 clang/test/SemaCXX/crash-GH76228.cpp   | 28 --
 clang/test/SemaCXX/paren-list-agg-init.cpp |  2 +-
 3 files changed, 1 insertion(+), 37 deletions(-)
 delete mode 100644 clang/test/SemaCXX/crash-GH76228.cpp

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index cc9db5ded1149a..61d244f3bb9798 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -5512,14 +5512,6 @@ static void TryOrBuildParenListInitialization(
   } else if (auto *RT = Entity.getType()->getAs()) {
 bool IsUnion = RT->isUnionType();
 const CXXRecordDecl *RD = cast(RT->getDecl());
-if (RD->isInvalidDecl()) {
-  // Exit early to avoid confusion when processing members.
-  // We do the same for braced list initialization in
-  // `CheckStructUnionTypes`.
-  Sequence.SetFailed(
-  clang::InitializationSequence::FK_ParenthesizedListInitFailed);
-  return;
-}
 
 if (!IsUnion) {
   for (const CXXBaseSpecifier  : RD->bases()) {
diff --git a/clang/test/SemaCXX/crash-GH76228.cpp 
b/clang/test/SemaCXX/crash-GH76228.cpp
deleted file mode 100644
index 33a9395823127e..00
--- a/clang/test/SemaCXX/crash-GH76228.cpp
+++ /dev/null
@@ -1,28 +0,0 @@
-// RUN: %clang_cc1 -std=c++20 -verify %s
-// Check we don't crash on incomplete members and bases when handling 
parenthesized initialization.
-class incomplete; // expected-note@-0 3  {{forward declaration of 
'incomplete'}}
-struct foo {
-  int a;
-  incomplete b;
-  // expected-error@-1 {{incomplete type}}
-};
-foo a1(0);
-
-struct one_int {
-int a;
-};
-struct bar : one_int, incomplete {};
-// expected-error@-1 {{incomplete type}}
-bar a2(0);
-
-incomplete a3[3](1,2,3);
-// expected-error@-1 {{incomplete type}}
-
-struct qux : foo {
-};
-qux a4(0);
-
-struct fred {
-foo a[3];
-};
-fred a5(0);
diff --git a/clang/test/SemaCXX/paren-list-agg-init.cpp 
b/clang/test/SemaCXX/paren-list-agg-init.cpp
index c1964a5a9eb005..f60b20e0d46568 100644
--- a/clang/test/SemaCXX/paren-list-agg-init.cpp
+++ b/clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -289,7 +289,7 @@ int test() {
   // used to crash
   S a(0, 1);
   S b(0);
-  S c(0, 0, 1);
+  S c(0, 0, 1); // beforecxx20-warning {{aggregate initialization of type 'S' 
from a parenthesized list of values is a C++20 extension}}
 
   S d {0, 1};
   S e {0};

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


[clang] Revert "[Sema] Fix crash on invalid code with parenthesized aggregate initialization" (PR #76272)

2023-12-22 Thread Vitaly Buka via cfe-commits

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


[clang] Revert "[Sema] Fix crash on invalid code with parenthesized aggregate initialization" (PR #76272)

2023-12-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Vitaly Buka (vitalybuka)


Changes

Reverts llvm/llvm-project#76232 to recover build bots.

Breaks libc++ tests, details in #76232

#76263 

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaInit.cpp (-8) 
- (removed) clang/test/SemaCXX/crash-GH76228.cpp (-28) 


``diff
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index cc9db5ded1149a..61d244f3bb9798 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -5512,14 +5512,6 @@ static void TryOrBuildParenListInitialization(
   } else if (auto *RT = Entity.getType()->getAs()) {
 bool IsUnion = RT->isUnionType();
 const CXXRecordDecl *RD = cast(RT->getDecl());
-if (RD->isInvalidDecl()) {
-  // Exit early to avoid confusion when processing members.
-  // We do the same for braced list initialization in
-  // `CheckStructUnionTypes`.
-  Sequence.SetFailed(
-  clang::InitializationSequence::FK_ParenthesizedListInitFailed);
-  return;
-}
 
 if (!IsUnion) {
   for (const CXXBaseSpecifier  : RD->bases()) {
diff --git a/clang/test/SemaCXX/crash-GH76228.cpp 
b/clang/test/SemaCXX/crash-GH76228.cpp
deleted file mode 100644
index 33a9395823127e..00
--- a/clang/test/SemaCXX/crash-GH76228.cpp
+++ /dev/null
@@ -1,28 +0,0 @@
-// RUN: %clang_cc1 -std=c++20 -verify %s
-// Check we don't crash on incomplete members and bases when handling 
parenthesized initialization.
-class incomplete; // expected-note@-0 3  {{forward declaration of 
'incomplete'}}
-struct foo {
-  int a;
-  incomplete b;
-  // expected-error@-1 {{incomplete type}}
-};
-foo a1(0);
-
-struct one_int {
-int a;
-};
-struct bar : one_int, incomplete {};
-// expected-error@-1 {{incomplete type}}
-bar a2(0);
-
-incomplete a3[3](1,2,3);
-// expected-error@-1 {{incomplete type}}
-
-struct qux : foo {
-};
-qux a4(0);
-
-struct fred {
-foo a[3];
-};
-fred a5(0);

``




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


[clang] Revert "[Sema] Fix crash on invalid code with parenthesized aggregate initialization" (PR #76272)

2023-12-22 Thread Vitaly Buka via cfe-commits

https://github.com/vitalybuka created 
https://github.com/llvm/llvm-project/pull/76272

Reverts llvm/llvm-project#76232 to recover build bots.

Breaks libc++ tests, details in #76232

#76263 

>From 4c7293181d3139e16647c3c6daeeb3ae7b344816 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Fri, 22 Dec 2023 14:23:46 -0800
Subject: [PATCH] Revert "[Sema] Fix crash on invalid code with parenthesized
 aggregate initialization (#76232)"

This reverts commit 86dc6e15f22610bbb53eb4efda0a178ecefc933a.
---
 clang/lib/Sema/SemaInit.cpp  |  8 
 clang/test/SemaCXX/crash-GH76228.cpp | 28 
 2 files changed, 36 deletions(-)
 delete mode 100644 clang/test/SemaCXX/crash-GH76228.cpp

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index cc9db5ded1149a0..61d244f3bb9798a 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -5512,14 +5512,6 @@ static void TryOrBuildParenListInitialization(
   } else if (auto *RT = Entity.getType()->getAs()) {
 bool IsUnion = RT->isUnionType();
 const CXXRecordDecl *RD = cast(RT->getDecl());
-if (RD->isInvalidDecl()) {
-  // Exit early to avoid confusion when processing members.
-  // We do the same for braced list initialization in
-  // `CheckStructUnionTypes`.
-  Sequence.SetFailed(
-  clang::InitializationSequence::FK_ParenthesizedListInitFailed);
-  return;
-}
 
 if (!IsUnion) {
   for (const CXXBaseSpecifier  : RD->bases()) {
diff --git a/clang/test/SemaCXX/crash-GH76228.cpp 
b/clang/test/SemaCXX/crash-GH76228.cpp
deleted file mode 100644
index 33a9395823127ea..000
--- a/clang/test/SemaCXX/crash-GH76228.cpp
+++ /dev/null
@@ -1,28 +0,0 @@
-// RUN: %clang_cc1 -std=c++20 -verify %s
-// Check we don't crash on incomplete members and bases when handling 
parenthesized initialization.
-class incomplete; // expected-note@-0 3  {{forward declaration of 
'incomplete'}}
-struct foo {
-  int a;
-  incomplete b;
-  // expected-error@-1 {{incomplete type}}
-};
-foo a1(0);
-
-struct one_int {
-int a;
-};
-struct bar : one_int, incomplete {};
-// expected-error@-1 {{incomplete type}}
-bar a2(0);
-
-incomplete a3[3](1,2,3);
-// expected-error@-1 {{incomplete type}}
-
-struct qux : foo {
-};
-qux a4(0);
-
-struct fred {
-foo a[3];
-};
-fred a5(0);

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


[clang] 0e039fc - [APINotes] Use DenseMap::contains (NFC)

2023-12-22 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-12-22T14:23:25-08:00
New Revision: 0e039fc39e29320c9a0eeadb34a5e83ac51d48ba

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

LOG: [APINotes] Use DenseMap::contains (NFC)

Added: 


Modified: 
clang/lib/APINotes/APINotesManager.cpp

Removed: 




diff  --git a/clang/lib/APINotes/APINotesManager.cpp 
b/clang/lib/APINotes/APINotesManager.cpp
index a921c8b9fce3e0..d3aef09dac9105 100644
--- a/clang/lib/APINotes/APINotesManager.cpp
+++ b/clang/lib/APINotes/APINotesManager.cpp
@@ -125,7 +125,7 @@ APINotesManager::loadAPINotes(StringRef Buffer) {
 
 bool APINotesManager::loadAPINotes(const DirectoryEntry *HeaderDir,
FileEntryRef APINotesFile) {
-  assert(Readers.find(HeaderDir) == Readers.end());
+  assert(!Readers.contains(HeaderDir));
   if (auto Reader = loadAPINotes(APINotesFile)) {
 Readers[HeaderDir] = Reader.release();
 return false;



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


[clang] [clang-format] Add an fnmatch-like function for .clang-format-ignore (PR #76021)

2023-12-22 Thread Owen Pan via cfe-commits

owenca wrote:

> Are we going to use this specific implementation on all platforms for parity?

Yes, similar to 
[this](https://github.com/owenca/llvm-project/commit/52866dcfe31cf5a43d86b27ec1f0420077034780#diff-0cfce704bac218438436bd4388319d112780509ea474d5b3253d45746a62713aR123).

> The logic on its own looks good as far as I can tell, but, for example, POSIX 
> Section 2.13 mentions that a leading period (hidden files) isn't matched by 
> `*`.

`matchFilePath(Pattern, FilePath)` is roughly equivalent to `!fnmatch(Pattern, 
FilePath, FNM_PATHNAME)`, similar to how I used `fnmatch()` 
[before](https://github.com/owenca/llvm-project/commit/efc1f1b582c014bdb2b5ef31d3fbafa77c143d05#diff-e3dfffecb8a56cc7fc60530acb5047c79903e66221d2b5b605f0486ac04c3cd3R629).
 To be consistent with the 
[spec](https://github.com/llvm/llvm-project/issues/52975#issuecomment-1848386526),
 I intentionally didn't use the `FNM_PERIOD` flag, which would prevent a 
leading period from being matched by `*`.

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


[clang] [clang-format] Add an fnmatch-like function for .clang-format-ignore (PR #76021)

2023-12-22 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/76021

>From 4954f52278ca41652be79318843d3538a2eb1205 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Tue, 19 Dec 2023 23:25:57 -0800
Subject: [PATCH 1/2] [clang-format] Add an fnmatch-like function for
 .clang-format-ignore

This is needed because Windows doesn't have anything equivalent to the POSIX
fnmatch() function.
---
 clang/lib/Format/CMakeLists.txt  |   1 +
 clang/lib/Format/MatchFilePath.cpp   | 121 +
 clang/lib/Format/MatchFilePath.h |  22 +++
 clang/unittests/Format/CMakeLists.txt|   1 +
 clang/unittests/Format/MatchFilePathTest.cpp | 169 +++
 5 files changed, 314 insertions(+)
 create mode 100644 clang/lib/Format/MatchFilePath.cpp
 create mode 100644 clang/lib/Format/MatchFilePath.h
 create mode 100644 clang/unittests/Format/MatchFilePathTest.cpp

diff --git a/clang/lib/Format/CMakeLists.txt b/clang/lib/Format/CMakeLists.txt
index 015ec7c0cc84e3..84a3c136f650a8 100644
--- a/clang/lib/Format/CMakeLists.txt
+++ b/clang/lib/Format/CMakeLists.txt
@@ -11,6 +11,7 @@ add_clang_library(clangFormat
   IntegerLiteralSeparatorFixer.cpp
   MacroCallReconstructor.cpp
   MacroExpander.cpp
+  MatchFilePath.cpp
   NamespaceEndCommentsFixer.cpp
   ObjCPropertyAttributeOrderFixer.cpp
   QualifierAlignmentFixer.cpp
diff --git a/clang/lib/Format/MatchFilePath.cpp 
b/clang/lib/Format/MatchFilePath.cpp
new file mode 100644
index 00..476af644b5f235
--- /dev/null
+++ b/clang/lib/Format/MatchFilePath.cpp
@@ -0,0 +1,121 @@
+//===--- MatchFilePath.cpp - Match file path with pattern ---*- 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
+//
+//===--===//
+///
+/// \file
+/// This file implements the functionality of matching a file path name to
+/// a pattern, similar to the POSIX fnmatch() function.
+///
+//===--===//
+
+#include "MatchFilePath.h"
+
+using namespace llvm;
+
+namespace clang {
+namespace format {
+
+// Check whether `FilePath` matches `Pattern` based on POSIX Section 2.13.
+bool matchFilePath(StringRef Pattern, StringRef FilePath) {
+  assert(!Pattern.empty());
+  assert(!FilePath.empty());
+
+  // No match if `Pattern` ends with a non-meta character not equal to the last
+  // character of `FilePath`.
+  if (const auto C = Pattern.back(); !strchr("?*]", C) && C != FilePath.back())
+return false;
+
+  constexpr auto Separator = '/';
+  const auto EOP = Pattern.size();  // End of `Pattern`.
+  const auto End = FilePath.size(); // End of `FilePath`.
+  unsigned I = 0;   // Index to `Pattern`.
+
+  for (unsigned J = 0; J < End; ++J) {
+if (I == EOP)
+  return false;
+
+switch (const auto F = FilePath[J]; Pattern[I]) {
+case '\\':
+  if (++I == EOP || F != Pattern[I])
+return false;
+  break;
+case '?':
+  if (F == Separator)
+return false;
+  break;
+case '*': {
+  while (++I < EOP && Pattern[I] == '*') { // Skip consecutive stars.
+  }
+  const auto K = FilePath.find(Separator, J); // Index of next `Separator`.
+  const bool NoMoreSeparatorsInFilePath = K == StringRef::npos;
+  if (I == EOP) // `Pattern` ends with a star.
+return NoMoreSeparatorsInFilePath;
+  // `Pattern` ends with a lone backslash.
+  if (Pattern[I] == '\\' && ++I == EOP)
+return false;
+  // The star is followed by a (possibly escaped) `Separator`.
+  if (Pattern[I] == Separator) {
+if (NoMoreSeparatorsInFilePath)
+  return false;
+J = K; // Skip to next `Separator` in `FilePath`.
+break;
+  }
+  // Recurse.
+  for (auto Pat = Pattern.substr(I); J < End && FilePath[J] != Separator;
+   ++J) {
+if (matchFilePath(Pat, FilePath.substr(J)))
+  return true;
+  }
+  return false;
+}
+case '[':
+  // Skip e.g. `[!]`.
+  if (I + 3 < EOP || (I + 3 == EOP && Pattern[I + 1] != '!')) {
+// Skip unpaired `[`, brackets containing slashes, and `[]`.
+if (const auto K = Pattern.find_first_of("]/", I + 1);
+K != StringRef::npos && Pattern[K] == ']' && K > I + 1) {
+  if (F == Separator)
+return false;
+  ++I; // After the `[`.
+  bool Negated = false;
+  if (Pattern[I] == '!') {
+Negated = true;
+++I; // After the `!`.
+  }
+  bool Match = false;
+  do {
+if (I + 2 < K && Pattern[I + 1] == '-') {
+  Match = Pattern[I] <= F && F <= Pattern[I + 2];
+  I += 3; // After the range, e.g. `A-Z`.
+} else {
+   

[llvm] [clang] [TargetParser] Define AEK_FCMA and AEK_JSCVT for tsv110 (PR #75516)

2023-12-22 Thread Qi Hu via cfe-commits

https://github.com/Qi-Hu updated https://github.com/llvm/llvm-project/pull/75516

>From e93dd2aa9005435b401d0ca3b1005768f8a636dd Mon Sep 17 00:00:00 2001
From: Qi Hu 
Date: Thu, 14 Dec 2023 13:35:52 -0500
Subject: [PATCH] [TargetParser] Define AEK_FCMA and AEK_JSCVT for tsv110

We define AEK_JSCVT and AEK_FCMA for CPU features FEAT_JSCVT and FEAT_FCMA
respectively, and add them to the CpuInfo of tsv110.
---
 clang/test/CodeGen/aarch64-targetattr.c  | 12 ++--
 clang/test/Preprocessor/aarch64-target-features.c| 10 +-
 llvm/include/llvm/TargetParser/AArch64TargetParser.h | 11 +++
 llvm/lib/Target/AArch64/AArch64.td   |  3 ++-
 llvm/unittests/TargetParser/TargetParserTest.cpp | 11 ---
 5 files changed, 28 insertions(+), 19 deletions(-)

diff --git a/clang/test/CodeGen/aarch64-targetattr.c 
b/clang/test/CodeGen/aarch64-targetattr.c
index 9664b723a2b2cd..1693b6ff3b853c 100644
--- a/clang/test/CodeGen/aarch64-targetattr.c
+++ b/clang/test/CodeGen/aarch64-targetattr.c
@@ -97,19 +97,19 @@ void minusarch() {}
 // CHECK: attributes #0 = { {{.*}} 
"target-features"="+crc,+fp-armv8,+lse,+neon,+ras,+rdm,+v8.1a,+v8.2a,+v8a" }
 // CHECK: attributes #1 = { {{.*}} 
"target-features"="+crc,+fp-armv8,+fullfp16,+lse,+neon,+ras,+rdm,+sve,+v8.1a,+v8.2a,+v8a"
 }
 // CHECK: attributes #2 = { {{.*}} 
"target-features"="+crc,+fp-armv8,+fullfp16,+lse,+neon,+ras,+rdm,+sve,+sve2,+v8.1a,+v8.2a,+v8a"
 }
-// CHECK: attributes #3 = { {{.*}} 
"target-features"="+bf16,+crc,+dotprod,+fp-armv8,+fullfp16,+i8mm,+lse,+neon,+ras,+rcpc,+rdm,+sve,+sve2,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8.6a,+v8a"
 }
-// CHECK: attributes #4 = { {{.*}} "target-cpu"="cortex-a710" 
"target-features"="+bf16,+crc,+dotprod,+flagm,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+lse,+mte,+neon,+pauth,+ras,+rcpc,+rdm,+sb,+sve,+sve2,+sve2-bitperm"
 }
+// CHECK: attributes #3 = { {{.*}} 
"target-features"="+bf16,+complxnum,+crc,+dotprod,+fp-armv8,+fullfp16,+i8mm,+jsconv,+lse,+neon,+ras,+rcpc,+rdm,+sve,+sve2,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8.6a,+v8a"
 }
+// CHECK: attributes #4 = { {{.*}} "target-cpu"="cortex-a710" 
"target-features"="+bf16,+complxnum,+crc,+dotprod,+flagm,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+jsconv,+lse,+mte,+neon,+pauth,+ras,+rcpc,+rdm,+sb,+sve,+sve2,+sve2-bitperm"
 }
 // CHECK: attributes #5 = { {{.*}} "tune-cpu"="cortex-a710" }
 // CHECK: attributes #6 = { {{.*}} "target-cpu"="generic" }
 // CHECK: attributes #7 = { {{.*}} "tune-cpu"="generic" }
 // CHECK: attributes #8 = { {{.*}} "target-cpu"="neoverse-n1" 
"target-features"="+aes,+crc,+dotprod,+fp-armv8,+fullfp16,+lse,+neon,+ras,+rcpc,+rdm,+sha2,+spe,+ssbs"
 "tune-cpu"="cortex-a710" }
 // CHECK: attributes #9 = { {{.*}} 
"target-features"="+fp-armv8,+fullfp16,+neon,+sve" "tune-cpu"="cortex-a710" }
-// CHECK: attributes #10 = { {{.*}} "target-cpu"="neoverse-v1" 
"target-features"="+aes,+bf16,+crc,+dotprod,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+lse,+neon,+rand,+ras,+rcpc,+rdm,+sha2,+sha3,+sm4,+spe,+ssbs,+sve,+sve2"
 }
-// CHECK: attributes #11 = { {{.*}} "target-cpu"="neoverse-v1" 
"target-features"="+aes,+bf16,+crc,+dotprod,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+lse,+neon,+rand,+ras,+rcpc,+rdm,+sha2,+sha3,+sm4,+spe,+ssbs,-sve"
 }
+// CHECK: attributes #10 = { {{.*}} "target-cpu"="neoverse-v1" 
"target-features"="+aes,+bf16,+complxnum,+crc,+dotprod,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+jsconv,+lse,+neon,+rand,+ras,+rcpc,+rdm,+sha2,+sha3,+sm4,+spe,+ssbs,+sve,+sve2"
 }
+// CHECK: attributes #11 = { {{.*}} "target-cpu"="neoverse-v1" 
"target-features"="+aes,+bf16,+complxnum,+crc,+dotprod,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+jsconv,+lse,+neon,+rand,+ras,+rcpc,+rdm,+sha2,+sha3,+sm4,+spe,+ssbs,-sve"
 }
 // CHECK: attributes #12 = { {{.*}} 
"target-features"="+fp-armv8,+fullfp16,+neon,+sve" }
 // CHECK: attributes #13 = { {{.*}} 
"target-features"="+fp-armv8,+fullfp16,+neon,+sve,-sve2" }
 // CHECK: attributes #14 = { {{.*}} "target-features"="+fullfp16" }
-// CHECK: attributes #15 = { {{.*}} "target-cpu"="neoverse-n1" 
"target-features"="+aes,+bf16,+crc,+dotprod,+fp-armv8,+fullfp16,+i8mm,+lse,+neon,+ras,+rcpc,+rdm,+sha2,+spe,+ssbs,+sve,+sve2,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8.6a,+v8a"
 "tune-cpu"="cortex-a710" }
-// CHECK: attributes #16 = { {{.*}} "branch-target-enforcement"="true" {{.*}} 
"target-features"="+aes,+bf16,+crc,+dotprod,+fp-armv8,+fullfp16,+i8mm,+lse,+neon,+ras,+rcpc,+rdm,+sha2,+spe,+ssbs,+sve,+sve2,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8.6a,+v8a"
 "tune-cpu"="cortex-a710" }
+// CHECK: attributes #15 = { {{.*}} "target-cpu"="neoverse-n1" 
"target-features"="+aes,+bf16,+complxnum,+crc,+dotprod,+fp-armv8,+fullfp16,+i8mm,+jsconv,+lse,+neon,+ras,+rcpc,+rdm,+sha2,+spe,+ssbs,+sve,+sve2,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8.6a,+v8a"
 "tune-cpu"="cortex-a710" }
+// CHECK: attributes #16 = { {{.*}} "branch-target-enforcement"="true" {{.*}} 

[clang] [clang-format] Add an fnmatch-like function for .clang-format-ignore (PR #76021)

2023-12-22 Thread Owen Pan via cfe-commits


@@ -0,0 +1,169 @@
+//===- unittest/Format/MatchFilePathTest.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "../../lib/Format/MatchFilePath.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace format {
+namespace {
+
+class MatchFilePathTest : public ::testing::Test {
+protected:
+  bool match(llvm::StringRef FilePath, llvm::StringRef Pattern) {
+return matchFilePath(Pattern, FilePath);
+  }
+};
+
+// Most of the test cases below are from:
+// https://github.com/python/cpython/blob/main/Lib/test/test_fnmatch.py
+
+TEST_F(MatchFilePathTest, Wildcard) {
+  EXPECT_TRUE(match("abc", "?*?"));
+  EXPECT_TRUE(match("abc", "???*"));
+  EXPECT_TRUE(match("abc", "*???"));
+  EXPECT_TRUE(match("abc", "???"));
+  EXPECT_TRUE(match("abc", "*"));
+  EXPECT_TRUE(match("abc", "ab[cd]"));
+  EXPECT_TRUE(match("abc", "ab[!de]"));
+  EXPECT_TRUE(!match("abc", "ab[de]"));

owenca wrote:

I used `!` instead of `EXPECT_FALSE` on purpose because it's easier for me to 
spot the `!` which has a different color in my editor, but I'll oblige though. 
:)

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


[clang] [clang-format] Support of TableGen formatting. (PR #76059)

2023-12-22 Thread Björn Schäpers via cfe-commits


@@ -2165,6 +2165,56 @@ TEST_F(TokenAnnotatorTest, UnderstandsVerilogOperators) {
   EXPECT_TOKEN(Tokens[4], tok::string_literal, TT_Unknown);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandTableGenTokens) {
+  auto Style = getLLVMStyle(FormatStyle::LK_TableGen);
+  Style.TableGenBreakingDAGArgOperators = {"ins", "outs"};
+
+  auto AnnotateValue = [this, ](llvm::StringRef Code) {
+// Values are annotated only in specific context.
+auto Result = annotate(("def X { let V = " + Code + "; }").str(), Style);
+return decltype(Result){Result.begin() + 6, Result.end() - 3};
+  };
+  // Both of bang/cond operators

HazardyKnusperkeks wrote:

```suggestion
  // Both of bang/cond operators.
```

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


[clang] [clang-format] Support of TableGen formatting. (PR #76059)

2023-12-22 Thread Björn Schäpers via cfe-commits


@@ -681,6 +700,10 @@ struct FormatToken {
   return true;
 if (is(TT_DictLiteral) && is(tok::greater))
   return true;
+if (is(TT_TableGenParamAngleCloser))
+  return true;
+if (is(TT_TableGenListCloser))
+  return true;
 return isOneOf(tok::r_paren, tok::r_brace, tok::r_square,
TT_TemplateCloser);

HazardyKnusperkeks wrote:

```suggestion
return isOneOf(tok::r_paren, tok::r_brace, tok::r_square,
   TT_TemplateCloser, TT_TableGenParamAngleCloser, 
TT_TableGenListCloser);
```

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


[clang] [clang-format] Support of TableGen formatting. (PR #76059)

2023-12-22 Thread Björn Schäpers via cfe-commits


@@ -396,6 +396,36 @@ struct FormatStyle {
   /// \version 17
   ShortCaseStatementsAlignmentStyle AlignConsecutiveShortCaseStatements;
 
+  /// Style of aligning consecutive TableGen cond operator colons.
+  /// \code
+  ///   !cond(!eq(size, 1) : 1,
+  /// !eq(size, 16): 1,
+  /// true : 0)
+  /// \endcode
+  /// \version 18
+  AlignConsecutiveStyle AlignConsecutiveTableGenCondOperatorColons;
+
+  /// Style of aligning consecutive TableGen DAGArg operator colons.
+  /// Intended to be used with TableGenBreakInsideDAGArgList
+  /// \code
+  ///   let dagarg = (ins
+  ///   a  :$src1,
+  ///   aa :$src2,
+  ///   aaa:$src3
+  ///   )
+  /// \endcode
+  /// \version 18
+  AlignConsecutiveStyle AlignConsecutiveTableGenBreakingDAGArgColons;

HazardyKnusperkeks wrote:

Please sort alphabetically.

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


[clang] [clang-format] Support of TableGen formatting. (PR #76059)

2023-12-22 Thread Björn Schäpers via cfe-commits


@@ -4656,6 +4687,15 @@ struct FormatStyle {
   /// \version 8
   std::vector StatementMacros;
 
+  /// Tablegen
+  bool TableGenAllowBreakBeforeInheritColon;
+  bool TableGenAllowBreakAfterInheritColon;

HazardyKnusperkeks wrote:

Do you need both options to be enabled at the same time? Otherwise 
`BreakInheritanceList` should already be the option to check.

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


[clang] [clang-format] Support of TableGen formatting. (PR #76059)

2023-12-22 Thread Björn Schäpers via cfe-commits


@@ -396,6 +396,36 @@ struct FormatStyle {
   /// \version 17
   ShortCaseStatementsAlignmentStyle AlignConsecutiveShortCaseStatements;
 
+  /// Style of aligning consecutive TableGen cond operator colons.
+  /// \code
+  ///   !cond(!eq(size, 1) : 1,
+  /// !eq(size, 16): 1,
+  /// true : 0)
+  /// \endcode
+  /// \version 18
+  AlignConsecutiveStyle AlignConsecutiveTableGenCondOperatorColons;
+
+  /// Style of aligning consecutive TableGen DAGArg operator colons.
+  /// Intended to be used with TableGenBreakInsideDAGArgList
+  /// \code
+  ///   let dagarg = (ins
+  ///   a  :$src1,
+  ///   aa :$src2,
+  ///   aaa:$src3
+  ///   )
+  /// \endcode
+  /// \version 18
+  AlignConsecutiveStyle AlignConsecutiveTableGenBreakingDAGArgColons;
+
+  /// Style of aligning consecutive TableGen def colons.
+  /// \code
+  ///   def Def   : Parent {}
+  ///   def DefDef: Parent {}
+  ///   def DefDefDef : Parent {}
+  /// \endcode
+  /// \version 18
+  AlignConsecutiveStyle AlignConsecutiveTableGenDefinitions;

HazardyKnusperkeks wrote:

Couldn't you reuse `AlignConsecutiveDeclarations` and handle table gen there?

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


[clang] [clang-format] Support of TableGen formatting. (PR #76059)

2023-12-22 Thread Björn Schäpers via cfe-commits

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

I think we all would gain a lot, if you could split this into multiple pull 
requests. The discussion can be more focused and you have a greater chance to 
get something merged. Similar to the Verilog changes.

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


[clang] [clang-format] Support of TableGen formatting. (PR #76059)

2023-12-22 Thread Björn Schäpers via cfe-commits


@@ -4656,6 +4687,15 @@ struct FormatStyle {
   /// \version 8
   std::vector StatementMacros;
 
+  /// Tablegen

HazardyKnusperkeks wrote:

We need a bit more documentation here.

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


[clang] [clang-format] Support of TableGen formatting. (PR #76059)

2023-12-22 Thread Björn Schäpers via cfe-commits

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


[clang] [Sema] Fix crash on invalid code with parenthesized aggregate initialization (PR #76232)

2023-12-22 Thread Vladimir Vereschaka via cfe-commits

vvereschaka wrote:

these changes break the libc++ tests - 
`llvm-libc++-static.cfg.in::transform_error.mandates.verify.cpp`

```
# .---command stderr
# | error: 'expected-error' diagnostics expected but not seen: 
# |   File * Line * (directive at 
C:\buildbot\as-builder-2\x-aarch64\llvm-project\libcxx\test\libcxx\utilities\expected\expected.void\transform_error.mandates.verify.cpp:49):
 {{(excess elements in struct initializer|no matching constructor for 
initialization of)}}{{.*}}
# |   File * Line * (directive at 
C:\buildbot\as-builder-2\x-aarch64\llvm-project\libcxx\test\libcxx\utilities\expected\expected.void\transform_error.mandates.verify.cpp:53):
 {{(excess elements in struct initializer|no matching constructor for 
initialization of)}}{{.*}}
# |   File * Line * (directive at 
C:\buildbot\as-builder-2\x-aarch64\llvm-project\libcxx\test\libcxx\utilities\expected\expected.void\transform_error.mandates.verify.cpp:61):
 {{(excess elements in struct initializer|no matching constructor for 
initialization of)}}{{.*}}
# |   File * Line * (directive at 
C:\buildbot\as-builder-2\x-aarch64\llvm-project\libcxx\test\libcxx\utilities\expected\expected.void\transform_error.mandates.verify.cpp:63):
 {{(excess elements in struct initializer|no matching constructor for 
initialization of)}}{{.*}}
# |   File * Line * (directive at 
C:\buildbot\as-builder-2\x-aarch64\llvm-project\libcxx\test\libcxx\utilities\expected\expected.void\transform_error.mandates.verify.cpp:70):
 {{(excess elements in struct initializer|no matching constructor for 
initialization of)}}{{.*}}
# |   File * Line * (directive at 
C:\buildbot\as-builder-2\x-aarch64\llvm-project\libcxx\test\libcxx\utilities\expected\expected.void\transform_error.mandates.verify.cpp:72):
 {{(excess elements in struct initializer|no matching constructor for 
initialization of)}}{{.*}}
# |   File * Line * (directive at 
C:\buildbot\as-builder-2\x-aarch64\llvm-project\libcxx\test\libcxx\utilities\expected\expected.void\transform_error.mandates.verify.cpp:79):
 {{(excess elements in struct initializer|no matching constructor for 
initialization of)}}{{.*}}
# |   File * Line * (directive at 
C:\buildbot\as-builder-2\x-aarch64\llvm-project\libcxx\test\libcxx\utilities\expected\expected.void\transform_error.mandates.verify.cpp:81):
 {{(excess elements in struct initializer|no matching constructor for 
initialization of)}}{{.*}}
# | 8 errors generated.
# `-
# error: command failed with exit status: 1

```

https://lab.llvm.org/buildbot/#/builders/119/builds/16381
https://lab.llvm.org/buildbot/#/builders/60/builds/15226

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


[clang] [clang-format] Fix a bug in annotating function declaration names (PR #76206)

2023-12-22 Thread Björn Schäpers via cfe-commits

HazardyKnusperkeks wrote:

> Thanks for doing this. Does it mean we would have to add every type we use to 
> our config? It would be much more convenient if clang-format treated the 
> argument list the same way that it treats in definitions. For example
> 
> ```shell
> printf "int\niso_time(time_t) { return 1; }\n" | clang-format -style='{ 
> AlwaysBreakAfterReturnType: All }'
> ```
> 
> gives
> 
> ```c
> int
> iso_time(time_t) {
>   return 1;
> }
> ```
> 
> whereas
> 
> ```shell
> printf "int\niso_time(time_t);\n" | clang-format -style='{ 
> AlwaysBreakAfterReturnType: All }'
> ```
> 
> will need a config edit to work.
> 

`clang-format` doesn't know what are types, except for the keywords. So there 
is no way to decide if this is a function declaration without naming the 
parameters, or a variable declaration with a constructor call.

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


[clang] [clang-format] Fix a bug in annotating function declaration names (PR #76206)

2023-12-22 Thread Björn Schäpers via cfe-commits

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


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


[flang] [clang] [flang][driver] Remove Fortain_main static library from linking stages (PR #75816)

2023-12-22 Thread via cfe-commits


@@ -163,6 +163,62 @@ forward compiler options to the frontend driver, 
`flang-new -fc1`.
 You can read more on the design of `clangDriver` in Clang's [Driver Design &
 Internals](https://clang.llvm.org/docs/DriverInternals.html).
 
+## Linker Driver
+When used as a linker, Flang's frontend driver assembles the command line for 
an
+external linker command (e.g., LLVM's `lld`) and invokes it to create the final
+executable by linking static and shared libraries together with all the
+translation units supplied as object files.
+
+By default, the Flang linker driver adds several libraries to the linker
+invocation to make sure that all entrypoints for program start
+(Fortran's program unit) and runtime routines can be resolved by the linker.
+
+An abridged example (only showing the Fortran specific linker flags, omission
+indicated by `[...]`) for such a linker invocation on a Linux system would look
+like this:
+
+```
+$ flang -v -o example example.o
+"/usr/bin/ld" [...] example.o [...] "--whole-archive" "-lFortran_main"
+"--no-whole-archive" "-lFortranRuntime" "-lFortranDecimal" [...]
+```
+
+The automatically added libraries are:
+
+* `Fortran_main`: Provides the main entry point `main` that then invokes
+  `_QQmain` with the Fortran program unit.  This library has a dependency to
+  the `FortranRuntime` library.
+* `FortranRuntime`: Provides most of the Flang runtime library.
+* `FortranDecimal`: Provides operations for decimal numbers.
+
+The default is that, when using Flang as the linker, one of the Fortran
+translation units provides the program unit and therefore it is assumed that
+Fortran is the main code part (calling into C/C++ routines via `BIND (C)`
+interfaces).  When composing the linker commandline, Flang uses
+`--whole-archive` and `--no-whole-archive` (Windows: `/WHOLEARCHIVE:`,
+Darwin & AIX: *not implemented yet*) to make sure that all for `Fortran_main`
+is processed by the linker.  This is done to issue a proper error message when
+multiple definitions of `main` occur.  This happens, for instance, when linking
+a code that has a Fortran program unit with a C/C++ code that also defines a
+`main` function.  A user may be required to explicitly provide the C++ runtime
+libraries at link time (e.g., via `-lstdc++` for STL)
+
+If the code is C/C++ based and invokes Fortran routines, one can either use 
Clang
+for Flang as the linker driver.  If Clang is used, it will automatically all
+required runtime libraries needed by C++ (e.g., for STL) to the linker 
invocation.
+In this case, one has to explicitly provide the Fortran runtime libraries
+`FortranRuntime` and/or `FortranDecimal`.  An alternative is to use Flang to 
link
+and use the `-fno-fortran-main` flag.  This flag removes
+`Fortran_main` from the linker stage and hence requires one of the C/C++
+translation units to provide a definition of the `main` function. In this case,
+it may be required to explicitly supply C++ runtime libraries as mentioned 
above.
+
+When creating shared or static libraries, `Fortran_main` is automatically

kkwli wrote:

How about this?

When creating shared or static libraries using Flang with `-shared` or 
`-static` flag, `Fortran_main` is automatically removed from the linker stage 
(i.e. -fno-fortran-main is on by default).

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


[clang] [flang] [flang][driver] Remove Fortain_main static library from linking stages (PR #75816)

2023-12-22 Thread via cfe-commits


@@ -163,6 +163,62 @@ forward compiler options to the frontend driver, 
`flang-new -fc1`.
 You can read more on the design of `clangDriver` in Clang's [Driver Design &
 Internals](https://clang.llvm.org/docs/DriverInternals.html).
 
+## Linker Driver
+When used as a linker, Flang's frontend driver assembles the command line for 
an
+external linker command (e.g., LLVM's `lld`) and invokes it to create the final
+executable by linking static and shared libraries together with all the
+translation units supplied as object files.
+
+By default, the Flang linker driver adds several libraries to the linker
+invocation to make sure that all entrypoints for program start
+(Fortran's program unit) and runtime routines can be resolved by the linker.
+
+An abridged example (only showing the Fortran specific linker flags, omission
+indicated by `[...]`) for such a linker invocation on a Linux system would look
+like this:
+
+```
+$ flang -v -o example example.o
+"/usr/bin/ld" [...] example.o [...] "--whole-archive" "-lFortran_main"
+"--no-whole-archive" "-lFortranRuntime" "-lFortranDecimal" [...]
+```
+
+The automatically added libraries are:
+
+* `Fortran_main`: Provides the main entry point `main` that then invokes
+  `_QQmain` with the Fortran program unit.  This library has a dependency to
+  the `FortranRuntime` library.
+* `FortranRuntime`: Provides most of the Flang runtime library.
+* `FortranDecimal`: Provides operations for decimal numbers.
+
+The default is that, when using Flang as the linker, one of the Fortran
+translation units provides the program unit and therefore it is assumed that
+Fortran is the main code part (calling into C/C++ routines via `BIND (C)`
+interfaces).  When composing the linker commandline, Flang uses
+`--whole-archive` and `--no-whole-archive` (Windows: `/WHOLEARCHIVE:`,
+Darwin & AIX: *not implemented yet*) to make sure that all for `Fortran_main`
+is processed by the linker.  This is done to issue a proper error message when
+multiple definitions of `main` occur.  This happens, for instance, when linking
+a code that has a Fortran program unit with a C/C++ code that also defines a
+`main` function.  A user may be required to explicitly provide the C++ runtime
+libraries at link time (e.g., via `-lstdc++` for STL)
+
+If the code is C/C++ based and invokes Fortran routines, one can either use 
Clang
+for Flang as the linker driver.  If Clang is used, it will automatically all

kkwli wrote:

```suggestion
or Flang as the linker driver.  If Clang is used, it will automatically all
```

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


[flang] [clang] [flang][driver] Remove Fortain_main static library from linking stages (PR #75816)

2023-12-22 Thread via cfe-commits


@@ -163,6 +163,62 @@ forward compiler options to the frontend driver, 
`flang-new -fc1`.
 You can read more on the design of `clangDriver` in Clang's [Driver Design &
 Internals](https://clang.llvm.org/docs/DriverInternals.html).
 
+## Linker Driver
+When used as a linker, Flang's frontend driver assembles the command line for 
an
+external linker command (e.g., LLVM's `lld`) and invokes it to create the final
+executable by linking static and shared libraries together with all the
+translation units supplied as object files.
+
+By default, the Flang linker driver adds several libraries to the linker
+invocation to make sure that all entrypoints for program start
+(Fortran's program unit) and runtime routines can be resolved by the linker.
+
+An abridged example (only showing the Fortran specific linker flags, omission
+indicated by `[...]`) for such a linker invocation on a Linux system would look
+like this:
+
+```
+$ flang -v -o example example.o
+"/usr/bin/ld" [...] example.o [...] "--whole-archive" "-lFortran_main"
+"--no-whole-archive" "-lFortranRuntime" "-lFortranDecimal" [...]
+```
+
+The automatically added libraries are:
+
+* `Fortran_main`: Provides the main entry point `main` that then invokes
+  `_QQmain` with the Fortran program unit.  This library has a dependency to
+  the `FortranRuntime` library.
+* `FortranRuntime`: Provides most of the Flang runtime library.
+* `FortranDecimal`: Provides operations for decimal numbers.
+
+The default is that, when using Flang as the linker, one of the Fortran
+translation units provides the program unit and therefore it is assumed that
+Fortran is the main code part (calling into C/C++ routines via `BIND (C)`
+interfaces).  When composing the linker commandline, Flang uses
+`--whole-archive` and `--no-whole-archive` (Windows: `/WHOLEARCHIVE:`,
+Darwin & AIX: *not implemented yet*) to make sure that all for `Fortran_main`
+is processed by the linker.  This is done to issue a proper error message when
+multiple definitions of `main` occur.  This happens, for instance, when linking
+a code that has a Fortran program unit with a C/C++ code that also defines a
+`main` function.  A user may be required to explicitly provide the C++ runtime
+libraries at link time (e.g., via `-lstdc++` for STL)
+
+If the code is C/C++ based and invokes Fortran routines, one can either use 
Clang
+for Flang as the linker driver.  If Clang is used, it will automatically all
+required runtime libraries needed by C++ (e.g., for STL) to the linker 
invocation.

kkwli wrote:

> If Clang is used, it will automatically all required runtime libraries needed 
> by C++ (e.g., for STL) to the linker invocation.

Not sure if it depends on the invocation (clang vs clang++). I guess clang 
invocation will not automatically link the C++ libraries.


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


[clang] [clang] Better bitfield access units (PR #65742)

2023-12-22 Thread Nathan Sidwell via cfe-commits

urnathan wrote:

ping?

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


[clang] [clang][NFC] Adjust TBAA Base Info API (PR #73263)

2023-12-22 Thread Nathan Sidwell via cfe-commits

urnathan wrote:

ping?

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


[clang] [clang-format] Add an fnmatch-like function for .clang-format-ignore (PR #76021)

2023-12-22 Thread Björn Schäpers via cfe-commits


@@ -0,0 +1,169 @@
+//===- unittest/Format/MatchFilePathTest.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "../../lib/Format/MatchFilePath.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace format {
+namespace {
+
+class MatchFilePathTest : public ::testing::Test {
+protected:
+  bool match(llvm::StringRef FilePath, llvm::StringRef Pattern) {
+return matchFilePath(Pattern, FilePath);
+  }
+};
+
+// Most of the test cases below are from:
+// https://github.com/python/cpython/blob/main/Lib/test/test_fnmatch.py
+
+TEST_F(MatchFilePathTest, Wildcard) {
+  EXPECT_TRUE(match("abc", "?*?"));
+  EXPECT_TRUE(match("abc", "???*"));
+  EXPECT_TRUE(match("abc", "*???"));
+  EXPECT_TRUE(match("abc", "???"));
+  EXPECT_TRUE(match("abc", "*"));
+  EXPECT_TRUE(match("abc", "ab[cd]"));
+  EXPECT_TRUE(match("abc", "ab[!de]"));
+  EXPECT_TRUE(!match("abc", "ab[de]"));

HazardyKnusperkeks wrote:

```suggestion
  EXPECT_FALSE(match("abc", "ab[de]"));
```
Way better to read.

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


[llvm] [clang] [SPARC] Support reserving arbitrary general purpose registers (PR #74927)

2023-12-22 Thread Sergei Barannikov via cfe-commits


@@ -1125,6 +1130,10 @@ Register SparcTargetLowering::getRegisterByName(const 
char* RegName, LLT VT,
 .Case("g4", SP::G4).Case("g5", SP::G5).Case("g6", SP::G6).Case("g7", 
SP::G7)
 .Default(0);
 
+  const SparcRegisterInfo *TRI = Subtarget->getRegisterInfo();
+  if (!TRI->isReservedReg(MF, Reg))
+Reg = 0;

s-barannikov wrote:

I think we should follow gcc as much as possible. Some info can be found 
[here](https://gcc.gnu.org/onlinedocs/gcc/Global-Register-Variables.html).
In particular, gcc does not seem to require -ffixed-reg option for a register 
used in 'register asm' construct (global or local). Reserving an ABI register 
does not prohibit function calls either. I've been only able to get an error 
when trying to reserve the frame pointer.


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


[clang] [Sema] Fix crash on invalid code with parenthesized aggregate initialization (PR #76232)

2023-12-22 Thread Vitaly Buka via cfe-commits

vitalybuka wrote:

Breaks multiple bots
https://lab.llvm.org/buildbot/#/builders/168/builds/17604
https://lab.llvm.org/buildbot/#/builders/74/builds/24426
https://lab.llvm.org/buildbot/#/builders/239/builds/4971
and some others

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


[flang] [clang] [flang][Driver] Support `-pthread` to the frontend. (PR #75739)

2023-12-22 Thread Kareem Ergawy via cfe-commits

ergawy wrote:

Abandoning this PR since for the GNU toolchain there is no need to explicitly 
link with pthread to use the API.

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


[flang] [clang] [flang][Driver] Support `-pthread` to the frontend. (PR #75739)

2023-12-22 Thread Kareem Ergawy via cfe-commits

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


[clang] [llvm] [Clang][IR] add TBAA metadata on pointer, union and array types. (PR #75177)

2023-12-22 Thread Nikita Popov via cfe-commits

nikic wrote:

(As usual, please make any LLVM changes separately from Clang changes, 
especially if they affect IR design.)

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


[llvm] [clang] [Clang][IR] add TBAA metadata on pointer, union and array types. (PR #75177)

2023-12-22 Thread Bushev Dmitry via cfe-commits


@@ -105,13 +105,28 @@ static bool isValidBaseType(QualType QTy) {
 if (RD->hasFlexibleArrayMember())
   return false;
 // RD can be struct, union, class, interface or enum.
-// For now, we only handle struct and class.
-if (RD->isStruct() || RD->isClass())
+if (RD->isStruct() || RD->isClass() ||
+(RD->isUnion() && CodeGenOpts.UnionTBAA))
   return true;
   }
   return false;
 }
 
+std::string CodeGenTBAA::getPointeeName(const Type *Ty) {
+  if (isa(Ty)) {
+llvm::MDNode *ScalarMD = getTypeInfoHelper(Ty);
+auto  = ScalarMD->getOperand(CodeGenOpts.NewStructPathTBAA ? 2 : 0);
+assert(isa(Op) && "Expected MDString operand");
+return cast(Op)->getString().str();
+  }
+
+  if (Ty->isIncompleteType())
+return "";

dybv-sc wrote:

Removed. I was uncertain in a moment what to do in that case, but after 
revisiting C/C++ standard I learned that there is no difference between 
complete and incomplete types when considering their similarity/compatibility.

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


[llvm] [clang] [Clang][IR] add TBAA metadata on pointer, union and array types. (PR #75177)

2023-12-22 Thread Bushev Dmitry via cfe-commits

dybv-sc wrote:

@rjmccall , I updated part of commit that handles pointers. Added comment with 
C/C++ standard references to explain my decisions. Could you please review it 
again?

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


[clang] [llvm] [Clang][IR] add TBAA metadata on pointer, union and array types. (PR #75177)

2023-12-22 Thread Bushev Dmitry via cfe-commits


@@ -216,6 +216,9 @@ ENUM_CODEGENOPT(StructReturnConvention, 
StructReturnConventionKind, 2, SRCK_Defa
 CODEGENOPT(RelaxAll  , 1, 0) ///< Relax all machine code instructions.
 CODEGENOPT(RelaxedAliasing   , 1, 0) ///< Set when -fno-strict-aliasing is 
enabled.
 CODEGENOPT(StructPathTBAA, 1, 0) ///< Whether or not to use struct-path 
TBAA.
+CODEGENOPT(UnionTBAA, 1, 0) ///< Whether or not to use struct-path TBAA on 
unions.
+CODEGENOPT(PointerTBAA, 1, 0) ///< Whether or not to generate TBAA on 
pointers.
+CODEGENOPT(ArrayTBAA, 1, 0) ///< Whether or not to generate TBAA on arrays.

dybv-sc wrote:

fixed

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


[clang] [llvm] [Clang][IR] add TBAA metadata on pointer, union and array types. (PR #75177)

2023-12-22 Thread Bushev Dmitry via cfe-commits


@@ -184,13 +199,24 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type 
*Ty) {
 return getChar();
 
   // Handle pointers and references.
-  // TODO: Implement C++'s type "similarity" and consider dis-"similar"
-  // pointers distinct.
-  if (Ty->isPointerType() || Ty->isReferenceType())
-return createScalarTypeNode("any pointer", getChar(), Size);
+  // Pointer types never alias if their pointee type is distinct.
+  if ((Ty->isPointerType() || Ty->isReferenceType())) {
+llvm::MDNode *AnyPtr = createScalarTypeNode("any pointer", getChar(), 
Size);
+if (!CodeGenOpts.PointerTBAA)
+  return AnyPtr;
+unsigned PtrDepth = 0;
+do {
+  PtrDepth++;
+  Ty = Ty->getPointeeType().getTypePtr();
+} while (!Ty->getPointeeType().isNull());

dybv-sc wrote:

Actually I want to look for member pointers. In [conv.qual] of C++ standard 
mentioned:

> each Pi is “pointer to” (9.3.4.2), “pointer to member of
> class Ci of type” (9.3.4.4), “array of Ni”, or “array of unknown bound of” 
> (9.3.4.5

Where Pi is i-th inderection in qualification decomposition. I want to consider 
all those types of indirection.
I think, all I do if I get rid of getPointeeType() is just move most of it's 
checks outside.

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


[clang] [llvm] [clang-tools-extra] [flang] [flang] Pass to add frame pointer attribute (PR #74598)

2023-12-22 Thread Radu Salavat via cfe-commits

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


[clang-tools-extra] [clang] [llvm] [flang] [flang] Pass to add frame pointer attribute (PR #74598)

2023-12-22 Thread Radu Salavat via cfe-commits

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


[clang-tools-extra] [clang] [llvm] [flang] [flang] Pass to add frame pointer attribute (PR #74598)

2023-12-22 Thread Radu Salavat via cfe-commits

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


[clang-tools-extra] [clang] [llvm] [flang] [flang] Pass to add frame pointer attribute (PR #74598)

2023-12-22 Thread Radu Salavat via cfe-commits

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


[clang-tools-extra] [clang] [llvm] [flang] [flang] Pass to add frame pointer attribute (PR #74598)

2023-12-22 Thread Radu Salavat via cfe-commits




Radu2k wrote:

That looks good to me, thought it needs to check line by 
line(flang/test/Driver/mlir-debug-pass-pipeline.f90 - lines 35-38) but will 
update, replacing ALL-NEXT to ALL at line 85.

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


[clang] [flang] [flang][driver] Remove Fortain_main static library from linking stages (PR #75816)

2023-12-22 Thread Michael Klemm via cfe-commits


@@ -163,6 +163,40 @@ forward compiler options to the frontend driver, 
`flang-new -fc1`.
 You can read more on the design of `clangDriver` in Clang's [Driver Design &
 Internals](https://clang.llvm.org/docs/DriverInternals.html).
 
+## Linker Driver
+When used as a linker, Flang's frontend driver assembles the command line for 
an
+external linker command (e.g., LLVM's `lld`) and invokes it to create the final
+executable by linking static and shared libraries together with all the
+translation units supplied as object files.
+
+By default, the Flang linker driver adds several libraries to the linker
+invocation to make sure that all entrypoints for program start
+(Fortran's program unit) and runtime routines can be resolved by the linker.
+The libraries are:
+
+* `Fortran_main`: Provides the main entry point `main` that then invokes
+  `_QQmain` with the Fortran program unit.  This library has a dependency to
+  the `FortranRuntime` library.
+* `FortranRuntime`: Provides most of the Flang runtime library.
+* `FortranDecimal`: Provides operations for decimal numbers.
+
+The default is that, when using Flang as the linker, one of the Fortran
+translation units provides the program unit and therefore it is assumed that
+Fortran is the main code part (calling into C/C++ routines via `BIND
+(C)` interfaces).  When composing the linker commandline, Flang uses
+`--whole-archive` and `--no-whole-archive` (Windows: `/WHOLEARCHIVE:`,
+Darwin: *not implemented yet*) to make sure that all for `Fortran_main` is
+processed by the linker.  This is done to issue a proper error message when
+multiple definitions of `main` occur.  This happens, for instance, when linking
+a code that has a Fortran program unit with a C/C++ code that also defines a
+`main` function.
+
+If the code is C/C++ based and invokes Fortran routines, either use Clang as 
the
+linker driver (supplying `FortranRuntime` and/or `FortranDecimal` to the linker

mjklemm wrote:

I have tried to clarify a bit what the two choices are when using Clang vs 
Flang to link a program. Is this better now?

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


[clang] [flang] [flang][driver] Remove Fortain_main static library from linking stages (PR #75816)

2023-12-22 Thread Michael Klemm via cfe-commits


@@ -163,6 +163,40 @@ forward compiler options to the frontend driver, 
`flang-new -fc1`.
 You can read more on the design of `clangDriver` in Clang's [Driver Design &
 Internals](https://clang.llvm.org/docs/DriverInternals.html).
 
+## Linker Driver

mjklemm wrote:

I have tried to capture this now.

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


[clang-tools-extra] [clang] [llvm] [flang] [flang] Pass to add frame pointer attribute (PR #74598)

2023-12-22 Thread Andrzej Warzyński via cfe-commits




banach-space wrote:

Thanks for the explanation!

> Therefore it is mandatory to add omitting frame pointer

No. You can also update the expected output. So there are 2 options. And what 
would be preferred - this test is checking pass pipelines and including 
`-fomit-frame-pointer` suggests that that flag will impact those pipelines. 
That's not the case though.

You can do this:
```
! ALL-LABEL: Fortran::lower::VerifierPass
! ALL-NEXT: 'func.func' Pipeline
! ALL: InlineElementals
! ALL-NEXT: LowerHLFIROrderedAssignments
```

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


[clang-tools-extra] [clang] [llvm] [flang] [flang] Pass to add frame pointer attribute (PR #74598)

2023-12-22 Thread Andrzej Warzyński via cfe-commits


@@ -1,9 +1,12 @@
 ! Test that flang-new forwards -fno-omit-frame-pointer and 
-fomit-frame-pointer Flang frontend
-! RUN: %flang -fno-omit-frame-pointer --target=x86-none-none -fsyntax-only 
-### %s -o %t 2>&1  | FileCheck %s
-! CHECK: "-mframe-pointer=all"
+! RUN: %flang --target=aarch64-none-none -fsyntax-only -### %s -o %t 2>&1  | 
FileCheck %s --check-prefix=CHECK-NOVALUE
+! CHECK-NOVALUE: "-mframe-pointer=non-leaf"

banach-space wrote:

See the comment at the top of the file:

> ! Test that flang-new forwards -fno-omit-frame-pointer and 
> -fomit-frame-pointer Flang frontend

In order to identify that this is indeed checking the **frontend** driver 
invocation (as per the comment, that's the intention), you need to check for 
`-fc1`. That's something that was missing here to begin with, so strictly 
speaking it's tangential to your change. But since you are updating these CHECK 
lines anyway ...

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


[clang-tools-extra] [clang-tidy] Add check readability-return-expression-in-void-function (PR #76249)

2023-12-22 Thread Piotr Zegar via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,31 @@
+//===--- AvoidReturnWithVoidValueCheck.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 "AvoidReturnWithVoidValueCheck.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+void AvoidReturnWithVoidValueCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  returnStmt(hasReturnValue(hasType(voidType(.bind("void_return"),
+  this);
+}
+
+void AvoidReturnWithVoidValueCheck::check(
+const MatchFinder::MatchResult ) {
+  const auto *VoidReturn = Result.Nodes.getNodeAs("void_return");
+  diag(VoidReturn->getBeginLoc(),
+   "return statement in void function should not return a value");

PiotrZSL wrote:

consider "return statement within a void function should not have a specified 
return value"

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


[clang-tools-extra] [clang-tidy] Add check readability-return-expression-in-void-function (PR #76249)

2023-12-22 Thread Piotr Zegar via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,33 @@
+//===--- AvoidReturnWithVoidValueCheck.h - clang-tidy ---*- 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
+//
+//===--===//
+
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_AVOIDRETURNWITHVOIDVALUECHECK_H
+#define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_AVOIDRETURNWITHVOIDVALUECHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::readability {
+
+/// Looks for statements returning expressions of type `void`.
+///
+/// For the user-facing documentation see:
+/// 
http://clang.llvm.org/extra/clang-tidy/checks/readability/avoid-return-with-void-value.html
+class AvoidReturnWithVoidValueCheck : public ClangTidyCheck {
+public:
+  AvoidReturnWithVoidValueCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult ) override;
+  std::optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }

PiotrZSL wrote:

Limit check to C++ only, look to other checks how to do that.

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


[clang-tools-extra] [clang-tidy] Add check readability-return-expression-in-void-function (PR #76249)

2023-12-22 Thread Piotr Zegar via cfe-commits
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,30 @@
+.. title:: clang-tidy - readability-avoid-return-with-void-value
+
+readability-avoid-return-with-void-value
+
+
+Complains about statements returning expressions of type ``void``. It can be
+confusing if a function returns an expression even though its return type is
+``void``.
+

PiotrZSL wrote:

Add info that in "C" those issues are detected by -Wpedantic warning.
`warning: void function 'f' should not return void expression [-Wpedantic]`

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


[clang-tools-extra] [clang-tidy] Add check readability-return-expression-in-void-function (PR #76249)

2023-12-22 Thread Piotr Zegar via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 



@@ -218,6 +218,13 @@ New checks
   Detects C++ code where a reference variable is used to extend the lifetime
   of a temporary object that has just been constructed.
 
+- New :doc:`readability-avoid-return-with-void-value
+  ` check.
+
+  Complains about statements returning expressions of type ``void``. It can be

PiotrZSL wrote:

Consider simplifying description of check make to something like "Finds return 
statements with void values used within functions with a void result type."

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


[clang-tools-extra] [clang-tidy] Add check readability-return-expression-in-void-function (PR #76249)

2023-12-22 Thread Piotr Zegar via cfe-commits
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,31 @@
+//===--- AvoidReturnWithVoidValueCheck.cpp - clang-tidy -===//

PiotrZSL wrote:

format this line to match length of line 7

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


[clang-tools-extra] [clang-tidy] Add check readability-return-expression-in-void-function (PR #76249)

2023-12-22 Thread Piotr Zegar via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,30 @@
+.. title:: clang-tidy - readability-avoid-return-with-void-value
+
+readability-avoid-return-with-void-value
+
+
+Complains about statements returning expressions of type ``void``. It can be
+confusing if a function returns an expression even though its return type is
+``void``.

PiotrZSL wrote:

consider: "Void function is intended to perform a task without producing a 
return value. Including a return value in such functions can lead to confusion 
and may miscommunicate the function's intended behavior." or something similar.

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


[clang-tools-extra] [clang-tidy] Add check readability-return-expression-in-void-function (PR #76249)

2023-12-22 Thread Piotr Zegar via cfe-commits
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= 
Message-ID:
In-Reply-To: 


https://github.com/PiotrZSL commented:

Last nits.

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


[clang-tools-extra] [clang-tidy] Add check readability-return-expression-in-void-function (PR #76249)

2023-12-22 Thread Piotr Zegar via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 


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


[llvm] [clang-tools-extra] [flang] [clang] [flang] Pass to add frame pointer attribute (PR #74598)

2023-12-22 Thread Radu Salavat via cfe-commits


@@ -51,9 +51,9 @@
 ! Content to check from the MLIR outputs
 !--
 ! MLIR-FIR-NOT: llvm.func
-! MLIR-FIR: func.func @{{.*}}main() {
+! MLIR-FIR: func.func @{{.*}}main(){{.*}}{

Radu2k wrote:

Since this is target dependent, frame pointer will be added or not. It is 
either adding `{{.*}}` or adding `-fomit-frame-pointer`.

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


[llvm] [clang-tools-extra] [flang] [clang] [flang] Pass to add frame pointer attribute (PR #74598)

2023-12-22 Thread Andrzej Warzyński via cfe-commits


@@ -245,6 +245,24 @@ static void 
parseCodeGenArgs(Fortran::frontend::CodeGenOptions ,
 
   opts.AliasAnalysis = opts.OptimizationLevel > 0;
 
+  if (const llvm::opt::Arg *a =
+  args.getLastArg(clang::driver::options::OPT_mframe_pointer_EQ)) {
+llvm::StringRef s = a->getValue();
+
+if (!(s == "none" || s == "non-leaf" || s == "all")) {
+  const auto debugWarningId = diags.getCustomDiagID(
+  clang::DiagnosticsEngine::Error, "Frame pointer: %0");

banach-space wrote:

Now I see :)

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


[llvm] [clang-tools-extra] [flang] [clang] [flang] Pass to add frame pointer attribute (PR #74598)

2023-12-22 Thread Radu Salavat via cfe-commits

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


[llvm] [clang-tools-extra] [flang] [clang] [flang] Pass to add frame pointer attribute (PR #74598)

2023-12-22 Thread Radu Salavat via cfe-commits


@@ -1,9 +1,12 @@
 ! Test that flang-new forwards -fno-omit-frame-pointer and 
-fomit-frame-pointer Flang frontend
-! RUN: %flang -fno-omit-frame-pointer --target=x86-none-none -fsyntax-only 
-### %s -o %t 2>&1  | FileCheck %s
-! CHECK: "-mframe-pointer=all"
+! RUN: %flang --target=aarch64-none-none -fsyntax-only -### %s -o %t 2>&1  | 
FileCheck %s --check-prefix=CHECK-NOVALUE
+! CHECK-NOVALUE: "-mframe-pointer=non-leaf"

Radu2k wrote:

If we add this then it will be added as `"-fc1"{{.*}}"`.  Why is it necessary? 

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


[flang] [clang] [lldb] [clang-tools-extra] [compiler-rt] [libcxx] [llvm] [libc] [RegAllocFast] Refactor dominates algorithm for large basic block (PR #72250)

2023-12-22 Thread Nikita Popov via cfe-commits


@@ -62,6 +62,107 @@ static RegisterRegAlloc fastRegAlloc("fast", "fast register 
allocator",
 
 namespace {
 
+/// Assign ascending index for instructions in machine basic block. The index
+/// can be used to determine dominance between instructions in same MBB.
+class InstrPosIndexes {
+public:
+  void init(const MachineBasicBlock ) {
+CurMBB = 
+Instr2PosIndex.clear();
+uint64_t LastIndex = 0;
+for (const MachineInstr  : MBB) {
+  LastIndex += InstrDist;
+  Instr2PosIndex[] = LastIndex;
+}

nikic wrote:

Can we do this lazily, on first query?

It looks like dominates() is actually only used in very rare situations (where 
a block branches back to itself), so populating this map is unnecessary for 
most blocks.



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


[clang] [Clang][RISCV] Add missing support for `__builtin_riscv_cpop_32/64` (PR #76256)

2023-12-22 Thread via cfe-commits

llvmbot wrote:




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

Author: Yingwei Zheng (dtcxzyw)


Changes

This patch adds support for `__builtin_riscv_cpop_32/64`, which are used by 
`riscv_bitmanip.h`.
See also 
https://github.com/llvm/llvm-project/blob/04c473bea3e0f135432698fcaafab52e1fe1b5ec/clang/lib/Headers/riscv_bitmanip.h#L35-L60.
Thank @Liaoshihua for reporting this!


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


3 Files Affected:

- (modified) clang/include/clang/Basic/BuiltinsRISCV.def (+2) 
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+10) 
- (modified) clang/test/CodeGen/RISCV/rvb-intrinsics/zbb.c (+26) 


``diff
diff --git a/clang/include/clang/Basic/BuiltinsRISCV.def 
b/clang/include/clang/Basic/BuiltinsRISCV.def
index 1528b18c82eade..1df1c53733cfa1 100644
--- a/clang/include/clang/Basic/BuiltinsRISCV.def
+++ b/clang/include/clang/Basic/BuiltinsRISCV.def
@@ -22,6 +22,8 @@ TARGET_BUILTIN(__builtin_riscv_clz_32, "UiUi", "nc", 
"zbb|xtheadbb")
 TARGET_BUILTIN(__builtin_riscv_clz_64, "UiUWi", "nc", "zbb|xtheadbb,64bit")
 TARGET_BUILTIN(__builtin_riscv_ctz_32, "UiUi", "nc", "zbb")
 TARGET_BUILTIN(__builtin_riscv_ctz_64, "UiUWi", "nc", "zbb,64bit")
+TARGET_BUILTIN(__builtin_riscv_cpop_32, "UiUi", "nc", "zbb")
+TARGET_BUILTIN(__builtin_riscv_cpop_64, "UiUWi", "nc", "zbb,64bit")
 
 // Zbc or Zbkc extension
 TARGET_BUILTIN(__builtin_riscv_clmul_32, "UiUiUi", "nc", "zbc|zbkc")
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 5081062da2862e..64210e76ed2218 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -20696,6 +20696,8 @@ Value *CodeGenFunction::EmitRISCVBuiltinExpr(unsigned 
BuiltinID,
   case RISCV::BI__builtin_riscv_clz_64:
   case RISCV::BI__builtin_riscv_ctz_32:
   case RISCV::BI__builtin_riscv_ctz_64:
+  case RISCV::BI__builtin_riscv_cpop_32:
+  case RISCV::BI__builtin_riscv_cpop_64:
   case RISCV::BI__builtin_riscv_clmul_32:
   case RISCV::BI__builtin_riscv_clmul_64:
   case RISCV::BI__builtin_riscv_clmulh_32:
@@ -20735,6 +20737,14 @@ Value *CodeGenFunction::EmitRISCVBuiltinExpr(unsigned 
BuiltinID,
"cast");
   return Result;
 }
+case RISCV::BI__builtin_riscv_cpop_32:
+case RISCV::BI__builtin_riscv_cpop_64: {
+  Value *Result = Builder.CreateUnaryIntrinsic(Intrinsic::ctpop, Ops[0]);
+  if (Result->getType() != ResultType)
+Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/ true,
+   "cast");
+  return Result;
+}
 
 // Zbc
 case RISCV::BI__builtin_riscv_clmul_32:
diff --git a/clang/test/CodeGen/RISCV/rvb-intrinsics/zbb.c 
b/clang/test/CodeGen/RISCV/rvb-intrinsics/zbb.c
index 3a421f8c6cd421..a5715e330172bd 100644
--- a/clang/test/CodeGen/RISCV/rvb-intrinsics/zbb.c
+++ b/clang/test/CodeGen/RISCV/rvb-intrinsics/zbb.c
@@ -82,3 +82,29 @@ unsigned int ctz_64(unsigned long a) {
   return __builtin_riscv_ctz_64(a);
 }
 #endif
+
+// RV32ZBB-LABEL: @cpop_32(
+// RV32ZBB-NEXT:  entry:
+// RV32ZBB-NEXT:[[TMP0:%.*]] = call i32 @llvm.ctpop.i32(i32 [[A:%.*]])
+// RV32ZBB-NEXT:ret i32 [[TMP0]]
+//
+// RV64ZBB-LABEL: @cpop_32(
+// RV64ZBB-NEXT:  entry:
+// RV64ZBB-NEXT:[[TMP0:%.*]] = call i32 @llvm.ctpop.i32(i32 [[A:%.*]])
+// RV64ZBB-NEXT:ret i32 [[TMP0]]
+//
+unsigned int cpop_32(unsigned int a) {
+  return __builtin_riscv_cpop_32(a);
+}
+
+#if __riscv_xlen == 64
+// RV64ZBB-LABEL: @cpop_64(
+// RV64ZBB-NEXT:  entry:
+// RV64ZBB-NEXT:[[TMP0:%.*]] = call i64 @llvm.ctpop.i64(i64 [[A:%.*]])
+// RV64ZBB-NEXT:[[CAST:%.*]] = trunc i64 [[TMP0]] to i32
+// RV64ZBB-NEXT:ret i32 [[CAST]]
+//
+unsigned int cpop_64(unsigned long a) {
+  return __builtin_riscv_cpop_64(a);
+}
+#endif

``




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


[clang-tools-extra] [llvm] [clang] [flang] [flang] Pass to add frame pointer attribute (PR #74598)

2023-12-22 Thread Radu Salavat via cfe-commits




Radu2k wrote:

This is needed because depending on the target, if the frame pointer is not 
specified, then the best option will be automatically added, therefore a 

```
'func.func' Pipeline
  FunctionAttr
```
will appear or not, depending of the target, at the end of the file. 

Therefore it is mandatory to add omitting frame pointer.

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


[clang] [Clang][RISCV] Add missing support for `__builtin_riscv_cpop_32/64` (PR #76256)

2023-12-22 Thread Yingwei Zheng via cfe-commits

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

This patch adds support for `__builtin_riscv_cpop_32/64`, which are used by 
`riscv_bitmanip.h`.
See also 
https://github.com/llvm/llvm-project/blob/04c473bea3e0f135432698fcaafab52e1fe1b5ec/clang/lib/Headers/riscv_bitmanip.h#L35-L60.
Thank @Liaoshihua for reporting this!


>From a69599fcda5f1a4df13ec0bfe3432ba39ef09246 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Sat, 23 Dec 2023 01:21:39 +0800
Subject: [PATCH] [Clang][RISCV] Add missing support for
 __builtin_riscv_cpop_32/64

---
 clang/include/clang/Basic/BuiltinsRISCV.def   |  2 ++
 clang/lib/CodeGen/CGBuiltin.cpp   | 10 +++
 clang/test/CodeGen/RISCV/rvb-intrinsics/zbb.c | 26 +++
 3 files changed, 38 insertions(+)

diff --git a/clang/include/clang/Basic/BuiltinsRISCV.def 
b/clang/include/clang/Basic/BuiltinsRISCV.def
index 1528b18c82eade..1df1c53733cfa1 100644
--- a/clang/include/clang/Basic/BuiltinsRISCV.def
+++ b/clang/include/clang/Basic/BuiltinsRISCV.def
@@ -22,6 +22,8 @@ TARGET_BUILTIN(__builtin_riscv_clz_32, "UiUi", "nc", 
"zbb|xtheadbb")
 TARGET_BUILTIN(__builtin_riscv_clz_64, "UiUWi", "nc", "zbb|xtheadbb,64bit")
 TARGET_BUILTIN(__builtin_riscv_ctz_32, "UiUi", "nc", "zbb")
 TARGET_BUILTIN(__builtin_riscv_ctz_64, "UiUWi", "nc", "zbb,64bit")
+TARGET_BUILTIN(__builtin_riscv_cpop_32, "UiUi", "nc", "zbb")
+TARGET_BUILTIN(__builtin_riscv_cpop_64, "UiUWi", "nc", "zbb,64bit")
 
 // Zbc or Zbkc extension
 TARGET_BUILTIN(__builtin_riscv_clmul_32, "UiUiUi", "nc", "zbc|zbkc")
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 5081062da2862e..64210e76ed2218 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -20696,6 +20696,8 @@ Value *CodeGenFunction::EmitRISCVBuiltinExpr(unsigned 
BuiltinID,
   case RISCV::BI__builtin_riscv_clz_64:
   case RISCV::BI__builtin_riscv_ctz_32:
   case RISCV::BI__builtin_riscv_ctz_64:
+  case RISCV::BI__builtin_riscv_cpop_32:
+  case RISCV::BI__builtin_riscv_cpop_64:
   case RISCV::BI__builtin_riscv_clmul_32:
   case RISCV::BI__builtin_riscv_clmul_64:
   case RISCV::BI__builtin_riscv_clmulh_32:
@@ -20735,6 +20737,14 @@ Value *CodeGenFunction::EmitRISCVBuiltinExpr(unsigned 
BuiltinID,
"cast");
   return Result;
 }
+case RISCV::BI__builtin_riscv_cpop_32:
+case RISCV::BI__builtin_riscv_cpop_64: {
+  Value *Result = Builder.CreateUnaryIntrinsic(Intrinsic::ctpop, Ops[0]);
+  if (Result->getType() != ResultType)
+Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/ true,
+   "cast");
+  return Result;
+}
 
 // Zbc
 case RISCV::BI__builtin_riscv_clmul_32:
diff --git a/clang/test/CodeGen/RISCV/rvb-intrinsics/zbb.c 
b/clang/test/CodeGen/RISCV/rvb-intrinsics/zbb.c
index 3a421f8c6cd421..a5715e330172bd 100644
--- a/clang/test/CodeGen/RISCV/rvb-intrinsics/zbb.c
+++ b/clang/test/CodeGen/RISCV/rvb-intrinsics/zbb.c
@@ -82,3 +82,29 @@ unsigned int ctz_64(unsigned long a) {
   return __builtin_riscv_ctz_64(a);
 }
 #endif
+
+// RV32ZBB-LABEL: @cpop_32(
+// RV32ZBB-NEXT:  entry:
+// RV32ZBB-NEXT:[[TMP0:%.*]] = call i32 @llvm.ctpop.i32(i32 [[A:%.*]])
+// RV32ZBB-NEXT:ret i32 [[TMP0]]
+//
+// RV64ZBB-LABEL: @cpop_32(
+// RV64ZBB-NEXT:  entry:
+// RV64ZBB-NEXT:[[TMP0:%.*]] = call i32 @llvm.ctpop.i32(i32 [[A:%.*]])
+// RV64ZBB-NEXT:ret i32 [[TMP0]]
+//
+unsigned int cpop_32(unsigned int a) {
+  return __builtin_riscv_cpop_32(a);
+}
+
+#if __riscv_xlen == 64
+// RV64ZBB-LABEL: @cpop_64(
+// RV64ZBB-NEXT:  entry:
+// RV64ZBB-NEXT:[[TMP0:%.*]] = call i64 @llvm.ctpop.i64(i64 [[A:%.*]])
+// RV64ZBB-NEXT:[[CAST:%.*]] = trunc i64 [[TMP0]] to i32
+// RV64ZBB-NEXT:ret i32 [[CAST]]
+//
+unsigned int cpop_64(unsigned long a) {
+  return __builtin_riscv_cpop_64(a);
+}
+#endif

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


[clang] [llvm] [SPARC] Support reserving arbitrary general purpose registers (PR #74927)

2023-12-22 Thread via cfe-commits


@@ -1125,6 +1130,10 @@ Register SparcTargetLowering::getRegisterByName(const 
char* RegName, LLT VT,
 .Case("g4", SP::G4).Case("g5", SP::G5).Case("g6", SP::G6).Case("g7", 
SP::G7)
 .Default(0);
 
+  const SparcRegisterInfo *TRI = Subtarget->getRegisterInfo();
+  if (!TRI->isReservedReg(MF, Reg))
+Reg = 0;

koachan wrote:

The intention is to make explicit register references (e.g GCC-style `register 
int r asm("g1");`) to fail unless we also pass the corresponding `-ffixed` 
flags to reserve it (unless, of course, the target register is already marked 
as reserved by the ABI).

I've made a test case, but I am not sure how to put it in the .ll files since 
the expected result is a `report_fatal_error` crash... any idea how to test for 
this?

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


[clang-tools-extra] [clang-tidy] Add check readability-return-expression-in-void-function (PR #76249)

2023-12-22 Thread Danny Mösch via cfe-commits


@@ -119,6 +120,8 @@ class ReadabilityModule : public ClangTidyModule {
 "readability-redundant-preprocessor");
 CheckFactories.registerCheck(
 "readability-reference-to-constructed-temporary");
+CheckFactories.registerCheck(
+"readability-return-expression-in-void-function");

SimplyDanny wrote:

`readability-avoid-return-with-void-value` sounds good.

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


[clang-tools-extra] [clang-tidy] Add check readability-return-expression-in-void-function (PR #76249)

2023-12-22 Thread Danny Mösch via cfe-commits

https://github.com/SimplyDanny updated 
https://github.com/llvm/llvm-project/pull/76249

From 0daffd13160bc10e15e36327e596f8cabb96706e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Danny=20M=C3=B6sch?= 
Date: Fri, 22 Dec 2023 17:09:59 +0100
Subject: [PATCH 1/6] [clang-tidy] Add check
 readability-return-expression-in-void-function

---
 .../clang-tidy/readability/CMakeLists.txt |  1 +
 .../readability/ReadabilityTidyModule.cpp |  3 ++
 .../ReturnExpressionInVoidFunctionCheck.cpp   | 31 +++
 .../ReturnExpressionInVoidFunctionCheck.h | 30 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |  7 +
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../return-expression-in-void-function.rst| 30 ++
 .../return-expression-in-void-function.cpp| 23 ++
 8 files changed, 126 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/readability/ReturnExpressionInVoidFunctionCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/readability/ReturnExpressionInVoidFunctionCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/readability/return-expression-in-void-function.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/return-expression-in-void-function.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
index 5452c2d48a4617..7d0399ed901267 100644
--- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -42,6 +42,7 @@ add_clang_library(clangTidyReadabilityModule
   RedundantStringCStrCheck.cpp
   RedundantStringInitCheck.cpp
   ReferenceToConstructedTemporaryCheck.cpp
+  ReturnExpressionInVoidFunctionCheck.cpp
   SimplifyBooleanExprCheck.cpp
   SimplifySubscriptExprCheck.cpp
   StaticAccessedThroughInstanceCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp 
b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
index b8e6e641432060..2a9134071b9a72 100644
--- a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
@@ -45,6 +45,7 @@
 #include "RedundantStringCStrCheck.h"
 #include "RedundantStringInitCheck.h"
 #include "ReferenceToConstructedTemporaryCheck.h"
+#include "ReturnExpressionInVoidFunctionCheck.h"
 #include "SimplifyBooleanExprCheck.h"
 #include "SimplifySubscriptExprCheck.h"
 #include "StaticAccessedThroughInstanceCheck.h"
@@ -119,6 +120,8 @@ class ReadabilityModule : public ClangTidyModule {
 "readability-redundant-preprocessor");
 CheckFactories.registerCheck(
 "readability-reference-to-constructed-temporary");
+CheckFactories.registerCheck(
+"readability-return-expression-in-void-function");
 CheckFactories.registerCheck(
 "readability-simplify-subscript-expr");
 CheckFactories.registerCheck(
diff --git 
a/clang-tools-extra/clang-tidy/readability/ReturnExpressionInVoidFunctionCheck.cpp
 
b/clang-tools-extra/clang-tidy/readability/ReturnExpressionInVoidFunctionCheck.cpp
new file mode 100644
index 00..2308d0782ae1c3
--- /dev/null
+++ 
b/clang-tools-extra/clang-tidy/readability/ReturnExpressionInVoidFunctionCheck.cpp
@@ -0,0 +1,31 @@
+//===--- ReturnExpressionInVoidFunctionCheck.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 "ReturnExpressionInVoidFunctionCheck.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+void ReturnExpressionInVoidFunctionCheck::registerMatchers(
+MatchFinder *Finder) {
+  Finder->addMatcher(
+  returnStmt(hasReturnValue(hasType(voidType(.bind("void_return"),
+  this);
+}
+
+void ReturnExpressionInVoidFunctionCheck::check(
+const MatchFinder::MatchResult ) {
+  const auto *VoidReturn = Result.Nodes.getNodeAs("void_return");
+  diag(VoidReturn->getBeginLoc(), "return statements should not return void");
+}
+
+} // namespace clang::tidy::readability
diff --git 
a/clang-tools-extra/clang-tidy/readability/ReturnExpressionInVoidFunctionCheck.h
 
b/clang-tools-extra/clang-tidy/readability/ReturnExpressionInVoidFunctionCheck.h
new file mode 100644
index 00..e28f9cebd2620e
--- /dev/null
+++ 
b/clang-tools-extra/clang-tidy/readability/ReturnExpressionInVoidFunctionCheck.h
@@ -0,0 +1,30 @@
+//===--- ReturnExpressionInVoidFunctionCheck.h - clang-tidy -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with 

[clang-tools-extra] [clang-tidy] Add check readability-return-expression-in-void-function (PR #76249)

2023-12-22 Thread Danny Mösch via cfe-commits

https://github.com/SimplyDanny updated 
https://github.com/llvm/llvm-project/pull/76249

From 0daffd13160bc10e15e36327e596f8cabb96706e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Danny=20M=C3=B6sch?= 
Date: Fri, 22 Dec 2023 17:09:59 +0100
Subject: [PATCH 1/5] [clang-tidy] Add check
 readability-return-expression-in-void-function

---
 .../clang-tidy/readability/CMakeLists.txt |  1 +
 .../readability/ReadabilityTidyModule.cpp |  3 ++
 .../ReturnExpressionInVoidFunctionCheck.cpp   | 31 +++
 .../ReturnExpressionInVoidFunctionCheck.h | 30 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |  7 +
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../return-expression-in-void-function.rst| 30 ++
 .../return-expression-in-void-function.cpp| 23 ++
 8 files changed, 126 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/readability/ReturnExpressionInVoidFunctionCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/readability/ReturnExpressionInVoidFunctionCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/readability/return-expression-in-void-function.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/return-expression-in-void-function.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
index 5452c2d48a4617..7d0399ed901267 100644
--- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -42,6 +42,7 @@ add_clang_library(clangTidyReadabilityModule
   RedundantStringCStrCheck.cpp
   RedundantStringInitCheck.cpp
   ReferenceToConstructedTemporaryCheck.cpp
+  ReturnExpressionInVoidFunctionCheck.cpp
   SimplifyBooleanExprCheck.cpp
   SimplifySubscriptExprCheck.cpp
   StaticAccessedThroughInstanceCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp 
b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
index b8e6e641432060..2a9134071b9a72 100644
--- a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
@@ -45,6 +45,7 @@
 #include "RedundantStringCStrCheck.h"
 #include "RedundantStringInitCheck.h"
 #include "ReferenceToConstructedTemporaryCheck.h"
+#include "ReturnExpressionInVoidFunctionCheck.h"
 #include "SimplifyBooleanExprCheck.h"
 #include "SimplifySubscriptExprCheck.h"
 #include "StaticAccessedThroughInstanceCheck.h"
@@ -119,6 +120,8 @@ class ReadabilityModule : public ClangTidyModule {
 "readability-redundant-preprocessor");
 CheckFactories.registerCheck(
 "readability-reference-to-constructed-temporary");
+CheckFactories.registerCheck(
+"readability-return-expression-in-void-function");
 CheckFactories.registerCheck(
 "readability-simplify-subscript-expr");
 CheckFactories.registerCheck(
diff --git 
a/clang-tools-extra/clang-tidy/readability/ReturnExpressionInVoidFunctionCheck.cpp
 
b/clang-tools-extra/clang-tidy/readability/ReturnExpressionInVoidFunctionCheck.cpp
new file mode 100644
index 00..2308d0782ae1c3
--- /dev/null
+++ 
b/clang-tools-extra/clang-tidy/readability/ReturnExpressionInVoidFunctionCheck.cpp
@@ -0,0 +1,31 @@
+//===--- ReturnExpressionInVoidFunctionCheck.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 "ReturnExpressionInVoidFunctionCheck.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+void ReturnExpressionInVoidFunctionCheck::registerMatchers(
+MatchFinder *Finder) {
+  Finder->addMatcher(
+  returnStmt(hasReturnValue(hasType(voidType(.bind("void_return"),
+  this);
+}
+
+void ReturnExpressionInVoidFunctionCheck::check(
+const MatchFinder::MatchResult ) {
+  const auto *VoidReturn = Result.Nodes.getNodeAs("void_return");
+  diag(VoidReturn->getBeginLoc(), "return statements should not return void");
+}
+
+} // namespace clang::tidy::readability
diff --git 
a/clang-tools-extra/clang-tidy/readability/ReturnExpressionInVoidFunctionCheck.h
 
b/clang-tools-extra/clang-tidy/readability/ReturnExpressionInVoidFunctionCheck.h
new file mode 100644
index 00..e28f9cebd2620e
--- /dev/null
+++ 
b/clang-tools-extra/clang-tidy/readability/ReturnExpressionInVoidFunctionCheck.h
@@ -0,0 +1,30 @@
+//===--- ReturnExpressionInVoidFunctionCheck.h - clang-tidy -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with 

[clang-tools-extra] [clang-tidy] Add check readability-return-expression-in-void-function (PR #76249)

2023-12-22 Thread Piotr Zegar via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 



@@ -119,6 +120,8 @@ class ReadabilityModule : public ClangTidyModule {
 "readability-redundant-preprocessor");
 CheckFactories.registerCheck(
 "readability-reference-to-constructed-temporary");
+CheckFactories.registerCheck(
+"readability-return-expression-in-void-function");

PiotrZSL wrote:

Consider: readability-return-void-value or readability-void-return-statement or 
readability-avoid-return-with-void-value. 

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


[clang-tools-extra] [clang-tidy] Add check readability-return-expression-in-void-function (PR #76249)

2023-12-22 Thread Danny Mösch via cfe-commits

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


[clang-tools-extra] [clang-tidy] Add check readability-return-expression-in-void-function (PR #76249)

2023-12-22 Thread Danny Mösch via cfe-commits

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


[clang-tools-extra] [clang-tidy] Add check readability-return-expression-in-void-function (PR #76249)

2023-12-22 Thread Danny Mösch via cfe-commits

https://github.com/SimplyDanny updated 
https://github.com/llvm/llvm-project/pull/76249

From 0daffd13160bc10e15e36327e596f8cabb96706e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Danny=20M=C3=B6sch?= 
Date: Fri, 22 Dec 2023 17:09:59 +0100
Subject: [PATCH 1/5] [clang-tidy] Add check
 readability-return-expression-in-void-function

---
 .../clang-tidy/readability/CMakeLists.txt |  1 +
 .../readability/ReadabilityTidyModule.cpp |  3 ++
 .../ReturnExpressionInVoidFunctionCheck.cpp   | 31 +++
 .../ReturnExpressionInVoidFunctionCheck.h | 30 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |  7 +
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../return-expression-in-void-function.rst| 30 ++
 .../return-expression-in-void-function.cpp| 23 ++
 8 files changed, 126 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/readability/ReturnExpressionInVoidFunctionCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/readability/ReturnExpressionInVoidFunctionCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/readability/return-expression-in-void-function.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/return-expression-in-void-function.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
index 5452c2d48a4617..7d0399ed901267 100644
--- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -42,6 +42,7 @@ add_clang_library(clangTidyReadabilityModule
   RedundantStringCStrCheck.cpp
   RedundantStringInitCheck.cpp
   ReferenceToConstructedTemporaryCheck.cpp
+  ReturnExpressionInVoidFunctionCheck.cpp
   SimplifyBooleanExprCheck.cpp
   SimplifySubscriptExprCheck.cpp
   StaticAccessedThroughInstanceCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp 
b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
index b8e6e641432060..2a9134071b9a72 100644
--- a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
@@ -45,6 +45,7 @@
 #include "RedundantStringCStrCheck.h"
 #include "RedundantStringInitCheck.h"
 #include "ReferenceToConstructedTemporaryCheck.h"
+#include "ReturnExpressionInVoidFunctionCheck.h"
 #include "SimplifyBooleanExprCheck.h"
 #include "SimplifySubscriptExprCheck.h"
 #include "StaticAccessedThroughInstanceCheck.h"
@@ -119,6 +120,8 @@ class ReadabilityModule : public ClangTidyModule {
 "readability-redundant-preprocessor");
 CheckFactories.registerCheck(
 "readability-reference-to-constructed-temporary");
+CheckFactories.registerCheck(
+"readability-return-expression-in-void-function");
 CheckFactories.registerCheck(
 "readability-simplify-subscript-expr");
 CheckFactories.registerCheck(
diff --git 
a/clang-tools-extra/clang-tidy/readability/ReturnExpressionInVoidFunctionCheck.cpp
 
b/clang-tools-extra/clang-tidy/readability/ReturnExpressionInVoidFunctionCheck.cpp
new file mode 100644
index 00..2308d0782ae1c3
--- /dev/null
+++ 
b/clang-tools-extra/clang-tidy/readability/ReturnExpressionInVoidFunctionCheck.cpp
@@ -0,0 +1,31 @@
+//===--- ReturnExpressionInVoidFunctionCheck.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 "ReturnExpressionInVoidFunctionCheck.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+void ReturnExpressionInVoidFunctionCheck::registerMatchers(
+MatchFinder *Finder) {
+  Finder->addMatcher(
+  returnStmt(hasReturnValue(hasType(voidType(.bind("void_return"),
+  this);
+}
+
+void ReturnExpressionInVoidFunctionCheck::check(
+const MatchFinder::MatchResult ) {
+  const auto *VoidReturn = Result.Nodes.getNodeAs("void_return");
+  diag(VoidReturn->getBeginLoc(), "return statements should not return void");
+}
+
+} // namespace clang::tidy::readability
diff --git 
a/clang-tools-extra/clang-tidy/readability/ReturnExpressionInVoidFunctionCheck.h
 
b/clang-tools-extra/clang-tidy/readability/ReturnExpressionInVoidFunctionCheck.h
new file mode 100644
index 00..e28f9cebd2620e
--- /dev/null
+++ 
b/clang-tools-extra/clang-tidy/readability/ReturnExpressionInVoidFunctionCheck.h
@@ -0,0 +1,30 @@
+//===--- ReturnExpressionInVoidFunctionCheck.h - clang-tidy -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with 

[llvm] [flang] [clang-tools-extra] [clang] [flang] Pass to add frame pointer attribute (PR #74598)

2023-12-22 Thread Andrzej Warzyński via cfe-commits


@@ -51,9 +51,9 @@
 ! Content to check from the MLIR outputs
 !--
 ! MLIR-FIR-NOT: llvm.func
-! MLIR-FIR: func.func @{{.*}}main() {
+! MLIR-FIR: func.func @{{.*}}main(){{.*}}{

banach-space wrote:

Could you explain why it was failing? I just don't see how this particular 
change is related to what this PR is implementing. It would help if you 
included code "before" and "after" this PR.

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


[llvm] [clang-tools-extra] [clang] [flang] [flang] Pass to add frame pointer attribute (PR #74598)

2023-12-22 Thread Andrzej Warzyński via cfe-commits


@@ -0,0 +1,23 @@
+! Test that -mframe-pointer can accept only specific values.

banach-space wrote:

You seem to be testing a bit more in this file than this comment suggests (e.g. 
that `-mframe-pointer` will make the compiler insert the new attributes)

Please, could you:
* update the comment to capture what's actually being tested (the 
`-mframe-pointer` flag)
* rename the file - it's testing a particular flag rather than any "func"tion 
"attr"ibute

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


  1   2   3   >