[PATCH] D137494: [Clangd] Fix the code action `RemoveUsingNamespace`

2022-11-05 Thread v1nh1shungry via Phabricator via cfe-commits
v1nh1shungry updated this revision to Diff 473480.
v1nh1shungry added a comment.

Format codes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137494

Files:
  clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
  clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp


Index: clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
@@ -226,6 +226,29 @@
   int main() {
 std::vector V;
   }
+)cpp"},
+  {// Does not qualify operators declared in a non-class context
+   R"cpp(
+  namespace ns {
+  struct Foo {};
+  void operator+(const Foo &, int) {}
+  }
+  using namespace n^s;
+  int main() {
+Foo foo;
+foo + 10;
+  }
+)cpp",
+   R"cpp(
+  namespace ns {
+  struct Foo {};
+  void operator+(const Foo &, int) {}
+  }
+  
+  int main() {
+ns::Foo foo;
+foo + 10;
+  }
 )cpp"}};
   for (auto C : Cases)
 EXPECT_EQ(C.second, apply(C.first)) << C.first;
Index: clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
@@ -155,6 +155,13 @@
 if (!visibleContext(T->getDeclContext())
  ->Equals(TargetDirective->getNominatedNamespace()))
   return;
+// Avoid adding qualifiers before operators, e.g.
+//   using namespace std;
+//   cout << "foo"; // Must not changed to std::cout std:: << "foo"
+// FIXME: User-defined literals are not handled
+if (T->isInIdentifierNamespace(
+Decl::IdentifierNamespace::IDNS_NonMemberOperator))
+  return;
   }
   SourceLocation Loc = Ref.NameLoc;
   if (Loc.isMacroID()) {


Index: clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
@@ -226,6 +226,29 @@
   int main() {
 std::vector V;
   }
+)cpp"},
+  {// Does not qualify operators declared in a non-class context
+   R"cpp(
+  namespace ns {
+  struct Foo {};
+  void operator+(const Foo &, int) {}
+  }
+  using namespace n^s;
+  int main() {
+Foo foo;
+foo + 10;
+  }
+)cpp",
+   R"cpp(
+  namespace ns {
+  struct Foo {};
+  void operator+(const Foo &, int) {}
+  }
+  
+  int main() {
+ns::Foo foo;
+foo + 10;
+  }
 )cpp"}};
   for (auto C : Cases)
 EXPECT_EQ(C.second, apply(C.first)) << C.first;
Index: clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
@@ -155,6 +155,13 @@
 if (!visibleContext(T->getDeclContext())
  ->Equals(TargetDirective->getNominatedNamespace()))
   return;
+// Avoid adding qualifiers before operators, e.g.
+//   using namespace std;
+//   cout << "foo"; // Must not changed to std::cout std:: << "foo"
+// FIXME: User-defined literals are not handled
+if (T->isInIdentifierNamespace(
+Decl::IdentifierNamespace::IDNS_NonMemberOperator))
+  return;
   }
   SourceLocation Loc = Ref.NameLoc;
   if (Loc.isMacroID()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137494: [Clangd] Fix the code action `RemoveUsingNamespace`

2022-11-05 Thread v1nh1shungry via Phabricator via cfe-commits
v1nh1shungry added a comment.

@junaire Thank you for reviewing!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137494

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


[PATCH] D137494: [Clangd] Fix the code action `RemoveUsingNamespace`

2022-11-05 Thread Jun Zhang via Phabricator via cfe-commits
junaire added inline comments.



Comment at: 
clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp:236
+  }
+  using namespace n^s;
+  int main() {

v1nh1shungry wrote:
> junaire wrote:
> > is this a typo?
> I guess not. I refer to the tests above and I think this represents the 
> cursor. But I'm not sure though.
> I guess not. I refer to the tests above and I think this represents the 
> cursor. But I'm not sure though.

OK, thanks for the clarification!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137494

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


[PATCH] D136846: [Driver] Add -fsample-profile-use-profi

2022-11-05 Thread Wenlei He via Phabricator via cfe-commits
wenlei added a comment.

In D136846#3910272 , @MaskRay wrote:

> In D136846#3890699 , @wenlei wrote:
>
>> Did you see measurable perf boost with profi on autofdo? Or what motivated 
>> you to turn on profi? In most cases, profi helps when csspgo is used 
>> (instead of traditional autofdo).
>
> LG in my view, but @wenlei may have something to add.

lgtm.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136846

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


[PATCH] D137494: [Clangd] Fix the code action `RemoveUsingNamespace`

2022-11-05 Thread v1nh1shungry via Phabricator via cfe-commits
v1nh1shungry added inline comments.



Comment at: 
clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp:236
+  }
+  using namespace n^s;
+  int main() {

junaire wrote:
> is this a typo?
I guess not. I refer to the tests above and I think this represents the cursor. 
But I'm not sure though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137494

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


[PATCH] D137494: [Clangd] Fix the code action `RemoveUsingNamespace`

2022-11-05 Thread v1nh1shungry via Phabricator via cfe-commits
v1nh1shungry added a comment.

In D137494#3910500 , @v1nh1shungry 
wrote:

> @tom-anders Thank you for reviewing!
>
> I tried adding a test but I don't know how to run the tests.
>
> And I just found that operators declared in a class context are already 
> handled in the existing version, but user-defined literals are not, so I 
> rewrote the comments.

Sorry, I found tips about running tests in the document. Feel like a fool :)

Please check this test is correct and suitable. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137494

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


[PATCH] D137494: [Clangd] Fix the code action `RemoveUsingNamespace`

2022-11-05 Thread Jun Zhang via Phabricator via cfe-commits
junaire added a comment.

In D137494#3910500 , @v1nh1shungry 
wrote:

> @tom-anders Thank you for reviewing!
>
> I tried adding a test but I don't know how to run the tests.
>
> And I just found that operators declared in a class context are already 
> handled in the existing version, but user-defined literals are not, so I 
> rewrote the comments.

I guess that's `ninja check-clangd`?




Comment at: 
clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp:236
+  }
+  using namespace n^s;
+  int main() {

is this a typo?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137494

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


[PATCH] D137494: [Clangd] Fix the code action `RemoveUsingNamespace`

2022-11-05 Thread v1nh1shungry via Phabricator via cfe-commits
v1nh1shungry updated this revision to Diff 473478.
v1nh1shungry added a comment.

Correct the test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137494

Files:
  clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
  clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp


Index: clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
@@ -226,7 +226,30 @@
   int main() {
 std::vector V;
   }
-)cpp"}};
+)cpp"},
+  {// Does not qualify operators declared in a non-class context
+   R"cpp(
+  namespace ns {
+  struct Foo {};
+  void operator+(const Foo &, int) {}
+  }
+  using namespace n^s;
+  int main() {
+Foo foo;
+foo + 10;
+  }
+  )cpp",
+   R"cpp(
+  namespace ns {
+  struct Foo {};
+  void operator+(const Foo &, int) {}
+  }
+  
+  int main() {
+ns::Foo foo;
+foo + 10;
+  }
+  )cpp"}};
   for (auto C : Cases)
 EXPECT_EQ(C.second, apply(C.first)) << C.first;
 }
Index: clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
@@ -155,6 +155,13 @@
 if (!visibleContext(T->getDeclContext())
  ->Equals(TargetDirective->getNominatedNamespace()))
   return;
+// Avoid adding qualifiers before operators, e.g.
+//   using namespace std;
+//   cout << "foo"; // Must not changed to std::cout std:: << "foo"
+// FIXME: User-defined literals are not handled
+if (T->isInIdentifierNamespace(
+Decl::IdentifierNamespace::IDNS_NonMemberOperator))
+  return;
   }
   SourceLocation Loc = Ref.NameLoc;
   if (Loc.isMacroID()) {


Index: clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
@@ -226,7 +226,30 @@
   int main() {
 std::vector V;
   }
-)cpp"}};
+)cpp"},
+  {// Does not qualify operators declared in a non-class context
+   R"cpp(
+  namespace ns {
+  struct Foo {};
+  void operator+(const Foo &, int) {}
+  }
+  using namespace n^s;
+  int main() {
+Foo foo;
+foo + 10;
+  }
+  )cpp",
+   R"cpp(
+  namespace ns {
+  struct Foo {};
+  void operator+(const Foo &, int) {}
+  }
+  
+  int main() {
+ns::Foo foo;
+foo + 10;
+  }
+  )cpp"}};
   for (auto C : Cases)
 EXPECT_EQ(C.second, apply(C.first)) << C.first;
 }
Index: clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
@@ -155,6 +155,13 @@
 if (!visibleContext(T->getDeclContext())
  ->Equals(TargetDirective->getNominatedNamespace()))
   return;
+// Avoid adding qualifiers before operators, e.g.
+//   using namespace std;
+//   cout << "foo"; // Must not changed to std::cout std:: << "foo"
+// FIXME: User-defined literals are not handled
+if (T->isInIdentifierNamespace(
+Decl::IdentifierNamespace::IDNS_NonMemberOperator))
+  return;
   }
   SourceLocation Loc = Ref.NameLoc;
   if (Loc.isMacroID()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137494: [Clangd] Fix the code action `RemoveUsingNamespace`

2022-11-05 Thread v1nh1shungry via Phabricator via cfe-commits
v1nh1shungry added a comment.

@tom-anders Thank you for reviewing!

I tried adding a test but I don't know how to run the tests.

And I just found that operators declared in a class context are already handled 
in the existing version, but user-defined literals are not, so I rewrote the 
comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137494

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


[PATCH] D137494: [Clangd] Fix the code action `RemoveUsingNamespace`

2022-11-05 Thread v1nh1shungry via Phabricator via cfe-commits
v1nh1shungry updated this revision to Diff 473477.
v1nh1shungry added a comment.

Correct the test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137494

Files:
  clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
  clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp


Index: clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
@@ -226,7 +226,30 @@
   int main() {
 std::vector V;
   }
-)cpp"}};
+)cpp"},
+  {// Does not qualify operators declared in a non-class context
+   R"cpp(
+  namespace ns {
+  struct Foo {};
+  void operator+(const Foo &, int) {}
+  }
+  using namespace n^s;
+  int main() {
+Foo foo;
+foo + 10;
+  }
+  )cpp",
+   R"cpp(
+  namespace ns {
+  struct Foo {};
+  void operator+(const Foo &, int) {}
+  }
+
+  int main() {
+ns::Foo foo;
+foo + 10;
+  }
+  )cpp"}};
   for (auto C : Cases)
 EXPECT_EQ(C.second, apply(C.first)) << C.first;
 }
Index: clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
@@ -155,6 +155,13 @@
 if (!visibleContext(T->getDeclContext())
  ->Equals(TargetDirective->getNominatedNamespace()))
   return;
+// Avoid adding qualifiers before operators, e.g.
+//   using namespace std;
+//   cout << "foo"; // Must not changed to std::cout std:: << "foo"
+// FIXME: User-defined literals are not handled
+if (T->isInIdentifierNamespace(
+Decl::IdentifierNamespace::IDNS_NonMemberOperator))
+  return;
   }
   SourceLocation Loc = Ref.NameLoc;
   if (Loc.isMacroID()) {


Index: clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
@@ -226,7 +226,30 @@
   int main() {
 std::vector V;
   }
-)cpp"}};
+)cpp"},
+  {// Does not qualify operators declared in a non-class context
+   R"cpp(
+  namespace ns {
+  struct Foo {};
+  void operator+(const Foo &, int) {}
+  }
+  using namespace n^s;
+  int main() {
+Foo foo;
+foo + 10;
+  }
+  )cpp",
+   R"cpp(
+  namespace ns {
+  struct Foo {};
+  void operator+(const Foo &, int) {}
+  }
+
+  int main() {
+ns::Foo foo;
+foo + 10;
+  }
+  )cpp"}};
   for (auto C : Cases)
 EXPECT_EQ(C.second, apply(C.first)) << C.first;
 }
Index: clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
@@ -155,6 +155,13 @@
 if (!visibleContext(T->getDeclContext())
  ->Equals(TargetDirective->getNominatedNamespace()))
   return;
+// Avoid adding qualifiers before operators, e.g.
+//   using namespace std;
+//   cout << "foo"; // Must not changed to std::cout std:: << "foo"
+// FIXME: User-defined literals are not handled
+if (T->isInIdentifierNamespace(
+Decl::IdentifierNamespace::IDNS_NonMemberOperator))
+  return;
   }
   SourceLocation Loc = Ref.NameLoc;
   if (Loc.isMacroID()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137494: [Clangd] Fix the code action `RemoveUsingNamespace`

2022-11-05 Thread v1nh1shungry via Phabricator via cfe-commits
v1nh1shungry updated this revision to Diff 473475.
v1nh1shungry added a comment.

Add a test and rewrite the comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137494

Files:
  clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
  clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp


Index: clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
@@ -226,7 +226,30 @@
   int main() {
 std::vector V;
   }
-)cpp"}};
+)cpp"},
+  {// Does not qualify operators
+   R"cpp(
+  namespace ns {
+  struct Foo {};
+  void operator+(const Foo &, int) {}
+  }
+  using namespace ns;
+  int main() {
+Foo foo;
+foo + 10;
+  }
+  )cpp",
+   R"cpp(
+  namespace ns {
+  struct Foo {};
+  void operator+(const Foo &, int) {}
+  }
+
+  int main() {
+ns::Foo foo;
+foo + 10;
+  }
+  )cpp"}};
   for (auto C : Cases)
 EXPECT_EQ(C.second, apply(C.first)) << C.first;
 }
Index: clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
@@ -155,6 +155,13 @@
 if (!visibleContext(T->getDeclContext())
  ->Equals(TargetDirective->getNominatedNamespace()))
   return;
+// Avoid adding qualifiers before operators, e.g.
+//   using namespace std;
+//   cout << "foo"; // Must not changed to std::cout std:: << "foo"
+// FIXME: User-defined literals are not handled
+if (T->isInIdentifierNamespace(
+Decl::IdentifierNamespace::IDNS_NonMemberOperator))
+  return;
   }
   SourceLocation Loc = Ref.NameLoc;
   if (Loc.isMacroID()) {


Index: clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp
@@ -226,7 +226,30 @@
   int main() {
 std::vector V;
   }
-)cpp"}};
+)cpp"},
+  {// Does not qualify operators
+   R"cpp(
+  namespace ns {
+  struct Foo {};
+  void operator+(const Foo &, int) {}
+  }
+  using namespace ns;
+  int main() {
+Foo foo;
+foo + 10;
+  }
+  )cpp",
+   R"cpp(
+  namespace ns {
+  struct Foo {};
+  void operator+(const Foo &, int) {}
+  }
+
+  int main() {
+ns::Foo foo;
+foo + 10;
+  }
+  )cpp"}};
   for (auto C : Cases)
 EXPECT_EQ(C.second, apply(C.first)) << C.first;
 }
Index: clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
@@ -155,6 +155,13 @@
 if (!visibleContext(T->getDeclContext())
  ->Equals(TargetDirective->getNominatedNamespace()))
   return;
+// Avoid adding qualifiers before operators, e.g.
+//   using namespace std;
+//   cout << "foo"; // Must not changed to std::cout std:: << "foo"
+// FIXME: User-defined literals are not handled
+if (T->isInIdentifierNamespace(
+Decl::IdentifierNamespace::IDNS_NonMemberOperator))
+  return;
   }
   SourceLocation Loc = Ref.NameLoc;
   if (Loc.isMacroID()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137263: add boundary check for ASTUnresolvedSet::erase

2022-11-05 Thread zhouyizhou via Phabricator via cfe-commits
zhouyizhou added a comment.

In D137263#3909722 , @MaskRay wrote:

> I find that if I comment out ` 
> cast(Shadow->getDeclContext())->removeConversion(Shadow);` in 
> `Sema::HideUsingShadowDecl`, no test fails... So we have a missing coverage 
> issue.

Hi 
I found a counterexample for above case, excited! !  and I could not hesitate 
to report you that good news ;-)

  struct A
  {
  struct Nested {};
  operator Nested*() {return 0;};
  };
  
  struct B : A
  {
  using A::operator typename A::Nested*;
  operator typename A::Nested *() {
  struct A * thi = this;
  return *thi;
  };
  };
  
  int
  main()
  {
  
  struct B b;
  auto s = *b;
  
  }

After  comment out ` 
cast(Shadow->getDeclContext())->removeConversion(Shadow);`
clang++ report following:

  using.C:21:11: error: use of overloaded operator '*' is ambiguous (operand 
type 'struct B')
  auto s = *b;
   ^~
  using.C:21:11: note: because of ambiguity in conversion of 'struct B' to 
'A::Nested *'
  using.C:4:9: note: candidate function
  operator Nested*() {return 0;};
  ^
  using.C:10:9: note: candidate function
  operator typename A::Nested *() {
  ^
  using.C:21:11: note: built-in candidate operator*(struct A::Nested *)
  auto s = *b;
   ^
  using.C:21:11: note: built-in candidate operator*(const struct A::Nested *)
  1 error generated.

So I think we could add above to the test case.
What's your opinion?

I learned a lot under your guidance!

Thank you both
Sincerely 
Zhouyi


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

https://reviews.llvm.org/D137263

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


[PATCH] D137181: [clang-format] Don't use 'PPIndentWidth' inside multi-line macros

2022-11-05 Thread Noah Goldstein via Phabricator via cfe-commits
goldstein.w.n added a comment.

In D137181#3904383 , @owenpan wrote:

> With `ColumnLimit: 16` and `IndentPPDirectives: BeforeHash`, the format 
> should be:
>
>   #ifdef foo
>#define bar() \
>if (A) {  \
>B();  \
>} \
>C();
>   #endif
>
> With `IndentPPDirectives: AfterHash`, it should look like:
>
>   #ifdef foo
>   # define bar() \
>if (A) {  \
>B();  \
>} \
>C();
>   #endif

Doesn't that add an arbitrary +1 to the begining of the indentation?
Shouldn't it be:

  // IndentPPDirectives: AfterHash
  #ifdef foo
  # define bar() \\
if (A) { \\
B(); \\
}\\
C();
  #endif
  
  // IndentPPDirectives: BeforeHash
  #ifdef foo
   #define bar() \\
if (A) { \\
B(); \\
}\\
C();
  #endif
  
  // IndentPPDirectives: NoneHash
  #ifdef foo
  #define bar() \\
   if (A) { \\
   B(); \\
   }\\
   C();
  #endif


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137181

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


[clang] d1829c3 - Add support of the next Ubuntu (Ubuntu 23.04 - Lunar Lobster)

2022-11-05 Thread Sylvestre Ledru via cfe-commits

Author: Sylvestre Ledru
Date: 2022-11-05T22:35:54+01:00
New Revision: d1829c308da9c2adc46640a960c105b573db6555

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

LOG: Add support of the next Ubuntu (Ubuntu 23.04 - Lunar Lobster)

Added: 


Modified: 
clang/include/clang/Driver/Distro.h
clang/lib/Driver/Distro.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Distro.h 
b/clang/include/clang/Driver/Distro.h
index 01d66b30b0386..1aaf93ddb7c43 100644
--- a/clang/include/clang/Driver/Distro.h
+++ b/clang/include/clang/Driver/Distro.h
@@ -76,6 +76,7 @@ class Distro {
 UbuntuImpish,
 UbuntuJammy,
 UbuntuKinetic,
+UbuntuLunar,
 UnknownDistro
   };
 
@@ -127,7 +128,7 @@ class Distro {
   }
 
   bool IsUbuntu() const {
-return DistroVal >= UbuntuHardy && DistroVal <= UbuntuKinetic;
+return DistroVal >= UbuntuHardy && DistroVal <= UbuntuLunar;
   }
 
   bool IsAlpineLinux() const { return DistroVal == AlpineLinux; }

diff  --git a/clang/lib/Driver/Distro.cpp b/clang/lib/Driver/Distro.cpp
index 1898667279cc3..87a0c5a585115 100644
--- a/clang/lib/Driver/Distro.cpp
+++ b/clang/lib/Driver/Distro.cpp
@@ -92,6 +92,7 @@ static Distro::DistroType 
DetectLsbRelease(llvm::vfs::FileSystem ) {
 .Case("impish", Distro::UbuntuImpish)
 .Case("jammy", Distro::UbuntuJammy)
 .Case("kinetic", Distro::UbuntuKinetic)
+.Case("lunar", Distro::UbuntuLunar)
 .Default(Distro::UnknownDistro);
   return Version;
 }



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


[PATCH] D137488: [clang][Interp] Array initialization via string literal

2022-11-05 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:1138
+// FIXME: There is a certain code duplication between here
+//   and Porgram::createGlobalString().
+const size_t CharWidth = SL->getCharByteWidth();

tschuett wrote:
> tschuett wrote:
> > Program
> Probably I misunderstood something. It says:
> ```
> Porgram::createGlobalString
> ```
> I would expected it to start with **Program** and not **Porgram**.
> 
Yep, I fixed it locally.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137488

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


[PATCH] D137267: [clang][Headers] Only define FLT_EVAL_METHOD for C99 and later

2022-11-05 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.
This revision is now accepted and ready to land.

Thanks! C99 and C++11 look good and the new behavior matches GCC.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137267

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


[PATCH] D137268: [clang][Headers] Do not define varargs macros for __need___va_list

2022-11-05 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay requested changes to this revision.
MaskRay added a comment.
This revision now requires changes to proceed.

LGTM, but changes are needed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137268

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


[PATCH] D136846: [Driver] Add -fsample-profile-use-profi

2022-11-05 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.
This revision is now accepted and ready to land.

In D136846#3890699 , @wenlei wrote:

> Did you see measurable perf boost with profi on autofdo? Or what motivated 
> you to turn on profi? In most cases, profi helps when csspgo is used (instead 
> of traditional autofdo).

LG in my view, but @wenlei may have something to add.




Comment at: clang/test/Driver/pgo-sample-use-profi.c:2
+/// Test if profi flat is enabled in frontend as user-facing feature.
+// RUN: %clang -c -fsample-profile-use-profi 
-fprofile-sample-use=%S/../CodeGen/Inputs/pgo-sample.prof -### %s 2>&1 | 
FileCheck %s
+

Such a cross-directory test file reference is generally not acceptable. Use a 
dummy file `-fprofile-sample-use=/dev/null`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136846

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


[PATCH] D137329: [flang] Add -f[no-]associative-math and -mreassociate

2022-11-05 Thread Kiran Chandramohan via Phabricator via cfe-commits
kiranchandramohan added a comment.

In D137329#3909943 , @awarzynski 
wrote:

> In D137329#3909082 , @clementval 
> wrote:
>
>> Wouldn't it be good to have a RFC for all these options and what they will 
>> do in Flang instead of just adding them all? Or did I miss the RFC?
>
> +1

Fast Math attributes supported in LLVM IR are documented in 
https://llvm.org/docs/LangRef.html#fast-math-flags. This set of patches 
(details below) provides a way to set or unset each of these attributes.

While making policy decisions about these flags, like for ffp-contract, we have 
created an RFC 
(https://discourse.llvm.org/t/rfc-ffp-contract-default-value/66301).  When 
adding umbrella flags like 
-ffast-math/-Ofast/-ffp-model/-funsafe-math-optimizations, we will submit RFCs.

Patch : Flag Name : LLVM IR Attribute
https://reviews.llvm.org/D137325 : f[no-]honor-nans: nnan
https://reviews.llvm.org/D137072 : f[no-]honor-infinities  : ninf
https://reviews.llvm.org/D137328 : f[no-]signed-zeros  : nsz
https://reviews.llvm.org/D137330 : f[no-]reciprocal-math : arcp
https://reviews.llvm.org/D136080 : ffp-contract option : contract
https://reviews.llvm.org/D137326 : f[no-]approx-func: afn
https://reviews.llvm.org/D137329 : f[no-]associative-math: reassoc


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137329

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


[PATCH] D137494: [Clangd] Fix the code action `RemoveUsingNamespace`

2022-11-05 Thread Tom Praschan via Phabricator via cfe-commits
tom-anders requested changes to this revision.
tom-anders added a comment.
This revision now requires changes to proceed.

Did a quick test on my machine, seems to work! Can you add a regression test to 
clang-tools-extra/clangd/unittests/tweaks/RemoveUsingNamespaceTests.cpp though?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137494

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


[PATCH] D137488: [clang][Interp] Array initialization via string literal

2022-11-05 Thread Thorsten via Phabricator via cfe-commits
tschuett added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:1138
+// FIXME: There is a certain code duplication between here
+//   and Porgram::createGlobalString().
+const size_t CharWidth = SL->getCharByteWidth();

tschuett wrote:
> Program
Probably I misunderstood something. It says:
```
Porgram::createGlobalString
```
I would expected it to start with **Program** and not **Porgram**.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137488

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


[PATCH] D137487: [clang][Interp] Start implementing builtin functions

2022-11-05 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 473443.

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

https://reviews.llvm.org/D137487

Files:
  clang/lib/AST/CMakeLists.txt
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/Function.h
  clang/lib/AST/Interp/Interp.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/InterpBuiltin.cpp
  clang/test/AST/Interp/builtins.cpp

Index: clang/test/AST/Interp/builtins.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/builtins.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter %s -verify
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -verify=ref %s -Wno-constant-evaluated
+// RUN: %clang_cc1 -verify=ref %s -Wno-constant-evaluated %s -S -emit-llvm -o - | FileCheck %s
+
+// expected-no-diagnostics
+// ref-no-diagnostics
+
+using size_t = decltype(sizeof(int));
+
+namespace std {
+inline constexpr bool is_constant_evaluated() noexcept {
+  return __builtin_is_constant_evaluated();
+}
+} // namespace std
+
+constexpr bool b = std::is_constant_evaluated();
+static_assert(b, "");
+static_assert(std::is_constant_evaluated() , "");
+
+
+bool is_this_constant() {
+  return __builtin_is_constant_evaluated(); // CHECK: ret i1 false
+}
Index: clang/lib/AST/Interp/InterpBuiltin.cpp
===
--- /dev/null
+++ clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -0,0 +1,51 @@
+//===--- InterpBuiltin.cpp - Interpreter for the constexpr VM ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#include "Boolean.h"
+#include "Interp.h"
+#include "PrimType.h"
+#include "clang/Basic/Builtins.h"
+
+namespace clang {
+namespace interp {
+
+/// This is a slightly simplified version of the Ret() we have in Interp.cpp
+/// If they end up diverging in the future, we should get rid of the code
+/// duplication.
+template ::T>
+static bool Ret(InterpState , CodePtr ) {
+  S.CallStackDepth--;
+  const T  = S.Stk.pop();
+
+  assert(S.Current->getFrameOffset() == S.Stk.size() && "Invalid frame");
+  if (!S.checkingPotentialConstantExpression())
+S.Current->popArgs();
+
+  InterpFrame *Caller = S.Current->Caller;
+  assert(Caller);
+
+  PC = S.Current->getRetPC();
+  delete S.Current;
+  S.Current = Caller;
+  S.Stk.push(Ret);
+
+  return true;
+}
+
+bool InterpretBuiltin(InterpState , CodePtr PC, unsigned BuiltinID) {
+  switch (BuiltinID) {
+  case Builtin::BI__builtin_is_constant_evaluated:
+S.Stk.push(Boolean::from(S.inConstantContext()));
+Ret(S, PC);
+return true;
+  }
+
+  return false;
+}
+
+} // namespace interp
+} // namespace clang
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -110,6 +110,8 @@
 /// Interpreter entry point.
 bool Interpret(InterpState , APValue );
 
+bool InterpretBuiltin(InterpState , CodePtr PC, unsigned BuiltinID);
+
 enum class ArithOp { Add, Sub };
 
 //===--===//
@@ -1349,21 +1351,29 @@
   InterpFrame *FrameBefore = S.Current;
   S.Current = NewFrame.get();
 
-  APValue CallResult;
-  // Note that we cannot assert(CallResult.hasValue()) here since
-  // Ret() above only sets the APValue if the curent frame doesn't
-  // have a caller set.
-  if (Interpret(S, CallResult)) {
-NewFrame.release(); // Frame was delete'd already.
-assert(S.Current == FrameBefore);
-
-// For constructors, check that all fields have been initialized.
-if (Func->isConstructor()) {
-  if (!CheckCtorCall(S, PC, ThisPtr))
-return false;
+  // Evaluate builtin functions directly.
+  if (unsigned BID = Func->getBuiltinID()) {
+if (InterpretBuiltin(S, PC, BID)) {
+  NewFrame.release();
+  return true;
 }
+  } else {
+APValue CallResult;
+// Note that we cannot assert(CallResult.hasValue()) here since
+// Ret() above only sets the APValue if the curent frame doesn't
+// have a caller set.
+if (Interpret(S, CallResult)) {
+  NewFrame.release(); // Frame was delete'd already.
+  assert(S.Current == FrameBefore);
+
+  // For constructors, check that all fields have been initialized.
+  if (Func->isConstructor()) {
+if (!CheckCtorCall(S, PC, ThisPtr))
+  return false;
+  }
 
-return true;
+  return true;
+}
   }
 
   // Interpreting the function failed somehow. Reset to
Index: clang/lib/AST/Interp/Interp.cpp
===
--- 

[PATCH] D137494: [Clangd] Fix the code action `RemoveUsingNamespace`

2022-11-05 Thread v1nh1shungry via Phabricator via cfe-commits
v1nh1shungry created this revision.
v1nh1shungry added reviewers: thesamesam, tom-anders, junaire.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
v1nh1shungry requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Avoid adding qualifiers before C++ operators declared in a non-class context


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137494

Files:
  clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp


Index: clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
@@ -155,6 +155,13 @@
 if (!visibleContext(T->getDeclContext())
  ->Equals(TargetDirective->getNominatedNamespace()))
   return;
+// Avoid adding qualifiers before operators, e.g.
+//   using namespace std;
+//   cout << "foo"; // Must not changed to std::cout std:: << "foo"
+// FIXME: Operators declared in a class context are not handled
+if (T->isInIdentifierNamespace(
+Decl::IdentifierNamespace::IDNS_NonMemberOperator))
+  return;
   }
   SourceLocation Loc = Ref.NameLoc;
   if (Loc.isMacroID()) {


Index: clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
@@ -155,6 +155,13 @@
 if (!visibleContext(T->getDeclContext())
  ->Equals(TargetDirective->getNominatedNamespace()))
   return;
+// Avoid adding qualifiers before operators, e.g.
+//   using namespace std;
+//   cout << "foo"; // Must not changed to std::cout std:: << "foo"
+// FIXME: Operators declared in a class context are not handled
+if (T->isInIdentifierNamespace(
+Decl::IdentifierNamespace::IDNS_NonMemberOperator))
+  return;
   }
   SourceLocation Loc = Ref.NameLoc;
   if (Loc.isMacroID()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137302: [clang-tidy] Add modernize-type-traits check

2022-11-05 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.h:17
+namespace tidy {
+namespace modernize {
+

tschuett wrote:
> Why do you refuse to use nested namespaces in `modernize` ?
I think this is done for legacy reasons. This should be done for all checks and 
`add_new_check.py`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137302

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


[PATCH] D137302: [clang-tidy] Add modernize-type-traits check

2022-11-05 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.h:17
+namespace tidy {
+namespace modernize {
+

tschuett wrote:
> Why do you refuse to use nested namespaces in `modernize` ?
Because the add_new_check script hasn't been updated since we went to c++17


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137302

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


[PATCH] D137302: [clang-tidy] Add modernize-type-traits check

2022-11-05 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 473439.
njames93 added a comment.

Fix crash when running over llvm


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137302

Files:
  clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
  clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp
  clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/modernize/type-traits.rst
  clang-tools-extra/test/clang-tidy/checkers/modernize/type-traits.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/type-traits.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/type-traits.cpp
@@ -0,0 +1,62 @@
+// RUN: %check_clang_tidy -std=c++14 %s modernize-type-traits %t
+// RUN: %check_clang_tidy -std=c++17 %s modernize-type-traits %t -check-suffixes=',CXX17'
+
+namespace std{
+  template 
+  struct is_const {
+static constexpr bool value = true;
+  };
+
+  template 
+  struct is_same {
+static constexpr bool value = true;
+  };
+
+  template
+  struct enable_if {
+using type = T;
+  };
+} // namespace std
+
+bool NoTemplate = std::is_const::value;
+// CHECK-MESSAGES-CXX17: :[[@LINE-1]]:19: warning: use c++17 style variable templates
+// CHeCK-FIXES-CXX17: bool NoTemplate = std::is_const_v
+
+template
+constexpr bool InTemplate = std::is_const::value;
+// CHECK-MESSAGES-CXX17: :[[@LINE-1]]:29: warning: use c++17 style variable templates
+// CHECK-FIXES-CXX17: constexpr bool InTemplate = std::is_const_v;
+
+template
+constexpr bool Template2Params = std::is_same::value;
+// CHECK-MESSAGES-CXX17: :[[@LINE-1]]:34: warning: use c++17 style variable templates
+// CHECK-FIXES-CXX17: constexpr bool Template2Params = std::is_same_v;
+
+template
+typename std::enable_if::type inTemplate();
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use c++14 style type templates
+// CHECK-FIXES: std::enable_if_tinTemplate();
+
+typename std::enable_if::type noTemplate();
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use c++14 style type templates
+// CHECK-FIXES: std::enable_if_tnoTemplate();
+
+std::enable_if::type noTemplateOrTypename();
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use c++14 style type templates
+// CHECK-FIXES: std::enable_if_tnoTemplateOrTypename();
+
+using UsingNoTypename = std::enable_if::type;
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: use c++14 style type templates
+// CHECK-FIXES: using UsingNoTypename = std::enable_if_t;
+
+// For macros we don't want any fixes to be emitted
+
+#define VALUE_MACRO std::is_same::value
+bool MacroValue = VALUE_MACRO;
+// CHECK-MESSAGES-CXX17: :[[@LINE-1]]:19: warning: use c++17 style variable templates
+// CHECK-FIXES-CXX17: #define VALUE_MACRO std::is_same::value
+
+#define TYPE_MACRO typename std::enable_if::type
+using MacroType = TYPE_MACRO;
+// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use c++14 style type templates
+// CHECK-FIXES: #define TYPE_MACRO typename std::enable_if::type
Index: clang-tools-extra/docs/clang-tidy/checks/modernize/type-traits.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/modernize/type-traits.rst
@@ -0,0 +1,25 @@
+.. title:: clang-tidy - modernize-type-traits
+
+modernize-type-traits
+=
+
+Converts standard library type traits of the form ``traits<...>::type`` and
+``traits<...>::value`` into ``traits_t<...>`` and ``traits_v<...>`` respectively.
+
+For example:
+
+.. code-block:: c++
+
+  std::is_integral::value
+  std::is_same::value
+  typename std::add_const::type
+  std::make_signed::type
+
+Would be converted into:
+
+.. code-block:: c++
+
+  std::is_integral_v
+  std::is_same_v
+  std::add_const_t
+  std::make_signed_t
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -276,6 +276,7 @@
`modernize-replace-random-shuffle `_, "Yes"
`modernize-return-braced-init-list `_, "Yes"
`modernize-shrink-to-fit `_, "Yes"
+   `modernize-type-traits `_, "Yes"
`modernize-unary-static-assert `_, "Yes"
`modernize-use-auto `_, "Yes"
`modernize-use-bool-literals `_, "Yes"
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -115,6 +115,12 @@
 
   Warns when using ``do-while`` loops.
 
+- New :doc:`modernize-type-traits
+  ` check.
+
+  Converts standard library type traits of the form ``traits<...>::type`` and
+  

[PATCH] D136283: [clang-tools-extra] [clangd] Split huge generated CompletionModel.cpp into smaller files

2022-11-05 Thread Nico Weber via Phabricator via cfe-commits
thakis added inline comments.



Comment at: clang-tools-extra/clangd/quality/CompletionModel.cmake:25
+
+  file(GLOB cpp_files "${output_dir}/${filename}*.cpp")
+

Can we list them? We try not to use globs in cmakelists.txt files.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136283

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


[PATCH] D137491: [clang][NFC] Use c++17 style variable type traits

2022-11-05 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added reviewers: aaron.ballman, rsmith.
Herald added subscribers: steakhal, martong.
Herald added a reviewer: shafik.
Herald added a reviewer: NoQ.
Herald added a project: All.
njames93 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This was done as a test for D137302  and it 
makes sense to push these changes


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137491

Files:
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Comment.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/AST/Interp/Disasm.cpp
  clang/lib/Analysis/CFG.cpp
  clang/lib/Analysis/RetainSummaryManager.cpp
  clang/lib/Basic/SourceLocation.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Lex/MacroArgs.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/lib/Tooling/ASTDiff/ASTDiff.cpp
  clang/unittests/Lex/HeaderMapTest.cpp
  clang/unittests/Tooling/ASTSelectionTest.cpp
  clang/unittests/Tooling/Syntax/TreeTest.cpp

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -151,9 +151,9 @@
   // FIXME: mutate and observe no invalidation. Mutations are private for now...
   auto It = Range.begin();
   auto CIt = ConstRange.begin();
-  static_assert(std::is_same::value,
+  static_assert(std::is_same_v,
 "mutable range");
-  static_assert(std::is_same::value,
+  static_assert(std::is_same_v,
 "const range");
 
   for (unsigned I = 0; I < 3; ++I) {
Index: clang/unittests/Tooling/ASTSelectionTest.cpp
===
--- clang/unittests/Tooling/ASTSelectionTest.cpp
+++ clang/unittests/Tooling/ASTSelectionTest.cpp
@@ -104,7 +104,7 @@
 const SelectedASTNode (
 const SelectedASTNode , SourceSelectionKind SelectionKind,
 unsigned NumChildren = 0,
-std::enable_if_t::value, T> *StmtOverloadChecker =
+std::enable_if_t, T> *StmtOverloadChecker =
 nullptr) {
   checkNodeImpl(isa(StmtNode.Node.get()), StmtNode, SelectionKind,
 NumChildren);
@@ -115,7 +115,7 @@
 const SelectedASTNode (
 const SelectedASTNode , SourceSelectionKind SelectionKind,
 unsigned NumChildren = 0, StringRef Name = "",
-std::enable_if_t::value, T> *DeclOverloadChecker =
+std::enable_if_t, T> *DeclOverloadChecker =
 nullptr) {
   checkNodeImpl(isa(DeclNode.Node.get()), DeclNode, SelectionKind,
 NumChildren);
Index: clang/unittests/Lex/HeaderMapTest.cpp
===
--- clang/unittests/Lex/HeaderMapTest.cpp
+++ clang/unittests/Lex/HeaderMapTest.cpp
@@ -115,8 +115,7 @@
 TEST(HeaderMapTest, lookupFilenameTruncatedSuffix) {
   typedef HMapFileMock<2, 64 - sizeof(HMapHeader) - 2 * sizeof(HMapBucket)>
   FileTy;
-  static_assert(std::is_standard_layout::value,
-"Expected standard layout");
+  static_assert(std::is_standard_layout_v, "Expected standard layout");
   static_assert(sizeof(FileTy) == 64, "check the math");
   PaddedFile P;
   auto  = P.File;
@@ -151,8 +150,7 @@
 TEST(HeaderMapTest, lookupFilenameTruncatedPrefix) {
   typedef HMapFileMock<2, 64 - sizeof(HMapHeader) - 2 * sizeof(HMapBucket)>
   FileTy;
-  static_assert(std::is_standard_layout::value,
-"Expected standard layout");
+  static_assert(std::is_standard_layout_v, "Expected standard layout");
   static_assert(sizeof(FileTy) == 64, "check the math");
   PaddedFile P;
   auto  = P.File;
Index: clang/lib/Tooling/ASTDiff/ASTDiff.cpp
===
--- clang/lib/Tooling/ASTDiff/ASTDiff.cpp
+++ clang/lib/Tooling/ASTDiff/ASTDiff.cpp
@@ -117,12 +117,12 @@
   Impl(SyntaxTree *Parent, Stmt *N, ASTContext );
   template 
   Impl(SyntaxTree *Parent,
-   std::enable_if_t::value, T> *Node,
+   std::enable_if_t, T> *Node,
ASTContext )
   : Impl(Parent, dyn_cast(Node), AST) {}
   template 
   Impl(SyntaxTree *Parent,
-   std::enable_if_t::value, T> *Node,
+   std::enable_if_t, T> *Node,
ASTContext )
   : Impl(Parent, dyn_cast(Node), AST) {}
 
Index: clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -912,9 +912,9 @@
 
   // Try to do as much compile time checking as possible.
   // FIXME: check for invocable instead of function?
-  static_assert(std::is_function>::value,
+  static_assert(std::is_function_v>,
 "Printer is not a function!");
-  static_assert(std::is_convertible::value,
+  

[PATCH] D137302: [clang-tidy] Add modernize-type-traits check

2022-11-05 Thread Thorsten via Phabricator via cfe-commits
tschuett added inline comments.



Comment at: clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.h:17
+namespace tidy {
+namespace modernize {
+

Why do you refuse to use nested namespaces in `modernize` ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137302

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


[PATCH] D137302: [clang-tidy] Add modernize-type-traits check

2022-11-05 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 473427.
njames93 added a comment.

Fix various crashes on real world code


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137302

Files:
  clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
  clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp
  clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/modernize/type-traits.rst
  clang-tools-extra/test/clang-tidy/checkers/modernize/type-traits.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/type-traits.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/type-traits.cpp
@@ -0,0 +1,62 @@
+// RUN: %check_clang_tidy -std=c++14 %s modernize-type-traits %t
+// RUN: %check_clang_tidy -std=c++17 %s modernize-type-traits %t -check-suffixes=',CXX17'
+
+namespace std{
+  template 
+  struct is_const {
+static constexpr bool value = true;
+  };
+
+  template 
+  struct is_same {
+static constexpr bool value = true;
+  };
+
+  template
+  struct enable_if {
+using type = T;
+  };
+} // namespace std
+
+bool NoTemplate = std::is_const::value;
+// CHECK-MESSAGES-CXX17: :[[@LINE-1]]:19: warning: use c++17 style variable templates
+// CHeCK-FIXES-CXX17: bool NoTemplate = std::is_const_v
+
+template
+constexpr bool InTemplate = std::is_const::value;
+// CHECK-MESSAGES-CXX17: :[[@LINE-1]]:29: warning: use c++17 style variable templates
+// CHECK-FIXES-CXX17: constexpr bool InTemplate = std::is_const_v;
+
+template
+constexpr bool Template2Params = std::is_same::value;
+// CHECK-MESSAGES-CXX17: :[[@LINE-1]]:34: warning: use c++17 style variable templates
+// CHECK-FIXES-CXX17: constexpr bool Template2Params = std::is_same_v;
+
+template
+typename std::enable_if::type inTemplate();
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use c++14 style type templates
+// CHECK-FIXES: std::enable_if_tinTemplate();
+
+typename std::enable_if::type noTemplate();
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use c++14 style type templates
+// CHECK-FIXES: std::enable_if_tnoTemplate();
+
+std::enable_if::type noTemplateOrTypename();
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use c++14 style type templates
+// CHECK-FIXES: std::enable_if_tnoTemplateOrTypename();
+
+using UsingNoTypename = std::enable_if::type;
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: use c++14 style type templates
+// CHECK-FIXES: using UsingNoTypename = std::enable_if_t;
+
+// For macros we don't want any fixes to be emitted
+
+#define VALUE_MACRO std::is_same::value
+bool MacroValue = VALUE_MACRO;
+// CHECK-MESSAGES-CXX17: :[[@LINE-1]]:19: warning: use c++17 style variable templates
+// CHECK-FIXES-CXX17: #define VALUE_MACRO std::is_same::value
+
+#define TYPE_MACRO typename std::enable_if::type
+using MacroType = TYPE_MACRO;
+// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use c++14 style type templates
+// CHECK-FIXES: #define TYPE_MACRO typename std::enable_if::type
Index: clang-tools-extra/docs/clang-tidy/checks/modernize/type-traits.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/modernize/type-traits.rst
@@ -0,0 +1,25 @@
+.. title:: clang-tidy - modernize-type-traits
+
+modernize-type-traits
+=
+
+Converts standard library type traits of the form ``traits<...>::type`` and
+``traits<...>::value`` into ``traits_t<...>`` and ``traits_v<...>`` respectively.
+
+For example:
+
+.. code-block:: c++
+
+  std::is_integral::value
+  std::is_same::value
+  typename std::add_const::type
+  std::make_signed::type
+
+Would be converted into:
+
+.. code-block:: c++
+
+  std::is_integral_v
+  std::is_same_v
+  std::add_const_t
+  std::make_signed_t
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -276,6 +276,7 @@
`modernize-replace-random-shuffle `_, "Yes"
`modernize-return-braced-init-list `_, "Yes"
`modernize-shrink-to-fit `_, "Yes"
+   `modernize-type-traits `_, "Yes"
`modernize-unary-static-assert `_, "Yes"
`modernize-use-auto `_, "Yes"
`modernize-use-bool-literals `_, "Yes"
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -115,6 +115,12 @@
 
   Warns when using ``do-while`` loops.
 
+- New :doc:`modernize-type-traits
+  ` check.
+
+  Converts standard library type traits of the form ``traits<...>::type`` and
+  

[PATCH] D137487: [clang][Interp] Start implementing builtin functions

2022-11-05 Thread Thorsten via Phabricator via cfe-commits
tschuett added inline comments.



Comment at: clang/lib/AST/Interp/InterpBuiltin.cpp:14
+namespace clang {
+namespace interp {
+

You are allowed to use nested namespaces.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137487

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


[PATCH] D137488: [clang][Interp] Array initialization via string literal

2022-11-05 Thread Thorsten via Phabricator via cfe-commits
tschuett added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:1138
+// FIXME: There is a certain code duplication between here
+//   and Porgram::createGlobalString().
+const size_t CharWidth = SL->getCharByteWidth();

Program


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137488

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


[PATCH] D137488: [clang][Interp] Array initialization via string literal

2022-11-05 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137488

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/literals.cpp


Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -350,6 +350,13 @@
 #endif
 
 #pragma clang diagnostic pop
+
+  constexpr char foo[12] = "abc";
+  static_assert(foo[0] == 'a', "");
+  static_assert(foo[1] == 'b', "");
+  static_assert(foo[2] == 'c', "");
+  static_assert(foo[3] == 0, "");
+  static_assert(foo[11] == 0, "");
 };
 
 #if __cplusplus > 201402L
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1129,6 +1129,46 @@
 return false;
 }
 return true;
+  } else if (const auto *SL = dyn_cast(Initializer)) {
+const ArrayType *AT = SL->getType()->getAsArrayTypeUnsafe();
+const auto *CAT = cast(AT);
+size_t NumElems = CAT->getSize().getZExtValue();
+
+// FIXME: There is a certain code duplication between here
+//   and Porgram::createGlobalString().
+const size_t CharWidth = SL->getCharByteWidth();
+PrimType CharType;
+switch (CharWidth) {
+case 1:
+  CharType = PT_Sint8;
+  break;
+case 2:
+  CharType = PT_Uint16;
+  break;
+case 4:
+  CharType = PT_Uint32;
+  break;
+default:
+  llvm_unreachable("unsupported character width");
+}
+
+unsigned N = SL->getLength();
+for (size_t I = 0; I != NumElems; ++I) {
+  const uint32_t CodePoint = I < N ? SL->getCodeUnit(I) : 0;
+  // TODO(Perf): 0 is implicit; we can just stop iterating at that point.
+  if (CharWidth == 1)
+this->emitConstSint8(CodePoint, SL);
+  else if (CharWidth == 2)
+this->emitConstUint16(CodePoint, SL);
+  else if (CharWidth == 4)
+this->emitConstUint32(CodePoint, SL);
+  else
+return false;
+
+  if (!this->emitInitElem(CharType, I, SL))
+return false;
+}
+return true;
   }
 
   assert(false && "Unknown expression for array initialization");


Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -350,6 +350,13 @@
 #endif
 
 #pragma clang diagnostic pop
+
+  constexpr char foo[12] = "abc";
+  static_assert(foo[0] == 'a', "");
+  static_assert(foo[1] == 'b', "");
+  static_assert(foo[2] == 'c', "");
+  static_assert(foo[3] == 0, "");
+  static_assert(foo[11] == 0, "");
 };
 
 #if __cplusplus > 201402L
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1129,6 +1129,46 @@
 return false;
 }
 return true;
+  } else if (const auto *SL = dyn_cast(Initializer)) {
+const ArrayType *AT = SL->getType()->getAsArrayTypeUnsafe();
+const auto *CAT = cast(AT);
+size_t NumElems = CAT->getSize().getZExtValue();
+
+// FIXME: There is a certain code duplication between here
+//   and Porgram::createGlobalString().
+const size_t CharWidth = SL->getCharByteWidth();
+PrimType CharType;
+switch (CharWidth) {
+case 1:
+  CharType = PT_Sint8;
+  break;
+case 2:
+  CharType = PT_Uint16;
+  break;
+case 4:
+  CharType = PT_Uint32;
+  break;
+default:
+  llvm_unreachable("unsupported character width");
+}
+
+unsigned N = SL->getLength();
+for (size_t I = 0; I != NumElems; ++I) {
+  const uint32_t CodePoint = I < N ? SL->getCodeUnit(I) : 0;
+  // TODO(Perf): 0 is implicit; we can just stop iterating at that point.
+  if (CharWidth == 1)
+this->emitConstSint8(CodePoint, SL);
+  else if (CharWidth == 2)
+this->emitConstUint16(CodePoint, SL);
+  else if (CharWidth == 4)
+this->emitConstUint32(CodePoint, SL);
+  else
+return false;
+
+  if (!this->emitInitElem(CharType, I, SL))
+return false;
+}
+return true;
   }
 
   assert(false && "Unknown expression for array initialization");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D137487: [clang][Interp] Start implementing builtin functions

2022-11-05 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Another try at this.

This time, only implement `__builtin_is_constant_evaluated()`.

Unfortunately I can't just use 
`clang/test/SemaCXX/builtin-is-constant-evaluated.cpp`  because there are some 
other unsupported expressions in there.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137487

Files:
  clang/lib/AST/CMakeLists.txt
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/Function.h
  clang/lib/AST/Interp/Interp.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/InterpBuiltin.cpp
  clang/test/AST/Interp/builtins.cpp

Index: clang/test/AST/Interp/builtins.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/builtins.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter %s -verify
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter %s -S -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -verify=ref %s -Wno-constant-evaluated
+// RUN: %clang_cc1 -verify=ref %s -Wno-constant-evaluated
+// RUN: %clang_cc1 -verify=ref %s -Wno-constant-evaluated -S -emit-llvm -o - | FileCheck %s
+
+// expected-no-diagnostics
+// ref-no-diagnostics
+
+using size_t = decltype(sizeof(int));
+
+namespace std {
+inline constexpr bool is_constant_evaluated() noexcept {
+  return __builtin_is_constant_evaluated();
+}
+} // namespace std
+
+constexpr bool b = std::is_constant_evaluated();
+static_assert(b, "");
+static_assert(std::is_constant_evaluated() , "");
+
+
+bool is_this_constant() {
+  return __builtin_is_constant_evaluated(); // CHECK: ret i1 false
+}
Index: clang/lib/AST/Interp/InterpBuiltin.cpp
===
--- /dev/null
+++ clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -0,0 +1,51 @@
+//===--- InterpBuiltin.cpp - Interpreter for the constexpr VM ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#include "Boolean.h"
+#include "Interp.h"
+#include "PrimType.h"
+#include "clang/Basic/Builtins.h"
+
+namespace clang {
+namespace interp {
+
+/// This is a slightly simplified version of the Ret() we have in Interp.cpp
+/// If they end up diverging in the future, we should get rid of the code
+/// duplication.
+template ::T>
+static bool Ret(InterpState , CodePtr ) {
+  S.CallStackDepth--;
+  const T  = S.Stk.pop();
+
+  assert(S.Current->getFrameOffset() == S.Stk.size() && "Invalid frame");
+  if (!S.checkingPotentialConstantExpression())
+S.Current->popArgs();
+
+  InterpFrame *Caller = S.Current->Caller;
+  assert(Caller);
+
+  PC = S.Current->getRetPC();
+  delete S.Current;
+  S.Current = Caller;
+  S.Stk.push(Ret);
+
+  return true;
+}
+
+bool InterpretBuiltin(InterpState , CodePtr PC, unsigned BuiltinID) {
+  switch (BuiltinID) {
+  case Builtin::BI__builtin_is_constant_evaluated:
+S.Stk.push(Boolean::from(S.inConstantContext()));
+Ret(S, PC);
+return true;
+  }
+
+  return false;
+}
+
+} // namespace interp
+} // namespace clang
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -110,6 +110,8 @@
 /// Interpreter entry point.
 bool Interpret(InterpState , APValue );
 
+bool InterpretBuiltin(InterpState , CodePtr PC, unsigned BuiltinID);
+
 enum class ArithOp { Add, Sub };
 
 //===--===//
@@ -1349,21 +1351,29 @@
   InterpFrame *FrameBefore = S.Current;
   S.Current = NewFrame.get();
 
-  APValue CallResult;
-  // Note that we cannot assert(CallResult.hasValue()) here since
-  // Ret() above only sets the APValue if the curent frame doesn't
-  // have a caller set.
-  if (Interpret(S, CallResult)) {
-NewFrame.release(); // Frame was delete'd already.
-assert(S.Current == FrameBefore);
-
-// For constructors, check that all fields have been initialized.
-if (Func->isConstructor()) {
-  if (!CheckCtorCall(S, PC, ThisPtr))
-return false;
+  // Evaluate builtin functions directly.
+  if (unsigned BID = Func->getBuiltinID()) {
+if (InterpretBuiltin(S, PC, BID)) {
+  NewFrame.release();
+  return true;
 }
+  } else {
+APValue CallResult;
+// Note that we cannot assert(CallResult.hasValue()) here since
+// Ret() above only sets the APValue if the curent frame doesn't
+// have a caller set.
+if (Interpret(S, CallResult)) {
+  NewFrame.release(); // Frame was delete'd 

[PATCH] D137486: [clang-format] Correctly annotate function names before attributes

2022-11-05 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel added a comment.

Are both isCpp11AttributeSpecifier and isCppAttribute required?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137486

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


[PATCH] D137486: [clang-format] Correctly annotate function names before attributes

2022-11-05 Thread Owen Pan via Phabricator via cfe-commits
owenpan created this revision.
owenpan added reviewers: MyDeveloperDay, HazardyKnusperkeks, rymiel.
owenpan added a project: clang-format.
Herald added a project: All.
owenpan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixes https://github.com/llvm/llvm-project/issues/58827.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137486

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

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1035,6 +1035,16 @@
   EXPECT_TOKEN(Tokens[8], tok::r_paren, TT_Unknown);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandsFunctionDeclarationNames) {
+  auto Tokens = annotate("void f [[noreturn]] ();");
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::identifier, TT_FunctionDeclarationName);
+
+  Tokens = annotate("void f [[noreturn]] () {}");
+  ASSERT_EQ(Tokens.size(), 12u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::identifier, TT_FunctionDeclarationName);
+}
+
 TEST_F(TokenAnnotatorTest, UnderstandsVerilogOperators) {
   auto Annotate = [this](llvm::StringRef Code) {
 return annotate(Code, getLLVMStyle(FormatStyle::LK_Verilog));
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -71,6 +71,38 @@
  tok::kw_constexpr, tok::kw_catch);
 }
 
+/// Returns \c true if the token starts a C++ attribute, \c false otherwise.
+static bool isCppAttribute(bool IsCpp, const FormatToken ) {
+  if (!IsCpp || !Tok.startsSequence(tok::l_square, tok::l_square))
+return false;
+  // The first square bracket is part of an ObjC array literal
+  if (Tok.Previous && Tok.Previous->is(tok::at))
+return false;
+  const FormatToken *AttrTok = Tok.Next->Next;
+  if (!AttrTok)
+return false;
+  // C++17 '[[using ns: foo, bar(baz, blech)]]'
+  // We assume nobody will name an ObjC variable 'using'.
+  if (AttrTok->startsSequence(tok::kw_using, tok::identifier, tok::colon))
+return true;
+  if (AttrTok->isNot(tok::identifier))
+return false;
+  while (AttrTok && !AttrTok->startsSequence(tok::r_square, tok::r_square)) {
+// ObjC message send. We assume nobody will use : in a C++11 attribute
+// specifier parameter, although this is technically valid:
+// [[foo(:)]].
+if (AttrTok->is(tok::colon) ||
+AttrTok->startsSequence(tok::identifier, tok::identifier) ||
+AttrTok->startsSequence(tok::r_paren, tok::identifier)) {
+  return false;
+}
+if (AttrTok->is(tok::ellipsis))
+  return true;
+AttrTok = AttrTok->Next;
+  }
+  return AttrTok && AttrTok->startsSequence(tok::r_square, tok::r_square);
+}
+
 /// A parser that gathers additional information about tokens.
 ///
 /// The \c TokenAnnotator tries to match parenthesis and square brakets and
@@ -537,34 +569,7 @@
   }
 
   bool isCpp11AttributeSpecifier(const FormatToken ) {
-if (!Style.isCpp() || !Tok.startsSequence(tok::l_square, tok::l_square))
-  return false;
-// The first square bracket is part of an ObjC array literal
-if (Tok.Previous && Tok.Previous->is(tok::at))
-  return false;
-const FormatToken *AttrTok = Tok.Next->Next;
-if (!AttrTok)
-  return false;
-// C++17 '[[using ns: foo, bar(baz, blech)]]'
-// We assume nobody will name an ObjC variable 'using'.
-if (AttrTok->startsSequence(tok::kw_using, tok::identifier, tok::colon))
-  return true;
-if (AttrTok->isNot(tok::identifier))
-  return false;
-while (AttrTok && !AttrTok->startsSequence(tok::r_square, tok::r_square)) {
-  // ObjC message send. We assume nobody will use : in a C++11 attribute
-  // specifier parameter, although this is technically valid:
-  // [[foo(:)]].
-  if (AttrTok->is(tok::colon) ||
-  AttrTok->startsSequence(tok::identifier, tok::identifier) ||
-  AttrTok->startsSequence(tok::r_paren, tok::identifier)) {
-return false;
-  }
-  if (AttrTok->is(tok::ellipsis))
-return true;
-  AttrTok = AttrTok->Next;
-}
-return AttrTok && AttrTok->startsSequence(tok::r_square, tok::r_square);
+return isCppAttribute(Style.isCpp(), Tok);
   }
 
   bool parseSquare() {
@@ -2835,6 +2840,8 @@
 }
 if (!Next->is(tok::identifier))
   return false;
+  } else if (isCppAttribute(IsCpp, *Next)) {
+Next = Next->MatchingParen;
   } else if (Next->is(tok::l_paren)) {
 break;
   } else {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136554: Implement CWG2631

2022-11-05 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

reduced to

  struct a {
  } constexpr b;
  class c {
  public:
c(a);
  };
  class d {
d() {}
c e = b;
  }


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136554

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


[PATCH] D137329: [flang] Add -f[no-]associative-math and -mreassociate

2022-11-05 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

In D137329#3909082 , @clementval 
wrote:

> Wouldn't it be good to have a RFC for all these options and what they will do 
> in Flang instead of just adding them all? Or did I miss the RFC?

+1


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137329

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


[PATCH] D137484: [Test] Fix driverkit-path.c with lib64 dir

2022-11-05 Thread Thomas Preud'homme via Phabricator via cfe-commits
thopre created this revision.
thopre added reviewers: yln, rsmith.
Herald added a project: All.
thopre requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137484

Files:
  clang/test/Driver/driverkit-path.c


Index: clang/test/Driver/driverkit-path.c
===
--- clang/test/Driver/driverkit-path.c
+++ clang/test/Driver/driverkit-path.c
@@ -29,6 +29,6 @@
 // INC:   -isysroot [[PATH:[^ ]*/Inputs/DriverKit19.0.sdk]]
 // INC-LABEL: #include <...> search starts here:
 // INC:   [[PATH]]/System/DriverKit/usr/local/include
-// INC:   /lib/clang/{{[^/ ]+}}/include
+// INC:   /lib{{(64)?}}/clang/{{[^/ ]+}}/include
 // INC:   [[PATH]]/System/DriverKit/usr/include
 // INC:   [[PATH]]/System/DriverKit/System/Library/Frameworks (framework 
directory)


Index: clang/test/Driver/driverkit-path.c
===
--- clang/test/Driver/driverkit-path.c
+++ clang/test/Driver/driverkit-path.c
@@ -29,6 +29,6 @@
 // INC:   -isysroot [[PATH:[^ ]*/Inputs/DriverKit19.0.sdk]]
 // INC-LABEL: #include <...> search starts here:
 // INC:   [[PATH]]/System/DriverKit/usr/local/include
-// INC:   /lib/clang/{{[^/ ]+}}/include
+// INC:   /lib{{(64)?}}/clang/{{[^/ ]+}}/include
 // INC:   [[PATH]]/System/DriverKit/usr/include
 // INC:   [[PATH]]/System/DriverKit/System/Library/Frameworks (framework directory)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134859: [clang][Interp] Implement basic support for floating point values

2022-11-05 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 473409.
tbaeder added a comment.

Added a `const-fpfeatures.cpp` test and added semantics converstion to `::add` 
as an example.


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

https://reviews.llvm.org/D134859

Files:
  clang/lib/AST/CMakeLists.txt
  clang/lib/AST/Interp/Boolean.h
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/Context.cpp
  clang/lib/AST/Interp/Descriptor.cpp
  clang/lib/AST/Interp/Floating.cpp
  clang/lib/AST/Interp/Floating.h
  clang/lib/AST/Interp/Integral.h
  clang/lib/AST/Interp/Interp.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/InterpStack.h
  clang/lib/AST/Interp/Opcodes.td
  clang/lib/AST/Interp/PrimType.h
  clang/lib/AST/Interp/Primitives.h
  clang/test/AST/Interp/const-fpfeatures.cpp
  clang/test/AST/Interp/floats.cpp
  clang/test/SemaCXX/rounding-math.cpp

Index: clang/test/SemaCXX/rounding-math.cpp
===
--- clang/test/SemaCXX/rounding-math.cpp
+++ clang/test/SemaCXX/rounding-math.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -triple x86_64-linux -verify=norounding -Wno-unknown-pragmas %s
 // RUN: %clang_cc1 -triple x86_64-linux -verify=rounding %s -frounding-math -Wno-unknown-pragmas
+// RUN: %clang_cc1 -triple x86_64-linux -verify=rounding %s -frounding-math -fexperimental-new-constant-interpreter -Wno-unknown-pragmas
 // rounding-no-diagnostics
 
 #define fold(x) (__builtin_constant_p(x) ? (x) : (x))
Index: clang/test/AST/Interp/floats.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/floats.cpp
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
+// RUN: %clang_cc1 -verify=ref %s
+
+constexpr int i = 2;
+constexpr float f = 1.0f;
+static_assert(f == 1.0f, "");
+
+constexpr float f2 = 1u * f;
+static_assert(f2 == 1.0f, "");
+
+static_assert(1.0f + 3u == 4, "");
+static_assert(4.0f / 1.0f == 4, "");
+static_assert(10.0f * false == 0, "");
+
+constexpr float floats[] = {1.0f, 2.0f, 3.0f, 4.0f};
+
+constexpr float m = 5.0f / 0.0f; // ref-error {{must be initialized by a constant expression}} \
+ // ref-note {{division by zero}} \
+ // expected-error {{must be initialized by a constant expression}} \
+ // expected-note {{division by zero}}
+
+static_assert(~2.0f == 3, ""); // ref-error {{invalid argument type 'float' to unary expression}} \
+   // expected-error {{invalid argument type 'float' to unary expression}}
+
+/// Initialized by a double.
+constexpr float df = 0.0;
+/// The other way around.
+constexpr double fd = 0.0f;
+
+static_assert(0.0f == -0.0f, "");
+
+const int k = 3 * (1.0f / 3.0f);
+static_assert(k == 1, "");
+
+constexpr bool b = 1.0;
+static_assert(b, "");
+
+constexpr double db = true;
+static_assert(db == 1.0, "");
+
+constexpr float fa[] = {1.0f, 2.0, 1, false};
+constexpr float da[] = {1.0f, 2.0, 1, false};
Index: clang/test/AST/Interp/const-fpfeatures.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/const-fpfeatures.cpp
@@ -0,0 +1,65 @@
+// RUN: %clang_cc1 -S -emit-llvm -triple i386-linux -std=c++2a -Wno-unknown-pragmas %s -o - | FileCheck %s
+// RUN: %clang_cc1 -S -emit-llvm -triple i386-linux -fexperimental-new-constant-interpreter -std=c++2a -Wno-unknown-pragmas %s -o - | FileCheck %s
+
+
+#pragma STDC FENV_ROUND FE_UPWARD
+
+float F1u = 1.0F + 0x0.02p0F;
+float F2u = 1.0F + 0x0.01p0F;
+float F3u = 0x1.01p0;
+// CHECK: @F1u = {{.*}} float 0x3FF02000
+// CHECK: @F2u = {{.*}} float 0x3FF02000
+// CHECK: @F3u = {{.*}} float 0x3FF02000
+
+#pragma STDC FENV_ROUND FE_DOWNWARD
+
+float F1d = 1.0F + 0x0.02p0F;
+float F2d = 1.0F + 0x0.01p0F;
+float F3d = 0x1.01p0;
+
+// CHECK: @F1d = {{.*}} float 0x3FF02000
+// CHECK: @F2d = {{.*}} float 1.00e+00
+// CHECK: @F3d = {{.*}} float 1.00e+00
+
+// nextUp(1.F) == 0x1.02p0F
+
+constexpr float add_round_down(float x, float y) {
+  #pragma STDC FENV_ROUND FE_DOWNWARD
+  float res = x;
+  res += y;
+  return res;
+}
+
+constexpr float add_round_up(float x, float y) {
+  #pragma STDC FENV_ROUND FE_UPWARD
+  float res = x;
+  res += y;
+  return res;
+}
+
+float V1 = add_round_down(1.0F, 0x0.01p0F);
+float V2 = add_round_up(1.0F, 0x0.01p0F);
+// CHECK: @V1 = {{.*}} float 1.00e+00
+// CHECK: @V2 = {{.*}} float 0x3FF02000
+
+constexpr float add_cast_round_down(float x, double y) {
+  #pragma STDC FENV_ROUND FE_DOWNWARD
+  float res = x;
+  res += y;
+  return res;
+}
+
+constexpr float add_cast_round_up(float x, double y) {
+  #pragma STDC FENV_ROUND FE_UPWARD
+  float res = x;
+  res += y;
+  return res;
+}
+
+float V3 = add_cast_round_down(1.0F, 0x0.01p0F);
+float 

[PATCH] D137040: [clangd] Add heuristic for dropping snippet when completing member function pointer

2022-11-05 Thread Tom Praschan via Phabricator via cfe-commits
tom-anders added a comment.

The test in clangd/unittests/CodeCompleteTests.cpp still passes. We now 
probably also need a unit test for Sema that tests the new flag, right?




Comment at: clang-tools-extra/clangd/CodeComplete.cpp:414
, IsPattern);
+  if (!C.SemaResult->FunctionCanBeCall)
+S.SnippetSuffix.clear();

Here, the SnippetSuffix is still created and then immediately cleared again. 
But the logic inside getSignature is quite complex and it's used in multiple 
places, so I didn't really want to touch that function for now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137040

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


[PATCH] D137040: [clangd] Add heuristic for dropping snippet when completing member function pointer

2022-11-05 Thread Tom Praschan via Phabricator via cfe-commits
tom-anders updated this revision to Diff 473408.
tom-anders added a comment.
Herald added a project: clang.

Move logic to SemaCodeComplete.cpp


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137040

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang/include/clang/Sema/CodeCompleteConsumer.h
  clang/lib/Sema/SemaCodeComplete.cpp

Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -1379,6 +1379,33 @@
 OverloadSet.Add(Method, Results.size());
   }
 
+  // When completing a non-static member function (and not via
+  // dot/arrow member access) and we're not inside that class' scope,
+  // it can't be a call.
+  if (CompletionContext.getKind() == clang::CodeCompletionContext::CCC_Symbol) {
+const auto *Method = dyn_cast(R.getDeclaration());
+if (Method && !Method->isStatic()) {
+  // Find the class scope that we're currently in.
+  // We could e.g. be inside a lambda, so walk up the DeclContext until we
+  // find a CXXMethodDecl.
+  const auto *CurrentClassScope = [&]() -> const CXXRecordDecl * {
+for (DeclContext *Ctx = SemaRef.CurContext; Ctx;
+ Ctx = Ctx->getParent()) {
+  const auto *CtxMethod = llvm::dyn_cast(Ctx);
+  if (CtxMethod && !CtxMethod->getParent()->isLambda()) {
+return CtxMethod->getParent();
+  }
+}
+return nullptr;
+  }();
+
+  R.FunctionCanBeCall =
+  CurrentClassScope &&
+  (CurrentClassScope == Method->getParent() ||
+   CurrentClassScope->isDerivedFrom(Method->getParent()));
+}
+  }
+
   // Insert this result into the set of results.
   Results.push_back(R);
 
Index: clang/include/clang/Sema/CodeCompleteConsumer.h
===
--- clang/include/clang/Sema/CodeCompleteConsumer.h
+++ clang/include/clang/Sema/CodeCompleteConsumer.h
@@ -850,6 +850,12 @@
   /// rather than a use of that entity.
   bool DeclaringEntity : 1;
 
+  /// When completing a function, whether it can be a call. This will usually be
+  /// true, but we have some heuristics, e.g. when a pointer to a non-static
+  /// member function is completed outside of that class' scope, it can never
+  /// be a call.
+  bool FunctionCanBeCall : 1;
+
   /// If the result should have a nested-name-specifier, this is it.
   /// When \c QualifierIsInformative, the nested-name-specifier is
   /// informative rather than required.
@@ -876,7 +882,7 @@
 FixIts(std::move(FixIts)), Hidden(false), InBaseClass(false),
 QualifierIsInformative(QualifierIsInformative),
 StartsNestedNameSpecifier(false), AllParametersAreInformative(false),
-DeclaringEntity(false), Qualifier(Qualifier) {
+DeclaringEntity(false), FunctionCanBeCall(true), Qualifier(Qualifier) {
 // FIXME: Add assert to check FixIts range requirements.
 computeCursorKindAndAvailability(Accessible);
   }
@@ -886,7 +892,8 @@
   : Keyword(Keyword), Priority(Priority), Kind(RK_Keyword),
 CursorKind(CXCursor_NotImplemented), Hidden(false), InBaseClass(false),
 QualifierIsInformative(false), StartsNestedNameSpecifier(false),
-AllParametersAreInformative(false), DeclaringEntity(false) {}
+AllParametersAreInformative(false), DeclaringEntity(false),
+FunctionCanBeCall(true) {}
 
   /// Build a result that refers to a macro.
   CodeCompletionResult(const IdentifierInfo *Macro,
@@ -896,7 +903,7 @@
 CursorKind(CXCursor_MacroDefinition), Hidden(false), InBaseClass(false),
 QualifierIsInformative(false), StartsNestedNameSpecifier(false),
 AllParametersAreInformative(false), DeclaringEntity(false),
-MacroDefInfo(MI) {}
+FunctionCanBeCall(true), MacroDefInfo(MI) {}
 
   /// Build a result that refers to a pattern.
   CodeCompletionResult(
@@ -908,7 +915,7 @@
 CursorKind(CursorKind), Availability(Availability), Hidden(false),
 InBaseClass(false), QualifierIsInformative(false),
 StartsNestedNameSpecifier(false), AllParametersAreInformative(false),
-DeclaringEntity(false) {}
+DeclaringEntity(false), FunctionCanBeCall(true) {}
 
   /// Build a result that refers to a pattern with an associated
   /// declaration.
@@ -917,7 +924,7 @@
   : Declaration(D), Pattern(Pattern), Priority(Priority), Kind(RK_Pattern),
 Hidden(false), InBaseClass(false), QualifierIsInformative(false),
 StartsNestedNameSpecifier(false), AllParametersAreInformative(false),
-DeclaringEntity(false) {
+DeclaringEntity(false), FunctionCanBeCall(true) {
 computeCursorKindAndAvailability();
   }
 
Index: 

[PATCH] D134859: [clang][Interp] Implement basic support for floating point values

2022-11-05 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added inline comments.



Comment at: clang/lib/AST/Interp/Opcodes.td:502
+  let Types = [AluTypeClass];
+  let Args = [ArgFltSemantics];
+  let HasGroup = 1;

tbaeder wrote:
> jcranmer-intel wrote:
> > Integer-to-floating point conversion is dependent on rounding 
> > mode--consider `(float)UINT_MAX`.
> This test succeeds here, whether I use `-frounding-math` or not:
> 
> ```
> constexpr float f = (float)4294967295;
> static_assert(f == (float)4.2949673E+9);
> ```
> How can I test this behavior?
You can use `#pragma STDC FENV_ROUND`. See `clang/test/AST/const-fpfeatures.c` 
as an example.


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

https://reviews.llvm.org/D134859

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


[PATCH] D130015: [clangd] Add "usedAsMutablePointer" highlighting modifier

2022-11-05 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

In D130015#3702004 , @ckandeler wrote:

> IMO the relevant point is the (non-)const-ness of the corresponding 
> parameter, i.e. can the passed object get mutated or not. The fact that 
> there's an ampersand at the call site (which is not even the case if the 
> variable is itself a pointer) does not tell me that.

Taking another look at this, I find this use case convincing and I'm fine with 
taking this patch.

I do prefer the separate modifier for customizability, as I think the 
desirability of highlighting this can vary based on the coding convention. For 
example, one project I work with is slightly older and a lot of objects are 
passed around by non-const pointer, but actual "`out` parameters" almost always 
take the form of `` at the call site **or** use a reference; in such a 
case, the pointer modifier would be fairly noisy and it's nice to be able to 
disable it while keeping the reference modifier on.




Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:587
 
 // FIXME Add "unwrapping" for ArraySubscriptExpr and UnaryOperator,
 //  e.g. highlight `a` in `a[i]`

nit: you can remove the "and UnaryOperator" part of the FIXME, since you're 
addressing it



Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:592
+  Arg = IC->getSubExprAsWritten();
+if (auto *UO = dyn_cast(Arg)) {
+  if (UO->getOpcode() == UO_AddrOf)

Could you add a test case that exercises the `UnaryOperator` case?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130015

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


[PATCH] D137475: Explicitly initialize opaque pointer mode when -fthinlto-index is used

2022-11-05 Thread Nikita Popov via Phabricator via cfe-commits
nikic added inline comments.



Comment at: clang/lib/CodeGen/CodeGenAction.cpp:1112
+// mixing opaque pointers and typed pointers bitcode files.
+VMContext->setOpaquePointers(CI.getCodeGenOpts().OpaquePointers);
+

I think it would be fine to always do this, not just for the ThinLTO case.



Comment at: clang/test/CodeGen/thinlto-opaque-typed-mix.ll:14
+; RUN:   -fthinlto-index=%t/typed.bc.thinlto.bc
+; RUN: false
+

What's the `false` doing here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137475

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


[PATCH] D136936: [clang][Interp] Handle undefined functions better

2022-11-05 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeEmitter.cpp:24-31
+  bool HasBody = true;
+
+  // Function is not defined at all or not yet. We will
+  // create a Function instance but not compile the body. That
+  // will (maybe) happen later.
   if (!FuncDecl->isDefined(FuncDecl) ||
   (!FuncDecl->hasBody() && FuncDecl->willHaveBody()))

aaron.ballman wrote:
> tbaeder wrote:
> > aaron.ballman wrote:
> > >  negating the Boolean calculation and applying deMorgan's law did not 
> > > make that code more clear, did it (assuming I did everything right)? If 
> > > you agree, then I'm fine with the more complicated form and letting the 
> > > optimizer make it faster.
> > I can see that going either way. I think your version is a more confusing 
> > though because the two body conditions are coupled with the `isDefined` 
> > condition. E.g. `HasBody` is `true` if `isDefined() && !willHaveBody()`, 
> > which doesn't make sense to me I think.
> > 
> > I think I just read this code too many times now.  How does being defined 
> > even relate to the function having a body? Should that code just be 
> > `HasBody = hasBody() || willHaveBody()`?
> > I can see that going either way. I think your version is a more confusing 
> > though because the two body conditions are coupled with the isDefined 
> > condition. E.g. HasBody is true if isDefined() && !willHaveBody(), which 
> > doesn't make sense to me I think.
> 
> I'm glad we both are confused about the same thing!
> 
> > I think I just read this code too many times now. How does being defined 
> > even relate to the function having a body? Should that code just be HasBody 
> > = hasBody() || willHaveBody()?
> 
> I've not dug back in time to see how we got to that predicate in the first 
> place, but my *hunch* is that this may have to do with implicit function 
> definitions for things like special member functions. That's a case where you 
> can have a function definition without a body. e.g.,
> ```
> struct S {
>   S();
> };
> 
> S::S() = default;
> ```
Well, any sort of digging usually just gets you to the //one// commit that 
introduced all of the new constant interpreter :P 

`willHaveBody()` isn't even relevant here, is it?
I think simply

``` 
bool hasBody = FuncDecl->isDefined() || FuncDecl->hasBody();

```
makes the most sense.


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

https://reviews.llvm.org/D136936

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


[PATCH] D136828: [clang][Interp] Diagnose uninitialized array record fields

2022-11-05 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/Interp.cpp:446-448
+static void DiagnoseUninitializedSubobject(InterpState , const SourceInfo 
,
+   QualType SubObjType,
+   SourceLocation SL) {

aaron.ballman wrote:
> Some comments describing what `SL` does would be helpful, since it's a bit 
> special.
Renamed it to `SubObjLoc` instead of adding a comment, I think that's enough.


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

https://reviews.llvm.org/D136828

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


[PATCH] D136828: [clang][Interp] Diagnose uninitialized array record fields

2022-11-05 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 473405.
tbaeder marked an inline comment as done.

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

https://reviews.llvm.org/D136828

Files:
  clang/lib/AST/Interp/Interp.cpp
  clang/lib/AST/Interp/Pointer.h
  clang/test/AST/Interp/cxx20.cpp

Index: clang/test/AST/Interp/cxx20.cpp
===
--- clang/test/AST/Interp/cxx20.cpp
+++ clang/test/AST/Interp/cxx20.cpp
@@ -85,8 +85,8 @@
 namespace UninitializedFields {
   class A {
   public:
-int a; // expected-note {{subobject declared here}} \
-   // ref-note {{subobject declared here}}
+int a; // expected-note 2{{subobject declared here}} \
+   // ref-note 2{{subobject declared here}}
 constexpr A() {}
   };
   constexpr A a; // expected-error {{must be initialized by a constant expression}} \
@@ -112,6 +112,42 @@
  // expected-note {{in call to 'Derived()'}} \
  // ref-error {{must be initialized by a constant expression}} \
  // ref-note {{subobject of type 'int' is not initialized}}
+
+  class C2 {
+  public:
+A a;
+constexpr C2() {} // expected-note {{subobject of type 'int' is not initialized}}
+  };
+  constexpr C2 c2; // expected-error {{must be initialized by a constant expression}} \
+   // expected-note {{in call to 'C2()'}} \
+   // ref-error {{must be initialized by a constant expression}} \
+   // ref-note {{subobject of type 'int' is not initialized}}
+
+
+  // FIXME: These two are currently disabled because the array fields
+  //   cannot be initialized.
+#if 0
+  class C3 {
+  public:
+A a[2];
+constexpr C3() {}
+  };
+  constexpr C3 c3; // expected-error {{must be initialized by a constant expression}} \
+   // expected-note {{subobject of type 'int' is not initialized}} \
+   // ref-error {{must be initialized by a constant expression}} \
+   // ref-note {{subobject of type 'int' is not initialized}}
+
+  class C4 {
+  public:
+bool B[2][3]; // expected-note {{subobject declared here}} \
+  // ref-note {{subobject declared here}}
+constexpr C4(){}
+  };
+  constexpr C4 c4; // expected-error {{must be initialized by a constant expression}} \
+   // expected-note {{subobject of type 'bool' is not initialized}} \
+   // ref-error {{must be initialized by a constant expression}} \
+   // ref-note {{subobject of type 'bool' is not initialized}}
+#endif
 };
 
 namespace ConstThis {
Index: clang/lib/AST/Interp/Pointer.h
===
--- clang/lib/AST/Interp/Pointer.h
+++ clang/lib/AST/Interp/Pointer.h
@@ -242,6 +242,8 @@
 
   /// Returns the record descriptor of a class.
   Record *getRecord() const { return getFieldDesc()->ElemRecord; }
+  // Returns the element record type, if this is a non-primive array.
+  Record *getElemRecord() const { return getFieldDesc()->ElemDesc->ElemRecord; }
   /// Returns the field information.
   const FieldDecl *getField() const { return getFieldDesc()->asFieldDecl(); }
 
Index: clang/lib/AST/Interp/Interp.cpp
===
--- clang/lib/AST/Interp/Interp.cpp
+++ clang/lib/AST/Interp/Interp.cpp
@@ -407,6 +407,48 @@
   return false;
 }
 
+static void DiagnoseUninitializedSubobject(InterpState , const SourceInfo ,
+   QualType SubObjType,
+   SourceLocation SubObjLoc) {
+  S.FFDiag(SI, diag::note_constexpr_uninitialized) << true << SubObjType;
+  if (SubObjLoc.isValid())
+S.Note(SubObjLoc, diag::note_constexpr_subobject_declared_here);
+}
+
+static bool CheckFieldsInitialized(InterpState , CodePtr OpPC,
+   const Pointer , const Record *R);
+
+static bool CheckArrayInitialized(InterpState , CodePtr OpPC,
+  const Pointer ,
+  const ConstantArrayType *CAT) {
+  bool Result = true;
+  size_t NumElems = CAT->getSize().getZExtValue();
+  QualType ElemType = CAT->getElementType();
+
+  if (isa(ElemType.getTypePtr())) {
+const Record *R = BasePtr.getElemRecord();
+for (size_t I = 0; I != NumElems; ++I) {
+  Pointer ElemPtr = BasePtr.atIndex(I).narrow();
+  Result &= CheckFieldsInitialized(S, OpPC, ElemPtr, R);
+}
+  } else if (auto *ElemCAT = dyn_cast(ElemType)) {
+for (size_t I = 0; I != NumElems; ++I) {
+  Pointer ElemPtr = BasePtr.atIndex(I).narrow();
+  Result &= CheckArrayInitialized(S, OpPC, ElemPtr, ElemCAT);
+}
+  } else {
+for (size_t I = 0; I != NumElems; ++I) {
+  if (!BasePtr.atIndex(I).isInitialized()) {
+DiagnoseUninitializedSubobject(S, S.Current->getSource(OpPC), ElemType,
+  

[PATCH] D134859: [clang][Interp] Implement basic support for floating point values

2022-11-05 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 473404.

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

https://reviews.llvm.org/D134859

Files:
  clang/lib/AST/CMakeLists.txt
  clang/lib/AST/Interp/Boolean.h
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/Context.cpp
  clang/lib/AST/Interp/Descriptor.cpp
  clang/lib/AST/Interp/Floating.cpp
  clang/lib/AST/Interp/Floating.h
  clang/lib/AST/Interp/Integral.h
  clang/lib/AST/Interp/Interp.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/InterpStack.h
  clang/lib/AST/Interp/Opcodes.td
  clang/lib/AST/Interp/PrimType.h
  clang/lib/AST/Interp/Primitives.h
  clang/test/AST/Interp/floats.cpp
  clang/test/SemaCXX/rounding-math.cpp

Index: clang/test/SemaCXX/rounding-math.cpp
===
--- clang/test/SemaCXX/rounding-math.cpp
+++ clang/test/SemaCXX/rounding-math.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -triple x86_64-linux -verify=norounding -Wno-unknown-pragmas %s
 // RUN: %clang_cc1 -triple x86_64-linux -verify=rounding %s -frounding-math -Wno-unknown-pragmas
+// RUN: %clang_cc1 -triple x86_64-linux -verify=rounding %s -frounding-math -fexperimental-new-constant-interpreter -Wno-unknown-pragmas
 // rounding-no-diagnostics
 
 #define fold(x) (__builtin_constant_p(x) ? (x) : (x))
Index: clang/test/AST/Interp/floats.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/floats.cpp
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
+// RUN: %clang_cc1 -verify=ref %s
+
+constexpr int i = 2;
+constexpr float f = 1.0f;
+static_assert(f == 1.0f, "");
+
+constexpr float f2 = 1u * f;
+static_assert(f2 == 1.0f, "");
+
+static_assert(1.0f + 3u == 4, "");
+static_assert(4.0f / 1.0f == 4, "");
+static_assert(10.0f * false == 0, "");
+
+constexpr float floats[] = {1.0f, 2.0f, 3.0f, 4.0f};
+
+constexpr float m = 5.0f / 0.0f; // ref-error {{must be initialized by a constant expression}} \
+ // ref-note {{division by zero}} \
+ // expected-error {{must be initialized by a constant expression}} \
+ // expected-note {{division by zero}}
+
+static_assert(~2.0f == 3, ""); // ref-error {{invalid argument type 'float' to unary expression}} \
+   // expected-error {{invalid argument type 'float' to unary expression}}
+
+/// Initialized by a double.
+constexpr float df = 0.0;
+/// The other way around.
+constexpr double fd = 0.0f;
+
+static_assert(0.0f == -0.0f, "");
+
+const int k = 3 * (1.0f / 3.0f);
+static_assert(k == 1, "");
+
+constexpr bool b = 1.0;
+static_assert(b, "");
+
+constexpr double db = true;
+static_assert(db == 1.0, "");
+
+constexpr float fa[] = {1.0f, 2.0, 1, false};
+constexpr float da[] = {1.0f, 2.0, 1, false};
Index: clang/lib/AST/Interp/Primitives.h
===
--- /dev/null
+++ clang/lib/AST/Interp/Primitives.h
@@ -0,0 +1,36 @@
+//===-- Primitives.h - Types for the constexpr VM ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Utilities and helper functions for all primitive types:
+//  - Integral
+//  - Floating
+//  - Boolean
+//
+//===--===//
+
+#ifndef LLVM_CLANG_AST_INTERP_PRIMITIVES_H
+#define LLVM_CLANG_AST_INTERP_PRIMITIVES_H
+
+#include "clang/AST/ComparisonCategories.h"
+
+namespace clang {
+namespace interp {
+
+/// Helper to compare two comparable types.
+template  ComparisonCategoryResult Compare(const T , const T ) {
+  if (X < Y)
+return ComparisonCategoryResult::Less;
+  if (X > Y)
+return ComparisonCategoryResult::Greater;
+  return ComparisonCategoryResult::Equal;
+}
+
+} // namespace interp
+} // namespace clang
+
+#endif
Index: clang/lib/AST/Interp/PrimType.h
===
--- clang/lib/AST/Interp/PrimType.h
+++ clang/lib/AST/Interp/PrimType.h
@@ -13,11 +13,12 @@
 #ifndef LLVM_CLANG_AST_INTERP_TYPE_H
 #define LLVM_CLANG_AST_INTERP_TYPE_H
 
+#include "Boolean.h"
+#include "Floating.h"
+#include "Integral.h"
 #include 
 #include 
 #include 
-#include "Boolean.h"
-#include "Integral.h"
 
 namespace clang {
 namespace interp {
@@ -35,6 +36,7 @@
   PT_Sint64,
   PT_Uint64,
   PT_Bool,
+  PT_Float,
   PT_Ptr,
 };
 
@@ -48,6 +50,7 @@
 template <> struct PrimConv { using T = Integral<32, false>; };
 template <> struct PrimConv { using T = Integral<64, true>; };
 template <> struct PrimConv { using T = Integral<64, false>; };
+template <> 

[PATCH] D131295: [clangd] Implement textDocument/codeLens

2022-11-05 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a reviewer: kadircet.
nridge added a comment.

Haven't had a chance to look at this yet. I do see that the earier 
implementation in D91930  was the subject of 
some design discussions about performance with @kadircet, adding him as an 
additional reviewer.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131295

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


[PATCH] D134859: [clang][Interp] Implement basic support for floating point values

2022-11-05 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/Interp.cpp:487
+  if (S.inConstantContext())
+return true;
+

jcranmer-intel wrote:
> Not sure I understand the conditions that cause `S.inConstantContext()` to be 
> true, which gives me some cause for concern. Additionally, there's no tests 
> covering the checks in the function.
This function is almost copy/paste from `checkFloatingPointResult` in 
`ExprConstant.cpp`: 
https://github.com/llvm/llvm-project/blob/main/clang/lib/AST/ExprConstant.cpp#L2581



Comment at: clang/lib/AST/Interp/Opcodes.td:502
+  let Types = [AluTypeClass];
+  let Args = [ArgFltSemantics];
+  let HasGroup = 1;

jcranmer-intel wrote:
> Integer-to-floating point conversion is dependent on rounding mode--consider 
> `(float)UINT_MAX`.
This test succeeds here, whether I use `-frounding-math` or not:

```
constexpr float f = (float)4294967295;
static_assert(f == (float)4.2949673E+9);
```
How can I test this behavior?


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

https://reviews.llvm.org/D134859

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


[PATCH] D137223: [clang-format] Remove special case for kw_operator when aligning decls

2022-11-05 Thread Owen Pan via Phabricator via cfe-commits
owenpan accepted this revision.
owenpan added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137223

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