[PATCH] D140817: [Driver] move NetBSD header search path management to the driver

2023-01-01 Thread Brad Smith via Phabricator via cfe-commits
brad created this revision.
brad added reviewers: MaskRay, mgorny, krytarowski.
brad added a project: clang.
Herald added subscribers: StephenFan, ormris, arichardson, emaste.
Herald added a project: All.
brad requested review of this revision.

This matches OpenBSD and FreeBSD.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140817

Files:
  clang/lib/Driver/ToolChains/NetBSD.cpp
  clang/lib/Driver/ToolChains/NetBSD.h
  clang/lib/Lex/InitHeaderSearch.cpp
  clang/test/Driver/netbsd.c
  clang/test/Driver/netbsd.cpp

Index: clang/test/Driver/netbsd.cpp
===
--- clang/test/Driver/netbsd.cpp
+++ clang/test/Driver/netbsd.cpp
@@ -339,3 +339,11 @@
 // S-POWERPC64: "{{.*}}/usr/lib{{/|}}crti.o"
 // S-POWERPC64: "{{.*}}/usr/lib{{/|}}crtbegin.o" "{{.*}}.o" "-lc++"
 // S-POWERPC64: "-lm" "-lc" "{{.*}}/usr/lib{{/|}}crtend.o" "{{.*}}/usr/lib{{/|}}crtn.o"
+
+// Check that the driver passes include paths to cc1 on NetBSD.
+// RUN: %clang -### %s --target=x86_64-unknown-netbsd -r 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=DRIVER-PASS-INCLUDES
+// DRIVER-PASS-INCLUDES:  "-cc1" {{.*}}"-resource-dir" "[[RESOURCE:[^"]+]]"
+// DRIVER-PASS-INCLUDES-SAME: {{^}} "-internal-isystem" "/usr/include/c++/v1"
+// DRIVER-PASS-INCLUDES-SAME: {{^}} "-internal-isystem" "[[RESOURCE]]{{/|}}include"
+// DRIVER-PASS-INCLUDES-SAME: {{^}} "-internal-externc-isystem" "/usr/include"
Index: clang/test/Driver/netbsd.c
===
--- clang/test/Driver/netbsd.c
+++ clang/test/Driver/netbsd.c
@@ -477,3 +477,10 @@
 // RELOCATABLE-NOT: "-dynamic-linker"
 // RELOCATABLE-NOT: "-l
 // RELOCATABLE-NOT: crt{{[^./\\]+}}.o
+
+// Check that the driver passes include paths to cc1 on NetBSD.
+// RUN: %clang -### %s --target=x86_64-unknown-netbsd -r 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=DRIVER-PASS-INCLUDES
+// DRIVER-PASS-INCLUDES:  "-cc1" {{.*}}"-resource-dir" "[[RESOURCE:[^"]+]]"
+// DRIVER-PASS-INCLUDES-SAME: {{^}} "-internal-isystem" "[[RESOURCE]]{{/|}}include"
+// DRIVER-PASS-INCLUDES-SAME: {{^}} "-internal-externc-isystem" "/usr/include"
Index: clang/lib/Lex/InitHeaderSearch.cpp
===
--- clang/lib/Lex/InitHeaderSearch.cpp
+++ clang/lib/Lex/InitHeaderSearch.cpp
@@ -231,7 +231,6 @@
   if (HSOpts.UseStandardSystemIncludes) {
 switch (os) {
 case llvm::Triple::CloudABI:
-case llvm::Triple::NetBSD:
 case llvm::Triple::NaCl:
 case llvm::Triple::PS4:
 case llvm::Triple::PS5:
@@ -412,9 +411,10 @@
   case llvm::Triple::AIX:
   case llvm::Triple::Emscripten:
   case llvm::Triple::FreeBSD:
+  case llvm::Triple::NetBSD:
+  case llvm::Triple::OpenBSD:
   case llvm::Triple::Hurd:
   case llvm::Triple::Linux:
-  case llvm::Triple::OpenBSD:
   case llvm::Triple::Solaris:
   case llvm::Triple::WASI:
 return false;
Index: clang/lib/Driver/ToolChains/NetBSD.h
===
--- clang/lib/Driver/ToolChains/NetBSD.h
+++ clang/lib/Driver/ToolChains/NetBSD.h
@@ -58,6 +58,9 @@
 
   CXXStdlibType GetDefaultCXXStdlibType() const override;
 
+  void
+  AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
+llvm::opt::ArgStringList &CC1Args) const override;
   void addLibCxxIncludePaths(
   const llvm::opt::ArgList &DriverArgs,
   llvm::opt::ArgStringList &CC1Args) const override;
Index: clang/lib/Driver/ToolChains/NetBSD.cpp
===
--- clang/lib/Driver/ToolChains/NetBSD.cpp
+++ clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -11,6 +11,7 @@
 #include "Arch/Mips.h"
 #include "Arch/Sparc.h"
 #include "CommonArgs.h"
+#include "clang/Config/config.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/Options.h"
@@ -435,6 +436,40 @@
   return ToolChain::CST_Libstdcxx;
 }
 
+void NetBSD::AddClangSystemIncludeArgs(
+const llvm::opt::ArgList &DriverArgs,
+llvm::opt::ArgStringList &CC1Args) const {
+  const Driver &D = getDriver();
+
+  if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
+return;
+
+  if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
+SmallString<128> Dir(D.ResourceDir);
+llvm::sys::path::append(Dir, "include");
+addSystemInclude(DriverArgs, CC1Args, Dir.str());
+  }
+
+  if (DriverArgs.hasArg(options::OPT_nostdlibinc))
+return;
+
+  // Check for configure-time C include directories.
+  StringRef CIncludeDirs(C_INCLUDE_DIRS);
+  if (CIncludeDirs != "") {
+SmallVector dirs;
+CIncludeDirs.split(dirs, ":");
+for (StringRef dir : dirs) {
+  StringRef Prefix =
+  llvm::sys::path::is_absolute(dir) ? StringRef(D.SysRoot) : "";
+  addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir);
+}
+return;
+  }
+
+  addExternCSystemInclude(DriverArg

[clang-tools-extra] d408c34 - [clangd] Add extension for adding context (enclosing function or class) in references results

2023-01-01 Thread Tom Praschan via cfe-commits

Author: Tom Praschan
Date: 2023-01-01T15:25:18+01:00
New Revision: d408c34d1f588e518b0ee15c00b55db131944cfb

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

LOG: [clangd] Add extension for adding context (enclosing function or class) in 
references results

Relevant issue: https://github.com/clangd/clangd/issues/177

Reviewed By: nridge

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

Added: 
clang-tools-extra/clangd/test/references-container.test

Modified: 
clang-tools-extra/clangd/ClangdLSPServer.cpp
clang-tools-extra/clangd/ClangdLSPServer.h
clang-tools-extra/clangd/ClangdServer.cpp
clang-tools-extra/clangd/ClangdServer.h
clang-tools-extra/clangd/Protocol.cpp
clang-tools-extra/clangd/Protocol.h
clang-tools-extra/clangd/XRefs.cpp
clang-tools-extra/clangd/XRefs.h
clang-tools-extra/clangd/index/SymbolCollector.cpp
clang-tools-extra/clangd/index/SymbolCollector.h
clang-tools-extra/clangd/unittests/XRefsTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index 6259057e9cf47..8f5c8fa702429 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -485,6 +485,7 @@ void ClangdLSPServer::onInitialize(const InitializeParams 
&Params,
   SupportsCodeAction = Params.capabilities.CodeActionStructure;
   SupportsHierarchicalDocumentSymbol =
   Params.capabilities.HierarchicalDocumentSymbol;
+  SupportsReferenceContainer = Params.capabilities.ReferenceContainer;
   SupportFileStatus = Params.initializationOptions.FileStatus;
   HoverContentFormat = Params.capabilities.HoverContentFormat;
   Opts.LineFoldingOnly = Params.capabilities.LineFoldingOnly;
@@ -1375,25 +1376,27 @@ void ClangdLSPServer::onChangeConfiguration(
   applyConfiguration(Params.settings);
 }
 
-void ClangdLSPServer::onReference(const ReferenceParams &Params,
-  Callback> Reply) {
-  Server->findReferences(
-  Params.textDocument.uri.file(), Params.position, Opts.ReferencesLimit,
-  [Reply = std::move(Reply),
-   IncludeDecl(Params.context.includeDeclaration)](
-  llvm::Expected Refs) mutable {
-if (!Refs)
-  return Reply(Refs.takeError());
-// Filter out declarations if the client asked.
-std::vector Result;
-Result.reserve(Refs->References.size());
-for (auto &Ref : Refs->References) {
-  bool IsDecl = Ref.Attributes & ReferencesResult::Declaration;
-  if (IncludeDecl || !IsDecl)
-Result.push_back(std::move(Ref.Loc));
-}
-return Reply(std::move(Result));
-  });
+void ClangdLSPServer::onReference(
+const ReferenceParams &Params,
+Callback> Reply) {
+  Server->findReferences(Params.textDocument.uri.file(), Params.position,
+ Opts.ReferencesLimit, SupportsReferenceContainer,
+ [Reply = std::move(Reply),
+  IncludeDecl(Params.context.includeDeclaration)](
+ llvm::Expected Refs) mutable {
+   if (!Refs)
+ return Reply(Refs.takeError());
+   // Filter out declarations if the client asked.
+   std::vector Result;
+   Result.reserve(Refs->References.size());
+   for (auto &Ref : Refs->References) {
+ bool IsDecl =
+ Ref.Attributes & 
ReferencesResult::Declaration;
+ if (IncludeDecl || !IsDecl)
+   Result.push_back(std::move(Ref.Loc));
+   }
+   return Reply(std::move(Result));
+ });
 }
 
 void ClangdLSPServer::onGoToType(const TextDocumentPositionParams &Params,

diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.h 
b/clang-tools-extra/clangd/ClangdLSPServer.h
index bbf72d8a54c76..43b5e748075d7 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.h
+++ b/clang-tools-extra/clangd/ClangdLSPServer.h
@@ -120,7 +120,7 @@ class ClangdLSPServer : private ClangdServer::Callbacks,
   Callback>);
   void onGoToImplementation(const TextDocumentPositionParams &,
 Callback>);
-  void onReference(const ReferenceParams &, Callback>);
+  void onReference(const ReferenceParams &, 
Callback>);
   void onSwitchSourceHeader(const TextDocumentIdentifier &,
 Callback>);
   void onDocumentHighlight(const TextDocumentPositionParams &,
@@ -262,6 +262,8 @@ class ClangdLSPServer : private ClangdServer::Callbacks,

[PATCH] D137894: [clangd] Add extension for adding context (enclosing function or class) in references results

2023-01-01 Thread Tom Praschan 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 rGd408c34d1f58: [clangd] Add extension for adding context 
(enclosing function or class) in… (authored by tom-anders).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137894

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/Protocol.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/XRefs.h
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/clangd/index/SymbolCollector.h
  clang-tools-extra/clangd/test/references-container.test
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -301,6 +301,9 @@
 MATCHER_P(sym, Name, "") { return arg.Name == Name; }
 
 MATCHER_P(rangeIs, R, "") { return arg.Loc.range == R; }
+MATCHER_P(containerIs, C, "") {
+  return arg.Loc.containerName.value_or("") == C;
+}
 MATCHER_P(attrsAre, A, "") { return arg.Attributes == A; }
 MATCHER_P(hasID, ID, "") { return arg.ID == ID; }
 
@@ -1900,28 +1903,30 @@
 
   auto AST = TU.build();
   std::vector> ExpectedLocations;
-  for (const auto &R : T.ranges())
-ExpectedLocations.push_back(AllOf(rangeIs(R), attrsAre(0u)));
+  for (const auto &[R, Context] : T.rangesWithPayload())
+ExpectedLocations.push_back(
+AllOf(rangeIs(R), containerIs(Context), attrsAre(0u)));
   // $def is actually shorthand for both definition and declaration.
   // If we have cases that are definition-only, we should change this.
-  for (const auto &R : T.ranges("def"))
-ExpectedLocations.push_back(
-AllOf(rangeIs(R), attrsAre(ReferencesResult::Definition |
-   ReferencesResult::Declaration)));
-  for (const auto &R : T.ranges("decl"))
-ExpectedLocations.push_back(
-AllOf(rangeIs(R), attrsAre(ReferencesResult::Declaration)));
-  for (const auto &R : T.ranges("overridedecl"))
+  for (const auto &[R, Context] : T.rangesWithPayload("def"))
+ExpectedLocations.push_back(AllOf(rangeIs(R), containerIs(Context),
+  attrsAre(ReferencesResult::Definition |
+   ReferencesResult::Declaration)));
+  for (const auto &[R, Context] : T.rangesWithPayload("decl"))
+ExpectedLocations.push_back(AllOf(rangeIs(R), containerIs(Context),
+  attrsAre(ReferencesResult::Declaration)));
+  for (const auto &[R, Context] : T.rangesWithPayload("overridedecl"))
 ExpectedLocations.push_back(AllOf(
-rangeIs(R),
+rangeIs(R), containerIs(Context),
 attrsAre(ReferencesResult::Declaration | ReferencesResult::Override)));
-  for (const auto &R : T.ranges("overridedef"))
-ExpectedLocations.push_back(
-AllOf(rangeIs(R), attrsAre(ReferencesResult::Declaration |
-   ReferencesResult::Definition |
-   ReferencesResult::Override)));
+  for (const auto &[R, Context] : T.rangesWithPayload("overridedef"))
+ExpectedLocations.push_back(AllOf(rangeIs(R), containerIs(Context),
+  attrsAre(ReferencesResult::Declaration |
+   ReferencesResult::Definition |
+   ReferencesResult::Override)));
   for (const auto &P : T.points()) {
-EXPECT_THAT(findReferences(AST, P, 0, UseIndex ? TU.index().get() : nullptr)
+EXPECT_THAT(findReferences(AST, P, 0, UseIndex ? TU.index().get() : nullptr,
+   /*AddContext*/ true)
 .References,
 UnorderedElementsAreArray(ExpectedLocations))
 << "Failed for Refs at " << P << "\n"
@@ -1933,18 +1938,18 @@
   const char *Tests[] = {
   R"cpp(// Local variable
 int main() {
-  int $def[[foo]];
-  [[^foo]] = 2;
-  int test1 = [[foo]];
+  int $def(main)[[foo]];
+  $(main)[[^foo]] = 2;
+  int test1 = $(main)[[foo]];
 }
   )cpp",
 
   R"cpp(// Struct
 namespace ns1 {
-struct $def[[Foo]] {};
+struct $def(ns1)[[Foo]] {};
 } // namespace ns1
 int main() {
-  ns1::[[Fo^o]]* Params;
+  ns1::$(main)[[Fo^o]]* Params;
 }
   )cpp",
 
@@ -1952,51 +1957,51 @@
 class $decl[[Foo]];
 class $def[[Foo]] {};
 int main() {
-  [[Fo^o]] foo;
+  $(main

[PATCH] D140793: [clang-tidy] Implement CppCoreGuideline CP.53

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



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidReferenceCoroutineParametersCheck.cpp:31
+const MatchFinder::MatchResult &Result) {
+  const auto *Param = Result.Nodes.getNodeAs("param");
+

Check for nullptr before dereferencing. Typically it's done like:

  if (const auto *Param = Result.Nodes.getNodeAs("param"))
diag(Param->getBeginLoc(), ...);





Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidReferenceCoroutineParametersCheck.h:31
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  bool isLanguageVersionSupported(const LangOptions &LO) const override {
+return LO.CPlusPlus20;

Nit: this is called "LangOpts" in 157/159 checks, please rename for consistency.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-reference-coroutine-parameters.rst:20
+This check implements
+`CppCoreGuideline CP.53 
`_.

Add full link to this particular rule:

https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rcoro-reference-parameters


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140793

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


[PATCH] D133574: [C2x] reject type definitions in offsetof

2023-01-01 Thread Yingchi Long via Phabricator via cfe-commits
inclyc added a comment.

ping :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133574

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


[PATCH] D140543: [clang-format] Add an option to format integer literal separators

2023-01-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/docs/ClangFormatStyleOptions.rst:3168-3171
+  Separator format of integer literals of different bases.
+  <0: Remove separators.
+   0: Leave the literal as is.
+  >0: Insert separators between digits, starting from the rightmost digit.

This is causing the Sphinx build to fail:

Warning, treated as error:
/home/buildbot/llvm-build-dir/clang-sphinx-docs/llvm/build/tools/clang/docs/ClangFormatStyleOptions.rst:3170:Unexpected
 indentation.

https://lab.llvm.org/buildbot/#/builders/92/builds/38032

I think you need to remove one leading whitespace from line 3170 so that `0` 
aligns with `<` from the line above.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140543

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


[PATCH] D140800: Precompute OptTable prefixes union table through tablegen

2023-01-01 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Could we make this an optional opt-in maybe? I imagine for the majority of the 
tools, this has no measurable effect, but it currently makes the Opt library 
harder to use for every client.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140800

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


[PATCH] D140800: Precompute OptTable prefixes union table through tablegen

2023-01-01 Thread serge via Phabricator via cfe-commits
serge-sans-paille added a comment.

In D140800#4021228 , @thakis wrote:

> Could we make this an optional opt-in maybe? I imagine for the majority of 
> the tools, this has no measurable effect, but it currently makes the Opt 
> library harder to use for every client.

Sure, let's have two constructors, one that uses a precomputed table and one 
that does the precomputation.
Would you prefer having only clang use the faster-but-less efficient method, or 
can I keep the changes as is?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140800

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


[PATCH] D140800: Precompute OptTable prefixes union table through tablegen

2023-01-01 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

I'd only use it in clang tbh. Clang uses many orders of magnitudes more opts 
than all other tools, and even there it's not a _huge_ win. (2% on empty file 
is very nice! But most of the time, people don't compile empty files, and I'm 
guessing on non-empty files this is a negligible win even in clang.) What do 
you think?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140800

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


[clang] b027cdc - [clang-format][NFC] Clean up IntegerLiteralSeparatorFixer::process

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

Author: Owen Pan
Date: 2023-01-01T14:49:12-08:00
New Revision: b027cdc5b99f56fdfe6c6dbb05188675b94a1aa5

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

LOG: [clang-format][NFC] Clean up IntegerLiteralSeparatorFixer::process

Added: 


Modified: 
clang/lib/Format/IntegerLiteralSeparatorFixer.cpp

Removed: 




diff  --git a/clang/lib/Format/IntegerLiteralSeparatorFixer.cpp 
b/clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
index 4082a1cf8385..ef07ab06760b 100644
--- a/clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
+++ b/clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
@@ -78,10 +78,9 @@ IntegerLiteralSeparatorFixer::process(const Environment &Env,
   Lex.SetCommentRetentionState(true);
 
   Token Tok;
-  Lex.LexFromRawLexer(Tok);
-
   tooling::Replacements Result;
-  for (bool Skip = false; Tok.isNot(tok::eof); Lex.LexFromRawLexer(Tok)) {
+
+  for (bool Skip = false; !Lex.LexFromRawLexer(Tok);) {
 auto Length = Tok.getLength();
 if (Length < 2)
   continue;



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


[clang] ed4afd1 - [clang-format][docs] Fix indentation for the Sphinx build

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

Author: Owen Pan
Date: 2023-01-01T15:13:36-08:00
New Revision: ed4afd1bba8347e1d7ea943c242fccabf606489c

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

LOG: [clang-format][docs] Fix indentation for the Sphinx build

See https://reviews.llvm.org/D140543#4021209.

Added: 


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

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 989c91e9a3ef..b69a1158acfd 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -3166,9 +3166,9 @@ the configuration (without a prefix: ``Auto``).
   Nested configuration flags:
 
   Separator format of integer literals of 
diff erent bases.
-  <0: Remove separators.
-   0: Leave the literal as is.
-  >0: Insert separators between digits, starting from the rightmost digit.
+  If <0: Remove separators.
+  If  0: Leave the literal as is.
+  If >0: Insert separators between digits starting from the rightmost digit.
 
   * ``int8_t Binary`` .. code-block:: c++
 

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 9162028c53ed..514ef16d8708 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2451,9 +2451,9 @@ struct FormatStyle {
   TrailingCommaStyle InsertTrailingCommas;
 
   /// Separator format of integer literals of 
diff erent bases.
-  /// <0: Remove separators.
-  ///  0: Leave the literal as is.
-  /// >0: Insert separators between digits, starting from the rightmost digit.
+  /// If <0: Remove separators.
+  /// If  0: Leave the literal as is.
+  /// If >0: Insert separators between digits starting from the rightmost 
digit.
   struct IntegerLiteralSeparatorStyle {
 /// \code
 ///-1: 0b10001101



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


[PATCH] D140793: [clang-tidy] Implement CppCoreGuideline CP.53

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

- Cleanups


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140793

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidReferenceCoroutineParametersCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidReferenceCoroutineParametersCheck.h
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-reference-coroutine-parameters.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst


Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -182,7 +182,7 @@
`cppcoreguidelines-avoid-do-while `_,
`cppcoreguidelines-avoid-goto `_,
`cppcoreguidelines-avoid-non-const-global-variables 
`_,
-   `cppcoreguidelines-avoid-reference-coroutine-parameters 
`_, "Yes"
+   `cppcoreguidelines-avoid-reference-coroutine-parameters 
`_,
`cppcoreguidelines-init-variables 
`_, "Yes"
`cppcoreguidelines-interfaces-global-init 
`_,
`cppcoreguidelines-macro-usage `_,
Index: 
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-reference-coroutine-parameters.rst
===
--- 
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-reference-coroutine-parameters.rst
+++ 
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-reference-coroutine-parameters.rst
@@ -17,4 +17,4 @@
   }
 
 This check implements
-`CppCoreGuideline CP.53 
`_.
+`CppCoreGuideline CP.53 
`_.
Index: 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidReferenceCoroutineParametersCheck.h
===
--- 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidReferenceCoroutineParametersCheck.h
+++ 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidReferenceCoroutineParametersCheck.h
@@ -23,11 +23,12 @@
 /// 
http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/avoid-reference-coroutine-parameters.html
 class AvoidReferenceCoroutineParametersCheck : public ClangTidyCheck {
 public:
-  AvoidReferenceCoroutineParametersCheck(StringRef Name, ClangTidyContext 
*Context)
+  AvoidReferenceCoroutineParametersCheck(StringRef Name,
+ ClangTidyContext *Context)
   : ClangTidyCheck(Name, Context) {}
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
-  bool isLanguageVersionSupported(const LangOptions &LO) const override {
+  bool isLanguageVersionSupported(const LangOpts &LO) const override {
 return LO.CPlusPlus20;
   }
 };
Index: 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidReferenceCoroutineParametersCheck.cpp
===
--- 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidReferenceCoroutineParametersCheck.cpp
+++ 
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidReferenceCoroutineParametersCheck.cpp
@@ -28,9 +28,9 @@
 
 void AvoidReferenceCoroutineParametersCheck::check(
 const MatchFinder::MatchResult &Result) {
-  const auto *Param = Result.Nodes.getNodeAs("param");
-
-  diag(Param->getBeginLoc(), "coroutine parameters should not be references");
+  if (const auto *Param = Result.Nodes.getNodeAs("param")) {
+diag(Param->getBeginLoc(), "coroutine parameters should not be 
references");
+  }
 }
 
 } // namespace cppcoreguidelines


Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -182,7 +182,7 @@
`cppcoreguidelines-avoid-do-while `_,
`cppcoreguidelines-avoid-goto `_,
`cppcoreguidelines-avoid-non-const-global-variables `_,
-   `cppcoreguidelines-avoid-reference-coroutine-parameters `_, "Yes"
+   `cppcoreguidelines-avoid-reference-coroutine-parameters `_,
`cppcoreguidelines-init-variables `_, "Yes"
`cppcoreguidelines-interfaces-global-init `_,
`cppcoreguidelines-macro-usage `_,
Index: clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-reference-coroutine-parameters.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-reference-coroutine-parameters.rst
+++ clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-reference-coroutine-parameters.rst
@@ -17,4 +17,4 @@
   }
 
 This check implements
-`CppCoreGuideline CP.53 

[PATCH] D140793: [clang-tidy] Implement CppCoreGuideline CP.53

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

- oops - bad arc diff / bad change


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140793

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidReferenceCoroutineParametersCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidReferenceCoroutineParametersCheck.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-reference-coroutine-parameters.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-reference-coroutine-parameters.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-reference-coroutine-parameters.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-reference-coroutine-parameters.cpp
@@ -0,0 +1,84 @@
+// RUN: %check_clang_tidy -std=c++20 %s cppcoreguidelines-avoid-reference-coroutine-parameters %t
+
+// NOLINTBEGIN
+namespace std {
+  template 
+  struct coroutine_traits {
+using promise_type = typename T::promise_type;
+  };
+  template 
+  struct coroutine_handle;
+  template <>
+  struct coroutine_handle {
+coroutine_handle() noexcept;
+coroutine_handle(decltype(nullptr)) noexcept;
+static constexpr coroutine_handle from_address(void*);
+  };
+  template 
+  struct coroutine_handle {
+coroutine_handle() noexcept;
+coroutine_handle(decltype(nullptr)) noexcept;
+static constexpr coroutine_handle from_address(void*);
+operator coroutine_handle<>() const noexcept;
+  };
+} // namespace std
+
+struct Awaiter {
+  bool await_ready() noexcept;
+  void await_suspend(std::coroutine_handle<>) noexcept;
+  void await_resume() noexcept;
+};
+
+struct Coro {
+  struct promise_type {
+Awaiter initial_suspend();
+Awaiter final_suspend() noexcept;
+void return_void();
+Coro get_return_object();
+void unhandled_exception();
+  };
+};
+// NOLINTEND
+
+struct Obj {};
+
+Coro no_args() {
+  co_return;
+}
+
+Coro no_references(int x, int* y, Obj z, const Obj w) {
+  co_return;
+}
+
+Coro accepts_references(int& x, const int &y) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: coroutine parameters should not be references [cppcoreguidelines-avoid-reference-coroutine-parameters]
+  // CHECK-MESSAGES: :[[@LINE-2]]:33: warning: coroutine parameters should not be references [cppcoreguidelines-avoid-reference-coroutine-parameters]
+  co_return;
+}
+
+Coro accepts_references_and_non_references(int& x, int y) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:44: warning: coroutine parameters should not be references [cppcoreguidelines-avoid-reference-coroutine-parameters]
+  co_return;
+}
+
+Coro accepts_references_to_objects(Obj& x) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:36: warning: coroutine parameters should not be references [cppcoreguidelines-avoid-reference-coroutine-parameters]
+  co_return;
+}
+
+Coro non_coro_accepts_references(int& x) {
+  if (x);
+  return Coro{};
+}
+
+void defines_a_lambda() {
+  auto NoArgs = [](int x) -> Coro { co_return; };
+
+  auto NoReferences = [](int x) -> Coro { co_return; };
+
+  auto WithReferences = [](int& x) -> Coro { co_return; };
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: coroutine parameters should not be references [cppcoreguidelines-avoid-reference-coroutine-parameters]
+
+  auto WithReferences2 = [](int&) -> Coro { co_return; };
+  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: coroutine parameters should not be references [cppcoreguidelines-avoid-reference-coroutine-parameters]
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -182,6 +182,7 @@
`cppcoreguidelines-avoid-do-while `_,
`cppcoreguidelines-avoid-goto `_,
`cppcoreguidelines-avoid-non-const-global-variables `_,
+   `cppcoreguidelines-avoid-reference-coroutine-parameters `_,
`cppcoreguidelines-init-variables `_, "Yes"
`cppcoreguidelines-interfaces-global-init `_,
`cppcoreguidelines-macro-usage `_,
Index: clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-reference-coroutine-parameters.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-reference-coroutine-parameters.rst
@@ -0,0 +1,20 @@
+.. title:: clang-tidy - cppcoreguidelines-avoid-reference-coroutine-parameters
+
+cppcoreguidelines-avoid-reference-coroutine-parameters
+==

[PATCH] D118743: [clang-tidy] Add `modernize-use-inline-const-variables-in-headers` check

2023-01-01 Thread Evgeny Shulgin via Phabricator via cfe-commits
Izaron added a comment.

In D118743#3965423 , @Lounarok wrote:

> I tried this patch and it's really helpful!

You're welcome!

> According to this ,  "A 
> `constexpr` specifier used in a function or `static` data member (since 
> C++17) declaration implies `inline`."

That's correct, for //functions// and //static data members//.

> However I found that it warns when it comes to `constexpr static` variable.
>
> Snippet: `constexpr static int UNDEFINED_ERROR{0};`
> Warning msg: `warning: global constant 'UNDEFINED_ERROR' should be marked as 
> 'inline' [modernize-use-inline-const-variables-in-headers]`
> According to this ,  "A 
> `constexpr` specifier used in a function or `static` data member (since 
> C++17) declaration implies `inline`." 
> It seems it should not warn on `constexpr static` variable.

`UNDEFINED_ERROR` is neither a //function// nor a //static data member//. 
Therefore a warning is meaningful. There is no `inline` implication in your 
case.

(//data member// is a variable inside a struct/class, but not a "freestanding" 
one)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118743

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


[PATCH] D140835: [clang-format] Improve UnwrappedLineParser::mightFitOnOneLine()

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

Account for an r_brace that precedes an "else if" statement when calculating 
whether the line might fit on one line if the r_brace is removed.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140835

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


Index: clang/unittests/Format/BracesRemoverTest.cpp
===
--- clang/unittests/Format/BracesRemoverTest.cpp
+++ clang/unittests/Format/BracesRemoverTest.cpp
@@ -828,6 +828,17 @@
"}",
Style);
 
+  verifyFormat("if (foo)\n"
+   "  f();\n"
+   "else if (bar || baz)\n"
+   "  g();",
+   "if (foo) {\n"
+   "  f();\n"
+   "} else if (bar || baz) {\n"
+   "  g();\n"
+   "}",
+   Style);
+
   Style.ColumnLimit = 0;
   verifyFormat("if (a)\n"
"  b234567890223456789032345678904234567890 = "
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -836,6 +836,11 @@
 Length -= OpeningBrace->TokenText.size() + 1;
   }
 
+  if (const auto *FirstToken = Line.First; FirstToken->is(tok::r_brace)) {
+assert(!OpeningBrace || OpeningBrace->is(TT_ControlStatementLBrace));
+Length -= FirstToken->TokenText.size() + 1;
+  }
+
   Index = 0;
   for (auto &Token : Tokens) {
 const auto &SavedToken = SavedTokens[Index++];


Index: clang/unittests/Format/BracesRemoverTest.cpp
===
--- clang/unittests/Format/BracesRemoverTest.cpp
+++ clang/unittests/Format/BracesRemoverTest.cpp
@@ -828,6 +828,17 @@
"}",
Style);
 
+  verifyFormat("if (foo)\n"
+   "  f();\n"
+   "else if (bar || baz)\n"
+   "  g();",
+   "if (foo) {\n"
+   "  f();\n"
+   "} else if (bar || baz) {\n"
+   "  g();\n"
+   "}",
+   Style);
+
   Style.ColumnLimit = 0;
   verifyFormat("if (a)\n"
"  b234567890223456789032345678904234567890 = "
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -836,6 +836,11 @@
 Length -= OpeningBrace->TokenText.size() + 1;
   }
 
+  if (const auto *FirstToken = Line.First; FirstToken->is(tok::r_brace)) {
+assert(!OpeningBrace || OpeningBrace->is(TT_ControlStatementLBrace));
+Length -= FirstToken->TokenText.size() + 1;
+  }
+
   Index = 0;
   for (auto &Token : Tokens) {
 const auto &SavedToken = SavedTokens[Index++];
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140270: MIPS: fix build from IR files, nan2008 and FpAbi

2023-01-01 Thread Nathan Chancellor via Phabricator via cfe-commits
nathanchance added a comment.

This does not show any issues with any of the MIPS configurations that I build 
in the Linux kernel, thanks for fixing the problems I reported!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140270

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


[PATCH] D140838: [clang] fix crash on generic lambda with lambda in decltype

2023-01-01 Thread Vincent Hong via Phabricator via cfe-commits
v1nh1shungry created this revision.
v1nh1shungry added reviewers: aaron.ballman, shafik.
Herald added a project: All.
v1nh1shungry requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Relevant issue: https://github.com/llvm/llvm-project/issues/59771

During the instantiation of a generic lambda, a non-generic lambda in
the trailing `decltype` is a `DeclContext` but not a dependent context,
so we shouldn't call `PerformDependentDiagnostics` on it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140838

Files:
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/SemaCXX/lambda-unevaluated.cpp


Index: clang/test/SemaCXX/lambda-unevaluated.cpp
===
--- clang/test/SemaCXX/lambda-unevaluated.cpp
+++ clang/test/SemaCXX/lambda-unevaluated.cpp
@@ -144,3 +144,7 @@
 using d = decltype(sizeof([] static { return 0; }));
 
 }
+
+namespace lambda_in_trailing_decltype {
+auto x = ([](auto) -> decltype([] {}()) {}(0), 2);
+}
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1230,7 +1230,7 @@
 
   // We recreated a local declaration, but not by instantiating it. There
   // may be pending dependent diagnostics to produce.
-  if (auto *DC = dyn_cast(Old))
+  if (auto *DC = dyn_cast(Old); DC && 
DC->isDependentContext())
 SemaRef.PerformDependentDiagnostics(DC, TemplateArgs);
 }
 


Index: clang/test/SemaCXX/lambda-unevaluated.cpp
===
--- clang/test/SemaCXX/lambda-unevaluated.cpp
+++ clang/test/SemaCXX/lambda-unevaluated.cpp
@@ -144,3 +144,7 @@
 using d = decltype(sizeof([] static { return 0; }));
 
 }
+
+namespace lambda_in_trailing_decltype {
+auto x = ([](auto) -> decltype([] {}()) {}(0), 2);
+}
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1230,7 +1230,7 @@
 
   // We recreated a local declaration, but not by instantiating it. There
   // may be pending dependent diagnostics to produce.
-  if (auto *DC = dyn_cast(Old))
+  if (auto *DC = dyn_cast(Old); DC && DC->isDependentContext())
 SemaRef.PerformDependentDiagnostics(DC, TemplateArgs);
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits