[clang-tools-extra] 845618c - [clang-tidy] Refactor common code from the Noexcept*Checks into `NoexceptFunctionCheck`

2023-06-18 Thread Piotr Zegar via cfe-commits

Author: AMS21
Date: 2023-06-18T06:50:05Z
New Revision: 845618cf69e89313084a4e93f8ff31d8e6ea4499

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

LOG: [clang-tidy] Refactor common code from the Noexcept*Checks into 
`NoexceptFunctionCheck`

As discussed in the https://reviews.llvm.org/D148697 review.

Reviewed By: PiotrZSL

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

Added: 
clang-tools-extra/clang-tidy/performance/NoexceptFunctionBaseCheck.cpp
clang-tools-extra/clang-tidy/performance/NoexceptFunctionBaseCheck.h

Modified: 
clang-tools-extra/clang-tidy/performance/CMakeLists.txt
clang-tools-extra/clang-tidy/performance/NoexceptDestructorCheck.cpp
clang-tools-extra/clang-tidy/performance/NoexceptDestructorCheck.h
clang-tools-extra/clang-tidy/performance/NoexceptMoveConstructorCheck.cpp
clang-tools-extra/clang-tidy/performance/NoexceptMoveConstructorCheck.h
clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp
clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.h

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/performance/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/performance/CMakeLists.txt
index 74a2cac092f86..de13894dabc34 100644
--- a/clang-tools-extra/clang-tidy/performance/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/performance/CMakeLists.txt
@@ -16,6 +16,7 @@ add_clang_library(clangTidyPerformanceModule
   NoAutomaticMoveCheck.cpp
   NoIntToPtrCheck.cpp
   NoexceptDestructorCheck.cpp
+  NoexceptFunctionBaseCheck.cpp
   NoexceptMoveConstructorCheck.cpp
   NoexceptSwapCheck.cpp
   PerformanceTidyModule.cpp

diff  --git 
a/clang-tools-extra/clang-tidy/performance/NoexceptDestructorCheck.cpp 
b/clang-tools-extra/clang-tidy/performance/NoexceptDestructorCheck.cpp
index a21451dd232df..9f28b8ef30876 100644
--- a/clang-tools-extra/clang-tidy/performance/NoexceptDestructorCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/NoexceptDestructorCheck.cpp
@@ -7,8 +7,6 @@
 
//===--===//
 
 #include "NoexceptDestructorCheck.h"
-#include "../utils/LexerUtils.h"
-#include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 
 using namespace clang::ast_matchers;
@@ -16,42 +14,21 @@ using namespace clang::ast_matchers;
 namespace clang::tidy::performance {
 
 void NoexceptDestructorCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(
-  functionDecl(unless(isDeleted()), cxxDestructorDecl()).bind("decl"),
-  this);
+  Finder->addMatcher(functionDecl(unless(isDeleted()), cxxDestructorDecl())
+ .bind(BindFuncDeclName),
+ this);
 }
 
-void NoexceptDestructorCheck::check(const MatchFinder::MatchResult &Result) {
-  const auto *FuncDecl = Result.Nodes.getNodeAs("decl");
-  assert(FuncDecl);
-
-  if (SpecAnalyzer.analyze(FuncDecl) !=
-  utils::ExceptionSpecAnalyzer::State::Throwing)
-return;
-
-  // Don't complain about nothrow(false), but complain on nothrow(expr)
-  // where expr evaluates to false.
-  const auto *ProtoType = FuncDecl->getType()->castAs();
-  const Expr *NoexceptExpr = ProtoType->getNoexceptExpr();
-  if (NoexceptExpr) {
-NoexceptExpr = NoexceptExpr->IgnoreImplicit();
-if (!isa(NoexceptExpr)) {
-  diag(NoexceptExpr->getExprLoc(),
-   "noexcept specifier on the destructor evaluates to 'false'");
-}
-return;
-  }
-
-  auto Diag = diag(FuncDecl->getLocation(), "destructors should "
-"be marked noexcept");
-
-  // Add FixIt hints.
-  const SourceManager &SM = *Result.SourceManager;
+DiagnosticBuilder
+NoexceptDestructorCheck::reportMissingNoexcept(const FunctionDecl *FuncDecl) {
+  return diag(FuncDecl->getLocation(), "destructors should "
+   "be marked noexcept");
+}
 
-  const SourceLocation NoexceptLoc =
-  utils::lexer::getLocationForNoexceptSpecifier(FuncDecl, SM);
-  if (NoexceptLoc.isValid())
-Diag << FixItHint::CreateInsertion(NoexceptLoc, " noexcept ");
+void NoexceptDestructorCheck::reportNoexceptEvaluatedToFalse(
+const FunctionDecl *FuncDecl, const Expr *NoexceptExpr) {
+  diag(NoexceptExpr->getExprLoc(),
+   "noexcept specifier on the destructor evaluates to 'false'");
 }
 
 } // namespace clang::tidy::performance

diff  --git 
a/clang-tools-extra/clang-tidy/performance/NoexceptDestructorCheck.h 
b/clang-tools-extra/clang-tidy/performance/NoexceptDestructorCheck.h
index 38ae9272b7de7..ab3850f0970a8 100644
--- a/clang-tools-extra/clang-tidy/performance/NoexceptDestructorCheck.h
+++ b/clang-tools-extra/clang-tidy/performance/NoexceptDestructorCheck.h
@@ -10,7 +10,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TID

[PATCH] D153198: [clang-tidy] Refactor common code from the Noexcept*Checks into `NoexceptFunctionCheck`

2023-06-18 Thread Piotr Zegar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG845618cf69e8: [clang-tidy] Refactor common code from the 
Noexcept*Checks into… (authored by AMS21, committed by PiotrZSL).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153198

Files:
  clang-tools-extra/clang-tidy/performance/CMakeLists.txt
  clang-tools-extra/clang-tidy/performance/NoexceptDestructorCheck.cpp
  clang-tools-extra/clang-tidy/performance/NoexceptDestructorCheck.h
  clang-tools-extra/clang-tidy/performance/NoexceptFunctionBaseCheck.cpp
  clang-tools-extra/clang-tidy/performance/NoexceptFunctionBaseCheck.h
  clang-tools-extra/clang-tidy/performance/NoexceptMoveConstructorCheck.cpp
  clang-tools-extra/clang-tidy/performance/NoexceptMoveConstructorCheck.h
  clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp
  clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.h

Index: clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.h
===
--- clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.h
+++ clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.h
@@ -10,7 +10,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_NOEXCEPTSWAPCHECK_H
 
 #include "../ClangTidyCheck.h"
-#include "../utils/ExceptionSpecAnalyzer.h"
+#include "NoexceptFunctionBaseCheck.h"
 
 namespace clang::tidy::performance {
 
@@ -20,21 +20,17 @@
 ///
 /// For the user-facing documentation see:
 /// https://clang.llvm.org/extra/clang-tidy/checks/performance/noexcept-swap.html
-class NoexceptSwapCheck : public ClangTidyCheck {
+class NoexceptSwapCheck : public NoexceptFunctionBaseCheck {
 public:
-  NoexceptSwapCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  using NoexceptFunctionBaseCheck::NoexceptFunctionBaseCheck;
+
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
-  bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
-return LangOpts.CPlusPlus11 && LangOpts.CXXExceptions;
-  }
-  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
-  std::optional getCheckTraversalKind() const override {
-return TK_IgnoreUnlessSpelledInSource;
-  }
 
 private:
-  utils::ExceptionSpecAnalyzer SpecAnalyzer;
+  DiagnosticBuilder
+  reportMissingNoexcept(const FunctionDecl *FuncDecl) final override;
+  void reportNoexceptEvaluatedToFalse(const FunctionDecl *FuncDecl,
+  const Expr *NoexceptExpr) final override;
 };
 
 } // namespace clang::tidy::performance
Index: clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp
===
--- clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp
+++ clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp
@@ -7,10 +7,7 @@
 //===--===//
 
 #include "NoexceptSwapCheck.h"
-#include "../utils/LexerUtils.h"
-#include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "clang/Lex/Lexer.h"
 
 using namespace clang::ast_matchers;
 
@@ -18,40 +15,20 @@
 
 void NoexceptSwapCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
-  functionDecl(unless(isDeleted()), hasName("swap")).bind("decl"), this);
+  functionDecl(unless(isDeleted()), hasName("swap")).bind(BindFuncDeclName),
+  this);
 }
 
-void NoexceptSwapCheck::check(const MatchFinder::MatchResult &Result) {
-  const auto *FuncDecl = Result.Nodes.getNodeAs("decl");
-  assert(FuncDecl);
-
-  if (SpecAnalyzer.analyze(FuncDecl) !=
-  utils::ExceptionSpecAnalyzer::State::Throwing)
-return;
-
-  // Don't complain about nothrow(false), but complain on nothrow(expr)
-  // where expr evaluates to false.
-  const auto *ProtoType = FuncDecl->getType()->castAs();
-  const Expr *NoexceptExpr = ProtoType->getNoexceptExpr();
-  if (NoexceptExpr) {
-NoexceptExpr = NoexceptExpr->IgnoreImplicit();
-if (!isa(NoexceptExpr)) {
-  diag(NoexceptExpr->getExprLoc(),
-   "noexcept specifier on swap function evaluates to 'false'");
-}
-return;
-  }
-
-  auto Diag = diag(FuncDecl->getLocation(), "swap functions should "
-"be marked noexcept");
-
-  // Add FixIt hints.
-  const SourceManager &SM = *Result.SourceManager;
+DiagnosticBuilder
+NoexceptSwapCheck::reportMissingNoexcept(const FunctionDecl *FuncDecl) {
+  return diag(FuncDecl->getLocation(), "swap functions should "
+   "be marked noexcept");
+}
 
-  const SourceLocation NoexceptLoc =
-  utils::lexer::getLocationForNoexceptSpecifier(FuncDecl, SM);
-  if (NoexceptLoc.isValid())
-Diag << FixItHint::CreateInsertion(NoexceptLoc, " noexcept ");
+void NoexceptSwapCheck::reportNoe

[PATCH] D153220: [clang-tidy] Improve `performance-move-const-arg` message when no move constructor is available

2023-06-18 Thread André Schackier via Phabricator via cfe-commits
AMS21 created this revision.
AMS21 added reviewers: PiotrZSL, carlosgalvezp.
Herald added a subscriber: xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
AMS21 requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

We now display a simple note if the reason is that the used class does not
support move semantics.

This fixes llvm#62550


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153220

Files:
  clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp
@@ -340,3 +340,51 @@
   // CHECK-FIXES: choice(a, std::move(a));
   // CHECK-MESSAGES: :[[@LINE-3]]:24: warning: std::move of the variable 'a' of the trivially-copyable type 'int' has no effect [performance-move-const-arg]
 }
+
+namespace issue_62550 {
+
+struct NonMoveConstructable {
+  NonMoveConstructable();
+  NonMoveConstructable(const NonMoveConstructable&);
+  NonMoveConstructable& operator=(const NonMoveConstructable&);
+  NonMoveConstructable& operator=(NonMoveConstructable&&);
+};
+
+void testNonMoveConstructible() {
+  NonMoveConstructable t1;
+  NonMoveConstructable t2{std::move(t1)};
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg]
+}
+
+struct NonMoveAssignable {
+  NonMoveAssignable();
+  NonMoveAssignable(const NonMoveAssignable&);
+  NonMoveAssignable(NonMoveAssignable&&);
+
+  NonMoveAssignable& operator=(const NonMoveAssignable&);
+};
+
+void testNonMoveAssignable() {
+  NonMoveAssignable t1;
+  NonMoveAssignable t2;
+
+  t2 = std::move(t1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg]
+}
+
+struct NonMoveable {
+  NonMoveable();
+  NonMoveable(const NonMoveable&);
+  NonMoveable& operator=(const NonMoveable&);
+};
+
+void testNonMoveable() {
+  NonMoveable t1;
+  NonMoveable t2{std::move(t1)};
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg]
+
+  t1 = std::move(t2);
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg]
+}
+
+} // namespace issue_62550
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -374,6 +374,10 @@
   `IgnoreTemplateInstantiations` option to optionally ignore virtual function
   overrides that are part of template instantiations.
 
+- Improved :doc:`performance-move-const-arg
+  `: warning when no move
+  constructor is available.
+
 - Improved :doc:`performance-no-automatic-move
   `: warn on ``const &&``
   constructors.
Index: clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
===
--- clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
+++ clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
@@ -103,6 +103,7 @@
 AlreadyCheckedMoves.insert(CallMove);
 
   const Expr *Arg = CallMove->getArg(0);
+  const QualType ArgType = Arg->getType();
   SourceManager &SM = Result.Context->getSourceManager();
 
   CharSourceRange MoveRange =
@@ -112,12 +113,11 @@
   if (!FileMoveRange.isValid())
 return;
 
-  bool IsConstArg = Arg->getType().isConstQualified();
-  bool IsTriviallyCopyable =
-  Arg->getType().isTriviallyCopyableType(*Result.Context);
+  bool IsConstArg = ArgType.isConstQualified();
+  bool IsTriviallyCopyable = ArgType.isTriviallyCopyableType(*Result.Context);
 
   if (IsConstArg || IsTriviallyCopyable) {
-if (const CXXRecordDecl *R = Arg->getType()->getAsCXXRecordDecl()) {
+if (const CXXRecordDecl *R = ArgType->getAsCXXRecordDecl()) {
   // According to [expr.prim.lambda]p3, "whether the closure type is
   // trivially copyable" property can be changed by the implementation of
   // the language, so we shouldn't rely on it when issuing diagnostics.
@@ -151,7 +151,7 @@
   << IsConstArg << IsVariable << IsTriviallyCopyable
   << IsRVRefParam
   << (IsConstArg && IsVariable && !IsTriviallyCopyable) << Var
-  << Arg->getType();
+  << ArgType;
   if (!IsRVRefParam)
   

[PATCH] D153220: [clang-tidy] Improve `performance-move-const-arg` message when no move constructor is available

2023-06-18 Thread André Schackier via Phabricator via cfe-commits
AMS21 added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp:345
+namespace issue_62550 {
+
+struct NonMoveConstructable {

I've tried to add

```
// CHECK-MESSAGES: [[@LINE+1]]:1: note: 'NonMoveConstructable' is not move 
constructible
```

here. But doing so actually fails the tests and I'm not quite sure why.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153220

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


[PATCH] D153218: [clang-tidy] Fix `llvmlibc-inline-function-decl` false positives for templated function definitions

2023-06-18 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL requested changes to this revision.
PiotrZSL added a comment.
This revision now requires changes to proceed.

I got one concern, if you write this:

  template LIBC_INLINE void 
VariadicTemplate::goodVariadicTemplate() {}
  template inline void 
VariadicTemplate::badVariadicTemplate() {}

Aka, no space after `>`, warning will be emitted for both.
That's because of `TemplateParams->getRAngleLoc().getLocWithOffset(1);`
So we find `>` character, then we skip it, now we pointing into `inline` or 
whitespace location, and when we skip to a next token.
If you remove this `getLocWithOffset(1)` then `findNextTokenSkippingComments` 
should work correctly.

Additionally you missing release notes.
There is also other way to deal with this issue, simply use 
`FunctionDecl::getReturnTypeSourceRange()` and work with 
`tidy::utils::lexer::getPreviousToken`.
But in theory both solutions should work fine. Question is also how it will 
work with attributes, like `[[nodiscard]]` that could be put before inline.

Requesting change mainly due to false-positive with space.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153218

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


[PATCH] D153220: [clang-tidy] Improve `performance-move-const-arg` message when no move constructor is available

2023-06-18 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added a comment.

Overall looks ok,
Add some test with records being used via typedef.




Comment at: clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp:117
+  bool IsConstArg = ArgType.isConstQualified();
+  bool IsTriviallyCopyable = ArgType.isTriviallyCopyableType(*Result.Context);
 

make sure you use here canonical type, or it may not work correctly with 
typedefs, like typedefs to records.
same in line 120, in fact only on line 154 would be good to use original type.



Comment at: clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp:209
+!RecordDecl->hasMoveConstructor() || !RecordDecl->hasMoveAssignment())
+  diag(RecordDecl->getSourceRange().getBegin(),
+   "'%0' is not move constructible", DiagnosticIDs::Note)

`getLocation ()`



Comment at: clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp:211
+   "'%0' is not move constructible", DiagnosticIDs::Note)
+  << RecordDecl->getName();
   }

`<< RecordDecl`
should work, do not use getName, it could cause crash for unnamed records.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:378
+- Improved :doc:`performance-move-const-arg
+  `: warning when no move
+  constructor is available.

"check to warn when ..."



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp:345
+namespace issue_62550 {
+
+struct NonMoveConstructable {

AMS21 wrote:
> I've tried to add
> 
> ```
> // CHECK-MESSAGES: [[@LINE+1]]:1: note: 'NonMoveConstructable' is not move 
> constructible
> ```
> 
> here. But doing so actually fails the tests and I'm not quite sure why.
There are 2 ways to deal with this.
If you use CHECK-MESSAGES, then order of issues is checked, and that why for 
current notes you may see thing like `@LINE-27`, so you would need to put it 
into places when its emited.
Other way is to use CHECK-NOTES, then all warnings are checked out of order.
So simply I would put those CHECK-MESSAGES, after a warning in lines 256, 372, 
384, 387


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153220

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


[PATCH] D153218: [clang-tidy] Fix `llvmlibc-inline-function-decl` false positives for templated function definitions

2023-06-18 Thread André Schackier via Phabricator via cfe-commits
AMS21 updated this revision to Diff 532455.
AMS21 added a comment.

Implemented suggested fix and added a test case
Added entry to ReleaseNotes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153218

Files:
  clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp

Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
===
--- clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
@@ -68,6 +68,197 @@
   [](){};
 }
 
+namespace issue_62746 {
+
+void goodSimpleFunction();
+void badSimpleFunction();
+void badSimpleFunctionWrongLocation();
+
+LIBC_INLINE void goodSimpleFunction() {}
+
+inline void badSimpleFunction() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: 'badSimpleFunction' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
+
+void LIBC_INLINE badSimpleFunctionWrongLocation() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: 'badSimpleFunctionWrongLocation' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
+
+template 
+void goodTemplateFunction();
+template 
+void badTemplateFunction();
+template 
+void badTemplateFunctionWrongLocation();
+
+template  LIBC_INLINE void goodTemplateFunction() {}
+
+template  inline void badTemplateFunction() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: 'badTemplateFunction' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
+
+template  void LIBC_INLINE badTemplateFunctionWrongLocation() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: 'badTemplateFunctionWrongLocation' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
+
+template 
+void goodVariadicFunction();
+template 
+void badVariadicFunction();
+template 
+void badVariadicFunctionWrongLocation();
+
+template  LIBC_INLINE void goodVariadicFunction() {}
+
+template  inline void badVariadicFunction() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: 'badVariadicFunction' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
+
+template  void LIBC_INLINE badVariadicFunctionWrongLocation() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: 'badVariadicFunctionWrongLocation' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
+
+struct NoTemplate {
+  void goodNoTemplate();
+  void badNoTemplate();
+  void badNoTemplateWrongLocation();
+
+  template 
+  void goodNestedTemplate();
+  template 
+  void badNestedTemplate();
+  template 
+  void badNestedTemplateWrongLocation();
+
+  template 
+  void goodVariadicTemplate();
+  template 
+  void badVariadicTemplate();
+  template 
+  void badVariadicTemplateWrongLocation();
+
+};
+
+LIBC_INLINE void NoTemplate::goodNoTemplate() {}
+
+inline void NoTemplate::badNoTemplate() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: 'badNoTemplate' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
+
+void LIBC_INLINE NoTemplate::badNoTemplateWrongLocation() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: 'badNoTemplateWrongLocation' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
+
+template  LIBC_INLINE void NoTemplate::goodNestedTemplate() {}
+
+template  inline void NoTemplate::badNestedTemplate() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: 'badNestedTemplate' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
+
+template  void LIBC_INLINE NoTemplate::badNestedTemplateWrongLocation() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: 'badNestedTemplateWrongLocation' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
+
+template  LIBC_INLINE void NoTemplate::goodVariadicTemplate() {}
+
+template  void inline NoTemplate::badVariadicTemplate() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: 'badVariadicTemplate' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
+
+template  void LIBC_INLINE NoTemplate::badVariadicTemplateWrongLocation(

[PATCH] D153218: [clang-tidy] Fix `llvmlibc-inline-function-decl` false positives for templated function definitions

2023-06-18 Thread André Schackier via Phabricator via cfe-commits
AMS21 added a comment.

Regarding the problems with attributes like nodiscard. I'm honestly not quite 
sure, but from the way the check is implemented and the warning is worded, it 
sounds to me like the attributes should come after LIBC_INLINE. Although 
looking at the Styleguide for libc, I didn't find anything the placement of the 
macro there.

I thinks its best for now to leave the behavior as it was.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153218

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


[PATCH] D153220: [clang-tidy] Improve `performance-move-const-arg` message when no move constructor is available

2023-06-18 Thread André Schackier via Phabricator via cfe-commits
AMS21 updated this revision to Diff 532458.
AMS21 marked 5 inline comments as done.
AMS21 added a comment.

Implement suggested changes
Add tests with typedefs


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153220

Files:
  clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp
@@ -39,10 +39,14 @@
   A(A &&rhs) {}
 };
 
+using AlsoA = A;
+
 struct TriviallyCopyable {
   int i;
 };
 
+using TrivialAlias = TriviallyCopyable;
+
 void f(TriviallyCopyable) {}
 
 void g() {
@@ -50,6 +54,11 @@
   f(std::move(obj));
   // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: std::move of the variable 'obj' of the trivially-copyable type 'TriviallyCopyable' has no effect; remove std::move() [performance-move-const-arg]
   // CHECK-FIXES: f(obj);
+
+  TrivialAlias obj2;
+  f(std::move(obj2));
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: std::move of the variable 'obj2' of the trivially-copyable type 'TrivialAlias' (aka 'TriviallyCopyable') has no effect; remove std::move() [performance-move-const-arg]
+  // CHECK-FIXES: f(obj2);
 }
 
 int f1() {
@@ -72,12 +81,20 @@
 
 A f4(A x4) { return std::move(x4); }
 
+AlsoA f4_a(AlsoA x4) { return std::move(x4); }
+
 A f5(const A x5) {
   return std::move(x5);
   // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the const variable 'x5' has no effect; remove std::move() or make the variable non-const [performance-move-const-arg]
   // CHECK-FIXES: return x5;
 }
 
+AlsoA f5_a(const AlsoA x5) {
+  return std::move(x5);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the const variable 'x5' has no effect; remove std::move() or make the variable non-const [performance-move-const-arg]
+  // CHECK-FIXES: return x5;
+}
+
 template 
 T f6(const T x6) {
   return std::move(x6);
@@ -115,6 +132,8 @@
   NoMoveSemantics &operator=(const NoMoveSemantics &);
 };
 
+using NoMoveSemanticsAlias = NoMoveSemantics;
+
 void callByConstRef(const NoMoveSemantics &);
 void callByConstRef(int i, const NoMoveSemantics &);
 
@@ -147,6 +166,35 @@
   // CHECK-FIXES: other = obj;
 }
 
+void moveToConstReferencePositivesAlias() {
+  NoMoveSemanticsAlias obj;
+
+  // Basic case.
+  callByConstRef(std::move(obj));
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg]
+  // CHECK-FIXES: callByConstRef(obj);
+
+  // Also works for second argument.
+  callByConstRef(1, std::move(obj));
+  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg]
+  // CHECK-FIXES: callByConstRef(1, obj);
+
+  // Works if std::move() applied to a temporary.
+  callByConstRef(std::move(NoMoveSemanticsAlias()));
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg]
+  // CHECK-FIXES: callByConstRef(NoMoveSemanticsAlias());
+
+  // Works if calling a copy constructor.
+  NoMoveSemanticsAlias other(std::move(obj));
+  // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg]
+  // CHECK-FIXES: NoMoveSemanticsAlias other(obj);
+
+  // Works if calling assignment operator.
+  other = std::move(obj);
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg]
+  // CHECK-FIXES: other = obj;
+}
+
 class MoveSemantics {
 public:
   MoveSemantics();
@@ -155,6 +203,8 @@
   MoveSemantics &operator=(MoveSemantics &&);
 };
 
+using MoveSemanticsAlias = MoveSemantics;
+
 void callByValue(MoveSemantics);
 
 void callByRValueRef(MoveSemantics &&);
@@ -197,6 +247,32 @@
   auto lambda2 = std::move(lambda);
 }
 
+void moveToConstReferenceNegativesAlias() {
+  // No warning when actual move takes place.
+  MoveSemanticsAlias move_semantics;
+  callByValue(std::move(move_semantics));
+  callByRValueRef(std::move(move_semantics));
+  MoveSemanticsAlias other(std::move(move_semantics));
+  other = std::move(move_semantics);
+
+  // No warning if std::move() not used.
+  NoMoveSemanticsAlias no_move_semantics;
+  callByConstRef(no_move_semantics);
+
+  // No warning if instantiating a template.
+  templateFunction(no_move_semantics);
+
+  // No warning inside of macro expansions.
+  M3(NoMoveSemanticsA

[PATCH] D153218: [clang-tidy] Fix `llvmlibc-inline-function-decl` false positives for templated function definitions

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

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153218

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


[PATCH] D153220: [clang-tidy] Improve `performance-move-const-arg` message when no move constructor is available

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

+- LGTM




Comment at: clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp:207
+
+if (const CXXRecordDecl *RecordDecl = ArgType->getAsCXXRecordDecl();
+!RecordDecl->hasMoveConstructor() || !RecordDecl->hasMoveAssignment())

You need t check RecordDecl  here also.
like `if (...; RecordDecl  && !(RecordDecl->hasMoveConstructor() && 
RecordDecl->hasMoveAssignment()))`



Comment at: clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp:209
+!RecordDecl->hasMoveConstructor() || !RecordDecl->hasMoveAssignment())
+  diag(RecordDecl->getLocation(), "%0 is not move constructible",
+   DiagnosticIDs::Note)

maybe this should be `constructible/assignable` depend on what we are missing 
(constructor, assign operator)...
Simply this may be strange to get warn about construct when we assign.
Still things like std::optional cold use move constructor instead of assign 
operator on assign.
So this wound need to be checked... It's fine if we won't be very detailed here



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:378
+- Improved :doc:`performance-move-const-arg
+  `: check to warn when no move
+  constructor is available.

remove `:`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153220

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


[PATCH] D153218: [clang-tidy] Fix `llvmlibc-inline-function-decl` false positives for templated function definitions

2023-06-18 Thread André Schackier via Phabricator via cfe-commits
AMS21 added a comment.

If there are no more problems, I would kindly as for someone to push this on my 
behalf :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153218

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


[PATCH] D153220: [clang-tidy] Improve `performance-move-const-arg` message when no move constructor is available

2023-06-18 Thread André Schackier via Phabricator via cfe-commits
AMS21 updated this revision to Diff 532466.
AMS21 marked 2 inline comments as done.
AMS21 added a comment.

Implemented suggested changes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153220

Files:
  clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp
@@ -39,10 +39,14 @@
   A(A &&rhs) {}
 };
 
+using AlsoA = A;
+
 struct TriviallyCopyable {
   int i;
 };
 
+using TrivialAlias = TriviallyCopyable;
+
 void f(TriviallyCopyable) {}
 
 void g() {
@@ -50,6 +54,11 @@
   f(std::move(obj));
   // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: std::move of the variable 'obj' of the trivially-copyable type 'TriviallyCopyable' has no effect; remove std::move() [performance-move-const-arg]
   // CHECK-FIXES: f(obj);
+
+  TrivialAlias obj2;
+  f(std::move(obj2));
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: std::move of the variable 'obj2' of the trivially-copyable type 'TrivialAlias' (aka 'TriviallyCopyable') has no effect; remove std::move() [performance-move-const-arg]
+  // CHECK-FIXES: f(obj2);
 }
 
 int f1() {
@@ -72,12 +81,20 @@
 
 A f4(A x4) { return std::move(x4); }
 
+AlsoA f4_a(AlsoA x4) { return std::move(x4); }
+
 A f5(const A x5) {
   return std::move(x5);
   // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the const variable 'x5' has no effect; remove std::move() or make the variable non-const [performance-move-const-arg]
   // CHECK-FIXES: return x5;
 }
 
+AlsoA f5_a(const AlsoA x5) {
+  return std::move(x5);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the const variable 'x5' has no effect; remove std::move() or make the variable non-const [performance-move-const-arg]
+  // CHECK-FIXES: return x5;
+}
+
 template 
 T f6(const T x6) {
   return std::move(x6);
@@ -115,6 +132,8 @@
   NoMoveSemantics &operator=(const NoMoveSemantics &);
 };
 
+using NoMoveSemanticsAlias = NoMoveSemantics;
+
 void callByConstRef(const NoMoveSemantics &);
 void callByConstRef(int i, const NoMoveSemantics &);
 
@@ -147,6 +166,35 @@
   // CHECK-FIXES: other = obj;
 }
 
+void moveToConstReferencePositivesAlias() {
+  NoMoveSemanticsAlias obj;
+
+  // Basic case.
+  callByConstRef(std::move(obj));
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg]
+  // CHECK-FIXES: callByConstRef(obj);
+
+  // Also works for second argument.
+  callByConstRef(1, std::move(obj));
+  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg]
+  // CHECK-FIXES: callByConstRef(1, obj);
+
+  // Works if std::move() applied to a temporary.
+  callByConstRef(std::move(NoMoveSemanticsAlias()));
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg]
+  // CHECK-FIXES: callByConstRef(NoMoveSemanticsAlias());
+
+  // Works if calling a copy constructor.
+  NoMoveSemanticsAlias other(std::move(obj));
+  // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg]
+  // CHECK-FIXES: NoMoveSemanticsAlias other(obj);
+
+  // Works if calling assignment operator.
+  other = std::move(obj);
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg]
+  // CHECK-FIXES: other = obj;
+}
+
 class MoveSemantics {
 public:
   MoveSemantics();
@@ -155,6 +203,8 @@
   MoveSemantics &operator=(MoveSemantics &&);
 };
 
+using MoveSemanticsAlias = MoveSemantics;
+
 void callByValue(MoveSemantics);
 
 void callByRValueRef(MoveSemantics &&);
@@ -197,6 +247,32 @@
   auto lambda2 = std::move(lambda);
 }
 
+void moveToConstReferenceNegativesAlias() {
+  // No warning when actual move takes place.
+  MoveSemanticsAlias move_semantics;
+  callByValue(std::move(move_semantics));
+  callByRValueRef(std::move(move_semantics));
+  MoveSemanticsAlias other(std::move(move_semantics));
+  other = std::move(move_semantics);
+
+  // No warning if std::move() not used.
+  NoMoveSemanticsAlias no_move_semantics;
+  callByConstRef(no_move_semantics);
+
+  // No warning if instantiating a template.
+  templateFunction(no_move_semantics);
+
+  // No warning inside of macro expansions.
+  M3(NoMoveSemanticsAlias, no_move_semantic

[PATCH] D153220: [clang-tidy] Improve `performance-move-const-arg` message when no move constructor is available

2023-06-18 Thread André Schackier via Phabricator via cfe-commits
AMS21 added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp:345
+namespace issue_62550 {
+
+struct NonMoveConstructable {

PiotrZSL wrote:
> AMS21 wrote:
> > I've tried to add
> > 
> > ```
> > // CHECK-MESSAGES: [[@LINE+1]]:1: note: 'NonMoveConstructable' is not move 
> > constructible
> > ```
> > 
> > here. But doing so actually fails the tests and I'm not quite sure why.
> There are 2 ways to deal with this.
> If you use CHECK-MESSAGES, then order of issues is checked, and that why for 
> current notes you may see thing like `@LINE-27`, so you would need to put it 
> into places when its emited.
> Other way is to use CHECK-NOTES, then all warnings are checked out of order.
> So simply I would put those CHECK-MESSAGES, after a warning in lines 256, 
> 372, 384, 387
Ah yes that makes total sense. Thanks for clarifying that :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153220

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


[PATCH] D153220: [clang-tidy] Improve `performance-move-const-arg` message when no move constructor is available

2023-06-18 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL accepted this revision.
PiotrZSL added a comment.

LGTM




Comment at: clang-tools-extra/docs/ReleaseNotes.rst:378-379
+- Improved :doc:`performance-move-const-arg
+  ` check to warn when no move
+  constructor is available.
+

NOTE: `check to warn when no move  constructor is available.` -> `check to warn 
when move special member functions are not available.`  or something similar, 
to not limit this only to construction


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153220

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


[PATCH] D153197: [AVR] Expand shifts during AVRISelLowering

2023-06-18 Thread Patryk Wychowaniec via Phabricator via cfe-commits
Patryk27 added inline comments.



Comment at: llvm/lib/Target/AVR/AVRISelLowering.cpp:2207
+  MF->push_back(LoopBB);
+  MachineBasicBlock *ExitBB = EntryBB->splitAt(MI, false);
+

Alright, this is wrong, after all - I've just tested it on a more elaborate 
code in rustc and `EntryBB->removeSuccessor(ExitBB);` triggers an LLVM panic 
(presumably because EntryBB == ExitBB).

I kinda don't understand why doing something like this:

```
MachineBasicBlock *ExitBB = EntryBB->splitAt(MI, false);

if (EntryBB == ExitBB) {
  assert(EntryBB->canFallThrough() && "Expected a fallthrough block!");
  ExitBB = EntryBB->getFallThrough();
}
```

... is not sufficient, though 👀


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153197

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


[PATCH] D153220: [clang-tidy] Improve `performance-move-const-arg` message when no move constructor is available

2023-06-18 Thread André Schackier via Phabricator via cfe-commits
AMS21 updated this revision to Diff 532467.
AMS21 added a comment.

Improve doc


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153220

Files:
  clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp
@@ -39,10 +39,14 @@
   A(A &&rhs) {}
 };
 
+using AlsoA = A;
+
 struct TriviallyCopyable {
   int i;
 };
 
+using TrivialAlias = TriviallyCopyable;
+
 void f(TriviallyCopyable) {}
 
 void g() {
@@ -50,6 +54,11 @@
   f(std::move(obj));
   // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: std::move of the variable 'obj' of the trivially-copyable type 'TriviallyCopyable' has no effect; remove std::move() [performance-move-const-arg]
   // CHECK-FIXES: f(obj);
+
+  TrivialAlias obj2;
+  f(std::move(obj2));
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: std::move of the variable 'obj2' of the trivially-copyable type 'TrivialAlias' (aka 'TriviallyCopyable') has no effect; remove std::move() [performance-move-const-arg]
+  // CHECK-FIXES: f(obj2);
 }
 
 int f1() {
@@ -72,12 +81,20 @@
 
 A f4(A x4) { return std::move(x4); }
 
+AlsoA f4_a(AlsoA x4) { return std::move(x4); }
+
 A f5(const A x5) {
   return std::move(x5);
   // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the const variable 'x5' has no effect; remove std::move() or make the variable non-const [performance-move-const-arg]
   // CHECK-FIXES: return x5;
 }
 
+AlsoA f5_a(const AlsoA x5) {
+  return std::move(x5);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the const variable 'x5' has no effect; remove std::move() or make the variable non-const [performance-move-const-arg]
+  // CHECK-FIXES: return x5;
+}
+
 template 
 T f6(const T x6) {
   return std::move(x6);
@@ -115,6 +132,8 @@
   NoMoveSemantics &operator=(const NoMoveSemantics &);
 };
 
+using NoMoveSemanticsAlias = NoMoveSemantics;
+
 void callByConstRef(const NoMoveSemantics &);
 void callByConstRef(int i, const NoMoveSemantics &);
 
@@ -147,6 +166,35 @@
   // CHECK-FIXES: other = obj;
 }
 
+void moveToConstReferencePositivesAlias() {
+  NoMoveSemanticsAlias obj;
+
+  // Basic case.
+  callByConstRef(std::move(obj));
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg]
+  // CHECK-FIXES: callByConstRef(obj);
+
+  // Also works for second argument.
+  callByConstRef(1, std::move(obj));
+  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg]
+  // CHECK-FIXES: callByConstRef(1, obj);
+
+  // Works if std::move() applied to a temporary.
+  callByConstRef(std::move(NoMoveSemanticsAlias()));
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg]
+  // CHECK-FIXES: callByConstRef(NoMoveSemanticsAlias());
+
+  // Works if calling a copy constructor.
+  NoMoveSemanticsAlias other(std::move(obj));
+  // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg]
+  // CHECK-FIXES: NoMoveSemanticsAlias other(obj);
+
+  // Works if calling assignment operator.
+  other = std::move(obj);
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg]
+  // CHECK-FIXES: other = obj;
+}
+
 class MoveSemantics {
 public:
   MoveSemantics();
@@ -155,6 +203,8 @@
   MoveSemantics &operator=(MoveSemantics &&);
 };
 
+using MoveSemanticsAlias = MoveSemantics;
+
 void callByValue(MoveSemantics);
 
 void callByRValueRef(MoveSemantics &&);
@@ -197,6 +247,32 @@
   auto lambda2 = std::move(lambda);
 }
 
+void moveToConstReferenceNegativesAlias() {
+  // No warning when actual move takes place.
+  MoveSemanticsAlias move_semantics;
+  callByValue(std::move(move_semantics));
+  callByRValueRef(std::move(move_semantics));
+  MoveSemanticsAlias other(std::move(move_semantics));
+  other = std::move(move_semantics);
+
+  // No warning if std::move() not used.
+  NoMoveSemanticsAlias no_move_semantics;
+  callByConstRef(no_move_semantics);
+
+  // No warning if instantiating a template.
+  templateFunction(no_move_semantics);
+
+  // No warning inside of macro expansions.
+  M3(NoMoveSemanticsAlias, no_move_semantics);
+
+  // No warning inside of macro expansion, even if 

[PATCH] D153220: [clang-tidy] Improve `performance-move-const-arg` message when no move constructor is available

2023-06-18 Thread André Schackier via Phabricator via cfe-commits
AMS21 added a comment.

As always if there are no more problems, I would kindly ask for someone to push 
this on my behalf :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153220

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


[PATCH] D150997: [llvm] Split out DenseMapInfo specialization

2023-06-18 Thread Elliot Goodrich via Phabricator via cfe-commits
IncludeGuardian added a comment.

This is good to review now.  Phabricator has become a bit confused after 
rebasing on top of https://reviews.llvm.org/D151557, I don't know whether it's 
worth creating a new, cleaner review and close this on?


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

https://reviews.llvm.org/D150997

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


[clang-tools-extra] c96306d - [clang-tidy] Fix `llvmlibc-inline-function-decl` false positives for templated function definitions

2023-06-18 Thread Piotr Zegar via cfe-commits

Author: AMS21
Date: 2023-06-18T11:40:33Z
New Revision: c96306db2cad4cf687cb044c8a0635f982a4db98

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

LOG: [clang-tidy] Fix `llvmlibc-inline-function-decl` false positives for 
templated function definitions

For a declaration the `FunctionDecl` begin location does not include the
template parameter lists, but for some reason if you have a separate
definitions to the declaration the begin location does include them.
With this patch we now correctly handle that case.

This fixes llvm#62746

Reviewed By: PiotrZSL

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp 
b/clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
index fa643a138792a..f901cd115a8ff 100644
--- a/clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
+++ b/clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
@@ -8,6 +8,7 @@
 
 #include "InlineFunctionDeclCheck.h"
 #include "../utils/FileExtensionsUtils.h"
+#include "../utils/LexerUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 
@@ -17,6 +18,27 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy::llvm_libc {
 
+namespace {
+
+const TemplateParameterList *
+getLastTemplateParameterList(const FunctionDecl *FuncDecl) {
+  const TemplateParameterList *ReturnList =
+  FuncDecl->getDescribedTemplateParams();
+
+  if (!ReturnList) {
+const unsigned NumberOfTemplateParameterLists =
+FuncDecl->getNumTemplateParameterLists();
+
+if (NumberOfTemplateParameterLists > 0)
+  ReturnList = FuncDecl->getTemplateParameterList(
+  NumberOfTemplateParameterLists - 1);
+  }
+
+  return ReturnList;
+}
+
+} // namespace
+
 InlineFunctionDeclCheck::InlineFunctionDeclCheck(StringRef Name,
  ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
@@ -34,16 +56,28 @@ void InlineFunctionDeclCheck::check(const 
MatchFinder::MatchResult &Result) {
 return;
 
   SourceLocation SrcBegin = FuncDecl->getBeginLoc();
+
+  // If we have a template parameter list, we need to skip that because the
+  // LIBC_INLINE macro must be placed after that.
+  if (const TemplateParameterList *TemplateParams =
+  getLastTemplateParameterList(FuncDecl)) {
+SrcBegin = TemplateParams->getRAngleLoc();
+std::optional NextToken =
+utils::lexer::findNextTokenSkippingComments(
+SrcBegin, *Result.SourceManager, Result.Context->getLangOpts());
+if (NextToken)
+  SrcBegin = NextToken->getLocation();
+  }
+
   // Consider functions only in header files.
   if (!utils::isSpellingLocInHeaderFile(SrcBegin, *Result.SourceManager,
 HeaderFileExtensions))
 return;
 
   // Ignore lambda functions as they are internal and implicit.
-  if (const auto *MethodDecl = dyn_cast(FuncDecl)) {
+  if (const auto *MethodDecl = dyn_cast(FuncDecl))
 if (MethodDecl->getParent()->isLambda())
   return;
-  }
 
   // Check if decl starts with LIBC_INLINE
   auto Loc = FullSourceLoc(Result.SourceManager->getFileLoc(SrcBegin),

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 32864fc13d834..7fa744d173649 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -325,6 +325,10 @@ Changes in existing checks
   ` check.
   Global options of the same name should be used instead.
 
+- Fix false positive in :doc:`llvmlibc-inline-function-decl
+  ` when using templated
+  function with separate declarations and definitions.
+
 - Improved the performance of the :doc:`misc-confusable-identifiers
   ` check through optimizations.
 

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp 
b/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
index 24d0441742a7f..ab4410ad4fb47 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
@@ -68,6 +68,197 @@ LIBC_INLINE void lambda() {
   [](){};
 }
 
+namespace issue_62746 {
+
+void goodSimpleFunction();
+void badSimpleFunction();
+void badSimpleFunctionWrongLocation();
+
+LIBC_INLINE void goodSimpleFunction() {}
+
+inline void badSimpleFunction() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: 'badSimpleFunction' 

[clang-tools-extra] 82d4dc2 - [clang-tidy] Improve `performance-move-const-arg` message when no move constructor is available

2023-06-18 Thread Piotr Zegar via cfe-commits

Author: AMS21
Date: 2023-06-18T11:40:47Z
New Revision: 82d4dc20efbd72e20b430913e985e38997c7a3e8

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

LOG: [clang-tidy] Improve `performance-move-const-arg` message when no move 
constructor is available

We now display a simple note if the reason is that the used class does not
support move semantics.

This fixes llvm#62550

Reviewed By: PiotrZSL

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp 
b/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
index 8d4c6de8dca72..413a37f4af9fa 100644
--- a/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
@@ -103,6 +103,7 @@ void MoveConstArgCheck::check(const 
MatchFinder::MatchResult &Result) {
 AlreadyCheckedMoves.insert(CallMove);
 
   const Expr *Arg = CallMove->getArg(0);
+  const QualType ArgType = Arg->getType().getCanonicalType();
   SourceManager &SM = Result.Context->getSourceManager();
 
   CharSourceRange MoveRange =
@@ -112,12 +113,11 @@ void MoveConstArgCheck::check(const 
MatchFinder::MatchResult &Result) {
   if (!FileMoveRange.isValid())
 return;
 
-  bool IsConstArg = Arg->getType().isConstQualified();
-  bool IsTriviallyCopyable =
-  Arg->getType().isTriviallyCopyableType(*Result.Context);
+  bool IsConstArg = ArgType.isConstQualified();
+  bool IsTriviallyCopyable = ArgType.isTriviallyCopyableType(*Result.Context);
 
   if (IsConstArg || IsTriviallyCopyable) {
-if (const CXXRecordDecl *R = Arg->getType()->getAsCXXRecordDecl()) {
+if (const CXXRecordDecl *R = ArgType->getAsCXXRecordDecl()) {
   // According to [expr.prim.lambda]p3, "whether the closure type is
   // trivially copyable" property can be changed by the implementation of
   // the language, so we shouldn't rely on it when issuing diagnostics.
@@ -196,11 +196,28 @@ void MoveConstArgCheck::check(const 
MatchFinder::MatchResult &Result) {
 if ((*InvocationParmType)->isRValueReferenceType())
   return;
 
-auto Diag = diag(FileMoveRange.getBegin(),
- "passing result of std::move() as a const reference "
- "argument; no move will actually happen");
+{
+  auto Diag = diag(FileMoveRange.getBegin(),
+   "passing result of std::move() as a const reference "
+   "argument; no move will actually happen");
+
+  replaceCallWithArg(CallMove, Diag, SM, getLangOpts());
+}
 
-replaceCallWithArg(CallMove, Diag, SM, getLangOpts());
+if (const CXXRecordDecl *RecordDecl = ArgType->getAsCXXRecordDecl();
+RecordDecl && !(RecordDecl->hasMoveConstructor() &&
+RecordDecl->hasMoveAssignment())) {
+  const bool MissingMoveAssignment = !RecordDecl->hasMoveAssignment();
+  const bool MissingMoveConstructor = !RecordDecl->hasMoveConstructor();
+  const bool MissingBoth = MissingMoveAssignment && MissingMoveConstructor;
+
+  diag(RecordDecl->getLocation(),
+   "%0 is not move "
+   "%select{|assignable}1%select{|/}2%select{|constructible}3",
+   DiagnosticIDs::Note)
+  << RecordDecl << MissingMoveAssignment << MissingBoth
+  << MissingMoveConstructor;
+}
   }
 }
 

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 7fa744d173649..1ca2db986ef90 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -378,6 +378,10 @@ Changes in existing checks
   `IgnoreTemplateInstantiations` option to optionally ignore virtual function
   overrides that are part of template instantiations.
 
+- Improved :doc:`performance-move-const-arg
+  ` check to warn when move
+  special member functions are not available.
+
 - Improved :doc:`performance-no-automatic-move
   `: warn on ``const &&``
   constructors.

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp
index c1e5761c538e9..4d90c124ad72c 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp
@@ -39,10 +39,14 @@ class A {
   A(A &&rhs) {}
 };
 
+using AlsoA = A;
+
 struct TriviallyCopyable {
   int i;
 };
 
+using TrivialAlias = TriviallyCopyable;
+
 void f(Trivial

[PATCH] D153218: [clang-tidy] Fix `llvmlibc-inline-function-decl` false positives for templated function definitions

2023-06-18 Thread Piotr Zegar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc96306db2cad: [clang-tidy] Fix 
`llvmlibc-inline-function-decl` false positives for templated… (authored by 
AMS21, committed by PiotrZSL).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153218

Files:
  clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp

Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
===
--- clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
@@ -68,6 +68,197 @@
   [](){};
 }
 
+namespace issue_62746 {
+
+void goodSimpleFunction();
+void badSimpleFunction();
+void badSimpleFunctionWrongLocation();
+
+LIBC_INLINE void goodSimpleFunction() {}
+
+inline void badSimpleFunction() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: 'badSimpleFunction' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
+
+void LIBC_INLINE badSimpleFunctionWrongLocation() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: 'badSimpleFunctionWrongLocation' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
+
+template 
+void goodTemplateFunction();
+template 
+void badTemplateFunction();
+template 
+void badTemplateFunctionWrongLocation();
+
+template  LIBC_INLINE void goodTemplateFunction() {}
+
+template  inline void badTemplateFunction() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: 'badTemplateFunction' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
+
+template  void LIBC_INLINE badTemplateFunctionWrongLocation() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: 'badTemplateFunctionWrongLocation' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
+
+template 
+void goodVariadicFunction();
+template 
+void badVariadicFunction();
+template 
+void badVariadicFunctionWrongLocation();
+
+template  LIBC_INLINE void goodVariadicFunction() {}
+
+template  inline void badVariadicFunction() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: 'badVariadicFunction' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
+
+template  void LIBC_INLINE badVariadicFunctionWrongLocation() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: 'badVariadicFunctionWrongLocation' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
+
+struct NoTemplate {
+  void goodNoTemplate();
+  void badNoTemplate();
+  void badNoTemplateWrongLocation();
+
+  template 
+  void goodNestedTemplate();
+  template 
+  void badNestedTemplate();
+  template 
+  void badNestedTemplateWrongLocation();
+
+  template 
+  void goodVariadicTemplate();
+  template 
+  void badVariadicTemplate();
+  template 
+  void badVariadicTemplateWrongLocation();
+
+};
+
+LIBC_INLINE void NoTemplate::goodNoTemplate() {}
+
+inline void NoTemplate::badNoTemplate() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: 'badNoTemplate' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
+
+void LIBC_INLINE NoTemplate::badNoTemplateWrongLocation() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: 'badNoTemplateWrongLocation' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
+
+template  LIBC_INLINE void NoTemplate::goodNestedTemplate() {}
+
+template  inline void NoTemplate::badNestedTemplate() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: 'badNestedTemplate' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
+
+template  void LIBC_INLINE NoTemplate::badNestedTemplateWrongLocation() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: 'badNestedTemplateWrongLocation' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
+
+template  LIBC_INLINE void NoTemplate::goodVariadicTemplate() {}
+
+template  void inline NoTemplate::badVariadicTemplate() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: 'badVariadicTemplate' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-fu

[PATCH] D153220: [clang-tidy] Improve `performance-move-const-arg` message when no move constructor is available

2023-06-18 Thread Piotr Zegar 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 rG82d4dc20efbd: [clang-tidy] Improve 
`performance-move-const-arg` message when no move… (authored by AMS21, 
committed by PiotrZSL).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153220

Files:
  clang-tools-extra/clang-tidy/performance/MoveConstArgCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance/move-const-arg.cpp
@@ -39,10 +39,14 @@
   A(A &&rhs) {}
 };
 
+using AlsoA = A;
+
 struct TriviallyCopyable {
   int i;
 };
 
+using TrivialAlias = TriviallyCopyable;
+
 void f(TriviallyCopyable) {}
 
 void g() {
@@ -50,6 +54,11 @@
   f(std::move(obj));
   // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: std::move of the variable 'obj' of the trivially-copyable type 'TriviallyCopyable' has no effect; remove std::move() [performance-move-const-arg]
   // CHECK-FIXES: f(obj);
+
+  TrivialAlias obj2;
+  f(std::move(obj2));
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: std::move of the variable 'obj2' of the trivially-copyable type 'TrivialAlias' (aka 'TriviallyCopyable') has no effect; remove std::move() [performance-move-const-arg]
+  // CHECK-FIXES: f(obj2);
 }
 
 int f1() {
@@ -72,12 +81,20 @@
 
 A f4(A x4) { return std::move(x4); }
 
+AlsoA f4_a(AlsoA x4) { return std::move(x4); }
+
 A f5(const A x5) {
   return std::move(x5);
   // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the const variable 'x5' has no effect; remove std::move() or make the variable non-const [performance-move-const-arg]
   // CHECK-FIXES: return x5;
 }
 
+AlsoA f5_a(const AlsoA x5) {
+  return std::move(x5);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: std::move of the const variable 'x5' has no effect; remove std::move() or make the variable non-const [performance-move-const-arg]
+  // CHECK-FIXES: return x5;
+}
+
 template 
 T f6(const T x6) {
   return std::move(x6);
@@ -115,6 +132,8 @@
   NoMoveSemantics &operator=(const NoMoveSemantics &);
 };
 
+using NoMoveSemanticsAlias = NoMoveSemantics;
+
 void callByConstRef(const NoMoveSemantics &);
 void callByConstRef(int i, const NoMoveSemantics &);
 
@@ -147,6 +166,35 @@
   // CHECK-FIXES: other = obj;
 }
 
+void moveToConstReferencePositivesAlias() {
+  NoMoveSemanticsAlias obj;
+
+  // Basic case.
+  callByConstRef(std::move(obj));
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg]
+  // CHECK-FIXES: callByConstRef(obj);
+
+  // Also works for second argument.
+  callByConstRef(1, std::move(obj));
+  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg]
+  // CHECK-FIXES: callByConstRef(1, obj);
+
+  // Works if std::move() applied to a temporary.
+  callByConstRef(std::move(NoMoveSemanticsAlias()));
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg]
+  // CHECK-FIXES: callByConstRef(NoMoveSemanticsAlias());
+
+  // Works if calling a copy constructor.
+  NoMoveSemanticsAlias other(std::move(obj));
+  // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg]
+  // CHECK-FIXES: NoMoveSemanticsAlias other(obj);
+
+  // Works if calling assignment operator.
+  other = std::move(obj);
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg]
+  // CHECK-FIXES: other = obj;
+}
+
 class MoveSemantics {
 public:
   MoveSemantics();
@@ -155,6 +203,8 @@
   MoveSemantics &operator=(MoveSemantics &&);
 };
 
+using MoveSemanticsAlias = MoveSemantics;
+
 void callByValue(MoveSemantics);
 
 void callByRValueRef(MoveSemantics &&);
@@ -197,6 +247,32 @@
   auto lambda2 = std::move(lambda);
 }
 
+void moveToConstReferenceNegativesAlias() {
+  // No warning when actual move takes place.
+  MoveSemanticsAlias move_semantics;
+  callByValue(std::move(move_semantics));
+  callByRValueRef(std::move(move_semantics));
+  MoveSemanticsAlias other(std::move(move_semantics));
+  other = std::move(move_semantics);
+
+  // No warning if std::move() not used.
+  NoMoveSemanticsAlias no_move_semantics;
+  callByConstRef(no_move_semantics);
+
+  // No warning if instantiating a

[PATCH] D153114: [clangd] [C++20] [Modules] Support C++20 modules for clangd

2023-06-18 Thread Pol M via Phabricator via cfe-commits
Destroyerrrocket requested changes to this revision.
Destroyerrrocket added inline comments.
This revision now requires changes to proceed.



Comment at: clang-tools-extra/clangd/ModulesManager.cpp:413-414
+  else
+WaitingCallables[Filename.str()].push_back(
+{std::move(ReadyCallback), std::move(ReadyCallback)});
+}

This is a bug; The second move is invalid. You could make a copy


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

https://reviews.llvm.org/D153114

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


[PATCH] D153092: [Clang][CodeGen]`vtable`, `typeinfo` et al. are globals

2023-06-18 Thread Alex Voicu via Phabricator via cfe-commits
AlexVlx updated this revision to Diff 532470.
AlexVlx added a comment.

`clang-format`


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

https://reviews.llvm.org/D153092

Files:
  clang/lib/CodeGen/CGVTT.cpp
  clang/lib/CodeGen/CGVTables.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGenCXX/vtable-align-address-space.cpp
  clang/test/CodeGenCXX/vtable-assume-load-address-space.cpp
  clang/test/CodeGenCXX/vtable-consteval-address-space.cpp
  clang/test/CodeGenCXX/vtable-constexpr-address-space.cpp
  clang/test/CodeGenCXX/vtable-key-function-address-space.cpp
  clang/test/CodeGenCXX/vtable-layout-extreme-address-space.cpp
  clang/test/CodeGenCXX/vtable-linkage-address-space.cpp
  clang/test/CodeGenCXX/vtable-pointer-initialization-address-space.cpp
  clang/test/CodeGenCXX/vtt-address-space.cpp
  clang/test/CodeGenCXX/vtt-layout-address-space.cpp
  clang/test/Headers/hip-header.hip

Index: clang/test/Headers/hip-header.hip
===
--- clang/test/Headers/hip-header.hip
+++ clang/test/Headers/hip-header.hip
@@ -60,9 +60,8 @@
 __device__ void test_vf() {
 derived d;
 }
-// CHECK: @_ZTV7derived = linkonce_odr unnamed_addr addrspace(1) constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr null, ptr @_ZN7derived2pvEv, ptr @__cxa_deleted_virtual] }, comdat, align 8
-// CHECK: @_ZTV4base = linkonce_odr unnamed_addr addrspace(1) constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr null, ptr @__cxa_pure_virtual, ptr @__cxa_deleted_virtual] }, comdat, align 8
-
+// CHECK: @_ZTV7derived = linkonce_odr unnamed_addr addrspace(1) constant { [4 x ptr addrspace(1)] } { [4 x ptr addrspace(1)] [ptr addrspace(1) null, ptr addrspace(1) null, ptr addrspace(1) addrspacecast (ptr @_ZN7derived2pvEv to ptr addrspace(1)), ptr addrspace(1) addrspacecast (ptr @__cxa_deleted_virtual to ptr addrspace(1))] }, comdat, align 8
+// CHECK: @_ZTV4base = linkonce_odr unnamed_addr addrspace(1) constant { [4 x ptr addrspace(1)] } { [4 x ptr addrspace(1)] [ptr addrspace(1) null, ptr addrspace(1) null, ptr addrspace(1) addrspacecast (ptr @__cxa_pure_virtual to ptr addrspace(1)), ptr addrspace(1) addrspacecast (ptr @__cxa_deleted_virtual to ptr addrspace(1))] }, comdat, align 8
 // CHECK: define{{.*}}void @__cxa_pure_virtual()
 // CHECK: define{{.*}}void @__cxa_deleted_virtual()
 
Index: clang/test/CodeGenCXX/vtt-layout-address-space.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/vtt-layout-address-space.cpp
@@ -0,0 +1,89 @@
+// RUN: %clang_cc1 %s -triple=amdgcn-amd-amdhsa -std=c++11 -emit-llvm -o - | FileCheck %s
+
+// Test1::B should just have a single entry in its VTT, which points to the vtable.
+namespace Test1 {
+struct A { };
+
+struct B : virtual A {
+  virtual void f();
+};
+
+void B::f() { }
+}
+
+// Check that we don't add a secondary virtual pointer for Test2::A, since Test2::A doesn't have any virtual member functions or bases.
+namespace Test2 {
+  struct A { };
+
+  struct B : A { virtual void f(); };
+  struct C : virtual B { };
+
+  C c;
+}
+
+// This is the sample from the C++ Itanium ABI, p2.6.2.
+namespace Test3 {
+  class A1 { int i; };
+  class A2 { int i; virtual void f(); };
+  class V1 : public A1, public A2 { int i; };
+  class B1 { int i; };
+  class B2 { int i; };
+  class V2 : public B1, public B2, public virtual V1 { int i; };
+  class V3 {virtual void g(); };
+  class C1 : public virtual V1 { int i; };
+  class C2 : public virtual V3, virtual V2 { int i; };
+  class X1 { int i; };
+  class C3 : public X1 { int i; };
+  class D : public C1, public C2, public C3 { int i;  };
+
+  D d;
+}
+
+// This is the sample from the C++ Itanium ABI, p2.6.2, with the change suggested
+// (making A2 a virtual base of V1)
+namespace Test4 {
+  class A1 { int i; };
+  class A2 { int i; virtual void f(); };
+  class V1 : public A1, public virtual A2 { int i; };
+  class B1 { int i; };
+  class B2 { int i; };
+  class V2 : public B1, public B2, public virtual V1 { int i; };
+  class V3 {virtual void g(); };
+  class C1 : public virtual V1 { int i; };
+  class C2 : public virtual V3, virtual V2 { int i; };
+  class X1 { int i; };
+  class C3 : public X1 { int i; };
+  class D : public C1, public C2, public C3 { int i;  };
+
+  D d;
+}
+
+namespace Test5 {
+  struct A {
+virtual void f() = 0;
+virtual void anchor();
+  };
+
+  void A::anchor() {
+  }
+}
+
+namespace Test6 {
+  struct A {
+virtual void f() = delete;
+virtual void anchor();
+  };
+
+  void A::anchor() {
+  }
+}
+
+// CHECK: @_ZTTN5Test11BE ={{.*}} unnamed_addr addrspace(1) constant [1 x ptr addrspace(1)] [ptr addrspace(1) getelementptr inbounds ({ [4 x ptr addrspace(1)] }, ptr addrspace(1) @_ZTVN5Test11BE, i32 0, inrange i32 0, i32 3)]
+// CHECK: @_ZTVN5Test51AE ={{.*}} unnamed_addr addrspace(1) constant { [4 x ptr addrspace(1)] } { [4 x ptr addrspace(1)] [ptr addrspace(1) n

[PATCH] D153226: OpenMP: Don't include stdbool.h in builtin headers

2023-06-18 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm created this revision.
arsenm added reviewers: ronlieb, jdoerfert, doru1004.
Herald added subscribers: sunshaoce, guansong, yaxunl.
Herald added a project: All.
arsenm requested review of this revision.
Herald added subscribers: jplehr, sstefan1, wdng.

Pre-C99 didn't include bool, and C99 allows you to redefine true/false
apparently.


https://reviews.llvm.org/D153226

Files:
  clang/lib/Headers/__clang_hip_libdevice_declares.h
  clang/lib/Headers/openmp_wrappers/__clang_openmp_device_functions.h
  clang/test/Headers/openmp-device-functions-bool.c

Index: clang/test/Headers/openmp-device-functions-bool.c
===
--- /dev/null
+++ clang/test/Headers/openmp-device-functions-bool.c
@@ -0,0 +1,89 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 2
+// RUN: %clang_cc1 -x c -fopenmp -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_device_functions.h -internal-isystem %S/../../lib/Headers/openmp_wrappers -internal-isystem %S/Inputs/include -emit-llvm %s -fopenmp-is-device  -o - | FileCheck %s --check-prefixes=CHECK,CHECK-C
+// RUN: %clang_cc1 -x c++ -fopenmp -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_device_functions.h -internal-isystem %S/../../lib/Headers/openmp_wrappers -internal-isystem %S/Inputs/include -emit-llvm %s -fopenmp-is-device  -o - | FileCheck %s --check-prefixes=CHECK,CHECK-CPP
+
+// Test that we did not include  in C, and OCKL functions using bool
+// produce an i1
+
+#ifdef __cplusplus
+typedef bool ockl_bool;
+#define EXTERN_C extern "C"
+#else
+typedef _Bool ockl_bool;
+#define EXTERN_C
+#endif
+
+#pragma omp begin declare target
+
+// CHECK-LABEL: define hidden float @test_fdot2
+// CHECK-SAME: (<2 x half> noundef [[A:%.*]], <2 x half> noundef [[B:%.*]], float noundef [[C:%.*]], i1 noundef zeroext [[S:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[RETVAL:%.*]] = alloca float, align 4, addrspace(5)
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca <2 x half>, align 4, addrspace(5)
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca <2 x half>, align 4, addrspace(5)
+// CHECK-NEXT:[[C_ADDR:%.*]] = alloca float, align 4, addrspace(5)
+// CHECK-NEXT:[[S_ADDR:%.*]] = alloca i8, align 1, addrspace(5)
+// CHECK-NEXT:[[RETVAL_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[RETVAL]] to ptr
+// CHECK-NEXT:[[A_ADDR_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[A_ADDR]] to ptr
+// CHECK-NEXT:[[B_ADDR_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[B_ADDR]] to ptr
+// CHECK-NEXT:[[C_ADDR_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[C_ADDR]] to ptr
+// CHECK-NEXT:[[S_ADDR_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[S_ADDR]] to ptr
+// CHECK-NEXT:store <2 x half> [[A]], ptr [[A_ADDR_ASCAST]], align 4
+// CHECK-NEXT:store <2 x half> [[B]], ptr [[B_ADDR_ASCAST]], align 4
+// CHECK-NEXT:store float [[C]], ptr [[C_ADDR_ASCAST]], align 4
+// CHECK-NEXT:[[FROMBOOL:%.*]] = zext i1 [[S]] to i8
+// CHECK-NEXT:store i8 [[FROMBOOL]], ptr [[S_ADDR_ASCAST]], align 1
+// CHECK-NEXT:[[TMP0:%.*]] = load <2 x half>, ptr [[A_ADDR_ASCAST]], align 4
+// CHECK-NEXT:[[TMP1:%.*]] = load <2 x half>, ptr [[B_ADDR_ASCAST]], align 4
+// CHECK-NEXT:[[TMP2:%.*]] = load float, ptr [[C_ADDR_ASCAST]], align 4
+// CHECK-NEXT:[[TMP3:%.*]] = load i8, ptr [[S_ADDR_ASCAST]], align 1
+// CHECK-NEXT:[[TOBOOL:%.*]] = trunc i8 [[TMP3]] to i1
+// CHECK-NEXT:[[CALL:%.*]] = call float @__ockl_fdot2(<2 x half> noundef [[TMP0]], <2 x half> noundef [[TMP1]], float noundef [[TMP2]], i1 noundef zeroext [[TOBOOL]]) #[[ATTR2:[0-9]+]]
+// CHECK-NEXT:ret float [[CALL]]
+//
+EXTERN_C float test_fdot2(__2f16 a, __2f16 b, float c, ockl_bool s) {
+  return __ockl_fdot2(a, b, c, s);
+}
+
+
+#ifndef __cplusplus
+
+enum my_bool {
+  false,
+  true
+};
+
+// CHECK-C-LABEL: define hidden i32 @use_my_bool
+// CHECK-C-SAME: (i32 noundef [[B:%.*]]) #[[ATTR0]] {
+// CHECK-C-NEXT:  entry:
+// CHECK-C-NEXT:[[RETVAL:%.*]] = alloca i32, align 4, addrspace(5)
+// CHECK-C-NEXT:[[B_ADDR:%.*]] = alloca i32, align 4, addrspace(5)
+// CHECK-C-NEXT:[[T:%.*]] = alloca i32, align 4, addrspace(5)
+// CHECK-C-NEXT:[[F:%.*]] = alloca i32, align 4, addrspace(5)
+// CHECK-C-NEXT:[[RETVAL_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[RETVAL]] to ptr
+// CHECK-C-NEXT:[[B_ADDR_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[B_ADDR]] to ptr
+// CHECK-C-NEXT:[[T_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[T]] to ptr
+// CHECK-C-NEXT:[[F_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[F]] to ptr
+// CHECK-C-NEXT:store i32 [[B]], ptr [[B_ADDR_ASCAST]], align 4
+// CHECK-C-NEXT:store volat

[PATCH] D153226: OpenMP: Don't include stdbool.h in builtin headers

2023-06-18 Thread Ron Lieberman via Phabricator via cfe-commits
ronlieb added a subscriber: mhalk.
ronlieb added a comment.

@mhalk  to review


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

https://reviews.llvm.org/D153226

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


[PATCH] D153226: OpenMP: Don't include stdbool.h in builtin headers

2023-06-18 Thread Ron Lieberman via Phabricator via cfe-commits
ronlieb accepted this revision.
ronlieb added a comment.
This revision is now accepted and ready to land.

patch applied to local build resolves issues seen


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

https://reviews.llvm.org/D153226

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


[PATCH] D153228: [clang-format] Fixed bad performance with enabled qualifier fixer.

2023-06-18 Thread Sedenion via Phabricator via cfe-commits
Sedeniono created this revision.
Sedeniono added a reviewer: MyDeveloperDay.
Herald added projects: All, clang, clang-format.
Herald added a subscriber: cfe-commits.
Herald added reviewers: rymiel, HazardyKnusperkeks, owenpan.
Sedeniono requested review of this revision.

This fixes github issue #57117: If the "QualifierAlignment"
option of clang-format is set to anything else but "Leave", the
"QualifierAlignmentFixer" pass gets enabled. This pass scales
quadratically with the number of preprocessor branches, i.e.
with the number of elements in TokenAnalyzer::UnwrappedLines.
The reason is that QualifierAlignmentFixer::process() generates
the UnwrappedLines, but then QualifierAlignmentFixer::analyze()
calls LeftRightQualifierAlignmentFixer::process() several times
(once for each qualifier) which again each time generates the
UnwrappedLines.

This commit gets rid of this double loop by registering the
individual LeftRightQualifierAlignmentFixer passes directly in
the top most container of passes (local variable "Passes" in
reformat()).
With this change, the original example in the github issue #57117
now takes only around 3s instead of >300s to format.

Since QualifierAlignmentFixer::analyze() got deleted, we also
no longer have the code with the NonNoOpFixes. This causes
replacements that end up not changing anything to appear in the
list of final replacements. There is a unit test to check that
this does not happen: QualifierFixerTest.NoOpQualifierReplacements.
However, it got broken at some point in time. So this commit
fixes the test. To keep the behavior that no no-op replacements
should appear from the qualifier fixer, the corresponding code
from QualifierAlignmentFixer::analyze() was moved to the top
reformat() function. Thus, is now done for **every** replacement
of every formatting pass. If no-op replacements are a problem
for the qualifier fixer, then it seems to be a good idea to
filter them out always.

See
https://github.com/llvm/llvm-project/issues/57117#issuecomment-1546716934
for some more details.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153228

Files:
  clang/lib/Format/Format.cpp
  clang/lib/Format/QualifierAlignmentFixer.cpp
  clang/lib/Format/QualifierAlignmentFixer.h
  clang/unittests/Format/QualifierFixerTest.cpp

Index: clang/unittests/Format/QualifierFixerTest.cpp
===
--- clang/unittests/Format/QualifierFixerTest.cpp
+++ clang/unittests/Format/QualifierFixerTest.cpp
@@ -1016,8 +1016,8 @@
   std::vector Left;
   std::vector Right;
   std::vector ConfiguredTokens;
-  QualifierAlignmentFixer::PrepareLeftRightOrdering(Style.QualifierOrder, Left,
-Right, ConfiguredTokens);
+  prepareLeftRightOrderingForQualifierAlignmentFixer(Style.QualifierOrder, Left,
+ Right, ConfiguredTokens);
 
   EXPECT_EQ(Left.size(), (size_t)2);
   EXPECT_EQ(Right.size(), (size_t)2);
@@ -1181,10 +1181,12 @@
   Style.QualifierAlignment = FormatStyle::QAS_Custom;
   Style.QualifierOrder = {"static", "const", "type"};
 
-  ReplacementCount = 0;
-  EXPECT_EQ(ReplacementCount, 0);
   verifyFormat("static const uint32 foo[] = {0, 31};", Style);
+  EXPECT_EQ(ReplacementCount, 0);
+
   verifyFormat("#define MACRO static const", Style);
+  EXPECT_EQ(ReplacementCount, 0);
+
   verifyFormat("using sc = static const", Style);
   EXPECT_EQ(ReplacementCount, 0);
 }
Index: clang/lib/Format/QualifierAlignmentFixer.h
===
--- clang/lib/Format/QualifierAlignmentFixer.h
+++ clang/lib/Format/QualifierAlignmentFixer.h
@@ -25,32 +25,13 @@
 const Environment &)>
 AnalyzerPass;
 
-class QualifierAlignmentFixer : public TokenAnalyzer {
-  // Left to Right ordering requires multiple passes
-  SmallVector Passes;
-  StringRef &Code;
-  ArrayRef Ranges;
-  unsigned FirstStartColumn;
-  unsigned NextStartColumn;
-  unsigned LastStartColumn;
-  StringRef FileName;
+void addQualifierAlignmentFixerPasses(const FormatStyle &Style,
+  SmallVector &Passes);
 
-public:
-  QualifierAlignmentFixer(const Environment &Env, const FormatStyle &Style,
-  StringRef &Code, ArrayRef Ranges,
-  unsigned FirstStartColumn, unsigned NextStartColumn,
-  unsigned LastStartColumn, StringRef FileName);
-
-  std::pair
-  analyze(TokenAnnotator &Annotator,
-  SmallVectorImpl &AnnotatedLines,
-  FormatTokenLexer &Tokens) override;
-
-  static void PrepareLeftRightOrdering(const std::vector &Order,
-   std::vector &LeftOrder,
-   std::vector &RightOrder,
-   std::vector &Qualifiers);
-};
+void prepareLeftRightOrderingForQualifierAlignmentFixer(
+const std::vector &Order, std::vec

[PATCH] D152351: [clang] Add __builtin_isfpclass

2023-06-18 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added a comment.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152351

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


[clang] 7dd387d - [clang] Add __builtin_isfpclass

2023-06-18 Thread Serge Pavlov via cfe-commits

Author: Serge Pavlov
Date: 2023-06-18T22:53:32+07:00
New Revision: 7dd387d2971d7759cadfffeb2082439f6c7ddd49

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

LOG: [clang] Add __builtin_isfpclass

A new builtin function __builtin_isfpclass is added. It is called as:

__builtin_isfpclass(, )

and returns an integer value, which is non-zero if the floating point
argument falls into one of the classes specified by the second argument,
and zero otherwise. The set of classes is an integer value, where each
value class is represented by a bit. There are ten data classes, as
defined by the IEEE-754 standard, they are represented by bits:

0x0001 (__FPCLASS_SNAN) - Signaling NaN
0x0002 (__FPCLASS_QNAN) - Quiet NaN
0x0004 (__FPCLASS_NEGINF)   - Negative infinity
0x0008 (__FPCLASS_NEGNORMAL)- Negative normal
0x0010 (__FPCLASS_NEGSUBNORMAL) - Negative subnormal
0x0020 (__FPCLASS_NEGZERO)  - Negative zero
0x0040 (__FPCLASS_POSZERO)  - Positive zero
0x0080 (__FPCLASS_POSSUBNORMAL) - Positive subnormal
0x0100 (__FPCLASS_POSNORMAL)- Positive normal
0x0200 (__FPCLASS_POSINF)   - Positive infinity

They have corresponding builtin macros to facilitate using the builtin
function:

if (__builtin_isfpclass(x, __FPCLASS_NEGZERO | __FPCLASS_POSZERO) {
  // x is any zero.
}

The data class encoding is identical to that used in llvm.is.fpclass
function.

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

Added: 
clang/test/CodeGen/isfpclass.c

Modified: 
clang/docs/LanguageExtensions.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/Builtins.def
clang/lib/AST/ExprConstant.cpp
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Frontend/InitPreprocessor.cpp
clang/lib/Sema/SemaChecking.cpp
clang/test/CodeGen/builtins.c
clang/test/Preprocessor/init-aarch64.c
clang/test/Preprocessor/init.c
clang/test/Sema/builtins.c
clang/test/Sema/constant-builtins-2.c
llvm/include/llvm/IR/IRBuilder.h
llvm/lib/IR/IRBuilder.cpp

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index f37db774a0f7b..4bcb05d202234 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -3489,6 +3489,68 @@ Query for this feature with 
``__has_builtin(__builtin_add_overflow)``, etc.
 Floating point builtins
 ---
 
+``__builtin_isfpclass``
+---
+
+``__builtin_isfpclass`` is used to test if the specified floating-point value
+falls into one of the specified floating-point classes.
+
+**Syntax**:
+
+.. code-block:: c++
+
+int __builtin_isfpclass(fp_type expr, int mask)
+
+``fp_type`` is a floating-point type supported by the target. ``mask`` is an
+integer constant expression, where each bit represents floating-point class to
+test. The function returns boolean value.
+
+**Example of use**:
+
+.. code-block:: c++
+
+  if (__builtin_isfpclass(x, 448)) {
+ // `x` is positive finite value
+...
+  }
+
+**Description**:
+
+The ``__builtin_isfpclass()`` builtin is a generalization of functions 
``isnan``,
+``isinf``, ``isfinite`` and some others defined by the C standard. It tests if
+the floating-point value, specified by the first argument, falls into any of 
data
+classes, specified by the second argument. The later is a bitmask, in which 
each
+data class is represented by a bit using the encoding:
+
+== === ==
+Mask value Data class  Macro
+== === ==
+0x0001 Signaling NaN   __FPCLASS_SNAN
+0x0002 Quiet NaN   __FPCLASS_QNAN
+0x0004 Negative infinity   __FPCLASS_NEGINF
+0x0008 Negative normal __FPCLASS_NEGNORMAL
+0x0010 Negative subnormal  __FPCLASS_NEGSUBNORMAL
+0x0020 Negative zero   __FPCLASS_NEGZERO
+0x0040 Positive zero   __FPCLASS_POSZERO
+0x0080 Positive subnormal  __FPCLASS_POSSUBNORMAL
+0x0100 Positive normal __FPCLASS_POSNORMAL
+0x0200 Positive infinity   __FPCLASS_POSINF
+
+For convenience preprocessor defines macros for these values. The function
+returns 1 if ``expr`` falls into one of the specified data classes, 0 
otherwise.
+
+In the example above the mask value 448 (0x1C0) contains the bits selecting
+positive zero, positive subnormal and positive normal classes.
+``__builtin_isfpclass(x, 448)`` would return true only if ``x`` if of any of
+these data classes. Using suitable mask value, the function can implement any 
of
+the standard classification functions, for example, ``__builtin_isfpclass(x, 
3)``
+is identical to ``isnan``,``__builtin_isfpclass(x, 504)`` - to ``isf

[PATCH] D152351: [clang] Add __builtin_isfpclass

2023-06-18 Thread Serge Pavlov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7dd387d2971d: [clang] Add __builtin_isfpclass (authored by 
sepavloff).

Changed prior to commit:
  https://reviews.llvm.org/D152351?vs=530772&id=532477#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152351

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/Builtins.def
  clang/lib/AST/ExprConstant.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins.c
  clang/test/CodeGen/isfpclass.c
  clang/test/Preprocessor/init-aarch64.c
  clang/test/Preprocessor/init.c
  clang/test/Sema/builtins.c
  clang/test/Sema/constant-builtins-2.c
  llvm/include/llvm/IR/IRBuilder.h
  llvm/lib/IR/IRBuilder.cpp

Index: llvm/lib/IR/IRBuilder.cpp
===
--- llvm/lib/IR/IRBuilder.cpp
+++ llvm/lib/IR/IRBuilder.cpp
@@ -1383,6 +1383,14 @@
   return Fn;
 }
 
+Value *IRBuilderBase::createIsFPClass(Value *FPNum, unsigned Test) {
+  ConstantInt *TestV = getInt32(Test);
+  Module *M = BB->getParent()->getParent();
+  Function *FnIsFPClass =
+  Intrinsic::getDeclaration(M, Intrinsic::is_fpclass, {FPNum->getType()});
+  return CreateCall(FnIsFPClass, {FPNum, TestV});
+}
+
 CallInst *IRBuilderBase::CreateAlignmentAssumptionHelper(const DataLayout &DL,
  Value *PtrValue,
  Value *AlignValue,
Index: llvm/include/llvm/IR/IRBuilder.h
===
--- llvm/include/llvm/IR/IRBuilder.h
+++ llvm/include/llvm/IR/IRBuilder.h
@@ -2528,6 +2528,8 @@
  unsigned Index, unsigned FieldIndex,
  MDNode *DbgInfo);
 
+  Value *createIsFPClass(Value *FPNum, unsigned Test);
+
 private:
   /// Helper function that creates an assume intrinsic call that
   /// represents an alignment assumption on the provided pointer \p PtrValue
Index: clang/test/Sema/constant-builtins-2.c
===
--- clang/test/Sema/constant-builtins-2.c
+++ clang/test/Sema/constant-builtins-2.c
@@ -124,6 +124,47 @@
 char isnormal_nan[!__builtin_isnormal(__builtin_nan("")) ? 1 : -1];
 char isnormal_snan   [!__builtin_isnormal(__builtin_nans("")) ? 1 : -1];
 
+char isfpclass_inf_pos_0[__builtin_isfpclass(__builtin_inf(), 0x0200) ? 1 : -1]; // fcPosInf
+char isfpclass_inf_pos_1[!__builtin_isfpclass(__builtin_inff(), 0x0004) ? 1 : -1]; // fcNegInf
+char isfpclass_inf_pos_2[__builtin_isfpclass(__builtin_infl(), 0x0207) ? 1 : -1]; // fcSNan|fcQNan|fcNegInf|fcPosInf
+char isfpclass_inf_pos_3[!__builtin_isfpclass(__builtin_inf(), 0x01F8) ? 1 : -1]; // fcFinite
+char isfpclass_pos_0[__builtin_isfpclass(1.0, 0x0100) ? 1 : -1]; // fcPosNormal
+char isfpclass_pos_1[!__builtin_isfpclass(1.0f, 0x0008) ? 1 : -1]; // fcNegNormal
+char isfpclass_pos_2[__builtin_isfpclass(1.0L, 0x01F8) ? 1 : -1]; // fcFinite
+char isfpclass_pos_3[!__builtin_isfpclass(1.0, 0x0003) ? 1 : -1]; // fcSNan|fcQNan
+char isfpclass_pdenorm_0[__builtin_isfpclass(1.0e-40f, 0x0080) ? 1 : -1]; // fcPosSubnormal
+char isfpclass_pdenorm_1[__builtin_isfpclass(1.0e-310, 0x01F8) ? 1 : -1]; // fcFinite
+char isfpclass_pdenorm_2[!__builtin_isfpclass(1.0e-40f, 0x003C) ? 1 : -1]; // fcNegative
+char isfpclass_pdenorm_3[!__builtin_isfpclass(1.0e-310, 0x0207) ? 1 : -1]; // ~fcFinite
+char isfpclass_pzero_0  [__builtin_isfpclass(0.0f, 0x0060) ? 1 : -1]; // fcZero
+char isfpclass_pzero_1  [__builtin_isfpclass(0.0, 0x01F8) ? 1 : -1]; // fcFinite
+char isfpclass_pzero_2  [!__builtin_isfpclass(0.0L, 0x0020) ? 1 : -1]; // fcNegZero
+char isfpclass_pzero_3  [!__builtin_isfpclass(0.0, 0x0003) ? 1 : -1]; // fcNan
+char isfpclass_nzero_0  [__builtin_isfpclass(-0.0f, 0x0060) ? 1 : -1]; // fcZero
+char isfpclass_nzero_1  [__builtin_isfpclass(-0.0, 0x01F8) ? 1 : -1]; // fcFinite
+char isfpclass_nzero_2  [!__builtin_isfpclass(-0.0L, 0x0040) ? 1 : -1]; // fcPosZero
+char isfpclass_nzero_3  [!__builtin_isfpclass(-0.0, 0x0003) ? 1 : -1]; // fcNan
+char isfpclass_ndenorm_0[__builtin_isfpclass(-1.0e-40f, 0x0010) ? 1 : -1]; // fcNegSubnormal
+char isfpclass_ndenorm_1[__builtin_isfpclass(-1.0e-310, 0x01F8) ? 1 : -1]; // fcFinite
+char isfpclass_ndenorm_2[!__builtin_isfpclass(-1.0e-40f, 0x03C0) ? 1 : -1]; // fcPositive
+char isfpclass_ndenorm_3[!__builtin_isfpclass(-1.0e-310, 0x0207) ? 1 : -1]; // ~fcFinite
+char isfpclass_neg_0[__builtin_isfpclass(-1.0, 0x0008) ? 1 : -1]; // fcNegNormal
+char isfpclass_neg_1[!__builtin_isfpclass(-1.0f, 0x00100) ? 1 : -1]; // fcPosNormal
+char isfpclass_neg_2[__builtin_isfpclass(-1.0L, 0x01F8) ? 1 : -1]; // fcFinite
+char isfpclass

[clang] 112fa9a - [Doc] Fix table layout

2023-06-18 Thread Serge Pavlov via cfe-commits

Author: Serge Pavlov
Date: 2023-06-18T23:46:08+07:00
New Revision: 112fa9aa7042861ba101828d87e8d6b629121eae

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

LOG: [Doc] Fix table layout

Added: 


Modified: 
clang/docs/LanguageExtensions.rst

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 4bcb05d202234..9944cb28f0487 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -3535,6 +3535,7 @@ Mask value Data class  Macro
 0x0080 Positive subnormal  __FPCLASS_POSSUBNORMAL
 0x0100 Positive normal __FPCLASS_POSNORMAL
 0x0200 Positive infinity   __FPCLASS_POSINF
+== === ==
 
 For convenience preprocessor defines macros for these values. The function
 returns 1 if ``expr`` falls into one of the specified data classes, 0 
otherwise.



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


[PATCH] D149280: [clang-tidy] Add modernize-printf-to-std-print check

2023-06-18 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe marked 6 inline comments as done.
mikecrowe added a comment.

Thanks for the comprehensive review.




Comment at: clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp:43-44
+
+  if (!MaybeHeaderToInclude && (ReplacementPrintFunction == "std::print" ||
+ReplacementPrintlnFunction == "std::println"))
+MaybeHeaderToInclude = "";

PiotrZSL wrote:
> this code is already duplicated, move it to some separate private function, 
> like isCpp23PrintConfigured or something...
You're correct that `ReplacementPrintFunction == "std::print" || 
ReplacementPrintlnFunction == "std::println"` is duplicated in 
`isLanguageVersionSupported`, but in that code we're considering which C++ 
version the functions require and in this code we're considering which header 
the functions require. These are not the same question. It just so happens that 
these checks are against the same function names now, but they need not be. If 
another function is added to `` in C++26 and this code ends up being 
able to convert to it then the checks would need to diverge.

Nevertheless, I will do as you request if you still think it's worthwhile.




Comment at: clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp:56
+  Finder->addMatcher(
+  traverse(TK_IgnoreUnlessSpelledInSource,
+   callExpr(callee(functionDecl(matchers::matchesAnyListedName(

PiotrZSL wrote:
> Those TK_IgnoreUnlessSpelledInSource should be moved into 
> getCheckTraversalKind()
Ah, that was added since I wrote the original version of this check. I'll 
address this.



Comment at: clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.h:40
+  StringRef ReplacementPrintlnFunction;
+  utils::IncludeInserter IncludeInserter;
+  std::optional MaybeHeaderToInclude;

PiotrZSL wrote:
> I heard that using clang::tooling::HeaderIncludes is more recommended.
> And this is just some house-made stuff
I'm afraid that I don't really understand this comment. The use of 
`IncludeInserter` is far more common in the existing checks than 
`HeaderIncludes` and from looking at `IncludeCleaner.cpp` the use of the latter 
is rather more complex. New features were being added to `IncludeInserter` 
within the last six months. I'm unsure what "house-made" means in the context 
of the `IncludeInserter` code that I didn't write.

Do you have anything more concrete than hearsay? If there is a plan to 
deprecate `IncludeInserter` then it feels like something closer to its 
convenient interface would need to be implemented in terms of `HeaderIncludes` 
for checks to use rather than them duplicating the code in `IncludeCleaner.cpp`.

If you can explain what you'd like me to do, and ideally provide pointers to 
similar things being done elsewhere then perhaps I can address this comment.



Comment at: clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp:185
+  assert(FormatExpr);
+  PrintfFormatString = FormatExpr->getString();
+

PiotrZSL wrote:
> This may crash for wchar, maybe better limit StringLiteral to Ordinary and 
> UTF8 or only Ordinary 
It doesn't look like there's any support for u8 literals in `printf` or 
`std::print` (yet), so I think just Ordinary is sufficient.



Comment at: clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp:202
+/// Called for each format specifier by ParsePrintfString.
+bool FormatStringConverter::HandlePrintfSpecifier(
+const analyze_printf::PrintfSpecifier &FS, const char *StartSpecifier,

PiotrZSL wrote:
> this function should be split into smaller one.
I agree. I'm surprised it hasn't come up in review earlier. I tried to do so 
prior to pushing the very first version of this for review and gave up since 
the parts ended up referring to so many local variables making the code even 
harder to understand than it is now. I will have another attempt.



Comment at: clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp:230
+return conversionNotPossible("'%m' is not supported in format string");
+  } else {
+StandardFormatString.push_back('{');

PiotrZSL wrote:
> general: no need for else after return
In general, you're correct that I've used else after return in other places and 
I will fix them. However, in this case the else is required since the very 
first `if` block above doesn't have a return. (Hopefully this complexity will 
go away if I succeed in splitting this function up.)



Comment at: clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp:384-397
+const auto StringDecl = type(hasUnqualifiedDesugaredType(recordType(
+hasDeclaration(cxxRecordDecl(hasName("::std::basic_string"));
+const auto StringExpr = expr(anyOf(
+hasType(StringDecl), hasType(qualType(pointsTo(StringDecl);
+
+const a

[clang] b57e049 - clang/HIP: Use __builtin_fmaf16

2023-06-18 Thread Matt Arsenault via cfe-commits

Author: Matt Arsenault
Date: 2023-06-18T13:13:49-04:00
New Revision: b57e049fe5ccf48bb105b96020901d2912de9588

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

LOG: clang/HIP: Use __builtin_fmaf16

Missed these in 43fd46fda3c90b014e8a73c62f67af9543ea4d59

Added: 


Modified: 
clang/lib/Headers/__clang_hip_cmath.h
clang/test/Headers/__clang_hip_cmath.hip
clang/test/Headers/__clang_hip_math.hip
clang/test/Headers/hip-header.hip

Removed: 




diff  --git a/clang/lib/Headers/__clang_hip_cmath.h 
b/clang/lib/Headers/__clang_hip_cmath.h
index d488db0a94d9d..b52d6b7816611 100644
--- a/clang/lib/Headers/__clang_hip_cmath.h
+++ b/clang/lib/Headers/__clang_hip_cmath.h
@@ -171,7 +171,7 @@ __DEVICE__ __CONSTEXPR__ bool signbit(double __x) { return 
::__signbit(__x); }
 // Other functions.
 __DEVICE__ __CONSTEXPR__ _Float16 fma(_Float16 __x, _Float16 __y,
   _Float16 __z) {
-  return __ocml_fma_f16(__x, __y, __z);
+  return __builtin_fmaf16(__x, __y, __z);
 }
 __DEVICE__ __CONSTEXPR__ _Float16 pow(_Float16 __base, int __iexp) {
   return __ocml_pown_f16(__base, __iexp);

diff  --git a/clang/test/Headers/__clang_hip_cmath.hip 
b/clang/test/Headers/__clang_hip_cmath.hip
index 9ef6f149bcd88..f66f5f3c3ee44 100644
--- a/clang/test/Headers/__clang_hip_cmath.hip
+++ b/clang/test/Headers/__clang_hip_cmath.hip
@@ -18,13 +18,13 @@
 
 // DEFAULT-LABEL: @test_fma_f16(
 // DEFAULT-NEXT:  entry:
-// DEFAULT-NEXT:[[CALL_I:%.*]] = tail call contract half 
@__ocml_fma_f16(half noundef [[X:%.*]], half noundef [[Y:%.*]], half noundef 
[[Z:%.*]]) #[[ATTR8:[0-9]+]]
-// DEFAULT-NEXT:ret half [[CALL_I]]
+// DEFAULT-NEXT:[[TMP0:%.*]] = tail call contract half @llvm.fma.f16(half 
[[X:%.*]], half [[Y:%.*]], half [[Z:%.*]])
+// DEFAULT-NEXT:ret half [[TMP0]]
 //
 // FINITEONLY-LABEL: @test_fma_f16(
 // FINITEONLY-NEXT:  entry:
-// FINITEONLY-NEXT:[[CALL_I:%.*]] = tail call nnan ninf contract 
nofpclass(nan inf) half @__ocml_fma_f16(half noundef nofpclass(nan inf) 
[[X:%.*]], half noundef nofpclass(nan inf) [[Y:%.*]], half noundef 
nofpclass(nan inf) [[Z:%.*]]) #[[ATTR8:[0-9]+]]
-// FINITEONLY-NEXT:ret half [[CALL_I]]
+// FINITEONLY-NEXT:[[TMP0:%.*]] = tail call nnan ninf contract half 
@llvm.fma.f16(half [[X:%.*]], half [[Y:%.*]], half [[Z:%.*]])
+// FINITEONLY-NEXT:ret half [[TMP0]]
 //
 extern "C" __device__ _Float16 test_fma_f16(_Float16 x, _Float16 y,
 _Float16 z) {
@@ -33,12 +33,12 @@ extern "C" __device__ _Float16 test_fma_f16(_Float16 x, 
_Float16 y,
 
 // DEFAULT-LABEL: @test_pow_f16(
 // DEFAULT-NEXT:  entry:
-// DEFAULT-NEXT:[[CALL_I:%.*]] = tail call contract half 
@__ocml_pown_f16(half noundef [[X:%.*]], i32 noundef [[Y:%.*]]) 
#[[ATTR9:[0-9]+]]
+// DEFAULT-NEXT:[[CALL_I:%.*]] = tail call contract half 
@__ocml_pown_f16(half noundef [[X:%.*]], i32 noundef [[Y:%.*]]) 
#[[ATTR7:[0-9]+]]
 // DEFAULT-NEXT:ret half [[CALL_I]]
 //
 // FINITEONLY-LABEL: @test_pow_f16(
 // FINITEONLY-NEXT:  entry:
-// FINITEONLY-NEXT:[[CALL_I:%.*]] = tail call nnan ninf contract 
nofpclass(nan inf) half @__ocml_pown_f16(half noundef nofpclass(nan inf) 
[[X:%.*]], i32 noundef [[Y:%.*]]) #[[ATTR9:[0-9]+]]
+// FINITEONLY-NEXT:[[CALL_I:%.*]] = tail call nnan ninf contract 
nofpclass(nan inf) half @__ocml_pown_f16(half noundef nofpclass(nan inf) 
[[X:%.*]], i32 noundef [[Y:%.*]]) #[[ATTR7:[0-9]+]]
 // FINITEONLY-NEXT:ret half [[CALL_I]]
 //
 extern "C" __device__ _Float16 test_pow_f16(_Float16 x, int y) {
@@ -61,12 +61,12 @@ extern "C" __device__ float test_fabs_f32(float x) {
 
 // DEFAULT-LABEL: @test_sin_f32(
 // DEFAULT-NEXT:  entry:
-// DEFAULT-NEXT:[[CALL_I_I:%.*]] = tail call contract float 
@__ocml_sin_f32(float noundef [[X:%.*]]) #[[ATTR10:[0-9]+]]
+// DEFAULT-NEXT:[[CALL_I_I:%.*]] = tail call contract float 
@__ocml_sin_f32(float noundef [[X:%.*]]) #[[ATTR8:[0-9]+]]
 // DEFAULT-NEXT:ret float [[CALL_I_I]]
 //
 // FINITEONLY-LABEL: @test_sin_f32(
 // FINITEONLY-NEXT:  entry:
-// FINITEONLY-NEXT:[[CALL_I_I:%.*]] = tail call nnan ninf contract 
nofpclass(nan inf) float @__ocml_sin_f32(float noundef nofpclass(nan inf) 
[[X:%.*]]) #[[ATTR10:[0-9]+]]
+// FINITEONLY-NEXT:[[CALL_I_I:%.*]] = tail call nnan ninf contract 
nofpclass(nan inf) float @__ocml_sin_f32(float noundef nofpclass(nan inf) 
[[X:%.*]]) #[[ATTR8:[0-9]+]]
 // FINITEONLY-NEXT:ret float [[CALL_I_I]]
 //
 extern "C" __device__ float test_sin_f32(float x) {
@@ -75,12 +75,12 @@ extern "C" __device__ float test_sin_f32(float x) {
 
 // DEFAULT-LABEL: @test_cos_f32(
 // DEFAULT-NEXT:  entry:
-// DEFAULT-NEXT:[[CALL_I_I:%.*]] = tail call contract float 
@__ocml_cos_f32(float noundef [[X:%.*]]) #[[ATT

[PATCH] D144802: clang: Add __builtin_elementwise_round

2023-06-18 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm updated this revision to Diff 532481.
arsenm marked 2 inline comments as done.
arsenm added a comment.

Fix description and add release notes


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

https://reviews.llvm.org/D144802

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/Builtins.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-elementwise-math.c
  clang/test/Sema/builtins-elementwise-math.c

Index: clang/test/Sema/builtins-elementwise-math.c
===
--- clang/test/Sema/builtins-elementwise-math.c
+++ clang/test/Sema/builtins-elementwise-math.c
@@ -459,6 +459,32 @@
   // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
 }
 
+void test_builtin_elementwise_round(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
+
+  struct Foo s = __builtin_elementwise_round(f);
+  // expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'float'}}
+
+  i = __builtin_elementwise_round();
+  // expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
+
+  i = __builtin_elementwise_round(i);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'int')}}
+
+  i = __builtin_elementwise_round(f, f);
+  // expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
+
+  u = __builtin_elementwise_round(u);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned int')}}
+
+  uv = __builtin_elementwise_round(uv);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
+
+  // FIXME: Error should not mention integer
+  _Complex float c1, c2;
+  c1 = __builtin_elementwise_round(c1);
+  // expected-error@-1 {{1st argument must be a vector, integer or floating point type (was '_Complex float')}}
+}
+
 void test_builtin_elementwise_sin(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
 
   struct Foo s = __builtin_elementwise_sin(f);
Index: clang/test/CodeGen/builtins-elementwise-math.c
===
--- clang/test/CodeGen/builtins-elementwise-math.c
+++ clang/test/CodeGen/builtins-elementwise-math.c
@@ -468,6 +468,22 @@
   vf2 = __builtin_elementwise_roundeven(vf1);
 }
 
+void test_builtin_elementwise_round(float f1, float f2, double d1, double d2,
+float4 vf1, float4 vf2) {
+  // CHECK-LABEL: define void @test_builtin_elementwise_round(
+  // CHECK:  [[F1:%.+]] = load float, ptr %f1.addr, align 4
+  // CHECK-NEXT:  call float @llvm.round.f32(float [[F1]])
+  f2 = __builtin_elementwise_round(f1);
+
+  // CHECK:  [[D1:%.+]] = load double, ptr %d1.addr, align 8
+  // CHECK-NEXT: call double @llvm.round.f64(double [[D1]])
+  d2 = __builtin_elementwise_round(d1);
+
+  // CHECK:  [[VF1:%.+]] = load <4 x float>, ptr %vf1.addr, align 16
+  // CHECK-NEXT: call <4 x float> @llvm.round.v4f32(<4 x float> [[VF1]])
+  vf2 = __builtin_elementwise_round(vf1);
+}
+
 void test_builtin_elementwise_sin(float f1, float f2, double d1, double d2,
   float4 vf1, float4 vf2) {
   // CHECK-LABEL: define void @test_builtin_elementwise_sin(
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -2636,6 +2636,7 @@
   case Builtin::BI__builtin_elementwise_log2:
   case Builtin::BI__builtin_elementwise_log10:
   case Builtin::BI__builtin_elementwise_roundeven:
+  case Builtin::BI__builtin_elementwise_round:
   case Builtin::BI__builtin_elementwise_sin:
   case Builtin::BI__builtin_elementwise_trunc:
   case Builtin::BI__builtin_elementwise_canonicalize: {
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -3194,6 +3194,9 @@
   case Builtin::BI__builtin_elementwise_roundeven:
 return RValue::get(emitUnaryBuiltin(*this, E, llvm::Intrinsic::roundeven,
 "elt.roundeven"));
+  case Builtin::BI__builtin_elementwise_round:
+return RValue::get(emitUnaryBuiltin(*this, E, llvm::Intrinsic::round,
+"elt.round"));
   case Builtin::BI__builtin_elementwise_sin:
 return RValue::get(
 emitUnaryBuiltin(*this, E, llvm::Intrinsic::sin, "elt.sin"));
Index: clang/include/clang/Basic/Builtins.def
===
--- clang/include/clang/Basic/Builtins.def
+++ clang/include/clang/Basic/Builtins.def
@@ -687,6 +687,7 @@
 BUILTIN(__builtin_elementwise_log2, "v.", "nct")
 

[PATCH] D153229: [llvm] Move StringExtras.h include from Error.h to Error.cpp

2023-06-18 Thread Elliot Goodrich via Phabricator via cfe-commits
IncludeGuardian created this revision.
Herald added subscribers: bviyer, luke, Moerafaat, kmitropoulou, zero9178, 
steakhal, mtrofin, bzcheeseman, mattd, gchakrabarti, pmatos, asb, sdasgup3, 
asavonic, jeroen.dobbelaere, wenzhicui, wrengr, ormris, foad, ChuanqiXu, cota, 
teijeong, frasercrmck, rdzhabarov, tatianashp, okura, jdoerfert, msifontes, 
jurahul, kuter, Kayjukh, grosul1, martong, Joonsoo, kerbowa, liufengdb, 
aartbik, mgester, arpith-jacob, csigg, antiagainst, shauheen, rriddle, 
mehdi_amini, luismarques, apazos, sameer.abuasal, pengfei, s.egerton, Jim, 
asbirlea, thopre, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, 
edward-jones, zzheng, jrtc27, niosHD, sabuasal, simoncook, johnrusso, rbar, 
kbarton, hiraditya, arichardson, sbc100, jvesely, nemanjai, arsenm.
Herald added a reviewer: alexander-shaposhnikov.
Herald added a reviewer: jhenderson.
Herald added a reviewer: NoQ.
Herald added a project: All.
IncludeGuardian requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, wangpc, 
stephenneuendorffer, nicolasvasilache, MaskRay, aheejin, jholewinski.
Herald added a reviewer: jdoerfert.
Herald added a reviewer: sstefan1.
Herald added projects: clang, MLIR, LLVM.

Move the implementation of the `toString` function from `llvm/Support/Error.h` 
to the source file, 
which allows us to move `#include "llvm/ADT/StringExtras.h"` to the source file 
as well.

As `Error.h` is present in a large number of translation units this means we 
are unnecessarily bringing in the 
contents of `StringExtras.h` - itself a large file with lots of includes - and 
slowing down compilation.

Includes have been added to source/header files that are needed but were being 
transitively included. The 
majority needed `StringExtras.h` but a few only required a smaller header: 
`APInt.h`, `APSInt.h`, or 
`SmallString.h`.

This reduces the total number of preprocessing tokens across the LLVM source 
files in lib from (roughly) 
1,920,413,050 to 1,903,629,230 - a reduction of ~0.87%. This should result in a 
small improvement in compilation 
time.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153229

Files:
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/Basic/Sarif.cpp
  clang/lib/Driver/Job.cpp
  clang/lib/Driver/ToolChains/AIX.cpp
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaModule.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaStmtAsm.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/StaticAnalyzer/Core/CheckerContext.cpp
  clang/tools/clang-offload-packager/ClangOffloadPackager.cpp
  clang/tools/driver/cc1as_main.cpp
  llvm/include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h
  llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
  llvm/include/llvm/DebugInfo/GSYM/FunctionInfo.h
  llvm/include/llvm/Debuginfod/HTTPClient.h
  llvm/include/llvm/ProfileData/GCOV.h
  llvm/include/llvm/Support/Error.h
  llvm/lib/Analysis/AliasSetTracker.cpp
  llvm/lib/Analysis/CallGraphSCCPass.cpp
  llvm/lib/Analysis/InlineAdvisor.cpp
  llvm/lib/Analysis/ScalarEvolution.cpp
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
  llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp
  llvm/lib/CodeGen/MachineBasicBlock.cpp
  llvm/lib/CodeGen/MachineCheckDebugify.cpp
  llvm/lib/CodeGen/RegisterBankInfo.cpp
  llvm/lib/DWARFLinker/DWARFLinker.cpp
  llvm/lib/DWARFLinker/DWARFLinkerCompileUnit.cpp
  llvm/lib/DWARFLinkerParallel/DWARFLinkerUnit.h
  llvm/lib/DebugInfo/CodeView/CodeViewRecordIO.cpp
  llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
  llvm/lib/DebugInfo/PDB/Native/InputFile.cpp
  llvm/lib/DebugInfo/PDB/Native/NativeEnumInjectedSources.cpp
  llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp
  llvm/lib/DebugInfo/PDB/Native/NativeSourceFile.cpp
  llvm/lib/DebugInfo/PDB/Native/PDBFileBuilder.cpp
  llvm/lib/ExecutionEngine/JITLink/JITLink.cpp
  llvm/lib/FileCheck/FileCheck.cpp
  llvm/lib/IR/DIBuilder.cpp
  llvm/lib/MC/ELFObjectWriter.cpp
  llvm/lib/MC/MCAsmInfo.cpp
  llvm/lib/MC/MCParser/ELFAsmParser.cpp
  llvm/lib/MC/MCParser/WasmAsmParser.cpp
  llvm/lib/ObjCopy/COFF/COFFObjcopy.cpp
  llvm/lib/Object/Decompressor.cpp
  llvm/lib/Object/ELF.cpp
  llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp
  llvm/lib/Remarks/YAMLRemarkParser.cpp
  llvm/lib/Support/BinaryStreamWriter.cpp
  llvm/lib/Support/DataExtractor.cpp
  llvm/lib/Support/Error.cpp
  llvm/lib/Support/JSON.cpp
  llvm/lib/Support/Path.cpp
  llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
  llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.h
  llvm/lib/Target/Hexagon/HexagonInstrInfo.cpp
  llvm/l

[PATCH] D153229: [llvm] Move StringExtras.h include from Error.h to Error.cpp

2023-06-18 Thread Elliot Goodrich via Phabricator via cfe-commits
IncludeGuardian added a comment.
Herald added a subscriber: jsetoain.

This was found with IncludeGuardian 0.0.8.

The line that suggested this can be found in the output here 
.

The count of preprocessing tokens before and after this change can be found in 
before.yaml 

 and after.yaml 
.
 Note that both these were run on top of https://reviews.llvm.org/D150997, 
which is yet to make it into the main branch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153229

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


[PATCH] D152975: [clang-format] Allow break after return keyword

2023-06-18 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

In D152975#4430504 , @gedare wrote:

> In D152975#4425932 , 
> @HazardyKnusperkeks wrote:
>
>> And please add a remark in the changelog.
>
> Is there a separate changelog file?  I don't understand this request. //Edit: 
> I think this refers to `./clang/docs/ReleaseNotes.rst` //

Yep that's the file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152975

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


[clang] 9932eb0 - [AST] Use DenseMapBase::lookup (NFC)

2023-06-18 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-06-18T11:52:59-07:00
New Revision: 9932eb083a0b735dbbf8b3341ba93dccc00358ae

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

LOG: [AST] Use DenseMapBase::lookup (NFC)

Added: 


Modified: 
clang/lib/AST/DeclCXX.cpp
clang/lib/AST/MicrosoftMangle.cpp

Removed: 




diff  --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index efc933ef5cbcd..56c40e18ca28f 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -1659,10 +1659,7 @@ void CXXRecordDecl::setLambdaNumbering(LambdaNumbering 
Numbering) {
 
 unsigned CXXRecordDecl::getDeviceLambdaManglingNumber() const {
   assert(isLambda() && "Not a lambda closure type!");
-  auto I = getASTContext().DeviceLambdaManglingNumbers.find(this);
-  if (I != getASTContext().DeviceLambdaManglingNumbers.end())
-return I->second;
-  return 0;
+  return getASTContext().DeviceLambdaManglingNumbers.lookup(this);
 }
 
 static CanQualType GetConversionType(ASTContext &Context, NamedDecl *Conv) {

diff  --git a/clang/lib/AST/MicrosoftMangle.cpp 
b/clang/lib/AST/MicrosoftMangle.cpp
index d70f1a19acbbd..1f9687e322c9d 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -290,12 +290,8 @@ class MicrosoftMangleContextImpl : public 
MicrosoftMangleContext {
 assert(!RD->isExternallyVisible() && "RD must not be visible!");
 assert(RD->getLambdaManglingNumber() == 0 &&
"RD must not have a mangling number!");
-llvm::DenseMap::iterator Result =
-LambdaIds.find(RD);
 // The lambda should exist, but return 0 in case it doesn't.
-if (Result == LambdaIds.end())
-  return 0;
-return Result->second;
+return LambdaIds.lookup(RD);
   }
 
   /// Return a character sequence that is (somewhat) unique to the TU suitable



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


[PATCH] D153205: [clang-format] Add new block type ListInit

2023-06-18 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

In D153205#4430528 , @owenpan wrote:

> It seems to me that there has been a proliferation of new options being 
> proposed and/or accepted recently. I'd like to remind everyone of the 
> long-standing policy 
> 
>  of adding new options. That being said, I wonder if we should add a new 
> language `LK_C` along with its variants C78 (i.e. K&R C), C89 (i.e. ANSI C), 
> GNU extensions (e.g. #55745 
>  and #62755 
> ), etc.

That was already discussed: D117416#3250415 


You add a lot of checks and I honestly can't say if it does not affect other 
code that is not covered by the tests.




Comment at: clang/lib/Format/FormatToken.cpp:79
 bool FormatToken::opensBlockOrBlockTypeList(const FormatStyle &Style) const {
+  auto bk = getBlockKind();
   // C# Does not indent object initialisers as continuations.





Comment at: clang/lib/Format/FormatToken.cpp:86-88
+  if (is(tok::l_brace) && (bk == BK_BracedInit || bk == BK_ListInit) &&
+  Style.Cpp11BracedListStyle && Style.Language == FormatStyle::LK_Cpp)
+return false;

Which clang-format should've added.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153205

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


[PATCH] D153208: [clang-format] Add InsertNewlineAtEOF to .clang-format files

2023-06-18 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks accepted this revision.
HazardyKnusperkeks added a comment.
This revision is now accepted and ready to land.

We also could add a clang-format style, the you wouldn't have to to touch all 
.clang-format files. ;)


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

https://reviews.llvm.org/D153208

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


[PATCH] D152263: [clang][CFG] Add support for partitioning CFG into intervals.

2023-06-18 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added inline comments.



Comment at: clang/include/clang/Analysis/Analyses/IntervalPartition.h:35
+
+  std::set Blocks;
+

Nit: I wonder if we want something like `llvm::DenseSet` when we use smaller 
types like pointers. Same for `Successors`.



Comment at: clang/lib/Analysis/IntervalPartition.cpp:26
+
+  std::queue Worklist;
+  for (const CFGBlock *S : Header.succs())

Is it possible we end up adding the same node to the queue multiple times? Is 
that desirable or do we want to make sure we only have each node at most once?



Comment at: clang/lib/Analysis/IntervalPartition.cpp:37
+  // successors.
+  std::vector MaybeSuccessors;
+

Same question here, is it possible we might end up adding the same nodes 
multiple times? 



Comment at: clang/lib/Analysis/IntervalPartition.cpp:46-47
+
+// Check whether all predecessors are in the interval, in which case `B`
+// is included as well.
+bool AllInInterval = true;

I wonder if this approach is correct. Consider the following scenario:

```
   A
  / \
 B   C
 |   |
 |   D
  \ /
   E
```

In the BFS, we might visit: ABCED. Since we visit `E` before `D`, we might not 
recognize that `E` is part of the interval. Do I miss something?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152263

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


[PATCH] D153228: [clang-format] Fixed bad performance with enabled qualifier fixer.

2023-06-18 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

I'm shocked, astonished and in awe how small this patch is. Great work and 
explanation!




Comment at: clang/lib/Format/Format.cpp:3475
   AnalyzerPass;
   SmallVector Passes;
 

Just increase here, and add a comment that there are multiple passes added in 
`addQualifierAlignmentFixerPasses`.

I think the idea was and should be that we always store the pointers on the 
stack.



Comment at: clang/lib/Format/QualifierAlignmentFixer.cpp:36
+
+  Passes.reserve(Passes.size() + LeftOrder.size() + RightOrder.size());
 

I think we can drop this, see my other comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153228

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


[PATCH] D149280: [clang-tidy] Add modernize-printf-to-std-print check

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

Except readability issues with this check code (bunch of else, ..), and that I 
didn't took a deep dive into format string conversion (I hope that author is 
right there).
I would say that this check probably could be delivered. Would be nice to run 
it on some test projects, just to be sure that it wont crash or wont produce 
too much false-positives.
I still would expect that probably there can be some issues with it...

Next steps for this check would be:

- Fix some known (breaking) issues (like option naming)
- Deliver check to main
- Refactor code for performance / readability.
- Deliver code refactor.

Once on main branch, check can be tested by other users, and there is a chance 
that some issues with it could be found before branch-out.




Comment at: clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp:117
+  *MaybeHeaderToInclude);
+  } else
+DiagnosticBuilder Diag = diag(PrintfCall->getBeginLoc(),

Personally I would invert this, `if (!...canApply()) { 
diag(PrintfCall->getBeginLoc(),  "unable to use '%0' instead of %1 because %2") 
<< ...; return; }`



Comment at: clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp:118
+  } else
+DiagnosticBuilder Diag = diag(PrintfCall->getBeginLoc(),
+  "unable to use '%0' instead of %1 because 
%2")

no need to assign this to Diag, it will be destroyed anyway, just call diag.



Comment at: clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp:27
+
+namespace {
+/// Is the passed type the actual "char" type, whether that be signed or

no need for anonymous namespace per LLVM codding standard, use static keyword 
for all functions, put them all into clang::tidy::utils namespace



Comment at: clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp:146-148
+namespace clang::ast_matchers {
+AST_MATCHER(QualType, isRealChar) { return isRealCharType(Node); }
+} // namespace clang::ast_matchers

do not put matchers into clang::ast_matchers to avoid ODR issues. put it into 
anonymous namespace under clang::tidy::utils



Comment at: clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp:157-175
+: Context(ContextIn), CastMismatchedIntegerTypes([Call, StrictMode]() {
+/// For printf-style functions, the signedness of the type printed is
+/// indicated by the corresponding type in the format string.
+/// std::print will determine the signedness from the type of the
+/// argument. This means that it is necessary to generate a cast in
+/// StrictMode to ensure that the exact behaviour is maintained.
+/// However, for templated functions like absl::PrintF and

consider moving this into separate function that take Call and StrictMode as an 
argument this isn't readable. make function static.



Comment at: clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp:384-397
+const auto StringDecl = type(hasUnqualifiedDesugaredType(recordType(
+hasDeclaration(cxxRecordDecl(hasName("::std::basic_string"));
+const auto StringExpr = expr(anyOf(
+hasType(StringDecl), hasType(qualType(pointsTo(StringDecl);
+
+const auto StringCStrCallExpr =
+cxxMemberCallExpr(on(StringExpr.bind("arg")),

mikecrowe wrote:
> PiotrZSL wrote:
> > constant construction of those marchers may be costly.. can be cache them 
> > somehow in this object ?
> Good idea. Do you have any pointers to code that does this? I couldn't find 
> any.
> 
> The types involved all seem to be in the `internal::` namespace and 
> presumably subject to change. Ideally, I'd put:
> ```
> std::optional StringCStrCallExprMatcher;
> ```
> in the class and then populate it here the first time lazily. Unfortunately I 
> have no idea what type to use for `SomeSortOfMatcherType`.
`clang::ast_matchers::StatementMatcher`, this is defined as 
`using clang::ast_matchers::StatementMatcher = typedef internal::Matcher`.
I would create it in class constructor as private member.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst:117
+
+.. option:: PrintFunction
+

mikecrowe wrote:
> Is `PrintFunction` (and the soon-to-arrive `PrintlnFunction`) distinct enough 
> from `PrintfLikeFunctions` and `FprintfLikeFunctions`? Should I use 
> `ReplacementPrintFunction` instead?
Use `Replacement`. It will be way better.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149280

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

[PATCH] D149280: [clang-tidy] Add modernize-printf-to-std-print check

2023-06-18 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe added inline comments.



Comment at: clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp:202
+/// Called for each format specifier by ParsePrintfString.
+bool FormatStringConverter::HandlePrintfSpecifier(
+const analyze_printf::PrintfSpecifier &FS, const char *StartSpecifier,

mikecrowe wrote:
> PiotrZSL wrote:
> > this function should be split into smaller one.
> I agree. I'm surprised it hasn't come up in review earlier. I tried to do so 
> prior to pushing the very first version of this for review and gave up since 
> the parts ended up referring to so many local variables making the code even 
> harder to understand than it is now. I will have another attempt.
It turns out that things are working out much better in my second attempt at 
splitting this function. I shall address the other new review comments before 
sending another revision for review though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149280

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


[PATCH] D153008: [RISCV] Allow slash-star comments in instruction operands

2023-06-18 Thread Abel Bernabeu via Phabricator via cfe-commits
abel-bernabeu updated this revision to Diff 532488.
abel-bernabeu added a comment.

Updated commit message:

- fixed a typo
- added a co-author


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153008

Files:
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/test/CodeGen/RISCV/inline-asm-gcc-comments.ll

Index: llvm/test/CodeGen/RISCV/inline-asm-gcc-comments.ll
===
--- /dev/null
+++ llvm/test/CodeGen/RISCV/inline-asm-gcc-comments.ll
@@ -0,0 +1,17 @@
+; RUN: llc -mtriple=riscv32 -mattr=+f -target-abi ilp32f -verify-machineinstrs < %s \
+; RUN:   | FileCheck -check-prefix=RV32IF %s
+; RUN: llc -mtriple=riscv64 -mattr=+f -target-abi lp64f -verify-machineinstrs < %s \
+; RUN:   | FileCheck -check-prefix=RV64IF %s
+
+define i64 @f() #0 {
+; RV32IF-LABEL:   f:
+; RV32IF: li a0, 0 # this is fine # this is also fine # and last but not least
+;
+; RV64IF-LABEL:   f:
+; RV64IF: li a0, 0 # this is fine # this is also fine # and last but not least
+  %1 = alloca i64, align 8
+  %2 = call i64 asm "li /* this is fine */ $0 , /* this is also fine */ 0 /* and last but not least */\0A", "=r"()
+  store i64 %2, ptr %1, align 8
+  %3 = load i64, ptr %1, align 8
+  ret i64 %3
+}
\ No newline at end of file
Index: llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
===
--- llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -1617,7 +1617,7 @@
   Operands.push_back(RISCVOperand::createToken("(", FirstS));
 SMLoc S = getLoc();
 SMLoc E = SMLoc::getFromPointer(S.getPointer() + Name.size());
-getLexer().Lex();
+getParser().Lex();
 Operands.push_back(RISCVOperand::createReg(RegNo, S, E));
   }
 
@@ -1978,11 +1978,11 @@
 return MatchOperand_Success;
   case AsmToken::Plus:
 Opcode = MCBinaryExpr::Add;
-getLexer().Lex();
+getParser().Lex();
 break;
   case AsmToken::Minus:
 Opcode = MCBinaryExpr::Sub;
-getLexer().Lex();
+getParser().Lex();
 break;
   }
 
@@ -2131,11 +2131,11 @@
   MaskAgnostic))
 return MatchOperand_NoMatch;
 
-  getLexer().Lex();
+  getParser().Lex();
 
   while (getLexer().is(AsmToken::Comma)) {
 // Consume comma.
-getLexer().Lex();
+getParser().Lex();
 
 if (getLexer().isNot(AsmToken::Identifier))
   break;
@@ -2146,7 +2146,7 @@
 MaskAgnostic))
   break;
 
-getLexer().Lex();
+getParser().Lex();
   }
 
   if (getLexer().is(AsmToken::EndOfStatement) && State == VTypeState_Done) {
@@ -2186,7 +2186,7 @@
 return MatchOperand_NoMatch;
   SMLoc S = getLoc();
   SMLoc E = SMLoc::getFromPointer(S.getPointer() + Name.size());
-  getLexer().Lex();
+  getParser().Lex();
   Operands.push_back(RISCVOperand::createReg(RegNo, S, E));
   return MatchOperand_Success;
 }
@@ -2202,7 +2202,7 @@
 return MatchOperand_NoMatch;
   SMLoc S = getLoc();
   SMLoc E = SMLoc::getFromPointer(S.getPointer() + Name.size());
-  getLexer().Lex();
+  getParser().Lex();
   Operands.push_back(RISCVOperand::createReg(
   RegNo, S, E, !getSTI().hasFeature(RISCV::FeatureStdExtF)));
   return MatchOperand_Success;
@@ -2391,11 +2391,11 @@
 Error(getLoc(), "register list must start from 'ra' or 'x1'");
 return MatchOperand_ParseFail;
   }
-  getLexer().Lex();
+  getParser().Lex();
 
   // parse case like ,s0
   if (getLexer().is(AsmToken::Comma)) {
-getLexer().Lex();
+getParser().Lex();
 if (getLexer().isNot(AsmToken::Identifier)) {
   Error(getLoc(), "invalid register");
   return MatchOperand_ParseFail;
@@ -2410,12 +2410,12 @@
   Error(getLoc(), "continuous register list must start from 's0' or 'x8'");
   return MatchOperand_ParseFail;
 }
-getLexer().Lex(); // eat reg
+getParser().Lex(); // eat reg
   }
 
   // parse case like -s1
   if (getLexer().is(AsmToken::Minus)) {
-getLexer().Lex();
+getParser().Lex();
 StringRef EndName = getLexer().getTok().getIdentifier();
 // FIXME: the register mapping and checks of EABI is wrong
 RegEnd = matchRegisterNameHelper(IsEABI, EndName);
@@ -2428,7 +2428,7 @@
   "'x8-x9' pair");
   return MatchOperand_ParseFail;
 }
-getLexer().Lex();
+getParser().Lex();
   }
 
   if (!IsEABI) {
@@ -2442,7 +2442,7 @@
   }
 
   // parse ', x18' for extra part
-  getLexer().Lex();
+  getParser().Lex();
   if (getLexer().isNot(AsmToken::Identifier)) {
 Error(getLoc(), "invalid register");
 return MatchOperand_ParseFail;
@@ -2453,11 +2453,11 @@
 "must start from 'x18'");
 return MatchOperand_ParseFail;
   }
-  getLexer().Lex();
+  getParser().Lex();
 
   // parse '-x20' for extra part
   if (getLexer().is(AsmToken

[PATCH] D153008: [RISCV] Allow slash-star comments in instruction operands

2023-06-18 Thread Abel Bernabeu via Phabricator via cfe-commits
abel-bernabeu updated this revision to Diff 532489.
abel-bernabeu added a comment.

Fixed a typo on commit message


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153008

Files:
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/test/CodeGen/RISCV/inline-asm-gcc-comments.ll

Index: llvm/test/CodeGen/RISCV/inline-asm-gcc-comments.ll
===
--- /dev/null
+++ llvm/test/CodeGen/RISCV/inline-asm-gcc-comments.ll
@@ -0,0 +1,17 @@
+; RUN: llc -mtriple=riscv32 -mattr=+f -target-abi ilp32f -verify-machineinstrs < %s \
+; RUN:   | FileCheck -check-prefix=RV32IF %s
+; RUN: llc -mtriple=riscv64 -mattr=+f -target-abi lp64f -verify-machineinstrs < %s \
+; RUN:   | FileCheck -check-prefix=RV64IF %s
+
+define i64 @f() #0 {
+; RV32IF-LABEL:   f:
+; RV32IF: li a0, 0 # this is fine # this is also fine # and last but not least
+;
+; RV64IF-LABEL:   f:
+; RV64IF: li a0, 0 # this is fine # this is also fine # and last but not least
+  %1 = alloca i64, align 8
+  %2 = call i64 asm "li /* this is fine */ $0 , /* this is also fine */ 0 /* and last but not least */\0A", "=r"()
+  store i64 %2, ptr %1, align 8
+  %3 = load i64, ptr %1, align 8
+  ret i64 %3
+}
\ No newline at end of file
Index: llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
===
--- llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -1617,7 +1617,7 @@
   Operands.push_back(RISCVOperand::createToken("(", FirstS));
 SMLoc S = getLoc();
 SMLoc E = SMLoc::getFromPointer(S.getPointer() + Name.size());
-getLexer().Lex();
+getParser().Lex();
 Operands.push_back(RISCVOperand::createReg(RegNo, S, E));
   }
 
@@ -1978,11 +1978,11 @@
 return MatchOperand_Success;
   case AsmToken::Plus:
 Opcode = MCBinaryExpr::Add;
-getLexer().Lex();
+getParser().Lex();
 break;
   case AsmToken::Minus:
 Opcode = MCBinaryExpr::Sub;
-getLexer().Lex();
+getParser().Lex();
 break;
   }
 
@@ -2131,11 +2131,11 @@
   MaskAgnostic))
 return MatchOperand_NoMatch;
 
-  getLexer().Lex();
+  getParser().Lex();
 
   while (getLexer().is(AsmToken::Comma)) {
 // Consume comma.
-getLexer().Lex();
+getParser().Lex();
 
 if (getLexer().isNot(AsmToken::Identifier))
   break;
@@ -2146,7 +2146,7 @@
 MaskAgnostic))
   break;
 
-getLexer().Lex();
+getParser().Lex();
   }
 
   if (getLexer().is(AsmToken::EndOfStatement) && State == VTypeState_Done) {
@@ -2186,7 +2186,7 @@
 return MatchOperand_NoMatch;
   SMLoc S = getLoc();
   SMLoc E = SMLoc::getFromPointer(S.getPointer() + Name.size());
-  getLexer().Lex();
+  getParser().Lex();
   Operands.push_back(RISCVOperand::createReg(RegNo, S, E));
   return MatchOperand_Success;
 }
@@ -2202,7 +2202,7 @@
 return MatchOperand_NoMatch;
   SMLoc S = getLoc();
   SMLoc E = SMLoc::getFromPointer(S.getPointer() + Name.size());
-  getLexer().Lex();
+  getParser().Lex();
   Operands.push_back(RISCVOperand::createReg(
   RegNo, S, E, !getSTI().hasFeature(RISCV::FeatureStdExtF)));
   return MatchOperand_Success;
@@ -2391,11 +2391,11 @@
 Error(getLoc(), "register list must start from 'ra' or 'x1'");
 return MatchOperand_ParseFail;
   }
-  getLexer().Lex();
+  getParser().Lex();
 
   // parse case like ,s0
   if (getLexer().is(AsmToken::Comma)) {
-getLexer().Lex();
+getParser().Lex();
 if (getLexer().isNot(AsmToken::Identifier)) {
   Error(getLoc(), "invalid register");
   return MatchOperand_ParseFail;
@@ -2410,12 +2410,12 @@
   Error(getLoc(), "continuous register list must start from 's0' or 'x8'");
   return MatchOperand_ParseFail;
 }
-getLexer().Lex(); // eat reg
+getParser().Lex(); // eat reg
   }
 
   // parse case like -s1
   if (getLexer().is(AsmToken::Minus)) {
-getLexer().Lex();
+getParser().Lex();
 StringRef EndName = getLexer().getTok().getIdentifier();
 // FIXME: the register mapping and checks of EABI is wrong
 RegEnd = matchRegisterNameHelper(IsEABI, EndName);
@@ -2428,7 +2428,7 @@
   "'x8-x9' pair");
   return MatchOperand_ParseFail;
 }
-getLexer().Lex();
+getParser().Lex();
   }
 
   if (!IsEABI) {
@@ -2442,7 +2442,7 @@
   }
 
   // parse ', x18' for extra part
-  getLexer().Lex();
+  getParser().Lex();
   if (getLexer().isNot(AsmToken::Identifier)) {
 Error(getLoc(), "invalid register");
 return MatchOperand_ParseFail;
@@ -2453,11 +2453,11 @@
 "must start from 'x18'");
 return MatchOperand_ParseFail;
   }
-  getLexer().Lex();
+  getParser().Lex();
 
   // parse '-x20' for extra part
   if (getLexer().is(AsmToken::Minus)) {
-getLexer

[PATCH] D153233: clang: Add __builtin_elementwise_rint and nearbyint

2023-06-18 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm created this revision.
arsenm added reviewers: aaron.ballman, RKSimon, fhahn, junaire, bob80905, 
python3kgae, erichkeane, sepavloff, kpn, andrew.w.kaylor.
Herald added a subscriber: StephenFan.
Herald added a project: All.
arsenm requested review of this revision.
Herald added a subscriber: wdng.

These are basically the same thing and only differ for strictfp,
so add both for future proofing. Note all the elementwise functions are
currently broken for strictfp, and use non-constrained ops. Add a test
that demonstrates this, but doesn't attempt to fix it.


https://reviews.llvm.org/D153233

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/Builtins.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-elementwise-math.c
  clang/test/CodeGen/strictfp-elementwise-bulitins.cpp
  clang/test/Sema/builtins-elementwise-math.c

Index: clang/test/Sema/builtins-elementwise-math.c
===
--- clang/test/Sema/builtins-elementwise-math.c
+++ clang/test/Sema/builtins-elementwise-math.c
@@ -460,7 +460,6 @@
 }
 
 void test_builtin_elementwise_round(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
-
   struct Foo s = __builtin_elementwise_round(f);
   // expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'float'}}
 
@@ -485,6 +484,56 @@
   // expected-error@-1 {{1st argument must be a vector, integer or floating point type (was '_Complex float')}}
 }
 
+void test_builtin_elementwise_rint(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
+  struct Foo s = __builtin_elementwise_rint(f);
+  // expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'float'}}
+
+  i = __builtin_elementwise_rint();
+  // expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
+
+  i = __builtin_elementwise_rint(i);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'int')}}
+
+  i = __builtin_elementwise_rint(f, f);
+  // expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
+
+  u = __builtin_elementwise_rint(u);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned int')}}
+
+  uv = __builtin_elementwise_rint(uv);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
+
+  // FIXME: Error should not mention integer
+  _Complex float c1, c2;
+  c1 = __builtin_elementwise_rint(c1);
+  // expected-error@-1 {{1st argument must be a vector, integer or floating point type (was '_Complex float')}}
+}
+
+void test_builtin_elementwise_nearbyint(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
+  struct Foo s = __builtin_elementwise_nearbyint(f);
+  // expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'float'}}
+
+  i = __builtin_elementwise_nearbyint();
+  // expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
+
+  i = __builtin_elementwise_nearbyint(i);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'int')}}
+
+  i = __builtin_elementwise_nearbyint(f, f);
+  // expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
+
+  u = __builtin_elementwise_nearbyint(u);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned int')}}
+
+  uv = __builtin_elementwise_nearbyint(uv);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
+
+  // FIXME: Error should not mention integer
+  _Complex float c1, c2;
+  c1 = __builtin_elementwise_nearbyint(c1);
+  // expected-error@-1 {{1st argument must be a vector, integer or floating point type (was '_Complex float')}}
+}
+
 void test_builtin_elementwise_sin(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
 
   struct Foo s = __builtin_elementwise_sin(f);
Index: clang/test/CodeGen/strictfp-elementwise-bulitins.cpp
===
--- /dev/null
+++ clang/test/CodeGen/strictfp-elementwise-bulitins.cpp
@@ -0,0 +1,264 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 2
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fexperimental-strict-floating-point -frounding-math -ffp-exception-behavior=strict -O2 -emit-llvm -o - %s | FileCheck %s
+
+typedef float float2 __attribute__((ext_vector_type(2)));
+
+// Sanity check we're getting constrained ops for a non-builtin.
+// CHECK-LABEL: define dso_local noundef double @_Z11strict_faddDv2_fS_
+// CHECK-SAME: (double noundef [[A_COERCE:%.*]], double noundef [[B_COERCE:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = bitcast double [[A_COERC

[PATCH] D151696: [x86] Remove CPU_SPECIFIC* MACROs and add getManglingForCPU

2023-06-18 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe updated this revision to Diff 532494.
FreddyYe added a comment.

Update cpus-intel.ll.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151696

Files:
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/attr-cpuspecific-avx-abi.c
  clang/test/CodeGen/attr-cpuspecific.c
  llvm/include/llvm/TargetParser/X86TargetParser.def
  llvm/include/llvm/TargetParser/X86TargetParser.h
  llvm/lib/Target/X86/X86.td
  llvm/lib/TargetParser/X86TargetParser.cpp
  llvm/test/CodeGen/X86/cpus-intel.ll

Index: llvm/test/CodeGen/X86/cpus-intel.ll
===
--- llvm/test/CodeGen/X86/cpus-intel.ll
+++ llvm/test/CodeGen/X86/cpus-intel.ll
@@ -6,16 +6,24 @@
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=i586 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium-mmx 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_mmx 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=i686 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentiumpro 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_pro 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium2 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_ii 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium3 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium3m 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_iii 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_iii_no_xmm_regs 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_m 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium-m 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium4 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium4m 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_4 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=yonah 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=prescott 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_4_sse3 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=lakemont 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=raptorlake 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=meteorlake 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
@@ -26,26 +34,39 @@
 
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=nocona 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=core2 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=core_2_duo_ssse3 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=penryn 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=core_2_duo_sse4_1 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null 

[PATCH] D152764: [clang-tidy] Reserved-identifier: Improved AllowedIdentifiers option to support regular expressions

2023-06-18 Thread Félix-Antoine Constantin via Phabricator via cfe-commits
felix642 updated this revision to Diff 532495.
felix642 added a comment.

Resolved comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152764

Files:
  clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/reserved-identifier.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/reserved-identifier-invert.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/reserved-identifier-invert.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/reserved-identifier-invert.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/reserved-identifier-invert.cpp
@@ -1,7 +1,7 @@
 // RUN: %check_clang_tidy %s bugprone-reserved-identifier %t -- \
 // RUN:   -config='{CheckOptions: [ \
 // RUN: {key: bugprone-reserved-identifier.Invert, value: true}, \
-// RUN: {key: bugprone-reserved-identifier.AllowedIdentifiers, value: std;reference_wrapper;ref;cref;type;get}, \
+// RUN: {key: bugprone-reserved-identifier.AllowedIdentifiers, value: "std;reference_wrapper;^c?ref;type;get"}, \
 // RUN:   ]}' -- \
 // RUN:   -I%S/Inputs/reserved-identifier \
 // RUN:   -isystem %S/Inputs/reserved-identifier/system
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone/reserved-identifier.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/bugprone/reserved-identifier.rst
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone/reserved-identifier.rst
@@ -53,5 +53,5 @@
 
 .. option:: AllowedIdentifiers
 
-   Semicolon-separated list of names that the check ignores. Default is an
+   Semicolon-separated list of regular expressions that the check ignores. Default is an
empty list.
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -243,6 +243,10 @@
   ` check by adding support for
   other floating point representations in float constant like ``0.5L``.
 
+- Improved the :doc:`bugprone-reserved-identifier 
+  ` check by enhancing the 
+  `AllowedIdentifiers` option to support regular expressions.
+
 - Deprecated check-local options `HeaderFileExtensions` and `ImplementationFileExtensions`
   in :doc:`bugprone-suspicious-include
   ` check.
Index: clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.h
===
--- clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.h
@@ -30,7 +30,8 @@
 /// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/reserved-identifier.html
 class ReservedIdentifierCheck final : public RenamerClangTidyCheck {
   const bool Invert;
-  const std::vector AllowedIdentifiers;
+  const std::vector AllowedIdentifiersRaw;
+  const llvm::SmallVector AllowedIdentifiers;
 
 public:
   ReservedIdentifierCheck(StringRef Name, ClangTidyContext *Context);
@@ -46,6 +47,7 @@
   const SourceManager &SM) const override;
   DiagInfo getDiagInfo(const NamingCheckId &ID,
const NamingCheckFailure &Failure) const override;
+  llvm::SmallVector parseAllowedIdentifiers() const;
 };
 
 } // namespace clang::tidy::bugprone
Index: clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp
@@ -39,18 +39,35 @@
   return 0;
 }
 
+llvm::SmallVector
+ReservedIdentifierCheck::parseAllowedIdentifiers() const {
+  llvm::SmallVector AllowedIdentifiers;
+  AllowedIdentifiers.reserve(AllowedIdentifiersRaw.size());
+
+  for (const auto &Identifier : AllowedIdentifiersRaw) {
+AllowedIdentifiers.emplace_back(Identifier.str());
+if (!AllowedIdentifiers.back().isValid()) {
+  configurationDiag("Invalid allowed identifier regex '%0'") << Identifier;
+  AllowedIdentifiers.pop_back();
+}
+  }
+
+  return AllowedIdentifiers;
+}
+
 ReservedIdentifierCheck::ReservedIdentifierCheck(StringRef Name,
  ClangTidyContext *Context)
 : RenamerClangTidyCheck(Name, Context),
   Invert(Options.get("Invert", false)),
-  AllowedIdentifiers(utils::options::parseStringList(
-  Options.get("AllowedIdentifiers", ""))) {}
+  AllowedIdentifiersRaw(utils::options::parseStringList(
+  Options.get("AllowedIdentifiers", ""))),
+  AllowedIdentifiers(parseAllowedIdentifiers()) {}
 
 void ReservedIdentifierCheck:

[PATCH] D151696: [x86] Remove CPU_SPECIFIC* MACROs and add getManglingForCPU

2023-06-18 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe marked 2 inline comments as done.
FreddyYe added inline comments.



Comment at: llvm/test/CodeGen/X86/cpus-intel.ll:8
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium 2>&1 
| FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
-; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium-mmx 
2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium-mmx 
-mcpu=pentium_mmx 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR 
--allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=i686 2>&1 | 
FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty

RKSimon wrote:
> I meant like this:
> ```
> ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium-mmx 
> 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
> ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_mmx 
> 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
> ```
> The idea is to keep RUN lines that test the equivalent cpus together, so its 
> easier for any future edits to handle them together
Woops, I really misunderstood. Updated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151696

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


[PATCH] D153235: [RISCV] Change the type of argument to clz and ctz from ZiZi/WiWi to iUi/iULi

2023-06-18 Thread Jim Lin via Phabricator via cfe-commits
Jim created this revision.
Herald added subscribers: jobnoorman, luke, VincentWu, vkmr, frasercrmck, 
luismarques, apazos, sameer.abuasal, s.egerton, benna, psnobl, jocewei, PkmX, 
the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, 
shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, 
arichardson.
Herald added a project: All.
Jim requested review of this revision.
Herald added subscribers: cfe-commits, wangpc, eopXD, MaskRay.
Herald added a project: clang.

In clang/include/clang/Basic/Builtins.def, the argument type of __builtin_clz 
and __builtin_ctz
are defined `iUi` and __builtin_clzl and __builtin_ctzl are defined `iULi`.

clz/ctz are similar to RISC-V's clz_32 and ctz_32.
clzl/ctzl are similar to RISC-V's clz_64 and ctz_64.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153235

Files:
  clang/include/clang/Basic/BuiltinsRISCV.def
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb.c
  clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbb.c


Index: clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbb.c
===
--- clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbb.c
+++ clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbb.c
@@ -34,7 +34,7 @@
 // RV64ZBB-NEXT:[[TMP1:%.*]] = call i32 @llvm.ctlz.i32(i32 [[TMP0]], i1 
false)
 // RV64ZBB-NEXT:ret i32 [[TMP1]]
 //
-int clz_32(int a) {
+int clz_32(unsigned int a) {
   return __builtin_riscv_clz_32(a);
 }
 
@@ -46,7 +46,7 @@
 // RV64ZBB-NEXT:[[TMP1:%.*]] = call i64 @llvm.ctlz.i64(i64 [[TMP0]], i1 
false)
 // RV64ZBB-NEXT:ret i64 [[TMP1]]
 //
-long clz_64(long a) {
+long clz_64(unsigned long a) {
   return __builtin_riscv_clz_64(a);
 }
 
@@ -58,7 +58,7 @@
 // RV64ZBB-NEXT:[[TMP1:%.*]] = call i32 @llvm.cttz.i32(i32 [[TMP0]], i1 
false)
 // RV64ZBB-NEXT:ret i32 [[TMP1]]
 //
-int ctz_32(int a) {
+int ctz_32(unsigned int a) {
   return __builtin_riscv_ctz_32(a);
 }
 
@@ -70,6 +70,6 @@
 // RV64ZBB-NEXT:[[TMP1:%.*]] = call i64 @llvm.cttz.i64(i64 [[TMP0]], i1 
false)
 // RV64ZBB-NEXT:ret i64 [[TMP1]]
 //
-long ctz_64(long a) {
+long ctz_64(unsigned long a) {
   return __builtin_riscv_ctz_64(a);
 }
\ No newline at end of file
Index: clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb.c
===
--- clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb.c
+++ clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb.c
@@ -22,7 +22,7 @@
 // RV32ZBB-NEXT:[[TMP1:%.*]] = call i32 @llvm.ctlz.i32(i32 [[TMP0]], i1 
false)
 // RV32ZBB-NEXT:ret i32 [[TMP1]]
 //
-int clz_32(int a) {
+int clz_32(unsigned int a) {
   return __builtin_riscv_clz_32(a);
 }
 
@@ -34,6 +34,6 @@
 // RV32ZBB-NEXT:[[TMP1:%.*]] = call i32 @llvm.cttz.i32(i32 [[TMP0]], i1 
false)
 // RV32ZBB-NEXT:ret i32 [[TMP1]]
 //
-int ctz_32(int a) {
+int ctz_32(unsigned int a) {
   return __builtin_riscv_ctz_32(a);
 }
\ No newline at end of file
Index: clang/include/clang/Basic/BuiltinsRISCV.def
===
--- clang/include/clang/Basic/BuiltinsRISCV.def
+++ clang/include/clang/Basic/BuiltinsRISCV.def
@@ -18,10 +18,10 @@
 // Zbb extension
 TARGET_BUILTIN(__builtin_riscv_orc_b_32, "ZiZi", "nc", "zbb")
 TARGET_BUILTIN(__builtin_riscv_orc_b_64, "WiWi", "nc", "zbb,64bit")
-TARGET_BUILTIN(__builtin_riscv_clz_32, "ZiZi", "nc", "zbb|xtheadbb")
-TARGET_BUILTIN(__builtin_riscv_clz_64, "WiWi", "nc", "zbb|xtheadbb,64bit")
-TARGET_BUILTIN(__builtin_riscv_ctz_32, "ZiZi", "nc", "zbb")
-TARGET_BUILTIN(__builtin_riscv_ctz_64, "WiWi", "nc", "zbb,64bit")
+TARGET_BUILTIN(__builtin_riscv_clz_32, "iUi", "nc", "zbb|xtheadbb")
+TARGET_BUILTIN(__builtin_riscv_clz_64, "iULi", "nc", "zbb|xtheadbb,64bit")
+TARGET_BUILTIN(__builtin_riscv_ctz_32, "iUi", "nc", "zbb")
+TARGET_BUILTIN(__builtin_riscv_ctz_64, "iULi", "nc", "zbb,64bit")
 
 // Zbc or Zbkc extension
 TARGET_BUILTIN(__builtin_riscv_clmul, "LiLiLi", "nc", "zbc|zbkc")


Index: clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbb.c
===
--- clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbb.c
+++ clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbb.c
@@ -34,7 +34,7 @@
 // RV64ZBB-NEXT:[[TMP1:%.*]] = call i32 @llvm.ctlz.i32(i32 [[TMP0]], i1 false)
 // RV64ZBB-NEXT:ret i32 [[TMP1]]
 //
-int clz_32(int a) {
+int clz_32(unsigned int a) {
   return __builtin_riscv_clz_32(a);
 }
 
@@ -46,7 +46,7 @@
 // RV64ZBB-NEXT:[[TMP1:%.*]] = call i64 @llvm.ctlz.i64(i64 [[TMP0]], i1 false)
 // RV64ZBB-NEXT:ret i64 [[TMP1]]
 //
-long clz_64(long a) {
+long clz_64(unsigned long a) {
   return __builtin_riscv_clz_64(a);
 }
 
@@ -58,7 +58,7 @@
 // RV64ZBB-NEXT:[[TMP1:%.*]] = call i32 @llvm.cttz.i32(i32 [[TMP0]], i1 false)
 // RV64ZBB-NEXT:ret i32 [[TMP1]]
 //
-int ctz_32(int a) {
+int ctz_32(unsigned int a) {
   return __builtin_riscv_ctz_32(a);
 }
 
@@ -70

[PATCH] D153114: [clangd] [C++20] [Modules] Support C++20 modules for clangd

2023-06-18 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu updated this revision to Diff 532502.
ChuanqiXu added a comment.

Address comments.


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

https://reviews.llvm.org/D153114

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
  clang-tools-extra/clangd/GlobalCompilationDatabase.h
  clang-tools-extra/clangd/ModulesManager.cpp
  clang-tools-extra/clangd/ModulesManager.h
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/test/CMakeLists.txt
  clang-tools-extra/clangd/test/modules.test
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/ModulesManagerTests.cpp
  clang-tools-extra/docs/ReleaseNotes.rst

Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -48,6 +48,9 @@
 Improvements to clangd
 --
 
+- Implemented the experimental support for C++20 modules. This can be enabled by
+  `-experimental-modules-support` option.
+
 Inlay hints
 ^^^
 
Index: clang-tools-extra/clangd/unittests/ModulesManagerTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/ModulesManagerTests.cpp
@@ -0,0 +1,350 @@
+//===-- ModulesManagerTests.cpp -*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Config.h"
+#include "ModulesManager.h"
+
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using namespace clang;
+using namespace clang::clangd;
+using namespace llvm;
+
+namespace {
+class ModulesManagerTest : public ::testing::Test {
+  void SetUp() override {
+ASSERT_FALSE(sys::fs::createUniqueDirectory("modules-test", TestDir));
+llvm::errs() << "Created TestDir: " << TestDir << "\n";
+  }
+
+  void TearDown() override {
+// sys::fs::remove_directories(TestDir);
+  }
+
+public:
+  SmallString<256> TestDir;
+
+  // Add files to the working testing directory and repalce all the
+  // `__DIR__` to TestDir.
+  void addFile(StringRef Path, StringRef Contents) {
+ASSERT_FALSE(sys::path::is_absolute(Path));
+
+SmallString<256> AbsPath(TestDir);
+sys::path::append(AbsPath, Path);
+
+ASSERT_FALSE(
+sys::fs::create_directories(llvm::sys::path::parent_path(AbsPath)));
+
+std::error_code EC;
+llvm::raw_fd_ostream OS(AbsPath, EC);
+ASSERT_FALSE(EC);
+
+std::size_t Pos = Contents.find("__DIR__");
+while (Pos != llvm::StringRef::npos) {
+  OS << Contents.take_front(Pos);
+  OS << TestDir;
+  Contents = Contents.drop_front(Pos + sizeof("__DIR__") - 1);
+  Pos = Contents.find("__DIR__");
+}
+
+OS << Contents;
+  }
+
+  // Get the absolute path for file specified by Path under testing working
+  // directory.
+  std::string getFullPath(StringRef Path) {
+SmallString<128> Result(TestDir);
+sys::path::append(Result, Path);
+return Result.str().str();
+  }
+};
+
+TEST_F(ModulesManagerTest, ReplaceCommandsTest) {
+  addFile("build/compile_commands.json", R"cpp(
+[
+{
+  "directory": "__DIR__",
+  "command": "clang++ -std=c++20 __DIR__/M.cppm -c -o __DIR__/M.o -fmodule-file=D=__DIR__/D.pcm",
+  "file": "__DIR__/M.cppm",
+  "output": "__DIR__/M.o"
+}
+]
+  )cpp");
+
+  addFile("M.cppm", R"cpp(
+export module M;
+import D;
+  )cpp");
+
+  RealThreadsafeFS TFS;
+  DirectoryBasedGlobalCompilationDatabase::Options Opts(TFS);
+  DirectoryBasedModulesGlobalCompilationDatabase MCDB(Opts,
+  /*AsyncThreadsCount*/ 4);
+
+  std::optional Cmd =
+  MCDB.getCompileCommand(getFullPath("M.cppm"));
+  EXPECT_TRUE(Cmd);
+  // Since the graph is not built yet. We don't expect to see the mutated
+  // command line for modules.
+  EXPECT_FALSE(any_of(Cmd->CommandLine, [](StringRef Arg) {
+return Arg.count("-fprebuilt-module-path");
+  }));
+  EXPECT_TRUE(any_of(Cmd->CommandLine, [](StringRef Arg) {
+return Arg.count("-fmodule-file=");
+  }));
+
+  ModulesManager *MMgr = MCDB.getModulesManager();
+  EXPECT_TRUE(MMgr);
+  MMgr->UpdateNode(getFullPath("M.cppm"));
+
+  MMgr->waitUntilInitialized();
+
+  Cmd = MCDB.getCompileCommand(getFullPath("M.cppm"));
+  EXPECT_TRUE(Cmd);
+  // Since the graph has been built. We expect to see the mutated command line
+  // for modules.
+  EXPECT_TRUE(any_of(C

[PATCH] D153114: [clangd] [C++20] [Modules] Support C++20 modules for clangd

2023-06-18 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added inline comments.



Comment at: clang-tools-extra/clangd/ModulesManager.cpp:413-414
+  else
+WaitingCallables[Filename.str()].push_back(
+{std::move(ReadyCallback), std::move(ReadyCallback)});
+}

Destroyerrrocket wrote:
> This is a bug; The second move is invalid. You could make a copy
Done. Thanks for looking this. I changed it with a new signature for the 
callbacks with a bool argument.


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

https://reviews.llvm.org/D153114

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


[PATCH] D152785: [COFF] Support -gsplit-dwarf for COFF on Windows

2023-06-18 Thread Haohai, Wen via Phabricator via cfe-commits
HaohaiWen updated this revision to Diff 532507.
HaohaiWen added a comment.

Use --target


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152785

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/split-debug.c
  llvm/include/llvm/MC/MCWinCOFFObjectWriter.h
  llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
  llvm/lib/MC/MCAsmBackend.cpp
  llvm/lib/MC/WinCOFFObjectWriter.cpp
  llvm/test/DebugInfo/COFF/dwarf-headers.ll
  llvm/test/DebugInfo/COFF/fission-cu.ll
  llvm/test/DebugInfo/COFF/fission-sections.ll

Index: llvm/test/DebugInfo/COFF/fission-sections.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/COFF/fission-sections.ll
@@ -0,0 +1,42 @@
+; RUN: llc -split-dwarf-file=baz.dwo -split-dwarf-output=%t.dwo -O0 %s -mtriple=x86_64-unknown-windows-msvc -filetype=obj -o %t
+; RUN: llvm-objdump -h %t | FileCheck --check-prefix=OBJ %s
+; RUN: llvm-objdump -h %t.dwo | FileCheck --check-prefix=DWO %s
+
+; This test is derived from test/DebugInfo/X86/fission-cu.ll
+; But it checks that the output objects have the expected sections
+
+source_filename = "test/DebugInfo/X86/fission-cu.ll"
+
+@a = common global i32 0, align 4, !dbg !0
+
+!llvm.dbg.cu = !{!4}
+!llvm.module.flags = !{!7}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = !DIGlobalVariable(name: "a", scope: null, file: !2, line: 1, type: !3, isLocal: false, isDefinition: true)
+!2 = !DIFile(filename: "baz.c", directory: "e:\\llvm-project\\tmp")
+!3 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
+!4 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, producer: "clang version 3.3 (trunk 169021) (llvm/trunk 169020)", isOptimized: false, runtimeVersion: 0, splitDebugFilename: "baz.dwo", emissionKind: FullDebug, enums: !5, retainedTypes: !5, globals: !6, imports: !5)
+!5 = !{}
+!6 = !{!0}
+!7 = !{i32 1, !"Debug Info Version", i32 3}
+
+; CHECK-LABEL: Sections:
+
+; OBJ: Idx Name
+; OBJ-NEXT:  0 .text
+; OBJ-NEXT:  1 .data
+; OBJ-NEXT:  2 .bss
+; OBJ-NEXT:  3 .debug_abbrev
+; OBJ-NEXT:  4 .debug_info
+; OBJ-NEXT:  5 .debug_str
+; OBJ-NEXT:  6 .debug_addr
+; OBJ-NEXT:  7 .debug_pubnames
+; OBJ-NEXT:  8 .debug_pubtypes
+; OBJ-NEXT:  9 .debug_line
+
+; DWO:  Idx Name
+; DWO-NEXT:   0 .debug_str.dwo
+; DWO-NEXT:   1 .debug_str_offsets.dwo
+; DWO-NEXT:   2 .debug_info.dwo
+; DWO-NEXT:   3 .debug_abbrev.dwo
Index: llvm/test/DebugInfo/COFF/fission-cu.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/COFF/fission-cu.ll
@@ -0,0 +1,120 @@
+; RUN: llc -split-dwarf-file=baz.dwo -O0 %s -mtriple=x86_64-unknown-windows-msvc -filetype=obj -o %t
+; RUN: llvm-dwarfdump -v -all %t | FileCheck %s
+; RUN: llvm-readobj --relocations %t | FileCheck --check-prefix=OBJ %s
+; RUN: llvm-objdump -h %t | FileCheck --check-prefix=HDR %s
+
+; This test is derived from test/DebugInfo/X86/fission-cu.ll
+
+source_filename = "test/DebugInfo/X86/fission-cu.ll"
+
+@a = common global i32 0, align 4, !dbg !0
+
+!llvm.dbg.cu = !{!4}
+!llvm.module.flags = !{!7}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = !DIGlobalVariable(name: "a", scope: null, file: !2, line: 1, type: !3, isLocal: false, isDefinition: true)
+!2 = !DIFile(filename: "baz.c", directory: "e:\\llvm-project\\tmp")
+!3 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
+!4 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, producer: "clang version 3.3 (trunk 169021) (llvm/trunk 169020)", isOptimized: false, runtimeVersion: 0, splitDebugFilename: "baz.dwo", emissionKind: FullDebug, enums: !5, retainedTypes: !5, globals: !6, imports: !5)
+!5 = !{}
+; Check that the skeleton compile unit contains the proper attributes:
+; This DIE has the following attributes: DW_AT_comp_dir, DW_AT_stmt_list,
+; DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges, DW_AT_dwo_name, DW_AT_dwo_id,
+; DW_AT_ranges_base, DW_AT_addr_base.
+
+; CHECK: .debug_abbrev contents:
+; CHECK: Abbrev table for offset: 0x
+; CHECK: [1] DW_TAG_compile_unit DW_CHILDREN_no
+; CHECK: DW_AT_stmt_list DW_FORM_sec_offset
+; CHECK: DW_AT_comp_dir  DW_FORM_strp
+; CHECK: DW_AT_GNU_dwo_name  DW_FORM_strp
+; CHECK: DW_AT_GNU_dwo_idDW_FORM_data8
+
+; Check that we're using the right forms.
+; CHECK: .debug_abbrev.dwo contents:
+; CHECK: Abbrev table for offset: 0x
+; CHECK: [1] DW_TAG_compile_unit DW_CHILDREN_yes
+; CHECK: DW_AT_producer  DW_FORM_GNU_str_index
+; CHECK: DW_AT_language  DW_FORM_data2
+; CHECK: DW_AT_name  DW_FORM_GNU_str_index
+; CHECK: DW_AT_GNU_dwo_name  DW_FORM_GNU_str_index
+; CHECK-NOT: DW_AT_low_pc
+; CHECK-NOT: DW_AT_stmt_list
+; CHECK-NOT: DW_AT_comp_dir
+; CHECK: DW_AT_GNU_dwo_idDW_FORM_da

[PATCH] D152785: [COFF] Support -gsplit-dwarf for COFF on Windows

2023-06-18 Thread Haohai, Wen via Phabricator via cfe-commits
HaohaiWen marked 7 inline comments as done.
HaohaiWen added inline comments.



Comment at: llvm/lib/MC/WinCOFFObjectWriter.cpp:124
 
+bool isDwoSection(const MCSection &Sec) {
+  return Sec.getName().endswith(".dwo");

MaskRay wrote:
> static
It's already in anonymous namespace.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152785

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


[clang] 2d8044e - Recommit [ABI] [C++20] [Modules] Don't generate vtable if the class is defined in other module unit

2023-06-18 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2023-06-19T10:41:12+08:00
New Revision: 2d8044ee8b19f23e0a7fe5cd35876515d0d1d72e

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

LOG: Recommit [ABI] [C++20] [Modules] Don't generate vtable if the class is 
defined in other module unit

Close https://github.com/llvm/llvm-project/issues/61940.

The root cause is that clang will generate vtable as strong symbol now
even if the corresponding class is defined in other module units. After
I check the wording in Itanium ABI, I find this is not inconsistent.
Itanium ABI 5.2.3
(https://itanium-cxx-abi.github.io/cxx-abi/abi.html#vague-vtable) says:

> The virtual table for a class is emitted in the same object containing
> the definition of its key function, i.e. the first non-pure virtual
> function that is not inline at the point of class definition.

So the current behavior is incorrect. This patch tries to address this.
Also I think we need to do a similar change for MSVC ABI. But I don't
find the formal wording. So I don't address this in this patch.

Reviewed By: rjmccall, iains, dblaikie

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

Added: 
clang/test/CodeGenCXX/modules-vtable.cppm

Modified: 
clang/lib/CodeGen/CGVTables.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGVTables.cpp b/clang/lib/CodeGen/CGVTables.cpp
index 32259d1e4cbff..fb0276af57b25 100644
--- a/clang/lib/CodeGen/CGVTables.cpp
+++ b/clang/lib/CodeGen/CGVTables.cpp
@@ -1172,9 +1172,16 @@ bool CodeGenVTables::isVTableExternal(const 
CXXRecordDecl *RD) {
   if (!keyFunction)
 return false;
 
+  const FunctionDecl *Def;
   // Otherwise, if we don't have a definition of the key function, the
   // vtable must be defined somewhere else.
-  return !keyFunction->hasBody();
+  if (!keyFunction->hasBody(Def))
+return true;
+
+  assert(Def && "The body of the key function is not assigned to Def?");
+  // If the non-inline key function comes from another module unit, the vtable
+  // must be defined there.
+  return Def->isInAnotherModuleUnit() && !Def->isInlineSpecified();
 }
 
 /// Given that we're currently at the end of the translation unit, and

diff  --git a/clang/test/CodeGenCXX/modules-vtable.cppm 
b/clang/test/CodeGenCXX/modules-vtable.cppm
new file mode 100644
index 0..5d13225697b4d
--- /dev/null
+++ b/clang/test/CodeGenCXX/modules-vtable.cppm
@@ -0,0 +1,98 @@
+// REQUIRES: !system-windows
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 
-emit-module-interface \
+// RUN: %t/Mod.cppm -o %t/Mod.pcm
+//
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 %t/Mod.pcm \
+// RUN: -emit-llvm -o - | FileCheck %t/Mod.cppm
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 
-fmodule-file=Mod=%t/Mod.pcm \
+// RUN: %t/Use.cpp  -emit-llvm -o - | FileCheck %t/Use.cpp
+//
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 
-emit-module-interface \
+// RUN: %t/Mod.cppm -o %t/Mod.pcm -DKEY_FUNCTION_INLINE
+//
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 %t/Mod.pcm \
+// RUN: -emit-llvm -o - | FileCheck %t/Mod.cppm -check-prefix=CHECK-INLINE
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 
-fmodule-file=Mod=%t/Mod.pcm \
+// RUN: %t/Use.cpp  -emit-llvm -o - | FileCheck %t/Use.cpp 
-check-prefix=CHECK-INLINE
+//
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 
-emit-module-interface \
+// RUN: %t/M-A.cppm -o %t/M-A.pcm
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 
-fmodule-file=M:A=%t/M-A.pcm \
+// RUN: %t/M-B.cppm  -emit-llvm -o - | FileCheck %t/M-B.cppm
+
+//--- Mod.cppm
+export module Mod;
+
+export class Base {
+public:
+virtual ~Base();
+};
+#ifdef KEY_FUNCTION_INLINE
+inline
+#endif
+Base::~Base() {}
+
+// CHECK: @_ZTVW3Mod4Base = unnamed_addr constant
+// CHECK: @_ZTSW3Mod4Base = constant
+// CHECK: @_ZTIW3Mod4Base = constant
+
+// CHECK-INLINE: @_ZTVW3Mod4Base = linkonce_odr {{.*}}unnamed_addr constant
+// CHECK-INLINE: @_ZTSW3Mod4Base = linkonce_odr {{.*}}constant
+// CHECK-INLINE: @_ZTIW3Mod4Base = linkonce_odr {{.*}}constant
+
+module :private;
+int private_use() {
+Base base;
+return 43;
+}
+
+//--- Use.cpp
+import Mod;
+int use() {
+Base* base = new Base();
+return 43;
+}
+
+// CHECK-NOT: @_ZTSW3Mod4Base = constant
+// CHECK-NOT: @_ZTIW3Mod4Base = constant
+// CHECK: @_ZTVW3Mod4Base = external unnamed_addr
+
+// CHECK-INLINE: @_ZTVW3Mod4Base = linkonce_odr {{.*}}unnamed_addr constant
+// CHECK-INLINE: @_ZTSW3Mod4Base = linkonce_odr {{.*}}constant
+// CHECK-INLINE: @_ZTIW3Mod4Base = linkonce_odr {{.*}}constant
+
+// Check the case that the declaration of the key function comes from another
+// module unit but the de

[PATCH] D148216: Add support for annotations in UpdateTestChecks (NFC)

2023-06-18 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

could you put a little more information in the commit message please. "It won't 
do X when we do Y", could mean a lot of things. We don't do Y anymore, or we do 
X' now, with various choices for X'.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148216

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


[PATCH] D153236: [NFC] Fix potential dereferencing of nullptr.

2023-06-18 Thread Sindhu Chittireddy via Phabricator via cfe-commits
schittir created this revision.
schittir added reviewers: aaron.ballman, tahonermann, erichkeane.
Herald added a project: All.
schittir requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Replace getAs with castAs and add assert if needed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153236

Files:
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Sema/SemaExprObjC.cpp
  clang/lib/Sema/SemaObjCProperty.cpp
  clang/lib/Sema/SemaType.cpp


Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2709,7 +2709,7 @@
   }
   // Only support _BitInt elements with byte-sized power of 2 NumBits.
   if (CurType->isBitIntType()) {
-unsigned NumBits = CurType->getAs()->getNumBits();
+unsigned NumBits = CurType->casttAs()->getNumBits();
 if (!llvm::isPowerOf2_32(NumBits) || NumBits < 8) {
   Diag(AttrLoc, diag::err_attribute_invalid_bitint_vector_type)
   << (NumBits < 8);
Index: clang/lib/Sema/SemaObjCProperty.cpp
===
--- clang/lib/Sema/SemaObjCProperty.cpp
+++ clang/lib/Sema/SemaObjCProperty.cpp
@@ -1363,10 +1363,9 @@
 if (!Context.hasSameType(PropertyIvarType, IvarType)) {
   if (isa(PropertyIvarType)
   && isa(IvarType))
-compat =
-  Context.canAssignObjCInterfaces(
-  
PropertyIvarType->getAs(),
-  IvarType->getAs());
+compat = Context.canAssignObjCInterfaces(
+PropertyIvarType->castAs(),
+IvarType->castAs());
   else {
 compat = (CheckAssignmentConstraints(PropertyIvarLoc, PropertyIvarType,
  IvarType)
Index: clang/lib/Sema/SemaExprObjC.cpp
===
--- clang/lib/Sema/SemaExprObjC.cpp
+++ clang/lib/Sema/SemaExprObjC.cpp
@@ -2438,6 +2438,7 @@
   if (!ReceiverType.isNull())
 receiverTypeInfo = Context.getTrivialTypeSourceInfo(ReceiverType);
 
+  assert(receiverTypeInfo && "receiverTypeInfo cannot be null");
   return BuildClassMessage(receiverTypeInfo, ReceiverType,
   /*SuperLoc=*/isSuperReceiver ? Loc : 
SourceLocation(),
Sel, Method, Loc, Loc, Loc, Args,
Index: clang/lib/Parse/ParseStmt.cpp
===
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -883,8 +883,10 @@
   Stmt *NextDeepest = Case.get();
   if (TopLevelCase.isInvalid())
 TopLevelCase = Case;
-  else
+  else {
+assert(DeepestParsedCaseStmt && "DeepestParsedCaseStmt cannot be 
null");
 Actions.ActOnCaseStmtBody(DeepestParsedCaseStmt, Case.get());
+  }
   DeepestParsedCaseStmt = NextDeepest;
 }
 


Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2709,7 +2709,7 @@
   }
   // Only support _BitInt elements with byte-sized power of 2 NumBits.
   if (CurType->isBitIntType()) {
-unsigned NumBits = CurType->getAs()->getNumBits();
+unsigned NumBits = CurType->casttAs()->getNumBits();
 if (!llvm::isPowerOf2_32(NumBits) || NumBits < 8) {
   Diag(AttrLoc, diag::err_attribute_invalid_bitint_vector_type)
   << (NumBits < 8);
Index: clang/lib/Sema/SemaObjCProperty.cpp
===
--- clang/lib/Sema/SemaObjCProperty.cpp
+++ clang/lib/Sema/SemaObjCProperty.cpp
@@ -1363,10 +1363,9 @@
 if (!Context.hasSameType(PropertyIvarType, IvarType)) {
   if (isa(PropertyIvarType)
   && isa(IvarType))
-compat =
-  Context.canAssignObjCInterfaces(
-  PropertyIvarType->getAs(),
-  IvarType->getAs());
+compat = Context.canAssignObjCInterfaces(
+PropertyIvarType->castAs(),
+IvarType->castAs());
   else {
 compat = (CheckAssignmentConstraints(PropertyIvarLoc, PropertyIvarType,
  IvarType)
Index: clang/lib/Sema/SemaExprObjC.cpp
===
--- clang/lib/Sema/SemaExprObjC.cpp
+++ clang/lib/Sema/SemaExprObjC.cpp
@@ -2438,6 +2438,7 @@
   if (!ReceiverType.isNull())
 receiverTypeInfo = Context.getTrivialTypeSourceInfo(ReceiverType);
 
+  assert(receiverTypeInfo && "receiverTypeInfo cannot be null");
   return BuildClassMessage(receiverTypeInfo, ReceiverType,
   /*SuperLoc=*/isSuperReceiver ? Loc : SourceLocation(),
Sel, Method, Loc, Loc, Loc, Args,
Index: clang/lib/Parse/ParseStmt.cpp
===

[PATCH] D151696: [x86] Remove CPU_SPECIFIC* MACROs and add getManglingForCPU

2023-06-18 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe updated this revision to Diff 532517.
FreddyYe marked an inline comment as done.
FreddyYe added a comment.

Typo refine: OnlyForCPUSpecificDispath -> OnlyForCPUDispatchSpecific


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151696

Files:
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/attr-cpuspecific-avx-abi.c
  clang/test/CodeGen/attr-cpuspecific.c
  llvm/include/llvm/TargetParser/X86TargetParser.def
  llvm/include/llvm/TargetParser/X86TargetParser.h
  llvm/lib/Target/X86/X86.td
  llvm/lib/TargetParser/X86TargetParser.cpp
  llvm/test/CodeGen/X86/cpus-intel.ll

Index: llvm/test/CodeGen/X86/cpus-intel.ll
===
--- llvm/test/CodeGen/X86/cpus-intel.ll
+++ llvm/test/CodeGen/X86/cpus-intel.ll
@@ -6,16 +6,24 @@
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=i586 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium-mmx 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_mmx 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=i686 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentiumpro 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_pro 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium2 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_ii 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium3 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium3m 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_iii 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_iii_no_xmm_regs 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_m 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium-m 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium4 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium4m 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_4 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=yonah 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=prescott 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=pentium_4_sse3 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=lakemont 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=raptorlake 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=meteorlake 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
@@ -26,26 +34,39 @@
 
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=nocona 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=core2 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=core_2_duo_ssse3 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=penryn 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=core_2_duo_sse4_1 2>&1

[PATCH] D151696: [x86] Remove CPU_SPECIFIC* MACROs and add getManglingForCPU

2023-06-18 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe added a comment.

Thanks for @RKSimon 's review, I'd like also to mention that 
https://reviews.llvm.org/D152989 is supposed to be the base commit of here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151696

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


[PATCH] D153008: [RISCV] Allow slash-star comments in instruction operands

2023-06-18 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 added a comment.

- I'd prefer Lex() over equivalent getParser().Lex() because it is shorter.
- Ideally, every change should be tested.
- The tests should be minimal. That is, they should be assembly files passed to 
llvm-mc rather than ll files passed to llc.

I'm not very familiar with RISC-V, so I'll leave further review to code owners.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153008

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


[PATCH] D153236: [NFC] Fix potential dereferencing of nullptr.

2023-06-18 Thread Sindhu Chittireddy via Phabricator via cfe-commits
schittir updated this revision to Diff 532528.
schittir added a comment.

Fix typo


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

https://reviews.llvm.org/D153236

Files:
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Sema/SemaExprObjC.cpp
  clang/lib/Sema/SemaObjCProperty.cpp
  clang/lib/Sema/SemaType.cpp


Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2709,7 +2709,7 @@
   }
   // Only support _BitInt elements with byte-sized power of 2 NumBits.
   if (CurType->isBitIntType()) {
-unsigned NumBits = CurType->getAs()->getNumBits();
+unsigned NumBits = CurType->castAs()->getNumBits();
 if (!llvm::isPowerOf2_32(NumBits) || NumBits < 8) {
   Diag(AttrLoc, diag::err_attribute_invalid_bitint_vector_type)
   << (NumBits < 8);
Index: clang/lib/Sema/SemaObjCProperty.cpp
===
--- clang/lib/Sema/SemaObjCProperty.cpp
+++ clang/lib/Sema/SemaObjCProperty.cpp
@@ -1363,10 +1363,9 @@
 if (!Context.hasSameType(PropertyIvarType, IvarType)) {
   if (isa(PropertyIvarType)
   && isa(IvarType))
-compat =
-  Context.canAssignObjCInterfaces(
-  
PropertyIvarType->getAs(),
-  IvarType->getAs());
+compat = Context.canAssignObjCInterfaces(
+PropertyIvarType->castAs(),
+IvarType->castAs());
   else {
 compat = (CheckAssignmentConstraints(PropertyIvarLoc, PropertyIvarType,
  IvarType)
Index: clang/lib/Sema/SemaExprObjC.cpp
===
--- clang/lib/Sema/SemaExprObjC.cpp
+++ clang/lib/Sema/SemaExprObjC.cpp
@@ -2438,6 +2438,7 @@
   if (!ReceiverType.isNull())
 receiverTypeInfo = Context.getTrivialTypeSourceInfo(ReceiverType);
 
+  assert(receiverTypeInfo && "receiverTypeInfo cannot be null");
   return BuildClassMessage(receiverTypeInfo, ReceiverType,
   /*SuperLoc=*/isSuperReceiver ? Loc : 
SourceLocation(),
Sel, Method, Loc, Loc, Loc, Args,
Index: clang/lib/Parse/ParseStmt.cpp
===
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -883,8 +883,10 @@
   Stmt *NextDeepest = Case.get();
   if (TopLevelCase.isInvalid())
 TopLevelCase = Case;
-  else
+  else {
+assert(DeepestParsedCaseStmt && "DeepestParsedCaseStmt cannot be 
null");
 Actions.ActOnCaseStmtBody(DeepestParsedCaseStmt, Case.get());
+  }
   DeepestParsedCaseStmt = NextDeepest;
 }
 


Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2709,7 +2709,7 @@
   }
   // Only support _BitInt elements with byte-sized power of 2 NumBits.
   if (CurType->isBitIntType()) {
-unsigned NumBits = CurType->getAs()->getNumBits();
+unsigned NumBits = CurType->castAs()->getNumBits();
 if (!llvm::isPowerOf2_32(NumBits) || NumBits < 8) {
   Diag(AttrLoc, diag::err_attribute_invalid_bitint_vector_type)
   << (NumBits < 8);
Index: clang/lib/Sema/SemaObjCProperty.cpp
===
--- clang/lib/Sema/SemaObjCProperty.cpp
+++ clang/lib/Sema/SemaObjCProperty.cpp
@@ -1363,10 +1363,9 @@
 if (!Context.hasSameType(PropertyIvarType, IvarType)) {
   if (isa(PropertyIvarType)
   && isa(IvarType))
-compat =
-  Context.canAssignObjCInterfaces(
-  PropertyIvarType->getAs(),
-  IvarType->getAs());
+compat = Context.canAssignObjCInterfaces(
+PropertyIvarType->castAs(),
+IvarType->castAs());
   else {
 compat = (CheckAssignmentConstraints(PropertyIvarLoc, PropertyIvarType,
  IvarType)
Index: clang/lib/Sema/SemaExprObjC.cpp
===
--- clang/lib/Sema/SemaExprObjC.cpp
+++ clang/lib/Sema/SemaExprObjC.cpp
@@ -2438,6 +2438,7 @@
   if (!ReceiverType.isNull())
 receiverTypeInfo = Context.getTrivialTypeSourceInfo(ReceiverType);
 
+  assert(receiverTypeInfo && "receiverTypeInfo cannot be null");
   return BuildClassMessage(receiverTypeInfo, ReceiverType,
   /*SuperLoc=*/isSuperReceiver ? Loc : SourceLocation(),
Sel, Method, Loc, Loc, Loc, Args,
Index: clang/lib/Parse/ParseStmt.cpp
===
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -883,8 +883,10 @@
   Stmt *NextDeepest = Case.get();
   if (TopLev

[PATCH] D153233: clang: Add __builtin_elementwise_rint and nearbyint

2023-06-18 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added inline comments.



Comment at: clang/docs/LanguageExtensions.rst:656
+  T __builtin_elementwise_nearbyint(T x) round x to the nearest  integer 
value in floating point format,  floating point types
+ rounding halfway according to the 
current current rounding
+ direction. May not raise 
floating-point exceptions. This is

"halfway'" is superfluous here.



Comment at: clang/docs/LanguageExtensions.rst:657
+ rounding halfway according to the 
current current rounding
+ direction. May not raise 
floating-point exceptions. This is
+ treated the same as 
``__builtin_elementwise_rint`` unless

`nearbyint` should not rise only `inexact` exception. Other exceptions, like 
`invalid` are allowed.



Comment at: clang/docs/LanguageExtensions.rst:662
+ T __builtin_elementwise_rint(T x)   round x to the nearest  integer 
value in floating point format,  floating point types
+ rounding halfway cases according 
to the current rounding
+ direction. May raise 
floating-point exceptions. This is treated

"halfway'" is superfluous here.



Comment at: clang/test/CodeGen/strictfp-elementwise-bulitins.cpp:2
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 2
+// RUN: %clang_cc1 -triple x86_64-linux-gnu 
-fexperimental-strict-floating-point -frounding-math 
-ffp-exception-behavior=strict -O2 -emit-llvm -o - %s | FileCheck %s
+

For X86 `-fexperimental-strict-floating-point` is not needed.



Comment at: clang/test/CodeGen/strictfp-elementwise-bulitins.cpp:13-14
+// CHECK-NEXT:[[ADD:%.*]] = tail call <2 x float> 
@llvm.experimental.constrained.fadd.v2f32(<2 x float> [[TMP0]], <2 x float> 
[[TMP1]], metadata !"round.dynamic", metadata !"fpexcept.strict") 
#[[ATTR4:[0-9]+]]
+// CHECK-NEXT:[[TMP2:%.*]] = bitcast <2 x float> [[ADD]] to double
+// CHECK-NEXT:ret double [[TMP2]]
+//

Why vector type is bitcasted to scalar? The function must return <2 x float>, 
no?


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

https://reviews.llvm.org/D153233

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


[PATCH] D152785: [COFF] Support -gsplit-dwarf for COFF on Windows

2023-06-18 Thread Kan Shengchen via Phabricator via cfe-commits
skan accepted this revision.
skan added a comment.
This revision is now accepted and ready to land.

LGTM for the MC part.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152785

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


[PATCH] D152764: [clang-tidy] Reserved-identifier: Improved AllowedIdentifiers option to support regular expressions

2023-06-18 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL accepted this revision.
PiotrZSL added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152764

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


[PATCH] D151397: [3/3][RISCV][POC] Model vxrm in C intrinsics for RVV fixed-point instruction vaadd, vasub

2023-06-18 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 532531.
eopXD added a comment.

Rebase to latest main.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151397

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/lib/Sema/SemaChecking.cpp
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vaadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vaaddu.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vasub.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vasubu.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vaadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vaaddu.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vasub.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vasubu.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vaadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vaaddu.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vasub.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vasubu.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/vaadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/vaaddu.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/vasub.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/vasubu.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vaadd-out-of-range.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vaaddu-out-of-range.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vasub-out-of-range.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vasubu-out-of-range.c
  llvm/include/llvm/IR/IntrinsicsRISCV.td
  llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td
  llvm/test/CodeGen/RISCV/rvv/masked-tama.ll
  llvm/test/CodeGen/RISCV/rvv/masked-tamu.ll
  llvm/test/CodeGen/RISCV/rvv/masked-tuma.ll
  llvm/test/CodeGen/RISCV/rvv/masked-tumu.ll
  llvm/test/CodeGen/RISCV/rvv/vaadd.ll
  llvm/test/CodeGen/RISCV/rvv/vaaddu.ll
  llvm/test/CodeGen/RISCV/rvv/vasub.ll
  llvm/test/CodeGen/RISCV/rvv/vasubu.ll

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


[PATCH] D152879: [RISCV] Model vxrm control for vsmul, vssra, vssrl, vnclip, and vnclipu

2023-06-18 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 532532.
eopXD added a comment.

Rebase to latest main.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152879

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/lib/Sema/SemaChecking.cpp
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vnclip.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vnclipu.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vsmul.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vssra.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vssrl.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vnclip.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vnclipu.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vsmul.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vssra.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vssrl.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vnclip.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vnclipu.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vsmul.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vssra.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vssrl.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/vnclip.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/vnclipu.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/vsmul.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/vssra.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/vssrl.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vnclip-out-of-range.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vnclipu-out-of-range.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vsmul-eew64-overloaded.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vsmul-eew64.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vsmul-out-of-range.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vssra-out-of-range.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vssrl-out-of-range.c
  llvm/include/llvm/IR/IntrinsicsRISCV.td
  llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td
  llvm/test/CodeGen/RISCV/rvv/masked-tama.ll
  llvm/test/CodeGen/RISCV/rvv/masked-tamu.ll
  llvm/test/CodeGen/RISCV/rvv/masked-tuma.ll
  llvm/test/CodeGen/RISCV/rvv/masked-tumu.ll
  llvm/test/CodeGen/RISCV/rvv/mutate-prior-vsetvli-avl.ll
  llvm/test/CodeGen/RISCV/rvv/unmasked-tu.ll
  llvm/test/CodeGen/RISCV/rvv/vnclip.ll
  llvm/test/CodeGen/RISCV/rvv/vnclipu.ll
  llvm/test/CodeGen/RISCV/rvv/vsmul-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vsmul-rv64.ll
  llvm/test/CodeGen/RISCV/rvv/vssra-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vssra-rv64.ll
  llvm/test/CodeGen/RISCV/rvv/vssrl-rv32.ll
  llvm/test/CodeGen/RISCV/rvv/vssrl-rv64.ll

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


[PATCH] D153241: [clang][Diagnostics] Provide source range to invalid casts in const expr

2023-06-18 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, shafik, hazohelet, cjdb.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153241

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/Interp/Interp.cpp
  clang/test/Misc/constexpr-source-ranges.cpp


Index: clang/test/Misc/constexpr-source-ranges.cpp
===
--- clang/test/Misc/constexpr-source-ranges.cpp
+++ clang/test/Misc/constexpr-source-ranges.cpp
@@ -7,3 +7,9 @@
 }
 
 // CHECK: constexpr-source-ranges.cpp:5:3:{5:3-5:10}
+
+
+constexpr int I = 12;
+constexpr const int *P = &I;
+constexpr long L = (long)P;
+// CHECK: constexpr-source-ranges.cpp:14:20:{14:20-14:27}
Index: clang/lib/AST/Interp/Interp.cpp
===
--- clang/lib/AST/Interp/Interp.cpp
+++ clang/lib/AST/Interp/Interp.cpp
@@ -524,7 +524,7 @@
 
   const SourceInfo &E = S.Current->getSource(OpPC);
   S.CCEDiag(E, diag::note_constexpr_invalid_cast)
-  << 2 << S.getLangOpts().CPlusPlus;
+  << 2 << S.getLangOpts().CPlusPlus << S.Current->getRange(OpPC);
   return false;
 }
 
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -13724,7 +13724,7 @@
 
   case CK_PointerToIntegral: {
 CCEDiag(E, diag::note_constexpr_invalid_cast)
-<< 2 << Info.Ctx.getLangOpts().CPlusPlus;
+<< 2 << Info.Ctx.getLangOpts().CPlusPlus << E->getSourceRange();
 
 LValue LV;
 if (!EvaluatePointer(SubExpr, LV, Info))


Index: clang/test/Misc/constexpr-source-ranges.cpp
===
--- clang/test/Misc/constexpr-source-ranges.cpp
+++ clang/test/Misc/constexpr-source-ranges.cpp
@@ -7,3 +7,9 @@
 }
 
 // CHECK: constexpr-source-ranges.cpp:5:3:{5:3-5:10}
+
+
+constexpr int I = 12;
+constexpr const int *P = &I;
+constexpr long L = (long)P;
+// CHECK: constexpr-source-ranges.cpp:14:20:{14:20-14:27}
Index: clang/lib/AST/Interp/Interp.cpp
===
--- clang/lib/AST/Interp/Interp.cpp
+++ clang/lib/AST/Interp/Interp.cpp
@@ -524,7 +524,7 @@
 
   const SourceInfo &E = S.Current->getSource(OpPC);
   S.CCEDiag(E, diag::note_constexpr_invalid_cast)
-  << 2 << S.getLangOpts().CPlusPlus;
+  << 2 << S.getLangOpts().CPlusPlus << S.Current->getRange(OpPC);
   return false;
 }
 
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -13724,7 +13724,7 @@
 
   case CK_PointerToIntegral: {
 CCEDiag(E, diag::note_constexpr_invalid_cast)
-<< 2 << Info.Ctx.getLangOpts().CPlusPlus;
+<< 2 << Info.Ctx.getLangOpts().CPlusPlus << E->getSourceRange();
 
 LValue LV;
 if (!EvaluatePointer(SubExpr, LV, Info))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153132: [clang analysis][NFCI] Preparatory work for D153131.

2023-06-18 Thread Clement Courbet via Phabricator via cfe-commits
courbet added a comment.

> Is this actually required for the subsequent change? I don't see the 
> connection.

In the followup change, we have to check the returns after the enter and exit 
CFG block are computed. We can't analyze the returns as they are seen because , 
because what matters for the returns is the locks that are live at the end of 
the function, not those that are live at the point where the `return` happens.

The `BuildLockset` class only lives for the duration of the analysis of a 
single block, while the `ThreadSafetyAnalyzer` lives for the whole function. So 
return checking is done in the `ThreadSafetyAnalyzer`, so we need the 
check/warn functions to be available here.

From a design perspective I think it might actually make more sens for them to 
be in the analyzer as `warnIfMutexNotHeld` and friends actually inspects quite 
a lot of the `Analyzer` state.




Comment at: clang/lib/Analysis/ThreadSafety.cpp:1541
 class BuildLockset : public ConstStmtVisitor {
+  using VisitorBase = ConstStmtVisitor;
   friend class ThreadSafetyAnalyzer;

aaronpuchert wrote:
> Why the alias? I find this just obfuscates.
I'm using it one more time in the followup patch, but no strong opinion, 
removed.



Comment at: clang/lib/Analysis/ThreadSafety.cpp:1588
 /// of at least the passed in AccessKind.
-void BuildLockset::warnIfMutexNotHeld(const NamedDecl *D, const Expr *Exp,
-  AccessKind AK, Expr *MutexExp,
-  ProtectedOperationKind POK,
-  til::LiteralPtr *Self,
-  SourceLocation Loc) {
+void ThreadSafetyAnalyzer::warnIfMutexNotHeld(
+const FactSet &FSet, const NamedDecl *D, const Expr *Exp, AccessKind AK,

aaronpuchert wrote:
> Hmm, functions of the same class naturally want to be together, but if you 
> move them, it "destroys" the Git history.
Yes, I decided to make review/history tracking esaier by not moving them, but I 
can move them if you want.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153132

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


[PATCH] D153132: [clang analysis][NFCI] Preparatory work for D153131.

2023-06-18 Thread Clement Courbet via Phabricator via cfe-commits
courbet updated this revision to Diff 532534.
courbet added a comment.

remove type alias


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153132

Files:
  clang/lib/Analysis/ThreadSafety.cpp

Index: clang/lib/Analysis/ThreadSafety.cpp
===
--- clang/lib/Analysis/ThreadSafety.cpp
+++ clang/lib/Analysis/ThreadSafety.cpp
@@ -1016,6 +1016,19 @@
 
   BeforeSet *GlobalBeforeSet;
 
+  void warnIfMutexNotHeld(const FactSet &FSet, const NamedDecl *D,
+  const Expr *Exp, AccessKind AK, Expr *MutexExp,
+  ProtectedOperationKind POK, til::LiteralPtr *Self,
+  SourceLocation Loc);
+  void warnIfMutexHeld(const FactSet &FSet, const NamedDecl *D, const Expr *Exp,
+   Expr *MutexExp, til::LiteralPtr *Self,
+   SourceLocation Loc);
+
+  void checkAccess(const FactSet &FSet, const Expr *Exp, AccessKind AK,
+   ProtectedOperationKind POK);
+  void checkPtAccess(const FactSet &FSet, const Expr *Exp, AccessKind AK,
+ ProtectedOperationKind POK);
+
 public:
   ThreadSafetyAnalyzer(ThreadSafetyHandler &H, BeforeSet* Bset)
   : Arena(&Bpa), SxBuilder(Arena), Handler(H), GlobalBeforeSet(Bset) {}
@@ -1535,16 +1548,15 @@
   unsigned CtxIndex;
 
   // helper functions
-  void warnIfMutexNotHeld(const NamedDecl *D, const Expr *Exp, AccessKind AK,
-  Expr *MutexExp, ProtectedOperationKind POK,
-  til::LiteralPtr *Self, SourceLocation Loc);
-  void warnIfMutexHeld(const NamedDecl *D, const Expr *Exp, Expr *MutexExp,
-   til::LiteralPtr *Self, SourceLocation Loc);
 
   void checkAccess(const Expr *Exp, AccessKind AK,
-   ProtectedOperationKind POK = POK_VarAccess);
+   ProtectedOperationKind POK = POK_VarAccess) {
+Analyzer->checkAccess(FSet, Exp, AK, POK);
+  }
   void checkPtAccess(const Expr *Exp, AccessKind AK,
- ProtectedOperationKind POK = POK_VarAccess);
+ ProtectedOperationKind POK = POK_VarAccess) {
+Analyzer->checkPtAccess(FSet, Exp, AK, POK);
+  }
 
   void handleCall(const Expr *Exp, const NamedDecl *D,
   til::LiteralPtr *Self = nullptr,
@@ -1572,17 +1584,14 @@
 
 /// Warn if the LSet does not contain a lock sufficient to protect access
 /// of at least the passed in AccessKind.
-void BuildLockset::warnIfMutexNotHeld(const NamedDecl *D, const Expr *Exp,
-  AccessKind AK, Expr *MutexExp,
-  ProtectedOperationKind POK,
-  til::LiteralPtr *Self,
-  SourceLocation Loc) {
+void ThreadSafetyAnalyzer::warnIfMutexNotHeld(
+const FactSet &FSet, const NamedDecl *D, const Expr *Exp, AccessKind AK,
+Expr *MutexExp, ProtectedOperationKind POK, til::LiteralPtr *Self,
+SourceLocation Loc) {
   LockKind LK = getLockKindFromAccessKind(AK);
-
-  CapabilityExpr Cp =
-  Analyzer->SxBuilder.translateAttrExpr(MutexExp, D, Exp, Self);
+  CapabilityExpr Cp = SxBuilder.translateAttrExpr(MutexExp, D, Exp, Self);
   if (Cp.isInvalid()) {
-warnInvalidLock(Analyzer->Handler, MutexExp, D, Exp, Cp.getKind());
+warnInvalidLock(Handler, MutexExp, D, Exp, Cp.getKind());
 return;
   } else if (Cp.shouldIgnore()) {
 return;
@@ -1590,68 +1599,67 @@
 
   if (Cp.negative()) {
 // Negative capabilities act like locks excluded
-const FactEntry *LDat = FSet.findLock(Analyzer->FactMan, !Cp);
+const FactEntry *LDat = FSet.findLock(FactMan, !Cp);
 if (LDat) {
-  Analyzer->Handler.handleFunExcludesLock(
-  Cp.getKind(), D->getNameAsString(), (!Cp).toString(), Loc);
-  return;
+Handler.handleFunExcludesLock(Cp.getKind(), D->getNameAsString(),
+  (!Cp).toString(), Loc);
+return;
 }
 
 // If this does not refer to a negative capability in the same class,
 // then stop here.
-if (!Analyzer->inCurrentScope(Cp))
-  return;
+if (!inCurrentScope(Cp))
+return;
 
 // Otherwise the negative requirement must be propagated to the caller.
-LDat = FSet.findLock(Analyzer->FactMan, Cp);
+LDat = FSet.findLock(FactMan, Cp);
 if (!LDat) {
-  Analyzer->Handler.handleNegativeNotHeld(D, Cp.toString(), Loc);
+Handler.handleNegativeNotHeld(D, Cp.toString(), Loc);
 }
 return;
   }
 
-  const FactEntry *LDat = FSet.findLockUniv(Analyzer->FactMan, Cp);
+  const FactEntry *LDat = FSet.findLockUniv(FactMan, Cp);
   bool NoError = true;
   if (!LDat) {
 // No exact match found.  Look for a partial match.
-LDat = FSet.findPartialMatch(Analyzer->FactMan, Cp);
+LDat = FSet.findPartialMatch(FactMan, Cp);
 if (L

[PATCH] D153111: [clang][Serialization][RISCV] Increase the number of reserved predefined type IDs

2023-06-18 Thread Zixuan Wu via Phabricator via cfe-commits
zixuan-wu added a comment.

I also caught this issue.


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

https://reviews.llvm.org/D153111

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


[PATCH] D152996: [RISCV][POC] Model frm control for vfadd

2023-06-18 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 532536.
eopXD added a comment.
Herald added a subscriber: qcolombet.

Update code:

- Change value to indicate no rounding mode change from `99` to `7`.
- Add code under `RISCVDAGToDAGISel::performCombineVMergeAndVOps` to deal with 
the extra rounding mode operand
- This patch was originally depending upon D152889 
, the patch is dropped and now this patch 
depends on D152879 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152996

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/include/clang/Basic/riscv_vector_common.td
  clang/include/clang/Support/RISCVVIntrinsicUtils.h
  clang/lib/Sema/SemaRISCVVectorLookup.cpp
  clang/lib/Support/RISCVVIntrinsicUtils.cpp
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vfadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/vfadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/vfadd.c
  
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/vfadd.c
  clang/utils/TableGen/RISCVVEmitter.cpp
  llvm/include/llvm/IR/IntrinsicsRISCV.td
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
  llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
  llvm/lib/Target/RISCV/RISCVInsertReadWriteCSR.cpp
  llvm/lib/Target/RISCV/RISCVInstrFormats.td
  llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td
  llvm/lib/Target/RISCV/RISCVInstrInfoVSDPatterns.td
  llvm/lib/Target/RISCV/RISCVInstrInfoVVLPatterns.td
  llvm/test/CodeGen/RISCV/rvv/alloca-load-store-scalable-struct.ll
  llvm/test/CodeGen/RISCV/rvv/fixed-vectors-fmf.ll
  llvm/test/CodeGen/RISCV/rvv/masked-tama.ll
  llvm/test/CodeGen/RISCV/rvv/masked-tamu.ll
  llvm/test/CodeGen/RISCV/rvv/masked-tuma.ll
  llvm/test/CodeGen/RISCV/rvv/masked-tumu.ll
  llvm/test/CodeGen/RISCV/rvv/rv32-spill-vector-csr.ll
  llvm/test/CodeGen/RISCV/rvv/rv64-spill-vector-csr.ll
  llvm/test/CodeGen/RISCV/rvv/rvv-peephole-vmerge-masked-vops.ll
  llvm/test/CodeGen/RISCV/rvv/unmasked-tu.ll
  llvm/test/CodeGen/RISCV/rvv/vfadd.ll
  llvm/test/CodeGen/RISCV/rvv/vsetvli-insert-crossbb.ll
  llvm/test/CodeGen/RISCV/rvv/vsetvli-insert.ll

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


[PATCH] D153243: [clang-format] Don't finalize #if, #else, #endif, etc.

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

Don't finalize a preprocessor branch directive if it's the first token of an 
annotated line.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153243

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -23106,6 +23106,13 @@
"int* j;\n"
"// clang-format only\n"
"int* k;");
+
+  verifyNoChange("// clang-format off\n"
+ "#if 0\n"
+ "#if SHOULD_STAY_INDENTED\n"
+ " #endif\n"
+ "#endif\n"
+ "// clang-format on");
 }
 
 TEST_F(FormatTest, DoNotCrashOnInvalidInput) {
Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -49,16 +49,8 @@
   unsigned Spaces,
   unsigned StartOfTokenColumn,
   bool IsAligned, bool InPPDirective) {
-  auto PPBranchDirectiveStartsLine = [&Tok] {
-return Tok.is(tok::hash) && !Tok.Previous && Tok.Next &&
-   Tok.Next->isOneOf(tok::pp_if, tok::pp_ifdef, tok::pp_ifndef,
- tok::pp_elif, tok::pp_elifdef, tok::pp_elifndef,
- tok::pp_else, tok::pp_endif);
-  };
-  if ((Tok.Finalized && !PPBranchDirectiveStartsLine()) ||
-  (Tok.MacroCtx && Tok.MacroCtx->Role == MR_ExpandedArg)) {
+  if (Tok.Finalized || (Tok.MacroCtx && Tok.MacroCtx->Role == MR_ExpandedArg))
 return;
-  }
   Tok.setDecision((Newlines > 0) ? FD_Break : FD_Continue);
   Changes.push_back(Change(Tok, /*CreateReplacement=*/true, 
Tok.WhitespaceRange,
Spaces, StartOfTokenColumn, Newlines, "", "",
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1411,8 +1411,16 @@
   NextLine = Joiner.getNextMergedLine(DryRun, IndentTracker);
   RangeMinLevel = UINT_MAX;
 }
-if (!DryRun)
-  markFinalized(TheLine.First);
+if (!DryRun) {
+  auto *Tok = TheLine.First;
+  if (Tok->is(tok::hash) && !Tok->Previous && Tok->Next &&
+  Tok->Next->isOneOf(tok::pp_if, tok::pp_ifdef, tok::pp_ifndef,
+ tok::pp_elif, tok::pp_elifdef, tok::pp_elifndef,
+ tok::pp_else, tok::pp_endif)) {
+Tok = Tok->Next;
+  }
+  markFinalized(Tok);
+}
   }
   PenaltyCache[CacheKey] = Penalty;
   return Penalty;


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -23106,6 +23106,13 @@
"int* j;\n"
"// clang-format only\n"
"int* k;");
+
+  verifyNoChange("// clang-format off\n"
+ "#if 0\n"
+ "#if SHOULD_STAY_INDENTED\n"
+ " #endif\n"
+ "#endif\n"
+ "// clang-format on");
 }
 
 TEST_F(FormatTest, DoNotCrashOnInvalidInput) {
Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -49,16 +49,8 @@
   unsigned Spaces,
   unsigned StartOfTokenColumn,
   bool IsAligned, bool InPPDirective) {
-  auto PPBranchDirectiveStartsLine = [&Tok] {
-return Tok.is(tok::hash) && !Tok.Previous && Tok.Next &&
-   Tok.Next->isOneOf(tok::pp_if, tok::pp_ifdef, tok::pp_ifndef,
- tok::pp_elif, tok::pp_elifdef, tok::pp_elifndef,
- tok::pp_else, tok::pp_endif);
-  };
-  if ((Tok.Finalized && !PPBranchDirectiveStartsLine()) ||
-  (Tok.MacroCtx && Tok.MacroCtx->Role == MR_ExpandedArg)) {
+  if (Tok.Finalized || (Tok.MacroCtx && Tok.MacroCtx->Role == MR_ExpandedArg))
 return;
-  }
   Tok.setDecision((Newlines > 0) ? FD_Break : FD_Continue);
   Changes.push_back(Change(Tok, /*CreateReplacement=*/true, T

[PATCH] D153111: [clang][Serialization][RISCV] Increase the number of reserved predefined type IDs

2023-06-18 Thread Roger Ferrer Ibanez via Phabricator via cfe-commits
rogfer01 added a comment.

Thanks @eopXD. Not sure why you didn't observe the failure. I understand your 
build has `-DLLVM_ENABLE_ASSERTIONS=ON`.

I investigated a bit the libcxx errors flagged by the precommit CI. I can get 
similar (but not exactly the same errors) if the build before this change is 
`-DLLVM_ENABLE_PROJECTS=clang -DLLVM_ENABLE_RUNTIMES=libcxx`, then I apply this 
change and then I run libcxx tests: several precompiled headers become stale 
after this change and would need to be rebuilt. Starting from a clean build 
directory avoids this issue.

I want to do a few more checks locally before committing. Sorry for the delay.


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

https://reviews.llvm.org/D153111

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


[PATCH] D153208: [clang-format] Add InsertNewlineAtEOF to .clang-format files

2023-06-18 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

In D153208#4431239 , 
@HazardyKnusperkeks wrote:

> We also could add a clang-format style, the you wouldn't have to to touch all 
> .clang-format files. ;)

Something like `BasedOnStyle: clang-format`? I like it but feel that it should 
be an undocumented feature. What do you all think?


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

https://reviews.llvm.org/D153208

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