[clang-tools-extra] ffad4f8 - [clang-tidy] Container-size-empty fixed c++ version in tests to support string_literals operator

2023-08-26 Thread Piotr Zegar via cfe-commits

Author: Felix
Date: 2023-08-26T07:23:05Z
New Revision: ffad4f8fcac5fa5e65b979ab2a2fcf903a66e5e2

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

LOG: [clang-tidy] Container-size-empty fixed c++ version in tests to support 
string_literals operator

The goal of this PR is to properly implement the 
std::string_literals::operator""s that was added in commit (4001ae175cbe) but 
was later changed in commit (ba52a10fca6fc7b791894c584233db012def68a5).

The operator""s was added in c++14 but we were running tests under c++11 which 
would raise an error when compiling the file.

Reviewed By: PiotrZSL

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

Added: 


Modified: 

clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp

Removed: 




diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
index a7e4977e767455..6f1c014feccb58 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s readability-container-size-empty %t -- \
+// RUN: %check_clang_tidy -std=c++14-or-later %s 
readability-container-size-empty %t -- \
 // RUN: -config="{CheckOptions: 
{readability-container-size-empty.ExcludedComparisonTypes: 
'::std::array;::IgnoredDummyType'}}" \
 // RUN: -- -fno-delayed-template-parsing -isystem %clang_tidy_headers
 #include 
@@ -23,7 +23,7 @@ template  struct set {
 }
 
 namespace string_literals{
-string operator""_s(const char *, size_t);
+string operator""s(const char *, size_t);
 }
 
 }
@@ -778,7 +778,7 @@ bool testIgnoredDummyType(const IgnoredDummyType& value) {
 bool testStringLiterals(const std::string& s)
 {
   using namespace std::string_literals;
-  return s == ""_s;
+  return s == ""s;
   // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: the 'empty' method should be 
used
   // CHECK-FIXES: {{^  }}return s.empty()
 }
@@ -786,5 +786,5 @@ bool testStringLiterals(const std::string& s)
 bool testNotEmptyStringLiterals(const std::string& s)
 {
   using namespace std::string_literals;
-  return s == "foo"_s;
+  return s == "foo"s;
 }



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


[PATCH] D158691: [clang-tidy] Container-size-empty fixed c++ version in tests to support string_literals operator

2023-08-26 Thread Piotr Zegar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGffad4f8fcac5: [clang-tidy] Container-size-empty fixed c++ 
version in tests to support… (authored by felix642, committed by PiotrZSL).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158691

Files:
  
clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s readability-container-size-empty %t -- \
+// RUN: %check_clang_tidy -std=c++14-or-later %s 
readability-container-size-empty %t -- \
 // RUN: -config="{CheckOptions: 
{readability-container-size-empty.ExcludedComparisonTypes: 
'::std::array;::IgnoredDummyType'}}" \
 // RUN: -- -fno-delayed-template-parsing -isystem %clang_tidy_headers
 #include 
@@ -23,7 +23,7 @@
 }
 
 namespace string_literals{
-string operator""_s(const char *, size_t);
+string operator""s(const char *, size_t);
 }
 
 }
@@ -778,7 +778,7 @@
 bool testStringLiterals(const std::string& s)
 {
   using namespace std::string_literals;
-  return s == ""_s;
+  return s == ""s;
   // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: the 'empty' method should be 
used
   // CHECK-FIXES: {{^  }}return s.empty()
 }
@@ -786,5 +786,5 @@
 bool testNotEmptyStringLiterals(const std::string& s)
 {
   using namespace std::string_literals;
-  return s == "foo"_s;
+  return s == "foo"s;
 }


Index: clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s readability-container-size-empty %t -- \
+// RUN: %check_clang_tidy -std=c++14-or-later %s readability-container-size-empty %t -- \
 // RUN: -config="{CheckOptions: {readability-container-size-empty.ExcludedComparisonTypes: '::std::array;::IgnoredDummyType'}}" \
 // RUN: -- -fno-delayed-template-parsing -isystem %clang_tidy_headers
 #include 
@@ -23,7 +23,7 @@
 }
 
 namespace string_literals{
-string operator""_s(const char *, size_t);
+string operator""s(const char *, size_t);
 }
 
 }
@@ -778,7 +778,7 @@
 bool testStringLiterals(const std::string& s)
 {
   using namespace std::string_literals;
-  return s == ""_s;
+  return s == ""s;
   // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: the 'empty' method should be used
   // CHECK-FIXES: {{^  }}return s.empty()
 }
@@ -786,5 +786,5 @@
 bool testNotEmptyStringLiterals(const std::string& s)
 {
   using namespace std::string_literals;
-  return s == "foo"_s;
+  return s == "foo"s;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158371: [clang-tidy] Fix DanglingHandleCheck to work in C++17 and later mode

2023-08-26 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL accepted this revision.
PiotrZSL added a comment.
This revision is now accepted and ready to land.

Overall looks to be fine, but I didn't get too deep into AST matchers.
I assume that tests cover them.
Please wait like 2 weeks before pushing this, so someone else could be able to 
verify this if they need.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158371

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


[PATCH] D158923: [clang-c] Visit ranged for initializer

2023-08-26 Thread Kai Stierand via Phabricator via cfe-commits
kiloalphaindia created this revision.
kiloalphaindia added reviewers: HAPPY, aaron.ballman.
kiloalphaindia added a project: clang-c.
Herald added a subscriber: arphaman.
Herald added a project: All.
kiloalphaindia requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Visit the ranged for init statement when using C-Interface.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158923

Files:
  clang/tools/libclang/CIndex.cpp
  clang/unittests/libclang/LibclangTest.cpp


Index: clang/unittests/libclang/LibclangTest.cpp
===
--- clang/unittests/libclang/LibclangTest.cpp
+++ clang/unittests/libclang/LibclangTest.cpp
@@ -1138,6 +1138,33 @@
 "class ns1::Class1");
 }
 
+TEST_F(LibclangParseTest, VisitCXXForRangeStmt_InitStmt) {
+  const char testSource[] = R"cpp(
+void fun()
+{
+char text[] = "test";
+for (int init = 0; auto x:text) {}
+}
+)cpp";
+  std::string fileName = "main.cpp";
+  WriteFile(fileName, testSource);
+  const char *Args[] = {"-xc++", "-std=c++20"};
+  ClangTU = clang_parseTranslationUnit(Index, fileName.c_str(), Args,
+   std::size(Args), nullptr, 0, TUFlags);
+
+  bool found = false;
+  ;
+  Traverse([&](CXCursor cursor, CXCursor parent) -> CXChildVisitResult {
+if (cursor.kind == CXCursor_VarDecl &&
+fromCXString(clang_getCursorSpelling(cursor)) == "init") {
+  found = true;
+  return CXChildVisit_Break;
+}
+return CXChildVisit_Recurse;
+  });
+  ASSERT_TRUE(found);
+}
+
 TEST_F(LibclangParseTest, BinaryOperator) {
   std::string Main = "main.cpp";
   WriteFile(Main, "int foo() { return 5 + 9; }");
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -2831,6 +2831,9 @@
   AddStmt(S->getBody());
   AddStmt(S->getRangeInit());
   AddDecl(S->getLoopVariable());
+  if (auto *init = S->getInit()) {
+AddStmt(init);
+  }
 }
 
 void EnqueueVisitor::VisitDeclRefExpr(const DeclRefExpr *DR) {


Index: clang/unittests/libclang/LibclangTest.cpp
===
--- clang/unittests/libclang/LibclangTest.cpp
+++ clang/unittests/libclang/LibclangTest.cpp
@@ -1138,6 +1138,33 @@
 "class ns1::Class1");
 }
 
+TEST_F(LibclangParseTest, VisitCXXForRangeStmt_InitStmt) {
+  const char testSource[] = R"cpp(
+void fun()
+{
+char text[] = "test";
+for (int init = 0; auto x:text) {}
+}
+)cpp";
+  std::string fileName = "main.cpp";
+  WriteFile(fileName, testSource);
+  const char *Args[] = {"-xc++", "-std=c++20"};
+  ClangTU = clang_parseTranslationUnit(Index, fileName.c_str(), Args,
+   std::size(Args), nullptr, 0, TUFlags);
+
+  bool found = false;
+  ;
+  Traverse([&](CXCursor cursor, CXCursor parent) -> CXChildVisitResult {
+if (cursor.kind == CXCursor_VarDecl &&
+fromCXString(clang_getCursorSpelling(cursor)) == "init") {
+  found = true;
+  return CXChildVisit_Break;
+}
+return CXChildVisit_Recurse;
+  });
+  ASSERT_TRUE(found);
+}
+
 TEST_F(LibclangParseTest, BinaryOperator) {
   std::string Main = "main.cpp";
   WriteFile(Main, "int foo() { return 5 + 9; }");
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -2831,6 +2831,9 @@
   AddStmt(S->getBody());
   AddStmt(S->getRangeInit());
   AddDecl(S->getLoopVariable());
+  if (auto *init = S->getInit()) {
+AddStmt(init);
+  }
 }
 
 void EnqueueVisitor::VisitDeclRefExpr(const DeclRefExpr *DR) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158923: [clang-c] Visit ranged for initializer

2023-08-26 Thread Kai Stierand via Phabricator via cfe-commits
kiloalphaindia added a comment.

Can we get this into release/17.x still?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158923

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


[PATCH] D158925: [clang-format][NFC] Skip stability test if input is pre-formatted

2023-08-26 Thread Owen Pan via Phabricator via cfe-commits
owenpan created this revision.
Herald added projects: All, clang, clang-format.
Herald added a subscriber: cfe-commits.
Herald added reviewers: rymiel, HazardyKnusperkeks, MyDeveloperDay.
owenpan requested review of this revision.

This shortens the run-time of `FormatTests` by about 10% on average (and by up 
to 50% if formatting would not change the input).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158925

Files:
  clang/unittests/Format/FormatTestBase.h


Index: clang/unittests/Format/FormatTestBase.h
===
--- clang/unittests/Format/FormatTestBase.h
+++ clang/unittests/Format/FormatTestBase.h
@@ -85,9 +85,11 @@
  const std::optional &Style = {},
  const std::vector &Ranges = {}) {
 testing::ScopedTrace t(File, Line, ::testing::Message() << Code.str());
-EXPECT_EQ(Expected.str(),
-  format(Expected, Style, SC_ExpectComplete, Ranges))
-<< "Expected code is not stable";
+if (!Expected.equals(Code)) {
+  EXPECT_EQ(Expected.str(),
+format(Expected, Style, SC_ExpectComplete, Ranges))
+  << "Expected code is not stable";
+}
 EXPECT_EQ(Expected.str(), format(Code, Style, SC_ExpectComplete, Ranges));
 auto UsedStyle = Style ? Style.value() : getDefaultStyle();
 if (UsedStyle.Language == FormatStyle::LK_Cpp) {


Index: clang/unittests/Format/FormatTestBase.h
===
--- clang/unittests/Format/FormatTestBase.h
+++ clang/unittests/Format/FormatTestBase.h
@@ -85,9 +85,11 @@
  const std::optional &Style = {},
  const std::vector &Ranges = {}) {
 testing::ScopedTrace t(File, Line, ::testing::Message() << Code.str());
-EXPECT_EQ(Expected.str(),
-  format(Expected, Style, SC_ExpectComplete, Ranges))
-<< "Expected code is not stable";
+if (!Expected.equals(Code)) {
+  EXPECT_EQ(Expected.str(),
+format(Expected, Style, SC_ExpectComplete, Ranges))
+  << "Expected code is not stable";
+}
 EXPECT_EQ(Expected.str(), format(Code, Style, SC_ExpectComplete, Ranges));
 auto UsedStyle = Style ? Style.value() : getDefaultStyle();
 if (UsedStyle.Language == FormatStyle::LK_Cpp) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158926: [clangd] Show parameter hints for operator()

2023-08-26 Thread Younan Zhang via Phabricator via cfe-commits
zyounan created this revision.
zyounan added a reviewer: nridge.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
zyounan requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Closes https://github.com/clangd/clangd/issues/1742


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158926

Files:
  clang-tools-extra/clangd/InlayHints.cpp
  clang-tools-extra/clangd/unittests/InlayHintTests.cpp

Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -89,7 +89,7 @@
ExpectedHints... Expected) {
   Annotations Source(AnnotatedSource);
   TestTU TU = TestTU::withCode(Source.code());
-  TU.ExtraArgs.push_back("-std=c++20");
+  TU.ExtraArgs.push_back("-std=c++23");
   TU.HeaderCode = HeaderContent;
   auto AST = TU.build();
 
@@ -807,6 +807,42 @@
   )cpp");
 }
 
+TEST(ParameterHints, FunctionCallOperator) {
+  assertParameterHints(R"cpp(
+struct W {
+  void operator()(int x);
+};
+struct S : W {
+  using W::operator();
+  static void operator()(int x, int y);
+};
+void bar() {
+  auto l1 = [](int x) {};
+  auto l2 = [](int x) static {};
+
+  S s;
+  s($1[[1]]);
+  s.operator()($2[[1]]);
+  s.operator()($3[[1]], $4[[2]]);
+  S::operator()($5[[1]], $6[[2]]);
+
+  l1($7[[1]]);
+  l1.operator()($8[[1]]);
+  l2($9[[1]]);
+  l2.operator()($10[[1]]);
+
+  void (*ptr)(int a, int b) = &S::operator();
+  ptr($11[[1]], $12[[2]]);
+}
+  )cpp",
+   ExpectedHint{"x: ", "1"}, ExpectedHint{"x: ", "2"},
+   ExpectedHint{"x: ", "3"}, ExpectedHint{"y: ", "4"},
+   ExpectedHint{"x: ", "5"}, ExpectedHint{"y: ", "6"},
+   ExpectedHint{"x: ", "7"}, ExpectedHint{"x: ", "8"},
+   ExpectedHint{"x: ", "9"}, ExpectedHint{"x: ", "10"},
+   ExpectedHint{"a: ", "11"}, ExpectedHint{"b: ", "12"});
+}
+
 TEST(ParameterHints, Macros) {
   // Handling of macros depends on where the call's argument list comes from.
 
Index: clang-tools-extra/clangd/InlayHints.cpp
===
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -586,11 +586,13 @@
 if (!Cfg.InlayHints.Parameters)
   return true;
 
-// Do not show parameter hints for operator calls written using operator
-// syntax or user-defined literals. (Among other reasons, the resulting
+bool IsFunctor = isFunctionObjectCallExpr(E);
+// Do not show parameter hints for user-defined literals or
+// operator calls except for operator(). (Among other reasons, the resulting
 // hints can look awkward, e.g. the expression can itself be a function
 // argument and then we'd get two hints side by side).
-if (isa(E) || isa(E))
+if ((isa(E) && !IsFunctor) ||
+isa(E))
   return true;
 
 auto CalleeDecls = Resolver->resolveCalleeOfCallExpr(E);
@@ -607,7 +609,22 @@
 else
   return true;
 
-processCall(Callee, {E->getArgs(), E->getNumArgs()});
+// N4868 [over.call.object]p3 says,
+// The argument list submitted to overload resolution consists of the
+// argument expressions present in the function call syntax preceded by the
+// implied object argument (E).
+//
+// However, we don't have the implied object argument for static
+// operator() per clang::Sema::BuildCallToObjectOfClassType.
+llvm::ArrayRef Args = {E->getArgs(), E->getNumArgs()};
+if (IsFunctor)
+  // We don't have the implied object argument through
+  // a function pointer either.
+  if (const CXXMethodDecl *Method =
+  dyn_cast_or_null(Callee.Decl);
+  Method && Method->isInstance())
+Args = Args.drop_front(1);
+processCall(Callee, Args);
 return true;
   }
 
@@ -1202,6 +1219,12 @@
 return Range{HintStart, HintEnd};
   }
 
+  bool isFunctionObjectCallExpr(CallExpr *E) const noexcept {
+if (auto *CallExpr = dyn_cast(E))
+  return CallExpr->getOperator() == OverloadedOperatorKind::OO_Call;
+return false;
+  }
+
   std::vector &Results;
   ASTContext &AST;
   const syntax::TokenBuffer &Tokens;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156605: [clangd][CodeComplete] Improve FunctionCanBeCall

2023-08-26 Thread Younan Zhang via Phabricator via cfe-commits
zyounan added a comment.

Gently ping~


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156605

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


[PATCH] D158061: [clang] Construct ExprRequirement with SubstitutionDiagnostic on SubstFailure

2023-08-26 Thread Younan Zhang via Phabricator via cfe-commits
zyounan added a comment.

Gently ping~


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158061

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


[PATCH] D158928: [clang-tidy] Add IgnoreTypes option to modernize-use-nullptr

2023-08-26 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL created this revision.
PiotrZSL added reviewers: carlosgalvezp, njames93.
Herald added a subscriber: xazax.hun.
Herald added a project: All.
PiotrZSL requested review of this revision.
Herald added subscribers: cfe-commits, wangpc.
Herald added a project: clang-tools-extra.

New option added and configured in a way, so types
related to std::strong_ordering would be ignored.

Fixes: #63478


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158928

Files:
  clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.h
  clang-tools-extra/clang-tidy/utils/Matchers.cpp
  clang-tools-extra/clang-tidy/utils/Matchers.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/modernize/use-nullptr.rst
  clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-cxx20.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-cxx20.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-cxx20.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-cxx20.cpp
@@ -1,35 +1,51 @@
-// RUN: %check_clang_tidy -std=c++20 %s modernize-use-nullptr %t
+// RUN: %check_clang_tidy -std=c++20 %s modernize-use-nullptr %t -- -- -DGCC
+// RUN: %check_clang_tidy -std=c++20 %s modernize-use-nullptr %t -- -- -DCLANG
 
 namespace std {
 class strong_ordering;
 
 // Mock how STD defined unspecified parameters for the operators below.
+#ifdef CLANG
 struct _CmpUnspecifiedParam {
   consteval
   _CmpUnspecifiedParam(int _CmpUnspecifiedParam::*) noexcept {}
 };
 
+#define UNSPECIFIED_TYPE _CmpUnspecifiedParam
+#endif
+
+#ifdef GCC
+namespace __cmp_cat {
+  struct __unspec {
+constexpr __unspec(__unspec*) noexcept { }
+  };
+}
+
+#define UNSPECIFIED_TYPE __cmp_cat::__unspec
+#endif
+
 struct strong_ordering {
   signed char value;
 
   friend constexpr bool operator==(strong_ordering v,
-   _CmpUnspecifiedParam) noexcept {
+   UNSPECIFIED_TYPE) noexcept {
 return v.value == 0;
   }
   friend constexpr bool operator<(strong_ordering v,
-  _CmpUnspecifiedParam) noexcept {
+  UNSPECIFIED_TYPE) noexcept {
 return v.value < 0;
   }
   friend constexpr bool operator>(strong_ordering v,
-  _CmpUnspecifiedParam) noexcept {
+  UNSPECIFIED_TYPE) noexcept {
 return v.value > 0;
   }
   friend constexpr bool operator>=(strong_ordering v,
-   _CmpUnspecifiedParam) noexcept {
+   UNSPECIFIED_TYPE) noexcept {
 return v.value >= 0;
   }
   static const strong_ordering equal, greater, less;
 };
+
 constexpr strong_ordering strong_ordering::equal = {0};
 constexpr strong_ordering strong_ordering::greater = {1};
 constexpr strong_ordering strong_ordering::less = {-1};
@@ -59,6 +75,13 @@
   // CHECK-FIXES: result = (a1 > ((a1 > (ptr == nullptr ? a1 : a2)) ? a1 : a2));
 }
 
+void testValidZero() {
+  A a1, a2;
+  auto result = a1 <=> a2;
+  if (result < 0) {}
+  // CHECK-FIXES: if (result < 0) {}
+}
+
 template
 struct P {
   T1 x1;
Index: clang-tools-extra/docs/clang-tidy/checks/modernize/use-nullptr.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/modernize/use-nullptr.rst
+++ clang-tools-extra/docs/clang-tidy/checks/modernize/use-nullptr.rst
@@ -39,6 +39,12 @@
 Options
 ---
 
+.. option:: IgnoredTypes
+
+  Semicolon-separated list of regular expressions to match pointer types for
+  which implicit casts will be ignored. Default value:
+  `std::_CmpUnspecifiedParam::;^std::__cmp_cat::__unspec`.
+
 .. option:: NullMacros
 
Comma-separated list of macro names that will be transformed along with
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -230,6 +230,10 @@
   ` to support for-loops with
   iterators initialized by free functions like ``begin``, ``end``, or ``size``.
 
+- Improved :doc:`modernize-use-nullptr
+  ` check by adding option
+  `IgnoredTypes` that can be used to exclude some pointer types.
+
 - Improved :doc:`performance-faster-string-find
   ` check to properly escape
   single quotes.
Index: clang-tools-extra/clang-tidy/utils/Matchers.h
===
--- clang-tools-extra/clang-tidy/utils/Matchers.h
+++ clang-tools-extra/clang-tidy/utils/Matchers.h
@@ -158,6 +158,28 @@
   return Builder->removeBindings(Predicate);
 }
 
+// A matcher implementation that matches a list of type name regular expressions
+// against a QualType.
+class MatchesAnyListedTypeNameMatcher
+  

[PATCH] D158929: [clang-tidy] Add exit code support to clang-tidy-diff.py

2023-08-26 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL created this revision.
PiotrZSL added reviewers: njames93, carlosgalvezp.
Herald added a subscriber: xazax.hun.
Herald added a project: All.
PiotrZSL requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Modify script to fail when some run clang-tidy
command fails. Based on run_clang-tidy.

Fixes: #65000


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158929

Files:
  clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
  clang-tools-extra/docs/ReleaseNotes.rst


Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -113,6 +113,10 @@
 
 - Improved `--dump-config` to print check options in alphabetical order.
 
+- Improved :program:`clang-tidy-diff.py` script. It now returns exit code `1`
+  if any :program:`clang-tidy` subprocess exits with a non-zero code or if
+  exporting fixes fails.
+
 New checks
 ^^
 
Index: clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
===
--- clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
+++ clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
@@ -49,7 +49,7 @@
 import queue as queue
 
 
-def run_tidy(task_queue, lock, timeout):
+def run_tidy(task_queue, lock, timeout, failed_files):
 watchdog = None
 while True:
 command = task_queue.get()
@@ -63,6 +63,14 @@
 watchdog.start()
 
 stdout, stderr = proc.communicate()
+if proc.returncode != 0:
+if proc.returncode < 0:
+msg = "Terminated by signal %d : %s\n" % (
+-proc.returncode,
+" ".join(command),
+)
+stderr += msg.encode("utf-8")
+failed_files.append(command)
 
 with lock:
 sys.stdout.write(stdout.decode("utf-8") + "\n")
@@ -84,9 +92,11 @@
 task_queue.task_done()
 
 
-def start_workers(max_tasks, tidy_caller, task_queue, lock, timeout):
+def start_workers(max_tasks, tidy_caller, task_queue, lock, timeout, 
failed_files):
 for _ in range(max_tasks):
-t = threading.Thread(target=tidy_caller, args=(task_queue, lock, 
timeout))
+t = threading.Thread(
+target=tidy_caller, args=(task_queue, lock, timeout, failed_files)
+)
 t.daemon = True
 t.start()
 
@@ -259,8 +269,13 @@
 # A lock for console output.
 lock = threading.Lock()
 
+# List of files with a non-zero return code.
+failed_files = []
+
 # Run a pool of clang-tidy workers.
-start_workers(max_task_count, run_tidy, task_queue, lock, args.timeout)
+start_workers(
+max_task_count, run_tidy, task_queue, lock, args.timeout, failed_files
+)
 
 # Form the common args list.
 common_clang_tidy_args = []
@@ -301,8 +316,15 @@
 
 task_queue.put(command)
 
+# Application return code
+return_code = 0
+
 # Wait for all threads to be done.
 task_queue.join()
+# Application return code
+return_code = 0
+if len(failed_files):
+return_code = 1
 
 if yaml and args.export_fixes:
 print("Writing fixes to " + args.export_fixes + " ...")
@@ -311,9 +333,11 @@
 except:
 sys.stderr.write("Error exporting fixes.\n")
 traceback.print_exc()
+return_code = 1
 
 if tmpdir:
 shutil.rmtree(tmpdir)
+sys.exit(return_code)
 
 
 if __name__ == "__main__":


Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -113,6 +113,10 @@
 
 - Improved `--dump-config` to print check options in alphabetical order.
 
+- Improved :program:`clang-tidy-diff.py` script. It now returns exit code `1`
+  if any :program:`clang-tidy` subprocess exits with a non-zero code or if
+  exporting fixes fails.
+
 New checks
 ^^
 
Index: clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
===
--- clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
+++ clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
@@ -49,7 +49,7 @@
 import queue as queue
 
 
-def run_tidy(task_queue, lock, timeout):
+def run_tidy(task_queue, lock, timeout, failed_files):
 watchdog = None
 while True:
 command = task_queue.get()
@@ -63,6 +63,14 @@
 watchdog.start()
 
 stdout, stderr = proc.communicate()
+if proc.returncode != 0:
+if proc.returncode < 0:
+msg = "Terminated by signal %d : %s\n" % (
+-proc.returncode,
+" ".join(command),
+  

[PATCH] D158929: [clang-tidy] Add exit code support to clang-tidy-diff.py

2023-08-26 Thread Flash Sheridan via Phabricator via cfe-commits
FlashSheridan added a comment.

Thank you, looks promising and I will test it on Monday.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158929

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


[PATCH] D156605: [clangd][CodeComplete] Improve FunctionCanBeCall

2023-08-26 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

(I'm away on travels, will get back to this within the next week)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156605

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


[clang] 1d0061f - [clang-format][doc] Correct typos

2023-08-26 Thread via cfe-commits

Author: sstwcw
Date: 2023-08-26T13:55:21Z
New Revision: 1d0061fc5e1fe68f34135a6d9520bde4679b43db

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

LOG: [clang-format][doc] Correct typos

I ran the script for dumping the format style options before committing
16ccba51072b just in case.  It turned out that the 2 files didn't matchc
any more since 11e2975810acd due to an attempt at fixing typos.

Reviewed By: owenpan

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

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/include/clang/Format/Format.h

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 3b3f6f2860906a..7847f6aa5fb1c9 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -1549,14 +1549,14 @@ the configuration (without a prefix: ``Auto``).
   .. code-block:: c++
 
 x = (char *__capability)&y;
-int function(void) __ununsed;
+int function(void) __unused;
 void only_writes_to_buffer(char *__output buffer);
 
   In the .clang-format configuration file, this can be configured like:
 
   .. code-block:: yaml
 
-AttributeMacros: ['__capability', '__output', '__ununsed']
+AttributeMacros: ['__capability', '__output', '__unused']
 
 .. _BinPackArguments:
 

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 192cc68e51fad7..eb47715e71ca01 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -971,13 +971,13 @@ struct FormatStyle {
   /// For example:
   /// \code
   ///   x = (char *__capability)&y;
-  ///   int function(void) __ununsed;
+  ///   int function(void) __unused;
   ///   void only_writes_to_buffer(char *__output buffer);
   /// \endcode
   ///
   /// In the .clang-format configuration file, this can be configured like:
   /// \code{.yaml}
-  ///   AttributeMacros: ['__capability', '__output', '__ununsed']
+  ///   AttributeMacros: ['__capability', '__output', '__unused']
   /// \endcode
   ///
   /// \version 12
@@ -4015,7 +4015,7 @@ struct FormatStyle {
   /// AfterFunctionDefinitionName: true
   /// \endcode
   struct SpaceBeforeParensCustom {
-/// If ``true``, put space betwee control statement keywords
+/// If ``true``, put space between control statement keywords
 /// (for/if/while...) and opening parentheses.
 /// \code
 ///true:  false:



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


[PATCH] D158697: [clang-format][doc] Correct typos

2023-08-26 Thread sstwcw via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1d0061fc5e1f: [clang-format][doc] Correct typos (authored by 
sstwcw).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158697

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h


Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -971,13 +971,13 @@
   /// For example:
   /// \code
   ///   x = (char *__capability)&y;
-  ///   int function(void) __ununsed;
+  ///   int function(void) __unused;
   ///   void only_writes_to_buffer(char *__output buffer);
   /// \endcode
   ///
   /// In the .clang-format configuration file, this can be configured like:
   /// \code{.yaml}
-  ///   AttributeMacros: ['__capability', '__output', '__ununsed']
+  ///   AttributeMacros: ['__capability', '__output', '__unused']
   /// \endcode
   ///
   /// \version 12
@@ -4015,7 +4015,7 @@
   /// AfterFunctionDefinitionName: true
   /// \endcode
   struct SpaceBeforeParensCustom {
-/// If ``true``, put space betwee control statement keywords
+/// If ``true``, put space between control statement keywords
 /// (for/if/while...) and opening parentheses.
 /// \code
 ///true:  false:
Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -1549,14 +1549,14 @@
   .. code-block:: c++
 
 x = (char *__capability)&y;
-int function(void) __ununsed;
+int function(void) __unused;
 void only_writes_to_buffer(char *__output buffer);
 
   In the .clang-format configuration file, this can be configured like:
 
   .. code-block:: yaml
 
-AttributeMacros: ['__capability', '__output', '__ununsed']
+AttributeMacros: ['__capability', '__output', '__unused']
 
 .. _BinPackArguments:
 


Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -971,13 +971,13 @@
   /// For example:
   /// \code
   ///   x = (char *__capability)&y;
-  ///   int function(void) __ununsed;
+  ///   int function(void) __unused;
   ///   void only_writes_to_buffer(char *__output buffer);
   /// \endcode
   ///
   /// In the .clang-format configuration file, this can be configured like:
   /// \code{.yaml}
-  ///   AttributeMacros: ['__capability', '__output', '__ununsed']
+  ///   AttributeMacros: ['__capability', '__output', '__unused']
   /// \endcode
   ///
   /// \version 12
@@ -4015,7 +4015,7 @@
   /// AfterFunctionDefinitionName: true
   /// \endcode
   struct SpaceBeforeParensCustom {
-/// If ``true``, put space betwee control statement keywords
+/// If ``true``, put space between control statement keywords
 /// (for/if/while...) and opening parentheses.
 /// \code
 ///true:  false:
Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -1549,14 +1549,14 @@
   .. code-block:: c++
 
 x = (char *__capability)&y;
-int function(void) __ununsed;
+int function(void) __unused;
 void only_writes_to_buffer(char *__output buffer);
 
   In the .clang-format configuration file, this can be configured like:
 
   .. code-block:: yaml
 
-AttributeMacros: ['__capability', '__output', '__ununsed']
+AttributeMacros: ['__capability', '__output', '__unused']
 
 .. _BinPackArguments:
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154093: [clang-format] Break long string literals in C#, etc.

2023-08-26 Thread sstwcw via Phabricator via cfe-commits
sstwcw updated this revision to Diff 553729.
sstwcw added a comment.

Stop using `SmallString` in the tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154093

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/BreakableToken.cpp
  clang/lib/Format/BreakableToken.h
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/FormatToken.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/WhitespaceManager.cpp
  clang/unittests/Format/FormatTestCSharp.cpp
  clang/unittests/Format/FormatTestJS.cpp
  clang/unittests/Format/FormatTestJava.cpp
  clang/unittests/Format/FormatTestVerilog.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1863,6 +1863,30 @@
   EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_Unknown);
   EXPECT_TOKEN(Tokens[5], tok::comma, TT_Unknown);
   EXPECT_TOKEN(Tokens[8], tok::r_paren, TT_Unknown);
+
+  // String literals in concatenation.
+  Tokens = Annotate("x = {\"\"};");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_StringInConcatenation);
+  Tokens = Annotate("x = {\"\", \"\"};");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_StringInConcatenation);
+  EXPECT_TOKEN(Tokens[5], tok::string_literal, TT_StringInConcatenation);
+  Tokens = Annotate("x = '{{\"\"}};");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::string_literal, TT_StringInConcatenation);
+  // Cases where the string should not be annotated that type.  Fix the
+  // `TT_Unknown` if needed in the future.
+  Tokens = Annotate("x = {\"\" == \"\"};");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_Unknown);
+  EXPECT_TOKEN(Tokens[5], tok::string_literal, TT_Unknown);
+  Tokens = Annotate("x = {(\"\")};");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::string_literal, TT_Unknown);
+  Tokens = Annotate("x = '{\"\"};");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::string_literal, TT_Unknown);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandConstructors) {
Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -1157,6 +1157,66 @@
   verifyFormat("{< Ranges(1, tooling::Range(Offset, Length));
-tooling::Replacements Replaces = reformat(Style, Code, Ranges);
-auto Result = applyAllReplacements(Code, Replaces);
-EXPECT_TRUE(static_cast(Result));
-LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
-return *Result;
-  }
-
-  static std::string
-  format(llvm::StringRef Code,
- const FormatStyle &Style = getGoogleStyle(FormatStyle::LK_Java)) {
-return format(Code, 0, Code.size(), Style);
+  FormatStyle getDefaultStyle() const override {
+return getGoogleStyle(FormatStyle::LK_Java);
   }
 
   static FormatStyle getStyleWithColumns(unsigned ColumnLimit) {
@@ -41,13 +26,6 @@
 Style.ColumnLimit = ColumnLimit;
 return Style;
   }
-
-  static void verifyFormat(
-  llvm::StringRef Code,
-  const FormatStyle &Style = getGoogleStyle(FormatStyle::LK_Java)) {
-EXPECT_EQ(Code.str(), format(Code, Style)) << "Expected code is not stable";
-EXPECT_EQ(Code.str(), format(test::messUp(Code), Style));
-  }
 };
 
 TEST_F(FormatTestJava, NoAlternativeOperatorNames) {
@@ -565,9 +543,9 @@
 }
 
 TEST_F(FormatTestJava, BreaksStringLiterals) {
-  // FIXME: String literal breaking is currently disabled for Java and JS, as it
-  // requires strings to be merged using "+" which we don't support.
-  verifyFormat("\"some text other\";", getStyleWithColumns(14));
+  verifyFormat("x = \"some text \"\n"
+   "+ \"other\";",
+   "x = \"some text other\";", getStyleWithColumns(18));
 }
 
 TEST_F(FormatTestJava, AlignsBlockComments) {
@@ -625,5 +603,7 @@
Style);
 }
 
+} // namespace
+} // namespace test
 } // namespace format
-} // end namespace clang
+} // namespace clang
Index: clang/unittests/Format/FormatTestJS.cpp
===
--- clang/unittests/Format/FormatTestJS.cpp
+++ clang/unittests/Format/FormatTestJS.cpp
@@ -1505,6 +1505,97 @@
 TEST_F(FormatTestJS, StringLiteralConcatenation) {
   verifyFormat("var literal = 'hello ' +\n"
"'world';");
+
+  // Long strings should be broken.
+  verifyFormat("var literal =\n"
+   "' ' +\n"
+   "'';",
+   "var literal = ' ';",
+

[PATCH] D157810: [clang][ExtractAPI] Create extractapi::RecordLocation

2023-08-26 Thread Ankur Saini via Phabricator via cfe-commits
Arsenic updated this revision to Diff 553730.
Arsenic added a comment.

Fix minor typo is comments

- Move creation of DocComment in it's own seperate function
- Update the Underlying DataType used by RecordLocation
- Update the patch to account for new C++ APIRecords


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157810

Files:
  clang/include/clang/ExtractAPI/API.h
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/lib/ExtractAPI/API.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/tools/libclang/CXExtractAPI.cpp

Index: clang/tools/libclang/CXExtractAPI.cpp
===
--- clang/tools/libclang/CXExtractAPI.cpp
+++ clang/tools/libclang/CXExtractAPI.cpp
@@ -61,9 +61,12 @@
 Context.getSourceManager().getPresumedLoc(Decl->getLocation());
 LinkageInfo Linkage = Decl->getLinkageAndVisibility();
 DocComment Comment;
-if (auto *RawComment = fetchRawCommentForDecl(Interface))
-  Comment = RawComment->getFormattedLines(Context.getSourceManager(),
-  Context.getDiagnostics());
+if (auto *RawComment = fetchRawCommentForDecl(Interface)) {
+  auto RawCommentVec = RawComment->getFormattedLines(
+  Context.getSourceManager(), Context.getDiagnostics());
+  std::copy(RawCommentVec.begin(), RawCommentVec.end(),
+std::back_inserter(Comment));
+}
 
 // Build declaration fragments and sub-heading by generating them for the
 // interface.
Index: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
===
--- clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -14,6 +14,7 @@
 #include "clang/ExtractAPI/Serialization/SymbolGraphSerializer.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/Version.h"
+#include "clang/ExtractAPI/API.h"
 #include "clang/ExtractAPI/DeclarationFragments.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/STLFunctionalExtras.h"
@@ -105,8 +106,7 @@
 }
 
 /// Serialize a source position.
-Object serializeSourcePosition(const PresumedLoc &Loc) {
-  assert(Loc.isValid() && "invalid source position");
+Object serializeSourcePosition(const RecordLocation &Loc) {
 
   Object SourcePosition;
   SourcePosition["line"] = Loc.getLine();
@@ -120,7 +120,7 @@
 /// \param Loc The presumed location to serialize.
 /// \param IncludeFileURI If true, include the file path of \p Loc as a URI.
 /// Defaults to false.
-Object serializeSourceLocation(const PresumedLoc &Loc,
+Object serializeSourceLocation(const RecordLocation &Loc,
bool IncludeFileURI = false) {
   Object SourceLocation;
   serializeObject(SourceLocation, "position", serializeSourcePosition(Loc));
@@ -136,8 +136,8 @@
 }
 
 /// Serialize a source range with begin and end locations.
-Object serializeSourceRange(const PresumedLoc &BeginLoc,
-const PresumedLoc &EndLoc) {
+Object serializeSourceRange(const RecordLocation &BeginLoc,
+const RecordLocation &EndLoc) {
   Object SourceRange;
   serializeObject(SourceRange, "start", serializeSourcePosition(BeginLoc));
   serializeObject(SourceRange, "end", serializeSourcePosition(EndLoc));
Index: clang/lib/ExtractAPI/API.cpp
===
--- clang/lib/ExtractAPI/API.cpp
+++ clang/lib/ExtractAPI/API.cpp
@@ -46,7 +46,7 @@
 
 NamespaceRecord *
 APISet::addNamespace(APIRecord *Parent, StringRef Name, StringRef USR,
- PresumedLoc Loc, AvailabilitySet Availability,
+ RecordLocation Loc, AvailabilitySet Availability,
  LinkageInfo Linkage, const DocComment &Comment,
  DeclarationFragments Declaration,
  DeclarationFragments SubHeading, bool IsFromSystemHeader) {
@@ -61,7 +61,7 @@
 }
 
 GlobalVariableRecord *
-APISet::addGlobalVar(StringRef Name, StringRef USR, PresumedLoc Loc,
+APISet::addGlobalVar(StringRef Name, StringRef USR, RecordLocation Loc,
  AvailabilitySet Availabilities, LinkageInfo Linkage,
  const DocComment &Comment, DeclarationFragments Fragments,
  DeclarationFragments SubHeading, bool IsFromSystemHeader) {
@@ -71,7 +71,7 @@
 }
 
 GlobalVariableTemplateRecord *APISet::addGlobalVariableTemplate(
-StringRef Name, StringRef USR, PresumedLoc Loc,
+StringRef Name, StringRef USR, RecordLocation Loc,
 AvailabilitySet Availability, LinkageInfo Linkage,
 const DocComment &Comment, DeclarationFragments Declaration,
 DeclarationFragments SubHeading, Template Template,
@@ -83,7 +83,7 @@
 }
 
 GlobalFunctionRecord *APISet::addGlobalFunction(
-Strin

[PATCH] D158933: [clang] Implement -funsigned-bitfields

2023-08-26 Thread David Ferenc Szabo via Phabricator via cfe-commits
DavidFerencSzabo created this revision.
Herald added a project: All.
DavidFerencSzabo requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158933

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/unsigned-bitfields.c

Index: clang/test/Sema/unsigned-bitfields.c
===
--- /dev/null
+++ clang/test/Sema/unsigned-bitfields.c
@@ -0,0 +1,161 @@
+// RUN: %clang_cc1 -fdump-record-layouts -emit-codegen-only %s -funsigned-bitfields | FileCheck %s
+
+// CHECK: BitFields
+// CHECK: Offset:0 Size:1 IsSigned:0
+// CHECK: Offset:1 Size:1 IsSigned:0
+// CHECK: Offset:2 Size:1 IsSigned:0
+// CHECK: Offset:3 Size:1 IsSigned:1
+// CHECK: Offset:4 Size:1 IsSigned:1
+// CHECK: Offset:5 Size:1 IsSigned:1
+// CHECK: Offset:6 Size:1 IsSigned:0
+// CHECK: Offset:7 Size:1 IsSigned:0
+// CHECK: Offset:8 Size:1 IsSigned:0
+// CHECK: Offset:9 Size:1 IsSigned:0
+// CHECK: Offset:10 Size:1 IsSigned:0
+// CHECK: Offset:11 Size:1 IsSigned:0
+// CHECK: Offset:12 Size:1 IsSigned:0
+// CHECK: Offset:13 Size:1 IsSigned:0
+// CHECK: Offset:14 Size:1 IsSigned:0
+// CHECK: Offset:15 Size:1 IsSigned:0
+// CHECK: Offset:16 Size:1 IsSigned:0
+// CHECK: Offset:17 Size:1 IsSigned:0
+// CHECK: Offset:18 Size:1 IsSigned:0
+// CHECK: Offset:19 Size:1 IsSigned:0
+// CHECK: Offset:20 Size:1 IsSigned:0
+// CHECK: Offset:21 Size:1 IsSigned:0
+// CHECK: Offset:22 Size:1 IsSigned:0
+// CHECK: Offset:23 Size:1 IsSigned:0
+// CHECK: Offset:24 Size:1 IsSigned:0
+// CHECK: Offset:25 Size:1 IsSigned:0
+// CHECK: Offset:26 Size:1 IsSigned:0
+// CHECK: Offset:27 Size:1 IsSigned:0
+// CHECK: Offset:28 Size:1 IsSigned:0
+// CHECK: Offset:29 Size:1 IsSigned:0
+// CHECK: Offset:30 Size:1 IsSigned:0
+// CHECK: Offset:31 Size:1 IsSigned:0
+// CHECK: Offset:32 Size:1 IsSigned:0
+// CHECK: Offset:33 Size:1 IsSigned:0
+// CHECK: Offset:34 Size:1 IsSigned:0
+// CHECK: Offset:35 Size:1 IsSigned:0
+// CHECK: Offset:36 Size:1 IsSigned:0
+// CHECK: Offset:37 Size:1 IsSigned:0
+// CHECK: Offset:38 Size:1 IsSigned:0
+// CHECK: Offset:39 Size:1 IsSigned:0
+// CHECK: Offset:40 Size:1 IsSigned:0
+// CHECK: Offset:41 Size:1 IsSigned:0
+// CHECK: Offset:42 Size:1 IsSigned:0
+// CHECK: Offset:43 Size:1 IsSigned:0
+// CHECK: Offset:44 Size:1 IsSigned:0
+
+
+
+typedef char c;
+typedef signed char sc;
+typedef unsigned char uc;
+typedef short s;
+typedef signed short ss;
+typedef unsigned short us;
+typedef int i;
+typedef signed int si;
+typedef unsigned int ui;
+typedef long l;
+typedef signed long sl;
+typedef unsigned long ul;
+typedef long long ll;
+typedef signed long long sll;
+typedef unsigned long long ull;
+
+typedef c ct;
+typedef sc sct;
+typedef uc uct;
+typedef s st;
+typedef ss sst;
+typedef us ust;
+typedef i it;
+typedef si sit;
+typedef ui uit;
+typedef l lt;
+typedef sl slt;
+typedef ul ult;
+typedef ll llt;
+typedef sll sllt;
+typedef ull ullt;
+
+struct foo {
+  char char0 : 1;
+  c char1 : 1;
+  ct char2 : 1;
+  signed char schar0 : 1;
+  sc schar1 : 1;
+  sct schar2 : 1;
+  unsigned char uchar0 : 1;
+  uc uchar1 : 1;
+  uct uchar2 : 1;
+  short short0 : 1;
+  s short1 : 1;
+  st short2 : 1;
+  signed short sshort0 : 1;
+  ss sshort1 : 1;
+  sst sshort2 : 1;
+  unsigned short ushort0 : 1;
+  us ushort1 : 1;
+  ust ushort2 : 1;
+  int int3 : 1;
+  i int4 : 1;
+  it int5 : 1;
+  signed int sint0 : 1;
+  si sint1 : 1;
+  sit sint2 : 1;
+  unsigned int uint0 : 1;
+  ui uint1 : 1;
+  uit uint2 : 1;
+  long long0 : 1;
+  l long1 : 1;
+  lt long2 : 1;
+  signed long slong0 : 1;
+  sl slong1 : 1;
+  slt slong2 : 1;
+  unsigned long ulong0 : 1;
+  ul ulong1 : 1;
+  ult ulong2 : 1;
+  long long llong0 : 1;
+  ll llong1 : 1;
+  llt llong2 : 1;
+  signed long long sllong0 : 1;
+  sll sllong1 : 1;
+  sllt sllong2 : 1;
+  unsigned long long ullong0 : 1;
+  ull ullong1 : 1;
+  ullt ullong2 : 1;
+};
+
+struct foo x;
+
+extern void abort (void);
+extern void exit (int);
+extern void *memset (void *, int, __SIZE_TYPE__);
+
+int
+main (void)
+{
+  memset (&x, (unsigned char)-1, sizeof(x));
+  if (x.char0 != 1 || x.char1 != 1 || x.char2 != 1
+  || x.schar0 != -1 || x.schar1 != -1 || x.schar2 != -1
+  || x.uchar0 != 1 || x.uchar1 != 1 || x.uchar2 != 1
+  || x.short0 != 1 || x.short1 != 1 || x.short2 != 1
+  || x.sshort0 != -1 || x.sshort1 != -1 || x.sshort2 != -1
+  || x.ushort0 != 1 || x.ushort1 != 1 || x.ushort2 != 1
+  || x.int3 != 1 || x.int4 != 1 || x.int5 != 1
+  || x.sint0 != -1 || x.sint1 != -1 || x.sint2 != -1
+  || x.uint0 != 1 || x.uint1 != 1 || x.uint2 != 1
+  || x.long0 != 1 || x.long1 != 1 || x.long2 != 1
+  || x.slong0 != -1 || x.slong1 != -1 || x.slong2 != -1
+  || x.ulong0 != 1 || x.ulong1 != 1 || x.ulong2 != 1
+

[PATCH] D158566: Add CLANGD_INCLUDE_TESTS as a separate flag to control clangd tests

2023-08-26 Thread Aditya Kumar via Phabricator via cfe-commits
hiraditya updated this revision to Diff 553738.

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

https://reviews.llvm.org/D158566

Files:
  clang-tools-extra/clangd/CMakeLists.txt


Index: clang-tools-extra/clangd/CMakeLists.txt
===
--- clang-tools-extra/clangd/CMakeLists.txt
+++ clang-tools-extra/clangd/CMakeLists.txt
@@ -208,13 +208,14 @@
   include(AddGRPC)
 endif()
 
-if(CLANG_INCLUDE_TESTS)
+if(CLANGD_INCLUDE_TESTS AND CLANG_INCLUDE_TESTS)
   add_subdirectory(test)
   add_subdirectory(unittests)
 endif()
 
 # FIXME(kirillbobyrev): Document this in the LLVM docs once remote index is 
stable.
 option(CLANGD_ENABLE_REMOTE "Use gRPC library to enable remote index support 
for Clangd" OFF)
+option(CLANGD_INCLUDE_TESTS "Include Clangd tests" ON)
 set(GRPC_INSTALL_PATH "" CACHE PATH "Path to gRPC library manual 
installation.")
 
 add_subdirectory(index/remote)


Index: clang-tools-extra/clangd/CMakeLists.txt
===
--- clang-tools-extra/clangd/CMakeLists.txt
+++ clang-tools-extra/clangd/CMakeLists.txt
@@ -208,13 +208,14 @@
   include(AddGRPC)
 endif()
 
-if(CLANG_INCLUDE_TESTS)
+if(CLANGD_INCLUDE_TESTS AND CLANG_INCLUDE_TESTS)
   add_subdirectory(test)
   add_subdirectory(unittests)
 endif()
 
 # FIXME(kirillbobyrev): Document this in the LLVM docs once remote index is stable.
 option(CLANGD_ENABLE_REMOTE "Use gRPC library to enable remote index support for Clangd" OFF)
+option(CLANGD_INCLUDE_TESTS "Include Clangd tests" ON)
 set(GRPC_INSTALL_PATH "" CACHE PATH "Path to gRPC library manual installation.")
 
 add_subdirectory(index/remote)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158566: Add CLANGD_INCLUDE_TESTS as a separate flag to control clangd tests

2023-08-26 Thread Aditya Kumar via Phabricator via cfe-commits
hiraditya added a comment.

> I'm marking as requiring changes mostly for the latter comment about 
> CLANG_INCLUDE_TESTS.

Added CLANG_INCLUDE_TESTS to the conditional. btw when CLANG_INCLUDE_TESTS is 
OFF, `ninja check-clang-tools` target doesn't get created so adding 
CLANG_INCLUDE_TESTS here didn't seem necessary, although tbh i'm not too 
familiar with the build system.


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

https://reviews.llvm.org/D158566

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


[clang] 2c9372e - [clang-format] Rename qualifier file comments (#64354)

2023-08-26 Thread via cfe-commits

Author: MyDeveloperDay
Date: 2023-08-26T16:48:52+01:00
New Revision: 2c9372e78d7c183ba7f28095cee0e2fb6a074c88

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

LOG: [clang-format] Rename qualifier file comments (#64354)

* [clang-format] rename the file comments to match the file name

* [clang-format] rename the file comments to match the file name

* Remove extraneous space

* [clang-format] NFC remove EOF

-

Co-authored-by: paul_hoad 

Added: 


Modified: 
clang/lib/Format/QualifierAlignmentFixer.cpp
clang/lib/Format/QualifierAlignmentFixer.h

Removed: 




diff  --git a/clang/lib/Format/QualifierAlignmentFixer.cpp 
b/clang/lib/Format/QualifierAlignmentFixer.cpp
old mode 100644
new mode 100755
index 2f920cdc4db2b5..77586532c851ff
--- a/clang/lib/Format/QualifierAlignmentFixer.cpp
+++ b/clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -1,4 +1,4 @@
-//===--- LeftRightQualifierAlignmentFixer.cpp ---*- 
C++--*-===//
+//===--- QualifierAlignmentFixer.cpp *- 
C++--*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -7,7 +7,7 @@
 
//===--===//
 ///
 /// \file
-/// This file implements LeftRightQualifierAlignmentFixer, a TokenAnalyzer that
+/// This file implements QualifierAlignmentFixer, a TokenAnalyzer that
 /// enforces either left or right const depending on the style.
 ///
 
//===--===//

diff  --git a/clang/lib/Format/QualifierAlignmentFixer.h 
b/clang/lib/Format/QualifierAlignmentFixer.h
old mode 100644
new mode 100755
index dc6f92e86ae7c7..a72d135179f1ec
--- a/clang/lib/Format/QualifierAlignmentFixer.h
+++ b/clang/lib/Format/QualifierAlignmentFixer.h
@@ -1,5 +1,4 @@
-//===--- LeftRightQualifierAlignmentFixer.h --*- 
C++
-//-*-===//
+//===--- QualifierAlignmentFixer.h ---*- 
C++-*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -8,7 +7,7 @@
 
//===--===//
 ///
 /// \file
-/// This file declares LeftRightQualifierAlignmentFixer, a TokenAnalyzer that
+/// This file declares QualifierAlignmentFixer, a TokenAnalyzer that
 /// enforces either east or west const depending on the style.
 ///
 
//===--===//



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


[PATCH] D158933: [clang] Implement -funsigned-bitfields

2023-08-26 Thread David Ferenc Szabo via Phabricator via cfe-commits
DavidFerencSzabo updated this revision to Diff 553745.

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

https://reviews.llvm.org/D158933

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/unsigned-bitfields.c

Index: clang/test/Sema/unsigned-bitfields.c
===
--- /dev/null
+++ clang/test/Sema/unsigned-bitfields.c
@@ -0,0 +1,160 @@
+// RUN: %clang_cc1 -fdump-record-layouts -emit-codegen-only %s -funsigned-bitfields | FileCheck %s
+
+// CHECK: BitFields
+// CHECK: Offset:0 Size:1 IsSigned:0
+// CHECK: Offset:1 Size:1 IsSigned:1
+// CHECK: Offset:2 Size:1 IsSigned:1
+// CHECK: Offset:3 Size:1 IsSigned:1
+// CHECK: Offset:4 Size:1 IsSigned:1
+// CHECK: Offset:5 Size:1 IsSigned:1
+// CHECK: Offset:6 Size:1 IsSigned:0
+// CHECK: Offset:7 Size:1 IsSigned:0
+// CHECK: Offset:8 Size:1 IsSigned:0
+// CHECK: Offset:9 Size:1 IsSigned:0
+// CHECK: Offset:10 Size:1 IsSigned:1
+// CHECK: Offset:11 Size:1 IsSigned:1
+// CHECK: Offset:12 Size:1 IsSigned:1
+// CHECK: Offset:13 Size:1 IsSigned:1
+// CHECK: Offset:14 Size:1 IsSigned:1
+// CHECK: Offset:15 Size:1 IsSigned:0
+// CHECK: Offset:16 Size:1 IsSigned:0
+// CHECK: Offset:17 Size:1 IsSigned:0
+// CHECK: Offset:18 Size:1 IsSigned:0
+// CHECK: Offset:19 Size:1 IsSigned:1
+// CHECK: Offset:20 Size:1 IsSigned:1
+// CHECK: Offset:21 Size:1 IsSigned:1
+// CHECK: Offset:22 Size:1 IsSigned:1
+// CHECK: Offset:23 Size:1 IsSigned:1
+// CHECK: Offset:24 Size:1 IsSigned:0
+// CHECK: Offset:25 Size:1 IsSigned:0
+// CHECK: Offset:26 Size:1 IsSigned:0
+// CHECK: Offset:27 Size:1 IsSigned:0
+// CHECK: Offset:28 Size:1 IsSigned:1
+// CHECK: Offset:29 Size:1 IsSigned:1
+// CHECK: Offset:30 Size:1 IsSigned:1
+// CHECK: Offset:31 Size:1 IsSigned:1
+// CHECK: Offset:32 Size:1 IsSigned:1
+// CHECK: Offset:33 Size:1 IsSigned:0
+// CHECK: Offset:34 Size:1 IsSigned:0
+// CHECK: Offset:35 Size:1 IsSigned:0
+// CHECK: Offset:36 Size:1 IsSigned:0
+// CHECK: Offset:37 Size:1 IsSigned:1
+// CHECK: Offset:38 Size:1 IsSigned:1
+// CHECK: Offset:39 Size:1 IsSigned:1
+// CHECK: Offset:40 Size:1 IsSigned:1
+// CHECK: Offset:41 Size:1 IsSigned:1
+// CHECK: Offset:42 Size:1 IsSigned:0
+// CHECK: Offset:43 Size:1 IsSigned:0
+// CHECK: Offset:44 Size:1 IsSigned:0
+
+
+
+typedef char c;
+typedef signed char sc;
+typedef unsigned char uc;
+typedef short s;
+typedef signed short ss;
+typedef unsigned short us;
+typedef int i;
+typedef signed int si;
+typedef unsigned int ui;
+typedef long l;
+typedef signed long sl;
+typedef unsigned long ul;
+typedef long long ll;
+typedef signed long long sll;
+typedef unsigned long long ull;
+
+typedef c ct;
+typedef sc sct;
+typedef uc uct;
+typedef s st;
+typedef ss sst;
+typedef us ust;
+typedef i it;
+typedef si sit;
+typedef ui uit;
+typedef l lt;
+typedef sl slt;
+typedef ul ult;
+typedef ll llt;
+typedef sll sllt;
+typedef ull ullt;
+
+struct foo {
+  char char0 : 1;
+  c char1 : 1;
+  ct char2 : 1;
+  signed char schar0 : 1;
+  sc schar1 : 1;
+  sct schar2 : 1;
+  unsigned char uchar0 : 1;
+  uc uchar1 : 1;
+  uct uchar2 : 1;
+  short short0 : 1;
+  s short1 : 1;
+  st short2 : 1;
+  signed short sshort0 : 1;
+  ss sshort1 : 1;
+  sst sshort2 : 1;
+  unsigned short ushort0 : 1;
+  us ushort1 : 1;
+  ust ushort2 : 1;
+  int int3 : 1;
+  i int4 : 1;
+  it int5 : 1;
+  signed int sint0 : 1;
+  si sint1 : 1;
+  sit sint2 : 1;
+  unsigned int uint0 : 1;
+  ui uint1 : 1;
+  uit uint2 : 1;
+  long long0 : 1;
+  l long1 : 1;
+  lt long2 : 1;
+  signed long slong0 : 1;
+  sl slong1 : 1;
+  slt slong2 : 1;
+  unsigned long ulong0 : 1;
+  ul ulong1 : 1;
+  ult ulong2 : 1;
+  long long llong0 : 1;
+  ll llong1 : 1;
+  llt llong2 : 1;
+  signed long long sllong0 : 1;
+  sll sllong1 : 1;
+  sllt sllong2 : 1;
+  unsigned long long ullong0 : 1;
+  ull ullong1 : 1;
+  ullt ullong2 : 1;
+};
+
+struct foo x;
+
+extern void abort (void);
+extern void exit (int);
+extern void *memset (void *, int, __SIZE_TYPE__);
+
+int
+main (void)
+{
+  memset (&x, (unsigned char)-1, sizeof(x));
+  if (x.char0 != 1 || x.char1 != 1 || x.char2 != 1
+  || x.schar0 != -1 || x.schar1 != -1 || x.schar2 != -1
+  || x.uchar0 != 1 || x.uchar1 != 1 || x.uchar2 != 1
+  || x.short0 != 1 || x.short1 != 1 || x.short2 != 1
+  || x.sshort0 != -1 || x.sshort1 != -1 || x.sshort2 != -1
+  || x.ushort0 != 1 || x.ushort1 != 1 || x.ushort2 != 1
+  || x.int3 != 1 || x.int4 != 1 || x.int5 != 1
+  || x.sint0 != -1 || x.sint1 != -1 || x.sint2 != -1
+  || x.uint0 != 1 || x.uint1 != 1 || x.uint2 != 1
+  || x.long0 != 1 || x.long1 != 1 || x.long2 != 1
+  || x.slong0 != -1 || x.slong1 != -1 || x.slong2 != -1
+  || x.ulong0 != 1 || x.ulong1 != 1 || x.ulong2 != 1
+  || x.llong0 != 1 || x.llong1 != 1 || x.llong2 != 1
+  || x.sllong0 != -1 || x.sllong1 != -1 || x.sllong2 != -1
+  || x.ullong0 != 1 || x.ullong1 !=

[PATCH] D158925: [clang-format][NFC] Skip stability test if input is pre-formatted

2023-08-26 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/unittests/Format/FormatTestBase.h:88
 testing::ScopedTrace t(File, Line, ::testing::Message() << Code.str());
-EXPECT_EQ(Expected.str(),
-  format(Expected, Style, SC_ExpectComplete, Ranges))
-<< "Expected code is not stable";
+if (!Expected.equals(Code)) {
+  EXPECT_EQ(Expected.str(),

Will fix it before landing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158925

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


[PATCH] D154382: [ClangRepl] support code completion at a REPL

2023-08-26 Thread Fred Fu via Phabricator via cfe-commits
capfredf updated this revision to Diff 553759.
capfredf added a comment.

fix potential memory issues


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154382

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang/include/clang/Frontend/ASTUnit.h
  clang/include/clang/Interpreter/CodeCompletion.h
  clang/include/clang/Sema/CodeCompleteConsumer.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Frontend/ASTUnit.cpp
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/CodeCompletion.cpp
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/CodeCompleteConsumer.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/incrememal-mode-completion-no-error.cpp
  clang/test/CodeCompletion/incremental-top-level.cpp
  clang/tools/clang-repl/ClangRepl.cpp
  clang/tools/libclang/CIndexCodeCompletion.cpp
  clang/unittests/Interpreter/CMakeLists.txt
  clang/unittests/Interpreter/CodeCompletionTest.cpp

Index: clang/unittests/Interpreter/CodeCompletionTest.cpp
===
--- /dev/null
+++ clang/unittests/Interpreter/CodeCompletionTest.cpp
@@ -0,0 +1,100 @@
+#include "clang/Interpreter/CodeCompletion.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Interpreter/Interpreter.h"
+#include "clang/Sema/CodeCompleteConsumer.h"
+#include "llvm/LineEditor/LineEditor.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+namespace {
+auto CB = clang::IncrementalCompilerBuilder();
+
+static std::unique_ptr createInterpreter() {
+  auto CI = cantFail(CB.CreateCpp());
+  return cantFail(clang::Interpreter::create(std::move(CI)));
+}
+
+static std::vector runComp(clang::Interpreter &MainInterp,
+llvm::StringRef Prefix,
+llvm::Error &ErrR) {
+  auto CI = CB.CreateCpp();
+  if (auto Err = CI.takeError()) {
+ErrR = std::move(Err);
+return {};
+  }
+
+  auto Interp = clang::Interpreter::create(std::move(*CI));
+  if (auto Err = Interp.takeError()) {
+// log the error and returns an empty vector;
+ErrR = std::move(Err);
+
+return {};
+  }
+
+  std::vector Results;
+  std::vector Comps;
+
+  codeComplete(
+  const_cast((*Interp)->getCompilerInstance()),
+  Prefix, 1, Prefix.size(), MainInterp.getCompilerInstance(), Results);
+
+  for (auto Res : Results)
+if (Res.find(Prefix) == 0)
+  Comps.push_back(Res);
+
+  return Comps;
+}
+
+TEST(CodeCompletionTest, Sanity) {
+  auto Interp = createInterpreter();
+  if (auto R = Interp->ParseAndExecute("int foo = 12;")) {
+consumeError(std::move(R));
+return;
+  }
+  auto Err = llvm::Error::success();
+  auto comps = runComp(*Interp, "f", Err);
+  EXPECT_EQ((size_t)2, comps.size()); // foo and float
+  EXPECT_EQ(comps[0], std::string("foo"));
+  EXPECT_EQ((bool)Err, false);
+}
+
+TEST(CodeCompletionTest, SanityNoneValid) {
+  auto Interp = createInterpreter();
+  if (auto R = Interp->ParseAndExecute("int foo = 12;")) {
+consumeError(std::move(R));
+return;
+  }
+  auto Err = llvm::Error::success();
+  auto comps = runComp(*Interp, "babanana", Err);
+  EXPECT_EQ((size_t)0, comps.size()); // foo and float
+  EXPECT_EQ((bool)Err, false);
+}
+
+TEST(CodeCompletionTest, TwoDecls) {
+  auto Interp = createInterpreter();
+  if (auto R = Interp->ParseAndExecute("int application = 12;")) {
+consumeError(std::move(R));
+return;
+  }
+  if (auto R = Interp->ParseAndExecute("int apple = 12;")) {
+consumeError(std::move(R));
+return;
+  }
+  auto Err = llvm::Error::success();
+  auto comps = runComp(*Interp, "app", Err);
+  EXPECT_EQ((size_t)2, comps.size());
+  EXPECT_EQ((bool)Err, false);
+}
+
+TEST(CodeCompletionTest, CompFunDeclsNoError) {
+  auto Interp = createInterpreter();
+  auto Err = llvm::Error::success();
+  auto comps = runComp(*Interp, "void app(", Err);
+  EXPECT_EQ((bool)Err, false);
+}
+
+} // anonymous namespace
Index: clang/unittests/Interpreter/CMakeLists.txt
===
--- clang/unittests/Interpreter/CMakeLists.txt
+++ clang/unittests/Interpreter/CMakeLists.txt
@@ -9,6 +9,7 @@
 add_clang_unittest(ClangReplInterpreterTests
   IncrementalProcessingTest.cpp
   InterpreterTest.cpp
+  CodeCompletionTest.cpp
   )
 target_link_libraries(ClangReplInterpreterTests PUBLIC
   clangAST
Index: clang/tools/libclang/CIndexCodeCompletion.cpp
===
--- clang/tools/libclang/CIndexCodeCompletion.cpp
+++ clang/tools/libclang/CIndexCodeCompletion.cpp
@@ -11,8 +11,8 @@
 //
 //===-

[PATCH] D154382: [ClangRepl] support code completion at a REPL

2023-08-26 Thread Fred Fu via Phabricator via cfe-commits
capfredf updated this revision to Diff 553762.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154382

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang/include/clang/Frontend/ASTUnit.h
  clang/include/clang/Interpreter/CodeCompletion.h
  clang/include/clang/Sema/CodeCompleteConsumer.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Frontend/ASTUnit.cpp
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/CodeCompletion.cpp
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/CodeCompleteConsumer.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/incrememal-mode-completion-no-error.cpp
  clang/test/CodeCompletion/incremental-top-level.cpp
  clang/tools/clang-repl/ClangRepl.cpp
  clang/tools/libclang/CIndexCodeCompletion.cpp
  clang/unittests/Interpreter/CMakeLists.txt
  clang/unittests/Interpreter/CodeCompletionTest.cpp

Index: clang/unittests/Interpreter/CodeCompletionTest.cpp
===
--- /dev/null
+++ clang/unittests/Interpreter/CodeCompletionTest.cpp
@@ -0,0 +1,101 @@
+#include "clang/Interpreter/CodeCompletion.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Interpreter/Interpreter.h"
+#include "clang/Sema/CodeCompleteConsumer.h"
+#include "llvm/LineEditor/LineEditor.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+namespace {
+auto CB = clang::IncrementalCompilerBuilder();
+
+static std::unique_ptr createInterpreter() {
+  auto CI = cantFail(CB.CreateCpp());
+  return cantFail(clang::Interpreter::create(std::move(CI)));
+}
+
+static std::vector runComp(clang::Interpreter &MainInterp,
+llvm::StringRef Prefix,
+llvm::Error &ErrR) {
+  auto CI = CB.CreateCpp();
+  if (auto Err = CI.takeError()) {
+ErrR = std::move(Err);
+return {};
+  }
+
+  auto Interp = clang::Interpreter::create(std::move(*CI));
+  if (auto Err = Interp.takeError()) {
+// log the error and returns an empty vector;
+ErrR = std::move(Err);
+
+return {};
+  }
+
+  std::vector Results;
+  std::vector Comps;
+
+  codeComplete(
+  const_cast((*Interp)->getCompilerInstance()),
+  Prefix, /* Lines */ 1, Prefix.size(), MainInterp.getCompilerInstance(),
+  Results);
+
+  for (auto Res : Results)
+if (Res.find(Prefix) == 0)
+  Comps.push_back(Res);
+
+  return Comps;
+}
+
+TEST(CodeCompletionTest, Sanity) {
+  auto Interp = createInterpreter();
+  if (auto R = Interp->ParseAndExecute("int foo = 12;")) {
+consumeError(std::move(R));
+return;
+  }
+  auto Err = llvm::Error::success();
+  auto comps = runComp(*Interp, "f", Err);
+  EXPECT_EQ((size_t)2, comps.size()); // foo and float
+  EXPECT_EQ(comps[0], std::string("foo"));
+  EXPECT_EQ((bool)Err, false);
+}
+
+TEST(CodeCompletionTest, SanityNoneValid) {
+  auto Interp = createInterpreter();
+  if (auto R = Interp->ParseAndExecute("int foo = 12;")) {
+consumeError(std::move(R));
+return;
+  }
+  auto Err = llvm::Error::success();
+  auto comps = runComp(*Interp, "babanana", Err);
+  EXPECT_EQ((size_t)0, comps.size()); // foo and float
+  EXPECT_EQ((bool)Err, false);
+}
+
+TEST(CodeCompletionTest, TwoDecls) {
+  auto Interp = createInterpreter();
+  if (auto R = Interp->ParseAndExecute("int application = 12;")) {
+consumeError(std::move(R));
+return;
+  }
+  if (auto R = Interp->ParseAndExecute("int apple = 12;")) {
+consumeError(std::move(R));
+return;
+  }
+  auto Err = llvm::Error::success();
+  auto comps = runComp(*Interp, "app", Err);
+  EXPECT_EQ((size_t)2, comps.size());
+  EXPECT_EQ((bool)Err, false);
+}
+
+TEST(CodeCompletionTest, CompFunDeclsNoError) {
+  auto Interp = createInterpreter();
+  auto Err = llvm::Error::success();
+  auto comps = runComp(*Interp, "void app(", Err);
+  EXPECT_EQ((bool)Err, false);
+}
+
+} // anonymous namespace
Index: clang/unittests/Interpreter/CMakeLists.txt
===
--- clang/unittests/Interpreter/CMakeLists.txt
+++ clang/unittests/Interpreter/CMakeLists.txt
@@ -9,6 +9,7 @@
 add_clang_unittest(ClangReplInterpreterTests
   IncrementalProcessingTest.cpp
   InterpreterTest.cpp
+  CodeCompletionTest.cpp
   )
 target_link_libraries(ClangReplInterpreterTests PUBLIC
   clangAST
Index: clang/tools/libclang/CIndexCodeCompletion.cpp
===
--- clang/tools/libclang/CIndexCodeCompletion.cpp
+++ clang/tools/libclang/CIndexCodeCompletion.cpp
@@ -11,8 +11,8 @@
 //
 //===--===//
 
-#in

[PATCH] D158641: [AArch64][Android][DRAFT] Fix FMV ifunc resolver usage on old Android APIs.

2023-08-26 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: compiler-rt/lib/builtins/cpu_model.c:1379
 
+void init_cpu_features_resolver(unsigned long hwcap, const __ifunc_arg_t *arg) 
{
+  if (__aarch64_cpu_features.features)

It seems that we don't need the `_constructor` function. We can just move the 

```
#if defined(__ANDROID__)
  // ifunc resolvers don't have hwcaps in arguments on Android API lower
  // than 30. In this case set detection done and keep all CPU features
  // unsupported (zeros).
  if (android_get_device_api_level() < 30) {
setCPUFeature(FEAT_MAX);
return;
  }
```

logic to init_cpu_features_resolver


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158641

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


[clang] c852145 - [clang-format][NFC] Skip stability test if input is pre-formatted

2023-08-26 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2023-08-26T14:48:04-07:00
New Revision: c8521451708a49a5a55cf02c28189efac11b779e

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

LOG: [clang-format][NFC] Skip stability test if input is pre-formatted

This shortens the run-time of FormatTests by about 10% on average (and
by up to 50% if formatting would not change the input).

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

Added: 


Modified: 
clang/unittests/Format/FormatTestBase.h

Removed: 




diff  --git a/clang/unittests/Format/FormatTestBase.h 
b/clang/unittests/Format/FormatTestBase.h
index 40442d60aa3300..2b0c4550bb951f 100644
--- a/clang/unittests/Format/FormatTestBase.h
+++ b/clang/unittests/Format/FormatTestBase.h
@@ -85,9 +85,11 @@ class FormatTestBase : public ::testing::Test {
  const std::optional &Style = {},
  const std::vector &Ranges = {}) {
 testing::ScopedTrace t(File, Line, ::testing::Message() << Code.str());
-EXPECT_EQ(Expected.str(),
-  format(Expected, Style, SC_ExpectComplete, Ranges))
-<< "Expected code is not stable";
+if (Expected != Code) {
+  EXPECT_EQ(Expected.str(),
+format(Expected, Style, SC_ExpectComplete, Ranges))
+  << "Expected code is not stable";
+}
 EXPECT_EQ(Expected.str(), format(Code, Style, SC_ExpectComplete, Ranges));
 auto UsedStyle = Style ? Style.value() : getDefaultStyle();
 if (UsedStyle.Language == FormatStyle::LK_Cpp) {



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


[PATCH] D158925: [clang-format][NFC] Skip stability test if input is pre-formatted

2023-08-26 Thread Owen Pan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc8521451708a: [clang-format][NFC] Skip stability test if 
input is pre-formatted (authored by owenpan).

Changed prior to commit:
  https://reviews.llvm.org/D158925?vs=553714&id=553765#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158925

Files:
  clang/unittests/Format/FormatTestBase.h


Index: clang/unittests/Format/FormatTestBase.h
===
--- clang/unittests/Format/FormatTestBase.h
+++ clang/unittests/Format/FormatTestBase.h
@@ -85,9 +85,11 @@
  const std::optional &Style = {},
  const std::vector &Ranges = {}) {
 testing::ScopedTrace t(File, Line, ::testing::Message() << Code.str());
-EXPECT_EQ(Expected.str(),
-  format(Expected, Style, SC_ExpectComplete, Ranges))
-<< "Expected code is not stable";
+if (Expected != Code) {
+  EXPECT_EQ(Expected.str(),
+format(Expected, Style, SC_ExpectComplete, Ranges))
+  << "Expected code is not stable";
+}
 EXPECT_EQ(Expected.str(), format(Code, Style, SC_ExpectComplete, Ranges));
 auto UsedStyle = Style ? Style.value() : getDefaultStyle();
 if (UsedStyle.Language == FormatStyle::LK_Cpp) {


Index: clang/unittests/Format/FormatTestBase.h
===
--- clang/unittests/Format/FormatTestBase.h
+++ clang/unittests/Format/FormatTestBase.h
@@ -85,9 +85,11 @@
  const std::optional &Style = {},
  const std::vector &Ranges = {}) {
 testing::ScopedTrace t(File, Line, ::testing::Message() << Code.str());
-EXPECT_EQ(Expected.str(),
-  format(Expected, Style, SC_ExpectComplete, Ranges))
-<< "Expected code is not stable";
+if (Expected != Code) {
+  EXPECT_EQ(Expected.str(),
+format(Expected, Style, SC_ExpectComplete, Ranges))
+  << "Expected code is not stable";
+}
 EXPECT_EQ(Expected.str(), format(Code, Style, SC_ExpectComplete, Ranges));
 auto UsedStyle = Style ? Style.value() : getDefaultStyle();
 if (UsedStyle.Language == FormatStyle::LK_Cpp) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158945: [clang-format] Handle Template Arguments with AlignConsecutiveXX

2023-08-26 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks created this revision.
Herald added projects: All, clang, clang-format.
Herald added a subscriber: cfe-commits.
Herald added reviewers: rymiel, owenpan, MyDeveloperDay.
HazardyKnusperkeks requested review of this revision.

This fixes https://github.com/llvm/llvm-project/issues/64928.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158945

Files:
  clang/lib/Format/WhitespaceManager.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -18726,6 +18726,13 @@
"{a_longer_name_for_wrap,\n"
" a_longer_name_for_wrap}};",
Alignment);
+
+  Alignment.ColumnLimit = 60;
+  verifyFormat("using II = typename TI>::I;\n"
+   "using I  = std::conditional_t= 0,\n"
+   "  std::ic,\n"
+   "  std::ic>;",
+   Alignment);
 }
 
 TEST_F(FormatTest, AlignConsecutiveBitFields) {
Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -425,6 +425,10 @@
   return true;
 }
 
+// Continued template parameter.
+if (Changes[ScopeStart - 1].Tok->is(TT_TemplateOpener))
+  return true;
+
 return false;
   };
 


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -18726,6 +18726,13 @@
"{a_longer_name_for_wrap,\n"
" a_longer_name_for_wrap}};",
Alignment);
+
+  Alignment.ColumnLimit = 60;
+  verifyFormat("using II = typename TI>::I;\n"
+   "using I  = std::conditional_t= 0,\n"
+   "  std::ic,\n"
+   "  std::ic>;",
+   Alignment);
 }
 
 TEST_F(FormatTest, AlignConsecutiveBitFields) {
Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -425,6 +425,10 @@
   return true;
 }
 
+// Continued template parameter.
+if (Changes[ScopeStart - 1].Tok->is(TT_TemplateOpener))
+  return true;
+
 return false;
   };
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158946: Delete Ananas support

2023-08-26 Thread Brad Smith via Phabricator via cfe-commits
brad created this revision.
brad added a reviewer: MaskRay.
brad added a project: LLVM.
Herald added subscribers: ormris, hiraditya.
Herald added a project: All.
brad requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

After looking at this further I think the Ananas support should be removed.

They stopped using Clang,.There have never been any releases either; as in 
source only, and the backend is not maintained.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158946

Files:
  clang/docs/tools/clang-formatted-files.txt
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Ananas.cpp
  clang/lib/Driver/ToolChains/Ananas.h
  clang/test/Driver/ananas.c
  clang/test/Preprocessor/predefined-macros-no-warnings.c
  llvm/include/llvm/TargetParser/Triple.h
  llvm/lib/TargetParser/Triple.cpp
  llvm/unittests/TargetParser/TripleTest.cpp
  llvm/utils/gn/secondary/clang/lib/Driver/BUILD.gn

Index: llvm/utils/gn/secondary/clang/lib/Driver/BUILD.gn
===
--- llvm/utils/gn/secondary/clang/lib/Driver/BUILD.gn
+++ llvm/utils/gn/secondary/clang/lib/Driver/BUILD.gn
@@ -48,7 +48,6 @@
 "ToolChains/AMDGPU.cpp",
 "ToolChains/AMDGPUOpenMP.cpp",
 "ToolChains/AVR.cpp",
-"ToolChains/Ananas.cpp",
 "ToolChains/Arch/AArch64.cpp",
 "ToolChains/Arch/ARM.cpp",
 "ToolChains/Arch/CSKY.cpp",
Index: llvm/unittests/TargetParser/TripleTest.cpp
===
--- llvm/unittests/TargetParser/TripleTest.cpp
+++ llvm/unittests/TargetParser/TripleTest.cpp
@@ -319,12 +319,6 @@
   EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
   EXPECT_EQ(Triple::UnknownOS, T.getOS());
 
-  T = Triple("x86_64-unknown-ananas");
-  EXPECT_EQ(Triple::x86_64, T.getArch());
-  EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
-  EXPECT_EQ(Triple::Ananas, T.getOS());
-  EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
-
   T = Triple("x86_64-unknown-cloudabi");
   EXPECT_EQ(Triple::x86_64, T.getArch());
   EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
Index: llvm/lib/TargetParser/Triple.cpp
===
--- llvm/lib/TargetParser/Triple.cpp
+++ llvm/lib/TargetParser/Triple.cpp
@@ -207,7 +207,6 @@
   case AIX: return "aix";
   case AMDHSA: return "amdhsa";
   case AMDPAL: return "amdpal";
-  case Ananas: return "ananas";
   case CUDA: return "cuda";
   case CloudABI: return "cloudabi";
   case Darwin: return "darwin";
@@ -571,7 +570,6 @@
 
 static Triple::OSType parseOS(StringRef OSName) {
   return StringSwitch(OSName)
-.StartsWith("ananas", Triple::Ananas)
 .StartsWith("cloudabi", Triple::CloudABI)
 .StartsWith("darwin", Triple::Darwin)
 .StartsWith("dragonfly", Triple::DragonFly)
Index: llvm/include/llvm/TargetParser/Triple.h
===
--- llvm/include/llvm/TargetParser/Triple.h
+++ llvm/include/llvm/TargetParser/Triple.h
@@ -184,7 +184,6 @@
   enum OSType {
 UnknownOS,
 
-Ananas,
 CloudABI,
 Darwin,
 DragonFly,
Index: clang/test/Preprocessor/predefined-macros-no-warnings.c
===
--- clang/test/Preprocessor/predefined-macros-no-warnings.c
+++ clang/test/Preprocessor/predefined-macros-no-warnings.c
@@ -135,7 +135,6 @@
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple tcele
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple i686
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple i686-darwin
-// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple i686-ananas
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple i686-cloudabi
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple i686-linux
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple i686-linux-android
@@ -157,7 +156,6 @@
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple i686-hurd
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple x86_64
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple x86_64-darwin
-// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple x86_64-ananas
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple x86_64-cloudabi
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple x86_64-linux
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple x86_64-linux-android
Index: clang/test/Driver/ananas.c
===
--- clang/test/Driver/ananas.c
+++ /dev/null
@@ -1,26 +0,0 @@
-// RUN: %clang --target=x86_64-unknown-ananas -static %s \
-// RUN:   --sysroot=%S/Inputs/ananas-tree -### 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-STATIC %s
-// CHECK-STATIC: ld{{.*}}" "-Bs

[clang] 19e3dfa - [clang-format][NFC] Chang some verifyFormat() to verifyNoChange()

2023-08-26 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2023-08-26T19:44:05-07:00
New Revision: 19e3dfad58d36ed5aee798fc1b0af2a449002afc

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

LOG: [clang-format][NFC] Chang some verifyFormat() to verifyNoChange()

Added: 


Modified: 
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 9ef59a8a35d9cb..a0a6b942d8dfa6 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -6169,7 +6169,7 @@ TEST_F(FormatTest, IndentPreprocessorDirectives) {
"#  define C 0\n"
"#endif";
 EXPECT_EQ(Expected, format(ToFormat, Style));
-verifyFormat(Expected, Style);
+verifyNoChange(Expected, Style);
   }
   // Keep block quotes aligned.
   {
@@ -6219,7 +6219,7 @@ TEST_F(FormatTest, IndentPreprocessorDirectives) {
"   // Code. Not aligned with #\n"
"#define C 0\n";
 EXPECT_EQ(Expected, format(ToFormat, Style));
-verifyFormat(Expected, Style);
+verifyNoChange(Expected, Style);
   }
   // Test AfterHash with tabs.
   {
@@ -6306,7 +6306,7 @@ TEST_F(FormatTest, IndentPreprocessorDirectives) {
"#endif\n"
"}";
 EXPECT_EQ(Expected, format(ToFormat, Style));
-verifyFormat(Expected, Style);
+verifyNoChange(Expected, Style);
   }
   {
 const char *Expected = "void f() {\n"
@@ -24190,11 +24190,11 @@ TEST_F(FormatTest, WhitespaceSensitiveMacros) {
 
   // Don't use the helpers here, since 'mess up' will change the whitespace
   // and these are all whitespace sensitive by definition
-  verifyFormat("FOO(String-ized&Messy+But(: :Still)=Intentional);", Style);
+  verifyNoChange("FOO(String-ized&Messy+But(: :Still)=Intentional);", Style);
   EXPECT_EQ(
   "FOO(String-ized&Messy+But\\(: :Still)=Intentional);",
   format("FOO(String-ized&Messy+But\\(: :Still)=Intentional);", Style));
-  verifyFormat("FOO(String-ized&Messy+But,: :Still=Intentional);", Style);
+  verifyNoChange("FOO(String-ized&Messy+But,: :Still=Intentional);", Style);
   EXPECT_EQ("FOO(String-ized&Messy+But,: :\n"
 "   Still=Intentional);",
 format("FOO(String-ized&Messy+But,: :\n"
@@ -24208,7 +24208,7 @@ TEST_F(FormatTest, WhitespaceSensitiveMacros) {
Style));
 
   Style.ColumnLimit = 21;
-  verifyFormat("FOO(String-ized&Messy+But: :Still=Intentional);", Style);
+  verifyNoChange("FOO(String-ized&Messy+But: :Still=Intentional);", Style);
 }
 
 TEST_F(FormatTest, VeryLongNamespaceCommentSplit) {



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


[clang] f2b8666 - [ORC][clang-repl] Fix clang-repl -host-supports-jit option after 122ebe3b500.

2023-08-26 Thread Lang Hames via cfe-commits

Author: Lang Hames
Date: 2023-08-26T19:46:33-07:00
New Revision: f2b866653169d479a964f99b7679738742f6a6a2

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

LOG: [ORC][clang-repl] Fix clang-repl -host-supports-jit option after 
122ebe3b500.

Same fix as 8a62d6ba7e: We need to make sure that the supports-JIT check uses
the same JIT config that will be used by the clang-repl tool.

Added: 


Modified: 
clang/tools/clang-repl/ClangRepl.cpp

Removed: 




diff  --git a/clang/tools/clang-repl/ClangRepl.cpp 
b/clang/tools/clang-repl/ClangRepl.cpp
index f46452d9e10d1a..535866b8495eff 100644
--- a/clang/tools/clang-repl/ClangRepl.cpp
+++ b/clang/tools/clang-repl/ClangRepl.cpp
@@ -87,7 +87,9 @@ int main(int argc, const char **argv) {
   llvm::InitializeAllAsmPrinters();
 
   if (OptHostSupportsJit) {
-auto J = llvm::orc::LLJITBuilder().create();
+auto J = llvm::orc::LLJITBuilder()
+   .setEnableDebuggerSupport(true)
+   .create();
 if (J)
   llvm::outs() << "true\n";
 else {



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


[PATCH] D158947: [clang-format][NFC] Test formatting the input before messing it up

2023-08-26 Thread Owen Pan via Phabricator via cfe-commits
owenpan created this revision.
Herald added projects: All, clang, clang-format.
Herald added a subscriber: cfe-commits.
Herald added reviewers: rymiel, HazardyKnusperkeks, MyDeveloperDay.
owenpan requested review of this revision.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158947

Files:
  clang/unittests/Format/FormatTestBase.h


Index: clang/unittests/Format/FormatTestBase.h
===
--- clang/unittests/Format/FormatTestBase.h
+++ clang/unittests/Format/FormatTestBase.h
@@ -105,7 +105,9 @@
 
   void _verifyFormat(const char *File, int Line, llvm::StringRef Code,
  const std::optional &Style = {}) {
-_verifyFormat(File, Line, Code, test::messUp(Code), Style);
+_verifyFormat(File, Line, Code, Code, Style);
+if (const auto MessedUpCode{messUp(Code)}; MessedUpCode != Code)
+  _verifyFormat(File, Line, Code, MessedUpCode, Style);
   }
 
   void _verifyIncompleteFormat(const char *File, int Line, llvm::StringRef 
Code,


Index: clang/unittests/Format/FormatTestBase.h
===
--- clang/unittests/Format/FormatTestBase.h
+++ clang/unittests/Format/FormatTestBase.h
@@ -105,7 +105,9 @@
 
   void _verifyFormat(const char *File, int Line, llvm::StringRef Code,
  const std::optional &Style = {}) {
-_verifyFormat(File, Line, Code, test::messUp(Code), Style);
+_verifyFormat(File, Line, Code, Code, Style);
+if (const auto MessedUpCode{messUp(Code)}; MessedUpCode != Code)
+  _verifyFormat(File, Line, Code, MessedUpCode, Style);
   }
 
   void _verifyIncompleteFormat(const char *File, int Line, llvm::StringRef Code,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 08bbff4 - [OpenMP] Codegen support for thread_limit on target directive for host

2023-08-26 Thread Sandeep Kosuri via cfe-commits

Author: Sandeep Kosuri
Date: 2023-08-26T22:18:49-05:00
New Revision: 08bbff4aad57c70a38d5d2680a61901977e66637

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

LOG: [OpenMP] Codegen support for thread_limit on target directive for host
offloading

- This patch adds support for thread_limit clause on target directive according 
to OpenMP 51 [2.14.5]
- The idea is to create an outer task for target region, when there is a 
thread_limit clause, and manipulate the thread_limit of task instead. This way, 
thread_limit will be applied to all the relevant constructs enclosed by the 
target region.

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

Added: 
clang/test/OpenMP/target_parallel_for_simd_tl_codegen.cpp
clang/test/OpenMP/target_parallel_for_tl_codegen.cpp
clang/test/OpenMP/target_parallel_generic_loop_tl_codegen.cpp
clang/test/OpenMP/target_parallel_tl_codegen.cpp
clang/test/OpenMP/target_simd_tl_codegen.cpp
openmp/runtime/test/target/target_thread_limit.cpp

Modified: 
clang/include/clang/Basic/OpenMPKinds.h
clang/lib/Basic/OpenMPKinds.cpp
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/CodeGen/CGOpenMPRuntime.h
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/target_codegen.cpp
llvm/include/llvm/Frontend/OpenMP/OMP.td
llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
openmp/runtime/src/kmp.h
openmp/runtime/src/kmp_csupport.cpp
openmp/runtime/src/kmp_ftn_entry.h
openmp/runtime/src/kmp_global.cpp
openmp/runtime/src/kmp_runtime.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/OpenMPKinds.h 
b/clang/include/clang/Basic/OpenMPKinds.h
index f5fc7a8ce5bb3c..ac1b3cdfff145b 100644
--- a/clang/include/clang/Basic/OpenMPKinds.h
+++ b/clang/include/clang/Basic/OpenMPKinds.h
@@ -356,6 +356,13 @@ void getOpenMPCaptureRegions(
 /// \return true - if the above condition is met for this directive
 /// otherwise - false.
 bool isOpenMPCombinedParallelADirective(OpenMPDirectiveKind DKind);
+
+/// Checks if the specified target directive, combined or not, needs task based
+/// thread_limit
+/// \param DKind Specified directive.
+/// \return true - if the above condition is met for this directive
+/// otherwise - false.
+bool needsTaskBasedThreadLimit(OpenMPDirectiveKind DKind);
 }
 
 #endif

diff  --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp
index a679f2ecf0e2b5..86de067da134a0 100644
--- a/clang/lib/Basic/OpenMPKinds.cpp
+++ b/clang/lib/Basic/OpenMPKinds.cpp
@@ -748,6 +748,13 @@ bool 
clang::isOpenMPCombinedParallelADirective(OpenMPDirectiveKind DKind) {
  DKind == OMPD_parallel_sections;
 }
 
+bool clang::needsTaskBasedThreadLimit(OpenMPDirectiveKind DKind) {
+  return DKind == OMPD_target || DKind == OMPD_target_parallel ||
+ DKind == OMPD_target_parallel_for ||
+ DKind == OMPD_target_parallel_for_simd || DKind == OMPD_target_simd ||
+ DKind == OMPD_target_parallel_loop;
+}
+
 void clang::getOpenMPCaptureRegions(
 SmallVectorImpl &CaptureRegions,
 OpenMPDirectiveKind DKind) {

diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 5d947a2c0943a1..253ef8b75163ec 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -9681,9 +9681,13 @@ void CGOpenMPRuntime::emitTargetCall(
 
   assert((OffloadingMandatory || OutlinedFn) && "Invalid outlined function!");
 
-  const bool RequiresOuterTask = D.hasClausesOfKind() ||
- D.hasClausesOfKind() ||
- D.hasClausesOfKind();
+  const bool RequiresOuterTask =
+  D.hasClausesOfKind() ||
+  D.hasClausesOfKind() ||
+  D.hasClausesOfKind() ||
+  (CGM.getLangOpts().OpenMP >= 51 &&
+   needsTaskBasedThreadLimit(D.getDirectiveKind()) &&
+   D.hasClausesOfKind());
   llvm::SmallVector CapturedVars;
   const CapturedStmt &CS = *D.getCapturedStmt(OMPD_target);
   auto &&ArgsCodegen = [&CS, &CapturedVars](CodeGenFunction &CGF,
@@ -10235,6 +10239,24 @@ void 
CGOpenMPRuntime::emitNumTeamsClause(CodeGenFunction &CGF,
   PushNumTeamsArgs);
 }
 
+void CGOpenMPRuntime::emitThreadLimitClause(CodeGenFunction &CGF,
+const Expr *ThreadLimit,
+SourceLocation Loc) {
+  llvm::Value *RTLoc = emitUpdateLocation(CGF, Loc);
+  llvm::Value *ThreadLimitVal =
+  ThreadLimit
+  ? CGF.Builder.CreateIntCast(CGF.EmitScalarExpr(ThreadLimit),
+  CGF.CGM.Int32Ty, /* isSigned = */ true)
+  : CGF.Builder.getInt32(0);
+
+  // Build call __kmpc_set_thread_limit(&loc, global_tid, 

[PATCH] D152054: [OpenMP] Codegen support for thread_limit on target directive

2023-08-26 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG08bbff4aad57: [OpenMP] Codegen support for thread_limit on 
target directive for host (authored by sandeepkosuri, committed by Sandeep 
Kosuri ).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152054

Files:
  clang/include/clang/Basic/OpenMPKinds.h
  clang/lib/Basic/OpenMPKinds.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/target_codegen.cpp
  clang/test/OpenMP/target_parallel_for_simd_tl_codegen.cpp
  clang/test/OpenMP/target_parallel_for_tl_codegen.cpp
  clang/test/OpenMP/target_parallel_generic_loop_tl_codegen.cpp
  clang/test/OpenMP/target_parallel_tl_codegen.cpp
  clang/test/OpenMP/target_simd_tl_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMP.td
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
  openmp/runtime/src/kmp.h
  openmp/runtime/src/kmp_csupport.cpp
  openmp/runtime/src/kmp_ftn_entry.h
  openmp/runtime/src/kmp_global.cpp
  openmp/runtime/src/kmp_runtime.cpp
  openmp/runtime/test/target/target_thread_limit.cpp

Index: openmp/runtime/test/target/target_thread_limit.cpp
===
--- /dev/null
+++ openmp/runtime/test/target/target_thread_limit.cpp
@@ -0,0 +1,168 @@
+// RUN: %libomp-cxx-compile -fopenmp-version=51
+// RUN: %libomp-run | FileCheck %s --check-prefix OMP51
+
+#include 
+#include 
+
+void foo() {
+#pragma omp parallel num_threads(10)
+  { printf("\ntarget: foo(): parallel num_threads(10)"); }
+}
+
+int main(void) {
+
+  int tl = 4;
+  printf("\nmain: thread_limit = %d", omp_get_thread_limit());
+  // OMP51: main: thread_limit = {{[0-9]+}}
+
+#pragma omp target thread_limit(tl)
+  {
+printf("\ntarget: thread_limit = %d", omp_get_thread_limit());
+// OMP51: target: thread_limit = 4
+// check whether thread_limit is honoured
+#pragma omp parallel
+{ printf("\ntarget: parallel"); }
+// OMP51: target: parallel
+// OMP51: target: parallel
+// OMP51: target: parallel
+// OMP51: target: parallel
+// OMP51-NOT: target: parallel
+
+// check whether num_threads is honoured
+#pragma omp parallel num_threads(2)
+{ printf("\ntarget: parallel num_threads(2)"); }
+// OMP51: target: parallel num_threads(2)
+// OMP51: target: parallel num_threads(2)
+// OMP51-NOT: target: parallel num_threads(2)
+
+// check whether thread_limit is honoured when there is a conflicting
+// num_threads
+#pragma omp parallel num_threads(10)
+{ printf("\ntarget: parallel num_threads(10)"); }
+// OMP51: target: parallel num_threads(10)
+// OMP51: target: parallel num_threads(10)
+// OMP51: target: parallel num_threads(10)
+// OMP51: target: parallel num_threads(10)
+// OMP51-NOT: target: parallel num_threads(10)
+
+// check whether threads are limited across functions
+foo();
+// OMP51: target: foo(): parallel num_threads(10)
+// OMP51: target: foo(): parallel num_threads(10)
+// OMP51: target: foo(): parallel num_threads(10)
+// OMP51: target: foo(): parallel num_threads(10)
+// OMP51-NOT: target: foo(): parallel num_threads(10)
+
+// check if user can set num_threads at runtime
+omp_set_num_threads(2);
+#pragma omp parallel
+{ printf("\ntarget: parallel with omp_set_num_thread(2)"); }
+// OMP51: target: parallel with omp_set_num_thread(2)
+// OMP51: target: parallel with omp_set_num_thread(2)
+// OMP51-NOT: target: parallel with omp_set_num_thread(2)
+
+// make sure thread_limit is unaffected by omp_set_num_threads
+printf("\ntarget: thread_limit = %d", omp_get_thread_limit());
+// OMP51: target: thread_limit = 4
+  }
+
+// checking consecutive target regions with different thread_limits
+#pragma omp target thread_limit(3)
+  {
+printf("\nsecond target: thread_limit = %d", omp_get_thread_limit());
+// OMP51: second target: thread_limit = 3
+#pragma omp parallel
+{ printf("\nsecond target: parallel"); }
+// OMP51: second target: parallel
+// OMP51: second target: parallel
+// OMP51: second target: parallel
+// OMP51-NOT: second target: parallel
+  }
+
+  // confirm that thread_limit's effects are limited to target region
+  printf("\nmain: thread_limit = %d", omp_get_thread_limit());
+  // OMP51: main: thread_limit = {{[0-9]+}}
+#pragma omp parallel num_threads(10)
+  { printf("\nmain: parallel num_threads(10)"); }
+  // OMP51: main: parallel num_threads(10)
+  // OMP51: main: parallel num_threads(10)
+  // OMP51: main: parallel num_threads(10)
+  // OMP51: main: parallel num_threads(10)
+  // OMP51: main: parallel num_threads(10)
+  // OMP51: main: parallel num_threads(10)
+  // OMP51: main: parallel num_threads(10)
+  // OMP51: main: parallel num_threads(10)
+  // OMP51: main: parallel num_threads(10)
+  // OM

[PATCH] D158872: [clang][ASTMatchers] Add a few type-related Matchers

2023-08-26 Thread Ding Fei via Phabricator via cfe-commits
danix800 updated this revision to Diff 553779.
danix800 added a comment.

Update doc: fix improper naming in objc testcase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158872

Files:
  clang/docs/LibASTMatchersReference.html
  clang/docs/ReleaseNotes.rst
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/ASTMatchFinder.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersTest.h

Index: clang/unittests/ASTMatchers/ASTMatchersTest.h
===
--- clang/unittests/ASTMatchers/ASTMatchersTest.h
+++ clang/unittests/ASTMatchers/ASTMatchersTest.h
@@ -284,6 +284,33 @@
   {"-fopenmp=libomp", "-fopenmp-version=51"});
 }
 
+template 
+testing::AssertionResult matchesOpenCL(const Twine &Code, const T &AMatcher) {
+  return matchesConditionally(Code, AMatcher, true,
+  {"-x", "cl", "-cl-no-stdinc", "-cl-std=CL2.0"},
+  FileContentMappings(), "input.cl");
+}
+
+template 
+testing::AssertionResult notMatchesOpenCL(const Twine &Code,
+  const T &AMatcher) {
+  return matchesConditionally(Code, AMatcher, false,
+  {"-x", "cl", "-cl-no-stdinc", "-cl-std=CL2.0"},
+  FileContentMappings(), "input.cl");
+}
+
+template 
+testing::AssertionResult matchesWithMatrixEnabled(const Twine &Code,
+  const T &AMatcher) {
+  return matchesConditionally(Code, AMatcher, true, {"-fenable-matrix"});
+}
+
+template 
+testing::AssertionResult notMatchesWithMatrixEnabled(const Twine &Code,
+ const T &AMatcher) {
+  return matchesConditionally(Code, AMatcher, false, {"-fenable-matrix"});
+}
+
 template 
 testing::AssertionResult matchAndVerifyResultConditionally(
 const Twine &Code, const T &AMatcher,
Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -1549,6 +1549,89 @@
   EXPECT_TRUE(matches("struct S {};", qualType().bind("loc")));
 }
 
+TEST_P(ASTMatchersTest, BitIntType) {
+  StringRef code = "_BitInt(10) i;";
+  EXPECT_TRUE(matches(code, varDecl(hasType(bitIntType();
+  EXPECT_TRUE(notMatches(code, varDecl(hasType(builtinType();
+}
+
+TEST_P(ASTMatchersTest, ConstantMatrixType) {
+  StringRef Code = "typedef int __attribute__((matrix_type(5, 5))) X;";
+
+  EXPECT_TRUE(matchesWithMatrixEnabled(
+  Code, typedefDecl(hasType(constantMatrixType();
+  EXPECT_TRUE(
+  notMatchesWithMatrixEnabled(Code, typedefDecl(hasType(vectorType();
+}
+
+TEST_P(ASTMatchersTest, DependentAddressSpaceType) {
+  if (!GetParam().isCXX())
+return;
+
+  StringRef Code = "template"
+   "class vector {"
+   "  typedef T __attribute__((address_space(AddrSpace))) X;"
+   "};";
+  EXPECT_TRUE(matches(Code, typedefDecl(hasType(dependentAddressSpaceType();
+
+  EXPECT_TRUE(notMatches("int __attribute__((address_space(0))) X;",
+ typedefDecl(hasType(dependentAddressSpaceType();
+}
+
+TEST_P(ASTMatchersTest, DependentBitIntType) {
+  if (!GetParam().isCXX11OrLater())
+return;
+
+  EXPECT_TRUE(matches("template using X = _BitInt(Width);",
+  typeAliasDecl(hasType(dependentBitIntType();
+
+  EXPECT_TRUE(notMatches("typedef _BitInt(10) Int10;",
+ typedefDecl(hasType(dependentBitIntType();
+}
+
+TEST_P(ASTMatchersTest, DependentVectorType) {
+  if (!GetParam().isCXX())
+return;
+
+  StringRef DepCode = "template"
+  "class vector {"
+  "  typedef T __attribute__((vector_size(Size))) X;"
+  "};";
+  EXPECT_TRUE(matches(DepCode, dependentVectorType()));
+
+  StringRef NonDepCode = "typedef int __attribute__((vector_size(16))) X;";
+  EXPECT_TRUE(notMatches(NonDepCode, dependentVectorType()));
+}
+
+TEST_P(ASTMatchersTest, VectorType) {
+  if (!GetParam().isCXX())
+return;
+
+  StringRef NonDepCode = "typedef int __attribute__((vector_size(16))) X;";
+  EXPECT_TRUE(matches(NonDepCode, vectorType()));
+
+  StringRef DepCode = "template"
+  "class vector {"
+  "  typedef T __attribute__((vector_size(Size))) X;"
+  "};";
+  EXPECT_TRUE(notMatches(DepCode, vectorType()));
+}
+
+TEST_P(ASTMatchersTest, DependentSizedMatrixType) {
+  if (!GetParam().isCXX())
+return;
+
+  StringRef DepCode = "template"
+  "clas

[PATCH] D158948: [clang][ASTImporter] Add import of type-related nodes

2023-08-26 Thread Ding Fei via Phabricator via cfe-commits
danix800 created this revision.
danix800 added a reviewer: balazske.
danix800 added a project: clang.
Herald added a subscriber: martong.
Herald added a reviewer: a.sidorin.
Herald added a reviewer: shafik.
Herald added a project: All.
danix800 requested review of this revision.
Herald added a subscriber: cfe-commits.

Add import of type-related nodes:

- bitIntType
- constantMatrixType
- dependentAddressSpaceType
- dependentBitIntType
- dependentSizedMatrixType
- dependentVectorType
- hasTypeForDecl
- objcTypeParamDecl
- objcTypeParamType
- pipeType
- vectorType


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158948

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterObjCTest.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -583,6 +583,88 @@
   functionDecl(hasDescendant(typedefDecl(has(atomicType());
 }
 
+TEST_P(ImportType, ImportBitIntType) {
+  MatchVerifier Verifier;
+  testImport("_BitInt(10) declToImport;", Lang_CXX11, "", Lang_CXX11, Verifier,
+ varDecl(hasType(bitIntType(;
+}
+
+TEST_P(ImportType, ImportDependentBitIntType) {
+  MatchVerifier Verifier;
+  testImport("template using declToImport = _BitInt(Width);",
+ Lang_CXX11, "", Lang_CXX11, Verifier,
+ typeAliasTemplateDecl(
+ has(typeAliasDecl(hasType(dependentBitIntType());
+}
+
+TEST_P(ImportType, ImportDependentAddressSpaceType) {
+  MatchVerifier Verifier;
+  testImport(
+  R"(
+template
+using declToImport = T __attribute__((address_space(AddrSpace)));
+  )",
+  Lang_CXX11, "", Lang_CXX11, Verifier,
+  typeAliasTemplateDecl(
+  has(typeAliasDecl(hasType(dependentAddressSpaceType());
+}
+
+TEST_P(ImportType, ImportVectorType) {
+  MatchVerifier Verifier;
+  testImport("typedef int __attribute__((vector_size(12))) declToImport;",
+ Lang_CXX11, "", Lang_CXX11, Verifier,
+ typedefDecl(hasType(vectorType(;
+}
+
+TEST_P(ImportType, ImportDependentVectorType) {
+  MatchVerifier Verifier;
+  testImport(
+  R"(
+template
+using declToImport = T __attribute__((vector_size(Size)));
+  )",
+  Lang_CXX11, "", Lang_CXX11, Verifier,
+  typeAliasTemplateDecl(
+  has(typeAliasDecl(hasType(dependentVectorType());
+}
+
+struct ImportOpenCLPipe : ImportType {
+  std::vector getExtraArgs() const override {
+return {"-x", "cl", "-cl-no-stdinc", "-cl-std=CL2.0"};
+  }
+};
+
+TEST_P(ImportOpenCLPipe, ImportPipeType) {
+  MatchVerifier Verifier;
+  testImport("typedef pipe int declToImport;", Lang_OpenCL, "", Lang_OpenCL,
+ Verifier, typedefDecl(hasType(pipeType(;
+}
+
+struct ImportMatrixType : ImportType {
+  std::vector getExtraArgs() const override {
+return {"-fenable-matrix"};
+  }
+};
+
+TEST_P(ImportMatrixType, ImportConstantMatrixType) {
+  MatchVerifier Verifier;
+  testImport("typedef int __attribute__((matrix_type(5, 5))) declToImport;",
+ Lang_CXX11, "", Lang_CXX11, Verifier,
+ typedefDecl(hasType(constantMatrixType(;
+}
+
+TEST_P(ImportMatrixType, ImportDependentSizedMatrixType) {
+  MatchVerifier Verifier;
+  testImport(
+  R"(
+template
+using declToImport = T __attribute__((matrix_type(Rows, Cols)));
+  )",
+  Lang_CXX11, "", Lang_CXX11, Verifier,
+  typeAliasTemplateDecl(
+  has(typeAliasDecl(hasType(dependentSizedMatrixType());
+}
+
 TEST_P(ImportType, ImportUsingType) {
   MatchVerifier Verifier;
   testImport("struct C {};"
Index: clang/unittests/AST/ASTImporterObjCTest.cpp
===
--- clang/unittests/AST/ASTImporterObjCTest.cpp
+++ clang/unittests/AST/ASTImporterObjCTest.cpp
@@ -77,6 +77,31 @@
   }
 }
 
+TEST_P(ImportObjCDecl, ImportObjCTypeParamDecl) {
+  Decl *FromTU = getTuDecl(
+  R"(
+@interface X 
+@end
+  )",
+  Lang_OBJCXX, "input.mm");
+  auto Pattern = objcTypeParamDecl(hasTypeForDecl(objcTypeParamType()));
+  auto *FromInterfaceDecl = FirstDeclMatcher().match(
+  FromTU, namedDecl(hasName("X")));
+  auto *FromTypeParamDecl =
+  FirstDeclMatcher().match(FromInterfaceDecl, Pattern);
+
+  auto ToTypeParamDeclImported = Import(FromTypeParamDecl, Lang_OBJCXX);
+
+  auto *ToInterfaceDecl = FirstDeclMatcher().match(
+  ToTypeParamDeclImported->getTranslationUnitDecl(),
+  namedDecl(hasName("X")));
+  auto *ToTypeParamDeclMatched =
+  FirstDeclMatcher().match(ToInterfaceDecl, Pattern);
+  ASSERT_TRUE(ToTypeParamDeclImported);
+  ASSERT_TRUE(ToTypeParamDeclMatched);
+  ASSERT_TRUE(ToTypeParamDeclImported == ToTypeParamDeclMatched);
+}
+
 static const auto ObjCTestArrayForRunOptions =
 std::array, 2>{
 {std:

[PATCH] D158795: Fix AlignArrayOfStructures + Cpp11BracedListStyle=false

2023-08-26 Thread Galen Elias via Phabricator via cfe-commits
galenelias marked an inline comment as done.
galenelias added inline comments.



Comment at: clang/lib/Format/WhitespaceManager.cpp:1247
 if (Previous && Previous->isNot(TT_LineComment)) {
-  Changes[Next->Index].Spaces = 0;
+  Changes[Next->Index].Spaces = BracePadding;
   Changes[Next->Index].NewlinesBefore = 0;

owenpan wrote:
> owenpan wrote:
> > Can we assert that `Spaces == 0`? If not, we should add a test case.
> We can't assert that, but setting `Spaces` here seems superfluous as it's set 
> correctly below anyways?
I admit I'm not super confident on my understanding of this code, but this 
setting of Spaces is not redundant with any below settings.  If we set it to 
'3' for instance, that won't get overwritten later (because the other sets are 
all conditional, and don't hit for the `}` token).

So, I think this is still required (minus the issue of the existing 'Spaces' 
calculation from previous formatting pass seemingly already setting Spaces to 
the correct value).



Comment at: clang/unittests/Format/FormatTest.cpp:20888
+   "  {  7, 5,\"!!\" }\n"
+   "};\n",
+   Style);

owenpan wrote:
> 
This is consistent with basically every single adjacent test in this function.  
While I agree that this is unnecessary, in general I error on the side of 
consistency with the surrounding tests.  I'll defer to the maintainers, just 
wanted to make sure this is actually the preferred change given the numerous 
adjacent tests with this form.


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

https://reviews.llvm.org/D158795

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


[PATCH] D158795: Fix AlignArrayOfStructures + Cpp11BracedListStyle=false

2023-08-26 Thread Galen Elias via Phabricator via cfe-commits
galenelias updated this revision to Diff 553783.

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

https://reviews.llvm.org/D158795

Files:
  clang/lib/Format/WhitespaceManager.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -20880,6 +20880,16 @@
"});\n",
Style);
 
+  Style.Cpp11BracedListStyle = false;
+  verifyFormat("struct test demo[] = {\n"
+   "  { 56,23, \"hello\" },\n"
+   "  { -1, 93463, \"world\" },\n"
+   "  {  7, 5,\"!!\" }\n"
+   "};\n",
+   Style);
+
+  Style.Cpp11BracedListStyle = true;
+
   Style.ColumnLimit = 0;
   EXPECT_EQ(
   "test demo[] = {\n"
@@ -21112,6 +21122,15 @@
"});\n",
Style);
 
+  Style.Cpp11BracedListStyle = false;
+  verifyFormat("struct test demo[] = {\n"
+   "  { 56, 23,\"hello\" },\n"
+   "  { -1, 93463, \"world\" },\n"
+   "  { 7,  5, \"!!\"}\n"
+   "};\n",
+   Style);
+  Style.Cpp11BracedListStyle = true;
+
   Style.ColumnLimit = 0;
   EXPECT_EQ(
   "test demo[] = {\n"
Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -1226,6 +1226,7 @@
   if (!CellDescs.isRectangular())
 return;
 
+  const int BracePadding = Style.Cpp11BracedListStyle ? 0 : 1;
   auto &Cells = CellDescs.Cells;
   // Now go through and fixup the spaces.
   auto *CellIter = Cells.begin();
@@ -1243,7 +1244,7 @@
   do {
 const FormatToken *Previous = Changes[Next->Index].Tok->Previous;
 if (Previous && Previous->isNot(TT_LineComment)) {
-  Changes[Next->Index].Spaces = 0;
+  Changes[Next->Index].Spaces = BracePadding;
   Changes[Next->Index].NewlinesBefore = 0;
 }
 Next = Next->NextColumnElement;
@@ -1276,7 +1277,7 @@
   NetWidth;
   if (Changes[CellIter->Index].NewlinesBefore == 0) {
 Changes[CellIter->Index].Spaces = (CellWidth - (ThisWidth + NetWidth));
-Changes[CellIter->Index].Spaces += (i > 0) ? 1 : 0;
+Changes[CellIter->Index].Spaces += (i > 0) ? 1 : BracePadding;
   }
   alignToStartOfCell(CellIter->Index, CellIter->EndIndex);
   for (const auto *Next = CellIter->NextColumnElement; Next;
@@ -1285,7 +1286,7 @@
 calculateCellWidth(Next->Index, Next->EndIndex, true) + NetWidth;
 if (Changes[Next->Index].NewlinesBefore == 0) {
   Changes[Next->Index].Spaces = (CellWidth - ThisWidth);
-  Changes[Next->Index].Spaces += (i > 0) ? 1 : 0;
+  Changes[Next->Index].Spaces += (i > 0) ? 1 : BracePadding;
 }
 alignToStartOfCell(Next->Index, Next->EndIndex);
   }
@@ -1299,12 +1300,13 @@
   if (!CellDescs.isRectangular())
 return;
 
+  const int BracePadding = Style.Cpp11BracedListStyle ? 0 : 1;
   auto &Cells = CellDescs.Cells;
   // Now go through and fixup the spaces.
   auto *CellIter = Cells.begin();
   // The first cell needs to be against the left brace.
   if (Changes[CellIter->Index].NewlinesBefore == 0)
-Changes[CellIter->Index].Spaces = 0;
+Changes[CellIter->Index].Spaces = BracePadding;
   else
 Changes[CellIter->Index].Spaces = CellDescs.InitialSpaces;
   ++CellIter;
@@ -1317,7 +1319,7 @@
 if (Changes[CellIter->Index].NewlinesBefore == 0) {
   Changes[CellIter->Index].Spaces =
   MaxNetWidth - ThisNetWidth +
-  (Changes[CellIter->Index].Tok->isNot(tok::r_brace) ? 1 : 0);
+  (Changes[CellIter->Index].Tok->isNot(tok::r_brace) ? 1 : BracePadding);
 }
 auto RowCount = 1U;
 auto Offset = std::distance(Cells.begin(), CellIter);
@@ -1331,7 +1333,7 @@
   if (Changes[Next->Index].NewlinesBefore == 0) {
 Changes[Next->Index].Spaces =
 MaxNetWidth - ThisNetWidth +
-(Changes[Next->Index].Tok->isNot(tok::r_brace) ? 1 : 0);
+(Changes[Next->Index].Tok->isNot(tok::r_brace) ? 1 : BracePadding);
   }
   ++RowCount;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158795: Fix AlignArrayOfStructures + Cpp11BracedListStyle=false

2023-08-26 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/unittests/Format/FormatTest.cpp:20888
+   "  {  7, 5,\"!!\" }\n"
+   "};\n",
+   Style);

galenelias wrote:
> owenpan wrote:
> > 
> This is consistent with basically every single adjacent test in this 
> function.  While I agree that this is unnecessary, in general I error on the 
> side of consistency with the surrounding tests.  I'll defer to the 
> maintainers, just wanted to make sure this is actually the preferred change 
> given the numerous adjacent tests with this form.
If you rebase your patch, you'll see that the trailing newlines in the 
surrounding tests have been removed. (Even if they had not been removed, we 
still wouldn't want new tests to have superfluous trailing newlines.)


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

https://reviews.llvm.org/D158795

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