[PATCH] D95753: Store compilation dir separately in coverage mapping

2021-02-12 Thread Petr Hosek via Phabricator via cfe-commits
phosek updated this revision to Diff 323231.
phosek added a comment.

Documentation updated and test included.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95753

Files:
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CoverageMappingGen.cpp
  clang/lib/CodeGen/CoverageMappingGen.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CoverageMapping/abspath.cpp
  clang/test/Profile/profile-prefix-map.c
  compiler-rt/include/profile/InstrProfData.inc
  llvm/docs/CoverageMappingFormat.rst
  llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
  llvm/include/llvm/ProfileData/Coverage/CoverageMappingReader.h
  llvm/include/llvm/ProfileData/Coverage/CoverageMappingWriter.h
  llvm/include/llvm/ProfileData/InstrProfData.inc
  llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
  llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp
  llvm/test/tools/llvm-cov/Inputs/binary-formats.v6.linux64l
  llvm/test/tools/llvm-cov/binary-formats.c
  llvm/unittests/ProfileData/CoverageMappingTest.cpp

Index: llvm/unittests/ProfileData/CoverageMappingTest.cpp
===
--- llvm/unittests/ProfileData/CoverageMappingTest.cpp
+++ llvm/unittests/ProfileData/CoverageMappingTest.cpp
@@ -129,6 +129,7 @@
 struct CoverageMappingTest : ::testing::TestWithParam> {
   bool UseMultipleReaders;
   StringMap Files;
+  std::vector Filenames;
   std::vector InputFunctions;
   std::vector OutputFunctions;
 
@@ -146,7 +147,7 @@
 auto R = Files.find(Name);
 if (R != Files.end())
   return R->second;
-unsigned Index = Files.size();
+unsigned Index = Files.size() + 1;
 Files.try_emplace(Name, Index);
 return Index;
   }
@@ -200,11 +201,12 @@
 
   void readCoverageRegions(const std::string &Coverage,
OutputFunctionCoverageData &Data) {
-SmallVector Filenames(Files.size());
+Filenames.resize(Files.size() + 1);
 for (const auto &E : Files)
-  Filenames[E.getValue()] = E.getKey();
+  Filenames[E.getValue()] = E.getKey().str();
 std::vector Expressions;
-RawCoverageMappingReader Reader(Coverage, Filenames, Data.Filenames,
+ArrayRef FilenameRefs = llvm::makeArrayRef(Filenames);
+RawCoverageMappingReader Reader(Coverage, FilenameRefs, Data.Filenames,
 Expressions, Data.Regions);
 EXPECT_THAT_ERROR(Reader.read(), Succeeded());
   }
@@ -895,7 +897,7 @@
   std::pair({true, true})),);
 
 TEST(CoverageMappingTest, filename_roundtrip) {
-  std::vector Paths({"a", "b", "c", "d", "e"});
+  std::vector Paths({"", "a", "b", "c", "d", "e"});
 
   for (bool Compress : {false, true}) {
 std::string EncodedFilenames;
@@ -905,16 +907,12 @@
   Writer.write(OS, Compress);
 }
 
-std::vector ReadFilenames;
+std::vector ReadFilenames;
 RawCoverageFilenamesReader Reader(EncodedFilenames, ReadFilenames);
-BinaryCoverageReader::DecompressedData Decompressed;
-EXPECT_THAT_ERROR(Reader.read(CovMapVersion::CurrentVersion, Decompressed),
-  Succeeded());
-if (!Compress)
-  ASSERT_EQ(Decompressed.size(), 0U);
+EXPECT_THAT_ERROR(Reader.read(CovMapVersion::CurrentVersion), Succeeded());
 
 ASSERT_EQ(ReadFilenames.size(), Paths.size());
-for (unsigned I = 0; I < Paths.size(); ++I)
+for (unsigned I = 1; I < Paths.size(); ++I)
   ASSERT_TRUE(ReadFilenames[I] == Paths[I]);
   }
 }
Index: llvm/test/tools/llvm-cov/binary-formats.c
===
--- llvm/test/tools/llvm-cov/binary-formats.c
+++ llvm/test/tools/llvm-cov/binary-formats.c
@@ -8,5 +8,6 @@
 // RUN: llvm-cov show %S/Inputs/binary-formats.macho64l -instr-profile %t.profdata -path-equivalence=/tmp,%S %s | FileCheck %s
 // RUN: llvm-cov show %S/Inputs/binary-formats.macho32b -instr-profile %t.profdata -path-equivalence=/tmp,%S %s | FileCheck %s
 // RUN: llvm-cov show %S/Inputs/binary-formats.v3.macho64l -instr-profile %t.profdata -path-equivalence=/tmp,%S %s | FileCheck %s
+// RUN: llvm-cov show %S/Inputs/binary-formats.v6.linux64l -instr-profile %t.profdata -path-equivalence=/tmp,%S %s | FileCheck %s
 
 // RUN: llvm-cov export %S/Inputs/binary-formats.macho64l -instr-profile %t.profdata | FileCheck %S/Inputs/binary-formats.canonical.json
Index: llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp
===
--- llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp
+++ llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp
@@ -27,7 +27,7 @@
 using namespace coverage;
 
 CoverageFilenamesSectionWriter::CoverageFilenamesSectionWriter(
-ArrayRef Filenames)
+ArrayRef Filenames)
 : Filenames(Filenames) {
 #ifndef NDEBUG
   StringSet<> NameSet;
Index: llvm/li

[PATCH] D96578: [clangd] Remove the cross-file-rename option.

2021-02-12 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: sammccall.
Herald added subscribers: usaxena95, kadircet, arphaman.
hokein requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.
Herald added a project: clang.

and simplify the code.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96578

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

Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -189,25 +189,6 @@
 };
   )cpp",
 
-  // Class methods overrides.
-  R"cpp(
-struct A {
- virtual void [[f^oo]]() {}
-};
-struct B : A {
-  void [[f^oo]]() override {}
-};
-struct C : B {
-  void [[f^oo]]() override {}
-};
-
-void func() {
-  A().[[f^oo]]();
-  B().[[f^oo]]();
-  C().[[f^oo]]();
-}
-  )cpp",
-
   // Templated method instantiation.
   R"cpp(
 template
@@ -831,13 +812,10 @@
 auto TU = TestTU::withCode(Code.code());
 TU.ExtraArgs.push_back("-xobjective-c++");
 auto AST = TU.build();
+auto Index = TU.index();
 for (const auto &RenamePos : Code.points()) {
-  auto RenameResult = rename({RenamePos,
-  NewName,
-  AST,
-  testPath(TU.Filename),
-  /*Index*/ nullptr,
-  {/*CrossFile*/ false}});
+  auto RenameResult =
+  rename({RenamePos, NewName, AST, testPath(TU.Filename), Index.get()});
   ASSERT_TRUE(bool(RenameResult)) << RenameResult.takeError();
   ASSERT_EQ(1u, RenameResult->GlobalChanges.size());
   EXPECT_EQ(
@@ -851,95 +829,40 @@
   struct Case {
 const char *Code;
 const char* ErrorMessage; // null if no error
-bool IsHeaderFile;
-const SymbolIndex *Index;
 llvm::StringRef NewName = "DummyName";
   };
-  TestTU OtherFile = TestTU::withCode("Outside s; auto ss = &foo;");
-  const char *CommonHeader = R"cpp(
-class Outside {};
-void foo();
-  )cpp";
-  OtherFile.HeaderCode = CommonHeader;
-  OtherFile.Filename = "other.cc";
-  // The index has a "Outside" reference and a "foo" reference.
-  auto OtherFileIndex = OtherFile.index();
-  const SymbolIndex *Index = OtherFileIndex.get();
-
-  const bool HeaderFile = true;
   Case Cases[] = {
   {R"cpp(// allow -- function-local
 void f(int [[Lo^cal]]) {
   [[Local]] = 2;
 }
   )cpp",
-   nullptr, HeaderFile, Index},
-
-  {R"cpp(// allow -- symbol is indexable and has no refs in index.
-void [[On^lyInThisFile]]();
-  )cpp",
-   nullptr, HeaderFile, Index},
-
-  {R"cpp(
-void ^f();
-  )cpp",
-   "keyword", HeaderFile, Index, "return"},
-
-  {R"cpp(// disallow -- symbol is indexable and has other refs in index.
-void f() {
-  Out^side s;
-}
-  )cpp",
-   "used outside main file", HeaderFile, Index},
-
-  {R"cpp(// disallow -- symbol in anonymous namespace in header is not indexable.
-namespace {
-class Unin^dexable {};
-}
-  )cpp",
-   "not eligible for indexing", HeaderFile, Index},
-
-  {R"cpp(// allow -- symbol in anonymous namespace in non-header file is indexable.
-namespace {
-class [[F^oo]] {};
-}
-  )cpp",
-   nullptr, !HeaderFile, Index},
+   nullptr},
 
   {R"cpp(// disallow -- namespace symbol isn't supported
 namespace n^s {}
   )cpp",
-   "not a supported kind", HeaderFile, Index},
+   "not a supported kind"},
 
   {
   R"cpp(
  #define MACRO 1
  int s = MAC^RO;
)cpp",
-  "not a supported kind", HeaderFile, Index},
+  "not a supported kind"},
 
   {
   R"cpp(
 struct X { X operator++(int); };
 void f(X x) {x+^+;})cpp",
-  "no symbol", HeaderFile, Index},
-
-  {R"cpp(// foo is declared outside the file.
-void fo^o() {}
-  )cpp",
-   "used outside main file", !HeaderFile /*cc file*/, Index},
-
-  {R"cpp(
- // We should detect the symbol is used outside the file from the AST.
- void fo^o() {})cpp",
-   "used outside main file", !HeaderFile, nullptr /*no index*/},
+  "no symbol"},
 
   {R"cpp(// disallow rename on excluded symbols (e.g. std symbols)
  namespace std {
  class str^ing {};
  }
)cpp",
-   "not a supported kind", !HeaderFile, Index},
+   "not a supported kind"},
   {R"cpp(// disallow renam

[PATCH] D96578: [clangd] Remove the cross-file-rename option.

2021-02-12 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/ClangdServer.cpp:405
+// prepareRename is latency-sensitive: we deliberately pass a nullptr index
+// to save the cost, thus the result may be incomplete as it only contains
+// main-file occurrences.

i'd trim this down a bit now: "we don't query the index, as we only need 
main-file references"



Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:237
-IsMainFileOnly = false;
-  // If the symbol is not indexable, we disallow rename.
-  if (!SymbolCollector::shouldCollectSymbol(

I don't understand why we're now allowing rename of non-indexable symbols.
Is this really intended? At the least it seems like an unrelated change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96578

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


[PATCH] D96538: [SYCL] Ignore file-scope asm during device-side SYCL compilation.

2021-02-12 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews accepted this revision.
eandrews added a comment.

LGTM Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96538

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


[PATCH] D96578: [clangd] Remove the cross-file-rename option.

2021-02-12 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 323250.
hokein marked an inline comment as done.
hokein added a comment.

address review comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96578

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

Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -189,25 +189,6 @@
 };
   )cpp",
 
-  // Class methods overrides.
-  R"cpp(
-struct A {
- virtual void [[f^oo]]() {}
-};
-struct B : A {
-  void [[f^oo]]() override {}
-};
-struct C : B {
-  void [[f^oo]]() override {}
-};
-
-void func() {
-  A().[[f^oo]]();
-  B().[[f^oo]]();
-  C().[[f^oo]]();
-}
-  )cpp",
-
   // Templated method instantiation.
   R"cpp(
 template
@@ -831,13 +812,10 @@
 auto TU = TestTU::withCode(Code.code());
 TU.ExtraArgs.push_back("-xobjective-c++");
 auto AST = TU.build();
+auto Index = TU.index();
 for (const auto &RenamePos : Code.points()) {
-  auto RenameResult = rename({RenamePos,
-  NewName,
-  AST,
-  testPath(TU.Filename),
-  /*Index*/ nullptr,
-  {/*CrossFile*/ false}});
+  auto RenameResult =
+  rename({RenamePos, NewName, AST, testPath(TU.Filename), Index.get()});
   ASSERT_TRUE(bool(RenameResult)) << RenameResult.takeError();
   ASSERT_EQ(1u, RenameResult->GlobalChanges.size());
   EXPECT_EQ(
@@ -852,20 +830,8 @@
 const char *Code;
 const char* ErrorMessage; // null if no error
 bool IsHeaderFile;
-const SymbolIndex *Index;
 llvm::StringRef NewName = "DummyName";
   };
-  TestTU OtherFile = TestTU::withCode("Outside s; auto ss = &foo;");
-  const char *CommonHeader = R"cpp(
-class Outside {};
-void foo();
-  )cpp";
-  OtherFile.HeaderCode = CommonHeader;
-  OtherFile.Filename = "other.cc";
-  // The index has a "Outside" reference and a "foo" reference.
-  auto OtherFileIndex = OtherFile.index();
-  const SymbolIndex *Index = OtherFileIndex.get();
-
   const bool HeaderFile = true;
   Case Cases[] = {
   {R"cpp(// allow -- function-local
@@ -873,73 +839,39 @@
   [[Local]] = 2;
 }
   )cpp",
-   nullptr, HeaderFile, Index},
-
-  {R"cpp(// allow -- symbol is indexable and has no refs in index.
-void [[On^lyInThisFile]]();
-  )cpp",
-   nullptr, HeaderFile, Index},
-
-  {R"cpp(
-void ^f();
-  )cpp",
-   "keyword", HeaderFile, Index, "return"},
-
-  {R"cpp(// disallow -- symbol is indexable and has other refs in index.
-void f() {
-  Out^side s;
-}
-  )cpp",
-   "used outside main file", HeaderFile, Index},
+   nullptr, HeaderFile},
 
   {R"cpp(// disallow -- symbol in anonymous namespace in header is not indexable.
 namespace {
 class Unin^dexable {};
 }
   )cpp",
-   "not eligible for indexing", HeaderFile, Index},
-
-  {R"cpp(// allow -- symbol in anonymous namespace in non-header file is indexable.
-namespace {
-class [[F^oo]] {};
-}
-  )cpp",
-   nullptr, !HeaderFile, Index},
+   "not eligible for indexing", HeaderFile},
 
   {R"cpp(// disallow -- namespace symbol isn't supported
 namespace n^s {}
   )cpp",
-   "not a supported kind", HeaderFile, Index},
+   "not a supported kind", HeaderFile},
 
   {
   R"cpp(
  #define MACRO 1
  int s = MAC^RO;
)cpp",
-  "not a supported kind", HeaderFile, Index},
+  "not a supported kind", HeaderFile},
 
   {
   R"cpp(
 struct X { X operator++(int); };
 void f(X x) {x+^+;})cpp",
-  "no symbol", HeaderFile, Index},
-
-  {R"cpp(// foo is declared outside the file.
-void fo^o() {}
-  )cpp",
-   "used outside main file", !HeaderFile /*cc file*/, Index},
-
-  {R"cpp(
- // We should detect the symbol is used outside the file from the AST.
- void fo^o() {})cpp",
-   "used outside main file", !HeaderFile, nullptr /*no index*/},
+  "no symbol", HeaderFile},
 
   {R"cpp(// disallow rename on excluded symbols (e.g. std symbols)
  namespace std {
  class str^ing {};
  }
)cpp",
-   "not a supported kind", !HeaderFile, Index},
+   "not a supported kind", !HeaderFile},
   {R"cpp(// di

[PATCH] D96578: [clangd] Remove the cross-file-rename option.

2021-02-12 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:237
-IsMainFileOnly = false;
-  // If the symbol is not indexable, we disallow rename.
-  if (!SymbolCollector::shouldCollectSymbol(

sammccall wrote:
> I don't understand why we're now allowing rename of non-indexable symbols.
> Is this really intended? At the least it seems like an unrelated change.
oh, you're right. I didn't think it too much when removing the code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96578

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


[PATCH] D96572: [Clang][ASan] Introduce `-fsanitize-address-destructor-kind=` driver & frontend option.

2021-02-12 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added inline comments.



Comment at: clang/include/clang/Driver/Options.td:1485
+def sanitize_address_destructor_kind_EQ : Joined<["-"], 
"fsanitize-address-destructor-kind=">,
+  MetaVarName<"">,
+  Flags<[CC1Option]>,

What is the difference between them and why it's need to be configured from 
outside?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96572

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


[PATCH] D96456: [ThinLTO, NewPM] Register sanitizers with OptimizerLastPassBuilderHook

2021-02-12 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added inline comments.



Comment at: clang/lib/CodeGen/BackendUtil.cpp:1070-1071
+// ThinLTOIndexFile is provideds so we must be in ThinLTO PostLink.
+// For -O0 ThinLTO PreLink does basic optimization and triggers
+// OptimizerLastEPCallbacks. PostLink will not
+// run optimizations and this callback should

aeubanks wrote:
> We could fix this. It doesn't make sense for only -O0 to run 
> OptimizerLastEPCallbacks prelink. Would that help simplify this?
Do you mean move optimizer of -O0 into PostLink as well?
Yes, this would be more consistent.
Still I guess it should a separate patch.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96456

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


[clang] 18a7079 - [OpenCL][Docs] Describe internals of TableGen builtins

2021-02-12 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2021-02-12T09:56:32Z
New Revision: 18a70797e798ade57a3deb017692d4c47d12d6f0

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

LOG: [OpenCL][Docs] Describe internals of TableGen builtins

Add a high level explanation of the `-fdeclare-opencl-builtins` option.

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

Added: 


Modified: 
clang/docs/OpenCLSupport.rst

Removed: 




diff  --git a/clang/docs/OpenCLSupport.rst b/clang/docs/OpenCLSupport.rst
index 716ce9953e35..bf5aea1a8a67 100644
--- a/clang/docs/OpenCLSupport.rst
+++ b/clang/docs/OpenCLSupport.rst
@@ -114,6 +114,8 @@ flags that forward options to the frontend e.g. ``-cc1`` or 
``-Xclang``.
 OpenCL builtins
 ---
 
+**Clang builtins**
+
 There are some standard OpenCL functions that are implemented as Clang 
builtins:
 
 - All pipe functions from `section 6.13.16.2/6.13.16.3
@@ -129,6 +131,28 @@ There are some standard OpenCL functions that are 
implemented as Clang builtins:
   enqueue query functions from `section 6.13.17.5
   `_.
 
+**Fast builtin function declarations**
+
+The implementation of the fast builtin function declarations (available via the
+:ref:`-fdeclare-opencl-builtins option `) consists of the
+following main components:
+
+- A TableGen definitions file ``OpenCLBuiltins.td``.  This contains a compact
+  representation of the supported builtin functions.  When adding new builtin
+  function declarations, this is normally the only file that needs modifying.
+
+- A Clang TableGen emitter defined in ``ClangOpenCLBuiltinEmitter.cpp``.  
During
+  Clang build time, the emitter reads the TableGen definition file and
+  generates ``OpenCLBuiltins.inc``.  This generated file contains various 
tables
+  and functions that capture the builtin function data from the TableGen
+  definitions in a compact manner.
+
+- OpenCL specific code in ``SemaLookup.cpp``.  When ``Sema::LookupBuiltin``
+  encounters a potential builtin function, it will check if the name 
corresponds
+  to a valid OpenCL builtin function.  If so, all overloads of the function are
+  inserted using ``InsertOCLBuiltinDeclarationsFromTable`` and overload
+  resolution takes place.
+
 .. _opencl_addrsp:
 
 Address spaces attribute
@@ -239,6 +263,8 @@ Feel free to contact us on `cfe-dev
 `_ or via `Bugzilla
 `__.
 
+.. _opencl_fast_builtins:
+
 Fast builtin function declarations
 --
 



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


[clang] 18f16c9 - [OpenCL][Docs] Clean up trailing characters

2021-02-12 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2021-02-12T09:58:18Z
New Revision: 18f16c945f52c1125b2f92a51f9dc159cb0875d1

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

LOG: [OpenCL][Docs] Clean up trailing characters

Clean up trailing whitespace and a stray backtick.

Added: 


Modified: 
clang/docs/OpenCLSupport.rst

Removed: 




diff  --git a/clang/docs/OpenCLSupport.rst b/clang/docs/OpenCLSupport.rst
index bf5aea1a8a67..266fde3436d3 100644
--- a/clang/docs/OpenCLSupport.rst
+++ b/clang/docs/OpenCLSupport.rst
@@ -44,13 +44,13 @@ backends and OpenCL runtime.
 
 Each kernel will have function metadata attached to it, specifying the 
arguments.
 Kernel argument metadata is used to provide source level information for 
querying
-at runtime, for example using the `clGetKernelArgInfo 
+at runtime, for example using the `clGetKernelArgInfo
 `_
 call.
 
 Note that ``-cl-kernel-arg-info`` enables more information about the original
 kernel code to be added e.g. kernel parameter names will appear in the OpenCL
-metadata along with other information. 
+metadata along with other information.
 
 The IDs used to encode the OpenCL's logical address spaces in the argument info
 metadata follows the SPIR address space mapping as defined in the SPIR
@@ -120,7 +120,7 @@ There are some standard OpenCL functions that are 
implemented as Clang builtins:
 
 - All pipe functions from `section 6.13.16.2/6.13.16.3
   `_ of
-  the OpenCL v2.0 kernel language specification. `
+  the OpenCL v2.0 kernel language specification.
 
 - Address space qualifier conversion functions 
``to_global``/``to_local``/``to_private``
   from `section 6.13.9
@@ -216,7 +216,7 @@ OpenCL 3.0 Implementation Status
 
 
 The following table provides an overview of features in OpenCL C 3.0 and their
-implementation status. 
+implementation status.
 
 
+--+--+--+---+
 | Category | Feature   
   | Status   | Reviews 
  |
@@ -278,7 +278,7 @@ if full functionality is required.
 **Example of Use**:
 
 .. code-block:: console
- 
+
   $ clang -Xclang -fdeclare-opencl-builtins test.cl
 
 Note that this is a frontend-only flag and therefore it requires the use of



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


[PATCH] D96150: [OpenCL][Docs] Describe internals of TableGen BIFs

2021-02-12 Thread Sven van Haastregt 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 rG18a70797e798: [OpenCL][Docs] Describe internals of TableGen 
builtins (authored by svenvh).

Changed prior to commit:
  https://reviews.llvm.org/D96150?vs=321791&id=323261#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96150

Files:
  clang/docs/OpenCLSupport.rst


Index: clang/docs/OpenCLSupport.rst
===
--- clang/docs/OpenCLSupport.rst
+++ clang/docs/OpenCLSupport.rst
@@ -114,6 +114,8 @@
 OpenCL builtins
 ---
 
+**Clang builtins**
+
 There are some standard OpenCL functions that are implemented as Clang 
builtins:
 
 - All pipe functions from `section 6.13.16.2/6.13.16.3
@@ -129,6 +131,28 @@
   enqueue query functions from `section 6.13.17.5
   `_.
 
+**Fast builtin function declarations**
+
+The implementation of the fast builtin function declarations (available via the
+:ref:`-fdeclare-opencl-builtins option `) consists of the
+following main components:
+
+- A TableGen definitions file ``OpenCLBuiltins.td``.  This contains a compact
+  representation of the supported builtin functions.  When adding new builtin
+  function declarations, this is normally the only file that needs modifying.
+
+- A Clang TableGen emitter defined in ``ClangOpenCLBuiltinEmitter.cpp``.  
During
+  Clang build time, the emitter reads the TableGen definition file and
+  generates ``OpenCLBuiltins.inc``.  This generated file contains various 
tables
+  and functions that capture the builtin function data from the TableGen
+  definitions in a compact manner.
+
+- OpenCL specific code in ``SemaLookup.cpp``.  When ``Sema::LookupBuiltin``
+  encounters a potential builtin function, it will check if the name 
corresponds
+  to a valid OpenCL builtin function.  If so, all overloads of the function are
+  inserted using ``InsertOCLBuiltinDeclarationsFromTable`` and overload
+  resolution takes place.
+
 .. _opencl_addrsp:
 
 Address spaces attribute
@@ -239,6 +263,8 @@
 `_ or via `Bugzilla
 `__.
 
+.. _opencl_fast_builtins:
+
 Fast builtin function declarations
 --
 


Index: clang/docs/OpenCLSupport.rst
===
--- clang/docs/OpenCLSupport.rst
+++ clang/docs/OpenCLSupport.rst
@@ -114,6 +114,8 @@
 OpenCL builtins
 ---
 
+**Clang builtins**
+
 There are some standard OpenCL functions that are implemented as Clang builtins:
 
 - All pipe functions from `section 6.13.16.2/6.13.16.3
@@ -129,6 +131,28 @@
   enqueue query functions from `section 6.13.17.5
   `_.
 
+**Fast builtin function declarations**
+
+The implementation of the fast builtin function declarations (available via the
+:ref:`-fdeclare-opencl-builtins option `) consists of the
+following main components:
+
+- A TableGen definitions file ``OpenCLBuiltins.td``.  This contains a compact
+  representation of the supported builtin functions.  When adding new builtin
+  function declarations, this is normally the only file that needs modifying.
+
+- A Clang TableGen emitter defined in ``ClangOpenCLBuiltinEmitter.cpp``.  During
+  Clang build time, the emitter reads the TableGen definition file and
+  generates ``OpenCLBuiltins.inc``.  This generated file contains various tables
+  and functions that capture the builtin function data from the TableGen
+  definitions in a compact manner.
+
+- OpenCL specific code in ``SemaLookup.cpp``.  When ``Sema::LookupBuiltin``
+  encounters a potential builtin function, it will check if the name corresponds
+  to a valid OpenCL builtin function.  If so, all overloads of the function are
+  inserted using ``InsertOCLBuiltinDeclarationsFromTable`` and overload
+  resolution takes place.
+
 .. _opencl_addrsp:
 
 Address spaces attribute
@@ -239,6 +263,8 @@
 `_ or via `Bugzilla
 `__.
 
+.. _opencl_fast_builtins:
+
 Fast builtin function declarations
 --
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D96586: [analyzer][CTU][NFC] Add an extra regression test

2021-02-12 Thread Balázs Benics via Phabricator via cfe-commits
steakhal created this revision.
steakhal added reviewers: martong, balazske, Szelethus, NoQ, vsavchenko, 
gamesh411.
Herald added subscribers: ASDenysPetrov, Charusso, dkrupp, donat.nagy, 
mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun, 
whisperity.
steakhal requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Before bc713f6a004723d1325bc16e1efc32d0ac82f939 
 landed, 
the analyzer crashed on this reduced example.
It seems important to have bot `ctu` and `-analyzer-opt-analyze-headers` 
enabled in the example.

This test file ensures that no regression happens in the future in this regard.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96586

Files:
  clang/test/Analysis/Inputs/ctu-inherited-default-ctor-other.cpp
  clang/test/Analysis/ctu-inherited-default-ctor.cpp


Index: clang/test/Analysis/ctu-inherited-default-ctor.cpp
===
--- /dev/null
+++ clang/test/Analysis/ctu-inherited-default-ctor.cpp
@@ -0,0 +1,28 @@
+// Should not crash with '-analyzer-opt-analyze-headers' option during CTU 
analysis.
+//
+// RUN: rm -r %t && mkdir -p %t/ctudir
+// RUN: %clang_cc1 -std=c++14 -triple x86_64-pc-linux-gnu \
+// RUN:   -emit-pch -o %t/ctudir/ctu-inherited-default-ctor-other.cpp.ast \
+// RUN:%S/Inputs/ctu-inherited-default-ctor-other.cpp
+// RUN: echo "c:@N@clang@S@DeclContextLookupResult@SingleElementDummyList 
ctu-inherited-default-ctor-other.cpp.ast" \
+// RUN:   > %t/ctudir/externalDefMap.txt
+//
+// RUN: %clang_analyze_cc1 -std=c++14 -triple x86_64-pc-linux-gnu \
+// RUN:   -analyzer-opt-analyze-headers \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config experimental-enable-naive-ctu-analysis=true \
+// RUN:   -analyzer-config ctu-dir=%t/ctudir \
+// RUN:   -analyzer-config display-ctu-progress=true \
+// RUN:   -verify %s 2>&1 | FileCheck %s
+//
+// expected-no-diagnostics
+//
+// CHECK: CTU loaded AST file: ctu-inherited-default-ctor-other.cpp.ast
+
+namespace clang {}
+namespace llvm {}
+namespace clang {
+class DeclContextLookupResult {
+  static int *const SingleElementDummyList;
+};
+} // namespace clang
Index: clang/test/Analysis/Inputs/ctu-inherited-default-ctor-other.cpp
===
--- /dev/null
+++ clang/test/Analysis/Inputs/ctu-inherited-default-ctor-other.cpp
@@ -0,0 +1,27 @@
+namespace llvm {
+template 
+class impl;
+// basecase
+template 
+class impl {};
+// recursion
+template 
+class impl : impl {
+  using child = impl;
+  using child::child; // no-crash
+  impl(T);
+};
+template 
+class container : impl<0, TS...> {};
+} // namespace llvm
+namespace clang {
+class fun {
+  llvm::container k;
+  fun() {}
+};
+class DeclContextLookupResult {
+  static int *const SingleElementDummyList;
+};
+} // namespace clang
+using namespace clang;
+int *const DeclContextLookupResult::SingleElementDummyList = nullptr;


Index: clang/test/Analysis/ctu-inherited-default-ctor.cpp
===
--- /dev/null
+++ clang/test/Analysis/ctu-inherited-default-ctor.cpp
@@ -0,0 +1,28 @@
+// Should not crash with '-analyzer-opt-analyze-headers' option during CTU analysis.
+//
+// RUN: rm -r %t && mkdir -p %t/ctudir
+// RUN: %clang_cc1 -std=c++14 -triple x86_64-pc-linux-gnu \
+// RUN:   -emit-pch -o %t/ctudir/ctu-inherited-default-ctor-other.cpp.ast \
+// RUN:%S/Inputs/ctu-inherited-default-ctor-other.cpp
+// RUN: echo "c:@N@clang@S@DeclContextLookupResult@SingleElementDummyList ctu-inherited-default-ctor-other.cpp.ast" \
+// RUN:   > %t/ctudir/externalDefMap.txt
+//
+// RUN: %clang_analyze_cc1 -std=c++14 -triple x86_64-pc-linux-gnu \
+// RUN:   -analyzer-opt-analyze-headers \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-config experimental-enable-naive-ctu-analysis=true \
+// RUN:   -analyzer-config ctu-dir=%t/ctudir \
+// RUN:   -analyzer-config display-ctu-progress=true \
+// RUN:   -verify %s 2>&1 | FileCheck %s
+//
+// expected-no-diagnostics
+//
+// CHECK: CTU loaded AST file: ctu-inherited-default-ctor-other.cpp.ast
+
+namespace clang {}
+namespace llvm {}
+namespace clang {
+class DeclContextLookupResult {
+  static int *const SingleElementDummyList;
+};
+} // namespace clang
Index: clang/test/Analysis/Inputs/ctu-inherited-default-ctor-other.cpp
===
--- /dev/null
+++ clang/test/Analysis/Inputs/ctu-inherited-default-ctor-other.cpp
@@ -0,0 +1,27 @@
+namespace llvm {
+template 
+class impl;
+// basecase
+template 
+class impl {};
+// recursion
+template 
+class impl : impl {
+  using child = impl;
+  using child::child; // no-crash
+  impl(T);
+};
+template 
+class container : impl<0, TS...> {};
+} // namespace llvm
+namespace clang {
+class fun {
+  llvm::container k;
+  fun() {}

[PATCH] D95244: [clang][AST] Handle overload callee type in CallExpr::getCallReturnType.

2021-02-12 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95244

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


[PATCH] D96163: [analyzer] Add 12.0.0. release notes

2021-02-12 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

I'm ok with this on my part.


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

https://reviews.llvm.org/D96163

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


[PATCH] D96588: [OpenCL] Remove FIXME in getOpenCLFeatureDefines

2021-02-12 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.
svenvh added reviewers: Anastasia, azabaznov.
svenvh added a project: clang.
Herald added a subscriber: yaxunl.
svenvh requested review of this revision.
Herald added a subscriber: cfe-commits.

The suggestion in D92277  was to move 
`OpenCLOptions` into `LanguageOptions`, but
this is not viable.  Sema's `LangOpts` is immutable, and embedding
`OpenCLOptions` into `LangOpts` would make `OpenCLOptions` immutable too.
This is incompatible with handling of pragmas that alter the
`OpenCLOptions` during parsing/sema.

Perhaps there might be another solution, so putting this up for discussion with
@Anastasia and @azabaznov to start with.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96588

Files:
  clang/lib/Basic/Targets.cpp


Index: clang/lib/Basic/Targets.cpp
===
--- clang/lib/Basic/Targets.cpp
+++ clang/lib/Basic/Targets.cpp
@@ -720,9 +720,6 @@
 /// and language version
 void TargetInfo::getOpenCLFeatureDefines(const LangOptions &Opts,
  MacroBuilder &Builder) const {
-  // FIXME: OpenCL options which affect language semantics/syntax
-  // should be moved into LangOptions, thus macro definitions of
-  // such options is better to be done in clang::InitializePreprocessor
   auto defineOpenCLExtMacro = [&](llvm::StringRef Name, unsigned AvailVer,
   unsigned CoreVersions,
   unsigned OptionalVersions) {


Index: clang/lib/Basic/Targets.cpp
===
--- clang/lib/Basic/Targets.cpp
+++ clang/lib/Basic/Targets.cpp
@@ -720,9 +720,6 @@
 /// and language version
 void TargetInfo::getOpenCLFeatureDefines(const LangOptions &Opts,
  MacroBuilder &Builder) const {
-  // FIXME: OpenCL options which affect language semantics/syntax
-  // should be moved into LangOptions, thus macro definitions of
-  // such options is better to be done in clang::InitializePreprocessor
   auto defineOpenCLExtMacro = [&](llvm::StringRef Name, unsigned AvailVer,
   unsigned CoreVersions,
   unsigned OptionalVersions) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D96515: [OpenCL] Add builtin declarations by default.

2021-02-12 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added a comment.

It probably makes sense to update `clang/docs/UsersManual.rst` as part of this 
change.  In particular the following sentence is no longer true after this 
patch: "By default the OpenCL headers are not loaded and therefore certain 
builtin types and most of builtin functions are not declared."




Comment at: clang/include/clang/Driver/Options.td:822
+def cl_no_stdinc : Flag<["-"], "cl-no-stdinc">, Group,
+  HelpText<"OpenCL only. Disables all standard includes containing non-native 
to compiler types and functions from OpenCL C.">;
 def client__name : JoinedOrSeparate<["-"], "client_name">;

Typo.

Also, this suggests the option is limited to OpenCL C, is that your intent?


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

https://reviews.llvm.org/D96515

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


[PATCH] D96203: [clang][patch] Modify sanitizer options names: renaming blacklist to blocklist

2021-02-12 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

>> FWIW I would prefer denylist as well. (Also uses of whitelist should be 
>> allowlist, but also incremental :)

I feel like existing and proposed value do match the meaning of this list.
maybe ignorelist, skiplist (can be confused with data structure?), or just 
asan_no_sanitize.txt or even no_asan.txt

> I can change D82244  used blocklist to 
> denylist . If there is no need for compatibility, I'll just replace the 
> strings. If there is need for compatibility, I can make blocklist an alias.

I don't think we need compatibility for D82244 
. If we change clang, we can update D82244 
 to the same for consistency.




Comment at: clang/unittests/Driver/SanitizerArgsTest.cpp:134-136
   Contains(StrEq("-fxray-always-instrument=" + XRayWhitelist)));
   EXPECT_THAT(Command.getArguments(),
+  Contains(StrEq("-fxray-never-instrument=" + XRayBlocklist)));

always/never?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96203

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


[PATCH] D96524: [OpenCL] Add support of OpenCL C 3.0 __opencl_c_fp64

2021-02-12 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added inline comments.



Comment at: clang/include/clang/Basic/OpenCLOptions.h:157
+  // Is OpenCL C feature (OpenCL C 3.0, 6.2.1. Features)
+  bool isFeature(llvm::StringRef Ext) const;
+

The argument "Ext" suggests "Extension", so perhaps rename if this is about 
features? (also in the definition in the .cpp file)



Comment at: clang/lib/Basic/TargetInfo.cpp:395
+
+// Set extensions simultaneosly with correspoding features
+// for OpenCL C 3.0 and higher

simultaneosly -> simultaneously
correspoding -> corresponding



Comment at: clang/lib/Headers/opencl-c.h:4635
 
-#ifdef cl_khr_fp64
+#if defined(cl_khr_fp64) || defined(__opencl_c_fp64)
 #pragma OPENCL EXTENSION cl_khr_fp64 : enable

Wondering if we need a similar change in `clang/lib/Headers/opencl-c-base.h` to 
guard the double vector types?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96524

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


[clang] fdb640e - Mark output as text if it is really text

2021-02-12 Thread Abhina Sreeskantharajan via cfe-commits

Author: Abhina Sreeskantharajan
Date: 2021-02-12T07:14:21-05:00
New Revision: fdb640ea30d416368b76b68b106deda580c6aced

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

LOG: Mark output as text if it is really text

This is a continuation of https://reviews.llvm.org/D67696. The following places 
need to set the OF_Text flag correctly.

Reviewed By: JDevlieghere

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

Added: 


Modified: 
clang/lib/Driver/Driver.cpp
clang/lib/Frontend/Rewrite/FrontendActions.cpp
llvm/tools/dsymutil/DwarfLinkerForBinary.cpp

Removed: 




diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 54a66992f84b..02f4f478031f 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1445,7 +1445,9 @@ void Driver::generateCompilationDiagnostics(
   llvm::SmallString<128> Script(CrashInfo.Filename);
   llvm::sys::path::replace_extension(Script, "sh");
   std::error_code EC;
-  llvm::raw_fd_ostream ScriptOS(Script, EC, llvm::sys::fs::CD_CreateNew);
+  llvm::raw_fd_ostream ScriptOS(Script, EC, llvm::sys::fs::CD_CreateNew,
+llvm::sys::fs::FA_Write,
+llvm::sys::fs::OF_Text);
   if (EC) {
 Diag(clang::diag::note_drv_command_failed_diag_msg)
 << "Error generating run script: " << Script << " " << EC.message();

diff  --git a/clang/lib/Frontend/Rewrite/FrontendActions.cpp 
b/clang/lib/Frontend/Rewrite/FrontendActions.cpp
index 5351ff0593ed..13e668a47a2f 100644
--- a/clang/lib/Frontend/Rewrite/FrontendActions.cpp
+++ b/clang/lib/Frontend/Rewrite/FrontendActions.cpp
@@ -185,7 +185,7 @@ RewriteObjCAction::CreateASTConsumer(CompilerInstance &CI, 
StringRef InFile) {
 void RewriteMacrosAction::ExecuteAction() {
   CompilerInstance &CI = getCompilerInstance();
   std::unique_ptr OS =
-  CI.createDefaultOutputFile(true, getCurrentFileOrBufferName());
+  CI.createDefaultOutputFile(/*Binary=*/false, 
getCurrentFileOrBufferName());
   if (!OS) return;
 
   RewriteMacrosInInput(CI.getPreprocessor(), OS.get());
@@ -270,7 +270,7 @@ class RewriteIncludesAction::RewriteImportsListener : 
public ASTReaderListener {
 bool RewriteIncludesAction::BeginSourceFileAction(CompilerInstance &CI) {
   if (!OutputStream) {
 OutputStream =
-CI.createDefaultOutputFile(true, getCurrentFileOrBufferName());
+CI.createDefaultOutputFile(/*Binary=*/false, 
getCurrentFileOrBufferName());
 if (!OutputStream)
   return false;
   }

diff  --git a/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp 
b/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
index 01ee325002df..b2eaa067a3d9 100644
--- a/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
+++ b/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
@@ -252,7 +252,10 @@ static Error emitRemarks(const LinkOptions &Options, 
StringRef BinaryPath,
   }
 
   std::error_code EC;
-  raw_fd_ostream OS(Options.NoOutput ? "-" : Path.str(), EC, sys::fs::OF_None);
+  raw_fd_ostream OS(Options.NoOutput ? "-" : Path.str(), EC,
+Options.RemarksFormat == remarks::Format::Bitstream
+? sys::fs::OF_None
+: sys::fs::OF_Text);
   if (EC)
 return errorCodeToError(EC);
 



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


[PATCH] D96363: Mark output as text if it is really text

2021-02-12 Thread Abhina Sree 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 rGfdb640ea30d4: Mark output as text if it is really text 
(authored by abhina.sreeskantharajan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96363

Files:
  clang/lib/Driver/Driver.cpp
  clang/lib/Frontend/Rewrite/FrontendActions.cpp
  llvm/tools/dsymutil/DwarfLinkerForBinary.cpp


Index: llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
===
--- llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
+++ llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
@@ -252,7 +252,10 @@
   }
 
   std::error_code EC;
-  raw_fd_ostream OS(Options.NoOutput ? "-" : Path.str(), EC, sys::fs::OF_None);
+  raw_fd_ostream OS(Options.NoOutput ? "-" : Path.str(), EC,
+Options.RemarksFormat == remarks::Format::Bitstream
+? sys::fs::OF_None
+: sys::fs::OF_Text);
   if (EC)
 return errorCodeToError(EC);
 
Index: clang/lib/Frontend/Rewrite/FrontendActions.cpp
===
--- clang/lib/Frontend/Rewrite/FrontendActions.cpp
+++ clang/lib/Frontend/Rewrite/FrontendActions.cpp
@@ -185,7 +185,7 @@
 void RewriteMacrosAction::ExecuteAction() {
   CompilerInstance &CI = getCompilerInstance();
   std::unique_ptr OS =
-  CI.createDefaultOutputFile(true, getCurrentFileOrBufferName());
+  CI.createDefaultOutputFile(/*Binary=*/false, 
getCurrentFileOrBufferName());
   if (!OS) return;
 
   RewriteMacrosInInput(CI.getPreprocessor(), OS.get());
@@ -270,7 +270,7 @@
 bool RewriteIncludesAction::BeginSourceFileAction(CompilerInstance &CI) {
   if (!OutputStream) {
 OutputStream =
-CI.createDefaultOutputFile(true, getCurrentFileOrBufferName());
+CI.createDefaultOutputFile(/*Binary=*/false, 
getCurrentFileOrBufferName());
 if (!OutputStream)
   return false;
   }
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1445,7 +1445,9 @@
   llvm::SmallString<128> Script(CrashInfo.Filename);
   llvm::sys::path::replace_extension(Script, "sh");
   std::error_code EC;
-  llvm::raw_fd_ostream ScriptOS(Script, EC, llvm::sys::fs::CD_CreateNew);
+  llvm::raw_fd_ostream ScriptOS(Script, EC, llvm::sys::fs::CD_CreateNew,
+llvm::sys::fs::FA_Write,
+llvm::sys::fs::OF_Text);
   if (EC) {
 Diag(clang::diag::note_drv_command_failed_diag_msg)
 << "Error generating run script: " << Script << " " << EC.message();


Index: llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
===
--- llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
+++ llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
@@ -252,7 +252,10 @@
   }
 
   std::error_code EC;
-  raw_fd_ostream OS(Options.NoOutput ? "-" : Path.str(), EC, sys::fs::OF_None);
+  raw_fd_ostream OS(Options.NoOutput ? "-" : Path.str(), EC,
+Options.RemarksFormat == remarks::Format::Bitstream
+? sys::fs::OF_None
+: sys::fs::OF_Text);
   if (EC)
 return errorCodeToError(EC);
 
Index: clang/lib/Frontend/Rewrite/FrontendActions.cpp
===
--- clang/lib/Frontend/Rewrite/FrontendActions.cpp
+++ clang/lib/Frontend/Rewrite/FrontendActions.cpp
@@ -185,7 +185,7 @@
 void RewriteMacrosAction::ExecuteAction() {
   CompilerInstance &CI = getCompilerInstance();
   std::unique_ptr OS =
-  CI.createDefaultOutputFile(true, getCurrentFileOrBufferName());
+  CI.createDefaultOutputFile(/*Binary=*/false, getCurrentFileOrBufferName());
   if (!OS) return;
 
   RewriteMacrosInInput(CI.getPreprocessor(), OS.get());
@@ -270,7 +270,7 @@
 bool RewriteIncludesAction::BeginSourceFileAction(CompilerInstance &CI) {
   if (!OutputStream) {
 OutputStream =
-CI.createDefaultOutputFile(true, getCurrentFileOrBufferName());
+CI.createDefaultOutputFile(/*Binary=*/false, getCurrentFileOrBufferName());
 if (!OutputStream)
   return false;
   }
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1445,7 +1445,9 @@
   llvm::SmallString<128> Script(CrashInfo.Filename);
   llvm::sys::path::replace_extension(Script, "sh");
   std::error_code EC;
-  llvm::raw_fd_ostream ScriptOS(Script, EC, llvm::sys::fs::CD_CreateNew);
+  llvm::raw_fd_ostream ScriptOS(Script, EC, llvm::sys::fs::CD_CreateNew,
+llvm::sys::fs::FA_Write,
+llvm::sys::fs::OF_Text);
   if (EC) {
 Diag(clang::dia

[PATCH] D96542: [clang-tidy] Fix `TransformerClangTidyCheck`'s handling of include insertions.

2021-02-12 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

Thanks, the fix looks good.

> This patch was tested manually. The clang tidy unit test framework does not
> support testing changes to header files. Given that this is a bug fix for a 
> live
> bug, the patch relies on manual testing rather than blocking on upgrading the
> unit test framework.

If extending the test framework is too much work, I think we can write a lit 
test for a transformer-based check e.g. abseil-string-find-str-contains: setup 
an include header, and verify the include is inserted in the header.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96542

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


[PATCH] D87587: [clang-format][PR47290] Add ShortNamespaceLines format option

2021-02-12 Thread Krystian Kuzniarek via Phabricator via cfe-commits
kuzkry updated this revision to Diff 323289.
kuzkry marked 2 inline comments as done.
kuzkry added a comment.

Rebased to the tip of the main branch, merged similar tests (requested by 
@curdeius)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87587

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/NamespaceEndCommentsFixer.cpp
  clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp

Index: clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
===
--- clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
+++ clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
@@ -816,7 +816,7 @@
 "}\n"));
 }
 
-TEST_F(NamespaceEndCommentsFixerTest, AddEndCommentForNamespacesAroundMacros) {
+TEST_F(NamespaceEndCommentsFixerTest, AddsEndCommentForNamespacesAroundMacros) {
   // Conditional blocks around are fine
   EXPECT_EQ("namespace A {\n"
 "#if 1\n"
@@ -1116,6 +1116,75 @@
 "}\n"
 "}\n"));
 }
+
+using ShortNamespaceLinesTest = NamespaceEndCommentsFixerTest;
+
+TEST_F(ShortNamespaceLinesTest, ZeroUnwrappedLines) {
+  auto Style = getLLVMStyle();
+  Style.ShortNamespaceLines = 0u;
+
+  EXPECT_EQ("namespace OneLinerNamespace {}\n",
+fixNamespaceEndComments("namespace OneLinerNamespace {}\n", Style));
+  EXPECT_EQ("namespace ShortNamespace {\n"
+"}\n",
+fixNamespaceEndComments("namespace ShortNamespace {\n"
+"}\n",
+Style));
+  EXPECT_EQ("namespace LongNamespace {\n"
+"int i;\n"
+"}// namespace LongNamespace\n",
+fixNamespaceEndComments("namespace LongNamespace {\n"
+"int i;\n"
+"}\n",
+Style));
+}
+
+TEST_F(ShortNamespaceLinesTest, OneUnwrappedLine) {
+  constexpr auto DefaultUnwrappedLines = 1u;
+  auto const Style = getLLVMStyle();
+
+  EXPECT_EQ(DefaultUnwrappedLines, Style.ShortNamespaceLines);
+  EXPECT_EQ("namespace ShortNamespace {\n"
+"int i;\n"
+"}\n",
+fixNamespaceEndComments("namespace ShortNamespace {\n"
+"int i;\n"
+"}\n"));
+  EXPECT_EQ("namespace LongNamespace {\n"
+"int i;\n"
+"int j;\n"
+"}// namespace LongNamespace\n",
+fixNamespaceEndComments("namespace LongNamespace {\n"
+"int i;\n"
+"int j;\n"
+"}\n"));
+}
+
+TEST_F(ShortNamespaceLinesTest, MultipleUnwrappedLine) {
+  auto Style = getLLVMStyle();
+  Style.ShortNamespaceLines = 2u;
+
+  EXPECT_EQ("namespace ShortNamespace {\n"
+"int i;\n"
+"int j;\n"
+"}\n",
+fixNamespaceEndComments("namespace ShortNamespace {\n"
+"int i;\n"
+"int j;\n"
+"}\n",
+Style));
+  EXPECT_EQ("namespace LongNamespace {\n"
+"int i;\n"
+"int j;\n"
+"int k;\n"
+"}// namespace LongNamespace\n",
+fixNamespaceEndComments("namespace LongNamespace {\n"
+"int i;\n"
+"int j;\n"
+"int k;\n"
+"}\n",
+Style));
+}
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: clang/lib/Format/NamespaceEndCommentsFixer.cpp
===
--- clang/lib/Format/NamespaceEndCommentsFixer.cpp
+++ clang/lib/Format/NamespaceEndCommentsFixer.cpp
@@ -22,10 +22,6 @@
 namespace format {
 
 namespace {
-// The maximal number of unwrapped lines that a short namespace spans.
-// Short namespaces don't need an end comment.
-static const int kShortNamespaceMaxLines = 1;
-
 // Computes the name of a namespace given the namespace token.
 // Returns "" for anonymous namespace.
 std::string computeName(const FormatToken *NamespaceTok) {
@@ -283,7 +279,7 @@
 computeEndCommentText(NamespaceName, AddNewline, NamespaceTok,
   Style.SpacesInLineCommentPrefix.Minimum);
 if (!hasEndComment(EndCommentPrevTok)) {
-  bool isShort = I - StartLineIndex <= kShortNamespaceMaxLines + 1;
+  bool isShort = I - StartLineIndex <= Style.ShortNamespaceLines + 1;
   if (!isShort)
 addEnd

[PATCH] D87587: [clang-format][PR47290] Add ShortNamespaceLines format option

2021-02-12 Thread Krystian Kuzniarek via Phabricator via cfe-commits
kuzkry marked 2 inline comments as done.
kuzkry added inline comments.



Comment at: clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp:1162
+
+  EXPECT_EQ(DefaultUnwrappedLines, Style.ShortNamespaceLines);
+  EXPECT_EQ("namespace ShortNamespace {\n"

curdeius wrote:
> Nit.
Well, instead of using comments or giving it a separate test, I wanted to have 
a nice self-explanatory name.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87587

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


[PATCH] D96344: [flang][driver] Add options for -fdefault* and -flarge-sizes

2021-02-12 Thread Arnamoy B via Phabricator via cfe-commits
arnamoy10 added inline comments.



Comment at: clang/include/clang/Driver/Options.td:4163
 defm d_lines_as_comments : BooleanFFlag<"d-lines-as-comments">, 
Group;
-defm default_double_8 : BooleanFFlag<"default-double-8">, 
Group;
-defm default_integer_8 : BooleanFFlag<"default-integer-8">, 
Group;
-defm default_real_8 : BooleanFFlag<"default-real-8">, Group;
+defm default_double_8 : BooleanFFlag<"default-double-8">, 
Group, Flags<[FlangOption,FC1Option]>;
+defm default_integer_8 : BooleanFFlag<"default-integer-8">, 
Group, Flags<[FlangOption,FC1Option]>;

awarzynski wrote:
> Could you add a help text? Note that once you add a help text, you will have 
> to add `FlangOnlyOption` flag to make sure this option doesn't show up in: 
> ```
> clang -help
> ```
> 
> Some for other options here. Also, at that point, I suggest moving these 
> options near other Flang options: 
> https://github.com/llvm/llvm-project/blob/ec4fb5bcd3b92867156a5bd75fa0be4c74084f3c/clang/include/clang/Driver/Options.td#L4224-L4238.
> 
> AFAIK, these options are no longer forwarded to `gfortran` anyway (since this 
> [[ 
> https://github.com/llvm/llvm-project/commit/6a75496836ea14bcfd2f4b59d35a1cad4ac58cee
>  | patch ]]).
What should be the help text for `-flarge-sizes`, given we cannot take 
reference from gfortran


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96344

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


[PATCH] D96244: [clangd] Introduce Modules

2021-02-12 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 323290.
kadircet marked 7 inline comments as done.
kadircet added a comment.

- Define destruction order
- Get rid of Module.cpp and Module::id
- Define begin/end iterators for ModuleSet


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96244

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/Module.h
  clang-tools-extra/clangd/unittests/ParsedASTTests.cpp

Index: clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
===
--- clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
+++ clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
@@ -376,7 +376,7 @@
 void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
 StringRef FileName, bool IsAngled,
 CharSourceRange FilenameRange, const FileEntry *,
-StringRef, StringRef, const Module *,
+StringRef, StringRef, const clang::Module *,
 SrcMgr::CharacteristicKind) override {
   Includes.emplace_back(SM, HashLoc, IncludeTok, FileName, IsAngled,
 FilenameRange);
Index: clang-tools-extra/clangd/Module.h
===
--- /dev/null
+++ clang-tools-extra/clangd/Module.h
@@ -0,0 +1,55 @@
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_MODULE_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_MODULE_H
+
+#include "llvm/ADT/StringRef.h"
+#include 
+#include 
+
+namespace clang {
+namespace clangd {
+
+/// A Module contributes a vertical feature to clangd.
+///
+/// FIXME: Extend this with LSP bindings to support reading/updating
+/// capabilities and implementing LSP endpoints.
+///
+/// The lifetime of a module is roughly:
+///  - modules are created before the LSP server, in ClangdMain.cpp
+///  - these modules are then passed to ClangdLSPServer and ClangdServer
+///FIXME: LSP bindings should be registered at ClangdLSPServer creation, and
+///we should make some server facilities like TUScheduler and index
+///available to those modules after ClangdServer is initalized.
+///  - module hooks can be called afterwards.
+///  - ClangdServer will not be destroyed until all the requests are done.
+///FIXME: Block server shutdown until all the modules are idle.
+///  - modules will be destroyed after ClangdLSPServer is destroyed.
+///
+/// Conventionally, standard modules live in the `clangd` namespace, and other
+/// exposed details live in a sub-namespace.
+class Module {
+public:
+  virtual ~Module() = default;
+
+  /// Some modules might own background tasks. They should override this method
+  /// to indicate status of these tasks.
+  virtual void blockUntilIdle() {}
+};
+
+class ModuleSet {
+  std::vector> Modules;
+
+public:
+  explicit ModuleSet(std::vector> Modules)
+  : Modules(std::move(Modules)) {}
+
+  using iterator = llvm::pointee_iterator;
+  using const_iterator =
+  llvm::pointee_iterator;
+  iterator begin() { return iterator(Modules.begin()); }
+  iterator end() { return iterator(Modules.end()); }
+  const_iterator begin() const { return const_iterator(Modules.begin()); }
+  const_iterator end() const { return const_iterator(Modules.end()); }
+};
+} // namespace clangd
+} // namespace clang
+#endif
Index: clang-tools-extra/clangd/Headers.cpp
===
--- clang-tools-extra/clangd/Headers.cpp
+++ clang-tools-extra/clangd/Headers.cpp
@@ -36,7 +36,7 @@
   CharSourceRange /*FilenameRange*/,
   const FileEntry *File, llvm::StringRef /*SearchPath*/,
   llvm::StringRef /*RelativePath*/,
-  const Module * /*Imported*/,
+  const clang::Module * /*Imported*/,
   SrcMgr::CharacteristicKind FileKind) override {
 auto MainFID = SM.getMainFileID();
 // If an include is part of the preamble patch, translate #line directives.
Index: clang-tools-extra/clangd/ClangdServer.h
===
--- clang-tools-extra/clangd/ClangdServer.h
+++ clang-tools-extra/clangd/ClangdServer.h
@@ -14,6 +14,7 @@
 #include "ConfigProvider.h"
 #include "GlobalCompilationDatabase.h"
 #include "Hover.h"
+#include "Module.h"
 #include "Protocol.h"
 #include "SemanticHighlighting.h"
 #include "TUScheduler.h"
@@ -29,14 +30,17 @@
 #include "support/ThreadsafeFS.h"
 #include "clang/Tooling/CompilationDatabase.h"
 #include "clang/Tooling/Core/Replacement.h"
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/FunctionExtras.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/ADT/Optional.h"
 #include 

[PATCH] D96244: [clangd] Introduce Modules

2021-02-12 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/Module.h:25
+///  - module hooks can be called afterwards.
+///  - modules can be destroyed before/after ClangdServer and ClangdLSPServer
+///FIXME: Once we make server facilities available to modules, we'll need 
to

sammccall wrote:
> this doesn't make sense to me - neither of these own the modules (right?), so 
> who would be destroying them while the server is still alive (and how would 
> we ensure this is safe)?
I was leaving this out from initial patch because current module interface 
didn't have any dependence on server facilities (hence the fixme below). Happy 
to declare the semantics now though, all your points are right.



Comment at: clang-tools-extra/clangd/Module.h:36
+  /// Identifier for the plugin, should be unique.
+  virtual llvm::StringLiteral id() = 0;
+

sammccall wrote:
> what is this for? is it needed?
no more. i was planning to make use of it to dispatch command executions to 
relevant module, but as we discussed offline when modules register those 
themselves it won't be needed.



Comment at: clang-tools-extra/clangd/Module.h:39
+  /// Some modules might own background tasks. They should override this method
+  /// to indicate status of these tasks.
+  virtual void blockUntilIdle() {}

sammccall wrote:
> Some indication that this is for testing.
this is needed to block clangdserver shutdown until modules finish any 
background tasks. would it make sense to rename it to `stop` instead?



Comment at: clang-tools-extra/clangd/Module.h:43
+
+/// Wrapper around a set of modules to provide type based grouping.
+// Ideas for implementing this:

sammccall wrote:
> As discussed offline, I don't think sub-interfaces are a great way to express 
> the various ways to express clangd, at least initially.
> You end up either having to deal with multiple inheritance or multiple module 
> instances.
> The former is a hassle we only need consider if the interface gets wide, the 
> latter loses some of the simplicity of the model (if a feature contains 3 
> hooks that share state, where does that state go?)
> 
> For now, I think it's enough to be able to iterate over Module&s (Given the 
> ModuleSet name, I think defining begin()/end() etc make sense)
SG. I've copied the iterators from your patch :)



Comment at: clang-tools-extra/clangd/Module.h:53
+public:
+  explicit ModuleSet(std::vector> Modules);
+  // Returns all the modules of type T.

sammccall wrote:
> this interface isn't compatible with modules eventually having public 
> interfaces, because it loses the type information. but we can change this 
> later
agreed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96244

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


[PATCH] D87587: [clang-format][PR47290] Add ShortNamespaceLines format option

2021-02-12 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks accepted this revision.
HazardyKnusperkeks added a comment.

Although I would put it in one test, this is fine by me.




Comment at: clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp:1201-1206
+}
+
+TEST_F(ShortNamespaceLinesTest,
+   MultipleUnwrappedLine_AddsEndCommentForLongNamespace) {
+  auto Style = getLLVMStyle();
+  Style.ShortNamespaceLines = 2u;

curdeius wrote:
> What I meant by "merging the tests together" is just writing:
> ```
> TEST_F(ShortNamespaceLinesTest,
>MultipleUnwrappedLine) {
>   auto Style = getLLVMStyle();
>   Style.ShortNamespaceLines = 2u;
> 
>   EXPECT_EQ(...);
> 
>   EXPECT_EQ(...);
> }
> ```
> This will get rid of duplicated setup (even if small), and, what's more 
> important, show the behaviour with the same style on different cases.
> 
> Or even, but I'm not forcing you to do so, having a single test case for all 
> `ShortNamespaceLinesTest.*` tests. It groups the test for the same feature 
> together.
I would even go further and put the 0, 1, and 2 in one function.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87587

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


[PATCH] D95396: Improve static_assert/_Static_assert diagnostics

2021-02-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Parse/ParseDeclCXX.cpp:874-876
+if (!getLangOpts().CPlusPlus)
+  Diag(Tok, diag::warn_cxx_static_assert_in_c)
+  << FixItHint::CreateReplacement(Tok.getLocation(), "_Static_assert");

rsmith wrote:
> aaron.ballman wrote:
> > aaron.ballman wrote:
> > > rsmith wrote:
> > > > I don't think this diagnostic is useful as-is: on Windows, including 
> > > > `` doesn't help because it doesn't `#define static_assert`. 
> > > > And people hitting this also can't switch to using `_Static_assert`, 
> > > > because MSVC doesn't provide it, only `static_assert`.
> > > > 
> > > > If we want to warn here, we could perhaps check whether `` 
> > > > has been included, but getting that check correct across PCH / modules 
> > > > is not straightforward. (If we knew what include guard the CRT's 
> > > > `assert.h` used (if any), I guess we could check whether that's 
> > > > defined, but that'd be a bit of a hack.) But I'm somewhat inclined to 
> > > > think we don't have a good way to distinguish between the good cases 
> > > > and the bad ones, so we shouldn't warn. Hopefully MS will fix their CRT 
> > > > at some point and we can stop providing this compatibility hack 
> > > > entirely (or start warning on it by default).
> > > Are you sure they don't support `_Static_assert` yet? I seem to be able 
> > > to use it fine: https://godbolt.org/z/vG47he
> > > 
> > > That said, this does appear to be only available in newer versions of 
> > > MSVC, so perhaps you're correct about the diagnostic being a bit 
> > > unhelpful. My primary concern is that use of `static_assert` in C is a 
> > > nonconforming extension and we default to `-fms-compatibility` on Windows 
> > > when Clang is built by MSVC. So it's not difficult to accidentally run 
> > > into this, but the only warning we give on it with `-Weverything 
> > > -pedantic` is how it's not compatible with C++98.
> > > 
> > > WDYT?
> > I suppose one option would be to look at what version of MSVC we're trying 
> > to be compatible with to see if that's a version that supports `/std:c11` 
> > and only emit this diagnostic in that case, but tbh, that feels like it'll 
> > lead to confusing diagnostic behavior (esp given that we default to ms 
> > compatibility mode silently when you build Clang with MSVC on Windows).
> > 
> > Given that MSVC does support `_Static_assert` when you enable C11 or later 
> > language mode, I'm inclined to warn on this construct by default.
> > 
> > WDYT?
> Well, it's good to see that they've made progress, but it [looks 
> like](https://godbolt.org/z/YfEhGW) their `` still doesn't `#define 
> static_assert`, so I think we still don't have an actionable warning we can 
> produce here. We can't reasonably tell people to include `` (as 
> this patch does) because that doesn't work. And it doesn't seem reasonable to 
> tell people to use `_Static_assert` instead, if they actually have included 
> ``. (I don't think we want to encourage people to use 
> `_Static_assert` instead of `` + `static_assert`.)
> 
> So I don't think MSVC adding support for `_Static_assert` really changes 
> anything here -- until their `` works, or we find some good way to 
> detect whether it was properly included, this warning will fire on both 
> correct code and incorrect code, which doesn't seem all that useful.
>  And it doesn't seem reasonable to tell people to use _Static_assert instead, 
> if they actually have included . (I don't think we want to 
> encourage people to use _Static_assert instead of  + static_assert.)

Ideally, yes. But this isn't ideal -- we produce no diagnostic for this 
nonconforming extension and that's causing pain in practice. As an example of 
where I ran into this: I had a header file that was shared between C and 
(mostly) C++ code and added a `static_assert` to it but forgot to add `#include 
`. This compiled great in MSVC and clang-cl, but when compiled with 
clang on CI is when I finally found the issue. e.g., like this: 
https://godbolt.org/z/cs8YGb

If I had to pick between behaviors, I think I'd prefer pushing people towards 
using `_Static_assert` even if `assert.h` is included over silently accepting a 
nonconforming extension in pedantic mode.

Rather than trying to see what header guard was used by ``, couldn't 
we assume that if `assert` is defined as a macro then `` must have 
been included (or the user triggered UB and gets what they get)? So the logic 
could be: only diagnose use of the `static_assert` (keyword) in C mode if 
`assert` is not defined?

> We can't reasonably tell people to include  (as this patch does) 
> because that doesn't work.

But it does (as far as the user is concerned)? In MS compatibility mode, 
`static_assert` is always accepted, so the include isn't strictly necessary but 
isn't harmful either. Outside of MS compatibility mode, the include is required 
to spell it `static_assert` because we won't

[PATCH] D96597: [DebugInfo] Keep the DWARF64 flag in the module metadata

2021-02-12 Thread Igor Kudrin via Phabricator via cfe-commits
ikudrin created this revision.
ikudrin added reviewers: ayermolo, MaskRay, wenlei, dblaikie.
ikudrin added projects: LLVM, clang, debug-info.
Herald added subscribers: dexonsmith, ormris, hiraditya.
ikudrin requested review of this revision.

This allows the option to affect the LTO output. `Module::Max` helps to 
generate debug info for all modules in the same format.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96597

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/dwarf-format.c
  llvm/include/llvm/IR/Module.h
  llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
  llvm/lib/IR/Module.cpp
  llvm/test/DebugInfo/X86/dwarf64-module-flag.ll

Index: llvm/test/DebugInfo/X86/dwarf64-module-flag.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/X86/dwarf64-module-flag.ll
@@ -0,0 +1,37 @@
+; This checks that the debug info is generated in the 64-bit format if the
+; module has the corresponding flag.
+
+; RUN: llc -mtriple=x86_64 -filetype=obj %s -o %t
+; RUN: llvm-dwarfdump -debug-info -debug-line %t | FileCheck %s
+
+; CHECK:  Compile Unit: {{.*}} format = DWARF64
+; CHECK:  debug_line[
+; CHECK-NEXT: Line table prologue:
+; CHECK-NEXT:   total_length:
+; CHECK-NEXT: format: DWARF64
+
+; IR generated and reduced from:
+; $ cat foo.c
+; int foo;
+; $ clang -g -gdwarf64 -S -emit-llvm foo.c -o foo.ll
+
+target triple = "x86_64-unknown-linux-gnu"
+
+@foo = dso_local global i32 0, align 4, !dbg !0
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!7, !8, !9, !10}
+!llvm.ident = !{!11}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "foo", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true)
+!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 12.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, splitDebugInlining: false, nameTableKind: None)
+!3 = !DIFile(filename: "foo.c", directory: "/tmp")
+!4 = !{}
+!5 = !{!0}
+!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!7 = !{i32 7, !"Dwarf Version", i32 4}
+!8 = !{i32 7, !"DWARF64", i32 1}
+!9 = !{i32 2, !"Debug Info Version", i32 3}
+!10 = !{i32 1, !"wchar_size", i32 4}
+!11 = !{!"clang version 13.0.0"}
Index: llvm/lib/IR/Module.cpp
===
--- llvm/lib/IR/Module.cpp
+++ llvm/lib/IR/Module.cpp
@@ -509,6 +509,11 @@
   return cast(Val->getValue())->getZExtValue();
 }
 
+bool Module::isDwarf64() const {
+  auto *Val = cast_or_null(getModuleFlag("DWARF64"));
+  return Val && cast(Val->getValue())->isOne();
+}
+
 unsigned Module::getCodeViewFlag() const {
   auto *Val = cast_or_null(getModuleFlag("CodeView"));
   if (!Val)
Index: llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
===
--- llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -392,10 +392,11 @@
   DwarfVersion =
   TT.isNVPTX() ? 2 : (DwarfVersion ? DwarfVersion : dwarf::DWARF_VERSION);
 
-  bool Dwarf64 = Asm->TM.Options.MCOptions.Dwarf64 &&
- DwarfVersion >= 3 &&   // DWARF64 was introduced in DWARFv3.
- TT.isArch64Bit() &&// DWARF64 requires 64-bit relocations.
- TT.isOSBinFormatELF(); // Support only ELF for now.
+  bool Dwarf64 =
+  (Asm->TM.Options.MCOptions.Dwarf64 || MMI->getModule()->isDwarf64()) &&
+  DwarfVersion >= 3 &&   // DWARF64 was introduced in DWARFv3.
+  TT.isArch64Bit() &&// DWARF64 requires 64-bit relocations.
+  TT.isOSBinFormatELF(); // Support only ELF for now.
 
   UseRangesSection = !NoDwarfRangesSection && !TT.isNVPTX();
 
Index: llvm/include/llvm/IR/Module.h
===
--- llvm/include/llvm/IR/Module.h
+++ llvm/include/llvm/IR/Module.h
@@ -805,6 +805,9 @@
   /// Returns the Dwarf Version by checking module flags.
   unsigned getDwarfVersion() const;
 
+  /// Returns the DWARF format by checking module flags.
+  bool isDwarf64() const;
+
   /// Returns the CodeView Version by checking module flags.
   /// Returns zero if not present in module.
   unsigned getCodeViewFlag() const;
Index: clang/test/CodeGen/dwarf-format.c
===
--- /dev/null
+++ clang/test/CodeGen/dwarf-format.c
@@ -0,0 +1,13 @@
+// RUN: %clang -target x86_64-linux-gnu -g -S -emit-llvm -o - %s | \
+// RUN:   FileCheck %s --check-prefix=NODWARF64
+// RUN: %clang -target x86_64-linux-gnu -g -gdwarf64 -S -emit-llvm -o - %s | \
+// RUN:   FileCheck %s --check-prefix=DWARF64
+// RUN: %clang -target x86_64-linux-gnu -g -gdwarf64 -gdwarf32 -S -emit-llvm -o - %s | \
+// RUN:   FileCheck %s --check-prefix=NODWARF64
+
+// DWARF64: !{i32 7, !"DWARF64", i32 1}
+// NODWARF64-NOT: !"DWARF64"
+
+int main (void) {
+ 

[PATCH] D96344: [flang][driver] Add options for -fdefault* and -flarge-sizes

2021-02-12 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

Btw, could you clang-format your patch? I normally use `git -lang-format 
HEAD~`. Thank you!




Comment at: flang/lib/Frontend/CompilerInvocation.cpp:261
+   diags.getCustomDiagID(clang::DiagnosticsEngine::Error,
+ "Use of `-fdefault-double-8` requires `-fdefault-real-8`");
+   diags.Report(diagID);

arnamoy10 wrote:
> awarzynski wrote:
> > Is this requirement document anywhere?
> Just found out through running `gfortran`
Oh, indeed:
```
gfortran -fdefault-double-8 file.f
f951: Fatal Error: Use of ‘-fdefault-double-8’ requires ‘-fdefault-real-8’
compilation terminated.
```
Thanks you for being so thorough and checking this! :)

I think that it would help to:
* add a comment explaining _why_ this diagnostic is added (compatibility with 
`gfortran` is a good reason IMO)
*  add a test to verify that it's indeed issued.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96344

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


[PATCH] D69560: [clang-tidy] Add 'bugprone-easily-swappable-parameters' check

2021-02-12 Thread Whisperity via Phabricator via cfe-commits
whisperity updated this revision to Diff 323305.
whisperity added a comment.

Make sure that overloadable binary operators are ignored properly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69560

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/bugprone-easily-swappable-parameters.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-ignore.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len2.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters-len3.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters.c

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters.c
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-easily-swappable-parameters.c
@@ -0,0 +1,148 @@
+// RUN: %check_clang_tidy %s bugprone-easily-swappable-parameters %t \
+// RUN:   -config='{CheckOptions: [ \
+// RUN: {key: bugprone-easily-swappable-parameters.MinimumLength, value: 2}, \
+// RUN: {key: bugprone-easily-swappable-parameters.IgnoredParameterNames, value: ""}, \
+// RUN: {key: bugprone-easily-swappable-parameters.IgnoredParameterTypeSuffixes, value: "bool;MyBool;struct U;MAKE_LOGICAL_TYPE(int)"} \
+// RUN:  ]}' -- -x c
+
+#define bool _Bool
+#define true 1
+#define false 0
+
+typedef bool MyBool;
+
+#define TheLogicalType bool
+
+void declVoid(void); // NO-WARN: Declaration only.
+void decl(); // NO-WARN: Declaration only.
+void oneParam(int I) {}  // NO-WARN: 1 parameter.
+void variadic(int I, ...) {} // NO-WARN: 1 visible parameter.
+
+void trivial(int I, int J) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: 2 adjacent parameters of 'trivial' of similar type ('int') are easily swapped by mistake [bugprone-easily-swappable-parameters]
+// CHECK-MESSAGES: :[[@LINE-2]]:18: note: the first parameter in the range is 'I'
+// CHECK-MESSAGES: :[[@LINE-3]]:25: note: the last parameter in the range is 'J'
+
+void qualifier(int I, const int CI) {} // NO-WARN: Distinct types.
+
+void restrictQualifier(char *restrict CPR1, char *restrict CPR2) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: 2 adjacent parameters of 'restrictQualifier' of similar type ('char *restrict')
+// CHECK-MESSAGES: :[[@LINE-2]]:39: note: the first parameter in the range is 'CPR1'
+// CHECK-MESSAGES: :[[@LINE-3]]:60: note: the last parameter in the range is 'CPR2'
+
+void pointer1(int *IP1, int *IP2) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: 2 adjacent parameters of 'pointer1' of similar type ('int *')
+// CHECK-MESSAGES: :[[@LINE-2]]:20: note: the first parameter in the range is 'IP1'
+// CHECK-MESSAGES: :[[@LINE-3]]:30: note: the last parameter in the range is 'IP2'
+
+void pointerConversion(int *IP, long *LP) {}
+// NO-WARN: Even though C can convert any T* to U* back and forth, compiler
+// warnings already exist for this.
+
+void testVariadicsCall() {
+  int IVal = 1;
+  decl(IVal); // NO-WARN: Particular calls to "variadics" are like template
+  // instantiations, and we do not model them.
+
+  variadic(IVal);  // NO-WARN.
+  variadic(IVal, 2, 3, 4); // NO-WARN.
+}
+
+struct S {};
+struct T {};
+
+void taggedTypes1(struct S SVar, struct T TVar) {} // NO-WARN: Distinct types.
+
+void taggedTypes2(struct S SVar1, struct S SVar2) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: 2 adjacent parameters of 'taggedTypes2' of similar type ('struct S')
+// CHECK-MESSAGES: :[[@LINE-2]]:28: note: the first parameter in the range is 'SVar1'
+// CHECK-MESSAGES: :[[@LINE-3]]:44: note: the last parameter in the range is 'SVar2'
+
+void wrappers(struct { int I; } I1, struct { int I; } I2) {} // NO-WARN: Distinct anonymous types.
+
+void knr(I, J)
+  int I;
+  int J;
+{}
+// CHECK-MESSAGES: :[[@LINE-3]]:3: warning: 2 adjacent parameters of 'knr' of similar type ('int')
+// CHECK-MESSAGES: :[[@LINE-4]]:7: note: the first parameter in the range is 'I'
+// CHECK-MESSAGES: :[[@LINE-4]]:7: note: the last parameter in the range is 'J'
+
+void boolAsWritten(bool B1, bool B2) {} // NO-WARN: The type name is ignored.
+// Note that "bool" is a macro that expands to "_Bool" internally, but it is
+// only "bool" that is ignored from the two.
+
+void underscoreBoolAsWritten(_Bool B1, _Bool B2) {}
+// Even though it is "_Bool" that is written in the code, the diagnostic message
+// respects the printing policy as defined by the compila

[PATCH] D96265: [PowerPC] Change target data layout for 16-byte stack alignment

2021-02-12 Thread Ahsan Saghir via Phabricator via cfe-commits
saghir updated this revision to Diff 323307.
saghir added a comment.

Merged tests into one file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96265

Files:
  clang/lib/Basic/Targets/PPC.h
  clang/test/CodeGen/target-data.c
  lld/test/ELF/common-archive-lookup.s
  llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
  llvm/test/CodeGen/PowerPC/P10-stack-alignment.ll

Index: llvm/test/CodeGen/PowerPC/P10-stack-alignment.ll
===
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/P10-stack-alignment.ll
@@ -0,0 +1,106 @@
+; RUN: opt --passes=sroa,loop-vectorize,loop-unroll,instcombine -S \
+; RUN: -vectorizer-maximize-bandwidth --mtriple=powerpc64le-- < %s | \
+; RUN: FileCheck %s
+
+
+define dso_local signext i32 @test_32byte_vector() nounwind {
+; CHECK-LABEL: @test_32byte_vector(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[TMP0:%.*]] = alloca <8 x i32>, align 32
+; CHECK: store <8 x i32> , <8 x i32>* [[TMP0:%.*]], align 32
+; CHECK: load <8 x i32>, <8 x i32>* [[TMP0:%.*]], align 32
+entry:
+  %a = alloca <8 x i32>, align 32
+  %0 = bitcast <8 x i32>* %a to i8*
+  call void @llvm.lifetime.start.p0i8(i64 32, i8* %0)
+  store <8 x i32> , <8 x i32>* %a, align 32
+  call void @test(<8 x i32>* %a)
+  %1 = load <8 x i32>, <8 x i32>* %a, align 32
+  %vecext = extractelement <8 x i32> %1, i32 0
+  %2 = bitcast <8 x i32>* %a to i8*
+  call void @llvm.lifetime.end.p0i8(i64 32, i8* %2)
+  ret i32 %vecext
+}
+
+define dso_local signext i32 @test_32byte_aligned_vector() nounwind {
+; CHECK-LABEL: @test_32byte_aligned_vector(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[TMP0:%.*]] = alloca <4 x i32>, align 32
+; CHECK: store <4 x i32> , <4 x i32>* [[TMP0:%.*]], align 32
+
+entry:
+  %a = alloca <4 x i32>, align 32
+  %0 = bitcast <4 x i32>* %a to i8*
+  call void @llvm.lifetime.start.p0i8(i64 16, i8* %0)
+  store <4 x i32> , <4 x i32>* %a, align 32
+  call void @test1(<4 x i32>* %a)
+  %1 = load <4 x i32>, <4 x i32>* %a, align 32
+  %vecext = extractelement <4 x i32> %1, i32 0
+  %2 = bitcast <4 x i32>* %a to i8*
+  call void @llvm.lifetime.end.p0i8(i64 16, i8* %2)
+  ret i32 %vecext
+}
+
+
+@Arr1 = dso_local global [64 x i8] zeroinitializer, align 1
+
+define dso_local void @test_Array() nounwind {
+; CHECK-LABEL: @test_Array(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: %Arr2 = alloca [64 x i16], align 32
+; CHECK: store <16 x i16> [[TMP0:%.*]], <16 x i16>* [[TMP0:%.*]], align 32
+entry:
+  %Arr2 = alloca [64 x i16], align 2
+  %i = alloca i32, align 4
+  %0 = bitcast [64 x i16]* %Arr2 to i8*
+  call void @llvm.lifetime.start.p0i8(i64 128, i8* %0)
+  %1 = bitcast i32* %i to i8*
+  call void @llvm.lifetime.start.p0i8(i64 4, i8* %1)
+  store i32 0, i32* %i, align 4
+  br label %for.cond
+
+for.cond: ; preds = %for.inc, %entry
+  %2 = load i32, i32* %i, align 4
+  %cmp = icmp slt i32 %2, 64
+  br i1 %cmp, label %for.body, label %for.cond.cleanup
+
+for.cond.cleanup: ; preds = %for.cond
+  %3 = bitcast i32* %i to i8*
+  call void @llvm.lifetime.end.p0i8(i64 4, i8* %3)
+  br label %for.end
+
+for.body: ; preds = %for.cond
+  %4 = load i32, i32* %i, align 4
+  %idxprom = sext i32 %4 to i64
+  %arrayidx = getelementptr inbounds [64 x i8], [64 x i8]* @Arr1, i64 0, i64 %idxprom
+  %5 = load i8, i8* %arrayidx, align 1
+  %conv = zext i8 %5 to i16
+  %6 = load i32, i32* %i, align 4
+  %idxprom1 = sext i32 %6 to i64
+  %arrayidx2 = getelementptr inbounds [64 x i16], [64 x i16]* %Arr2, i64 0, i64 %idxprom1
+  store i16 %conv, i16* %arrayidx2, align 2
+  br label %for.inc
+
+for.inc:  ; preds = %for.body
+  %7 = load i32, i32* %i, align 4
+  %inc = add nsw i32 %7, 1
+  store i32 %inc, i32* %i, align 4
+  br label %for.cond
+
+for.end:  ; preds = %for.cond.cleanup
+  %arraydecay = getelementptr inbounds [64 x i16], [64 x i16]* %Arr2, i64 0, i64 0
+  call void @test_arr(i16* %arraydecay)
+  %8 = bitcast [64 x i16]* %Arr2 to i8*
+  call void @llvm.lifetime.end.p0i8(i64 128, i8* %8)
+  ret void
+}
+
+declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) nounwind
+
+declare void @test(<8 x i32>*) nounwind
+declare void @test1(<4 x i32>*) nounwind
+declare void @test_arr(i16*)
+
+declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) nounwind
+
+
Index: llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
===
--- llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
+++ llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
@@ -157,9 +157,8 @@
   // Specify the vector alignment explicitly. For v256i1 and v512i1, the
   // calculated alignment would be 256*alignment(i1) and 512*alignment(i1),
   // which is 256 and 512 bytes - way over aligned.
-  if ((T.getArch() == Triple::ppc64

[PATCH] D94640: adds more checks to -Wfree-nonheap-object

2021-02-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/test/Analysis/free.c:84
+  // expected-warning@-1{{Argument to free() is a block, which is not memory 
allocated by malloc()}}
+  // expected-warning@-2{{attempt to call free on non-heap object : block 
expression}}
 }

cjdb wrote:
> aaron.ballman wrote:
> > cjdb wrote:
> > > aaron.ballman wrote:
> > > > The formatting for this diagnostic is somewhat unfortunate in that it 
> > > > has the leading space before the `:`. I think that changing the 
> > > > diagnostic to use a `%select` would be an improvement.
> > > I'm having a *lot* of difficulty getting `%select` to work. Here's what 
> > > I've tried, but the space in `%select{ %2` is being ignored :(
> > > 
> > > ```
> > > : Warning<"attempt to call %0 on non-heap object%select{ %2|: block 
> > > expression}1">,
> > > ```
> > We could cheat a little bit. :-D
> > 
> > `Warning<"attempt to call %0 on non-heap %select{object %2|object: block 
> > expression}1">`
> > 
> > (The diagnostic should probably be updated to distinguish between block 
> > expressions and lambda expressions, which may add another layer of 
> > `%select` not shown here.)
> That doesn't fix the issue, which is that everything before `%2` is deleted.
Huh? That seems very surprising given that we use this pattern in plenty of 
other places:

https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/DiagnosticSemaKinds.td#L483
https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/DiagnosticSemaKinds.td#L685
https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/DiagnosticSemaKinds.td#L1439

Can you post the output you're getting when you try my workaround? (I don't 
know if your original attempt will work because of the lack of whitespace 
before the `%select` in `object%select`.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94640

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


[PATCH] D96578: [clangd] Remove the cross-file-rename option.

2021-02-12 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGee4dd0f87698: [clangd] Remove the cross-file-rename option. 
(authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96578

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

Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -189,25 +189,6 @@
 };
   )cpp",
 
-  // Class methods overrides.
-  R"cpp(
-struct A {
- virtual void [[f^oo]]() {}
-};
-struct B : A {
-  void [[f^oo]]() override {}
-};
-struct C : B {
-  void [[f^oo]]() override {}
-};
-
-void func() {
-  A().[[f^oo]]();
-  B().[[f^oo]]();
-  C().[[f^oo]]();
-}
-  )cpp",
-
   // Templated method instantiation.
   R"cpp(
 template
@@ -831,13 +812,10 @@
 auto TU = TestTU::withCode(Code.code());
 TU.ExtraArgs.push_back("-xobjective-c++");
 auto AST = TU.build();
+auto Index = TU.index();
 for (const auto &RenamePos : Code.points()) {
-  auto RenameResult = rename({RenamePos,
-  NewName,
-  AST,
-  testPath(TU.Filename),
-  /*Index*/ nullptr,
-  {/*CrossFile*/ false}});
+  auto RenameResult =
+  rename({RenamePos, NewName, AST, testPath(TU.Filename), Index.get()});
   ASSERT_TRUE(bool(RenameResult)) << RenameResult.takeError();
   ASSERT_EQ(1u, RenameResult->GlobalChanges.size());
   EXPECT_EQ(
@@ -852,20 +830,8 @@
 const char *Code;
 const char* ErrorMessage; // null if no error
 bool IsHeaderFile;
-const SymbolIndex *Index;
 llvm::StringRef NewName = "DummyName";
   };
-  TestTU OtherFile = TestTU::withCode("Outside s; auto ss = &foo;");
-  const char *CommonHeader = R"cpp(
-class Outside {};
-void foo();
-  )cpp";
-  OtherFile.HeaderCode = CommonHeader;
-  OtherFile.Filename = "other.cc";
-  // The index has a "Outside" reference and a "foo" reference.
-  auto OtherFileIndex = OtherFile.index();
-  const SymbolIndex *Index = OtherFileIndex.get();
-
   const bool HeaderFile = true;
   Case Cases[] = {
   {R"cpp(// allow -- function-local
@@ -873,73 +839,39 @@
   [[Local]] = 2;
 }
   )cpp",
-   nullptr, HeaderFile, Index},
-
-  {R"cpp(// allow -- symbol is indexable and has no refs in index.
-void [[On^lyInThisFile]]();
-  )cpp",
-   nullptr, HeaderFile, Index},
-
-  {R"cpp(
-void ^f();
-  )cpp",
-   "keyword", HeaderFile, Index, "return"},
-
-  {R"cpp(// disallow -- symbol is indexable and has other refs in index.
-void f() {
-  Out^side s;
-}
-  )cpp",
-   "used outside main file", HeaderFile, Index},
+   nullptr, HeaderFile},
 
   {R"cpp(// disallow -- symbol in anonymous namespace in header is not indexable.
 namespace {
 class Unin^dexable {};
 }
   )cpp",
-   "not eligible for indexing", HeaderFile, Index},
-
-  {R"cpp(// allow -- symbol in anonymous namespace in non-header file is indexable.
-namespace {
-class [[F^oo]] {};
-}
-  )cpp",
-   nullptr, !HeaderFile, Index},
+   "not eligible for indexing", HeaderFile},
 
   {R"cpp(// disallow -- namespace symbol isn't supported
 namespace n^s {}
   )cpp",
-   "not a supported kind", HeaderFile, Index},
+   "not a supported kind", HeaderFile},
 
   {
   R"cpp(
  #define MACRO 1
  int s = MAC^RO;
)cpp",
-  "not a supported kind", HeaderFile, Index},
+  "not a supported kind", HeaderFile},
 
   {
   R"cpp(
 struct X { X operator++(int); };
 void f(X x) {x+^+;})cpp",
-  "no symbol", HeaderFile, Index},
-
-  {R"cpp(// foo is declared outside the file.
-void fo^o() {}
-  )cpp",
-   "used outside main file", !HeaderFile /*cc file*/, Index},
-
-  {R"cpp(
- // We should detect the symbol is used outside the file from the AST.
- void fo^o() {})cpp",
-   "used outside main file", !HeaderFile, nullptr /*no index*/},
+  "no symbol", HeaderFile},
 
   {R"cpp(// disallow rename on excluded symbols (e.g. std symbols)
  namespace std {
  class str^ing {};
  }
)cpp",
-   "not a supported kind", !HeaderFile, Index},
+   "not a supported 

[clang-tools-extra] ee4dd0f - [clangd] Remove the cross-file-rename option.

2021-02-12 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2021-02-12T15:38:55+01:00
New Revision: ee4dd0f87698330a8d86ed268d69c4fe9be49e6f

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

LOG: [clangd] Remove the cross-file-rename option.

and simplify the code.

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

Added: 


Modified: 
clang-tools-extra/clangd/ClangdServer.cpp
clang-tools-extra/clangd/refactor/Rename.cpp
clang-tools-extra/clangd/refactor/Rename.h
clang-tools-extra/clangd/unittests/RenameTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/ClangdServer.cpp 
b/clang-tools-extra/clangd/ClangdServer.cpp
index a1ffacf96848..b39e582d84a1 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -397,20 +397,15 @@ void ClangdServer::prepareRename(PathRef File, Position 
Pos,
  const RenameOptions &RenameOpts,
  Callback CB) {
   auto Action = [Pos, File = File.str(), CB = std::move(CB),
- NewName = std::move(NewName), RenameOpts,
- this](llvm::Expected InpAST) mutable {
+ NewName = std::move(NewName),
+ RenameOpts](llvm::Expected InpAST) mutable {
 if (!InpAST)
   return CB(InpAST.takeError());
-// prepareRename is latency-sensitive:
-//  - for single-file rename, performing rename isn't substantially more
-//expensive than doing an AST-based check (the index is used to see if
-//the rename is complete);
-//  - for cross-file rename, we deliberately pass a nullptr index to save
-//the cost, thus the result may be incomplete as it only contains
-//main-file occurrences;
+// prepareRename is latency-sensitive: we don't query the index, as we
+// only need main-file references
 auto Results = clangd::rename(
 {Pos, NewName.getValueOr("__clangd_rename_dummy"), InpAST->AST, File,
- RenameOpts.AllowCrossFile ? nullptr : Index, RenameOpts});
+ /*Index=*/nullptr, RenameOpts});
 if (!Results) {
   // LSP says to return null on failure, but that will result in a generic
   // failure message. If we send an LSP error response, clients can surface

diff  --git a/clang-tools-extra/clangd/refactor/Rename.cpp 
b/clang-tools-extra/clangd/refactor/Rename.cpp
index 6c117fc26273..96cd79bcea35 100644
--- a/clang-tools-extra/clangd/refactor/Rename.cpp
+++ b/clang-tools-extra/clangd/refactor/Rename.cpp
@@ -60,27 +60,6 @@ bool isInMacroBody(const SourceManager &SM, SourceLocation 
Loc) {
   return false;
 }
 
-// Query the index to find some other files where the Decl is referenced.
-llvm::Optional getOtherRefFile(const Decl &D, StringRef MainFile,
-const SymbolIndex &Index) {
-  RefsRequest Req;
-  // We limit the number of results, this is a correctness/performance
-  // tradeoff. We expect the number of symbol references in the current file
-  // is smaller than the limit.
-  Req.Limit = 100;
-  Req.IDs.insert(getSymbolID(&D));
-  llvm::Optional OtherFile;
-  Index.refs(Req, [&](const Ref &R) {
-if (OtherFile)
-  return;
-if (auto RefFilePath = filePath(R.Location, /*HintFilePath=*/MainFile)) {
-  if (!pathEqual(*RefFilePath, MainFile))
-OtherFile = *RefFilePath;
-}
-  });
-  return OtherFile;
-}
-
 // Canonical declarations help simplify the process of renaming. Examples:
 // - Template's canonical decl is the templated declaration (i.e.
 //   ClassTemplateDecl is canonicalized to its child CXXRecordDecl,
@@ -195,7 +174,6 @@ enum class ReasonToReject {
   NoSymbolFound,
   NoIndexProvided,
   NonIndexable,
-  UsedOutsideFile, // for within-file rename only.
   UnsupportedSymbol,
   AmbiguousSymbol,
 
@@ -206,8 +184,7 @@ enum class ReasonToReject {
 
 llvm::Optional renameable(const NamedDecl &RenameDecl,
   StringRef MainFilePath,
-  const SymbolIndex *Index,
-  bool CrossFile) {
+  const SymbolIndex *Index) {
   trace::Span Tracer("Renameable");
   // Filter out symbols that are unsupported in both rename modes.
   if (llvm::isa(&RenameDecl))
@@ -240,34 +217,9 @@ llvm::Optional renameable(const NamedDecl 
&RenameDecl,
   IsMainFileOnly))
 return ReasonToReject::NonIndexable;
 
-  if (!CrossFile) {
-if (!DeclaredInMainFile)
-  // We are sure the symbol is used externally, bail out early.
-  return ReasonToReject::UsedOutsideFile;
-
-// If the symbol is declared in the main file (which is not a header), we
-// rename it.
-if (!MainFileIsHeader)
-  return N

[PATCH] D96244: [clangd] Introduce Modules

2021-02-12 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/ClangdServer.h:33
 #include "clang/Tooling/Core/Replacement.h"
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/FunctionExtras.h"

(include no longer used?)



Comment at: clang-tools-extra/clangd/Module.h:19
+///  - these modules are then passed to ClangdLSPServer and ClangdServer
+///FIXME: LSP bindings should be registered at ClangdLSPServer creation, 
and
+///we should make some server facilities like TUScheduler and index

not at creation, but rather at `initialize` time



Comment at: clang-tools-extra/clangd/Module.h:20
+///FIXME: LSP bindings should be registered at ClangdLSPServer creation, 
and
+///we should make some server facilities like TUScheduler and index
+///available to those modules after ClangdServer is initalized.

maybe this is a separate fixme (basically ClangdLSPServer vs Server)



Comment at: clang-tools-extra/clangd/Module.h:22
+///available to those modules after ClangdServer is initalized.
+///  - module hooks can be called afterwards.
+///  - ClangdServer will not be destroyed until all the requests are done.

after what? at this point?



Comment at: clang-tools-extra/clangd/Module.h:31
+public:
+  virtual ~Module() = default;
+

Should either:
 - doc that destructor should cancel as much background work as possible and 
block until it's done
 - add a requestStop() and doc that destructor should block
 - remove the concept of background work completely (i.e. blockUntilIdle())


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96244

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


[PATCH] D96203: [clang][patch] Modify sanitizer options names: renaming blacklist to blocklist

2021-02-12 Thread Melanie Blower via Phabricator via cfe-commits
mibintc added a comment.

In D96203#2559426 , @vitalybuka wrote:

>>> FWIW I would prefer denylist as well. (Also uses of whitelist should be 
>>> allowlist, but also incremental :)
>
> I feel like existing and proposed value do match the meaning of this list.
> maybe ignorelist, skiplist (can be confused with data structure?), or just 
> asan_no_sanitize.txt or even no_asan.txt

Would you use ignorelist (skiplist) in the option name as well as the filename? 
 Can you recommend a name for the antonym as well (i.e. replacement for 
whitelist)

>> I can change D82244  used blocklist to 
>> denylist . If there is no need for compatibility, I'll just replace the 
>> strings. If there is need for compatibility, I can make blocklist an alias.
>
> I don't think we need compatibility for D82244 
> . If we change clang, we can update D82244 
>  to the same for consistency.

Yes I agree.




Comment at: clang/unittests/Driver/SanitizerArgsTest.cpp:134-136
   Contains(StrEq("-fxray-always-instrument=" + XRayWhitelist)));
   EXPECT_THAT(Command.getArguments(),
+  Contains(StrEq("-fxray-never-instrument=" + XRayBlocklist)));

vitalybuka wrote:
> always/never?
Can you say a few more works here? You mean use always as replacement for 
white, and never as replacement for black? 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96203

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


[clang-tools-extra] cea9f05 - [clangd] Move command handlers into a map in ClangdLSPServer. NFC

2021-02-12 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2021-02-12T15:57:43+01:00
New Revision: cea9f054327be2eb83093f0202a7814b904f1076

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

LOG: [clangd] Move command handlers into a map in ClangdLSPServer. NFC

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

Added: 


Modified: 
clang-tools-extra/clangd/ClangdLSPServer.cpp
clang-tools-extra/clangd/ClangdLSPServer.h
clang-tools-extra/clangd/Protocol.cpp
clang-tools-extra/clangd/Protocol.h

Removed: 




diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index 4263edb8cd6a..2aca82ee09d5 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -51,7 +51,6 @@
 namespace clang {
 namespace clangd {
 namespace {
-
 // Tracks end-to-end latency of high level lsp calls. Measurements are in
 // seconds.
 constexpr trace::Metric LSPLatency("lsp_latency", trace::Metric::Distribution,
@@ -71,6 +70,9 @@ llvm::Optional decodeVersion(llvm::StringRef 
Encoded) {
   return llvm::None;
 }
 
+const llvm::StringLiteral APPLY_FIX_COMMAND = "clangd.applyFix";
+const llvm::StringLiteral APPLY_TWEAK_COMMAND = "clangd.applyTweak";
+
 /// Transforms a tweak into a code action that would apply it if executed.
 /// EXPECTS: T.prepare() was called and returned true.
 CodeAction toCodeAction(const ClangdServer::TweakRef &T, const URIForFile 
&File,
@@ -85,11 +87,12 @@ CodeAction toCodeAction(const ClangdServer::TweakRef &T, 
const URIForFile &File,
   //directly.
   CA.command.emplace();
   CA.command->title = T.Title;
-  CA.command->command = std::string(Command::CLANGD_APPLY_TWEAK);
-  CA.command->tweakArgs.emplace();
-  CA.command->tweakArgs->file = File;
-  CA.command->tweakArgs->tweakID = T.ID;
-  CA.command->tweakArgs->selection = Selection;
+  CA.command->command = std::string(APPLY_TWEAK_COMMAND);
+  TweakArgs Args;
+  Args.file = File;
+  Args.tweakID = T.ID;
+  Args.selection = Selection;
+  CA.command->argument = std::move(Args);
   return CA;
 }
 
@@ -582,6 +585,10 @@ void ClangdLSPServer::onInitialize(const InitializeParams 
&Params,
  {CodeAction::QUICKFIX_KIND, CodeAction::REFACTOR_KIND,
   CodeAction::INFO_KIND}}};
 
+  std::vector Commands;
+  llvm::append_range(Commands, CommandHandlers.keys());
+  llvm::sort(Commands);
+
   llvm::json::Object Result{
   {{"serverInfo",
 llvm::json::Object{{"name", "clangd"},
@@ -641,11 +648,7 @@ void ClangdLSPServer::onInitialize(const InitializeParams 
&Params,
 {"referencesProvider", true},
 {"astProvider", true}, // clangd extension
 {"executeCommandProvider",
- llvm::json::Object{
- {"commands",
-  {ExecuteCommandParams::CLANGD_APPLY_FIX_COMMAND,
-   ExecuteCommandParams::CLANGD_APPLY_TWEAK}},
- }},
+ llvm::json::Object{{"commands", Commands}}},
 {"typeHierarchyProvider", true},
 {"memoryUsageProvider", true}, // clangd extension
 {"compilationDatabase",// clangd extension
@@ -730,85 +733,86 @@ void ClangdLSPServer::onFileEvent(const 
DidChangeWatchedFilesParams &Params) {
 
 void ClangdLSPServer::onCommand(const ExecuteCommandParams &Params,
 Callback Reply) {
-  auto ApplyEdit = [this](WorkspaceEdit WE, std::string SuccessMessage,
-  decltype(Reply) Reply) {
-ApplyWorkspaceEditParams Edit;
-Edit.edit = std::move(WE);
-call(
-"workspace/applyEdit", std::move(Edit),
-[Reply = std::move(Reply), SuccessMessage = std::move(SuccessMessage)](
-llvm::Expected Response) mutable {
-  if (!Response)
-return Reply(Response.takeError());
-  if (!Response->applied) {
-std::string Reason = Response->failureReason
- ? *Response->failureReason
- : "unknown reason";
-return Reply(error("edits were not applied: {0}", Reason));
-  }
-  return Reply(SuccessMessage);
-});
-  };
-
-  if (Params.command == ExecuteCommandParams::CLANGD_APPLY_FIX_COMMAND &&
-  Params.workspaceEdit) {
-// The flow for "apply-fix" :
-// 1. We publish a diagnostic, including fixits
-// 2. The user clicks on the diagnostic, the editor asks us for code 
actions
-// 3. We send code actions, with the fixit embedded as context
-// 4. The user selects the fixit, the editor asks us to apply it
-// 5. We unwrap the changes and send them back to the editor
-// 6. The editor applies the changes (applyEdit), and sends us a reply
-// 7. We 

[PATCH] D96507: [clangd] Move command handlers into a map in ClangdLSPServer. NFC

2021-02-12 Thread Sam McCall via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
sammccall marked 3 inline comments as done.
Closed by commit rGcea9f054327b: [clangd] Move command handlers into a map in 
ClangdLSPServer. NFC (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D96507?vs=323005&id=323319#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96507

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/Protocol.h

Index: clang-tools-extra/clangd/Protocol.h
===
--- clang-tools-extra/clangd/Protocol.h
+++ clang-tools-extra/clangd/Protocol.h
@@ -913,26 +913,13 @@
 bool fromJSON(const llvm::json::Value &, TweakArgs &, llvm::json::Path);
 llvm::json::Value toJSON(const TweakArgs &A);
 
-/// Exact commands are not specified in the protocol so we define the
-/// ones supported by Clangd here. The protocol specifies the command arguments
-/// to be "any[]" but to make this safer and more manageable, each command we
-/// handle maps to a certain llvm::Optional of some struct to contain its
-/// arguments. Different commands could reuse the same llvm::Optional as
-/// arguments but a command that needs different arguments would simply add a
-/// new llvm::Optional and not use any other ones. In practice this means only
-/// one argument type will be parsed and set.
 struct ExecuteCommandParams {
-  // Command to apply fix-its. Uses WorkspaceEdit as argument.
-  const static llvm::StringLiteral CLANGD_APPLY_FIX_COMMAND;
-  // Command to apply the code action. Uses TweakArgs as argument.
-  const static llvm::StringLiteral CLANGD_APPLY_TWEAK;
-
-  /// The command identifier, e.g. CLANGD_APPLY_FIX_COMMAND
+  /// The identifier of the actual command handler.
   std::string command;
 
-  // Arguments
-  llvm::Optional workspaceEdit;
-  llvm::Optional tweakArgs;
+  // This is `arguments?: []any` in LSP.
+  // All clangd's commands accept a single argument (or none => null).
+  llvm::json::Value argument = nullptr;
 };
 bool fromJSON(const llvm::json::Value &, ExecuteCommandParams &,
   llvm::json::Path);
Index: clang-tools-extra/clangd/Protocol.cpp
===
--- clang-tools-extra/clangd/Protocol.cpp
+++ clang-tools-extra/clangd/Protocol.cpp
@@ -655,27 +655,27 @@
   return O && O.map("changes", R.changes);
 }
 
-const llvm::StringLiteral ExecuteCommandParams::CLANGD_APPLY_FIX_COMMAND =
-"clangd.applyFix";
-const llvm::StringLiteral ExecuteCommandParams::CLANGD_APPLY_TWEAK =
-"clangd.applyTweak";
-
 bool fromJSON(const llvm::json::Value &Params, ExecuteCommandParams &R,
   llvm::json::Path P) {
   llvm::json::ObjectMapper O(Params, P);
   if (!O || !O.map("command", R.command))
 return false;
 
-  const auto *Args = Params.getAsObject()->getArray("arguments");
-  if (R.command == ExecuteCommandParams::CLANGD_APPLY_FIX_COMMAND) {
-return Args && Args->size() == 1 &&
-   fromJSON(Args->front(), R.workspaceEdit,
-P.field("arguments").index(0));
+  const auto *Args = Params.getAsObject()->get("arguments");
+  if (!Args)
+return true; // Missing args is ok, argument is null.
+  const auto *ArgsArray = Args->getAsArray();
+  if (!ArgsArray) {
+P.field("arguments").report("expected array");
+return false;
   }
-  if (R.command == ExecuteCommandParams::CLANGD_APPLY_TWEAK)
-return Args && Args->size() == 1 &&
-   fromJSON(Args->front(), R.tweakArgs, P.field("arguments").index(0));
-  return false; // Unrecognized command.
+  if (ArgsArray->size() > 1) {
+P.field("arguments").report("Command should have 0 or 1 argument");
+return false;
+  } else if (ArgsArray->size() == 1) {
+R.argument = ArgsArray->front();
+  }
+  return true;
 }
 
 llvm::json::Value toJSON(const SymbolInformation &P) {
@@ -743,10 +743,8 @@
 
 llvm::json::Value toJSON(const Command &C) {
   auto Cmd = llvm::json::Object{{"title", C.title}, {"command", C.command}};
-  if (C.workspaceEdit)
-Cmd["arguments"] = {*C.workspaceEdit};
-  if (C.tweakArgs)
-Cmd["arguments"] = {*C.tweakArgs};
+  if (!C.argument.getAsNull())
+Cmd["arguments"] = llvm::json::Array{C.argument};
   return std::move(Cmd);
 }
 
Index: clang-tools-extra/clangd/ClangdLSPServer.h
===
--- clang-tools-extra/clangd/ClangdLSPServer.h
+++ clang-tools-extra/clangd/ClangdLSPServer.h
@@ -126,7 +126,6 @@
   void onDocumentHighlight(const TextDocumentPositionParams &,
Callback>);
   void onFileEvent(const DidChangeWatchedFilesParams &);
-  void onCommand(const ExecuteCommandParams &, Callback);
   void onWorksp

[PATCH] D96544: [clangd] Extract binding of typed->untyped LSP handlers to LSPBinder. NFC

2021-02-12 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 323321.
sammccall added a comment.

Rebase and include commands after D96507 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96544

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/LSPBinder.h
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/LSPBinderTests.cpp

Index: clang-tools-extra/clangd/unittests/LSPBinderTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/LSPBinderTests.cpp
@@ -0,0 +1,92 @@
+//===-- LSPBinderTests.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: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "LSPBinder.h"
+#include "llvm/Testing/Support/Error.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+
+using testing::_;
+using testing::HasSubstr;
+using testing::Pair;
+using testing::UnorderedElementsAre;
+
+// JSON-serializable type for testing.
+struct Foo {
+  int x;
+};
+bool fromJSON(const llvm::json::Value &V, Foo &F, llvm::json::Path P) {
+  return fromJSON(V, F.x, P);
+}
+llvm::json::Value toJSON(const Foo &F) { return F.x; }
+
+// Creates a Callback that writes its received value into an Optional.
+template 
+llvm::unique_function)>
+capture(llvm::Optional> &Out) {
+  Out.reset();
+  return [&Out](llvm::Expected V) { Out.emplace(std::move(V)); };
+}
+
+TEST(LSPBinderTest, IncomingCalls) {
+  LSPBinder::RawHandlers RawHandlers;
+  LSPBinder Binder{RawHandlers};
+  struct Handler {
+void plusOne(const Foo &Params, Callback Reply) {
+  Reply(Foo{Params.x + 1});
+}
+void fail(const Foo &Params, Callback Reply) {
+  Reply(error("x={0}", Params.x));
+}
+void notify(const Foo &Params) { lastNotify = Params.x; }
+int lastNotify = -1;
+  };
+
+  Handler H;
+  Binder.method("plusOne", &H, &Handler::plusOne);
+  Binder.method("fail", &H, &Handler::fail);
+  Binder.notification("notify", &H, &Handler::notify);
+  Binder.command("cmdPlusOne", &H, &Handler::plusOne);
+  ASSERT_THAT(RawHandlers.MethodHandlers.keys(),
+  UnorderedElementsAre("plusOne", "fail"));
+  ASSERT_THAT(RawHandlers.NotificationHandlers.keys(),
+  UnorderedElementsAre("notify"));
+  ASSERT_THAT(RawHandlers.CommandHandlers.keys(),
+  UnorderedElementsAre("cmdPlusOne"));
+  llvm::Optional> Reply;
+
+  auto &RawPlusOne = RawHandlers.MethodHandlers["plusOne"];
+  RawPlusOne(1, capture(Reply));
+  EXPECT_THAT_EXPECTED(Reply.getValue(), llvm::HasValue(2));
+  RawPlusOne("foo", capture(Reply));
+  EXPECT_THAT_EXPECTED(
+  Reply.getValue(),
+  llvm::FailedWithMessage(
+  HasSubstr("failed to decode plusOne request: expected integer")));
+
+  auto &RawFail = RawHandlers.MethodHandlers["fail"];
+  RawFail(2, capture(Reply));
+  EXPECT_THAT_EXPECTED(Reply.getValue(), llvm::FailedWithMessage("x=2"));
+
+  auto &RawNotify = RawHandlers.NotificationHandlers["notify"];
+  RawNotify(42);
+  EXPECT_EQ(H.lastNotify, 42);
+  RawNotify("hi"); // invalid, will be logged
+  EXPECT_EQ(H.lastNotify, 42);
+
+  auto &RawCmdPlusOne = RawHandlers.CommandHandlers["cmdPlusOne"];
+  RawCmdPlusOne(1, capture(Reply));
+  EXPECT_THAT_EXPECTED(Reply.getValue(), llvm::HasValue(2));
+}
+} // namespace
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/unittests/CMakeLists.txt
===
--- clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -70,6 +70,7 @@
   IndexTests.cpp
   JSONTransportTests.cpp
   LoggerTests.cpp
+  LSPBinderTests.cpp
   LSPClient.cpp
   ModulesTests.cpp
   ParsedASTTests.cpp
Index: clang-tools-extra/clangd/LSPBinder.h
===
--- /dev/null
+++ clang-tools-extra/clangd/LSPBinder.h
@@ -0,0 +1,138 @@
+//===--- LSPBinder.h - Tables of LSP handlers *- 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_TOOLS_EXTRA_CLANGD_LSPBINDER_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_LSPBINDER_H
+
+#include "Protocol.h"
+#include "support/Function.h"
+#include "support/Logger.h"
+#include "llvm/ADT/FunctionExtras.h"
+#in

[PATCH] D96508: [clangd] Retire clang-tidy-checks flag.

2021-02-12 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

Ping? It would be nice to get this fix in the release branch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96508

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


[clang] 33e731e - [analyzer][Liveness][NFC] Remove an unneeded pass to collect variables that appear in an assignment

2021-02-12 Thread Kirstóf Umann via cfe-commits

Author: Kirstóf Umann
Date: 2021-02-12T16:19:20+01:00
New Revision: 33e731e62dae49d5143410248234963fc7a5e1db

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

LOG: [analyzer][Liveness][NFC] Remove an unneeded pass to collect variables 
that appear in an assignment

Suppose you stumble across a DeclRefExpr in the AST, that references a VarDecl.
How would you know that that variable is written in the containing statement, or
not? One trick would be to ascend the AST through Stmt::getParent, and see
whether the variable appears on the left hand side of the assignment.

Liveness does something similar, but instead of ascending the AST, it descends
into it with a StmtVisitor, and after finding an assignment, it notes that the
LHS appears in the context of an assignemnt. However, as [1] demonstrates, the
analysis isn't ran on the AST of an entire function, but rather on CFG, where
the order of the statements, visited in order, would make it impossible to know
this information by descending.

void f() {
  int i;

  i = 5;
}

`-FunctionDecl 0x55a6e1b070b8  line:1:6 f 'void ()'
  `-CompoundStmt 0x55a6e1b07298 
|-DeclStmt 0x55a6e1b07220 
| `-VarDecl 0x55a6e1b071b8  col:7 used i 'int'
`-BinaryOperator 0x55a6e1b07278  'int' lvalue '='
  |-DeclRefExpr 0x55a6e1b07238  'int' lvalue Var 0x55a6e1b071b8 'i' 
'int'
  `-IntegerLiteral 0x55a6e1b07258  'int' 5

void f()
 [B2 (ENTRY)]
   Succs (1): B1

 [B1]
   1: int i;
   2: 5
   3: i
   4: [B1.3] = [B1.2]
   Preds (1): B2
   Succs (1): B0

 [B0 (EXIT)]
   Preds (1): B1

You can see that the arguments (rightfully so, they need to be evaluated first)
precede the assignment operator. For this reason, Liveness implemented a pass to
scan the CFG and note which variables appear in an assignment.

BUT.

This problem only exists if we traverse a CFGBlock in order. And Liveness in
fact does it reverse order. So a distinct pass is indeed unnecessary, we can
note the appearance of the assignment by the time we reach the variable.

[1] http://lists.llvm.org/pipermail/cfe-dev/2020-July/066330.html

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

Added: 


Modified: 
clang/include/clang/Analysis/CFG.h
clang/lib/Analysis/LiveVariables.cpp

Removed: 




diff  --git a/clang/include/clang/Analysis/CFG.h 
b/clang/include/clang/Analysis/CFG.h
index 43fb523c863a..a0f8c6d21a67 100644
--- a/clang/include/clang/Analysis/CFG.h
+++ b/clang/include/clang/Analysis/CFG.h
@@ -1307,6 +1307,12 @@ class CFG {
 
   iterator nodes_begin() { return iterator(Blocks.begin()); }
   iterator nodes_end() { return iterator(Blocks.end()); }
+
+  llvm::iterator_range nodes() { return {begin(), end()}; }
+  llvm::iterator_range const_nodes() const {
+return {begin(), end()};
+  }
+
   const_iterator nodes_begin() const { return const_iterator(Blocks.begin()); }
   const_iterator nodes_end() const { return const_iterator(Blocks.end()); }
 
@@ -1315,6 +1321,13 @@ class CFG {
   const_reverse_iteratorrbegin()  const{ return Blocks.rbegin(); }
   const_reverse_iteratorrend()const{ return Blocks.rend(); }
 
+  llvm::iterator_range reverse_nodes() {
+return {rbegin(), rend()};
+  }
+  llvm::iterator_range const_reverse_nodes() const {
+return {rbegin(), rend()};
+  }
+
   CFGBlock &getEntry() { return *Entry; }
   const CFGBlock &  getEntry()const{ return *Entry; }
   CFGBlock &getExit()  { return *Exit; }

diff  --git a/clang/lib/Analysis/LiveVariables.cpp 
b/clang/lib/Analysis/LiveVariables.cpp
index 8cdc4cc5bd61..6c601c290c92 100644
--- a/clang/lib/Analysis/LiveVariables.cpp
+++ b/clang/lib/Analysis/LiveVariables.cpp
@@ -325,6 +325,11 @@ static bool writeShouldKill(const VarDecl *VD) {
 }
 
 void TransferFunctions::VisitBinaryOperator(BinaryOperator *B) {
+  if (LV.killAtAssign && B->getOpcode() == BO_Assign) {
+if (const auto *DR = dyn_cast(B->getLHS()->IgnoreParens())) {
+  LV.inAssignment[DR] = 1;
+}
+  }
   if (B->isAssignmentOp()) {
 if (!LV.killAtAssign)
   return;
@@ -513,29 +518,8 @@ LiveVariables::computeLiveness(AnalysisDeclContext &AC, 
bool killAtAssign) {
   llvm::BitVector everAnalyzedBlock(cfg->getNumBlockIDs());
 
   // FIXME: we should enqueue using post order.
-  for (CFG::const_iterator it = cfg->begin(), ei = cfg->end(); it != ei; ++it) 
{
-const CFGBlock *block = *it;
-worklist.enqueueBlock(block);
-
-// FIXME: Scan for DeclRefExprs using in the LHS of an assignment.
-// We need to do this because we lack context in the reverse analysis
-// to determine if a DeclRefExpr appears in such a context, and thus
-// doesn't constitute a "use".
-if (killAtAssign)
-  for (CFGBlock::const_i

[PATCH] D87518: [analyzer][Liveness][NFC] Remove an unneeded pass to collect variables that appear in an assignment

2021-02-12 Thread Kristóf Umann 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 rG33e731e62dae: [analyzer][Liveness][NFC] Remove an unneeded 
pass to collect variables that… (authored by Szelethus).

Changed prior to commit:
  https://reviews.llvm.org/D87518?vs=291234&id=323328#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87518

Files:
  clang/include/clang/Analysis/CFG.h
  clang/lib/Analysis/LiveVariables.cpp


Index: clang/lib/Analysis/LiveVariables.cpp
===
--- clang/lib/Analysis/LiveVariables.cpp
+++ clang/lib/Analysis/LiveVariables.cpp
@@ -325,6 +325,11 @@
 }
 
 void TransferFunctions::VisitBinaryOperator(BinaryOperator *B) {
+  if (LV.killAtAssign && B->getOpcode() == BO_Assign) {
+if (const auto *DR = dyn_cast(B->getLHS()->IgnoreParens())) {
+  LV.inAssignment[DR] = 1;
+}
+  }
   if (B->isAssignmentOp()) {
 if (!LV.killAtAssign)
   return;
@@ -513,29 +518,8 @@
   llvm::BitVector everAnalyzedBlock(cfg->getNumBlockIDs());
 
   // FIXME: we should enqueue using post order.
-  for (CFG::const_iterator it = cfg->begin(), ei = cfg->end(); it != ei; ++it) 
{
-const CFGBlock *block = *it;
-worklist.enqueueBlock(block);
-
-// FIXME: Scan for DeclRefExprs using in the LHS of an assignment.
-// We need to do this because we lack context in the reverse analysis
-// to determine if a DeclRefExpr appears in such a context, and thus
-// doesn't constitute a "use".
-if (killAtAssign)
-  for (CFGBlock::const_iterator bi = block->begin(), be = block->end();
-   bi != be; ++bi) {
-if (Optional cs = bi->getAs()) {
-  const Stmt* stmt = cs->getStmt();
-  if (const auto *BO = dyn_cast(stmt)) {
-if (BO->getOpcode() == BO_Assign) {
-  if (const auto *DR =
-dyn_cast(BO->getLHS()->IgnoreParens())) {
-LV->inAssignment[DR] = 1;
-  }
-}
-  }
-}
-  }
+  for (const CFGBlock *B : cfg->nodes()) {
+worklist.enqueueBlock(B);
   }
 
   while (const CFGBlock *block = worklist.dequeue()) {
Index: clang/include/clang/Analysis/CFG.h
===
--- clang/include/clang/Analysis/CFG.h
+++ clang/include/clang/Analysis/CFG.h
@@ -1307,6 +1307,12 @@
 
   iterator nodes_begin() { return iterator(Blocks.begin()); }
   iterator nodes_end() { return iterator(Blocks.end()); }
+
+  llvm::iterator_range nodes() { return {begin(), end()}; }
+  llvm::iterator_range const_nodes() const {
+return {begin(), end()};
+  }
+
   const_iterator nodes_begin() const { return const_iterator(Blocks.begin()); }
   const_iterator nodes_end() const { return const_iterator(Blocks.end()); }
 
@@ -1315,6 +1321,13 @@
   const_reverse_iteratorrbegin()  const{ return Blocks.rbegin(); }
   const_reverse_iteratorrend()const{ return Blocks.rend(); }
 
+  llvm::iterator_range reverse_nodes() {
+return {rbegin(), rend()};
+  }
+  llvm::iterator_range const_reverse_nodes() const {
+return {rbegin(), rend()};
+  }
+
   CFGBlock &getEntry() { return *Entry; }
   const CFGBlock &  getEntry()const{ return *Entry; }
   CFGBlock &getExit()  { return *Exit; }


Index: clang/lib/Analysis/LiveVariables.cpp
===
--- clang/lib/Analysis/LiveVariables.cpp
+++ clang/lib/Analysis/LiveVariables.cpp
@@ -325,6 +325,11 @@
 }
 
 void TransferFunctions::VisitBinaryOperator(BinaryOperator *B) {
+  if (LV.killAtAssign && B->getOpcode() == BO_Assign) {
+if (const auto *DR = dyn_cast(B->getLHS()->IgnoreParens())) {
+  LV.inAssignment[DR] = 1;
+}
+  }
   if (B->isAssignmentOp()) {
 if (!LV.killAtAssign)
   return;
@@ -513,29 +518,8 @@
   llvm::BitVector everAnalyzedBlock(cfg->getNumBlockIDs());
 
   // FIXME: we should enqueue using post order.
-  for (CFG::const_iterator it = cfg->begin(), ei = cfg->end(); it != ei; ++it) {
-const CFGBlock *block = *it;
-worklist.enqueueBlock(block);
-
-// FIXME: Scan for DeclRefExprs using in the LHS of an assignment.
-// We need to do this because we lack context in the reverse analysis
-// to determine if a DeclRefExpr appears in such a context, and thus
-// doesn't constitute a "use".
-if (killAtAssign)
-  for (CFGBlock::const_iterator bi = block->begin(), be = block->end();
-   bi != be; ++bi) {
-if (Optional cs = bi->getAs()) {
-  const Stmt* stmt = cs->getStmt();
-  if (const auto *BO = dyn_cast(stmt)) {
-if (BO->getOpcode() == BO_Assign) {
-  if (const auto *DR =
-dyn_cast(BO->getLHS()->IgnoreParens())) {

[PATCH] D96607: [clang-tidy] Add check 'readability-pointer-type-star-placement'.

2021-02-12 Thread Balázs Kéri via Phabricator via cfe-commits
balazske created this revision.
Herald added subscribers: martong, gamesh411, Szelethus, dkrupp, xazax.hun, 
whisperity, mgorny.
balazske requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This check should warn if '*' character at pointer declarations is not aligned 
to right side.
I know that clang-format can do these changes but if the goal is not to 
reformat the whole code
this check can be useful.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96607

Files:
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/PointerTypeStarPlacementCheck.cpp
  clang-tools-extra/clang-tidy/readability/PointerTypeStarPlacementCheck.h
  clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/readability-pointer-type-star-placement.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability-pointer-type-star-placement.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability-pointer-type-star-placement.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability-pointer-type-star-placement.cpp
@@ -0,0 +1,75 @@
+// RUN: %check_clang_tidy %s readability-pointer-type-star-placement %t
+
+// clang-format off
+
+int *P1;
+
+int *P2;
+// CHECK-MESSAGES: :[[@LINE-1]]:4: warning: star character at pointer declaration should be aligned to the right
+int *P3;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: star character at pointer declaration should be aligned to the right
+int *P4;
+// CHECK-MESSAGES: :[[@LINE-1]]:4: warning: star character at pointer declaration should be aligned to the right
+
+int **P5;
+// CHECK-MESSAGES: :[[@LINE-1]]:4: warning: star character at pointer declaration should be aligned to the right
+
+int **P6;
+int **P7;
+// CHECK-MESSAGES: :[[@LINE-1]]:4: warning: star character at pointer declaration should be aligned to the right
+int **P8;
+// CHECK-MESSAGES: :[[@LINE-1]]:4: warning: star character at pointer declaration should be aligned to the right
+// CHECK-MESSAGES: :[[@LINE-2]]:5: warning: star character at pointer declaration should be aligned to the right
+
+int **P9;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: star character at pointer declaration should be aligned to the right
+int **P10;
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: star character at pointer declaration should be aligned to the right
+int **P11;
+// CHECK-MESSAGES: :[[@LINE-1]]:4: warning: star character at pointer declaration should be aligned to the right
+// CHECK-MESSAGES: :[[@LINE-2]]:6: warning: star character at pointer declaration should be aligned to the right
+
+int **P12;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: star character at pointer declaration should be aligned to the right
+// CHECK-MESSAGES: :[[@LINE-2]]:7: warning: star character at pointer declaration should be aligned to the right
+
+int *P13, *P14, *P15;
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: star character at pointer declaration should be aligned to the right
+
+int *PArr1[2];
+// CHECK-MESSAGES: :[[@LINE-1]]:4: warning: star character at pointer declaration should be aligned to the right
+int *(*PArr2)[2];
+int *(*PArr3)[2];
+// CHECK-MESSAGES: :[[@LINE-1]]:4: warning: star character at pointer declaration should be aligned to the right
+// CHECK-MESSAGES: :[[@LINE-2]]:7: warning: star character at pointer declaration should be aligned to the right
+
+void f1(int *P1, int *P2, int *P3, int *P4);
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: star character at pointer declaration should be aligned to the right
+// CHECK-MESSAGES: :[[@LINE-2]]:30: warning: star character at pointer declaration should be aligned to the right
+// CHECK-MESSAGES: :[[@LINE-3]]:39: warning: star character at pointer declaration should be aligned to the right
+void f2(int *, int *);
+// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: star character at pointer declaration should be aligned to the right
+
+struct S {
+  void f1(int *, int *);
+  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: star character at pointer declaration should be aligned to the right
+};
+int S::*PM1;
+void (S::*PM2)(int *, int *);
+// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: star character at pointer declaration should be aligned to the right
+
+int *const *PC1;
+int *const *PC2;
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: star character at pointer declaration should be aligned to the right
+int *const *PC3;
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: star character at pointer declaration should be aligned to the right
+int *const *PC4;
+// CHECK-MESSAGES: :[[@LINE-1]]:4: warning: star character at pointer declaration should be aligned to the right
+int *const *PC5;
+// CHECK-MESSAGES: :[[@LINE-1]]:4: warning: star character at pointer 

[PATCH] D96608: [clangd] Delay binding LSP methods until initialize. NFC

2021-02-12 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: kadircet.
Herald added subscribers: usaxena95, arphaman.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang.

This is NFC because the MessageHandler refused to dispatch to them until the
server is initialized anyway.

This is a more natural time to bind them - it's when they become callable, and
it's when client capabalities are available and server ones can be set.

One module-lifecycle function will be responsible for all three.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96608

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h


Index: clang-tools-extra/clangd/ClangdLSPServer.h
===
--- clang-tools-extra/clangd/ClangdLSPServer.h
+++ clang-tools-extra/clangd/ClangdLSPServer.h
@@ -171,6 +171,7 @@
   void applyEdit(WorkspaceEdit WE, llvm::json::Value Success,
  Callback Reply);
 
+  void bindMethods();
   std::vector getFixes(StringRef File, const clangd::Diagnostic &D);
 
   /// Checks if completion request should be ignored. We need this due to the
Index: clang-tools-extra/clangd/ClangdLSPServer.cpp
===
--- clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -162,15 +162,15 @@
 log("<-- {0}", Method);
 if (Method == "exit")
   return false;
-if (!Server.Server) {
-  elog("Notification {0} before initialization", Method);
-} else if (Method == "$/cancelRequest") {
+if (Method == "$/cancelRequest") {
   onCancel(std::move(Params));
 } else if (auto Handler = Notifications.lookup(Method)) {
   Handler(std::move(Params));
   Server.maybeExportMemoryProfile();
   Server.maybeCleanupMemory();
-} else {
+} else if (!Server.Server) {
+  elog("Notification {0} before initialization", Method);
+} else if (Method == "$/cancelRequest") {
   log("unhandled notification {0}", Method);
 }
 return true;
@@ -185,15 +185,16 @@
 SPAN_ATTACH(Tracer, "Params", Params);
 ReplyOnce Reply(ID, Method, &Server, Tracer.Args);
 log("<-- {0}({1})", Method, ID);
-if (!Server.Server && Method != "initialize") {
+if (auto Handler = Calls.lookup(Method)) {
+  Handler(std::move(Params), std::move(Reply));
+} else if (!Server.Server) {
   elog("Call {0} before initialization.", Method);
   Reply(llvm::make_error("server not initialized",
ErrorCode::ServerNotInitialized));
-} else if (auto Handler = Calls.lookup(Method))
-  Handler(std::move(Params), std::move(Reply));
-else
+} else {
   Reply(llvm::make_error("method not found",
ErrorCode::MethodNotFound));
+}
 return true;
   }
 
@@ -568,6 +569,8 @@
 BackgroundIndexProgressState = BackgroundIndexProgress::Empty;
   BackgroundIndexSkipCreate = Params.capabilities.ImplicitProgressCreation;
 
+  bindMethods();
+
   // Per LSP, renameProvider can be either boolean or RenameOptions.
   // RenameOptions will be specified if the client states it supports prepare.
   llvm::json::Value RenameProvider =
@@ -1490,9 +1493,11 @@
 this->Opts.ContextProvider = ClangdServer::createConfiguredContextProvider(
 Opts.ConfigProvider, this);
   }
+  MsgHandler->bind("initialize", &ClangdLSPServer::onInitialize);
+}
 
+void ClangdLSPServer::bindMethods() {
   // clang-format off
-  MsgHandler->bind("initialize", &ClangdLSPServer::onInitialize);
   MsgHandler->bind("initialized", &ClangdLSPServer::onInitialized);
   MsgHandler->bind("shutdown", &ClangdLSPServer::onShutdown);
   MsgHandler->bind("sync", &ClangdLSPServer::onSync);


Index: clang-tools-extra/clangd/ClangdLSPServer.h
===
--- clang-tools-extra/clangd/ClangdLSPServer.h
+++ clang-tools-extra/clangd/ClangdLSPServer.h
@@ -171,6 +171,7 @@
   void applyEdit(WorkspaceEdit WE, llvm::json::Value Success,
  Callback Reply);
 
+  void bindMethods();
   std::vector getFixes(StringRef File, const clangd::Diagnostic &D);
 
   /// Checks if completion request should be ignored. We need this due to the
Index: clang-tools-extra/clangd/ClangdLSPServer.cpp
===
--- clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -162,15 +162,15 @@
 log("<-- {0}", Method);
 if (Method == "exit")
   return false;
-if (!Server.Server) {
-  elog("Notification {0} before initialization", Method);
-} else if (Method == "$/cancelRequest") {
+if (Method == "$/cancelRequest") {
   onCancel(std::move(Params));
 } else if (auto Handler = No

[PATCH] D96508: [clangd] Retire clang-tidy-checks flag.

2021-02-12 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

I think we should have the config mechanism available for one release cycle 
before removing the old one.

So I think it's fine to retire the flag but we shouldn't pick this into the 12  
release branch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96508

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


[PATCH] D68590: [clangd] Improve hover scopes for Objective-C code

2021-02-12 Thread David Goldman via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG07c5a800dc17: Improve hover scopes for Objective-C code 
(authored by dgoldman).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68590

Files:
  clang-tools-extra/clangd/AST.cpp
  clang-tools-extra/clangd/AST.h
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp

Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -2167,7 +2167,8 @@
 HI.Name = "data";
 HI.Type = "char";
 HI.Kind = index::SymbolKind::Field;
-HI.NamespaceScope = "ObjC::"; // FIXME: fix it
+HI.LocalScope = "ObjC::";
+HI.NamespaceScope = "";
 HI.Definition = "char data";
   }},
   {
@@ -2260,6 +2261,86 @@
 HI.Name = "this";
 HI.Definition = "const Foo *";
   }},
+  {
+  R"cpp(
+  @interface MYObject
+  @end
+  @interface MYObject (Private)
+  @property(nonatomic, assign) int privateField;
+  @end
+
+  int someFunction() {
+MYObject *obj = [MYObject sharedInstance];
+return obj.[[private^Field]];
+  }
+  )cpp",
+  [](HoverInfo &HI) {
+HI.Name = "privateField";
+HI.Kind = index::SymbolKind::InstanceProperty;
+HI.LocalScope = "MYObject(Private)::";
+HI.NamespaceScope = "";
+HI.Definition = "@property(nonatomic, assign, unsafe_unretained, "
+"readwrite) int privateField;";
+  }},
+  {
+  R"cpp(
+  @protocol MYProtocol
+  @property(nonatomic, assign) int prop1;
+  @end
+
+  int someFunction() {
+id obj = 0;
+return obj.[[pro^p1]];
+  }
+  )cpp",
+  [](HoverInfo &HI) {
+HI.Name = "prop1";
+HI.Kind = index::SymbolKind::InstanceProperty;
+HI.LocalScope = "MYProtocol::";
+HI.NamespaceScope = "";
+HI.Definition = "@property(nonatomic, assign, unsafe_unretained, "
+"readwrite) int prop1;";
+  }},
+  {R"objc(
+@interface Foo
+@end
+
+@implementation Foo(Private)
++ (int)somePrivateMethod {
+  int [[res^ult]] = 2;
+  return result;
+}
+@end
+)objc",
+   [](HoverInfo &HI) {
+ HI.Name = "result";
+ HI.Definition = "int result = 2";
+ HI.Kind = index::SymbolKind::Variable;
+ HI.Type = "int";
+ HI.LocalScope = "+[Foo(Private) somePrivateMethod]::";
+ HI.NamespaceScope = "";
+ HI.Value = "2";
+   }},
+  {R"objc(
+@interface Foo
+@end
+
+@implementation Foo
+- (int)variadicArgMethod:(id)first, ... {
+  int [[res^ult]] = 0;
+  return result;
+}
+@end
+)objc",
+   [](HoverInfo &HI) {
+ HI.Name = "result";
+ HI.Definition = "int result = 0";
+ HI.Kind = index::SymbolKind::Variable;
+ HI.Type = "int";
+ HI.LocalScope = "-[Foo variadicArgMethod:, ...]::";
+ HI.NamespaceScope = "";
+ HI.Value = "0";
+   }},
   };
 
   // Create a tiny index, so tests above can verify documentation is fetched.
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -22,6 +22,7 @@
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
 #include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclObjC.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
@@ -64,6 +65,15 @@
 std::string getLocalScope(const Decl *D) {
   std::vector Scopes;
   const DeclContext *DC = D->getDeclContext();
+
+  // ObjC scopes won't have multiple components for us to join, instead:
+  // - Methods: "-[Class methodParam1:methodParam2]"
+  // - Classes, categories, and protocols: "MyClass(Category)"
+  if (const ObjCMethodDecl *MD = dyn_cast(DC))
+return printObjCMethod(*MD);
+  else if (const ObjCContainerDecl *CD = dyn_cast(DC))
+return printObjCContainer(*CD);
+
   auto GetName = [](const TypeDecl *D) {
 if (!D->getDeclName().isEmpty()) {
   PrintingPolicy Policy = D->getASTContext().getPrintingPolicy();
@@ -90,6 +100,11 @@
 std::string getNamespaceScope(const Decl *D) {
   const DeclContext *DC = D->getDeclContext();
 
+  // ObjC does not have the concept of namespaces, so instead we support
+  // local scopes.
+  if (isa(DC))
+retu

[clang-tools-extra] 07c5a80 - Improve hover scopes for Objective-C code

2021-02-12 Thread David Goldman via cfe-commits

Author: David Goldman
Date: 2021-02-12T10:27:32-05:00
New Revision: 07c5a800dc1769f3f684d4a864f3903ac9ffa9f3

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

LOG: Improve hover scopes for Objective-C code

- Instead of `AppDelegate::application:didFinishLaunchingWithOptions:` you
will now see `-[AppDelegate application:didFinishLaunchingWithOptions:]`

- Also include categories in the name when printing the scopes, e.g. 
`Class(Category)` and `-[Class(Category) method]`

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

Added: 


Modified: 
clang-tools-extra/clangd/AST.cpp
clang-tools-extra/clangd/AST.h
clang-tools-extra/clangd/Hover.cpp
clang-tools-extra/clangd/unittests/HoverTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/AST.cpp 
b/clang-tools-extra/clangd/AST.cpp
index aecaf7e6b8f7..abcfc1af848b 100644
--- a/clang-tools-extra/clangd/AST.cpp
+++ b/clang-tools-extra/clangd/AST.cpp
@@ -283,6 +283,52 @@ std::string printNamespaceScope(const DeclContext &DC) {
   return "";
 }
 
+static llvm::StringRef
+getNameOrErrForObjCInterface(const ObjCInterfaceDecl *ID) {
+  return ID ? ID->getName() : "<>";
+}
+
+std::string printObjCMethod(const ObjCMethodDecl &Method) {
+  std::string Name;
+  llvm::raw_string_ostream OS(Name);
+
+  OS << (Method.isInstanceMethod() ? '-' : '+') << '[';
+
+  // Should always be true.
+  if (const ObjCContainerDecl *C =
+  dyn_cast(Method.getDeclContext()))
+OS << printObjCContainer(*C);
+
+  Method.getSelector().print(OS << ' ');
+  if (Method.isVariadic())
+OS << ", ...";
+
+  OS << ']';
+  OS.flush();
+  return Name;
+}
+
+std::string printObjCContainer(const ObjCContainerDecl &C) {
+  if (const ObjCCategoryDecl *Category = dyn_cast(&C)) {
+std::string Name;
+llvm::raw_string_ostream OS(Name);
+const ObjCInterfaceDecl *Class = Category->getClassInterface();
+OS << getNameOrErrForObjCInterface(Class) << '(' << Category->getName()
+   << ')';
+OS.flush();
+return Name;
+  }
+  if (const ObjCCategoryImplDecl *CID = dyn_cast(&C)) {
+std::string Name;
+llvm::raw_string_ostream OS(Name);
+const ObjCInterfaceDecl *Class = CID->getClassInterface();
+OS << getNameOrErrForObjCInterface(Class) << '(' << CID->getName() << ')';
+OS.flush();
+return Name;
+  }
+  return C.getNameAsString();
+}
+
 SymbolID getSymbolID(const Decl *D) {
   llvm::SmallString<128> USR;
   if (index::generateUSRForDecl(D, USR))

diff  --git a/clang-tools-extra/clangd/AST.h b/clang-tools-extra/clangd/AST.h
index b603964189e8..94984a915422 100644
--- a/clang-tools-extra/clangd/AST.h
+++ b/clang-tools-extra/clangd/AST.h
@@ -15,6 +15,7 @@
 
 #include "index/SymbolID.h"
 #include "clang/AST/Decl.h"
+#include "clang/AST/DeclObjC.h"
 #include "clang/AST/NestedNameSpecifier.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Lex/MacroInfo.h"
@@ -64,6 +65,14 @@ std::string printName(const ASTContext &Ctx, const NamedDecl 
&ND);
 /// string if decl is not a template specialization.
 std::string printTemplateSpecializationArgs(const NamedDecl &ND);
 
+/// Print the Objective-C method name, including the full container name, e.g.
+/// `-[MyClass(Category) method:]`
+std::string printObjCMethod(const ObjCMethodDecl &Method);
+
+/// Print the Objective-C container name including categories, e.g. `MyClass`,
+// `MyClass()`, `MyClass(Category)`, and `MyProtocol`.
+std::string printObjCContainer(const ObjCContainerDecl &C);
+
 /// Gets the symbol ID for a declaration. Returned SymbolID might be null.
 SymbolID getSymbolID(const Decl *D);
 

diff  --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index 6d707c8d1521..42acebd7f293 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -22,6 +22,7 @@
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
 #include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclObjC.h"
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
@@ -64,6 +65,15 @@ PrintingPolicy getPrintingPolicy(PrintingPolicy Base) {
 std::string getLocalScope(const Decl *D) {
   std::vector Scopes;
   const DeclContext *DC = D->getDeclContext();
+
+  // ObjC scopes won't have multiple components for us to join, instead:
+  // - Methods: "-[Class methodParam1:methodParam2]"
+  // - Classes, categories, and protocols: "MyClass(Category)"
+  if (const ObjCMethodDecl *MD = dyn_cast(DC))
+return printObjCMethod(*MD);
+  else if (const ObjCContainerDecl *CD = dyn_cast(DC))
+return printObjCContainer(*CD);
+
   auto GetName = [](const TypeDecl *D) {
 if (!D->getDeclName().isEmpty()) {
   PrintingPolicy Policy = D->getASTContext().getPrintingPolicy();
@@ -90,6 +

[clang] 053e61d - Relands "[HIP] Change default --gpu-max-threads-per-block value to 1024"

2021-02-12 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2021-02-12T10:53:59-05:00
New Revision: 053e61d54e63810b005adacf5e73a6465ca24bd2

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

LOG: Relands "[HIP] Change default --gpu-max-threads-per-block value to 1024"

This reverts commit e384e94fbe7c1d5c89fcdde33ffda04e9802c2ce.

Added: 


Modified: 
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/TargetInfo.cpp
clang/test/CodeGenCUDA/amdgpu-kernel-attrs.cu
clang/test/CodeGenCUDA/kernel-amdgcn.cu

Removed: 




diff  --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 1a9f8048bc17..e24408985dec 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -242,7 +242,7 @@ LANGOPT(CUDAHostDeviceConstexpr, 1, 1, "treating 
unattributed constexpr function
 LANGOPT(CUDADeviceApproxTranscendentals, 1, 0, "using approximate 
transcendental functions")
 LANGOPT(GPURelocatableDeviceCode, 1, 0, "generate relocatable device code")
 LANGOPT(GPUAllowDeviceInit, 1, 0, "allowing device side global init functions 
for HIP")
-LANGOPT(GPUMaxThreadsPerBlock, 32, 256, "default max threads per block for 
kernel launch bounds for HIP")
+LANGOPT(GPUMaxThreadsPerBlock, 32, 1024, "default max threads per block for 
kernel launch bounds for HIP")
 LANGOPT(GPUDeferDiag, 1, 0, "defer host/device related diagnostic messages for 
CUDA/HIP")
 LANGOPT(GPUExcludeWrongSideOverloads, 1, 0, "always exclude wrong side 
overloads in overloading resolution for CUDA/HIP")
 

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index bcb9916a4abd..5228396ebcd9 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -925,7 +925,7 @@ defm gpu_exclude_wrong_side_overloads : 
BoolFOption<"gpu-exclude-wrong-side-over
 def gpu_max_threads_per_block_EQ : Joined<["--"], 
"gpu-max-threads-per-block=">,
   Flags<[CC1Option]>,
   HelpText<"Default max threads per block for kernel launch bounds for HIP">,
-  MarshallingInfoStringInt, "256">,
+  MarshallingInfoStringInt, "1024">,
   ShouldParseIf;
 def gpu_instrument_lib_EQ : Joined<["--"], "gpu-instrument-lib=">,
   HelpText<"Instrument device library for HIP, which is a LLVM bitcode 
containing "

diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index bcd24292ff41..d42541282aea 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -8998,9 +8998,13 @@ void AMDGPUTargetCodeGenInfo::setTargetAttributes(
   assert(Max == 0 && "Max must be zero");
   } else if (IsOpenCLKernel || IsHIPKernel) {
 // By default, restrict the maximum size to a value specified by
-// --gpu-max-threads-per-block=n or its default value.
+// --gpu-max-threads-per-block=n or its default value for HIP.
+const unsigned OpenCLDefaultMaxWorkGroupSize = 256;
+const unsigned DefaultMaxWorkGroupSize =
+IsOpenCLKernel ? OpenCLDefaultMaxWorkGroupSize
+   : M.getLangOpts().GPUMaxThreadsPerBlock;
 std::string AttrVal =
-std::string("1,") + 
llvm::utostr(M.getLangOpts().GPUMaxThreadsPerBlock);
+std::string("1,") + llvm::utostr(DefaultMaxWorkGroupSize);
 F->addFnAttr("amdgpu-flat-work-group-size", AttrVal);
   }
 

diff  --git a/clang/test/CodeGenCUDA/amdgpu-kernel-attrs.cu 
b/clang/test/CodeGenCUDA/amdgpu-kernel-attrs.cu
index a1d62e30dcb0..3e602b1c7655 100644
--- a/clang/test/CodeGenCUDA/amdgpu-kernel-attrs.cu
+++ b/clang/test/CodeGenCUDA/amdgpu-kernel-attrs.cu
@@ -39,7 +39,7 @@ __global__ void num_vgpr_64() {
 // NAMD-NOT: "amdgpu-num-vgpr"
 // NAMD-NOT: "amdgpu-num-sgpr"
 
-// DEFAULT-DAG: attributes [[FLAT_WORK_GROUP_SIZE_DEFAULT]] = 
{{.*}}"amdgpu-flat-work-group-size"="1,256"{{.*}}"uniform-work-group-size"="true"
+// DEFAULT-DAG: attributes [[FLAT_WORK_GROUP_SIZE_DEFAULT]] = 
{{.*}}"amdgpu-flat-work-group-size"="1,1024"{{.*}}"uniform-work-group-size"="true"
 // MAX1024-DAG: attributes [[FLAT_WORK_GROUP_SIZE_DEFAULT]] = 
{{.*}}"amdgpu-flat-work-group-size"="1,1024"
 // CHECK-DAG: attributes [[FLAT_WORK_GROUP_SIZE_32_64]] = 
{{.*}}"amdgpu-flat-work-group-size"="32,64"
 // CHECK-DAG: attributes [[WAVES_PER_EU_2]] = {{.*}}"amdgpu-waves-per-eu"="2"

diff  --git a/clang/test/CodeGenCUDA/kernel-amdgcn.cu 
b/clang/test/CodeGenCUDA/kernel-amdgcn.cu
index 5f48a9ecb82f..48473b92ccff 100644
--- a/clang/test/CodeGenCUDA/kernel-amdgcn.cu
+++ b/clang/test/CodeGenCUDA/kernel-amdgcn.cu
@@ -39,4 +39,4 @@ int main() {
   launch((void*)D.Empty());
   return 0;
 }
-// CHECK: attributes #[[ATTR]] = {{.*}}"amdgpu-flat-work-group-size"="1,256"
+// CHECK: attributes #[[ATTR]] = {{.*}}"amdg

[PATCH] D96508: [clangd] Retire clang-tidy-checks flag.

2021-02-12 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

In D96508#2559936 , @sammccall wrote:

> I think we should have the config mechanism available for one release cycle 
> before removing the old one.
>
> So I think it's fine to retire the flag but we shouldn't pick this into the 
> 12  release branch.

I definitely agree this retiring should be for the next release cycle, I didn't 
think we should try and cherry pick this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96508

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


[PATCH] D96204: [clangd] Fix clang tidy provider when multiple config files exist in directory tree

2021-02-12 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

@sammccall I meant to ping this one sorry.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96204

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


[PATCH] D90851: [clang-tidy] Extending bugprone-signal-handler with POSIX functions.

2021-02-12 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 323340.
balazske added a comment.

Changed definition of size_t in test header.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90851

Files:
  clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.h
  clang-tools-extra/docs/clang-tidy/checks/bugprone-signal-handler.rst
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/signal.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/stdlib.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/string.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/system-other.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/unistd.h
  clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler-minimal.c
  clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler-posix.c
  clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler.c

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler.c
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler.c
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler.c
@@ -1,8 +1,9 @@
-// RUN: %check_clang_tidy %s cert-sig30-c %t -- -- -isystem %S/Inputs/Headers
+// RUN: %check_clang_tidy %s bugprone-signal-handler %t -- -- -isystem %S/Inputs/Headers
 
 #include "signal.h"
-#include "stdio.h"
 #include "stdlib.h"
+#include "stdio.h"
+#include "system-other.h"
 
 // The function should be classified as system call even if there is
 // declaration the in source file.
@@ -16,17 +17,9 @@
   abort();
 }
 
-void handler__Exit(int) {
-  _Exit(0);
-}
-
-void handler_quick_exit(int) {
-  quick_exit(0);
-}
-
 void handler_other(int) {
   printf("1234");
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [cert-sig30-c]
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
 }
 
 void handler_signal(int) {
@@ -40,7 +33,7 @@
 
 void f_bad() {
   printf("1234");
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [cert-sig30-c]
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
 }
 
 void f_extern();
@@ -55,13 +48,11 @@
 
 void handler_extern(int) {
   f_extern();
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'f_extern' may not be asynchronous-safe; calling it from a signal handler may be dangerous [cert-sig30-c]
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'f_extern' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
 }
 
 void test() {
   signal(SIGINT, handler_abort);
-  signal(SIGINT, handler__Exit);
-  signal(SIGINT, handler_quick_exit);
   signal(SIGINT, handler_signal);
   signal(SIGINT, handler_other);
 
@@ -69,9 +60,9 @@
   signal(SIGINT, handler_bad);
   signal(SIGINT, handler_extern);
 
-  signal(SIGINT, quick_exit);
+  signal(SIGINT, _Exit);
   signal(SIGINT, other_call);
-  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'other_call' may not be asynchronous-safe; calling it from a signal handler may be dangerous [cert-sig30-c]
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'other_call' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
 
   signal(SIGINT, SIG_IGN);
   signal(SIGINT, SIG_DFL);
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler-posix.c
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler-posix.c
@@ -0,0 +1,29 @@
+// RUN: %check_clang_tidy %s bugprone-signal-handler %t \
+// RUN: -config='{CheckOptions: \
+// RUN:  [{key: bugprone-signal-handler.AsyncSafeFunctionSet, value: "POSIX"}]}' \
+// RUN: -- -isystem %S/Inputs/Headers
+
+#include "signal.h"
+#include "stdlib.h"
+#include "stdio.h"
+#include "string.h"
+#include "unistd.h"
+
+void handler_bad(int) {
+  printf("1234");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'printf' may not be asynchronous-safe; calling it from a signal handler may be dangerous [bugprone-signal-handler]
+}
+
+void handler_good(int) {
+  abort();
+  _Exit(0);
+  _exit(0);
+  quick_exit(0);
+  signal(0, SIG_DFL);
+  memcpy((void*)10, (const void*)20, 1);
+}
+
+void test() {
+  signal(SIGINT, handler_good);
+  signal(SIGINT, handler_bad);
+}
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-signal-handler-minimal.c
===
--- /dev/null
+++ clang-too

[PATCH] D96138: [clang-tidy] Simplify delete null ptr check

2021-02-12 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

Seems that your test cases are failing on windows, I'm guessing this is a MSVC 
template compatibility issue. 
Probably need to add `-fno-delayed-template-parsing` to the clang driver args 
(after `-- --`).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96138

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


[PATCH] D96139: [clang-tidy] Simplify inaccurate erase check

2021-02-12 Thread Nathan James via Phabricator via cfe-commits
njames93 accepted this revision.
njames93 added a comment.
This revision is now accepted and ready to land.

LG with nit.




Comment at: clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.cpp:25-27
+  1, anyOf(cxxMemberCallExpr(callee(cxxMethodDecl(hasName("end"
+   .bind("end"),
+   anything(

This seems like a use case for the optionally matcher.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96139

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


[clang-tools-extra] 33f35a4 - [clang-tidy] Fix `TransformerClangTidyCheck`'s handling of include insertions.

2021-02-12 Thread Yitzhak Mandelbaum via cfe-commits

Author: Yitzhak Mandelbaum
Date: 2021-02-12T16:23:53Z
New Revision: 33f35a4b793bb53b830f8893110af57672e1dc79

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

LOG: [clang-tidy] Fix `TransformerClangTidyCheck`'s handling of include 
insertions.

Currently, all include insertions are directed to the main file. However,
Transformer rules can specify alternative destinations for include
insertions. This patch fixes the code to associate the include with the correct
file.

This patch was tested manually. The clang tidy unit test framework does not
support testing changes to header files. Given that this is a bug fix for a live
bug, the patch relies on manual testing rather than blocking on upgrading the
unit test framework.

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp 
b/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
index e93f3fbf21d7..9f64c562600b 100644
--- a/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
@@ -104,7 +104,8 @@ void TransformerClangTidyCheck::check(
   Diag << FixItHint::CreateReplacement(T.Range, T.Replacement);
   break;
 case transformer::EditKind::AddInclude:
-  Diag << Inserter.createMainFileIncludeInsertion(T.Replacement);
+  Diag << Inserter.createIncludeInsertion(
+  Result.SourceManager->getFileID(T.Range.getBegin()), T.Replacement);
   break;
 }
 }



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


[PATCH] D96542: [clang-tidy] Fix `TransformerClangTidyCheck`'s handling of include insertions.

2021-02-12 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG33f35a4b793b: [clang-tidy] Fix 
`TransformerClangTidyCheck`'s handling of include insertions. (authored by 
ymandel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96542

Files:
  clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp


Index: clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
===
--- clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
+++ clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
@@ -104,7 +104,8 @@
   Diag << FixItHint::CreateReplacement(T.Range, T.Replacement);
   break;
 case transformer::EditKind::AddInclude:
-  Diag << Inserter.createMainFileIncludeInsertion(T.Replacement);
+  Diag << Inserter.createIncludeInsertion(
+  Result.SourceManager->getFileID(T.Range.getBegin()), T.Replacement);
   break;
 }
 }


Index: clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
===
--- clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
+++ clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
@@ -104,7 +104,8 @@
   Diag << FixItHint::CreateReplacement(T.Range, T.Replacement);
   break;
 case transformer::EditKind::AddInclude:
-  Diag << Inserter.createMainFileIncludeInsertion(T.Replacement);
+  Diag << Inserter.createIncludeInsertion(
+  Result.SourceManager->getFileID(T.Range.getBegin()), T.Replacement);
   break;
 }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87519: [analyzer][Liveness][NFC] Enqueue the CFGBlocks post-order

2021-02-12 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

I don't insist on this patch, though I will end up removing the FIXME even if I 
leave the actual code unchanged, as it seems to be outdated.




Comment at: clang/lib/Analysis/LiveVariables.cpp:522
 
-  // FIXME: we should enqueue using post order.
-  for (const CFGBlock *B : cfg->nodes()) {
+  for (const CFGBlock *B : *AC.getAnalysis()) {
 worklist.enqueueBlock(B);

baloghadamsoftware wrote:
> martong wrote:
> > xazax.hun wrote:
> > > With `BackwardDataflowWorklist`, each  `enqueueBlock` will insert the 
> > > block into a `llvm::PriorityQueue`. So regardless of the insertion order, 
> > > `dequeue` will return the nodes in the reverse post order. 
> > > 
> > > Inserting elements in the right order into the heap might be beneficial 
> > > is we need to to less work to "heapify". But on the other hand, we did 
> > > more work to insert them in the right order, in the first place. All in 
> > > all, I am not sure whether the comment is still valid and whether this 
> > > patch would provide any benefit over the original code. 
> > > 
> > Yes, what Gabor says makes sense. On the other hand I don't see any 
> > overhead - I might be wrong though - in the post order visitation. And it 
> > makes the code more consistent IMHO.
> > 
> > Well, it would be important to know why the original author put the 
> > ```
> > // FIXME: we should enqueue using post order.
> > ```
> > there. The blamed commit 77ff930fff15c3fc76101b38199dad355be0866b is not 
> > saying much.
> Please compare the execution time with and without this patch. I think it is 
> difficult do decide in theory which one costs more: the heapification during 
> insertion or the reverse ordering before the insertion.
I think the performance hit, given that there is any, must be negligible. 

On the project [[ https://github.com/rswier/c4 | c4 ]], a tiny C compiler 
written in 4 large functions, the current liveness analysis runtimes on my 
machine in debug mode look like this:

Liveness analysis on next: 7.397604e-03s
Liveness analysis on expr: 1.203549e-02s
Liveness analysis on stmt: 5.470070e-04s
Liveness analysis on main: 1.344798e-02s
Liveness analysis on main: 1.415095e-02s
Liveness analysis on stmt: 5.550660e-04s
Liveness analysis on expr: 1.197334e-02s
Liveness analysis on next: 7.181059e-03s

After this patch, they look like this:

Liveness analysis on next: 7.313751e-03s
Liveness analysis on expr: 1.211920e-02s
Liveness analysis on stmt: 5.582670e-04s
Liveness analysis on main: 1.372210e-02s
Liveness analysis on main: 1.437104e-02s
Liveness analysis on stmt: 5.685340e-04s
Liveness analysis on expr: 1.269498e-02s
Liveness analysis on next: 7.094738e-03s

Mind that this measured the entire analysis, not just enqueuing. I think its 
fair to say that even on relatively large functions, the difference is within 
the margin of error, and is most definitely incomparable to its only user's 
runtime, the static analyzer itself.

> Well, it would be important to know why the original author put the [TODO] 
> there.

Yep, I think its just an outdated comment.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87519

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


[PATCH] D96407: [flang][driver] Add extension options and -finput-charset

2021-02-12 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

Thank you for submitting this @FarisRehman !

Overall this looks good to me. I've left a few minor comments inline. Also, I 
think that it is worth adding a help message for `-finput-charset`. Lack of it 
in `clang` feels like an accidental omission. We can follow GCC here:

  $ gcc --help=joined | grep input-charset
-finput-charset=  Specify the default character set for source 
files.




Comment at: flang/test/Flang-Driver/implicit-none.f90:9
+! RUN: %flang-new -fsyntax-only %s  2>&1 | FileCheck %s --allow-empty 
--check-prefix=DEFAULT
+! RUN: not %flang-new -fsyntax-only -fimplicit-none %s  2>&1 | FileCheck %s 
--check-prefix=ALWAYS
+! RUN: %flang-new -fsyntax-only -fno-implicit-none %s  2>&1 | FileCheck %s 
--allow-empty --check-prefix=DEFAULT

[nit] `ALWAYS` is a bit unclear to me. Perhaps `WITH_IMPL_NONE`?



Comment at: flang/test/Flang-Driver/implicit-none.f90:10
+! RUN: not %flang-new -fsyntax-only -fimplicit-none %s  2>&1 | FileCheck %s 
--check-prefix=ALWAYS
+! RUN: %flang-new -fsyntax-only -fno-implicit-none %s  2>&1 | FileCheck %s 
--allow-empty --check-prefix=DEFAULT
+

What about:
```
! RUN: %flang-new -fsyntax-only %s  2>&1 | FileCheck %s --allow-empty 
--check-prefix=DEFAULT
```
and:
```
! RUN: %flang-new -fimplicit-none -fno-implicit-none -fsyntax-only %s  2>&1 | 
FileCheck %s --allow-empty --check-prefix=DEFAULT
```

Similar point for other tests.



Comment at: flang/test/Flang-Driver/implicit-none.f90:28-29
+! ALWAYS:No explicit type declared for 'a'
+! ALWAYS-NEXT:function a()
+! ALWAYS-NEXT:^
+! ALWAYS-NEXT:No explicit type declared for 'b'

[nit] This particular output might change in the future, which could make this 
test a bit fragile. I also think that it's not key here (IIUC, lines 27 and 30 
are). Perhaps we could skip these?



Comment at: flang/test/Flang-Driver/input-charset.f90:1-14
+! Ensure argument -finput-charset is forwarded to the frontend.
+
+! REQUIRES: new-flang-driver
+
+!--
+! FLANG DRIVER (flang-new)
+!--

Could this be merged with `pipeline.f90` from https://reviews.llvm.org/D96344? 
(btw, IMHO it is worth renaming that file) 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96407

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


[PATCH] D96223: [clang-tidy] Simplify static assert check

2021-02-12 Thread Nathan James via Phabricator via cfe-commits
njames93 accepted this revision.
njames93 added a comment.
This revision is now accepted and ready to land.

LG with a few nits.




Comment at: clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp:49-51
+  expr(anyOf(expr(anyOf(AssertExprRoot,
+unaryOperator(hasUnaryOperand(AssertExprRoot,
+ anything()),

Can this be cleaned up to use `optionally` matcher.



Comment at: clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp:60-63
   Finder->addMatcher(
-  ifStmt(hasCondition(Condition), unless(isInTemplateInstantiation()))
-  .bind("condStmt"),
-  this);
+  conditionalOperator(hasCondition(Condition)).bind("condStmt"), this);
+
+  Finder->addMatcher(ifStmt(hasCondition(Condition)).bind("condStmt"), this);

Can't you use the `mapAnyOf` matcher here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96223

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


[PATCH] D93110: [analyzer] Implement fine-grained suppressions via attributes

2021-02-12 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added a comment.

In D93110#2534690 , @aaron.ballman 
wrote:

> In D93110#2529917 , @NoQ wrote:
>
>>> What I want to avoid is having a static analyzer-specific suppression 
>>> attribute, and a different one for clang-tidy, and a third one for the 
>>> frontend.
>>
>> Given that there are already multiple suppression mechanisms circulating 
>> around (clang-tidy's `// NOLINT`, frontend pragmas, static analyzer's 
>> `#ifdef __clang_analyzer__`, now also attribute), i guess a path forward 
>> would be to eventually add support for multiple mechanisms everywhere.  This 
>> may be tedious to implement but benefits may be well worth it. Consistency 
>> across tools is important when tools are used together; for instance, when 
>> clang-tidy integrates static analyzer, static analyzer automatically starts 
>> supporting `// NOLINT` through clang-tidy's diagnostic consumer magic. This 
>> would also be amazing for discoverability: users can keep using their 
>> preferred mechanism and it'd just work out of the box when they add a new 
>> tool to their arsenal.
>
> To be clear, I'm fine with multiple mechanisms, but not fine with multiple of 
> the same mechanisms. e.g., I don't think it's an issue that we can suppress 
> via the command line, pragmas, NOLINT comments, and attribute usage, but I do 
> think it's a problem if there's one attribute used by clang-tidy and a 
> different attribute used by the static analyzer, and a third attribute for 
> clang itself. Using different attributes causes users to have to consider 
> what basically amount to implementation details of their toolchain and makes 
> it harder to do things like integrate clang-tidy and the clang static 
> analyzer together.

We can integrate these solutions together for clang-tidy and for clang static 
analyzer, it's not a problem at all.  I would've used the existing Suppress 
attribute if it was without `gsl` part.  As I mentioned in the summary, at the 
moment, we want to use it ONLY inside functions.  I can see that `SuppressAttr` 
is not used anywhere in the whole, but I can't be sure that it's not used 
somewhere externally.  So, I couldn't just reduce the scope of it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93110

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


[PATCH] D92290: [clangd] Factor out the heuristic resolver code into its own class

2021-02-12 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Sorry for the looong delay getting back to this :-\

I do think this should be nullable (and const-friendly) but otherwise this is 
good to land.




Comment at: clang-tools-extra/clangd/HeuristicResolver.h:73
+  std::vector
+  resolveDependentMember(const Type *T, DeclarationName NameFactory,
+ llvm::function_ref Filter);

nit: NameFactory is a weird name now



Comment at: clang-tools-extra/clangd/HeuristicResolver.h:60
+  // or more declarations that it likely references.
+  std::vector resolveExprToDecls(const Expr *E);
+

nridge wrote:
> sammccall wrote:
> > This is pretty vaguely defined. From reading the implementation, this can 
> > choose to return two things:
> > 
> > 1. a ValueDecl representing the value of E
> > 2. a TypeDecl representing the type of E
> > 
> > Case 1 is used by heuristic go-to-def, which never hits case 2 because it 
> > only passes certain kinds of E.
> > Case 1+2 are used internally by the heuristic resolver to resolve base 
> > types, and are unified by resolveDeclsToType which handles them as two 
> > cases.
> > 
> > This doesn't seem like a clean public API :-) It also seems to lead to some 
> > convolution internally.
> > 
> > --- 
> > 
> > I think we should distribute the work of this function into a few smaller 
> > functions with couple of flavors.
> > 
> > Some that deal with specific node types, extracted from resolveExprToDecls:
> >  - `Decl* memberExprTarget(CXXDependentMemberExpr*)`. Uses exprToType (for 
> > the base type), pointee (for arrow exprs), resolveDependentMember (the 
> > final lookup).
> >  - `Type* callExprType(CallExpr*)`. Uses exprToType (for the callee type).
> >  - `Decl* declRefExprTarget(DependentScopeDeclRefExpr*)` - this is 
> > currently a trivial wrapper for resolveDependentMember.
> > 
> > And some that are more generic building blocks:
> >  - `Type* exprType(Expr*)`, which tries to handle any expr, dispatching to 
> > the node-specific function and falling back to Expr::getType().
> >  - `getPointeeType(Type*)` and `resolveDependentMember(...)` as now
> > 
> > It's not entirely clear what should be public vs private, but one idea I 
> > quite like is: all the node-specific methods are public, and all the 
> > building blocks are private.
> > - This would mean adding some more node-specific methods to cover the 
> > external callers of `resolveDependentMember`, but in each case I looked at 
> > this seems to make sense.
> >   (This neatly deals with the slightly grungy signature of 
> > resolveDependentMember by hiding it)
> > - it also mostly answers the question about contracts on non-dependent 
> > code: most non-dependent node types simply can't be passed in
> Thanks, you make some good points about this method being messy (and 
> particularly that we're duplicating some "resolve the type of a non-dependent 
> expression" logic, which has bothered me as well).
> 
> I like your proposed breakdown into smaller methods, and I partially 
> implemented it.
> 
> A couple of notes:
> 
>  * I had to keep the [MemberExpr 
> case](https://searchfox.org/llvm/rev/b3d7e761e347d562333893652dcf3837fa55d777/clang-tools-extra/clangd/FindTarget.cpp#218)
>  around. It could not be subsumed by `Expr::getType()`, because for a 
> `MemberExpr` that returns [this 
> thing](https://searchfox.org/llvm/rev/b3d7e761e347d562333893652dcf3837fa55d777/clang/include/clang/AST/BuiltinTypes.def#283),
>  while `getMemberDecl()->getType()` returns the function type of the member 
> function, and we want the latter (for [this call 
> site](https://searchfox.org/llvm/rev/b3d7e761e347d562333893652dcf3837fa55d777/clang-tools-extra/clangd/FindTarget.cpp#205)).
>  * We don't quite achieve "non-dependent node types simply can't be passed 
> in", because `resolveCallExpr()` can be called with a non-dependent call 
> expr. However, it currently has no external callers -- perhaps we should make 
> it private?
> 
> I left `resolveDependentMember()` public (and left its external callers 
> alone) for now. I can make it private and add additional public wrappers if 
> you'd like, but I'm wondering what the motivation is (especially as you've 
> described it as "a really nice example of a heuristic lookup with a clear 
> contract" :-)).
Those notes/caveats seem totally fine to me.

> resolveCallExpr ... perhaps we should make it private?
>  left resolveDependentMember() public ... I can make it private... I'm 
> wondering what the motivation is

I just think it's a little easier to understand how to use this class, and how 
to maintain/extend it, if the public methods form a consistent set with the 
same level of abstraction. Having all the public methods handle node types is 
tempting from this point of view.

I won't insist on this. We can inline the handling of UnusedUsingValueDecl into 
the caller as it happens to be simple, but I don't see a strong reason to do so.

[PATCH] D96204: [clangd] Fix clang tidy provider when multiple config files exist in directory tree

2021-02-12 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Sorry about dropping this (and others, i'm trying to get through them now)

Agree about cherrypicking this.

Regarding the extra test case... I'm not sure either. It's a nice test, but the 
conceptual dependency is annoying.
If it's simple enough, feel free to add it and we can remove if it causes 
problems.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96204

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


[PATCH] D96524: [OpenCL] Add support of OpenCL C 3.0 __opencl_c_fp64

2021-02-12 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:9899
 def err_opencl_requires_extension : Error<
-  "use of %select{type|declaration}0 %1 requires %2 extension to be enabled">;
+  "use of %select{type|declaration}0 %1 requires %2 
%select{extension|feature}3 to be enabled">;
 def warn_opencl_generic_address_space_arg : Warning<

We shouldn't require enabling the features besides features and extensions are 
conceptually the same, let's avoid adding too much complexity due to the 
unfortunate differences in the spec wording. 

I suggest changing this to something like:

```
use of %select{type|declaration}0 %1 requires %2 support
```


FYI I would also be happy if we don't guard the types by the pragma at all and 
just allow using the type freely if the extensions is supported. This already 
happens for the functions so it is not clear why functions and types should be 
different. The benefit of the pragma guarding hasn't been found after more than 
a year of investigations.



Comment at: clang/lib/Basic/OpenCLOptions.cpp:24
+  auto CLVer = LO.OpenCLCPlusPlus ? 200 : LO.OpenCLVersion;
+  return CLVer >= 300 ? isEnabled("__opencl_c_fp64") : 
isEnabled("cl_khr_fp64");
+}

We should at least be checking for `isSupported("__opencl_c_fp64")`, but 
frankly I would prefer to check for supported and not for enabled for 
`cl_khr_fp64` too. Note that we don't break backward compatibility if we change 
this because the existing kernels will still be valid and it makes things 
easier for writing new kernels too.



Comment at: clang/lib/Basic/TargetInfo.cpp:398
+auto CLVer = Opts.OpenCLCPlusPlus ? 200 : Opts.OpenCLVersion;
+if (CLVer >= 300) {
+  auto &OCLOpts = getSupportedOpenCLOpts();

I suggest we move this onto `OpenCLOptions::addSupport`.



Comment at: clang/lib/Headers/opencl-c.h:4635
 
-#ifdef cl_khr_fp64
+#if defined(cl_khr_fp64) || defined(__opencl_c_fp64)
 #pragma OPENCL EXTENSION cl_khr_fp64 : enable

svenvh wrote:
> Wondering if we need a similar change in `clang/lib/Headers/opencl-c-base.h` 
> to guard the double vector types?
Instead of growing the guard condition, I suggest we only check for one for 
example the feature macro and then make sure the feature macro is defined in 
`opencl-c-base.h` if the extensions that aliases to the feature is supported. 
However, it would also be ok to do the opposite since the extensions and the 
corresponding features should both be available.

FYI, something similar was done in https://reviews.llvm.org/D92004.

This will also help to propagate the functionality into Tablegen header because 
we won't need to extend it to work with multiple extensions but we might still 
need to do the rename.



Comment at: clang/lib/Sema/Sema.cpp:356
+  if (getLangOpts().OpenCLVersion >= 300)
+setOpenCLExtensionForType(AtomicDoubleT, "__opencl_c_fp64");
+  else

I think we should just guard

```
addImplicitTypedef("atomic_double", AtomicDoubleT);
```

by the feature support instead...

Or alternatively, we could also just change this entire diagnostic set up to 
check for extensions and features being supported and not enabled.

Frankly, I would prefer the first solution because this aligns with C/C++ 
concept. It is not possible for the compiler to know all possible types and 
functions that are added via the libraries so this diagnostic only worked for 
some cases (that are added to the compiler) but not all cases. However, I don't 
think we need to expose to the developer where and how features are 
implemented. This will avoid unnessasary questions - why in some cases they get 
one diagnostic and in the other case they get another diagnostic. It will allow 
us to change the implementation without the developers to notice. And 
considering that this doesn't break backward compatibility it is a pretty 
reasonable direction in my opinion.



Comment at: clang/test/SemaOpenCL/opencl-fp64-feature.cl:1
+// Test with a target not supporting fp64.
+// RUN: %clang_cc1 -cl-std=CL3.0 %s -triple r600-unknown-unknown -target-cpu 
r600 -verify -pedantic -fsyntax-only -DNOFP64

I suggest we merge this with `extensions.cl` that has similar functionality. As 
it mainly tests doubles I don't mind if you prefer to rename it then.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96524

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


[clang] fb4d8fe - [clang] Update mustprogress tests.

2021-02-12 Thread Florian Hahn via cfe-commits

Author: Florian Hahn
Date: 2021-02-12T16:53:51Z
New Revision: fb4d8fe807016fed221263d9a406e3856c8dfa4c

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

LOG: [clang] Update mustprogress tests.

This unifies the positive and negative tests in a single file and
manually adjusts the check lines to check for differences surgically.

Added: 
clang/test/CodeGen/attr-mustprogress.c
clang/test/CodeGenCXX/attr-mustprogress.cpp

Modified: 


Removed: 
clang/test/CodeGen/attr-mustprogress-0.c
clang/test/CodeGen/attr-mustprogress-0.cpp
clang/test/CodeGen/attr-mustprogress-1.c
clang/test/CodeGen/attr-mustprogress-1.cpp



diff  --git a/clang/test/CodeGen/attr-mustprogress-0.c 
b/clang/test/CodeGen/attr-mustprogress-0.c
deleted file mode 100644
index 2af24e88ceef..
--- a/clang/test/CodeGen/attr-mustprogress-0.c
+++ /dev/null
@@ -1,184 +0,0 @@
-// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --check-attributes
-// RUN: %clang_cc1 -std=c89 -triple=x86_64-unknown-linux-gnu -S -emit-llvm %s 
-o - | FileCheck %s
-// RUN: %clang_cc1 -std=c99 -triple=x86_64-unknown-linux-gnu -S -emit-llvm %s 
-o - | FileCheck %s
-
-int a = 0;
-int b = 0;
-
-// CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: @f1(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:br label [[FOR_COND:%.*]]
-// CHECK:   for.cond:
-// CHECK-NEXT:br i1 true, label [[FOR_BODY:%.*]], label [[FOR_END:%.*]]
-// CHECK:   for.body:
-// CHECK-NEXT:br label [[FOR_COND]]
-// CHECK:   for.end:
-// CHECK-NEXT:ret void
-//
-void f1() {
-  for (; 1;) {
-  }
-}
-
-// CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: @f2(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:br label [[FOR_COND:%.*]]
-// CHECK:   for.cond:
-// CHECK-NEXT:[[TMP0:%.*]] = load i32, i32* @a, align 4
-// CHECK-NEXT:[[TMP1:%.*]] = load i32, i32* @b, align 4
-// CHECK-NEXT:[[CMP:%.*]] = icmp eq i32 [[TMP0]], [[TMP1]]
-// CHECK-NEXT:br i1 [[CMP]], label [[FOR_BODY:%.*]], label [[FOR_END:%.*]]
-// CHECK:   for.body:
-// CHECK-NEXT:br label [[FOR_COND]]
-// CHECK:   for.end:
-// CHECK-NEXT:ret void
-//
-void f2() {
-  for (; a == b;) {
-  }
-}
-
-// CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: @F(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:br label [[FOR_COND:%.*]]
-// CHECK:   for.cond:
-// CHECK-NEXT:br i1 true, label [[FOR_BODY:%.*]], label [[FOR_END:%.*]]
-// CHECK:   for.body:
-// CHECK-NEXT:br label [[FOR_COND]]
-// CHECK:   for.end:
-// CHECK-NEXT:br label [[FOR_COND1:%.*]]
-// CHECK:   for.cond1:
-// CHECK-NEXT:[[TMP0:%.*]] = load i32, i32* @a, align 4
-// CHECK-NEXT:[[TMP1:%.*]] = load i32, i32* @b, align 4
-// CHECK-NEXT:[[CMP:%.*]] = icmp eq i32 [[TMP0]], [[TMP1]]
-// CHECK-NEXT:br i1 [[CMP]], label [[FOR_BODY2:%.*]], label 
[[FOR_END3:%.*]]
-// CHECK:   for.body2:
-// CHECK-NEXT:br label [[FOR_COND1]]
-// CHECK:   for.end3:
-// CHECK-NEXT:ret void
-//
-void F() {
-  for (; 1;) {
-  }
-  for (; a == b;) {
-  }
-}
-
-// CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: @w1(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:br label [[WHILE_BODY:%.*]]
-// CHECK:   while.body:
-// CHECK-NEXT:br label [[WHILE_BODY]]
-//
-void w1() {
-  while (1) {
-  }
-}
-
-// CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: @w2(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:br label [[WHILE_COND:%.*]]
-// CHECK:   while.cond:
-// CHECK-NEXT:[[TMP0:%.*]] = load i32, i32* @a, align 4
-// CHECK-NEXT:[[TMP1:%.*]] = load i32, i32* @b, align 4
-// CHECK-NEXT:[[CMP:%.*]] = icmp eq i32 [[TMP0]], [[TMP1]]
-// CHECK-NEXT:br i1 [[CMP]], label [[WHILE_BODY:%.*]], label 
[[WHILE_END:%.*]]
-// CHECK:   while.body:
-// CHECK-NEXT:br label [[WHILE_COND]]
-// CHECK:   while.end:
-// CHECK-NEXT:ret void
-//
-void w2() {
-  while (a == b) {
-  }
-}
-
-// CHECK: Function Attrs: noinline nounwind optnone
-// CHECK-LABEL: @W(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:br label [[WHILE_COND:%.*]]
-// CHECK:   while.cond:
-// CHECK-NEXT:[[TMP0:%.*]] = load i32, i32* @a, align 4
-// CHECK-NEXT:[[TMP1:%.*]] = load i32, i32* @b, align 4
-// CHECK-NEXT:[[CMP:%.*]] = icmp eq i32 [[TMP0]], [[TMP1]]
-// CHECK-NEXT:br i1 [[CMP]], label [[WHILE_BODY:%.*]], label 
[[WHILE_END:%.*]]
-// CHECK:   while.body:
-// CHECK-NEXT:br label [[WHILE_COND]]
-// CHECK:   while.end:
-// CHECK-NEXT:br label [[WHILE_BODY2:%.*]]
-// CHECK:   while.body2:
-// CHECK-NEXT:br label [[WHILE_BODY2]]
-//
-void W() {
-  while (a == b) {
-  }
-  while (1) {
-  }
-}
-
-// CHECK: Function Attrs: noinline nounwind optn

[PATCH] D96507: [clangd] Move command handlers into a map in ClangdLSPServer. NFC

2021-02-12 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Looks like this doesn't build on Windows: 
http://45.33.8.238/win/33161/step_4.txt (clang-cl + msvc stdlib)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96507

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


[PATCH] D96611: [analyzer][tests] Fix issue comparison script

2021-02-12 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko created this revision.
vsavchenko added a reviewer: NoQ.
Herald added subscribers: steakhal, ASDenysPetrov, Charusso, dkrupp, 
donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, 
xazax.hun.
vsavchenko requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

When newer build has duplicate issues the script tried to
remove it from the list more than once.  The new approach
changes the way we filter out matching issues.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96611

Files:
  clang/utils/analyzer/CmpRuns.py


Index: clang/utils/analyzer/CmpRuns.py
===
--- clang/utils/analyzer/CmpRuns.py
+++ clang/utils/analyzer/CmpRuns.py
@@ -36,7 +36,7 @@
 from copy import copy
 from enum import Enum
 from typing import (Any, DefaultDict, Dict, List, NamedTuple, Optional,
-Sequence, TextIO, TypeVar, Tuple, Union)
+Sequence, Set, TextIO, TypeVar, Tuple, Union)
 
 
 Number = Union[int, float]
@@ -374,8 +374,9 @@
 
 # Quadratic algorithms in this part are fine because 'old' and 'new'
 # are most commonly of size 1.
-for a in copy(old):
-for b in copy(new):
+common: Set[AnalysisDiagnostic] = set()
+for a in old:
+for b in new:
 if a.get_issue_identifier() == b.get_issue_identifier():
 a_path_len = a.get_path_length()
 b_path_len = b.get_path_length()
@@ -394,16 +395,22 @@
 path_difference_data.append(
 a_path_len - b_path_len)
 
-res.add_common(a)
-old.remove(a)
-new.remove(b)
+res.add_common(b)
+common.add(a)
+
+old = filter_issues(old, common)
+new = filter_issues(new, common)
+common = set()
 
-for a in copy(old):
-for b in copy(new):
+for a in old:
+for b in new:
 if a.is_similar_to(b):
 res.add_changed(a, b)
-old.remove(a)
-new.remove(b)
+common.add(a)
+common.add(b)
+
+old = filter_issues(old, common)
+new = filter_issues(new, common)
 
 # Whatever is left in 'old' doesn't have a corresponding diagnostic
 # in 'new', so we need to mark it as 'removed'.
@@ -443,6 +450,12 @@
 return res
 
 
+def filter_issues(origin: List[AnalysisDiagnostic],
+  to_remove: Set[AnalysisDiagnostic]) \
+  -> List[AnalysisDiagnostic]:
+return [diag for diag in origin if diag not in to_remove]
+
+
 def compute_percentile(values: Sequence[T], percentile: float) -> T:
 """
 Return computed percentile.


Index: clang/utils/analyzer/CmpRuns.py
===
--- clang/utils/analyzer/CmpRuns.py
+++ clang/utils/analyzer/CmpRuns.py
@@ -36,7 +36,7 @@
 from copy import copy
 from enum import Enum
 from typing import (Any, DefaultDict, Dict, List, NamedTuple, Optional,
-Sequence, TextIO, TypeVar, Tuple, Union)
+Sequence, Set, TextIO, TypeVar, Tuple, Union)
 
 
 Number = Union[int, float]
@@ -374,8 +374,9 @@
 
 # Quadratic algorithms in this part are fine because 'old' and 'new'
 # are most commonly of size 1.
-for a in copy(old):
-for b in copy(new):
+common: Set[AnalysisDiagnostic] = set()
+for a in old:
+for b in new:
 if a.get_issue_identifier() == b.get_issue_identifier():
 a_path_len = a.get_path_length()
 b_path_len = b.get_path_length()
@@ -394,16 +395,22 @@
 path_difference_data.append(
 a_path_len - b_path_len)
 
-res.add_common(a)
-old.remove(a)
-new.remove(b)
+res.add_common(b)
+common.add(a)
+
+old = filter_issues(old, common)
+new = filter_issues(new, common)
+common = set()
 
-for a in copy(old):
-for b in copy(new):
+for a in old:
+for b in new:
 if a.is_similar_to(b):
 res.add_changed(a, b)
-old.remove(a)
-new.remove(b)
+common.add(a)
+common.add(b)
+
+old = filter_issues(old, common)
+new = filter_issues(new, common)
 
 # Whatever is left in 'old' doesn't have a corresponding diagnostic
 # in 'new', so we need to mark it as 'removed'.
@@ -443,6 +450,12 @@
 return res
 
 
+def filter_issues(origin: List[AnalysisDiagnos

[clang-tools-extra] ba3ea9c - [clangd] Fix clang tidy provider when multiple config files exist in directory tree

2021-02-12 Thread Nathan James via cfe-commits

Author: Nathan James
Date: 2021-02-12T16:55:46Z
New Revision: ba3ea9c60f0f259f0ccc47e47daf8253a5885531

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

LOG: [clangd] Fix clang tidy provider when multiple config files exist in 
directory tree

Currently Clang tidy provider searches from the root directory up to the target 
directory, this is the opposite of how clang-tidy searches for config files.
The result of this is .clang-tidy files are ignored in any subdirectory of a 
directory containing a .clang-tidy file.

Reviewed By: sammccall

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

Added: 
clang-tools-extra/clangd/unittests/TidyProviderTests.cpp

Modified: 
clang-tools-extra/clangd/TidyProvider.cpp
clang-tools-extra/clangd/unittests/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/clangd/TidyProvider.cpp 
b/clang-tools-extra/clangd/TidyProvider.cpp
index c26c59fd347d..bcf1cd5a6183 100644
--- a/clang-tools-extra/clangd/TidyProvider.cpp
+++ b/clang-tools-extra/clangd/TidyProvider.cpp
@@ -106,7 +106,7 @@ class DotClangTidyTree {
 llvm::SmallVector Caches;
 {
   std::lock_guard Lock(Mu);
-  for (auto I = path::begin(Parent), E = path::end(Parent); I != E; ++I) {
+  for (auto I = path::rbegin(Parent), E = path::rend(Parent); I != E; ++I) 
{
 assert(I->end() >= Parent.begin() && I->end() <= Parent.end() &&
"Canonical path components should be substrings");
 llvm::StringRef Ancestor(Parent.begin(), I->end() - Parent.begin());

diff  --git a/clang-tools-extra/clangd/unittests/CMakeLists.txt 
b/clang-tools-extra/clangd/unittests/CMakeLists.txt
index adf4ac827cce..f4d364720eaf 100644
--- a/clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ b/clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -93,6 +93,7 @@ add_unittest(ClangdUnitTests ClangdTests
   TestIndex.cpp
   TestTU.cpp
   TestWorkspace.cpp
+  TidyProviderTests.cpp
   TypeHierarchyTests.cpp
   URITests.cpp
   XRefsTests.cpp

diff  --git a/clang-tools-extra/clangd/unittests/TidyProviderTests.cpp 
b/clang-tools-extra/clangd/unittests/TidyProviderTests.cpp
new file mode 100644
index ..a16c87456a1a
--- /dev/null
+++ b/clang-tools-extra/clangd/unittests/TidyProviderTests.cpp
@@ -0,0 +1,60 @@
+//===-- TidyProviderTests.cpp - Clang tidy configuration provider tests 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "TestFS.h"
+#include "TidyProvider.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace clangd {
+
+namespace {
+
+TEST(TidyProvider, NestedDirectories) {
+  MockFS FS;
+  FS.Files[testPath(".clang-tidy")] = R"yaml(
+  Checks: 'llvm-*'
+  CheckOptions:
+- key: TestKey
+  value: 1
+)yaml";
+  FS.Files[testPath("sub1/.clang-tidy")] = R"yaml(
+  Checks: 'misc-*'
+  CheckOptions:
+- key: TestKey
+  value: 2
+)yaml";
+  FS.Files[testPath("sub1/sub2/.clang-tidy")] = R"yaml(
+  Checks: 'bugprone-*'
+  CheckOptions:
+- key: TestKey
+  value: 3
+  InheritParentConfig: true
+)yaml";
+
+  TidyProvider Provider = provideClangTidyFiles(FS);
+
+  auto BaseOptions = getTidyOptionsForFile(Provider, testPath("File.cpp"));
+  ASSERT_TRUE(BaseOptions.Checks.hasValue());
+  EXPECT_EQ(*BaseOptions.Checks, "llvm-*");
+  EXPECT_EQ(BaseOptions.CheckOptions.lookup("TestKey").Value, "1");
+
+  auto Sub1Options = getTidyOptionsForFile(Provider, 
testPath("sub1/File.cpp"));
+  ASSERT_TRUE(Sub1Options.Checks.hasValue());
+  EXPECT_EQ(*Sub1Options.Checks, "misc-*");
+  EXPECT_EQ(Sub1Options.CheckOptions.lookup("TestKey").Value, "2");
+
+  auto Sub2Options =
+  getTidyOptionsForFile(Provider, testPath("sub1/sub2/File.cpp"));
+  ASSERT_TRUE(Sub2Options.Checks.hasValue());
+  EXPECT_EQ(*Sub2Options.Checks, "misc-*,bugprone-*");
+  EXPECT_EQ(Sub2Options.CheckOptions.lookup("TestKey").Value, "3");
+}
+} // namespace
+} // namespace clangd
+} // namespace clang



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


[PATCH] D96204: [clangd] Fix clang tidy provider when multiple config files exist in directory tree

2021-02-12 Thread Nathan James via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGba3ea9c60f0f: [clangd] Fix clang tidy provider when multiple 
config files exist in directory… (authored by njames93).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96204

Files:
  clang-tools-extra/clangd/TidyProvider.cpp
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/TidyProviderTests.cpp


Index: clang-tools-extra/clangd/unittests/TidyProviderTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/TidyProviderTests.cpp
@@ -0,0 +1,60 @@
+//===-- TidyProviderTests.cpp - Clang tidy configuration provider tests 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "TestFS.h"
+#include "TidyProvider.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace clangd {
+
+namespace {
+
+TEST(TidyProvider, NestedDirectories) {
+  MockFS FS;
+  FS.Files[testPath(".clang-tidy")] = R"yaml(
+  Checks: 'llvm-*'
+  CheckOptions:
+- key: TestKey
+  value: 1
+)yaml";
+  FS.Files[testPath("sub1/.clang-tidy")] = R"yaml(
+  Checks: 'misc-*'
+  CheckOptions:
+- key: TestKey
+  value: 2
+)yaml";
+  FS.Files[testPath("sub1/sub2/.clang-tidy")] = R"yaml(
+  Checks: 'bugprone-*'
+  CheckOptions:
+- key: TestKey
+  value: 3
+  InheritParentConfig: true
+)yaml";
+
+  TidyProvider Provider = provideClangTidyFiles(FS);
+
+  auto BaseOptions = getTidyOptionsForFile(Provider, testPath("File.cpp"));
+  ASSERT_TRUE(BaseOptions.Checks.hasValue());
+  EXPECT_EQ(*BaseOptions.Checks, "llvm-*");
+  EXPECT_EQ(BaseOptions.CheckOptions.lookup("TestKey").Value, "1");
+
+  auto Sub1Options = getTidyOptionsForFile(Provider, 
testPath("sub1/File.cpp"));
+  ASSERT_TRUE(Sub1Options.Checks.hasValue());
+  EXPECT_EQ(*Sub1Options.Checks, "misc-*");
+  EXPECT_EQ(Sub1Options.CheckOptions.lookup("TestKey").Value, "2");
+
+  auto Sub2Options =
+  getTidyOptionsForFile(Provider, testPath("sub1/sub2/File.cpp"));
+  ASSERT_TRUE(Sub2Options.Checks.hasValue());
+  EXPECT_EQ(*Sub2Options.Checks, "misc-*,bugprone-*");
+  EXPECT_EQ(Sub2Options.CheckOptions.lookup("TestKey").Value, "3");
+}
+} // namespace
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/unittests/CMakeLists.txt
===
--- clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -93,6 +93,7 @@
   TestIndex.cpp
   TestTU.cpp
   TestWorkspace.cpp
+  TidyProviderTests.cpp
   TypeHierarchyTests.cpp
   URITests.cpp
   XRefsTests.cpp
Index: clang-tools-extra/clangd/TidyProvider.cpp
===
--- clang-tools-extra/clangd/TidyProvider.cpp
+++ clang-tools-extra/clangd/TidyProvider.cpp
@@ -106,7 +106,7 @@
 llvm::SmallVector Caches;
 {
   std::lock_guard Lock(Mu);
-  for (auto I = path::begin(Parent), E = path::end(Parent); I != E; ++I) {
+  for (auto I = path::rbegin(Parent), E = path::rend(Parent); I != E; ++I) 
{
 assert(I->end() >= Parent.begin() && I->end() <= Parent.end() &&
"Canonical path components should be substrings");
 llvm::StringRef Ancestor(Parent.begin(), I->end() - Parent.begin());


Index: clang-tools-extra/clangd/unittests/TidyProviderTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/TidyProviderTests.cpp
@@ -0,0 +1,60 @@
+//===-- TidyProviderTests.cpp - Clang tidy configuration provider tests ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "TestFS.h"
+#include "TidyProvider.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace clangd {
+
+namespace {
+
+TEST(TidyProvider, NestedDirectories) {
+  MockFS FS;
+  FS.Files[testPath(".clang-tidy")] = R"yaml(
+  Checks: 'llvm-*'
+  CheckOptions:
+- key: TestKey
+  value: 1
+)yaml";
+  FS.Files[testPath("sub1/.clang-tidy")] = R"yaml(
+  Checks: 'misc-*'
+  CheckOptions:
+- key: TestKey
+  value: 2
+)yaml";
+  FS.Files[testPath("sub1/sub2/.clang-tidy")] = R"yaml(
+  Checks: 'bugprone-*'
+  CheckOptions:
+- key: TestKey
+  value: 3
+  InheritParentConfig: true
+)yaml";
+
+  TidyProvider Provider = provideClangTidyFiles(FS);
+
+  auto BaseOptions = getTidyO

[PATCH] D95561: [Clang] Introduce Swift async calling convention.

2021-02-12 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple added inline comments.



Comment at: clang/test/CodeGen/debug-info-cc.c:60-66
+// [FIXME: swiftasynccc] Update debuginfo tag to SwiftAsync once LLVM support 
lands.
+// LINUX: !DISubprogram({{.*}}"add_swiftasynccall", {{.*}}type: ![[FTY:[0-9]+]]
+// LINUX: ![[FTY]] = !DISubroutineType({{.*}}cc: DW_CC_LLVM_Swift,
+__attribute__((swiftasynccall)) int add_swiftasynccall(int a, int b) {
+  return a+b;
+}
+

This needs to be changed in some way, it triggers a test failure in its current 
state. https://github.com/apple/llvm-project/pull/2444


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95561

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


[PATCH] D96612: [clangd] Improve printing of Objective-C categories and methods

2021-02-12 Thread David Goldman via Phabricator via cfe-commits
dgoldman created this revision.
dgoldman added a reviewer: sammccall.
Herald added subscribers: usaxena95, kadircet, arphaman.
dgoldman requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang.

- Categories will now be printed as `MyClass(Category)` instead of `Category`

- Methods will now be printed as `-selector:` or `+selector:` instead of 
`selector:` to differentiate between instance and class methods

This is primarily noticable for DocumentSymbols


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96612

Files:
  clang-tools-extra/clangd/AST.cpp
  clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp


Index: clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
+++ clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
@@ -848,6 +848,39 @@
 SymRange(Main.range("forwardfunc");
 }
 
+TEST(DocumentSymbolsTest, ObjCCategoriesAndClassExtensions) {
+  TestTU TU;
+  TU.ExtraArgs = {"-xobjective-c++", "-Wno-objc-root-class"};
+  Annotations Main(R"cpp(
+  $Cat[[@interface Cat
+  @end]]
+  $SneakyCat[[@interface Cat (Sneaky)
+  - (id)sneak:(id)behavior;
+  @end]]
+
+  $MeowCat[[@interface Cat ()
+  - (void)meow;
+  @end]]
+  $PurCat[[@interface Cat ()
+  - (void)pur;
+  @end]]
+)cpp");
+  TU.Code = Main.code().str();
+  EXPECT_THAT(
+  getSymbols(TU.build()),
+  ElementsAre(
+  AllOf(WithName("Cat"), SymRange(Main.range("Cat"))),
+  AllOf(WithName("Cat(Sneaky)"), SymRange(Main.range("SneakyCat")),
+Children(
+AllOf(WithName("-sneak:"), WithKind(SymbolKind::Method,
+  AllOf(
+  WithName("Cat()"), SymRange(Main.range("MeowCat")),
+  Children(AllOf(WithName("-meow"), 
WithKind(SymbolKind::Method,
+  AllOf(WithName("Cat()"), SymRange(Main.range("PurCat")),
+Children(
+AllOf(WithName("-pur"), WithKind(SymbolKind::Method));
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/AST.cpp
===
--- clang-tools-extra/clangd/AST.cpp
+++ clang-tools-extra/clangd/AST.cpp
@@ -221,6 +221,14 @@
 return Out.str();
   }
 
+  if (const ObjCContainerDecl *C = dyn_cast(&ND))
+return printObjCContainer(*C);
+  if (const ObjCMethodDecl *Method = dyn_cast(&ND)) {
+Out << (Method->isInstanceMethod() ? '-' : '+');
+Method->getSelector().print(Out);
+return Out.str();
+  }
+
   if (isAnonymous(ND.getDeclName())) {
 // Come up with a presentation for an anonymous entity.
 if (isa(ND))


Index: clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
+++ clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
@@ -848,6 +848,39 @@
 SymRange(Main.range("forwardfunc");
 }
 
+TEST(DocumentSymbolsTest, ObjCCategoriesAndClassExtensions) {
+  TestTU TU;
+  TU.ExtraArgs = {"-xobjective-c++", "-Wno-objc-root-class"};
+  Annotations Main(R"cpp(
+  $Cat[[@interface Cat
+  @end]]
+  $SneakyCat[[@interface Cat (Sneaky)
+  - (id)sneak:(id)behavior;
+  @end]]
+
+  $MeowCat[[@interface Cat ()
+  - (void)meow;
+  @end]]
+  $PurCat[[@interface Cat ()
+  - (void)pur;
+  @end]]
+)cpp");
+  TU.Code = Main.code().str();
+  EXPECT_THAT(
+  getSymbols(TU.build()),
+  ElementsAre(
+  AllOf(WithName("Cat"), SymRange(Main.range("Cat"))),
+  AllOf(WithName("Cat(Sneaky)"), SymRange(Main.range("SneakyCat")),
+Children(
+AllOf(WithName("-sneak:"), WithKind(SymbolKind::Method,
+  AllOf(
+  WithName("Cat()"), SymRange(Main.range("MeowCat")),
+  Children(AllOf(WithName("-meow"), WithKind(SymbolKind::Method,
+  AllOf(WithName("Cat()"), SymRange(Main.range("PurCat")),
+Children(
+AllOf(WithName("-pur"), WithKind(SymbolKind::Method));
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/AST.cpp
===
--- clang-tools-extra/clangd/AST.cpp
+++ clang-tools-extra/clangd/AST.cpp
@@ -221,6 +221,14 @@
 return Out.str();
   }
 
+  if (const ObjCContainerDecl *C = dyn_cast(&ND))
+return printObjCContainer(*C);
+  if (const ObjCMethodDecl *Method = dyn_cast(&ND)) {
+Out << (Method->isInstanceMethod() ? '-' : '+');
+Method->getSelector().print(Out);
+return Out.str();
+  }
+
   if (isAnonymous(ND.getDeclName())) {
 // Come up with a presentation for an anonym

[clang-tools-extra] 8dd6dd9 - [clangd] Work around presumed MSVC stdlib bug

2021-02-12 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2021-02-12T18:00:43+01:00
New Revision: 8dd6dd947c148515bbd5fc06c0b5786148038750

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

LOG: [clangd] Work around presumed MSVC stdlib bug

http://45.33.8.238/win/33161/step_4.txt

Added: 


Modified: 
clang-tools-extra/clangd/ClangdLSPServer.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index 2aca82ee09d5..1d8efe6d84b7 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -586,7 +586,8 @@ void ClangdLSPServer::onInitialize(const InitializeParams 
&Params,
   CodeAction::INFO_KIND}}};
 
   std::vector Commands;
-  llvm::append_range(Commands, CommandHandlers.keys());
+  for (llvm::StringRef Command : CommandHandlers.keys())
+Commands.push_back(Command);
   llvm::sort(Commands);
 
   llvm::json::Object Result{



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


[PATCH] D96051: [OpenCL] Support enum and typedef args in TableGen BIFs

2021-02-12 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl:27
+  // expected-error@-3 0+{{no matching function for call to 'barrier'}}
+  // expected-error@* {{typedef type cl_mem_fence_flags not found; include the 
base header with -finclude-default-header}}
+}

Actually, could we remove the `typedef` from the diagnostic because it exposes 
the implementation details unnecessarily? I believe the spec doesn't say what 
the type is aside from enums?  As a matter of fact, we have some types 
implemented as typedefs that should have been a native types e.g. vector types 
that we might change one day.


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

https://reviews.llvm.org/D96051

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


[PATCH] D96090: [analyzer] Replace StoreManager::CastRetrievedVal with SValBuilder::evalCast

2021-02-12 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

@steakhal

> In the upcoming days, I'm gonna schedule this on our CI. We will see the 
> results.

Thank you. That would be great!


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

https://reviews.llvm.org/D96090

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


[PATCH] D96051: [OpenCL] Support enum and typedef args in TableGen BIFs

2021-02-12 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh added inline comments.



Comment at: clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl:27
+  // expected-error@-3 0+{{no matching function for call to 'barrier'}}
+  // expected-error@* {{typedef type cl_mem_fence_flags not found; include the 
base header with -finclude-default-header}}
+}

Anastasia wrote:
> Actually, could we remove the `typedef` from the diagnostic because it 
> exposes the implementation details unnecessarily? I believe the spec doesn't 
> say what the type is aside from enums?  As a matter of fact, we have some 
> types implemented as typedefs that should have been a native types e.g. 
> vector types that we might change one day.
I agree it's an implementation detail, but I can see reasons for keeping it: 
when there is an enum type with the same name available in the translation 
unit, then the message "type X not found" is not completely correct, because a 
type X exists, but it is of the wrong type. By prefixing "enum" or "typedef", 
the diagnostic is more accurate.  This diagnostic is mainly targeted at Clang 
developers actually, because a user shouldn't see this diagnostic in any normal 
use case (with the driver setting both -fdeclare-opencl-builtins and 
-finclude-default-header).


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

https://reviews.llvm.org/D96051

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


[PATCH] D96244: [clangd] Introduce Modules

2021-02-12 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 323361.
kadircet marked 7 inline comments as done.
kadircet added a comment.

- Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96244

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/Module.h
  clang-tools-extra/clangd/unittests/ParsedASTTests.cpp

Index: clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
===
--- clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
+++ clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
@@ -376,7 +376,7 @@
 void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
 StringRef FileName, bool IsAngled,
 CharSourceRange FilenameRange, const FileEntry *,
-StringRef, StringRef, const Module *,
+StringRef, StringRef, const clang::Module *,
 SrcMgr::CharacteristicKind) override {
   Includes.emplace_back(SM, HashLoc, IncludeTok, FileName, IsAngled,
 FilenameRange);
Index: clang-tools-extra/clangd/Module.h
===
--- /dev/null
+++ clang-tools-extra/clangd/Module.h
@@ -0,0 +1,52 @@
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_MODULE_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_MODULE_H
+
+#include "llvm/ADT/StringRef.h"
+#include 
+#include 
+
+namespace clang {
+namespace clangd {
+
+/// A Module contributes a vertical feature to clangd.
+///
+/// FIXME: Extend this with LSP bindings to support reading/updating
+/// capabilities and implementing LSP endpoints.
+///
+/// The lifetime of a module is roughly:
+///  - modules are created before the LSP server, in ClangdMain.cpp
+///  - these modules are then passed to ClangdLSPServer and ClangdServer
+///FIXME: LSP bindings should be registered at ClangdLSPServer
+///initialization.
+///  - module hooks can be called at this point.
+///FIXME: We should make some server facilities like TUScheduler and index
+///available to those modules after ClangdServer is initalized.
+///  - ClangdServer will not be destroyed until all the requests are done.
+///FIXME: Block server shutdown until all the modules are idle.
+///  - modules will be destroyed after ClangdLSPServer is destroyed.
+///
+/// Conventionally, standard modules live in the `clangd` namespace, and other
+/// exposed details live in a sub-namespace.
+class Module {
+public:
+  virtual ~Module() = default;
+};
+
+class ModuleSet {
+  std::vector> Modules;
+
+public:
+  explicit ModuleSet(std::vector> Modules)
+  : Modules(std::move(Modules)) {}
+
+  using iterator = llvm::pointee_iterator;
+  using const_iterator =
+  llvm::pointee_iterator;
+  iterator begin() { return iterator(Modules.begin()); }
+  iterator end() { return iterator(Modules.end()); }
+  const_iterator begin() const { return const_iterator(Modules.begin()); }
+  const_iterator end() const { return const_iterator(Modules.end()); }
+};
+} // namespace clangd
+} // namespace clang
+#endif
Index: clang-tools-extra/clangd/Headers.cpp
===
--- clang-tools-extra/clangd/Headers.cpp
+++ clang-tools-extra/clangd/Headers.cpp
@@ -36,7 +36,7 @@
   CharSourceRange /*FilenameRange*/,
   const FileEntry *File, llvm::StringRef /*SearchPath*/,
   llvm::StringRef /*RelativePath*/,
-  const Module * /*Imported*/,
+  const clang::Module * /*Imported*/,
   SrcMgr::CharacteristicKind FileKind) override {
 auto MainFID = SM.getMainFileID();
 // If an include is part of the preamble patch, translate #line directives.
Index: clang-tools-extra/clangd/ClangdServer.h
===
--- clang-tools-extra/clangd/ClangdServer.h
+++ clang-tools-extra/clangd/ClangdServer.h
@@ -14,6 +14,7 @@
 #include "ConfigProvider.h"
 #include "GlobalCompilationDatabase.h"
 #include "Hover.h"
+#include "Module.h"
 #include "Protocol.h"
 #include "SemanticHighlighting.h"
 #include "TUScheduler.h"
@@ -151,6 +152,8 @@
 /// Enable preview of FoldingRanges feature.
 bool FoldingRanges = false;
 
+ModuleSet *Modules = nullptr;
+
 explicit operator TUScheduler::Options() const;
   };
   // Sensible default options for use in tests.
@@ -345,6 +348,7 @@
 
   const GlobalCompilationDatabase &CDB;
   const ThreadsafeFS &TFS;
+  ModuleSet *Modules = nullptr;
 
   Path ResourceDir;
   // The index used to look up symbols. This could be:
Index: clang-tools-extra/clangd/ClangdServer.cpp
===

[PATCH] D96244: [clangd] Introduce Modules

2021-02-12 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/ClangdServer.h:33
 #include "clang/Tooling/Core/Replacement.h"
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/FunctionExtras.h"

sammccall wrote:
> (include no longer used?)
well it is still used by `formatCode` :P (but dropping to keep the irrelevant 
changes out, same for memory and vector)



Comment at: clang-tools-extra/clangd/Module.h:31
+public:
+  virtual ~Module() = default;
+

sammccall wrote:
> Should either:
>  - doc that destructor should cancel as much background work as possible and 
> block until it's done
>  - add a requestStop() and doc that destructor should block
>  - remove the concept of background work completely (i.e. blockUntilIdle())
as discussed offline going with `remove the concept of background work 
completely (i.e. blockUntilIdle())`. we can go with requestStop and blocking 
destructors, once the need arises. (i.e. we better understand the usecases)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96244

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


[PATCH] D96515: [OpenCL] Add builtin declarations by default.

2021-02-12 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia updated this revision to Diff 323362.
Anastasia added a comment.

Changed command line option text.


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

https://reviews.llvm.org/D96515

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/Types.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/Types.cpp
  clang/test/Driver/default-includes.cl
  clang/unittests/AST/MatchVerifier.h

Index: clang/unittests/AST/MatchVerifier.h
===
--- clang/unittests/AST/MatchVerifier.h
+++ clang/unittests/AST/MatchVerifier.h
@@ -117,6 +117,7 @@
 FileName = "input.cc";
 break;
   case Lang_OpenCL:
+Args.push_back("-cl-no-stdinc");
 FileName = "input.cl";
 break;
   case Lang_OBJCXX:
Index: clang/test/Driver/default-includes.cl
===
--- /dev/null
+++ clang/test/Driver/default-includes.cl
@@ -0,0 +1,13 @@
+// RUN: %clang %s -Xclang -verify -fsyntax-only
+// RUN: %clang %s -cl-no-stdinc -Xclang -verify -DNOINC -fsyntax-only
+
+#ifndef NOINC
+//expected-no-diagnostics
+#endif
+
+void test() {
+int i = get_global_id(0);
+#ifdef NOINC
+//expected-error@-2{{implicit declaration of function 'get_global_id' is invalid in OpenCL}}
+#endif
+}
Index: clang/lib/Driver/Types.cpp
===
--- clang/lib/Driver/Types.cpp
+++ clang/lib/Driver/Types.cpp
@@ -160,6 +160,8 @@
   }
 }
 
+bool types::isOpenCL(ID Id) { return Id == TY_CL; }
+
 bool types::isCXX(ID Id) {
   switch (Id) {
   default:
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3158,7 +3158,8 @@
   }
 }
 
-static void RenderOpenCLOptions(const ArgList &Args, ArgStringList &CmdArgs) {
+static void RenderOpenCLOptions(const ArgList &Args, ArgStringList &CmdArgs,
+types::ID InputType) {
   // cl-denorms-are-zero is not forwarded. It is translated into a generic flag
   // for denormal flushing handling based on the target.
   const unsigned ForwardedArguments[] = {
@@ -3183,6 +3184,13 @@
   for (const auto &Arg : ForwardedArguments)
 if (const auto *A = Args.getLastArg(Arg))
   CmdArgs.push_back(Args.MakeArgString(A->getOption().getPrefixedName()));
+
+  // Only add the default headers if we are compiling OpenCL sources.
+  if ((types::isOpenCL(InputType) || Args.hasArg(options::OPT_cl_std_EQ)) &&
+  !Args.hasArg(options::OPT_cl_no_stdinc)) {
+CmdArgs.push_back("-finclude-default-header");
+CmdArgs.push_back("-fdeclare-opencl-builtins");
+  }
 }
 
 static void RenderARCMigrateToolOptions(const Driver &D, const ArgList &Args,
@@ -5680,7 +5688,7 @@
   }
 
   // Forward -cl options to -cc1
-  RenderOpenCLOptions(Args, CmdArgs);
+  RenderOpenCLOptions(Args, CmdArgs, InputType);
 
   if (IsHIP) {
 if (Args.hasFlag(options::OPT_fhip_new_launch_api,
Index: clang/include/clang/Driver/Types.h
===
--- clang/include/clang/Driver/Types.h
+++ clang/include/clang/Driver/Types.h
@@ -81,6 +81,9 @@
   /// isObjC - Is this an "ObjC" input (Obj-C and Obj-C++ sources and headers).
   bool isObjC(ID Id);
 
+  /// isOpenCL - Is this an "OpenCL" input.
+  bool isOpenCL(ID Id);
+
   /// isFortran - Is this a Fortran input.
   bool isFortran(ID Id);
 
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -818,6 +818,8 @@
 def cl_uniform_work_group_size : Flag<["-"], "cl-uniform-work-group-size">, Group, Flags<[CC1Option]>,
   HelpText<"OpenCL only. Defines that the global work-size be a multiple of the work-group size specified to clEnqueueNDRangeKernel">,
   MarshallingInfoFlag>;
+def cl_no_stdinc : Flag<["-"], "cl-no-stdinc">, Group,
+  HelpText<"OpenCL only. Disables all standard includes containing non-native compiler types and functions.">;
 def client__name : JoinedOrSeparate<["-"], "client_name">;
 def combine : Flag<["-", "--"], "combine">, Flags<[NoXarchOption, Unsupported]>;
 def compatibility__version : JoinedOrSeparate<["-"], "compatibility_version">;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D95561: [Clang] Introduce Swift async calling convention.

2021-02-12 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple updated this revision to Diff 323363.
varungandhi-apple added a comment.

Fix test case for debuginfo.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95561

Files:
  clang/include/clang-c/Index.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/Specifiers.h
  clang/include/clang/CodeGen/SwiftCallingConv.h
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Basic/Targets/PPC.h
  clang/lib/Basic/Targets/SystemZ.h
  clang/lib/Basic/Targets/WebAssembly.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/arm-swiftcall.c
  clang/test/CodeGen/debug-info-cc.c
  clang/test/Sema/attr-c2x.c
  clang/test/Sema/attr-swiftcall.c
  clang/test/Sema/no_callconv.cpp
  clang/test/SemaCXX/attr-swiftcall.cpp
  clang/tools/libclang/CXType.cpp
  llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
  llvm/lib/Demangle/MicrosoftDemangle.cpp
  llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
  llvm/test/Demangle/ms-mangle.test

Index: llvm/test/Demangle/ms-mangle.test
===
--- llvm/test/Demangle/ms-mangle.test
+++ llvm/test/Demangle/ms-mangle.test
@@ -341,6 +341,9 @@
 ?swift_func@@YSXXZ
 ; CHECK: void __attribute__((__swiftcall__)) swift_func(void)
 
+?swift_async_func@@YTXXZ
+; CHECK: void __attribute__((__swiftasynccall__)) swift_async_func(void)
+
 ??$fn_tmpl@$1?extern_c_func@@YAXXZ@@YAXXZ
 ; CHECK: void __cdecl fn_tmpl<&void __cdecl extern_c_func(void)>(void)
 
Index: llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
===
--- llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
+++ llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
@@ -110,6 +110,9 @@
   case CallingConv::Swift:
 OS << "__attribute__((__swiftcall__)) ";
 break;
+  case CallingConv::SwiftAsync:
+OS << "__attribute__((__swiftasynccall__)) ";
+break;
   default:
 break;
   }
Index: llvm/lib/Demangle/MicrosoftDemangle.cpp
===
--- llvm/lib/Demangle/MicrosoftDemangle.cpp
+++ llvm/lib/Demangle/MicrosoftDemangle.cpp
@@ -1713,6 +1713,8 @@
 return CallingConv::Vectorcall;
   case 'S':
 return CallingConv::Swift;
+  case 'T':
+return CallingConv::SwiftAsync;
   }
 
   return CallingConv::None;
Index: llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
===
--- llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
+++ llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
@@ -67,7 +67,8 @@
   Eabi,
   Vectorcall,
   Regcall,
-  Swift, // Clang-only
+  Swift,  // Clang-only
+  SwiftAsync, // Clang-only
 };
 
 enum class ReferenceKind : uint8_t { None, LValueRef, RValueRef };
Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -664,6 +664,7 @@
   TCALLINGCONV(AAPCS_VFP);
   TCALLINGCONV(IntelOclBicc);
   TCALLINGCONV(Swift);
+  TCALLINGCONV(SwiftAsync);
   TCALLINGCONV(PreserveMost);
   TCALLINGCONV(PreserveAll);
 case CC_SpirFunction: return CXCallingConv_Unexposed;
Index: clang/test/SemaCXX/attr-swiftcall.cpp
===
--- clang/test/SemaCXX/attr-swiftcall.cpp
+++ clang/test/SemaCXX/attr-swiftcall.cpp
@@ -1,14 +1,20 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify %s
 
 #define SWIFTCALL __attribute__((swiftcall))
+#define SWIFTASYNCCALL __attribute__((swiftasynccall))
 #define INDIRECT_RESULT __attribute__((swift_indirect_result))
 #define ERROR_RESULT __attribute__((swift_error_result))
 #define CONTEXT __attribute__((swift_context))
+#define ASYNC_CONTEXT __attribute__((swift_async_context))
 
 int notAFunction SWIFTCALL; // expected-warning {{'swiftcall' only applies to function types; type here is 'int'}}
+int notAnAsyncFunction SWIFTASYNCCALL; // expected-warning {{'swiftasynccall' only applies to function types; type here is 'int'}}
 void variadic(int x, ...) SWIFTCALL; // expected-error {{variadic function cannot use swiftcall calling convention}}
+void variadic_async(int x, ...) SWIFTASYNCCALL; // expected-error {{variadic function cannot use swiftasynccall calling convention}}
 void multiple_ccs(int x) SWIFTCALL __attribute__((vectorcall)); // expected-error {{vectorcall and swiftcall attributes are not compatible}}
+void multiple_ccs_async(int x) SWIFTASYNCCALL __attribute__((v

[PATCH] D95704: [CodeGen] Introduce DWARF tag for SwiftTail and emit it in CodeGen.

2021-02-12 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple updated this revision to Diff 323364.
varungandhi-apple added a comment.

Tweak test case diff to adjust for change in previous commit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95704

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGen/debug-info-cc.c
  llvm/include/llvm/BinaryFormat/Dwarf.def


Index: llvm/include/llvm/BinaryFormat/Dwarf.def
===
--- llvm/include/llvm/BinaryFormat/Dwarf.def
+++ llvm/include/llvm/BinaryFormat/Dwarf.def
@@ -788,6 +788,7 @@
 HANDLE_DW_CC(0xc9, LLVM_PreserveMost)
 HANDLE_DW_CC(0xca, LLVM_PreserveAll)
 HANDLE_DW_CC(0xcb, LLVM_X86RegCall)
+HANDLE_DW_CC(0xcc, LLVM_SwiftTail)
 // From GCC source code (include/dwarf2.h): This DW_CC_ value is not currently
 // generated by any toolchain.  It is used internally to GDB to indicate 
OpenCL C
 // functions that have been compiled with the IBM XL C for OpenCL compiler and 
use
Index: clang/test/CodeGen/debug-info-cc.c
===
--- clang/test/CodeGen/debug-info-cc.c
+++ clang/test/CodeGen/debug-info-cc.c
@@ -57,11 +57,10 @@
   return a+b;
 }
 
-// [FIXME: swiftasynccc] Update debuginfo tag to SwiftAsync once LLVM support 
lands.
 // LINUX: !DISubprogram({{.*}}"add_swiftasynccall", {{.*}}type: ![[FTY:[0-9]+]]
-// LINUX: ![[FTY]] = !DISubroutineType({{.*}}cc: DW_CC_LLVM_Swift,
-__attribute__((swiftasynccall)) int add_swiftasynccall(int a, int b, int c) {
-  return a+b+c;
+// LINUX: ![[FTY]] = !DISubroutineType({{.*}}cc: DW_CC_LLVM_SwiftTail,
+__attribute__((swiftasynccall)) int add_swiftasynccall(int a, int b) {
+  return a+b;
 }
 
 // LINUX: !DISubprogram({{.*}}"add_inteloclbicc", {{.*}}type: ![[FTY:[0-9]+]]
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1249,8 +1249,7 @@
   case CC_Swift:
 return llvm::dwarf::DW_CC_LLVM_Swift;
   case CC_SwiftAsync:
-// [FIXME: swiftasynccc] Update to SwiftAsync once LLVM support lands.
-return llvm::dwarf::DW_CC_LLVM_Swift;
+return llvm::dwarf::DW_CC_LLVM_SwiftTail;
   case CC_PreserveMost:
 return llvm::dwarf::DW_CC_LLVM_PreserveMost;
   case CC_PreserveAll:


Index: llvm/include/llvm/BinaryFormat/Dwarf.def
===
--- llvm/include/llvm/BinaryFormat/Dwarf.def
+++ llvm/include/llvm/BinaryFormat/Dwarf.def
@@ -788,6 +788,7 @@
 HANDLE_DW_CC(0xc9, LLVM_PreserveMost)
 HANDLE_DW_CC(0xca, LLVM_PreserveAll)
 HANDLE_DW_CC(0xcb, LLVM_X86RegCall)
+HANDLE_DW_CC(0xcc, LLVM_SwiftTail)
 // From GCC source code (include/dwarf2.h): This DW_CC_ value is not currently
 // generated by any toolchain.  It is used internally to GDB to indicate OpenCL C
 // functions that have been compiled with the IBM XL C for OpenCL compiler and use
Index: clang/test/CodeGen/debug-info-cc.c
===
--- clang/test/CodeGen/debug-info-cc.c
+++ clang/test/CodeGen/debug-info-cc.c
@@ -57,11 +57,10 @@
   return a+b;
 }
 
-// [FIXME: swiftasynccc] Update debuginfo tag to SwiftAsync once LLVM support lands.
 // LINUX: !DISubprogram({{.*}}"add_swiftasynccall", {{.*}}type: ![[FTY:[0-9]+]]
-// LINUX: ![[FTY]] = !DISubroutineType({{.*}}cc: DW_CC_LLVM_Swift,
-__attribute__((swiftasynccall)) int add_swiftasynccall(int a, int b, int c) {
-  return a+b+c;
+// LINUX: ![[FTY]] = !DISubroutineType({{.*}}cc: DW_CC_LLVM_SwiftTail,
+__attribute__((swiftasynccall)) int add_swiftasynccall(int a, int b) {
+  return a+b;
 }
 
 // LINUX: !DISubprogram({{.*}}"add_inteloclbicc", {{.*}}type: ![[FTY:[0-9]+]]
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1249,8 +1249,7 @@
   case CC_Swift:
 return llvm::dwarf::DW_CC_LLVM_Swift;
   case CC_SwiftAsync:
-// [FIXME: swiftasynccc] Update to SwiftAsync once LLVM support lands.
-return llvm::dwarf::DW_CC_LLVM_Swift;
+return llvm::dwarf::DW_CC_LLVM_SwiftTail;
   case CC_PreserveMost:
 return llvm::dwarf::DW_CC_LLVM_PreserveMost;
   case CC_PreserveAll:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D96515: [OpenCL] Add builtin declarations by default.

2021-02-12 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In D96515#2559424 , @svenvh wrote:

> It probably makes sense to update `clang/docs/UsersManual.rst` as part of 
> this change.  In particular the following sentence is no longer true after 
> this patch: "By default the OpenCL headers are not loaded and therefore 
> certain builtin types and most of builtin functions are not declared."

Yes, that's right but I think there is a bigger change that needs to be made 
i.e. I would completely remove `-finclude-default-header` and let it live on 
OpenCLSupport page. I would prefer a separate review for docs though.


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

https://reviews.llvm.org/D96515

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


[PATCH] D96608: [clangd] Delay binding LSP methods until initialize. NFC

2021-02-12 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/ClangdLSPServer.cpp:165
   return false;
-if (!Server.Server) {
-  elog("Notification {0} before initialization", Method);
-} else if (Method == "$/cancelRequest") {
+if (Method == "$/cancelRequest") {
   onCancel(std::move(Params));

this one is a functional change though , previously we would say `notification 
X before initialization` for cancellations that arrived before init, now we are 
going to say "bad cancellation request". not that it is bad, but it makes me 
wonder if it is intentional :D



Comment at: clang-tools-extra/clangd/ClangdLSPServer.cpp:173
+  elog("Notification {0} before initialization", Method);
+} else if (Method == "$/cancelRequest") {
   log("unhandled notification {0}", Method);

you mean just `else` ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96608

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


[clang-tools-extra] 2423a38 - [clangd] Introduce Modules

2021-02-12 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2021-02-12T18:37:16+01:00
New Revision: 2423a3863e0743635f76d30062413f21b2c59349

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

LOG: [clangd] Introduce Modules

Modules can be used to augment clangd's behaviours in various features.

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

Added: 
clang-tools-extra/clangd/Module.h

Modified: 
clang-tools-extra/clangd/ClangdServer.cpp
clang-tools-extra/clangd/ClangdServer.h
clang-tools-extra/clangd/Headers.cpp
clang-tools-extra/clangd/unittests/ParsedASTTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/ClangdServer.cpp 
b/clang-tools-extra/clangd/ClangdServer.cpp
index b39e582d84a1..bf834eccd9f5 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -127,7 +127,7 @@ ClangdServer::Options::operator TUScheduler::Options() 
const {
 ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB,
const ThreadsafeFS &TFS, const Options &Opts,
Callbacks *Callbacks)
-: CDB(CDB), TFS(TFS),
+: CDB(CDB), TFS(TFS), Modules(Opts.Modules),
   DynamicIdx(Opts.BuildDynamicSymbolIndex ? new FileIndex() : nullptr),
   ClangTidyProvider(Opts.ClangTidyProvider),
   WorkspaceRoot(Opts.WorkspaceRoot),

diff  --git a/clang-tools-extra/clangd/ClangdServer.h 
b/clang-tools-extra/clangd/ClangdServer.h
index c299d7334603..5e51616a4b2d 100644
--- a/clang-tools-extra/clangd/ClangdServer.h
+++ b/clang-tools-extra/clangd/ClangdServer.h
@@ -14,6 +14,7 @@
 #include "ConfigProvider.h"
 #include "GlobalCompilationDatabase.h"
 #include "Hover.h"
+#include "Module.h"
 #include "Protocol.h"
 #include "SemanticHighlighting.h"
 #include "TUScheduler.h"
@@ -142,6 +143,8 @@ class ClangdServer {
 /// Enable preview of FoldingRanges feature.
 bool FoldingRanges = false;
 
+ModuleSet *Modules = nullptr;
+
 explicit operator TUScheduler::Options() const;
   };
   // Sensible default options for use in tests.
@@ -336,6 +339,7 @@ class ClangdServer {
 
   const GlobalCompilationDatabase &CDB;
   const ThreadsafeFS &TFS;
+  ModuleSet *Modules = nullptr;
 
   Path ResourceDir;
   // The index used to look up symbols. This could be:

diff  --git a/clang-tools-extra/clangd/Headers.cpp 
b/clang-tools-extra/clangd/Headers.cpp
index 876645cd6a50..111b05849b81 100644
--- a/clang-tools-extra/clangd/Headers.cpp
+++ b/clang-tools-extra/clangd/Headers.cpp
@@ -36,7 +36,7 @@ class RecordHeaders : public PPCallbacks {
   CharSourceRange /*FilenameRange*/,
   const FileEntry *File, llvm::StringRef 
/*SearchPath*/,
   llvm::StringRef /*RelativePath*/,
-  const Module * /*Imported*/,
+  const clang::Module * /*Imported*/,
   SrcMgr::CharacteristicKind FileKind) override {
 auto MainFID = SM.getMainFileID();
 // If an include is part of the preamble patch, translate #line directives.

diff  --git a/clang-tools-extra/clangd/Module.h 
b/clang-tools-extra/clangd/Module.h
new file mode 100644
index ..d32618238867
--- /dev/null
+++ b/clang-tools-extra/clangd/Module.h
@@ -0,0 +1,52 @@
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_MODULE_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_MODULE_H
+
+#include "llvm/ADT/StringRef.h"
+#include 
+#include 
+
+namespace clang {
+namespace clangd {
+
+/// A Module contributes a vertical feature to clangd.
+///
+/// FIXME: Extend this with LSP bindings to support reading/updating
+/// capabilities and implementing LSP endpoints.
+///
+/// The lifetime of a module is roughly:
+///  - modules are created before the LSP server, in ClangdMain.cpp
+///  - these modules are then passed to ClangdLSPServer and ClangdServer
+///FIXME: LSP bindings should be registered at ClangdLSPServer
+///initialization.
+///  - module hooks can be called at this point.
+///FIXME: We should make some server facilities like TUScheduler and index
+///available to those modules after ClangdServer is initalized.
+///  - ClangdServer will not be destroyed until all the requests are done.
+///FIXME: Block server shutdown until all the modules are idle.
+///  - modules will be destroyed after ClangdLSPServer is destroyed.
+///
+/// Conventionally, standard modules live in the `clangd` namespace, and other
+/// exposed details live in a sub-namespace.
+class Module {
+public:
+  virtual ~Module() = default;
+};
+
+class ModuleSet {
+  std::vector> Modules;
+
+public:
+  explicit ModuleSet(std::vector> Modules)
+  : Modules(std::move(Modules)) {}
+
+  using iterator = llvm::pointee_iterator;
+  using const_iterator =
+ 

[PATCH] D96244: [clangd] Introduce Modules

2021-02-12 Thread Kadir Cetinkaya 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 rG2423a3863e07: [clangd] Introduce Modules (authored by 
kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96244

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/Module.h
  clang-tools-extra/clangd/unittests/ParsedASTTests.cpp

Index: clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
===
--- clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
+++ clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
@@ -373,7 +373,7 @@
 void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
 StringRef FileName, bool IsAngled,
 CharSourceRange FilenameRange, const FileEntry *,
-StringRef, StringRef, const Module *,
+StringRef, StringRef, const clang::Module *,
 SrcMgr::CharacteristicKind) override {
   Includes.emplace_back(SM, HashLoc, IncludeTok, FileName, IsAngled,
 FilenameRange);
Index: clang-tools-extra/clangd/Module.h
===
--- /dev/null
+++ clang-tools-extra/clangd/Module.h
@@ -0,0 +1,52 @@
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_MODULE_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_MODULE_H
+
+#include "llvm/ADT/StringRef.h"
+#include 
+#include 
+
+namespace clang {
+namespace clangd {
+
+/// A Module contributes a vertical feature to clangd.
+///
+/// FIXME: Extend this with LSP bindings to support reading/updating
+/// capabilities and implementing LSP endpoints.
+///
+/// The lifetime of a module is roughly:
+///  - modules are created before the LSP server, in ClangdMain.cpp
+///  - these modules are then passed to ClangdLSPServer and ClangdServer
+///FIXME: LSP bindings should be registered at ClangdLSPServer
+///initialization.
+///  - module hooks can be called at this point.
+///FIXME: We should make some server facilities like TUScheduler and index
+///available to those modules after ClangdServer is initalized.
+///  - ClangdServer will not be destroyed until all the requests are done.
+///FIXME: Block server shutdown until all the modules are idle.
+///  - modules will be destroyed after ClangdLSPServer is destroyed.
+///
+/// Conventionally, standard modules live in the `clangd` namespace, and other
+/// exposed details live in a sub-namespace.
+class Module {
+public:
+  virtual ~Module() = default;
+};
+
+class ModuleSet {
+  std::vector> Modules;
+
+public:
+  explicit ModuleSet(std::vector> Modules)
+  : Modules(std::move(Modules)) {}
+
+  using iterator = llvm::pointee_iterator;
+  using const_iterator =
+  llvm::pointee_iterator;
+  iterator begin() { return iterator(Modules.begin()); }
+  iterator end() { return iterator(Modules.end()); }
+  const_iterator begin() const { return const_iterator(Modules.begin()); }
+  const_iterator end() const { return const_iterator(Modules.end()); }
+};
+} // namespace clangd
+} // namespace clang
+#endif
Index: clang-tools-extra/clangd/Headers.cpp
===
--- clang-tools-extra/clangd/Headers.cpp
+++ clang-tools-extra/clangd/Headers.cpp
@@ -36,7 +36,7 @@
   CharSourceRange /*FilenameRange*/,
   const FileEntry *File, llvm::StringRef /*SearchPath*/,
   llvm::StringRef /*RelativePath*/,
-  const Module * /*Imported*/,
+  const clang::Module * /*Imported*/,
   SrcMgr::CharacteristicKind FileKind) override {
 auto MainFID = SM.getMainFileID();
 // If an include is part of the preamble patch, translate #line directives.
Index: clang-tools-extra/clangd/ClangdServer.h
===
--- clang-tools-extra/clangd/ClangdServer.h
+++ clang-tools-extra/clangd/ClangdServer.h
@@ -14,6 +14,7 @@
 #include "ConfigProvider.h"
 #include "GlobalCompilationDatabase.h"
 #include "Hover.h"
+#include "Module.h"
 #include "Protocol.h"
 #include "SemanticHighlighting.h"
 #include "TUScheduler.h"
@@ -142,6 +143,8 @@
 /// Enable preview of FoldingRanges feature.
 bool FoldingRanges = false;
 
+ModuleSet *Modules = nullptr;
+
 explicit operator TUScheduler::Options() const;
   };
   // Sensible default options for use in tests.
@@ -336,6 +339,7 @@
 
   const GlobalCompilationDatabase &CDB;
   const ThreadsafeFS &TFS;
+  ModuleSet *Modules = nullptr;
 
   Path ResourceDir;
   // The index used to look up symbols. This could be:
In

[PATCH] D95753: Store compilation dir separately in coverage mapping

2021-02-12 Thread Vedant Kumar via Phabricator via cfe-commits
vsk accepted this revision.
vsk added a comment.
This revision is now accepted and ready to land.

Thanks, lgtm. The pre-merge checks appear to have flagged some issues, but I 
don't anticipate any major revision.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95753

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


[PATCH] D95753: Store compilation dir separately in coverage mapping

2021-02-12 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added inline comments.



Comment at: llvm/docs/CoverageMappingFormat.rst:277
+There is one difference between versions 6 and 5:
+
+There is one difference between versions 5 and 4:

I think the above bullet point could go in this section?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95753

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


[PATCH] D96419: [clang] Add -ffinite-loops & -fno-finite-loops options.

2021-02-12 Thread Florian Hahn via Phabricator via cfe-commits
fhahn updated this revision to Diff 323373.
fhahn added a comment.

Rebased the patch to apply wihtout  D96418 . 
Will land soon.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96419

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/attr-mustprogress.c
  clang/test/CodeGenCXX/attr-mustprogress.cpp

Index: clang/test/CodeGenCXX/attr-mustprogress.cpp
===
--- clang/test/CodeGenCXX/attr-mustprogress.cpp
+++ clang/test/CodeGenCXX/attr-mustprogress.cpp
@@ -4,6 +4,12 @@
 // RUN: %clang_cc1 -std=c++17 -triple=x86_64-unknown-linux-gnu -S -emit-llvm %s -o - | FileCheck --check-prefix=CHECK --check-prefix=CXX11 %s
 // RUN: %clang_cc1 -std=c++20 -triple=x86_64-unknown-linux-gnu -S -emit-llvm %s -o - | FileCheck --check-prefix=CHECK --check-prefix=CXX11 %s
 
+// Make sure -ffinite-loops overrides -std=c++98 for loops.
+// RUN: %clang_cc1 -std=c++98 -ffinite-loops -triple=x86_64-unknown-linux-gnu -S -emit-llvm %s -o - | FileCheck --check-prefix=CHECK --check-prefix=FINITE %s
+
+// Make sure -fno_finite-loops overrides -std=c++11
+// RUN: %clang_cc1 -std=c++11 -fno-finite-loops -triple=x86_64-unknown-linux-gnu -S -emit-llvm %s -o - | FileCheck --check-prefix=CHECK --check-prefix=CXX98 %s
+
 int a = 0;
 int b = 0;
 
@@ -11,26 +17,26 @@
 
 // CXX98-NOT: mustprogress
 // CXX11-NOT: mustprogress
+// FINITE-NOT: mustprogress
 // CHECK-LABEL: @_Z2f0v(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:br label %for.cond
 // CHECK:   for.cond:
-// CXX98-NOT:br {{.*}} llvm.loop
-// CXX11-NOT:br {{.*}} llvm.loop
+// CHECK-NOT:br {{.*}} llvm.loop
 void f0() {
   for (; ;) ;
 }
 
 // CXX98-NOT: mustprogress
 // CXX11-NOT: mustprogress
+// FINITE-NOT: mustprogress
 // CHECK-LABEL: @_Z2f1v(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:br label %for.cond
 // CHECK:   for.cond:
 // CHECK-NEXT:br i1 true, label %for.body, label %for.end
 // CHECK:   for.body:
-// CXX98-NOT:br {{.*}}, !llvm.loop
-// CXX11-NOT:br {{.*}}, !llvm.loop
+// CHECK-NOT:br {{.*}}, !llvm.loop
 // CHECK:   for.end:
 // CHECK-NEXT:ret void
 //
@@ -41,6 +47,7 @@
 
 // CXX98-NOT: mustprogress
 // CXX11: mustprogress
+// FINITE-NOT: mustprogress
 // CHECK-LABEL: @_Z2f2v(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:br label %for.cond
@@ -52,6 +59,7 @@
 // CHECK:   for.body:
 // CXX98-NOT:br {{.*}}, !llvm.loop
 // CXX11:br label %for.cond, !llvm.loop [[LOOP1:!.*]]
+// FINITE-NEXT:   br label %for.cond, !llvm.loop [[LOOP1:!.*]]
 // CHECK:   for.end:
 // CHECK-NEXT:ret void
 //
@@ -62,14 +70,14 @@
 
 // CXX98-NOT: mustprogress
 // CXX11-NOT: mustprogress
+// FINITE-NOT: mustprogress
 // CHECK-LABEL: @_Z1Fv(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:br label %for.cond
 // CHECK:   for.cond:
 // CHECK-NEXT:br i1 true, label %for.body, label %for.end
 // CHECK:   for.body:
-// CXX98-NOT: br {{.*}}, !llvm.loop
-// CXX11-NOT: br {{.*}}, !llvm.loop
+// CHECK-NOT: br {{.*}}, !llvm.loop
 // CHECK:   for.end:
 // CHECK-NEXT:br label %for.cond1
 // CHECK:   for.cond1:
@@ -78,8 +86,9 @@
 // CHECK-NEXT:[[CMP:%.*]] = icmp eq i32 [[TMP0]], [[TMP1]]
 // CHECK-NEXT:br i1 [[CMP]], label %for.body2, label %for.end3
 // CHECK:   for.body2:
-// CXX98-NOT:br {{.*}}, !llvm.loop
-// CXX11:br label %for.cond1, !llvm.loop [[LOOP2:!.*]]
+// CXX98-NOT: br {{.*}}, !llvm.loop
+// CXX11-NEXT:br label %for.cond1, !llvm.loop [[LOOP2:!.*]]
+// FINITE-NEXT:   br label %for.cond1, !llvm.loop [[LOOP2:!.*]]
 // CHECK:   for.end3:
 // CHECK-NEXT:ret void
 //
@@ -91,7 +100,8 @@
 }
 
 // CXX98-NOT: mustprogress
-// CXX11_NOT: mustprogress
+// CXX11-NOT: mustprogress
+// FINITE-NOT: mustprogress
 // CHECK-LABEL: @_Z2F2v(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:br label %for.cond
@@ -102,14 +112,14 @@
 // CHECK-NEXT:br i1 [[CMP]], label %for.body, label %for.end
 // CHECK:   for.body:
 // CXX98_NOT: br {{.*}} !llvm.loop
-// CXX11-NEXT:br label %for.cond, !llvm.loop
+// CXX11-NEXT:br label %for.cond, !llvm.loop [[LOOP3:!.*]]
+// FINITE-NEXT:br label %for.cond, !llvm.loop [[LOOP3:!.*]]
 // CHECK:   for.end:
 // CHECK-NEXT:br label %for.cond1
 // CHECK:   for.cond1:
 // CHECK-NEXT:br i1 true, label %for.body2, label %for.end3
 // CHECK:   for.body2:
-// CXX98-NOT: br {{.*}}, !llvm.loop
-// CXX11-NOT: br {{.*}}, !llvm.loop
+// CHECK-NOT: br {{.*}}, !llvm.loop
 // CHECK:   for.end3:
 // CHECK-NEXT:ret void
 //
@@ -122,12 +132,12 @@
 
 // CXX98-NOT: mustprogress
 // CXX11-NOT: mustprogress
+// FINITE-NO

[clang] ed4718e - [ObjC][ARC] Use operand bundle 'clang.arc.attachedcall' instead of

2021-02-12 Thread Akira Hatanaka via cfe-commits

Author: Akira Hatanaka
Date: 2021-02-12T09:51:57-08:00
New Revision: ed4718eccb12bd42214ca4fb17d196d49561c0c7

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

LOG: [ObjC][ARC] Use operand bundle 'clang.arc.attachedcall' instead of
explicitly emitting retainRV or claimRV calls in the IR

Background:

This fixes a longstanding problem where llvm breaks ARC's autorelease
optimization (see the link below) by separating calls from the marker
instructions or retainRV/claimRV calls. The backend changes are in
https://reviews.llvm.org/D92569.

https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-autoreleasereturnvalue

What this patch does to fix the problem:

- The front-end adds operand bundle "clang.arc.attachedcall" to calls,
  which indicates the call is implicitly followed by a marker
  instruction and an implicit retainRV/claimRV call that consumes the
  call result. In addition, it emits a call to
  @llvm.objc.clang.arc.noop.use, which consumes the call result, to
  prevent the middle-end passes from changing the return type of the
  called function. This is currently done only when the target is arm64
  and the optimization level is higher than -O0.

- ARC optimizer temporarily emits retainRV/claimRV calls after the calls
  with the operand bundle in the IR and removes the inserted calls after
  processing the function.

- ARC contract pass emits retainRV/claimRV calls after the call with the
  operand bundle. It doesn't remove the operand bundle on the call since
  the backend needs it to emit the marker instruction. The retainRV and
  claimRV calls are emitted late in the pipeline to prevent optimization
  passes from transforming the IR in a way that makes it harder for the
  ARC middle-end passes to figure out the def-use relationship between
  the call and the retainRV/claimRV calls (which is the cause of
  PR31925).

- The function inliner removes an autoreleaseRV call in the callee if
  nothing in the callee prevents it from being paired up with the
  retainRV/claimRV call in the caller. It then inserts a release call if
  claimRV is attached to the call since autoreleaseRV+claimRV is
  equivalent to a release. If it cannot find an autoreleaseRV call, it
  tries to transfer the operand bundle to a function call in the callee.
  This is important since the ARC optimizer can remove the autoreleaseRV
  returning the callee result, which makes it impossible to pair it up
  with the retainRV/claimRV call in the caller. If that fails, it simply
  emits a retain call in the IR if retainRV is attached to the call and
  does nothing if claimRV is attached to it.

- SCCP refrains from replacing the return value of a call with a
  constant value if the call has the operand bundle. This ensures the
  call always has at least one user (the call to
  @llvm.objc.clang.arc.noop.use).

- This patch also fixes a bug in replaceUsesOfNonProtoConstant where
  multiple operand bundles of the same kind were being added to a call.

Future work:

- Use the operand bundle on x86-64.

- Fix the auto upgrader to convert call+retainRV/claimRV pairs into
  calls with the operand bundles.

rdar://71443534

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

Added: 
clang/test/CodeGenObjC/arc-rv-attr.m
llvm/include/llvm/Analysis/ObjCARCUtil.h
llvm/test/Transforms/Inline/inline-retainRV-call.ll
llvm/test/Transforms/ObjCARC/contract-rv-attr.ll
llvm/test/Transforms/SCCP/clang-arc-rv.ll

Modified: 
clang/lib/CodeGen/CGObjC.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenModule.h
clang/test/CodeGenObjC/arc-unsafeclaim.m
llvm/docs/LangRef.rst
llvm/include/llvm/IR/InstrTypes.h
llvm/include/llvm/IR/Intrinsics.td
llvm/include/llvm/IR/LLVMContext.h
llvm/lib/Analysis/ObjCARCInstKind.cpp
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
llvm/lib/IR/AutoUpgrade.cpp
llvm/lib/IR/Instructions.cpp
llvm/lib/IR/LLVMContext.cpp
llvm/lib/IR/Verifier.cpp
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
llvm/lib/Transforms/ObjCARC/ARCRuntimeEntryPoints.h
llvm/lib/Transforms/ObjCARC/ObjCARC.cpp
llvm/lib/Transforms/ObjCARC/ObjCARC.h
llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp
llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
llvm/lib/Transforms/ObjCARC/PtrState.cpp
llvm/lib/Transforms/ObjCARC/PtrState.h
llvm/lib/Transforms/Scalar/SCCP.cpp
llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp
llvm/lib/Transforms/Utils/InlineFunction.cpp
llvm/test/Bitcode/operand-bundles-bc-analyzer.ll
llvm/test/CodeGen/AArch64/call-rv-marker.ll
llvm/test/Transforms/DeadArgElim/deadretval.ll
llvm/test/Transforms/ObjCARC/contract-marker-funclet.ll
llvm/test/Transforms/ObjCARC/contract.ll
llvm/test/Transform

[PATCH] D92808: [ObjC][ARC] Use operand bundle 'clang.arc.attachedcall' instead of explicitly emitting retainRV or claimRV calls in the IR

2021-02-12 Thread Akira Hatanaka 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 rGed4718eccb12: [ObjC][ARC] Use operand bundle 
'clang.arc.attachedcall' instead of (authored by ahatanak).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92808

Files:
  clang/lib/CodeGen/CGObjC.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/test/CodeGenObjC/arc-rv-attr.m
  clang/test/CodeGenObjC/arc-unsafeclaim.m
  llvm/docs/LangRef.rst
  llvm/include/llvm/Analysis/ObjCARCUtil.h
  llvm/include/llvm/IR/InstrTypes.h
  llvm/include/llvm/IR/Intrinsics.td
  llvm/include/llvm/IR/LLVMContext.h
  llvm/lib/Analysis/ObjCARCInstKind.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/lib/IR/Instructions.cpp
  llvm/lib/IR/LLVMContext.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/lib/Transforms/ObjCARC/ARCRuntimeEntryPoints.h
  llvm/lib/Transforms/ObjCARC/ObjCARC.cpp
  llvm/lib/Transforms/ObjCARC/ObjCARC.h
  llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp
  llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
  llvm/lib/Transforms/ObjCARC/PtrState.cpp
  llvm/lib/Transforms/ObjCARC/PtrState.h
  llvm/lib/Transforms/Scalar/SCCP.cpp
  llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp
  llvm/lib/Transforms/Utils/InlineFunction.cpp
  llvm/test/Bitcode/operand-bundles-bc-analyzer.ll
  llvm/test/CodeGen/AArch64/call-rv-marker.ll
  llvm/test/Transforms/DeadArgElim/deadretval.ll
  llvm/test/Transforms/Inline/inline-retainRV-call.ll
  llvm/test/Transforms/ObjCARC/contract-marker-funclet.ll
  llvm/test/Transforms/ObjCARC/contract-rv-attr.ll
  llvm/test/Transforms/ObjCARC/contract.ll
  llvm/test/Transforms/ObjCARC/intrinsic-use.ll
  llvm/test/Transforms/ObjCARC/rv.ll
  llvm/test/Transforms/SCCP/clang-arc-rv.ll
  llvm/test/Transforms/TailCallElim/deopt-bundle.ll
  llvm/test/Verifier/operand-bundles.ll

Index: llvm/test/Verifier/operand-bundles.ll
===
--- llvm/test/Verifier/operand-bundles.ll
+++ llvm/test/Verifier/operand-bundles.ll
@@ -1,10 +1,13 @@
 ; RUN: not opt -verify < %s 2>&1 | FileCheck %s
 
+%0 = type opaque
+declare void @g()
+declare %0* @foo0()
+declare i8 @foo1()
+
 ; Operand bundles uses are like regular uses, and need to be dominated
 ; by their defs.
 
-declare void @g()
-
 define void @f0(i32* %ptr) {
 ; CHECK: Instruction does not dominate all uses!
 ; CHECK-NEXT:  %x = add i32 42, 1
@@ -60,3 +63,15 @@
   %x = add i32 42, 1
   ret void
 }
+
+define void @f_clang_arc_attachedcall() {
+; CHECK: Multiple "clang.arc.attachedcall" operand bundles
+; CHECK-NEXT: call %0* @foo0() [ "clang.arc.attachedcall"(i64 0), "clang.arc.attachedcall"(i64 0) ]
+; CHECK-NEXT: must call a function returning a pointer
+; CHECK-NEXT: call i8 @foo1() [ "clang.arc.attachedcall"(i64 0) ]
+
+  call %0* @foo0() [ "clang.arc.attachedcall"(i64 0) ]
+  call %0* @foo0() [ "clang.arc.attachedcall"(i64 0), "clang.arc.attachedcall"(i64 0) ]
+  call i8 @foo1() [ "clang.arc.attachedcall"(i64 0) ]
+  ret void
+}
Index: llvm/test/Transforms/TailCallElim/deopt-bundle.ll
===
--- llvm/test/Transforms/TailCallElim/deopt-bundle.ll
+++ llvm/test/Transforms/TailCallElim/deopt-bundle.ll
@@ -55,3 +55,13 @@
 exit:
   ret void
 }
+
+; CHECK-LABEL: @test_clang_arc_attachedcall(
+; CHECK: tail call i8* @getObj(
+
+declare i8* @getObj()
+
+define i8* @test_clang_arc_attachedcall() {
+  %r = call i8* @getObj() [ "clang.arc.attachedcall"(i64 0) ]
+  ret i8* %r
+}
Index: llvm/test/Transforms/SCCP/clang-arc-rv.ll
===
--- /dev/null
+++ llvm/test/Transforms/SCCP/clang-arc-rv.ll
@@ -0,0 +1,24 @@
+; RUN: opt < %s -ipsccp -S | FileCheck %s
+; Return value can't be zapped if there is a call that has operand bundle
+; "clang.arc.attachedcall".
+
+@g0 = global i8 zeroinitializer, align 1
+
+; CHECK-LABEL: @foo(
+; CHECK: ret i8* @g0
+
+define internal i8* @foo() {
+  ret i8* @g0
+}
+
+; CHECK-LABEL: @test(
+; CHECK: %[[R:.*]] = call i8* @foo()
+; CHECK call void (...) @llvm.objc.clang.arc.noop.use(i8* %[[R]])
+
+define void @test() {
+  %r = call i8* @foo() [ "clang.arc.attachedcall"(i64 1) ]
+  call void (...) @llvm.objc.clang.arc.noop.use(i8* %r)
+  ret void
+}
+
+declare void @llvm.objc.clang.arc.noop.use(...)
Index: llvm/test/Transforms/ObjCARC/rv.ll
===
--- llvm/test/Transforms/ObjCARC/rv.ll
+++ llvm/test/Transforms/ObjCARC/rv.ll
@@ -11,6 +11,7 @@
 declare void @llvm.objc.autoreleasePoolPop(i8*)
 declare void @llvm.objc.autoreleasePoolPush()
 declare i8* @llvm.objc.retainBlock(i8*)
+declare void @llvm.objc.clang.arc.noop.use(...)
 
 de

[PATCH] D94554: [clangd] Add a Filesystem that overlays Dirty files.

2021-02-12 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 323378.
njames93 added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94554

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/DraftStore.cpp
  clang-tools-extra/clangd/DraftStore.h
  clang-tools-extra/clangd/unittests/DraftStoreTests.cpp

Index: clang-tools-extra/clangd/unittests/DraftStoreTests.cpp
===
--- clang-tools-extra/clangd/unittests/DraftStoreTests.cpp
+++ clang-tools-extra/clangd/unittests/DraftStoreTests.cpp
@@ -52,8 +52,8 @@
 llvm::Expected Result =
 DS.updateDraft(Path, llvm::None, {Event});
 ASSERT_TRUE(!!Result);
-EXPECT_EQ(Result->Contents, SrcAfter.code());
-EXPECT_EQ(DS.getDraft(Path)->Contents, SrcAfter.code());
+EXPECT_EQ(*Result->Contents, SrcAfter.code());
+EXPECT_EQ(*DS.getDraft(Path)->Contents, SrcAfter.code());
 EXPECT_EQ(Result->Version, static_cast(i));
   }
 }
@@ -84,8 +84,8 @@
   DS.updateDraft(Path, llvm::None, Changes);
 
   ASSERT_TRUE(!!Result) << llvm::toString(Result.takeError());
-  EXPECT_EQ(Result->Contents, FinalSrc.code());
-  EXPECT_EQ(DS.getDraft(Path)->Contents, FinalSrc.code());
+  EXPECT_EQ(*Result->Contents, FinalSrc.code());
+  EXPECT_EQ(*DS.getDraft(Path)->Contents, FinalSrc.code());
   EXPECT_EQ(Result->Version, 1);
 }
 
@@ -345,7 +345,7 @@
 
   Optional Contents = DS.getDraft(File);
   EXPECT_TRUE(Contents);
-  EXPECT_EQ(Contents->Contents, OriginalContents);
+  EXPECT_EQ(*Contents->Contents, OriginalContents);
   EXPECT_EQ(Contents->Version, 0);
 }
 
Index: clang-tools-extra/clangd/DraftStore.h
===
--- clang-tools-extra/clangd/DraftStore.h
+++ clang-tools-extra/clangd/DraftStore.h
@@ -11,6 +11,7 @@
 
 #include "Protocol.h"
 #include "support/Path.h"
+#include "support/ThreadsafeFS.h"
 #include "clang/Basic/LLVM.h"
 #include "llvm/ADT/StringMap.h"
 #include 
@@ -20,6 +21,20 @@
 namespace clang {
 namespace clangd {
 
+/// A Reference counted string that is used to hold the contents of open files.
+class RefCntString : public llvm::ThreadSafeRefCountedBase {
+public:
+  RefCntString(std::string Str) : Data(std::move(Str)) {}
+
+  StringRef str() const { return Data; }
+
+  operator const std::string &() const { return Data; }
+  operator StringRef() const { return str(); }
+
+private:
+  std::string Data;
+};
+
 /// A thread-safe container for files opened in a workspace, addressed by
 /// filenames. The contents are owned by the DraftStore. This class supports
 /// both whole and incremental updates of the documents.
@@ -28,10 +43,14 @@
 class DraftStore {
 public:
   struct Draft {
-std::string Contents;
+llvm::IntrusiveRefCntPtr Contents;
 int64_t Version = -1;
   };
 
+  DraftStore(const ThreadsafeFS &BaseFS);
+
+  DraftStore() = default;
+
   /// \return Contents of the stored document.
   /// For untracked files, a llvm::None is returned.
   llvm::Optional getDraft(PathRef File) const;
@@ -59,9 +78,20 @@
   /// Remove the draft from the store.
   void removeDraft(PathRef File);
 
+  const ThreadsafeFS &getDraftFS() const {
+assert(DraftFS && "No draft fs has been set up");
+return *DraftFS;
+  }
+
 private:
+  struct DraftAndTime {
+Draft Draft;
+llvm::sys::TimePoint<> MTime;
+  };
+  class DraftstoreFS;
+  std::unique_ptr DraftFS;
   mutable std::mutex Mutex;
-  llvm::StringMap Drafts;
+  llvm::StringMap Drafts;
 };
 
 } // namespace clangd
Index: clang-tools-extra/clangd/DraftStore.cpp
===
--- clang-tools-extra/clangd/DraftStore.cpp
+++ clang-tools-extra/clangd/DraftStore.cpp
@@ -9,7 +9,9 @@
 #include "DraftStore.h"
 #include "SourceCode.h"
 #include "support/Logger.h"
+#include "llvm/Support/Chrono.h"
 #include "llvm/Support/Errc.h"
+#include 
 
 namespace clang {
 namespace clangd {
@@ -21,7 +23,7 @@
   if (It == Drafts.end())
 return None;
 
-  return It->second;
+  return It->second.Draft;
 }
 
 std::vector DraftStore::getActiveFiles() const {
@@ -47,14 +49,19 @@
   }
 }
 
+static void updateTime(llvm::sys::TimePoint<> &Time) {
+  Time = llvm::sys::TimePoint<>::clock::now();
+}
+
 int64_t DraftStore::addDraft(PathRef File, llvm::Optional Version,
  llvm::StringRef Contents) {
   std::lock_guard Lock(Mutex);
 
-  Draft &D = Drafts[File];
-  updateVersion(D, Version);
-  D.Contents = Contents.str();
-  return D.Version;
+  DraftAndTime &D = Drafts[File];
+  updateVersion(D.Draft, Version);
+  updateTime(D.MTime);
+  D.Draft.Contents = llvm::makeIntrusiveRefCnt(Contents.str());
+  return D.Draft.Version;
 }
 
 llvm::Expected DraftStore::updateDraft(
@@ -68,8 +75,8 @@
  "Trying to do incremental

[PATCH] D95043: [clangd] Use Dirty Filesystem for cross file rename.

2021-02-12 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 323379.
njames93 added a comment.

Rebase and fix up tests after changes to rename.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95043

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

Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -33,6 +33,19 @@
 using testing::UnorderedElementsAre;
 using testing::UnorderedElementsAreArray;
 
+llvm::IntrusiveRefCntPtr
+createOverlay(llvm::IntrusiveRefCntPtr Base,
+  llvm::IntrusiveRefCntPtr Overlay) {
+  auto OFS =
+  llvm::makeIntrusiveRefCnt(std::move(Base));
+  OFS->pushOverlay(std::move(Overlay));
+  return OFS;
+}
+
+llvm::IntrusiveRefCntPtr getVFSFromAST(ParsedAST &AST) {
+  return &AST.getSourceManager().getFileManager().getVirtualFileSystem();
+}
+
 // Convert a Range to a Ref.
 Ref refWithRange(const clangd::Range &Range, const std::string &URI) {
   Ref Result;
@@ -815,7 +828,8 @@
 auto Index = TU.index();
 for (const auto &RenamePos : Code.points()) {
   auto RenameResult =
-  rename({RenamePos, NewName, AST, testPath(TU.Filename), Index.get()});
+  rename({RenamePos, NewName, AST, testPath(TU.Filename),
+  getVFSFromAST(AST), Index.get()});
   ASSERT_TRUE(bool(RenameResult)) << RenameResult.takeError();
   ASSERT_EQ(1u, RenameResult->GlobalChanges.size());
   EXPECT_EQ(
@@ -1072,7 +1086,8 @@
 }
 auto AST = TU.build();
 llvm::StringRef NewName = Case.NewName;
-auto Results = rename({T.point(), NewName, AST, testPath(TU.Filename)});
+auto Results = rename(
+{T.point(), NewName, AST, testPath(TU.Filename), getVFSFromAST(AST)});
 bool WantRename = true;
 if (T.ranges().empty())
   WantRename = false;
@@ -1101,13 +1116,20 @@
   auto AST = TU.build();
 
   auto Main = testPath("main.cc");
+  auto InMemFS = llvm::makeIntrusiveRefCnt();
+  InMemFS->addFile(testPath("main.cc"), 0,
+   llvm::MemoryBuffer::getMemBuffer(Code.code()));
+  InMemFS->addFile(testPath("other.cc"), 0,
+   llvm::MemoryBuffer::getMemBuffer(Code.code()));
 
   auto Rename = [&](const SymbolIndex *Idx) {
-auto GetDirtyBuffer = [&](PathRef Path) -> llvm::Optional {
-  return Code.code().str(); // Every file has the same content.
-};
-RenameInputs Inputs{Code.point(), "xPrime",AST,   Main,
-Idx,  RenameOptions(), GetDirtyBuffer};
+RenameInputs Inputs{Code.point(),
+"xPrime",
+AST,
+Main,
+createOverlay(getVFSFromAST(AST), InMemFS),
+Idx,
+RenameOptions()};
 auto Results = rename(Inputs);
 EXPECT_TRUE(bool(Results)) << llvm::toString(Results.takeError());
 return std::move(*Results);
@@ -1156,8 +1178,8 @@
   auto AST = TU.build();
   llvm::StringRef NewName = "abcde";
 
-  auto RenameResult =
-  rename({Code.point(), NewName, AST, testPath(TU.Filename)});
+  auto RenameResult = rename(
+  {Code.point(), NewName, AST, testPath(TU.Filename), getVFSFromAST(AST)});
   ASSERT_TRUE(bool(RenameResult)) << RenameResult.takeError() << Code.point();
   ASSERT_EQ(1u, RenameResult->GlobalChanges.size());
   EXPECT_EQ(applyEdits(std::move(RenameResult->GlobalChanges)).front().second,
@@ -1173,7 +1195,8 @@
   )cpp";
   TU.HeaderFilename = "protobuf.pb.h";
   auto AST = TU.build();
-  auto Results = rename({Code.point(), "newName", AST, testPath(TU.Filename)});
+  auto Results = rename({Code.point(), "newName", AST, testPath(TU.Filename),
+ getVFSFromAST(AST)});
   EXPECT_FALSE(Results);
   EXPECT_THAT(llvm::toString(Results.takeError()),
   testing::HasSubstr("not a supported kind"));
@@ -1237,25 +1260,19 @@
 
   Annotations MainCode("class  [[Fo^o]] {};");
   auto MainFilePath = testPath("main.cc");
-  // Dirty buffer for foo.cc.
-  auto GetDirtyBuffer = [&](PathRef Path) -> llvm::Optional {
-if (Path == FooPath)
-  return FooDirtyBuffer.code().str();
-return llvm::None;
-  };
+  llvm::IntrusiveRefCntPtr InMemFS =
+  new llvm::vfs::InMemoryFileSystem;
+  InMemFS->addFile(FooPath, 0,
+   llvm::MemoryBuffer::getMemBuffer(FooDirtyBuffer.code()));
 
   // Run rename on Foo, there is a dirty buffer for foo.cc, rename should
   // respect the dirty buffer.
   TestTU TU = TestTU::withCode(MainCode.code());
   auto AST = TU.build();
   llvm

[PATCH] D96611: [analyzer][tests] Fix issue comparison script

2021-02-12 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

Thx!~




Comment at: clang/utils/analyzer/CmpRuns.py:401-402
+
+old = filter_issues(old, common)
+new = filter_issues(new, common)
+common = set()

If `old` and `new` were sets from the beginning we could have turned this into 
`old = old - common` etc. and it would have been kinda neat.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96611

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


[PATCH] D96616: [OpenCL][Docs] Change documentation for the OpenCL standard headers

2021-02-12 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia created this revision.
Anastasia added a reviewer: svenvh.
Herald added subscribers: ebevhan, yaxunl.
Anastasia requested review of this revision.

After updating the user interface (https://reviews.llvm.org/D96515), make sure 
the doc reflects the change.


https://reviews.llvm.org/D96616

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

Index: clang/docs/UsersManual.rst
===
--- clang/docs/UsersManual.rst
+++ clang/docs/UsersManual.rst
@@ -2934,35 +2934,20 @@
 
 Some extra options are available to support special OpenCL features.
 
-.. option:: -finclude-default-header
+.. _opencl_cl_no_stdinc:
 
-Adds most of builtin types and function declarations during compilations. By
-default the OpenCL headers are not loaded and therefore certain builtin
-types and most of builtin functions are not declared. To load them
-automatically this flag can be passed to the frontend (see also :ref:`the
-section on the OpenCL Header `):
+.. option:: -cl-no-stdinc
 
-   .. code-block:: console
-
- $ clang -Xclang -finclude-default-header test.cl
-
-Note that this is a frontend-only flag and therefore it requires the use of
-flags that forward options to the frontend, e.g. ``-cc1`` or ``-Xclang``.
-
-Alternatively the internal header `opencl-c.h` containing the declarations
-can be included manually using ``-include`` or ``-I`` followed by the path
-to the header location. The header can be found in the clang source tree or
-installation directory.
+Allows to disable all extra types and functions that are not native to the compiler.
+This might reduce the compilation speed marginally but many declaration from the
+OpenCL standard won't be accessible i.e. the following example will fail to compile.
 
.. code-block:: console
 
- $ clang -I/lib/Headers/opencl-c.h test.cl
- $ clang -I/lib/clang//include/opencl-c.h/opencl-c.h test.cl
-
-In this example it is assumed that the kernel code contains
-``#include `` just as a regular C include.
+ $ echo "bool is_wg_uniform(int i){return get_enqueued_local_size(i)==get_local_size(i);}" > test.cl
+ $ clang -cl-std=CL2.0 -cl-no-stdinc test.cl
 
-More options are documented in :doc:`OpenCLSupport`.
+More information about the standard types and functions is provided in :ref:``.
 
 OpenCL Targets
 --
@@ -2999,11 +2984,8 @@
 
.. code-block:: console
 
-$ clang -cc1 -triple=spir test.cl
-$ clang -cc1 -triple=spir64 test.cl
-
-  Note that this is a frontend-only target and therefore it requires the use of
-  flags that forward options to the frontend e.g. ``-cc1`` or ``-Xclang``.
+$ clang -target spir test.cl -emit-llvm -c
+$ clang -target spir64 test.cl -emit-llvm -c
 
   All known OpenCL extensions are supported in the SPIR targets. Clang will
   generate SPIR v1.2 compatible IR for OpenCL versions up to 2.0 and SPIR v2.0
@@ -3026,31 +3008,17 @@
 OpenCL Header
 -
 
-By default Clang will not include standard headers and therefore OpenCL builtin
-functions and some types (i.e. vectors) are unknown during compilation. The
-default CL header is, however, provided in the Clang installation and can be
-enabled by passing the ``-finclude-default-header`` flag (see :ref:`flags
-description ` for more details).
+By default Clang will include standard headers and therefore most of OpenCL
+builtin functions and types are available during compilation. The
+default declarations of non-native compiler types and functions can be disabled
+by using flag :ref:``.
 
.. code-block:: console
 
  $ echo "bool is_wg_uniform(int i){return get_enqueued_local_size(i)==get_local_size(i);}" > test.cl
- $ clang -Xclang -finclude-default-header -cl-std=CL2.0 test.cl
-
-Because the header is very large and long to parse, PCH (:doc:`PCHInternals`)
-and modules (:doc:`Modules`) are used internally to improve the compilation
-speed.
-
-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 -cl-std=CL2.0 test.cl
 
-Another way to circumvent long parsing latency for the OpenCL builtin
-declarations is to use mechanism enabled by ``-fdeclare-opencl-builtins`` flag
-that is available as an experimental feature (see more information in
-:doc:`OpenCLSupport`).
+More information about the default headers is provided in :doc:`OpenCLSupport`.
 
 OpenCL Extensions
 -
Index: clang/docs/OpenCLSupport.rst
===
--- clang/docs/OpenCLSupport.rst
+++ clang/docs/OpenCLSupport.rst
@@ -63,6 +63,10 @@
 In addition to the options described in :doc:`UsersManual` there are the
 following options specific to the OpenCL frontend.
 
+All the options in this section are frontend-only and therefore if used
+with regular clang driver t

[PATCH] D96515: [OpenCL] Add builtin declarations by default.

2021-02-12 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In D96515#2560280 , @Anastasia wrote:

> In D96515#2559424 , @svenvh wrote:
>
>> It probably makes sense to update `clang/docs/UsersManual.rst` as part of 
>> this change.  In particular the following sentence is no longer true after 
>> this patch: "By default the OpenCL headers are not loaded and therefore 
>> certain builtin types and most of builtin functions are not declared."
>
> Yes, that's right but I think there is a bigger change that needs to be made 
> i.e. I would completely remove `-finclude-default-header` and let it live on 
> OpenCLSupport page. I would prefer a separate review for docs though.

FYI here is the review for the docs update: https://reviews.llvm.org/D96616


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

https://reviews.llvm.org/D96515

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


[clang] 1b5c291 - [DebugInfo] Add an attribute to force type info to be emitted for

2021-02-12 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2021-02-12T10:16:49-08:00
New Revision: 1b5c2915a2318705727ada586290de15e2cad202

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

LOG: [DebugInfo] Add an attribute to force type info to be emitted for
class types.

The goal is to provide a way to bypass constructor homing when emitting
class definitions and force class definitions in the debug info.

Not sure about the wording of the attribute, or whether it should be
specific to classes with constructors

Added: 
clang/test/CodeGenCXX/debug-info-emit-as-needed-attribute.cpp

Modified: 
clang/include/clang/Basic/Attr.td
clang/lib/CodeGen/CGDebugInfo.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index bc2d8ceeeb6c..5bddef1b4ef2 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1660,6 +1660,13 @@ def NoDebug : InheritableAttr {
   let Documentation = [NoDebugDocs];
 }
 
+def DebugTypeInfoAsNeeded : InheritableAttr {
+  let Spellings = [Clang<"debug_type_info_as_needed">];
+  let Subjects = SubjectList<[CXXRecord]>;
+  let Documentation = [Undocumented];
+  let SimpleHandler = 1;
+}
+
 def NoDuplicate : InheritableAttr {
   let Spellings = [Clang<"noduplicate">];
   let Subjects = SubjectList<[Function]>;

diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 48b9bf049f48..ef17983b446a 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2344,6 +2344,10 @@ static bool 
shouldOmitDefinition(codegenoptions::DebugInfoKind DebugKind,
   if (!CXXDecl)
 return false;
 
+  // Don't omit definition if marked with attribute.
+  if (RD->hasAttr())
+return false;
+
   // Only emit complete debug info for a dynamic class when its vtable is
   // emitted.  However, Microsoft debuggers don't resolve type information
   // across DLL boundaries, so skip this optimization if the class or any of 
its

diff  --git a/clang/test/CodeGenCXX/debug-info-emit-as-needed-attribute.cpp 
b/clang/test/CodeGenCXX/debug-info-emit-as-needed-attribute.cpp
new file mode 100644
index ..a2f0eae314c8
--- /dev/null
+++ b/clang/test/CodeGenCXX/debug-info-emit-as-needed-attribute.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -DSETATTR=0 -emit-llvm -std=c++14 
-debug-info-kind=constructor %s -o - | FileCheck %s --check-prefix=DEBUG
+// RUN: %clang_cc1 -DSETATTR=1 -emit-llvm -std=c++14 
-debug-info-kind=constructor %s -o - | FileCheck %s --check-prefix=WITHATTR
+
+#if SETATTR
+#define DEBUGASNEEDED __attribute__((debug_type_info_as_needed))
+#else
+#define DEBUGASNEEDED
+#endif
+
+// Struct that isn't constructed, so its full type info should be omitted with
+// -debug-info-kind=constructor.
+struct DEBUGASNEEDED some_struct {
+  some_struct() {}
+};
+
+void func1(some_struct s) {}
+// void func2() { func1(); }
+// DEBUG:  !DICompositeType({{.*}}name: "some_struct"
+// DEBUG-SAME:  flags: {{.*}}DIFlagFwdDecl
+// WITHATTR: !DICompositeType({{.*}}name: "some_struct"
+// WITHATTR-NOT: DIFlagFwdDecl
+



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


[clang] 3fe465f - Revert "[DebugInfo] Add an attribute to force type info to be emitted for"

2021-02-12 Thread Amy Huang via cfe-commits

Author: Amy Huang
Date: 2021-02-12T10:18:17-08:00
New Revision: 3fe465fb2cd64cd7bd910c761920e3378fe8d1b0

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

LOG: Revert "[DebugInfo] Add an attribute to force type info to be emitted for"

Didn't mean to commit this.

This reverts commit 1b5c2915a2318705727ada586290de15e2cad202.

Added: 


Modified: 
clang/include/clang/Basic/Attr.td
clang/lib/CodeGen/CGDebugInfo.cpp

Removed: 
clang/test/CodeGenCXX/debug-info-emit-as-needed-attribute.cpp



diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 5bddef1b4ef2..bc2d8ceeeb6c 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1660,13 +1660,6 @@ def NoDebug : InheritableAttr {
   let Documentation = [NoDebugDocs];
 }
 
-def DebugTypeInfoAsNeeded : InheritableAttr {
-  let Spellings = [Clang<"debug_type_info_as_needed">];
-  let Subjects = SubjectList<[CXXRecord]>;
-  let Documentation = [Undocumented];
-  let SimpleHandler = 1;
-}
-
 def NoDuplicate : InheritableAttr {
   let Spellings = [Clang<"noduplicate">];
   let Subjects = SubjectList<[Function]>;

diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index ef17983b446a..48b9bf049f48 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2344,10 +2344,6 @@ static bool 
shouldOmitDefinition(codegenoptions::DebugInfoKind DebugKind,
   if (!CXXDecl)
 return false;
 
-  // Don't omit definition if marked with attribute.
-  if (RD->hasAttr())
-return false;
-
   // Only emit complete debug info for a dynamic class when its vtable is
   // emitted.  However, Microsoft debuggers don't resolve type information
   // across DLL boundaries, so skip this optimization if the class or any of 
its

diff  --git a/clang/test/CodeGenCXX/debug-info-emit-as-needed-attribute.cpp 
b/clang/test/CodeGenCXX/debug-info-emit-as-needed-attribute.cpp
deleted file mode 100644
index a2f0eae314c8..
--- a/clang/test/CodeGenCXX/debug-info-emit-as-needed-attribute.cpp
+++ /dev/null
@@ -1,22 +0,0 @@
-// RUN: %clang_cc1 -DSETATTR=0 -emit-llvm -std=c++14 
-debug-info-kind=constructor %s -o - | FileCheck %s --check-prefix=DEBUG
-// RUN: %clang_cc1 -DSETATTR=1 -emit-llvm -std=c++14 
-debug-info-kind=constructor %s -o - | FileCheck %s --check-prefix=WITHATTR
-
-#if SETATTR
-#define DEBUGASNEEDED __attribute__((debug_type_info_as_needed))
-#else
-#define DEBUGASNEEDED
-#endif
-
-// Struct that isn't constructed, so its full type info should be omitted with
-// -debug-info-kind=constructor.
-struct DEBUGASNEEDED some_struct {
-  some_struct() {}
-};
-
-void func1(some_struct s) {}
-// void func2() { func1(); }
-// DEBUG:  !DICompositeType({{.*}}name: "some_struct"
-// DEBUG-SAME:  flags: {{.*}}DIFlagFwdDecl
-// WITHATTR: !DICompositeType({{.*}}name: "some_struct"
-// WITHATTR-NOT: DIFlagFwdDecl
-



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


[PATCH] D96572: [Clang][ASan] Introduce `-fsanitize-address-destructor-kind=` driver & frontend option.

2021-02-12 Thread Dan Liew via Phabricator via cfe-commits
delcypher added a comment.

Note this patch depends on https://reviews.llvm.org/D96571


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96572

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


[PATCH] D96572: [Clang][ASan] Introduce `-fsanitize-address-destructor-kind=` driver & frontend option.

2021-02-12 Thread Dan Liew via Phabricator via cfe-commits
delcypher added inline comments.



Comment at: clang/include/clang/Driver/Options.td:1485
+def sanitize_address_destructor_kind_EQ : Joined<["-"], 
"fsanitize-address-destructor-kind=">,
+  MetaVarName<"">,
+  Flags<[CC1Option]>,

vitalybuka wrote:
> What is the difference between them and why it's need to be configured from 
> outside?
Good questions. 

> What is the difference between them

I'll add some documentation to explain this. But the two different modes are 
introduced by https://reviews.llvm.org/D96571. Basically the default ("global") 
emits ASan module destructor calls via `llvm.global_dtors` which was the 
previous behaviour. The other mode "none" simply causes no ASan module 
destructors to be emitted. I plan to introduce another mode in a future patch.

> why it's need to be configured from outside?

At the bare minimum this option needs to be controllable by the driver so that 
we can do the next patch (https://reviews.llvm.org/D96573) where based on 
target details and other flags we set the ASan destructor kind. This means that 
the frontend needs to be able to consume to option too.

It is technically not necessary for this new option to be a driver option. 
However, I made it a driver option too to match the existing ASan clang 
frontend options which are also driver options (e.g. 
`-fsanitize-address-use-odr-indicator`).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96572

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


[PATCH] D96612: [clangd] Improve printing of Objective-C categories and methods

2021-02-12 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

I'm not an objc guy, but can you add a test case demonstrating class(?) methods 
showing as `+name:`?




Comment at: clang-tools-extra/clangd/AST.cpp:224-226
+  if (const ObjCContainerDecl *C = dyn_cast(&ND))
+return printObjCContainer(*C);
+  if (const ObjCMethodDecl *Method = dyn_cast(&ND)) {

nit: Can make these `const auto *` as the type is spelt in the initialisation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96612

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


[PATCH] D85817: [analyzer] Fix crash with pointer to members values

2021-02-12 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD added a comment.

@vsavchenko, why did you chose NamedDecl instead of ValueDecl to account for 
the indirect fields? I couldn't quite follow it from the discussion above.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85817

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


[PATCH] D96588: [OpenCL] Remove FIXME in getOpenCLFeatureDefines

2021-02-12 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

> The suggestion in D92277  was to move 
> OpenCLOptions into LanguageOptions, but



> this is not viable. Sema's LangOpts is immutable, and embedding
> OpenCLOptions into LangOpts would make OpenCLOptions immutable too.
> This is incompatible with handling of pragmas that alter the
> OpenCLOptions during parsing/sema.

That's right in general `OpenCLOptions` should become a part of `LangOptions` 
as they are the same conceptually. `CompilerInvocation` has `LangOptions` as 
non-const member and it sets many of its fields. So it could do the same for 
OpenCL specific options as it also contains `TargetOptions` with 
`OpenCLFeaturesMap` so it know what the targets support and, therefore, has the 
full information needed to complete the right setup.

I agree dynamic modifications of `OpenCLOptions` via pragmas makes things more 
complicated. However, we could do something similar to  `CurFPFeatures` in 
`Sema` that duplicates some of floating point options of the `LangOptions` and 
provides the functionality of dynamic modification via pragmas too. The OpenCL 
use case is exactly the same.  In reality, very few options would need the 
pragma so the number of items in that extra data structure would be very small. 
But unfortunately, this is not where we are right now yet. Because with time a 
lot of pragma uses have been added without good justification. So perhaps it is 
not a practical refactoring at the moment. But maybe it is something we could 
still do in the future if we modify the pragma use cases?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96588

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


  1   2   >