[PATCH] D142296: [clang-format] Fix bugs in parsing C++20 module import statements

2023-01-22 Thread Owen Pan via Phabricator via cfe-commits
owenpan updated this revision to Diff 491135.
owenpan retitled this revision from "[clang-format] Fix a bug in parsing C++20 
import statements" to "[clang-format] Fix bugs in parsing C++20 module import 
statements".
owenpan edited the summary of this revision.
owenpan added a comment.

Also fixed a potential bug in `export import ...`.


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

https://reviews.llvm.org/D142296

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -12810,6 +12810,7 @@
   // But 'import' might also be a regular C++ namespace.
   verifyFormat("import::SomeFunction(aaa,\n"
" a);");
+  verifyFormat("import::Bar foo(val ? 2 : 1);");
 }
 
 //===--===//
@@ -24654,6 +24655,8 @@
   verifyFormat("import", Style);
   verifyFormat("module", Style);
   verifyFormat("export", Style);
+
+  verifyFormat("import = val ? 2 : 1;");
 }
 
 TEST_F(FormatTest, CoroutineForCoawait) {
Index: clang/lib/Format/UnwrappedLineParser.h
===
--- clang/lib/Format/UnwrappedLineParser.h
+++ clang/lib/Format/UnwrappedLineParser.h
@@ -153,7 +153,7 @@
   void parseCaseLabel();
   void parseSwitch();
   void parseNamespace();
-  void parseModuleImport();
+  bool parseModuleImport();
   void parseNew();
   void parseAccessSpecifier();
   bool parseEnum();
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -41,7 +41,7 @@
 
   // Returns the token that would be returned by the next call to
   // getNextToken().
-  virtual FormatToken *peekNextToken() = 0;
+  virtual FormatToken *peekNextToken(bool SkipComment = false) = 0;
 
   // Returns whether we are at the end of the file.
   // This can be different from whether getNextToken() returned an eof token
@@ -169,10 +169,10 @@
 return PreviousTokenSource->getPreviousToken();
   }
 
-  FormatToken *peekNextToken() override {
+  FormatToken *peekNextToken(bool SkipComment) override {
 if (eof())
   return &FakeEOF;
-return PreviousTokenSource->peekNextToken();
+return PreviousTokenSource->peekNextToken(SkipComment);
   }
 
   bool isEOF() override { return PreviousTokenSource->isEOF(); }
@@ -288,8 +288,11 @@
 return Position > 0 ? Tokens[Position - 1] : nullptr;
   }
 
-  FormatToken *peekNextToken() override {
+  FormatToken *peekNextToken(bool SkipComment) override {
 int Next = Position + 1;
+if (SkipComment)
+  while (Tokens[Next]->is(tok::comment))
+++Next;
 LLVM_DEBUG({
   llvm::dbgs() << "Peeking ";
   dbgToken(Next);
@@ -1435,8 +1438,22 @@
   return Tok->Previous && Tok->Previous->isOneOf(tok::l_paren, tok::comma);
 }
 
-void UnwrappedLineParser::parseModuleImport() {
-  nextToken();
+bool UnwrappedLineParser::parseModuleImport() {
+  assert(FormatTok->is(Keywords.kw_import) && "'import' expected");
+
+  auto CanFollowImport = [](auto Token) {
+return Token->Tok.getIdentifierInfo() != nullptr ||
+   Token->isOneOf(tok::colon, tok::less, tok::string_literal);
+  };
+
+  if (!CanFollowImport(Tokens->peekNextToken(/*SkipComment=*/true)))
+return false;
+
+  do {
+nextToken();
+  } while (FormatTok->is(tok::comment));
+  assert(CanFollowImport(FormatTok));
+
   while (!eof()) {
 if (FormatTok->is(tok::colon)) {
   FormatTok->setFinalizedType(TT_ModulePartitionColon);
@@ -1462,6 +1479,7 @@
   }
 
   addUnwrappedLine();
+  return true;
 }
 
 // readTokenWithJavaScriptASI reads the next token and terminates the current
@@ -1682,14 +1700,12 @@
 }
 if (Style.isCpp()) {
   nextToken();
-  if (FormatTok->is(Keywords.kw_import)) {
-parseModuleImport();
-return;
-  }
   if (FormatTok->is(tok::kw_namespace)) {
 parseNamespace();
 return;
   }
+  if (FormatTok->is(Keywords.kw_import) && parseModuleImport())
+return;
 }
 break;
   case tok::kw_inline:
@@ -1726,10 +1742,8 @@
 addUnwrappedLine();
 return;
   }
-  if (Style.isCpp()) {
-parseModuleImport();
+  if (Style.isCpp() && parseModuleImport())
 return;
-  }
 }
 if (Style.isCpp() &&
 FormatTok->isOneOf(Keywords.kw_signals, Keywords.kw_qsignals,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141248: [Clang] [Python] Fix tests when default config file contains -include

2023-01-22 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n added inline comments.



Comment at: clang/bindings/python/tests/cindex/util.py:82
+# our tests.
+os.environ["CLANG_NO_DEFAULT_CONFIG"] = "1"
 

This is essentially an import-time side effect, IMO it could be better to 
instead put the envvar provision in 
`clang/bindings/python/tests/CMakeLists.txt`: the `add_custom_target` there 
already is making use of `env` so should be relatively easy to stuff this there 
too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141248

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


[PATCH] D142296: [clang-format] Fix bugs in parsing C++20 module import statements

2023-01-22 Thread Owen Pan via Phabricator via cfe-commits
owenpan updated this revision to Diff 491137.
owenpan added a comment.

Simplified `parseModuleImport()` a little bit.


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

https://reviews.llvm.org/D142296

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -12810,6 +12810,7 @@
   // But 'import' might also be a regular C++ namespace.
   verifyFormat("import::SomeFunction(aaa,\n"
" a);");
+  verifyFormat("import::Bar foo(val ? 2 : 1);");
 }
 
 //===--===//
@@ -24654,6 +24655,8 @@
   verifyFormat("import", Style);
   verifyFormat("module", Style);
   verifyFormat("export", Style);
+
+  verifyFormat("import = val ? 2 : 1;");
 }
 
 TEST_F(FormatTest, CoroutineForCoawait) {
Index: clang/lib/Format/UnwrappedLineParser.h
===
--- clang/lib/Format/UnwrappedLineParser.h
+++ clang/lib/Format/UnwrappedLineParser.h
@@ -153,7 +153,7 @@
   void parseCaseLabel();
   void parseSwitch();
   void parseNamespace();
-  void parseModuleImport();
+  bool parseModuleImport();
   void parseNew();
   void parseAccessSpecifier();
   bool parseEnum();
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -41,7 +41,7 @@
 
   // Returns the token that would be returned by the next call to
   // getNextToken().
-  virtual FormatToken *peekNextToken() = 0;
+  virtual FormatToken *peekNextToken(bool SkipComment = false) = 0;
 
   // Returns whether we are at the end of the file.
   // This can be different from whether getNextToken() returned an eof token
@@ -169,10 +169,10 @@
 return PreviousTokenSource->getPreviousToken();
   }
 
-  FormatToken *peekNextToken() override {
+  FormatToken *peekNextToken(bool SkipComment) override {
 if (eof())
   return &FakeEOF;
-return PreviousTokenSource->peekNextToken();
+return PreviousTokenSource->peekNextToken(SkipComment);
   }
 
   bool isEOF() override { return PreviousTokenSource->isEOF(); }
@@ -288,8 +288,11 @@
 return Position > 0 ? Tokens[Position - 1] : nullptr;
   }
 
-  FormatToken *peekNextToken() override {
+  FormatToken *peekNextToken(bool SkipComment) override {
 int Next = Position + 1;
+if (SkipComment)
+  while (Tokens[Next]->is(tok::comment))
+++Next;
 LLVM_DEBUG({
   llvm::dbgs() << "Peeking ";
   dbgToken(Next);
@@ -1435,8 +1438,15 @@
   return Tok->Previous && Tok->Previous->isOneOf(tok::l_paren, tok::comma);
 }
 
-void UnwrappedLineParser::parseModuleImport() {
-  nextToken();
+bool UnwrappedLineParser::parseModuleImport() {
+  assert(FormatTok->is(Keywords.kw_import) && "'import' expected");
+
+  if (auto Token = Tokens->peekNextToken(/*SkipComment=*/true);
+  !Token->Tok.getIdentifierInfo() &&
+  !Token->isOneOf(tok::colon, tok::less, tok::string_literal)) {
+return false;
+  }
+
   while (!eof()) {
 if (FormatTok->is(tok::colon)) {
   FormatTok->setFinalizedType(TT_ModulePartitionColon);
@@ -1462,6 +1472,7 @@
   }
 
   addUnwrappedLine();
+  return true;
 }
 
 // readTokenWithJavaScriptASI reads the next token and terminates the current
@@ -1682,14 +1693,12 @@
 }
 if (Style.isCpp()) {
   nextToken();
-  if (FormatTok->is(Keywords.kw_import)) {
-parseModuleImport();
-return;
-  }
   if (FormatTok->is(tok::kw_namespace)) {
 parseNamespace();
 return;
   }
+  if (FormatTok->is(Keywords.kw_import) && parseModuleImport())
+return;
 }
 break;
   case tok::kw_inline:
@@ -1726,10 +1735,8 @@
 addUnwrappedLine();
 return;
   }
-  if (Style.isCpp()) {
-parseModuleImport();
+  if (Style.isCpp() && parseModuleImport())
 return;
-  }
 }
 if (Style.isCpp() &&
 FormatTok->isOneOf(Keywords.kw_signals, Keywords.kw_qsignals,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D142296: [clang-format] Fix bugs in parsing C++20 module import statements

2023-01-22 Thread Owen Pan via Phabricator via cfe-commits
owenpan updated this revision to Diff 491138.
owenpan added a comment.

Added test cases with `import` followed by comments.


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

https://reviews.llvm.org/D142296

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -12810,6 +12810,7 @@
   // But 'import' might also be a regular C++ namespace.
   verifyFormat("import::SomeFunction(aaa,\n"
" a);");
+  verifyFormat("import::Bar foo(val ? 2 : 1);");
 }
 
 //===--===//
@@ -24628,6 +24629,7 @@
   verifyFormat("import foo.bar;", Style);
   verifyFormat("import foo:bar;", Style);
   verifyFormat("import :bar;", Style);
+  verifyFormat("import /* module partition */ :bar;", Style);
   verifyFormat("import ;", Style);
   verifyFormat("import \"header\";", Style);
 
@@ -24654,6 +24656,8 @@
   verifyFormat("import", Style);
   verifyFormat("module", Style);
   verifyFormat("export", Style);
+
+  verifyFormat("import /* not keyword */ = val ? 2 : 1;");
 }
 
 TEST_F(FormatTest, CoroutineForCoawait) {
Index: clang/lib/Format/UnwrappedLineParser.h
===
--- clang/lib/Format/UnwrappedLineParser.h
+++ clang/lib/Format/UnwrappedLineParser.h
@@ -153,7 +153,7 @@
   void parseCaseLabel();
   void parseSwitch();
   void parseNamespace();
-  void parseModuleImport();
+  bool parseModuleImport();
   void parseNew();
   void parseAccessSpecifier();
   bool parseEnum();
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -41,7 +41,7 @@
 
   // Returns the token that would be returned by the next call to
   // getNextToken().
-  virtual FormatToken *peekNextToken() = 0;
+  virtual FormatToken *peekNextToken(bool SkipComment = false) = 0;
 
   // Returns whether we are at the end of the file.
   // This can be different from whether getNextToken() returned an eof token
@@ -169,10 +169,10 @@
 return PreviousTokenSource->getPreviousToken();
   }
 
-  FormatToken *peekNextToken() override {
+  FormatToken *peekNextToken(bool SkipComment) override {
 if (eof())
   return &FakeEOF;
-return PreviousTokenSource->peekNextToken();
+return PreviousTokenSource->peekNextToken(SkipComment);
   }
 
   bool isEOF() override { return PreviousTokenSource->isEOF(); }
@@ -288,8 +288,11 @@
 return Position > 0 ? Tokens[Position - 1] : nullptr;
   }
 
-  FormatToken *peekNextToken() override {
+  FormatToken *peekNextToken(bool SkipComment) override {
 int Next = Position + 1;
+if (SkipComment)
+  while (Tokens[Next]->is(tok::comment))
+++Next;
 LLVM_DEBUG({
   llvm::dbgs() << "Peeking ";
   dbgToken(Next);
@@ -1435,8 +1438,15 @@
   return Tok->Previous && Tok->Previous->isOneOf(tok::l_paren, tok::comma);
 }
 
-void UnwrappedLineParser::parseModuleImport() {
-  nextToken();
+bool UnwrappedLineParser::parseModuleImport() {
+  assert(FormatTok->is(Keywords.kw_import) && "'import' expected");
+
+  if (auto Token = Tokens->peekNextToken(/*SkipComment=*/true);
+  !Token->Tok.getIdentifierInfo() &&
+  !Token->isOneOf(tok::colon, tok::less, tok::string_literal)) {
+return false;
+  }
+
   while (!eof()) {
 if (FormatTok->is(tok::colon)) {
   FormatTok->setFinalizedType(TT_ModulePartitionColon);
@@ -1462,6 +1472,7 @@
   }
 
   addUnwrappedLine();
+  return true;
 }
 
 // readTokenWithJavaScriptASI reads the next token and terminates the current
@@ -1682,14 +1693,12 @@
 }
 if (Style.isCpp()) {
   nextToken();
-  if (FormatTok->is(Keywords.kw_import)) {
-parseModuleImport();
-return;
-  }
   if (FormatTok->is(tok::kw_namespace)) {
 parseNamespace();
 return;
   }
+  if (FormatTok->is(Keywords.kw_import) && parseModuleImport())
+return;
 }
 break;
   case tok::kw_inline:
@@ -1726,10 +1735,8 @@
 addUnwrappedLine();
 return;
   }
-  if (Style.isCpp()) {
-parseModuleImport();
+  if (Style.isCpp() && parseModuleImport())
 return;
-  }
 }
 if (Style.isCpp() &&
 FormatTok->isOneOf(Keywords.kw_signals, Keywords.kw_qsignals,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 53a1314 - [C++20][Modules] Fix named module import diagnostics.

2023-01-22 Thread Iain Sandoe via cfe-commits

Author: Iain Sandoe
Date: 2023-01-22T10:22:36Z
New Revision: 53a1314ed1b5021822071d3c7a751a5ec52619b7

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

LOG: [C++20][Modules] Fix named module import diagnostics.

We have been incorrectly disallowing imports of named modules in the
global and private module fragments.

This addresses: https://github.com/llvm/llvm-project/issues/59688

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

Added: 
clang/test/Modules/cxx20-import-diagnostics-b.cpp

Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Parse/Parser.cpp
clang/lib/Sema/SemaModule.cpp
clang/test/Modules/cxx20-import-diagnostics-a.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 7fbd8ef7e229e..3e3fb2b0cc56d 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3146,12 +3146,15 @@ class Sema final {
   /// fragments and imports.  If we are not parsing a C++20 TU, or we find
   /// an error in state transition, the state is set to NotACXX20Module.
   enum class ModuleImportState {
-FirstDecl,   ///< Parsing the first decl in a TU.
-GlobalFragment,  ///< after 'module;' but before 'module X;'
-ImportAllowed,   ///< after 'module X;' but before any non-import decl.
-ImportFinished,  ///< after any non-import decl.
-PrivateFragment, ///< after 'module :private;'.
-NotACXX20Module  ///< Not a C++20 TU, or an invalid state was found.
+FirstDecl,  ///< Parsing the first decl in a TU.
+GlobalFragment, ///< after 'module;' but before 'module X;'
+ImportAllowed,  ///< after 'module X;' but before any non-import decl.
+ImportFinished, ///< after any non-import decl.
+PrivateFragmentImportAllowed,  ///< after 'module :private;' but before any
+   ///< non-import decl.
+PrivateFragmentImportFinished, ///< after 'module :private;' but a
+   ///< non-import decl has already been seen.
+NotACXX20Module ///< Not a C++20 TU, or an invalid state was found.
   };
 
 private:

diff  --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 104836aca4a94..6db3dc3156fdf 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -750,6 +750,10 @@ bool Parser::ParseTopLevelDecl(DeclGroupPtrTy &Result,
 else if (ImportState == Sema::ModuleImportState::ImportAllowed)
   // Non-imports disallow further imports.
   ImportState = Sema::ModuleImportState::ImportFinished;
+else if (ImportState ==
+ Sema::ModuleImportState::PrivateFragmentImportAllowed)
+  // Non-imports disallow further imports.
+  ImportState = Sema::ModuleImportState::PrivateFragmentImportFinished;
   }
   return false;
 }
@@ -2427,7 +2431,9 @@ Parser::ParseModuleDecl(Sema::ModuleImportState 
&ImportState) {
 SourceLocation PrivateLoc = ConsumeToken();
 DiagnoseAndSkipCXX11Attributes();
 ExpectAndConsumeSemi(diag::err_private_module_fragment_expected_semi);
-ImportState = Sema::ModuleImportState::PrivateFragment;
+ImportState = ImportState == Sema::ModuleImportState::ImportAllowed
+  ? Sema::ModuleImportState::PrivateFragmentImportAllowed
+  : Sema::ModuleImportState::PrivateFragmentImportFinished;
 return Actions.ActOnPrivateModuleFragmentDecl(ModuleLoc, PrivateLoc);
   }
 
@@ -2544,23 +2550,28 @@ Decl *Parser::ParseModuleImport(SourceLocation AtLoc,
   SeenError = false;
 break;
   case Sema::ModuleImportState::GlobalFragment:
-// We can only have pre-processor directives in the global module
-// fragment.  We cannot import a named modules here, however we have a
-// header unit import.
-if (!HeaderUnit || HeaderUnit->Kind != 
Module::ModuleKind::ModuleHeaderUnit)
-  Diag(ImportLoc, diag::err_import_in_wrong_fragment) << IsPartition << 0;
+  case Sema::ModuleImportState::PrivateFragmentImportAllowed:
+// We can only have pre-processor directives in the global module fragment
+// which allows pp-import, but not of a partition (since the global module
+// does not have partitions).
+// We cannot import a partition into a private module fragment, since
+// [module.private.frag]/1 disallows private module fragments in a multi-
+// TU module.
+if (IsPartition || (HeaderUnit && HeaderUnit->Kind !=
+  
Module::ModuleKind::ModuleHeaderUnit))
+  Diag(ImportLoc, diag::err_import_in_wrong_fragment)
+  << IsPartition
+  << (ImportState == Sema::ModuleImportState::GlobalFragment ? 0 : 1);
 else
   SeenError = false;
 break;
   case Sema::ModuleImportState::ImportFinished

[PATCH] D140927: [C++20][Modules] Fix named module import diagnostics.

2023-01-22 Thread Iain Sandoe 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 rG53a1314ed1b5: [C++20][Modules] Fix named module import 
diagnostics. (authored by iains).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140927

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/SemaModule.cpp
  clang/test/Modules/cxx20-import-diagnostics-a.cpp
  clang/test/Modules/cxx20-import-diagnostics-b.cpp

Index: clang/test/Modules/cxx20-import-diagnostics-b.cpp
===
--- /dev/null
+++ clang/test/Modules/cxx20-import-diagnostics-b.cpp
@@ -0,0 +1,61 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface  %t/a.cpp -o %t/a.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface  %t/c.cpp \
+// RUN: -fmodule-file=%t/a.pcm -o %t/c.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface  %t/d.cpp \
+// RUN: -fmodule-file=%t/a.pcm -o %t/d.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface  %t/e.cpp \
+// RUN: -fmodule-file=%t/a.pcm -o %t/e.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface  %t/a-part.cpp \
+// RUN: -o %t/a-part.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface  %t/f.cpp \
+// RUN: -fmodule-file=%t/a.pcm -o %t/f.pcm -verify
+
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface  %t/g.cpp \
+// RUN: -fmodule-file=%t/a.pcm -o %t/g.pcm -verify
+
+//--- a.cpp
+export module a;
+
+//--- b.hpp
+import a;
+
+//--- c.cpp
+module;
+#include "b.hpp"
+export module c;
+
+//--- d.cpp
+module;
+import a;
+
+export module d;
+
+//--- e.cpp
+export module e;
+
+module :private;
+import a;
+
+//--- a-part.cpp
+export module a:part;
+
+//--- f.cpp
+module;
+import :part ; // expected-error {{module partition imports cannot be in the global module fragment}}
+
+export module f;
+
+//--- g.cpp
+
+export module g;
+module :private;
+import :part; // expected-error {{module partition imports cannot be in the private module fragment}}
Index: clang/test/Modules/cxx20-import-diagnostics-a.cpp
===
--- clang/test/Modules/cxx20-import-diagnostics-a.cpp
+++ clang/test/Modules/cxx20-import-diagnostics-a.cpp
@@ -95,14 +95,13 @@
 //--- import-diags-tu7.cpp
 
 module;
-// We can only have preprocessor directives here, which permits an include-
-// translated header unit.  However those are identified specifically by the
-// preprocessor; non-preprocessed user code should not contain an 'import' here.
-import B; // expected-error {{module imports cannot be in the global module fragment}}
-
+// We can only have preprocessor directives here, which permits
+// header units (include-translated or not) and named modules.
+import B;
 export module D;
 
 int delta ();
+// expected-no-diagnostics
 
 //--- import-diags-tu8.cpp
 
@@ -112,7 +111,7 @@
 
 module :private;
 
-import B; // expected-error {{module imports cannot be in the private module fragment}}
+import B; // expected-error {{imports must immediately follow the module declaration}}
 
 //--- import-diags-tu9.cpp
 
Index: clang/lib/Sema/SemaModule.cpp
===
--- clang/lib/Sema/SemaModule.cpp
+++ clang/lib/Sema/SemaModule.cpp
@@ -591,9 +591,6 @@
  (ModuleScopes.back().ModuleInterface ||
   (getLangOpts().CPlusPlusModules &&
ModuleScopes.back().Module->isGlobalModule( {
-assert((!ModuleScopes.back().Module->isGlobalModule() ||
-Mod->Kind == Module::ModuleKind::ModuleHeaderUnit) &&
-   "should only be importing a header unit into the GMF");
 // Re-export the module if the imported module is exported.
 // Note that we don't need to add re-exported module to Imports field
 // since `Exports` implies the module is imported already.
Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -750,6 +750,10 @@
 else if (ImportState == Sema::ModuleImportState::ImportAllowed)
   // Non-imports disallow further imports.
   ImportState = Sema::ModuleImportState::ImportFinished;
+else if (ImportState ==
+ Sema::ModuleImportState::PrivateFragmentImportAllowed)
+  // Non-imports disallow further imports.
+  ImportState = Sema::ModuleImportState::PrivateFragmentImportFinished;
   }
   return false;
 }
@@ -2427,7 +2431,9 @@
 SourceLocation PrivateLoc = ConsumeToken();
 DiagnoseAndSkipCXX11Attributes();
 ExpectAndConsumeSemi(diag::err_private_module_fragment_expected_semi);
-ImportState = Sema::ModuleImportState::PrivateFragment;
+ImportState = ImportState == Sema::ModuleImportState::ImportAllowe

[clang] dadfc6b - [clang-format][NFC] Set LineEnding to LF in config files

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

Author: Owen Pan
Date: 2023-01-22T02:53:06-08:00
New Revision: dadfc6b38b00ff6e7c243ccc834f06d794a32b59

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

LOG: [clang-format][NFC] Set LineEnding to LF in config files

To prevent \r\n line endings from getting into the source files.

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

Added: 


Modified: 
clang/include/clang/Format/.clang-format
clang/lib/Format/.clang-format
clang/unittests/Format/.clang-format

Removed: 




diff  --git a/clang/include/clang/Format/.clang-format 
b/clang/include/clang/Format/.clang-format
index 0e362770f3537..60f4950c01a59 100644
--- a/clang/include/clang/Format/.clang-format
+++ b/clang/include/clang/Format/.clang-format
@@ -1,3 +1,4 @@
 BasedOnStyle: LLVM
 InsertBraces: true
+LineEnding: LF
 RemoveBracesLLVM: true

diff  --git a/clang/lib/Format/.clang-format b/clang/lib/Format/.clang-format
index 0e362770f3537..60f4950c01a59 100644
--- a/clang/lib/Format/.clang-format
+++ b/clang/lib/Format/.clang-format
@@ -1,3 +1,4 @@
 BasedOnStyle: LLVM
 InsertBraces: true
+LineEnding: LF
 RemoveBracesLLVM: true

diff  --git a/clang/unittests/Format/.clang-format 
b/clang/unittests/Format/.clang-format
index 0e362770f3537..60f4950c01a59 100644
--- a/clang/unittests/Format/.clang-format
+++ b/clang/unittests/Format/.clang-format
@@ -1,3 +1,4 @@
 BasedOnStyle: LLVM
 InsertBraces: true
+LineEnding: LF
 RemoveBracesLLVM: true



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


[PATCH] D141098: [clang-format][NFC] Set LineEnding to LF in config files

2023-01-22 Thread Owen Pan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdadfc6b38b00: [clang-format][NFC] Set LineEnding to LF in 
config files (authored by owenpan).

Changed prior to commit:
  https://reviews.llvm.org/D141098?vs=486708&id=491142#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141098

Files:
  clang/include/clang/Format/.clang-format
  clang/lib/Format/.clang-format
  clang/unittests/Format/.clang-format


Index: clang/unittests/Format/.clang-format
===
--- clang/unittests/Format/.clang-format
+++ clang/unittests/Format/.clang-format
@@ -1,3 +1,4 @@
 BasedOnStyle: LLVM
 InsertBraces: true
+LineEnding: LF
 RemoveBracesLLVM: true
Index: clang/lib/Format/.clang-format
===
--- clang/lib/Format/.clang-format
+++ clang/lib/Format/.clang-format
@@ -1,3 +1,4 @@
 BasedOnStyle: LLVM
 InsertBraces: true
+LineEnding: LF
 RemoveBracesLLVM: true
Index: clang/include/clang/Format/.clang-format
===
--- clang/include/clang/Format/.clang-format
+++ clang/include/clang/Format/.clang-format
@@ -1,3 +1,4 @@
 BasedOnStyle: LLVM
 InsertBraces: true
+LineEnding: LF
 RemoveBracesLLVM: true


Index: clang/unittests/Format/.clang-format
===
--- clang/unittests/Format/.clang-format
+++ clang/unittests/Format/.clang-format
@@ -1,3 +1,4 @@
 BasedOnStyle: LLVM
 InsertBraces: true
+LineEnding: LF
 RemoveBracesLLVM: true
Index: clang/lib/Format/.clang-format
===
--- clang/lib/Format/.clang-format
+++ clang/lib/Format/.clang-format
@@ -1,3 +1,4 @@
 BasedOnStyle: LLVM
 InsertBraces: true
+LineEnding: LF
 RemoveBracesLLVM: true
Index: clang/include/clang/Format/.clang-format
===
--- clang/include/clang/Format/.clang-format
+++ clang/include/clang/Format/.clang-format
@@ -1,3 +1,4 @@
 BasedOnStyle: LLVM
 InsertBraces: true
+LineEnding: LF
 RemoveBracesLLVM: true
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a0dab49 - [clang-format][NFC] Add .clang-format to clang/tools/clang-format/

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

Author: Owen Pan
Date: 2023-01-22T02:59:23-08:00
New Revision: a0dab49508e377bdf1ad7af314e16a8a037bc589

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

LOG: [clang-format][NFC] Add .clang-format to clang/tools/clang-format/

And reformat ClangFormat.cpp in the directory.

Added: 
clang/tools/clang-format/.clang-format

Modified: 
clang/tools/clang-format/ClangFormat.cpp

Removed: 




diff  --git a/clang/tools/clang-format/.clang-format 
b/clang/tools/clang-format/.clang-format
new file mode 100644
index 0..60f4950c01a59
--- /dev/null
+++ b/clang/tools/clang-format/.clang-format
@@ -0,0 +1,4 @@
+BasedOnStyle: LLVM
+InsertBraces: true
+LineEnding: LF
+RemoveBracesLLVM: true

diff  --git a/clang/tools/clang-format/ClangFormat.cpp 
b/clang/tools/clang-format/ClangFormat.cpp
index 9e8b881c8fafe..dab8a7f2f8c57 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -128,8 +128,7 @@ static cl::opt QualifierAlignment(
 static cl::opt Files(
 "files",
 cl::desc("A file containing a list of files to process, one per line."),
-cl::value_desc("filename"),
-cl::init(""), cl::cat(ClangFormatCategory));
+cl::value_desc("filename"), cl::init(""), cl::cat(ClangFormatCategory));
 
 static cl::opt
 Verbose("verbose", cl::desc("If set, shows the list of processed files"),



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


[PATCH] D141000: [clang-tidy] Introduce HeaderFileExtensions and ImplementationFileExtensions options

2023-01-22 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

@njames93 Let me know if you are happy with the patch, I'd like to land before 
24th of January :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141000

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


[PATCH] D142304: [Clang] Fix a Wbitfield-enum-conversion warning in DirectoryLookup.h

2023-01-22 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta created this revision.
xgupta added reviewers: aaron.ballman, fahadnayyar.
Herald added a project: All.
xgupta requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

When compiling clang/Lex/DirectoryLookup.h with option 
-Wbitfield-enum-conversion, we get the following warning:

DirectoryLookup.h:77:17: warning:

  bit-field 'DirCharacteristic' is not wide enough to store all enumerators of
  'CharacteristicKind' [-Wbitfield-enum-conversion]
  : u(Map), DirCharacteristic(DT), LookupType(LT_HeaderMap),

DirCharacteristic is a bitfield with 2 bits (4 values)

  /// DirCharacteristic - The type of directory this is: this is an instance of
  /// SrcMgr::CharacteristicKind.
  unsigned DirCharacteristic : 2;

Whereas SrcMgr::CharacterKind is an enum with 5 values:
enum CharacteristicKind {

  C_User,
  C_System,
  C_ExternCSystem,
  C_User_ModuleMap,
  C_System_ModuleMap

};

Solution is to increase DirCharacteristic bitfield from 2 to 3.
Patch by Dimitri van Heesch


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142304

Files:
  clang/include/clang/Lex/DirectoryLookup.h


Index: clang/include/clang/Lex/DirectoryLookup.h
===
--- clang/include/clang/Lex/DirectoryLookup.h
+++ clang/include/clang/Lex/DirectoryLookup.h
@@ -50,7 +50,7 @@
 
   /// DirCharacteristic - The type of directory this is: this is an instance of
   /// SrcMgr::CharacteristicKind.
-  unsigned DirCharacteristic : 2;
+  unsigned DirCharacteristic : 3;
 
   /// LookupType - This indicates whether this DirectoryLookup object is a
   /// normal directory, a framework, or a headermap.


Index: clang/include/clang/Lex/DirectoryLookup.h
===
--- clang/include/clang/Lex/DirectoryLookup.h
+++ clang/include/clang/Lex/DirectoryLookup.h
@@ -50,7 +50,7 @@
 
   /// DirCharacteristic - The type of directory this is: this is an instance of
   /// SrcMgr::CharacteristicKind.
-  unsigned DirCharacteristic : 2;
+  unsigned DirCharacteristic : 3;
 
   /// LookupType - This indicates whether this DirectoryLookup object is a
   /// normal directory, a framework, or a headermap.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D142297: [Clang][OpenMP] Find the type `omp_allocator_handle_t` from identifier table

2023-01-22 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/test/OpenMP/target_uses_allocators.c:108
 // CHECK-NEXT: store i32 %[[#R1]], ptr %.x..void.addr, align 4
-// CHECK-NEXT: call void @__kmpc_free(i32 %[[#R0]], ptr %.x..void.addr, ptr 
inttoptr (i64 8 to ptr))
\ No newline at end of file
+// CHECK-NEXT: call void @__kmpc_free(i32 %[[#R0]], ptr %.x..void.addr, ptr 
inttoptr (i64 8 to ptr))

Would be good to have a test that shows the difference.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142297

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


[PATCH] D142007: [NFC] Fix "form/from" typos

2023-01-22 Thread Piotr Fusik via Phabricator via cfe-commits
pfusik added a comment.

@ldionne Can you check it in?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142007

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


[PATCH] D141000: [clang-tidy] Introduce HeaderFileExtensions and ImplementationFileExtensions options

2023-01-22 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

D142123  also cries for it :-) Somehow I was 
not able to make comments there :-(


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141000

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


[clang] c8d16bf - [clang][doc] Fixes formatting of a text block.

2023-01-22 Thread Mark de Wever via cfe-commits

Author: Mark de Wever
Date: 2023-01-22T16:21:11+01:00
New Revision: c8d16bf3048305876fe600a598a610dfedcab1ee

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

LOG: [clang][doc] Fixes formatting of a text block.

Added: 


Modified: 
clang/docs/StandardCPlusPlusModules.rst

Removed: 




diff  --git a/clang/docs/StandardCPlusPlusModules.rst 
b/clang/docs/StandardCPlusPlusModules.rst
index 1010948ae91b3..44762fa6b3153 100644
--- a/clang/docs/StandardCPlusPlusModules.rst
+++ b/clang/docs/StandardCPlusPlusModules.rst
@@ -295,7 +295,7 @@ Module name requirement
 
 [module.unit]p1 says:
 
-::
+.. code-block:: text
 
   All module-names either beginning with an identifier consisting of std 
followed by zero
   or more digits or containing a reserved identifier ([lex.name]) are reserved 
and shall not



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


[PATCH] D141000: [clang-tidy] Introduce HeaderFileExtensions and ImplementationFileExtensions options

2023-01-22 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

In D141000#4071793 , @Eugene.Zelenko 
wrote:

> D142123  also cries for it :-) Somehow I 
> was not able to make comments there :-(

Yep, one more reason to get this in asap :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141000

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


[PATCH] D138655: [clang-tidy] Fix `cppcoreguidelines-init-variables` for invalid vardecl

2023-01-22 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp accepted this revision.
carlosgalvezp added a comment.
This revision is now accepted and ready to land.

LGTM, thanks for the fix!


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

https://reviews.llvm.org/D138655

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


[PATCH] D140434: readability-const-return-type: don't diagnose a template function returning T, even if sometimes instantiated with e.g. T = const int.

2023-01-22 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

In D140434#4053053 , @suertreus wrote:

> Thanks for reviewing.
>
> I don't have commit access; can someone who does please do the thing?

@suertreus I can help you land the patch, what user name and email should I use 
for attribution?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140434

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


[PATCH] D141133: [clang-tidy] Implement CppCoreGuideline F.54

2023-01-22 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp requested changes to this revision.
carlosgalvezp added inline comments.
This revision now requires changes to proceed.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.cpp:19
+
+namespace clang {
+namespace tidy {

We recently switched to using C++17 nested namespaces for all the clang-tidy 
folder, please update to keep it consistent.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141133

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


[PATCH] D142123: [clang-tidy] Add check to suggest use of #pragma once

2023-01-22 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

Please note, `HeaderFileExtensions` is becoming a global option in this patch 
to avoid duplication, which will land in the next 2 days.
https://reviews.llvm.org/D141000

Therefore you'll need to update the patch based on that.


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

https://reviews.llvm.org/D142123

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


[PATCH] D141133: [clang-tidy] Implement CppCoreGuideline F.54

2023-01-22 Thread Chris Cotter via Phabricator via cfe-commits
ccotter updated this revision to Diff 491165.
ccotter added a comment.

- Use nested namespace


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141133

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.h
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-capture-default-when-capturing-this.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-capture-default-when-capturing-this.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-capture-default-when-capturing-this.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-capture-default-when-capturing-this.cpp
@@ -0,0 +1,92 @@
+// RUN: %check_clang_tidy -std=c++11-or-later %s cppcoreguidelines-avoid-capture-default-when-capturing-this %t
+
+struct Obj {
+  void lambdas_that_warn_default_capture_copy() {
+int local{};
+int local2{};
+
+auto explicit_this_capture = [=, this]() { };
+// CHECK-MESSAGES: :[[@LINE-1]]:35: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: auto explicit_this_capture = [this]() { };
+
+auto explicit_this_capture_locals1 = [=, this]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:43: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: auto explicit_this_capture_locals1 = [local, this]() { return (local+x) > 10; };
+
+auto explicit_this_capture_locals2 = [=, this]() { return (local+local2) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:43: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: auto explicit_this_capture_locals2 = [local, local2, this]() { return (local+local2) > 10; };
+
+auto explicit_this_capture_local_ref = [=, this, &local]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:45: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: auto explicit_this_capture_local_ref = [this, &local]() { return (local+x) > 10; };
+
+auto explicit_this_capture_local_ref2 = [=, &local, this]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:46: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: auto explicit_this_capture_local_ref2 = [&local, this]() { return (local+x) > 10; };
+
+auto explicit_this_capture_local_ref3 = [=, &local, this, &local2]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:46: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: auto explicit_this_capture_local_ref3 = [&local, this, &local2]() { return (local+x) > 10; };
+
+auto explicit_this_capture_local_ref4 = [=, &local, &local2, this]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:46: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: auto explicit_this_capture_local_ref4 = [&local, &local2, this]() { return (local+x) > 10; };
+
+auto explicit_this_capture_local_ref_extra_whitespace = [=, &  local, &local2, this]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:62: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: auto explicit_this_capture_local_ref_extra_whitespace = [&  local, &local2, this]() { return (local+x) > 10; };
+
+auto explicit_this_capture_local_ref_with_comment = [=, & /* byref */ local, &local2, this]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:58: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: auto explicit_this_capture_local_ref_with_comment = [& /* byref */ local, &local2, this]() { return (local+x) > 10; };
+
+auto implicit_this_capture = [=]() { return x > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:35: w

[PATCH] D141133: [clang-tidy] Implement CppCoreGuideline F.54

2023-01-22 Thread Chris Cotter via Phabricator via cfe-commits
ccotter marked an inline comment as done.
ccotter added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.cpp:19
+
+namespace clang {
+namespace tidy {

carlosgalvezp wrote:
> We recently switched to using C++17 nested namespaces for all the clang-tidy 
> folder, please update to keep it consistent.
Just curious - I noticed the clang-tidy headers do not use nested namespaces as 
part of the recent switch. Are the headers slated to be updated too?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141133

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


[PATCH] D141133: [clang-tidy] Implement CppCoreGuideline F.54

2023-01-22 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.h:41-43
+} // namespace cppcoreguidelines
+} // namespace tidy
+} // namespace clang

Forgot to comment but you'll need it here too :) 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141133

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


[PATCH] D141133: [clang-tidy] Implement CppCoreGuideline F.54

2023-01-22 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.cpp:19
+
+namespace clang {
+namespace tidy {

ccotter wrote:
> carlosgalvezp wrote:
> > We recently switched to using C++17 nested namespaces for all the 
> > clang-tidy folder, please update to keep it consistent.
> Just curious - I noticed the clang-tidy headers do not use nested namespaces 
> as part of the recent switch. Are the headers slated to be updated too?
Oh crap, I must have missed to add the `header-filter` option when applying the 
change, it should apply to headers as well! Will fix in a separate patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141133

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


[PATCH] D141133: [clang-tidy] Implement CppCoreGuideline F.54

2023-01-22 Thread Chris Cotter via Phabricator via cfe-commits
ccotter updated this revision to Diff 491171.
ccotter marked an inline comment as done.
ccotter added a comment.

- Use nested namespace in header too;


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141133

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidCaptureDefaultWhenCapturingThisCheck.h
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-capture-default-when-capturing-this.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-capture-default-when-capturing-this.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-capture-default-when-capturing-this.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-capture-default-when-capturing-this.cpp
@@ -0,0 +1,92 @@
+// RUN: %check_clang_tidy -std=c++11-or-later %s cppcoreguidelines-avoid-capture-default-when-capturing-this %t
+
+struct Obj {
+  void lambdas_that_warn_default_capture_copy() {
+int local{};
+int local2{};
+
+auto explicit_this_capture = [=, this]() { };
+// CHECK-MESSAGES: :[[@LINE-1]]:35: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: auto explicit_this_capture = [this]() { };
+
+auto explicit_this_capture_locals1 = [=, this]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:43: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: auto explicit_this_capture_locals1 = [local, this]() { return (local+x) > 10; };
+
+auto explicit_this_capture_locals2 = [=, this]() { return (local+local2) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:43: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: auto explicit_this_capture_locals2 = [local, local2, this]() { return (local+local2) > 10; };
+
+auto explicit_this_capture_local_ref = [=, this, &local]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:45: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: auto explicit_this_capture_local_ref = [this, &local]() { return (local+x) > 10; };
+
+auto explicit_this_capture_local_ref2 = [=, &local, this]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:46: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: auto explicit_this_capture_local_ref2 = [&local, this]() { return (local+x) > 10; };
+
+auto explicit_this_capture_local_ref3 = [=, &local, this, &local2]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:46: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: auto explicit_this_capture_local_ref3 = [&local, this, &local2]() { return (local+x) > 10; };
+
+auto explicit_this_capture_local_ref4 = [=, &local, &local2, this]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:46: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: auto explicit_this_capture_local_ref4 = [&local, &local2, this]() { return (local+x) > 10; };
+
+auto explicit_this_capture_local_ref_extra_whitespace = [=, &  local, &local2, this]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:62: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: auto explicit_this_capture_local_ref_extra_whitespace = [&  local, &local2, this]() { return (local+x) > 10; };
+
+auto explicit_this_capture_local_ref_with_comment = [=, & /* byref */ local, &local2, this]() { return (local+x) > 10; };
+// CHECK-MESSAGES: :[[@LINE-1]]:58: warning: lambdas that capture 'this' should not specify a capture default [cppcoreguidelines-avoid-capture-default-when-capturing-this]
+// CHECK-FIXES: auto explicit_this_capture_local_ref_with_comment = [& /* byref */ local, &local2, this]() { return (local+x) > 10; };
+
+auto implicit_this_capture = [=]() { ret

[PATCH] D141787: [clang-tidy] fix a false positive of `modernize-concat-nested-namespaces`

2023-01-22 Thread Vincent Hong via Phabricator via cfe-commits
v1nh1shungry added a comment.

Ping? @njames93




Comment at: 
clang-tools-extra/test/clang-tidy/checkers/modernize/concat-nested-namespaces.cpp:173
+namespace n48 {
+// CHECK-MESSAGES-DAG: :[[@LINE-2]]:1: warning: nested namespaces can be 
concatenated [modernize-concat-nested-namespaces]
+// CHECK-FIXES: namespace n47::n48

v1nh1shungry wrote:
> njames93 wrote:
> > Is `CHECK-MESSAGES-DAG` needed here, why does it fail if this is omitted?
> Hmm, doesn't `CHECK-MESSAGES-DAG` means to check whether there is a message? 
> (I referred to the tests above.)
> 
> If it's other cases, maybe it's due to 
> https://github.com/llvm/llvm-project/issues/60051.
> 
> I'm not sure I understand what you mean, sorry!
> Hmm, doesn't `CHECK-MESSAGES-DAG` means to check whether there is a message? 
> (I referred to the tests above.)
> 
> If it's other cases, maybe it's due to 
> https://github.com/llvm/llvm-project/issues/60051.
> 
> I'm not sure I understand what you mean, sorry!

I think I understand now. You mean the whole test doesn't fail even without 
this `CHECK-MESSAGES-DAG`, right?

If so, this `CHECK-MESSAGES-DAG` is needed. I think the reason that the test 
doesn't fail without it is https://github.com/llvm/llvm-project/issues/60051. 
The check isn't applied correctly before I make any code changes, you can have 
a play with https://godbolt.org/z/nc34shM8W. But I think the problem isn't 
related to the check itself because when I apply this check through clangd's 
code action it produces correct codes as I mentioned in the GitHub issue.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141787

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


[PATCH] D142307: [clang-tidy][NFC] Use C++17 nested namespaces in clang-tidy headers

2023-01-22 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko accepted this revision.
Eugene.Zelenko added a comment.
This revision is now accepted and ready to land.

Looks OK for me, but please fix small formatting issues. Will be good idea to 
await for other eyes.




Comment at: clang-tools-extra/clang-tidy/utils/FixItHintUtils.h:47
   QualifierPolicy CP = QualifierPolicy::Left);
-} // namespace fixit
-} // namespace utils
-} // namespace tidy
-} // namespace clang
+} // namespace clang::tidy::utils::fixit
 

Please separate with newline.



Comment at: clang-tools-extra/clang-tidy/utils/IncludeInserter.h:19
 namespace clang {
 class Preprocessor;
+namespace tidy::utils {

Ditto.



Comment at: clang-tools-extra/clang-tidy/utils/IncludeSorter.h:75
 };
-} // namespace tidy
-} // namespace clang
+} // namespace clang::tidy
 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_INCLUDESORTER_H

Ditto,


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142307

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


[PATCH] D141569: [clang-tidy] Implement CppCoreGuideline F.18

2023-01-22 Thread Chris Cotter via Phabricator via cfe-commits
ccotter updated this revision to Diff 491186.
ccotter added a comment.

- Properly handle forwarding references


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141569

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/rvalue-reference-param-not-moved.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/rvalue-reference-param-not-moved.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/rvalue-reference-param-not-moved.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/rvalue-reference-param-not-moved.cpp
@@ -0,0 +1,253 @@
+// RUN: %check_clang_tidy -std=c++14-or-later %s cppcoreguidelines-rvalue-reference-param-not-moved %t -- -- -fno-delayed-template-parsing
+
+// NOLINTBEGIN
+namespace std {
+template 
+struct remove_reference;
+
+template 
+struct remove_reference {
+  typedef _Tp type;
+};
+
+template 
+constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) noexcept;
+
+template 
+constexpr _Tp &&
+forward(typename remove_reference<_Tp>::type &__t) noexcept;
+
+}
+// NOLINTEND
+
+struct Obj {
+  Obj();
+  Obj(const Obj&);
+  Obj& operator=(const Obj&);
+  Obj(Obj&&);
+  Obj& operator=(Obj&&);
+  void member() const;
+};
+
+void consumes_object(Obj);
+
+void never_moves_param(Obj&& o) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: rvalue reference parameter is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+  o.member();
+}
+
+void copies_object(Obj&& o) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: rvalue reference parameter is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+  Obj copy = o;
+}
+
+template 
+void never_moves_param_template(Obj&& o, T t) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: rvalue reference parameter is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+  o.member();
+}
+
+void never_moves_params(Obj&& o1, Obj&& o2) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: rvalue reference parameter is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+  // CHECK-MESSAGES: :[[@LINE-2]]:35: warning: rvalue reference parameter is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+}
+
+void never_moves_some_params(Obj&& o1, Obj&& o2) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: rvalue reference parameter is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+
+  Obj other{std::move(o2)};
+}
+
+void never_moves_mixed(Obj o1, Obj&& o2) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: rvalue reference parameter is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+}
+
+void lambda_captures_parameter_as_value(Obj&& o) {
+  auto f = [o]() {
+consumes_object(std::move(o));
+  };
+  // CHECK-MESSAGES: :[[@LINE-4]]:41: warning: rvalue reference parameter is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+}
+
+void lambda_captures_parameter_as_value_nested(Obj&& o) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:48: warning: rvalue reference parameter is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+  auto f = [&o]() {
+auto f_nested = [o]() {
+  consumes_object(std::move(o));
+};
+  };
+  auto f2 = [o]() {
+auto f_nested = [&o]() {
+  consumes_object(std::move(o));
+};
+  };
+  auto f3 = [o]() {
+auto f_nested = [&o]() {
+  auto f_nested_inner = [&o]() {
+consumes_object(std::move(o));
+  };
+};
+  };
+  auto f4 = [&o]() {
+auto f_nested = [&o]() {
+  auto f_nested_inner = [o]() {
+consumes_object(std::move(o));
+  };
+};
+  };
+}
+
+void misc_lambda_checks() {
+  auto never_moves = [](Obj&& o1) {
+Obj other{o1};
+  };
+  // CHECK-MESSAGES: :[[@LINE-3]]:25: warning: rvalue reference parameter is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+
+  auto never_moves_with_auto_param = [](Obj&& o1, auto& v) {
+Obj other{o1};
+  };
+  // CHECK-MESSAGES: :[[@LINE-3]]:41: warning: rvalue reference parameter is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]

[PATCH] D142007: [NFC] Fix "form/from" typos

2023-01-22 Thread Mark de Wever via Phabricator via cfe-commits
Mordante added a comment.

In D142007#4071765 , @pfusik wrote:

> @ldionne Can you check it in?

Can you provide your name and email address to we can attribute the patch to 
you?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142007

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


[PATCH] D142007: [NFC] Fix "form/from" typos

2023-01-22 Thread Piotr Fusik via Phabricator via cfe-commits
pfusik added a comment.

In D142007#4072036 , @Mordante wrote:

> Can you provide your name and email address to we can attribute the patch to 
> you?

Piotr Fusik 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142007

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


[PATCH] D142307: [clang-tidy][NFC] Use C++17 nested namespaces in clang-tidy headers

2023-01-22 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

In D142307#4071952 , @Eugene.Zelenko 
wrote:

> Looks OK for me, but please fix small formatting issues. Will be good idea to 
> await for other eyes.

Thanks for the quick review! I applied clang-format to the patch; any 
additional manual formatting wanted belongs in a separate patch IMHO.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142307

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


[clang] 898b5c9 - [NFC] Fix "form/from" typos

2023-01-22 Thread Mark de Wever via cfe-commits

Author: Piotr Fusik
Date: 2023-01-22T20:05:51+01:00
New Revision: 898b5c9f5e7715f3ea4bb0ca2a8f23c301efa9c2

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

LOG: [NFC] Fix "form/from" typos

Reviewed By: #libc, ldionne

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
libcxx/include/__format/extended_grapheme_cluster_table.h
libcxx/utils/generate_extended_grapheme_cluster_table.py
lldb/include/lldb/Host/File.h
lldb/source/Plugins/CMakeLists.txt
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
llvm/lib/Analysis/IVDescriptors.cpp
llvm/lib/CodeGen/CodeGenPrepare.cpp
llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
llvm/test/DebugInfo/ARM/PR26163.ll
llvm/tools/llvm-exegesis/lib/Clustering.cpp
llvm/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp
llvm/unittests/FuzzMutate/RandomIRBuilderTest.cpp
mlir/lib/Dialect/Transform/IR/TransformDialect.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp 
b/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
index 7286f940328ee..44166aaf5b85b 100644
--- a/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
@@ -1095,7 +1095,7 @@ ObjCLoopChecker::checkPointerEscape(ProgramStateRef State,
 PointerEscapeKind Kind) const {
   SymbolRef ImmutableReceiver = getMethodReceiverIfKnownImmutable(Call);
 
-  // Remove the invalidated symbols form the collection count map.
+  // Remove the invalidated symbols from the collection count map.
   for (InvalidatedSymbols::const_iterator I = Escaped.begin(),
E = Escaped.end();
I != E; ++I) {

diff  --git a/libcxx/include/__format/extended_grapheme_cluster_table.h 
b/libcxx/include/__format/extended_grapheme_cluster_table.h
index 0e00670df780b..1ffcfeb549686 100644
--- a/libcxx/include/__format/extended_grapheme_cluster_table.h
+++ b/libcxx/include/__format/extended_grapheme_cluster_table.h
@@ -111,7 +111,7 @@ enum class __property : uint8_t {
 /// - https://www.unicode.org/Public/UCD/latest/ucd/emoji/emoji-data.txt
 ///
 /// The data has 3 values
-/// - bits [0, 3] The property. One of the values generated form the datafiles
+/// - bits [0, 3] The property. One of the values generated from the datafiles
 ///   of \ref __property
 /// - bits [4, 10] The size of the range.
 /// - bits [11, 31] The lower bound code point of the range. The upper bound of

diff  --git a/libcxx/utils/generate_extended_grapheme_cluster_table.py 
b/libcxx/utils/generate_extended_grapheme_cluster_table.py
index 7dd201615ee03..2762c013214f9 100755
--- a/libcxx/utils/generate_extended_grapheme_cluster_table.py
+++ b/libcxx/utils/generate_extended_grapheme_cluster_table.py
@@ -99,7 +99,7 @@ def compactPropertyRanges(input: list[PropertyRange]) -> 
list[PropertyRange]:
 /// - https://www.unicode.org/Public/UCD/latest/ucd/emoji/emoji-data.txt
 ///
 /// The data has 3 values
-/// - bits [0, 3] The property. One of the values generated form the datafiles
+/// - bits [0, 3] The property. One of the values generated from the datafiles
 ///   of \\ref __property
 /// - bits [4, 10] The size of the range.
 /// - bits [11, 31] The lower bound code point of the range. The upper bound of

diff  --git a/lldb/include/lldb/Host/File.h b/lldb/include/lldb/Host/File.h
index b2e7ebf5bba35..a1199a51b8a69 100644
--- a/lldb/include/lldb/Host/File.h
+++ b/lldb/include/lldb/Host/File.h
@@ -226,7 +226,7 @@ class File : public IOObject {
   /// A buffer where to put the bytes that are read.
   ///
   /// \param[in,out] num_bytes
-  /// The number of bytes to read form the current file position
+  /// The number of bytes to read from the current file position
   /// which gets modified with the number of bytes that were read.
   ///
   /// \param[in,out] offset

diff  --git a/lldb/source/Plugins/CMakeLists.txt 
b/lldb/source/Plugins/CMakeLists.txt
index 84cc065c3ca5a..855c9f671f479 100644
--- a/lldb/source/Plugins/CMakeLists.txt
+++ b/lldb/source/Plugins/CMakeLists.txt
@@ -36,7 +36,7 @@ set(LLDB_PROCESS_WINDOWS_PLUGIN "")
 set(LLDB_PROCESS_GDB_PLUGIN "")
 
 foreach(p ${LLDB_ALL_PLUGINS})
-  # Strip lldbPlugin form the plugin name.
+  # Strip lldbPlugin from the plugin name.
   string(SUBSTRING ${p} 10 -1 pStripped)
   if(${pStripped} MATCHES "^ScriptInterpreter*")
 set(LLDB_ENUM_PLUGINS 
"${LLDB_ENUM_PLUGINS}LLDB_SCRIPT_PLUGIN(${pStripped})\n")

diff  --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSyste

[PATCH] D142007: [NFC] Fix "form/from" typos

2023-01-22 Thread Mark de Wever 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 rG898b5c9f5e77: [NFC] Fix "form/from" typos 
(authored by pfusik, committed by Mordante).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142007

Files:
  clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
  libcxx/include/__format/extended_grapheme_cluster_table.h
  libcxx/utils/generate_extended_grapheme_cluster_table.py
  lldb/include/lldb/Host/File.h
  lldb/source/Plugins/CMakeLists.txt
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h
  llvm/lib/Analysis/IVDescriptors.cpp
  llvm/lib/CodeGen/CodeGenPrepare.cpp
  llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
  llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
  llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
  llvm/test/DebugInfo/ARM/PR26163.ll
  llvm/tools/llvm-exegesis/lib/Clustering.cpp
  llvm/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp
  llvm/unittests/FuzzMutate/RandomIRBuilderTest.cpp
  mlir/lib/Dialect/Transform/IR/TransformDialect.cpp

Index: mlir/lib/Dialect/Transform/IR/TransformDialect.cpp
===
--- mlir/lib/Dialect/Transform/IR/TransformDialect.cpp
+++ mlir/lib/Dialect/Transform/IR/TransformDialect.cpp
@@ -74,7 +74,7 @@
 
 void transform::TransformDialect::mergeInPDLMatchHooks(
 llvm::StringMap &&constraintFns) {
-  // Steal the constraint functions form the given map.
+  // Steal the constraint functions from the given map.
   for (auto &it : constraintFns)
 pdlMatchHooks.registerConstraintFunction(it.getKey(), std::move(it.second));
 }
Index: llvm/unittests/FuzzMutate/RandomIRBuilderTest.cpp
===
--- llvm/unittests/FuzzMutate/RandomIRBuilderTest.cpp
+++ llvm/unittests/FuzzMutate/RandomIRBuilderTest.cpp
@@ -130,7 +130,7 @@
 }
 
 TEST(RandomIRBuilderTest, ShuffleVectorSink) {
-  // Check that we will never use shuffle vector mask as a sink form the
+  // Check that we will never use shuffle vector mask as a sink from the
   // unrelated operation.
 
   LLVMContext Ctx;
Index: llvm/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp
===
--- llvm/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp
+++ llvm/unittests/ExecutionEngine/MCJIT/MCJITCAPITest.cpp
@@ -6,7 +6,7 @@
 //
 //===--===//
 //
-// This test suite verifies basic MCJIT functionality when invoked form the C
+// This test suite verifies basic MCJIT functionality when invoked from the C
 // API.
 //
 //===--===//
Index: llvm/tools/llvm-exegesis/lib/Clustering.cpp
===
--- llvm/tools/llvm-exegesis/lib/Clustering.cpp
+++ llvm/tools/llvm-exegesis/lib/Clustering.cpp
@@ -314,7 +314,7 @@
   // Actually append to-be-moved points to the new cluster.
   UnstableCluster.PointIndices.insert(UnstableCluster.PointIndices.end(),
   it, OldCluster.PointIndices.end());
-  // And finally, remove "to-be-moved" points form the old cluster.
+  // And finally, remove "to-be-moved" points from the old cluster.
   OldCluster.PointIndices.erase(it, OldCluster.PointIndices.end());
   // Now, the old cluster may end up being empty, but let's just keep it
   // in whatever state it ended up. Purging empty clusters isn't worth it.
Index: llvm/test/DebugInfo/ARM/PR26163.ll
===
--- llvm/test/DebugInfo/ARM/PR26163.ll
+++ llvm/test/DebugInfo/ARM/PR26163.ll
@@ -17,7 +17,7 @@
 ; CHECK-NEXT: DW_AT_location (DW_OP_lit0, DW_OP_stack_value, DW_OP_piece 0x4)
 ; CHECK-NEXT: DW_AT_abstract_origin
 
-; Created form the following test case (PR26163) with
+; Created from the following test case (PR26163) with
 ; clang -cc1 -triple armv4t--freebsd11.0-gnueabi -emit-obj -debug-info-kind=standalone -O2 -x c test.c
 ;
 ; typedef	unsigned int	size_t;
Index: llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
===
--- llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
+++ llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
@@ -722,7 +722,7 @@
 
 /// Updates the operand at Idx in instruction Inst with the result of
 ///instruction Mat. If the instruction is a PHI node then special
-///handling for duplicate values form the same incoming basic block is
+///handling for duplicate values from the same incoming basic block is
 ///required.
 /// \return The update will always succeed, but the return value indicated if
 /// Mat was used for the update or not.
Index: ll

[PATCH] D142007: [NFC] Fix "form/from" typos

2023-01-22 Thread Mark de Wever via Phabricator via cfe-commits
Mordante added a comment.

Thanks for your contribution, I just landed this patch on your behalf.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142007

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


[PATCH] D142315: [clang] Add test for CWG1111

2023-01-22 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill created this revision.
Endill added a reviewer: clang-language-wg.
Herald added a project: All.
Endill 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/D142315

Files:
  clang/test/CXX/drs/dr11xx.cpp
  clang/www/cxx_dr_status.html


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -6473,7 +6473,7 @@
 https://wg21.link/cwg";>
 C++11
 Remove dual-scope lookup of member template names
-Unknown
+Clang 6
   
   
 https://wg21.link/cwg1112";>1112
Index: clang/test/CXX/drs/dr11xx.cpp
===
--- clang/test/CXX/drs/dr11xx.cpp
+++ clang/test/CXX/drs/dr11xx.cpp
@@ -1,9 +1,35 @@
-// RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
+// RUN: %clang_cc1 -std=c++98 %s -verify=expected,cxx98 -fexceptions 
-fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
 // RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
 // RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
 // RUN: %clang_cc1 -std=c++2a %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
 
+namespace dr { // dr: 6
+  // FIXME: warning is emitted for well-formed code in C++98 mode, which
+  // follows the old behavior (clang 5 and earlier). Behavior is correct in all
+  // modes, though: only candidates from the class of the object expression are
+  // considered.
+
+  template
+  struct set; // #dr-set-template
+
+  struct X {
+template  void set(const T& value); // #dr-set-member
+  };
+  void foo() {
+X x;
+x.set(3.2); // cxx98-error {{lookup of 'set' in member access 
expression is ambiguous; using member of 'X'}}
+// cxx98-note@#dr-set-member {{lookup in the object type 'X' refers 
here}}
+// cxx98-note@#dr-set-template {{lookup from the current scope refers 
here}}
+  }
+
+  struct Y {};
+  void bar() {
+Y y;
+y.set(3.2); // expected-error {{no member named 'set' in 
'dr::Y'}}
+  }
+}
+
 namespace dr1113 { // dr1113: partial
   namespace named {
 extern int a; // expected-note {{previous}}


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -6473,7 +6473,7 @@
 https://wg21.link/cwg";>
 C++11
 Remove dual-scope lookup of member template names
-Unknown
+Clang 6
   
   
 https://wg21.link/cwg1112";>1112
Index: clang/test/CXX/drs/dr11xx.cpp
===
--- clang/test/CXX/drs/dr11xx.cpp
+++ clang/test/CXX/drs/dr11xx.cpp
@@ -1,9 +1,35 @@
-// RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++98 %s -verify=expected,cxx98 -fexceptions -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++2a %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
 
+namespace dr { // dr: 6
+  // FIXME: warning is emitted for well-formed code in C++98 mode, which
+  // follows the old behavior (clang 5 and earlier). Behavior is correct in all
+  // modes, though: only candidates from the class of the object expression are
+  // considered.
+
+  template
+  struct set; // #dr-set-template
+
+  struct X {
+template  void set(const T& value); // #dr-set-member
+  };
+  void foo() {
+X x;
+x.set(3.2); // cxx98-error {{lookup of 'set' in member access expression is ambiguous; using member of 'X'}}
+// cxx98-note@#dr-set-member {{lookup in the object type 'X' refers here}}
+// cxx98-note@#dr-set-template {{lookup from the current scope refers here}}
+  }
+
+  struct Y {};
+  void bar() {
+Y y;
+y.set(3.2); // expected-error {{no member named 'set' in 'dr::Y'}}
+  }
+}
+
 namespace dr1113 { // dr1113: partial
   namespace named {
 extern int a; // expected-note {{previous}}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D142316: [clang] Add test for CWG2396

2023-01-22 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill created this revision.
Endill added a reviewer: clang-language-wg.
Herald added a project: All.
Endill requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Also mark CWG1291 and CWG2385 as "na".

P1787 : CWG1291 and CWG2396 are resolved by 
explicitly specifying how to look up names in a conversion-type-id.
Wording: see changes to [basic.lookup.unqual]/5 and [basic.lookup.qual]/2.

"Calling a conversion function" example in P1787 
 is also relevant.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142316

Files:
  clang/test/CXX/drs/dr12xx.cpp
  clang/test/CXX/drs/dr23xx.cpp
  clang/www/cxx_dr_status.html


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -7553,7 +7553,7 @@
 https://wg21.link/cwg1291";>1291
 CD6
 Looking up a conversion-type-id
-Unknown
+N/A
   
   
 https://wg21.link/cwg1292";>1292
@@ -14117,7 +14117,7 @@
 https://wg21.link/cwg2385";>2385
 CD5
 Lookup for conversion-function-ids
-Unknown
+N/A
   
   
 https://wg21.link/cwg2386";>2386
@@ -14183,7 +14183,7 @@
 https://wg21.link/cwg2396";>2396
 CD6
 Lookup of names in complex conversion-type-ids
-Unknown
+No
   
   
 https://wg21.link/cwg2397";>2397
Index: clang/test/CXX/drs/dr23xx.cpp
===
--- clang/test/CXX/drs/dr23xx.cpp
+++ clang/test/CXX/drs/dr23xx.cpp
@@ -169,6 +169,8 @@
 } //namespace dr2303
 #endif
 
+// dr2385: na
+
 namespace dr2394 { // dr2394: 15
 
 struct A {};
@@ -179,3 +181,26 @@
 B b;
 
 }
+
+namespace dr2396 { // dr2396: no
+  template
+  struct identity {
+typedef T type;
+  };
+
+  struct A {
+struct B;
+operator B B::*();
+  };
+  struct B;
+
+  // FIXME: per P1787 "Calling a conversion function" example, all of the
+  // examples below are well-formed, with B resolving to A::B, but currently
+  // it's been resolved to dr2396::B. 
+
+  // void f(A a) { a.operator B B::*(); }
+  // void g(A a) { a.operator decltype(B()) B::*(); }
+  // void g2(A a) { a.operator B decltype(B())::*(); }
+  // void h(A a) { a.operator identity::type B::*(); }  
+  // void h2(A a) { a.operator B identity::type::*(); } 
+}
Index: clang/test/CXX/drs/dr12xx.cpp
===
--- clang/test/CXX/drs/dr12xx.cpp
+++ clang/test/CXX/drs/dr12xx.cpp
@@ -68,6 +68,8 @@
 #endif
 }
 
+// dr1291: na
+
 namespace dr1295 { // dr1295: 4
   struct X {
 unsigned bitfield : 4;


Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -7553,7 +7553,7 @@
 https://wg21.link/cwg1291";>1291
 CD6
 Looking up a conversion-type-id
-Unknown
+N/A
   
   
 https://wg21.link/cwg1292";>1292
@@ -14117,7 +14117,7 @@
 https://wg21.link/cwg2385";>2385
 CD5
 Lookup for conversion-function-ids
-Unknown
+N/A
   
   
 https://wg21.link/cwg2386";>2386
@@ -14183,7 +14183,7 @@
 https://wg21.link/cwg2396";>2396
 CD6
 Lookup of names in complex conversion-type-ids
-Unknown
+No
   
   
 https://wg21.link/cwg2397";>2397
Index: clang/test/CXX/drs/dr23xx.cpp
===
--- clang/test/CXX/drs/dr23xx.cpp
+++ clang/test/CXX/drs/dr23xx.cpp
@@ -169,6 +169,8 @@
 } //namespace dr2303
 #endif
 
+// dr2385: na
+
 namespace dr2394 { // dr2394: 15
 
 struct A {};
@@ -179,3 +181,26 @@
 B b;
 
 }
+
+namespace dr2396 { // dr2396: no
+  template
+  struct identity {
+typedef T type;
+  };
+
+  struct A {
+struct B;
+operator B B::*();
+  };
+  struct B;
+
+  // FIXME: per P1787 "Calling a conversion function" example, all of the
+  // examples below are well-formed, with B resolving to A::B, but currently
+  // it's been resolved to dr2396::B. 
+
+  // void f(A a) { a.operator B B::*(); }
+  // void g(A a) { a.operator decltype(B()) B::*(); }
+  // void g2(A a) { a.operator B decltype(B())::*(); }
+  // void h(A a) { a.operator identity::type B::*(); }  
+  // void h2(A a) { a.operator B identity::type::*(); } 
+}
Index: clang/test/CXX/drs/dr12xx.cpp
===
--- clang/test/CXX/drs/dr12xx.cpp
+++ clang/test/CXX/drs/dr12xx.cpp
@@ -68,6 +68,8 @@
 #endif
 }
 
+// dr1291: na
+
 namespace dr1295 { // dr1295: 4
   struct X {
 unsigned bitfield : 4;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141569: [clang-tidy] Implement CppCoreGuideline F.18

2023-01-22 Thread Chris Cotter via Phabricator via cfe-commits
ccotter updated this revision to Diff 491197.
ccotter added a comment.

- Allow move of any expr containing the parameter


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141569

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/rvalue-reference-param-not-moved.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/rvalue-reference-param-not-moved.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/rvalue-reference-param-not-moved.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/rvalue-reference-param-not-moved.cpp
@@ -0,0 +1,279 @@
+// RUN: %check_clang_tidy -std=c++14-or-later %s cppcoreguidelines-rvalue-reference-param-not-moved %t -- -- -fno-delayed-template-parsing
+
+// NOLINTBEGIN
+namespace std {
+template 
+struct remove_reference;
+
+template 
+struct remove_reference {
+  typedef _Tp type;
+};
+
+template 
+constexpr typename std::remove_reference<_Tp>::type &&move(_Tp &&__t) noexcept;
+
+template 
+constexpr _Tp &&
+forward(typename remove_reference<_Tp>::type &__t) noexcept;
+
+}
+// NOLINTEND
+
+struct Obj {
+  Obj();
+  Obj(const Obj&);
+  Obj& operator=(const Obj&);
+  Obj(Obj&&);
+  Obj& operator=(Obj&&);
+  void member() const;
+};
+
+void consumes_object(Obj);
+
+void never_moves_param(Obj&& o) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: rvalue reference parameter is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+  o.member();
+}
+
+void copies_object(Obj&& o) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: rvalue reference parameter is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+  Obj copy = o;
+}
+
+template 
+void never_moves_param_template(Obj&& o, T t) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: rvalue reference parameter is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+  o.member();
+}
+
+void never_moves_params(Obj&& o1, Obj&& o2) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: rvalue reference parameter is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+  // CHECK-MESSAGES: :[[@LINE-2]]:35: warning: rvalue reference parameter is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+}
+
+void never_moves_some_params(Obj&& o1, Obj&& o2) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: rvalue reference parameter is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+
+  Obj other{std::move(o2)};
+}
+
+void never_moves_mixed(Obj o1, Obj&& o2) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: rvalue reference parameter is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+}
+
+void lambda_captures_parameter_as_value(Obj&& o) {
+  auto f = [o]() {
+consumes_object(std::move(o));
+  };
+  // CHECK-MESSAGES: :[[@LINE-4]]:41: warning: rvalue reference parameter is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+}
+
+void lambda_captures_parameter_as_value_nested(Obj&& o) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:48: warning: rvalue reference parameter is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+  auto f = [&o]() {
+auto f_nested = [o]() {
+  consumes_object(std::move(o));
+};
+  };
+  auto f2 = [o]() {
+auto f_nested = [&o]() {
+  consumes_object(std::move(o));
+};
+  };
+  auto f3 = [o]() {
+auto f_nested = [&o]() {
+  auto f_nested_inner = [&o]() {
+consumes_object(std::move(o));
+  };
+};
+  };
+  auto f4 = [&o]() {
+auto f_nested = [&o]() {
+  auto f_nested_inner = [o]() {
+consumes_object(std::move(o));
+  };
+};
+  };
+}
+
+void misc_lambda_checks() {
+  auto never_moves = [](Obj&& o1) {
+Obj other{o1};
+  };
+  // CHECK-MESSAGES: :[[@LINE-3]]:25: warning: rvalue reference parameter is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-not-moved]
+
+  auto never_moves_with_auto_param = [](Obj&& o1, auto& v) {
+Obj other{o1};
+  };
+  // CHECK-MESSAGES: :[[@LINE-3]]:41: warning: rvalue reference parameter is never moved from inside the function body [cppcoreguidelines-rvalue-reference-param-n

[clang] caa99a0 - Use llvm::popcount instead of llvm::countPopulation(NFC)

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

Author: Kazu Hirata
Date: 2023-01-22T12:48:51-08:00
New Revision: caa99a01f5dd2f865df318a2f93abc811273a25d

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

LOG: Use llvm::popcount instead of llvm::countPopulation(NFC)

Added: 


Modified: 
clang-tools-extra/pseudo/include/clang-pseudo/grammar/LRTable.h
clang/lib/Basic/Sanitizers.cpp
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
lldb/source/Symbol/CompactUnwindInfo.cpp
llvm/include/llvm/ADT/APInt.h
llvm/include/llvm/ADT/BitVector.h
llvm/include/llvm/ADT/SmallBitVector.h
llvm/include/llvm/ADT/SparseBitVector.h
llvm/include/llvm/CodeGen/TargetLowering.h
llvm/include/llvm/MC/LaneBitmask.h
llvm/include/llvm/MC/SubtargetFeature.h
llvm/include/llvm/MCA/HardwareUnits/ResourceManager.h
llvm/lib/Analysis/MemoryProfileInfo.cpp
llvm/lib/CodeGen/CodeGenPrepare.cpp
llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
llvm/lib/CodeGen/MachinePipeliner.cpp
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
llvm/lib/DebugInfo/PDB/Native/GlobalsStream.cpp
llvm/lib/MC/MCSchedule.cpp
llvm/lib/MCA/HardwareUnits/ResourceManager.cpp
llvm/lib/MCA/InstrBuilder.cpp
llvm/lib/MCA/Stages/ExecuteStage.cpp
llvm/lib/Support/APInt.cpp
llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp
llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp
llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp
llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp
llvm/lib/Target/AMDGPU/EvergreenInstructions.td
llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp
llvm/lib/Target/AMDGPU/SIISelLowering.cpp
llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
llvm/lib/Target/AMDGPU/SIInstructions.td
llvm/lib/Target/AMDGPU/SILoadStoreOptimizer.cpp
llvm/lib/Target/AMDGPU/SIRegisterInfo.h
llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
llvm/lib/Target/Hexagon/HexagonISelDAGToDAGHVX.cpp
llvm/lib/Target/Hexagon/MCTargetDesc/HexagonShuffler.cpp
llvm/lib/Target/Hexagon/MCTargetDesc/HexagonShuffler.h
llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp
llvm/lib/Target/RISCV/RISCVInstrInfoZb.td
llvm/lib/Target/SystemZ/SystemZSelectionDAGInfo.cpp
llvm/lib/Target/X86/X86FloatingPoint.cpp
llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/lib/Target/X86/X86InstrInfo.cpp
llvm/tools/llvm-exegesis/lib/SchedClassResolution.cpp
llvm/tools/llvm-readobj/ARMWinEHPrinter.cpp
llvm/utils/TableGen/CodeGenDAGPatterns.h
mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
mlir/tools/mlir-tblgen/SPIRVUtilsGen.cpp

Removed: 




diff  --git a/clang-tools-extra/pseudo/include/clang-pseudo/grammar/LRTable.h 
b/clang-tools-extra/pseudo/include/clang-pseudo/grammar/LRTable.h
index 9fc4689da22b7..1706b6936c9ea 100644
--- a/clang-tools-extra/pseudo/include/clang-pseudo/grammar/LRTable.h
+++ b/clang-tools-extra/pseudo/include/clang-pseudo/grammar/LRTable.h
@@ -226,7 +226,7 @@ class LRTable {
   // Count the number of values since the checkpoint.
   Word BelowKeyMask = KeyMask - 1;
   unsigned CountSinceCheckpoint =
-  llvm::countPopulation(HasValue[KeyWord] & BelowKeyMask);
+  llvm::popcount(HasValue[KeyWord] & BelowKeyMask);
   // Find the value relative to the last checkpoint.
   return Values[Checkpoints[KeyWord] + CountSinceCheckpoint];
 }

diff  --git a/clang/lib/Basic/Sanitizers.cpp b/clang/lib/Basic/Sanitizers.cpp
index 7d903c8fdf5ec..62ccdf8e9bbf2 100644
--- a/clang/lib/Basic/Sanitizers.cpp
+++ b/clang/lib/Basic/Sanitizers.cpp
@@ -61,7 +61,7 @@ namespace clang {
 unsigned SanitizerMask::countPopulation() const {
   unsigned total = 0;
   for (const auto &Val : maskLoToHigh)
-total += llvm::countPopulation(Val);
+total += llvm::popcount(Val);
   return total;
 }
 

diff  --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp 
b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index 2716cf0cc56a8..d1745d970c441 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -8970,7 +8970,7 @@ static bool DumpEnumValue(const clang::QualType 
&qual_type, Stream *s,
   for (auto *enumerator : enum_decl->enumerators()) {
 uint64_t val = enumerator->getInitVal().getSExtValue();
 val = llvm::SignExtend64(val, 8*byte_size);
-if (llvm::countPopulation(val) != 1 && (val & ~covered_bits) != 0)
+if (llvm::popcount(val) != 1 && (val & ~covered_bits) != 0)
   can_be_bitfield = false;
 covered_bits |= val;
 ++num_enumerators;
@@ -9006,9 +9006,10 @@ st

[PATCH] D141892: Implement modernize-use-constraints

2023-01-22 Thread Chris Cotter via Phabricator via cfe-commits
ccotter updated this revision to Diff 491201.
ccotter added a comment.

- Use nested namespaces


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141892

Files:
  clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
  clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/modernize/use-constraints.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize/use-constraints-first-greatergreater.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize/use-constraints.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-constraints.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-constraints.cpp
@@ -0,0 +1,693 @@
+// RUN: %check_clang_tidy -std=c++20 %s modernize-use-constraints %t -- -- -fno-delayed-template-parsing
+
+// NOLINTBEGIN
+namespace std {
+template  struct enable_if { };
+
+template  struct enable_if { typedef T type; };
+
+template 
+using enable_if_t = typename enable_if::type;
+
+} // namespace std
+// NOLINTEND
+
+template 
+struct ConsumeVariadic;
+
+struct Obj {
+};
+
+namespace enable_if_in_return_type {
+
+
+// Section 1: enable_if in return type of function
+
+
+
+// General tests
+
+
+template 
+typename std::enable_if::type basic() {
+  return Obj{};
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints]
+// CHECK-FIXES: {{^}}Obj basic() requires T::some_value {{{$}}
+
+template 
+std::enable_if_t basic_t() {
+  return Obj{};
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints]
+// CHECK-FIXES: {{^}}Obj basic_t() requires T::some_value {{{$}}
+
+template 
+auto basic_trailing() -> typename std::enable_if::type {
+  return Obj{};
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:26: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints]
+// CHECK-FIXES: {{^}}auto basic_trailing() -> Obj requires T::some_value {{{$}}
+
+template 
+typename std::enable_if::type existing_constraint() requires (T::another_value) {
+  return Obj{};
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints]
+// CHECK-FIXES: {{^}}typename std::enable_if::type existing_constraint() requires (T::another_value) {{{$}}
+
+template 
+typename std::enable_if::type decl_without_def();
+
+template 
+typename std::enable_if::type decl_with_separate_def();
+
+template 
+typename std::enable_if::type decl_with_separate_def() {
+  return Obj{};
+}
+// FIXME - Support definitions with separate decls
+
+template 
+std::enable_if_t no_dependent_type(U) {
+  return Obj{};
+}
+// FIXME - Support non-dependent enable_ifs. Low priority though...
+
+template 
+typename std::enable_if::type* pointer_of_enable_if() {
+  return nullptr;
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints]
+// CHECK-FIXES: {{^}}template {{$}}
+// CHECK-FIXES-NEXT: {{^}}int* pointer_of_enable_if() requires T::some_value {{{$}}
+
+template 
+std::enable_if_t* pointer_of_enable_if_t() {
+  return nullptr;
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints]
+// CHECK-FIXES: {{^}}template {{$}}
+// CHECK-FIXES-NEXT: {{^}}int* pointer_of_enable_if_t() requires T::some_value {{{$}}
+
+template 
+const std::enable_if_t* const_pointer_of_enable_if_t() {
+  return nullptr;
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:7: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints]
+// CHECK-FIXES: {{^}}template {{$}}
+// CHECK-FIXES-NEXT: {{^}}const int* const_pointer_of_enable_if_t() requires T::some_value {{{$}}
+
+template 
+std::enable_if_t const * const_pointer_of_enable_if_t2() {
+  return nullptr;
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints]
+// CHECK-FIXES: {{^}}template {{$}}
+// CHECK-FIXES-NEXT: {{^}}int const * const_pointer_of_enable_if_t2() requires T::some_value {{{$}}
+
+
+template 
+std::enable_if_t& reference_of_enable_if_t() {
+  static int x; return x;
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:1: warning: use C++20 requires constraints instead of enable_if [modernize-use-constraints]
+// CHECK-FIXES: {{^}}template {{$}}
+// CHECK-FIXES-NEXT: {{^}}int& reference_of_enable_if_t()

[PATCH] D142046: [BPF][clang] Ignore stack protector options for BPF target

2023-01-22 Thread Douglas Yung via Phabricator via cfe-commits
dyung added a comment.

In D142046#4071594 , @yonghong-song 
wrote:

> @dyung I just pushed the fix to the 'main' branch 
> (https://github.com/llvm/llvm-project/commit/183d075055c591dedead7ece972f1bdea611aa3b).
>  Please check it out. Thanks for reporting!

That fixed it, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142046

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


[PATCH] D137753: [Clang][AIX][p]Enable -p Functionality

2023-01-22 Thread Michael Francis via Phabricator via cfe-commits
francii updated this revision to Diff 491204.
francii added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137753

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/AIX.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/aix-ld.c


Index: clang/test/Driver/aix-ld.c
===
--- clang/test/Driver/aix-ld.c
+++ clang/test/Driver/aix-ld.c
@@ -135,6 +135,8 @@
 // CHECK-LD32-PROF-NOT: "--no-as-needed"
 // CHECK-LD32-PROF-NOT: "-lm"
 // CHECK-LD32-PROF: "-lc"
+// CHECK-LD32-PROF: "-L[[SYSROOT]]/lib/profiled"
+// CHECK-LD32-PROF: "-L[[SYSROOT]]/usr/lib/profiled"
 
 // Check powerpc64-ibm-aix7.1.0.0, 64-bit. Enable profiling.
 // RUN: %clang %s -### 2>&1 \
@@ -162,6 +164,8 @@
 // CHECK-LD64-PROF-NOT: "--no-as-needed"
 // CHECK-LD64-PROF-NOT: "-lm"
 // CHECK-LD64-PROF: "-lc"
+// CHECK-LD64-PROF: "-L[[SYSROOT]]/lib/profiled"
+// CHECK-LD64-PROF: "-L[[SYSROOT]]/usr/lib/profiled
 
 // Check powerpc-ibm-aix7.1.0.0, 32-bit. Enable g-profiling.
 // RUN: %clang %s -### 2>&1 \
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6288,6 +6288,8 @@
   D.Diag(diag::err_drv_unsupported_opt_for_target)
   << A->getAsString(Args) << TripleStr;
 }
+if (TC.getTriple().isOSAIX())
+  CmdArgs.push_back("-pg");
   }
 
   if (Args.getLastArg(options::OPT_fapple_kext) ||
Index: clang/lib/Driver/ToolChains/AIX.cpp
===
--- clang/lib/Driver/ToolChains/AIX.cpp
+++ clang/lib/Driver/ToolChains/AIX.cpp
@@ -271,7 +271,7 @@
 
 CmdArgs.push_back("-lc");
 
-if (Args.hasArg(options::OPT_pg)) {
+if (Args.hasArg(options::OPT_p, options::OPT_pg)) {
   CmdArgs.push_back(Args.MakeArgString((llvm::Twine("-L") + D.SysRoot) +
"/lib/profiled"));
   CmdArgs.push_back(Args.MakeArgString((llvm::Twine("-L") + D.SysRoot) +
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -4137,6 +4137,7 @@
   MarshallingInfoFlag>;
 def pedantic : Flag<["-", "--"], "pedantic">, Group, 
Flags<[CC1Option,FlangOption,FC1Option]>,
   HelpText<"Warn on language extensions">, 
MarshallingInfoFlag>;
+def p : Flag<["-"], "p">, HelpText<"Enable mcount instrumentation with prof">, 
Flags<[CC1Option]>;
 def pg : Flag<["-"], "pg">, HelpText<"Enable mcount instrumentation">, 
Flags<[CC1Option]>,
   MarshallingInfoFlag>;
 def pipe : Flag<["-", "--"], "pipe">,
@@ -4183,7 +4184,6 @@
   LangOpts<"POSIXThreads">, DefaultFalse,
   PosFlag,
   NegFlag, BothFlags<[CC1Option]>>;
-def p : Flag<["-"], "p">;
 def pie : Flag<["-"], "pie">, Group;
 def static_pie : Flag<["-"], "static-pie">, Group;
 def read__only__relocs : Separate<["-"], "read_only_relocs">;


Index: clang/test/Driver/aix-ld.c
===
--- clang/test/Driver/aix-ld.c
+++ clang/test/Driver/aix-ld.c
@@ -135,6 +135,8 @@
 // CHECK-LD32-PROF-NOT: "--no-as-needed"
 // CHECK-LD32-PROF-NOT: "-lm"
 // CHECK-LD32-PROF: "-lc"
+// CHECK-LD32-PROF: "-L[[SYSROOT]]/lib/profiled"
+// CHECK-LD32-PROF: "-L[[SYSROOT]]/usr/lib/profiled"
 
 // Check powerpc64-ibm-aix7.1.0.0, 64-bit. Enable profiling.
 // RUN: %clang %s -### 2>&1 \
@@ -162,6 +164,8 @@
 // CHECK-LD64-PROF-NOT: "--no-as-needed"
 // CHECK-LD64-PROF-NOT: "-lm"
 // CHECK-LD64-PROF: "-lc"
+// CHECK-LD64-PROF: "-L[[SYSROOT]]/lib/profiled"
+// CHECK-LD64-PROF: "-L[[SYSROOT]]/usr/lib/profiled
 
 // Check powerpc-ibm-aix7.1.0.0, 32-bit. Enable g-profiling.
 // RUN: %clang %s -### 2>&1 \
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6288,6 +6288,8 @@
   D.Diag(diag::err_drv_unsupported_opt_for_target)
   << A->getAsString(Args) << TripleStr;
 }
+if (TC.getTriple().isOSAIX())
+  CmdArgs.push_back("-pg");
   }
 
   if (Args.getLastArg(options::OPT_fapple_kext) ||
Index: clang/lib/Driver/ToolChains/AIX.cpp
===
--- clang/lib/Driver/ToolChains/AIX.cpp
+++ clang/lib/Driver/ToolChains/AIX.cpp
@@ -271,7 +271,7 @@
 
 CmdArgs.push_back("-lc");
 
-if (Args.hasArg(options::OPT_pg)) {
+if (Args.hasArg(options::OPT_p, options::OPT_pg)) {
   CmdArgs.push_back(Args.MakeArgString((llvm::Twine("-L") + D.SysRoot) +
"/lib/profiled"));
   CmdArgs.push_back(Args.MakeArgString((l

[PATCH] D142046: [BPF][clang] Ignore stack protector options for BPF target

2023-01-22 Thread Eduard Zingerman via Phabricator via cfe-commits
eddyz87 added a comment.

Hi Yonghong,

Thank you for taking care of this issue.
This was sloppy on my side as the parameter name was completely
irrelevant for the test.

Best regards,
Eduard


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142046

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


[clang] c487b84 - [HIP] Change default offload arch to gfx906

2023-01-22 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2023-01-22T20:26:30-05:00
New Revision: c487b84d755298b6451a823447612fda84db9522

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

LOG: [HIP] Change default offload arch to gfx906

Reviewed by: Artem Belevich

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

Added: 


Modified: 
clang/lib/Driver/Driver.cpp
clang/test/Driver/cuda-flush-denormals-to-zero.cu
clang/test/Driver/hip-default-gpu-arch.hip

Removed: 




diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 58e1090673fad..49faa193fb7b1 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -3303,7 +3303,7 @@ class OffloadingActionBuilder final {
 HIPActionBuilder(Compilation &C, DerivedArgList &Args,
  const Driver::InputList &Inputs)
 : CudaActionBuilderBase(C, Args, Inputs, Action::OFK_HIP) {
-  DefaultCudaArch = CudaArch::GFX803;
+  DefaultCudaArch = CudaArch::GFX906;
   if (Args.hasArg(options::OPT_gpu_bundle_output,
   options::OPT_no_gpu_bundle_output))
 BundleOutput = Args.hasFlag(options::OPT_gpu_bundle_output,

diff  --git a/clang/test/Driver/cuda-flush-denormals-to-zero.cu 
b/clang/test/Driver/cuda-flush-denormals-to-zero.cu
index c971d15c53560..15525f9c1b814 100644
--- a/clang/test/Driver/cuda-flush-denormals-to-zero.cu
+++ b/clang/test/Driver/cuda-flush-denormals-to-zero.cu
@@ -25,9 +25,10 @@
 // Test the default changing with no argument based on the subtarget in HIP 
mode
 // RUN: %clang -x hip -### --target=x86_64-linux-gnu -c -march=haswell 
--cuda-gpu-arch=gfx803 -nocudainc -nogpulib %s 2>&1 | FileCheck 
-check-prefix=FTZ %s
 // RUN: %clang -x hip -### --target=x86_64-linux-gnu -c -march=haswell 
--cuda-gpu-arch=gfx900 -nocudainc -nogpulib %s 2>&1 | FileCheck 
-check-prefix=NOFTZ %s
+// RUN: %clang -x hip -### --target=x86_64-linux-gnu -c -march=haswell 
--cuda-gpu-arch=gfx906 -nocudainc -nogpulib %s 2>&1 | FileCheck 
-check-prefix=NOFTZ %s
 
-// Test no subtarget, which should get the denormal setting of the default 
gfx803
-// RUN: %clang -x hip -### --target=x86_64-linux-gnu -c -march=haswell 
-nocudainc -nogpulib %s 2>&1 | FileCheck -check-prefix=FTZ %s
+// Test no subtarget, which should get the denormal setting of the default 
gfx906
+// RUN: %clang -x hip -### --target=x86_64-linux-gnu -c -march=haswell 
-nocudainc -nogpulib %s 2>&1 | FileCheck -check-prefix=NOFTZ %s
 
 // Test multiple offload archs with 
diff erent defaults.
 // RUN: %clang -x hip -### --target=x86_64-linux-gnu -c -march=haswell 
--cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 -nocudainc -nogpulib %s 2>&1 | 
FileCheck -check-prefix=MIXED-DEFAULT-MODE %s

diff  --git a/clang/test/Driver/hip-default-gpu-arch.hip 
b/clang/test/Driver/hip-default-gpu-arch.hip
index 69d98d0f35695..2bb7afecd806f 100644
--- a/clang/test/Driver/hip-default-gpu-arch.hip
+++ b/clang/test/Driver/hip-default-gpu-arch.hip
@@ -3,4 +3,4 @@
 
 // RUN: %clang -### -c %s 2>&1 | FileCheck %s
 
-// CHECK: {{.*}}clang{{.*}}"-target-cpu" "gfx803"
+// CHECK: {{.*}}clang{{.*}}"-target-cpu" "gfx906"



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


[PATCH] D142246: [HIP] Change default offload arch to gfx906

2023-01-22 Thread Yaxun Liu 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 rGc487b84d7552: [HIP] Change default offload arch to gfx906 
(authored by yaxunl).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D142246?vs=490935&id=491217#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142246

Files:
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/cuda-flush-denormals-to-zero.cu
  clang/test/Driver/hip-default-gpu-arch.hip


Index: clang/test/Driver/hip-default-gpu-arch.hip
===
--- clang/test/Driver/hip-default-gpu-arch.hip
+++ clang/test/Driver/hip-default-gpu-arch.hip
@@ -3,4 +3,4 @@
 
 // RUN: %clang -### -c %s 2>&1 | FileCheck %s
 
-// CHECK: {{.*}}clang{{.*}}"-target-cpu" "gfx803"
+// CHECK: {{.*}}clang{{.*}}"-target-cpu" "gfx906"
Index: clang/test/Driver/cuda-flush-denormals-to-zero.cu
===
--- clang/test/Driver/cuda-flush-denormals-to-zero.cu
+++ clang/test/Driver/cuda-flush-denormals-to-zero.cu
@@ -25,9 +25,10 @@
 // Test the default changing with no argument based on the subtarget in HIP 
mode
 // RUN: %clang -x hip -### --target=x86_64-linux-gnu -c -march=haswell 
--cuda-gpu-arch=gfx803 -nocudainc -nogpulib %s 2>&1 | FileCheck 
-check-prefix=FTZ %s
 // RUN: %clang -x hip -### --target=x86_64-linux-gnu -c -march=haswell 
--cuda-gpu-arch=gfx900 -nocudainc -nogpulib %s 2>&1 | FileCheck 
-check-prefix=NOFTZ %s
+// RUN: %clang -x hip -### --target=x86_64-linux-gnu -c -march=haswell 
--cuda-gpu-arch=gfx906 -nocudainc -nogpulib %s 2>&1 | FileCheck 
-check-prefix=NOFTZ %s
 
-// Test no subtarget, which should get the denormal setting of the default 
gfx803
-// RUN: %clang -x hip -### --target=x86_64-linux-gnu -c -march=haswell 
-nocudainc -nogpulib %s 2>&1 | FileCheck -check-prefix=FTZ %s
+// Test no subtarget, which should get the denormal setting of the default 
gfx906
+// RUN: %clang -x hip -### --target=x86_64-linux-gnu -c -march=haswell 
-nocudainc -nogpulib %s 2>&1 | FileCheck -check-prefix=NOFTZ %s
 
 // Test multiple offload archs with different defaults.
 // RUN: %clang -x hip -### --target=x86_64-linux-gnu -c -march=haswell 
--cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 -nocudainc -nogpulib %s 2>&1 | 
FileCheck -check-prefix=MIXED-DEFAULT-MODE %s
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -3303,7 +3303,7 @@
 HIPActionBuilder(Compilation &C, DerivedArgList &Args,
  const Driver::InputList &Inputs)
 : CudaActionBuilderBase(C, Args, Inputs, Action::OFK_HIP) {
-  DefaultCudaArch = CudaArch::GFX803;
+  DefaultCudaArch = CudaArch::GFX906;
   if (Args.hasArg(options::OPT_gpu_bundle_output,
   options::OPT_no_gpu_bundle_output))
 BundleOutput = Args.hasFlag(options::OPT_gpu_bundle_output,


Index: clang/test/Driver/hip-default-gpu-arch.hip
===
--- clang/test/Driver/hip-default-gpu-arch.hip
+++ clang/test/Driver/hip-default-gpu-arch.hip
@@ -3,4 +3,4 @@
 
 // RUN: %clang -### -c %s 2>&1 | FileCheck %s
 
-// CHECK: {{.*}}clang{{.*}}"-target-cpu" "gfx803"
+// CHECK: {{.*}}clang{{.*}}"-target-cpu" "gfx906"
Index: clang/test/Driver/cuda-flush-denormals-to-zero.cu
===
--- clang/test/Driver/cuda-flush-denormals-to-zero.cu
+++ clang/test/Driver/cuda-flush-denormals-to-zero.cu
@@ -25,9 +25,10 @@
 // Test the default changing with no argument based on the subtarget in HIP mode
 // RUN: %clang -x hip -### --target=x86_64-linux-gnu -c -march=haswell --cuda-gpu-arch=gfx803 -nocudainc -nogpulib %s 2>&1 | FileCheck -check-prefix=FTZ %s
 // RUN: %clang -x hip -### --target=x86_64-linux-gnu -c -march=haswell --cuda-gpu-arch=gfx900 -nocudainc -nogpulib %s 2>&1 | FileCheck -check-prefix=NOFTZ %s
+// RUN: %clang -x hip -### --target=x86_64-linux-gnu -c -march=haswell --cuda-gpu-arch=gfx906 -nocudainc -nogpulib %s 2>&1 | FileCheck -check-prefix=NOFTZ %s
 
-// Test no subtarget, which should get the denormal setting of the default gfx803
-// RUN: %clang -x hip -### --target=x86_64-linux-gnu -c -march=haswell -nocudainc -nogpulib %s 2>&1 | FileCheck -check-prefix=FTZ %s
+// Test no subtarget, which should get the denormal setting of the default gfx906
+// RUN: %clang -x hip -### --target=x86_64-linux-gnu -c -march=haswell -nocudainc -nogpulib %s 2>&1 | FileCheck -check-prefix=NOFTZ %s
 
 // Test multiple offload archs with different defaults.
 // RUN: %clang -x hip -### --target=x86_64-linux-gnu -c -march=haswell --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 -nocudainc -nogpulib %s 2>&1 | F

[PATCH] D141248: [Clang] [Python] Fix tests when default config file contains -include

2023-01-22 Thread Sam James via Phabricator via cfe-commits
thesamesam added inline comments.



Comment at: clang/bindings/python/tests/cindex/util.py:82
+# our tests.
+os.environ["CLANG_NO_DEFAULT_CONFIG"] = "1"
 

xen0n wrote:
> This is essentially an import-time side effect, IMO it could be better to 
> instead put the envvar provision in 
> `clang/bindings/python/tests/CMakeLists.txt`: the `add_custom_target` there 
> already is making use of `env` so should be relatively easy to stuff this 
> there too.
I hesitated to do that because it doesn't vary with the environment at all (the 
test should never really be run with custom configs), but given you've 
suggested it, that tips the balance on me being undecided - so I'll implement 
that now. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141248

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


[PATCH] D141248: [Clang] [Python] Fix tests when default config file contains -include

2023-01-22 Thread Sam James via Phabricator via cfe-commits
thesamesam updated this revision to Diff 491220.
thesamesam added a comment.

Switch to setting CLANG_NO_DEFAULT_CONFIG via CMake instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141248

Files:
  clang/bindings/python/tests/CMakeLists.txt


Index: clang/bindings/python/tests/CMakeLists.txt
===
--- clang/bindings/python/tests/CMakeLists.txt
+++ clang/bindings/python/tests/CMakeLists.txt
@@ -1,7 +1,10 @@
 # Test target to run Python test suite from main build.
 
+# Avoid configurations including '-include' from interfering with
+# our tests by setting CLANG_NO_DEFAULT_CONFIG.
 add_custom_target(check-clang-python
 COMMAND ${CMAKE_COMMAND} -E env
+CLANG_NO_DEFAULT_CONFIG=1
 CLANG_LIBRARY_PATH=$
 "${Python3_EXECUTABLE}" -m unittest discover
 DEPENDS libclang


Index: clang/bindings/python/tests/CMakeLists.txt
===
--- clang/bindings/python/tests/CMakeLists.txt
+++ clang/bindings/python/tests/CMakeLists.txt
@@ -1,7 +1,10 @@
 # Test target to run Python test suite from main build.
 
+# Avoid configurations including '-include' from interfering with
+# our tests by setting CLANG_NO_DEFAULT_CONFIG.
 add_custom_target(check-clang-python
 COMMAND ${CMAKE_COMMAND} -E env
+CLANG_NO_DEFAULT_CONFIG=1
 CLANG_LIBRARY_PATH=$
 "${Python3_EXECUTABLE}" -m unittest discover
 DEPENDS libclang
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D142296: [clang-format] Fix bugs in parsing C++20 module import statements

2023-01-22 Thread Owen Pan via Phabricator via cfe-commits
owenpan updated this revision to Diff 491221.
owenpan added a comment.

Put back the inadvertently removed line `nextToken();`, which was just before 
the outer `while` loop in `parseModuleImport()`.


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

https://reviews.llvm.org/D142296

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -12810,6 +12810,7 @@
   // But 'import' might also be a regular C++ namespace.
   verifyFormat("import::SomeFunction(aaa,\n"
" a);");
+  verifyFormat("import::Bar foo(val ? 2 : 1);");
 }
 
 //===--===//
@@ -24628,6 +24629,7 @@
   verifyFormat("import foo.bar;", Style);
   verifyFormat("import foo:bar;", Style);
   verifyFormat("import :bar;", Style);
+  verifyFormat("import /* module partition */ :bar;", Style);
   verifyFormat("import ;", Style);
   verifyFormat("import \"header\";", Style);
 
@@ -24654,6 +24656,8 @@
   verifyFormat("import", Style);
   verifyFormat("module", Style);
   verifyFormat("export", Style);
+
+  verifyFormat("import /* not keyword */ = val ? 2 : 1;");
 }
 
 TEST_F(FormatTest, CoroutineForCoawait) {
Index: clang/lib/Format/UnwrappedLineParser.h
===
--- clang/lib/Format/UnwrappedLineParser.h
+++ clang/lib/Format/UnwrappedLineParser.h
@@ -153,7 +153,7 @@
   void parseCaseLabel();
   void parseSwitch();
   void parseNamespace();
-  void parseModuleImport();
+  bool parseModuleImport();
   void parseNew();
   void parseAccessSpecifier();
   bool parseEnum();
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -41,7 +41,7 @@
 
   // Returns the token that would be returned by the next call to
   // getNextToken().
-  virtual FormatToken *peekNextToken() = 0;
+  virtual FormatToken *peekNextToken(bool SkipComment = false) = 0;
 
   // Returns whether we are at the end of the file.
   // This can be different from whether getNextToken() returned an eof token
@@ -169,10 +169,10 @@
 return PreviousTokenSource->getPreviousToken();
   }
 
-  FormatToken *peekNextToken() override {
+  FormatToken *peekNextToken(bool SkipComment) override {
 if (eof())
   return &FakeEOF;
-return PreviousTokenSource->peekNextToken();
+return PreviousTokenSource->peekNextToken(SkipComment);
   }
 
   bool isEOF() override { return PreviousTokenSource->isEOF(); }
@@ -288,8 +288,11 @@
 return Position > 0 ? Tokens[Position - 1] : nullptr;
   }
 
-  FormatToken *peekNextToken() override {
+  FormatToken *peekNextToken(bool SkipComment) override {
 int Next = Position + 1;
+if (SkipComment)
+  while (Tokens[Next]->is(tok::comment))
+++Next;
 LLVM_DEBUG({
   llvm::dbgs() << "Peeking ";
   dbgToken(Next);
@@ -1435,7 +1438,15 @@
   return Tok->Previous && Tok->Previous->isOneOf(tok::l_paren, tok::comma);
 }
 
-void UnwrappedLineParser::parseModuleImport() {
+bool UnwrappedLineParser::parseModuleImport() {
+  assert(FormatTok->is(Keywords.kw_import) && "'import' expected");
+
+  if (auto Token = Tokens->peekNextToken(/*SkipComment=*/true);
+  !Token->Tok.getIdentifierInfo() &&
+  !Token->isOneOf(tok::colon, tok::less, tok::string_literal)) {
+return false;
+  }
+
   nextToken();
   while (!eof()) {
 if (FormatTok->is(tok::colon)) {
@@ -1462,6 +1473,7 @@
   }
 
   addUnwrappedLine();
+  return true;
 }
 
 // readTokenWithJavaScriptASI reads the next token and terminates the current
@@ -1682,14 +1694,12 @@
 }
 if (Style.isCpp()) {
   nextToken();
-  if (FormatTok->is(Keywords.kw_import)) {
-parseModuleImport();
-return;
-  }
   if (FormatTok->is(tok::kw_namespace)) {
 parseNamespace();
 return;
   }
+  if (FormatTok->is(Keywords.kw_import) && parseModuleImport())
+return;
 }
 break;
   case tok::kw_inline:
@@ -1726,10 +1736,8 @@
 addUnwrappedLine();
 return;
   }
-  if (Style.isCpp()) {
-parseModuleImport();
+  if (Style.isCpp() && parseModuleImport())
 return;
-  }
 }
 if (Style.isCpp() &&
 FormatTok->isOneOf(Keywords.kw_signals, Keywords.kw_qsignals,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D142268: [clang][DebugInfo] Don't canonicalize names in template argument list for alias templates

2023-01-22 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

So @Michael137 and I talked about this offline, and a few extra details:

- Generally it's important that types have identical names. Templates try to do 
this, but get it wrong in a bunch of ways (& certainly between GCC and Clang we 
get it different in a bunch of ways too) which are all problematic/could cause 
a debugger to not correctly identify two types in distinct CUs as being 
actually the same type.
  - That's why we usually use the full name of a template, to ensure it's 
identical between instantiations in different CUs
- Because compilers don't all produce character-for-character identical names, 
debuggers mostly have to throw away the "<.*>" and recanonicalize from the 
`DW_TAG_template_*_parameter`s anyway..
- But none of that matters, because alias templates aren't strong aliases - 
they aren't part of the type system, they're just a name that code can use
- As mentioned, GCC currently only uses the base name, no template parameters - 
which isn't super helpful (since you'd then end up with a bunch of different 
alias template instantiations all with the same name).
- Clang produces the alias template with the template parameters in the 
`DW_AT_name`, but without any `DW_TAG_template_*_parameter` DIEs, which means 
we can't apply Simple Template Names here, currently - though might be a nice 
thing to do at somepoint.

But for now, since the name doesn't actually have to be 
deconstruct/canonicalize the template parameters - we can just pick whatever 
name is nice for the user, really.

So, I think this is an OK change to make for now - though probably the nicer 
thing, long-term, would be to add the template parameter DIEs, and under 
`-gsimple-template-names` remove the template parameters from the `DW_AT_name` 
(& maybe eventually turn that on by default/migrate to 
`-gsimple-template-names`) but for now/when using non`-gsimple-template-names`, 
this seems OK, if a bit weird/inconsistent, but for good reasons because the 
alias template isn't part of the type system. (thanks for including the FIXME 
there)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142268

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


[PATCH] D142268: [clang][DebugInfo] Don't canonicalize names in template argument list for alias templates

2023-01-22 Thread David Blaikie via Phabricator via cfe-commits
dblaikie accepted this revision.
dblaikie 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/D142268/new/

https://reviews.llvm.org/D142268

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


[PATCH] D142326: [clang][RISCV][test] Add test cases for empty structs and the FP calling conventions

2023-01-22 Thread Alex Bradbury via Phabricator via cfe-commits
asb created this revision.
asb added reviewers: kito-cheng, reames, jrtc27, craig.topper, luke.
Herald added subscribers: wingo, pmatos, VincentWu, vkmr, frasercrmck, evandro, 
luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, 
PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, 
shiva0217, niosHD, sabuasal, simoncook, johnrusso, rbar, arichardson.
Herald added a project: All.
asb requested review of this revision.
Herald added subscribers: cfe-commits, pcwang-thead, eopXD, MaskRay.
Herald added a project: clang.

As reported in https://github.com/llvm/llvm-project/issues/58929, Clang 
currently differs from GCC in the handling of empty structs. This commit adds 
some test coverage for the handling of such structs.

Posting for review rather than committing directly because more eyes on our 
test coverage for in these areas would be useful.

A follow-up patch implements a fix to match g++.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142326

Files:
  clang/test/CodeGen/RISCV/abi-empty-structs.c

Index: clang/test/CodeGen/RISCV/abi-empty-structs.c
===
--- /dev/null
+++ clang/test/CodeGen/RISCV/abi-empty-structs.c
@@ -0,0 +1,141 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --filter "^define |^entry:"
+// RUN: %clang_cc1 -triple riscv32 -target-feature +f -target-abi ilp32f -emit-llvm %s -o - \
+// RUN:   | FileCheck -check-prefixes=CHECK-C,CHECK32-C %s
+// RUN: %clang_cc1 -triple riscv32 -target-feature +f -target-feature +d -target-abi ilp32d -emit-llvm %s -o - \
+// RUN:   | FileCheck -check-prefixes=CHECK-C,CHECK32-C
+// RUN: %clang_cc1 -triple riscv64 -target-feature +f -target-abi lp64f -emit-llvm %s -o - \
+// RUN:   | FileCheck -check-prefixes=CHECK-C,CHECK64-C %s
+// RUN: %clang_cc1 -triple riscv64 -target-feature +f -target-feature +d -target-abi lp64d -emit-llvm %s -o - \
+// RUN:   | FileCheck -check-prefixes=CHECK-C,CHECK64-C
+// RUN: %clang_cc1 -x c++ -triple riscv32 -target-feature +f -target-abi ilp32f -emit-llvm %s -o - \
+// RUN:   | FileCheck -check-prefixes=CHECK-CXX,CHECK32-CXX %s
+// RUN: %clang_cc1 -x c++ -triple riscv32 -target-feature +f -target-feature +d -target-abi ilp32d -emit-llvm %s -o - \
+// RUN:   | FileCheck -check-prefixes=CHECK-CXX,CHECK32-CXX
+// RUN: %clang_cc1 -x c++ -triple riscv64 -target-feature +f -target-abi lp64f -emit-llvm %s -o - \
+// RUN:   | FileCheck -check-prefixes=CHECK-CXX,CHECK64-CXX %s
+// RUN: %clang_cc1 -x c++ -triple riscv64 -target-feature +f -target-feature +d -target-abi lp64d -emit-llvm %s -o - \
+// RUN:   | FileCheck -check-prefixes=CHECK-CXX,CHECK64-CXX
+
+#include 
+
+// Fields containing empty structs or unions are ignored when flattening
+// structs for the hard FP ABIs, even in C++.
+// FIXME: This isn't currently respected.
+
+struct empty { struct { struct { } e; }; };
+struct s1 { struct empty e; float f; };
+
+// CHECK-C-LABEL: define dso_local float @test_s1
+// CHECK-C-SAME: (float [[TMP0:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-C:  entry:
+//
+// CHECK32-CXX-LABEL: define dso_local [2 x i32] @_Z7test_s12s1
+// CHECK32-CXX-SAME: ([2 x i32] [[A_COERCE:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK32-CXX:  entry:
+//
+// CHECK64-CXX-LABEL: define dso_local i64 @_Z7test_s12s1
+// CHECK64-CXX-SAME: (i64 [[A_COERCE:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK64-CXX:  entry:
+//
+struct s1 test_s1(struct s1 a) {
+  return a;
+}
+
+struct s2 { struct empty e; int32_t i; float f; };
+
+// CHECK-C-LABEL: define dso_local { i32, float } @test_s2
+// CHECK-C-SAME: (i32 [[TMP0:%.*]], float [[TMP1:%.*]]) #[[ATTR0]] {
+// CHECK-C:  entry:
+//
+// CHECK32-CXX-LABEL: define dso_local void @_Z7test_s22s2
+// CHECK32-CXX-SAME: (ptr noalias sret([[STRUCT_S2:%.*]]) align 4 [[AGG_RESULT:%.*]], ptr noundef [[A:%.*]]) #[[ATTR0]] {
+// CHECK32-CXX:  entry:
+//
+// CHECK64-CXX-LABEL: define dso_local [2 x i64] @_Z7test_s22s2
+// CHECK64-CXX-SAME: ([2 x i64] [[A_COERCE:%.*]]) #[[ATTR0]] {
+// CHECK64-CXX:  entry:
+//
+struct s2 test_s2(struct s2 a) {
+  return a;
+}
+
+struct s3 { struct empty e; float f; float g; };
+
+// CHECK-C-LABEL: define dso_local { float, float } @test_s3
+// CHECK-C-SAME: (float [[TMP0:%.*]], float [[TMP1:%.*]]) #[[ATTR0]] {
+// CHECK-C:  entry:
+//
+// CHECK32-CXX-LABEL: define dso_local void @_Z7test_s32s3
+// CHECK32-CXX-SAME: (ptr noalias sret([[STRUCT_S3:%.*]]) align 4 [[AGG_RESULT:%.*]], ptr noundef [[A:%.*]]) #[[ATTR0]] {
+// CHECK32-CXX:  entry:
+//
+// CHECK64-CXX-LABEL: define dso_local [2 x i64] @_Z7test_s32s3
+// CHECK64-CXX-SAME: ([2 x i64] [[A_COERCE:%.*]]) #[[ATTR0]] {
+// CHECK64-CXX:  entry:
+//
+struct s3 test_s3(struct s3 a) {
+  return a;
+}
+
+struct s4 { struct empty e; float __complex__ c; };
+
+// CHECK-C-LABEL: define dso_local { float, float } @test_s4
+// CHECK-C-SAME: (float [[TMP0:%.*]], float [[TMP1:%.*]]) #[[ATTR0]] {
+// CHECK

[PATCH] D142327: [clang][RISCV] Fix ABI handling of empty structs with hard FP calling conventions in C++

2023-01-22 Thread Alex Bradbury via Phabricator via cfe-commits
asb created this revision.
asb added reviewers: kito-cheng, jrtc27, reames, craig.topper, uweigand, luke.
Herald added subscribers: wingo, pmatos, VincentWu, vkmr, frasercrmck, evandro, 
luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, 
PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, 
shiva0217, niosHD, sabuasal, simoncook, johnrusso, rbar, arichardson.
Herald added a project: All.
asb requested review of this revision.
Herald added subscribers: cfe-commits, pcwang-thead, eopXD, MaskRay.
Herald added a project: clang.

As reported in https://github.com/llvm/llvm-project/issues/58929,
Clang's handling of empty structs in the case of small structs that may
be eligible to be passed using the hard FP calling convention doesn't
match g++. In general, C++ record fields are never empty unless
[[no_unique_address]] is used, but the RISC-V FP ABI overrides this.

After this patch, fields of structs that contain empty records will be
ignored, even in C++, when considering eligibility for the FP calling
convention ('flattening'). It isn't explicitly noted in the RISC-V
psABI, but arrays of empty records will disqualify a struct for
consideration of using the FP calling convention in g++. This patch
matches that behaviour. The psABI issue
https://github.com/riscv-non-isa/riscv-elf-psabi-doc/issues/358 seeks
to clarify this.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142327

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/RISCV/abi-empty-structs.c

Index: clang/test/CodeGen/RISCV/abi-empty-structs.c
===
--- clang/test/CodeGen/RISCV/abi-empty-structs.c
+++ clang/test/CodeGen/RISCV/abi-empty-structs.c
@@ -29,13 +29,9 @@
 // CHECK-C-SAME: (float [[TMP0:%.*]]) #[[ATTR0:[0-9]+]] {
 // CHECK-C:  entry:
 //
-// CHECK32-CXX-LABEL: define dso_local [2 x i32] @_Z7test_s12s1
-// CHECK32-CXX-SAME: ([2 x i32] [[A_COERCE:%.*]]) #[[ATTR0:[0-9]+]] {
-// CHECK32-CXX:  entry:
-//
-// CHECK64-CXX-LABEL: define dso_local i64 @_Z7test_s12s1
-// CHECK64-CXX-SAME: (i64 [[A_COERCE:%.*]]) #[[ATTR0:[0-9]+]] {
-// CHECK64-CXX:  entry:
+// CHECK-CXX-LABEL: define dso_local float @_Z7test_s12s1
+// CHECK-CXX-SAME: (float [[TMP0:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-CXX:  entry:
 //
 struct s1 test_s1(struct s1 a) {
   return a;
@@ -47,13 +43,9 @@
 // CHECK-C-SAME: (i32 [[TMP0:%.*]], float [[TMP1:%.*]]) #[[ATTR0]] {
 // CHECK-C:  entry:
 //
-// CHECK32-CXX-LABEL: define dso_local void @_Z7test_s22s2
-// CHECK32-CXX-SAME: (ptr noalias sret([[STRUCT_S2:%.*]]) align 4 [[AGG_RESULT:%.*]], ptr noundef [[A:%.*]]) #[[ATTR0]] {
-// CHECK32-CXX:  entry:
-//
-// CHECK64-CXX-LABEL: define dso_local [2 x i64] @_Z7test_s22s2
-// CHECK64-CXX-SAME: ([2 x i64] [[A_COERCE:%.*]]) #[[ATTR0]] {
-// CHECK64-CXX:  entry:
+// CHECK-CXX-LABEL: define dso_local { i32, float } @_Z7test_s22s2
+// CHECK-CXX-SAME: (i32 [[TMP0:%.*]], float [[TMP1:%.*]]) #[[ATTR0]] {
+// CHECK-CXX:  entry:
 //
 struct s2 test_s2(struct s2 a) {
   return a;
@@ -65,13 +57,9 @@
 // CHECK-C-SAME: (float [[TMP0:%.*]], float [[TMP1:%.*]]) #[[ATTR0]] {
 // CHECK-C:  entry:
 //
-// CHECK32-CXX-LABEL: define dso_local void @_Z7test_s32s3
-// CHECK32-CXX-SAME: (ptr noalias sret([[STRUCT_S3:%.*]]) align 4 [[AGG_RESULT:%.*]], ptr noundef [[A:%.*]]) #[[ATTR0]] {
-// CHECK32-CXX:  entry:
-//
-// CHECK64-CXX-LABEL: define dso_local [2 x i64] @_Z7test_s32s3
-// CHECK64-CXX-SAME: ([2 x i64] [[A_COERCE:%.*]]) #[[ATTR0]] {
-// CHECK64-CXX:  entry:
+// CHECK-CXX-LABEL: define dso_local { float, float } @_Z7test_s32s3
+// CHECK-CXX-SAME: (float [[TMP0:%.*]], float [[TMP1:%.*]]) #[[ATTR0]] {
+// CHECK-CXX:  entry:
 //
 struct s3 test_s3(struct s3 a) {
   return a;
@@ -83,13 +71,9 @@
 // CHECK-C-SAME: (float [[TMP0:%.*]], float [[TMP1:%.*]]) #[[ATTR0]] {
 // CHECK-C:  entry:
 //
-// CHECK32-CXX-LABEL: define dso_local void @_Z7test_s42s4
-// CHECK32-CXX-SAME: (ptr noalias sret([[STRUCT_S4:%.*]]) align 4 [[AGG_RESULT:%.*]], ptr noundef [[A:%.*]]) #[[ATTR0]] {
-// CHECK32-CXX:  entry:
-//
-// CHECK64-CXX-LABEL: define dso_local [2 x i64] @_Z7test_s42s4
-// CHECK64-CXX-SAME: ([2 x i64] [[A_COERCE:%.*]]) #[[ATTR0]] {
-// CHECK64-CXX:  entry:
+// CHECK-CXX-LABEL: define dso_local { float, float } @_Z7test_s42s4
+// CHECK-CXX-SAME: (float [[TMP0:%.*]], float [[TMP1:%.*]]) #[[ATTR0]] {
+// CHECK-CXX:  entry:
 //
 struct s4 test_s4(struct s4 a) {
   return a;
@@ -136,6 +120,5 @@
 }
 
  NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
-// CHECK-CXX: {{.*}}
 // CHECK32-C: {{.*}}
 // CHECK64-C: {{.*}}
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -548,12 +548,13 @@
   return Ctx.getOrInsertSyncScopeID(""); /* default sync scope */
 }
 
-static bool isEmptyRecord(ASTContext &Context, QualTyp

[PATCH] D142328: [clang][Interp] Fix compound assign operator types

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

  Just like we do (or will do) for floating types, we need to take into
  acocunt that the LHSComputationType, ResultType and type of the
  expression (what we ultimately store) might be different.
  
  Do this by emitting cast ops before and after doing the computation.
  
  This fixes the test failures introduced by
  490e8214fca48824beda8b508d6d6bbbf3d8d9a7 on big endian machines.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142328

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


Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -525,10 +525,13 @@
 const CompoundAssignOperator *E) {
   const Expr *LHS = E->getLHS();
   const Expr *RHS = E->getRHS();
-  std::optional LT = classify(E->getLHS()->getType());
-  std::optional RT = classify(E->getRHS()->getType());
+  std::optional LHSComputationT =
+  classify(E->getComputationLHSType());
+  std::optional LT = classify(LHS->getType());
+  std::optional RT = classify(E->getComputationResultType());
+  std::optional ResultT = classify(E->getType());
 
-  if (!LT || !RT)
+  if (!LT || !RT || !ResultT || !LHSComputationT)
 return false;
 
   assert(!E->getType()->isPointerType() &&
@@ -539,29 +542,36 @@
 return false;
   if (!this->emitLoad(*LT, E))
 return false;
+  // If necessray, cast LHS to its computation type.
+  if (*LT != *LHSComputationT) {
+if (!this->emitCast(*LT, *LHSComputationT, E))
+  return false;
+  }
+
   if (!visit(RHS))
 return false;
 
   // Perform operation.
   switch (E->getOpcode()) {
   case BO_AddAssign:
-if (!this->emitAdd(*LT, E))
+if (!this->emitAdd(*LHSComputationT, E))
   return false;
 break;
   case BO_SubAssign:
-if (!this->emitSub(*LT, E))
+if (!this->emitSub(*LHSComputationT, E))
   return false;
 break;
 
   case BO_MulAssign:
   case BO_DivAssign:
   case BO_RemAssign:
+
   case BO_ShlAssign:
-if (!this->emitShl(*LT, *RT, E))
+if (!this->emitShl(*LHSComputationT, *RT, E))
   return false;
 break;
   case BO_ShrAssign:
-if (!this->emitShr(*LT, *RT, E))
+if (!this->emitShr(*LHSComputationT, *RT, E))
   return false;
 break;
   case BO_AndAssign:
@@ -571,10 +581,15 @@
 llvm_unreachable("Unimplemented compound assign operator");
   }
 
+  if (*ResultT != *LHSComputationT) {
+if (!this->emitCast(*LHSComputationT, *ResultT, E))
+  return false;
+  }
+
   // And store the result in LHS.
   if (DiscardResult)
-return this->emitStorePop(*LT, E);
-  return this->emitStore(*LT, E);
+return this->emitStorePop(*ResultT, E);
+  return this->emitStore(*ResultT, E);
 }
 
 template  bool ByteCodeExprGen::discard(const Expr *E) 
{


Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -525,10 +525,13 @@
 const CompoundAssignOperator *E) {
   const Expr *LHS = E->getLHS();
   const Expr *RHS = E->getRHS();
-  std::optional LT = classify(E->getLHS()->getType());
-  std::optional RT = classify(E->getRHS()->getType());
+  std::optional LHSComputationT =
+  classify(E->getComputationLHSType());
+  std::optional LT = classify(LHS->getType());
+  std::optional RT = classify(E->getComputationResultType());
+  std::optional ResultT = classify(E->getType());
 
-  if (!LT || !RT)
+  if (!LT || !RT || !ResultT || !LHSComputationT)
 return false;
 
   assert(!E->getType()->isPointerType() &&
@@ -539,29 +542,36 @@
 return false;
   if (!this->emitLoad(*LT, E))
 return false;
+  // If necessray, cast LHS to its computation type.
+  if (*LT != *LHSComputationT) {
+if (!this->emitCast(*LT, *LHSComputationT, E))
+  return false;
+  }
+
   if (!visit(RHS))
 return false;
 
   // Perform operation.
   switch (E->getOpcode()) {
   case BO_AddAssign:
-if (!this->emitAdd(*LT, E))
+if (!this->emitAdd(*LHSComputationT, E))
   return false;
 break;
   case BO_SubAssign:
-if (!this->emitSub(*LT, E))
+if (!this->emitSub(*LHSComputationT, E))
   return false;
 break;
 
   case BO_MulAssign:
   case BO_DivAssign:
   case BO_RemAssign:
+
   case BO_ShlAssign:
-if (!this->emitShl(*LT, *RT, E))
+if (!this->emitShl(*LHSComputationT, *RT, E))
   return false;
 break;
   case BO_ShrAssign:
-if (!this->emitShr(*LT, *RT, E))
+if (!this->emitShr(*LHSComputationT, *RT, E))
   return false;
 break;
   case BO_AndAssign:
@@ -571,10 +581,15 @@
 llvm_unreachable("Unimplemented compound assign o

[PATCH] D142328: [clang][Interp] Fix compound assign operator types

2023-01-22 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

The casts emitted are similar to https://reviews.llvm.org/D140377 now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142328

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


[PATCH] D142327: [clang][RISCV] Fix ABI handling of empty structs with hard FP calling conventions in C++

2023-01-22 Thread Alex Bradbury via Phabricator via cfe-commits
asb updated this revision to Diff 491237.
asb added a comment.

Removed FIXME missed in initial version.


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

https://reviews.llvm.org/D142327

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/RISCV/abi-empty-structs.c

Index: clang/test/CodeGen/RISCV/abi-empty-structs.c
===
--- clang/test/CodeGen/RISCV/abi-empty-structs.c
+++ clang/test/CodeGen/RISCV/abi-empty-structs.c
@@ -20,7 +20,6 @@
 
 // Fields containing empty structs or unions are ignored when flattening
 // structs for the hard FP ABIs, even in C++.
-// FIXME: This isn't currently respected.
 
 struct empty { struct { struct { } e; }; };
 struct s1 { struct empty e; float f; };
@@ -29,13 +28,9 @@
 // CHECK-C-SAME: (float [[TMP0:%.*]]) #[[ATTR0:[0-9]+]] {
 // CHECK-C:  entry:
 //
-// CHECK32-CXX-LABEL: define dso_local [2 x i32] @_Z7test_s12s1
-// CHECK32-CXX-SAME: ([2 x i32] [[A_COERCE:%.*]]) #[[ATTR0:[0-9]+]] {
-// CHECK32-CXX:  entry:
-//
-// CHECK64-CXX-LABEL: define dso_local i64 @_Z7test_s12s1
-// CHECK64-CXX-SAME: (i64 [[A_COERCE:%.*]]) #[[ATTR0:[0-9]+]] {
-// CHECK64-CXX:  entry:
+// CHECK-CXX-LABEL: define dso_local float @_Z7test_s12s1
+// CHECK-CXX-SAME: (float [[TMP0:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-CXX:  entry:
 //
 struct s1 test_s1(struct s1 a) {
   return a;
@@ -47,13 +42,9 @@
 // CHECK-C-SAME: (i32 [[TMP0:%.*]], float [[TMP1:%.*]]) #[[ATTR0]] {
 // CHECK-C:  entry:
 //
-// CHECK32-CXX-LABEL: define dso_local void @_Z7test_s22s2
-// CHECK32-CXX-SAME: (ptr noalias sret([[STRUCT_S2:%.*]]) align 4 [[AGG_RESULT:%.*]], ptr noundef [[A:%.*]]) #[[ATTR0]] {
-// CHECK32-CXX:  entry:
-//
-// CHECK64-CXX-LABEL: define dso_local [2 x i64] @_Z7test_s22s2
-// CHECK64-CXX-SAME: ([2 x i64] [[A_COERCE:%.*]]) #[[ATTR0]] {
-// CHECK64-CXX:  entry:
+// CHECK-CXX-LABEL: define dso_local { i32, float } @_Z7test_s22s2
+// CHECK-CXX-SAME: (i32 [[TMP0:%.*]], float [[TMP1:%.*]]) #[[ATTR0]] {
+// CHECK-CXX:  entry:
 //
 struct s2 test_s2(struct s2 a) {
   return a;
@@ -65,13 +56,9 @@
 // CHECK-C-SAME: (float [[TMP0:%.*]], float [[TMP1:%.*]]) #[[ATTR0]] {
 // CHECK-C:  entry:
 //
-// CHECK32-CXX-LABEL: define dso_local void @_Z7test_s32s3
-// CHECK32-CXX-SAME: (ptr noalias sret([[STRUCT_S3:%.*]]) align 4 [[AGG_RESULT:%.*]], ptr noundef [[A:%.*]]) #[[ATTR0]] {
-// CHECK32-CXX:  entry:
-//
-// CHECK64-CXX-LABEL: define dso_local [2 x i64] @_Z7test_s32s3
-// CHECK64-CXX-SAME: ([2 x i64] [[A_COERCE:%.*]]) #[[ATTR0]] {
-// CHECK64-CXX:  entry:
+// CHECK-CXX-LABEL: define dso_local { float, float } @_Z7test_s32s3
+// CHECK-CXX-SAME: (float [[TMP0:%.*]], float [[TMP1:%.*]]) #[[ATTR0]] {
+// CHECK-CXX:  entry:
 //
 struct s3 test_s3(struct s3 a) {
   return a;
@@ -83,13 +70,9 @@
 // CHECK-C-SAME: (float [[TMP0:%.*]], float [[TMP1:%.*]]) #[[ATTR0]] {
 // CHECK-C:  entry:
 //
-// CHECK32-CXX-LABEL: define dso_local void @_Z7test_s42s4
-// CHECK32-CXX-SAME: (ptr noalias sret([[STRUCT_S4:%.*]]) align 4 [[AGG_RESULT:%.*]], ptr noundef [[A:%.*]]) #[[ATTR0]] {
-// CHECK32-CXX:  entry:
-//
-// CHECK64-CXX-LABEL: define dso_local [2 x i64] @_Z7test_s42s4
-// CHECK64-CXX-SAME: ([2 x i64] [[A_COERCE:%.*]]) #[[ATTR0]] {
-// CHECK64-CXX:  entry:
+// CHECK-CXX-LABEL: define dso_local { float, float } @_Z7test_s42s4
+// CHECK-CXX-SAME: (float [[TMP0:%.*]], float [[TMP1:%.*]]) #[[ATTR0]] {
+// CHECK-CXX:  entry:
 //
 struct s4 test_s4(struct s4 a) {
   return a;
@@ -136,6 +119,5 @@
 }
 
  NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
-// CHECK-CXX: {{.*}}
 // CHECK32-C: {{.*}}
 // CHECK64-C: {{.*}}
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -548,12 +548,13 @@
   return Ctx.getOrInsertSyncScopeID(""); /* default sync scope */
 }
 
-static bool isEmptyRecord(ASTContext &Context, QualType T, bool AllowArrays);
+static bool isEmptyRecord(ASTContext &Context, QualType T, bool AllowArrays,
+  bool AsIfNoUniqueAddr = false);
 
 /// isEmptyField - Return true iff a the field is "empty", that is it
 /// is an unnamed bit-field or an (array of) empty record(s).
 static bool isEmptyField(ASTContext &Context, const FieldDecl *FD,
- bool AllowArrays) {
+ bool AllowArrays, bool AsIfNoUniqueAddr = false) {
   if (FD->isUnnamedBitfield())
 return true;
 
@@ -587,16 +588,19 @@
   // not arrays of records, so we must also check whether we stripped off an
   // array type above.
   if (isa(RT->getDecl()) &&
-  (WasArray || !FD->hasAttr()))
+  (WasArray || (!FD->hasAttr() && !AsIfNoUniqueAddr)))
 return false;
 
-  return isEmptyRecord(Context, FT, AllowArrays);
+  return isEmptyRecord(Context, FT, AllowArrays, AsIfNoUniqueAddr);
 }
 
 /// isEmptyRecord - Return true iff a struct

[PATCH] D138802: [clang][Interp] Implement DecompositionDecls

2023-01-22 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Ping


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

https://reviews.llvm.org/D138802

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


[PATCH] D140723: [clang][Interp] Only check constructors for global variables

2023-01-22 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140723

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


[PATCH] D141591: [clang][Interp] Properly identify not-yet-defined functions

2023-01-22 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Ping


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

https://reviews.llvm.org/D141591

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


[PATCH] D141858: [clang][Interp] Fix Pointer::toAPValue() for expressions

2023-01-22 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Ping


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

https://reviews.llvm.org/D141858

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


[PATCH] D141757: [clangd] allow extracting to variable for complete lambda expressions

2023-01-22 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

LGTM, thanks!




Comment at: clang-tools-extra/docs/ReleaseNotes.rst:81
 
+- The extract variable tweak gained support for extracting complete lambda 
expressions to a variable.
+

Maybe add a "Code Actions" section for this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141757

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


[PATCH] D142328: [clang][Interp] Fix compound assign operator types

2023-01-22 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 491238.

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

https://reviews.llvm.org/D142328

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


Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -525,10 +525,13 @@
 const CompoundAssignOperator *E) {
   const Expr *LHS = E->getLHS();
   const Expr *RHS = E->getRHS();
-  std::optional LT = classify(E->getLHS()->getType());
-  std::optional RT = classify(E->getRHS()->getType());
+  std::optional LHSComputationT =
+  classify(E->getComputationLHSType());
+  std::optional LT = classify(LHS->getType());
+  std::optional RT = classify(E->getComputationResultType());
+  std::optional ResultT = classify(E->getType());
 
-  if (!LT || !RT)
+  if (!LT || !RT || !ResultT || !LHSComputationT)
 return false;
 
   assert(!E->getType()->isPointerType() &&
@@ -539,29 +542,36 @@
 return false;
   if (!this->emitLoad(*LT, E))
 return false;
+  // If necessary, cast LHS to its computation type.
+  if (*LT != *LHSComputationT) {
+if (!this->emitCast(*LT, *LHSComputationT, E))
+  return false;
+  }
+
   if (!visit(RHS))
 return false;
 
   // Perform operation.
   switch (E->getOpcode()) {
   case BO_AddAssign:
-if (!this->emitAdd(*LT, E))
+if (!this->emitAdd(*LHSComputationT, E))
   return false;
 break;
   case BO_SubAssign:
-if (!this->emitSub(*LT, E))
+if (!this->emitSub(*LHSComputationT, E))
   return false;
 break;
 
   case BO_MulAssign:
   case BO_DivAssign:
   case BO_RemAssign:
+
   case BO_ShlAssign:
-if (!this->emitShl(*LT, *RT, E))
+if (!this->emitShl(*LHSComputationT, *RT, E))
   return false;
 break;
   case BO_ShrAssign:
-if (!this->emitShr(*LT, *RT, E))
+if (!this->emitShr(*LHSComputationT, *RT, E))
   return false;
 break;
   case BO_AndAssign:
@@ -571,10 +581,16 @@
 llvm_unreachable("Unimplemented compound assign operator");
   }
 
+  // And now cast from LHSComputationT to ResultT.
+  if (*ResultT != *LHSComputationT) {
+if (!this->emitCast(*LHSComputationT, *ResultT, E))
+  return false;
+  }
+
   // And store the result in LHS.
   if (DiscardResult)
-return this->emitStorePop(*LT, E);
-  return this->emitStore(*LT, E);
+return this->emitStorePop(*ResultT, E);
+  return this->emitStore(*ResultT, E);
 }
 
 template  bool ByteCodeExprGen::discard(const Expr *E) 
{


Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -525,10 +525,13 @@
 const CompoundAssignOperator *E) {
   const Expr *LHS = E->getLHS();
   const Expr *RHS = E->getRHS();
-  std::optional LT = classify(E->getLHS()->getType());
-  std::optional RT = classify(E->getRHS()->getType());
+  std::optional LHSComputationT =
+  classify(E->getComputationLHSType());
+  std::optional LT = classify(LHS->getType());
+  std::optional RT = classify(E->getComputationResultType());
+  std::optional ResultT = classify(E->getType());
 
-  if (!LT || !RT)
+  if (!LT || !RT || !ResultT || !LHSComputationT)
 return false;
 
   assert(!E->getType()->isPointerType() &&
@@ -539,29 +542,36 @@
 return false;
   if (!this->emitLoad(*LT, E))
 return false;
+  // If necessary, cast LHS to its computation type.
+  if (*LT != *LHSComputationT) {
+if (!this->emitCast(*LT, *LHSComputationT, E))
+  return false;
+  }
+
   if (!visit(RHS))
 return false;
 
   // Perform operation.
   switch (E->getOpcode()) {
   case BO_AddAssign:
-if (!this->emitAdd(*LT, E))
+if (!this->emitAdd(*LHSComputationT, E))
   return false;
 break;
   case BO_SubAssign:
-if (!this->emitSub(*LT, E))
+if (!this->emitSub(*LHSComputationT, E))
   return false;
 break;
 
   case BO_MulAssign:
   case BO_DivAssign:
   case BO_RemAssign:
+
   case BO_ShlAssign:
-if (!this->emitShl(*LT, *RT, E))
+if (!this->emitShl(*LHSComputationT, *RT, E))
   return false;
 break;
   case BO_ShrAssign:
-if (!this->emitShr(*LT, *RT, E))
+if (!this->emitShr(*LHSComputationT, *RT, E))
   return false;
 break;
   case BO_AndAssign:
@@ -571,10 +581,16 @@
 llvm_unreachable("Unimplemented compound assign operator");
   }
 
+  // And now cast from LHSComputationT to ResultT.
+  if (*ResultT != *LHSComputationT) {
+if (!this->emitCast(*LHSComputationT, *ResultT, E))
+  return false;
+  }
+
   // And store the result in LHS.
   if (DiscardResult)
-return this->emitStorePop(*LT, E);
-  return this->emitStore(*LT, E);
+return this->emitStorePop(*ResultT, E);
+  return this->emitStore(*ResultT, E);
 }
 
 template  bool ByteCodeExprGen::discard(const Expr *E) {

[PATCH] D142014: [clangd] fix wrong CalleeArgInfo in the hover

2023-01-22 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a subscriber: adamcz.
nridge added a comment.

Thanks for the patch!

I had a look at the code history, and it looks like the original reason for not 
using the param decl's type to determine the passing mode was (based on this 
comment ) to handle cases like 
this correctly:

  struct C { C(int&); };
  void foo(const C&);
  int main() {
int y;
foo(y);
  }

However, your patch keeps this case working by keeping the check for a 
`CXXConstructExpr` and using the constructor's parameter decl instead (and this 
scenario has test coverage in the test `Hover.CallPassType`), so this seems 
fine to me, and indeed a nice simplification.

That said, I will cc @adamcz and @kadircet (as author and reviewer of the 
original patch) to see if they have any concerns about this refactoring 
breaking any other cases.




Comment at: clang-tools-extra/clangd/Hover.cpp:955
 
+HoverInfo::PassType::PassMode getPassMode(QualType QT) {
+  if (QT->isReferenceType()) {

nit: name the parameter `ParmType`, so it's clear whose type it's expecting



Comment at: clang-tools-extra/clangd/Hover.cpp:1032
+  } else {
+PassType.PassBy = getPassMode(CD->getParamDecl(0)->getType());
 PassType.Converted = true;

Please explicily check `getNumParams()` before calling `getParamDecl(0)`. (Even 
though the constructpr //should// have at least one parameter, we don't want to 
risk crashing in the case of invalid code or some other unexpected situation.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142014

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


[PATCH] D140562: [clang][ASTImporter] Improve import of InjectedClassNameType.

2023-01-22 Thread Balázs Kéri via Phabricator via cfe-commits
balazske planned changes to this revision.
balazske added a comment.

I plan to improve the fix and change the code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140562

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