[PATCH] D132640: [clang-tidy] Fix modernize-use-emplace to support alias cases

2022-08-27 Thread Dong-hee Na via Phabricator via cfe-commits
corona10 updated this revision to Diff 456173.
corona10 added a comment.

- clang-format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132640

Files:
  clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/modernize/use-emplace.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-emplace.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/use-emplace.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-emplace.cpp
@@ -1061,6 +1061,82 @@
   // CHECK-FIXES: priority_queue.emplace(13);
 }
 
+void test_AliasEmplacyFunctions() {
+  typedef std::list L;
+  using DQ = std::deque;
+  L l;
+  l.emplace_back(Foo(3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: unnecessary temporary object created while calling emplace_back
+  // CHECK-FIXES: l.emplace_back(3);
+
+  DQ dq;
+  dq.emplace_back(Foo(3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: unnecessary temporary object created while calling emplace_back
+  // CHECK-FIXES: dq.emplace_back(3);
+
+  typedef std::stack STACK;
+  using PQ = std::priority_queue;
+  STACK stack;
+  stack.emplace(Foo(3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: unnecessary temporary object created while calling emplace
+  // CHECK-FIXES: stack.emplace(3);
+
+  PQ pq;
+  pq.emplace(Foo(3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: unnecessary temporary object created while calling emplace
+  // CHECK-FIXES: pq.emplace(3);
+
+  typedef std::forward_list FL;
+  using DQ2 = std::deque;
+  FL fl;
+  fl.emplace_front(Foo(3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: unnecessary temporary object created while calling emplace_front
+  // CHECK-FIXES: fl.emplace_front(3);
+
+  DQ2 dq2;
+  dq2.emplace_front(Foo(3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: unnecessary temporary object created while calling emplace_front
+  // CHECK-FIXES: dq2.emplace_front(3);
+}
+
+void test_Alias() {
+  typedef std::list L;
+  using DQ = std::deque;
+  L l;
+  l.push_back(Foo(3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back instead of push_back [modernize-use-emplace]
+  // CHECK-FIXES: l.emplace_back(3);
+
+  DQ dq;
+  dq.push_back(Foo(3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_back instead of push_back [modernize-use-emplace]
+  // CHECK-FIXES: dq.emplace_back(3);
+
+  typedef std::stack STACK;
+  using PQ = std::priority_queue;
+  STACK stack;
+  stack.push(Foo(3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use emplace instead of push [modernize-use-emplace]
+  // CHECK-FIXES: stack.emplace(3);
+
+  PQ pq;
+  pq.push(Foo(3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace instead of push [modernize-use-emplace]
+  // CHECK-FIXES: pq.emplace(3);
+
+  typedef std::forward_list FL;
+  using DQ2 = std::deque;
+  FL fl;
+  fl.push_front(Foo(3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_front instead of push_front [modernize-use-emplace]
+  // CHECK-FIXES: fl.emplace_front(3);
+
+  DQ2 dq2;
+  dq2.push_front(Foo(3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use emplace_front instead of push_front [modernize-use-emplace]
+  // CHECK-FIXES: dq2.emplace_front(3);
+}
+
 struct Bar {
 public:
   Bar(){};
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -125,13 +125,17 @@
   ` when warnings
   would be emitted for uninitialized members of an anonymous union despite
   there being an initializer for one of the other members.
-  
+
 - Improved `modernize-use-emplace `_ check.
 
   The check now supports detecting inefficient invocations of ``push`` and
   ``push_front`` on STL-style containers and replacing them with ``emplace``
   or ``emplace_front``.
 
+  The check now supports detecting alias cases of ``push_back`` ``push`` and
+  ``push_front`` on STL-style containers and replacing them with ``emplace_back``,
+  ``emplace`` or ``emplace_front``.
+
 - Improved `modernize-use-equals-default `_ check.
 
   The check now skips unions since in this case a default constructor with empty body
Index: clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp
@@ -134,22 +134,25 @@
   // + match for emplace calls that should be replaced with insertion
   auto CallPushBack = cxxMemberCallExpr(
   hasDeclaration(functionDecl(hasName("push_back"))),
-  on(hasType(cxxRecordDecl(hasAnyName(ContainersWithPushBack);
+  on(hasType(hasCanonicalType(
+  hasDeclaration(cxxRec

[PATCH] D132640: [clang-tidy] Fix modernize-use-emplace to support alias cases

2022-08-27 Thread Dong-hee Na via Phabricator via cfe-commits
corona10 marked an inline comment as done.
corona10 added a comment.

Thanks! I updated the change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132640

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


[PATCH] D132640: [clang-tidy] Fix modernize-use-emplace to support alias cases

2022-08-27 Thread Dong-hee Na via Phabricator via cfe-commits
corona10 updated this revision to Diff 456172.
corona10 added a comment.

Address code review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132640

Files:
  clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/modernize/use-emplace.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-emplace.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/use-emplace.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-emplace.cpp
@@ -1061,6 +1061,82 @@
   // CHECK-FIXES: priority_queue.emplace(13);
 }
 
+void test_AliasEmplacyFunctions() {
+  typedef std::list L;
+  using DQ = std::deque;
+  L l;
+  l.emplace_back(Foo(3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: unnecessary temporary object created while calling emplace_back
+  // CHECK-FIXES: l.emplace_back(3);
+
+  DQ dq;
+  dq.emplace_back(Foo(3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: unnecessary temporary object created while calling emplace_back
+  // CHECK-FIXES: dq.emplace_back(3);
+
+  typedef std::stack STACK;
+  using PQ = std::priority_queue;
+  STACK stack;
+  stack.emplace(Foo(3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: unnecessary temporary object created while calling emplace
+  // CHECK-FIXES: stack.emplace(3);
+
+  PQ pq;
+  pq.emplace(Foo(3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: unnecessary temporary object created while calling emplace
+  // CHECK-FIXES: pq.emplace(3);
+
+  typedef std::forward_list FL;
+  using DQ2 = std::deque;
+  FL fl;
+  fl.emplace_front(Foo(3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: unnecessary temporary object created while calling emplace_front
+  // CHECK-FIXES: fl.emplace_front(3);
+
+  DQ2 dq2;
+  dq2.emplace_front(Foo(3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: unnecessary temporary object created while calling emplace_front
+  // CHECK-FIXES: dq2.emplace_front(3);
+}
+
+void test_Alias() {
+  typedef std::list L;
+  using DQ = std::deque;
+  L l;
+  l.push_back(Foo(3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back instead of push_back [modernize-use-emplace]
+  // CHECK-FIXES: l.emplace_back(3);
+
+  DQ dq;
+  dq.push_back(Foo(3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_back instead of push_back [modernize-use-emplace]
+  // CHECK-FIXES: dq.emplace_back(3);
+
+  typedef std::stack STACK;
+  using PQ = std::priority_queue;
+  STACK stack;
+  stack.push(Foo(3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use emplace instead of push [modernize-use-emplace]
+  // CHECK-FIXES: stack.emplace(3);
+
+  PQ pq;
+  pq.push(Foo(3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace instead of push [modernize-use-emplace]
+  // CHECK-FIXES: pq.emplace(3);
+
+  typedef std::forward_list FL;
+  using DQ2 = std::deque;
+  FL fl;
+  fl.push_front(Foo(3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use emplace_front instead of push_front [modernize-use-emplace]
+  // CHECK-FIXES: fl.emplace_front(3);
+
+  DQ2 dq2;
+  dq2.push_front(Foo(3));
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use emplace_front instead of push_front [modernize-use-emplace]
+  // CHECK-FIXES: dq2.emplace_front(3);
+}
+
 struct Bar {
 public:
   Bar(){};
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -125,13 +125,17 @@
   ` when warnings
   would be emitted for uninitialized members of an anonymous union despite
   there being an initializer for one of the other members.
-  
+
 - Improved `modernize-use-emplace `_ check.
 
   The check now supports detecting inefficient invocations of ``push`` and
   ``push_front`` on STL-style containers and replacing them with ``emplace``
   or ``emplace_front``.
 
+  The check now supports detecting alias cases of ``push_back`` ``push`` and
+  ``push_front`` on STL-style containers and replacing them with ``emplace_back``,
+  ``emplace`` or ``emplace_front``.
+
 - Improved `modernize-use-equals-default `_ check.
 
   The check now skips unions since in this case a default constructor with empty body
Index: clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp
@@ -132,24 +132,27 @@
   // because this requires special treatment (it could cause performance
   // regression)
   // + match for emplace calls that should be replaced with insertion
-  auto CallPushBack = cxxMemberCallExpr(
-  hasDeclaration(functionDecl(hasName("push_back"))),
-  on(hasType(cxxRecordDecl(hasAnyName

[PATCH] D132804: [clang-tidy] Add option to ignore CRTP overrides in convert-member-functions-to-static

2022-08-27 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 456170.
njames93 marked an inline comment as done.
njames93 added a comment.

Fix documentation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132804

Files:
  clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
  clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/readability/convert-member-functions-to-static.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/convert-member-functions-to-static-crtp.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/convert-member-functions-to-static-crtp.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability/convert-member-functions-to-static-crtp.cpp
@@ -0,0 +1,19 @@
+// If the option is true, expect no warnigs, however the check_clang_tidy script can't handle that case.
+// RUN: clang-tidy %s -checks=-*,readability-convert-member-functions-to-static \
+// RUN: -config='{CheckOptions: {readability-convert-member-functions-to-static.IgnorePseudoOverrides: true}}' \
+// RUN: -- -std=c++14 | count 0
+
+// RUN: %check_clang_tidy %s readability-convert-member-functions-to-static %t -- \
+// RUN: -config='{CheckOptions: {readability-convert-member-functions-to-static.IgnorePseudoOverrides: false}}' 
+template
+class CRTP{
+  bool foo();
+  bool bar();
+};
+
+class CRTPInstance : public CRTP {
+  // CHECK-MESSAGES: :[[@LINE+1]]:8: warning: method 'foo' can be made static
+  bool foo() { return false; }
+  // CHECK-MESSAGES: :[[@LINE+1]]:8: warning: method 'bar' can be made static
+  void bar() { return; }
+};
Index: clang-tools-extra/docs/clang-tidy/checks/readability/convert-member-functions-to-static.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/readability/convert-member-functions-to-static.rst
+++ clang-tools-extra/docs/clang-tidy/checks/readability/convert-member-functions-to-static.rst
@@ -12,3 +12,26 @@
 After making a member function ``static``, you might want to run the check
 `readability-static-accessed-through-instance <../readability/static-accessed-through-instance.html>`_ to replace calls like
 ``Instance.method()`` by ``Class::method()``.
+
+Options
+---
+
+.. option:: IgnorePseudoOverrides
+
+  When `true`, if there is a base class with a method with the same name, no
+  warning will be emitted. Often occurs with CRTP like classes.
+  For the case below a warning would only be emitted for 
+  ``Derived::shouldTraverse`` if this is set to `false`.
+  
+  Default value is `false`
+
+  .. code-block:: c++
+
+template 
+struct CRTPBase {
+  bool shouldTraverse();
+};
+
+struct Derived : CRTPBase {
+  bool shouldTraverse() { return false; }
+};
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -141,6 +141,11 @@
   The check now skips unions since in this case a default constructor with empty body
   is not equivalent to the explicitly defaulted one.
 
+- Improved :doc:`readability-convert-member-functions-to-static
+  ` check. 
+
+  This check can now ignore CRTP pseudooverrides.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.h
===
--- clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.h
+++ clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.h
@@ -23,10 +23,13 @@
 /// readability-convert-member-functions-to-static.html
 class ConvertMemberFunctionsToStatic : public ClangTidyCheck {
 public:
-  ConvertMemberFunctionsToStatic(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  ConvertMemberFunctionsToStatic(StringRef Name, ClangTidyContext *Context);
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  void storeOptions(ClangTidyOptions::OptionMap &Options) override;
+
+private:
+  const bool IgnorePseudoOverrides;
 };
 
 } // namespace readability
Index: clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
===
--- clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
+++ clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
@@ -71,6 +71,15 @@
   return UsageOfThis.Used;
 }
 
+AST_MATCHER(CXXMethodDecl, potentialCTRPOverride) {
+  for (const CXXBaseSpecifier &Base : Node.getParent()->bases()) {
+if (const auto

[PATCH] D130665: [clang-tidy] Fix false negative in readability-convert-member-functions-to-static

2022-08-27 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130665

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


[PATCH] D132640: [clang-tidy] Fix modernize-use-emplace to support alias cases

2022-08-27 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp:138
+on(hasType(hasCanonicalType(hasDeclaration(
+namedDecl(hasAnyName(ContainersWithPushBack)));
 

Sorry about that, not sure what happened.
Anyway same goes for below, use a cxxRecordDecl matcher instead of namedDecl.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132640

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


[PATCH] D132762: [clang-format] Allow `throw` to be a keyword in front of casts

2022-08-27 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay accepted this revision.
MyDeveloperDay added a comment.
This revision is now accepted and ready to land.

This at least seems to make sense


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132762

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


[PATCH] D132805: [clang-format] Fix a bug in removing braces for the LLVM style

2022-08-27 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay accepted this revision.
MyDeveloperDay 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/D132805/new/

https://reviews.llvm.org/D132805

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


[PATCH] D132805: [clang-format] Fix a bug in removing braces for the LLVM style

2022-08-27 Thread Owen Pan via Phabricator via cfe-commits
owenpan created this revision.
owenpan added reviewers: MyDeveloperDay, HazardyKnusperkeks, curdeius.
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.

When an l_brace is wrapped and the line above it ends with a
comment, the annotator adds ColumnLimit to the TotalLength of the
l_brace, so the actual column position of the l_brance must be
adjusted accordingly.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132805

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25815,6 +25815,14 @@
"}",
Style);
 
+  verifyFormat("if (a) // comment\n"
+   "  b = 1;",
+   "if (a) // comment\n"
+   "{\n"
+   "  b = 1;\n"
+   "}",
+   Style);
+
   verifyFormat("if (a) {\n"
"Label:\n"
"}",
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -815,6 +815,10 @@
   auto Length = LastToken->TotalLength;
   if (OpeningBrace) {
 assert(OpeningBrace != Tokens.front().Tok);
+if (auto Prev = OpeningBrace->Previous;
+Prev && Prev->TotalLength + ColumnLimit == OpeningBrace->TotalLength) {
+  Length -= ColumnLimit;
+}
 Length -= OpeningBrace->TokenText.size() + 1;
   }
 


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25815,6 +25815,14 @@
"}",
Style);
 
+  verifyFormat("if (a) // comment\n"
+   "  b = 1;",
+   "if (a) // comment\n"
+   "{\n"
+   "  b = 1;\n"
+   "}",
+   Style);
+
   verifyFormat("if (a) {\n"
"Label:\n"
"}",
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -815,6 +815,10 @@
   auto Length = LastToken->TotalLength;
   if (OpeningBrace) {
 assert(OpeningBrace != Tokens.front().Tok);
+if (auto Prev = OpeningBrace->Previous;
+Prev && Prev->TotalLength + ColumnLimit == OpeningBrace->TotalLength) {
+  Length -= ColumnLimit;
+}
 Length -= OpeningBrace->TokenText.size() + 1;
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D132804: [clang-tidy] Add option to ignore CRTP overrides in convert-member-functions-to-static

2022-08-27 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/readability/convert-member-functions-to-static.rst:23
+  warning will be emitted. Often occurs with CRTP like classes.
+  For the case below a warning would only be emitted for 
Derived::shouldTraverse
+  if this is set to `false`.

Please highlight `Derived::shouldTraverse` with double back-ticks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132804

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


[PATCH] D132640: [clang-tidy] Fix modernize-use-emplace to support alias cases

2022-08-27 Thread Dong-hee Na via Phabricator via cfe-commits
corona10 added a comment.

In D132640#3753744 , @njames93 wrote:

> LGTM, just with a small nit.

@njames93

Thank you but I can not find your comment about nit.
Would you like to check the comment one more time?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132640

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


[clang-tools-extra] 33b9304 - Use llvm::is_contained (NFC)

2022-08-27 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-08-27T21:21:00-07:00
New Revision: 33b93044352fae09376b7d71ce6f2441a34f343d

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

LOG: Use llvm::is_contained (NFC)

Added: 


Modified: 
clang-tools-extra/clang-tidy/zircon/TemporaryObjectsCheck.cpp
clang-tools-extra/clangd/QueryDriverDatabase.cpp
clang/lib/Frontend/FrontendAction.cpp
flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp
llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/zircon/TemporaryObjectsCheck.cpp 
b/clang-tools-extra/clang-tidy/zircon/TemporaryObjectsCheck.cpp
index 88fd926158093..b75ab9dbb2fe3 100644
--- a/clang-tools-extra/clang-tidy/zircon/TemporaryObjectsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/zircon/TemporaryObjectsCheck.cpp
@@ -22,8 +22,7 @@ namespace zircon {
 
 AST_MATCHER_P(CXXRecordDecl, matchesAnyName, ArrayRef, Names) {
   std::string QualifiedName = Node.getQualifiedNameAsString();
-  return llvm::any_of(Names,
-  [&](StringRef Name) { return QualifiedName == Name; });
+  return llvm::is_contained(Names, QualifiedName);
 }
 
 void TemporaryObjectsCheck::registerMatchers(MatchFinder *Finder) {

diff  --git a/clang-tools-extra/clangd/QueryDriverDatabase.cpp 
b/clang-tools-extra/clangd/QueryDriverDatabase.cpp
index e96912c6290c7..3fdacf397028e 100644
--- a/clang-tools-extra/clangd/QueryDriverDatabase.cpp
+++ b/clang-tools-extra/clangd/QueryDriverDatabase.cpp
@@ -189,8 +189,7 @@ extractSystemIncludesAndTarget(llvm::SmallString<128> 
Driver,
 
   for (size_t I = 0, E = CommandLine.size(); I < E; ++I) {
 llvm::StringRef Arg = CommandLine[I];
-if (llvm::any_of(FlagsToPreserve,
- [&Arg](llvm::StringRef S) { return S == Arg; })) {
+if (llvm::is_contained(FlagsToPreserve, Arg)) {
   Args.push_back(Arg);
 } else {
   const auto *Found =

diff  --git a/clang/lib/Frontend/FrontendAction.cpp 
b/clang/lib/Frontend/FrontendAction.cpp
index 4b639a7764954..78c8de78d7ab0 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -196,10 +196,8 @@ FrontendAction::CreateWrappedASTConsumer(CompilerInstance 
&CI,
 ActionType == PluginASTAction::CmdlineBeforeMainAction) {
   // This is O(|plugins| * |add_plugins|), but since both numbers are
   // way below 50 in practice, that's ok.
-  if (llvm::any_of(CI.getFrontendOpts().AddPluginActions,
-   [&](const std::string &PluginAction) {
- return PluginAction == Plugin.getName();
-   })) {
+  if (llvm::is_contained(CI.getFrontendOpts().AddPluginActions,
+ Plugin.getName())) {
 if (ActionType == PluginASTAction::CmdlineBeforeMainAction)
   ActionType = PluginASTAction::AddBeforeMainAction;
 else

diff  --git a/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp 
b/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp
index 188a9d251cdfd..61f19013787e1 100644
--- a/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp
+++ b/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp
@@ -62,8 +62,7 @@ class BoxprocTypeRewriter : public mlir::TypeConverter {
   return false;
 }
 if (auto recTy = ty.dyn_cast()) {
-  if (llvm::any_of(visitedTypes,
-   [&](mlir::Type rt) { return rt == recTy; }))
+  if (llvm::is_contained(visitedTypes, recTy))
 return false;
   bool result = false;
   visitedTypes.push_back(recTy);

diff  --git a/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp 
b/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
index 007ec5b70899f..a761a1a37ee7f 100644
--- a/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
@@ -424,8 +424,7 @@ bool AArch64RegisterInfo::isArgumentRegister(const 
MachineFunction &MF,
   bool IsVarArg = STI.isCallingConvWin64(MF.getFunction().getCallingConv());
 
   auto HasReg = [](ArrayRef RegList, MCRegister Reg) {
-return llvm::any_of(RegList,
-[Reg](const MCRegister R) { return R == Reg; });
+return llvm::is_contained(RegList, Reg);
   };
 
   switch (CC) {

diff  --git a/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp 
b/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp
index 1b1e0e74e24b6..ae9e95da4cd8d 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp
@@ -459,8 +459,7 @@ LogicalResult MmaOp::verify() {
 
   // Check that we matched an existing shape/dtype combination.
   if (expectedA.empty() || expectedB.empty() || expectedC.empty() ||
-  !llvm::any_of(allowedShapes,
-[&](const auto &allow

[PATCH] D132804: [clang-tidy] Add option to ignore CRTP overrides in convert-member-functions-to-static

2022-08-27 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added reviewers: aaron.ballman, gribozavr2, LegalizeAdulthood, 
JonasToth.
Herald added subscribers: carlosgalvezp, xazax.hun.
Herald added a project: All.
njames93 requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

In cases where a member function is a CRTP override, marking the 'derived' as 
static is likely to reduce in less readable code.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132804

Files:
  clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
  clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/readability/convert-member-functions-to-static.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/convert-member-functions-to-static-crtp.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/convert-member-functions-to-static-crtp.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability/convert-member-functions-to-static-crtp.cpp
@@ -0,0 +1,19 @@
+// If the option is true, expect no warnigs, however the check_clang_tidy script can't handle that case.
+// RUN: clang-tidy %s -checks=-*,readability-convert-member-functions-to-static \
+// RUN: -config='{CheckOptions: {readability-convert-member-functions-to-static.IgnorePseudoOverrides: true}}' \
+// RUN: -- -std=c++14 | count 0
+
+// RUN: %check_clang_tidy %s readability-convert-member-functions-to-static %t -- \
+// RUN: -config='{CheckOptions: {readability-convert-member-functions-to-static.IgnorePseudoOverrides: false}}' 
+template
+class CRTP{
+  bool foo();
+  bool bar();
+};
+
+class CRTPInstance : public CRTP {
+  // CHECK-MESSAGES: :[[@LINE+1]]:8: warning: method 'foo' can be made static
+  bool foo() { return false; }
+  // CHECK-MESSAGES: :[[@LINE+1]]:8: warning: method 'bar' can be made static
+  void bar() { return; }
+};
Index: clang-tools-extra/docs/clang-tidy/checks/readability/convert-member-functions-to-static.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/readability/convert-member-functions-to-static.rst
+++ clang-tools-extra/docs/clang-tidy/checks/readability/convert-member-functions-to-static.rst
@@ -12,3 +12,24 @@
 After making a member function ``static``, you might want to run the check
 `readability-static-accessed-through-instance <../readability/static-accessed-through-instance.html>`_ to replace calls like
 ``Instance.method()`` by ``Class::method()``.
+
+Options
+---
+
+.. option:: IgnorePseudoOverrides
+
+  When `true`, if there is a base class with a method with the same name, no
+  warning will be emitted. Often occurs with CRTP like classes.
+  For the case below a warning would only be emitted for Derived::shouldTraverse
+  if this is set to `false`.
+
+  .. code-block:: c++
+
+template 
+struct CRTPBase {
+  bool shouldTraverse();
+};
+
+struct Derived : CRTPBase {
+  bool shouldTraverse() { return false; }
+};
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -141,6 +141,11 @@
   The check now skips unions since in this case a default constructor with empty body
   is not equivalent to the explicitly defaulted one.
 
+- Improved :doc:`readability-convert-member-functions-to-static
+  ` check. 
+
+  This check can now ignore CRTP pseudooverrides.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.h
===
--- clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.h
+++ clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.h
@@ -23,10 +23,13 @@
 /// readability-convert-member-functions-to-static.html
 class ConvertMemberFunctionsToStatic : public ClangTidyCheck {
 public:
-  ConvertMemberFunctionsToStatic(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  ConvertMemberFunctionsToStatic(StringRef Name, ClangTidyContext *Context);
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  void storeOptions(ClangTidyOptions::OptionMap &Options) override;
+
+private:
+  const bool IgnorePseudoOverrides;
 };
 
 } // namespace readability
Index: clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
===
--- clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
+++ clang-tools-extra/clang-tidy/readability/ConvertMember

[PATCH] D132801: [driver] Additional ignoring of module-map related flags, if modules are disabled

2022-08-27 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi created this revision.
Herald added a project: All.
akyrtzi requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132801

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/modules.m


Index: clang/test/Driver/modules.m
===
--- clang/test/Driver/modules.m
+++ clang/test/Driver/modules.m
@@ -80,3 +80,6 @@
 
 // RUN: %clang -fno-modules -fmodules-validate-system-headers -### %s 2>&1 | 
FileCheck -check-prefix=VALIDATE_SYSTEM_FLAG %s
 // VALIDATE_SYSTEM_FLAG-NOT: -fmodules-validate-system-headers
+
+// RUN: %clang -fno-modules -fmodule-map-file=module.modulemap -### %s 2>&1 | 
FileCheck -check-prefix=MODULE_MAP_FILE %s
+// MODULE_MAP_FILE-NOT: -fmodule-map-file
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3726,25 +3726,29 @@
  options::OPT_fno_modules_validate_input_files_content,
  false))
   CmdArgs.push_back("-fvalidate-ast-input-files-content");
-  }
-
-  // -fmodule-name specifies the module that is currently being built (or
-  // used for header checking by -fmodule-maps).
-  Args.AddLastArg(CmdArgs, options::OPT_fmodule_name_EQ);
 
-  // -fmodule-map-file can be used to specify files containing module
-  // definitions.
-  Args.AddAllArgs(CmdArgs, options::OPT_fmodule_map_file);
-
-  // -fbuiltin-module-map can be used to load the clang
-  // builtin headers modulemap file.
-  if (Args.hasArg(options::OPT_fbuiltin_module_map)) {
-SmallString<128> BuiltinModuleMap(D.ResourceDir);
-llvm::sys::path::append(BuiltinModuleMap, "include");
-llvm::sys::path::append(BuiltinModuleMap, "module.modulemap");
-if (llvm::sys::fs::exists(BuiltinModuleMap))
-  CmdArgs.push_back(
-  Args.MakeArgString("-fmodule-map-file=" + BuiltinModuleMap));
+// -fmodule-name specifies the module that is currently being built (or
+// used for header checking by -fmodule-maps).
+Args.AddLastArg(CmdArgs, options::OPT_fmodule_name_EQ);
+
+// -fmodule-map-file can be used to specify files containing module
+// definitions.
+Args.AddAllArgs(CmdArgs, options::OPT_fmodule_map_file);
+
+// -fbuiltin-module-map can be used to load the clang
+// builtin headers modulemap file.
+if (Args.hasArg(options::OPT_fbuiltin_module_map)) {
+  SmallString<128> BuiltinModuleMap(D.ResourceDir);
+  llvm::sys::path::append(BuiltinModuleMap, "include");
+  llvm::sys::path::append(BuiltinModuleMap, "module.modulemap");
+  if (llvm::sys::fs::exists(BuiltinModuleMap))
+CmdArgs.push_back(
+Args.MakeArgString("-fmodule-map-file=" + BuiltinModuleMap));
+}
+  } else {
+Args.ClaimAllArgs(options::OPT_fmodule_name_EQ);
+Args.ClaimAllArgs(options::OPT_fmodule_map_file);
+Args.ClaimAllArgs(options::OPT_fbuiltin_module_map);
   }
 
   // The -fmodule-file== form specifies the mapping of module


Index: clang/test/Driver/modules.m
===
--- clang/test/Driver/modules.m
+++ clang/test/Driver/modules.m
@@ -80,3 +80,6 @@
 
 // RUN: %clang -fno-modules -fmodules-validate-system-headers -### %s 2>&1 | FileCheck -check-prefix=VALIDATE_SYSTEM_FLAG %s
 // VALIDATE_SYSTEM_FLAG-NOT: -fmodules-validate-system-headers
+
+// RUN: %clang -fno-modules -fmodule-map-file=module.modulemap -### %s 2>&1 | FileCheck -check-prefix=MODULE_MAP_FILE %s
+// MODULE_MAP_FILE-NOT: -fmodule-map-file
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3726,25 +3726,29 @@
  options::OPT_fno_modules_validate_input_files_content,
  false))
   CmdArgs.push_back("-fvalidate-ast-input-files-content");
-  }
-
-  // -fmodule-name specifies the module that is currently being built (or
-  // used for header checking by -fmodule-maps).
-  Args.AddLastArg(CmdArgs, options::OPT_fmodule_name_EQ);
 
-  // -fmodule-map-file can be used to specify files containing module
-  // definitions.
-  Args.AddAllArgs(CmdArgs, options::OPT_fmodule_map_file);
-
-  // -fbuiltin-module-map can be used to load the clang
-  // builtin headers modulemap file.
-  if (Args.hasArg(options::OPT_fbuiltin_module_map)) {
-SmallString<128> BuiltinModuleMap(D.ResourceDir);
-llvm::sys::path::append(BuiltinModuleMap, "include");
-llvm::sys::path::append(BuiltinModuleMap, "module.modulemap");
-if (llvm::sys::fs::exists(BuiltinModuleMap))
-  CmdArgs.push_back(
-  Args.MakeArgString("-fmodule-map-file=" + BuiltinModuleMap));
+// -fmodule-name specif

[PATCH] D132795: [clang-tidy] Tweak diagnostics for bugprone-assign-in-if-condition

2022-08-27 Thread Nathan James via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
njames93 marked an inline comment as done.
Closed by commit rG32d88239ae65: [clang-tidy] Tweak diagnostics for 
bugprone-assign-in-if-condition (authored by njames93).

Changed prior to commit:
  https://reviews.llvm.org/D132795?vs=456144&id=456157#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132795

Files:
  clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.h
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/assignment-in-if-condition.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/assignment-in-if-condition.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/assignment-in-if-condition.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/assignment-in-if-condition.cpp
@@ -3,7 +3,7 @@
 void f(int arg) {
   int f = 3;
   if ((f = arg) || (f == (arg + 1)))
-  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
   {
 f = 5;
   }
@@ -12,7 +12,7 @@
 void f1(int arg) {
   int f = 3;
   if ((f == arg) || (f = (arg + 1)))
-  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
+  // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
   {
 f = 5;
   }
@@ -21,7 +21,7 @@
 void f2(int arg) {
   int f = 3;
   if (f = arg)
-  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
   {
 f = 5;
   }
@@ -32,7 +32,7 @@
 void f3(int arg) {
   int f = 3;
   if ((f == arg) || ((arg + 6 < f) && (f = v)))
-  // CHECK-MESSAGES: :[[@LINE-1]]:40: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
+  // CHECK-MESSAGES: :[[@LINE-1]]:42: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
   {
 f = 5;
   }
@@ -41,11 +41,11 @@
 void f4(int arg) {
   int f = 3;
   if ((f == arg) || ((arg + 6 < f) && ((f = v) || (f < 8
-  // CHECK-MESSAGES: :[[@LINE-1]]:41: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
+  // CHECK-MESSAGES: :[[@LINE-1]]:43: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
   {
 f = 5;
   } else if ((arg + 8 < f) && ((f = v) || (f < 8)))
-  // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
+  // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
   {
 f = 6;
   }
@@ -68,12 +68,12 @@
 f = 6;
   }
   if (bo = 3)
-  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
   {
 f = 7;
   }
   if ((arg == 3) || (bo = 6))
-  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
   {
 f = 8;
   }
Index: clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.h
===
--- clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.h
@@ -25,7 +25,7 @@
   : ClangTidyCheck(Name, Context) {}
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
-  void report(const Expr *E);
+  void report(const Expr *AssignmentExpr);
 };
 
 } // namespace bugprone
Index: clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
@@ -61,14 +61,18 @@
   Visitor(*this).TraverseAST(*Result.Context);
 }
 
-void Assignmen

[clang-tools-extra] 32d8823 - [clang-tidy] Tweak diagnostics for bugprone-assign-in-if-condition

2022-08-27 Thread Nathan James via cfe-commits

Author: Nathan James
Date: 2022-08-28T00:21:40+01:00
New Revision: 32d88239ae654239f16b516ee81ee9ff88b0ce07

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

LOG: [clang-tidy] Tweak diagnostics for bugprone-assign-in-if-condition

Currently the diagnostic is printed at the start of the assignment expression, 
This can be misleading.
Having the location for the diagnostic be the location of the assignment 
operator is much more intuitive.

Reviewed By: gribozavr2

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.h

clang-tools-extra/test/clang-tidy/checkers/bugprone/assignment-in-if-condition.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
index 05f0ae74282e..47a82e3c09e2 100644
--- a/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
@@ -61,14 +61,18 @@ void AssignmentInIfConditionCheck::check(
   Visitor(*this).TraverseAST(*Result.Context);
 }
 
-void AssignmentInIfConditionCheck::report(const Expr *MatchedDecl) {
-  diag(MatchedDecl->getBeginLoc(),
-   "an assignment within an 'if' condition is bug-prone");
-  diag(MatchedDecl->getBeginLoc(),
+void AssignmentInIfConditionCheck::report(const Expr *AssignmentExpr) {
+  SourceLocation OpLoc =
+  isa(AssignmentExpr)
+  ? cast(AssignmentExpr)->getOperatorLoc()
+  : cast(AssignmentExpr)->getOperatorLoc();
+
+  diag(OpLoc, "an assignment within an 'if' condition is bug-prone")
+  << AssignmentExpr->getSourceRange();
+  diag(OpLoc,
"if it should be an assignment, move it out of the 'if' condition",
DiagnosticIDs::Note);
-  diag(MatchedDecl->getBeginLoc(),
-   "if it is meant to be an equality check, change '=' to '=='",
+  diag(OpLoc, "if it is meant to be an equality check, change '=' to '=='",
DiagnosticIDs::Note);
 }
 

diff  --git 
a/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.h 
b/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.h
index f84ae93ed2eb..f49dda24c9a9 100644
--- a/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.h
@@ -25,7 +25,7 @@ class AssignmentInIfConditionCheck : public ClangTidyCheck {
   : ClangTidyCheck(Name, Context) {}
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
-  void report(const Expr *E);
+  void report(const Expr *AssignmentExpr);
 };
 
 } // namespace bugprone

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/assignment-in-if-condition.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/assignment-in-if-condition.cpp
index 20c30d73516b..ad0d360d99fe 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/assignment-in-if-condition.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/assignment-in-if-condition.cpp
@@ -3,7 +3,7 @@
 void f(int arg) {
   int f = 3;
   if ((f = arg) || (f == (arg + 1)))
-  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: an assignment within an 'if' 
condition is bug-prone [bugprone-assignment-in-if-condition]
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: an assignment within an 'if' 
condition is bug-prone [bugprone-assignment-in-if-condition]
   {
 f = 5;
   }
@@ -12,7 +12,7 @@ void f(int arg) {
 void f1(int arg) {
   int f = 3;
   if ((f == arg) || (f = (arg + 1)))
-  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: an assignment within an 'if' 
condition is bug-prone [bugprone-assignment-in-if-condition]
+  // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: an assignment within an 'if' 
condition is bug-prone [bugprone-assignment-in-if-condition]
   {
 f = 5;
   }
@@ -21,7 +21,7 @@ void f1(int arg) {
 void f2(int arg) {
   int f = 3;
   if (f = arg)
-  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: an assignment within an 'if' 
condition is bug-prone [bugprone-assignment-in-if-condition]
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: an assignment within an 'if' 
condition is bug-prone [bugprone-assignment-in-if-condition]
   {
 f = 5;
   }
@@ -32,7 +32,7 @@ volatile int v = 32;
 void f3(int arg) {
   int f = 3;
   if ((f == arg) || ((arg + 6 < f) && (f = v)))
-  // CHECK-MESSAGES: :[[@LINE-1]]:40: warning: an assignment within an 'if' 
condition is bug-prone [bugprone-assignment-in-if-condition]
+  // CHECK-MESSAGES: :[[@LINE-1]]:42: warni

[clang] aa7ce60 - [Clang] Avoid crashes when parsing using enum declarations

2022-08-27 Thread Shafik Yaghmour via cfe-commits

Author: Shafik Yaghmour
Date: 2022-08-27T15:18:36-07:00
New Revision: aa7ce60536a642e825d26d89b4a4347a36b63360

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

LOG: [Clang] Avoid crashes when parsing using enum declarations

In Parser::ParseUsingDeclaration(...) when we call ParseEnumSpecifier(...) it is
not calling SetTypeSpecError() on DS when it detects an error. That means that
DS is left set to TST_unspecified. When we then pass DS into
Sema::ActOnUsingEnumDeclaration(...) we hit an llvm_unreachable(...) since it
expects it to be one of three states TST_error, TST_enum or TST_typename.

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

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

Added: 
clang/test/Parser/cxx20-using-enum.cpp

Modified: 
clang/lib/Parse/ParseDecl.cpp
clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p9-0x.cpp
clang/test/CXX/drs/dr3xx.cpp
clang/test/Parser/recovery.cpp
clang/test/Sema/enum.c
clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp
clang/test/SemaCXX/enum-scoped.cpp

Removed: 




diff  --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 97a856a4a8f50..c502fc5e01019 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -4647,6 +4647,7 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, 
DeclSpec &DS,
 
 if (Spec.isSet() && Tok.isNot(tok::identifier)) {
   Diag(Tok, diag::err_expected) << tok::identifier;
+  DS.SetTypeSpecError();
   if (Tok.isNot(tok::l_brace)) {
 // Has no name and is not a definition.
 // Skip the rest of this declarator, up until the comma or semicolon.
@@ -4663,6 +4664,7 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, 
DeclSpec &DS,
   Tok.isNot(tok::colon)) {
 Diag(Tok, diag::err_expected_either) << tok::identifier << tok::l_brace;
 
+DS.SetTypeSpecError();
 // Skip the rest of this declarator, up until the comma or semicolon.
 SkipUntil(tok::comma, StopAtSemi);
 return;
@@ -4838,6 +4840,7 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, 
DeclSpec &DS,
   if (!Name && TUK != Sema::TUK_Definition) {
 Diag(Tok, diag::err_enumerator_unnamed_no_def);
 
+DS.SetTypeSpecError();
 // Skip the rest of this declarator, up until the comma or semicolon.
 SkipUntil(tok::comma, StopAtSemi);
 return;

diff  --git a/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p9-0x.cpp 
b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p9-0x.cpp
index 719aeeddebcc0..93fad2ff90ec9 100644
--- a/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p9-0x.cpp
+++ b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p9-0x.cpp
@@ -4,4 +4,4 @@
 // will necessarily be ill-formed as a trailing return type for a function
 // definition), and recover with a "type cannot be defined in a trailing return
 // type" error.
-auto j() -> enum { e3 }; // expected-error{{unnamed enumeration must be a 
definition}} expected-error {{expected a type}}
+auto j() -> enum { e3 }; // expected-error{{unnamed enumeration must be a 
definition}}

diff  --git a/clang/test/CXX/drs/dr3xx.cpp b/clang/test/CXX/drs/dr3xx.cpp
index 0278a7d7f4974..e6f7328dd4d6c 100644
--- a/clang/test/CXX/drs/dr3xx.cpp
+++ b/clang/test/CXX/drs/dr3xx.cpp
@@ -30,7 +30,7 @@ namespace dr301 { // dr301: yes
 typename T::template operator+ a; // expected-error {{typename 
specifier refers to a non-type template}} expected-error +{{}}
 // FIXME: This shouldn't say (null).
 class T::template operator+ b; // expected-error {{identifier 
followed by '<' indicates a class template specialization but (null) refers to 
a function template}}
-enum T::template operator+ c; // expected-error {{expected 
identifier}} expected-error {{does not declare anything}}
+enum T::template operator+ c; // expected-error {{expected 
identifier}}
 enum T::template operator+::E d; // expected-error {{qualified name 
refers into a specialization of function template 'T::template operator +'}} 
expected-error {{forward reference}}
 enum T::template X::E e;
 T::template operator+::foobar(); // expected-error {{qualified name 
refers into a specialization of function template 'T::template operator +'}}

diff  --git a/clang/test/Parser/cxx20-using-enum.cpp 
b/clang/test/Parser/cxx20-using-enum.cpp
new file mode 100644
index 0..d6744d3a91290
--- /dev/null
+++ b/clang/test/Parser/cxx20-using-enum.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+namespace GH57347 {
+namespace A {}
+
+void f() {
+  using enum A::+; // expected-error {{expected identifier}}
+  using enum; // expected-error {{expected identifier or '{'}}
+  using enum class; // expected-error {{expected identifier or '{'}}
+  using enum : bla

[PATCH] D132695: [Clang] Avoid crashes when parsing using enum declarations

2022-08-27 Thread Shafik Yaghmour via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaa7ce60536a6: [Clang] Avoid crashes when parsing using enum 
declarations (authored by shafik).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132695

Files:
  clang/lib/Parse/ParseDecl.cpp
  clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p9-0x.cpp
  clang/test/CXX/drs/dr3xx.cpp
  clang/test/Parser/cxx20-using-enum.cpp
  clang/test/Parser/recovery.cpp
  clang/test/Sema/enum.c
  clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp
  clang/test/SemaCXX/enum-scoped.cpp

Index: clang/test/SemaCXX/enum-scoped.cpp
===
--- clang/test/SemaCXX/enum-scoped.cpp
+++ clang/test/SemaCXX/enum-scoped.cpp
@@ -114,8 +114,7 @@
   long_enum_val = 1
 };
 
-enum : long x; // expected-error{{unnamed enumeration must be a definition}} \
-// expected-warning{{declaration does not declare anything}}
+enum : long x; // expected-error{{unnamed enumeration must be a definition}}
 
 void PR9333() {
   enum class scoped_enum { yes, no, maybe };
Index: clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp
===
--- clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp
+++ clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp
@@ -432,7 +432,7 @@
   a::b c; // expected-error {{qualified name refers into a specialization of variable template 'a'}}
 
   class a {}; // expected-error {{identifier followed by '<' indicates a class template specialization but 'a' refers to a variable template}}
-  enum a {}; // expected-error {{expected identifier or '{'}} expected-warning {{does not declare anything}}
+  enum a {}; // expected-error {{expected identifier or '{'}}
 }
 
 namespace PR18530 {
Index: clang/test/Sema/enum.c
===
--- clang/test/Sema/enum.c
+++ clang/test/Sema/enum.c
@@ -160,7 +160,7 @@
   } e;
 };
 
-enum struct GH42372_1 { // expected-error {{expected identifier or '{'}} expected-warning {{declaration does not declare anything}}
+enum struct GH42372_1 { // expected-error {{expected identifier or '{'}}
   One
 };
 
Index: clang/test/Parser/recovery.cpp
===
--- clang/test/Parser/recovery.cpp
+++ clang/test/Parser/recovery.cpp
@@ -209,7 +209,7 @@
 namespace InvalidEmptyNames {
 // These shouldn't crash, the diagnostics aren't important.
 struct ::, struct ::; // expected-error 2 {{expected identifier}} expected-error 2 {{declaration of anonymous struct must be a definition}} expected-warning {{declaration does not declare anything}}
-enum ::, enum ::; // expected-error 2 {{expected identifier}} expected-warning {{declaration does not declare anything}}
+enum ::, enum ::; // expected-error 2 {{expected identifier}}
 struct ::__super, struct ::__super; // expected-error 2 {{expected identifier}} expected-error 2 {{expected '::' after '__super'}}
 struct ::template foo, struct ::template bar; // expected-error 2 {{expected identifier}} expected-error 2 {{declaration of anonymous struct must be a definition}} expected-warning {{declaration does not declare anything}}
 struct ::foo struct::; // expected-error {{no struct named 'foo' in the global namespace}} expected-error {{expected identifier}} expected-error {{declaration of anonymous struct must be a definition}}
Index: clang/test/Parser/cxx20-using-enum.cpp
===
--- /dev/null
+++ clang/test/Parser/cxx20-using-enum.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+namespace GH57347 {
+namespace A {}
+
+void f() {
+  using enum A::+; // expected-error {{expected identifier}}
+  using enum; // expected-error {{expected identifier or '{'}}
+  using enum class; // expected-error {{expected identifier or '{'}}
+  using enum : blah; // expected-error {{unknown type name 'blah'}} expected-error {{unnamed enumeration must be a definition}}
+}
+}
Index: clang/test/CXX/drs/dr3xx.cpp
===
--- clang/test/CXX/drs/dr3xx.cpp
+++ clang/test/CXX/drs/dr3xx.cpp
@@ -30,7 +30,7 @@
 typename T::template operator+ a; // expected-error {{typename specifier refers to a non-type template}} expected-error +{{}}
 // FIXME: This shouldn't say (null).
 class T::template operator+ b; // expected-error {{identifier followed by '<' indicates a class template specialization but (null) refers to a function template}}
-enum T::template operator+ c; // expected-error {{expected identifier}} expected-error {{does not declare anything}}
+enum T::template operator+ c; // expected-error {{expected identifier}}
 enum T::template operator+::E d; // expected-error {{qualified name refers into a 

[PATCH] D132795: [clang-tidy] Tweak diagnostics for bugprone-assign-in-if-condition

2022-08-27 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 accepted this revision.
gribozavr2 added inline comments.
This revision is now accepted and ready to land.



Comment at: 
clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp:64
 
 void AssignmentInIfConditionCheck::report(const Expr *MatchedDecl) {
+  SourceLocation OpLoc =

Drive-by comment -- an Expr is not a Decl (feel free to defer to a separate 
patch).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132795

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


[clang] 44a06b5 - [clang-format] Rework removeBraces() in Format.cpp

2022-08-27 Thread via cfe-commits

Author: owenca
Date: 2022-08-27T14:10:24-07:00
New Revision: 44a06b51b2ce2c75ec327902b7ddd1172e54bc8f

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

LOG: [clang-format] Rework removeBraces() in Format.cpp

Fixes #57373.

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index fd6a1799578d8..c2c020ea7ca85 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1902,31 +1902,30 @@ class BracesRemover : public TokenAnalyzer {
   void removeBraces(SmallVectorImpl &Lines,
 tooling::Replacements &Result) {
 const auto &SourceMgr = Env.getSourceManager();
-bool EndsWithComment = false;
-for (AnnotatedLine *Line : Lines) {
+const auto End = Lines.end();
+for (auto I = Lines.begin(); I != End; ++I) {
+  const auto Line = *I;
   removeBraces(Line->Children, Result);
-  if (Line->Affected) {
-for (FormatToken *Token = Line->First; Token && !Token->Finalized;
- Token = Token->Next) {
-  if (!Token->Optional)
-continue;
-  assert(Token->isOneOf(tok::l_brace, tok::r_brace));
-  assert(Token->Previous || Token == Line->First);
-  const FormatToken *Next = Token->Next;
-  assert(Next || Token == Line->Last);
-  const auto Start =
-  (!Token->Previous && EndsWithComment) ||
-  (Next && !(Next->isOneOf(tok::kw_else, tok::comment) &&
- Next->NewlinesBefore > 0))
-  ? Token->Tok.getLocation()
-  : Token->WhitespaceRange.getBegin();
-  const auto Range =
-  CharSourceRange::getCharRange(Start, Token->Tok.getEndLoc());
-  cantFail(Result.add(tooling::Replacement(SourceMgr, Range, "")));
-}
+  if (!Line->Affected)
+continue;
+  const auto NextLine = I + 1 == End ? nullptr : I[1];
+  for (auto Token = Line->First; Token && !Token->Finalized;
+   Token = Token->Next) {
+if (!Token->Optional)
+  continue;
+assert(Token->isOneOf(tok::l_brace, tok::r_brace));
+auto Next = Token->Next;
+assert(Next || Token == Line->Last);
+if (!Next && NextLine)
+  Next = NextLine->First;
+const auto Start =
+Next && Next->NewlinesBefore == 0 && Next->isNot(tok::eof)
+? Token->Tok.getLocation()
+: Token->WhitespaceRange.getBegin();
+const auto Range =
+CharSourceRange::getCharRange(Start, Token->Tok.getEndLoc());
+cantFail(Result.add(tooling::Replacement(SourceMgr, Range, "")));
   }
-  assert(Line->Last);
-  EndsWithComment = Line->Last->is(tok::comment);
 }
   }
 };

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 4879b0e06bd38..6abe155c388da 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -26005,6 +26005,14 @@ TEST_F(FormatTest, RemoveBraces) {
"}",
Style);
 
+  verifyFormat("if (a) // comment\n"
+   "  b = 1;",
+   "if (a) // comment\n"
+   "{\n"
+   "  b = 1;\n"
+   "}",
+   Style);
+
   Style.ColumnLimit = 20;
 
   verifyFormat("int ab = [](int i) {\n"



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


[PATCH] D132797: [clangd] Support renaming virtual methods

2022-08-27 Thread Tom Praschan via Phabricator via cfe-commits
tom-anders created this revision.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
tom-anders requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Fixes https://github.com/clangd/clangd/issues/706


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132797

Files:
  clang-tools-extra/clangd/refactor/Rename.cpp
  clang-tools-extra/clangd/unittests/RenameTests.cpp

Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -886,12 +886,6 @@
  @end
)cpp",
"not a supported kind", HeaderFile},
-  {R"cpp(// FIXME: rename virtual/override methods is not supported yet.
- struct A {
-  virtual void f^oo() {}
- };
-  )cpp",
-   "not a supported kind", !HeaderFile},
   {R"cpp(
  void foo(int);
  void foo(char);
@@ -1490,6 +1484,37 @@
 }
   )cpp",
   },
+  {
+  // virtual methods.
+  R"cpp(
+class Base {
+  virtual void [[foo]]();
+};
+class Derived1 : public Base {
+  void [[f^oo]]() override;
+};
+class NotDerived {
+  void foo() {};
+}
+  )cpp",
+  R"cpp(
+#include "foo.h"
+void Base::[[foo]]() {}
+void Derived1::[[foo]]() {}
+
+class Derived2 : public Derived1 {
+  void [[foo]]() override {};
+};
+
+void func(Base* b, Derived1* d1, 
+  Derived2* d2, NotDerived* nd) {
+  b->[[foo]]();
+  d1->[[foo]]();
+  d2->[[foo]]();
+  nd->foo();
+}
+  )cpp",
+  },
   {
   // rename on constructor and destructor.
   R"cpp(
Index: clang-tools-extra/clangd/refactor/Rename.cpp
===
--- clang-tools-extra/clangd/refactor/Rename.cpp
+++ clang-tools-extra/clangd/refactor/Rename.cpp
@@ -214,13 +214,6 @@
   IsMainFileOnly))
 return ReasonToReject::NonIndexable;
 
-
-  // FIXME: Renaming virtual methods requires to rename all overridens in
-  // subclasses, our index doesn't have this information.
-  if (const auto *S = llvm::dyn_cast(&RenameDecl)) {
-if (S->isVirtual())
-  return ReasonToReject::UnsupportedSymbol;
-  }
   return None;
 }
 
@@ -551,6 +544,20 @@
   return R;
 }
 
+namespace {
+void recursivelyInsertOverrides(const SymbolID &Base,
+llvm::DenseSet &IDs,
+const SymbolIndex &Index) {
+  RelationsRequest Req;
+  Req.Predicate = RelationKind::OverriddenBy;
+  Req.Subjects = {Base};
+  Index.relations(Req, [&](const SymbolID &, const Symbol &Override) {
+IDs.insert(Override.ID);
+recursivelyInsertOverrides(Override.ID, IDs, Index);
+  });
+}
+} // namespace
+
 // Return all rename occurrences (using the index) outside of the main file,
 // grouped by the absolute file path.
 llvm::Expected>>
@@ -561,6 +568,10 @@
   RefsRequest RQuest;
   RQuest.IDs.insert(getSymbolID(&RenameDecl));
 
+  if (const auto *MethodDecl = llvm::dyn_cast(&RenameDecl))
+if (MethodDecl->isVirtual())
+  recursivelyInsertOverrides(*RQuest.IDs.begin(), RQuest.IDs, Index);
+
   // Absolute file path => rename occurrences in that file.
   llvm::StringMap> AffectedFiles;
   bool HasMore = Index.refs(RQuest, [&](const Ref &R) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D132719: [clang-format] Rework removeBraces() in Format.cpp

2022-08-27 Thread Owen Pan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG44a06b51b2ce: [clang-format] Rework removeBraces() in 
Format.cpp (authored by owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132719

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -26005,6 +26005,14 @@
"}",
Style);
 
+  verifyFormat("if (a) // comment\n"
+   "  b = 1;",
+   "if (a) // comment\n"
+   "{\n"
+   "  b = 1;\n"
+   "}",
+   Style);
+
   Style.ColumnLimit = 20;
 
   verifyFormat("int ab = [](int i) {\n"
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -1902,31 +1902,30 @@
   void removeBraces(SmallVectorImpl &Lines,
 tooling::Replacements &Result) {
 const auto &SourceMgr = Env.getSourceManager();
-bool EndsWithComment = false;
-for (AnnotatedLine *Line : Lines) {
+const auto End = Lines.end();
+for (auto I = Lines.begin(); I != End; ++I) {
+  const auto Line = *I;
   removeBraces(Line->Children, Result);
-  if (Line->Affected) {
-for (FormatToken *Token = Line->First; Token && !Token->Finalized;
- Token = Token->Next) {
-  if (!Token->Optional)
-continue;
-  assert(Token->isOneOf(tok::l_brace, tok::r_brace));
-  assert(Token->Previous || Token == Line->First);
-  const FormatToken *Next = Token->Next;
-  assert(Next || Token == Line->Last);
-  const auto Start =
-  (!Token->Previous && EndsWithComment) ||
-  (Next && !(Next->isOneOf(tok::kw_else, tok::comment) &&
- Next->NewlinesBefore > 0))
-  ? Token->Tok.getLocation()
-  : Token->WhitespaceRange.getBegin();
-  const auto Range =
-  CharSourceRange::getCharRange(Start, Token->Tok.getEndLoc());
-  cantFail(Result.add(tooling::Replacement(SourceMgr, Range, "")));
-}
+  if (!Line->Affected)
+continue;
+  const auto NextLine = I + 1 == End ? nullptr : I[1];
+  for (auto Token = Line->First; Token && !Token->Finalized;
+   Token = Token->Next) {
+if (!Token->Optional)
+  continue;
+assert(Token->isOneOf(tok::l_brace, tok::r_brace));
+auto Next = Token->Next;
+assert(Next || Token == Line->Last);
+if (!Next && NextLine)
+  Next = NextLine->First;
+const auto Start =
+Next && Next->NewlinesBefore == 0 && Next->isNot(tok::eof)
+? Token->Tok.getLocation()
+: Token->WhitespaceRange.getBegin();
+const auto Range =
+CharSourceRange::getCharRange(Start, Token->Tok.getEndLoc());
+cantFail(Result.add(tooling::Replacement(SourceMgr, Range, "")));
   }
-  assert(Line->Last);
-  EndsWithComment = Line->Last->is(tok::comment);
 }
   }
 };


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -26005,6 +26005,14 @@
"}",
Style);
 
+  verifyFormat("if (a) // comment\n"
+   "  b = 1;",
+   "if (a) // comment\n"
+   "{\n"
+   "  b = 1;\n"
+   "}",
+   Style);
+
   Style.ColumnLimit = 20;
 
   verifyFormat("int ab = [](int i) {\n"
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -1902,31 +1902,30 @@
   void removeBraces(SmallVectorImpl &Lines,
 tooling::Replacements &Result) {
 const auto &SourceMgr = Env.getSourceManager();
-bool EndsWithComment = false;
-for (AnnotatedLine *Line : Lines) {
+const auto End = Lines.end();
+for (auto I = Lines.begin(); I != End; ++I) {
+  const auto Line = *I;
   removeBraces(Line->Children, Result);
-  if (Line->Affected) {
-for (FormatToken *Token = Line->First; Token && !Token->Finalized;
- Token = Token->Next) {
-  if (!Token->Optional)
-continue;
-  assert(Token->isOneOf(tok::l_brace, tok::r_brace));
-  assert(Token->Previous || Token == Line->First);
-  const FormatToken *Next = Token->Next;
-  assert(Next || Token == Line->Last);
-  const auto Start =
-

[PATCH] D132719: [clang-format] Rework removeBraces() in Format.cpp

2022-08-27 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/lib/Format/Format.cpp:1914
-  assert(Token->isOneOf(tok::l_brace, tok::r_brace));
-  assert(Token->Previous || Token == Line->First);
-  const FormatToken *Next = Token->Next;

owenpan wrote:
> Deleted by mistake. Will add it back before landing.
Actually, it can (and should) be deleted as it was related to line 1918 below.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132719

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


[PATCH] D132640: [clang-tidy] Fix modernize-use-emplace to support alias cases

2022-08-27 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

LGTM, just with a small nit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132640

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


[PATCH] D132795: [clang-tidy] Tweak diagnostics for bugprone-assign-in-if-condition

2022-08-27 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 456144.
njames93 added a comment.

Remove unnecessary includes added.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132795

Files:
  clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/assignment-in-if-condition.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/bugprone/assignment-in-if-condition.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/bugprone/assignment-in-if-condition.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/bugprone/assignment-in-if-condition.cpp
@@ -3,7 +3,7 @@
 void f(int arg) {
   int f = 3;
   if ((f = arg) || (f == (arg + 1)))
-  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: an assignment within an 'if' 
condition is bug-prone [bugprone-assignment-in-if-condition]
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: an assignment within an 'if' 
condition is bug-prone [bugprone-assignment-in-if-condition]
   {
 f = 5;
   }
@@ -12,7 +12,7 @@
 void f1(int arg) {
   int f = 3;
   if ((f == arg) || (f = (arg + 1)))
-  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: an assignment within an 'if' 
condition is bug-prone [bugprone-assignment-in-if-condition]
+  // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: an assignment within an 'if' 
condition is bug-prone [bugprone-assignment-in-if-condition]
   {
 f = 5;
   }
@@ -21,7 +21,7 @@
 void f2(int arg) {
   int f = 3;
   if (f = arg)
-  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: an assignment within an 'if' 
condition is bug-prone [bugprone-assignment-in-if-condition]
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: an assignment within an 'if' 
condition is bug-prone [bugprone-assignment-in-if-condition]
   {
 f = 5;
   }
@@ -32,7 +32,7 @@
 void f3(int arg) {
   int f = 3;
   if ((f == arg) || ((arg + 6 < f) && (f = v)))
-  // CHECK-MESSAGES: :[[@LINE-1]]:40: warning: an assignment within an 'if' 
condition is bug-prone [bugprone-assignment-in-if-condition]
+  // CHECK-MESSAGES: :[[@LINE-1]]:42: warning: an assignment within an 'if' 
condition is bug-prone [bugprone-assignment-in-if-condition]
   {
 f = 5;
   }
@@ -41,11 +41,11 @@
 void f4(int arg) {
   int f = 3;
   if ((f == arg) || ((arg + 6 < f) && ((f = v) || (f < 8
-  // CHECK-MESSAGES: :[[@LINE-1]]:41: warning: an assignment within an 'if' 
condition is bug-prone [bugprone-assignment-in-if-condition]
+  // CHECK-MESSAGES: :[[@LINE-1]]:43: warning: an assignment within an 'if' 
condition is bug-prone [bugprone-assignment-in-if-condition]
   {
 f = 5;
   } else if ((arg + 8 < f) && ((f = v) || (f < 8)))
-  // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: an assignment within an 'if' 
condition is bug-prone [bugprone-assignment-in-if-condition]
+  // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: an assignment within an 'if' 
condition is bug-prone [bugprone-assignment-in-if-condition]
   {
 f = 6;
   }
@@ -68,12 +68,12 @@
 f = 6;
   }
   if (bo = 3)
-  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: an assignment within an 'if' 
condition is bug-prone [bugprone-assignment-in-if-condition]
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: an assignment within an 'if' 
condition is bug-prone [bugprone-assignment-in-if-condition]
   {
 f = 7;
   }
   if ((arg == 3) || (bo = 6))
-  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: an assignment within an 'if' 
condition is bug-prone [bugprone-assignment-in-if-condition]
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: an assignment within an 'if' 
condition is bug-prone [bugprone-assignment-in-if-condition]
   {
 f = 8;
   }
Index: clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
@@ -62,13 +62,17 @@
 }
 
 void AssignmentInIfConditionCheck::report(const Expr *MatchedDecl) {
-  diag(MatchedDecl->getBeginLoc(),
-   "an assignment within an 'if' condition is bug-prone");
-  diag(MatchedDecl->getBeginLoc(),
+  SourceLocation OpLoc =
+  isa(MatchedDecl)
+  ? cast(MatchedDecl)->getOperatorLoc()
+  : cast(MatchedDecl)->getOperatorLoc();
+
+  diag(OpLoc, "an assignment within an 'if' condition is bug-prone")
+  << MatchedDecl->getSourceRange();
+  diag(OpLoc,
"if it should be an assignment, move it out of the 'if' condition",
DiagnosticIDs::Note);
-  diag(MatchedDecl->getBeginLoc(),
-   "if it is meant to be an equality check, change '=' to '=='",
+  diag(OpLoc, "if it is meant to be an equality check, change '=' to '=='",
DiagnosticIDs::Note);
 }
 


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/assignment-in-if-condition.cpp

[PATCH] D132795: [clang-tidy] Tweak diagnostics for bugprone-assign-in-if-condition

2022-08-27 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added reviewers: aaron.ballman, gribozavr2, LegalizeAdulthood, 
dodohand.
Herald added subscribers: carlosgalvezp, xazax.hun.
Herald added a project: All.
njames93 requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Currently the diagnostic is printed at the start of the assignment expression, 
This can be misleading.
Having the location for the diagnostic be the location of the assignment 
operator is much more intuitive.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132795

Files:
  clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/assignment-in-if-condition.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/assignment-in-if-condition.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/assignment-in-if-condition.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/assignment-in-if-condition.cpp
@@ -3,7 +3,7 @@
 void f(int arg) {
   int f = 3;
   if ((f = arg) || (f == (arg + 1)))
-  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
   {
 f = 5;
   }
@@ -12,7 +12,7 @@
 void f1(int arg) {
   int f = 3;
   if ((f == arg) || (f = (arg + 1)))
-  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
+  // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
   {
 f = 5;
   }
@@ -21,7 +21,7 @@
 void f2(int arg) {
   int f = 3;
   if (f = arg)
-  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
   {
 f = 5;
   }
@@ -32,7 +32,7 @@
 void f3(int arg) {
   int f = 3;
   if ((f == arg) || ((arg + 6 < f) && (f = v)))
-  // CHECK-MESSAGES: :[[@LINE-1]]:40: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
+  // CHECK-MESSAGES: :[[@LINE-1]]:42: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
   {
 f = 5;
   }
@@ -41,11 +41,11 @@
 void f4(int arg) {
   int f = 3;
   if ((f == arg) || ((arg + 6 < f) && ((f = v) || (f < 8
-  // CHECK-MESSAGES: :[[@LINE-1]]:41: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
+  // CHECK-MESSAGES: :[[@LINE-1]]:43: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
   {
 f = 5;
   } else if ((arg + 8 < f) && ((f = v) || (f < 8)))
-  // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
+  // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
   {
 f = 6;
   }
@@ -68,12 +68,12 @@
 f = 6;
   }
   if (bo = 3)
-  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
   {
 f = 7;
   }
   if ((arg == 3) || (bo = 6))
-  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: an assignment within an 'if' condition is bug-prone [bugprone-assignment-in-if-condition]
   {
 f = 8;
   }
Index: clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
@@ -8,6 +8,8 @@
 
 #include "AssignmentInIfConditionCheck.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/ExprCXX.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 
@@ -62,13 +64,17 @@
 }
 
 void AssignmentInIfConditionCheck::report(const Expr *MatchedDecl) {
-  diag(MatchedDecl->getBeginLoc(),
-   "an assignment within an 'if' condition is bug-prone");
-  diag(MatchedDecl->getBeginLoc(),
+  SourceLocation OpLoc =
+  isa(MatchedDecl)
+  ? cast(MatchedDecl)->getOperatorLoc()
+  : cast(MatchedDecl)->getOperat

[PATCH] D131979: [clang][UBSan] Fix __builtin_assume_aligned crash

2022-08-27 Thread Wang Yihan via Phabricator via cfe-commits
yihanaa updated this revision to Diff 456142.
yihanaa added a comment.

Format code and recovery builtin-functions.cpp(Wrongly modified in the last 
update)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131979

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtin-assume-aligned.c
  clang/test/CodeGen/catch-alignment-assumption-array.c
  clang/test/CodeGen/catch-alignment-assumption-ignorelist.c

Index: clang/test/CodeGen/catch-alignment-assumption-ignorelist.c
===
--- clang/test/CodeGen/catch-alignment-assumption-ignorelist.c
+++ clang/test/CodeGen/catch-alignment-assumption-ignorelist.c
@@ -26,3 +26,9 @@
 void *ignore_volatiles(volatile void * x) {
   return __builtin_assume_aligned(x, 1);
 }
+
+// CHECK-LABEL: ignore_array_volatiles
+void *ignore_array_volatiles() {
+  volatile int arr[] = {1};
+  return __builtin_assume_aligned(arr, 4);
+}
Index: clang/test/CodeGen/catch-alignment-assumption-array.c
===
--- /dev/null
+++ clang/test/CodeGen/catch-alignment-assumption-array.c
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -no-opaque-pointers -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s
+// RUN: %clang_cc1 -no-opaque-pointers -fsanitize=alignment -fno-sanitize-recover=alignment -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_alignment_assumption" --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-ANYRECOVER,CHECK-SANITIZE-NORECOVER,CHECK-SANITIZE-UNREACHABLE
+// RUN: %clang_cc1 -no-opaque-pointers -fsanitize=alignment -fsanitize-recover=alignment -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_alignment_assumption" --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-ANYRECOVER,CHECK-SANITIZE-RECOVER
+// RUN: %clang_cc1 -no-opaque-pointers -fsanitize=alignment -fsanitize-trap=alignment -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_alignment_assumption" --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-TRAP,CHECK-SANITIZE-UNREACHABLE
+
+// CHECK-SANITIZE-ANYRECOVER: @[[CHAR:.*]] = {{.*}} c"'char *'\00" }
+// CHECK-SANITIZE-ANYRECOVER: @[[ALIGNMENT_ASSUMPTION:.*]] = {{.*}}, i32 31, i32 35 }, {{.*}}* @[[CHAR]] }
+
+void *caller(void) {
+  char str[] = "";
+  // CHECK:   define{{.*}}
+  // CHECK-NEXT:  entry:
+  // CHECK-NEXT:%[[STR:.*]] = alloca [1 x i8], align 1
+  // CHECK-NEXT:%[[BITCAST:.*]] = bitcast [1 x i8]* %[[STR]] to i8*
+  // CHECK-NEXT:call void @llvm.memset.p0i8.i64(i8* align 1 %[[BITCAST]], i8 0, i64 1, i1 false)
+  // CHECK-NEXT:%[[ARRAYDECAY:.*]] = getelementptr inbounds [1 x i8], [1 x i8]* %[[STR]], i64 0, i64 0
+  // CHECK-SANITIZE-NEXT:   %[[PTRINT:.*]] = ptrtoint i8* %[[ARRAYDECAY]] to i64
+  // CHECK-SANITIZE-NEXT:   %[[MASKEDPTR:.*]] = and i64 %[[PTRINT]], 0
+  // CHECK-SANITIZE-NEXT:   %[[MASKCOND:.*]] = icmp eq i64 %[[MASKEDPTR]], 0
+  // CHECK-SANITIZE-NEXT:   %[[PTRINT_DUP:.*]] = ptrtoint i8* %[[ARRAYDECAY]] to i64, !nosanitize
+  // CHECK-SANITIZE-NEXT:   br i1 %[[MASKCOND]], label %[[CONT:.*]], label %[[HANDLER_ALIGNMENT_ASSUMPTION:[^,]+]],{{.*}} !nosanitize
+  // CHECK-SANITIZE:  [[HANDLER_ALIGNMENT_ASSUMPTION]]:
+  // CHECK-SANITIZE-NORECOVER-NEXT: call void @__ubsan_handle_alignment_assumption_abort(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 1, i64 0){{.*}}, !nosanitize
+  // CHECK-SANITIZE-RECOVER-NEXT:   call void @__ubsan_handle_alignment_assumption(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 1, i64 0){{.*}}, !nosanitize
+  // CHECK-SANITIZE-TRAP-NEXT:  call void @llvm.ubsantrap(i8 23){{.*}}, !nosanitize
+  // CHECK-SANITIZE-UNREACHABLE-NEXT:   unreachable, !nosanitize
+  // CHECK-SANITIZE:  [[CONT]]:
+  // CHECK-NEXT:call void @llvm.assume(i1 true) [ "align"(i8* %[[ARRAYDECAY]], i64 1) ] 
+  // CHECK-NEXT:ret i8* %[[ARRAYDECAY]]
+  // CHECK-NEXT:  }
+  return __builtin_assume_aligned(str, 1);
+}
Index: clang/test/CodeGen/builtin-assume-aligned.c
===
--- clang/test/CodeGen/builtin-assume-aligned.c
+++ clang/test/CodeGen/builtin-assume-aligned.c
@@ -124,3 +124,11 @@
   a = __builtin_assume_aligned(a, 4294967296);
 return a[0];
 }
+
+// CHECK-LABEL: @test8()
+// CHECK-NEXT:  entry:
+// CHECK-NEXT

[PATCH] D131714: [compiler-rt][builtins] Add compiler flags to catch potential errors that can lead to security vulnerabilities

2022-08-27 Thread Lei Wang via Phabricator via cfe-commits
wlei added a comment.

Hi @ahatanak

This or its child diff broke our internal build, I saw it was reverted but the 
reapplied 
diff(https://github.com/llvm/llvm-project/commit/2e9df860468425645dcd1b241c5dbf76c072e314)
 still broke our build.

see the log:
(1)floatundidf.S.o :

  FAILED: 
projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-x86_64.dir/x86_64/floatundidf.S.o
  /home/engshare/third-party2/gcc/11.x/centos7-native/886b5eb/bin/gcc 
-DVISIBILITY_HIDDEN -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-Iprojects/compiler-rt/lib/builtins 
-I/home/engshare/third-party2/llvm-fb/12/src/llvm-project/compiler-rt/lib/builtins
 -Iinclude 
-I/home/engshare/third-party2/llvm-fb/12/src/llvm-project/llvm/include 
-fdebug-prefix-map=/home/engshare/third-party2/llvm-fb/12/src/llvm-project=/home/engshare/third-party2/llvm-fb/12/src/llvm-project
 
-fdebug-prefix-map=/home/engshare/third-party2/llvm-fb/12/src/build-platform010/build=/home/engshare/third-party2/llvm-fb/12/src/llvm-project
 -fPIC -O3 -DNDEBUG -m64 -fno-lto -Werror=array-bounds -Werror=uninitialized 
-Werror=shadow -Werror=empty-body -Werror=sizeof-pointer-memaccess 
-Werror=sizeof-array-argument -Werror=memset-transposed-args 
-Werror=format-security -std=c11 -MD -MT 
projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-x86_64.dir/x86_64/floatundidf.S.o
 -MF 
projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-x86_64.dir/x86_64/floatundidf.S.o.d
 -o 
projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-x86_64.dir/x86_64/floatundidf.S.o
 -c 
/home/engshare/third-party2/llvm-fb/12/src/llvm-project/compiler-rt/lib/builtins/x86_64/floatundidf.S
  cc1: error: '-Wformat-security' ignored without '-Wformat' 
[-Werror=format-security]
  cc1: some warnings being treated as errors
  [794/5411] 
/home/engshare/third-party2/gcc/11.x/centos7-native/886b5eb/bin/gcc 
-DVISIBILITY_HIDDEN -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-Iprojects/compiler-rt/lib/builtins 
-I/home/engshare/third-party2/llvm-fb/12/src/llvm-project/compiler-rt/lib/builtins
 -Iinclude 
-I/home/engshare/third-party2/llvm-fb/12/src/llvm-project/llvm/include 
-fdebug-prefix-map=/home/engshare/third-party2/llvm-fb/12/src/llvm-project=/home/engshare/third-party2/llvm-fb/12/src/llvm-project
 
-fdebug-prefix-map=/home/engshare/third-party2/llvm-fb/12/src/build-platform010/build=/home/engshare/third-party2/llvm-fb/12/src/llvm-project
 -fPIC -O3 -DNDEBUG -m64 -fno-lto -Werror=array-bounds -Werror=uninitialized 
-Werror=shadow -Werror=empty-body -Werror=sizeof-pointer-memaccess 
-Werror=sizeof-array-argument -Werror=memset-transposed-args 
-Werror=format-security -std=c11 -MD -MT 
projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-x86_64.dir/x86_64/floatundisf.S.o
 -MF 
projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-x86_64.dir/x86_64/floatundisf.S.o.d
 -o 
projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-x86_64.dir/x86_64/floatundisf.S.o
 -c 
/home/engshare/third-party2/llvm-fb/12/src/llvm-project/compiler-rt/lib/builtins/x86_64/floatundisf.S
  FAILED: 
projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-x86_64.dir/x86_64/floatundisf.S.o
  /home/engshare/third-party2/gcc/11.x/centos7-native/886b5eb/bin/gcc 
-DVISIBILITY_HIDDEN -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-Iprojects/compiler-rt/lib/builtins 
-I/home/engshare/third-party2/llvm-fb/12/src/llvm-project/compiler-rt/lib/builtins
 -Iinclude 
-I/home/engshare/third-party2/llvm-fb/12/src/llvm-project/llvm/include 
-fdebug-prefix-map=/home/engshare/third-party2/llvm-fb/12/src/llvm-project=/home/engshare/third-party2/llvm-fb/12/src/llvm-project
 
-fdebug-prefix-map=/home/engshare/third-party2/llvm-fb/12/src/build-platform010/build=/home/engshare/third-party2/llvm-fb/12/src/llvm-project
 -fPIC -O3 -DNDEBUG -m64 -fno-lto -Werror=array-bounds -Werror=uninitialized 
-Werror=shadow -Werror=empty-body -Werror=sizeof-pointer-memaccess 
-Werror=sizeof-array-argument -Werror=memset-transposed-args 
-Werror=format-security -std=c11 -MD -MT 
projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-x86_64.dir/x86_64/floatundisf.S.o
 -MF 
projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-x86_64.dir/x86_64/floatundisf.S.o.d
 -o 
projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-x86_64.dir/x86_64/floatundisf.S.o
 -c 
/home/engshare/third-party2/llvm-fb/12/src/llvm-project/compiler-rt/lib/builtins/x86_64/floatundisf.S
  cc1: error: '-Wformat-security' ignored without '-Wformat' 
[-Werror=format-security]

(2) floatundixf.S.o

  FAILED: 
projects/compiler-rt/lib/builtins/CMakeFiles/clang_rt.builtins-x86_64.dir/x86_64/floatundixf.S.o
 
  /home/engshare/third-party2/gcc/11.x/centos7-native/886b5eb/bin/gcc 
-DVISIBILITY_HIDDEN -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-Iprojects/

[PATCH] D131979: [clang][UBSan] Fix __builtin_assume_aligned crash

2022-08-27 Thread Wang Yihan via Phabricator via cfe-commits
yihanaa updated this revision to Diff 456140.
yihanaa added a comment.

Keep same behavior with current clang, don't emit an error when 1st arg is 
volatile qualified.

Ignore the implicit cast from user-written-type to 'const void *' on the 1st 
arg, because CodeGen need user-written-type to generate correct TypeDescriptor 
(this class in compiler-rt/UBSan), then, clang will emit cast instruction which 
cast type from user-written-type to VoidPtr in CodeGen.

But I still have some questions, for example: if someone pass a array type(e.g. 
char[1]) as the 1st arg, what should the correct TypeDescriptor? char[1] OR 
char *, clang will generate char * in this patch, you are experts and what do 
you all think?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131979

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Analysis/builtin-functions.cpp
  clang/test/CodeGen/builtin-assume-aligned.c
  clang/test/CodeGen/catch-alignment-assumption-array.c
  clang/test/CodeGen/catch-alignment-assumption-ignorelist.c

Index: clang/test/CodeGen/catch-alignment-assumption-ignorelist.c
===
--- clang/test/CodeGen/catch-alignment-assumption-ignorelist.c
+++ clang/test/CodeGen/catch-alignment-assumption-ignorelist.c
@@ -26,3 +26,9 @@
 void *ignore_volatiles(volatile void * x) {
   return __builtin_assume_aligned(x, 1);
 }
+
+// CHECK-LABEL: ignore_array_volatiles
+void *ignore_array_volatiles() {
+  volatile int arr[] = {1};
+  return __builtin_assume_aligned(arr, 4);
+}
Index: clang/test/CodeGen/catch-alignment-assumption-array.c
===
--- /dev/null
+++ clang/test/CodeGen/catch-alignment-assumption-array.c
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -no-opaque-pointers -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s
+// RUN: %clang_cc1 -no-opaque-pointers -fsanitize=alignment -fno-sanitize-recover=alignment -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_alignment_assumption" --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-ANYRECOVER,CHECK-SANITIZE-NORECOVER,CHECK-SANITIZE-UNREACHABLE
+// RUN: %clang_cc1 -no-opaque-pointers -fsanitize=alignment -fsanitize-recover=alignment -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_alignment_assumption" --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-ANYRECOVER,CHECK-SANITIZE-RECOVER
+// RUN: %clang_cc1 -no-opaque-pointers -fsanitize=alignment -fsanitize-trap=alignment -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_alignment_assumption" --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-TRAP,CHECK-SANITIZE-UNREACHABLE
+
+// CHECK-SANITIZE-ANYRECOVER: @[[CHAR:.*]] = {{.*}} c"'char *'\00" }
+// CHECK-SANITIZE-ANYRECOVER: @[[ALIGNMENT_ASSUMPTION:.*]] = {{.*}}, i32 31, i32 35 }, {{.*}}* @[[CHAR]] }
+
+void *caller(void) {
+  char str[] = "";
+  // CHECK:   define{{.*}}
+  // CHECK-NEXT:  entry:
+  // CHECK-NEXT:%[[STR:.*]] = alloca [1 x i8], align 1
+  // CHECK-NEXT:%[[BITCAST:.*]] = bitcast [1 x i8]* %[[STR]] to i8*
+  // CHECK-NEXT:call void @llvm.memset.p0i8.i64(i8* align 1 %[[BITCAST]], i8 0, i64 1, i1 false)
+  // CHECK-NEXT:%[[ARRAYDECAY:.*]] = getelementptr inbounds [1 x i8], [1 x i8]* %[[STR]], i64 0, i64 0
+  // CHECK-SANITIZE-NEXT:   %[[PTRINT:.*]] = ptrtoint i8* %[[ARRAYDECAY]] to i64
+  // CHECK-SANITIZE-NEXT:   %[[MASKEDPTR:.*]] = and i64 %[[PTRINT]], 0
+  // CHECK-SANITIZE-NEXT:   %[[MASKCOND:.*]] = icmp eq i64 %[[MASKEDPTR]], 0
+  // CHECK-SANITIZE-NEXT:   %[[PTRINT_DUP:.*]] = ptrtoint i8* %[[ARRAYDECAY]] to i64, !nosanitize
+  // CHECK-SANITIZE-NEXT:   br i1 %[[MASKCOND]], label %[[CONT:.*]], label %[[HANDLER_ALIGNMENT_ASSUMPTION:[^,]+]],{{.*}} !nosanitize
+  // CHECK-SANITIZE:  [[HANDLER_ALIGNMENT_ASSUMPTION]]:
+  // CHECK-SANITIZE-NORECOVER-NEXT: call void @__ubsan_handle_alignment_assumption_abort(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 1, i64 0){{.*}}, !nosanitize
+  // CHECK-SANITIZE-RECOVER-NEXT:   call void @__ubsan_handle_alignment_assumption(i8* bitcast ({ {{{.*}}}, {{{.*}}}, {{{.*}}}* }* @[[ALIGNMENT_ASSUMPTION]] to i8*), i64 %[[PTRINT_DUP]], i64 1, i64 0){{.*}}, !nosanitize
+  // CHECK-SANITIZE-TRAP-NEXT:  call void @llvm.ubsantrap(i8 23){{.*}}, !nosanitize
+  // CHECK-SANITIZE-UNREACHABLE-NEXT:   unreachable, !nosanitize
+  // CHECK-SANITIZE:  [[CONT]]:
+  // CHECK-NEXT: 

[clang-tools-extra] 2a0870c - [clang-tidy] Add missing header from 6bd98b4f2d

2022-08-27 Thread Nathan James via cfe-commits

Author: Nathan James
Date: 2022-08-27T19:59:16+01:00
New Revision: 2a0870c9d38d034b39d7cfa2a9929ff2819ecebd

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

LOG: [clang-tidy] Add missing header from 6bd98b4f2d

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
index 590505c1f47b..05f0ae74282e 100644
--- a/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
@@ -8,6 +8,7 @@
 
 #include "AssignmentInIfConditionCheck.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 
 using namespace clang::ast_matchers;



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


[PATCH] D132786: [clang-tidy] Fix a false positive in bugprone-assignment-in-if-condition

2022-08-27 Thread Nathan James via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6bd98b4f2df0: [clang-tidy] Fix a false positive in 
bugprone-assignment-in-if-condition (authored by njames93).

Changed prior to commit:
  https://reviews.llvm.org/D132786?vs=456102&id=456139#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132786

Files:
  clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/assignment-in-if-condition.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/assignment-in-if-condition.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/assignment-in-if-condition.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/assignment-in-if-condition.cpp
@@ -101,3 +101,20 @@
 f = 5;
   }
 }
+
+template  bool exec(Func F) { return F(); }
+
+void lambda_if() {
+  int X;
+  if ([&X] {
+X = 5;
+return true;
+  }()) {
+  }
+
+  if (exec([&] {
+X = 5;
+return true;
+  })) {
+  }
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -116,6 +116,10 @@
 Changes in existing checks
 ^^
 
+- Fixed a false positive in :doc:`bugprone-assignment-in-if-condition
+  ` check when there
+  was an assignement in a lambda found in the condition of an ``if``.
+
 - Improved :doc:`bugprone-signal-handler
   ` check. Partial
   support for C++14 signal handler rules was added. Bug report generation was
Index: clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.h
===
--- clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.h
@@ -25,6 +25,7 @@
   : ClangTidyCheck(Name, Context) {}
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  void report(const Expr *E);
 };
 
 } // namespace bugprone
Index: clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
@@ -17,23 +17,50 @@
 namespace bugprone {
 
 void AssignmentInIfConditionCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(ifStmt(hasCondition(forEachDescendant(
- binaryOperator(isAssignmentOperator())
- .bind("assignment_in_if_statement",
- this);
-  Finder->addMatcher(ifStmt(hasCondition(forEachDescendant(
- cxxOperatorCallExpr(isAssignmentOperator())
- .bind("assignment_in_if_statement",
- this);
+  Finder->addMatcher(translationUnitDecl(), this);
 }
 
 void AssignmentInIfConditionCheck::check(
-const MatchFinder::MatchResult &Result) {
-  const auto *MatchedDecl =
-  Result.Nodes.getNodeAs("assignment_in_if_statement");
-  if (!MatchedDecl) {
-return;
-  }
+const ast_matchers::MatchFinder::MatchResult &Result) {
+  class Visitor : public RecursiveASTVisitor {
+AssignmentInIfConditionCheck &Check;
+
+  public:
+explicit Visitor(AssignmentInIfConditionCheck &Check) : Check(Check) {}
+bool VisitIfStmt(IfStmt *If) {
+  class ConditionVisitor : public RecursiveASTVisitor {
+AssignmentInIfConditionCheck &Check;
+
+  public:
+explicit ConditionVisitor(AssignmentInIfConditionCheck &Check)
+: Check(Check) {}
+
+// Dont traverse into any lambda expressions.
+bool TraverseLambdaExpr(LambdaExpr *, DataRecursionQueue * = nullptr) {
+  return true;
+}
+
+bool VisitBinaryOperator(BinaryOperator *BO) {
+  if (BO->isAssignmentOp())
+Check.report(BO);
+  return true;
+}
+
+bool VisitCXXOperatorCallExpr(CXXOperatorCallExpr *OCE) {
+  if (OCE->isAssignmentOp())
+Check.report(OCE);
+  return true;
+}
+  };
+
+  ConditionVisitor(Check).TraverseStmt(If->getCond());
+  return true;
+}
+  };
+  Visitor(*this).TraverseAST(*Result.Context);
+}
+
+void AssignmentInIfConditionCheck::report(const Expr *MatchedDecl) {
   diag(MatchedDecl->getBeginLoc(),
"an assignment within an 'if' condition is bug-prone");
   diag(MatchedDecl->getBeginLoc(),

[clang-tools-extra] 6bd98b4 - [clang-tidy] Fix a false positive in bugprone-assignment-in-if-condition

2022-08-27 Thread Nathan James via cfe-commits

Author: Nathan James
Date: 2022-08-27T19:55:08+01:00
New Revision: 6bd98b4f2df02955b72343038ecf20cdfd23e01e

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

LOG: [clang-tidy] Fix a false positive in bugprone-assignment-in-if-condition

Fixed a false positive where a lambda expression in the condition which 
contained an assignement would trigger a warning.
Fixes #56729

Reviewed By: gribozavr2

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.h
clang-tools-extra/docs/ReleaseNotes.rst

clang-tools-extra/test/clang-tidy/checkers/bugprone/assignment-in-if-condition.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
index e4f52191e0b00..590505c1f47ba 100644
--- a/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
@@ -17,23 +17,50 @@ namespace tidy {
 namespace bugprone {
 
 void AssignmentInIfConditionCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(ifStmt(hasCondition(forEachDescendant(
- binaryOperator(isAssignmentOperator())
- .bind("assignment_in_if_statement",
- this);
-  Finder->addMatcher(ifStmt(hasCondition(forEachDescendant(
- cxxOperatorCallExpr(isAssignmentOperator())
- .bind("assignment_in_if_statement",
- this);
+  Finder->addMatcher(translationUnitDecl(), this);
 }
 
 void AssignmentInIfConditionCheck::check(
-const MatchFinder::MatchResult &Result) {
-  const auto *MatchedDecl =
-  Result.Nodes.getNodeAs("assignment_in_if_statement");
-  if (!MatchedDecl) {
-return;
-  }
+const ast_matchers::MatchFinder::MatchResult &Result) {
+  class Visitor : public RecursiveASTVisitor {
+AssignmentInIfConditionCheck &Check;
+
+  public:
+explicit Visitor(AssignmentInIfConditionCheck &Check) : Check(Check) {}
+bool VisitIfStmt(IfStmt *If) {
+  class ConditionVisitor : public RecursiveASTVisitor {
+AssignmentInIfConditionCheck &Check;
+
+  public:
+explicit ConditionVisitor(AssignmentInIfConditionCheck &Check)
+: Check(Check) {}
+
+// Dont traverse into any lambda expressions.
+bool TraverseLambdaExpr(LambdaExpr *, DataRecursionQueue * = nullptr) {
+  return true;
+}
+
+bool VisitBinaryOperator(BinaryOperator *BO) {
+  if (BO->isAssignmentOp())
+Check.report(BO);
+  return true;
+}
+
+bool VisitCXXOperatorCallExpr(CXXOperatorCallExpr *OCE) {
+  if (OCE->isAssignmentOp())
+Check.report(OCE);
+  return true;
+}
+  };
+
+  ConditionVisitor(Check).TraverseStmt(If->getCond());
+  return true;
+}
+  };
+  Visitor(*this).TraverseAST(*Result.Context);
+}
+
+void AssignmentInIfConditionCheck::report(const Expr *MatchedDecl) {
   diag(MatchedDecl->getBeginLoc(),
"an assignment within an 'if' condition is bug-prone");
   diag(MatchedDecl->getBeginLoc(),

diff  --git 
a/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.h 
b/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.h
index 8e57f1a7ca80d..f84ae93ed2ebf 100644
--- a/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.h
@@ -25,6 +25,7 @@ class AssignmentInIfConditionCheck : public ClangTidyCheck {
   : ClangTidyCheck(Name, Context) {}
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  void report(const Expr *E);
 };
 
 } // namespace bugprone

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 1656debda1368..1734f4acf6865 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -116,6 +116,10 @@ New check aliases
 Changes in existing checks
 ^^
 
+- Fixed a false positive in :doc:`bugprone-assignment-in-if-condition
+  ` check when there
+  was an assignement in a lambda found in the condition of an ``if``.
+
 - Improved :doc:`bugprone-signal-handler
   ` check. Partial
   support for C++14 signal handler rules was added. Bug report generation was

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/assignment-i

[PATCH] D128113: Clang: fix AST representation of expanded template arguments.

2022-08-27 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

In D128113#3753662 , @davrec wrote:

> Thanks for your work on this, and for explaining these complexities.

TBH I still don't know what to do here from the project perspective. I have a 
new deadline now that runs until November.

It seems that sitting down, figuring out a solution and coming up with a 
review-ready patch would take a considerable portion of that time. And then the 
review could take a year.

Meanwhile there is still considerable work remaining on the resugarer, in terms 
of addressing performance and getting everything into a reviewable state.

So I might try leaving this problem aside and not handle packs, for now. This 
would make us not able to resugar tuples for example, which is very unfortunate.

But in the unlikely case there was someone else interested in solving this 
problem, this could be parallelized.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128113

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


[PATCH] D128113: Clang: fix AST representation of expanded template arguments.

2022-08-27 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

In D128113#3753656 , @davrec wrote:

> If I'm missing something and it is substantially more complex than that, then 
> you're right that storing the pack index might end up the best solution - we 
> don't want to e.g. have to do considerable Sema logic in the Resugarer just 
> to infer the pack index.

Having a new Subst-like node that wraps the whole expanded pattern seems to 
simplify the case where we need to take the type apart, such as deductions, 
leaving you without the 'birds-eye' view. Otherwise we would need to dig into 
the type to figure out what pack indexes we need to preserve in the resulting 
type.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128113

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


[PATCH] D128113: Clang: fix AST representation of expanded template arguments.

2022-08-27 Thread David Rector via Phabricator via cfe-commits
davrec added a comment.

In D128113#3753656 , @davrec wrote:

> In D128113#3753640 , @mizvekov 
> wrote:
>
>> In D128113#3753624 , @davrec wrote:
>>
>>> Or just `SubstTemplateTypeParmType` could store this number in addition to 
>>> its `TemplateTypeParmType`?  (E.g. the first Ts in an expansion is 0, the 
>>> second Ts in the same expansion is 1, etc. - but it resets for the next 
>>> expansion.)
>>
>> Well that number is just the pack_index, as implemented in this current 
>> patch :)

Disregard my previous comment, you're right, that would be identical.  I'm 
mixing up my STTPTs and TTPTs :).  So the proposed solution would be to make 
the TTPTs unique, and map from the TTPTs to their current pack indices in the 
Resugarer.  But, that is probably identical in terms of memory usage as your 
proposal to introduce a new sugar type representing unique expansion instances, 
and the latter is probably clearer/less disruptive.

Thanks for your work on this, and for explaining these complexities.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128113

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


[PATCH] D128113: Clang: fix AST representation of expanded template arguments.

2022-08-27 Thread David Rector via Phabricator via cfe-commits
davrec added a comment.

In D128113#3753640 , @mizvekov wrote:

> In D128113#3753624 , @davrec wrote:
>
>> Or just `SubstTemplateTypeParmType` could store this number in addition to 
>> its `TemplateTypeParmType`?  (E.g. the first Ts in an expansion is 0, the 
>> second Ts in the same expansion is 1, etc. - but it resets for the next 
>> expansion.)
>
> Well that number is just the pack_index, as implemented in this current patch 
> :)

I meant that, in an of expansion `(Ts, Ts, Us)`, either the two `Ts` would be 
two unique `TemplateTypeParmType`s by adding an instanceIndex or whatever to 
refer to the two different syntactic instances (this would of course naturally 
result in two unique STTPTs), or for a bit more savings the TTPTs for the two 
`Ts` could continue to be the same but their STTPTs would include the 
instanceIndex, so there is only one unique TTPT but two unique STTPTs referring 
to `Ts`.

I.e. if there are 100 types in in `Ts` there would still only be two unique 
`SubstTemplateTypeParmTypes` created, as opposed to only 1 as there currently 
is, or 100 as this patch creates.

Any way it is done, the goal would be to make the STTPTs just as unique as 
necessary so the Resugarer can keep map from the unique STTPTs to its current 
pack index, and iterate the relevant index with each call to 
`TransformSubstTemplateTypeParmType`.

If I'm missing something and it is substantially more complex than that, then 
you're right that storing the pack index might end up the best solution - we 
don't want to e.g. have to do considerable Sema logic in the Resugarer just to 
infer the pack index.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128113

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


[PATCH] D128113: Clang: fix AST representation of expanded template arguments.

2022-08-27 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

In D128113#3753624 , @davrec wrote:

> Or just `SubstTemplateTypeParmType` could store this number in addition to 
> its `TemplateTypeParmType`?  (E.g. the first Ts in an expansion is 0, the 
> second Ts in the same expansion is 1, etc. - but it resets for the next 
> expansion.)

Well that number is just the pack_index, as implemented in this current patch :)

I like the idea obviously, this patch is so simple, and simple solutions are 
the best when they are good enough.

I am not completely sold that this solution is not good enough, it's hard to 
make the case that the reproducer is a reasonable program, but at the same time 
it's obvious that packs where designed to deal very cheaply with very large 
number of arguments.

And this patch does not make the worst case worse: If all arguments are 
different types in all expansions, then a different pack_index will not cause 
an extra uniquing because the underlying types will be different as well anyway.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128113

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


[clang] 86bc458 - Use std::clamp (NFC)

2022-08-27 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-08-27T09:53:13-07:00
New Revision: 86bc4587e1fdb7b1b90eadc138619f5e3f2dd6fd

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

LOG: Use std::clamp (NFC)

This patch replaces clamp idioms with std::clamp where the range is
obviously valid from the source code (that is, low <= high) to avoid
introducing undefined behavior.

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/TargetInfo.cpp
llvm/tools/llvm-xray/xray-color-helper.cpp
llvm/tools/llvm-xray/xray-graph-diff.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 63e293f26376..f2d0b20c00c4 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -60,11 +60,6 @@ using namespace clang;
 using namespace CodeGen;
 using namespace llvm;
 
-static
-int64_t clamp(int64_t Value, int64_t Low, int64_t High) {
-  return std::min(High, std::max(Low, Value));
-}
-
 static void initializeAlloca(CodeGenFunction &CGF, AllocaInst *AI, Value *Size,
  Align AlignmentInBytes) {
   ConstantInt *Byte;
@@ -16024,7 +16019,7 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned 
BuiltinID,
 assert(ArgCI &&
"Third arg to xxinsertw intrinsic must be constant integer");
 const int64_t MaxIndex = 12;
-int64_t Index = clamp(ArgCI->getSExtValue(), 0, MaxIndex);
+int64_t Index = std::clamp(ArgCI->getSExtValue(), (int64_t)0, MaxIndex);
 
 // The builtin semantics don't exactly match the xxinsertw instructions
 // semantics (which ppc_vsx_xxinsertw follows). The builtin extracts the
@@ -16066,7 +16061,7 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned 
BuiltinID,
 assert(ArgCI &&
"Second Arg to xxextractuw intrinsic must be a constant integer!");
 const int64_t MaxIndex = 12;
-int64_t Index = clamp(ArgCI->getSExtValue(), 0, MaxIndex);
+int64_t Index = std::clamp(ArgCI->getSExtValue(), (int64_t)0, MaxIndex);
 
 if (getTarget().isLittleEndian()) {
   // Reverse the index.

diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index 42d5a856edf3..370614f65e5b 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -6674,7 +6674,7 @@ ABIArgInfo ARMABIInfo::classifyArgumentType(QualType Ty, 
bool isVariadic,
   if (getABIKind() == ARMABIInfo::AAPCS_VFP ||
   getABIKind() == ARMABIInfo::AAPCS) {
 TyAlign = getContext().getTypeUnadjustedAlignInChars(Ty).getQuantity();
-ABIAlign = std::min(std::max(TyAlign, (uint64_t)4), (uint64_t)8);
+ABIAlign = std::clamp(TyAlign, (uint64_t)4, (uint64_t)8);
   } else {
 TyAlign = getContext().getTypeAlignInChars(Ty).getQuantity();
   }

diff  --git a/llvm/tools/llvm-xray/xray-color-helper.cpp 
b/llvm/tools/llvm-xray/xray-color-helper.cpp
index b2ed63881bdc..3dd5143ca8d0 100644
--- a/llvm/tools/llvm-xray/xray-color-helper.cpp
+++ b/llvm/tools/llvm-xray/xray-color-helper.cpp
@@ -111,7 +111,7 @@ convertToHSV(const std::tuple 
&Color) {
 // Takes a double precision number, clips it between 0 and 1 and then converts
 // that to an integer between 0x00 and 0xFF with proxpper rounding.
 static uint8_t unitIntervalTo8BitChar(double B) {
-  double n = std::max(std::min(B, 1.0), 0.0);
+  double n = std::clamp(B, 0.0, 1.0);
   return static_cast(255 * n + 0.5);
 }
 

diff  --git a/llvm/tools/llvm-xray/xray-graph-
diff .cpp b/llvm/tools/llvm-xray/xray-graph-
diff .cpp
index bcadade86bb5..8ccfd304ffe5 100644
--- a/llvm/tools/llvm-xray/xray-graph-
diff .cpp
+++ b/llvm/tools/llvm-xray/xray-graph-
diff .cpp
@@ -264,7 +264,7 @@ static std::string getColor(const 
GraphDiffRenderer::GraphT::EdgeValueType &E,
   const auto &RightStat = EdgeAttr.CorrEdgePtr[1]->second.S;
 
   double RelDiff = statRelDiff(LeftStat, RightStat, T);
-  double CappedRelDiff = std::min(1.0, std::max(-1.0, RelDiff));
+  double CappedRelDiff = std::clamp(RelDiff, -1.0, 1.0);
 
   return H.getColorString(CappedRelDiff);
 }
@@ -285,7 +285,7 @@ static std::string getColor(const 
GraphDiffRenderer::GraphT::VertexValueType &V,
   const auto &RightStat = VertexAttr.CorrVertexPtr[1]->second.S;
 
   double RelDiff = statRelDiff(LeftStat, RightStat, T);
-  double CappedRelDiff = std::min(1.0, std::max(-1.0, RelDiff));
+  double CappedRelDiff = std::clamp(RelDiff, -1.0, 1.0);
 
   return H.getColorString(CappedRelDiff);
 }



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


[clang] 21de288 - Use llvm::is_contained (NFC)

2022-08-27 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-08-27T09:53:11-07:00
New Revision: 21de2888a4b3bf60c68b6e507ed629b977ef5a0e

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

LOG: Use llvm::is_contained (NFC)

Added: 


Modified: 
clang/lib/AST/Expr.cpp
llvm/lib/CodeGen/WinEHPrepare.cpp
llvm/lib/IR/Instructions.cpp
llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
llvm/lib/Transforms/AggressiveInstCombine/TruncInstCombine.cpp
llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
llvm/lib/Transforms/Vectorize/VPlan.h
mlir/include/mlir/Analysis/Presburger/Utils.h
mlir/include/mlir/Dialect/Quant/QuantTypes.h

Removed: 




diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index e7bdce1bffcc..5fd412930181 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -4831,7 +4831,7 @@ RecoveryExpr::RecoveryExpr(ASTContext &Ctx, QualType T, 
SourceLocation BeginLoc,
OK_Ordinary),
   BeginLoc(BeginLoc), EndLoc(EndLoc), NumExprs(SubExprs.size()) {
   assert(!T.isNull());
-  assert(llvm::all_of(SubExprs, [](Expr* E) { return E != nullptr; }));
+  assert(!llvm::is_contained(SubExprs, nullptr));
 
   llvm::copy(SubExprs, getTrailingObjects());
   setDependence(computeDependence(this));

diff  --git a/llvm/lib/CodeGen/WinEHPrepare.cpp 
b/llvm/lib/CodeGen/WinEHPrepare.cpp
index b835503ee9ed..a71f6572e76f 100644
--- a/llvm/lib/CodeGen/WinEHPrepare.cpp
+++ b/llvm/lib/CodeGen/WinEHPrepare.cpp
@@ -847,10 +847,7 @@ void WinEHPrepare::cloneCommonBlocks(Function &F) {
   ColorVector &IncomingColors = BlockColors[IncomingBlock];
   assert(!IncomingColors.empty() && "Block not colored!");
   assert((IncomingColors.size() == 1 ||
-  llvm::all_of(IncomingColors,
-   [&](BasicBlock *Color) {
- return Color != FuncletPadBB;
-   })) &&
+  !llvm::is_contained(IncomingColors, FuncletPadBB)) &&
  "Cloning should leave this funclet's blocks monochromatic");
   EdgeTargetsFunclet = (IncomingColors.front() == FuncletPadBB);
 }

diff  --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp
index 6a79d2b1e367..78c13e698d6c 100644
--- a/llvm/lib/IR/Instructions.cpp
+++ b/llvm/lib/IR/Instructions.cpp
@@ -2511,7 +2511,7 @@ static bool isReplicationMaskWithParams(ArrayRef 
Mask,
 bool ShuffleVectorInst::isReplicationMask(ArrayRef Mask,
   int &ReplicationFactor, int &VF) {
   // undef-less case is trivial.
-  if (none_of(Mask, [](int MaskElt) { return MaskElt == UndefMaskElem; })) {
+  if (!llvm::is_contained(Mask, UndefMaskElem)) {
 ReplicationFactor =
 Mask.take_while([](int MaskElt) { return MaskElt == 0; }).size();
 if (ReplicationFactor == 0 || Mask.size() % ReplicationFactor != 0)

diff  --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp 
b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
index 93269da8b814..73844ca8c088 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
@@ -4277,9 +4277,7 @@ bool SIInstrInfo::verifyInstruction(const MachineInstr 
&MI,
   if (usesConstantBus(MRI, MO, MI.getDesc().OpInfo[OpIdx])) {
 if (MO.isReg()) {
   SGPRUsed = MO.getReg();
-  if (llvm::all_of(SGPRsUsed, [SGPRUsed](unsigned SGPR) {
-return SGPRUsed != SGPR;
-  })) {
+  if (!llvm::is_contained(SGPRsUsed, SGPRUsed)) {
 ++ConstantBusCount;
 SGPRsUsed.push_back(SGPRUsed);
   }

diff  --git a/llvm/lib/Transforms/AggressiveInstCombine/TruncInstCombine.cpp 
b/llvm/lib/Transforms/AggressiveInstCombine/TruncInstCombine.cpp
index 70ea68587b8e..6c62e84077ac 100644
--- a/llvm/lib/Transforms/AggressiveInstCombine/TruncInstCombine.cpp
+++ b/llvm/lib/Transforms/AggressiveInstCombine/TruncInstCombine.cpp
@@ -157,7 +157,7 @@ bool TruncInstCombine::buildTruncExpressionGraph() {
   getRelevantOperands(I, Operands);
   // Add only operands not in Stack to prevent cycle
   for (auto *Op : Operands)
-if (all_of(Stack, [Op](Value *V) { return Op != V; }))
+if (!llvm::is_contained(Stack, Op))
   Worklist.push_back(Op);
   break;
 }

diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp 
b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
index d435a7d76d0d..1fd12b441272 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -859,8 +859,7 @@ Instruction 
*InstCombinerImpl::foldAggregateConstructionIntoAggregateReuse(
 
   // Do we know values fo

[clang] a33ef8f - Use llvm::all_equal (NFC)

2022-08-27 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-08-27T09:53:10-07:00
New Revision: a33ef8f2b7b28e4ae50a6e4fa206f82d3b230a68

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

LOG: Use llvm::all_equal (NFC)

Added: 


Modified: 
clang/lib/Driver/Action.cpp
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChains/AMDGPU.cpp
llvm/lib/Target/AArch64/MCTargetDesc/AArch64AddressingModes.h
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/lib/Transforms/IPO/PartialInlining.cpp
llvm/lib/Transforms/Scalar/GVNSink.cpp
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
mlir/lib/Dialect/Shape/IR/ShapeCanonicalization.td

Removed: 




diff  --git a/clang/lib/Driver/Action.cpp b/clang/lib/Driver/Action.cpp
index cc7a59f9d956..1cb68276e11e 100644
--- a/clang/lib/Driver/Action.cpp
+++ b/clang/lib/Driver/Action.cpp
@@ -198,7 +198,7 @@ OffloadAction::OffloadAction(const DeviceDependences 
&DDeps, types::ID Ty)
   auto &OTCs = DDeps.getToolChains();
 
   // If all inputs agree on the same kind, use it also for this action.
-  if (llvm::all_of(OKinds, [&](OffloadKind K) { return K == OKinds.front(); }))
+  if (llvm::all_equal(OKinds))
 OffloadingDeviceKind = OKinds.front();
 
   // If we have a single dependency, inherit the architecture from it.

diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index d23a8931a8a8..db6e4898ed55 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -991,9 +991,7 @@ bool Driver::loadConfigFile() {
 std::vector ConfigFiles =
 CLOptions->getAllArgValues(options::OPT_config);
 if (ConfigFiles.size() > 1) {
-  if (!llvm::all_of(ConfigFiles, [ConfigFiles](const std::string &s) {
-return s == ConfigFiles[0];
-  })) {
+  if (!llvm::all_equal(ConfigFiles)) {
 Diag(diag::err_drv_duplicate_config);
 return true;
   }

diff  --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp 
b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index 8718ab53ac1a..89f8e482ded6 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -804,10 +804,7 @@ llvm::Error AMDGPUToolChain::getSystemGPUArch(const 
ArgList &Args,
   }
   GPUArch = GPUArchs[0];
   if (GPUArchs.size() > 1) {
-bool AllSame = llvm::all_of(GPUArchs, [&](const StringRef &GPUArch) {
-  return GPUArch == GPUArchs.front();
-});
-if (!AllSame)
+if (!llvm::all_equal(GPUArchs))
   return llvm::createStringError(
   std::error_code(), "Multiple AMD GPUs found with 
diff erent archs");
   }

diff  --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AddressingModes.h 
b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AddressingModes.h
index 876526093591..71862e85b49c 100644
--- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AddressingModes.h
+++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AddressingModes.h
@@ -755,7 +755,7 @@ static inline uint64_t decodeAdvSIMDModImmType12(uint8_t 
Imm) {
 template 
 static inline bool isSVEMaskOfIdenticalElements(int64_t Imm) {
   auto Parts = bit_cast>(Imm);
-  return all_of(Parts, [&](T Elem) { return Elem == Parts[0]; });
+  return llvm::all_equal(Parts);
 }
 
 /// Returns true if Imm is valid for CPY/DUP.

diff  --git a/llvm/lib/Target/X86/X86ISelLowering.cpp 
b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 59333bf1b843..369c7d3d6504 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -53986,7 +53986,7 @@ static SDValue combineConcatVectorOps(const SDLoc &DL, 
MVT VT,
 return getZeroVector(VT, Subtarget, DAG, DL);
 
   SDValue Op0 = Ops[0];
-  bool IsSplat = llvm::all_of(Ops, [&Op0](SDValue Op) { return Op == Op0; });
+  bool IsSplat = llvm::all_equal(Ops);
 
   // Repeated subvectors.
   if (IsSplat &&

diff  --git a/llvm/lib/Transforms/IPO/PartialInlining.cpp 
b/llvm/lib/Transforms/IPO/PartialInlining.cpp
index d2b37f6a5c0d..653addd726c5 100644
--- a/llvm/lib/Transforms/IPO/PartialInlining.cpp
+++ b/llvm/lib/Transforms/IPO/PartialInlining.cpp
@@ -1083,10 +1083,8 @@ void 
PartialInlinerImpl::FunctionCloner::normalizeReturnBlock() const {
 return;
 
   auto IsTrivialPhi = [](PHINode *PN) -> Value * {
-Value *CommonValue = PN->getIncomingValue(0);
-if (all_of(PN->incoming_values(),
-   [&](Value *V) { return V == CommonValue; }))
-  return CommonValue;
+if (llvm::all_equal(PN->incoming_values()))
+  return PN->getIncomingValue(0);
 return nullptr;
   };
 

diff  --git a/llvm/lib/Transforms/Scalar/GVNSink.cpp 
b/llvm/lib/Transforms/Scalar/GVNSink.cpp
index 6fc6a931a861..891f7d72529e 100644
--- a/llvm/lib/Transforms/Scalar/GVNSink.cpp
+++ b/llvm/lib/Transforms/Scalar/GVNSink.cpp
@@ -288,7 +288,7 @@ class ModelledPHI {
   ArrayRef getVa

[PATCH] D132791: Fix formatting in release notes

2022-08-27 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert updated this revision to Diff 456131.
aaronpuchert added a comment.

Use links instead `:manpage:`, which is meant for man pages cross-referencing 
each other.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132791

Files:
  clang/docs/ReleaseNotes.rst
  llvm/docs/ReleaseNotes.rst

Index: llvm/docs/ReleaseNotes.rst
===
--- llvm/docs/ReleaseNotes.rst
+++ llvm/docs/ReleaseNotes.rst
@@ -56,7 +56,7 @@
 * Visual Studio 2019 >= 16.7
 
 In LLVM 15.x these requirements will be "soft" requirements and the version
-check can be skipped by passing -DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=ON
+check can be skipped by passing ``-DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=ON``
 to CMake.
 
 With the release of LLVM 16.x these requirements will be hard and LLVM developers
@@ -74,6 +74,7 @@
 * Renamed ``llvm.experimental.vector.insert`` intrinsic to ``llvm.vector.insert``.
 * The constant expression variants of the following instructions have been
   removed:
+
   * ``extractvalue``
   * ``insertvalue``
   * ``udiv``
@@ -85,6 +86,7 @@
   * ``fmul``
   * ``fdiv``
   * ``frem``
+
 * Added the support for ``fmax`` and ``fmin`` in ``atomicrmw`` instruction. The
   comparison is expected to match the behavior of ``llvm.maxnum.*`` and
   ``llvm.minnum.*`` respectively.
@@ -140,7 +142,7 @@
 * Implemented generation of Windows SEH unwind information.
 * Switched the MinGW target to use SEH instead of DWARF for unwind information.
 * Added support for the Cortex-M85 CPU.
-* Added support for a new -mframe-chain=(none|aapcs|aapcs+leaf) command-line
+* Added support for a new ``-mframe-chain=(none|aapcs|aapcs+leaf)`` command-line
   option, which controls the generation of AAPCS-compliant Frame Records.
 
 Changes to the AVR Backend
@@ -227,6 +229,7 @@
   because the underlying constant expressions are no longer supported. Instead,
   an instruction should be created using the ``LLVMBuildXYZ`` APIs, which will
   constant fold the operands if possible and create an instruction otherwise:
+
   * ``LLVMConstExtractValue``
   * ``LLVMConstInsertValue``
   * ``LLVMConstUDiv``
@@ -246,6 +249,7 @@
 
 * As part of the opaque pointer migration, the following APIs are deprecated and
   will be removed in the next release:
+
   * ``LLVMBuildLoad`` -> ``LLVMBuildLoad2``
   * ``LLVMBuildCall`` -> ``LLVMBuildCall2``
   * ``LLVMBuildInvoke`` -> ``LLVMBuildInvoke2``
@@ -260,6 +264,7 @@
 * Refactor compression namespaces across the project, making way for a possible
   introduction of alternatives to zlib compression in the llvm toolchain.
   Changes are as follows:
+
   * Relocate the ``llvm::zlib`` namespace to ``llvm::compression::zlib``.
   * Remove crc32 from zlib compression namespace, people should use the ``llvm::crc32`` instead.
 
@@ -290,7 +295,7 @@
 Changes to the LLVM tools
 -
 
-* (Experimental) :manpage:`llvm-symbolizer(1)` now has ``--filter-markup`` to
+* (Experimental) :doc:`llvm-symbolizer ` now has ``--filter-markup`` to
   filter :doc:`Symbolizer Markup ` into human-readable
   form.
 * :doc:`llvm-objcopy ` has removed support for the legacy ``zlib-gnu`` format.
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -127,7 +127,7 @@
   This fixes Issue `Issue 53488 `_.
 - According to `CWG 1394 `_ and
   `C++20 [dcl.fct.def.general]p2 `_,
-  Clang should not diagnose incomplete types in function definitions if the function body is "= delete;".
+  Clang should not diagnose incomplete types in function definitions if the function body is ``= delete;``.
   This fixes Issue `Issue 52802 `_.
 - Unknown type attributes with a ``[[]]`` spelling are no longer diagnosed twice.
   This fixes Issue `Issue 54817 `_.
@@ -163,7 +163,7 @@
   promise_type body for coroutines if there is any allocation function
   declaration in the scope of promise_type. Additionally, to implement CWG2585,
   a coroutine will no longer generate a call to a global allocation function
-  with the signature (std::size_t, p0, ..., pn).
+  with the signature ``(std::size_t, p0, ..., pn)``.
   This fixes Issue `Issue 54881 `_.
 - Implement `CWG 2394 `_: Const class members
   may be initialized with a defaulted default constructor under the same
@@ -202,7 +202,7 @@
   considered to have one positive bit in order to represent the underlying
   value. This effects whether we consider the store of the value one to be well
   defined.
-- An operat

[PATCH] D128113: Clang: fix AST representation of expanded template arguments.

2022-08-27 Thread David Rector via Phabricator via cfe-commits
davrec added a comment.

Great examples.

> Check this example out: https://godbolt.org/z/rsGsM6GrM
>
>   template  struct A {
> template  struct B {
> using type1 = void ((void (*...fps)(Ts, Us)));
> };
>   };
>   using type2 = A::B::type1;
>
>   TypeAliasDecl 0x55ffe8b45368  col:7 type2 'A char>::B::type1':'void ((void (*)(int, short), void (*)(char, 
> bool)))'
> `-ElaboratedType 0x55ffe8b452f0 'A::B::type1' 
> sugar
>   `-TypedefType 0x55ffe8b452d0 'A::B::type1' sugar
> |-TypeAlias 0x55ffe8b45258 'type1'
> `-FunctionProtoType 0x55ffe8b451e0 'void ((void (*)(int, short), void 
> (*)(char, bool)))' cdecl
>   |-ParenType 0x55ffe8b12150 'void' sugar
>   | `-BuiltinType 0x55ffe8ac6370 'void'
>   |-PointerType 0x55ffe8b44550 'void (*)(int, short)'
>   | `-ParenType 0x55ffe8b444f0 'void (int, short)' sugar
>   |   `-FunctionProtoType 0x55ffe8b444b0 'void (int, short)' cdecl
>   | |-BuiltinType 0x55ffe8ac6370 'void'
>   | |-SubstTemplateTypeParmType 0x55ffe8b44310 'int' sugar
>   | | |-TemplateTypeParmType 0x55ffe8b11440 'Ts' dependent 
> contains_unexpanded_pack depth 0 index 0 pack
>   | | | `-TemplateTypeParm 0x55ffe8b113c0 'Ts'
>   | | `-BuiltinType 0x55ffe8ac6410 'int'
>   | `-SubstTemplateTypeParmType 0x55ffe8b443c0 'short' sugar
>   |   |-TemplateTypeParmType 0x55ffe8b11960 'Us' dependent 
> contains_unexpanded_pack depth 1 index 0 pack
>   |   | `-TemplateTypeParm 0x55ffe8b118d8 'Us'
>   |   `-BuiltinType 0x55ffe8ac63f0 'short'
>   `-PointerType 0x55ffe8b450c0 'void (*)(char, bool)'
> `-ParenType 0x55ffe8b45060 'void (char, bool)' sugar
>   `-FunctionProtoType 0x55ffe8b447d0 'void (char, bool)' cdecl
> |-BuiltinType 0x55ffe8ac6370 'void'
> |-SubstTemplateTypeParmType 0x55ffe8b44630 'char' sugar
> | |-TemplateTypeParmType 0x55ffe8b11440 'Ts' dependent 
> contains_unexpanded_pack depth 0 index 0 pack
> | | `-TemplateTypeParm 0x55ffe8b113c0 'Ts'
> | `-BuiltinType 0x55ffe8ac63b0 'char'
> `-SubstTemplateTypeParmType 0x55ffe8b446e0 'bool' sugar
>   |-TemplateTypeParmType 0x55ffe8b11960 'Us' dependent 
> contains_unexpanded_pack depth 1 index 0 pack
>   | `-TemplateTypeParm 0x55ffe8b118d8 'Us'
>   `-BuiltinType 0x55ffe8ac6390 'bool'

If it were as simple as the above case the Resugarer TreeTransform could say 
keep a map of `TemplateTypeParmType`s to current pack indices, and iterate 
those during each each `TransformSubstTemplateTypeParmType` call, but...

> And in fact, a given parameter pack might be referenced more than one time in 
> a given pack expansion pattern:
>
>   template  struct A {
> template  struct B {
> using type1 = void ((void (*...fps)(Ts, Ts, Us)));
> };
>   };
>
> Ie those two Ts are referencing the same argument within the pack, we can't 
> confuse that with an expansion.
>
> So think also about a case like the above, but where you are performing the 
> expansion just one time. It doesn't look like to me you can figure that out 
> from what Clang leaves behind in the AST at the moment.

...the different `Ts` are the same `TemplateTypeParmType`, so that wouldn't 
work.  You're right, more info is needed.

> We may need to create a new AST node, which is like a Subst variant of a 
> PackExpansionType, at the expansion loci.

Or, maybe `TemplateTypeParmType` could store a number that would make it unique 
for each *instance* of it in a given expansion?  Or just 
`SubstTemplateTypeParmType` could store this number in addition to its 
`TemplateTypeParmType`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128113

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


[PATCH] D132791: Fix formatting in release notes

2022-08-27 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added a comment.

This is for `release/15.x`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132791

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


[PATCH] D132695: [Clang] Avoid crashes when parsing using enum declarations

2022-08-27 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik updated this revision to Diff 456128.
shafik marked an inline comment as done.
shafik added a comment.

- Move `DS.SetTypeSpecError()` outside the `if` so that it is always called 
when the diagnostic is triggered.


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

https://reviews.llvm.org/D132695

Files:
  clang/lib/Parse/ParseDecl.cpp
  clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p9-0x.cpp
  clang/test/CXX/drs/dr3xx.cpp
  clang/test/Parser/cxx20-using-enum.cpp
  clang/test/Parser/recovery.cpp
  clang/test/Sema/enum.c
  clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp
  clang/test/SemaCXX/enum-scoped.cpp

Index: clang/test/SemaCXX/enum-scoped.cpp
===
--- clang/test/SemaCXX/enum-scoped.cpp
+++ clang/test/SemaCXX/enum-scoped.cpp
@@ -114,8 +114,7 @@
   long_enum_val = 1
 };
 
-enum : long x; // expected-error{{unnamed enumeration must be a definition}} \
-// expected-warning{{declaration does not declare anything}}
+enum : long x; // expected-error{{unnamed enumeration must be a definition}}
 
 void PR9333() {
   enum class scoped_enum { yes, no, maybe };
Index: clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp
===
--- clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp
+++ clang/test/SemaCXX/cxx1y-variable-templates_top_level.cpp
@@ -432,7 +432,7 @@
   a::b c; // expected-error {{qualified name refers into a specialization of variable template 'a'}}
 
   class a {}; // expected-error {{identifier followed by '<' indicates a class template specialization but 'a' refers to a variable template}}
-  enum a {}; // expected-error {{expected identifier or '{'}} expected-warning {{does not declare anything}}
+  enum a {}; // expected-error {{expected identifier or '{'}}
 }
 
 namespace PR18530 {
Index: clang/test/Sema/enum.c
===
--- clang/test/Sema/enum.c
+++ clang/test/Sema/enum.c
@@ -160,7 +160,7 @@
   } e;
 };
 
-enum struct GH42372_1 { // expected-error {{expected identifier or '{'}} expected-warning {{declaration does not declare anything}}
+enum struct GH42372_1 { // expected-error {{expected identifier or '{'}}
   One
 };
 
Index: clang/test/Parser/recovery.cpp
===
--- clang/test/Parser/recovery.cpp
+++ clang/test/Parser/recovery.cpp
@@ -209,7 +209,7 @@
 namespace InvalidEmptyNames {
 // These shouldn't crash, the diagnostics aren't important.
 struct ::, struct ::; // expected-error 2 {{expected identifier}} expected-error 2 {{declaration of anonymous struct must be a definition}} expected-warning {{declaration does not declare anything}}
-enum ::, enum ::; // expected-error 2 {{expected identifier}} expected-warning {{declaration does not declare anything}}
+enum ::, enum ::; // expected-error 2 {{expected identifier}}
 struct ::__super, struct ::__super; // expected-error 2 {{expected identifier}} expected-error 2 {{expected '::' after '__super'}}
 struct ::template foo, struct ::template bar; // expected-error 2 {{expected identifier}} expected-error 2 {{declaration of anonymous struct must be a definition}} expected-warning {{declaration does not declare anything}}
 struct ::foo struct::; // expected-error {{no struct named 'foo' in the global namespace}} expected-error {{expected identifier}} expected-error {{declaration of anonymous struct must be a definition}}
Index: clang/test/Parser/cxx20-using-enum.cpp
===
--- /dev/null
+++ clang/test/Parser/cxx20-using-enum.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+namespace GH57347 {
+namespace A {}
+
+void f() {
+  using enum A::+; // expected-error {{expected identifier}}
+  using enum; // expected-error {{expected identifier or '{'}}
+  using enum class; // expected-error {{expected identifier or '{'}}
+  using enum : blah; // expected-error {{unknown type name 'blah'}} expected-error {{unnamed enumeration must be a definition}}
+}
+}
Index: clang/test/CXX/drs/dr3xx.cpp
===
--- clang/test/CXX/drs/dr3xx.cpp
+++ clang/test/CXX/drs/dr3xx.cpp
@@ -30,7 +30,7 @@
 typename T::template operator+ a; // expected-error {{typename specifier refers to a non-type template}} expected-error +{{}}
 // FIXME: This shouldn't say (null).
 class T::template operator+ b; // expected-error {{identifier followed by '<' indicates a class template specialization but (null) refers to a function template}}
-enum T::template operator+ c; // expected-error {{expected identifier}} expected-error {{does not declare anything}}
+enum T::template operator+ c; // expected-error {{expected identifier}}
 enum T::template operator+::E d; // expected-error {{qualified name refers into a specialization of function template 

[PATCH] D132791: Fix formatting in release notes

2022-08-27 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert created this revision.
aaronpuchert added reviewers: aaron.ballman, thieta, tstellar.
Herald added a reviewer: alexander-shaposhnikov.
Herald added a project: All.
aaronpuchert requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Code needs double backticks, while single backticks produce italics.
Lists need to be fully indented and have blank lines around them.
Links are written "`text `_".


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132791

Files:
  clang/docs/ReleaseNotes.rst
  llvm/docs/ReleaseNotes.rst

Index: llvm/docs/ReleaseNotes.rst
===
--- llvm/docs/ReleaseNotes.rst
+++ llvm/docs/ReleaseNotes.rst
@@ -56,7 +56,7 @@
 * Visual Studio 2019 >= 16.7
 
 In LLVM 15.x these requirements will be "soft" requirements and the version
-check can be skipped by passing -DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=ON
+check can be skipped by passing ``-DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=ON``
 to CMake.
 
 With the release of LLVM 16.x these requirements will be hard and LLVM developers
@@ -74,6 +74,7 @@
 * Renamed ``llvm.experimental.vector.insert`` intrinsic to ``llvm.vector.insert``.
 * The constant expression variants of the following instructions have been
   removed:
+
   * ``extractvalue``
   * ``insertvalue``
   * ``udiv``
@@ -85,6 +86,7 @@
   * ``fmul``
   * ``fdiv``
   * ``frem``
+
 * Added the support for ``fmax`` and ``fmin`` in ``atomicrmw`` instruction. The
   comparison is expected to match the behavior of ``llvm.maxnum.*`` and
   ``llvm.minnum.*`` respectively.
@@ -140,7 +142,7 @@
 * Implemented generation of Windows SEH unwind information.
 * Switched the MinGW target to use SEH instead of DWARF for unwind information.
 * Added support for the Cortex-M85 CPU.
-* Added support for a new -mframe-chain=(none|aapcs|aapcs+leaf) command-line
+* Added support for a new ``-mframe-chain=(none|aapcs|aapcs+leaf)`` command-line
   option, which controls the generation of AAPCS-compliant Frame Records.
 
 Changes to the AVR Backend
@@ -227,6 +229,7 @@
   because the underlying constant expressions are no longer supported. Instead,
   an instruction should be created using the ``LLVMBuildXYZ`` APIs, which will
   constant fold the operands if possible and create an instruction otherwise:
+
   * ``LLVMConstExtractValue``
   * ``LLVMConstInsertValue``
   * ``LLVMConstUDiv``
@@ -246,6 +249,7 @@
 
 * As part of the opaque pointer migration, the following APIs are deprecated and
   will be removed in the next release:
+
   * ``LLVMBuildLoad`` -> ``LLVMBuildLoad2``
   * ``LLVMBuildCall`` -> ``LLVMBuildCall2``
   * ``LLVMBuildInvoke`` -> ``LLVMBuildInvoke2``
@@ -260,6 +264,7 @@
 * Refactor compression namespaces across the project, making way for a possible
   introduction of alternatives to zlib compression in the llvm toolchain.
   Changes are as follows:
+
   * Relocate the ``llvm::zlib`` namespace to ``llvm::compression::zlib``.
   * Remove crc32 from zlib compression namespace, people should use the ``llvm::crc32`` instead.
 
@@ -293,8 +298,8 @@
 * (Experimental) :manpage:`llvm-symbolizer(1)` now has ``--filter-markup`` to
   filter :doc:`Symbolizer Markup ` into human-readable
   form.
-* :doc:`llvm-objcopy ` has removed support for the legacy ``zlib-gnu`` format.
-* :doc:`llvm-objcopy ` now allows ``--set-section-flags src=... --rename-section src=tst``.
+* :manpage:`llvm-objcopy(1)` has removed support for the legacy ``zlib-gnu`` format.
+* :manpage:`llvm-objcopy(1)` now allows ``--set-section-flags src=... --rename-section src=tst``.
   ``--add-section=.foo1=... --rename-section=.foo1=.foo2`` now adds ``.foo1`` instead of ``.foo2``.
 * The LLVM gold plugin now ignores bitcode from the ``.llvmbc`` section of ELF
   files when doing LTO.  https://github.com/llvm/llvm-project/issues/47216
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -127,7 +127,7 @@
   This fixes Issue `Issue 53488 `_.
 - According to `CWG 1394 `_ and
   `C++20 [dcl.fct.def.general]p2 `_,
-  Clang should not diagnose incomplete types in function definitions if the function body is "= delete;".
+  Clang should not diagnose incomplete types in function definitions if the function body is ``= delete;``.
   This fixes Issue `Issue 52802 `_.
 - Unknown type attributes with a ``[[]]`` spelling are no longer diagnosed twice.
   This fixes Issue `Issue 54817 `_.
@@ -163,7 +163,7 @@
   promise_type body for coroutines if there is any allocation function
   declaration in the scope of promise_type. Additionally, to 

[PATCH] D131479: Handle explicitly defaulted consteval special members.

2022-08-27 Thread Mark de Wever via Phabricator via cfe-commits
Mordante added a comment.

In D131479#3753533 , @aaron.ballman 
wrote:

> In D131479#3753462 , @Mordante 
> wrote:
>
>> This change breaks the libc++ test 
>> `libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/move.fail.cpp`.
>>  
>> (https://buildkite.com/llvm-project/libcxx-ci/builds/13149#0182d0d4-341a-4b41-b67f-12937f41e6d5)
>>
>> Looking at the description of this patch it should only affect `consteval` 
>> functions, but it seems to affect `constexpr` functions too. Can you have a 
>> look?
>
> Agreed that we should take a look, but it's interesting to note that 
> libstdc++ seems to have a different behavior than libc++ here: 
> https://godbolt.org/z/6cWhf6GYj (the last three compiler panes show Clang 14 
> libstd++, Clang 14 libc++, and Clang trunk libc++). How sure are you that the 
> libc++ test is actually correct, because (without checking the standard, so 
> take with a giant grain of salt) this seems like it might have fixed a bug in 
> libc++? The release note says this is expected to impact constexpr and 
> consteval default special member functions, so behavioral changes to 
> `constexpr` aren't unexpected (though I agree that the commit message didn't 
> mention `constexpr` so the changes may seem surprising).

Thanks for confirming it's indeed intended to affect `constexpr` too! It was a 
bit confusing since it also referred to C++14, which didn't have `consteval`. I 
wasn't entirely sure about the status of libc++, but since the patch gave of a 
mixed message I wanted make sure that `constexpr` was intended.

I've done some further digging and according to cppreference the paper P0602R4 
was a DR against C++20. This was proposed in the paper.
Looking at the changes in the addressing this paper I see no C++ version checks 
https://reviews.llvm.org/D32385
In a followup introduces tests using C++ version checks 
https://reviews.llvm.org/D54772
The failing test was introduced in 308624127fd6cc36558b6eee4d4ffa4e215a074e 
before the paper was voted in

So I think there's indeed a bug in libc++ which was hidden since Clang hadn't 
implemented some DRs. I will look at the libc++ side what needs to be done to 
fix the CI failures.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131479

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


[PATCH] D128113: Clang: fix AST representation of expanded template arguments.

2022-08-27 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

In D128113#3753565 , @davrec wrote:

> 2: After thinking about it further I don't think the pack index provides 
> sufficiently useful info in any case, since packs will always be expanded in 
> full, in order: when you find the first `SubstTemplateTypeParmType` expanded 
> from a pack, the rest are sure to be right behind.  IIUC I see how including 
> the pack index makes resugaring more straightforward: the substitution of the 
> sugared info for the non-sugared info occurs via a TreeTransform (see 
> clang/lib/Sema/SemaTemplate.cpp in https://reviews.llvm.org/D127695), and by 
> storing the pack index Matheus can simply override 
> `TransformSubstTemplateTypeParmType` to make use of the pack index to easily 
> fetch the corresponding sugared info.  But since the pack indices are 
> predictable given a bird's eye view of the AST, maybe state info can be 
> stored in the TreeTransform to allow the pack index to be inferred in each 
> call to `TransformSubstTemplateTypeParmType`?

Packs are expanded from patterns, which is an arbitrary type that will 
reference one or more parameter pack anywhere within. So going back from an 
expanded pack back to a pattern + number of expansions will take more effort 
and we may need to add new markings to the AST to help with that.

Check this example out: https://godbolt.org/z/rsGsM6GrM

  template  struct A {
template  struct B {
using type1 = void ((void (*...fps)(Ts, Us)));
};
  };
  using type2 = A::B::type1;

  TypeAliasDecl 0x55ffe8b45368  col:7 type2 'A::B::type1':'void ((void (*)(int, short), void (*)(char, 
bool)))'
`-ElaboratedType 0x55ffe8b452f0 'A::B::type1' sugar
  `-TypedefType 0x55ffe8b452d0 'A::B::type1' sugar
|-TypeAlias 0x55ffe8b45258 'type1'
`-FunctionProtoType 0x55ffe8b451e0 'void ((void (*)(int, short), void 
(*)(char, bool)))' cdecl
  |-ParenType 0x55ffe8b12150 'void' sugar
  | `-BuiltinType 0x55ffe8ac6370 'void'
  |-PointerType 0x55ffe8b44550 'void (*)(int, short)'
  | `-ParenType 0x55ffe8b444f0 'void (int, short)' sugar
  |   `-FunctionProtoType 0x55ffe8b444b0 'void (int, short)' cdecl
  | |-BuiltinType 0x55ffe8ac6370 'void'
  | |-SubstTemplateTypeParmType 0x55ffe8b44310 'int' sugar
  | | |-TemplateTypeParmType 0x55ffe8b11440 'Ts' dependent 
contains_unexpanded_pack depth 0 index 0 pack
  | | | `-TemplateTypeParm 0x55ffe8b113c0 'Ts'
  | | `-BuiltinType 0x55ffe8ac6410 'int'
  | `-SubstTemplateTypeParmType 0x55ffe8b443c0 'short' sugar
  |   |-TemplateTypeParmType 0x55ffe8b11960 'Us' dependent 
contains_unexpanded_pack depth 1 index 0 pack
  |   | `-TemplateTypeParm 0x55ffe8b118d8 'Us'
  |   `-BuiltinType 0x55ffe8ac63f0 'short'
  `-PointerType 0x55ffe8b450c0 'void (*)(char, bool)'
`-ParenType 0x55ffe8b45060 'void (char, bool)' sugar
  `-FunctionProtoType 0x55ffe8b447d0 'void (char, bool)' cdecl
|-BuiltinType 0x55ffe8ac6370 'void'
|-SubstTemplateTypeParmType 0x55ffe8b44630 'char' sugar
| |-TemplateTypeParmType 0x55ffe8b11440 'Ts' dependent 
contains_unexpanded_pack depth 0 index 0 pack
| | `-TemplateTypeParm 0x55ffe8b113c0 'Ts'
| `-BuiltinType 0x55ffe8ac63b0 'char'
`-SubstTemplateTypeParmType 0x55ffe8b446e0 'bool' sugar
  |-TemplateTypeParmType 0x55ffe8b11960 'Us' dependent 
contains_unexpanded_pack depth 1 index 0 pack
  | `-TemplateTypeParm 0x55ffe8b118d8 'Us'
  `-BuiltinType 0x55ffe8ac6390 'bool'

And in fact, a given parameter pack might be referenced more than one time in a 
given pack expansion pattern:

  template  struct A {
template  struct B {
using type1 = void ((void (*...fps)(Ts, Ts, Us)));
};
  };

Ie those two Ts are referencing the same argument within the pack, we can't 
confuse that with an expansion.

So think also about a case like the above, but where you are performing the 
expansion just one time. It doesn't look like to me you can figure that out 
from what Clang leaves behind in the AST at the moment.
We may need to create a new AST node, which is like a Subst variant of a 
PackExpansionType, at the expansion loci.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128113

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


[clang] b9c2b60 - Avoid else-if after return, NFC

2022-08-27 Thread Jun Zhang via cfe-commits

Author: Jun Zhang
Date: 2022-08-27T23:14:48+08:00
New Revision: b9c2b6069ea7f3d253d88725c1993da463f39575

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

LOG: Avoid else-if after return, NFC

Signed-off-by: Jun Zhang 

Added: 


Modified: 
clang/lib/Basic/SourceManager.cpp

Removed: 




diff  --git a/clang/lib/Basic/SourceManager.cpp 
b/clang/lib/Basic/SourceManager.cpp
index 38545d1be918f..24e4aefd53f1c 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -1795,11 +1795,11 @@ void SourceManager::computeMacroArgsCache(MacroArgsMap 
&MacroArgsCache,
 if (Entry.getFile().NumCreatedFIDs)
   ID += Entry.getFile().NumCreatedFIDs - 1 /*because of next ++ID*/;
 continue;
-  } else if (IncludeLoc.isValid()) {
-// If file was included but not from FID, there is no more files/macros
-// that may be "contained" in this file.
-return;
   }
+  // If file was included but not from FID, there is no more files/macros
+  // that may be "contained" in this file.
+  if (IncludeLoc.isValid())
+return;
   continue;
 }
 



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


[PATCH] D128113: Clang: fix AST representation of expanded template arguments.

2022-08-27 Thread David Rector via Phabricator via cfe-commits
davrec added a comment.

Two last thoughts:
1: To reiterate it doesn't seem right to view this (or any patch adding 
not-semantically-relevant info to the AST) as a one-size-fits-all costs vs. 
benefits optimization.  On the one hand, the additional AST info hurts 
compilation performance.  On the other, the info might make debugging faster, 
or be useful to a tool.  A flag governing how much non-semantically-necessary 
info to add to the AST really seems the better solution in general, and 
warrants more discussion in cases like this (e.g. Matheus's other resugaring 
patches, which may cause this debate to resurface regardless of the approach he 
takes here).  The user could set the flag high when debugging, and decrease it 
when diagnostics/debug info are less expected/not needed.  (In light of the 
performance tests done here, the performance benefit of allowing the user to 
omit *other* non-semantically-necessary nodes from the AST could be 
significant; such a flag could allow that.)

2: After thinking about it further I don't think the pack index provides 
sufficiently useful info in any case, since packs will always be expanded in 
full, in order: when you find the first `SubstTemplateTypeParmType` expanded 
from a pack, the rest are sure to be right behind.  IIUC I see how including 
the pack index makes resugaring more straightforward: the substitution of the 
sugared info for the non-sugared info occurs via a TreeTransform (see 
clang/lib/Sema/SemaTemplate.cpp in https://reviews.llvm.org/D127695), and by 
storing the pack index Matheus can simply override 
`TransformSubstTemplateTypeParmType` to make use of the pack index to easily 
fetch the corresponding sugared info.  But since the pack indices are 
predictable given a bird's eye view of the AST, maybe state info can be stored 
in the TreeTransform to allow the pack index to be inferred in each call to 
`TransformSubstTemplateTypeParmType`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128113

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


[PATCH] D130831: [CodeGen] Track DeferredDecls that have been emitted

2022-08-27 Thread Jun Zhang via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa4f84f1b2e92: [CodeGen] Track DeferredDecls that have been 
emitted (authored by junaire).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130831

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/Interpreter/lambda.cpp


Index: clang/test/Interpreter/lambda.cpp
===
--- /dev/null
+++ clang/test/Interpreter/lambda.cpp
@@ -0,0 +1,21 @@
+// RUN: clang-repl "int x = 10;" "int y=7; err;" "int y = 10;"
+// RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
+// RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck 
--check-prefix=CHECK-DRIVER %s
+// REQUIRES: host-supports-jit
+// UNSUPPORTED: system-aix
+// CHECK-DRIVER: i = 10
+// RUN: cat %s | clang-repl | FileCheck %s
+// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
+extern "C" int printf(const char *, ...);
+
+auto l1 = []() { printf("ONE\n"); return 42; };
+auto l2 = []() { printf("TWO\n"); return 17; };
+
+auto r1 = l1();
+// CHECK: ONE
+auto r2 = l2();
+// CHECK: TWO
+auto r3 = l2();
+// CHECK: TWO
+
+%quit
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -3356,6 +3356,7 @@
 // The value must be emitted, but cannot be emitted eagerly.
 assert(!MayBeEmittedEagerly(Global));
 addDeferredDeclToEmit(GD);
+EmittedDeferredDecls[MangledName] = GD;
   } else {
 // Otherwise, remember that we saw a deferred decl with this name.  The
 // first use of the mangled name will cause it to move into
@@ -4073,6 +4074,7 @@
   // DeferredDeclsToEmit list, and remove it from DeferredDecls (since we
   // don't need it anymore).
   addDeferredDeclToEmit(DDI->second);
+  EmittedDeferredDecls[DDI->first] = DDI->second;
   DeferredDecls.erase(DDI);
 
   // Otherwise, there are cases we have to worry about where we're
@@ -4354,6 +4356,7 @@
 // Move the potentially referenced deferred decl to the DeferredDeclsToEmit
 // list, and remove it from DeferredDecls (since we don't need it anymore).
 addDeferredDeclToEmit(DDI->second);
+EmittedDeferredDecls[DDI->first] = DDI->second;
 DeferredDecls.erase(DDI);
   }
 


Index: clang/test/Interpreter/lambda.cpp
===
--- /dev/null
+++ clang/test/Interpreter/lambda.cpp
@@ -0,0 +1,21 @@
+// RUN: clang-repl "int x = 10;" "int y=7; err;" "int y = 10;"
+// RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
+// RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s
+// REQUIRES: host-supports-jit
+// UNSUPPORTED: system-aix
+// CHECK-DRIVER: i = 10
+// RUN: cat %s | clang-repl | FileCheck %s
+// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
+extern "C" int printf(const char *, ...);
+
+auto l1 = []() { printf("ONE\n"); return 42; };
+auto l2 = []() { printf("TWO\n"); return 17; };
+
+auto r1 = l1();
+// CHECK: ONE
+auto r2 = l2();
+// CHECK: TWO
+auto r3 = l2();
+// CHECK: TWO
+
+%quit
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -3356,6 +3356,7 @@
 // The value must be emitted, but cannot be emitted eagerly.
 assert(!MayBeEmittedEagerly(Global));
 addDeferredDeclToEmit(GD);
+EmittedDeferredDecls[MangledName] = GD;
   } else {
 // Otherwise, remember that we saw a deferred decl with this name.  The
 // first use of the mangled name will cause it to move into
@@ -4073,6 +4074,7 @@
   // DeferredDeclsToEmit list, and remove it from DeferredDecls (since we
   // don't need it anymore).
   addDeferredDeclToEmit(DDI->second);
+  EmittedDeferredDecls[DDI->first] = DDI->second;
   DeferredDecls.erase(DDI);
 
   // Otherwise, there are cases we have to worry about where we're
@@ -4354,6 +4356,7 @@
 // Move the potentially referenced deferred decl to the DeferredDeclsToEmit
 // list, and remove it from DeferredDecls (since we don't need it anymore).
 addDeferredDeclToEmit(DDI->second);
+EmittedDeferredDecls[DDI->first] = DDI->second;
 DeferredDecls.erase(DDI);
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a4f84f1 - [CodeGen] Track DeferredDecls that have been emitted

2022-08-27 Thread Jun Zhang via cfe-commits

Author: Jun Zhang
Date: 2022-08-27T22:32:47+08:00
New Revision: a4f84f1b2e92ea79b70b9961049a1af7d9e1f2fa

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

LOG: [CodeGen] Track DeferredDecls that have been emitted

If we run into a first usage or definition of a mangled name, and
there's a DeferredDecl that associated with it, we should remember it we
need to emit it later on.

Without this patch, clang-repl hits a JIT symbol not found error:
clang-repl> extern "C" int printf(const char *, ...);
clang-repl> auto l1 = []() { printf("ONE\n"); return 42; };
clang-repl> auto l2 = []() { printf("TWO\n"); return 17; };
clang-repl> auto r1 = l1();
ONE
clang-repl> auto r2 = l2();
TWO
clang-repl> auto r3 = l2();
JIT session error: Symbols not found: [ l2 ]
error: Failed to materialize symbols: { (main,
{ r3, orc_init_func.incr_module_5, $.incr_module_5.inits.0 }) }

Signed-off-by: Jun Zhang 

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

Added: 
clang/test/Interpreter/lambda.cpp

Modified: 
clang/lib/CodeGen/CodeGenModule.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 2ced1c5419813..6294fe9e87d32 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3356,6 +3356,7 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) {
 // The value must be emitted, but cannot be emitted eagerly.
 assert(!MayBeEmittedEagerly(Global));
 addDeferredDeclToEmit(GD);
+EmittedDeferredDecls[MangledName] = GD;
   } else {
 // Otherwise, remember that we saw a deferred decl with this name.  The
 // first use of the mangled name will cause it to move into
@@ -4073,6 +4074,7 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(
   // DeferredDeclsToEmit list, and remove it from DeferredDecls (since we
   // don't need it anymore).
   addDeferredDeclToEmit(DDI->second);
+  EmittedDeferredDecls[DDI->first] = DDI->second;
   DeferredDecls.erase(DDI);
 
   // Otherwise, there are cases we have to worry about where we're
@@ -4354,6 +4356,7 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef 
MangledName, llvm::Type *Ty,
 // Move the potentially referenced deferred decl to the DeferredDeclsToEmit
 // list, and remove it from DeferredDecls (since we don't need it anymore).
 addDeferredDeclToEmit(DDI->second);
+EmittedDeferredDecls[DDI->first] = DDI->second;
 DeferredDecls.erase(DDI);
   }
 

diff  --git a/clang/test/Interpreter/lambda.cpp 
b/clang/test/Interpreter/lambda.cpp
new file mode 100644
index 0..d06009d59fe08
--- /dev/null
+++ b/clang/test/Interpreter/lambda.cpp
@@ -0,0 +1,21 @@
+// RUN: clang-repl "int x = 10;" "int y=7; err;" "int y = 10;"
+// RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
+// RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck 
--check-prefix=CHECK-DRIVER %s
+// REQUIRES: host-supports-jit
+// UNSUPPORTED: system-aix
+// CHECK-DRIVER: i = 10
+// RUN: cat %s | clang-repl | FileCheck %s
+// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
+extern "C" int printf(const char *, ...);
+
+auto l1 = []() { printf("ONE\n"); return 42; };
+auto l2 = []() { printf("TWO\n"); return 17; };
+
+auto r1 = l1();
+// CHECK: ONE
+auto r2 = l2();
+// CHECK: TWO
+auto r3 = l2();
+// CHECK: TWO
+
+%quit



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


[PATCH] D127973: [analyzer] Eval construction of non POD type arrays.

2022-08-27 Thread Domján Dániel via Phabricator via cfe-commits
isuckatcs added a comment.

> I'm wondering if we should have a window for backward compatibility; There 
> are a couple of places already where we check for the presence of some 
> metadata and display it only if it exists.
> Do you think it would be useful for this change as well?

It has been fixed in D131187  as a part of 
another change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127973

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


[PATCH] D131479: Handle explicitly defaulted consteval special members.

2022-08-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D131479#3753462 , @Mordante wrote:

> This change breaks the libc++ test 
> `libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/move.fail.cpp`.
>  
> (https://buildkite.com/llvm-project/libcxx-ci/builds/13149#0182d0d4-341a-4b41-b67f-12937f41e6d5)
>
> Looking at the description of this patch it should only affect `consteval` 
> functions, but it seems to affect `constexpr` functions too. Can you have a 
> look?

Agreed that we should take a look, but it's interesting to note that libstdc++ 
seems to have a different behavior than libc++ here: 
https://godbolt.org/z/6cWhf6GYj (the last three compiler panes show Clang 14 
libstd++, Clang 14 libc++, and Clang trunk libc++). How sure are you that the 
libc++ test is actually correct, because (without checking the standard, so 
take with a giant grain of salt) this seems like it might have fixed a bug in 
libc++? The release note says this is expected to impact constexpr and 
consteval default special member functions, so behavioral changes to 
`constexpr` aren't unexpected (though I agree that the commit message didn't 
mention `constexpr` so the changes may seem surprising).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131479

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


[PATCH] D132749: Expose QualType::getUnqualifiedType in libclang

2022-08-27 Thread Luca Di sera via Phabricator via cfe-commits
diseraluca updated this revision to Diff 456116.
diseraluca added a comment.

Fixed some typos in the added documentation of `clang_getUnqualifiedType`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132749

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang-c/Index.h
  clang/tools/libclang/CXType.cpp
  clang/tools/libclang/libclang.map
  clang/unittests/libclang/LibclangTest.cpp

Index: clang/unittests/libclang/LibclangTest.cpp
===
--- clang/unittests/libclang/LibclangTest.cpp
+++ clang/unittests/libclang/LibclangTest.cpp
@@ -843,6 +843,54 @@
   },
   nullptr);
 }
+
+TEST_F(LibclangParseTest, clang_getUnqualifiedTypeRemovesQualifiers) {
+  std::string Header = "header.h";
+  WriteFile(Header, "void foo1(const int);\n"
+"void foo2(volatile int);\n"
+"void foo3(const volatile int);\n"
+"void foo4(int* const);\n"
+"void foo5(int* volatile);\n"
+"void foo6(int* restrict);\n"
+"void foo7(int* const volatile);\n"
+"void foo8(int* volatile restrict);\n"
+"void foo9(int* const restrict);\n"
+"void foo10(int* const volatile restrict);\n");
+
+  auto is_qualified = [](CXType type) -> bool {
+return clang_isConstQualifiedType(type) ||
+   clang_isVolatileQualifiedType(type) ||
+   clang_isRestrictQualifiedType(type);
+  };
+
+  auto from_CXString = [](CXString cx_string) -> std::string {
+std::string string{clang_getCString(cx_string)};
+
+clang_disposeString(cx_string);
+
+return string;
+  };
+
+  ClangTU = clang_parseTranslationUnit(Index, Header.c_str(), nullptr, 0,
+   nullptr, 0, TUFlags);
+
+  Traverse([&is_qualified, &from_CXString](CXCursor cursor, CXCursor) {
+if (clang_getCursorKind(cursor) == CXCursor_FunctionDecl) {
+  CXType arg_type = clang_getArgType(clang_getCursorType(cursor), 0);
+  EXPECT_TRUE(is_qualified(arg_type))
+  << "Input data '" << from_CXString(clang_getCursorSpelling(cursor))
+  << "' first argument does not have a qualified type.";
+
+  CXType unqualified_arg_type = clang_getUnqualifiedType(arg_type);
+  EXPECT_FALSE(is_qualified(unqualified_arg_type))
+  << "The type '" << from_CXString(clang_getTypeSpelling(arg_type))
+  << "' was not unqualified after a call to clang_getUnqualifiedType.";
+}
+
+return CXChildVisit_Continue;
+  });
+}
+
 class LibclangRewriteTest : public LibclangParseTest {
 public:
   CXRewriter Rew = nullptr;
Index: clang/tools/libclang/libclang.map
===
--- clang/tools/libclang/libclang.map
+++ clang/tools/libclang/libclang.map
@@ -405,6 +405,11 @@
   local: *;
 };
 
+LLVM_16 {
+  global:
+clang_getUnqualifiedType;
+};
+
 # Example of how to add a new symbol version entry.  If you do add a new symbol
 # version, please update the example to depend on the version you added.
 # LLVM_X {
Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -484,6 +484,10 @@
   return MakeCXType(T, GetTU(CT));
 }
 
+CXType clang_getUnqualifiedType(CXType CT) {
+  return MakeCXType(GetQualType(CT).getUnqualifiedType(), GetTU(CT));
+}
+
 CXCursor clang_getTypeDeclaration(CXType CT) {
   if (CT.kind == CXType_Invalid)
 return cxcursor::MakeCXCursorInvalid(CXCursor_NoDeclFound);
Index: clang/include/clang-c/Index.h
===
--- clang/include/clang-c/Index.h
+++ clang/include/clang-c/Index.h
@@ -3760,6 +3760,43 @@
  */
 CINDEX_LINKAGE CXType clang_getPointeeType(CXType T);
 
+/**
+ * Retrieve the unqualified variant of the given type, removing as
+ * little sugar as possible.
+ *
+ * For example, given the following series of typedefs:
+ *
+ * \code
+ * typedef int Integer;
+ * typedef const Integer CInteger;
+ * typedef CInteger DifferenceType;
+ * \endcode
+ *
+ * Executing \c clang_getUnqualifiedType() on a \c CXType that
+ * represents \c DifferenceType, will desugar to a type representing
+ * \c Integer, that has no qualifiers.
+ *
+ * And, executing \c clang_getUnqualifiedType() on the type of the
+ * first argument of the following function declaration:
+ *
+ * \code
+ * void foo(const int);
+ * \endcode
+ *
+ * Will return a type representing \c int, removing the \c const
+ * qualifier.
+ *
+ * Sugar over array types is not desugared.
+ *
+ * A type can be checked for qualifiers with \c
+ * clang_isConstQualifiedType(), \c clang_isVolatileQualifiedType()
+ * and \c clang_isRestrictQualifiedType().
+ *
+ * A type that resulted from a call to \c clang_getUnquali

[PATCH] D131388: [docs] Add "Standard C++ Modules"

2022-08-27 Thread Aaron Siddhartha Mondal via Phabricator via cfe-commits
aaronmondal added a comment.

@ChuanqiXu Thanks a lot for this!

We are currently implementing this module logic in the Bazel ruleset rules_ll 
.
This page helps clarify the differences between clang modules and C++ modules a 
lot. If I knew about this earlier we'd probably have saved a lot of time 😅

After reading this doc, a few things came to my mind. I can add a patch for 
this as a follow-up diff when I better understand how things work.

- The path logic that references the source files in BMIs is very important. 
When precompiling a module in one directory and then moving a header included 
in the global module fragment from the source file, things will break.
- As a result of this, some unintuitive things can happen when using sandboxed 
compilation. E.g. precompile BMI in sandbox, move BMI out of that sandbox, then 
start another sandbox that loads the previously built BMI. If the BMI used 
headers in a global module fragment, and those headers were in the original 
sandboxe, the header in the new sandbox will be in a different location 
(because the new sandbox is at a new location) and things will break.
- Clang modulemaps are cool, but for build systems that have to declare every 
output, implicit modulemaps seem like a bad idea. Clang's caching system, even 
with custom cache paths seems like a bad idea as well. It is probably helpful 
to mention caveats of implicit modules and how to disable them (or link to the 
Clang Module docs for this).
- The doc describes how to build e.g. an `iostream` module using the C++ 
semantics, but doesn't mention that AFAIK there is no "native" C++ Module build 
for libcxx yet. One would currently actually use Clang modules with implicit 
modulemaps. It may be helpful to mention this to avoid confusion.
- Issue https://github.com/llvm/llvm-project/issues/56770 and 
seems-to-be-a-consequence-issue 
https://github.com/llvm/llvm-project/issues/57293 may be relevant apart from 
the already mentioned issue about clang-scan-deps.


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

https://reviews.llvm.org/D131388

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


[PATCH] D132749: Expose QualType::getUnqualifiedType in libclang

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



Comment at: clang/include/clang-c/Index.h:3775
+ *
+ * Executing \c clang_getUnuqalifiedType() on a \c CXType that
+ * represents \c DifferenceType, will desugar to a type representing

Typo: Unuqualified



Comment at: clang/include/clang-c/Index.h:3779
+ *
+ * And, executing \c clang_getUnuqalifiedType() on the type of the
+ * first argument of the following function declaration:

Same



Comment at: clang/include/clang-c/Index.h:3792
+ * A type can be checked for qualifiers with \c
+ * clang_isConstQualifiedType(), \c clang_isVolativeQualifiedType()
+ * and \c clang_isRestrictQualifiedType().

Typo: Volative


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132749

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


[PATCH] D132568: [clang][Sema] check default argument promotions for printf

2022-08-27 Thread YingChi Long via Phabricator via cfe-commits
inclyc updated this revision to Diff 456111.
inclyc added a comment.

Delete extra newline.

Currently this patch has not fully implemented `wchar_t` related support, this
type seems to be even platform dependent in C language, if possible, maybe we
can consider support in subsequent patches?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132568

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/FormatString.h
  clang/lib/AST/FormatString.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/format-strings-freebsd.c
  clang/test/Sema/format-strings-scanf.c
  clang/test/Sema/format-strings.c
  clang/www/c_status.html

Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -819,13 +819,7 @@
 
   Unclear type relationship between a format specifier and its argument
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2562.pdf";>N2562
-  
-Partial
-  Clang supports diagnostics checking format specifier validity, but
-  does not yet account for all of the changes in this paper, especially
-  regarding length modifiers like h and hh.
-
-  
+  Clang 16
 
 
 
Index: clang/test/Sema/format-strings.c
===
--- clang/test/Sema/format-strings.c
+++ clang/test/Sema/format-strings.c
@@ -830,3 +830,57 @@
   printf_arg2("foo", "%s string %i\n", "aaa", 123);
   printf_arg2("%s string\n", "foo", "bar"); // expected-warning{{data argument not used by format string}}
 }
+
+void test_promotion(void) {
+  // Default argument promotions for *printf in N2562
+  // https://github.com/llvm/llvm-project/issues/57102
+  // N2562: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2562.pdf
+  int i;
+  signed char sc;
+  unsigned char uc;
+  char c;
+  short ss;
+  unsigned short us;
+
+  printf("%hhd %hd %d %hhd %hd %d", i, i, i, sc, sc, sc); // no-warning
+  printf("%hhd %hd %d %hhd %hd %d", uc, uc, uc, c, c, c); // no-warning
+
+  // %ld %lld %llx
+  printf("%ld", i); // expected-warning{{format specifies type 'long' but the argument has type 'int'}}
+  printf("%lld", i); // expected-warning{{format specifies type 'long long' but the argument has type 'int'}}
+  printf("%ld", sc); // expected-warning{{format specifies type 'long' but the argument has type 'signed char'}}
+  printf("%lld", sc); // expected-warning{{format specifies type 'long long' but the argument has type 'signed char'}}
+  printf("%ld", uc); // expected-warning{{format specifies type 'long' but the argument has type 'unsigned char'}}
+  printf("%lld", uc); // expected-warning{{format specifies type 'long long' but the argument has type 'unsigned char'}}
+  printf("%llx", i); // expected-warning{{format specifies type 'unsigned long long' but the argument has type 'int'}}
+
+  // ill formed spec for floats
+  printf("%hf", // expected-warning{{length modifier 'h' results in undefined behavior or no effect with 'f' conversion specifier}}
+  sc); // expected-warning{{format specifies type 'double' but the argument has type 'signed char'}}
+
+  // for %hhd and `short` they are compatible by promotions but more likely misuse
+  printf("%hd", ss); // no-warning
+  printf("%hhd", ss); // expected-warning{{format specifies type 'char' but the argument has type 'short'}}
+  printf("%hu", us); // no-warning
+  printf("%hhu", ss); // expected-warning{{format specifies type 'unsigned char' but the argument has type 'short'}}
+
+  // floats & integers are not compatible
+  printf("%f", i); // expected-warning{{format specifies type 'double' but the argument has type 'int'}}
+  printf("%f", sc); // expected-warning{{format specifies type 'double' but the argument has type 'signed char'}}
+  printf("%f", uc); // expected-warning{{format specifies type 'double' but the argument has type 'unsigned char'}}
+  printf("%f", c); // expected-warning{{format specifies type 'double' but the argument has type 'char'}}
+  printf("%f", ss); // expected-warning{{format specifies type 'double' but the argument has type 'short'}}
+  printf("%f", us); // expected-warning{{format specifies type 'double' but the argument has type 'unsigned short'}}
+
+  // character literals
+  // In C language engineering practice, printing a character literal with %hhd or %d is common, but %hd may be misuse.
+  printf("%hhu", 'a'); // no-warning
+  printf("%hhd", 'a'); // no-warning
+  printf("%hd", 'a'); // expected-warning{{format specifies type 'short' but the argument has type 'char'}}
+  printf("%hu", 'a'); // expected-warning{{format specifies type 'unsigned short' but the argument has type 'char'}}
+  printf("%d", 'a'); // no-warning
+  printf("%u", 'a'); // no-warning
+  
+  // pointers
+  printf("%s", i); // expected-warning{{format specifies type 'char *' but the a

[PATCH] D131479: Handle explicitly defaulted consteval special members.

2022-08-27 Thread Mark de Wever via Phabricator via cfe-commits
Mordante added a comment.

This change breaks the libc++ test 
`libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/move.fail.cpp`.
 
(https://buildkite.com/llvm-project/libcxx-ci/builds/13149#0182d0d4-341a-4b41-b67f-12937f41e6d5)

Looking at the description of this patch it should only affect `consteval` 
functions, but it seems to affect `constexpr` functions too. Can you have a 
look?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131479

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


[clang-tools-extra] 69c20a1 - [clang-tidy] Move bugprone-assignment-in-if-condition check to correct folder

2022-08-27 Thread Nathan James via cfe-commits

Author: Nathan James
Date: 2022-08-27T11:24:57+01:00
New Revision: 69c20a1f49aa5e19ed8ad291598caa1ec3b4d8f5

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

LOG: [clang-tidy] Move bugprone-assignment-in-if-condition check to correct 
folder

Added: 

clang-tools-extra/test/clang-tidy/checkers/bugprone/assignment-in-if-condition.cpp

Modified: 


Removed: 

clang-tools-extra/test/clang-tidy/checkers/bugprone-assignment-in-if-condition.cpp



diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone-assignment-in-if-condition.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/assignment-in-if-condition.cpp
similarity index 100%
rename from 
clang-tools-extra/test/clang-tidy/checkers/bugprone-assignment-in-if-condition.cpp
rename to 
clang-tools-extra/test/clang-tidy/checkers/bugprone/assignment-in-if-condition.cpp



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


[PATCH] D132786: [clang-tidy] Fix a false positive in bugprone-assignment-in-if-condition

2022-08-27 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added reviewers: aaron.ballman, alexfh, LegalizeAdulthood, gribozavr2, 
dodohand.
Herald added subscribers: carlosgalvezp, xazax.hun.
Herald added a project: All.
njames93 requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Fixed a false positive where a lambda expression in the condition which 
contained an assignement would trigger a warning.
Fixes #56729


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132786

Files:
  clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-assignment-in-if-condition.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/assignment-in-if-condition.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/assignment-in-if-condition.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/assignment-in-if-condition.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/assignment-in-if-condition.cpp
@@ -101,3 +101,20 @@
 f = 5;
   }
 }
+
+template  bool exec(Func F) { return F(); }
+
+void lambda_if() {
+  int X;
+  if ([&X] {
+X = 5;
+return true;
+  }()) {
+  }
+
+  if (exec([&] {
+X = 5;
+return true;
+  })) {
+  }
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -116,6 +116,10 @@
 Changes in existing checks
 ^^
 
+- Fixed a false positive in :doc:`bugprone-assignment-in-if-condition
+  ` check when there
+  was an assignement in a lambda found in the condition of an ``if``.
+
 - Improved :doc:`bugprone-signal-handler
   ` check. Partial
   support for C++14 signal handler rules was added. Bug report generation was
Index: clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.h
===
--- clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.h
@@ -25,6 +25,7 @@
   : ClangTidyCheck(Name, Context) {}
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  void report(const Expr *E);
 };
 
 } // namespace bugprone
Index: clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
@@ -8,7 +8,10 @@
 
 #include "AssignmentInIfConditionCheck.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 
 using namespace clang::ast_matchers;
 
@@ -17,23 +20,50 @@
 namespace bugprone {
 
 void AssignmentInIfConditionCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(ifStmt(hasCondition(forEachDescendant(
- binaryOperator(isAssignmentOperator())
- .bind("assignment_in_if_statement",
- this);
-  Finder->addMatcher(ifStmt(hasCondition(forEachDescendant(
- cxxOperatorCallExpr(isAssignmentOperator())
- .bind("assignment_in_if_statement",
- this);
+  Finder->addMatcher(translationUnitDecl(), this);
 }
 
 void AssignmentInIfConditionCheck::check(
-const MatchFinder::MatchResult &Result) {
-  const auto *MatchedDecl =
-  Result.Nodes.getNodeAs("assignment_in_if_statement");
-  if (!MatchedDecl) {
-return;
-  }
+const ast_matchers::MatchFinder::MatchResult &Result) {
+  class Visitor : public RecursiveASTVisitor {
+AssignmentInIfConditionCheck &Check;
+
+  public:
+explicit Visitor(AssignmentInIfConditionCheck &Check) : Check(Check) {}
+bool VisitIfStmt(IfStmt *If) {
+  class ConditionVisitor : public RecursiveASTVisitor {
+AssignmentInIfConditionCheck &Check;
+
+  public:
+explicit ConditionVisitor(AssignmentInIfConditionCheck &Check)
+: Check(Check) {}
+
+// Dont traverse into any lambda expressions.
+bool TraverseLambdaExpr(LambdaExpr *, DataRecursionQueue * = nullptr) {
+  return true;
+}
+
+bool VisitBinaryOperator(BinaryOperator *BO) {
+  if (BO->isAssignmentOp())
+Check.report(BO);
+  return true;
+}
+
+bool VisitCXXOperatorCallExpr(CXXOp

[PATCH] D132749: Expose QualType::getUnqualifiedType in libclang

2022-08-27 Thread Luca Di sera via Phabricator via cfe-commits
diseraluca added a comment.

In D132749#3752419 , @aaron.ballman 
wrote:

> 

> Welcome to the community!

Thank you for the kind welcome!

> Feel free to put up a new review for that and add me as a reviewer, I'm happy 
> to look at it

Thank you, I'll be sure to do that.

> In terms of this patch, it looks good to me, but can you add a release note 
> for the improvement?

This should be done now.

> What name and email address would you like used for patch attribution?

Name: Luca Di Sera
email: disera [dot] luca [at] gmail [dot] com

Is there a way for me to configure this so that it is picked up automatically?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132749

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


[PATCH] D132749: Expose QualType::getUnqualifiedType in libclang

2022-08-27 Thread Luca Di sera via Phabricator via cfe-commits
diseraluca updated this revision to Diff 456099.
diseraluca added a comment.

Added a note to the release-notes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132749

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang-c/Index.h
  clang/tools/libclang/CXType.cpp
  clang/tools/libclang/libclang.map
  clang/unittests/libclang/LibclangTest.cpp

Index: clang/unittests/libclang/LibclangTest.cpp
===
--- clang/unittests/libclang/LibclangTest.cpp
+++ clang/unittests/libclang/LibclangTest.cpp
@@ -843,6 +843,54 @@
   },
   nullptr);
 }
+
+TEST_F(LibclangParseTest, clang_getUnqualifiedTypeRemovesQualifiers) {
+  std::string Header = "header.h";
+  WriteFile(Header, "void foo1(const int);\n"
+"void foo2(volatile int);\n"
+"void foo3(const volatile int);\n"
+"void foo4(int* const);\n"
+"void foo5(int* volatile);\n"
+"void foo6(int* restrict);\n"
+"void foo7(int* const volatile);\n"
+"void foo8(int* volatile restrict);\n"
+"void foo9(int* const restrict);\n"
+"void foo10(int* const volatile restrict);\n");
+
+  auto is_qualified = [](CXType type) -> bool {
+return clang_isConstQualifiedType(type) ||
+   clang_isVolatileQualifiedType(type) ||
+   clang_isRestrictQualifiedType(type);
+  };
+
+  auto from_CXString = [](CXString cx_string) -> std::string {
+std::string string{clang_getCString(cx_string)};
+
+clang_disposeString(cx_string);
+
+return string;
+  };
+
+  ClangTU = clang_parseTranslationUnit(Index, Header.c_str(), nullptr, 0,
+   nullptr, 0, TUFlags);
+
+  Traverse([&is_qualified, &from_CXString](CXCursor cursor, CXCursor) {
+if (clang_getCursorKind(cursor) == CXCursor_FunctionDecl) {
+  CXType arg_type = clang_getArgType(clang_getCursorType(cursor), 0);
+  EXPECT_TRUE(is_qualified(arg_type))
+  << "Input data '" << from_CXString(clang_getCursorSpelling(cursor))
+  << "' first argument does not have a qualified type.";
+
+  CXType unqualified_arg_type = clang_getUnqualifiedType(arg_type);
+  EXPECT_FALSE(is_qualified(unqualified_arg_type))
+  << "The type '" << from_CXString(clang_getTypeSpelling(arg_type))
+  << "' was not unqualified after a call to clang_getUnqualifiedType.";
+}
+
+return CXChildVisit_Continue;
+  });
+}
+
 class LibclangRewriteTest : public LibclangParseTest {
 public:
   CXRewriter Rew = nullptr;
Index: clang/tools/libclang/libclang.map
===
--- clang/tools/libclang/libclang.map
+++ clang/tools/libclang/libclang.map
@@ -405,6 +405,11 @@
   local: *;
 };
 
+LLVM_16 {
+  global:
+clang_getUnqualifiedType;
+};
+
 # Example of how to add a new symbol version entry.  If you do add a new symbol
 # version, please update the example to depend on the version you added.
 # LLVM_X {
Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -484,6 +484,10 @@
   return MakeCXType(T, GetTU(CT));
 }
 
+CXType clang_getUnqualifiedType(CXType CT) {
+  return MakeCXType(GetQualType(CT).getUnqualifiedType(), GetTU(CT));
+}
+
 CXCursor clang_getTypeDeclaration(CXType CT) {
   if (CT.kind == CXType_Invalid)
 return cxcursor::MakeCXCursorInvalid(CXCursor_NoDeclFound);
Index: clang/include/clang-c/Index.h
===
--- clang/include/clang-c/Index.h
+++ clang/include/clang-c/Index.h
@@ -3760,6 +3760,43 @@
  */
 CINDEX_LINKAGE CXType clang_getPointeeType(CXType T);
 
+/**
+ * Retrieve the unqualified variant of the given type, removing as
+ * little sugar as possible.
+ *
+ * For example, given the following series of typedefs:
+ *
+ * \code
+ * typedef int Integer;
+ * typedef const Integer CInteger;
+ * typedef CInteger DifferenceType;
+ * \endcode
+ *
+ * Executing \c clang_getUnuqalifiedType() on a \c CXType that
+ * represents \c DifferenceType, will desugar to a type representing
+ * \c Integer, that has no qualifiers.
+ *
+ * And, executing \c clang_getUnuqalifiedType() on the type of the
+ * first argument of the following function declaration:
+ *
+ * \code
+ * void foo(const int);
+ * \endcode
+ *
+ * Will return a type representing \c int, removing the \c const
+ * qualifier.
+ *
+ * Sugar over array type is not desugared.
+ *
+ * A type can be checked for qualifiers with \c
+ * clang_isConstQualifiedType(), \c clang_isVolativeQualifiedType()
+ * and \c clang_isRestrictQualifiedType().
+ *
+ * A type that resulted from a call to \c clang_getUnqualifiedType
+ * will return \c false for all

[PATCH] D130793: [clang-tidy] adjust treating of array-of-pointers when 'AnalyzePointers' is deactivated

2022-08-27 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-values.cpp:27-30
+  for (const int *p_local1 : p_local0) {
+  // CHECK-MESSAGES: [[@LINE-1]]:8: warning: variable 'p_local1' of type 
'const int *' can be declared 'const'
+  // CHECK-FIXES: for (const int *const p_local1 : p_local0)
+  }

Wouldn't this behaviour be expected before the changes added in this patch, as 
p_local1 isn't an array type.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130793

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


[clang] b831af5 - [libTooling] Simplify code with constexpr if. NFCI.

2022-08-27 Thread Benjamin Kramer via cfe-commits

Author: Benjamin Kramer
Date: 2022-08-27T10:50:06+02:00
New Revision: b831af51977b4150763d69a26a2d912459c1114d

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

LOG: [libTooling] Simplify code with constexpr if. NFCI.

Added: 


Modified: 
clang/include/clang/Tooling/Transformer/Transformer.h

Removed: 




diff  --git a/clang/include/clang/Tooling/Transformer/Transformer.h 
b/clang/include/clang/Tooling/Transformer/Transformer.h
index 4e93783f2b9d9..23683bfb86036 100644
--- a/clang/include/clang/Tooling/Transformer/Transformer.h
+++ b/clang/include/clang/Tooling/Transformer/Transformer.h
@@ -112,22 +112,7 @@ class Transformer : public 
ast_matchers::MatchFinder::MatchCallback {
 };
 
 namespace detail {
-/// Asserts that all \c Metadata for the \c Rule is set.
-/// FIXME: Use constexpr-if in C++17.
-/// @{
-template 
-void assertMetadataSet(const transformer::RewriteRuleWith &Rule) {
-  assert(llvm::all_of(Rule.Metadata,
-  [](const typename transformer::Generator &Metadata)
-  -> bool { return !!Metadata; }) &&
- "metadata generator must be provided for each rule");
-}
-template <>
-inline void assertMetadataSet(const transformer::RewriteRuleWith &) {}
-/// @}
-
 /// Runs the metadata generator on \c Rule and stuffs it into \c Result.
-/// FIXME: Use constexpr-if in C++17.
 /// @{
 template 
 llvm::Error
@@ -135,17 +120,12 @@ populateMetadata(const transformer::RewriteRuleWith 
&Rule,
  size_t SelectedCase,
  const ast_matchers::MatchFinder::MatchResult &Match,
  TransformerResult &Result) {
-  auto Metadata = Rule.Metadata[SelectedCase]->eval(Match);
-  if (!Metadata)
-return Metadata.takeError();
-  Result.Metadata = std::move(*Metadata);
-  return llvm::Error::success();
-}
-template <>
-inline llvm::Error
-populateMetadata(const transformer::RewriteRuleWith &, size_t,
- const ast_matchers::MatchFinder::MatchResult &Match,
- TransformerResult &) {
+  if constexpr (!std::is_void_v) {
+auto Metadata = Rule.Metadata[SelectedCase]->eval(Match);
+if (!Metadata)
+  return Metadata.takeError();
+Result.Metadata = std::move(*Metadata);
+  }
   return llvm::Error::success();
 }
 /// @}
@@ -165,7 +145,11 @@ template  class WithMetadataImpl final : 
public TransformerImpl {
 [](const transformer::RewriteRuleBase::Case &Case)
 -> bool { return !!Case.Edits; }) &&
"edit generator must be provided for each rule");
-assertMetadataSet(Rule);
+if constexpr (!std::is_void_v)
+  assert(llvm::all_of(Rule.Metadata,
+  [](const typename transformer::Generator 
&Metadata)
+  -> bool { return !!Metadata; }) &&
+ "metadata generator must be provided for each rule");
   }
 
 private:



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


[PATCH] D131979: [clang][UBSan] Fix __builtin_assume_aligned crash

2022-08-27 Thread Wang Yihan via Phabricator via cfe-commits
yihanaa added a comment.

In D131979#3752208 , @rjmccall wrote:

> From the test case, it looks like the builtin just ignores pointers to 
> volatile types, which should be preserved by the conversions you're now doing 
> in Sema.  That is, you should be able to just check 
> `Ptr->getType()->castAs()->getPointeeType().isVolatile()`.
>
> It would be different if it ignored pointers loaded out of volatile l-values 
> or something, but that's explicitly not what it's doing.

Thanks for your tips John, form the test case global constants and compiler-rt 
ubsan class TypeDescriptor, it looks like pass an type description to 
__ubsan_handle_alignment_assumption, so, we have to use getSubExprAsWritten to 
get the origin(user written arg type) type description of 1st arg, but not 
'const void *', for example,   in 
catch-alignment-assumption-builtin_assume_aligned-three-params.cpp, the 1st arg 
type description is 'char **', but if we don't use getSubExprAsWritten, all the 
type description will be 'const void *'


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131979

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


[PATCH] D128830: [Pipelines] Introduce DAE after ArgumentPromotion

2022-08-27 Thread Pavel Samolysov via Phabricator via cfe-commits
psamolysov added a comment.

@aeubanks Thank you for the investigation! I believe this patch can be 
re-landed after D132764  is committed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128830

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