[PATCH] D143091: [clang-format] PackConstructorInitializers support PCIS_NextLineOnly

2023-02-05 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added inline comments.



Comment at: clang/docs/ClangFormatStyleOptions.rst:3891
 
+  * ``PCIS_OnlyNextLine`` (in configuration: ``OnlyNextLine``)
+Put all constructor initializers on the next line if they fit.

owenpan wrote:
> Backl1ght wrote:
> > @HazardyKnusperkeks Maybe I misunderstand something, I think I already add 
> > an entry here by running `clang/docs/tools/dump_format_style.py`.
> `NextLineOnly` instead?
> @HazardyKnusperkeks   Maybe I misunderstand something, I think I already add 
> an entry here by running `clang/docs/tools/dump_format_style.py`.

This is the documentation about the configuration. I was talking about an entry 
in the `clang/docs/ReleaseNotes.rst`.


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

https://reviews.llvm.org/D143091

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


[PATCH] D142077: [Clang][SemaCXX][Coroutines] Fix misleading diagnostics with -Wunsequenced

2023-02-05 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added inline comments.



Comment at: clang/lib/Sema/SemaChecking.cpp:15186
+  if (ChildExpr == CSE->getOperand())
+// Do not recurse over a CoroutineSuspendExpr's operand.
+// The operand is also a subexpression of getCommonExpr(), and

bruno wrote:
> ChuanqiXu wrote:
> > nridge wrote:
> > > Out of curiosity, since `getCommonExpr()` is itself a subexpression of 
> > > `getReadyExpr()`, `getSuspendExpr()`, and `getResumeExpr()` (which are 
> > > also children of the `CoroutineSuspendExpr`), shouldn't `getCommonExpr()` 
> > > be skipped for the same reason?
> > >  since getCommonExpr() is itself a subexpression of getReadyExpr(), 
> > > getSuspendExpr(), and getResumeExpr()
> > 
> > This looks not true. For this example:
> > 
> > ```
> > co_await foo();
> > ```
> > 
> > `foo()` is the Operand. And the Common is `auto __tmp__ = operator 
> > co_await(foo())`. ReadyExpr should be `__tmp__.await_ready();`. SuspendExpr 
> > should be `__tmp__.await_suspend();` and ResumeExpr should be 
> > `__tmp__.await_resume();`.
> > 
> > So the method here looks good to me.
> 
> > `foo()` is the Operand. And the Common is `auto __tmp__ = operator 
> > co_await(foo())`. ReadyExpr should be `__tmp__.await_ready();`. SuspendExpr 
> > should be `__tmp__.await_suspend();` and ResumeExpr should be 
> > `__tmp__.await_resume();`.
> 
> Exactly!
> 
> 
Thank you for the explanation! I overlooked the fact that 
ReadyExpr/SuspendExpr/ResumeExpr use an 
[OpaqueValueExpr](https://searchfox.org/llvm/rev/4b051b4248bb6f9971dd1cf87fe311ebe9be917e/clang/lib/Sema/SemaCoroutine.cpp#378-379)
 wrapping CommonExpr rather than using CommonExpr directly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142077

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


[PATCH] D142606: Lazyly initialize uncommon toolchain detector

2023-02-05 Thread serge via Phabricator via cfe-commits
serge-sans-paille updated this revision to Diff 494877.
serge-sans-paille added a comment.

remove mutable qualifier


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

https://reviews.llvm.org/D142606

Files:
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
  clang/lib/Driver/ToolChains/FreeBSD.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Gnu.h
  clang/lib/Driver/ToolChains/HIPAMD.cpp
  clang/lib/Driver/ToolChains/LazyDetector.h
  clang/lib/Driver/ToolChains/Linux.cpp

Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -681,23 +681,23 @@
 
 void Linux::AddCudaIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const {
-  CudaInstallation.AddCudaIncludeArgs(DriverArgs, CC1Args);
+  CudaInstallation->AddCudaIncludeArgs(DriverArgs, CC1Args);
 }
 
 void Linux::AddHIPIncludeArgs(const ArgList &DriverArgs,
   ArgStringList &CC1Args) const {
-  RocmInstallation.AddHIPIncludeArgs(DriverArgs, CC1Args);
+  RocmInstallation->AddHIPIncludeArgs(DriverArgs, CC1Args);
 }
 
 void Linux::AddHIPRuntimeLibArgs(const ArgList &Args,
  ArgStringList &CmdArgs) const {
   CmdArgs.push_back(
-  Args.MakeArgString(StringRef("-L") + RocmInstallation.getLibPath()));
+  Args.MakeArgString(StringRef("-L") + RocmInstallation->getLibPath()));
 
   if (Args.hasFlag(options::OPT_offload_add_rpath,
options::OPT_no_offload_add_rpath, false))
 CmdArgs.append(
-{"-rpath", Args.MakeArgString(RocmInstallation.getLibPath())});
+{"-rpath", Args.MakeArgString(RocmInstallation->getLibPath())});
 
   CmdArgs.push_back("-lamdhip64");
 }
Index: clang/lib/Driver/ToolChains/LazyDetector.h
===
--- /dev/null
+++ clang/lib/Driver/ToolChains/LazyDetector.h
@@ -0,0 +1,46 @@
+//===--- LazyDetector.h - Lazy ToolChain Detection --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_LAZYDETECTOR_H
+#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_LAZYDETECTOR_H
+
+#include "clang/Driver/Tool.h"
+#include "clang/Driver/ToolChain.h"
+#include 
+
+namespace clang {
+
+/// Simple wrapper for toolchain detector with costly initialization. This
+/// delays the creation of the actual detector until its first usage.
+
+template  class LazyDetector {
+  const driver::Driver &D;
+  const llvm::Triple &Triple;
+  const llvm::opt::ArgList &Args;
+
+  std::optional Detector;
+
+public:
+  LazyDetector(const driver::Driver &D, const llvm::Triple &Triple,
+   const llvm::opt::ArgList &Args)
+  : D(D), Triple(Triple), Args(Args) {}
+  T *operator->() {
+if (!Detector) {
+  Detector.emplace(D, Triple, Args);
+}
+return &Detector.value();
+  }
+  T const *operator->() const {
+return const_cast(
+const_cast(*this).operator->());
+  }
+};
+
+} // end namespace clang
+
+#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_LAZYDETECTOR_H
Index: clang/lib/Driver/ToolChains/HIPAMD.cpp
===
--- clang/lib/Driver/ToolChains/HIPAMD.cpp
+++ clang/lib/Driver/ToolChains/HIPAMD.cpp
@@ -315,7 +315,7 @@
 
 void HIPAMDToolChain::AddHIPIncludeArgs(const ArgList &DriverArgs,
 ArgStringList &CC1Args) const {
-  RocmInstallation.AddHIPIncludeArgs(DriverArgs, CC1Args);
+  RocmInstallation->AddHIPIncludeArgs(DriverArgs, CC1Args);
 }
 
 SanitizerMask HIPAMDToolChain::getSupportedSanitizers() const {
@@ -344,7 +344,7 @@
   ArgStringList LibraryPaths;
 
   // Find in --hip-device-lib-path and HIP_LIBRARY_PATH.
-  for (StringRef Path : RocmInstallation.getRocmDeviceLibPathArg())
+  for (StringRef Path : RocmInstallation->getRocmDeviceLibPathArg())
 LibraryPaths.push_back(DriverArgs.MakeArgString(Path));
 
   addDirectoryList(DriverArgs, LibraryPaths, "", "HIP_DEVICE_LIB_PATH");
@@ -366,7 +366,7 @@
   getDriver().Diag(diag::err_drv_no_such_file) << BCName;
 });
   } else {
-if (!RocmInstallation.hasDeviceLibrary()) {
+if (!RocmInstallation->hasDeviceLibrary()) {
   getDriver().Diag(diag::err_drv_no_rocm_device_lib) << 0;
   return {};
 }
@@ -377,7 +377,7 @@
 if (DriverArgs.hasFlag(options::OPT_fgpu_sanitize,
options::OPT_fno_gpu_sanitize, true) &&
 getSanitizerArgs(DriverArgs).needsAsanRt()) {
-  auto AsanRTL = RocmInstallation.getAsanRTLPath();
+  auto As

[PATCH] D142606: Lazyly initialize uncommon toolchain detector

2023-02-05 Thread serge via Phabricator via cfe-commits
serge-sans-paille added inline comments.



Comment at: clang/lib/Driver/ToolChains/LazyDetector.h:26
+
+  mutable std::optional Detector;
+

zero9178 wrote:
> serge-sans-paille wrote:
> > zero9178 wrote:
> > > Any reason this is `mutable`? I don't see it being used a non-const way 
> > > in a const method
> > yeah, `T const *operator->() const` updates the optional by actually 
> > creating the value. (`std::optional::empalce` is not const)
> Your `T const *operator->() const` method does not do so, `T *operator->()` 
> does, which is non-const and hence can call `emplace` without issues. 
> So as far as C++ goes it is not required. 
gotcha :-)


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

https://reviews.llvm.org/D142606

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


[PATCH] D142606: Lazyly initialize uncommon toolchain detector

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



Comment at: clang/lib/Driver/ToolChains/LazyDetector.h:36
+}
+return &Detector.value();
+  }

Is the `.value()` here permitted? AFAIK the convention is to always use 
`operator*`.

And I think @aaron.ballman would tell you to drop the `{}` around that 
single-statement `if` :)


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

https://reviews.llvm.org/D142606

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


[PATCH] D143334: [clang][Interp] Fix diagnosing uninitialized ctor record arrays

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

No idea why I used `isa(ElemType.getTypePtr())` here, but it broke 
detecting that the element type is of record type.

Other than that, I think a previous patch made it possible to enable those two 
tests that have been disabled so far.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143334

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


Index: clang/test/AST/Interp/cxx20.cpp
===
--- clang/test/AST/Interp/cxx20.cpp
+++ clang/test/AST/Interp/cxx20.cpp
@@ -138,8 +138,8 @@
 namespace UninitializedFields {
   class A {
   public:
-int a; // expected-note 2{{subobject declared here}} \
-   // ref-note 2{{subobject declared here}}
+int a; // expected-note 3{{subobject declared here}} \
+   // ref-note 3{{subobject declared here}}
 constexpr A() {}
   };
   constexpr A a; // expected-error {{must be initialized by a constant 
expression}} \
@@ -174,10 +174,6 @@
// ref-error {{must be initialized by a constant 
expression}} \
// ref-note {{subobject of type 'int' is not initialized}}
 
-
-  // FIXME: These two are currently disabled because the array fields
-  //   cannot be initialized.
-#if 0
   class C3 {
   public:
 A a[2];
@@ -198,7 +194,6 @@
// expected-note {{subobject of type 'bool' is not 
initialized}} \
// ref-error {{must be initialized by a constant 
expression}} \
// ref-note {{subobject of type 'bool' is not initialized}}
-#endif
 };
 
 namespace ConstThis {
Index: clang/lib/AST/Interp/Interp.cpp
===
--- clang/lib/AST/Interp/Interp.cpp
+++ clang/lib/AST/Interp/Interp.cpp
@@ -387,7 +387,7 @@
   size_t NumElems = CAT->getSize().getZExtValue();
   QualType ElemType = CAT->getElementType();
 
-  if (isa(ElemType.getTypePtr())) {
+  if (ElemType->isRecordType()) {
 const Record *R = BasePtr.getElemRecord();
 for (size_t I = 0; I != NumElems; ++I) {
   Pointer ElemPtr = BasePtr.atIndex(I).narrow();


Index: clang/test/AST/Interp/cxx20.cpp
===
--- clang/test/AST/Interp/cxx20.cpp
+++ clang/test/AST/Interp/cxx20.cpp
@@ -138,8 +138,8 @@
 namespace UninitializedFields {
   class A {
   public:
-int a; // expected-note 2{{subobject declared here}} \
-   // ref-note 2{{subobject declared here}}
+int a; // expected-note 3{{subobject declared here}} \
+   // ref-note 3{{subobject declared here}}
 constexpr A() {}
   };
   constexpr A a; // expected-error {{must be initialized by a constant expression}} \
@@ -174,10 +174,6 @@
// ref-error {{must be initialized by a constant expression}} \
// ref-note {{subobject of type 'int' is not initialized}}
 
-
-  // FIXME: These two are currently disabled because the array fields
-  //   cannot be initialized.
-#if 0
   class C3 {
   public:
 A a[2];
@@ -198,7 +194,6 @@
// expected-note {{subobject of type 'bool' is not initialized}} \
// ref-error {{must be initialized by a constant expression}} \
// ref-note {{subobject of type 'bool' is not initialized}}
-#endif
 };
 
 namespace ConstThis {
Index: clang/lib/AST/Interp/Interp.cpp
===
--- clang/lib/AST/Interp/Interp.cpp
+++ clang/lib/AST/Interp/Interp.cpp
@@ -387,7 +387,7 @@
   size_t NumElems = CAT->getSize().getZExtValue();
   QualType ElemType = CAT->getElementType();
 
-  if (isa(ElemType.getTypePtr())) {
+  if (ElemType->isRecordType()) {
 const Record *R = BasePtr.getElemRecord();
 for (size_t I = 0; I != NumElems; ++I) {
   Pointer ElemPtr = BasePtr.atIndex(I).narrow();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2023-02-05 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp updated this revision to Diff 494885.
carlosgalvezp added a comment.
Herald added a subscriber: arphaman.

- Apply fix to remaining checks.
- Fix documentation and release notes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142655

Files:
  clang-tools-extra/clang-tidy/ClangTidyCheck.h
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/FileExtensionsSet.h
  clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
  clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.h
  clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.cpp
  clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.h
  clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp
  clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.h
  clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
  clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.h
  clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
  clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.h
  clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
  clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.h
  clang-tools-extra/clang-tidy/utils/HeaderGuard.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-include.rst
  clang-tools-extra/docs/clang-tidy/checks/google/build-namespaces.rst
  clang-tools-extra/docs/clang-tidy/checks/google/global-names-in-headers.rst
  clang-tools-extra/docs/clang-tidy/checks/llvm/header-guard.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/definitions-in-headers.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/unused-using-decls.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/use-anonymous-namespace.rst
  clang-tools-extra/docs/clang-tidy/index.rst
  clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp
  clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
@@ -76,13 +76,20 @@
 
 TEST(ParseConfiguration, ValidConfiguration) {
   llvm::ErrorOr Options =
-  parseConfiguration(llvm::MemoryBufferRef("Checks: \"-*,misc-*\"\n"
-   "HeaderFilterRegex: \".*\"\n"
-   "AnalyzeTemporaryDtors: true\n"
-   "User: some.user",
-   "Options"));
+  parseConfiguration(llvm::MemoryBufferRef(
+  "Checks: \"-*,misc-*\"\n"
+  "HeaderFileExtensions: [\"\",\"h\",\"hh\",\"hpp\",\"hxx\"]\n"
+  "ImplementationFileExtensions: [\"c\",\"cc\",\"cpp\",\"cxx\"]\n"
+  "HeaderFilterRegex: \".*\"\n"
+  "AnalyzeTemporaryDtors: true\n"
+  "User: some.user",
+  "Options"));
   EXPECT_TRUE(!!Options);
   EXPECT_EQ("-*,misc-*", *Options->Checks);
+  EXPECT_EQ(std::vector({"", "h", "hh", "hpp", "hxx"}),
+*Options->HeaderFileExtensions);
+  EXPECT_EQ(std::vector({"c", "cc", "cpp", "cxx"}),
+*Options->ImplementationFileExtensions);
   EXPECT_EQ(".*", *Options->HeaderFilterRegex);
   EXPECT_EQ("some.user", *Options->User);
 }
@@ -105,6 +112,8 @@
   llvm::ErrorOr Options1 =
   parseConfiguration(llvm::MemoryBufferRef(R"(
   Checks: "check1,check2"
+  HeaderFileExtensions: ["h","hh"]
+  ImplementationFileExtensions: ["c","cc"]
   HeaderFilterRegex: "filter1"
   AnalyzeTemporaryDtors: true
   User: user1
@@ -117,6 +126,8 @@
   llvm::ErrorOr Options2 =
   parseConfiguration(llvm::MemoryBufferRef(R"(
   Checks: "check3,check4"
+  HeaderFileExtensions: ["hpp","hxx"]
+  ImplementationFileExtensions: ["cpp","cxx"]
   HeaderFilterRegex: "filter2"
   AnalyzeTemporaryDtors: false
   User: user2
@@ -128,6 +139,10 @@
   ASSERT_TRUE(!!Options2);
   ClangTidyOptions Options = Options1->merge(*Options2, 0);
   EXPECT_EQ("check1,check2,check3,check4", *Options.Checks);
+  EXPECT_EQ(std::vector({"hpp", "hxx"}),
+*Options.HeaderFileExtensions);
+  EXPECT_EQ(std::vector({"cpp", "cxx"}),
+*Options.ImplementationFileExtensions);
   EXPECT_EQ("filter2", *Options

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

2023-02-05 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp updated this revision to Diff 494886.
carlosgalvezp retitled this revision from "[WIP][clang-tidy] Introduce 
HeaderFileExtensions and ImplementationFileExtensions options" to "[clang-tidy] 
Introduce HeaderFileExtensions and ImplementationFileExtensions options".
carlosgalvezp edited the summary of this revision.
carlosgalvezp added a comment.

Update commit message


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142655

Files:
  clang-tools-extra/clang-tidy/ClangTidyCheck.h
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/FileExtensionsSet.h
  clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
  clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.h
  clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.cpp
  clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.h
  clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp
  clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.h
  clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
  clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.h
  clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
  clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.h
  clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
  clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.h
  clang-tools-extra/clang-tidy/utils/HeaderGuard.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-include.rst
  clang-tools-extra/docs/clang-tidy/checks/google/build-namespaces.rst
  clang-tools-extra/docs/clang-tidy/checks/google/global-names-in-headers.rst
  clang-tools-extra/docs/clang-tidy/checks/llvm/header-guard.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/definitions-in-headers.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/unused-using-decls.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/use-anonymous-namespace.rst
  clang-tools-extra/docs/clang-tidy/index.rst
  clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp
  clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
@@ -76,13 +76,20 @@
 
 TEST(ParseConfiguration, ValidConfiguration) {
   llvm::ErrorOr Options =
-  parseConfiguration(llvm::MemoryBufferRef("Checks: \"-*,misc-*\"\n"
-   "HeaderFilterRegex: \".*\"\n"
-   "AnalyzeTemporaryDtors: true\n"
-   "User: some.user",
-   "Options"));
+  parseConfiguration(llvm::MemoryBufferRef(
+  "Checks: \"-*,misc-*\"\n"
+  "HeaderFileExtensions: [\"\",\"h\",\"hh\",\"hpp\",\"hxx\"]\n"
+  "ImplementationFileExtensions: [\"c\",\"cc\",\"cpp\",\"cxx\"]\n"
+  "HeaderFilterRegex: \".*\"\n"
+  "AnalyzeTemporaryDtors: true\n"
+  "User: some.user",
+  "Options"));
   EXPECT_TRUE(!!Options);
   EXPECT_EQ("-*,misc-*", *Options->Checks);
+  EXPECT_EQ(std::vector({"", "h", "hh", "hpp", "hxx"}),
+*Options->HeaderFileExtensions);
+  EXPECT_EQ(std::vector({"c", "cc", "cpp", "cxx"}),
+*Options->ImplementationFileExtensions);
   EXPECT_EQ(".*", *Options->HeaderFilterRegex);
   EXPECT_EQ("some.user", *Options->User);
 }
@@ -105,6 +112,8 @@
   llvm::ErrorOr Options1 =
   parseConfiguration(llvm::MemoryBufferRef(R"(
   Checks: "check1,check2"
+  HeaderFileExtensions: ["h","hh"]
+  ImplementationFileExtensions: ["c","cc"]
   HeaderFilterRegex: "filter1"
   AnalyzeTemporaryDtors: true
   User: user1
@@ -117,6 +126,8 @@
   llvm::ErrorOr Options2 =
   parseConfiguration(llvm::MemoryBufferRef(R"(
   Checks: "check3,check4"
+  HeaderFileExtensions: ["hpp","hxx"]
+  ImplementationFileExtensions: ["cpp","cxx"]
   HeaderFilterRegex: "filter2"
   AnalyzeTemporaryDtors: false
   User: user2
@@ -128,6 +139,10 @@
   ASSERT_TRUE(!!Options2);
   ClangTidyOptions Options = Options1->merge(*Options2, 0);
   EXPECT_EQ("check1,check2,check3,check4", *Options.Checks);
+  EXPECT_EQ(std::vecto

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

2023-02-05 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp updated this revision to Diff 494888.
carlosgalvezp added a comment.

Use get functions from ClangTidyCheck instead of Context


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142655

Files:
  clang-tools-extra/clang-tidy/ClangTidyCheck.h
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/FileExtensionsSet.h
  clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
  clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.h
  clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.cpp
  clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.h
  clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp
  clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.h
  clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
  clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.h
  clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
  clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.h
  clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
  clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.h
  clang-tools-extra/clang-tidy/utils/HeaderGuard.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-include.rst
  clang-tools-extra/docs/clang-tidy/checks/google/build-namespaces.rst
  clang-tools-extra/docs/clang-tidy/checks/google/global-names-in-headers.rst
  clang-tools-extra/docs/clang-tidy/checks/llvm/header-guard.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/definitions-in-headers.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/unused-using-decls.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/use-anonymous-namespace.rst
  clang-tools-extra/docs/clang-tidy/index.rst
  clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp
  clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
@@ -76,13 +76,20 @@
 
 TEST(ParseConfiguration, ValidConfiguration) {
   llvm::ErrorOr Options =
-  parseConfiguration(llvm::MemoryBufferRef("Checks: \"-*,misc-*\"\n"
-   "HeaderFilterRegex: \".*\"\n"
-   "AnalyzeTemporaryDtors: true\n"
-   "User: some.user",
-   "Options"));
+  parseConfiguration(llvm::MemoryBufferRef(
+  "Checks: \"-*,misc-*\"\n"
+  "HeaderFileExtensions: [\"\",\"h\",\"hh\",\"hpp\",\"hxx\"]\n"
+  "ImplementationFileExtensions: [\"c\",\"cc\",\"cpp\",\"cxx\"]\n"
+  "HeaderFilterRegex: \".*\"\n"
+  "AnalyzeTemporaryDtors: true\n"
+  "User: some.user",
+  "Options"));
   EXPECT_TRUE(!!Options);
   EXPECT_EQ("-*,misc-*", *Options->Checks);
+  EXPECT_EQ(std::vector({"", "h", "hh", "hpp", "hxx"}),
+*Options->HeaderFileExtensions);
+  EXPECT_EQ(std::vector({"c", "cc", "cpp", "cxx"}),
+*Options->ImplementationFileExtensions);
   EXPECT_EQ(".*", *Options->HeaderFilterRegex);
   EXPECT_EQ("some.user", *Options->User);
 }
@@ -105,6 +112,8 @@
   llvm::ErrorOr Options1 =
   parseConfiguration(llvm::MemoryBufferRef(R"(
   Checks: "check1,check2"
+  HeaderFileExtensions: ["h","hh"]
+  ImplementationFileExtensions: ["c","cc"]
   HeaderFilterRegex: "filter1"
   AnalyzeTemporaryDtors: true
   User: user1
@@ -117,6 +126,8 @@
   llvm::ErrorOr Options2 =
   parseConfiguration(llvm::MemoryBufferRef(R"(
   Checks: "check3,check4"
+  HeaderFileExtensions: ["hpp","hxx"]
+  ImplementationFileExtensions: ["cpp","cxx"]
   HeaderFilterRegex: "filter2"
   AnalyzeTemporaryDtors: false
   User: user2
@@ -128,6 +139,10 @@
   ASSERT_TRUE(!!Options2);
   ClangTidyOptions Options = Options1->merge(*Options2, 0);
   EXPECT_EQ("check1,check2,check3,check4", *Options.Checks);
+  EXPECT_EQ(std::vector({"hpp", "hxx"}),
+*Options.HeaderFileExtensions);
+  EXPECT_EQ(std::vector({"cpp", "cxx"}),
+*Options.ImplementationFileExtensions);
   EXPECT_EQ("filter2", *Options.HeaderFilterRegex);
   EXPECT_EQ("user2", *Options.

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

2023-02-05 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp updated this revision to Diff 494889.
carlosgalvezp edited the summary of this revision.
carlosgalvezp added a comment.

Update commit message to clarify the difference
between the first attempt and this one.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142655

Files:
  clang-tools-extra/clang-tidy/ClangTidyCheck.h
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/FileExtensionsSet.h
  clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
  clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.h
  clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.cpp
  clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.h
  clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp
  clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.h
  clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
  clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.h
  clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
  clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.h
  clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
  clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.h
  clang-tools-extra/clang-tidy/utils/HeaderGuard.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-include.rst
  clang-tools-extra/docs/clang-tidy/checks/google/build-namespaces.rst
  clang-tools-extra/docs/clang-tidy/checks/google/global-names-in-headers.rst
  clang-tools-extra/docs/clang-tidy/checks/llvm/header-guard.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/definitions-in-headers.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/unused-using-decls.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/use-anonymous-namespace.rst
  clang-tools-extra/docs/clang-tidy/index.rst
  clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp
  clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
@@ -76,13 +76,20 @@
 
 TEST(ParseConfiguration, ValidConfiguration) {
   llvm::ErrorOr Options =
-  parseConfiguration(llvm::MemoryBufferRef("Checks: \"-*,misc-*\"\n"
-   "HeaderFilterRegex: \".*\"\n"
-   "AnalyzeTemporaryDtors: true\n"
-   "User: some.user",
-   "Options"));
+  parseConfiguration(llvm::MemoryBufferRef(
+  "Checks: \"-*,misc-*\"\n"
+  "HeaderFileExtensions: [\"\",\"h\",\"hh\",\"hpp\",\"hxx\"]\n"
+  "ImplementationFileExtensions: [\"c\",\"cc\",\"cpp\",\"cxx\"]\n"
+  "HeaderFilterRegex: \".*\"\n"
+  "AnalyzeTemporaryDtors: true\n"
+  "User: some.user",
+  "Options"));
   EXPECT_TRUE(!!Options);
   EXPECT_EQ("-*,misc-*", *Options->Checks);
+  EXPECT_EQ(std::vector({"", "h", "hh", "hpp", "hxx"}),
+*Options->HeaderFileExtensions);
+  EXPECT_EQ(std::vector({"c", "cc", "cpp", "cxx"}),
+*Options->ImplementationFileExtensions);
   EXPECT_EQ(".*", *Options->HeaderFilterRegex);
   EXPECT_EQ("some.user", *Options->User);
 }
@@ -105,6 +112,8 @@
   llvm::ErrorOr Options1 =
   parseConfiguration(llvm::MemoryBufferRef(R"(
   Checks: "check1,check2"
+  HeaderFileExtensions: ["h","hh"]
+  ImplementationFileExtensions: ["c","cc"]
   HeaderFilterRegex: "filter1"
   AnalyzeTemporaryDtors: true
   User: user1
@@ -117,6 +126,8 @@
   llvm::ErrorOr Options2 =
   parseConfiguration(llvm::MemoryBufferRef(R"(
   Checks: "check3,check4"
+  HeaderFileExtensions: ["hpp","hxx"]
+  ImplementationFileExtensions: ["cpp","cxx"]
   HeaderFilterRegex: "filter2"
   AnalyzeTemporaryDtors: false
   User: user2
@@ -128,6 +139,10 @@
   ASSERT_TRUE(!!Options2);
   ClangTidyOptions Options = Options1->merge(*Options2, 0);
   EXPECT_EQ("check1,check2,check3,check4", *Options.Checks);
+  EXPECT_EQ(std::vector({"hpp", "hxx"}),
+*Options.HeaderFileExtensions);
+  EXPECT_EQ(std::vector({"cpp", "cxx"}),
+*Options.ImplementationFileExtensions);
  

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

2023-02-05 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp updated this revision to Diff 494892.
carlosgalvezp added a comment.

Remove unneeded newlines and braces in single-line
if/else statements.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142655

Files:
  clang-tools-extra/clang-tidy/ClangTidyCheck.h
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/FileExtensionsSet.h
  clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
  clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.h
  clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.cpp
  clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.h
  clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp
  clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.h
  clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
  clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.h
  clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
  clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.h
  clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
  clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.h
  clang-tools-extra/clang-tidy/utils/HeaderGuard.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-include.rst
  clang-tools-extra/docs/clang-tidy/checks/google/build-namespaces.rst
  clang-tools-extra/docs/clang-tidy/checks/google/global-names-in-headers.rst
  clang-tools-extra/docs/clang-tidy/checks/llvm/header-guard.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/definitions-in-headers.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/unused-using-decls.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/use-anonymous-namespace.rst
  clang-tools-extra/docs/clang-tidy/index.rst
  clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp
  clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
@@ -76,13 +76,20 @@
 
 TEST(ParseConfiguration, ValidConfiguration) {
   llvm::ErrorOr Options =
-  parseConfiguration(llvm::MemoryBufferRef("Checks: \"-*,misc-*\"\n"
-   "HeaderFilterRegex: \".*\"\n"
-   "AnalyzeTemporaryDtors: true\n"
-   "User: some.user",
-   "Options"));
+  parseConfiguration(llvm::MemoryBufferRef(
+  "Checks: \"-*,misc-*\"\n"
+  "HeaderFileExtensions: [\"\",\"h\",\"hh\",\"hpp\",\"hxx\"]\n"
+  "ImplementationFileExtensions: [\"c\",\"cc\",\"cpp\",\"cxx\"]\n"
+  "HeaderFilterRegex: \".*\"\n"
+  "AnalyzeTemporaryDtors: true\n"
+  "User: some.user",
+  "Options"));
   EXPECT_TRUE(!!Options);
   EXPECT_EQ("-*,misc-*", *Options->Checks);
+  EXPECT_EQ(std::vector({"", "h", "hh", "hpp", "hxx"}),
+*Options->HeaderFileExtensions);
+  EXPECT_EQ(std::vector({"c", "cc", "cpp", "cxx"}),
+*Options->ImplementationFileExtensions);
   EXPECT_EQ(".*", *Options->HeaderFilterRegex);
   EXPECT_EQ("some.user", *Options->User);
 }
@@ -105,6 +112,8 @@
   llvm::ErrorOr Options1 =
   parseConfiguration(llvm::MemoryBufferRef(R"(
   Checks: "check1,check2"
+  HeaderFileExtensions: ["h","hh"]
+  ImplementationFileExtensions: ["c","cc"]
   HeaderFilterRegex: "filter1"
   AnalyzeTemporaryDtors: true
   User: user1
@@ -117,6 +126,8 @@
   llvm::ErrorOr Options2 =
   parseConfiguration(llvm::MemoryBufferRef(R"(
   Checks: "check3,check4"
+  HeaderFileExtensions: ["hpp","hxx"]
+  ImplementationFileExtensions: ["cpp","cxx"]
   HeaderFilterRegex: "filter2"
   AnalyzeTemporaryDtors: false
   User: user2
@@ -128,6 +139,10 @@
   ASSERT_TRUE(!!Options2);
   ClangTidyOptions Options = Options1->merge(*Options2, 0);
   EXPECT_EQ("check1,check2,check3,check4", *Options.Checks);
+  EXPECT_EQ(std::vector({"hpp", "hxx"}),
+*Options.HeaderFileExtensions);
+  EXPECT_EQ(std::vector({"cpp", "cxx"}),
+*Options.ImplementationFileExtensions);
   EXPECT_EQ("filter2", *Options.HeaderFilterRegex);
   EXPECT_EQ("use

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

2023-02-05 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp updated this revision to Diff 494893.
carlosgalvezp edited the summary of this revision.
carlosgalvezp added a comment.

Update commit message


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142655

Files:
  clang-tools-extra/clang-tidy/ClangTidyCheck.h
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/FileExtensionsSet.h
  clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
  clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.h
  clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.cpp
  clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.h
  clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp
  clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.h
  clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
  clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.h
  clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
  clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.h
  clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
  clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.h
  clang-tools-extra/clang-tidy/utils/HeaderGuard.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-include.rst
  clang-tools-extra/docs/clang-tidy/checks/google/build-namespaces.rst
  clang-tools-extra/docs/clang-tidy/checks/google/global-names-in-headers.rst
  clang-tools-extra/docs/clang-tidy/checks/llvm/header-guard.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/definitions-in-headers.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/unused-using-decls.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/use-anonymous-namespace.rst
  clang-tools-extra/docs/clang-tidy/index.rst
  clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp
  clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
@@ -76,13 +76,20 @@
 
 TEST(ParseConfiguration, ValidConfiguration) {
   llvm::ErrorOr Options =
-  parseConfiguration(llvm::MemoryBufferRef("Checks: \"-*,misc-*\"\n"
-   "HeaderFilterRegex: \".*\"\n"
-   "AnalyzeTemporaryDtors: true\n"
-   "User: some.user",
-   "Options"));
+  parseConfiguration(llvm::MemoryBufferRef(
+  "Checks: \"-*,misc-*\"\n"
+  "HeaderFileExtensions: [\"\",\"h\",\"hh\",\"hpp\",\"hxx\"]\n"
+  "ImplementationFileExtensions: [\"c\",\"cc\",\"cpp\",\"cxx\"]\n"
+  "HeaderFilterRegex: \".*\"\n"
+  "AnalyzeTemporaryDtors: true\n"
+  "User: some.user",
+  "Options"));
   EXPECT_TRUE(!!Options);
   EXPECT_EQ("-*,misc-*", *Options->Checks);
+  EXPECT_EQ(std::vector({"", "h", "hh", "hpp", "hxx"}),
+*Options->HeaderFileExtensions);
+  EXPECT_EQ(std::vector({"c", "cc", "cpp", "cxx"}),
+*Options->ImplementationFileExtensions);
   EXPECT_EQ(".*", *Options->HeaderFilterRegex);
   EXPECT_EQ("some.user", *Options->User);
 }
@@ -105,6 +112,8 @@
   llvm::ErrorOr Options1 =
   parseConfiguration(llvm::MemoryBufferRef(R"(
   Checks: "check1,check2"
+  HeaderFileExtensions: ["h","hh"]
+  ImplementationFileExtensions: ["c","cc"]
   HeaderFilterRegex: "filter1"
   AnalyzeTemporaryDtors: true
   User: user1
@@ -117,6 +126,8 @@
   llvm::ErrorOr Options2 =
   parseConfiguration(llvm::MemoryBufferRef(R"(
   Checks: "check3,check4"
+  HeaderFileExtensions: ["hpp","hxx"]
+  ImplementationFileExtensions: ["cpp","cxx"]
   HeaderFilterRegex: "filter2"
   AnalyzeTemporaryDtors: false
   User: user2
@@ -128,6 +139,10 @@
   ASSERT_TRUE(!!Options2);
   ClangTidyOptions Options = Options1->merge(*Options2, 0);
   EXPECT_EQ("check1,check2,check3,check4", *Options.Checks);
+  EXPECT_EQ(std::vector({"hpp", "hxx"}),
+*Options.HeaderFileExtensions);
+  EXPECT_EQ(std::vector({"cpp", "cxx"}),
+*Options.ImplementationFileExtensions);
   EXPECT_EQ("filter2", *Options.HeaderFilterRegex);
   EXPECT_EQ("u

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

2023-02-05 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp updated this revision to Diff 494894.
carlosgalvezp added a comment.

Fix release notes, ImplementationFileExtensions only
applies to one check.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142655

Files:
  clang-tools-extra/clang-tidy/ClangTidyCheck.h
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
  clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
  clang-tools-extra/clang-tidy/ClangTidyOptions.h
  clang-tools-extra/clang-tidy/FileExtensionsSet.h
  clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
  clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.h
  clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.cpp
  clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.h
  clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp
  clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.h
  clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
  clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.h
  clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
  clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.h
  clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
  clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.h
  clang-tools-extra/clang-tidy/utils/HeaderGuard.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/suspicious-include.rst
  clang-tools-extra/docs/clang-tidy/checks/google/build-namespaces.rst
  clang-tools-extra/docs/clang-tidy/checks/google/global-names-in-headers.rst
  clang-tools-extra/docs/clang-tidy/checks/llvm/header-guard.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/definitions-in-headers.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/unused-using-decls.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/use-anonymous-namespace.rst
  clang-tools-extra/docs/clang-tidy/index.rst
  clang-tools-extra/test/clang-tidy/infrastructure/verify-config.cpp
  clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
@@ -76,13 +76,20 @@
 
 TEST(ParseConfiguration, ValidConfiguration) {
   llvm::ErrorOr Options =
-  parseConfiguration(llvm::MemoryBufferRef("Checks: \"-*,misc-*\"\n"
-   "HeaderFilterRegex: \".*\"\n"
-   "AnalyzeTemporaryDtors: true\n"
-   "User: some.user",
-   "Options"));
+  parseConfiguration(llvm::MemoryBufferRef(
+  "Checks: \"-*,misc-*\"\n"
+  "HeaderFileExtensions: [\"\",\"h\",\"hh\",\"hpp\",\"hxx\"]\n"
+  "ImplementationFileExtensions: [\"c\",\"cc\",\"cpp\",\"cxx\"]\n"
+  "HeaderFilterRegex: \".*\"\n"
+  "AnalyzeTemporaryDtors: true\n"
+  "User: some.user",
+  "Options"));
   EXPECT_TRUE(!!Options);
   EXPECT_EQ("-*,misc-*", *Options->Checks);
+  EXPECT_EQ(std::vector({"", "h", "hh", "hpp", "hxx"}),
+*Options->HeaderFileExtensions);
+  EXPECT_EQ(std::vector({"c", "cc", "cpp", "cxx"}),
+*Options->ImplementationFileExtensions);
   EXPECT_EQ(".*", *Options->HeaderFilterRegex);
   EXPECT_EQ("some.user", *Options->User);
 }
@@ -105,6 +112,8 @@
   llvm::ErrorOr Options1 =
   parseConfiguration(llvm::MemoryBufferRef(R"(
   Checks: "check1,check2"
+  HeaderFileExtensions: ["h","hh"]
+  ImplementationFileExtensions: ["c","cc"]
   HeaderFilterRegex: "filter1"
   AnalyzeTemporaryDtors: true
   User: user1
@@ -117,6 +126,8 @@
   llvm::ErrorOr Options2 =
   parseConfiguration(llvm::MemoryBufferRef(R"(
   Checks: "check3,check4"
+  HeaderFileExtensions: ["hpp","hxx"]
+  ImplementationFileExtensions: ["cpp","cxx"]
   HeaderFilterRegex: "filter2"
   AnalyzeTemporaryDtors: false
   User: user2
@@ -128,6 +139,10 @@
   ASSERT_TRUE(!!Options2);
   ClangTidyOptions Options = Options1->merge(*Options2, 0);
   EXPECT_EQ("check1,check2,check3,check4", *Options.Checks);
+  EXPECT_EQ(std::vector({"hpp", "hxx"}),
+*Options.HeaderFileExtensions);
+  EXPECT_EQ(std::vector({"cpp", "cxx"}),
+*Options.ImplementationFileExtensions);
   EXPECT_EQ("filter2", *Options.HeaderFilterRegex);
   EXPECT_EQ(

[PATCH] D143318: [Support] Move ItaniumManglingCanonicalizer and SymbolRemappingReader from Support to ProfileData

2023-02-05 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added a comment.

In D143318#4104410 , @phosek wrote:

> Another alternative would be to move these classes to the Demangle library.

I'm happy to move this to LLVMDemangle instead if everyone agrees.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143318

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


[PATCH] D141939: [SVE][Builtins] Lower X forms of binop arithmetic builtins to dedicated intrinsics.

2023-02-05 Thread Paul Walker via Phabricator via cfe-commits
paulwalker-arm added inline comments.



Comment at: clang/include/clang/Basic/arm_sve.td:762
 
-multiclass SInstZPZZ flags=[]> {
-  def _M   : SInst;
-  def _X   : SInst;
-  def _Z   : SInst;
-
-  def _N_M : SInst;
-  def _N_X : SInst;
-  def _N_Z : SInst;
-}
-
-defm SVABD_S  : SInstZPZZ<"svabd",  "csil", "aarch64_sve_sabd">;
-defm SVABD_U  : SInstZPZZ<"svabd",  "UcUsUiUl", "aarch64_sve_uabd">;
-defm SVADD: SInstZPZZ<"svadd",  "csilUcUsUiUl", "aarch64_sve_add">;
-defm SVDIV_S  : SInstZPZZ<"svdiv",  "il",   "aarch64_sve_sdiv">;
-defm SVDIV_U  : SInstZPZZ<"svdiv",  "UiUl", "aarch64_sve_udiv">;
-defm SVDIVR_S : SInstZPZZ<"svdivr", "il",   "aarch64_sve_sdivr">;
-defm SVDIVR_U : SInstZPZZ<"svdivr", "UiUl", "aarch64_sve_udivr">;
-defm SVMAX_S  : SInstZPZZ<"svmax",  "csil", "aarch64_sve_smax">;
-defm SVMAX_U  : SInstZPZZ<"svmax",  "UcUsUiUl", "aarch64_sve_umax">;
-defm SVMIN_S  : SInstZPZZ<"svmin",  "csil", "aarch64_sve_smin">;
-defm SVMIN_U  : SInstZPZZ<"svmin",  "UcUsUiUl", "aarch64_sve_umin">;
-defm SVMUL: SInstZPZZ<"svmul",  "csilUcUsUiUl", "aarch64_sve_mul">;
-defm SVMULH_S : SInstZPZZ<"svmulh", "csil", "aarch64_sve_smulh">;
-defm SVMULH_U : SInstZPZZ<"svmulh", "UcUsUiUl", "aarch64_sve_umulh">;
-defm SVSUB: SInstZPZZ<"svsub",  "csilUcUsUiUl", "aarch64_sve_sub">;
-defm SVSUBR   : SInstZPZZ<"svsubr", "csilUcUsUiUl", "aarch64_sve_subr">;
+multiclass SInstZPZZ flags=[]> {
+  def _M   : SInst;

sdesmalen wrote:
> nit is it worth adding a `bit hasUndefVariant` and doing `!if 
> (hasUndefVariant, intrinsic # "_u", intrinsic)`?
Thanks for the suggestion but this assumes the `m` and `x` intrinsics have the 
same name, which for the reversed instructions is not the case (see SVDIVR_S 
for an example). It seemed wrong to add intrinsics for both `div_u` and 
`divr_u` given they're essentially the same operation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141939

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


[PATCH] D143091: [clang-format] PackConstructorInitializers support PCIS_NextLineOnly

2023-02-05 Thread Zhikai Zeng via Phabricator via cfe-commits
Backl1ght updated this revision to Diff 494903.
Backl1ght added a comment.

fix typo and add release note


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

https://reviews.llvm.org/D143091

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/ConfigParseTest.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -7289,6 +7289,19 @@
  Style);
 verifyFormat("Constructor() : a(a), b(b) {}", Style);
 
+Style.PackConstructorInitializers = FormatStyle::PCIS_NextLineOnly;
+verifyFormat("Constructor()\n"
+ ": (a), b(b) {}",
+ Style);
+verifyFormat("Constructor()\n"
+ ": a(a), b(b) {}",
+ Style);
+verifyFormat("Constructor()\n"
+ ": (a)\n"
+ ", b(b)\n"
+ ", cc(c) {}",
+ Style);
+
 Style.BreakConstructorInitializers = FormatStyle::BCIS_BeforeColon;
 Style.PackConstructorInitializers = FormatStyle::PCIS_NextLine;
 verifyFormat("Constructor()\n"
@@ -7301,6 +7314,19 @@
  "  b(b) {}",
  Style);
 
+Style.PackConstructorInitializers = FormatStyle::PCIS_NextLineOnly;
+verifyFormat("Constructor()\n"
+ ": (a), b(b) {}",
+ Style);
+verifyFormat("Constructor()\n"
+ ": a(a), b(b) {}",
+ Style);
+verifyFormat("Constructor()\n"
+ ": (a),\n"
+ "  b(b),\n"
+ "  cc(c) {}",
+ Style);
+
 Style.BreakConstructorInitializers = FormatStyle::BCIS_AfterColon;
 Style.PackConstructorInitializers = FormatStyle::PCIS_NextLine;
 verifyFormat("Constructor() :\n"
@@ -7312,6 +7338,19 @@
  "aa(a),\n"
  "b(b) {}",
  Style);
+
+Style.PackConstructorInitializers = FormatStyle::PCIS_NextLineOnly;
+verifyFormat("Constructor() :\n"
+ "aa(a), b(b) {}",
+ Style);
+verifyFormat("Constructor() :\n"
+ "a(a), b(b) {}",
+ Style);
+verifyFormat("Constructor() :\n"
+ "(a),\n"
+ "b(b),\n"
+ "cc(c) {}",
+ Style);
   }
 
   // Test interactions between AllowAllParametersOfDeclarationOnNextLine and
@@ -7319,6 +7358,7 @@
   // BreakConstructorInitializers modes
   Style.BreakConstructorInitializers = FormatStyle::BCIS_BeforeComma;
   Style.AllowAllParametersOfDeclarationOnNextLine = true;
+  Style.PackConstructorInitializers = FormatStyle::PCIS_CurrentLine;
   verifyFormat("SomeClassWithALongName::Constructor(\n"
"int , int b)\n"
": (a)\n"
@@ -7333,6 +7373,14 @@
": (a), b(b) {}",
Style);
 
+  Style.PackConstructorInitializers = FormatStyle::PCIS_NextLineOnly;
+  verifyFormat("SomeClassWithALongName::Constructor(\n"
+   "int ,\n"
+   "int b,\n"
+   "int )\n"
+   ": (a), b(b) {}",
+   Style);
+
   Style.AllowAllParametersOfDeclarationOnNextLine = false;
   Style.PackConstructorInitializers = FormatStyle::PCIS_CurrentLine;
   verifyFormat("SomeClassWithALongName::Constructor(\n"
@@ -7359,6 +7407,14 @@
": (a), b(b) {}",
Style);
 
+  Style.PackConstructorInitializers = FormatStyle::PCIS_NextLineOnly;
+  verifyFormat("SomeClassWithALongName::Constructor(\n"
+   "int ,\n"
+   "int b,\n"
+   "int )\n"
+   ": (a), b(b) {}",
+   Style);
+
   Style.AllowAllParametersOfDeclarationOnNextLine = false;
   Style.PackConstructorInitializers = FormatStyle::PCIS_CurrentLine;
   verifyFormat("SomeClassWithALongName::Constructor(\n"
@@ -7384,6 +7440,14 @@

[PATCH] D143325: [Driver] Add -mllvm= as an alias for -mllvm

2023-02-05 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl accepted this revision.
yaxunl added a comment.

LGTM. Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143325

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


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

2023-02-05 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp:31
+: ClangTidyCheck(Name, Context) {
+  std::optional HeaderFileExtensionsOption =
+  Options.get("HeaderFileExtensions");

Will be good idea to make function in `utils` instead of code duplication. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142655

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


[PATCH] D143342: [clang-tidy] Support std::format and std::print in readability-redundant-string-cstr

2023-02-05 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe created this revision.
mikecrowe added a reviewer: njames93.
mikecrowe added a project: clang-tools-extra.
Herald added subscribers: carlosgalvezp, xazax.hun.
Herald added a project: All.
mikecrowe requested review of this revision.
Herald added a subscriber: cfe-commits.

std::format (C++20) and std::print (C++23) are perfectly happy to accept
std::string parameters. Converting them to C-style strings by calling
c_str() is unnecessary and may cause extra walking of the string to
determine its length.

It's straightforward to teach readability-redundant-string-cstr to
identify the first such unnecessary call to c_str() in the parameter
list, but I was unable to come up with a way that worked for all the
parameters.

I was unable to come up with a way to make libstdc++'s format_string
first parameter to std::format and std::print work in the
redundant-string-cstr.cpp lit check. Using const char * is sufficient
though since that isn't the argument we're interested in.

I was able to successfully run the readability-redundant-string-cstr
check on a real source file that compiled successfully with what is
destined to become GCC 13, and saw the expected:

--8<--
/home/mac/git/llvm-project/build/bin/clang-tidy 
-checks=-*,readability-redundant-string-cstr format.cpp -- 
--gcc-toolchain=/home/mac/gcc-git
6 warnings generated.
/home/mac/src/random-hacks/std-format/format.cpp:13:39: warning: redundant call 
to 'c_str' [readability-redundant-string-cstr]

  std::puts(std::format("Hello {}", get().c_str()).c_str());
^
get()

Suppressed 5 warnings (5 with check filters).
-->8--


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143342

Files:
  clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
@@ -291,3 +291,59 @@
   Foo.func2((Str.c_str()));
 }
 } // namespace PR45286
+
+namespace std {
+  template
+  void print(const char *, Args &&...);
+  template
+  std::string format(const char *, Args &&...);
+}
+
+namespace notstd {
+  template
+  void print(const char *, Args &&...);
+  template
+  std::string format(const char *, Args &&...);
+}
+
+void std_print(const std::string &s1, const std::string &s2, const std::string 
&s3) {
+  std::print("One:{}\n", s1.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: redundant call to 'c_str' 
[readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}std::print("One:{}\n", s1);
+
+  // Ideally we'd fix both the second and fourth parameters here, but that 
doesn't work.
+  std::print("One:{} Two:{} Three:{}\n", s1.c_str(), s2, s3.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:42: warning: redundant call to 'c_str' 
[readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}std::print("One:{} Two:{} Three:{}\n", s1, s2, 
s3.c_str());
+}
+
+// There's no c_str() call here, so it shouldn't be touched.
+void std_print_no_cstr(const std::string &s1, const std::string &s2) {
+  std::print("One: {}, Two: {}\n", s1, s2);
+}
+
+// This isn't std::print, so it shouldn't be fixed.
+void not_std_print(const std::string &s1) {
+  notstd::print("One: {}\n", s1.c_str());
+}
+
+void std_format(const std::string &s1, const std::string &s2, const 
std::string &s3) {
+  auto r1 = std::format("One:{}\n", s1.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: redundant call to 'c_str' 
[readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}auto r1 = std::format("One:{}\n", s1);
+
+  // Ideally we'd fix both the second and fourth parameters here, but that 
doesn't work.
+  auto r2 = std::format("One:{} Two:{} Three:{}\n", s1.c_str(), s2, 
s3.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:53: warning: redundant call to 'c_str' 
[readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}auto r2 = std::format("One:{} Two:{} Three:{}\n", s1, 
s2, s3.c_str());
+}
+
+// There's are c_str() calls here, so it shouldn't be touched.
+std::string std_format_no_cstr(const std::string &s1, const std::string &s2) {
+  return std::format("One: {}, Two: {}\n", s1, s2);
+}
+
+// This is not std::format, so it shouldn't be fixed.
+std::string not_std_format(const std::string &s1) {
+  return notstd::format("One: {}\n", s1.c_str());
+}
Index: clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
@@ -178,6 +178,14 @@
   //

[PATCH] D143319: [clangd] Support iwyu pragma: no_include

2023-02-05 Thread Younan Zhang via Phabricator via cfe-commits
zyounan updated this revision to Diff 494911.
zyounan added a comment.
Herald added a subscriber: ormris.

Update tests && Use Preprocessor.LookupFile


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143319

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/Headers.h
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/index/CanonicalIncludes.h
  clang-tools-extra/clangd/unittests/HeadersTests.cpp
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp

Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -9,6 +9,7 @@
 #include "Annotations.h"
 #include "Config.h"
 #include "IncludeCleaner.h"
+#include "Protocol.h"
 #include "SourceCode.h"
 #include "TestFS.h"
 #include "TestTU.h"
@@ -22,8 +23,10 @@
 namespace clangd {
 namespace {
 
+using ::testing::AllOf;
 using ::testing::ElementsAre;
 using ::testing::ElementsAreArray;
+using ::testing::Field;
 using ::testing::IsEmpty;
 using ::testing::Pointee;
 using ::testing::UnorderedElementsAre;
@@ -611,6 +614,36 @@
   EXPECT_THAT(computeUnusedIncludesExperimental(AST), IsEmpty());
 }
 
+MATCHER_P(message, Message, "") { return arg.Message == Message; }
+MATCHER_P2(range, Start, End, "") {
+  return arg.start == Start && arg.end == End;
+}
+
+TEST(IncludeCleaner, IWYUPragmaNoInclude) {
+  TestTU TU;
+  TU.Code = R"cpp(
+#include "foo.h"
+#include "bar.h"
+// IWYU pragma: no_include "bar.h"
+  )cpp";
+  TU.AdditionalFiles["foo.h"] = guard("");
+  TU.AdditionalFiles["bar.h"] = guard("");
+  ParsedAST AST = TU.build();
+
+  auto Diags = issueNoIncludesDiagnostics(AST, TU.Code);
+  EXPECT_THAT(
+  Diags,
+  UnorderedElementsAre(AllOf(
+  message(
+  "included header 'bar.h' is marked as `no_include` at line 4"),
+  Field(&DiagBase::Range, range(Position{2, 0}, Position{2, 16});
+  ASSERT_TRUE(Diags.size() == 1);
+  ASSERT_TRUE(Diags.back().Fixes.size() == 1);
+  ASSERT_TRUE(Diags.back().Fixes.back().Edits.size() == 1);
+  EXPECT_THAT(Diags.back().Fixes.back().Edits.back().range,
+  range(Position{2, 0}, Position{3, 0}));
+}
+
 TEST(IncludeCleaner, NoDiagsForObjC) {
   TestTU TU;
   TU.Code = R"cpp(
Index: clang-tools-extra/clangd/unittests/HeadersTests.cpp
===
--- clang-tools-extra/clangd/unittests/HeadersTests.cpp
+++ clang-tools-extra/clangd/unittests/HeadersTests.cpp
@@ -93,7 +93,8 @@
   // Calculates the include path, or returns "" on error or header should not be
   // inserted.
   std::string calculate(PathRef Original, PathRef Preferred = "",
-const std::vector &Inclusions = {}) {
+const std::vector &Inclusions = {},
+const std::vector &IwyuNoIncludes = {}) {
 Clang = setupClang();
 PreprocessOnlyAction Action;
 EXPECT_TRUE(
@@ -111,6 +112,8 @@
  &Clang->getPreprocessor().getHeaderSearchInfo());
 for (const auto &Inc : Inclusions)
   Inserter.addExisting(Inc);
+for (const auto &Inc : IwyuNoIncludes)
+  Inserter.addNoInclude(Inc);
 auto Inserted = ToHeaderFile(Preferred);
 if (!Inserter.shouldInsertInclude(Original, Inserted))
   return "";
@@ -275,6 +278,47 @@
AllOf(written("\"bar.h\""), hasPragmaKeep(true;
 }
 
+TEST_F(HeadersTest, IWYUPragmaNoInclude) {
+  FS.Files[MainFile] = R"cpp(
+// IWYU pragma: no_include "baz.h"
+#include "foo.h"
+// IWYU pragma: no_include 
+// IWYU pragma: no_include  "headers.hpp" are not 
+// IWYU pragma: no_include  "headers.hpp" 
+// IWYU pragma: no_include "multiple"  "invalid"
+// IWYU pragma: no_include no_quotes are considered invalid
+// IWYU pragma: no_include  texts after are ignored
+// IWYU pragma: no_include not starting with quotes  "ignored"
+  )cpp";
+  FS.Files["sub/foo.h"] = "";
+  FS.Files["sub/bar.h"] = "";
+  FS.Files["sub/baz.h"] = "";
+  FS.Files["sub/valid"] = "";
+  FS.Files["sub/invalid"] = "";
+  FS.Files["sub/multiple"] = "";
+  FS.Files["sub/are"] = "";
+  FS.Files["sub/ignored"] = "";
+  FS.Files["sub/headers.hpp"] = "";
+
+  auto NI = collectIncludes().IwyuNoIncludes;
+  ASSERT_TRUE(NI);
+  EXPECT_THAT(*NI,
+  UnorderedElementsAre(
+  AllOf(written("\"baz.h\""),
+resolved("/clangd-test/sub/baz.h"), includeLine(1)),
+  AllOf(written(""), resolved("/clangd-test/sub/bar.h"),
+includeLine(3)),
+  AllOf(written(""), r

[PATCH] D143318: [Support] Move ItaniumManglingCanonicalizer and SymbolRemappingReader from Support to ProfileData

2023-02-05 Thread NAKAMURA Takumi via Phabricator via cfe-commits
chapuni added a comment.

@RKSimon
Could you cherry-pick it?
https://github.com/chapuni/llvm-project/commit/2c09237d8759bb6b1e99940e78901bde5b2bb98f

As a position to reduce overhead in tblgen, I don't agree to move this to 
LLVMDemangle.
LLVMSupport depends on LLVMDemangle. llvm-tblgen depends on them.

Besides, does this depend on LLVMSupport if you would move this to LLVMDemangle?

I think this is one of practical resolutions. One concern, "Does it make sense 
if llvm-cxxmap depends on LLVMProfile?"

@MaskRay
Fair enough, even if its user is only LLVMProfileData in the trunk.
That said, in fact, ItaniumManglingCanonicalizerTest.cpp spends the most time 
to build in LLVMSupport.

I don't have a strong opinion for this to move to LLVMProfileData.
Could we introduce another library, like "LLVMMangleSupport" ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143318

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


[PATCH] D143343: Broken link to SourceWeb (aka CxxCodeBrowser) project in "External Clang Examples" #60142

2023-02-05 Thread pratik sharma via Phabricator via cfe-commits
s-pratik created this revision.
s-pratik added a reviewer: aaron.ballman.
Herald added a project: All.
s-pratik requested review of this revision.
Herald added a project: clang.

Replaced the dead link with the correct link in ExternalClangExamples.rst


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143343

Files:
  clang/docs/ExternalClangExamples.rst


Index: clang/docs/ExternalClangExamples.rst
===
--- clang/docs/ExternalClangExamples.rst
+++ clang/docs/ExternalClangExamples.rst
@@ -33,7 +33,7 @@
a persistent in-memory database of references, symbolnames, completions
etc."
 
-``_
+``_
"A C/C++ source code indexer and navigator"
 
 ``_


Index: clang/docs/ExternalClangExamples.rst
===
--- clang/docs/ExternalClangExamples.rst
+++ clang/docs/ExternalClangExamples.rst
@@ -33,7 +33,7 @@
a persistent in-memory database of references, symbolnames, completions
etc."
 
-``_
+``_
"A C/C++ source code indexer and navigator"
 
 ``_
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D128465: [llvm] add zstd to `llvm::compression` namespace

2023-02-05 Thread Aaron Siddhartha Mondal via Phabricator via cfe-commits
aaronmondal added a comment.

Porting to bazel in https://reviews.llvm.org/D143344


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128465

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


[PATCH] D143342: [clang-tidy] Support std::format and std::print in readability-redundant-string-cstr

2023-02-05 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe added a comment.

This check can also work trivially for fmt::format and fmt::print[1] too (in 
fact, that's what I'm actually using), if the project would allow them to be 
added too.

[1] https://fmt.dev/


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143342

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


[PATCH] D143318: [Support] Move ItaniumManglingCanonicalizer and SymbolRemappingReader from Support to ProfileData

2023-02-05 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon updated this revision to Diff 494917.
RKSimon added a comment.

Add bazel build fix for llvm-cxxmap


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143318

Files:
  clang/docs/tools/clang-formatted-files.txt
  llvm/include/llvm/ProfileData/SampleProfReader.h
  llvm/include/llvm/Support/ItaniumManglingCanonicalizer.h
  llvm/include/llvm/Support/SymbolRemappingReader.h
  llvm/lib/ProfileData/CMakeLists.txt
  llvm/lib/ProfileData/InstrProfReader.cpp
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/ItaniumManglingCanonicalizer.cpp
  llvm/lib/Support/SymbolRemappingReader.cpp
  llvm/tools/llvm-cxxmap/CMakeLists.txt
  llvm/tools/llvm-cxxmap/llvm-cxxmap.cpp
  llvm/unittests/ProfileData/CMakeLists.txt
  llvm/unittests/Support/CMakeLists.txt
  llvm/unittests/Support/ItaniumManglingCanonicalizerTest.cpp
  llvm/unittests/Support/SymbolRemappingReaderTest.cpp
  llvm/utils/gn/secondary/llvm/lib/ProfileData/BUILD.gn
  llvm/utils/gn/secondary/llvm/lib/Support/BUILD.gn
  llvm/utils/gn/secondary/llvm/tools/llvm-cxxmap/BUILD.gn
  llvm/utils/gn/secondary/llvm/unittests/ProfileData/BUILD.gn
  llvm/utils/gn/secondary/llvm/unittests/Support/BUILD.gn
  utils/bazel/llvm-project-overlay/llvm/BUILD.bazel

Index: utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
===
--- utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
+++ utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
@@ -3188,6 +3188,7 @@
 copts = llvm_copts,
 stamp = 0,
 deps = [
+":ProfileData",
 ":Support",
 ],
 )
Index: llvm/utils/gn/secondary/llvm/unittests/Support/BUILD.gn
===
--- llvm/utils/gn/secondary/llvm/unittests/Support/BUILD.gn
+++ llvm/utils/gn/secondary/llvm/unittests/Support/BUILD.gn
@@ -49,7 +49,6 @@
 "HashBuilderTest.cpp",
 "IndexedAccessorTest.cpp",
 "InstructionCostTest.cpp",
-"ItaniumManglingCanonicalizerTest.cpp",
 "JSONTest.cpp",
 "KnownBitsTest.cpp",
 "LEB128Test.cpp",
@@ -79,7 +78,6 @@
 "SpecialCaseListTest.cpp",
 "SuffixTreeTest.cpp",
 "SwapByteOrderTest.cpp",
-"SymbolRemappingReaderTest.cpp",
 "TarWriterTest.cpp",
 "TaskQueueTest.cpp",
 "ThreadPool.cpp",
Index: llvm/utils/gn/secondary/llvm/unittests/ProfileData/BUILD.gn
===
--- llvm/utils/gn/secondary/llvm/unittests/ProfileData/BUILD.gn
+++ llvm/utils/gn/secondary/llvm/unittests/ProfileData/BUILD.gn
@@ -11,7 +11,9 @@
 "CoverageMappingTest.cpp",
 "InstrProfDataTest.cpp",
 "InstrProfTest.cpp",
+"ItaniumManglingCanonicalizerTest.cpp",
 "MemProfTest.cpp",
 "SampleProfTest.cpp",
+"SymbolRemappingReaderTest.cpp",
   ]
 }
Index: llvm/utils/gn/secondary/llvm/tools/llvm-cxxmap/BUILD.gn
===
--- llvm/utils/gn/secondary/llvm/tools/llvm-cxxmap/BUILD.gn
+++ llvm/utils/gn/secondary/llvm/tools/llvm-cxxmap/BUILD.gn
@@ -1,6 +1,7 @@
 executable("llvm-cxxmap") {
   deps = [
 "//llvm/lib/IR",
+"//llvm/lib/ProfileData",
 "//llvm/lib/Support",
 "//llvm/lib/Target:TargetsToBuild",
   ]
Index: llvm/utils/gn/secondary/llvm/lib/Support/BUILD.gn
===
--- llvm/utils/gn/secondary/llvm/lib/Support/BUILD.gn
+++ llvm/utils/gn/secondary/llvm/lib/Support/BUILD.gn
@@ -89,7 +89,6 @@
 "InstructionCost.cpp",
 "IntEqClasses.cpp",
 "IntervalMap.cpp",
-"ItaniumManglingCanonicalizer.cpp",
 "JSON.cpp",
 "KnownBits.cpp",
 "LEB128.cpp",
@@ -133,7 +132,6 @@
 "StringRef.cpp",
 "StringSaver.cpp",
 "SuffixTree.cpp",
-"SymbolRemappingReader.cpp",
 "SystemUtils.cpp",
 "TarWriter.cpp",
 "ThreadPool.cpp",
Index: llvm/utils/gn/secondary/llvm/lib/ProfileData/BUILD.gn
===
--- llvm/utils/gn/secondary/llvm/lib/ProfileData/BUILD.gn
+++ llvm/utils/gn/secondary/llvm/lib/ProfileData/BUILD.gn
@@ -14,11 +14,13 @@
 "InstrProfCorrelator.cpp",
 "InstrProfReader.cpp",
 "InstrProfWriter.cpp",
+"ItaniumManglingCanonicalizer.cpp",
 "MemProf.cpp",
 "ProfileSummaryBuilder.cpp",
 "RawMemProfReader.cpp",
 "SampleProf.cpp",
 "SampleProfReader.cpp",
 "SampleProfWriter.cpp",
+"SymbolRemappingReader.cpp",
   ]
 }
Index: llvm/unittests/Support/SymbolRemappingReaderTest.cpp
===
--- llvm/unittests/Support/SymbolRemappingReaderTest.cpp
+++ /dev/null
@@ -1,95 +0,0 @@
-//===- unittests/Support/SymbolRemappingReaderTest.cpp ===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: 

[PATCH] D143319: [clangd] Support iwyu pragma: no_include

2023-02-05 Thread Younan Zhang via Phabricator via cfe-commits
zyounan updated this revision to Diff 494921.
zyounan added a comment.

Fix test on windows


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143319

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/Headers.h
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/index/CanonicalIncludes.h
  clang-tools-extra/clangd/unittests/HeadersTests.cpp
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp

Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -9,6 +9,7 @@
 #include "Annotations.h"
 #include "Config.h"
 #include "IncludeCleaner.h"
+#include "Protocol.h"
 #include "SourceCode.h"
 #include "TestFS.h"
 #include "TestTU.h"
@@ -22,8 +23,10 @@
 namespace clangd {
 namespace {
 
+using ::testing::AllOf;
 using ::testing::ElementsAre;
 using ::testing::ElementsAreArray;
+using ::testing::Field;
 using ::testing::IsEmpty;
 using ::testing::Pointee;
 using ::testing::UnorderedElementsAre;
@@ -611,6 +614,36 @@
   EXPECT_THAT(computeUnusedIncludesExperimental(AST), IsEmpty());
 }
 
+MATCHER_P(message, Message, "") { return arg.Message == Message; }
+MATCHER_P2(range, Start, End, "") {
+  return arg.start == Start && arg.end == End;
+}
+
+TEST(IncludeCleaner, IWYUPragmaNoInclude) {
+  TestTU TU;
+  TU.Code = R"cpp(
+#include "foo.h"
+#include "bar.h"
+// IWYU pragma: no_include "bar.h"
+  )cpp";
+  TU.AdditionalFiles["foo.h"] = guard("");
+  TU.AdditionalFiles["bar.h"] = guard("");
+  ParsedAST AST = TU.build();
+
+  auto Diags = issueNoIncludesDiagnostics(AST, TU.Code);
+  EXPECT_THAT(
+  Diags,
+  UnorderedElementsAre(AllOf(
+  message(
+  "included header 'bar.h' is marked as `no_include` at line 4"),
+  Field(&DiagBase::Range, range(Position{2, 0}, Position{2, 16});
+  ASSERT_TRUE(Diags.size() == 1);
+  ASSERT_TRUE(Diags.back().Fixes.size() == 1);
+  ASSERT_TRUE(Diags.back().Fixes.back().Edits.size() == 1);
+  EXPECT_THAT(Diags.back().Fixes.back().Edits.back().range,
+  range(Position{2, 0}, Position{3, 0}));
+}
+
 TEST(IncludeCleaner, NoDiagsForObjC) {
   TestTU TU;
   TU.Code = R"cpp(
Index: clang-tools-extra/clangd/unittests/HeadersTests.cpp
===
--- clang-tools-extra/clangd/unittests/HeadersTests.cpp
+++ clang-tools-extra/clangd/unittests/HeadersTests.cpp
@@ -93,7 +93,8 @@
   // Calculates the include path, or returns "" on error or header should not be
   // inserted.
   std::string calculate(PathRef Original, PathRef Preferred = "",
-const std::vector &Inclusions = {}) {
+const std::vector &Inclusions = {},
+const std::vector &IwyuNoIncludes = {}) {
 Clang = setupClang();
 PreprocessOnlyAction Action;
 EXPECT_TRUE(
@@ -111,6 +112,8 @@
  &Clang->getPreprocessor().getHeaderSearchInfo());
 for (const auto &Inc : Inclusions)
   Inserter.addExisting(Inc);
+for (const auto &Inc : IwyuNoIncludes)
+  Inserter.addNoInclude(Inc);
 auto Inserted = ToHeaderFile(Preferred);
 if (!Inserter.shouldInsertInclude(Original, Inserted))
   return "";
@@ -275,6 +278,46 @@
AllOf(written("\"bar.h\""), hasPragmaKeep(true;
 }
 
+TEST_F(HeadersTest, IWYUPragmaNoInclude) {
+  FS.Files[MainFile] = R"cpp(
+// IWYU pragma: no_include "baz.h"
+#include "foo.h"
+// IWYU pragma: no_include 
+// IWYU pragma: no_include  "headers.hpp" are not 
+// IWYU pragma: no_include  "headers.hpp" 
+// IWYU pragma: no_include "multiple"  "invalid"
+// IWYU pragma: no_include no_quotes are considered invalid
+// IWYU pragma: no_include  texts after are ignored
+// IWYU pragma: no_include not starting with quotes  "ignored"
+  )cpp";
+  FS.Files["sub/foo.h"] = "";
+  FS.Files["sub/bar.h"] = "";
+  FS.Files["sub/baz.h"] = "";
+  FS.Files["sub/valid"] = "";
+  FS.Files["sub/invalid"] = "";
+  FS.Files["sub/multiple"] = "";
+  FS.Files["sub/are"] = "";
+  FS.Files["sub/ignored"] = "";
+  FS.Files["sub/headers.hpp"] = "";
+
+  auto NI = collectIncludes().IwyuNoIncludes;
+  ASSERT_TRUE(NI);
+  EXPECT_THAT(*NI, UnorderedElementsAre(
+   AllOf(written("\"baz.h\""),
+ resolved(testPath("sub/baz.h")), includeLine(1)),
+   AllOf(written(""),
+ resolved(testPath("sub/bar.h")), includeLine(3)),
+   AllOf(written(""),
+ resolved(testPath("sub/val

[PATCH] D143318: [Support] Move ItaniumManglingCanonicalizer and SymbolRemappingReader from Support to ProfileData

2023-02-05 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon updated this revision to Diff 494925.
RKSimon added a comment.

fix the git diff lost renames


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143318

Files:
  clang/docs/tools/clang-formatted-files.txt
  llvm/include/llvm/ProfileData/ItaniumManglingCanonicalizer.h
  llvm/include/llvm/ProfileData/SampleProfReader.h
  llvm/include/llvm/ProfileData/SymbolRemappingReader.h
  llvm/lib/ProfileData/CMakeLists.txt
  llvm/lib/ProfileData/InstrProfReader.cpp
  llvm/lib/ProfileData/ItaniumManglingCanonicalizer.cpp
  llvm/lib/ProfileData/SymbolRemappingReader.cpp
  llvm/lib/Support/CMakeLists.txt
  llvm/tools/llvm-cxxmap/CMakeLists.txt
  llvm/tools/llvm-cxxmap/llvm-cxxmap.cpp
  llvm/unittests/ProfileData/CMakeLists.txt
  llvm/unittests/ProfileData/ItaniumManglingCanonicalizerTest.cpp
  llvm/unittests/ProfileData/SymbolRemappingReaderTest.cpp
  llvm/unittests/Support/CMakeLists.txt
  llvm/utils/gn/secondary/llvm/lib/ProfileData/BUILD.gn
  llvm/utils/gn/secondary/llvm/lib/Support/BUILD.gn
  llvm/utils/gn/secondary/llvm/tools/llvm-cxxmap/BUILD.gn
  llvm/utils/gn/secondary/llvm/unittests/ProfileData/BUILD.gn
  llvm/utils/gn/secondary/llvm/unittests/Support/BUILD.gn
  utils/bazel/llvm-project-overlay/llvm/BUILD.bazel

Index: utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
===
--- utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
+++ utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
@@ -3188,6 +3188,7 @@
 copts = llvm_copts,
 stamp = 0,
 deps = [
+":ProfileData",
 ":Support",
 ],
 )
Index: llvm/utils/gn/secondary/llvm/unittests/Support/BUILD.gn
===
--- llvm/utils/gn/secondary/llvm/unittests/Support/BUILD.gn
+++ llvm/utils/gn/secondary/llvm/unittests/Support/BUILD.gn
@@ -49,7 +49,6 @@
 "HashBuilderTest.cpp",
 "IndexedAccessorTest.cpp",
 "InstructionCostTest.cpp",
-"ItaniumManglingCanonicalizerTest.cpp",
 "JSONTest.cpp",
 "KnownBitsTest.cpp",
 "LEB128Test.cpp",
@@ -79,7 +78,6 @@
 "SpecialCaseListTest.cpp",
 "SuffixTreeTest.cpp",
 "SwapByteOrderTest.cpp",
-"SymbolRemappingReaderTest.cpp",
 "TarWriterTest.cpp",
 "TaskQueueTest.cpp",
 "ThreadPool.cpp",
Index: llvm/utils/gn/secondary/llvm/unittests/ProfileData/BUILD.gn
===
--- llvm/utils/gn/secondary/llvm/unittests/ProfileData/BUILD.gn
+++ llvm/utils/gn/secondary/llvm/unittests/ProfileData/BUILD.gn
@@ -11,7 +11,9 @@
 "CoverageMappingTest.cpp",
 "InstrProfDataTest.cpp",
 "InstrProfTest.cpp",
+"ItaniumManglingCanonicalizerTest.cpp",
 "MemProfTest.cpp",
 "SampleProfTest.cpp",
+"SymbolRemappingReaderTest.cpp",
   ]
 }
Index: llvm/utils/gn/secondary/llvm/tools/llvm-cxxmap/BUILD.gn
===
--- llvm/utils/gn/secondary/llvm/tools/llvm-cxxmap/BUILD.gn
+++ llvm/utils/gn/secondary/llvm/tools/llvm-cxxmap/BUILD.gn
@@ -1,6 +1,7 @@
 executable("llvm-cxxmap") {
   deps = [
 "//llvm/lib/IR",
+"//llvm/lib/ProfileData",
 "//llvm/lib/Support",
 "//llvm/lib/Target:TargetsToBuild",
   ]
Index: llvm/utils/gn/secondary/llvm/lib/Support/BUILD.gn
===
--- llvm/utils/gn/secondary/llvm/lib/Support/BUILD.gn
+++ llvm/utils/gn/secondary/llvm/lib/Support/BUILD.gn
@@ -89,7 +89,6 @@
 "InstructionCost.cpp",
 "IntEqClasses.cpp",
 "IntervalMap.cpp",
-"ItaniumManglingCanonicalizer.cpp",
 "JSON.cpp",
 "KnownBits.cpp",
 "LEB128.cpp",
@@ -133,7 +132,6 @@
 "StringRef.cpp",
 "StringSaver.cpp",
 "SuffixTree.cpp",
-"SymbolRemappingReader.cpp",
 "SystemUtils.cpp",
 "TarWriter.cpp",
 "ThreadPool.cpp",
Index: llvm/utils/gn/secondary/llvm/lib/ProfileData/BUILD.gn
===
--- llvm/utils/gn/secondary/llvm/lib/ProfileData/BUILD.gn
+++ llvm/utils/gn/secondary/llvm/lib/ProfileData/BUILD.gn
@@ -14,11 +14,13 @@
 "InstrProfCorrelator.cpp",
 "InstrProfReader.cpp",
 "InstrProfWriter.cpp",
+"ItaniumManglingCanonicalizer.cpp",
 "MemProf.cpp",
 "ProfileSummaryBuilder.cpp",
 "RawMemProfReader.cpp",
 "SampleProf.cpp",
 "SampleProfReader.cpp",
 "SampleProfWriter.cpp",
+"SymbolRemappingReader.cpp",
   ]
 }
Index: llvm/unittests/Support/CMakeLists.txt
===
--- llvm/unittests/Support/CMakeLists.txt
+++ llvm/unittests/Support/CMakeLists.txt
@@ -46,7 +46,6 @@
   HashBuilderTest.cpp
   IndexedAccessorTest.cpp
   InstructionCostTest.cpp
-  ItaniumManglingCanonicalizerTest.cpp
   JSONTest.cpp
   KnownBitsTest.cpp
   LEB128Test.cpp
@@ -76,7 +75,6 @@
   SpecialCaseListTest.cpp
   SuffixTreeTest.cpp
   

[PATCH] D142606: Lazyly initialize uncommon toolchain detector

2023-02-05 Thread serge via Phabricator via cfe-commits
serge-sans-paille updated this revision to Diff 494927.
serge-sans-paille added a comment.

Address @tbader's comment


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

https://reviews.llvm.org/D142606

Files:
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
  clang/lib/Driver/ToolChains/FreeBSD.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Gnu.h
  clang/lib/Driver/ToolChains/HIPAMD.cpp
  clang/lib/Driver/ToolChains/LazyDetector.h
  clang/lib/Driver/ToolChains/Linux.cpp

Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -681,23 +681,23 @@
 
 void Linux::AddCudaIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const {
-  CudaInstallation.AddCudaIncludeArgs(DriverArgs, CC1Args);
+  CudaInstallation->AddCudaIncludeArgs(DriverArgs, CC1Args);
 }
 
 void Linux::AddHIPIncludeArgs(const ArgList &DriverArgs,
   ArgStringList &CC1Args) const {
-  RocmInstallation.AddHIPIncludeArgs(DriverArgs, CC1Args);
+  RocmInstallation->AddHIPIncludeArgs(DriverArgs, CC1Args);
 }
 
 void Linux::AddHIPRuntimeLibArgs(const ArgList &Args,
  ArgStringList &CmdArgs) const {
   CmdArgs.push_back(
-  Args.MakeArgString(StringRef("-L") + RocmInstallation.getLibPath()));
+  Args.MakeArgString(StringRef("-L") + RocmInstallation->getLibPath()));
 
   if (Args.hasFlag(options::OPT_offload_add_rpath,
options::OPT_no_offload_add_rpath, false))
 CmdArgs.append(
-{"-rpath", Args.MakeArgString(RocmInstallation.getLibPath())});
+{"-rpath", Args.MakeArgString(RocmInstallation->getLibPath())});
 
   CmdArgs.push_back("-lamdhip64");
 }
Index: clang/lib/Driver/ToolChains/LazyDetector.h
===
--- /dev/null
+++ clang/lib/Driver/ToolChains/LazyDetector.h
@@ -0,0 +1,45 @@
+//===--- LazyDetector.h - Lazy ToolChain Detection --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_LAZYDETECTOR_H
+#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_LAZYDETECTOR_H
+
+#include "clang/Driver/Tool.h"
+#include "clang/Driver/ToolChain.h"
+#include 
+
+namespace clang {
+
+/// Simple wrapper for toolchain detector with costly initialization. This
+/// delays the creation of the actual detector until its first usage.
+
+template  class LazyDetector {
+  const driver::Driver &D;
+  const llvm::Triple &Triple;
+  const llvm::opt::ArgList &Args;
+
+  std::optional Detector;
+
+public:
+  LazyDetector(const driver::Driver &D, const llvm::Triple &Triple,
+   const llvm::opt::ArgList &Args)
+  : D(D), Triple(Triple), Args(Args) {}
+  T *operator->() {
+if (!Detector)
+  Detector.emplace(D, Triple, Args);
+return &*Detector;
+  }
+  T const *operator->() const {
+return const_cast(
+const_cast(*this).operator->());
+  }
+};
+
+} // end namespace clang
+
+#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_LAZYDETECTOR_H
Index: clang/lib/Driver/ToolChains/HIPAMD.cpp
===
--- clang/lib/Driver/ToolChains/HIPAMD.cpp
+++ clang/lib/Driver/ToolChains/HIPAMD.cpp
@@ -315,7 +315,7 @@
 
 void HIPAMDToolChain::AddHIPIncludeArgs(const ArgList &DriverArgs,
 ArgStringList &CC1Args) const {
-  RocmInstallation.AddHIPIncludeArgs(DriverArgs, CC1Args);
+  RocmInstallation->AddHIPIncludeArgs(DriverArgs, CC1Args);
 }
 
 SanitizerMask HIPAMDToolChain::getSupportedSanitizers() const {
@@ -344,7 +344,7 @@
   ArgStringList LibraryPaths;
 
   // Find in --hip-device-lib-path and HIP_LIBRARY_PATH.
-  for (StringRef Path : RocmInstallation.getRocmDeviceLibPathArg())
+  for (StringRef Path : RocmInstallation->getRocmDeviceLibPathArg())
 LibraryPaths.push_back(DriverArgs.MakeArgString(Path));
 
   addDirectoryList(DriverArgs, LibraryPaths, "", "HIP_DEVICE_LIB_PATH");
@@ -366,7 +366,7 @@
   getDriver().Diag(diag::err_drv_no_such_file) << BCName;
 });
   } else {
-if (!RocmInstallation.hasDeviceLibrary()) {
+if (!RocmInstallation->hasDeviceLibrary()) {
   getDriver().Diag(diag::err_drv_no_rocm_device_lib) << 0;
   return {};
 }
@@ -377,7 +377,7 @@
 if (DriverArgs.hasFlag(options::OPT_fgpu_sanitize,
options::OPT_fno_gpu_sanitize, true) &&
 getSanitizerArgs(DriverArgs).needsAsanRt()) {
-  auto AsanRTL = RocmInstallation.getAsanRTLPath();
+  auto AsanRTL = RocmIns

cfe-commits@lists.llvm.org

2023-02-05 Thread David K Turner via Phabricator via cfe-commits
dkt01 marked 4 inline comments as done.
dkt01 added inline comments.



Comment at: clang/lib/Format/TokenAnnotator.cpp:123
 private:
+  ScopeType getScopeType(FormatToken &Token) {
+switch (Token.getType()) {

owenpan wrote:
> As suggested before.
Oops... missed the `const`s last time...


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

https://reviews.llvm.org/D141959

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


cfe-commits@lists.llvm.org

2023-02-05 Thread David K Turner via Phabricator via cfe-commits
dkt01 updated this revision to Diff 494928.
dkt01 marked an inline comment as done.
dkt01 added a comment.

Changes requested in owenpan's review.
Rebased changes onto latest main branch.


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

https://reviews.llvm.org/D141959

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

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -175,6 +175,73 @@
   ASSERT_EQ(Tokens.size(), 17u) << Tokens;
   EXPECT_TOKEN(Tokens[9], tok::ampamp, TT_PointerOrReference);
   EXPECT_TOKEN(Tokens[12], tok::ampamp, TT_PointerOrReference);
+
+  Tokens = annotate("Type1 &val1 = val2;");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::amp, TT_PointerOrReference);
+
+  Tokens = annotate("Type1 *val1 = &val2;");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::star, TT_PointerOrReference);
+  EXPECT_TOKEN(Tokens[4], tok::amp, TT_UnaryOperator);
+
+  Tokens = annotate("val1 & val2;");
+  ASSERT_EQ(Tokens.size(), 5u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::amp, TT_BinaryOperator);
+
+  Tokens = annotate("val1 & val2.member;");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::amp, TT_BinaryOperator);
+
+  Tokens = annotate("val1 & val2.*member;");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::amp, TT_BinaryOperator);
+
+  Tokens = annotate("val1.*member & val2;");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::amp, TT_BinaryOperator);
+
+  Tokens = annotate("val1 & val2->*member;");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::amp, TT_BinaryOperator);
+
+  Tokens = annotate("val1->member & val2;");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::amp, TT_BinaryOperator);
+
+  Tokens = annotate("val1 & val2 & val3;");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::amp, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[3], tok::amp, TT_BinaryOperator);
+
+  Tokens = annotate("val1 & val2 // comment\n"
+" & val3;");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::amp, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[4], tok::amp, TT_BinaryOperator);
+
+  Tokens =
+  annotate("val1 & val2.member & val3.member() & val4 & val5->member;");
+  ASSERT_EQ(Tokens.size(), 19u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::amp, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[5], tok::amp, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[11], tok::amp, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[13], tok::amp, TT_BinaryOperator);
+
+  Tokens = annotate("class c {\n"
+"  void func(type &a) { a & member; }\n"
+"  anotherType &member;\n"
+"}");
+  ASSERT_EQ(Tokens.size(), 22u) << Tokens;
+  EXPECT_TOKEN(Tokens[7], tok::amp, TT_PointerOrReference);
+  EXPECT_TOKEN(Tokens[12], tok::amp, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[17], tok::amp, TT_PointerOrReference);
+
+  Tokens = annotate("struct S {\n"
+"  auto Mem = C & D;\n"
+"}");
+  ASSERT_EQ(Tokens.size(), 12u) << Tokens;
+  EXPECT_TOKEN(Tokens[7], tok::amp, TT_BinaryOperator);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsUsesOfPlusAndMinus) {
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -11288,6 +11288,13 @@
 
   verifyFormat("int operator()(T (&&)[N]) { return 1; }");
   verifyFormat("int operator()(T (&)[N]) { return 0; }");
+
+  verifyFormat("val1 & val2;");
+  verifyFormat("val1 & val2 & val3;");
+  verifyFormat("class c {\n"
+   "  void func(type &a) { a & member; }\n"
+   "  anotherType &member;\n"
+   "}");
 }
 
 TEST_F(FormatTest, UnderstandsAttributes) {
Index: clang/lib/Format/TokenAnnotator.h
===
--- clang/lib/Format/TokenAnnotator.h
+++ clang/lib/Format/TokenAnnotator.h
@@ -34,6 +34,15 @@
   LT_CommentAbovePPDirective,
 };
 
+enum ScopeType {
+  // Contained in class declaration/definition.
+  ST_Class,
+  // Contained within function definition.
+  ST_Function,
+  // Contained within other scope block (loop, if/else, etc).
+  ST_Other,
+};
+
 class AnnotatedLine {
 public:
   AnnotatedLine(const UnwrappedLine &Line)
@@ -178,7 +187,7 @@
   // FIXME: Can/should this be done in the UnwrappedLineParser?
   void setCommentLineLevels(SmallVectorImpl &Lines) const;
 
-  void annotate(AnnotatedLine &Line) const;
+  void annotate(AnnotatedLine &Line);
  

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

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



Comment at: 
clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp:31
+: ClangTidyCheck(Name, Context) {
+  std::optional HeaderFileExtensionsOption =
+  Options.get("HeaderFileExtensions");

Eugene.Zelenko wrote:
> Will be good idea to make function in `utils` instead of code duplication. 
I thought about that, but found it quite difficult due to the dependencies to 
Options and diag(), which are only available in ClangTidyCheck. This is 
probably why there was duplication to begin with.

I could add a helper function in ClangTidyCheck, but I find it out of place and 
I see risk in people using it as if it were a solid function meant to stay. 
Since this code is temporary I think the duplication is a small price to pay 
for keeping backwards compatibility. It will all be gone when we remove the 
local options.

I might have missed something, if you have some concrete suggestion that could 
work I'm happy to use it!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142655

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


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

2023-02-05 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 wait for other opinion(s).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142655

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


[PATCH] D140290: [clang-tidy] Add misc-static-declaration-in-header check

2023-02-05 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp updated this revision to Diff 494929.
carlosgalvezp added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140290

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/clang-tidy/misc/StaticDeclarationInHeaderCheck.cpp
  clang-tools-extra/clang-tidy/misc/StaticDeclarationInHeaderCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/static-declaration-in-header.rst
  
clang-tools-extra/test/clang-tidy/checkers/misc/static-declaration-in-header.hpp

Index: clang-tools-extra/test/clang-tidy/checkers/misc/static-declaration-in-header.hpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc/static-declaration-in-header.hpp
@@ -0,0 +1,46 @@
+// RUN: %check_clang_tidy  -std=c++98,c++03,c++11,c++14 %s misc-static-declaration-in-header %t
+// RUN: %check_clang_tidy -check-suffix=CXX17-OR-LATER -std=c++17-or-later  %s misc-static-declaration-in-header %t
+
+static int v1 = 123;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: static declaration in header [misc-static-declaration-in-header]
+// CHECK-FIXES-CXX17-OR-LATER: {{^}}inline int v1 = 123;{{$}}
+
+static void f1(){}
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: static declaration in header
+// CHECK-FIXES: {{^}}inline void f1(){}{{$}}
+
+namespace foo {
+  static int v2 = 123;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: static declaration in header
+  // CHECK-FIXES-CXX17-OR-LATER: {{^}}  inline int v2 = 123;{{$}}
+
+  static int f2(){}
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: static declaration in header
+  // CHECK-FIXES: {{^}}  inline int f2(){}{{$}}
+}
+
+// OK
+struct Foo {
+  static const int v3 = 123;
+  static void f3(){}
+};
+
+// OK
+void f4() {
+  static int v4 = 123;
+}
+
+// OK, static doesn't make matters worse here due to the anonymous namespace
+namespace {
+  static int v5 = 123;
+  static int f5(){}
+}
+
+// OK, static is only redundant (readability)
+static const int v6 = 123;
+static inline void f6(){}
+
+#if __cplusplus >= 201103L
+static constexpr int v7 = 123;
+static constexpr int f7(){ return 123; }
+#endif
Index: clang-tools-extra/docs/clang-tidy/checks/misc/static-declaration-in-header.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/misc/static-declaration-in-header.rst
@@ -0,0 +1,59 @@
+.. title:: clang-tidy - misc-static-declaration-in-header
+
+misc-static-declaration-in-header
+=
+
+Warns about ``static`` variable and function declarations at file or namespace
+scope in header files.
+
+Header files are used to share code among different translation units. ``static``,
+on the other hand, can be used to express that a given declaration has internal
+linkage. Using ``static`` in header files leads to each translation unit creating
+their own internal copy of the function or variable at hand, which is problematic.
+This can cause unexpected results, bloat the resulting executable or even trigger
+one-definition-rule (ODR) violations.
+
+This problem is similar to having anonymous namespaces in header files, already
+covered by :doc:`google-build-namespaces`.
+
+Example of problematic code:
+
+.. code-block:: c++
+
+  // foo.h
+  static void f(){}
+  static int x = 123;
+
+The code should instead be changed to replace ``static`` with ``inline``, for
+both function and variable declarations (since C++17):
+
+.. code-block:: c++
+
+  // foo.h
+  inline void f(){}
+  inline int x = 123;  // Since C++17
+
+The check will issue automatic fixes if supported.
+
+Alternatively, the code could be changed to remove ``static`` and move the
+definitions to a separate translation unit.
+
+.. code-block:: c++
+
+  // foo.h
+  void f();
+  int x;
+
+  // foo.cpp
+  void f(){}
+  int x = 123;
+
+Options
+---
+
+.. option:: HeaderFileExtensions
+
+   A semicolon-separated list of filename extensions of header files (the filename
+   extensions should not include `.` prefix). Default is `;h;hh;hpp;hxx`.
+   For extension-less header files, using an empty string or leaving an
+   empty string between `;` if there are other filename extensions.
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
@@ -257,6 +257,7 @@
`misc-non-private-member-variables-in-classes `_,
`misc-redundant-expression `_, "Yes"
`misc-static-assert `_, "Yes"
+   `misc-static-declaration-in-header `_, "Yes"
`misc-throw-by-value-catch-by-reference `_,
`misc-

[PATCH] D143342: [clang-tidy] Support std::format and std::print in readability-redundant-string-cstr

2023-02-05 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

Please document change in Release Notes, as well as in the check documentation, 
together with its limitations (can only handle 1 argument at a time).




Comment at: 
clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp:182
+
+  Finder->addMatcher(
+  traverse(TK_AsIs,

Nit: add a comment explaining what this matcher does, for consistency with how 
it's done with the other matchers above.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143342

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


[PATCH] D143325: [Driver] Add -mllvm= as an alias for -mllvm

2023-02-05 Thread Fangrui Song 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 rG90094ab8850e: [Driver] Add -mllvm= as an alias for -mllvm 
(authored by MaskRay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143325

Files:
  clang/include/clang/Driver/Options.td
  clang/test/Driver/hip-options.hip


Index: clang/test/Driver/hip-options.hip
===
--- clang/test/Driver/hip-options.hip
+++ clang/test/Driver/hip-options.hip
@@ -27,10 +27,10 @@
 // MLLVM-NOT: 
"-mllvm"{{.*}}"-amdgpu-early-inline-all=true"{{.*}}"-mllvm"{{.*}}"-amdgpu-early-inline-all=true"
 
 // RUN: %clang -### -Xarch_device -g -nogpulib --cuda-gpu-arch=gfx900 \
-// RUN:   -Xarch_device -fcf-protection=branch \
+// RUN:   -Xarch_device -fcf-protection=branch -Xarch_device 
-mllvm=--inline-threshold=100 \
 // RUN:   --cuda-gpu-arch=gfx906  %s 2>&1 | FileCheck -check-prefix=DEV %s
-// DEV: "-cc1"{{.*}} "-fcuda-is-device" {{.*}} "-debug-info-kind={{.*}}" 
{{.*}} "-fcf-protection=branch"
-// DEV: "-cc1"{{.*}} "-fcuda-is-device" {{.*}} "-debug-info-kind={{.*}}" 
{{.*}} "-fcf-protection=branch"
+// DEV: "-cc1"{{.*}} "-fcuda-is-device" {{.*}} "-debug-info-kind={{.*}}" 
{{.*}} "-fcf-protection=branch" {{.*}}"-mllvm" "--inline-threshold=100"
+// DEV: "-cc1"{{.*}} "-fcuda-is-device" {{.*}} "-debug-info-kind={{.*}}" 
{{.*}} "-fcf-protection=branch" {{.*}}"-mllvm" "--inline-threshold=100"
 // DEV-NOT: clang{{.*}} {{.*}} "-debug-info-kind={{.*}}"
 
 // RUN: %clang -### -Xarch_host -g -nogpulib --cuda-gpu-arch=gfx900 \
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3478,6 +3478,8 @@
 def mllvm : Separate<["-"], 
"mllvm">,Flags<[CC1Option,CC1AsOption,CoreOption,FC1Option,FlangOption]>,
   HelpText<"Additional arguments to forward to LLVM's option processing">,
   MarshallingInfoStringVector>;
+def : Joined<["-"], "mllvm=">, Flags<[CoreOption,FlangOption]>, Alias,
+  HelpText<"Alias for -mllvm">, MetaVarName<"">;
 def mmlir : Separate<["-"], "mmlir">, 
Flags<[CoreOption,FC1Option,FlangOption]>,
   HelpText<"Additional arguments to forward to MLIR's option processing">;
 def ffuchsia_api_level_EQ : Joined<["-"], "ffuchsia-api-level=">,


Index: clang/test/Driver/hip-options.hip
===
--- clang/test/Driver/hip-options.hip
+++ clang/test/Driver/hip-options.hip
@@ -27,10 +27,10 @@
 // MLLVM-NOT: "-mllvm"{{.*}}"-amdgpu-early-inline-all=true"{{.*}}"-mllvm"{{.*}}"-amdgpu-early-inline-all=true"
 
 // RUN: %clang -### -Xarch_device -g -nogpulib --cuda-gpu-arch=gfx900 \
-// RUN:   -Xarch_device -fcf-protection=branch \
+// RUN:   -Xarch_device -fcf-protection=branch -Xarch_device -mllvm=--inline-threshold=100 \
 // RUN:   --cuda-gpu-arch=gfx906  %s 2>&1 | FileCheck -check-prefix=DEV %s
-// DEV: "-cc1"{{.*}} "-fcuda-is-device" {{.*}} "-debug-info-kind={{.*}}" {{.*}} "-fcf-protection=branch"
-// DEV: "-cc1"{{.*}} "-fcuda-is-device" {{.*}} "-debug-info-kind={{.*}}" {{.*}} "-fcf-protection=branch"
+// DEV: "-cc1"{{.*}} "-fcuda-is-device" {{.*}} "-debug-info-kind={{.*}}" {{.*}} "-fcf-protection=branch" {{.*}}"-mllvm" "--inline-threshold=100"
+// DEV: "-cc1"{{.*}} "-fcuda-is-device" {{.*}} "-debug-info-kind={{.*}}" {{.*}} "-fcf-protection=branch" {{.*}}"-mllvm" "--inline-threshold=100"
 // DEV-NOT: clang{{.*}} {{.*}} "-debug-info-kind={{.*}}"
 
 // RUN: %clang -### -Xarch_host -g -nogpulib --cuda-gpu-arch=gfx900 \
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3478,6 +3478,8 @@
 def mllvm : Separate<["-"], "mllvm">,Flags<[CC1Option,CC1AsOption,CoreOption,FC1Option,FlangOption]>,
   HelpText<"Additional arguments to forward to LLVM's option processing">,
   MarshallingInfoStringVector>;
+def : Joined<["-"], "mllvm=">, Flags<[CoreOption,FlangOption]>, Alias,
+  HelpText<"Alias for -mllvm">, MetaVarName<"">;
 def mmlir : Separate<["-"], "mmlir">, Flags<[CoreOption,FC1Option,FlangOption]>,
   HelpText<"Additional arguments to forward to MLIR's option processing">;
 def ffuchsia_api_level_EQ : Joined<["-"], "ffuchsia-api-level=">,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 90094ab - [Driver] Add -mllvm= as an alias for -mllvm

2023-02-05 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-02-05T10:29:58-08:00
New Revision: 90094ab8850ec435574fbd393d886a54a6dd2531

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

LOG: [Driver] Add -mllvm= as an alias for -mllvm

Similar to D131455 (-Xclang=). As well as making it convenient for some build
systems, this allows `-Xarch_device '-mllvm=--inline-threshold=100'` (and
`-Xarch_host`; so we don't need to allow space separators which are uncommon in
driver code).

Bear in mind that -mllvm options are unstable and should be avoided if possible.

Reviewed By: jhuber6, yaxunl

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

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/test/Driver/hip-options.hip

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 5a0e904ffb33b..03e6e7c52d63a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3478,6 +3478,8 @@ def mlinker_version_EQ : Joined<["-"], 
"mlinker-version=">,
 def mllvm : Separate<["-"], 
"mllvm">,Flags<[CC1Option,CC1AsOption,CoreOption,FC1Option,FlangOption]>,
   HelpText<"Additional arguments to forward to LLVM's option processing">,
   MarshallingInfoStringVector>;
+def : Joined<["-"], "mllvm=">, Flags<[CoreOption,FlangOption]>, Alias,
+  HelpText<"Alias for -mllvm">, MetaVarName<"">;
 def mmlir : Separate<["-"], "mmlir">, 
Flags<[CoreOption,FC1Option,FlangOption]>,
   HelpText<"Additional arguments to forward to MLIR's option processing">;
 def ffuchsia_api_level_EQ : Joined<["-"], "ffuchsia-api-level=">,

diff  --git a/clang/test/Driver/hip-options.hip 
b/clang/test/Driver/hip-options.hip
index a0a4df891b4e5..97d0c1370bc42 100644
--- a/clang/test/Driver/hip-options.hip
+++ b/clang/test/Driver/hip-options.hip
@@ -27,10 +27,10 @@
 // MLLVM-NOT: 
"-mllvm"{{.*}}"-amdgpu-early-inline-all=true"{{.*}}"-mllvm"{{.*}}"-amdgpu-early-inline-all=true"
 
 // RUN: %clang -### -Xarch_device -g -nogpulib --cuda-gpu-arch=gfx900 \
-// RUN:   -Xarch_device -fcf-protection=branch \
+// RUN:   -Xarch_device -fcf-protection=branch -Xarch_device 
-mllvm=--inline-threshold=100 \
 // RUN:   --cuda-gpu-arch=gfx906  %s 2>&1 | FileCheck -check-prefix=DEV %s
-// DEV: "-cc1"{{.*}} "-fcuda-is-device" {{.*}} "-debug-info-kind={{.*}}" 
{{.*}} "-fcf-protection=branch"
-// DEV: "-cc1"{{.*}} "-fcuda-is-device" {{.*}} "-debug-info-kind={{.*}}" 
{{.*}} "-fcf-protection=branch"
+// DEV: "-cc1"{{.*}} "-fcuda-is-device" {{.*}} "-debug-info-kind={{.*}}" 
{{.*}} "-fcf-protection=branch" {{.*}}"-mllvm" "--inline-threshold=100"
+// DEV: "-cc1"{{.*}} "-fcuda-is-device" {{.*}} "-debug-info-kind={{.*}}" 
{{.*}} "-fcf-protection=branch" {{.*}}"-mllvm" "--inline-threshold=100"
 // DEV-NOT: clang{{.*}} {{.*}} "-debug-info-kind={{.*}}"
 
 // RUN: %clang -### -Xarch_host -g -nogpulib --cuda-gpu-arch=gfx900 \



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


[PATCH] D143347: [lldb][DWARF] Infer no_unique_address attribute

2023-02-05 Thread Pavel Kosov via Phabricator via cfe-commits
kpdev42 created this revision.
kpdev42 added reviewers: DavidSpickett, davide, clayborg, k8stone.
kpdev42 added projects: LLVM, LLDB.
Herald added subscribers: Michael137, JDevlieghere, martong.
Herald added a reviewer: shafik.
Herald added a reviewer: shafik.
Herald added a project: All.
kpdev42 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The no_unique_address attribute is currently a part of C++20 standard and is 
being used in both libstdc++ and libc++. This causes problems when debugging 
C++ code with lldb because the latter doesn't expect two non-empty base classes 
having the same offset and crashes with assertion. Patch attempts to infer this 
attribute by detecting two consecutive base classes with the same offset to 
derived class and marking first of those classes as empty and adding 
no_unique_address attribute to all of its fields.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143347

Files:
  clang/include/clang/AST/DeclCXX.h
  clang/lib/AST/ASTImporter.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/test/API/types/TestEmptyBase.py
  lldb/test/API/types/empty_base_type.cpp

Index: lldb/test/API/types/empty_base_type.cpp
===
--- /dev/null
+++ lldb/test/API/types/empty_base_type.cpp
@@ -0,0 +1,23 @@
+struct C
+{
+ long c,d;
+};
+
+struct D
+{
+};
+
+struct B
+{
+  [[no_unique_address]] D x;
+};
+
+struct A : B,C
+{
+ long a,b;
+} _a;
+
+
+int main() {
+  return _a.a; // Set breakpoint here.
+}
Index: lldb/test/API/types/TestEmptyBase.py
===
--- /dev/null
+++ lldb/test/API/types/TestEmptyBase.py
@@ -0,0 +1,42 @@
+"""
+Test that recursive types are handled correctly.
+"""
+
+
+
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.lldbtest import *
+
+
+class EmptyBaseTestCase(TestBase):
+
+def setUp(self):
+# Call super's setUp().
+TestBase.setUp(self)
+
+# Find the line number to break for main.c.
+self.line = line_number('empty_base_type.cpp',
+'// Set breakpoint here.')
+
+self.sources = {
+'CXX_SOURCES': 'empty_base_type.cpp'}
+
+def test(self):
+"""Test that recursive structs are displayed correctly."""
+self.build(dictionary=self.sources)
+self.setTearDownCleanup(dictionary=self.sources)
+self.run_expr()
+
+def run_expr(self):
+self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
+
+lldbutil.run_break_set_by_file_and_line(
+self,
+"empty_base_type.cpp",
+self.line,
+num_expected_locations=-1,
+loc_exact=True)
+
+self.runCmd("run", RUN_SUCCEEDED)
+self.runCmd("expression _a")
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
===
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -1460,6 +1460,8 @@
   if (!result)
 return;
 
+  const clang::CXXBaseSpecifier *prev_base =
+  base_classes.empty() ? nullptr : base_classes.back().get();
   base_classes.push_back(std::move(result));
 
   if (is_virtual) {
@@ -1476,6 +1478,20 @@
 // be removed from LayoutRecordType() in the external
 // AST source in clang.
   } else {
+if (prev_base) {
+  clang::CXXRecordDecl *prev_base_decl =
+  prev_base->getType()->getAsCXXRecordDecl();
+  if (prev_base_decl && !prev_base_decl->isEmpty()) {
+auto it = layout_info.base_offsets.find(prev_base_decl);
+assert(it != layout_info.base_offsets.end());
+if (it->second.getQuantity() == member_byte_offset) {
+  prev_base_decl->markEmpty();
+  for (auto *field : prev_base_decl->fields())
+field->addAttr(clang::NoUniqueAddressAttr::Create(
+ast->getASTContext(), clang::SourceRange()));
+}
+  }
+}
 layout_info.base_offsets.insert(std::make_pair(
 ast->GetAsCXXRecordDecl(base_class_clang_type.GetOpaqueQualType()),
 clang::CharUnits::fromQuantity(member_byte_offset)));
Index: lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
===
--- lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp
@@ -548,6 +548,7 @@
 
 void ClangASTImporter::SetRecordLayout(clang::RecordDecl *decl,
 const LayoutInfo &layout) {
+
   m_record_decl_to_layout_map.insert(std::make_pair(decl, layout));
 }
 
Index: clang/lib/AST/ASTImporter.cpp
==

[PATCH] D143342: [clang-tidy] Support std::format and std::print in readability-redundant-string-cstr

2023-02-05 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe updated this revision to Diff 494937.
mikecrowe added a comment.

carlosgalvezp wrote:

> Please document change in Release Notes, as well as in the check 
> documentation, together with its limitations (can only handle 1 argument at a 
> time).

Hopefully I've done those things.


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

https://reviews.llvm.org/D143342

Files:
  clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/readability/redundant-string-cstr.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/redundant-string-cstr.cpp
@@ -291,3 +291,59 @@
   Foo.func2((Str.c_str()));
 }
 } // namespace PR45286
+
+namespace std {
+  template
+  void print(const char *, Args &&...);
+  template
+  std::string format(const char *, Args &&...);
+}
+
+namespace notstd {
+  template
+  void print(const char *, Args &&...);
+  template
+  std::string format(const char *, Args &&...);
+}
+
+void std_print(const std::string &s1, const std::string &s2, const std::string &s3) {
+  std::print("One:{}\n", s1.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}std::print("One:{}\n", s1);
+
+  // Ideally we'd fix both the second and fourth parameters here, but that doesn't work.
+  std::print("One:{} Two:{} Three:{}\n", s1.c_str(), s2, s3.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:42: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}std::print("One:{} Two:{} Three:{}\n", s1, s2, s3.c_str());
+}
+
+// There's no c_str() call here, so it shouldn't be touched.
+void std_print_no_cstr(const std::string &s1, const std::string &s2) {
+  std::print("One: {}, Two: {}\n", s1, s2);
+}
+
+// This isn't std::print, so it shouldn't be fixed.
+void not_std_print(const std::string &s1) {
+  notstd::print("One: {}\n", s1.c_str());
+}
+
+void std_format(const std::string &s1, const std::string &s2, const std::string &s3) {
+  auto r1 = std::format("One:{}\n", s1.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}auto r1 = std::format("One:{}\n", s1);
+
+  // Ideally we'd fix both the second and fourth parameters here, but that doesn't work.
+  auto r2 = std::format("One:{} Two:{} Three:{}\n", s1.c_str(), s2, s3.c_str());
+  // CHECK-MESSAGES: :[[@LINE-1]]:53: warning: redundant call to 'c_str' [readability-redundant-string-cstr]
+  // CHECK-FIXES: {{^  }}auto r2 = std::format("One:{} Two:{} Three:{}\n", s1, s2, s3.c_str());
+}
+
+// There's are c_str() calls here, so it shouldn't be touched.
+std::string std_format_no_cstr(const std::string &s1, const std::string &s2) {
+  return std::format("One: {}, Two: {}\n", s1, s2);
+}
+
+// This is not std::format, so it shouldn't be fixed.
+std::string not_std_format(const std::string &s1) {
+  return notstd::format("One: {}\n", s1.c_str());
+}
Index: clang-tools-extra/docs/clang-tidy/checks/readability/redundant-string-cstr.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/readability/redundant-string-cstr.rst
+++ clang-tools-extra/docs/clang-tidy/checks/readability/redundant-string-cstr.rst
@@ -5,3 +5,7 @@
 
 
 Finds unnecessary calls to ``std::string::c_str()`` and ``std::string::data()``.
+
+Only the first such call in an argument to ``std::print`` or
+``std::format`` will be detected, so it may be necessary to run the check
+more than once when applying fixes.
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -123,6 +123,12 @@
 
 Changes in existing checks
 ^^
+- Improved :doc:`readability-redundant-string-cstr
+  ` check to recognise
+  unnecessary ``std::string::c_str()`` and ``std::string::data()`` calls in
+  arguments to ``std::print`` and ``std::format``. Note that only the first
+  such argument is currently reported so it may be necessary to run the
+  check multiple times to fix all of them.
 
 Removed checks
 ^^
Index: clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/RedundantStringCStrCheck.cpp
@@ -178,6 +178,16 @@
   /

[PATCH] D143348: [Clang][Doc][OpenCL] Release 16 notes

2023-02-05 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia created this revision.
Anastasia added a reviewer: svenvh.
Herald added subscribers: Naghasan, ebevhan, yaxunl.
Herald added a project: All.
Anastasia requested review of this revision.

Documented major OpenCL features in release 16.


https://reviews.llvm.org/D143348

Files:
  clang/docs/ReleaseNotes.rst


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -828,10 +828,17 @@
 Objective-C Language Changes in Clang
 -
 
-OpenCL C Language Changes in Clang
+OpenCL Kernel Language Changes in Clang
 --
 
-...
+- Improved diagnostics for C++ templates used in kernel arguments.
+- Removed redundant pragma for the ``arm-integer-dot-product`` extension.
+- Improved support of enqueued block for AMDGPU.
+- Improved builtin functions support:
+  * Allow disabling default header-based feature/extension support by passing 
``-D__undef_``.
+  * Fixed conditional definition of the depth image and read_write image3d 
builtins.
+  * Added ``nounwind`` attribute to all builtin functions.
+
 
 ABI Changes in Clang
 


Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -828,10 +828,17 @@
 Objective-C Language Changes in Clang
 -
 
-OpenCL C Language Changes in Clang
+OpenCL Kernel Language Changes in Clang
 --
 
-...
+- Improved diagnostics for C++ templates used in kernel arguments.
+- Removed redundant pragma for the ``arm-integer-dot-product`` extension.
+- Improved support of enqueued block for AMDGPU.
+- Improved builtin functions support:
+  * Allow disabling default header-based feature/extension support by passing ``-D__undef_``.
+  * Fixed conditional definition of the depth image and read_write image3d builtins.
+  * Added ``nounwind`` attribute to all builtin functions.
+
 
 ABI Changes in Clang
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


cfe-commits@lists.llvm.org

2023-02-05 Thread Owen Pan via cfe-commits

Author: David Turner
Date: 2023-02-05T13:33:33-08:00
New Revision: 35f2ac1763adcbd5ee9b49a98de24c0c420c323e

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

LOG: [clang-format] Fix inconsistent annotation of operator&

Token annotator incorrectly annotates operator& as a reference type in
situations like Boost serialization archives:
https://www.boost.org/doc/libs/1_81_0/libs/serialization/doc/tutorial.html

Add annotation rules for standalone and chained operator& instances while
preserving behavior for reference declarations at class scope. Add tests to
validate annotation and formatting behavior.

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

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/lib/Format/TokenAnnotator.h
clang/unittests/Format/FormatTest.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 1b1123fa36456..161720ecb770a 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -111,14 +111,29 @@ static bool isCppAttribute(bool IsCpp, const FormatToken 
&Tok) {
 class AnnotatingParser {
 public:
   AnnotatingParser(const FormatStyle &Style, AnnotatedLine &Line,
-   const AdditionalKeywords &Keywords)
+   const AdditionalKeywords &Keywords,
+   SmallVector &Scopes)
   : Style(Style), Line(Line), CurrentToken(Line.First), AutoFound(false),
-Keywords(Keywords) {
+Keywords(Keywords), Scopes(Scopes) {
 Contexts.push_back(Context(tok::unknown, 1, /*IsExpression=*/false));
 resetTokenMetadata();
   }
 
 private:
+  ScopeType getScopeType(const FormatToken &Token) const {
+switch (Token.getType()) {
+case TT_FunctionLBrace:
+case TT_LambdaLBrace:
+  return ST_Function;
+case TT_ClassLBrace:
+case TT_StructLBrace:
+case TT_UnionLBrace:
+  return ST_Class;
+default:
+  return ST_Other;
+}
+  }
+
   bool parseAngle() {
 if (!CurrentToken || !CurrentToken->Previous)
   return false;
@@ -849,6 +864,9 @@ class AnnotatingParser {
 unsigned CommaCount = 0;
 while (CurrentToken) {
   if (CurrentToken->is(tok::r_brace)) {
+assert(!Scopes.empty());
+assert(Scopes.back() == getScopeType(OpeningBrace));
+Scopes.pop_back();
 assert(OpeningBrace.Optional == CurrentToken->Optional);
 OpeningBrace.MatchingParen = CurrentToken;
 CurrentToken->MatchingParen = &OpeningBrace;
@@ -1148,6 +1166,7 @@ class AnnotatingParser {
 if (Previous && Previous->getType() != TT_DictLiteral)
   Previous->setType(TT_SelectorName);
   }
+  Scopes.push_back(getScopeType(*Tok));
   if (!parseBrace())
 return false;
   break;
@@ -1178,6 +1197,9 @@ class AnnotatingParser {
 case tok::r_square:
   return false;
 case tok::r_brace:
+  // Don't pop scope when encountering unbalanced r_brace.
+  if (!Scopes.empty())
+Scopes.pop_back();
   // Lines can start with '}'.
   if (Tok->Previous)
 return false;
@@ -2448,6 +2470,28 @@ class AnnotatingParser {
 if (IsExpression && !Contexts.back().CaretFound)
   return TT_BinaryOperator;
 
+// Opeartors at class scope are likely pointer or reference members.
+if (!Scopes.empty() && Scopes.back() == ST_Class)
+  return TT_PointerOrReference;
+
+// Tokens that indicate member access or chained operator& use.
+auto IsChainedOperatorAmpOrMember = [](const FormatToken *token) {
+  return !token || token->isOneOf(tok::amp, tok::period, tok::arrow,
+  tok::arrowstar, tok::periodstar);
+};
+
+// It's more likely that & represents operator& than an uninitialized
+// reference.
+if (Tok.is(tok::amp) && PrevToken && PrevToken->Tok.isAnyIdentifier() &&
+IsChainedOperatorAmpOrMember(PrevToken->getPreviousNonComment()) &&
+NextToken && NextToken->Tok.isAnyIdentifier()) {
+  if (auto NextNext = NextToken->getNextNonComment();
+  NextNext &&
+  (IsChainedOperatorAmpOrMember(NextNext) || NextNext->is(tok::semi))) 
{
+return TT_BinaryOperator;
+  }
+}
+
 return TT_PointerOrReference;
   }
 
@@ -2485,6 +2529,8 @@ class AnnotatingParser {
   bool AutoFound;
   const AdditionalKeywords &Keywords;
 
+  SmallVector &Scopes;
+
   // Set of "<" tokens that do not open a template parameter list. If 
parseAngle
   // determines that a specific token can't be a template opener, it will make
   // same decision irrespective of the decisions for tokens leading up to it.
@@ -2765,11 +2811,11 @@ static unsigned maxNestingDepth

cfe-commits@lists.llvm.org

2023-02-05 Thread Owen Pan 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 rG35f2ac1763ad: [clang-format] Fix inconsistent annotation of 
operator& (authored by dkt01, committed by owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141959

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

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -175,6 +175,73 @@
   ASSERT_EQ(Tokens.size(), 17u) << Tokens;
   EXPECT_TOKEN(Tokens[9], tok::ampamp, TT_PointerOrReference);
   EXPECT_TOKEN(Tokens[12], tok::ampamp, TT_PointerOrReference);
+
+  Tokens = annotate("Type1 &val1 = val2;");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::amp, TT_PointerOrReference);
+
+  Tokens = annotate("Type1 *val1 = &val2;");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::star, TT_PointerOrReference);
+  EXPECT_TOKEN(Tokens[4], tok::amp, TT_UnaryOperator);
+
+  Tokens = annotate("val1 & val2;");
+  ASSERT_EQ(Tokens.size(), 5u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::amp, TT_BinaryOperator);
+
+  Tokens = annotate("val1 & val2.member;");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::amp, TT_BinaryOperator);
+
+  Tokens = annotate("val1 & val2.*member;");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::amp, TT_BinaryOperator);
+
+  Tokens = annotate("val1.*member & val2;");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::amp, TT_BinaryOperator);
+
+  Tokens = annotate("val1 & val2->*member;");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::amp, TT_BinaryOperator);
+
+  Tokens = annotate("val1->member & val2;");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::amp, TT_BinaryOperator);
+
+  Tokens = annotate("val1 & val2 & val3;");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::amp, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[3], tok::amp, TT_BinaryOperator);
+
+  Tokens = annotate("val1 & val2 // comment\n"
+" & val3;");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::amp, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[4], tok::amp, TT_BinaryOperator);
+
+  Tokens =
+  annotate("val1 & val2.member & val3.member() & val4 & val5->member;");
+  ASSERT_EQ(Tokens.size(), 19u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::amp, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[5], tok::amp, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[11], tok::amp, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[13], tok::amp, TT_BinaryOperator);
+
+  Tokens = annotate("class c {\n"
+"  void func(type &a) { a & member; }\n"
+"  anotherType &member;\n"
+"}");
+  ASSERT_EQ(Tokens.size(), 22u) << Tokens;
+  EXPECT_TOKEN(Tokens[7], tok::amp, TT_PointerOrReference);
+  EXPECT_TOKEN(Tokens[12], tok::amp, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[17], tok::amp, TT_PointerOrReference);
+
+  Tokens = annotate("struct S {\n"
+"  auto Mem = C & D;\n"
+"}");
+  ASSERT_EQ(Tokens.size(), 12u) << Tokens;
+  EXPECT_TOKEN(Tokens[7], tok::amp, TT_BinaryOperator);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsUsesOfPlusAndMinus) {
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -11288,6 +11288,13 @@
 
   verifyFormat("int operator()(T (&&)[N]) { return 1; }");
   verifyFormat("int operator()(T (&)[N]) { return 0; }");
+
+  verifyFormat("val1 & val2;");
+  verifyFormat("val1 & val2 & val3;");
+  verifyFormat("class c {\n"
+   "  void func(type &a) { a & member; }\n"
+   "  anotherType &member;\n"
+   "}");
 }
 
 TEST_F(FormatTest, UnderstandsAttributes) {
Index: clang/lib/Format/TokenAnnotator.h
===
--- clang/lib/Format/TokenAnnotator.h
+++ clang/lib/Format/TokenAnnotator.h
@@ -34,6 +34,15 @@
   LT_CommentAbovePPDirective,
 };
 
+enum ScopeType {
+  // Contained in class declaration/definition.
+  ST_Class,
+  // Contained within function definition.
+  ST_Function,
+  // Contained within other scope block (loop, if/else, etc).
+  ST_Other,
+};
+
 class AnnotatedLine {
 public:
   AnnotatedLine(const UnwrappedLine &Line)
@@ -178,7 +187,7 @@
   // FIXME: Can/should this be done in the UnwrappedLineParser?
   void setCommentLineLevels(SmallV

[PATCH] D138453: [clang] Add serialization for loop hint annotation tokens

2023-02-05 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

It looks like https://github.com/llvm/llvm-project/issues/60543 is hitting your 
added `llvm_unreachable("missing serialization code for annotation token");` is 
this expected.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138453

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


[PATCH] D138453: [clang] Add serialization for loop hint annotation tokens

2023-02-05 Thread Dustin L. Howett via Phabricator via cfe-commits
DHowett-MSFT added a comment.

In D138453#4105209 , @shafik wrote:

> It looks like https://github.com/llvm/llvm-project/issues/60543 is hitting 
> your added `llvm_unreachable("missing serialization code for annotation 
> token");` is this expected.

I believe it's expected that we hit this assertion - it's clearer than the 
original message, and more directly indicates that `#pragma pack` cannot be 
serialized.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138453

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


[PATCH] D143355: [RISCV] Default to -ffixed-x18 for Fuchsia

2023-02-05 Thread Roland McGrath via Phabricator via cfe-commits
mcgrathr created this revision.
mcgrathr added reviewers: phosek, paulkirth, leonardchan.
Herald added subscribers: luke, VincentWu, abrachet, vkmr, frasercrmck, 
evandro, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, 
jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, 
zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, 
rbar, asb, hiraditya, arichardson.
Herald added a project: All.
mcgrathr requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, pcwang-thead, eopXD, 
MaskRay.
Herald added projects: clang, LLVM.

Fuchsia's ABI always reserves the x18 (s2) register for the
ShadowCallStack ABI, even when -fsanitize=shadow-call-stack is
not enabled.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143355

Files:
  clang/lib/Driver/SanitizerArgs.cpp
  llvm/include/llvm/TargetParser/RISCVTargetParser.h
  llvm/lib/Target/RISCV/RISCVSubtarget.cpp
  llvm/lib/TargetParser/RISCVTargetParser.cpp
  llvm/test/CodeGen/RISCV/reserved-regs.ll

Index: llvm/test/CodeGen/RISCV/reserved-regs.ll
===
--- llvm/test/CodeGen/RISCV/reserved-regs.ll
+++ llvm/test/CodeGen/RISCV/reserved-regs.ll
@@ -57,6 +57,8 @@
 ; RUN: llc -mtriple=riscv32 -mattr=+reserve-x31 -verify-machineinstrs < %s | FileCheck %s -check-prefix=X31
 ; RUN: llc -mtriple=riscv64 -mattr=+reserve-x31 -verify-machineinstrs < %s | FileCheck %s -check-prefix=X31
 
+; RUN: llc -mtriple=riscv64-fuchsia -verify-machineinstrs < %s | FileCheck %s -check-prefix=X18
+
 ; This program is free to use all registers, but needs a stack pointer for
 ; spill values, so do not test for reserving the stack pointer.
 
Index: llvm/lib/TargetParser/RISCVTargetParser.cpp
===
--- llvm/lib/TargetParser/RISCVTargetParser.cpp
+++ llvm/lib/TargetParser/RISCVTargetParser.cpp
@@ -14,6 +14,7 @@
 #include "llvm/TargetParser/RISCVTargetParser.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/TargetParser/Triple.h"
 
 namespace llvm {
 namespace RISCV {
@@ -100,5 +101,10 @@
   return true;
 }
 
+bool isX18ReservedByDefault(const Triple &TT) {
+  // X18 is reserved for the ShadowCallStack ABI (even when not enabled).
+  return TT.isOSFuchsia();
+}
+
 } // namespace RISCV
 } // namespace llvm
Index: llvm/lib/Target/RISCV/RISCVSubtarget.cpp
===
--- llvm/lib/Target/RISCV/RISCVSubtarget.cpp
+++ llvm/lib/Target/RISCV/RISCVSubtarget.cpp
@@ -11,13 +11,13 @@
 //===--===//
 
 #include "RISCVSubtarget.h"
+#include "GISel/RISCVCallLowering.h"
+#include "GISel/RISCVLegalizerInfo.h"
+#include "GISel/RISCVRegisterBankInfo.h"
 #include "RISCV.h"
 #include "RISCVFrameLowering.h"
 #include "RISCVMacroFusion.h"
 #include "RISCVTargetMachine.h"
-#include "GISel/RISCVCallLowering.h"
-#include "GISel/RISCVLegalizerInfo.h"
-#include "GISel/RISCVRegisterBankInfo.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Support/ErrorHandling.h"
 
@@ -84,6 +84,9 @@
   initializeSubtargetDependencies(TT, CPU, TuneCPU, FS, ABIName)),
   InstrInfo(*this), RegInfo(getHwMode()), TLInfo(TM, *this),
   TargetTriple(TT) {
+  if (RISCV::isX18ReservedByDefault(TT))
+UserReservedRegister.set(RISCV::X18);
+
   CallLoweringInfo.reset(new RISCVCallLowering(*getTargetLowering()));
   Legalizer.reset(new RISCVLegalizerInfo(*this));
 
Index: llvm/include/llvm/TargetParser/RISCVTargetParser.h
===
--- llvm/include/llvm/TargetParser/RISCVTargetParser.h
+++ llvm/include/llvm/TargetParser/RISCVTargetParser.h
@@ -18,6 +18,9 @@
 #include 
 
 namespace llvm {
+
+class Triple;
+
 namespace RISCV {
 
 // We use 64 bits as the known part in the scalable vector types.
@@ -38,6 +41,8 @@
 void fillValidTuneCPUArchList(SmallVectorImpl &Values, bool IsRV64);
 bool getCPUFeaturesExceptStdExt(CPUKind Kind, std::vector &Features);
 
+bool isX18ReservedByDefault(const Triple &TT);
+
 } // namespace RISCV
 } // namespace llvm
 
Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -19,6 +19,7 @@
 #include "llvm/Support/TargetParser.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/TargetParser/AArch64TargetParser.h"
+#include "llvm/TargetParser/RISCVTargetParser.h"
 #include "llvm/Transforms/Instrumentation/AddressSanitizerOptions.h"
 #include 
 
@@ -545,7 +546,8 @@
   if ((Kinds & SanitizerKind::ShadowCallStack) &&
   ((TC.getTriple().isAArch64() &&
 !llvm::AArch64::isX18ReservedByDefault(TC.getTriple())) ||
-   TC.getTriple().isRISCV()) &&
+   (TC.getTriple().isRISCV() &&
+!llvm::RISCV::isX

[PATCH] D143357: [RISCV] Default to -fsanitize=shadow-call-stack for Fuchsia

2023-02-05 Thread Roland McGrath via Phabricator via cfe-commits
mcgrathr created this revision.
mcgrathr added reviewers: phosek, paulkirth, leonardchan.
Herald added subscribers: VincentWu, abrachet, vkmr, evandro, luismarques, 
sameer.abuasal, s.egerton, Jim, benna, psnobl, rogfer01, shiva0217, kito-cheng, 
simoncook, arichardson.
Herald added a project: All.
mcgrathr requested review of this revision.
Herald added subscribers: cfe-commits, pcwang-thead, eopXD, MaskRay.
Herald added a project: clang.

The ShadowCallStack is the preferred and default ABI for Fuchsia.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143357

Files:
  clang/lib/Driver/ToolChains/Fuchsia.cpp
  clang/test/Driver/fuchsia.c


Index: clang/test/Driver/fuchsia.c
===
--- clang/test/Driver/fuchsia.c
+++ clang/test/Driver/fuchsia.c
@@ -31,6 +31,7 @@
 // CHECK: "-isysroot" "[[SYSROOT:[^"]+]]"
 // CHECK: "-internal-externc-isystem" "[[SYSROOT]]{{/|}}include"
 // CHECK-AARCH64: "-fsanitize=shadow-call-stack"
+// CHECK-RISCV64: "-fsanitize=shadow-call-stack"
 // CHECK-X86_64: "-fsanitize=safe-stack"
 // CHECK: "-stack-protector" "2"
 // CHECK-AARCH64: "-target-feature" "+outline-atomics"
Index: clang/lib/Driver/ToolChains/Fuchsia.cpp
===
--- clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -466,6 +466,7 @@
   SanitizerMask Res;
   switch (getTriple().getArch()) {
   case llvm::Triple::aarch64:
+  case llvm::Triple::riscv64:
 Res |= SanitizerKind::ShadowCallStack;
 break;
   case llvm::Triple::x86_64:


Index: clang/test/Driver/fuchsia.c
===
--- clang/test/Driver/fuchsia.c
+++ clang/test/Driver/fuchsia.c
@@ -31,6 +31,7 @@
 // CHECK: "-isysroot" "[[SYSROOT:[^"]+]]"
 // CHECK: "-internal-externc-isystem" "[[SYSROOT]]{{/|}}include"
 // CHECK-AARCH64: "-fsanitize=shadow-call-stack"
+// CHECK-RISCV64: "-fsanitize=shadow-call-stack"
 // CHECK-X86_64: "-fsanitize=safe-stack"
 // CHECK: "-stack-protector" "2"
 // CHECK-AARCH64: "-target-feature" "+outline-atomics"
Index: clang/lib/Driver/ToolChains/Fuchsia.cpp
===
--- clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -466,6 +466,7 @@
   SanitizerMask Res;
   switch (getTriple().getArch()) {
   case llvm::Triple::aarch64:
+  case llvm::Triple::riscv64:
 Res |= SanitizerKind::ShadowCallStack;
 break;
   case llvm::Triple::x86_64:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D143357: [RISCV] Default to -fsanitize=shadow-call-stack for Fuchsia

2023-02-05 Thread Petr Hosek via Phabricator via cfe-commits
phosek accepted this revision.
phosek added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: clang/lib/Driver/ToolChains/Fuchsia.cpp:476
   default:
 // TODO: Enable SafeStack on RISC-V once tested.
 break;

Can you remove this `TODO`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143357

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


[PATCH] D143355: [RISCV] Default to -ffixed-x18 for Fuchsia

2023-02-05 Thread Petr Hosek via Phabricator via cfe-commits
phosek accepted this revision.
phosek 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/D143355/new/

https://reviews.llvm.org/D143355

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


[PATCH] D143355: [RISCV] Default to -ffixed-x18 for Fuchsia

2023-02-05 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added inline comments.



Comment at: llvm/lib/Target/RISCV/RISCVSubtarget.cpp:16
+#include "GISel/RISCVLegalizerInfo.h"
+#include "GISel/RISCVRegisterBankInfo.h"
 #include "RISCV.h"

Unrelated change


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143355

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


[clang] 26182df - [docs] Replace deprecated -target with --target=

2023-02-05 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-02-05T16:34:22-08:00
New Revision: 26182dfa3600f33995c20214a226eb482331fb01

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

LOG: [docs] Replace deprecated -target with --target=

Added: 


Modified: 
clang/docs/OpenCLSupport.rst
clang/docs/UsersManual.rst

Removed: 




diff  --git a/clang/docs/OpenCLSupport.rst b/clang/docs/OpenCLSupport.rst
index 8b68aa927116e..43c30970d113b 100644
--- a/clang/docs/OpenCLSupport.rst
+++ b/clang/docs/OpenCLSupport.rst
@@ -113,7 +113,7 @@ To enable modules for OpenCL:
 
.. code-block:: console
 
- $ clang -target spir-unknown-unknown -c -emit-llvm -Xclang 
-finclude-default-header -fmodules -fimplicit-module-maps 
-fmodules-cache-path= test.cl
+ $ clang --target=spir-unknown-unknown -c -emit-llvm -Xclang 
-finclude-default-header -fmodules -fimplicit-module-maps 
-fmodules-cache-path= test.cl
 
 Another way to circumvent long parsing latency for the OpenCL builtin
 declarations is to use mechanism enabled by :ref:`-fdeclare-opencl-builtins

diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 7dd8ecb5fcc4d..18e1e9aaca2c4 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -3305,8 +3305,8 @@ to the target, for example:
 
.. code-block:: console
 
- $ clang -target nvptx64-unknown-unknown test.cl
- $ clang -target amdgcn-amd-amdhsa -mcpu=gfx900 test.cl
+ $ clang --target=nvptx64-unknown-unknown test.cl
+ $ clang --target=amdgcn-amd-amdhsa -mcpu=gfx900 test.cl
 
 Compiling to bitcode can be done as follows:
 
@@ -3390,13 +3390,13 @@ Some extra options are available to support special 
OpenCL features.
 
.. code-block:: console
 
- $ clang -c -target spirv64 -cl-ext=-cl_khr_fp64 test.cl
+ $ clang -c --target=spirv64 -cl-ext=-cl_khr_fp64 test.cl
 
Enabling all extensions except double support in R600 AMD GPU can be done 
using:
 
.. code-block:: console
 
- $ clang -target r600 -cl-ext=-all,+cl_khr_fp16 test.cl
+ $ clang --target=r600 -cl-ext=-all,+cl_khr_fp16 test.cl
 
Note that some generic targets e.g. SPIR/SPIR-V enable all 
extensions/features in
clang by default.
@@ -3417,13 +3417,13 @@ There is a set of concrete HW architectures that OpenCL 
can be compiled for.
 
.. code-block:: console
 
- $ clang -target amdgcn-amd-amdhsa -mcpu=gfx900 test.cl
+ $ clang --target=amdgcn-amd-amdhsa -mcpu=gfx900 test.cl
 
 - For Nvidia architectures:
 
.. code-block:: console
 
- $ clang -target nvptx64-unknown-unknown test.cl
+ $ clang --target=nvptx64-unknown-unknown test.cl
 
 
 Generic Targets
@@ -3433,8 +3433,8 @@ Generic Targets
 
.. code-block:: console
 
-$ clang -target spirv32 -c test.cl
-$ clang -target spirv64 -c test.cl
+$ clang --target=spirv32 -c test.cl
+$ clang --target=spirv64 -c test.cl
 
   More details can be found in :ref:`the SPIR-V support section `.
 
@@ -3445,8 +3445,8 @@ Generic Targets
 
.. code-block:: console
 
-$ clang -target spir test.cl -emit-llvm -c
-$ clang -target spir64 test.cl -emit-llvm -c
+$ clang --target=spir test.cl -emit-llvm -c
+$ clang --target=spir64 test.cl -emit-llvm -c
 
   Clang will generate SPIR v1.2 compatible IR for OpenCL versions up to 2.0 and
   SPIR v2.0 for OpenCL v2.0 or C++ for OpenCL.
@@ -3678,7 +3678,7 @@ Example of use:
.. code-block:: console
 
  clang -cl-std=clc++1.0 test.clcpp
- clang -cl-std=clc++ -c -target spirv64 test.cl
+ clang -cl-std=clc++ -c --target=spirv64 test.cl
 
 
 By default, files with ``.clcpp`` extension are compiled with the C++ for
@@ -3926,8 +3926,8 @@ Example usage for OpenCL kernel compilation:
 
.. code-block:: console
 
- $ clang -target spirv32 -c test.cl
- $ clang -target spirv64 -c test.cl
+ $ clang --target=spirv32 -c test.cl
+ $ clang --target=spirv64 -c test.cl
 
 Both invocations of Clang will result in the generation of a SPIR-V binary file
 `test.o` for 32 bit and 64 bit respectively. This file can be imported
@@ -3944,7 +3944,7 @@ the command line.
 
.. code-block:: console
 
- $ clang -target spirv32 -fintegrated-objemitter -c test.cl
+ $ clang --target=spirv32 -fintegrated-objemitter -c test.cl
 
 Note that only very basic functionality is supported at this point and 
therefore
 it is not suitable for arbitrary use cases. This feature is only enabled when 
clang
@@ -3959,7 +3959,7 @@ installation instructions
 
.. code-block:: console
 
- $ clang -target spirv64 test1.cl test2.cl
+ $ clang --target=spirv64 test1.cl test2.cl
 
 More information about the SPIR-V target settings and supported versions of 
SPIR-V
 format can be found in `the SPIR-V target guide



___

[clang] cad708b - [clang-format] Recognize Verilog non-blocking assignment

2023-02-05 Thread via cfe-commits

Author: sstwcw
Date: 2023-02-06T00:58:11Z
New Revision: cad708b9a1ecbf5645706056bb7c4fc0ea4721b6

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

LOG: [clang-format] Recognize Verilog non-blocking assignment

Reviewed By: HazardyKnusperkeks, owenpan

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

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/lib/Format/WhitespaceManager.cpp
clang/unittests/Format/FormatTestVerilog.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 161720ecb770a..40e1951872243 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1647,6 +1647,7 @@ class AnnotatingParser {
 bool CaretFound = false;
 bool InCpp11AttributeSpecifier = false;
 bool InCSharpAttributeSpecifier = false;
+bool VerilogAssignmentFound = false;
 enum {
   Unknown,
   // Like the part after `:` in a constructor.
@@ -1944,6 +1945,17 @@ class AnnotatingParser {
(!Current.Previous || Current.Previous->isNot(tok::l_square)) &&
(!Current.is(tok::greater) &&
 Style.Language != FormatStyle::LK_TextProto)) {
+  if (Style.isVerilog()) {
+if (Current.is(tok::lessequal) && Contexts.size() == 1 &&
+!Contexts.back().VerilogAssignmentFound) {
+  // In Verilog `<=` is assignment if in its own statement. It is a
+  // statement instead of an expression, that is it can not be chained.
+  Current.ForcedPrecedence = prec::Assignment;
+  Current.setFinalizedType(TT_BinaryOperator);
+}
+if (Current.getPrecedence() == prec::Assignment)
+  Contexts.back().VerilogAssignmentFound = true;
+  }
   Current.setType(TT_BinaryOperator);
 } else if (Current.is(tok::comment)) {
   if (Current.TokenText.startswith("/*")) {

diff  --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index 9951906b6af01..a68759418d595 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -838,7 +838,12 @@ void WhitespaceManager::alignConsecutiveAssignments() {
 
 return Style.AlignConsecutiveAssignments.AlignCompound
? C.Tok->getPrecedence() == prec::Assignment
-   : C.Tok->is(tok::equal);
+   : (C.Tok->is(tok::equal) ||
+  // In Verilog the '<=' is not a compound assignment, thus
+  // it is aligned even when the AlignCompound option is 
not
+  // set.
+  (Style.isVerilog() && C.Tok->is(tok::lessequal) &&
+   C.Tok->getPrecedence() == prec::Assignment));
   },
   Changes, /*StartAt=*/0, Style.AlignConsecutiveAssignments,
   /*RightJustify=*/true);

diff  --git a/clang/unittests/Format/FormatTestVerilog.cpp 
b/clang/unittests/Format/FormatTestVerilog.cpp
index 92931d3e5e74c..7931a31decfa5 100644
--- a/clang/unittests/Format/FormatTestVerilog.cpp
+++ b/clang/unittests/Format/FormatTestVerilog.cpp
@@ -45,6 +45,58 @@ class FormatTestVerilog : public ::testing::Test {
   }
 };
 
+TEST_F(FormatTestVerilog, Align) {
+  FormatStyle Style = getLLVMStyle(FormatStyle::LK_Verilog);
+  Style.AlignConsecutiveAssignments.Enabled = true;
+  verifyFormat("x<= x;\n"
+   "sfdbddfbdfbb <= x;\n"
+   "x = x;",
+   Style);
+  verifyFormat("x= x;\n"
+   "sfdbddfbdfbb = x;\n"
+   "x= x;",
+   Style);
+  // Compound assignments are not aligned by default. '<=' is not a compound
+  // assignment.
+  verifyFormat("x<= x;\n"
+   "sfdbddfbdfbb <= x;",
+   Style);
+  verifyFormat("x += x;\n"
+   "sfdbddfbdfbb <= x;",
+   Style);
+  verifyFormat("x <<= x;\n"
+   "sfdbddfbdfbb <= x;",
+   Style);
+  verifyFormat("x <<<= x;\n"
+   "sfdbddfbdfbb <= x;",
+   Style);
+  verifyFormat("x >>= x;\n"
+   "sfdbddfbdfbb <= x;",
+   Style);
+  verifyFormat("x >>>= x;\n"
+   "sfdbddfbdfbb <= x;",
+   Style);
+  Style.AlignConsecutiveAssignments.AlignCompound = true;
+  verifyFormat("x<= x;\n"
+   "sfdbddfbdfbb <= x;",
+   Style);
+  verifyFormat("x+= x;\n"
+   "sfdbddfbdfbb <= x;",
+   Style);
+  verifyFormat("x<<= x;\n"
+   "sfdbddfbdfbb  <= x;",
+   Style);
+  verifyFormat("x<<<= x;\n"
+  

[PATCH] D142891: [clang-format] Recognize Verilog non-blocking assignment

2023-02-05 Thread sstwcw 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 rGcad708b9a1ec: [clang-format] Recognize Verilog non-blocking 
assignment (authored by sstwcw).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142891

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

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1314,6 +1314,21 @@
   EXPECT_TOKEN(Tokens[5], tok::question, TT_ConditionalExpr);
   EXPECT_TOKEN(Tokens[7], tok::colon, TT_ConditionalExpr);
   EXPECT_TOKEN(Tokens[9], tok::colon, TT_GotoLabelColon);
+  // Non-blocking assignments.
+  Tokens = Annotate("a <= b;");
+  ASSERT_EQ(Tokens.size(), 5u);
+  EXPECT_TOKEN(Tokens[1], tok::lessequal, TT_BinaryOperator);
+  EXPECT_TOKEN_PRECEDENCE(Tokens[1], prec::Assignment);
+  Tokens = Annotate("if (a <= b) break;");
+  ASSERT_EQ(Tokens.size(), 9u);
+  EXPECT_TOKEN(Tokens[3], tok::lessequal, TT_BinaryOperator);
+  EXPECT_TOKEN_PRECEDENCE(Tokens[3], prec::Relational);
+  Tokens = Annotate("a <= b <= a;");
+  ASSERT_EQ(Tokens.size(), 7u);
+  EXPECT_TOKEN(Tokens[1], tok::lessequal, TT_BinaryOperator);
+  EXPECT_TOKEN_PRECEDENCE(Tokens[1], prec::Assignment);
+  EXPECT_TOKEN(Tokens[3], tok::lessequal, TT_BinaryOperator);
+  EXPECT_TOKEN_PRECEDENCE(Tokens[3], prec::Relational);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandConstructors) {
Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -45,6 +45,58 @@
   }
 };
 
+TEST_F(FormatTestVerilog, Align) {
+  FormatStyle Style = getLLVMStyle(FormatStyle::LK_Verilog);
+  Style.AlignConsecutiveAssignments.Enabled = true;
+  verifyFormat("x<= x;\n"
+   "sfdbddfbdfbb <= x;\n"
+   "x = x;",
+   Style);
+  verifyFormat("x= x;\n"
+   "sfdbddfbdfbb = x;\n"
+   "x= x;",
+   Style);
+  // Compound assignments are not aligned by default. '<=' is not a compound
+  // assignment.
+  verifyFormat("x<= x;\n"
+   "sfdbddfbdfbb <= x;",
+   Style);
+  verifyFormat("x += x;\n"
+   "sfdbddfbdfbb <= x;",
+   Style);
+  verifyFormat("x <<= x;\n"
+   "sfdbddfbdfbb <= x;",
+   Style);
+  verifyFormat("x <<<= x;\n"
+   "sfdbddfbdfbb <= x;",
+   Style);
+  verifyFormat("x >>= x;\n"
+   "sfdbddfbdfbb <= x;",
+   Style);
+  verifyFormat("x >>>= x;\n"
+   "sfdbddfbdfbb <= x;",
+   Style);
+  Style.AlignConsecutiveAssignments.AlignCompound = true;
+  verifyFormat("x<= x;\n"
+   "sfdbddfbdfbb <= x;",
+   Style);
+  verifyFormat("x+= x;\n"
+   "sfdbddfbdfbb <= x;",
+   Style);
+  verifyFormat("x<<= x;\n"
+   "sfdbddfbdfbb  <= x;",
+   Style);
+  verifyFormat("x<<<= x;\n"
+   "sfdbddfbdfbb   <= x;",
+   Style);
+  verifyFormat("x>>= x;\n"
+   "sfdbddfbdfbb  <= x;",
+   Style);
+  verifyFormat("x>>>= x;\n"
+   "sfdbddfbdfbb   <= x;",
+   Style);
+}
+
 TEST_F(FormatTestVerilog, BasedLiteral) {
   verifyFormat("x = '0;");
   verifyFormat("x = '1;");
Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -838,7 +838,12 @@
 
 return Style.AlignConsecutiveAssignments.AlignCompound
? C.Tok->getPrecedence() == prec::Assignment
-   : C.Tok->is(tok::equal);
+   : (C.Tok->is(tok::equal) ||
+  // In Verilog the '<=' is not a compound assignment, thus
+  // it is aligned even when the AlignCompound option is not
+  // set.
+  (Style.isVerilog() && C.Tok->is(tok::lessequal) &&
+   C.Tok->getPrecedence() == prec::Assignment));
   },
   Changes, /*StartAt=*/0, Style.AlignConsecutiveAssignments,
   /*RightJustify=*/true);
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1647,6 +1647,7 @@
 bool

[PATCH] D143325: [Driver] Add -mllvm= as an alias for -mllvm

2023-02-05 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur added a comment.

This patch broke the Flang buildbot, e.g. 
https://lab.llvm.org/buildbot/#/builders/172/builds/23305

The tests
https://github.com/llvm/llvm-project/blob/main/flang/test/Driver/driver-help.f90
https://github.com/llvm/llvm-project/blob/main/flang/test/Driver/driver-help-hidden.f90

They check the entire output of `-help` and need to be updated for new options.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143325

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


[PATCH] D143325: [Driver] Add -mllvm= as an alias for -mllvm

2023-02-05 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D143325#4105356 , @Meinersbur 
wrote:

> This patch broke the Flang buildbot, e.g. 
> https://lab.llvm.org/buildbot/#/builders/172/builds/23305
>
> The tests
> https://github.com/llvm/llvm-project/blob/main/flang/test/Driver/driver-help.f90
> https://github.com/llvm/llvm-project/blob/main/flang/test/Driver/driver-help-hidden.f90
>
> They check the entire output of `-help` and need to be updated for new 
> options.

Thanks for the report. Already fixed by https://reviews.llvm.org/rG6a8a423c


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143325

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


[PATCH] D142606: Lazyly initialize uncommon toolchain detector

2023-02-05 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

LGTM




Comment at: clang/lib/Driver/ToolChains/LazyDetector.h:36
+}
+return &Detector.value();
+  }

tbaeder wrote:
> Is the `.value()` here permitted? AFAIK the convention is to always use 
> `operator*`.
> 
> And I think @aaron.ballman would tell you to drop the `{}` around that 
> single-statement `if` :)
llvm style prefers `const T` to `T const`


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

https://reviews.llvm.org/D142606

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


[PATCH] D143347: [lldb][DWARF] Infer no_unique_address attribute

2023-02-05 Thread Michael Buch via Phabricator via cfe-commits
Michael137 added a comment.

From a first glance looks ok but ideally the clang changes would be a separate 
review. Particularly the ASTImporter change could use a unittest


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143347

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


[PATCH] D143355: [RISCV] Default to -ffixed-x18 for Fuchsia

2023-02-05 Thread Roland McGrath via Phabricator via cfe-commits
mcgrathr added inline comments.



Comment at: llvm/lib/Target/RISCV/RISCVSubtarget.cpp:16
+#include "GISel/RISCVLegalizerInfo.h"
+#include "GISel/RISCVRegisterBankInfo.h"
 #include "RISCV.h"

jrtc27 wrote:
> Unrelated change
arcanist requested it via clang-format



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143355

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


[PATCH] D143355: [RISCV] Default to -ffixed-x18 for Fuchsia

2023-02-05 Thread Roland McGrath via Phabricator via cfe-commits
mcgrathr updated this revision to Diff 494970.
mcgrathr added a comment.

rebased


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143355

Files:
  clang/lib/Driver/SanitizerArgs.cpp
  llvm/include/llvm/TargetParser/RISCVTargetParser.h
  llvm/lib/Target/RISCV/RISCVSubtarget.cpp
  llvm/lib/TargetParser/RISCVTargetParser.cpp
  llvm/test/CodeGen/RISCV/reserved-regs.ll

Index: llvm/test/CodeGen/RISCV/reserved-regs.ll
===
--- llvm/test/CodeGen/RISCV/reserved-regs.ll
+++ llvm/test/CodeGen/RISCV/reserved-regs.ll
@@ -57,6 +57,8 @@
 ; RUN: llc -mtriple=riscv32 -mattr=+reserve-x31 -verify-machineinstrs < %s | FileCheck %s -check-prefix=X31
 ; RUN: llc -mtriple=riscv64 -mattr=+reserve-x31 -verify-machineinstrs < %s | FileCheck %s -check-prefix=X31
 
+; RUN: llc -mtriple=riscv64-fuchsia -verify-machineinstrs < %s | FileCheck %s -check-prefix=X18
+
 ; This program is free to use all registers, but needs a stack pointer for
 ; spill values, so do not test for reserving the stack pointer.
 
Index: llvm/lib/TargetParser/RISCVTargetParser.cpp
===
--- llvm/lib/TargetParser/RISCVTargetParser.cpp
+++ llvm/lib/TargetParser/RISCVTargetParser.cpp
@@ -14,6 +14,7 @@
 #include "llvm/TargetParser/RISCVTargetParser.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/TargetParser/Triple.h"
 
 namespace llvm {
 namespace RISCV {
@@ -100,5 +101,10 @@
   return true;
 }
 
+bool isX18ReservedByDefault(const Triple &TT) {
+  // X18 is reserved for the ShadowCallStack ABI (even when not enabled).
+  return TT.isOSFuchsia();
+}
+
 } // namespace RISCV
 } // namespace llvm
Index: llvm/lib/Target/RISCV/RISCVSubtarget.cpp
===
--- llvm/lib/Target/RISCV/RISCVSubtarget.cpp
+++ llvm/lib/Target/RISCV/RISCVSubtarget.cpp
@@ -11,13 +11,13 @@
 //===--===//
 
 #include "RISCVSubtarget.h"
+#include "GISel/RISCVCallLowering.h"
+#include "GISel/RISCVLegalizerInfo.h"
+#include "GISel/RISCVRegisterBankInfo.h"
 #include "RISCV.h"
 #include "RISCVFrameLowering.h"
 #include "RISCVMacroFusion.h"
 #include "RISCVTargetMachine.h"
-#include "GISel/RISCVCallLowering.h"
-#include "GISel/RISCVLegalizerInfo.h"
-#include "GISel/RISCVRegisterBankInfo.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Support/ErrorHandling.h"
 
@@ -83,6 +83,9 @@
   FrameLowering(
   initializeSubtargetDependencies(TT, CPU, TuneCPU, FS, ABIName)),
   InstrInfo(*this), RegInfo(getHwMode()), TLInfo(TM, *this) {
+  if (RISCV::isX18ReservedByDefault(TT))
+UserReservedRegister.set(RISCV::X18);
+
   CallLoweringInfo.reset(new RISCVCallLowering(*getTargetLowering()));
   Legalizer.reset(new RISCVLegalizerInfo(*this));
 
Index: llvm/include/llvm/TargetParser/RISCVTargetParser.h
===
--- llvm/include/llvm/TargetParser/RISCVTargetParser.h
+++ llvm/include/llvm/TargetParser/RISCVTargetParser.h
@@ -18,6 +18,9 @@
 #include 
 
 namespace llvm {
+
+class Triple;
+
 namespace RISCV {
 
 // We use 64 bits as the known part in the scalable vector types.
@@ -38,6 +41,8 @@
 void fillValidTuneCPUArchList(SmallVectorImpl &Values, bool IsRV64);
 bool getCPUFeaturesExceptStdExt(CPUKind Kind, std::vector &Features);
 
+bool isX18ReservedByDefault(const Triple &TT);
+
 } // namespace RISCV
 } // namespace llvm
 
Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -19,6 +19,7 @@
 #include "llvm/Support/TargetParser.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/TargetParser/AArch64TargetParser.h"
+#include "llvm/TargetParser/RISCVTargetParser.h"
 #include "llvm/Transforms/Instrumentation/AddressSanitizerOptions.h"
 #include 
 
@@ -545,7 +546,8 @@
   if ((Kinds & SanitizerKind::ShadowCallStack) &&
   ((TC.getTriple().isAArch64() &&
 !llvm::AArch64::isX18ReservedByDefault(TC.getTriple())) ||
-   TC.getTriple().isRISCV()) &&
+   (TC.getTriple().isRISCV() &&
+!llvm::RISCV::isX18ReservedByDefault(TC.getTriple( &&
   !Args.hasArg(options::OPT_ffixed_x18) && DiagnoseErrors) {
 D.Diag(diag::err_drv_argument_only_allowed_with)
 << lastArgumentForMask(D, Args, Kinds & SanitizerKind::ShadowCallStack)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D143355: [RISCV] Default to -ffixed-x18 for Fuchsia

2023-02-05 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: llvm/lib/Target/RISCV/RISCVSubtarget.cpp:16
+#include "GISel/RISCVLegalizerInfo.h"
+#include "GISel/RISCVRegisterBankInfo.h"
 #include "RISCV.h"

mcgrathr wrote:
> jrtc27 wrote:
> > Unrelated change
> arcanist requested it via clang-format
> 
Rebase. I fixed it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143355

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


[PATCH] D143355: [RISCV] Default to -ffixed-x18 for Fuchsia

2023-02-05 Thread Roland McGrath via Phabricator via cfe-commits
mcgrathr updated this revision to Diff 494972.
mcgrathr added a comment.

rebased, added clang driver test vs -fsanitize=shadow-call-stack


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143355

Files:
  clang/lib/Driver/SanitizerArgs.cpp
  clang/test/Driver/sanitizer-ld.c
  llvm/include/llvm/TargetParser/RISCVTargetParser.h
  llvm/lib/Target/RISCV/RISCVSubtarget.cpp
  llvm/lib/TargetParser/RISCVTargetParser.cpp
  llvm/test/CodeGen/RISCV/reserved-regs.ll

Index: llvm/test/CodeGen/RISCV/reserved-regs.ll
===
--- llvm/test/CodeGen/RISCV/reserved-regs.ll
+++ llvm/test/CodeGen/RISCV/reserved-regs.ll
@@ -57,6 +57,8 @@
 ; RUN: llc -mtriple=riscv32 -mattr=+reserve-x31 -verify-machineinstrs < %s | FileCheck %s -check-prefix=X31
 ; RUN: llc -mtriple=riscv64 -mattr=+reserve-x31 -verify-machineinstrs < %s | FileCheck %s -check-prefix=X31
 
+; RUN: llc -mtriple=riscv64-fuchsia -verify-machineinstrs < %s | FileCheck %s -check-prefix=X18
+
 ; This program is free to use all registers, but needs a stack pointer for
 ; spill values, so do not test for reserving the stack pointer.
 
Index: llvm/lib/TargetParser/RISCVTargetParser.cpp
===
--- llvm/lib/TargetParser/RISCVTargetParser.cpp
+++ llvm/lib/TargetParser/RISCVTargetParser.cpp
@@ -14,6 +14,7 @@
 #include "llvm/TargetParser/RISCVTargetParser.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/TargetParser/Triple.h"
 
 namespace llvm {
 namespace RISCV {
@@ -100,5 +101,10 @@
   return true;
 }
 
+bool isX18ReservedByDefault(const Triple &TT) {
+  // X18 is reserved for the ShadowCallStack ABI (even when not enabled).
+  return TT.isOSFuchsia();
+}
+
 } // namespace RISCV
 } // namespace llvm
Index: llvm/lib/Target/RISCV/RISCVSubtarget.cpp
===
--- llvm/lib/Target/RISCV/RISCVSubtarget.cpp
+++ llvm/lib/Target/RISCV/RISCVSubtarget.cpp
@@ -83,6 +83,9 @@
   FrameLowering(
   initializeSubtargetDependencies(TT, CPU, TuneCPU, FS, ABIName)),
   InstrInfo(*this), RegInfo(getHwMode()), TLInfo(TM, *this) {
+  if (RISCV::isX18ReservedByDefault(TT))
+UserReservedRegister.set(RISCV::X18);
+
   CallLoweringInfo.reset(new RISCVCallLowering(*getTargetLowering()));
   Legalizer.reset(new RISCVLegalizerInfo(*this));
 
Index: llvm/include/llvm/TargetParser/RISCVTargetParser.h
===
--- llvm/include/llvm/TargetParser/RISCVTargetParser.h
+++ llvm/include/llvm/TargetParser/RISCVTargetParser.h
@@ -18,6 +18,9 @@
 #include 
 
 namespace llvm {
+
+class Triple;
+
 namespace RISCV {
 
 // We use 64 bits as the known part in the scalable vector types.
@@ -38,6 +41,8 @@
 void fillValidTuneCPUArchList(SmallVectorImpl &Values, bool IsRV64);
 bool getCPUFeaturesExceptStdExt(CPUKind Kind, std::vector &Features);
 
+bool isX18ReservedByDefault(const Triple &TT);
+
 } // namespace RISCV
 } // namespace llvm
 
Index: clang/test/Driver/sanitizer-ld.c
===
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -731,6 +731,11 @@
 // RUN:   | FileCheck --check-prefix=CHECK-SHADOWCALLSTACK-LINUX-RISCV64 %s
 // CHECK-SHADOWCALLSTACK-LINUX-RISCV64: '-fsanitize=shadow-call-stack' only allowed with '-ffixed-x18'
 
+// RUN: %clang -fsanitize=shadow-call-stack -### %s 2>&1 \
+// RUN: --target=riscv64-unknown-fuchsia -fuse-ld=ld \
+// RUN:   | FileCheck --check-prefix=CHECK-SHADOWCALLSTACK-FUCHSIA-RISCV64 %s
+// CHECK-SHADOWCALLSTACK-FUCHSIA-RISCV64-NOT: error:
+
 // RUN: %clang -fsanitize=shadow-call-stack -### %s 2>&1 \
 // RUN: --target=aarch64-unknown-linux -fuse-ld=ld -ffixed-x18 \
 // RUN:   | FileCheck --check-prefix=CHECK-SHADOWCALLSTACK-LINUX-AARCH64-X18 %s
Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -19,6 +19,7 @@
 #include "llvm/Support/TargetParser.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/TargetParser/AArch64TargetParser.h"
+#include "llvm/TargetParser/RISCVTargetParser.h"
 #include "llvm/Transforms/Instrumentation/AddressSanitizerOptions.h"
 #include 
 
@@ -545,7 +546,8 @@
   if ((Kinds & SanitizerKind::ShadowCallStack) &&
   ((TC.getTriple().isAArch64() &&
 !llvm::AArch64::isX18ReservedByDefault(TC.getTriple())) ||
-   TC.getTriple().isRISCV()) &&
+   (TC.getTriple().isRISCV() &&
+!llvm::RISCV::isX18ReservedByDefault(TC.getTriple( &&
   !Args.hasArg(options::OPT_ffixed_x18) && DiagnoseErrors) {
 D.Diag(diag::err_drv_argument_only_allowed_with)
 << lastArgumentForMask(D, Args, Kinds & SanitizerKind::ShadowCallSta

[PATCH] D143357: [RISCV] Default to -fsanitize=shadow-call-stack for Fuchsia

2023-02-05 Thread Roland McGrath via Phabricator via cfe-commits
mcgrathr updated this revision to Diff 494973.
mcgrathr marked an inline comment as done.
mcgrathr added a comment.

remove TODO


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143357

Files:
  clang/lib/Driver/ToolChains/Fuchsia.cpp
  clang/test/Driver/fuchsia.c


Index: clang/test/Driver/fuchsia.c
===
--- clang/test/Driver/fuchsia.c
+++ clang/test/Driver/fuchsia.c
@@ -31,6 +31,7 @@
 // CHECK: "-isysroot" "[[SYSROOT:[^"]+]]"
 // CHECK: "-internal-externc-isystem" "[[SYSROOT]]{{/|}}include"
 // CHECK-AARCH64: "-fsanitize=shadow-call-stack"
+// CHECK-RISCV64: "-fsanitize=shadow-call-stack"
 // CHECK-X86_64: "-fsanitize=safe-stack"
 // CHECK: "-stack-protector" "2"
 // CHECK-AARCH64: "-target-feature" "+outline-atomics"
Index: clang/lib/Driver/ToolChains/Fuchsia.cpp
===
--- clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -466,13 +466,13 @@
   SanitizerMask Res;
   switch (getTriple().getArch()) {
   case llvm::Triple::aarch64:
+  case llvm::Triple::riscv64:
 Res |= SanitizerKind::ShadowCallStack;
 break;
   case llvm::Triple::x86_64:
 Res |= SanitizerKind::SafeStack;
 break;
   default:
-// TODO: Enable SafeStack on RISC-V once tested.
 break;
   }
   return Res;


Index: clang/test/Driver/fuchsia.c
===
--- clang/test/Driver/fuchsia.c
+++ clang/test/Driver/fuchsia.c
@@ -31,6 +31,7 @@
 // CHECK: "-isysroot" "[[SYSROOT:[^"]+]]"
 // CHECK: "-internal-externc-isystem" "[[SYSROOT]]{{/|}}include"
 // CHECK-AARCH64: "-fsanitize=shadow-call-stack"
+// CHECK-RISCV64: "-fsanitize=shadow-call-stack"
 // CHECK-X86_64: "-fsanitize=safe-stack"
 // CHECK: "-stack-protector" "2"
 // CHECK-AARCH64: "-target-feature" "+outline-atomics"
Index: clang/lib/Driver/ToolChains/Fuchsia.cpp
===
--- clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -466,13 +466,13 @@
   SanitizerMask Res;
   switch (getTriple().getArch()) {
   case llvm::Triple::aarch64:
+  case llvm::Triple::riscv64:
 Res |= SanitizerKind::ShadowCallStack;
 break;
   case llvm::Triple::x86_64:
 Res |= SanitizerKind::SafeStack;
 break;
   default:
-// TODO: Enable SafeStack on RISC-V once tested.
 break;
   }
   return Res;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 03ff435 - [RISCV] Default to -ffixed-x18 for Fuchsia

2023-02-05 Thread Roland McGrath via cfe-commits

Author: Roland McGrath
Date: 2023-02-05T18:51:18-08:00
New Revision: 03ff435da540b0feb8272784e05ce742831d5bc2

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

LOG: [RISCV] Default to -ffixed-x18 for Fuchsia

Fuchsia's ABI always reserves the x18 (s2) register for the
ShadowCallStack ABI, even when -fsanitize=shadow-call-stack is
not enabled.

Reviewed By: phosek

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

Added: 


Modified: 
clang/lib/Driver/SanitizerArgs.cpp
clang/test/Driver/sanitizer-ld.c
llvm/include/llvm/TargetParser/RISCVTargetParser.h
llvm/lib/Target/RISCV/RISCVSubtarget.cpp
llvm/lib/TargetParser/RISCVTargetParser.cpp
llvm/test/CodeGen/RISCV/reserved-regs.ll

Removed: 




diff  --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index 84be06b90ee62..49ae5cc6d88c9 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -19,6 +19,7 @@
 #include "llvm/Support/TargetParser.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/TargetParser/AArch64TargetParser.h"
+#include "llvm/TargetParser/RISCVTargetParser.h"
 #include "llvm/Transforms/Instrumentation/AddressSanitizerOptions.h"
 #include 
 
@@ -545,7 +546,8 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
   if ((Kinds & SanitizerKind::ShadowCallStack) &&
   ((TC.getTriple().isAArch64() &&
 !llvm::AArch64::isX18ReservedByDefault(TC.getTriple())) ||
-   TC.getTriple().isRISCV()) &&
+   (TC.getTriple().isRISCV() &&
+!llvm::RISCV::isX18ReservedByDefault(TC.getTriple( &&
   !Args.hasArg(options::OPT_ffixed_x18) && DiagnoseErrors) {
 D.Diag(diag::err_drv_argument_only_allowed_with)
 << lastArgumentForMask(D, Args, Kinds & SanitizerKind::ShadowCallStack)

diff  --git a/clang/test/Driver/sanitizer-ld.c 
b/clang/test/Driver/sanitizer-ld.c
index 3621d12eeb8c6..0ba209d870c2a 100644
--- a/clang/test/Driver/sanitizer-ld.c
+++ b/clang/test/Driver/sanitizer-ld.c
@@ -731,6 +731,11 @@
 // RUN:   | FileCheck --check-prefix=CHECK-SHADOWCALLSTACK-LINUX-RISCV64 %s
 // CHECK-SHADOWCALLSTACK-LINUX-RISCV64: '-fsanitize=shadow-call-stack' only 
allowed with '-ffixed-x18'
 
+// RUN: %clang -fsanitize=shadow-call-stack -### %s 2>&1 \
+// RUN: --target=riscv64-unknown-fuchsia -fuse-ld=ld \
+// RUN:   | FileCheck --check-prefix=CHECK-SHADOWCALLSTACK-FUCHSIA-RISCV64 %s
+// CHECK-SHADOWCALLSTACK-FUCHSIA-RISCV64-NOT: error:
+
 // RUN: %clang -fsanitize=shadow-call-stack -### %s 2>&1 \
 // RUN: --target=aarch64-unknown-linux -fuse-ld=ld -ffixed-x18 \
 // RUN:   | FileCheck --check-prefix=CHECK-SHADOWCALLSTACK-LINUX-AARCH64-X18 %s

diff  --git a/llvm/include/llvm/TargetParser/RISCVTargetParser.h 
b/llvm/include/llvm/TargetParser/RISCVTargetParser.h
index da2ecd8c1339d..f50576b8fee16 100644
--- a/llvm/include/llvm/TargetParser/RISCVTargetParser.h
+++ b/llvm/include/llvm/TargetParser/RISCVTargetParser.h
@@ -18,6 +18,9 @@
 #include 
 
 namespace llvm {
+
+class Triple;
+
 namespace RISCV {
 
 // We use 64 bits as the known part in the scalable vector types.
@@ -38,6 +41,8 @@ void fillValidCPUArchList(SmallVectorImpl &Values, 
bool IsRV64);
 void fillValidTuneCPUArchList(SmallVectorImpl &Values, bool IsRV64);
 bool getCPUFeaturesExceptStdExt(CPUKind Kind, std::vector 
&Features);
 
+bool isX18ReservedByDefault(const Triple &TT);
+
 } // namespace RISCV
 } // namespace llvm
 

diff  --git a/llvm/lib/Target/RISCV/RISCVSubtarget.cpp 
b/llvm/lib/Target/RISCV/RISCVSubtarget.cpp
index 2d134b2514a2b..1101d7eeeff8b 100644
--- a/llvm/lib/Target/RISCV/RISCVSubtarget.cpp
+++ b/llvm/lib/Target/RISCV/RISCVSubtarget.cpp
@@ -83,6 +83,9 @@ RISCVSubtarget::RISCVSubtarget(const Triple &TT, StringRef 
CPU,
   FrameLowering(
   initializeSubtargetDependencies(TT, CPU, TuneCPU, FS, ABIName)),
   InstrInfo(*this), RegInfo(getHwMode()), TLInfo(TM, *this) {
+  if (RISCV::isX18ReservedByDefault(TT))
+UserReservedRegister.set(RISCV::X18);
+
   CallLoweringInfo.reset(new RISCVCallLowering(*getTargetLowering()));
   Legalizer.reset(new RISCVLegalizerInfo(*this));
 

diff  --git a/llvm/lib/TargetParser/RISCVTargetParser.cpp 
b/llvm/lib/TargetParser/RISCVTargetParser.cpp
index 89cd5c082d72d..933a82b7c6cb2 100644
--- a/llvm/lib/TargetParser/RISCVTargetParser.cpp
+++ b/llvm/lib/TargetParser/RISCVTargetParser.cpp
@@ -14,6 +14,7 @@
 #include "llvm/TargetParser/RISCVTargetParser.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/TargetParser/Triple.h"
 
 namespace llvm {
 namespace RISCV {
@@ -100,5 +101,10 @@ bool getCPUFeaturesExceptStdExt(CPUKind Kind,
   return true;
 }
 
+bool isX18ReservedByDefault(const Triple &TT) {
+  // X18 is reserved for the ShadowCallStac

[PATCH] D143355: [RISCV] Default to -ffixed-x18 for Fuchsia

2023-02-05 Thread Roland McGrath 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 rG03ff435da540: [RISCV] Default to -ffixed-x18 for Fuchsia 
(authored by mcgrathr).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143355

Files:
  clang/lib/Driver/SanitizerArgs.cpp
  clang/test/Driver/sanitizer-ld.c
  llvm/include/llvm/TargetParser/RISCVTargetParser.h
  llvm/lib/Target/RISCV/RISCVSubtarget.cpp
  llvm/lib/TargetParser/RISCVTargetParser.cpp
  llvm/test/CodeGen/RISCV/reserved-regs.ll

Index: llvm/test/CodeGen/RISCV/reserved-regs.ll
===
--- llvm/test/CodeGen/RISCV/reserved-regs.ll
+++ llvm/test/CodeGen/RISCV/reserved-regs.ll
@@ -57,6 +57,8 @@
 ; RUN: llc -mtriple=riscv32 -mattr=+reserve-x31 -verify-machineinstrs < %s | FileCheck %s -check-prefix=X31
 ; RUN: llc -mtriple=riscv64 -mattr=+reserve-x31 -verify-machineinstrs < %s | FileCheck %s -check-prefix=X31
 
+; RUN: llc -mtriple=riscv64-fuchsia -verify-machineinstrs < %s | FileCheck %s -check-prefix=X18
+
 ; This program is free to use all registers, but needs a stack pointer for
 ; spill values, so do not test for reserving the stack pointer.
 
Index: llvm/lib/TargetParser/RISCVTargetParser.cpp
===
--- llvm/lib/TargetParser/RISCVTargetParser.cpp
+++ llvm/lib/TargetParser/RISCVTargetParser.cpp
@@ -14,6 +14,7 @@
 #include "llvm/TargetParser/RISCVTargetParser.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/TargetParser/Triple.h"
 
 namespace llvm {
 namespace RISCV {
@@ -100,5 +101,10 @@
   return true;
 }
 
+bool isX18ReservedByDefault(const Triple &TT) {
+  // X18 is reserved for the ShadowCallStack ABI (even when not enabled).
+  return TT.isOSFuchsia();
+}
+
 } // namespace RISCV
 } // namespace llvm
Index: llvm/lib/Target/RISCV/RISCVSubtarget.cpp
===
--- llvm/lib/Target/RISCV/RISCVSubtarget.cpp
+++ llvm/lib/Target/RISCV/RISCVSubtarget.cpp
@@ -83,6 +83,9 @@
   FrameLowering(
   initializeSubtargetDependencies(TT, CPU, TuneCPU, FS, ABIName)),
   InstrInfo(*this), RegInfo(getHwMode()), TLInfo(TM, *this) {
+  if (RISCV::isX18ReservedByDefault(TT))
+UserReservedRegister.set(RISCV::X18);
+
   CallLoweringInfo.reset(new RISCVCallLowering(*getTargetLowering()));
   Legalizer.reset(new RISCVLegalizerInfo(*this));
 
Index: llvm/include/llvm/TargetParser/RISCVTargetParser.h
===
--- llvm/include/llvm/TargetParser/RISCVTargetParser.h
+++ llvm/include/llvm/TargetParser/RISCVTargetParser.h
@@ -18,6 +18,9 @@
 #include 
 
 namespace llvm {
+
+class Triple;
+
 namespace RISCV {
 
 // We use 64 bits as the known part in the scalable vector types.
@@ -38,6 +41,8 @@
 void fillValidTuneCPUArchList(SmallVectorImpl &Values, bool IsRV64);
 bool getCPUFeaturesExceptStdExt(CPUKind Kind, std::vector &Features);
 
+bool isX18ReservedByDefault(const Triple &TT);
+
 } // namespace RISCV
 } // namespace llvm
 
Index: clang/test/Driver/sanitizer-ld.c
===
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -731,6 +731,11 @@
 // RUN:   | FileCheck --check-prefix=CHECK-SHADOWCALLSTACK-LINUX-RISCV64 %s
 // CHECK-SHADOWCALLSTACK-LINUX-RISCV64: '-fsanitize=shadow-call-stack' only allowed with '-ffixed-x18'
 
+// RUN: %clang -fsanitize=shadow-call-stack -### %s 2>&1 \
+// RUN: --target=riscv64-unknown-fuchsia -fuse-ld=ld \
+// RUN:   | FileCheck --check-prefix=CHECK-SHADOWCALLSTACK-FUCHSIA-RISCV64 %s
+// CHECK-SHADOWCALLSTACK-FUCHSIA-RISCV64-NOT: error:
+
 // RUN: %clang -fsanitize=shadow-call-stack -### %s 2>&1 \
 // RUN: --target=aarch64-unknown-linux -fuse-ld=ld -ffixed-x18 \
 // RUN:   | FileCheck --check-prefix=CHECK-SHADOWCALLSTACK-LINUX-AARCH64-X18 %s
Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -19,6 +19,7 @@
 #include "llvm/Support/TargetParser.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/TargetParser/AArch64TargetParser.h"
+#include "llvm/TargetParser/RISCVTargetParser.h"
 #include "llvm/Transforms/Instrumentation/AddressSanitizerOptions.h"
 #include 
 
@@ -545,7 +546,8 @@
   if ((Kinds & SanitizerKind::ShadowCallStack) &&
   ((TC.getTriple().isAArch64() &&
 !llvm::AArch64::isX18ReservedByDefault(TC.getTriple())) ||
-   TC.getTriple().isRISCV()) &&
+   (TC.getTriple().isRISCV() &&
+!llvm::RISCV::isX18ReservedByDefault(TC.getTriple( &&
   !Args.hasArg(options::OPT_ffixed_x18) && DiagnoseErrors) {
 D.Diag(diag::err_drv_argument_only_

[clang] f08d86f - [RISCV] Default to -fsanitize=shadow-call-stack for Fuchsia

2023-02-05 Thread Roland McGrath via cfe-commits

Author: Roland McGrath
Date: 2023-02-05T18:58:59-08:00
New Revision: f08d86fc7f4479d5f44d75c720201334682075b8

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

LOG: [RISCV] Default to -fsanitize=shadow-call-stack for Fuchsia

The ShadowCallStack is the preferred and default ABI for Fuchsia.

Reviewed By: phosek

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Fuchsia.cpp
clang/test/Driver/fuchsia.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Fuchsia.cpp 
b/clang/lib/Driver/ToolChains/Fuchsia.cpp
index d0e035f205ae0..36bd93a4913c6 100644
--- a/clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ b/clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -466,13 +466,13 @@ SanitizerMask Fuchsia::getDefaultSanitizers() const {
   SanitizerMask Res;
   switch (getTriple().getArch()) {
   case llvm::Triple::aarch64:
+  case llvm::Triple::riscv64:
 Res |= SanitizerKind::ShadowCallStack;
 break;
   case llvm::Triple::x86_64:
 Res |= SanitizerKind::SafeStack;
 break;
   default:
-// TODO: Enable SafeStack on RISC-V once tested.
 break;
   }
   return Res;

diff  --git a/clang/test/Driver/fuchsia.c b/clang/test/Driver/fuchsia.c
index a8bae5f655415..c785e3a52251c 100644
--- a/clang/test/Driver/fuchsia.c
+++ b/clang/test/Driver/fuchsia.c
@@ -31,6 +31,7 @@
 // CHECK: "-isysroot" "[[SYSROOT:[^"]+]]"
 // CHECK: "-internal-externc-isystem" "[[SYSROOT]]{{/|}}include"
 // CHECK-AARCH64: "-fsanitize=shadow-call-stack"
+// CHECK-RISCV64: "-fsanitize=shadow-call-stack"
 // CHECK-X86_64: "-fsanitize=safe-stack"
 // CHECK: "-stack-protector" "2"
 // CHECK-AARCH64: "-target-feature" "+outline-atomics"



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


[PATCH] D143357: [RISCV] Default to -fsanitize=shadow-call-stack for Fuchsia

2023-02-05 Thread Roland McGrath 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 rGf08d86fc7f44: [RISCV] Default to 
-fsanitize=shadow-call-stack for Fuchsia (authored by mcgrathr).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143357

Files:
  clang/lib/Driver/ToolChains/Fuchsia.cpp
  clang/test/Driver/fuchsia.c


Index: clang/test/Driver/fuchsia.c
===
--- clang/test/Driver/fuchsia.c
+++ clang/test/Driver/fuchsia.c
@@ -31,6 +31,7 @@
 // CHECK: "-isysroot" "[[SYSROOT:[^"]+]]"
 // CHECK: "-internal-externc-isystem" "[[SYSROOT]]{{/|}}include"
 // CHECK-AARCH64: "-fsanitize=shadow-call-stack"
+// CHECK-RISCV64: "-fsanitize=shadow-call-stack"
 // CHECK-X86_64: "-fsanitize=safe-stack"
 // CHECK: "-stack-protector" "2"
 // CHECK-AARCH64: "-target-feature" "+outline-atomics"
Index: clang/lib/Driver/ToolChains/Fuchsia.cpp
===
--- clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -466,13 +466,13 @@
   SanitizerMask Res;
   switch (getTriple().getArch()) {
   case llvm::Triple::aarch64:
+  case llvm::Triple::riscv64:
 Res |= SanitizerKind::ShadowCallStack;
 break;
   case llvm::Triple::x86_64:
 Res |= SanitizerKind::SafeStack;
 break;
   default:
-// TODO: Enable SafeStack on RISC-V once tested.
 break;
   }
   return Res;


Index: clang/test/Driver/fuchsia.c
===
--- clang/test/Driver/fuchsia.c
+++ clang/test/Driver/fuchsia.c
@@ -31,6 +31,7 @@
 // CHECK: "-isysroot" "[[SYSROOT:[^"]+]]"
 // CHECK: "-internal-externc-isystem" "[[SYSROOT]]{{/|}}include"
 // CHECK-AARCH64: "-fsanitize=shadow-call-stack"
+// CHECK-RISCV64: "-fsanitize=shadow-call-stack"
 // CHECK-X86_64: "-fsanitize=safe-stack"
 // CHECK: "-stack-protector" "2"
 // CHECK-AARCH64: "-target-feature" "+outline-atomics"
Index: clang/lib/Driver/ToolChains/Fuchsia.cpp
===
--- clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -466,13 +466,13 @@
   SanitizerMask Res;
   switch (getTriple().getArch()) {
   case llvm::Triple::aarch64:
+  case llvm::Triple::riscv64:
 Res |= SanitizerKind::ShadowCallStack;
 break;
   case llvm::Triple::x86_64:
 Res |= SanitizerKind::SafeStack;
 break;
   default:
-// TODO: Enable SafeStack on RISC-V once tested.
 break;
   }
   return Res;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D113352: [clang] Run LLVM Verifier in modes without CodeGen too

2023-02-05 Thread todd toddcarMAY via Phabricator via cfe-commits
toddcarmay added a comment.
Herald added a project: All.

I've been trying to find anything like this for a while now. Thanks for posting 
this, I've been hunting for it for a while. https://drift-boss.co/ drift boss


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D113352

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


[PATCH] D79378: PR34581: Don't remove an 'if (p)' guarding a call to 'operator delete(p)' under -Oz.

2023-02-05 Thread Shiva Chen via Phabricator via cfe-commits
shiva0217 added a comment.

In D79378#4103366 , @rjmccall wrote:

> In D79378#4101935 , @shiva0217 wrote:
>
>> In D79378#4101829 , @rjmccall wrote:
>>
>>> In D79378#4101613 , @shiva0217 
>>> wrote:
>>>
 Hi,

 I have a question for the delete function call sinking in -Oz.

 https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3690.pdf.
 According to 3.7.4.2/3
 ` The value of the first argument supplied to a deallocation function may 
 be a null pointer value; if so, and if the deallocation function is one 
 supplied in the standard library, the call has no effect. Otherwise, the 
 behavior is undefined`

 It seems the null checking can be skipped only when the delete is not from 
 the standard library(have been overloaded by the user), isn't it?
>>>
>>> The paragraph you just quoted says that the deallocation functions provided 
>>> by the standard library are required have no effect on null pointers.  That 
>>> means it's fine to call them with a null pointer even if the source 
>>> wouldn't normally execute that call.  We could just insert these calls into 
>>> random other code if we wanted to.
>>
>> Is a null operand of delete in the source code no effect because there will 
>> be null pointer checking generated?  Or the delete(null) in assembly code 
>> also valid?
>
> In [expr.delete], the standard specifies that using the `delete` operator on 
> a null pointer is required to have no effect.  It does not specify how that 
> should be implemented.  In [basic.std.dynamic.deallocation], the standard 
> also specifies that the library-provided `operator delete` functions must 
> have no effect when given a null pointer.  This requirement applies no matter 
> how the function is called, so yes, a call from assembly that passed a null 
> pointer would also be required to have no effect.  More officially, you can 
> simply take the address of `operator delete`, yielding an rvalue of `void 
> (*)(void *)` (or similar, depending on which `operator delete` you use), 
> which can then be called later in a context that doesn't understand it's 
> calling a deallocation function; such a call is still required to have no 
> effect when passing a null pointer, because the requirement is laid on the 
> function, separate from the circumstances of it being called as part of the 
> `delete` operator.
>
> Note also that calling `operator delete` unconditionally when implementing 
> the `delete` operator is explicitly blessed by [expr.delete]p7:
>
>> If the value of the operand of the delete-expression is not a null pointer 
>> value, then:
>>
>>   ...
>>
>> Otherwise, it is unspecified whether the deallocation function will be 
>> called.

Hi @rjmccall,

That make sense to me.
Thanks for sharing your insight of C++ standard and taking time to answer the 
questions. 
Thank you ^^


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79378

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


[PATCH] D139122: Generalize clang-tidy modernize-pass-by-value

2023-02-05 Thread Chris Cotter via Phabricator via cfe-commits
ccotter added inline comments.



Comment at: clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp:11
+#include "../utils/Aliasing.h"
+#include "../utils/ExprSequence.h"
 #include "clang/AST/ASTContext.h"

I think you need to add `clangAnalysis` (for Analysis/CFG.h) to the link 
libraries in modernize/CMakeLists.txt.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139122

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


[PATCH] D141700: AMDGPU: Move enqueued block handling into clang

2023-02-05 Thread Sameer Sahasrabuddhe via Phabricator via cfe-commits
sameerds added a comment.

LGTM, to the extent that I can see that the change does what is advertised, and 
the ultimately emitted HSA metadata preserves the current contract with the 
runtime.

A couple of tests can use a little more explanatory comments as noted.




Comment at: clang/lib/CodeGen/TargetInfo.cpp:12581
+  Mod, HandleTy,
+  /*isConstant=*/true, llvm::GlobalValue::InternalLinkage,
+  /*Initializer=*/RuntimeHandleInitializer, RuntimeHandleName,

jmmartinez wrote:
> Just a cosmetical remark: Is there any reason to keep the `/*isConstant=*/`, 
> `/*Initializer=*/`, ... comments? I think it would be better to avoid them.
FWIW, I find these comments very helpful when spelunking through code. I could 
sympathise with not needing `Initializer=` because the value name makes it 
clear. But an undecorated constant literal like "true" or "10" or "nullptr" 
works best when accompanied by a comment.



Comment at: llvm/test/Bitcode/amdgpu-autoupgrade-enqueued-block.ll:69
+
+; __enqueue_kernel* functions may get inlined
+define amdgpu_kernel void @inlined_caller(ptr addrspace(1) %a, i8 %b, ptr 
addrspace(1) %c, i64 %d) {

I did not understand what is being tested here.



Comment at: llvm/test/CodeGen/AMDGPU/amdgpu-export-kernel-runtime-handles.ll:2
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 
UTC_ARGS: --function-signature --check-attributes --check-globals
+; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -amdgpu-export-kernel-runtime-handles 
< %s | FileCheck %s
+

Is there any visible effect of the pass being tested? Or the intention is 
simply to check that the output is the same as input, and there is no error?


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

https://reviews.llvm.org/D141700

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


[PATCH] D139122: Generalize clang-tidy modernize-pass-by-value

2023-02-05 Thread Chris Cotter via Phabricator via cfe-commits
ccotter added a comment.

https://reviews.llvm.org/D137205 looks to be similar in part, as it applies a 
FixIt to a any last use of an object if the use a copy, including parameters 
and local objects.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139122

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


[PATCH] D137205: [clang-tidy] Add performance-unnecessary-copy-on-last-use check

2023-02-05 Thread Chris Cotter via Phabricator via cfe-commits
ccotter added inline comments.
Herald added a subscriber: ChuanqiXu.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-on-last-use.cpp:77
+
+Movable testReturn2(Movable && Mov, bool F) {
+  return F? Mov: Movable{}; 

Could you add another test where `Mov` is just a `Movable` value?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137205

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


[clang] bccf599 - Revert "[clang][WebAssembly] Initial support for reference type externref in clang"

2023-02-05 Thread Vitaly Buka via cfe-commits

Author: Vitaly Buka
Date: 2023-02-05T21:41:48-08:00
New Revision: bccf5999d38f14552f449618c1d72d18613f4285

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

LOG: Revert "[clang][WebAssembly] Initial support for reference type externref 
in clang"

Very likely breaks stage 3 of msan build bot.
Good: 764c88a50ac76a2df2d051a0eb5badc6867aabb6 
https://lab.llvm.org/buildbot/#/builders/74/builds/17058
Looks unrelated: 48b5a06dfcab12cf093a1a3df42cb5b684e2be4c
Bad: 48b5a06dfcab12cf093a1a3df42cb5b684e2be4c 
https://lab.llvm.org/buildbot/#/builders/74/builds/17059

This reverts commit eb66833d19573df97034a81279eda31b8d19815b.

Added: 


Modified: 
clang/include/clang/AST/ASTContext.h
clang/include/clang/AST/Type.h
clang/include/clang/AST/TypeProperties.td
clang/include/clang/Basic/BuiltinsWebAssembly.def
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/include/clang/Serialization/ASTBitCodes.h
clang/include/clang/module.modulemap
clang/lib/AST/ASTContext.cpp
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/ExprConstant.cpp
clang/lib/AST/ItaniumMangle.cpp
clang/lib/AST/MicrosoftMangle.cpp
clang/lib/AST/NSAPI.cpp
clang/lib/AST/PrintfFormatString.cpp
clang/lib/AST/Type.cpp
clang/lib/AST/TypeLoc.cpp
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/CodeGen/CGDebugInfo.h
clang/lib/CodeGen/CodeGenTypes.cpp
clang/lib/CodeGen/ItaniumCXXABI.cpp
clang/lib/CodeGen/TargetInfo.cpp
clang/lib/CodeGen/TargetInfo.h
clang/lib/Index/USRGeneration.cpp
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaType.cpp
clang/lib/Serialization/ASTCommon.cpp
clang/lib/Serialization/ASTReader.cpp
clang/test/CodeGen/builtins-wasm.c
clang/test/SemaTemplate/address_space-dependent.cpp
clang/tools/libclang/CIndex.cpp
llvm/include/llvm/IR/Type.h
llvm/include/llvm/Transforms/Utils.h
llvm/lib/CodeGen/ValueTypes.cpp
llvm/lib/IR/Type.cpp
llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
llvm/lib/Transforms/Utils/Mem2Reg.cpp

Removed: 
clang/include/clang/Basic/WebAssemblyReferenceTypes.def
clang/test/CodeGen/WebAssembly/wasm-externref.c
clang/test/CodeGenCXX/wasm-reftypes-mangle.cpp
clang/test/CodeGenCXX/wasm-reftypes-typeinfo.cpp
clang/test/Sema/wasm-refs.c
clang/test/SemaCXX/wasm-refs.cpp



diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 911ee8b21505..0238371927e0 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1126,8 +1126,6 @@ class ASTContext : public RefCountedBase {
 #define RVV_TYPE(Name, Id, SingletonId) \
   CanQualType SingletonId;
 #include "clang/Basic/RISCVVTypes.def"
-#define WASM_TYPE(Name, Id, SingletonId) CanQualType SingletonId;
-#include "clang/Basic/WebAssemblyReferenceTypes.def"
 
   // Types for deductions in C++0x [stmt.ranged]'s desugaring. Built on demand.
   mutable QualType AutoDeductTy; // Deduction against 'auto'.
@@ -1476,9 +1474,6 @@ class ASTContext : public RefCountedBase {
   /// \pre \p EltTy must be a built-in type.
   QualType getScalableVectorType(QualType EltTy, unsigned NumElts) const;
 
-  /// Return a WebAssembly externref type.
-  QualType getWebAssemblyExternrefType() const;
-
   /// Return the unique reference to a vector type of the specified
   /// element type and size.
   ///

diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 0252e3adbb7c..180251d7f6bd 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2029,10 +2029,6 @@ class alignas(8) Type : public ExtQualsTypeCommonBase {
   /// Returns true for SVE scalable vector types.
   bool isSVESizelessBuiltinType() const;
 
-  /// Check if this is a WebAssembly Reference Type.
-  bool isWebAssemblyReferenceType() const;
-  bool isWebAssemblyExternrefType() const;
-
   /// Determines if this is a sizeless type supported by the
   /// 'arm_sve_vector_bits' type attribute, which can be applied to a single
   /// SVE vector or predicate, excluding tuple types such as svint32x4_t.
@@ -2644,9 +2640,6 @@ class BuiltinType : public Type {
 // RVV Types
 #define RVV_TYPE(Name, Id, SingletonId) Id,
 #include "clang/Basic/RISCVVTypes.def"
-// WebAssembly reference types
-#define WASM_TYPE(Name, Id, SingletonId) Id,
-#include "clang/Basic/WebAssemblyReferenceTypes.def"
 // All other builtin types
 #define BUILTIN_TYPE(Id, SingletonId) Id,
 #define LAST_BUILTIN_TYPE(Id) LastKind = Id

diff  --git a/clang/include/clang/AST/TypeProperties.td 
b/clang/include/cl

[PATCH] D122215: [WebAssembly] Initial support for reference type externref in clang

2023-02-05 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka updated this revision to Diff 494999.
vitalybuka added a comment.

as reverted


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122215

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/WebAssemblyReferenceTypes.def
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/module.modulemap
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/AST/NSAPI.cpp
  clang/lib/AST/PrintfFormatString.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypeLoc.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CodeGenTypes.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/TargetInfo.h
  clang/lib/Index/USRGeneration.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Serialization/ASTCommon.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/test/CodeGen/WebAssembly/wasm-externref.c
  clang/test/CodeGen/builtins-wasm.c
  clang/test/CodeGenCXX/wasm-reftypes-mangle.cpp
  clang/test/CodeGenCXX/wasm-reftypes-typeinfo.cpp
  clang/test/Sema/wasm-refs.c
  clang/test/SemaCXX/wasm-refs.cpp
  clang/test/SemaTemplate/address_space-dependent.cpp
  clang/tools/libclang/CIndex.cpp
  llvm/include/llvm/IR/Type.h
  llvm/include/llvm/Transforms/Utils.h
  llvm/lib/CodeGen/ValueTypes.cpp
  llvm/lib/IR/Type.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
  llvm/lib/Transforms/Utils/Mem2Reg.cpp

Index: llvm/lib/Transforms/Utils/Mem2Reg.cpp
===
--- llvm/lib/Transforms/Utils/Mem2Reg.cpp
+++ llvm/lib/Transforms/Utils/Mem2Reg.cpp
@@ -74,15 +74,19 @@
 struct PromoteLegacyPass : public FunctionPass {
   // Pass identification, replacement for typeid
   static char ID;
+  bool ForcePass; /// If true, forces pass to execute, instead of skipping.
 
-  PromoteLegacyPass() : FunctionPass(ID) {
+  PromoteLegacyPass() : FunctionPass(ID), ForcePass(false) {
+initializePromoteLegacyPassPass(*PassRegistry::getPassRegistry());
+  }
+  PromoteLegacyPass(bool IsForced) : FunctionPass(ID), ForcePass(IsForced) {
 initializePromoteLegacyPassPass(*PassRegistry::getPassRegistry());
   }
 
   // runOnFunction - To run this pass, first we calculate the alloca
   // instructions that are safe for promotion, then we promote each one.
   bool runOnFunction(Function &F) override {
-if (skipFunction(F))
+if (!ForcePass && skipFunction(F))
   return false;
 
 DominatorTree &DT = getAnalysis().getDomTree();
@@ -111,6 +115,6 @@
 false, false)
 
 // createPromoteMemoryToRegister - Provide an entry point to create this pass.
-FunctionPass *llvm::createPromoteMemoryToRegisterPass() {
-  return new PromoteLegacyPass();
+FunctionPass *llvm::createPromoteMemoryToRegisterPass(bool IsForced) {
+  return new PromoteLegacyPass(IsForced);
 }
Index: llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
===
--- llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
@@ -16,6 +16,7 @@
 #include "TargetInfo/WebAssemblyTargetInfo.h"
 #include "Utils/WebAssemblyUtilities.h"
 #include "WebAssembly.h"
+#include "WebAssemblyISelLowering.h"
 #include "WebAssemblyMachineFunctionInfo.h"
 #include "WebAssemblyTargetObjectFile.h"
 #include "WebAssemblyTargetTransformInfo.h"
@@ -464,6 +465,14 @@
 }
 
 void WebAssemblyPassConfig::addISelPrepare() {
+  WebAssemblyTargetMachine *WasmTM = static_cast(TM);
+  const WebAssemblySubtarget *Subtarget = WasmTM
+->getSubtargetImpl(std::string(WasmTM->getTargetCPU()),
+   std::string(WasmTM->getTargetFeatureString()));
+  if(Subtarget->hasReferenceTypes()) {
+// We need to remove allocas for reference types
+addPass(createPromoteMemoryToRegisterPass(true));
+  }
   // Lower atomics and TLS if necessary
   addPass(new CoalesceFeaturesAndStripAtomics(&getWebAssemblyTargetMachine()));
 
Index: llvm/lib/IR/Type.cpp
===
--- llvm/lib/IR/Type.cpp
+++ llvm/lib/IR/Type.cpp
@@ -306,6 +306,18 @@
   return getInt64Ty(C)->getPointerTo(AS);
 }
 
+Type *Type::getWasm_ExternrefTy(LLVMContext &C) {
+  // opaque pointer in addrspace(10)
+  static PointerType *Ty = PointerType::get(C, 10);
+  return Ty;
+}
+
+Type *Type::getWasm_Fu