[PATCH] D93031: Enable fexec-charset option

2021-03-01 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added inline comments.



Comment at: clang/include/clang/Driver/Options.td:3583
 
+def fexec_charset : Separate<["-"], "fexec-charset">, MetaVarName<"">,
+  HelpText<"Set the execution  for string and character literals. "

Could you switch to the option marshalling infrastructure? 
https://clang.llvm.org/docs/InternalsManual.html#adding-new-command-line-option
Adding `MarshallingInfoString>` here should do the 
trick. You can then delete the option parsing in `CompilerInvocation.cpp`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93031

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


[clang] 588db1c - [clangd] Use flags from open files when opening headers they include

2021-03-01 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2021-03-01T09:43:59+01:00
New Revision: 588db1ccff713332c1f9358f423e682f18c06e8e

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

LOG: [clangd] Use flags from open files when opening headers they include

Currently our strategy for getting header compile flags is something like:

A) look for flags for the header in compile_commands.json
   This basically never works, build systems don't generate this info.
B) try to match to an impl file in compile_commands.json and use its flags
   This only (mostly) works if the headers are in the same project.
C) give up and use fallback flags
   This kind of works for stdlib in the default configuration, and
   otherwise doesn't.

Obviously there are big gaps here.

This patch inserts a new attempt between A and B: if the header is
transitively included by any open file (whether same project or not),
then we use its compile command.

This doesn't make any attempt to solve some related problems:
 - parsing non-self-contained header files in context (importing PP state)
 - using the compile flags of non-opened candidate files found in the index

Fixes https://github.com/clangd/clangd/issues/123
Fixes https://github.com/clangd/clangd/issues/695
See https://github.com/clangd/clangd/issues/519

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

Added: 


Modified: 
clang-tools-extra/clangd/Headers.h
clang-tools-extra/clangd/TUScheduler.cpp
clang-tools-extra/clangd/TUScheduler.h
clang-tools-extra/clangd/test/memory_tree.test
clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
clang/include/clang/Tooling/CompilationDatabase.h
clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
clang/unittests/Tooling/CompilationDatabaseTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Headers.h 
b/clang-tools-extra/clangd/Headers.h
index fd9db5562813..f4ca364880c4 100644
--- a/clang-tools-extra/clangd/Headers.h
+++ b/clang-tools-extra/clangd/Headers.h
@@ -114,6 +114,9 @@ class IncludeStructure {
 public:
   std::vector MainFileIncludes;
 
+  // Return all transitively reachable files.
+  llvm::ArrayRef allHeaders() const { return RealPathNames; }
+
   // Return all transitively reachable files, and their minimum include depth.
   // All transitive includes (absolute paths), with their minimum include 
depth.
   // Root --> 0, #included file --> 1, etc.

diff  --git a/clang-tools-extra/clangd/TUScheduler.cpp 
b/clang-tools-extra/clangd/TUScheduler.cpp
index 01b583fe64f3..306f690aac63 100644
--- a/clang-tools-extra/clangd/TUScheduler.cpp
+++ b/clang-tools-extra/clangd/TUScheduler.cpp
@@ -70,12 +70,14 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Allocator.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Threading.h"
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -179,7 +181,132 @@ class TUScheduler::ASTCache {
   std::vector LRU; /* GUARDED_BY(Mut) */
 };
 
+/// A map from header files to an opened "proxy" file that includes them.
+/// If you open the header, the compile command from the proxy file is used.
+///
+/// This inclusion information could also naturally live in the index, but 
there
+/// are advantages to using open files instead:
+///  - it's easier to achieve a *stable* choice of proxy, which is important
+///to avoid invalidating the preamble
+///  - context-sensitive flags for libraries with multiple configurations
+///(e.g. C++ stdlib sensitivity to -std version)
+///  - predictable behavior, e.g. guarantees that go-to-def landing on a header
+///will have a suitable command available
+///  - fewer scaling problems to solve (project include graphs are big!)
+///
+/// Implementation details:
+/// - We only record this for mainfiles where the command was trustworthy
+///   (i.e. not inferred). This avoids a bad inference "infecting" other files.
+/// - Once we've picked a proxy file for a header, we stick with it until the
+///   proxy file is invalidated *and* a new candidate proxy file is built.
+///   Switching proxies is expensive, as the compile flags will (probably)
+///   change and therefore we'll end up rebuilding the header's preamble.
+/// - We don't capture the actual compile command, but just the filename we
+///   should query to get it. This avoids getting out of sync with the CDB.
+///
+/// All methods are threadsafe. In practice, update() comes from preamble
+/// threads, remove()s mostly from the main thread, and get() from ASTWorker.
+/// Writes are rare and reads are cheap, so we don't expect much contention.
+class TUSchedule

[PATCH] D97351: [clangd] Use flags from open files when opening headers they include

2021-03-01 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 2 inline comments as done.
Closed by commit rG588db1ccff71: [clangd] Use flags from open files when 
opening headers they include (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D97351?vs=326042&id=327037#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97351

Files:
  clang-tools-extra/clangd/Headers.h
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/TUScheduler.h
  clang-tools-extra/clangd/test/memory_tree.test
  clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
  clang/include/clang/Tooling/CompilationDatabase.h
  clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
  clang/unittests/Tooling/CompilationDatabaseTest.cpp

Index: clang/unittests/Tooling/CompilationDatabaseTest.cpp
===
--- clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -843,6 +843,18 @@
   EXPECT_EQ(getCommand("bar.h"), "clang -D bar.cpp --driver-mode=cl /TP");
 }
 
+TEST(TransferCompileCommandTest, Smoke) {
+  CompileCommand Cmd;
+  Cmd.Filename = "foo.cc";
+  Cmd.CommandLine = {"clang", "-Wall", "foo.cc"};
+  Cmd.Directory = "dir";
+  CompileCommand Transferred = transferCompileCommand(std::move(Cmd), "foo.h");
+  EXPECT_EQ(Transferred.Filename, "foo.h");
+  EXPECT_THAT(Transferred.CommandLine,
+  ElementsAre("clang", "-Wall", "-x", "c++-header", "foo.h"));
+  EXPECT_EQ(Transferred.Directory, "dir");
+}
+
 TEST(CompileCommandTest, EqualityOperator) {
   CompileCommand CCRef("/foo/bar", "hello.c", {"a", "b"}, "hello.o");
   CompileCommand CCTest = CCRef;
Index: clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
===
--- clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
+++ clang/lib/Tooling/InterpolatingCompilationDatabase.cpp
@@ -204,8 +204,10 @@
   }
 
   // Produce a CompileCommand for \p filename, based on this one.
-  CompileCommand transferTo(StringRef Filename) const {
-CompileCommand Result = Cmd;
+  // (This consumes the TransferableCommand just to avoid copying Cmd).
+  CompileCommand transferTo(StringRef Filename) && {
+CompileCommand Result = std::move(Cmd);
+Result.Heuristic = "inferred from " + Result.Filename;
 Result.Filename = std::string(Filename);
 bool TypeCertain;
 auto TargetType = guessType(Filename, &TypeCertain);
@@ -234,7 +236,6 @@
   LangStandard::getLangStandardForKind(Std).getName()).str());
 }
 Result.CommandLine.push_back(std::string(Filename));
-Result.Heuristic = "inferred from " + Cmd.Filename;
 return Result;
   }
 
@@ -521,7 +522,7 @@
 Inner->getCompileCommands(Index.chooseProxy(Filename, foldType(Lang)));
 if (ProxyCommands.empty())
   return {};
-return {TransferableCommand(ProxyCommands[0]).transferTo(Filename)};
+return {transferCompileCommand(std::move(ProxyCommands.front()), Filename)};
   }
 
   std::vector getAllFiles() const override {
@@ -544,5 +545,10 @@
   return std::make_unique(std::move(Inner));
 }
 
+tooling::CompileCommand transferCompileCommand(CompileCommand Cmd,
+   StringRef Filename) {
+  return TransferableCommand(std::move(Cmd)).transferTo(Filename);
+}
+
 } // namespace tooling
 } // namespace clang
Index: clang/include/clang/Tooling/CompilationDatabase.h
===
--- clang/include/clang/Tooling/CompilationDatabase.h
+++ clang/include/clang/Tooling/CompilationDatabase.h
@@ -213,6 +213,12 @@
   std::vector CompileCommands;
 };
 
+/// Transforms a compile command so that it applies the same configuration to
+/// a different file. Most args are left intact, but tweaks may be needed
+/// to certain flags (-x, -std etc).
+tooling::CompileCommand transferCompileCommand(tooling::CompileCommand,
+   StringRef Filename);
+
 /// Returns a wrapped CompilationDatabase that defers to the provided one,
 /// but getCompileCommands() will infer commands for unknown files.
 /// The return value of getAllFiles() or getAllCompileCommands() is unchanged.
Index: clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
===
--- clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
+++ clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
@@ -9,6 +9,7 @@
 #include "Annotations.h"
 #include "ClangdServer.h"
 #include "Diagnostics.h"
+#include "GlobalCompilationDatabase.h"
 #include "Matchers.h"
 #include "ParsedAST.h"
 #include "Preamble.h"
@@ -43,12 +44,15 @@
 namespace clangd {
 namespace {
 
+using ::testing::AllOf;
 using ::

[PATCH] D87928: Provide -fsource-dir flag in Clang

2021-03-01 Thread Petr Hosek via Phabricator via cfe-commits
phosek abandoned this revision.
phosek added a comment.

No longer needed with `-fcoverage-compilation-dir`.


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

https://reviews.llvm.org/D87928

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


[PATCH] D97457: [flang][driver] Add `-fdebug-dump-parsing-log`

2021-03-01 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski updated this revision to Diff 327048.
awarzynski marked an inline comment as done.
awarzynski added a comment.

Move the call to setUpFrontendBasedOnAction after all options have been set


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97457

Files:
  clang/include/clang/Driver/Options.td
  flang/include/flang/Frontend/FrontendActions.h
  flang/include/flang/Frontend/FrontendOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  flang/test/Flang-Driver/debug-parsing-log.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/tools/f18/f18.cpp

Index: flang/tools/f18/f18.cpp
===
--- flang/tools/f18/f18.cpp
+++ flang/tools/f18/f18.cpp
@@ -536,7 +536,8 @@
   driver.debugModuleWriter = true;
 } else if (arg == "-fdebug-measure-parse-tree") {
   driver.measureTree = true;
-} else if (arg == "-fdebug-instrumented-parse") {
+} else if (arg == "-fdebug-instrumented-parse" ||
+arg == "-fdebug-dump-parsing-log") {
   options.instrumentedParse = true;
 } else if (arg == "-fdebug-no-semantics") {
   driver.debugNoSemantics = true;
Index: flang/test/Flang-Driver/driver-help.f90
===
--- flang/test/Flang-Driver/driver-help.f90
+++ flang/test/Flang-Driver/driver-help.f90
@@ -58,6 +58,8 @@
 ! HELP-FC1-NEXT: Enable the old style PARAMETER statement
 ! HELP-FC1-NEXT: -fbackslashSpecify that backslash in string introduces an escape character
 ! HELP-FC1-NEXT: -fdebug-dump-parse-tree Dump the parse tree
+! HELP-FC1-NEXT: -fdebug-dump-parsing-log
+! HELP-FC1-NEXT:   Run instrumented parse and dump the parsing log
 ! HELP-FC1-NEXT: -fdebug-dump-provenance Dump provenance
 ! HELP-FC1-NEXT: -fdebug-dump-symbolsDump symbols after the semantic analysis
 ! HELP-FC1-NEXT: -fdebug-measure-parse-tree
Index: flang/test/Flang-Driver/debug-parsing-log.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/debug-parsing-log.f90
@@ -0,0 +1,24 @@
+! RUN: %flang_fc1 -fdebug-dump-parsing-log %s  2>&1 | FileCheck %s
+
+!-
+! EXPECTED OUTPUT
+!-
+! Below are just few lines extracted from the dump. The actual output is much _much_ bigger.
+
+! CHECK: MODULE statement
+! CHECK:   fail 1
+! CHECK: module
+! CHECK:   fail 1
+! CHECK: END PROGRAM statement
+! CHECK:   pass 1
+! CHECK: PROGRAM statement
+! CHECK:   fail 1
+! CHECK: main program
+! CHECK:   pass 1
+! CHECK: specification construct
+! CHECK:   fail 2
+
+!-
+! TEST INPUT
+!-
+END PROGRAM
Index: flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -52,6 +52,9 @@
   case DebugDumpProvenance:
 return std::make_unique();
 break;
+  case DebugDumpParsingLog:
+return std::make_unique();
+break;
   case DebugMeasureParseTree:
 return std::make_unique();
 break;
Index: flang/lib/Frontend/FrontendActions.cpp
===
--- flang/lib/Frontend/FrontendActions.cpp
+++ flang/lib/Frontend/FrontendActions.cpp
@@ -307,6 +307,13 @@
   }
 }
 
+void DebugDumpParsingLogAction::ExecuteAction() {
+  CompilerInstance &ci = this->instance();
+
+  ci.parsing().Parse(llvm::errs());
+  ci.parsing().DumpParsingLog(llvm::outs());
+}
+
 void EmitObjAction::ExecuteAction() {
   CompilerInstance &ci = this->instance();
   unsigned DiagID = ci.diagnostics().getCustomDiagID(
Index: flang/lib/Frontend/CompilerInvocation.cpp
===
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -85,6 +85,15 @@
   return true;
 }
 
+// Tweak the frontend configuration based on the frontend action
+static void setUpFrontendBasedOnAction(FrontendOptions &opts) {
+  assert(opts.programAction_ != Fortran::frontend::InvalidAction &&
+  "Fortran frontend action not set!");
+
+  if (opts.programAction_ == DebugDumpParsingLog)
+opts.instrumentedParse_ = true;
+}
+
 static InputKind ParseFrontendArgs(FrontendOptions &opts,
 llvm::opt::ArgList &args, clang::DiagnosticsEngine &diags) {
 
@@ -125,6 +134,9 @@
 case clang::driver::options::OPT_fdebug_dump_provenance:
   opts.programAction_ = DebugDumpProvenance;
   break;
+case clang::driver::options::OPT_fdebug_dump_parsing_log:
+  opts.programAction_ = DebugDumpParsingLog;
+  break;
 case clang::driver::options::OPT_fdebug_measure_parse_tree:
   opts.programAction_ = DebugMeasureParseTree

[PATCH] D97457: [flang][driver] Add `-fdebug-dump-parsing-log`

2021-03-01 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added inline comments.



Comment at: flang/lib/Frontend/CompilerInvocation.cpp:88-95
+// Tweak the frontend configuration based on the frontend action
+static void setUpFrontendBasedOnAction(FrontendOptions &opts) {
+  assert(opts.programAction_ != Fortran::frontend::InvalidAction &&
+  "Fortran frontend action not set!");
+
+  if (opts.programAction_ == DebugDumpParsingLog)
+opts.instrumentedParse_ = true;

AMDChirag wrote:
> awarzynski wrote:
> > AMDChirag wrote:
> > > Will this function be extended in the future?
> > > If not, an entirely separate function for a couple statements seems 
> > > rather overkill.
> > > Will this function be extended in the future?
> > 
> > Yes.
> > 
> > Ideally we'd want _features_ and _actions_ to be orthogonal and to be 
> > controlled by dedicated flags. In this patch, we are adding an _action_ 
> > flag that toggles a _feature_ option. I think that that's a bit 
> > counter-intuitive, but not uncommon or unavoidable long-term.
> > 
> > Instead of adding comments, I prefer to introduce a dedicated method for 
> > this logic. It will make it easier for us to keep it in one place when new 
> > options like this are added.  Also, `ParseFrontendArgs` is already quite 
> > long and is only going to get longer.
> > 
> > Having said all that, we may decide in the future that there's a better way 
> > to split this logic. For now I mostly want to avoid extending 
> > `ParseFrontendArgs` too much. 
> Fair, thank you for explaining!
> 
> In such case, shouldn't the function call `setUpFrontendBasedOnAction(opts);` 
> be placed after all the fields of the `opts` variable have been set?
Thanks for the suggestion, updated!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97457

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


[clang] 80e8efd - Use a fast path when initializing LineOffsetMapping

2021-03-01 Thread via cfe-commits

Author: serge-sans-paille
Date: 2021-03-01T10:18:36+01:00
New Revision: 80e8efd563fda4d7b125b834d3243b3ef9a05270

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

LOG: Use a fast path when initializing LineOffsetMapping

Use the fact that the number of line break is lower than printable characters to
guide the optimization process. Also use a fuzzy test that catches both \n and
\r in a single check to speedup the computation.

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

Added: 


Modified: 
clang/lib/Basic/SourceManager.cpp

Removed: 




diff  --git a/clang/lib/Basic/SourceManager.cpp 
b/clang/lib/Basic/SourceManager.cpp
index c0b22837693b..cc275d4e8dc4 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -1270,13 +1270,16 @@ LineOffsetMapping 
LineOffsetMapping::get(llvm::MemoryBufferRef Buffer,
   const std::size_t BufLen = End - Buf;
   unsigned I = 0;
   while (I < BufLen) {
-if (Buf[I] == '\n') {
-  LineOffsets.push_back(I + 1);
-} else if (Buf[I] == '\r') {
-  // If this is \r\n, skip both characters.
-  if (I + 1 < BufLen && Buf[I + 1] == '\n')
-++I;
-  LineOffsets.push_back(I + 1);
+// Use a fast check to catch both newlines
+if (LLVM_UNLIKELY(Buf[I] <= std::max('\n', '\r'))) {
+  if (Buf[I] == '\n') {
+LineOffsets.push_back(I + 1);
+  } else if (Buf[I] == '\r') {
+// If this is \r\n, skip both characters.
+if (I + 1 < BufLen && Buf[I + 1] == '\n')
+  ++I;
+LineOffsets.push_back(I + 1);
+  }
 }
 ++I;
   }



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


[PATCH] D97320: Use a fast path when initializing LineOffsetMapping

2021-03-01 Thread serge 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 rG80e8efd563fd: Use a fast path when initializing 
LineOffsetMapping (authored by serge-sans-paille).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97320

Files:
  clang/lib/Basic/SourceManager.cpp


Index: clang/lib/Basic/SourceManager.cpp
===
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -1270,13 +1270,16 @@
   const std::size_t BufLen = End - Buf;
   unsigned I = 0;
   while (I < BufLen) {
-if (Buf[I] == '\n') {
-  LineOffsets.push_back(I + 1);
-} else if (Buf[I] == '\r') {
-  // If this is \r\n, skip both characters.
-  if (I + 1 < BufLen && Buf[I + 1] == '\n')
-++I;
-  LineOffsets.push_back(I + 1);
+// Use a fast check to catch both newlines
+if (LLVM_UNLIKELY(Buf[I] <= std::max('\n', '\r'))) {
+  if (Buf[I] == '\n') {
+LineOffsets.push_back(I + 1);
+  } else if (Buf[I] == '\r') {
+// If this is \r\n, skip both characters.
+if (I + 1 < BufLen && Buf[I + 1] == '\n')
+  ++I;
+LineOffsets.push_back(I + 1);
+  }
 }
 ++I;
   }


Index: clang/lib/Basic/SourceManager.cpp
===
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -1270,13 +1270,16 @@
   const std::size_t BufLen = End - Buf;
   unsigned I = 0;
   while (I < BufLen) {
-if (Buf[I] == '\n') {
-  LineOffsets.push_back(I + 1);
-} else if (Buf[I] == '\r') {
-  // If this is \r\n, skip both characters.
-  if (I + 1 < BufLen && Buf[I + 1] == '\n')
-++I;
-  LineOffsets.push_back(I + 1);
+// Use a fast check to catch both newlines
+if (LLVM_UNLIKELY(Buf[I] <= std::max('\n', '\r'))) {
+  if (Buf[I] == '\n') {
+LineOffsets.push_back(I + 1);
+  } else if (Buf[I] == '\r') {
+// If this is \r\n, skip both characters.
+if (I + 1 < BufLen && Buf[I + 1] == '\n')
+  ++I;
+LineOffsets.push_back(I + 1);
+  }
 }
 ++I;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97615: [clangd] Include macro expansions in documentSymbol hierarchy

2021-03-01 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

thanks, LGTM. with a couple nits and asking for some extra clarifications :)




Comment at: clang-tools-extra/clangd/FindSymbols.cpp:283
+  public:
+SymBuilder() = default;
+

nit: drop this one?



Comment at: clang-tools-extra/clangd/FindSymbols.cpp:290
+// This can fix some edge-cases in the AST, but is vital for macros.
+// (We determine macro hierarchy using primary location only, and in
+// general macros need not nest with AST nodes).

this comment feels a little out-of-place, maybe move it next to 
`possibleMacroContainer` call?



Comment at: clang-tools-extra/clangd/FindSymbols.cpp:327
+  Sym.selectionRange = halfOpenToRange(SM, Tok.range(SM).toCharRange(SM));
+  if (Exp)
+Sym.range = halfOpenToRange(SM, CharSourceRange::getCharRange(

nit:
```
Sym.range = Sym.selectionRange = halfOpenToRange(SM, 
Tok.range(SM).toCharRange(SM));
if (Exp) {
  Sym.range =  // cover Exp;
  // Populate Sym.detail.
}
```



Comment at: clang-tools-extra/clangd/FindSymbols.cpp:402
+
+  // Determines where a decl should appear in the DocumentSymbol hierarchy.
+  //

also mention that `there's at most one node for each macro invocation in the 
document symbol hierarchy, even if it yields multiple decls`



Comment at: clang-tools-extra/clangd/FindSymbols.cpp:424
+ Loc = SM.getImmediateMacroCallerLoc(Loc)) {
+  FileID MacroBody;
+  if (SM.isMacroArgExpansion(Loc)) {

nit:
```
SourceLocation ExpansionLoc = Loc;
// If ExpansionLoc is inside a macro argument, use the outer macro invocation 
instead. e.g:
//#define ID(X) X
//ID(int y); // chose location of ID, not X
if(SM.isMacroArgExpansion(ExpansionLoc))
  ExpansionLoc = SM.getImmediateExpansionRange(Loc).getBegin();
FileID MacroBody = SM.getFileID(ExpansionLoc);
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97615

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


[PATCH] D97669: [clang][AVR] Add avr-libc/include to clang system include paths

2021-03-01 Thread Ben Shi via Phabricator via cfe-commits
benshi001 created this revision.
benshi001 added reviewers: dylanmckay, MaskRay, aykevl.
Herald added a subscriber: Jim.
benshi001 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97669

Files:
  clang/lib/Driver/ToolChains/AVR.cpp
  clang/lib/Driver/ToolChains/AVR.h
  clang/test/Driver/Inputs/basic_avr_tree/usr/lib/avr/include/stdio.h
  clang/test/Driver/avr-toolchain.c


Index: clang/test/Driver/avr-toolchain.c
===
--- clang/test/Driver/avr-toolchain.c
+++ clang/test/Driver/avr-toolchain.c
@@ -2,3 +2,12 @@
 
 // RUN: %clang %s -### -no-canonical-prefixes -target avr 2>&1 | FileCheck 
-check-prefix=CC1 %s
 // CC1: clang{{.*}} "-cc1" "-triple" "avr"
+
+// RUN: %clang %s -### -target avr --sysroot %S/Inputs/basic_avr_tree 2>&1 | 
FileCheck -check-prefix CC1A %s
+// CC1A: clang{{.*}} "-cc1" "-triple" "avr" {{.*}} "-internal-isystem" 
{{".*avr/include"}}
+
+// RUN: %clang %s -### -target avr --sysroot %S/Inputs/basic_avr_tree 2>&1 
-nostdinc | FileCheck -check-prefix CC1B %s
+// CC1B-NOT: "-internal-isystem" {{".*avr/include"}}
+
+// RUN: %clang %s -### -target avr --sysroot %S/Inputs/basic_avr_tree 2>&1 
-nostdlibinc | FileCheck -check-prefix CC1C %s
+// CC1C-NOT: "-internal-isystem" {{".*avr/include"}}
Index: clang/lib/Driver/ToolChains/AVR.h
===
--- clang/lib/Driver/ToolChains/AVR.h
+++ clang/lib/Driver/ToolChains/AVR.h
@@ -22,6 +22,9 @@
 public:
   AVRToolChain(const Driver &D, const llvm::Triple &Triple,
const llvm::opt::ArgList &Args);
+  void
+  AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
+llvm::opt::ArgStringList &CC1Args) const override;
 
 protected:
   Tool *buildLinker() const override;
Index: clang/lib/Driver/ToolChains/AVR.cpp
===
--- clang/lib/Driver/ToolChains/AVR.cpp
+++ clang/lib/Driver/ToolChains/AVR.cpp
@@ -353,6 +353,23 @@
   }
 }
 
+void AVRToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
+ ArgStringList &CC1Args) const {
+  if (DriverArgs.hasArg(options::OPT_nostdinc) ||
+  DriverArgs.hasArg(options::OPT_nostdlibinc))
+return;
+
+  // Omit if there is no avr-libc installed.
+  Optional AVRLibcRoot = findAVRLibcInstallation();
+  if (!AVRLibcRoot.hasValue())
+return;
+
+  // Add 'avr-libc/include' to clang system include paths if applicable.
+  std::string AVRInc = AVRLibcRoot.getValue() + "/include";
+  if (llvm::sys::fs::is_directory(AVRInc))
+addSystemInclude(DriverArgs, CC1Args, AVRInc);
+}
+
 Tool *AVRToolChain::buildLinker() const {
   return new tools::AVR::Linker(getTriple(), *this, LinkStdlib);
 }


Index: clang/test/Driver/avr-toolchain.c
===
--- clang/test/Driver/avr-toolchain.c
+++ clang/test/Driver/avr-toolchain.c
@@ -2,3 +2,12 @@
 
 // RUN: %clang %s -### -no-canonical-prefixes -target avr 2>&1 | FileCheck -check-prefix=CC1 %s
 // CC1: clang{{.*}} "-cc1" "-triple" "avr"
+
+// RUN: %clang %s -### -target avr --sysroot %S/Inputs/basic_avr_tree 2>&1 | FileCheck -check-prefix CC1A %s
+// CC1A: clang{{.*}} "-cc1" "-triple" "avr" {{.*}} "-internal-isystem" {{".*avr/include"}}
+
+// RUN: %clang %s -### -target avr --sysroot %S/Inputs/basic_avr_tree 2>&1 -nostdinc | FileCheck -check-prefix CC1B %s
+// CC1B-NOT: "-internal-isystem" {{".*avr/include"}}
+
+// RUN: %clang %s -### -target avr --sysroot %S/Inputs/basic_avr_tree 2>&1 -nostdlibinc | FileCheck -check-prefix CC1C %s
+// CC1C-NOT: "-internal-isystem" {{".*avr/include"}}
Index: clang/lib/Driver/ToolChains/AVR.h
===
--- clang/lib/Driver/ToolChains/AVR.h
+++ clang/lib/Driver/ToolChains/AVR.h
@@ -22,6 +22,9 @@
 public:
   AVRToolChain(const Driver &D, const llvm::Triple &Triple,
const llvm::opt::ArgList &Args);
+  void
+  AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
+llvm::opt::ArgStringList &CC1Args) const override;
 
 protected:
   Tool *buildLinker() const override;
Index: clang/lib/Driver/ToolChains/AVR.cpp
===
--- clang/lib/Driver/ToolChains/AVR.cpp
+++ clang/lib/Driver/ToolChains/AVR.cpp
@@ -353,6 +353,23 @@
   }
 }
 
+void AVRToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
+ ArgStringList &CC1Args) const {
+  if (DriverArgs.hasArg(options::OPT_nostdinc) ||
+  DriverArgs.hasArg(options::OPT_nostdlibinc))
+return;
+
+  // Omit if there is no avr-libc installed.
+  Optional AVRLibcRoot = findAVRLibcInstallation();
+  if (!AVRLibcRoot.hasValue())
+return;
+
+  

[PATCH] D97669: [clang][AVR] Add avr-libc/include to clang system include paths

2021-03-01 Thread Ben Shi via Phabricator via cfe-commits
benshi001 added a comment.
Herald added a subscriber: ormris.

The wrong `stdio.h` (usr/include/stdio.h) is included with a simple a.c like

  #include 
  ...

However the expected one is avr-libc's `stdio.h`, and this patch add avr-libc's 
include/ to clang system include paths.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97669

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


[clang] 965f24d - [Driver] Don't litter the source directory in test

2021-03-01 Thread Benjamin Kramer via cfe-commits

Author: Benjamin Kramer
Date: 2021-03-01T11:20:13+01:00
New Revision: 965f24d4dbd6bc8905de75150d36c693d4396bfd

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

LOG: [Driver] Don't litter the source directory in test

Added: 


Modified: 
clang/test/Driver/cc-print-proc-stat.c

Removed: 




diff  --git a/clang/test/Driver/cc-print-proc-stat.c 
b/clang/test/Driver/cc-print-proc-stat.c
index f3a38559b78a..14029c3ccca0 100644
--- a/clang/test/Driver/cc-print-proc-stat.c
+++ b/clang/test/Driver/cc-print-proc-stat.c
@@ -5,5 +5,5 @@
 // CHECK-CSV: clang{{.*}},"{{.*}}.s",{{[0-9]+}},{{[0-9]+}},{{[0-9]+}}
 
 // RUN: env CC_PRINT_PROC_STAT=1 \
-// RUN: %clang -c -fintegrated-as %s | FileCheck %s
+// RUN: %clang -no-canonical-prefixes -c -fintegrated-as %s -o %t.o | 
FileCheck %s
 // CHECK: clang{{.*}}: output={{.*}}.o, total={{[0-9.]+}} ms, user={{[0-9.]+}} 
ms, mem={{[0-9]+}} Kb



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


[PATCH] D97620: Fix DecisionForestBenchmark.cpp compile errors

2021-03-01 Thread Utkarsh Saxena via Phabricator via cfe-commits
usaxena95 accepted this revision.
usaxena95 added a comment.
This revision is now accepted and ready to land.

LG. Thanks for noticing and fixing it!




Comment at: 
clang-tools-extra/clangd/benchmarks/CompletionModel/DecisionForestBenchmark.cpp:41
 E.setSymbolCategory(RandInt(10));   // 10 Symbol Category.
-
+E.setNumNameInContext(RandInt(20)); // 0 to ContextWords->keys().
+E.setFractionNameInContext(RandFloat(1.0)); // Float in range [0,1].

s/keys()/size().


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

https://reviews.llvm.org/D97620

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


[PATCH] D97535: [clangd] Use URIs instead of paths in the index file list

2021-03-01 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/index/FileIndex.cpp:292
+for (const auto &Sym : *Slab) {
+  if (Sym.Definition)
+Files.insert(Sym.Definition.FileURI);

it feels weird to choose one or the other here, why not just insert both (after 
checking if definition exists, ofc).

We are likely to have a merged symbol information anyway, and the logic here 
will likely result in no index owning the header files, unless there are some 
symbols *defined* (not just declared) in it.

This will likely result in some overshooting as knowing about a symbols 
declaration location doesn't mean indexing that particular file. But so does 
the current version, as knowing about definition location might be because of a 
merged symbol, rather than indexing of particular file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97535

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


[clang] 1b04bdc - [SEH] capture 'this'

2021-03-01 Thread Olivier Goffart via cfe-commits

Author: Olivier Goffart
Date: 2021-03-01T11:57:35+01:00
New Revision: 1b04bdc2f3ffaa7a0e1e3dbdc3a0cd08f0b9a4ce

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

LOG: [SEH] capture 'this'

Simply make sure that the CodeGenFunction::CXXThisValue and CXXABIThisValue
are correctly initialized to the recovered value.
For lambda capture, we also need to make sure to fill the LambdaCaptureFields

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

Added: 


Modified: 
clang/lib/CodeGen/CGException.cpp
clang/test/CodeGenCXX/exceptions-seh-filter-captures.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 7a64963183bc..ce8b42a8c63f 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -1702,10 +1702,8 @@ struct CaptureFinder : ConstStmtVisitor {
 
   void VisitDeclRefExpr(const DeclRefExpr *E) {
 // If this is already a capture, just make sure we capture 'this'.
-if (E->refersToEnclosingVariableOrCapture()) {
+if (E->refersToEnclosingVariableOrCapture())
   Captures.insert(ParentThis);
-  return;
-}
 
 const auto *D = dyn_cast(E->getDecl());
 if (D && D->isLocalVarDeclOrParm() && D->hasLocalStorage())
@@ -1865,11 +1863,6 @@ void CodeGenFunction::EmitCapturedLocals(CodeGenFunction 
&ParentCGF,
 
   // Create llvm.localrecover calls for all captures.
   for (const VarDecl *VD : Finder.Captures) {
-if (isa(VD)) {
-  CGM.ErrorUnsupported(VD, "'this' captured by SEH");
-  CXXThisValue = llvm::UndefValue::get(ConvertTypeForMem(VD->getType()));
-  continue;
-}
 if (VD->getType()->isVariablyModifiedType()) {
   CGM.ErrorUnsupported(VD, "VLA captured by SEH");
   continue;
@@ -1877,6 +1870,12 @@ void CodeGenFunction::EmitCapturedLocals(CodeGenFunction 
&ParentCGF,
 assert((isa(VD) || VD->isLocalVarDeclOrParm()) &&
"captured non-local variable");
 
+auto L = ParentCGF.LambdaCaptureFields.find(VD);
+if (L != ParentCGF.LambdaCaptureFields.end()) {
+  LambdaCaptureFields[VD] = L->second;
+  continue;
+}
+
 // If this decl hasn't been declared yet, it will be declared in the
 // OutlinedStmt.
 auto I = ParentCGF.LocalDeclMap.find(VD);
@@ -1884,8 +1883,14 @@ void CodeGenFunction::EmitCapturedLocals(CodeGenFunction 
&ParentCGF,
   continue;
 
 Address ParentVar = I->second;
-setAddrOfLocalVar(
-VD, recoverAddrOfEscapedLocal(ParentCGF, ParentVar, ParentFP));
+Address Recovered =
+recoverAddrOfEscapedLocal(ParentCGF, ParentVar, ParentFP);
+setAddrOfLocalVar(VD, Recovered);
+
+if (isa(VD)) {
+  CXXThisValue = Builder.CreateLoad(Recovered, "this");
+  CXXABIThisValue = CXXThisValue;
+}
   }
 
   if (Finder.SEHCodeSlot.isValid()) {

diff  --git a/clang/test/CodeGenCXX/exceptions-seh-filter-captures.cpp 
b/clang/test/CodeGenCXX/exceptions-seh-filter-captures.cpp
index ac33dbff0b1c..f6cca8eda9d9 100644
--- a/clang/test/CodeGenCXX/exceptions-seh-filter-captures.cpp
+++ b/clang/test/CodeGenCXX/exceptions-seh-filter-captures.cpp
@@ -39,13 +39,13 @@ void S::test_method() {
   int l1 = 13;
   __try {
 might_crash();
-  } __except(basic_filter(l1)) {
-// FIXME: Test capturing 'this' and 'm1'.
+  } __except (basic_filter(l1, m1)) {
   }
 }
 
 // CHECK-LABEL: define dso_local void @"?test_method@S@@QEAAXXZ"(%struct.S* 
{{[^,]*}} %this)
-// CHECK: @llvm.localescape(i32* %[[l1_addr:[^, ]*]])
+// CHECK: @llvm.localescape(i32* %[[l1_addr:[^, ]*]], %struct.S** 
%[[this_addr:[^, ]*]])
+// CHECK: store %struct.S* %this, %struct.S** %[[this_addr]], align 8
 // CHECK: store i32 13, i32* %[[l1_addr]], align 4
 // CHECK: invoke void @might_crash()
 
@@ -53,8 +53,45 @@ void S::test_method() {
 // CHECK: %[[fp:[^ ]*]] = call i8* @llvm.eh.recoverfp(i8* bitcast (void 
(%struct.S*)* @"?test_method@S@@QEAAXXZ" to i8*), i8* %frame_pointer)
 // CHECK: %[[l1_i8:[^ ]*]] = call i8* @llvm.localrecover(i8* bitcast (void 
(%struct.S*)* @"?test_method@S@@QEAAXXZ" to i8*), i8* %[[fp]], i32 0)
 // CHECK: %[[l1_ptr:[^ ]*]] = bitcast i8* %[[l1_i8]] to i32*
+// CHECK: %[[this_i8:[^ ]*]] = call i8* @llvm.localrecover(i8* bitcast (void 
(%struct.S*)* @"?test_method@S@@QEAAXXZ" to i8*), i8* %[[fp]], i32 1)
+// CHECK: %[[this_ptr:[^ ]*]] = bitcast i8* %[[this_i8]] to %struct.S**
+// CHECK: %[[this:[^ ]*]] = load %struct.S*, %struct.S** %[[this_ptr]], align 8
+// CHECK: %[[m1_ptr:[^ ]*]] = getelementptr inbounds %struct.S, %struct.S* 
%[[this]], i32 0, i32 0
+// CHECK: %[[m1:[^ ]*]] = load i32, i32* %[[m1_ptr]]
 // CHECK: %[[l1:[^ ]*]] = load i32, i32* %[[l1_ptr]]
-// CHECK: call i32 (i32, ...) @basic_filter(i32 %[[l1]])
+// CHECK: call i32 (i32, ...) @basic_filter(i32 %[[l1]], i32 

[PATCH] D97534: SEH: capture 'this'

2021-03-01 Thread Olivier Goffart via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1b04bdc2f3ff: [SEH] capture 'this' (authored by 
ogoffart).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97534

Files:
  clang/lib/CodeGen/CGException.cpp
  clang/test/CodeGenCXX/exceptions-seh-filter-captures.cpp

Index: clang/test/CodeGenCXX/exceptions-seh-filter-captures.cpp
===
--- clang/test/CodeGenCXX/exceptions-seh-filter-captures.cpp
+++ clang/test/CodeGenCXX/exceptions-seh-filter-captures.cpp
@@ -39,13 +39,13 @@
   int l1 = 13;
   __try {
 might_crash();
-  } __except(basic_filter(l1)) {
-// FIXME: Test capturing 'this' and 'm1'.
+  } __except (basic_filter(l1, m1)) {
   }
 }
 
 // CHECK-LABEL: define dso_local void @"?test_method@S@@QEAAXXZ"(%struct.S* {{[^,]*}} %this)
-// CHECK: @llvm.localescape(i32* %[[l1_addr:[^, ]*]])
+// CHECK: @llvm.localescape(i32* %[[l1_addr:[^, ]*]], %struct.S** %[[this_addr:[^, ]*]])
+// CHECK: store %struct.S* %this, %struct.S** %[[this_addr]], align 8
 // CHECK: store i32 13, i32* %[[l1_addr]], align 4
 // CHECK: invoke void @might_crash()
 
@@ -53,8 +53,45 @@
 // CHECK: %[[fp:[^ ]*]] = call i8* @llvm.eh.recoverfp(i8* bitcast (void (%struct.S*)* @"?test_method@S@@QEAAXXZ" to i8*), i8* %frame_pointer)
 // CHECK: %[[l1_i8:[^ ]*]] = call i8* @llvm.localrecover(i8* bitcast (void (%struct.S*)* @"?test_method@S@@QEAAXXZ" to i8*), i8* %[[fp]], i32 0)
 // CHECK: %[[l1_ptr:[^ ]*]] = bitcast i8* %[[l1_i8]] to i32*
+// CHECK: %[[this_i8:[^ ]*]] = call i8* @llvm.localrecover(i8* bitcast (void (%struct.S*)* @"?test_method@S@@QEAAXXZ" to i8*), i8* %[[fp]], i32 1)
+// CHECK: %[[this_ptr:[^ ]*]] = bitcast i8* %[[this_i8]] to %struct.S**
+// CHECK: %[[this:[^ ]*]] = load %struct.S*, %struct.S** %[[this_ptr]], align 8
+// CHECK: %[[m1_ptr:[^ ]*]] = getelementptr inbounds %struct.S, %struct.S* %[[this]], i32 0, i32 0
+// CHECK: %[[m1:[^ ]*]] = load i32, i32* %[[m1_ptr]]
 // CHECK: %[[l1:[^ ]*]] = load i32, i32* %[[l1_ptr]]
-// CHECK: call i32 (i32, ...) @basic_filter(i32 %[[l1]])
+// CHECK: call i32 (i32, ...) @basic_filter(i32 %[[l1]], i32 %[[m1]])
+
+struct V {
+  void test_virtual(int p1);
+  virtual void virt(int p1);
+};
+
+void V::test_virtual(int p1) {
+  __try {
+might_crash();
+  } __finally {
+virt(p1);
+  }
+}
+
+// CHECK-LABEL: define dso_local void @"?test_virtual@V@@QEAAXH@Z"(%struct.V* {{[^,]*}} %this, i32 %p1)
+// CHECK: @llvm.localescape(%struct.V** %[[this_addr:[^, ]*]], i32* %[[p1_addr:[^, ]*]])
+// CHECK: store i32 %p1, i32* %[[p1_addr]], align 4
+// CHECK: store %struct.V* %this, %struct.V** %[[this_addr]], align 8
+// CHECK: invoke void @might_crash()
+
+// CHECK-LABEL: define internal void @"?fin$0@0@test_virtual@V@@"(i8 %abnormal_termination, i8* %frame_pointer)
+// CHECK: %[[this_i8:[^ ]*]] = call i8* @llvm.localrecover(i8* bitcast (void (%struct.V*, i32)* @"?test_virtual@V@@QEAAXH@Z" to i8*), i8* %frame_pointer, i32 0)
+// CHECK: %[[this_ptr:[^ ]*]] = bitcast i8* %[[this_i8]] to %struct.V**
+// CHECK: %[[this:[^ ]*]] = load %struct.V*, %struct.V** %[[this_ptr]], align 8
+// CHECK: %[[p1_i8:[^ ]*]] = call i8* @llvm.localrecover(i8* bitcast (void (%struct.V*, i32)* @"?test_virtual@V@@QEAAXH@Z" to i8*), i8* %frame_pointer, i32 1)
+// CHECK: %[[p1_ptr:[^ ]*]] = bitcast i8* %[[p1_i8]] to i32*
+// CHECK: %[[p1:[^ ]*]] = load i32, i32* %[[p1_ptr]]
+// CHECK: %[[this_2:[^ ]*]] = bitcast %struct.V* %[[this]] to void (%struct.V*, i32)***
+// CHECK: %[[vtable:[^ ]*]] = load void (%struct.V*, i32)**, void (%struct.V*, i32)*** %[[this_2]], align 8
+// CHECK: %[[vfn:[^ ]*]] = getelementptr inbounds void (%struct.V*, i32)*, void (%struct.V*, i32)** %[[vtable]], i64 0
+// CHECK: %[[virt:[^ ]*]] = load void (%struct.V*, i32)*, void (%struct.V*, i32)** %[[vfn]], align 8
+// CHECK: call void %[[virt]](%struct.V* {{[^,]*}} %[[this]], i32 %[[p1]])
 
 void test_lambda() {
   int l1 = 13;
@@ -62,21 +99,27 @@
 int l2 = 42;
 __try {
   might_crash();
-} __except(basic_filter(l2)) {
-  // FIXME: Test 'l1' when we can capture the lambda's 'this' decl.
+} __except (basic_filter(l1, l2)) {
 }
   };
   lambda();
 }
 
 // CHECK-LABEL: define internal void @"??R@?0??test_lambda@@YAXXZ@QEBA@XZ"(%class.anon* {{[^,]*}} %this)
-// CHECK: @llvm.localescape(i32* %[[l2_addr:[^, ]*]])
+// CHECK: @llvm.localescape(%class.anon** %[[this_addr:[^, ]*]], i32* %[[l2_addr:[^, ]*]])
+// CHECK: store %class.anon* %this, %class.anon** %[[this_addr]], align 8
 // CHECK: store i32 42, i32* %[[l2_addr]], align 4
 // CHECK: invoke void @might_crash()
 
 // CHECK-LABEL: define internal i32 @"?filt$0@0@?R@?0??test_lambda@@YAXXZ@"(i8* %exception_pointers, i8* %frame_pointer)
 // CHECK: %[[fp:[^ ]*]] = call i8* @llvm.eh.recoverfp(i8* bitcast (void (%class.anon*)* @"??R@?0??test_lambda@@YAXXZ@QEBA@XZ" to i8*), i8* %frame_pointer)
-// C

[PATCH] D96976: [analyzer] Fix reinterpret_cast handling for pointer-to-member

2021-03-01 Thread Balázs Benics via Phabricator via cfe-commits
steakhal requested changes to this revision.
steakhal added a comment.
This revision now requires changes to proceed.

I have serious concerns inline.




Comment at: clang/test/Analysis/reinterpret-cast-pointer-to-member.cpp:20
   int DoubleDerived::*ddf = &Base::field;
   int Base::*bf = reinterpret_cast(reinterpret_cast(reinterpret_cast(ddf)));
   Base base;

Please have a note describing why you are doing this roundtrip.



Comment at: clang/test/Analysis/reinterpret-cast-pointer-to-member.cpp:29-31
+  Some some;
+  some.*sf = 14;
+  clang_analyzer_eval(some.*sf == 14); // expected-warning{{UNKNOWN}}

The assignment is actually UB.
TBH I don't know how to test such behavior xD
Same for the next example.

Shouldn't it return `undef` for reading via an invalid member pointer?



Comment at: clang/test/Analysis/reinterpret-cast-pointer-to-member.cpp:43-50
+struct A {};
+struct B : public A {};
+struct C {
+  int field;
+};
+struct D : public C {};
+struct E : public B, public D {};

An ASCII art would help so much:
```
A   C(field)
|   |
B   D
 \ /
  E
  |
  F
```
However, I'm still missing a diamond-shaped inheritance.



Comment at: clang/test/Analysis/reinterpret-cast-pointer-to-member.cpp:52-62
+void testMultiple() {
+  int F::*f = &F::field;
+  int A::*a = reinterpret_cast(f);
+  int C::*c = reinterpret_cast(f);
+  A aobj;
+  C cobj;
+  aobj.*a = 13;

Wait a minute. It's not how it works.
How I imagine member pointers, they are just offsets.
`&F::field` is notionally equivalent with `offsetof(F, field)`. That being 
said, You can not apply this member pointer to any object besides `F`.
Imagine if the classes of the inheritance tree would have other fields as well.
Then the `offsetof(T, field)` would be different for `F`, and `C`.

This example demonstrates that both of these member pointer dereferences are UB.
https://godbolt.org/z/15sMEP
It returns different values depending on the optimization level, which is a 
clear sign of UB.
BTW this issue is closely related to strict aliasing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96976

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


[PATCH] D96976: [analyzer] Fix reinterpret_cast handling for pointer-to-member

2021-03-01 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD marked an inline comment as done.
RedDocMD added inline comments.



Comment at: clang/test/Analysis/reinterpret-cast-pointer-to-member.cpp:43-50
+struct A {};
+struct B : public A {};
+struct C {
+  int field;
+};
+struct D : public C {};
+struct E : public B, public D {};

steakhal wrote:
> An ASCII art would help so much:
> ```
> A   C(field)
> |   |
> B   D
>  \ /
>   E
>   |
>   F
> ```
> However, I'm still missing a diamond-shaped inheritance.
> An ASCII art would help so much:
> ```
> A   C(field)
> |   |
> B   D
>  \ /
>   E
>   |
>   F
> ```
> However, I'm still missing a diamond-shaped inheritance.

Thanks for the ASCII art!
The diamond-shaped inheritance as far as I understood will cause illegal code.
Eg:
```
   A
   |
   B
 /   \
C D
 \   /
   E
```
According to my understanding, if I have a field in A or B, and try to define a 
member pointer like `int E::* ef = &A::field`, it is not allowed.
On GCC, this is the error message I get:
```
struct A {
  int field;
};

struct B : public A {};
struct C : public virtual B {};
struct D : public virtual B {};
struct E : public C, public D {};

int main() {
  int E::* ef1 = &A::field;
}
```
diamond-member-pointer.cpp: In function ‘int main()’:
diamond-member-pointer.cpp:11:22: error: pointer to member conversion via 
virtual base ‘B’
   11 |   int E::* ef1 = &A::field;
  |  ^
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96976

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


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

2021-03-01 Thread Balázs Kéri via Phabricator via cfe-commits
balazske abandoned this revision.
balazske added a comment.

Checks about code formatting are likely not to be accepted. Formatting can be 
done in external tool and is not subject for checks. The difference is that it 
is not possible to format separately for one rule only (with clang-format). But 
the better option should be to format the whole code instead of parts of it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96607

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


[PATCH] D97630: [clang-tidy] Added option to uniqueptr delete release check

2021-03-01 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 327077.
njames93 added a comment.

Add tests to ensure Parens are handled correctly.
Add support for pointers to and smart pointers to unique_ptr objects.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97630

Files:
  clang-tools-extra/clang-tidy/readability/UniqueptrDeleteReleaseCheck.cpp
  clang-tools-extra/clang-tidy/readability/UniqueptrDeleteReleaseCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/readability-uniqueptr-delete-release.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability-uniqueptr-delete-release.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability-uniqueptr-delete-release.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability-uniqueptr-delete-release.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-uniqueptr-delete-release.cpp
@@ -1,5 +1,6 @@
-// RUN: %check_clang_tidy %s readability-uniqueptr-delete-release %t
-
+// RUN: %check_clang_tidy %s readability-uniqueptr-delete-release %t -check-suffix=NULLPTR
+// RUN: %check_clang_tidy %s readability-uniqueptr-delete-release %t -check-suffix=RESET -config='{ \
+// RUN: CheckOptions: [{key: readability-uniqueptr-delete-release.PreferResetCall, value: true}]}'
 namespace std {
 template 
 struct default_delete {};
@@ -13,6 +14,9 @@
   template 
   unique_ptr(unique_ptr&&);
   T* release();
+  void reset(T *P = nullptr);
+  T &operator*() const;
+  T *operator->() const;
 };
 }  // namespace std
 
@@ -21,22 +25,62 @@
 void Positives() {
   std::unique_ptr P;
   delete P.release();
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer '= nullptr' to 'delete x.release()' to reset unique_ptr<> objects [readability-uniqueptr-delete-release]
-  // CHECK-FIXES: {{^}}  P = nullptr;
+  // CHECK-MESSAGES-NULLPTR: :[[@LINE-1]]:3: warning: prefer '= nullptr' to reset 'unique_ptr<>' objects
+  // CHECK-MESSAGES-RESET: :[[@LINE-2]]:3: warning: prefer 'reset()' to reset 'unique_ptr<>' objects
+  // CHECK-FIXES-NULLPTR: {{^}}  P = nullptr;
+  // CHECK-FIXES-RESET: {{^}}  P.reset();
 
   auto P2 = P;
   delete P2.release();
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer '= nullptr' to 'delete x.release()' to reset unique_ptr<> objects [readability-uniqueptr-delete-release]
-  // CHECK-FIXES: {{^}}  P2 = nullptr;
+  // CHECK-MESSAGES-NULLPTR: :[[@LINE-1]]:3: warning: prefer '= nullptr' to reset 'unique_ptr<>' objects
+  // CHECK-MESSAGES-RESET: :[[@LINE-2]]:3: warning: prefer 'reset()' to reset 'unique_ptr<>' objects
+  // CHECK-FIXES-NULLPTR: {{^}}  P2 = nullptr;
+  // CHECK-FIXES-RESET: {{^}}  P2.reset();
+
+  delete (P2.release());
+  // CHECK-MESSAGES-NULLPTR: :[[@LINE-1]]:3: warning: prefer '= nullptr'
+  // CHECK-MESSAGES-RESET: :[[@LINE-2]]:3: warning: prefer 'reset()'
+  // CHECK-FIXES-NULLPTR: {{^}}  (P2 = nullptr);
+  // CHECK-FIXES-RESET: {{^}}  (P2.reset());
 
   std::unique_ptr Array[20];
   delete Array[4].release();
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer '= nullptr' to 'delete
-  // CHECK-FIXES: {{^}}  Array[4] = nullptr;
+  // CHECK-MESSAGES-NULLPTR: :[[@LINE-1]]:3: warning: prefer '= nullptr'
+  // CHECK-MESSAGES-RESET: :[[@LINE-2]]:3: warning: prefer 'reset()'
+  // CHECK-FIXES-NULLPTR: {{^}}  Array[4] = nullptr;
+  // CHECK-FIXES-RESET: {{^}}  Array[4].reset();
 
   delete ReturnsAUnique().release();
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer '= nullptr' to 'delete
-  // CHECK-FIXES: {{^}}  ReturnsAUnique() = nullptr;
+  // CHECK-MESSAGES-NULLPTR: :[[@LINE-1]]:3: warning: prefer '= nullptr'
+  // CHECK-MESSAGES-RESET: :[[@LINE-2]]:3: warning: prefer 'reset()'
+  // CHECK-FIXES-NULLPTR: {{^}}  ReturnsAUnique() = nullptr;
+  // CHECK-FIXES-RESET: {{^}}  ReturnsAUnique().reset();
+
+  std::unique_ptr *P3(&P);
+  delete P3->release();
+  // CHECK-MESSAGES-NULLPTR: :[[@LINE-1]]:3: warning: prefer '= nullptr'
+  // CHECK-MESSAGES-RESET: :[[@LINE-2]]:3: warning: prefer 'reset()'
+  // CHECK-FIXES-NULLPTR: {{^}}  *P3 = nullptr;
+  // CHECK-FIXES-RESET: {{^}}  P3->reset();
+
+  std::unique_ptr> P4;
+  delete (*P4).release();
+  // CHECK-MESSAGES-NULLPTR: :[[@LINE-1]]:3: warning: prefer '= nullptr'
+  // CHECK-MESSAGES-RESET: :[[@LINE-2]]:3: warning: prefer 'reset()'
+  // CHECK-FIXES-NULLPTR: {{^}}  (*P4) = nullptr;
+  // CHECK-FIXES-RESET: {{^}}  (*P4).reset();
+
+  delete P4->release();
+  // CHECK-MESSAGES-NULLPTR: :[[@LINE-1]]:3: warning: prefer '= nullptr'
+  // CHECK-MESSAGES-RESET: :[[@LINE-2]]:3: warning: prefer 'reset()'
+  // CHECK-FIXES-NULLPTR: {{^}}  *P4 = nullptr;
+  // CHECK-FIXES-RESET: {{^}}  P4->reset();
+
+  delete (P4)->release();
+  // CHECK-MESSAGES-NULLPTR: :[[@LINE-1]]:3: warning: prefer '= nullptr'
+  // CHECK-MESSAGES-RESET: :[[@LINE-2]]:3: warning: prefer 'reset()'
+  // CHECK-FIXES-NULLPTR: {{^}}  *(P4) = nullptr;
+

[PATCH] D97457: [flang][driver] Add `-fdebug-dump-parsing-log`

2021-03-01 Thread Chirag Khandelwal via Phabricator via cfe-commits
AMDChirag added a comment.

LGTM.
I'll let someone else review the patch if required.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97457

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


[PATCH] D97680: [OpenMP] Simplify GPU memory globalization

2021-03-01 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 created this revision.
jhuber6 added a reviewer: jdoerfert.
jhuber6 added projects: LLVM, clang, OpenMP.
Herald added subscribers: jfb, guansong, hiraditya, yaxunl.
jhuber6 requested review of this revision.
Herald added subscribers: llvm-commits, openmp-commits, cfe-commits, sstefan1.

  Memory globalization is required to maintain OpenMP standard semantics for 
data sharing between
  worker and master threads. The GPU cannot share data between its threads so 
must allocate global or
  shared memory to store the data in. Currently this is implemented fully in 
the frontend using the
  `__kmpc_data_sharing_push_stack` and __kmpc_data_sharing_pop_stack` functions 
to emulate standard
  CPU stack sharing. The front-end scans the target region for variables that 
escape the region and
  must be shared between the threads. Each variable then has a field created 
for it in a global record
  type.
  
  This patch replaces this functionality with a single allocation command, 
effectively mimicking an
  alloca instruction for the variables that must be shared between the threads. 
This will be much
  slower than the current solution, but makes it much easier to optimize as we 
can analyze each
  variable independently and determine if it is not captured. In the future, we 
can replace these
  calls with an `alloca` and small allocations can be pushed to shared memory.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97680

Files:
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.h
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
  llvm/lib/Transforms/IPO/OpenMPOpt.cpp
  openmp/libomptarget/deviceRTLs/common/src/data_sharing.cu
  openmp/libomptarget/deviceRTLs/interface.h

Index: openmp/libomptarget/deviceRTLs/interface.h
===
--- openmp/libomptarget/deviceRTLs/interface.h
+++ openmp/libomptarget/deviceRTLs/interface.h
@@ -424,13 +424,8 @@
 EXTERN bool __kmpc_kernel_parallel(void **WorkFn);
 EXTERN void __kmpc_kernel_end_parallel();
 
-EXTERN void __kmpc_data_sharing_init_stack();
-EXTERN void __kmpc_data_sharing_init_stack_spmd();
-EXTERN void *__kmpc_data_sharing_coalesced_push_stack(size_t size,
-  int16_t UseSharedMemory);
-EXTERN void *__kmpc_data_sharing_push_stack(size_t size,
-int16_t UseSharedMemory);
-EXTERN void __kmpc_data_sharing_pop_stack(void *a);
+EXTERN void *__kmpc_alloc_shared(size_t size);
+EXTERN void __kmpc_free_shared(void *a);
 EXTERN void __kmpc_begin_sharing_variables(void ***GlobalArgs, size_t nArgs);
 EXTERN void __kmpc_end_sharing_variables();
 EXTERN void __kmpc_get_shared_variables(void ***GlobalArgs);
@@ -445,4 +440,11 @@
 EXTERN void __kmpc_restore_team_static_memory(int16_t isSPMDExecutionMode,
   int16_t is_shared);
 
+// Deprecated globalization interface
+EXTERN void *__kmpc_data_sharing_coalesced_push_stack(size_t size, int16_t s);
+EXTERN void *__kmpc_data_sharing_push_stack(size_t size, int16_t s);
+EXTERN void __kmpc_data_sharing_pop_stack(void *a);
+EXTERN void __kmpc_data_sharing_init_stack();
+EXTERN void __kmpc_data_sharing_init_stack_spmd();
+
 #endif
Index: openmp/libomptarget/deviceRTLs/common/src/data_sharing.cu
===
--- openmp/libomptarget/deviceRTLs/common/src/data_sharing.cu
+++ openmp/libomptarget/deviceRTLs/common/src/data_sharing.cu
@@ -23,125 +23,6 @@
 // Runtime functions for trunk data sharing scheme.
 
 
-INLINE static void data_sharing_init_stack_common() {
-  ASSERT0(LT_FUSSY, isRuntimeInitialized(), "Runtime must be initialized.");
-  omptarget_nvptx_TeamDescr *teamDescr =
-  &omptarget_nvptx_threadPrivateContext->TeamContext();
-
-  for (int WID = 0; WID < DS_Max_Warp_Number; WID++) {
-__kmpc_data_sharing_slot *RootS = teamDescr->GetPreallocatedSlotAddr(WID);
-DataSharingState.SlotPtr[WID] = RootS;
-DataSharingState.StackPtr[WID] = (void *)&RootS->Data[0];
-  }
-}
-
-// Initialize data sharing data structure. This function needs to be called
-// once at the beginning of a data sharing context (coincides with the kernel
-// initialization). This function is called only by the MASTER thread of each
-// team in non-SPMD mode.
-EXTERN void __kmpc_data_sharing_init_stack() {
-  ASSERT0(LT_FUSSY, isRuntimeInitialized(), "Runtime must be initialized.");
-  // This function initializes the stack pointer with the pointer to the
-  // statically allocated shared memory slots. The size of a shared memory
-  // slot is pre-determined to be 256 bytes.
-  data_sharing_init_stack_common();
-  omptarget_nvptx_globalArgs.Init();
-}
-
-// Initialize data sharing data structure. This function needs to be called
-// once at the beginning of a data sharing conte

[PATCH] D97680: [OpenMP] Simplify GPU memory globalization

2021-03-01 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

Fixing tests is WIP


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97680

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


[PATCH] D97681: [ASTMatchers] Add matchers for `CXXDeleteExpr`

2021-03-01 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added reviewers: klimek, aaron.ballman, steveire.
njames93 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add `deletes` traveral matcher which matches on the expression being delete
Extend `CXXNewExpr::isArray` matcher to work for `CXXDeleteExpr`. Currently 
this only matches array delete expressions as written.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97681

Files:
  clang-tools-extra/clang-tidy/bugprone/BoolPointerImplicitConversionCheck.cpp
  clang-tools-extra/clang-tidy/readability/DeleteNullPointerCheck.cpp
  clang-tools-extra/clang-tidy/readability/UniqueptrDeleteReleaseCheck.cpp
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/include/clang/ASTMatchers/ASTMatchersInternal.h
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -5466,5 +5466,31 @@
  IsPlacementNew));
 }
 
+TEST(CXXDeleteExpr, Deletes) {
+  StatementMatcher IsDeletingPtrVar = cxxDeleteExpr(
+  deletes(ignoringImpCasts(declRefExpr(to(varDecl(hasName("Ptr")));
+
+  EXPECT_TRUE(matches("void foo(int* Ptr) { delete Ptr; }", IsDeletingPtrVar));
+  EXPECT_TRUE(notMatches(R"(
+struct Foo{
+  int* Address;
+};
+void Bar(Foo& Ptr) {
+  delete Ptr.Address;
+}
+  )",
+ IsDeletingPtrVar));
+
+  EXPECT_TRUE(notMatches(R"(
+struct Foo{
+  int* Ptr;
+};
+void Bar(Foo& Ptr) {
+  delete Ptr.Ptr;
+}
+  )",
+ IsDeletingPtrVar));
+}
+
 } // namespace ast_matchers
 } // namespace clang
Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -3779,6 +3779,12 @@
 
   EXPECT_TRUE(matches("struct MyClass {}; MyClass *p1 = new MyClass[10];",
   cxxNewExpr(isArray(;
+
+  EXPECT_TRUE(
+  matches("void foo(int* p) { delete[] p; }", cxxDeleteExpr(isArray(;
+
+  EXPECT_TRUE(
+  notMatches("void foo(int* p) { delete p; }", cxxDeleteExpr(isArray(;
 }
 
 TEST_P(ASTMatchersTest, HasArraySize) {
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -214,6 +214,7 @@
   REGISTER_MATCHER(decltypeType);
   REGISTER_MATCHER(deducedTemplateSpecializationType);
   REGISTER_MATCHER(defaultStmt);
+  REGISTER_MATCHER(deletes);
   REGISTER_MATCHER(dependentSizedArrayType);
   REGISTER_MATCHER(designatedInitExpr);
   REGISTER_MATCHER(designatorCountIs);
@@ -266,7 +267,6 @@
   REGISTER_MATCHER(hasAnySubstatement);
   REGISTER_MATCHER(hasAnyTemplateArgument);
   REGISTER_MATCHER(hasAnyUsingShadowDecl);
-  REGISTER_MATCHER(hasArgument);
   REGISTER_MATCHER(hasArgumentOfType);
   REGISTER_MATCHER(hasArraySize);
   REGISTER_MATCHER(hasAttr);
Index: clang/include/clang/ASTMatchers/ASTMatchersInternal.h
===
--- clang/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ clang/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -155,6 +155,14 @@
   return Node.getAccessSpecifier();
 }
 
+/// Unifies obtaining the whether as new or delete operator operates on an
+/// array.
+inline bool isArrayOperator(const CXXNewExpr &Node) { return Node.isArray(); }
+
+inline bool isArrayOperator(const CXXDeleteExpr &Node) {
+  return Node.isArrayFormAsWritten();
+}
+
 /// Internal version of BoundNodes. Holds all the bound nodes.
 class BoundNodesMap {
 public:
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -7550,16 +7550,21 @@
   return Node.hasDefaultArg();
 }
 
-/// Matches array new expressions.
+/// Matches array new and delete expressions.
 ///
 /// Given:
 /// \code
 ///   MyClass *p1 = new MyClass[10];
+///   delete[] p1;
 /// \endcode
 /// cxxNewExpr(isArray())
 ///   matches the expression 'new MyClass[10]'.
-AST_MATCHER(CXXNewExpr, isArray) {
-  return Node.isArray();
+/// cxxDeleteExpr(isArray())
+///   matches the expression 'delete[] p1'.
+AST_POLYMORPHIC_MATCHER(isArray,
+AST_POLYMORPHIC_SUPPORTED_TYPES(CXXNewExpr,
+CXXDelet

[PATCH] D97474: [PowerPC][AIX] Enable passing vectors in variadic functions (front-end).

2021-03-01 Thread Zarko Todorovski via Phabricator via cfe-commits
ZarkoCA accepted this revision.
ZarkoCA added a comment.

It may be better to use `__builtin_va_list` and the like instead of the header 
inclusion but I don't want to make the test change too onerous if that turns 
out to be the case.




Comment at: clang/test/CodeGen/aix-altivec-vaargs.c:5
+
+#include 
+

Any reason for for including the header instead of builtins as in aix-vaargs.c? 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97474

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


[PATCH] D97683: [clang-tidy] Add include to misc-uniqueptr-reset-release

2021-03-01 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added reviewers: alexfh, aaron.ballman.
Herald added a subscriber: xazax.hun.
njames93 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is the only remaining check that creates `std::move` includes but doesn't 
add a `` include.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97683

Files:
  clang-tools-extra/clang-tidy/misc/UniqueptrResetReleaseCheck.cpp
  clang-tools-extra/clang-tidy/misc/UniqueptrResetReleaseCheck.h
  clang-tools-extra/docs/clang-tidy/checks/misc-uniqueptr-reset-release.rst
  clang-tools-extra/test/clang-tidy/checkers/misc-uniqueptr-reset-release.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/misc-uniqueptr-reset-release.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/misc-uniqueptr-reset-release.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/misc-uniqueptr-reset-release.cpp
@@ -1,5 +1,7 @@
 // RUN: %check_clang_tidy %s misc-uniqueptr-reset-release %t
 
+// CHECK-FIXES: #include 
+
 namespace std {
 
 template 
Index: clang-tools-extra/docs/clang-tidy/checks/misc-uniqueptr-reset-release.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/misc-uniqueptr-reset-release.rst
+++ clang-tools-extra/docs/clang-tidy/checks/misc-uniqueptr-reset-release.rst
@@ -14,3 +14,11 @@
 
 If ``y`` is already rvalue, ``std::move()`` is not added. ``x`` and ``y`` can
 also be ``std::unique_ptr*``.
+
+Options
+---
+
+.. option:: IncludeStyle
+
+   A string specifying which include-style is used, `llvm` or `google`. Default
+   is `llvm`.
Index: clang-tools-extra/clang-tidy/misc/UniqueptrResetReleaseCheck.h
===
--- clang-tools-extra/clang-tidy/misc/UniqueptrResetReleaseCheck.h
+++ clang-tools-extra/clang-tidy/misc/UniqueptrResetReleaseCheck.h
@@ -10,6 +10,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNIQUEPTRRESETRELEASECHECK_H
 
 #include "../ClangTidyCheck.h"
+#include "../utils/IncludeInserter.h"
 
 namespace clang {
 namespace tidy {
@@ -28,8 +29,7 @@
 /// be `std::unique_ptr*`.
 class UniqueptrResetReleaseCheck : public ClangTidyCheck {
 public:
-  UniqueptrResetReleaseCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  UniqueptrResetReleaseCheck(StringRef Name, ClangTidyContext *Context);
 
   bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
 // Only register the matchers for C++11; the functionality currently does
@@ -37,8 +37,13 @@
 // provide any benefit to other languages, despite being benign.
 return LangOpts.CPlusPlus11;
   }
+  void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
+   Preprocessor *ModuleExpanderPP) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+
+private:
+  utils::IncludeInserter Inserter;
 };
 
 } // namespace misc
Index: clang-tools-extra/clang-tidy/misc/UniqueptrResetReleaseCheck.cpp
===
--- clang-tools-extra/clang-tidy/misc/UniqueptrResetReleaseCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/UniqueptrResetReleaseCheck.cpp
@@ -16,6 +16,17 @@
 namespace tidy {
 namespace misc {
 
+UniqueptrResetReleaseCheck::UniqueptrResetReleaseCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  Inserter(Options.getLocalOrGlobal("IncludeStyle",
+utils::IncludeSorter::IS_LLVM)) {}
+
+void UniqueptrResetReleaseCheck::registerPPCallbacks(
+const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
+  Inserter.registerPreprocessor(PP);
+}
+
 void UniqueptrResetReleaseCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
   cxxMemberCallExpr(
@@ -119,15 +130,18 @@
 
   std::string NewText = LeftText + " = " + RightText;
 
-  diag(ResetMember->getExprLoc(),
-   "prefer ptr = %select{std::move(ptr2)|ReturnUnique()}0 over "
-   "ptr.reset(%select{ptr2|ReturnUnique()}0.release())")
-  << !IsMove
-  << FixItHint::CreateReplacement(
- CharSourceRange::getTokenRange(ResetCall->getSourceRange()),
- NewText);
+  auto D = diag(ResetMember->getExprLoc(),
+"prefer ptr = %select{std::move(ptr2)|ReturnUnique()}0 over "
+"ptr.reset(%select{ptr2|ReturnUnique()}0.release())")
+   << !IsMove
+   << FixItHint::CreateReplacement(
+  CharSourceRange::getTokenRange(ResetCall->getSourceRange()),
+  NewText);
+  if (IsMove)
+D << Inserter.createIncludeInsertion(
+Result.SourceManager->getFileID(ResetMember->getBeginLoc()),
+

[PATCH] D97535: [clangd] Use URIs instead of paths in the index file list

2021-03-01 Thread Aleksandr Platonov via Phabricator via cfe-commits
ArcsinX added inline comments.



Comment at: clang-tools-extra/clangd/index/FileIndex.cpp:292
+for (const auto &Sym : *Slab) {
+  if (Sym.Definition)
+Files.insert(Sym.Definition.FileURI);

kadircet wrote:
> it feels weird to choose one or the other here, why not just insert both 
> (after checking if definition exists, ofc).
> 
> We are likely to have a merged symbol information anyway, and the logic here 
> will likely result in no index owning the header files, unless there are some 
> symbols *defined* (not just declared) in it.
> 
> This will likely result in some overshooting as knowing about a symbols 
> declaration location doesn't mean indexing that particular file. But so does 
> the current version, as knowing about definition location might be because of 
> a merged symbol, rather than indexing of particular file.
I will try to explain on example:

- **test.h**
```
void f();
```
- **test.c**
```
#include "test.h"
void f() { }
```
- compile_commands.json contains a command for **test.c** compilation.

Scenario:
- open **test.c**
- try to find all references for `f()`

For that scenario result for `find all references` will be incorrect if both 
(decl and def) files are in the file list because:
- decl location is inside **test.h**
- def location is inside **test.c**
- the file list for the main file index contains **test.h** and **test.c**
- the main file index does not contain references from **test.h**
- the background (static) index contains references from **test.c**, but 
results from the background index will be skipped, because **test.h** is in the 
main file (dynamic) index file list.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97535

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


[PATCH] D96975: [Sema] Add some basic lambda capture fix-its

2021-03-01 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96975

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


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

2021-03-01 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

Ping?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94554

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


[PATCH] D96975: [Sema] Add some basic lambda capture fix-its

2021-03-01 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev added a comment.

In D96975#2594147 , @njames93 wrote:

> Ping

Hi Nathan! Thanks again for this patch and sorry for not taking time to review 
it yet. It is a busy week for me and my team, so I wasn't able to do much 
coding/reviewing, apologies for that. I expect to get some time for this in the 
upcoming days and I do think it's an important thing to dedicate time for.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96975

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


[PATCH] D97573: [OpenMP] Handle non-function context before checking for diagnostic emission

2021-03-01 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:1946
+FunctionEmissionStatus FES = getEmissionStatus(FD);
+switch (FES) {
+case FunctionEmissionStatus::Emitted:

Tabs here instead of spaces.

I think this is the right fix for SYCL, but @bader  should double-check that 
he's ok with this or OMP.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97573

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


[PATCH] D97683: [clang-tidy] Add include to misc-uniqueptr-reset-release

2021-03-01 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/clang-tidy/misc/UniqueptrResetReleaseCheck.cpp:22
+: ClangTidyCheck(Name, Context),
+  Inserter(Options.getLocalOrGlobal("IncludeStyle",
+utils::IncludeSorter::IS_LLVM)) {}

I think it'll be reasonable to try to get default from `.clang-format`. Same in 
other checks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97683

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


[PATCH] D84924: [clang-tidy] Added command line option `fix-notes`

2021-03-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84924

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


[PATCH] D97614: [clang-tidy] Remove OptionError

2021-03-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM, nice cleanup!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97614

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


[PATCH] D97681: [ASTMatchers] Add matchers for `CXXDeleteExpr`

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



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:7621
+///   matches the expression 'delete Ptr'.
+AST_MATCHER_P_OVERLOAD(CXXDeleteExpr, deletes, internal::Matcher,
+   InnerMatcher, 1) {

Why add this instead of continuing to use `has()`? (I worry a bit that we'll 
want to add a verb for different subexpression matchers and it won't scale well 
or we won't add verbs for different subexpressions and this'll introduce a new 
inconsistency.)



Comment at: clang/include/clang/ASTMatchers/ASTMatchersInternal.h:163
+inline bool isArrayOperator(const CXXDeleteExpr &Node) {
+  return Node.isArrayFormAsWritten();
+}

Do we need/want this interface to consider whether the user is matching things 
spelled in source or not?



Comment at: clang/lib/ASTMatchers/Dynamic/Registry.cpp:269
   REGISTER_MATCHER(hasAnyUsingShadowDecl);
-  REGISTER_MATCHER(hasArgument);
   REGISTER_MATCHER(hasArgumentOfType);

Why removing this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97681

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


[PATCH] D97683: [clang-tidy] Add include to misc-uniqueptr-reset-release

2021-03-01 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: clang-tools-extra/clang-tidy/misc/UniqueptrResetReleaseCheck.cpp:22
+: ClangTidyCheck(Name, Context),
+  Inserter(Options.getLocalOrGlobal("IncludeStyle",
+utils::IncludeSorter::IS_LLVM)) {}

Eugene.Zelenko wrote:
> I think it'll be reasonable to try to get default from `.clang-format`. Same 
> in other checks.
There isn't a nice way to get the default from `.clang-format` as the 
FormatStyle doesn't have a nice field that says if llvm or google style is 
used(because it's more flexible than that). Besides that, If there is a 
`.clang-format` config. clang-tidy will reformat all changes using that style, 
which in turn would reorder any added includes even if they were of the wrong 
style.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97683

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


[PATCH] D97687: [SEH] Fix capture of this in lambda functions

2021-03-01 Thread Olivier Goffart via Phabricator via cfe-commits
ogoffart created this revision.
ogoffart added a reviewer: rnk.
ogoffart requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Commit 1b04bdc2f3ffaa7a0e1e3dbdc3a0cd08f0b9a4ce 
 added 
support for
capturing the 'this' pointer in a SEH context (__finally or __except),
But the case in which the 'this' pointer is part of a lamdda capture
was not handled properly


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97687

Files:
  clang/lib/CodeGen/CGException.cpp
  clang/test/CodeGenCXX/exceptions-seh-filter-captures.cpp


Index: clang/test/CodeGenCXX/exceptions-seh-filter-captures.cpp
===
--- clang/test/CodeGenCXX/exceptions-seh-filter-captures.cpp
+++ clang/test/CodeGenCXX/exceptions-seh-filter-captures.cpp
@@ -123,3 +123,25 @@
 // CHECK: %[[l1_ref:[^ ]*]] = load i32*, i32** %[[l1_ref_ptr]]
 // CHECK: %[[l1:[^ ]*]] = load i32, i32* %[[l1_ref]]
 // CHECK: call i32 (i32, ...) @basic_filter(i32 %[[l1]], i32 %[[l2]])
+
+struct U {
+  void this_in_lambda();
+};
+
+void U::this_in_lambda() {
+  auto lambda = [=]() {
+__try {
+  might_crash();
+} __except (basic_filter(0, this)) {
+}
+  };
+  lambda();
+}
+
+// CHECK-LABEL: define internal i32 
@"?filt$0@0@?R@?0??this_in_lambda@U@@QEAAXXZ@"(i8* 
%exception_pointers, i8* %frame_pointer)
+// CHECK: %[[this_i8:[^ ]*]] = call i8* @llvm.localrecover(i8* bitcast (void 
(%class.anon.0*)* @"??R@?0??this_in_lambda@U@@QEAAXXZ@QEBA@XZ" to 
i8*), i8* %[[fp:[^ ]*]], i32 0)
+// CHECK: %[[this_ptr:[^ ]*]] = bitcast i8* %[[this_i8]] to %class.anon.0**
+// CHECK: %[[this:[^ ]*]] = load %class.anon.0*, %class.anon.0** 
%[[this_ptr]], align 8
+// CHECK: %[[actual_this_ptr:[^ ]*]] = getelementptr inbounds %class.anon.0, 
%class.anon.0* %[[this]], i32 0, i32 0
+// CHECK: %[[actual_this:[^ ]*]] = load %struct.U*, %struct.U** 
%[[actual_this_ptr]], align 8
+// CHECK: call i32 (i32, ...) @basic_filter(i32 0, %struct.U* %[[actual_this]])
Index: clang/lib/CodeGen/CGException.cpp
===
--- clang/lib/CodeGen/CGException.cpp
+++ clang/lib/CodeGen/CGException.cpp
@@ -1888,8 +1888,24 @@
 setAddrOfLocalVar(VD, Recovered);
 
 if (isa(VD)) {
-  CXXThisValue = Builder.CreateLoad(Recovered, "this");
-  CXXABIThisValue = CXXThisValue;
+  CXXABIThisAlignment = ParentCGF.CXXABIThisAlignment;
+  CXXThisAlignment = ParentCGF.CXXThisAlignment;
+  CXXABIThisValue = Builder.CreateLoad(Recovered, "this");
+  if (ParentCGF.LambdaThisCaptureField) {
+LambdaThisCaptureField = ParentCGF.LambdaThisCaptureField;
+// We are in a lambda function where "this" is captured so the
+// CXXThisValue need to be loaded from the lambda capture
+LValue ThisFieldLValue =
+EmitLValueForLambdaField(LambdaThisCaptureField);
+if (!LambdaThisCaptureField->getType()->isPointerType()) {
+  CXXThisValue = ThisFieldLValue.getAddress(*this).getPointer();
+} else {
+  CXXThisValue = EmitLoadOfLValue(ThisFieldLValue, SourceLocation())
+ .getScalarVal();
+}
+  } else {
+CXXThisValue = CXXABIThisValue;
+  }
 }
   }
 
@@ -1958,6 +1974,7 @@
   StartFunction(GlobalDecl(), RetTy, Fn, FnInfo, Args,
 OutlinedStmt->getBeginLoc(), OutlinedStmt->getBeginLoc());
   CurSEHParent = ParentCGF.CurSEHParent;
+  CurCodeDecl = ParentCGF.CurCodeDecl;
 
   CGM.SetInternalFunctionAttributes(GlobalDecl(), CurFn, FnInfo);
   EmitCapturedLocals(ParentCGF, OutlinedStmt, IsFilter);


Index: clang/test/CodeGenCXX/exceptions-seh-filter-captures.cpp
===
--- clang/test/CodeGenCXX/exceptions-seh-filter-captures.cpp
+++ clang/test/CodeGenCXX/exceptions-seh-filter-captures.cpp
@@ -123,3 +123,25 @@
 // CHECK: %[[l1_ref:[^ ]*]] = load i32*, i32** %[[l1_ref_ptr]]
 // CHECK: %[[l1:[^ ]*]] = load i32, i32* %[[l1_ref]]
 // CHECK: call i32 (i32, ...) @basic_filter(i32 %[[l1]], i32 %[[l2]])
+
+struct U {
+  void this_in_lambda();
+};
+
+void U::this_in_lambda() {
+  auto lambda = [=]() {
+__try {
+  might_crash();
+} __except (basic_filter(0, this)) {
+}
+  };
+  lambda();
+}
+
+// CHECK-LABEL: define internal i32 @"?filt$0@0@?R@?0??this_in_lambda@U@@QEAAXXZ@"(i8* %exception_pointers, i8* %frame_pointer)
+// CHECK: %[[this_i8:[^ ]*]] = call i8* @llvm.localrecover(i8* bitcast (void (%class.anon.0*)* @"??R@?0??this_in_lambda@U@@QEAAXXZ@QEBA@XZ" to i8*), i8* %[[fp:[^ ]*]], i32 0)
+// CHECK: %[[this_ptr:[^ ]*]] = bitcast i8* %[[this_i8]] to %class.anon.0**
+// CHECK: %[[this:[^ ]*]] = load %class.anon.0*, %class.anon.0** %[[this_ptr]], align 8
+// CHECK: %[[actual_this_ptr:[^ ]*]] = getelementptr inbounds %class.anon.0, %class.anon.0* %[[this]], i32 0, i32 

[PATCH] D97688: clang-format: use `ph` as a canonical raw string delimiter for google style

2021-03-01 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir created this revision.
krasimir requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97688

Files:
  clang/lib/Format/Format.cpp


Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -,7 +,7 @@
   },
   /*EnclosingFunctionNames=*/
   {},
-  /*CanonicalDelimiter=*/"",
+  /*CanonicalDelimiter=*/"pb",
   /*BasedOnStyle=*/"google",
   },
   {


Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -,7 +,7 @@
   },
   /*EnclosingFunctionNames=*/
   {},
-  /*CanonicalDelimiter=*/"",
+  /*CanonicalDelimiter=*/"pb",
   /*BasedOnStyle=*/"google",
   },
   {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D95458: [PowerPC] Exploit xxsplti32dx (constant materialization) for scalars

2021-03-01 Thread Stefan Pintilie via Phabricator via cfe-commits
stefanp added a comment.

Comments relate to just cleaning up the patch a little.




Comment at: llvm/lib/Target/PowerPC/PPCISelLowering.cpp:8593
+  return !convertToNonDenormSingle(ArgAPFloat);
+}
+

I'm wondering if it would not be better to just inline this. It's just "not" of 
another call. That would simplify the patch a little.



Comment at: llvm/lib/Target/PowerPC/PPCISelLowering.cpp:15874
+  return convertToNonDenormSingle(APFloatOfImm) ||
+ checkNonDenormCannotConvertToSingle(APFloatOfImm);
 }

Isn't this just :
```
return convertToNonDenormSingle(APFloatOfImm) ||
   !convertToNonDenormSingle(APFloatOfImm);
```
Which is always true?

Basically the logic is that we can now materialize without a load any `f32` or 
any `f64`.



Comment at: llvm/lib/Target/PowerPC/PPCISelLowering.h:1321
   bool convertToNonDenormSingle(APFloat &ArgAPFloat);
+  bool checkNonDenormCannotConvertToSingle(APInt &ArgAPInt);
+  bool checkNonDenormCannotConvertToSingle(APFloat &ArgAPFloat);

Conanap wrote:
> stefanp wrote:
> > Is the APInt version of this function used anywere?
> > 
> Hm I don't think so, although I implemented it for consistency with 
> `XXSPLTIDP` (`convertToNonDenormSingle`). I'll remove this if that is 
> preferred.
nit:
Ok, unless other reviewers disagree, just remove it.


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

https://reviews.llvm.org/D95458

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


[PATCH] D97491: [clang-tidy] Deprecate readability-deleted-default check

2021-03-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

In D97491#2589098 , @Eugene.Zelenko 
wrote:

> In D97491#2589097 , @njames93 wrote:
>
>> In D97491#2588835 , @Eugene.Zelenko 
>> wrote:
>>
>>> If `Wdefaulted-function-deleted` was introduced in 12.0, I think it's safe 
>>> just to remove `readability-deleted-default`.
>>
>> Wdefaulted-function-deleted was introduced in 8.0 and I think it was enabled 
>> by default even then. I'm thinking we may be able to squeeze this notice 
>> into the 12 branch and then it will be gone by 13
>
> Frankly, I don't remember any deprecated check in past. Obsolete checks were 
> just removed and this change was reflected in Release Notes.

With checks that have been released to the public, I think it's good to have a 
notice that the check was deprecated before we remove it.

LGTM! If we want to squeeze the notice into 12, I think that's also reasonable, 
but given that this has been around for a while, I'm also fine with a slightly 
longer deprecation period.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97491

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


[PATCH] D97681: [ASTMatchers] Add matchers for `CXXDeleteExpr`

2021-03-01 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:7621
+///   matches the expression 'delete Ptr'.
+AST_MATCHER_P_OVERLOAD(CXXDeleteExpr, deletes, internal::Matcher,
+   InnerMatcher, 1) {

aaron.ballman wrote:
> Why add this instead of continuing to use `has()`? (I worry a bit that we'll 
> want to add a verb for different subexpression matchers and it won't scale 
> well or we won't add verbs for different subexpressions and this'll introduce 
> a new inconsistency.)
This change is about lowering the barrier to entry. While `has` can be very 
powerful, its interface isn't newcomer friendly. 
You can put any matcher in, that may not make sense or ever be capable of 
actually matching but it will happily compile without emitting any warning. 
using `deletes` forces some type checking on the argument you provide.
The explicit names are also much better for documentation and API discovery.
When running in clang query with completions this is what appears at the top of 
the list
```
clang-query> m cxxDeleteExpr(
Matcher deletes(Matcher)
Matcher isArray()
```
A similar case is made for the matchers documentation.



Comment at: clang/include/clang/ASTMatchers/ASTMatchersInternal.h:163
+inline bool isArrayOperator(const CXXDeleteExpr &Node) {
+  return Node.isArrayFormAsWritten();
+}

aaron.ballman wrote:
> Do we need/want this interface to consider whether the user is matching 
> things spelled in source or not?
From what I can see the only time isArrayFrom and isArrayFromAsWritten 
differentiate is if normal `delete` operator is used on an arrayType. However 
that behaviour isn't standard afaik and was only added to be consistent with 
gcc and edg. If that case comes up we emit a fixit to add the `[]`.
Maybe there is merit to check traversal kind before assuming tho.




Comment at: clang/lib/ASTMatchers/Dynamic/Registry.cpp:269
   REGISTER_MATCHER(hasAnyUsingShadowDecl);
-  REGISTER_MATCHER(hasArgument);
   REGISTER_MATCHER(hasArgumentOfType);

aaron.ballman wrote:
> Why removing this?
Accident. Will re add.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97681

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


[PATCH] D97688: clang-format: use `ph` as a canonical raw string delimiter for google style

2021-03-01 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 327120.
krasimir added a comment.

clang-format: use `pb` as a canonical raw string delimiter for google style


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97688

Files:
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/Format.cpp


Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -1135,7 +1135,7 @@
   "ParseTestProto",
   "ParsePartialTestProto",
   },
-  /*CanonicalDelimiter=*/"",
+  /*CanonicalDelimiter=*/"pb",
   /*BasedOnStyle=*/"google",
   },
   };
Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -1651,7 +1651,7 @@
   StringRef OldDelimiter = *getRawStringDelimiter(Current.TokenText);
   StringRef NewDelimiter =
   getCanonicalRawStringDelimiter(Style, RawStringStyle.Language);
-  if (NewDelimiter.empty() || OldDelimiter.empty())
+  if (NewDelimiter.empty())
 NewDelimiter = OldDelimiter;
   // The text of a raw string is between the leading 'R"delimiter(' and the
   // trailing 'delimiter)"'.


Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -1135,7 +1135,7 @@
   "ParseTestProto",
   "ParsePartialTestProto",
   },
-  /*CanonicalDelimiter=*/"",
+  /*CanonicalDelimiter=*/"pb",
   /*BasedOnStyle=*/"google",
   },
   };
Index: clang/lib/Format/ContinuationIndenter.cpp
===
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -1651,7 +1651,7 @@
   StringRef OldDelimiter = *getRawStringDelimiter(Current.TokenText);
   StringRef NewDelimiter =
   getCanonicalRawStringDelimiter(Style, RawStringStyle.Language);
-  if (NewDelimiter.empty() || OldDelimiter.empty())
+  if (NewDelimiter.empty())
 NewDelimiter = OldDelimiter;
   // The text of a raw string is between the leading 'R"delimiter(' and the
   // trailing 'delimiter)"'.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97573: [OpenMP] Handle non-function context before checking for diagnostic emission

2021-03-01 Thread PremAnand Rao via Phabricator via cfe-commits
pmrao added inline comments.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:1946
+FunctionEmissionStatus FES = getEmissionStatus(FD);
+switch (FES) {
+case FunctionEmissionStatus::Emitted:

erichkeane wrote:
> Tabs here instead of spaces.
> 
> I think this is the right fix for SYCL, but @bader  should double-check that 
> he's ok with this or OMP.
> Tabs here instead of spaces.

Are you suggesting that I change the spaces to tabs instead?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97573

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


[PATCH] D95016: [Clang][RISCV] Add custom TableGen backend for riscv-vector intrinsics.

2021-03-01 Thread Zakk Chen via Phabricator via cfe-commits
khchen updated this revision to Diff 326980.
khchen marked 17 inline comments as done.
khchen added a comment.

1. address @jrtc27's suggestions, thanks.
2. fix several bugs.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95016

Files:
  clang/include/clang/Basic/BuiltinsRISCV.def
  clang/include/clang/Basic/CMakeLists.txt
  clang/include/clang/Basic/riscv_vector.td
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Headers/CMakeLists.txt
  clang/test/CodeGen/RISCV/rvv-intrinsics-generic/vadd.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-generic/vfadd.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vadd.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vfadd.c
  clang/test/CodeGen/RISCV/vadd.c
  clang/test/Headers/riscv-vector-header.c
  clang/utils/TableGen/CMakeLists.txt
  clang/utils/TableGen/RISCVVEmitter.cpp
  clang/utils/TableGen/TableGen.cpp
  clang/utils/TableGen/TableGenBackends.h
  llvm/docs/CommandGuide/tblgen.rst

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


[PATCH] D95016: [Clang][RISCV] Add custom TableGen backend for riscv-vector intrinsics.

2021-03-01 Thread Zakk Chen via Phabricator via cfe-commits
khchen added inline comments.



Comment at: clang/include/clang/Basic/riscv_vector.td:56
+//
+//   e: type of "t" as is (identity)
+//   v: computes a vector type whose element type is "t" for the current LMUL

jrtc27 wrote:
> khchen wrote:
> > jrtc27 wrote:
> > > Do we really need to invent an esoteric DSL?
> > I think this is different design choose.
> > Current design is based on 
> > https://repo.hca.bsc.es/gitlab/rferrer/llvm-epi/-/blob/EPI/clang/include/clang/Basic/epi_builtins.td,
> >  personally I think it makes td file more simpler.
> > 
> > Of course we can make td file more complex little bit and list all legal 
> > type and combination like 
> > https://github.com/isrc-cas/rvv-llvm/blob/rvv-iscas/clang/include/clang/Basic/riscv_vector.td
> >  did.
> > 
> > In fact, I don't have a strong opinion on which one is better
> > 
> > ps. current approach is similar to arm_sve.td design, maybe they know the 
> > some critical reason.
> I just find it really obfuscates things when we have all these magic 
> character sequences.
Sorry, what do you mean?



Comment at: clang/include/clang/Basic/riscv_vector.td:66
+//  element type which is bool
+//   0: void type, ignores "t"
+//   z: size_t, ignores "t"

craig.topper wrote:
> jrtc27 wrote:
> > craig.topper wrote:
> > > jrtc27 wrote:
> > > > khchen wrote:
> > > > > jrtc27 wrote:
> > > > > > Then why aren't these just base types? We don't have to follow the 
> > > > > > brain-dead nature of printf.
> > > > > Basically builtin interface is instantiated by the "base type + LMUL" 
> > > > > with type transformers. But in some intrinsic function we need a 
> > > > > specific type regardless "base type + LMUL"
> > > > > ex. `vuint32m2_t vssrl_vx_u32m2_vl (vuint32m2_t op1, uint8_t op2, 
> > > > > size_t vl);`
> > > > Then fix the way you define these? This is just bad design IMO.
> > > For each signature there is effectively a single key type that is a 
> > > vector. The type transformer is a list of rules for how to derive all of 
> > > the other operands from that one key type. Conceptually similar to 
> > > LLVMScalarOrSameVectorWidth or LLVMHalfElementsVectorType in 
> > > Intrinsics.td. Some types are fixed and don't vary by the key type. Like 
> > > the size_t vl operand or a store intrinsic returning void.  There is no 
> > > separate place to put a base type.
> > Oh I see, I hadn't appreciated that TypeRange got split up and each 
> > character was a whole separate intrinsic, I had misinterpreted it as it 
> > being a list of the types of arguments, i.e. an N-character string for an 
> > (N-1)-argument (plus return type) intrinsic that you could then use as a 
> > base and apply transformations too (e.g. "if" for a float-to-int intrinsic, 
> > with "vv" etc giving you a vectorised versions) and so was confused as to 
> > why the void/size_t/ptrdiff_t/uint8_t/bool-ness couldn't just be pushed 
> > into the TypeRange and the corresponding transforms left as "e". But, how 
> > _would_ you define vector float-to-int (and back) conversions with this 
> > scheme then?
> > 
> > On a related note, I feel one way to make this less obfuscated is change 
> > v/w/q/o to be v1/v2/v4/v8 (maybe with the 1 being optional, don't really 
> > care), and is also more extensible in future rather than ending up with yet 
> > more alphabet soup, though it does change the parsing from being a list of 
> > characters to a list of strings.
> I think these transforms are used for the float-to-int and int-to-float. 
> 
> //   I: given a vector type, compute the vector type with integer type
> //  elements of the same width
> //   F: given a vector type, compute the vector type with floating-point type
> //  elements of the same width
> 
> The float and integer types for conversion are always the same size or one 
> lmul up or one lmul down. So combining I and F with v or w should cover it.
Yes, thanks for Craig's comments, I and U are used to implement conversion.

void/size_t/ptrdiff_t/uint8_t are not related to basic type so it's why they 
are no transformed from transforms left as `e`.

> On a related note, I feel one way to make this less obfuscated is change 
> v/w/q/o to be v1/v2/v4/v8 (maybe with the 1 being optional, don't really 
> care), and is also more extensible in future rather than ending up with yet 
> more alphabet soup, though it does change the parsing from being a list of 
> characters to a list of strings.

In the downstream we define a "complex" transformer which is not included in 
this patch. It  uses a string and encode additional information for some 
special type, like indexed operand of indexed load/store (its type is using EEW 
encoded in the instruction with EMUL=(EEW/SEW)*LMUL).
I have considered to use list of string, but personally I still prefer to use a 
list of characters because it's not often to use "complex" transformer and 
overall looking at the riscv_vector.td I fee

[PATCH] D95016: [Clang][RISCV] Add custom TableGen backend for riscv-vector intrinsics.

2021-03-01 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added inline comments.



Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:50
+Boolean,
+SignInteger,
+UnsignedInteger,

Signed



Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:58-62
+  bool IsPointer = false;
+  // IsConstant indices are "int", but have the constant expression.
+  bool IsImmediate = false;
+  // const qualifier.
+  bool IsConstant = false;

This isn't expressive enough for the grammar you defined. `PCPCec` is supposed 
to give `const i8 * const i8 *`, whereas this will interpret it as `const i8 
*`. Given such types are presumably not needed you need to tighten the rules of 
your grammar.



Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:127
+
+enum RISCV_Extension : uint8_t {
+  Basic = 0,

No underscores in names



Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:173
+  StringRef getIRName() const { return IRName; }
+  uint8_t getRISCV_Extensions() const { return RISCV_Extensions; }
+

No underscores in names



Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:354-356
+  }
+
+  switch (ScalarType) {

Combine the two switch statements



Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:419
+  ClangBuiltinStr = "__rvv_";
+  if (isBoolean()) {
+ClangBuiltinStr += "bool" + utostr(64 / Scale.getValue()) + "_t";

Combine this with the switch



Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:441
+  assert(isValid() && "RVVType is invalid");
+  assert(ScalarType != ScalarTypeKind::Invalid && "ScalarType is invalid");
+  switch (ScalarType) {

Combine this with the switch



Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:452-467
+  default:
+break;
+  }
+
+  if (IsConstant)
+Str += "const ";
+

This should be able to be tidied up so there's only one switch



Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:627
+case 'W':
+  assert(isVector() && "'W' type transformer cannot be used on vectors");
+  ElementBitwidth *= 2;

This looks wrong



Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:259-260
+
+LMULType &LMULType::operator*=(unsigned RHS) {
+  this->Log2LMUL = this->Log2LMUL + RHS;
+  return *this;

khchen wrote:
> craig.topper wrote:
> > jrtc27 wrote:
> > > That's not how multiplication works. This is exponentiation. 
> > > Multiplication would be `Log2LMul + log2(RHS)`. Please don't abuse 
> > > operators like this.
> > This seems like it must be broken, but since we don't do widening or 
> > narrowing in this patch we didn't notice?
> Yes, thanks for point out. In my original plan is fixing that in followup 
> patches. 
> I also add more bug fixes into this patch.
Probably worth adding an an `assert(isPowerOf2_32(RHS));` too


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95016

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


[PATCH] D97573: [OpenMP] Handle non-function context before checking for diagnostic emission

2021-03-01 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:1946
+FunctionEmissionStatus FES = getEmissionStatus(FD);
+switch (FES) {
+case FunctionEmissionStatus::Emitted:

pmrao wrote:
> erichkeane wrote:
> > Tabs here instead of spaces.
> > 
> > I think this is the right fix for SYCL, but @bader  should double-check 
> > that he's ok with this or OMP.
> > Tabs here instead of spaces.
> 
> Are you suggesting that I change the spaces to tabs instead?
The reverse.  Change the tabs you have at the beginning of the line to spaces.  
I believe that is what the double-arrow character in Phab represents (a tab).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97573

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


[PATCH] D97573: [OpenMP] Handle non-function context before checking for diagnostic emission

2021-03-01 Thread PremAnand Rao via Phabricator via cfe-commits
pmrao marked an inline comment as not done.
pmrao added inline comments.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:1946
+FunctionEmissionStatus FES = getEmissionStatus(FD);
+switch (FES) {
+case FunctionEmissionStatus::Emitted:

erichkeane wrote:
> pmrao wrote:
> > erichkeane wrote:
> > > Tabs here instead of spaces.
> > > 
> > > I think this is the right fix for SYCL, but @bader  should double-check 
> > > that he's ok with this or OMP.
> > > Tabs here instead of spaces.
> > 
> > Are you suggesting that I change the spaces to tabs instead?
> The reverse.  Change the tabs you have at the beginning of the line to 
> spaces.  I believe that is what the double-arrow character in Phab represents 
> (a tab).
Oh!  I misunderstood then.   I thought phab was indicating that there are no 
changes in the line, except new indentation.

I didn't use tabs in my source file.   I don't see it in the character set.   
Perhaps something introduced it during the upload.   I will check.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97573

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


[PATCH] D97681: [ASTMatchers] Add matchers for `CXXDeleteExpr`

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



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:7621
+///   matches the expression 'delete Ptr'.
+AST_MATCHER_P_OVERLOAD(CXXDeleteExpr, deletes, internal::Matcher,
+   InnerMatcher, 1) {

njames93 wrote:
> aaron.ballman wrote:
> > Why add this instead of continuing to use `has()`? (I worry a bit that 
> > we'll want to add a verb for different subexpression matchers and it won't 
> > scale well or we won't add verbs for different subexpressions and this'll 
> > introduce a new inconsistency.)
> This change is about lowering the barrier to entry. While `has` can be very 
> powerful, its interface isn't newcomer friendly. 
> You can put any matcher in, that may not make sense or ever be capable of 
> actually matching but it will happily compile without emitting any warning. 
> using `deletes` forces some type checking on the argument you provide.
> The explicit names are also much better for documentation and API discovery.
> When running in clang query with completions this is what appears at the top 
> of the list
> ```
> clang-query> m cxxDeleteExpr(
> Matcher deletes(Matcher)
> Matcher isArray()
> ```
> A similar case is made for the matchers documentation.
Thanks! I agree with your assessment about this being a more user-friendly 
interface. My concerns are more mundane though. IIRC, each time we add a new 
matcher, we slow down compilation for the entire Clang project by a nontrivial 
amount because of the large amount of template instantiations involved. Because 
of that, we usually only add matchers when we find there's a need for them (as 
opposed to generating matchers for everything possible). So I worry that we'll 
slow down compile times and increase build sizes for a relatively uncommon AST 
matcher that isn't strictly necessary, and that it'll be a slippery slope to do 
more of this. That said, I've not measured the slowdown and perhaps things have 
improved here.

@klimek may have more context or thoughts on this.



Comment at: clang/include/clang/ASTMatchers/ASTMatchersInternal.h:163
+inline bool isArrayOperator(const CXXDeleteExpr &Node) {
+  return Node.isArrayFormAsWritten();
+}

njames93 wrote:
> aaron.ballman wrote:
> > Do we need/want this interface to consider whether the user is matching 
> > things spelled in source or not?
> From what I can see the only time isArrayFrom and isArrayFromAsWritten 
> differentiate is if normal `delete` operator is used on an arrayType. However 
> that behaviour isn't standard afaik and was only added to be consistent with 
> gcc and edg. If that case comes up we emit a fixit to add the `[]`.
> Maybe there is merit to check traversal kind before assuming tho.
> 
I think it's defensible either way, so I leave it to whatever you and @steveire 
think is appropriate.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97681

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


[PATCH] D97573: [OpenMP] Handle non-function context before checking for diagnostic emission

2021-03-01 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:1946
+FunctionEmissionStatus FES = getEmissionStatus(FD);
+switch (FES) {
+case FunctionEmissionStatus::Emitted:

pmrao wrote:
> erichkeane wrote:
> > pmrao wrote:
> > > erichkeane wrote:
> > > > Tabs here instead of spaces.
> > > > 
> > > > I think this is the right fix for SYCL, but @bader  should double-check 
> > > > that he's ok with this or OMP.
> > > > Tabs here instead of spaces.
> > > 
> > > Are you suggesting that I change the spaces to tabs instead?
> > The reverse.  Change the tabs you have at the beginning of the line to 
> > spaces.  I believe that is what the double-arrow character in Phab 
> > represents (a tab).
> Oh!  I misunderstood then.   I thought phab was indicating that there are no 
> changes in the line, except new indentation.
> 
> I didn't use tabs in my source file.   I don't see it in the character set.   
> Perhaps something introduced it during the upload.   I will check.
Oh, it looks like you're right, that must be a new feature of Phab that looks 
shockingly like an old one :)  I don't see tabs in the downloaded diff file, so 
consider that comment 'done'.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97573

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


[PATCH] D96120: [scudo] Port scudo sanitizer to Windows

2021-03-01 Thread Russell Gallop via Phabricator via cfe-commits
russell.gallop updated this revision to Diff 327123.
russell.gallop added a comment.

Update with suggested changes to MinGW.cpp


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

https://reviews.llvm.org/D96120

Files:
  clang/lib/Driver/ToolChains/MSVC.cpp
  clang/lib/Driver/ToolChains/MinGW.cpp
  compiler-rt/cmake/config-ix.cmake
  compiler-rt/lib/sanitizer_common/sanitizer_win.cpp
  compiler-rt/lib/scudo/CMakeLists.txt
  compiler-rt/lib/scudo/scudo_allocator.cpp
  compiler-rt/lib/scudo/scudo_crc32.cpp
  compiler-rt/lib/scudo/scudo_new_delete.cpp
  compiler-rt/lib/scudo/scudo_platform.h
  compiler-rt/lib/scudo/scudo_tsd.h
  compiler-rt/lib/scudo/scudo_tsd_shared.cpp
  compiler-rt/lib/scudo/scudo_tsd_shared.inc
  compiler-rt/test/scudo/cxx_threads.cpp
  compiler-rt/test/scudo/dealloc-race.c
  compiler-rt/test/scudo/fsanitize.c
  compiler-rt/test/scudo/interface.cpp
  compiler-rt/test/scudo/lit.cfg.py
  compiler-rt/test/scudo/malloc.cpp
  compiler-rt/test/scudo/memalign.c
  compiler-rt/test/scudo/mismatch.cpp
  compiler-rt/test/scudo/overflow.c
  compiler-rt/test/scudo/preload.cpp
  compiler-rt/test/scudo/rss.c
  compiler-rt/test/scudo/secondary.c
  compiler-rt/test/scudo/symbols.test
  compiler-rt/test/scudo/threads.c
  compiler-rt/test/scudo/tsd_destruction.c
  compiler-rt/test/scudo/valloc.c

Index: compiler-rt/test/scudo/valloc.c
===
--- compiler-rt/test/scudo/valloc.c
+++ compiler-rt/test/scudo/valloc.c
@@ -2,7 +2,7 @@
 // RUN: %run %t valid   2>&1
 // RUN: not %run %t invalid 2>&1 | FileCheck %s
 // RUN: %env_scudo_opts=allocator_may_return_null=1 %run %t invalid 2>&1
-// UNSUPPORTED: android
+// UNSUPPORTED: android, windows
 
 // Tests that valloc and pvalloc work as intended.
 
Index: compiler-rt/test/scudo/tsd_destruction.c
===
--- compiler-rt/test/scudo/tsd_destruction.c
+++ compiler-rt/test/scudo/tsd_destruction.c
@@ -1,5 +1,6 @@
 // RUN: %clang_scudo %s -o %t
 // RUN: %run %t 2>&1
+// UNSUPPORTED: windows
 
 #include 
 #include 
Index: compiler-rt/test/scudo/threads.c
===
--- compiler-rt/test/scudo/threads.c
+++ compiler-rt/test/scudo/threads.c
@@ -1,6 +1,7 @@
 // RUN: %clang_scudo %s -o %t
 // RUN: %env_scudo_opts="QuarantineSizeKb=0:ThreadLocalQuarantineSizeKb=0" %run %t 5 100 2>&1
 // RUN: %env_scudo_opts="QuarantineSizeKb=1024:ThreadLocalQuarantineSizeKb=64" %run %t 5 100 2>&1
+// UNSUPPORTED: windows
 
 // Tests parallel allocations and deallocations of memory chunks from a number
 // of concurrent threads, with and without quarantine.
Index: compiler-rt/test/scudo/symbols.test
===
--- compiler-rt/test/scudo/symbols.test
+++ compiler-rt/test/scudo/symbols.test
@@ -1,4 +1,4 @@
-UNSUPPORTED: android
+UNSUPPORTED: android, windows
 
 Verify that various functions are *not* present in the minimal binary. Presence
 of those symbols in the minimal runtime would mean that the split code made it
Index: compiler-rt/test/scudo/secondary.c
===
--- compiler-rt/test/scudo/secondary.c
+++ compiler-rt/test/scudo/secondary.c
@@ -6,37 +6,60 @@
 // allocated by the Secondary allocator, or writing too far in front of it.
 
 #include 
-#include 
-#include 
+#include 
 #include 
 #include 
+#ifdef _WIN32
+#include 
+#else
+#include 
 #include 
+#endif
 
+#ifdef _WIN32
+DWORD getsystempagesize() {
+  SYSTEM_INFO si;
+  GetSystemInfo(&si);
+  return si.dwPageSize;
+}
+LONG WINAPI handler(EXCEPTION_POINTERS *ExceptionInfo) {
+  fprintf(stderr, "AccessViolation\n");
+  ExitProcess(0);
+}
+#else
 void handler(int signo, siginfo_t *info, void *uctx) {
   if (info->si_code == SEGV_ACCERR) {
-fprintf(stderr, "SCUDO SIGSEGV\n");
+fprintf(stderr, "AccessViolation\n");
 exit(0);
   }
   exit(1);
 }
+long getsystempagesize() {
+  return sysconf(_SC_PAGESIZE);
+}
+#endif
 
 int main(int argc, char **argv)
 {
   // The size must be large enough to be serviced by the secondary allocator.
-  long page_size = sysconf(_SC_PAGESIZE);
-  size_t size = (1U << 17) + page_size;
-  struct sigaction a;
+  long page_size = getsystempagesize();
+  size_t size = (1U << 19) + page_size;
 
   assert(argc == 2);
-  memset(&a, 0, sizeof(a));
-  a.sa_sigaction = handler;
-  a.sa_flags = SA_SIGINFO;
 
   char *p = (char *)malloc(size);
   assert(p);
   memset(p, 'A', size); // This should not trigger anything.
   // Set up the SIGSEGV handler now, as the rest should trigger an AV.
+#ifdef _WIN32
+  SetUnhandledExceptionFilter(handler);
+#else
+  struct sigaction a = {0};
+  a.sa_sigaction = handler;
+  a.sa_flags = SA_SIGINFO;
   sigaction(SIGSEGV, &a, NULL);
+#endif
+
   if (!strcmp(argv[1], 

[PATCH] D96120: [scudo] Port scudo sanitizer to Windows

2021-03-01 Thread Russell Gallop via Phabricator via cfe-commits
russell.gallop added a comment.

In D96120#2591368 , @mstorsjo wrote:

> Yes, it would need something similar - I tried whipping something together, 
> which after some tweaks seems to work:
> Feel free to squash that into your patch (which saves me a bit of effort) :-)

Thanks for doing that. I've added this in.

> ...I did test building the double-free.cpp test with `-fsanitize=scudo`, and 
> it seems to work as it should for all three cases it tests...

Great, thanks.


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

https://reviews.llvm.org/D96120

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


[PATCH] D97411: [DebugInfo] Add an attribute to force type info to be emitted for types that are required to be complete.

2021-03-01 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added a comment.

I don't have an opinion about the attribute itself. I do have an opinion about 
using that attribute in libc++ instead of fixing the underlying issue (I think 
we shouldn't do it). Can you confirm what the problematic types are? In another 
patch I saw `__hash_node`, `__hash_value_type`, `__tree_node` and 
`__value_type`. Is that it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97411

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


[PATCH] D97693: [libclang] Remove LIBCLANG_INCLUDE_CLANG_TOOLS_EXTRA

2021-03-01 Thread Nico Weber via Phabricator via cfe-commits
thakis created this revision.
thakis added a reviewer: hans.
Herald added subscribers: arphaman, mgorny.
thakis requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

LIBCLANG_INCLUDE_CLANG_TOOLS_EXTRA causes clang-tools-extra tools
to be included in libclang, which caused a dependency cycle. The option
has been off by default for two releases now, and (based on a web search
and mailing list feedback) nobody seems to turn it on. Remove it, like
planned on https://reviews.llvm.org/D79599


https://reviews.llvm.org/D97693

Files:
  clang-tools-extra/test/CMakeLists.txt
  clang-tools-extra/test/clang-tidy/infrastructure/nolint-plugin.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/nolintnextline-plugin.cpp
  clang-tools-extra/test/lit.site.cfg.py.in
  clang/docs/ReleaseNotes.rst
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CMakeLists.txt
  llvm/utils/gn/secondary/clang-tools-extra/test/BUILD.gn
  llvm/utils/gn/secondary/clang/tools/libclang/BUILD.gn
  llvm/utils/gn/secondary/clang/tools/libclang/include_clang_tools_extra.gni

Index: llvm/utils/gn/secondary/clang/tools/libclang/include_clang_tools_extra.gni
===
--- llvm/utils/gn/secondary/clang/tools/libclang/include_clang_tools_extra.gni
+++ /dev/null
@@ -1,4 +0,0 @@
-declare_args() {
-  # Whether to include code from clang-tools-extra in libclang.
-  libclang_include_clang_tools_extra = false
-}
Index: llvm/utils/gn/secondary/clang/tools/libclang/BUILD.gn
===
--- llvm/utils/gn/secondary/clang/tools/libclang/BUILD.gn
+++ llvm/utils/gn/secondary/clang/tools/libclang/BUILD.gn
@@ -1,5 +1,4 @@
 import("//clang/lib/ARCMigrate/enable.gni")
-import("//clang/tools/libclang/include_clang_tools_extra.gni")
 import("//llvm/version.gni")
 
 # This build file is just enough to get check-clang to pass, it's missing
@@ -40,16 +39,6 @@
 
   defines = []
 
-  # FIXME: Once the GN build has a way to select which bits to build,
-  # only include this dependency if clang-tools-extra is part of the build.
-  if (libclang_include_clang_tools_extra) {
-defines += [ "CLANG_TOOL_EXTRA_BUILD" ]
-deps += [
-  "//clang-tools-extra/clang-include-fixer/plugin",
-  "//clang-tools-extra/clang-tidy/plugin",
-]
-  }
-
   if (host_os == "win") {
 defines += [ "_CINDEX_LIB_" ]
   }
Index: llvm/utils/gn/secondary/clang-tools-extra/test/BUILD.gn
===
--- llvm/utils/gn/secondary/clang-tools-extra/test/BUILD.gn
+++ llvm/utils/gn/secondary/clang-tools-extra/test/BUILD.gn
@@ -1,6 +1,5 @@
 import("//clang-tools-extra/clang-tidy/enable.gni")
 import("//clang/lib/StaticAnalyzer/Frontend/enable.gni")
-import("//clang/tools/libclang/include_clang_tools_extra.gni")
 import("//llvm/triples.gni")
 import("//llvm/utils/gn/build/write_cmake_config.gni")
 import("clang_tools_extra_lit_site_cfg_files.gni")
@@ -44,12 +43,6 @@
   } else {
 extra_values += [ "CLANG_TIDY_ENABLE_STATIC_ANALYZER=0" ]
   }
-
-  if (libclang_include_clang_tools_extra) {
-extra_values += [ "LIBCLANG_INCLUDE_CLANG_TOOLS_EXTRA=1" ]
-  } else {
-extra_values += [ "LIBCLANG_INCLUDE_CLANG_TOOLS_EXTRA=0" ]
-  }
 }
 
 write_lit_config("lit_unit_site_cfg") {
Index: clang/tools/libclang/CMakeLists.txt
===
--- clang/tools/libclang/CMakeLists.txt
+++ clang/tools/libclang/CMakeLists.txt
@@ -52,22 +52,6 @@
   list(APPEND LIBS clangARCMigrate)
 endif ()
 
-option(LIBCLANG_INCLUDE_CLANG_TOOLS_EXTRA
-  "Include code from clang-tools-extra in libclang." OFF)
-
-if (LIBCLANG_INCLUDE_CLANG_TOOLS_EXTRA)
-  if (TARGET clangTidyPlugin)
-add_definitions(-DCLANG_TOOL_EXTRA_BUILD)
-list(APPEND LIBS clangTidyPlugin)
-list(APPEND LIBS clangIncludeFixerPlugin)
-if(LLVM_ENABLE_MODULES)
-  list(APPEND LLVM_COMPILE_FLAGS "-fmodules-ignore-macro=CLANG_TOOL_EXTRA_BUILD")
-endif()
-  else ()
-message(FATAL_ERROR "LIBCLANG_INCLUDE_CLANG_TOOLS_EXTRA needs clang-tools-extra in LLVM_ENABLE_PROJECTS")
-  endif ()
-endif ()
-
 if (HAVE_LIBDL)
   list(APPEND LIBS ${CMAKE_DL_LIBS})
 elseif (CLANG_BUILT_STANDALONE)
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -9161,16 +9161,3 @@
 OS << "--\n";
   }
 }
-
-#ifdef CLANG_TOOL_EXTRA_BUILD
-// This anchor is used to force the linker to link the clang-tidy plugin.
-extern volatile int ClangTidyPluginAnchorSource;
-static int LLVM_ATTRIBUTE_UNUSED ClangTidyPluginAnchorDestination =
-ClangTidyPluginAnchorSource;
-
-// This anchor is used to force the linker to link the clang-include-fixer
-// plugin.
-extern volatile int ClangIncludeFixerPluginAnchorSource;
-static i

[PATCH] D94500: [clang-format] Rework Whitesmiths mode to use line-level values in UnwrappedLineParser

2021-03-01 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

In D94500#2593229 , @timwoj wrote:

> In D94500#2592448 , 
> @HazardyKnusperkeks wrote:
>
>> Do you need someone to push this?
>
> Yes I do. I don't have committer access.

Please state the name and mail for the commit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94500

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


[PATCH] D97695: [clang-cl] make -f(no-)ident a CoreOption

2021-03-01 Thread Nico Weber via Phabricator via cfe-commits
thakis created this revision.
thakis added a reviewer: hans.
Herald added subscribers: jansvoboda11, dang.
thakis requested review of this revision.

https://reviews.llvm.org/D97695

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


Index: clang/test/Driver/cl-options.c
===
--- clang/test/Driver/cl-options.c
+++ clang/test/Driver/cl-options.c
@@ -639,6 +639,8 @@
 // RUN: -fdiagnostics-parseable-fixits \
 // RUN: -fdiagnostics-absolute-paths \
 // RUN: -ferror-limit=10 \
+// RUN: -fident \
+// RUN: -fno-ident \
 // RUN: -fmsc-version=1800 \
 // RUN: -fno-strict-aliasing \
 // RUN: -fstrict-aliasing \
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -669,8 +669,10 @@
   HelpText<"Emit metadata containing compiler name and version">;
 def Qn : Flag<["-"], "Qn">, Flags<[CC1Option]>,
   HelpText<"Do not emit metadata containing compiler name and version">;
-def : Flag<["-"], "fident">, Group, Alias, Flags<[CC1Option]>;
-def : Flag<["-"], "fno-ident">, Group, Alias, Flags<[CC1Option]>;
+def : Flag<["-"], "fident">, Group, Alias,
+  Flags<[CoreOption, CC1Option]>;
+def : Flag<["-"], "fno-ident">, Group, Alias,
+  Flags<[CoreOption, CC1Option]>;
 def Qunused_arguments : Flag<["-"], "Qunused-arguments">, 
Flags<[NoXarchOption, CoreOption]>,
   HelpText<"Don't emit warning for unused driver arguments">;
 def Q : Flag<["-"], "Q">, IgnoredGCCCompat;


Index: clang/test/Driver/cl-options.c
===
--- clang/test/Driver/cl-options.c
+++ clang/test/Driver/cl-options.c
@@ -639,6 +639,8 @@
 // RUN: -fdiagnostics-parseable-fixits \
 // RUN: -fdiagnostics-absolute-paths \
 // RUN: -ferror-limit=10 \
+// RUN: -fident \
+// RUN: -fno-ident \
 // RUN: -fmsc-version=1800 \
 // RUN: -fno-strict-aliasing \
 // RUN: -fstrict-aliasing \
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -669,8 +669,10 @@
   HelpText<"Emit metadata containing compiler name and version">;
 def Qn : Flag<["-"], "Qn">, Flags<[CC1Option]>,
   HelpText<"Do not emit metadata containing compiler name and version">;
-def : Flag<["-"], "fident">, Group, Alias, Flags<[CC1Option]>;
-def : Flag<["-"], "fno-ident">, Group, Alias, Flags<[CC1Option]>;
+def : Flag<["-"], "fident">, Group, Alias,
+  Flags<[CoreOption, CC1Option]>;
+def : Flag<["-"], "fno-ident">, Group, Alias,
+  Flags<[CoreOption, CC1Option]>;
 def Qunused_arguments : Flag<["-"], "Qunused-arguments">, Flags<[NoXarchOption, CoreOption]>,
   HelpText<"Don't emit warning for unused driver arguments">;
 def Q : Flag<["-"], "Q">, IgnoredGCCCompat;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97695: [clang-cl] make -f(no-)ident a CoreOption

2021-03-01 Thread Hans Wennborg via Phabricator via cfe-commits
hans accepted this revision.
hans added a comment.
This revision is now accepted and ready to land.

lgtm

Probably worth explaining in the description why this is useful from clang-cl 
(it being on by default, and we'd like a nice way to turn it off).


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

https://reviews.llvm.org/D97695

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


[PATCH] D97573: [OpenMP] Handle non-function context before checking for diagnostic emission

2021-03-01 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

looks reasonable to me


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97573

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


[clang] 83feaa3 - [clang-cl] make -f(no-)ident a CoreOption

2021-03-01 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2021-03-01T11:53:51-05:00
New Revision: 83feaa36ad53ce93ed808169d3316ed757703e47

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

LOG: [clang-cl] make -f(no-)ident a CoreOption

On clang emits the compiler version string into debug information
by default for both dwarf and codeview. That makes compiler output
needlessly compiler-version-dependent which makes e.g. comparing
object file outputs during a bisect hard. So it's nice if there's
an easy way to turn this off.

(On ELF, this flag also controls the .comment section, but that
part is ELF-only. The debug-info bit isn't.)

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

Added: 


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

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c34c371197c3..f4da19324f02 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -669,8 +669,10 @@ def Qy : Flag<["-"], "Qy">, Flags<[CC1Option]>,
   HelpText<"Emit metadata containing compiler name and version">;
 def Qn : Flag<["-"], "Qn">, Flags<[CC1Option]>,
   HelpText<"Do not emit metadata containing compiler name and version">;
-def : Flag<["-"], "fident">, Group, Alias, Flags<[CC1Option]>;
-def : Flag<["-"], "fno-ident">, Group, Alias, Flags<[CC1Option]>;
+def : Flag<["-"], "fident">, Group, Alias,
+  Flags<[CoreOption, CC1Option]>;
+def : Flag<["-"], "fno-ident">, Group, Alias,
+  Flags<[CoreOption, CC1Option]>;
 def Qunused_arguments : Flag<["-"], "Qunused-arguments">, 
Flags<[NoXarchOption, CoreOption]>,
   HelpText<"Don't emit warning for unused driver arguments">;
 def Q : Flag<["-"], "Q">, IgnoredGCCCompat;

diff  --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c
index eb340a40421b..0e07ea49e4b8 100644
--- a/clang/test/Driver/cl-options.c
+++ b/clang/test/Driver/cl-options.c
@@ -639,6 +639,8 @@
 // RUN: -fdiagnostics-parseable-fixits \
 // RUN: -fdiagnostics-absolute-paths \
 // RUN: -ferror-limit=10 \
+// RUN: -fident \
+// RUN: -fno-ident \
 // RUN: -fmsc-version=1800 \
 // RUN: -fno-strict-aliasing \
 // RUN: -fstrict-aliasing \



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


[PATCH] D97695: [clang-cl] make -f(no-)ident a CoreOption

2021-03-01 Thread Nico Weber 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 rG83feaa36ad53: [clang-cl] make -f(no-)ident a CoreOption 
(authored by thakis).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97695

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


Index: clang/test/Driver/cl-options.c
===
--- clang/test/Driver/cl-options.c
+++ clang/test/Driver/cl-options.c
@@ -639,6 +639,8 @@
 // RUN: -fdiagnostics-parseable-fixits \
 // RUN: -fdiagnostics-absolute-paths \
 // RUN: -ferror-limit=10 \
+// RUN: -fident \
+// RUN: -fno-ident \
 // RUN: -fmsc-version=1800 \
 // RUN: -fno-strict-aliasing \
 // RUN: -fstrict-aliasing \
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -669,8 +669,10 @@
   HelpText<"Emit metadata containing compiler name and version">;
 def Qn : Flag<["-"], "Qn">, Flags<[CC1Option]>,
   HelpText<"Do not emit metadata containing compiler name and version">;
-def : Flag<["-"], "fident">, Group, Alias, Flags<[CC1Option]>;
-def : Flag<["-"], "fno-ident">, Group, Alias, Flags<[CC1Option]>;
+def : Flag<["-"], "fident">, Group, Alias,
+  Flags<[CoreOption, CC1Option]>;
+def : Flag<["-"], "fno-ident">, Group, Alias,
+  Flags<[CoreOption, CC1Option]>;
 def Qunused_arguments : Flag<["-"], "Qunused-arguments">, 
Flags<[NoXarchOption, CoreOption]>,
   HelpText<"Don't emit warning for unused driver arguments">;
 def Q : Flag<["-"], "Q">, IgnoredGCCCompat;


Index: clang/test/Driver/cl-options.c
===
--- clang/test/Driver/cl-options.c
+++ clang/test/Driver/cl-options.c
@@ -639,6 +639,8 @@
 // RUN: -fdiagnostics-parseable-fixits \
 // RUN: -fdiagnostics-absolute-paths \
 // RUN: -ferror-limit=10 \
+// RUN: -fident \
+// RUN: -fno-ident \
 // RUN: -fmsc-version=1800 \
 // RUN: -fno-strict-aliasing \
 // RUN: -fstrict-aliasing \
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -669,8 +669,10 @@
   HelpText<"Emit metadata containing compiler name and version">;
 def Qn : Flag<["-"], "Qn">, Flags<[CC1Option]>,
   HelpText<"Do not emit metadata containing compiler name and version">;
-def : Flag<["-"], "fident">, Group, Alias, Flags<[CC1Option]>;
-def : Flag<["-"], "fno-ident">, Group, Alias, Flags<[CC1Option]>;
+def : Flag<["-"], "fident">, Group, Alias,
+  Flags<[CoreOption, CC1Option]>;
+def : Flag<["-"], "fno-ident">, Group, Alias,
+  Flags<[CoreOption, CC1Option]>;
 def Qunused_arguments : Flag<["-"], "Qunused-arguments">, Flags<[NoXarchOption, CoreOption]>,
   HelpText<"Don't emit warning for unused driver arguments">;
 def Q : Flag<["-"], "Q">, IgnoredGCCCompat;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D97695: [clang-cl] make -f(no-)ident a CoreOption

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

Thanks! Landed with a more detailed commit description in 
https://reviews.llvm.org/rG83feaa36ad53ce93ed808169d3316ed757703e47


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97695

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


[PATCH] D97693: [libclang] Remove LIBCLANG_INCLUDE_CLANG_TOOLS_EXTRA

2021-03-01 Thread Hans Wennborg via Phabricator via cfe-commits
hans accepted this revision.
hans added a comment.
This revision is now accepted and ready to land.

lgtm


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

https://reviews.llvm.org/D97693

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


[clang] 21280d3 - [clang] SimpleMFlag helper in Options.td

2021-03-01 Thread Stanislav Mekhanoshin via cfe-commits

Author: Stanislav Mekhanoshin
Date: 2021-03-01T09:00:30-08:00
New Revision: 21280d35d652788309176831bd88257b58f674f9

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

LOG: [clang] SimpleMFlag helper in Options.td

This is the new helper to create a boolean -m and -mno-
options.

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

Added: 


Modified: 
clang/include/clang/Driver/Options.td

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index f4da19324f02..75c4eff29f1c 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -289,6 +289,17 @@ multiclass OptOutFFlag, HelpText;
 }
 
+// Creates a positive and negative flags where both of them are prefixed with
+// "m", have help text specified for positive and negative option, and a Group
+// optionally specified by the opt_group argument, otherwise Group.
+multiclass SimpleMFlag {
+  def m#NAME : Flag<["-"], "m"#name>, Group,
+HelpText;
+  def mno_#NAME : Flag<["-"], "mno-"#name>, Group,
+HelpText;
+}
+
 
//===--===//
 // BoolOption
 
//===--===//
@@ -3138,23 +3149,18 @@ def mcode_object_version_EQ : Joined<["-"], 
"mcode-object-version=">, Group,
   MetaVarName<"">, Values<"2,3,4">;
 
-def mcode_object_v3_legacy : Flag<["-"], "mcode-object-v3">, Group,
-  HelpText<"Legacy option to specify code object ABI V2 (-mnocode-object-v3) 
or V3 (-mcode-object-v3) (AMDGPU only)">;
-def mno_code_object_v3_legacy : Flag<["-"], "mno-code-object-v3">, 
Group;
-
-def mcumode : Flag<["-"], "mcumode">, Group,
-  HelpText<"Specify CU (-mcumode) or WGP (-mno-cumode) wavefront execution 
mode (AMDGPU only)">;
-def mno_cumode : Flag<["-"], "mno-cumode">, Group;
-
-def mtgsplit : Flag<["-"], "mtgsplit">, Group,
-  HelpText<"Enable threadgroup split execution mode (AMDGPU only)">;
-def mno_tgsplit : Flag<["-"], "mno-tgsplit">, Group,
-  HelpText<"Disable threadgroup split execution mode (AMDGPU only)">;
-
-def mwavefrontsize64 : Flag<["-"], "mwavefrontsize64">, Group,
-  HelpText<"Specify wavefront size 64 mode (AMDGPU only)">;
-def mno_wavefrontsize64 : Flag<["-"], "mno-wavefrontsize64">, Group,
-  HelpText<"Specify wavefront size 32 mode (AMDGPU only)">;
+defm code_object_v3_legacy : SimpleMFlag<"code-object-v3",
+  "Legacy option to specify code object ABI V3",
+  "Legacy option to specify code object ABI V2",
+  " (AMDGPU only)">;
+defm cumode : SimpleMFlag<"cumode",
+  "Specify CU wavefront", "Specify WGP wavefront",
+  " execution mode (AMDGPU only)", m_amdgpu_Features_Group>;
+defm tgsplit : SimpleMFlag<"tgsplit", "Enable", "Disable",
+  " threadgroup split execution mode (AMDGPU only)", m_amdgpu_Features_Group>;
+defm wavefrontsize64 : SimpleMFlag<"wavefrontsize64",
+  "Specify wavefront size 64", "Specify wavefront size 32",
+  " mode (AMDGPU only)">;
 
 defm unsafe_fp_atomics : BoolOption<"m", "unsafe-fp-atomics",
   TargetOpts<"AllowAMDGPUUnsafeFPAtomics">, DefaultFalse,



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


[PATCH] D97699: [analyzer] Add InvalidPtrChecker

2021-03-01 Thread Zurab Tsinadze via Phabricator via cfe-commits
zukatsinadze created this revision.
zukatsinadze added reviewers: NoQ, vsavchenko, Charusso, Szelethus, martong.
zukatsinadze added a project: clang.
Herald added subscribers: steakhal, ASDenysPetrov, ormris, dkrupp, donat.nagy, 
mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun, 
mgorny.
zukatsinadze requested review of this revision.
Herald added a subscriber: cfe-commits.

This patch introduces a new checker: `alpha.security.cert.env.InvalidPtr`

Checker finds usage of invalidated pointers.

Based on the following SEI CERT Rules:
ENV31-C: https://wiki.sei.cmu.edu/confluence/x/8tYxBQ
ENV34-C: https://wiki.sei.cmu.edu/confluence/x/5NUxBQ


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97699

Files:
  clang/docs/analyzer/checkers.rst
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
  clang/test/Analysis/cert/env31-c/_putenv_s.c
  clang/test/Analysis/cert/env31-c/_wputenv_s.c
  clang/test/Analysis/cert/env31-c/putenv.c
  clang/test/Analysis/cert/env31-c/setenv.c
  clang/test/Analysis/cert/env31-c/unsetenv.c
  clang/test/Analysis/cert/env34-c-cert-examples.c
  clang/test/Analysis/cert/env34-c.c

Index: clang/test/Analysis/cert/env34-c.c
===
--- /dev/null
+++ clang/test/Analysis/cert/env34-c.c
@@ -0,0 +1,241 @@
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=alpha.security.cert.env.InvalidPtr\
+// RUN:  -analyzer-output=text -verify -Wno-unused %s
+
+#include "../Inputs/system-header-simulator.h"
+char *getenv(const char *name);
+char *setlocale(int category, const char *locale);
+char *strerror(int errnum);
+
+typedef struct {
+  char * field;
+} lconv;
+lconv *localeconv(void);
+
+typedef struct {
+} tm;
+char *asctime(const tm *timeptr);
+
+int strcmp(const char*, const char*);
+extern void foo(char *e);
+extern char* bar();
+
+
+void getenv_test1() {
+  char *p, *p2, *p3;
+
+  p = getenv("VAR");
+  *p; // no-warning
+
+  p = getenv("VAR2");
+  // expected-note@-1{{previous function call was here}}
+  p3 = getenv("VAR2");
+  // expected-note@-1{{'getenv' call may invalidate the the result of the previous 'getenv'}}
+
+  p2 = getenv("VAR3");
+
+  *p;
+  // expected-warning@-1{{dereferencing an invalid pointer}}
+  // expected-note@-2{{dereferencing an invalid pointer}}
+}
+
+void getenv_test2() {
+  char *p, *p2;
+  p = getenv("VAR");
+  *p; // no-warning
+
+  p = getenv("VAR2");
+  // expected-note@-1{{previous function call was here}}
+  *p; // no-warning
+
+  p2 = getenv("VAR3");
+  // expected-note@-1{{previous function call was here}}
+  // expected-note@-2{{'getenv' call may invalidate the the result of the previous 'getenv'}}
+
+  *p;
+  // expected-warning@-1{{dereferencing an invalid pointer}}
+  // expected-note@-2{{dereferencing an invalid pointer}}
+
+  *p2; // no-warning
+
+  p = getenv("VAR4");
+  // expected-note@-1{{'getenv' call may invalidate the the result of the previous 'getenv'}}
+
+  *p; // no-warning
+  *p2;
+  // expected-warning@-1{{dereferencing an invalid pointer}}
+  // expected-note@-2{{dereferencing an invalid pointer}}
+}
+
+void getenv_test3() {
+  char *p, *p2;
+  p = getenv("VAR");
+  // expected-note@-1{{previous function call was here}}
+  *p; // no-warning
+
+  p2 = getenv("VAR2");
+  // expected-note@-1{{'getenv' call may invalidate the the result of the previous 'getenv'}}
+
+  foo(p);
+  // expected-warning@-1{{use of invalidated pointer 'p' in a function call}}
+  // expected-note@-2{{use of invalidated pointer 'p' in a function call}}
+}
+
+void getenv_test4() {
+  static const char *array[] = {
+ 0,
+ 0,
+ "/var/tmp",
+ "/usr/tmp",
+ "/tmp",
+ "."
+  };
+
+  if( !array[0] )
+  // expected-note@-1{{Taking true branch}}
+array[0] = getenv("TEMPDIR");
+// expected-note@-1{{previous function call was here}}
+
+  if( !array[1] )
+  // expected-note@-1{{Taking true branch}}
+array[1] = getenv("TMPDIR");
+// expected-note@-1{{'getenv' call may invalidate the the result of the previous 'getenv'}}
+
+  *array[0];
+  // expected-warning@-1{{dereferencing an invalid pointer}}
+  // expected-note@-2{{dereferencing an invalid pointer}}
+}
+
+void getenv_test5() {
+  char *p, *p2;
+  p = getenv("something");
+  p = bar();
+  p2 = getenv("something");
+  *p; // no-warning
+}
+
+void getenv_test6() {
+  strcmp(getenv("VAR1"), getenv("VAR2"));
+  // expected-note@-1{{'getenv' call may invalidate the the result of the previous 'getenv'}}
+  // expected-note@-2{{previous function call was here}}
+  // expected-warning@-3{{use of invalidated pointer 'getenv("VAR1")' in a function call}}
+  // expected-note@-4{{use of invalidated pointer 'getenv("VAR1")' in a function call}}
+}
+
+void setlocale_test1() {
+  char *p, *p2;
+  p = setlocale(0, "VAR");
+  *p; // no-warning
+
+  p = setlocale(0, "VAR2");
+  // e

[PATCH] D97699: [analyzer] Add InvalidPtrChecker

2021-03-01 Thread Zurab Tsinadze via Phabricator via cfe-commits
zukatsinadze added a comment.

Please suggest which package to use for the checker. 
CERT rules are ENV, however, it deals with non-ENV functions as well.

Also, I am having a problem with `checkDeadSymbols`, it is similar to one 
xazax.hun faced here: http://reviews.llvm.org/D14203 (many many years ago)
`envp` memory region is marked dead too early in case of aliasing. Please check 
the snippets, the second one is problematic:

  int main(int argc, char **argv, char *envp[]) {
putenv((char*) "NAME=VALUE"); // envp invalidated
envp[0]; // gives error
  }
  
  int main(int argc, char **argv, char *envp[]) {
char **e = envp;
putenv((char*) "NAME=VALUE"); // envp invalidated
e[0]; // does not give error :(
  
// warnOnDeadSymbol reports 'envp' dead here
  } 
  
  int main(int argc, char **argv, char *envp[]) {
char **e = envp;
putenv((char*) "NAME=VALUE"); // envp invalidated
e[0]; // gives error again
  
/*
  use 'envp' somehow here
*/
  }


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97699

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


[PATCH] D97681: [ASTMatchers] Add matchers for `CXXDeleteExpr`

2021-03-01 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:7621
+///   matches the expression 'delete Ptr'.
+AST_MATCHER_P_OVERLOAD(CXXDeleteExpr, deletes, internal::Matcher,
+   InnerMatcher, 1) {

aaron.ballman wrote:
> njames93 wrote:
> > aaron.ballman wrote:
> > > Why add this instead of continuing to use `has()`? (I worry a bit that 
> > > we'll want to add a verb for different subexpression matchers and it 
> > > won't scale well or we won't add verbs for different subexpressions and 
> > > this'll introduce a new inconsistency.)
> > This change is about lowering the barrier to entry. While `has` can be very 
> > powerful, its interface isn't newcomer friendly. 
> > You can put any matcher in, that may not make sense or ever be capable of 
> > actually matching but it will happily compile without emitting any warning. 
> > using `deletes` forces some type checking on the argument you provide.
> > The explicit names are also much better for documentation and API discovery.
> > When running in clang query with completions this is what appears at the 
> > top of the list
> > ```
> > clang-query> m cxxDeleteExpr(
> > Matcher deletes(Matcher)
> > Matcher isArray()
> > ```
> > A similar case is made for the matchers documentation.
> Thanks! I agree with your assessment about this being a more user-friendly 
> interface. My concerns are more mundane though. IIRC, each time we add a new 
> matcher, we slow down compilation for the entire Clang project by a 
> nontrivial amount because of the large amount of template instantiations 
> involved. Because of that, we usually only add matchers when we find there's 
> a need for them (as opposed to generating matchers for everything possible). 
> So I worry that we'll slow down compile times and increase build sizes for a 
> relatively uncommon AST matcher that isn't strictly necessary, and that it'll 
> be a slippery slope to do more of this. That said, I've not measured the 
> slowdown and perhaps things have improved here.
> 
> @klimek may have more context or thoughts on this.
That is a good point, maybe though if we felt so inclined. We could actually 
split up the Matcher definitions from their declarations. It may not work as 
nicely with PolymorphicMatchers but given around 3/4 of the matchers aren't, It 
could have a positive impact on compile time.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97681

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


[PATCH] D95204: [lld-macho] Switch default to new Darwin backend

2021-03-01 Thread Jez Ng via Phabricator via cfe-commits
int3 updated this revision to Diff 327145.
int3 added a comment.

keep around darwinnew link for now


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95204

Files:
  clang/lib/Driver/ToolChain.cpp
  clang/test/Driver/Inputs/lld/ld64.lld.darwinnew
  clang/test/Driver/Inputs/lld/ld64.lld.darwinold
  clang/test/Driver/darwin-ld-demangle-lld.c
  clang/test/Driver/darwin-ld-platform-version-ios.c
  clang/test/Driver/darwin-ld-platform-version-macos.c
  clang/test/Driver/darwin-ld-platform-version-tvos.c
  clang/test/Driver/darwin-ld-platform-version-watchos.c
  lld/tools/lld/CMakeLists.txt
  lld/tools/lld/lld.cpp
  llvm/utils/gn/build/BUILD.gn
  llvm/utils/gn/secondary/lld/tools/lld/BUILD.gn

Index: llvm/utils/gn/secondary/lld/tools/lld/BUILD.gn
===
--- llvm/utils/gn/secondary/lld/tools/lld/BUILD.gn
+++ llvm/utils/gn/secondary/lld/tools/lld/BUILD.gn
@@ -5,6 +5,7 @@
   "ld.lld",
   "ld64.lld",
   "ld64.lld.darwinnew",
+  "ld64.lld.darwinold",
   "wasm-ld",
 ]
 foreach(target, symlinks) {
Index: llvm/utils/gn/build/BUILD.gn
===
--- llvm/utils/gn/build/BUILD.gn
+++ llvm/utils/gn/build/BUILD.gn
@@ -218,11 +218,7 @@
 
   # On Windows, the linker is not invoked through the compiler driver.
   if (use_lld && host_os != "win") {
-if (host_os == "mac") {
-  ldflags += [ "-fuse-ld=lld.darwinnew" ]
-} else {
-  ldflags += [ "-fuse-ld=lld" ]
-}
+ldflags += [ "-fuse-ld=lld" ]
   }
 
   if (llvm_build_instrumented_coverage) {
Index: lld/tools/lld/lld.cpp
===
--- lld/tools/lld/lld.cpp
+++ lld/tools/lld/lld.cpp
@@ -56,7 +56,7 @@
   Gnu,   // -flavor gnu
   WinLink,   // -flavor link
   Darwin,// -flavor darwin
-  DarwinNew, // -flavor darwinnew
+  DarwinOld, // -flavor darwinold
   Wasm,  // -flavor wasm
 };
 
@@ -70,8 +70,9 @@
   .CasesLower("ld", "ld.lld", "gnu", Gnu)
   .CasesLower("wasm", "ld-wasm", Wasm)
   .CaseLower("link", WinLink)
-  .CasesLower("ld64", "ld64.lld", "darwin", Darwin)
-  .CasesLower("darwinnew", "ld64.lld.darwinnew", DarwinNew)
+  .CasesLower("ld64", "ld64.lld", "darwin", "darwinnew",
+  "ld64.lld.darwinnew", Darwin)
+  .CasesLower("darwinold", "ld64.lld.darwinold", DarwinOld)
   .Default(Invalid);
 }
 
@@ -154,9 +155,9 @@
   case WinLink:
 return !coff::link(args, exitEarly, stdoutOS, stderrOS);
   case Darwin:
-return !mach_o::link(args, exitEarly, stdoutOS, stderrOS);
-  case DarwinNew:
 return !macho::link(args, exitEarly, stdoutOS, stderrOS);
+  case DarwinOld:
+return !mach_o::link(args, exitEarly, stdoutOS, stderrOS);
   case Wasm:
 return !lld::wasm::link(args, exitEarly, stdoutOS, stderrOS);
   default:
Index: lld/tools/lld/CMakeLists.txt
===
--- lld/tools/lld/CMakeLists.txt
+++ lld/tools/lld/CMakeLists.txt
@@ -25,7 +25,7 @@
 
 if(NOT LLD_SYMLINKS_TO_CREATE)
   set(LLD_SYMLINKS_TO_CREATE
-  lld-link ld.lld ld64.lld ld64.lld.darwinnew wasm-ld)
+  lld-link ld.lld ld64.lld ld64.lld.darwinnew ld64.lld.darwinold wasm-ld)
 endif()
 
 foreach(link ${LLD_SYMLINKS_TO_CREATE})
Index: clang/test/Driver/darwin-ld-platform-version-watchos.c
===
--- clang/test/Driver/darwin-ld-platform-version-watchos.c
+++ clang/test/Driver/darwin-ld-platform-version-watchos.c
@@ -1,6 +1,6 @@
 // RUN: touch %t.o
 
-// RUN: %clang -target arm64_32-apple-watchos5.2 -fuse-ld= \
+// RUN: %clang -target arm64_32-apple-watchos5.2 -fuse-ld=lld.darwinold \
 // RUN:   -isysroot %S/Inputs/WatchOS6.0.sdk -mlinker-version=0 \
 // RUN:   -### %t.o 2>&1 \
 // RUN:   | FileCheck --check-prefix=LINKER-OLD %s
@@ -8,7 +8,7 @@
 // RUN:   -isysroot %S/Inputs/WatchOS6.0.sdk -mlinker-version=400 \
 // RUN:   -### %t.o 2>&1 \
 // RUN:   | FileCheck --check-prefix=LINKER-OLD %s
-// RUN: %clang -target arm64_32-apple-watchos5.2 -fuse-ld=lld.darwinnew \
+// RUN: %clang -target arm64_32-apple-watchos5.2 -fuse-ld=lld \
 // RUN:   -isysroot %S/Inputs/WatchOS6.0.sdk -mlinker-version=0 \
 // RUN:   -### %t.o -B%S/Inputs/lld 2>&1 \
 // RUN:   | FileCheck --check-prefix=LINKER-NEW %s
Index: clang/test/Driver/darwin-ld-platform-version-tvos.c
===
--- clang/test/Driver/darwin-ld-platform-version-tvos.c
+++ clang/test/Driver/darwin-ld-platform-version-tvos.c
@@ -1,6 +1,6 @@
 // RUN: touch %t.o
 
-// RUN: %clang -target arm64-apple-tvos12.3 -fuse-ld= \
+// RUN: %clang -target arm64-apple-tvos12.3 -fuse-ld=lld.darwinold \
 // RUN:   -isysroot %S/Inputs/iPhoneOS13.0.sdk -mlinker-version=0 \
 // RUN:   -### %t.o 2>&1 \
 // RUN:   | FileCheck --check-prefix=LINKER-OLD %s
@@ -8,7 +8,7 @@
 // RUN:

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

2021-03-01 Thread David Goldman via Phabricator via cfe-commits
dgoldman updated this revision to Diff 327146.
dgoldman added a comment.

Add comment and  rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96612

Files:
  clang-tools-extra/clangd/FindSymbols.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
@@ -912,6 +912,42 @@
 WithDetail(""));
 }
 
+TEST(DocumentSymbolsTest, ObjCCategoriesAndClassExtensions) {
+  TestTU TU;
+  TU.ExtraArgs = {"-xobjective-c++", "-Wno-objc-root-class"};
+  Annotations Main(R"cpp(
+  $Cat[[@interface Cat
+  + (id)sharedCat;
+  @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")),
+Children(AllOf(WithName("+sharedCat"),
+   WithKind(SymbolKind::Method,
+  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/FindSymbols.cpp
===
--- clang-tools-extra/clangd/FindSymbols.cpp
+++ clang-tools-extra/clangd/FindSymbols.cpp
@@ -172,6 +172,26 @@
 }
 
 namespace {
+std::string getSymbolName(ASTContext &Ctx, const NamedDecl &ND) {
+  // Print `MyClass(Category)` instead of `Category` and `MyClass()` instead
+  // of `anonymous`.
+  if (const auto *Container = dyn_cast(&ND))
+return printObjCContainer(*Container);
+  // Differentiate between class and instance methods: print `-foo` instead of
+  // `foo` and `+sharedInstance` instead of `sharedInstance`.
+  if (const auto *Method = dyn_cast(&ND)) {
+std::string Name;
+llvm::raw_string_ostream OS(Name);
+
+OS << (Method->isInstanceMethod() ? '-' : '+');
+Method->getSelector().print(OS);
+
+OS.flush();
+return Name;
+  }
+  return printName(Ctx, ND);
+}
+
 std::string getSymbolDetail(ASTContext &Ctx, const NamedDecl &ND) {
   PrintingPolicy P(Ctx.getPrintingPolicy());
   P.SuppressScope = true;
@@ -220,7 +240,7 @@
   SymbolKind SK = indexSymbolKindToSymbolKind(SymInfo.Kind);
 
   DocumentSymbol SI;
-  SI.name = printName(Ctx, ND);
+  SI.name = getSymbolName(Ctx, ND);
   SI.kind = SK;
   SI.deprecated = ND.isDeprecated();
   SI.range = Range{sourceLocToPosition(SM, SymbolRange->getBegin()),


Index: clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
+++ clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
@@ -912,6 +912,42 @@
 WithDetail(""));
 }
 
+TEST(DocumentSymbolsTest, ObjCCategoriesAndClassExtensions) {
+  TestTU TU;
+  TU.ExtraArgs = {"-xobjective-c++", "-Wno-objc-root-class"};
+  Annotations Main(R"cpp(
+  $Cat[[@interface Cat
+  + (id)sharedCat;
+  @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")),
+Children(AllOf(WithName("+sharedCat"),
+   WithKind(SymbolKind::Method,
+  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));
+}
+
 

[PATCH] D95204: [lld-macho] Switch default to new Darwin backend

2021-03-01 Thread Jez Ng 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 rG415c0cd698a8: [lld-macho] Switch default to new Darwin 
backend (authored by int3).
Herald added a project: lld-macho.

Changed prior to commit:
  https://reviews.llvm.org/D95204?vs=327145&id=327148#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95204

Files:
  clang/lib/Driver/ToolChain.cpp
  clang/test/Driver/Inputs/lld/ld64.lld.darwinnew
  clang/test/Driver/Inputs/lld/ld64.lld.darwinold
  clang/test/Driver/darwin-ld-demangle-lld.c
  clang/test/Driver/darwin-ld-platform-version-ios.c
  clang/test/Driver/darwin-ld-platform-version-macos.c
  clang/test/Driver/darwin-ld-platform-version-tvos.c
  clang/test/Driver/darwin-ld-platform-version-watchos.c
  lld/test/MachO/invalid/stub-link.s
  lld/test/MachO/lit.local.cfg
  lld/test/MachO/search-paths-darwin.test
  lld/test/MachO/syslibroot.test
  lld/test/darwin/cmdline-lto_library.objtxt
  lld/test/darwin/cmdline-objc_gc.objtxt
  lld/test/darwin/cmdline-objc_gc_compaction.objtxt
  lld/test/darwin/cmdline-objc_gc_only.objtxt
  lld/test/darwin/native-and-mach-o.objtxt
  lld/test/mach-o/Inputs/swift-version-1.yaml
  lld/test/mach-o/Inputs/wrong-arch-error.yaml
  lld/test/mach-o/PIE.yaml
  lld/test/mach-o/align_text.yaml
  lld/test/mach-o/arm-interworking-movw.yaml
  lld/test/mach-o/arm-interworking.yaml
  lld/test/mach-o/arm-shims.yaml
  lld/test/mach-o/arm-subsections-via-symbols.yaml
  lld/test/mach-o/arm64-reloc-negDelta32-fixup.yaml
  lld/test/mach-o/arm64-relocs-errors-delta64-offset.yaml
  lld/test/mach-o/arm64-section-order.yaml
  lld/test/mach-o/bind-opcodes.yaml
  lld/test/mach-o/cstring-sections.yaml
  lld/test/mach-o/data-in-code-load-command.yaml
  lld/test/mach-o/data-only-dylib.yaml
  lld/test/mach-o/dead-strip-globals.yaml
  lld/test/mach-o/debug-syms.yaml
  lld/test/mach-o/demangle.yaml
  lld/test/mach-o/dependency_info.yaml
  lld/test/mach-o/do-not-emit-unwind-fde-arm64.yaml
  lld/test/mach-o/dso_handle.yaml
  lld/test/mach-o/dylib-install-names.yaml
  lld/test/mach-o/eh-frame-relocs-arm64.yaml
  lld/test/mach-o/empty-sections.yaml
  lld/test/mach-o/error-simulator-vs-macosx.yaml
  lld/test/mach-o/exe-offsets.yaml
  lld/test/mach-o/exe-segment-overlap.yaml
  lld/test/mach-o/executable-exports.yaml
  lld/test/mach-o/export-trie-order.yaml
  lld/test/mach-o/exported_symbols_list-dylib.yaml
  lld/test/mach-o/exported_symbols_list-obj.yaml
  lld/test/mach-o/exported_symbols_list-undef.yaml
  lld/test/mach-o/fat-archive.yaml
  lld/test/mach-o/filelist.yaml
  lld/test/mach-o/flat_namespace_undef_error.yaml
  lld/test/mach-o/flat_namespace_undef_suppress.yaml
  lld/test/mach-o/force_load-dylib.yaml
  lld/test/mach-o/force_load-x86_64.yaml
  lld/test/mach-o/framework-user-paths.yaml
  lld/test/mach-o/function-starts-load-command.yaml
  lld/test/mach-o/gcc_except_tab-got-arm64.yaml
  lld/test/mach-o/got-order.yaml
  lld/test/mach-o/hello-world-arm64.yaml
  lld/test/mach-o/hello-world-armv6.yaml
  lld/test/mach-o/hello-world-armv7.yaml
  lld/test/mach-o/hello-world-x86.yaml
  lld/test/mach-o/hello-world-x86_64.yaml
  lld/test/mach-o/image-base.yaml
  lld/test/mach-o/infer-arch.yaml
  lld/test/mach-o/interposing-section.yaml
  lld/test/mach-o/keep_private_externs.yaml
  lld/test/mach-o/lazy-bind-x86_64.yaml
  lld/test/mach-o/lc_segment_filesize.yaml
  lld/test/mach-o/lib-search-paths.yaml
  lld/test/mach-o/library-order.yaml
  lld/test/mach-o/library-rescan.yaml
  lld/test/mach-o/libresolve-bizarre-root-override.yaml
  lld/test/mach-o/libresolve-multiple-syslibroots.yaml
  lld/test/mach-o/libresolve-one-syslibroot.yaml
  lld/test/mach-o/libresolve-simple.yaml
  lld/test/mach-o/libresolve-user-paths.yaml
  lld/test/mach-o/libresolve-z.yaml
  lld/test/mach-o/load-commands-size.yaml
  lld/test/mach-o/mach_header-cpusubtype.yaml
  lld/test/mach-o/mh_bundle_header.yaml
  lld/test/mach-o/mh_dylib_header.yaml
  lld/test/mach-o/objc-category-list-atom.yaml
  lld/test/mach-o/objc-image-info-host-vs-simulator.yaml
  lld/test/mach-o/objc-image-info-invalid-size.yaml
  lld/test/mach-o/objc-image-info-invalid-version.yaml
  lld/test/mach-o/objc-image-info-mismatched-swift-version.yaml
  lld/test/mach-o/objc-image-info-pass-output.yaml
  lld/test/mach-o/objc-image-info-simulator-vs-host.yaml
  lld/test/mach-o/objc-image-info-unsupported-gc.yaml
  lld/test/mach-o/objc_export_list.yaml
  lld/test/mach-o/order_file-basic.yaml
  lld/test/mach-o/parse-aliases.yaml
  lld/test/mach-o/parse-arm-relocs.yaml
  lld/test/mach-o/parse-cfstring32.yaml
  lld/test/mach-o/parse-cfstring64.yaml
  lld/test/mach-o/parse-compact-unwind32.yaml
  lld/test/mach-o/parse-compact-unwind64.yaml
  lld/test/mach-o/parse-data-in-code-armv7.yaml
  lld/test/mach-o/parse-data-in-code-x86.yaml
  lld/test/mach-o/parse-data-relocs-arm64.yaml
  lld/test/mach-o/parse-data-relo

[PATCH] D97699: [analyzer] Add InvalidPtrChecker

2021-03-01 Thread Zurab Tsinadze via Phabricator via cfe-commits
zukatsinadze updated this revision to Diff 327150.
zukatsinadze added a comment.

Fixed docs.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97699

Files:
  clang/docs/analyzer/checkers.rst
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
  clang/test/Analysis/cert/env31-c/_putenv_s.c
  clang/test/Analysis/cert/env31-c/_wputenv_s.c
  clang/test/Analysis/cert/env31-c/putenv.c
  clang/test/Analysis/cert/env31-c/setenv.c
  clang/test/Analysis/cert/env31-c/unsetenv.c
  clang/test/Analysis/cert/env34-c-cert-examples.c
  clang/test/Analysis/cert/env34-c.c

Index: clang/test/Analysis/cert/env34-c.c
===
--- /dev/null
+++ clang/test/Analysis/cert/env34-c.c
@@ -0,0 +1,241 @@
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=alpha.security.cert.env.InvalidPtr\
+// RUN:  -analyzer-output=text -verify -Wno-unused %s
+
+#include "../Inputs/system-header-simulator.h"
+char *getenv(const char *name);
+char *setlocale(int category, const char *locale);
+char *strerror(int errnum);
+
+typedef struct {
+  char * field;
+} lconv;
+lconv *localeconv(void);
+
+typedef struct {
+} tm;
+char *asctime(const tm *timeptr);
+
+int strcmp(const char*, const char*);
+extern void foo(char *e);
+extern char* bar();
+
+
+void getenv_test1() {
+  char *p, *p2, *p3;
+
+  p = getenv("VAR");
+  *p; // no-warning
+
+  p = getenv("VAR2");
+  // expected-note@-1{{previous function call was here}}
+  p3 = getenv("VAR2");
+  // expected-note@-1{{'getenv' call may invalidate the the result of the previous 'getenv'}}
+
+  p2 = getenv("VAR3");
+
+  *p;
+  // expected-warning@-1{{dereferencing an invalid pointer}}
+  // expected-note@-2{{dereferencing an invalid pointer}}
+}
+
+void getenv_test2() {
+  char *p, *p2;
+  p = getenv("VAR");
+  *p; // no-warning
+
+  p = getenv("VAR2");
+  // expected-note@-1{{previous function call was here}}
+  *p; // no-warning
+
+  p2 = getenv("VAR3");
+  // expected-note@-1{{previous function call was here}}
+  // expected-note@-2{{'getenv' call may invalidate the the result of the previous 'getenv'}}
+
+  *p;
+  // expected-warning@-1{{dereferencing an invalid pointer}}
+  // expected-note@-2{{dereferencing an invalid pointer}}
+
+  *p2; // no-warning
+
+  p = getenv("VAR4");
+  // expected-note@-1{{'getenv' call may invalidate the the result of the previous 'getenv'}}
+
+  *p; // no-warning
+  *p2;
+  // expected-warning@-1{{dereferencing an invalid pointer}}
+  // expected-note@-2{{dereferencing an invalid pointer}}
+}
+
+void getenv_test3() {
+  char *p, *p2;
+  p = getenv("VAR");
+  // expected-note@-1{{previous function call was here}}
+  *p; // no-warning
+
+  p2 = getenv("VAR2");
+  // expected-note@-1{{'getenv' call may invalidate the the result of the previous 'getenv'}}
+
+  foo(p);
+  // expected-warning@-1{{use of invalidated pointer 'p' in a function call}}
+  // expected-note@-2{{use of invalidated pointer 'p' in a function call}}
+}
+
+void getenv_test4() {
+  static const char *array[] = {
+ 0,
+ 0,
+ "/var/tmp",
+ "/usr/tmp",
+ "/tmp",
+ "."
+  };
+
+  if( !array[0] )
+  // expected-note@-1{{Taking true branch}}
+array[0] = getenv("TEMPDIR");
+// expected-note@-1{{previous function call was here}}
+
+  if( !array[1] )
+  // expected-note@-1{{Taking true branch}}
+array[1] = getenv("TMPDIR");
+// expected-note@-1{{'getenv' call may invalidate the the result of the previous 'getenv'}}
+
+  *array[0];
+  // expected-warning@-1{{dereferencing an invalid pointer}}
+  // expected-note@-2{{dereferencing an invalid pointer}}
+}
+
+void getenv_test5() {
+  char *p, *p2;
+  p = getenv("something");
+  p = bar();
+  p2 = getenv("something");
+  *p; // no-warning
+}
+
+void getenv_test6() {
+  strcmp(getenv("VAR1"), getenv("VAR2"));
+  // expected-note@-1{{'getenv' call may invalidate the the result of the previous 'getenv'}}
+  // expected-note@-2{{previous function call was here}}
+  // expected-warning@-3{{use of invalidated pointer 'getenv("VAR1")' in a function call}}
+  // expected-note@-4{{use of invalidated pointer 'getenv("VAR1")' in a function call}}
+}
+
+void setlocale_test1() {
+  char *p, *p2;
+  p = setlocale(0, "VAR");
+  *p; // no-warning
+
+  p = setlocale(0, "VAR2");
+  // expected-note@-1{{previous function call was here}}
+  *p; // no-warning
+
+  p2 = setlocale(0, "VAR3");
+  // expected-note@-1{{'setlocale' call may invalidate the the result of the previous 'setlocale'}}
+
+  *p;
+  // expected-warning@-1{{dereferencing an invalid pointer}}
+  // expected-note@-2{{dereferencing an invalid pointer}}
+}
+
+void setlocale_test2(int flag) {
+  char *p, *p2;
+  p = setlocale(0, "VAR");
+  *p; // no-warning
+
+  p = setlocale(0, "VAR2");
+  // expected-note@-1{{previous function 

[clang-tools-extra] 5a2141e - [clangd] Improve document symbols support for Objective-C categories and methods

2021-03-01 Thread David Goldman via cfe-commits

Author: David Goldman
Date: 2021-03-01T12:37:31-05:00
New Revision: 5a2141e3a08ccaacbdb8faf64a47347531b015e0

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

LOG: [clangd] Improve document symbols support for Objective-C categories and 
methods

- Categories will now show up as `MyClass(Category)` instead of
  `Category` and `MyCategory()` instead of `(anonymous)` in document
  symbols

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

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

Added: 


Modified: 
clang-tools-extra/clangd/FindSymbols.cpp
clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/FindSymbols.cpp 
b/clang-tools-extra/clangd/FindSymbols.cpp
index ca4b8dafa5a0..bf441e8bc1bf 100644
--- a/clang-tools-extra/clangd/FindSymbols.cpp
+++ b/clang-tools-extra/clangd/FindSymbols.cpp
@@ -172,6 +172,26 @@ getWorkspaceSymbols(llvm::StringRef Query, int Limit,
 }
 
 namespace {
+std::string getSymbolName(ASTContext &Ctx, const NamedDecl &ND) {
+  // Print `MyClass(Category)` instead of `Category` and `MyClass()` instead
+  // of `anonymous`.
+  if (const auto *Container = dyn_cast(&ND))
+return printObjCContainer(*Container);
+  // Differentiate between class and instance methods: print `-foo` instead of
+  // `foo` and `+sharedInstance` instead of `sharedInstance`.
+  if (const auto *Method = dyn_cast(&ND)) {
+std::string Name;
+llvm::raw_string_ostream OS(Name);
+
+OS << (Method->isInstanceMethod() ? '-' : '+');
+Method->getSelector().print(OS);
+
+OS.flush();
+return Name;
+  }
+  return printName(Ctx, ND);
+}
+
 std::string getSymbolDetail(ASTContext &Ctx, const NamedDecl &ND) {
   PrintingPolicy P(Ctx.getPrintingPolicy());
   P.SuppressScope = true;
@@ -220,7 +240,7 @@ llvm::Optional declToSym(ASTContext &Ctx, 
const NamedDecl &ND) {
   SymbolKind SK = indexSymbolKindToSymbolKind(SymInfo.Kind);
 
   DocumentSymbol SI;
-  SI.name = printName(Ctx, ND);
+  SI.name = getSymbolName(Ctx, ND);
   SI.kind = SK;
   SI.deprecated = ND.isDeprecated();
   SI.range = Range{sourceLocToPosition(SM, SymbolRange->getBegin()),

diff  --git a/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp 
b/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
index 7333d451fde1..8cae9d606159 100644
--- a/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
@@ -912,6 +912,42 @@ TEST(DocumentSymbolsTest, DependentType) {
 WithDetail(""));
 }
 
+TEST(DocumentSymbolsTest, ObjCCategoriesAndClassExtensions) {
+  TestTU TU;
+  TU.ExtraArgs = {"-xobjective-c++", "-Wno-objc-root-class"};
+  Annotations Main(R"cpp(
+  $Cat[[@interface Cat
+  + (id)sharedCat;
+  @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")),
+Children(AllOf(WithName("+sharedCat"),
+   WithKind(SymbolKind::Method,
+  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



___
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-03-01 Thread David Goldman 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 rG5a2141e3a08c: [clangd] Improve document symbols support for 
Objective-C categories and methods (authored by dgoldman).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96612

Files:
  clang-tools-extra/clangd/FindSymbols.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
@@ -912,6 +912,42 @@
 WithDetail(""));
 }
 
+TEST(DocumentSymbolsTest, ObjCCategoriesAndClassExtensions) {
+  TestTU TU;
+  TU.ExtraArgs = {"-xobjective-c++", "-Wno-objc-root-class"};
+  Annotations Main(R"cpp(
+  $Cat[[@interface Cat
+  + (id)sharedCat;
+  @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")),
+Children(AllOf(WithName("+sharedCat"),
+   WithKind(SymbolKind::Method,
+  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/FindSymbols.cpp
===
--- clang-tools-extra/clangd/FindSymbols.cpp
+++ clang-tools-extra/clangd/FindSymbols.cpp
@@ -172,6 +172,26 @@
 }
 
 namespace {
+std::string getSymbolName(ASTContext &Ctx, const NamedDecl &ND) {
+  // Print `MyClass(Category)` instead of `Category` and `MyClass()` instead
+  // of `anonymous`.
+  if (const auto *Container = dyn_cast(&ND))
+return printObjCContainer(*Container);
+  // Differentiate between class and instance methods: print `-foo` instead of
+  // `foo` and `+sharedInstance` instead of `sharedInstance`.
+  if (const auto *Method = dyn_cast(&ND)) {
+std::string Name;
+llvm::raw_string_ostream OS(Name);
+
+OS << (Method->isInstanceMethod() ? '-' : '+');
+Method->getSelector().print(OS);
+
+OS.flush();
+return Name;
+  }
+  return printName(Ctx, ND);
+}
+
 std::string getSymbolDetail(ASTContext &Ctx, const NamedDecl &ND) {
   PrintingPolicy P(Ctx.getPrintingPolicy());
   P.SuppressScope = true;
@@ -220,7 +240,7 @@
   SymbolKind SK = indexSymbolKindToSymbolKind(SymInfo.Kind);
 
   DocumentSymbol SI;
-  SI.name = printName(Ctx, ND);
+  SI.name = getSymbolName(Ctx, ND);
   SI.kind = SK;
   SI.deprecated = ND.isDeprecated();
   SI.range = Range{sourceLocToPosition(SM, SymbolRange->getBegin()),


Index: clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
+++ clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
@@ -912,6 +912,42 @@
 WithDetail(""));
 }
 
+TEST(DocumentSymbolsTest, ObjCCategoriesAndClassExtensions) {
+  TestTU TU;
+  TU.ExtraArgs = {"-xobjective-c++", "-Wno-objc-root-class"};
+  Annotations Main(R"cpp(
+  $Cat[[@interface Cat
+  + (id)sharedCat;
+  @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")),
+Children(AllOf(WithName("+sharedCat"),
+   WithKind(SymbolKind::Method,
+  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,
+  

[PATCH] D97449: [Diagnose] Unify MCContext and LLVMContext diagnosing

2021-03-01 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen updated this revision to Diff 327155.
ychen added a comment.

- Add clang Diagnostic Category/Group/Kinds for SourceMgr errors
- Add comments in MCContext
- Simplify Clang handler
- Implement DiagnosticInfoSrcMgr::print
- Simplify DiagnosticInfoSrcMgr ctor


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97449

Files:
  clang/include/clang/Basic/DiagnosticCategories.td
  clang/include/clang/Basic/DiagnosticFrontendKinds.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/lib/CodeGen/CodeGenAction.cpp
  lldb/source/Expression/IRExecutionUnit.cpp
  llvm/include/llvm/CodeGen/AsmPrinter.h
  llvm/include/llvm/IR/DiagnosticInfo.h
  llvm/include/llvm/IR/LLVMContext.h
  llvm/include/llvm/MC/MCContext.h
  llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
  llvm/lib/CodeGen/MachineModuleInfo.cpp
  llvm/lib/IR/DiagnosticInfo.cpp
  llvm/lib/IR/LLVMContext.cpp
  llvm/lib/IR/LLVMContextImpl.h
  llvm/lib/MC/MCContext.cpp
  llvm/lib/MC/MCParser/AsmParser.cpp
  llvm/test/CodeGen/AMDGPU/lds-initializer.ll
  llvm/test/CodeGen/AMDGPU/lds-zero-initializer.ll
  llvm/test/CodeGen/XCore/section-name.ll
  llvm/tools/llc/llc.cpp

Index: llvm/tools/llc/llc.cpp
===
--- llvm/tools/llc/llc.cpp
+++ llvm/tools/llc/llc.cpp
@@ -290,6 +290,22 @@
   bool *HasError;
   LLCDiagnosticHandler(bool *HasErrorPtr) : HasError(HasErrorPtr) {}
   bool handleDiagnostics(const DiagnosticInfo &DI) override {
+if (DI.getKind() == llvm::DK_SrcMgr) {
+  const auto &DISM = cast(DI);
+  const SMDiagnostic &SMD = DISM.getSMDiag();
+
+  if (SMD.getKind() == SourceMgr::DK_Error)
+*HasError = true;
+
+  SMD.print(nullptr, errs());
+
+  // For testing purposes, we print the LocCookie here.
+  if (DISM.isInlineAsmDiag() && DISM.getLocCookie())
+WithColor::note() << "!srcloc = " << DISM.getLocCookie() << "\n";
+
+  return true;
+}
+
 if (DI.getSeverity() == DS_Error)
   *HasError = true;
 
@@ -305,19 +321,6 @@
   }
 };
 
-static void InlineAsmDiagHandler(const SMDiagnostic &SMD, void *Context,
- unsigned LocCookie) {
-  bool *HasError = static_cast(Context);
-  if (SMD.getKind() == SourceMgr::DK_Error)
-*HasError = true;
-
-  SMD.print(nullptr, errs());
-
-  // For testing purposes, we print the LocCookie here.
-  if (LocCookie)
-WithColor::note() << "!srcloc = " << LocCookie << "\n";
-}
-
 // main - Entry point for the llc compiler.
 //
 int main(int argc, char **argv) {
@@ -367,7 +370,6 @@
   bool HasError = false;
   Context.setDiagnosticHandler(
   std::make_unique(&HasError));
-  Context.setInlineAsmDiagnosticHandler(InlineAsmDiagHandler, &HasError);
 
   Expected> RemarksFileOrErr =
   setupLLVMOptimizationRemarks(Context, RemarksFilename, RemarksPasses,
Index: llvm/test/CodeGen/XCore/section-name.ll
===
--- llvm/test/CodeGen/XCore/section-name.ll
+++ llvm/test/CodeGen/XCore/section-name.ll
@@ -1,4 +1,4 @@
-; RUN: llc < %s -march=xcore -o /dev/null 2>&1 | FileCheck %s
+; RUN: not llc < %s -march=xcore -o /dev/null 2>&1 | FileCheck %s
 
 @bar = internal global i32 zeroinitializer
 
Index: llvm/test/CodeGen/AMDGPU/lds-zero-initializer.ll
===
--- llvm/test/CodeGen/AMDGPU/lds-zero-initializer.ll
+++ llvm/test/CodeGen/AMDGPU/lds-zero-initializer.ll
@@ -1,7 +1,7 @@
-; RUN: llc -march=amdgcn -mcpu=tahiti < %s -o /dev/null 2>&1 | FileCheck %s
-; RUN: llc -march=amdgcn -mcpu=tonga < %s -o /dev/null 2>&1 | FileCheck %s
+; RUN: not llc -march=amdgcn -mcpu=tahiti -filetype=null < %s 2>&1 | FileCheck %s
+; RUN: not llc -march=amdgcn -mcpu=tonga -filetype=null < %s 2>&1 | FileCheck %s
 
-; CHECK: lds: unsupported initializer for address space
+; CHECK: error: lds: unsupported initializer for address space
 
 @lds = addrspace(3) global [256 x i32] zeroinitializer
 
Index: llvm/test/CodeGen/AMDGPU/lds-initializer.ll
===
--- llvm/test/CodeGen/AMDGPU/lds-initializer.ll
+++ llvm/test/CodeGen/AMDGPU/lds-initializer.ll
@@ -1,5 +1,5 @@
-; RUN: llc -march=amdgcn -mcpu=tahiti < %s -o /dev/null 2>&1 | FileCheck %s
-; RUN: llc -march=amdgcn -mcpu=tonga < %s -o /dev/null 2>&1 | FileCheck %s
+; RUN: not llc -march=amdgcn -mcpu=tahiti < %s -o /dev/null 2>&1 | FileCheck %s
+; RUN: not llc -march=amdgcn -mcpu=tonga < %s -o /dev/null 2>&1 | FileCheck %s
 
 ; CHECK: lds: unsupported initializer for address space
 
Index: llvm/lib/MC/MCParser/AsmParser.cpp
===
--- llvm/lib/MC/MCParser/AsmParser.cpp
+++ llvm/lib/MC/MCParser/AsmParser.cpp
@@ -2348,7 +2348,7 @@
 /// will use the last parsed cpp hash line filename comment
 /// for the Filename and LineNo if any in the diagnostic.

[PATCH] D97449: [Diagnose] Unify MCContext and LLVMContext diagnosing

2021-03-01 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added inline comments.



Comment at: clang/lib/CodeGen/CodeGenAction.cpp:477
+  StringRef Message = D.getMessage();
+  if (Message.startswith("error: "))
+Message = Message.substr(7);

MaskRay wrote:
> `StringRef::consume_front`
> 
> I know you are moving code, but do you know why it needs to chop off the 
> `error: ` prefix (why does the message get a prefix here?)
It was introduced by 
https://github.com/llvm/llvm-project/commit/5ec32e7fd845e0b7db33689f33cc2ef7c83710fa.
 

I guess it is to canonicalize error messages in case the user just throws in an 
"error: " prefix like `Ctx.diagnose("error: xxx")` which would give two `error` 
prefixes otherwise.



Comment at: llvm/lib/MC/MCContext.cpp:869
+SMLoc Loc,
+std::function GetMessage) {
+  SourceMgr SM;

MaskRay wrote:
> Use lightweight function_ref since you don't need to store the callback.
I was hesitant to do this because it requires including `STLExtras.h` in 
MCContext.h which could be bad for compile-time. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97449

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


[PATCH] D97449: [Diagnose] Unify MCContext and LLVMContext diagnosing

2021-03-01 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added inline comments.



Comment at: llvm/lib/MC/MCContext.cpp:870
+std::function GetMessage) {
+  SourceMgr SM;
+  const SourceMgr *SMP = &SM;

MaskRay wrote:
> This looks a bit strange: we need to construct a fresh SourceMgr to print a 
> diagnostic.
I've included comments to explain that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97449

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


[PATCH] D86376: [HIP] Emit kernel symbol

2021-03-01 Thread Artem Belevich via Phabricator via cfe-commits
tra accepted this revision.
tra added a comment.
This revision is now accepted and ready to land.

So, to summarize how the patch changes the under-the-hood kernel launch 
machinery:

- device-side is unchanged. Kernel function is generated with the real kernel 
name
- host-side stub is still generated with the `__device_stub` prefix.
- host-side generates a 'handle' variable with the kernel function name, which 
is a pointer to the stub.
- host-side registers the `handle variable` -> `device-side kernel name` 
association with the HIP runtime.
- the address of the handle variable is used everywhere where we need a kernel 
pointer on the host side. I.e. passing kernel pointers around, referring to 
kernels across TUs, etc.
- `<<<>>>` becomes an indirect call to a `__device_stub` function using the 
pointer retrieved from the handle.


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

https://reviews.llvm.org/D86376

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


[clang-tools-extra] 82289aa - [clang-tidy] Remove OptionError

2021-03-01 Thread Nathan James via cfe-commits

Author: Nathan James
Date: 2021-03-01T17:55:17Z
New Revision: 82289aa6c88ad9840369db294cc66ed829e8c435

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

LOG: [clang-tidy] Remove OptionError

The interface served a purpose, but since the ability to emit diagnostics when 
parsing configuration was added, its become mostly redundant. Emitting the 
diagnostic and removing the boilerplate is much cleaner.

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
clang-tools-extra/clang-tidy/ClangTidyCheck.h
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
index e1bea430a89a..46b69ed538cb 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
@@ -15,30 +15,6 @@
 namespace clang {
 namespace tidy {
 
-char MissingOptionError::ID;
-char UnparseableEnumOptionError::ID;
-char UnparseableIntegerOptionError::ID;
-
-std::string MissingOptionError::message() const {
-  llvm::SmallString<128> Buffer({"option not found '", OptionName, "'"});
-  return std::string(Buffer);
-}
-
-std::string UnparseableEnumOptionError::message() const {
-  llvm::SmallString<256> Buffer({"invalid configuration value '", LookupValue,
- "' for option '", LookupName, "'"});
-  if (SuggestedValue)
-Buffer.append({"; did you mean '", *SuggestedValue, "'?"});
-  return std::string(Buffer);
-}
-
-std::string UnparseableIntegerOptionError::message() const {
-  llvm::SmallString<256> Buffer({"invalid configuration value '", LookupValue,
- "' for option '", LookupName, "'; expected ",
- (IsBoolean ? "a bool" : "an integer value")});
-  return std::string(Buffer);
-}
-
 ClangTidyCheck::ClangTidyCheck(StringRef CheckName, ClangTidyContext *Context)
 : CheckName(CheckName), Context(Context),
   Options(CheckName, Context->getOptions().CheckOptions, Context) {
@@ -75,12 +51,12 @@ ClangTidyCheck::OptionsView::OptionsView(
 : NamePrefix(CheckName.str() + "."), CheckOptions(CheckOptions),
   Context(Context) {}
 
-llvm::Expected
+llvm::Optional
 ClangTidyCheck::OptionsView::get(StringRef LocalName) const {
   const auto &Iter = CheckOptions.find(NamePrefix + LocalName.str());
   if (Iter != CheckOptions.end())
 return Iter->getValue().Value;
-  return llvm::make_error((NamePrefix + LocalName).str());
+  return None;
 }
 
 static ClangTidyOptions::OptionMap::const_iterator
@@ -97,16 +73,16 @@ findPriorityOption(const ClangTidyOptions::OptionMap 
&Options, StringRef NamePre
   return IterGlobal;
 }
 
-llvm::Expected
+llvm::Optional
 ClangTidyCheck::OptionsView::getLocalOrGlobal(StringRef LocalName) const {
   auto Iter = findPriorityOption(CheckOptions, NamePrefix, LocalName);
   if (Iter != CheckOptions.end())
 return Iter->getValue().Value;
-  return llvm::make_error((NamePrefix + LocalName).str());
+  return None;
 }
 
-static llvm::Expected getAsBool(StringRef Value,
-  const llvm::Twine &LookupName) {
+static Optional getAsBool(StringRef Value,
+const llvm::Twine &LookupName) {
 
   if (llvm::Optional Parsed = llvm::yaml::parseBool(Value))
 return *Parsed;
@@ -115,46 +91,30 @@ static llvm::Expected getAsBool(StringRef Value,
   long long Number;
   if (!Value.getAsInteger(10, Number))
 return Number != 0;
-  return llvm::make_error(LookupName.str(),
- Value.str(), true);
+  return None;
 }
 
 template <>
-llvm::Expected
+llvm::Optional
 ClangTidyCheck::OptionsView::get(StringRef LocalName) const {
-  llvm::Expected ValueOr = get(LocalName);
-  if (ValueOr)
-return getAsBool(*ValueOr, NamePrefix + LocalName);
-  return ValueOr.takeError();
-}
-
-template <>
-bool ClangTidyCheck::OptionsView::get(StringRef LocalName,
-bool Default) const {
-  llvm::Expected ValueOr = get(LocalName);
-  if (ValueOr)
-return *ValueOr;
-  reportOptionParsingError(ValueOr.takeError());
-  return Default;
+  if (llvm::Optional ValueOr = get(LocalName)) {
+if (auto Result = getAsBool(*ValueOr, NamePrefix + LocalName))
+  return Result;
+diagnoseBadBooleanOption(NamePrefix + LocalName, *ValueOr);
+  }
+  return None;
 }
 
 template <>
-llvm::Expected
+llvm::Optional
 ClangTidyCheck::OptionsView::getLocalOrGlobal(StringRef LocalName) const 
{
   auto Iter = findPriorit

[PATCH] D97614: [clang-tidy] Remove OptionError

2021-03-01 Thread Nathan James 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 rG82289aa6c88a: [clang-tidy] Remove OptionError (authored by 
njames93).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97614

Files:
  clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
  clang-tools-extra/clang-tidy/ClangTidyCheck.h
  clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
  clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
@@ -190,6 +190,7 @@
 
 using ::testing::AllOf;
 using ::testing::ElementsAre;
+using ::testing::UnorderedElementsAre;
 
 TEST(ParseConfiguration, CollectDiags) {
   DiagCollecter Collector;
@@ -243,7 +244,6 @@
 return Options.getLocalOrGlobal(std::forward(Arguments)...);
   }
 };
-} // namespace
 
 #define CHECK_VAL(Value, Expected) \
   do { \
@@ -252,17 +252,22 @@
 EXPECT_EQ(*Item, Expected);\
   } while (false)
 
-#define CHECK_ERROR(Value, ErrorType, ExpectedMessage) \
-  do { \
-auto Item = Value; \
-ASSERT_FALSE(Item);\
-ASSERT_TRUE(Item.errorIsA());   \
-ASSERT_FALSE(llvm::handleErrors(   \
-Item.takeError(), [&](const ErrorType &Err) -> llvm::Error {   \
-  EXPECT_EQ(Err.message(), ExpectedMessage);   \
-  return llvm::Error::success();   \
-}));   \
-  } while (false)
+MATCHER_P(ToolDiagMessage, M, "") { return arg.Message.Message == M; }
+MATCHER_P(ToolDiagLevel, L, "") { return arg.DiagLevel == L; }
+
+} // namespace
+
+} // namespace test
+
+static constexpr auto Warning = tooling::Diagnostic::Warning;
+static constexpr auto Error = tooling::Diagnostic::Error;
+
+static void PrintTo(const ClangTidyError &Err, ::std::ostream *OS) {
+  *OS << (Err.DiagLevel == Error ? "error: " : "warning: ")
+  << Err.Message.Message;
+}
+
+namespace test {
 
 TEST(CheckOptionsValidation, MissingOptions) {
   ClangTidyOptions Options;
@@ -273,21 +278,21 @@
&DiagConsumer, false);
   Context.setDiagnosticsEngine(&DE);
   TestCheck TestCheck(&Context);
-  CHECK_ERROR(TestCheck.getLocal("Opt"), MissingOptionError,
-  "option not found 'test.Opt'");
+  EXPECT_FALSE(TestCheck.getLocal("Opt").hasValue());
   EXPECT_EQ(TestCheck.getLocal("Opt", "Unknown"), "Unknown");
+  // Missing options aren't errors.
+  EXPECT_TRUE(DiagConsumer.take().empty());
 }
 
 TEST(CheckOptionsValidation, ValidIntOptions) {
   ClangTidyOptions Options;
   auto &CheckOptions = Options.CheckOptions;
-  CheckOptions["test.IntExpected1"] = "1";
-  CheckOptions["test.IntExpected2"] = "1WithMore";
-  CheckOptions["test.IntExpected3"] = "NoInt";
-  CheckOptions["GlobalIntExpected1"] = "1";
-  CheckOptions["GlobalIntExpected2"] = "NoInt";
-  CheckOptions["test.DefaultedIntInvalid"] = "NoInt";
+  CheckOptions["test.IntExpected"] = "1";
+  CheckOptions["test.IntInvalid1"] = "1WithMore";
+  CheckOptions["test.IntInvalid2"] = "NoInt";
+  CheckOptions["GlobalIntExpected"] = "1";
   CheckOptions["GlobalIntInvalid"] = "NoInt";
+  CheckOptions["test.DefaultedIntInvalid"] = "NoInt";
   CheckOptions["test.BoolITrueValue"] = "1";
   CheckOptions["test.BoolIFalseValue"] = "0";
   CheckOptions["test.BoolTrueValue"] = "true";
@@ -304,22 +309,12 @@
   Context.setDiagnosticsEngine(&DE);
   TestCheck TestCheck(&Context);
 
-#define CHECK_ERROR_INT(Name, Expected)\
-  CHECK_ERROR(Name, UnparseableIntegerOptionError, Expected)
-
-  CHECK_VAL(TestCheck.getIntLocal("IntExpected1"), 1);
-  CHECK_VAL(TestCheck.getIntGlobal("GlobalIntExpected1"), 1);
-  CHECK_ERROR_INT(TestCheck.getIntLocal("IntExpected2"),
-  "invalid configuration value '1WithMore' for option "
-  "'test.IntExpected2'; expected an integer value");
-  CHECK_ERROR_INT(TestCheck.getIntLocal("IntExpected3"),
-  "invalid configuration value 'NoInt' for option "
-  "'test.IntExpected3'; expected an integer value");
-  CHECK_ERROR_INT(TestCheck.getIntGlobal("GlobalIntExpected2"),
-

[PATCH] D97699: [analyzer] Add InvalidPtrChecker

2021-03-01 Thread Zurab Tsinadze via Phabricator via cfe-commits
zukatsinadze added a comment.

Attaching results of CodeChecker run on some projects.F15697529: cc_results.zip 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97699

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


[PATCH] D97449: [Diagnose] Unify MCContext and LLVMContext diagnosing

2021-03-01 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen updated this revision to Diff 327162.
ychen added a comment.

- Use StringRef::consume_front


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97449

Files:
  clang/include/clang/Basic/DiagnosticCategories.td
  clang/include/clang/Basic/DiagnosticFrontendKinds.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/lib/CodeGen/CodeGenAction.cpp
  lldb/source/Expression/IRExecutionUnit.cpp
  llvm/include/llvm/CodeGen/AsmPrinter.h
  llvm/include/llvm/IR/DiagnosticInfo.h
  llvm/include/llvm/IR/LLVMContext.h
  llvm/include/llvm/MC/MCContext.h
  llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
  llvm/lib/CodeGen/MachineModuleInfo.cpp
  llvm/lib/IR/DiagnosticInfo.cpp
  llvm/lib/IR/LLVMContext.cpp
  llvm/lib/IR/LLVMContextImpl.h
  llvm/lib/MC/MCContext.cpp
  llvm/lib/MC/MCParser/AsmParser.cpp
  llvm/test/CodeGen/AMDGPU/lds-initializer.ll
  llvm/test/CodeGen/AMDGPU/lds-zero-initializer.ll
  llvm/test/CodeGen/XCore/section-name.ll
  llvm/tools/llc/llc.cpp

Index: llvm/tools/llc/llc.cpp
===
--- llvm/tools/llc/llc.cpp
+++ llvm/tools/llc/llc.cpp
@@ -290,6 +290,22 @@
   bool *HasError;
   LLCDiagnosticHandler(bool *HasErrorPtr) : HasError(HasErrorPtr) {}
   bool handleDiagnostics(const DiagnosticInfo &DI) override {
+if (DI.getKind() == llvm::DK_SrcMgr) {
+  const auto &DISM = cast(DI);
+  const SMDiagnostic &SMD = DISM.getSMDiag();
+
+  if (SMD.getKind() == SourceMgr::DK_Error)
+*HasError = true;
+
+  SMD.print(nullptr, errs());
+
+  // For testing purposes, we print the LocCookie here.
+  if (DISM.isInlineAsmDiag() && DISM.getLocCookie())
+WithColor::note() << "!srcloc = " << DISM.getLocCookie() << "\n";
+
+  return true;
+}
+
 if (DI.getSeverity() == DS_Error)
   *HasError = true;
 
@@ -305,19 +321,6 @@
   }
 };
 
-static void InlineAsmDiagHandler(const SMDiagnostic &SMD, void *Context,
- unsigned LocCookie) {
-  bool *HasError = static_cast(Context);
-  if (SMD.getKind() == SourceMgr::DK_Error)
-*HasError = true;
-
-  SMD.print(nullptr, errs());
-
-  // For testing purposes, we print the LocCookie here.
-  if (LocCookie)
-WithColor::note() << "!srcloc = " << LocCookie << "\n";
-}
-
 // main - Entry point for the llc compiler.
 //
 int main(int argc, char **argv) {
@@ -367,7 +370,6 @@
   bool HasError = false;
   Context.setDiagnosticHandler(
   std::make_unique(&HasError));
-  Context.setInlineAsmDiagnosticHandler(InlineAsmDiagHandler, &HasError);
 
   Expected> RemarksFileOrErr =
   setupLLVMOptimizationRemarks(Context, RemarksFilename, RemarksPasses,
Index: llvm/test/CodeGen/XCore/section-name.ll
===
--- llvm/test/CodeGen/XCore/section-name.ll
+++ llvm/test/CodeGen/XCore/section-name.ll
@@ -1,4 +1,4 @@
-; RUN: llc < %s -march=xcore -o /dev/null 2>&1 | FileCheck %s
+; RUN: not llc < %s -march=xcore -o /dev/null 2>&1 | FileCheck %s
 
 @bar = internal global i32 zeroinitializer
 
Index: llvm/test/CodeGen/AMDGPU/lds-zero-initializer.ll
===
--- llvm/test/CodeGen/AMDGPU/lds-zero-initializer.ll
+++ llvm/test/CodeGen/AMDGPU/lds-zero-initializer.ll
@@ -1,7 +1,7 @@
-; RUN: llc -march=amdgcn -mcpu=tahiti < %s -o /dev/null 2>&1 | FileCheck %s
-; RUN: llc -march=amdgcn -mcpu=tonga < %s -o /dev/null 2>&1 | FileCheck %s
+; RUN: not llc -march=amdgcn -mcpu=tahiti -filetype=null < %s 2>&1 | FileCheck %s
+; RUN: not llc -march=amdgcn -mcpu=tonga -filetype=null < %s 2>&1 | FileCheck %s
 
-; CHECK: lds: unsupported initializer for address space
+; CHECK: error: lds: unsupported initializer for address space
 
 @lds = addrspace(3) global [256 x i32] zeroinitializer
 
Index: llvm/test/CodeGen/AMDGPU/lds-initializer.ll
===
--- llvm/test/CodeGen/AMDGPU/lds-initializer.ll
+++ llvm/test/CodeGen/AMDGPU/lds-initializer.ll
@@ -1,5 +1,5 @@
-; RUN: llc -march=amdgcn -mcpu=tahiti < %s -o /dev/null 2>&1 | FileCheck %s
-; RUN: llc -march=amdgcn -mcpu=tonga < %s -o /dev/null 2>&1 | FileCheck %s
+; RUN: not llc -march=amdgcn -mcpu=tahiti < %s -o /dev/null 2>&1 | FileCheck %s
+; RUN: not llc -march=amdgcn -mcpu=tonga < %s -o /dev/null 2>&1 | FileCheck %s
 
 ; CHECK: lds: unsupported initializer for address space
 
Index: llvm/lib/MC/MCParser/AsmParser.cpp
===
--- llvm/lib/MC/MCParser/AsmParser.cpp
+++ llvm/lib/MC/MCParser/AsmParser.cpp
@@ -2348,7 +2348,7 @@
 /// will use the last parsed cpp hash line filename comment
 /// for the Filename and LineNo if any in the diagnostic.
 void AsmParser::DiagHandler(const SMDiagnostic &Diag, void *Context) {
-  const AsmParser *Parser = static_cast(Context);
+  auto *Parser = static_cast(Context);
 

[PATCH] D97702: [clang][modules] Use extensible RTTI for ModuleFileExtension

2021-03-01 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, dexonsmith.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Clang exposes an interface for extending the PCM/PCH file format: 
`ModuleFileExtension`.

Clang itself has only a single implementation of the interface: 
`TestModuleFileExtension` that can be instantiated via the 
`-ftest-module-file_extension=` command line argument (and is stored in 
`FrontendOptions::ModuleFileExtensions`).

Clients of the Clang library can extend the PCM/PCH file format by adding their 
implementation of the interface to `FrontendOptions::ModuleFileExtensions`.

When generating the `-ftest-module-file_extension=` command line argument from 
`FrontendOptions`, a downcast is used to distinguish between the Clang's 
testing extension and other (client extensions).

This functionality is enabled by LLVM-style RTTI. However, this style of RTTI 
is hard to extend, as it requires patching Clang (adding new case to the 
`ModuleFileExtensionKind` enum).

This patch switches to the LLVM RTTI for open class hierarchies, which allows 
libClang users (e.g. Swift) to create implementations of `ModuleFileExtension` 
without patching Clang.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97702

Files:
  clang/include/clang/Serialization/ModuleFileExtension.h
  clang/lib/Frontend/TestModuleFileExtension.cpp
  clang/lib/Frontend/TestModuleFileExtension.h
  clang/lib/Serialization/ModuleFileExtension.cpp
  clang/unittests/Frontend/CompilerInvocationTest.cpp

Index: clang/unittests/Frontend/CompilerInvocationTest.cpp
===
--- clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -11,6 +11,7 @@
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/TextDiagnosticBuffer.h"
 #include "clang/Lex/PreprocessorOptions.h"
+#include "clang/Serialization/ModuleFileExtension.h"
 #include "llvm/Support/Host.h"
 
 #include "gmock/gmock.h"
@@ -743,6 +744,58 @@
   ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fdigraphs")));
 }
 
+struct DummyModuleFileExtension
+: public llvm::RTTIExtends {
+  static char ID;
+
+  ModuleFileExtensionMetadata getExtensionMetadata() const override {
+return {};
+  };
+
+  llvm::hash_code hashExtension(llvm::hash_code Code) const override {
+return {};
+  }
+
+  std::unique_ptr
+  createExtensionWriter(ASTWriter &Writer) override {
+return {};
+  }
+
+  std::unique_ptr
+  createExtensionReader(const ModuleFileExtensionMetadata &Metadata,
+ASTReader &Reader, serialization::ModuleFile &Mod,
+const llvm::BitstreamCursor &Stream) override {
+return {};
+  }
+};
+
+char DummyModuleFileExtension::ID = 0;
+
+TEST_F(CommandLineTest, TestModuleFileExtension) {
+  const char *Args[] = {"-ftest-module-file-extension=first:2:1:0:first",
+"-ftest-module-file-extension=second:3:2:1:second"};
+
+  ASSERT_TRUE(CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags));
+  ASSERT_THAT(Invocation.getFrontendOpts().ModuleFileExtensions.size(), 2);
+
+  // Exercise the check that only serializes instances of
+  // TestModuleFileExtension by providing an instance of another
+  // ModuleFileExtension subclass.
+  Invocation.getFrontendOpts().ModuleFileExtensions.push_back(
+  std::make_shared());
+
+  Invocation.generateCC1CommandLine(GeneratedArgs, *this);
+
+  ASSERT_THAT(GeneratedArgs,
+  ContainsN(HasSubstr("-ftest-module-file-extension="), 2));
+  ASSERT_THAT(
+  GeneratedArgs,
+  Contains(StrEq("-ftest-module-file-extension=first:2:1:0:first")));
+  ASSERT_THAT(
+  GeneratedArgs,
+  Contains(StrEq("-ftest-module-file-extension=second:3:2:1:second")));
+}
+
 TEST_F(CommandLineTest, RoundTrip) {
   // Testing one marshalled and one manually generated option from each
   // CompilerInvocation member.
Index: clang/lib/Serialization/ModuleFileExtension.cpp
===
--- clang/lib/Serialization/ModuleFileExtension.cpp
+++ clang/lib/Serialization/ModuleFileExtension.cpp
@@ -9,6 +9,8 @@
 #include "llvm/ADT/Hashing.h"
 using namespace clang;
 
+char ModuleFileExtension::ID = 0;
+
 ModuleFileExtension::~ModuleFileExtension() { }
 
 llvm::hash_code ModuleFileExtension::hashExtension(llvm::hash_code Code) const {
Index: clang/lib/Frontend/TestModuleFileExtension.h
===
--- clang/lib/Frontend/TestModuleFileExtension.h
+++ clang/lib/Frontend/TestModuleFileExtension.h
@@ -17,7 +17,8 @@
 namespace clang {
 
 /// A module file extension used for testing purposes.
-class TestModuleFileExtension : public ModuleFileExtension {
+class TestModuleFileExtension
+: public llvm::RTTIExtends {
   std::string BlockName;
   unsi

[PATCH] D97608: Move EntryExitInstrumentation pass location

2021-03-01 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks updated this revision to Diff 327164.
aeubanks added a comment.
Herald added subscribers: kerbowa, atanasyan, jrtc27, nhaehnle, jvesely, 
nemanjai, sdardis.

missed non-x86 tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97608

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/test/CodeGen/X86/x86_64-instrument-functions.c
  clang/test/CodeGen/mcount.c
  clang/test/Frontend/gnu-mcount.c
  llvm/include/llvm/Transforms/Utils/EntryExitInstrumenter.h
  llvm/lib/CodeGen/TargetPassConfig.cpp
  llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
  llvm/test/CodeGen/AArch64/O0-pipeline.ll
  llvm/test/CodeGen/AArch64/O3-pipeline.ll
  llvm/test/CodeGen/AMDGPU/opt-pipeline.ll
  llvm/test/CodeGen/ARM/O3-pipeline.ll
  llvm/test/CodeGen/ARM/gnu_mcount_nc.ll
  llvm/test/CodeGen/Mips/long-call-mcount.ll
  llvm/test/CodeGen/Mips/mcount.ll
  llvm/test/CodeGen/PowerPC/mcount-insertion.ll
  llvm/test/CodeGen/X86/O0-pipeline.ll
  llvm/test/CodeGen/X86/musttail-inalloca.ll
  llvm/test/CodeGen/X86/opt-pipeline.ll
  llvm/test/Other/opt-O0-pipeline-enable-matrix.ll
  llvm/test/Other/opt-O0-pipeline.ll
  llvm/test/Other/opt-O2-pipeline.ll
  llvm/test/Other/opt-O3-pipeline-enable-matrix.ll
  llvm/test/Other/opt-O3-pipeline.ll
  llvm/test/Other/opt-Os-pipeline.ll

Index: llvm/test/Other/opt-Os-pipeline.ll
===
--- llvm/test/Other/opt-Os-pipeline.ll
+++ llvm/test/Other/opt-Os-pipeline.ll
@@ -12,7 +12,6 @@
 ; CHECK-NEXT: Module Verifier
 ; CHECK-EXT:  Good Bye World Pass
 ; CHECK-NOEXT-NOT:  Good Bye World Pass
-; CHECK-NEXT: Instrument function entry/exit with calls to e.g. mcount() (pre inlining)
 ; CHECK-NEXT: Simplify the CFG
 ; CHECK-NEXT: Dominator Tree Construction
 ; CHECK-NEXT: SROA
Index: llvm/test/Other/opt-O3-pipeline.ll
===
--- llvm/test/Other/opt-O3-pipeline.ll
+++ llvm/test/Other/opt-O3-pipeline.ll
@@ -12,7 +12,6 @@
 ; CHECK-NEXT: Module Verifier
 ; CHECK-EXT:  Good Bye World Pass
 ; CHECK-NOEXT-NOT:  Good Bye World Pass
-; CHECK-NEXT: Instrument function entry/exit with calls to e.g. mcount() (pre inlining)
 ; CHECK-NEXT: Simplify the CFG
 ; CHECK-NEXT: Dominator Tree Construction
 ; CHECK-NEXT: SROA
Index: llvm/test/Other/opt-O3-pipeline-enable-matrix.ll
===
--- llvm/test/Other/opt-O3-pipeline-enable-matrix.ll
+++ llvm/test/Other/opt-O3-pipeline-enable-matrix.ll
@@ -12,7 +12,6 @@
 ; CHECK-NEXT: Module Verifier
 ; CHECK-EXT:  Good Bye World Pass
 ; CHECK-NOEXT-NOT:  Good Bye World Pass
-; CHECK-NEXT: Instrument function entry/exit with calls to e.g. mcount() (pre inlining)
 ; CHECK-NEXT: Simplify the CFG
 ; CHECK-NEXT: Dominator Tree Construction
 ; CHECK-NEXT: SROA
Index: llvm/test/Other/opt-O2-pipeline.ll
===
--- llvm/test/Other/opt-O2-pipeline.ll
+++ llvm/test/Other/opt-O2-pipeline.ll
@@ -12,7 +12,6 @@
 ; CHECK-NEXT: Module Verifier
 ; CHECK-EXT:  Good Bye World Pass
 ; CHECK-NOEXT-NOT:  Good Bye World Pass
-; CHECK-NEXT: Instrument function entry/exit with calls to e.g. mcount() (pre inlining)
 ; CHECK-NEXT: Simplify the CFG
 ; CHECK-NEXT: Dominator Tree Construction
 ; CHECK-NEXT: SROA
Index: llvm/test/Other/opt-O0-pipeline.ll
===
--- llvm/test/Other/opt-O0-pipeline.ll
+++ llvm/test/Other/opt-O0-pipeline.ll
@@ -10,7 +10,6 @@
 ; CHECK-NEXT:   FunctionPass Manager
 ; CHECK-NEXT: Module Verifier
 ; CHECK-EXT: Good Bye World Pass
-; CHECK-NEXT: Instrument function entry/exit with calls to e.g. mcount() (pre inlining)
 ; CHECK-NEXT: Pass Arguments:
 ; CHECK-NEXT: Target Library Information
 ; CHECK-NEXT: Target Transform Information
Index: llvm/test/Other/opt-O0-pipeline-enable-matrix.ll
===
--- llvm/test/Other/opt-O0-pipeline-enable-matrix.ll
+++ llvm/test/Other/opt-O0-pipeline-enable-matrix.ll
@@ -6,7 +6,6 @@
 ; CHECK-NEXT: Target Transform Information
 ; CHECK-NEXT:   FunctionPass Manager
 ; CHECK-NEXT: Module Verifier
-; CHECK-NEXT: Instrument function entry/exit with calls to e.g. mcount() (pre inlining)
 ; CHECK-NEXT: Lower the matrix intrinsics (minimal)
 
 
Index: llvm/test/CodeGen/X86/opt-pipeline.ll
===
--- llvm/test/CodeGen/X86/opt-pipeline.ll
+++ llvm/test/CodeGen/X86/opt-pipeline.ll
@@ -53,7 +53,6 @@
 ; CHECK-NEXT:   Constant Hoisting
 ; CHECK-NEXT:   Replace intrinsics with calls to vector library
 ; CHECK-NEXT:   Partially inline calls to library functions
-; CHECK-NEXT:   Instrument function entry/exit with calls to e.g. m

[PATCH] D97608: Move EntryExitInstrumentation pass location

2021-03-01 Thread Arthur Eubanks 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 rG040c1b49d7a7: Move EntryExitInstrumentation pass location 
(authored by aeubanks).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97608

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/test/CodeGen/X86/x86_64-instrument-functions.c
  clang/test/CodeGen/mcount.c
  clang/test/Frontend/gnu-mcount.c
  llvm/include/llvm/Transforms/Utils/EntryExitInstrumenter.h
  llvm/lib/CodeGen/TargetPassConfig.cpp
  llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
  llvm/test/CodeGen/AArch64/O0-pipeline.ll
  llvm/test/CodeGen/AArch64/O3-pipeline.ll
  llvm/test/CodeGen/AMDGPU/opt-pipeline.ll
  llvm/test/CodeGen/ARM/O3-pipeline.ll
  llvm/test/CodeGen/ARM/gnu_mcount_nc.ll
  llvm/test/CodeGen/Mips/long-call-mcount.ll
  llvm/test/CodeGen/Mips/mcount.ll
  llvm/test/CodeGen/PowerPC/mcount-insertion.ll
  llvm/test/CodeGen/X86/O0-pipeline.ll
  llvm/test/CodeGen/X86/musttail-inalloca.ll
  llvm/test/CodeGen/X86/opt-pipeline.ll
  llvm/test/Other/opt-O0-pipeline-enable-matrix.ll
  llvm/test/Other/opt-O0-pipeline.ll
  llvm/test/Other/opt-O2-pipeline.ll
  llvm/test/Other/opt-O3-pipeline-enable-matrix.ll
  llvm/test/Other/opt-O3-pipeline.ll
  llvm/test/Other/opt-Os-pipeline.ll

Index: llvm/test/Other/opt-Os-pipeline.ll
===
--- llvm/test/Other/opt-Os-pipeline.ll
+++ llvm/test/Other/opt-Os-pipeline.ll
@@ -12,7 +12,6 @@
 ; CHECK-NEXT: Module Verifier
 ; CHECK-EXT:  Good Bye World Pass
 ; CHECK-NOEXT-NOT:  Good Bye World Pass
-; CHECK-NEXT: Instrument function entry/exit with calls to e.g. mcount() (pre inlining)
 ; CHECK-NEXT: Simplify the CFG
 ; CHECK-NEXT: Dominator Tree Construction
 ; CHECK-NEXT: SROA
Index: llvm/test/Other/opt-O3-pipeline.ll
===
--- llvm/test/Other/opt-O3-pipeline.ll
+++ llvm/test/Other/opt-O3-pipeline.ll
@@ -12,7 +12,6 @@
 ; CHECK-NEXT: Module Verifier
 ; CHECK-EXT:  Good Bye World Pass
 ; CHECK-NOEXT-NOT:  Good Bye World Pass
-; CHECK-NEXT: Instrument function entry/exit with calls to e.g. mcount() (pre inlining)
 ; CHECK-NEXT: Simplify the CFG
 ; CHECK-NEXT: Dominator Tree Construction
 ; CHECK-NEXT: SROA
Index: llvm/test/Other/opt-O3-pipeline-enable-matrix.ll
===
--- llvm/test/Other/opt-O3-pipeline-enable-matrix.ll
+++ llvm/test/Other/opt-O3-pipeline-enable-matrix.ll
@@ -12,7 +12,6 @@
 ; CHECK-NEXT: Module Verifier
 ; CHECK-EXT:  Good Bye World Pass
 ; CHECK-NOEXT-NOT:  Good Bye World Pass
-; CHECK-NEXT: Instrument function entry/exit with calls to e.g. mcount() (pre inlining)
 ; CHECK-NEXT: Simplify the CFG
 ; CHECK-NEXT: Dominator Tree Construction
 ; CHECK-NEXT: SROA
Index: llvm/test/Other/opt-O2-pipeline.ll
===
--- llvm/test/Other/opt-O2-pipeline.ll
+++ llvm/test/Other/opt-O2-pipeline.ll
@@ -12,7 +12,6 @@
 ; CHECK-NEXT: Module Verifier
 ; CHECK-EXT:  Good Bye World Pass
 ; CHECK-NOEXT-NOT:  Good Bye World Pass
-; CHECK-NEXT: Instrument function entry/exit with calls to e.g. mcount() (pre inlining)
 ; CHECK-NEXT: Simplify the CFG
 ; CHECK-NEXT: Dominator Tree Construction
 ; CHECK-NEXT: SROA
Index: llvm/test/Other/opt-O0-pipeline.ll
===
--- llvm/test/Other/opt-O0-pipeline.ll
+++ llvm/test/Other/opt-O0-pipeline.ll
@@ -10,7 +10,6 @@
 ; CHECK-NEXT:   FunctionPass Manager
 ; CHECK-NEXT: Module Verifier
 ; CHECK-EXT: Good Bye World Pass
-; CHECK-NEXT: Instrument function entry/exit with calls to e.g. mcount() (pre inlining)
 ; CHECK-NEXT: Pass Arguments:
 ; CHECK-NEXT: Target Library Information
 ; CHECK-NEXT: Target Transform Information
Index: llvm/test/Other/opt-O0-pipeline-enable-matrix.ll
===
--- llvm/test/Other/opt-O0-pipeline-enable-matrix.ll
+++ llvm/test/Other/opt-O0-pipeline-enable-matrix.ll
@@ -6,7 +6,6 @@
 ; CHECK-NEXT: Target Transform Information
 ; CHECK-NEXT:   FunctionPass Manager
 ; CHECK-NEXT: Module Verifier
-; CHECK-NEXT: Instrument function entry/exit with calls to e.g. mcount() (pre inlining)
 ; CHECK-NEXT: Lower the matrix intrinsics (minimal)
 
 
Index: llvm/test/CodeGen/X86/opt-pipeline.ll
===
--- llvm/test/CodeGen/X86/opt-pipeline.ll
+++ llvm/test/CodeGen/X86/opt-pipeline.ll
@@ -53,7 +53,6 @@
 ; CHECK-NEXT:   Constant Hoisting
 ; CHECK-NEXT:   Replace intrinsics with calls to vector library
 ; CHECK-NEXT:   Partially inline calls to library functions
-; CHECK-NEXT:   Instrume

[clang] 040c1b4 - Move EntryExitInstrumentation pass location

2021-03-01 Thread Arthur Eubanks via cfe-commits

Author: Arthur Eubanks
Date: 2021-03-01T10:08:10-08:00
New Revision: 040c1b49d7a7eaa23d883ca363744944f5597d92

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

LOG: Move EntryExitInstrumentation pass location

This seems to be more of a Clang thing rather than a generic LLVM thing,
so this moves it out of LLVM pipelines and as Clang extension hooks into
LLVM pipelines.

Move the post-inline EEInstrumentation out of the backend pipeline and
into a late pass, similar to other sanitizer passes. It doesn't fit
into the codegen pipeline.

Also fix up EntryExitInstrumentation not running at -O0 under the new
PM. PR49143

Reviewed By: hans

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

Added: 


Modified: 
clang/lib/CodeGen/BackendUtil.cpp
clang/test/CodeGen/X86/x86_64-instrument-functions.c
clang/test/CodeGen/mcount.c
clang/test/Frontend/gnu-mcount.c
llvm/include/llvm/Transforms/Utils/EntryExitInstrumenter.h
llvm/lib/CodeGen/TargetPassConfig.cpp
llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
llvm/test/CodeGen/AArch64/O0-pipeline.ll
llvm/test/CodeGen/AArch64/O3-pipeline.ll
llvm/test/CodeGen/AMDGPU/opt-pipeline.ll
llvm/test/CodeGen/ARM/O3-pipeline.ll
llvm/test/CodeGen/ARM/gnu_mcount_nc.ll
llvm/test/CodeGen/Mips/long-call-mcount.ll
llvm/test/CodeGen/Mips/mcount.ll
llvm/test/CodeGen/PowerPC/mcount-insertion.ll
llvm/test/CodeGen/X86/O0-pipeline.ll
llvm/test/CodeGen/X86/musttail-inalloca.ll
llvm/test/CodeGen/X86/opt-pipeline.ll
llvm/test/Other/opt-O0-pipeline-enable-matrix.ll
llvm/test/Other/opt-O0-pipeline.ll
llvm/test/Other/opt-O2-pipeline.ll
llvm/test/Other/opt-O3-pipeline-enable-matrix.ll
llvm/test/Other/opt-O3-pipeline.ll
llvm/test/Other/opt-Os-pipeline.ll

Removed: 




diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index ba9a13ed1ddf..bfa47e5dc16c 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -367,6 +367,17 @@ static void addDataFlowSanitizerPass(const 
PassManagerBuilder &Builder,
   PM.add(createDataFlowSanitizerLegacyPassPass(LangOpts.NoSanitizeFiles));
 }
 
+static void addEntryExitInstrumentationPass(const PassManagerBuilder &Builder,
+legacy::PassManagerBase &PM) {
+  PM.add(createEntryExitInstrumenterPass());
+}
+
+static void
+addPostInlineEntryExitInstrumentationPass(const PassManagerBuilder &Builder,
+  legacy::PassManagerBase &PM) {
+  PM.add(createPostInlineEntryExitInstrumenterPass());
+}
+
 static TargetLibraryInfoImpl *createTLII(llvm::Triple &TargetTriple,
  const CodeGenOptions &CodeGenOpts) {
   TargetLibraryInfoImpl *TLII = new TargetLibraryInfoImpl(TargetTriple);
@@ -783,6 +794,20 @@ void EmitAssemblyHelper::CreatePasses(legacy::PassManager 
&MPM,
addDataFlowSanitizerPass);
   }
 
+  if (CodeGenOpts.InstrumentFunctions ||
+  CodeGenOpts.InstrumentFunctionEntryBare ||
+  CodeGenOpts.InstrumentFunctionsAfterInlining ||
+  CodeGenOpts.InstrumentForProfiling) {
+PMBuilder.addExtension(PassManagerBuilder::EP_EarlyAsPossible,
+   addEntryExitInstrumentationPass);
+PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
+   addEntryExitInstrumentationPass);
+PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
+   addPostInlineEntryExitInstrumentationPass);
+PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
+   addPostInlineEntryExitInstrumentationPass);
+  }
+
   // Set up the per-function pass manager.
   FPM.add(new TargetLibraryInfoWrapperPass(*TLII));
   if (CodeGenOpts.VerifyModule)
@@ -1317,12 +1342,20 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
/*DropTypeTests=*/true));
   });
 
-if (Level != PassBuilder::OptimizationLevel::O0) {
+if (CodeGenOpts.InstrumentFunctions ||
+CodeGenOpts.InstrumentFunctionEntryBare ||
+CodeGenOpts.InstrumentFunctionsAfterInlining ||
+CodeGenOpts.InstrumentForProfiling) {
   PB.registerPipelineStartEPCallback(
   [](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
 MPM.addPass(createModuleToFunctionPassAdaptor(
 EntryExitInstrumenterPass(/*PostInlining=*/false)));
   });
+  PB.registerOptimizerLastEPCallback(
+  [](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
+MPM.addPass(createModuleToFunctionPassAdaptor(
+EntryExitInstrumenterPass(

[clang] 3f40dbb - [PowerPC][AIX] Enable passing vectors in variadic functions.

2021-03-01 Thread Sean Fertile via cfe-commits

Author: Sean Fertile
Date: 2021-03-01T13:08:28-05:00
New Revision: 3f40dbbbc71d28f6ad0bd616fe009bde861362ed

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

LOG: [PowerPC][AIX] Enable passing vectors in variadic functions.

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

Added: 
clang/test/CodeGen/aix-altivec-vaargs.c

Modified: 
clang/lib/CodeGen/TargetInfo.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index a11768d3807b..8c3857ff268b 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -4563,10 +4563,6 @@ Address AIXABIInfo::EmitVAArg(CodeGenFunction &CGF, 
Address VAListAddr,
   if (Ty->isAnyComplexType())
 llvm::report_fatal_error("complex type is not supported on AIX yet");
 
-  if (Ty->isVectorType())
-llvm::report_fatal_error(
-"vector types are not yet supported for variadic functions on AIX");
-
   auto TypeInfo = getContext().getTypeInfoInChars(Ty);
   TypeInfo.Align = getParamTypeAlignment(Ty);
 

diff  --git a/clang/test/CodeGen/aix-altivec-vaargs.c 
b/clang/test/CodeGen/aix-altivec-vaargs.c
new file mode 100644
index ..e144b9fcb464
--- /dev/null
+++ b/clang/test/CodeGen/aix-altivec-vaargs.c
@@ -0,0 +1,52 @@
+// REQUIRES: powerpc-registered-target
+// RUN: %clang_cc1 -triple powerpc-unknown-aix -emit-llvm -target-feature 
+altivec -target-cpu pwr7 -o - %s | FileCheck %s --check-prefixes=CHECK,AIX32
+// RUN: %clang_cc1 -triple powerpc64-unknown-aix -emit-llvm -target-feature 
+altivec -target-cpu pwr7 -o - %s | FileCheck %s --check-prefixes=CHECK,AIX64
+
+vector double vector_varargs(int count, ...) {
+  __builtin_va_list arg_list;
+  __builtin_va_start(arg_list, count);
+
+  vector double ret;
+
+  for (int i = 0; i != count; ++i) {
+ret = __builtin_va_arg(arg_list, vector double);
+  }
+
+  __builtin_va_end(arg_list);
+  return ret;
+}
+
+// CHECK: %arg_list = alloca i8*
+// CHECK: %arg_list1 = bitcast i8** %arg_list to i8*
+// CHECK: call void @llvm.va_start(i8* %arg_list1)
+
+// AIX32:   for.body:
+// AIX32-NEXT:%argp.cur = load i8*, i8** %arg_list, align 4
+// AIX32-NEXT:%2 = ptrtoint i8* %argp.cur to i32
+// AIX32-NEXT:%3 = add i32 %2, 15
+// AIX32-NEXT:%4 = and i32 %3, -16
+// AIX32-NEXT:%argp.cur.aligned = inttoptr i32 %4 to i8*
+// AIX32-NEXT:%argp.next = getelementptr inbounds i8, i8* 
%argp.cur.aligned, i32 16
+// AIX32-NEXT:store i8* %argp.next, i8** %arg_list, align 4
+// AIX32-NEXT:%5 = bitcast i8* %argp.cur.aligned to <2 x double>*
+// AIX32-NEXT:%6 = load <2 x double>, <2 x double>* %5, align 16
+// AIX32-NEXT:store <2 x double> %6, <2 x double>* %ret, align 16
+// AIX32-NEXT:br label %for.inc
+
+// AIX64:   for.body:
+// AIX64-NEXT:%argp.cur = load i8*, i8** %arg_list, align 8
+// AIX64-NEXT:%2 = ptrtoint i8* %argp.cur to i64
+// AIX64-NEXT:%3 = add i64 %2, 15
+// AIX64-NEXT:%4 = and i64 %3, -16
+// AIX64-NEXT:%argp.cur.aligned = inttoptr i64 %4 to i8*
+// AIX64-NEXT:%argp.next = getelementptr inbounds i8, i8* 
%argp.cur.aligned, i64 16
+// AIX64-NEXT:store i8* %argp.next, i8** %arg_list, align 8
+// AIX64-NEXT:%5 = bitcast i8* %argp.cur.aligned to <2 x double>*
+// AIX64-NEXT:%6 = load <2 x double>, <2 x double>* %5, align 16
+// AIX64-NEXT:store <2 x double> %6, <2 x double>* %ret, align 16
+// AIX64-NEXT:br label %for.inc
+
+
+// CHECK:  for.end:
+// CHECK:%arg_list2 = bitcast i8** %arg_list to i8*
+// CHECK:call void @llvm.va_end(i8* %arg_list2)



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


[PATCH] D97474: [PowerPC][AIX] Enable passing vectors in variadic functions (front-end).

2021-03-01 Thread Sean Fertile 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 rG3f40dbbbc71d: [PowerPC][AIX] Enable passing vectors in 
variadic functions. (authored by sfertile).

Changed prior to commit:
  https://reviews.llvm.org/D97474?vs=326385&id=327167#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97474

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/aix-altivec-vaargs.c


Index: clang/test/CodeGen/aix-altivec-vaargs.c
===
--- /dev/null
+++ clang/test/CodeGen/aix-altivec-vaargs.c
@@ -0,0 +1,52 @@
+// REQUIRES: powerpc-registered-target
+// RUN: %clang_cc1 -triple powerpc-unknown-aix -emit-llvm -target-feature 
+altivec -target-cpu pwr7 -o - %s | FileCheck %s --check-prefixes=CHECK,AIX32
+// RUN: %clang_cc1 -triple powerpc64-unknown-aix -emit-llvm -target-feature 
+altivec -target-cpu pwr7 -o - %s | FileCheck %s --check-prefixes=CHECK,AIX64
+
+vector double vector_varargs(int count, ...) {
+  __builtin_va_list arg_list;
+  __builtin_va_start(arg_list, count);
+
+  vector double ret;
+
+  for (int i = 0; i != count; ++i) {
+ret = __builtin_va_arg(arg_list, vector double);
+  }
+
+  __builtin_va_end(arg_list);
+  return ret;
+}
+
+// CHECK: %arg_list = alloca i8*
+// CHECK: %arg_list1 = bitcast i8** %arg_list to i8*
+// CHECK: call void @llvm.va_start(i8* %arg_list1)
+
+// AIX32:   for.body:
+// AIX32-NEXT:%argp.cur = load i8*, i8** %arg_list, align 4
+// AIX32-NEXT:%2 = ptrtoint i8* %argp.cur to i32
+// AIX32-NEXT:%3 = add i32 %2, 15
+// AIX32-NEXT:%4 = and i32 %3, -16
+// AIX32-NEXT:%argp.cur.aligned = inttoptr i32 %4 to i8*
+// AIX32-NEXT:%argp.next = getelementptr inbounds i8, i8* 
%argp.cur.aligned, i32 16
+// AIX32-NEXT:store i8* %argp.next, i8** %arg_list, align 4
+// AIX32-NEXT:%5 = bitcast i8* %argp.cur.aligned to <2 x double>*
+// AIX32-NEXT:%6 = load <2 x double>, <2 x double>* %5, align 16
+// AIX32-NEXT:store <2 x double> %6, <2 x double>* %ret, align 16
+// AIX32-NEXT:br label %for.inc
+
+// AIX64:   for.body:
+// AIX64-NEXT:%argp.cur = load i8*, i8** %arg_list, align 8
+// AIX64-NEXT:%2 = ptrtoint i8* %argp.cur to i64
+// AIX64-NEXT:%3 = add i64 %2, 15
+// AIX64-NEXT:%4 = and i64 %3, -16
+// AIX64-NEXT:%argp.cur.aligned = inttoptr i64 %4 to i8*
+// AIX64-NEXT:%argp.next = getelementptr inbounds i8, i8* 
%argp.cur.aligned, i64 16
+// AIX64-NEXT:store i8* %argp.next, i8** %arg_list, align 8
+// AIX64-NEXT:%5 = bitcast i8* %argp.cur.aligned to <2 x double>*
+// AIX64-NEXT:%6 = load <2 x double>, <2 x double>* %5, align 16
+// AIX64-NEXT:store <2 x double> %6, <2 x double>* %ret, align 16
+// AIX64-NEXT:br label %for.inc
+
+
+// CHECK:  for.end:
+// CHECK:%arg_list2 = bitcast i8** %arg_list to i8*
+// CHECK:call void @llvm.va_end(i8* %arg_list2)
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -4563,10 +4563,6 @@
   if (Ty->isAnyComplexType())
 llvm::report_fatal_error("complex type is not supported on AIX yet");
 
-  if (Ty->isVectorType())
-llvm::report_fatal_error(
-"vector types are not yet supported for variadic functions on AIX");
-
   auto TypeInfo = getContext().getTypeInfoInChars(Ty);
   TypeInfo.Align = getParamTypeAlignment(Ty);
 


Index: clang/test/CodeGen/aix-altivec-vaargs.c
===
--- /dev/null
+++ clang/test/CodeGen/aix-altivec-vaargs.c
@@ -0,0 +1,52 @@
+// REQUIRES: powerpc-registered-target
+// RUN: %clang_cc1 -triple powerpc-unknown-aix -emit-llvm -target-feature +altivec -target-cpu pwr7 -o - %s | FileCheck %s --check-prefixes=CHECK,AIX32
+// RUN: %clang_cc1 -triple powerpc64-unknown-aix -emit-llvm -target-feature +altivec -target-cpu pwr7 -o - %s | FileCheck %s --check-prefixes=CHECK,AIX64
+
+vector double vector_varargs(int count, ...) {
+  __builtin_va_list arg_list;
+  __builtin_va_start(arg_list, count);
+
+  vector double ret;
+
+  for (int i = 0; i != count; ++i) {
+ret = __builtin_va_arg(arg_list, vector double);
+  }
+
+  __builtin_va_end(arg_list);
+  return ret;
+}
+
+// CHECK: %arg_list = alloca i8*
+// CHECK: %arg_list1 = bitcast i8** %arg_list to i8*
+// CHECK: call void @llvm.va_start(i8* %arg_list1)
+
+// AIX32:   for.body:
+// AIX32-NEXT:%argp.cur = load i8*, i8** %arg_list, align 4
+// AIX32-NEXT:%2 = ptrtoint i8* %argp.cur to i32
+// AIX32-NEXT:%3 = add i32 %2, 15
+// AIX32-NEXT:%4 = and i32 %3, -16
+// AIX32-NEXT:%argp.cur.aligned = inttoptr i32 %4 to i8*
+// AIX32-NEXT:%argp.next = getelementptr inbounds i8, i8

[PATCH] D97510: [AArch64][Docs] Release notes 12.x on outline atomics

2021-03-01 Thread Pavel Iliin via Phabricator via cfe-commits
ilinpv closed this revision.
ilinpv added a comment.

Tim, thank you for review, noticed typos and overall support to outline atomics 
patches!
Notes pushed rG98f06b16a313ece593f5711778d7da9037f3a2ef 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97510

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


[PATCH] D97699: [analyzer] Add InvalidPtrChecker

2021-03-01 Thread Zurab Tsinadze via Phabricator via cfe-commits
zukatsinadze updated this revision to Diff 327173.
zukatsinadze added a comment.

Removed code repetition from the tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97699

Files:
  clang/docs/analyzer/checkers.rst
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  clang/lib/StaticAnalyzer/Checkers/cert/InvalidPtrChecker.cpp
  clang/test/Analysis/cert/env31-c.c
  clang/test/Analysis/cert/env34-c-cert-examples.c
  clang/test/Analysis/cert/env34-c.c

Index: clang/test/Analysis/cert/env34-c.c
===
--- /dev/null
+++ clang/test/Analysis/cert/env34-c.c
@@ -0,0 +1,241 @@
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=alpha.security.cert.env.InvalidPtr\
+// RUN:  -analyzer-output=text -verify -Wno-unused %s
+
+#include "../Inputs/system-header-simulator.h"
+char *getenv(const char *name);
+char *setlocale(int category, const char *locale);
+char *strerror(int errnum);
+
+typedef struct {
+  char * field;
+} lconv;
+lconv *localeconv(void);
+
+typedef struct {
+} tm;
+char *asctime(const tm *timeptr);
+
+int strcmp(const char*, const char*);
+extern void foo(char *e);
+extern char* bar();
+
+
+void getenv_test1() {
+  char *p, *p2, *p3;
+
+  p = getenv("VAR");
+  *p; // no-warning
+
+  p = getenv("VAR2");
+  // expected-note@-1{{previous function call was here}}
+  p3 = getenv("VAR2");
+  // expected-note@-1{{'getenv' call may invalidate the the result of the previous 'getenv'}}
+
+  p2 = getenv("VAR3");
+
+  *p;
+  // expected-warning@-1{{dereferencing an invalid pointer}}
+  // expected-note@-2{{dereferencing an invalid pointer}}
+}
+
+void getenv_test2() {
+  char *p, *p2;
+  p = getenv("VAR");
+  *p; // no-warning
+
+  p = getenv("VAR2");
+  // expected-note@-1{{previous function call was here}}
+  *p; // no-warning
+
+  p2 = getenv("VAR3");
+  // expected-note@-1{{previous function call was here}}
+  // expected-note@-2{{'getenv' call may invalidate the the result of the previous 'getenv'}}
+
+  *p;
+  // expected-warning@-1{{dereferencing an invalid pointer}}
+  // expected-note@-2{{dereferencing an invalid pointer}}
+
+  *p2; // no-warning
+
+  p = getenv("VAR4");
+  // expected-note@-1{{'getenv' call may invalidate the the result of the previous 'getenv'}}
+
+  *p; // no-warning
+  *p2;
+  // expected-warning@-1{{dereferencing an invalid pointer}}
+  // expected-note@-2{{dereferencing an invalid pointer}}
+}
+
+void getenv_test3() {
+  char *p, *p2;
+  p = getenv("VAR");
+  // expected-note@-1{{previous function call was here}}
+  *p; // no-warning
+
+  p2 = getenv("VAR2");
+  // expected-note@-1{{'getenv' call may invalidate the the result of the previous 'getenv'}}
+
+  foo(p);
+  // expected-warning@-1{{use of invalidated pointer 'p' in a function call}}
+  // expected-note@-2{{use of invalidated pointer 'p' in a function call}}
+}
+
+void getenv_test4() {
+  static const char *array[] = {
+ 0,
+ 0,
+ "/var/tmp",
+ "/usr/tmp",
+ "/tmp",
+ "."
+  };
+
+  if( !array[0] )
+  // expected-note@-1{{Taking true branch}}
+array[0] = getenv("TEMPDIR");
+// expected-note@-1{{previous function call was here}}
+
+  if( !array[1] )
+  // expected-note@-1{{Taking true branch}}
+array[1] = getenv("TMPDIR");
+// expected-note@-1{{'getenv' call may invalidate the the result of the previous 'getenv'}}
+
+  *array[0];
+  // expected-warning@-1{{dereferencing an invalid pointer}}
+  // expected-note@-2{{dereferencing an invalid pointer}}
+}
+
+void getenv_test5() {
+  char *p, *p2;
+  p = getenv("something");
+  p = bar();
+  p2 = getenv("something");
+  *p; // no-warning
+}
+
+void getenv_test6() {
+  strcmp(getenv("VAR1"), getenv("VAR2"));
+  // expected-note@-1{{'getenv' call may invalidate the the result of the previous 'getenv'}}
+  // expected-note@-2{{previous function call was here}}
+  // expected-warning@-3{{use of invalidated pointer 'getenv("VAR1")' in a function call}}
+  // expected-note@-4{{use of invalidated pointer 'getenv("VAR1")' in a function call}}
+}
+
+void setlocale_test1() {
+  char *p, *p2;
+  p = setlocale(0, "VAR");
+  *p; // no-warning
+
+  p = setlocale(0, "VAR2");
+  // expected-note@-1{{previous function call was here}}
+  *p; // no-warning
+
+  p2 = setlocale(0, "VAR3");
+  // expected-note@-1{{'setlocale' call may invalidate the the result of the previous 'setlocale'}}
+
+  *p;
+  // expected-warning@-1{{dereferencing an invalid pointer}}
+  // expected-note@-2{{dereferencing an invalid pointer}}
+}
+
+void setlocale_test2(int flag) {
+  char *p, *p2;
+  p = setlocale(0, "VAR");
+  *p; // no-warning
+
+  p = setlocale(0, "VAR2");
+  // expected-note@-1{{previous function call was here}}
+  *p; // no-warning
+
+  if (flag) {
+// expected-note@-1{{Assuming 'flag' is not equal to 0}}
+// expected-note@-2{{Taking true branch}}
+

[PATCH] D97632: [clang-tidy] Simplify diagnostics for UniqueptrResetRelease check

2021-03-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM aside from a nit with the diagnostic wording.




Comment at: clang-tools-extra/clang-tidy/misc/UniqueptrResetReleaseCheck.cpp:115
+  auto D = diag(ResetMember->getExprLoc(),
+"prefer 'unique_ptr<>' assignment over release and reset");
+  if (ResetMember->isArrow())




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97632

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


[PATCH] D91164: [clang-tidy] Improve C++ support in bugprone-signal-handler.

2021-03-01 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp:100-101
 const LangOptions &LangOpts) const {
-  // FIXME: Make the checker useful on C++ code.
-  if (LangOpts.CPlusPlus)
+  // FIXME: Improve C++ support.
+  if (LangOpts.CPlusPlus17)
 return false;

What happens differently in c++17 and later?



Comment at: clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp:137
 
+  if (!HandlerDecl->isExternC()) {
+reportNonExternCBug(HandlerExpr, HandlerDecl);

Why can't c++ linkage functions be used a signal handlers.
This is also not sticking to the documentation of this check. Ths documentation 
just lists that it guards against non asynchronous-safe functions being called 
from signal handlers.



Comment at: clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp:241-242
+void SignalHandlerCheck::reportLambdaBug(const Expr *HandlerRef) {
+  diag(HandlerRef->getBeginLoc(),
+   "lambda expression is not allowed as signal handler");
+}

Why can't lambdas be used as signal handlers, If they are stateless they can be 
implicitly converted to function pointers. Or is this something about needing C 
linkage?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D91164

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


[PATCH] D87321: Fix -gz=zlib options for linker

2021-03-01 Thread Ed Maste via Phabricator via cfe-commits
emaste added a comment.

I just ran into this issue on FreeBSD, bug report in 
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=253942

clang/lib/Driver/ToolChains/FreeBSD.cpp needs updating for this change also


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D87321

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


[PATCH] D97620: Fix DecisionForestBenchmark.cpp compile errors

2021-03-01 Thread Conrad Poelman via Phabricator via cfe-commits
poelmanc updated this revision to Diff 327174.
poelmanc added a comment.

Fix comment.


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

https://reviews.llvm.org/D97620

Files:
  
clang-tools-extra/clangd/benchmarks/CompletionModel/DecisionForestBenchmark.cpp


Index: 
clang-tools-extra/clangd/benchmarks/CompletionModel/DecisionForestBenchmark.cpp
===
--- 
clang-tools-extra/clangd/benchmarks/CompletionModel/DecisionForestBenchmark.cpp
+++ 
clang-tools-extra/clangd/benchmarks/CompletionModel/DecisionForestBenchmark.cpp
@@ -21,7 +21,7 @@
 namespace clangd {
 namespace {
 std::vector generateRandomDataset(int NumExamples) {
-  auto FlipCoin = [&](float Probability) {
+  auto FlipCoin = [&](double Probability) {
 return rand() % 1000 <= Probability * 1000;
   };
   auto RandInt = [&](int Max) { return rand() % Max; };
@@ -38,15 +38,15 @@
 E.setIsImplementationDetail(FlipCoin(0.3)); // Boolean.
 E.setNumReferences(RandInt(1)); // Can be large integer.
 E.setSymbolCategory(RandInt(10));   // 10 Symbol Category.
-
+E.setNumNameInContext(RandInt(20)); // 0 to ContextWords->size().
+E.setFractionNameInContext(RandFloat(1.0)); // Float in range [0,1].
 E.setIsNameInContext(FlipCoin(0.5)); // Boolean.
-E.setIsForbidden(FlipCoin(0.1)); // Boolean.
 E.setIsInBaseClass(FlipCoin(0.3));   // Boolean.
-E.setFileProximityDistance(
+E.setFileProximityDistanceCost(
 FlipCoin(0.1) ? 99 // Sometimes file distance is not available.
   : RandInt(20));
 E.setSemaFileProximityScore(RandFloat(1)); // Float in range [0,1].
-E.setSymbolScopeDistance(
+E.setSymbolScopeDistanceCost(
 FlipCoin(0.1) ? 99 // Sometimes scope distance is not available.
   : RandInt(20));
 E.setSemaSaysInScope(FlipCoin(0.5));  // Boolean.
@@ -56,7 +56,6 @@
 E.setHadContextType(FlipCoin(0.6));   // Boolean.
 E.setHadSymbolType(FlipCoin(0.6));// Boolean.
 E.setTypeMatchesPreferred(FlipCoin(0.5)); // Boolean.
-E.setFilterLength(RandInt(15));
 Examples.push_back(E);
   }
   return Examples;


Index: clang-tools-extra/clangd/benchmarks/CompletionModel/DecisionForestBenchmark.cpp
===
--- clang-tools-extra/clangd/benchmarks/CompletionModel/DecisionForestBenchmark.cpp
+++ clang-tools-extra/clangd/benchmarks/CompletionModel/DecisionForestBenchmark.cpp
@@ -21,7 +21,7 @@
 namespace clangd {
 namespace {
 std::vector generateRandomDataset(int NumExamples) {
-  auto FlipCoin = [&](float Probability) {
+  auto FlipCoin = [&](double Probability) {
 return rand() % 1000 <= Probability * 1000;
   };
   auto RandInt = [&](int Max) { return rand() % Max; };
@@ -38,15 +38,15 @@
 E.setIsImplementationDetail(FlipCoin(0.3)); // Boolean.
 E.setNumReferences(RandInt(1)); // Can be large integer.
 E.setSymbolCategory(RandInt(10));   // 10 Symbol Category.
-
+E.setNumNameInContext(RandInt(20)); // 0 to ContextWords->size().
+E.setFractionNameInContext(RandFloat(1.0)); // Float in range [0,1].
 E.setIsNameInContext(FlipCoin(0.5)); // Boolean.
-E.setIsForbidden(FlipCoin(0.1)); // Boolean.
 E.setIsInBaseClass(FlipCoin(0.3));   // Boolean.
-E.setFileProximityDistance(
+E.setFileProximityDistanceCost(
 FlipCoin(0.1) ? 99 // Sometimes file distance is not available.
   : RandInt(20));
 E.setSemaFileProximityScore(RandFloat(1)); // Float in range [0,1].
-E.setSymbolScopeDistance(
+E.setSymbolScopeDistanceCost(
 FlipCoin(0.1) ? 99 // Sometimes scope distance is not available.
   : RandInt(20));
 E.setSemaSaysInScope(FlipCoin(0.5));  // Boolean.
@@ -56,7 +56,6 @@
 E.setHadContextType(FlipCoin(0.6));   // Boolean.
 E.setHadSymbolType(FlipCoin(0.6));// Boolean.
 E.setTypeMatchesPreferred(FlipCoin(0.5)); // Boolean.
-E.setFilterLength(RandInt(15));
 Examples.push_back(E);
   }
   return Examples;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 52b8e10 - [libclang] Remove LIBCLANG_INCLUDE_CLANG_TOOLS_EXTRA

2021-03-01 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2021-03-01T13:21:59-05:00
New Revision: 52b8e10597315a96bc7cbc7cfe618e301c1e6e6c

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

LOG: [libclang] Remove LIBCLANG_INCLUDE_CLANG_TOOLS_EXTRA

LIBCLANG_INCLUDE_CLANG_TOOLS_EXTRA causes clang-tools-extra tools
to be included in libclang, which caused a dependency cycle. The option
has been off by default for two releases now, and (based on a web search
and mailing list feedback) nobody seems to turn it on. Remove it, like
planned on https://reviews.llvm.org/D79599

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

Added: 


Modified: 
clang-tools-extra/test/CMakeLists.txt
clang-tools-extra/test/lit.site.cfg.py.in
clang/docs/ReleaseNotes.rst
clang/tools/libclang/CIndex.cpp
clang/tools/libclang/CMakeLists.txt
llvm/utils/gn/secondary/clang-tools-extra/test/BUILD.gn
llvm/utils/gn/secondary/clang/tools/libclang/BUILD.gn

Removed: 
clang-tools-extra/test/clang-tidy/infrastructure/nolint-plugin.cpp
clang-tools-extra/test/clang-tidy/infrastructure/nolintnextline-plugin.cpp
llvm/utils/gn/secondary/clang/tools/libclang/include_clang_tools_extra.gni



diff  --git a/clang-tools-extra/test/CMakeLists.txt 
b/clang-tools-extra/test/CMakeLists.txt
index 662b138e9f46..06be00015223 100644
--- a/clang-tools-extra/test/CMakeLists.txt
+++ b/clang-tools-extra/test/CMakeLists.txt
@@ -17,7 +17,6 @@ string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} 
CLANG_TOOLS_DIR ${LLVM_RUN
 
 llvm_canonicalize_cmake_booleans(
   CLANG_TIDY_ENABLE_STATIC_ANALYZER
-  LIBCLANG_INCLUDE_CLANG_TOOLS_EXTRA
   )
 
 configure_lit_site_cfg(
@@ -68,10 +67,6 @@ set(CLANG_TOOLS_TEST_DEPS
   # Clang-tidy tests need clang for building modules.
   clang
 )
-if (LIBCLANG_INCLUDE_CLANG_TOOLS_EXTRA)
-  # For the clang-tidy libclang integration test.
-  set(CLANG_TOOLS_TEST_DEPS ${CLANG_TOOLS_TEST_DEPS} "c-index-test")
-endif ()
 
 # Add lit test dependencies.
 set(LLVM_UTILS_DEPS

diff  --git 
a/clang-tools-extra/test/clang-tidy/infrastructure/nolint-plugin.cpp 
b/clang-tools-extra/test/clang-tidy/infrastructure/nolint-plugin.cpp
deleted file mode 100644
index d10c16620749..
--- a/clang-tools-extra/test/clang-tidy/infrastructure/nolint-plugin.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
-// REQUIRES: static-analyzer, libclang_include_clang_tools_extra
-// RUN: c-index-test -test-load-source-reparse 2 all %s -Xclang -add-plugin 
-Xclang clang-tidy -Xclang -plugin-arg-clang-tidy -Xclang 
-checks='-*,google-explicit-constructor,clang-diagnostic-unused-variable,clang-analyzer-core.UndefinedBinaryOperatorResult'
 -Wunused-variable -I%S/Inputs/nolint 2>&1 | FileCheck %s
-
-#include "trigger_warning.h"
-void I(int& Out) {
-  int In;
-  A1(In, Out);
-}
-// CHECK-NOT: trigger_warning.h:{{.*}} warning
-// CHECK-NOT: :[[@LINE-4]]:{{.*}} note
-
-class A { A(int i); };
-// CHECK-DAG: :[[@LINE-1]]:11: warning: single-argument constructors must be 
marked explicit
-
-class B { B(int i); }; // NOLINT
-
-class C { C(int i); }; // NOLINT(for-some-other-check)
-// CHECK-DAG: :[[@LINE-1]]:11: warning: single-argument constructors must be 
marked explicit
-
-class C1 { C1(int i); }; // NOLINT(*)
-
-class C2 { C2(int i); }; // NOLINT(not-closed-bracket-is-treated-as-skip-all
-
-class C3 { C3(int i); }; // NOLINT(google-explicit-constructor)
-
-class C4 { C4(int i); }; // NOLINT(some-check, google-explicit-constructor)
-
-class C5 { C5(int i); }; // NOLINT without-brackets-skip-all, another-check
-
-void f() {
-  int i;
-// CHECK-DAG: :[[@LINE-1]]:7: warning: unused variable 'i' [-Wunused-variable]
-//  31:7: warning: unused variable 'i' 
[-Wunused-variable]
-//  int j; // NOLINT
-//  int k; // NOLINT(clang-diagnostic-unused-variable)
-}
-
-#define MACRO(X) class X { X(int i); };
-MACRO(D)
-// CHECK-DAG: :[[@LINE-1]]:7: warning: single-argument constructors must be 
marked explicit
-MACRO(E) // NOLINT
-
-#define MACRO_NOARG class F { F(int i); };
-MACRO_NOARG // NOLINT
-
-#define MACRO_NOLINT class G { G(int i); }; // NOLINT
-MACRO_NOLINT
-
-#define DOUBLE_MACRO MACRO(H) // NOLINT
-DOUBLE_MACRO

diff  --git 
a/clang-tools-extra/test/clang-tidy/infrastructure/nolintnextline-plugin.cpp 
b/clang-tools-extra/test/clang-tidy/infrastructure/nolintnextline-plugin.cpp
deleted file mode 100644
index 4835f4c52a45..
--- a/clang-tools-extra/test/clang-tidy/infrastructure/nolintnextline-plugin.cpp
+++ /dev/null
@@ -1,49 +0,0 @@
-// REQUIRES: libclang_include_clang_tools_extra
-// RUN: c-index-test -test-load-source-reparse 2 all %s -Xclang -add-plugin 
-Xclang clang-tidy -Xclang -plugin-arg-clang-tidy -Xclang 
-checks='-*,google-explicit-constructor' 2>&1 | FileCheck %s
-
-class A { A(int i); };
-// CHECK: :[[@LINE-1]]:1

[PATCH] D97693: [libclang] Remove LIBCLANG_INCLUDE_CLANG_TOOLS_EXTRA

2021-03-01 Thread Nico Weber via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG52b8e1059731: [libclang] Remove 
LIBCLANG_INCLUDE_CLANG_TOOLS_EXTRA (authored by thakis).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D97693?vs=327127&id=327175#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97693

Files:
  clang-tools-extra/test/CMakeLists.txt
  clang-tools-extra/test/clang-tidy/infrastructure/nolint-plugin.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/nolintnextline-plugin.cpp
  clang-tools-extra/test/lit.site.cfg.py.in
  clang/docs/ReleaseNotes.rst
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CMakeLists.txt
  llvm/utils/gn/secondary/clang-tools-extra/test/BUILD.gn
  llvm/utils/gn/secondary/clang/tools/libclang/BUILD.gn
  llvm/utils/gn/secondary/clang/tools/libclang/include_clang_tools_extra.gni

Index: llvm/utils/gn/secondary/clang/tools/libclang/include_clang_tools_extra.gni
===
--- llvm/utils/gn/secondary/clang/tools/libclang/include_clang_tools_extra.gni
+++ /dev/null
@@ -1,4 +0,0 @@
-declare_args() {
-  # Whether to include code from clang-tools-extra in libclang.
-  libclang_include_clang_tools_extra = false
-}
Index: llvm/utils/gn/secondary/clang/tools/libclang/BUILD.gn
===
--- llvm/utils/gn/secondary/clang/tools/libclang/BUILD.gn
+++ llvm/utils/gn/secondary/clang/tools/libclang/BUILD.gn
@@ -1,5 +1,4 @@
 import("//clang/lib/ARCMigrate/enable.gni")
-import("//clang/tools/libclang/include_clang_tools_extra.gni")
 import("//llvm/version.gni")
 
 # This build file is just enough to get check-clang to pass, it's missing
@@ -40,16 +39,6 @@
 
   defines = []
 
-  # FIXME: Once the GN build has a way to select which bits to build,
-  # only include this dependency if clang-tools-extra is part of the build.
-  if (libclang_include_clang_tools_extra) {
-defines += [ "CLANG_TOOL_EXTRA_BUILD" ]
-deps += [
-  "//clang-tools-extra/clang-include-fixer/plugin",
-  "//clang-tools-extra/clang-tidy/plugin",
-]
-  }
-
   if (host_os == "win") {
 defines += [ "_CINDEX_LIB_" ]
   }
Index: llvm/utils/gn/secondary/clang-tools-extra/test/BUILD.gn
===
--- llvm/utils/gn/secondary/clang-tools-extra/test/BUILD.gn
+++ llvm/utils/gn/secondary/clang-tools-extra/test/BUILD.gn
@@ -1,6 +1,5 @@
 import("//clang-tools-extra/clang-tidy/enable.gni")
 import("//clang/lib/StaticAnalyzer/Frontend/enable.gni")
-import("//clang/tools/libclang/include_clang_tools_extra.gni")
 import("//llvm/triples.gni")
 import("//llvm/utils/gn/build/write_cmake_config.gni")
 import("clang_tools_extra_lit_site_cfg_files.gni")
@@ -44,12 +43,6 @@
   } else {
 extra_values += [ "CLANG_TIDY_ENABLE_STATIC_ANALYZER=0" ]
   }
-
-  if (libclang_include_clang_tools_extra) {
-extra_values += [ "LIBCLANG_INCLUDE_CLANG_TOOLS_EXTRA=1" ]
-  } else {
-extra_values += [ "LIBCLANG_INCLUDE_CLANG_TOOLS_EXTRA=0" ]
-  }
 }
 
 write_lit_config("lit_unit_site_cfg") {
Index: clang/tools/libclang/CMakeLists.txt
===
--- clang/tools/libclang/CMakeLists.txt
+++ clang/tools/libclang/CMakeLists.txt
@@ -52,22 +52,6 @@
   list(APPEND LIBS clangARCMigrate)
 endif ()
 
-option(LIBCLANG_INCLUDE_CLANG_TOOLS_EXTRA
-  "Include code from clang-tools-extra in libclang." OFF)
-
-if (LIBCLANG_INCLUDE_CLANG_TOOLS_EXTRA)
-  if (TARGET clangTidyPlugin)
-add_definitions(-DCLANG_TOOL_EXTRA_BUILD)
-list(APPEND LIBS clangTidyPlugin)
-list(APPEND LIBS clangIncludeFixerPlugin)
-if(LLVM_ENABLE_MODULES)
-  list(APPEND LLVM_COMPILE_FLAGS "-fmodules-ignore-macro=CLANG_TOOL_EXTRA_BUILD")
-endif()
-  else ()
-message(FATAL_ERROR "LIBCLANG_INCLUDE_CLANG_TOOLS_EXTRA needs clang-tools-extra in LLVM_ENABLE_PROJECTS")
-  endif ()
-endif ()
-
 if (HAVE_LIBDL)
   list(APPEND LIBS ${CMAKE_DL_LIBS})
 elseif (CLANG_BUILT_STANDALONE)
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -9161,16 +9161,3 @@
 OS << "--\n";
   }
 }
-
-#ifdef CLANG_TOOL_EXTRA_BUILD
-// This anchor is used to force the linker to link the clang-tidy plugin.
-extern volatile int ClangTidyPluginAnchorSource;
-static int LLVM_ATTRIBUTE_UNUSED ClangTidyPluginAnchorDestination =
-ClangTidyPluginAnchorSource;
-
-// This anchor is used to force the linker to link the clang-include-fixer
-// plugin.
-extern volatile int ClangIncludeFixerPluginAnchorSource;
-static int LLVM_ATTRIBUTE_UNUSED ClangIncludeFixerPluginAnchorDestination =
-ClangIncludeFixerPluginAnchorSource;
-#endif
Index: clang/docs/Releas

[PATCH] D97620: Fix DecisionForestBenchmark.cpp compile errors

2021-03-01 Thread Conrad Poelman via Phabricator via cfe-commits
poelmanc marked an inline comment as done.
poelmanc added a comment.

Fixed comment as requested (keys()->size().) I don't have commit access so if 
you can push it that would be great, thanks!


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

https://reviews.llvm.org/D97620

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


[clang] 283db5f - BPF: fix enum value 0 issue for __builtin_preserve_enum_value()

2021-03-01 Thread Yonghong Song via cfe-commits

Author: Yonghong Song
Date: 2021-03-01T10:23:24-08:00
New Revision: 283db5f0837d55f91242812003adf6e189ba743e

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

LOG: BPF: fix enum value 0 issue for __builtin_preserve_enum_value()

Lorenz Bauer reported that the following code will have
compilation error for bpf target:
enum e { TWO };
bpf_core_enum_value_exists(enum e, TWO);
The clang emitted the following error message:
__builtin_preserve_enum_value argument 1 invalid

In SemaChecking, an expression like "*(enum NAME)1" will have
cast kind CK_IntegralToPointer, but "*(enum NAME)0" will have
cast kind CK_NullToPointer. Current implementation only permits
CK_IntegralToPointer, missing enum value 0 case.

This patch permits CK_NullToPointer cast kind and
the above test case can pass now.

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

Added: 


Modified: 
clang/lib/Sema/SemaChecking.cpp
clang/test/CodeGen/builtins-bpf-preserve-field-info-4.c

Removed: 




diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index f67cba189344..ccde2f3164a1 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -2626,7 +2626,10 @@ static bool isValidBPFPreserveEnumValueArg(Expr *Arg) {
 return false;
 
   const auto *CE = dyn_cast(UO->getSubExpr());
-  if (!CE || CE->getCastKind() != CK_IntegralToPointer)
+  if (!CE)
+return false;
+  if (CE->getCastKind() != CK_IntegralToPointer &&
+  CE->getCastKind() != CK_NullToPointer)
 return false;
 
   // The integer must be from an EnumConstantDecl.

diff  --git a/clang/test/CodeGen/builtins-bpf-preserve-field-info-4.c 
b/clang/test/CodeGen/builtins-bpf-preserve-field-info-4.c
index e07c680bb370..b167b776e385 100644
--- a/clang/test/CodeGen/builtins-bpf-preserve-field-info-4.c
+++ b/clang/test/CodeGen/builtins-bpf-preserve-field-info-4.c
@@ -4,10 +4,11 @@
 #define _(x, y) (__builtin_preserve_enum_value((x), (y)))
 
 enum AA {
+  VAL0 = 0,
   VAL1 = 2,
   VAL2 = 0x8000UL,
 };
-typedef enum { VAL10 = -2, VAL11 = 0x8000, }  __BB;
+typedef enum { VAL00, VAL10 = -2, VAL11 = 0x8000, }  __BB;
 
 unsigned unit1() {
   return _(*(enum AA *)VAL1, 0) + _(*(__BB *)VAL10, 1);
@@ -17,10 +18,16 @@ unsigned unit2() {
   return _(*(enum AA *)VAL2, 0) + _(*(__BB *)VAL11, 1);
 }
 
+unsigned unit3() {
+  return _(*(enum AA *)VAL0, 0) + _(*(__BB *)VAL00, 1);
+}
+
 // CHECK: @0 = private unnamed_addr constant [7 x i8] c"VAL1:2\00", align 1
 // CHECK: @1 = private unnamed_addr constant [9 x i8] c"VAL10:-2\00", align 1
 // CHECK: @2 = private unnamed_addr constant [17 x i8] c"VAL2:-2147483648\00", 
align 1
 // CHECK: @3 = private unnamed_addr constant [17 x i8] c"VAL11:4294934528\00", 
align 1
+// CHECK: @4 = private unnamed_addr constant [7 x i8] c"VAL0:0\00", align 1
+// CHECK: @5 = private unnamed_addr constant [8 x i8] c"VAL00:0\00", align 1
 
 // CHECK: call i64 @llvm.bpf.preserve.enum.value(i32 0, i8* getelementptr 
inbounds ([7 x i8], [7 x i8]* @0, i32 0, i32 0), i64 0), !dbg !{{[0-9]+}}, 
!llvm.preserve.access.index ![[ENUM_AA:[0-9]+]]
 // CHECK: call i64 @llvm.bpf.preserve.enum.value(i32 1, i8* getelementptr 
inbounds ([9 x i8], [9 x i8]* @1, i32 0, i32 0), i64 1), !dbg !{{[0-9]+}}, 
!llvm.preserve.access.index ![[TYPEDEF_ENUM:[0-9]+]]
@@ -28,5 +35,8 @@ unsigned unit2() {
 // CHECK: call i64 @llvm.bpf.preserve.enum.value(i32 2, i8* getelementptr 
inbounds ([17 x i8], [17 x i8]* @2, i32 0, i32 0), i64 0), !dbg !{{[0-9]+}}, 
!llvm.preserve.access.index ![[ENUM_AA]]
 // CHECK: call i64 @llvm.bpf.preserve.enum.value(i32 3, i8* getelementptr 
inbounds ([17 x i8], [17 x i8]* @3, i32 0, i32 0), i64 1), !dbg !{{[0-9]+}}, 
!llvm.preserve.access.index ![[TYPEDEF_ENUM]]
 
+// CHECK: call i64 @llvm.bpf.preserve.enum.value(i32 4, i8* getelementptr 
inbounds ([7 x i8], [7 x i8]* @4, i32 0, i32 0), i64 0), !dbg !{{[0-9]+}}, 
!llvm.preserve.access.index ![[ENUM_AA]]
+// CHECK: call i64 @llvm.bpf.preserve.enum.value(i32 5, i8* getelementptr 
inbounds ([8 x i8], [8 x i8]* @5, i32 0, i32 0), i64 1), !dbg !{{[0-9]+}}, 
!llvm.preserve.access.index ![[TYPEDEF_ENUM]]
+
 // CHECK: ![[ENUM_AA]] = !DICompositeType(tag: DW_TAG_enumeration_type, name: 
"AA"
 // CHECK: ![[TYPEDEF_ENUM]] = !DIDerivedType(tag: DW_TAG_typedef, name: "__BB"



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


[PATCH] D97659: BPF: fix enum value 0 issue for __builtin_preserve_enum_value()

2021-03-01 Thread Yonghong Song via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG283db5f0837d: BPF: fix enum value 0 issue for 
__builtin_preserve_enum_value() (authored by yonghong-song).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97659

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-bpf-preserve-field-info-4.c


Index: clang/test/CodeGen/builtins-bpf-preserve-field-info-4.c
===
--- clang/test/CodeGen/builtins-bpf-preserve-field-info-4.c
+++ clang/test/CodeGen/builtins-bpf-preserve-field-info-4.c
@@ -4,10 +4,11 @@
 #define _(x, y) (__builtin_preserve_enum_value((x), (y)))
 
 enum AA {
+  VAL0 = 0,
   VAL1 = 2,
   VAL2 = 0x8000UL,
 };
-typedef enum { VAL10 = -2, VAL11 = 0x8000, }  __BB;
+typedef enum { VAL00, VAL10 = -2, VAL11 = 0x8000, }  __BB;
 
 unsigned unit1() {
   return _(*(enum AA *)VAL1, 0) + _(*(__BB *)VAL10, 1);
@@ -17,10 +18,16 @@
   return _(*(enum AA *)VAL2, 0) + _(*(__BB *)VAL11, 1);
 }
 
+unsigned unit3() {
+  return _(*(enum AA *)VAL0, 0) + _(*(__BB *)VAL00, 1);
+}
+
 // CHECK: @0 = private unnamed_addr constant [7 x i8] c"VAL1:2\00", align 1
 // CHECK: @1 = private unnamed_addr constant [9 x i8] c"VAL10:-2\00", align 1
 // CHECK: @2 = private unnamed_addr constant [17 x i8] c"VAL2:-2147483648\00", 
align 1
 // CHECK: @3 = private unnamed_addr constant [17 x i8] c"VAL11:4294934528\00", 
align 1
+// CHECK: @4 = private unnamed_addr constant [7 x i8] c"VAL0:0\00", align 1
+// CHECK: @5 = private unnamed_addr constant [8 x i8] c"VAL00:0\00", align 1
 
 // CHECK: call i64 @llvm.bpf.preserve.enum.value(i32 0, i8* getelementptr 
inbounds ([7 x i8], [7 x i8]* @0, i32 0, i32 0), i64 0), !dbg !{{[0-9]+}}, 
!llvm.preserve.access.index ![[ENUM_AA:[0-9]+]]
 // CHECK: call i64 @llvm.bpf.preserve.enum.value(i32 1, i8* getelementptr 
inbounds ([9 x i8], [9 x i8]* @1, i32 0, i32 0), i64 1), !dbg !{{[0-9]+}}, 
!llvm.preserve.access.index ![[TYPEDEF_ENUM:[0-9]+]]
@@ -28,5 +35,8 @@
 // CHECK: call i64 @llvm.bpf.preserve.enum.value(i32 2, i8* getelementptr 
inbounds ([17 x i8], [17 x i8]* @2, i32 0, i32 0), i64 0), !dbg !{{[0-9]+}}, 
!llvm.preserve.access.index ![[ENUM_AA]]
 // CHECK: call i64 @llvm.bpf.preserve.enum.value(i32 3, i8* getelementptr 
inbounds ([17 x i8], [17 x i8]* @3, i32 0, i32 0), i64 1), !dbg !{{[0-9]+}}, 
!llvm.preserve.access.index ![[TYPEDEF_ENUM]]
 
+// CHECK: call i64 @llvm.bpf.preserve.enum.value(i32 4, i8* getelementptr 
inbounds ([7 x i8], [7 x i8]* @4, i32 0, i32 0), i64 0), !dbg !{{[0-9]+}}, 
!llvm.preserve.access.index ![[ENUM_AA]]
+// CHECK: call i64 @llvm.bpf.preserve.enum.value(i32 5, i8* getelementptr 
inbounds ([8 x i8], [8 x i8]* @5, i32 0, i32 0), i64 1), !dbg !{{[0-9]+}}, 
!llvm.preserve.access.index ![[TYPEDEF_ENUM]]
+
 // CHECK: ![[ENUM_AA]] = !DICompositeType(tag: DW_TAG_enumeration_type, name: 
"AA"
 // CHECK: ![[TYPEDEF_ENUM]] = !DIDerivedType(tag: DW_TAG_typedef, name: "__BB"
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -2626,7 +2626,10 @@
 return false;
 
   const auto *CE = dyn_cast(UO->getSubExpr());
-  if (!CE || CE->getCastKind() != CK_IntegralToPointer)
+  if (!CE)
+return false;
+  if (CE->getCastKind() != CK_IntegralToPointer &&
+  CE->getCastKind() != CK_NullToPointer)
 return false;
 
   // The integer must be from an EnumConstantDecl.


Index: clang/test/CodeGen/builtins-bpf-preserve-field-info-4.c
===
--- clang/test/CodeGen/builtins-bpf-preserve-field-info-4.c
+++ clang/test/CodeGen/builtins-bpf-preserve-field-info-4.c
@@ -4,10 +4,11 @@
 #define _(x, y) (__builtin_preserve_enum_value((x), (y)))
 
 enum AA {
+  VAL0 = 0,
   VAL1 = 2,
   VAL2 = 0x8000UL,
 };
-typedef enum { VAL10 = -2, VAL11 = 0x8000, }  __BB;
+typedef enum { VAL00, VAL10 = -2, VAL11 = 0x8000, }  __BB;
 
 unsigned unit1() {
   return _(*(enum AA *)VAL1, 0) + _(*(__BB *)VAL10, 1);
@@ -17,10 +18,16 @@
   return _(*(enum AA *)VAL2, 0) + _(*(__BB *)VAL11, 1);
 }
 
+unsigned unit3() {
+  return _(*(enum AA *)VAL0, 0) + _(*(__BB *)VAL00, 1);
+}
+
 // CHECK: @0 = private unnamed_addr constant [7 x i8] c"VAL1:2\00", align 1
 // CHECK: @1 = private unnamed_addr constant [9 x i8] c"VAL10:-2\00", align 1
 // CHECK: @2 = private unnamed_addr constant [17 x i8] c"VAL2:-2147483648\00", align 1
 // CHECK: @3 = private unnamed_addr constant [17 x i8] c"VAL11:4294934528\00", align 1
+// CHECK: @4 = private unnamed_addr constant [7 x i8] c"VAL0:0\00", align 1
+// CHECK: @5 = private unnamed_addr constant [8 x i8] c"VAL00:0\00", align 1
 
 // CHECK: call i64 @llvm.bpf.preserve.enum.value(i32 0, i8* getelementptr inb

[PATCH] D97706: Make -f[no-]split-dwarf-inlining CC1 default align with driver default (no inlining)

2021-03-01 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added a reviewer: dblaikie.
Herald added subscribers: jansvoboda11, dang.
MaskRay requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Verified that the below is still true:

- `clang -g` => `splitDebugInlining: false` in DICompileUnit
- `clang -g -gsplit-dwarf` => no `splitDebugInlining: false`


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97706

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/split-debug-inlining.c
  clang/test/Driver/split-debug.c


Index: clang/test/Driver/split-debug.c
===
--- clang/test/Driver/split-debug.c
+++ clang/test/Driver/split-debug.c
@@ -7,8 +7,8 @@
 /// -gsplit-dwarf=split is equivalent to -gsplit-dwarf.
 // RUN: %clang -### -c -target x86_64 -gsplit-dwarf=split -g %s 2>&1 | 
FileCheck %s --check-prefixes=NOINLINE,SPLIT
 
-// INLINE-NOT: "-fno-split-dwarf-inlining"
-// NOINLINE:   "-fno-split-dwarf-inlining"
+// INLINE: "-fsplit-dwarf-inlining"
+// NOINLINE-NOT: "-fsplit-dwarf-inlining"
 // SPLIT:  "-debug-info-kind=limited"
 // SPLIT-SAME: "-ggnu-pubnames"
 // SPLIT-SAME: "-split-dwarf-file" "split-debug.dwo" "-split-dwarf-output" 
"split-debug.dwo"
Index: clang/test/CodeGen/split-debug-inlining.c
===
--- clang/test/CodeGen/split-debug-inlining.c
+++ clang/test/CodeGen/split-debug-inlining.c
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -debug-info-kind=limited -fno-split-dwarf-inlining -S 
-emit-llvm -o - %s | FileCheck %s
-// RUN: %clang_cc1 -debug-info-kind=limited -S -emit-llvm -o - %s | FileCheck 
--check-prefix=ABSENT %s
+// RUN: %clang_cc1 -debug-info-kind=limited -S -emit-llvm -o - %s | FileCheck 
%s
+// RUN: %clang_cc1 -debug-info-kind=limited -fsplit-dwarf-inlining -S 
-emit-llvm -o - %s | FileCheck --check-prefix=ABSENT %s
 void f(void) {}
 // Verify that disabling split debug inlining info is propagated to the debug
 // info metadata.
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3979,8 +3979,8 @@
   }
 }
 
-  if (T.isOSBinFormatELF() && !SplitDWARFInlining)
-CmdArgs.push_back("-fno-split-dwarf-inlining");
+  if (T.isOSBinFormatELF() && SplitDWARFInlining)
+CmdArgs.push_back("-fsplit-dwarf-inlining");
 
   // After we've dealt with all combinations of things that could
   // make DebugInfoKind be other than None or DebugLineTablesOnly,
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2669,9 +2669,9 @@
   PosFlag,
   NegFlag>;
 defm split_dwarf_inlining : BoolFOption<"split-dwarf-inlining",
-  CodeGenOpts<"SplitDwarfInlining">, DefaultTrue,
-  NegFlag,
-  PosFlag, DefaultFalse,
+  NegFlag,
+  PosFlag>;
 def fdebug_default_version: Joined<["-"], "fdebug-default-version=">, 
Group,


Index: clang/test/Driver/split-debug.c
===
--- clang/test/Driver/split-debug.c
+++ clang/test/Driver/split-debug.c
@@ -7,8 +7,8 @@
 /// -gsplit-dwarf=split is equivalent to -gsplit-dwarf.
 // RUN: %clang -### -c -target x86_64 -gsplit-dwarf=split -g %s 2>&1 | FileCheck %s --check-prefixes=NOINLINE,SPLIT
 
-// INLINE-NOT: "-fno-split-dwarf-inlining"
-// NOINLINE:   "-fno-split-dwarf-inlining"
+// INLINE: "-fsplit-dwarf-inlining"
+// NOINLINE-NOT: "-fsplit-dwarf-inlining"
 // SPLIT:  "-debug-info-kind=limited"
 // SPLIT-SAME: "-ggnu-pubnames"
 // SPLIT-SAME: "-split-dwarf-file" "split-debug.dwo" "-split-dwarf-output" "split-debug.dwo"
Index: clang/test/CodeGen/split-debug-inlining.c
===
--- clang/test/CodeGen/split-debug-inlining.c
+++ clang/test/CodeGen/split-debug-inlining.c
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -debug-info-kind=limited -fno-split-dwarf-inlining -S -emit-llvm -o - %s | FileCheck %s
-// RUN: %clang_cc1 -debug-info-kind=limited -S -emit-llvm -o - %s | FileCheck --check-prefix=ABSENT %s
+// RUN: %clang_cc1 -debug-info-kind=limited -S -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -debug-info-kind=limited -fsplit-dwarf-inlining -S -emit-llvm -o - %s | FileCheck --check-prefix=ABSENT %s
 void f(void) {}
 // Verify that disabling split debug inlining info is propagated to the debug
 // info metadata.
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3979,8 +3979,8 @@
   }
 }
 
-  if (T.isOSBinFormatELF() && !SplitDWARFInlining)
-CmdArgs.push_back("-fno-split-dwarf-

[PATCH] D97617: [clangd] ObjC fixes for semantic highlighting and xref highlights

2021-03-01 Thread David Goldman via Phabricator via cfe-commits
dgoldman added a comment.

In D97617#2592424 , @sammccall wrote:

> (not really sure why this suddenly seemed important to me, but if you don't 
> have semantic highlighting on, you're missing out!)

Thanks!




Comment at: clang-tools-extra/clangd/FindTarget.cpp:657
+void VisitObjCInterfaceDecl(const ObjCInterfaceDecl *OID) {
+  if (OID->hasDefinition())
+visitProtocolList(OID->protocols(), OID->protocol_locs());

Should this be isThisDeclarationADefinition()? Is it even needed (will the 
protocol list just be empty otherwise)?



Comment at: clang-tools-extra/clangd/FindTarget.cpp:659
+visitProtocolList(OID->protocols(), OID->protocol_locs());
+  Base::VisitObjCInterfaceDecl(OID); // Visit the interface itself.
+}

Hmm, for what? might be better to say why/what it does



Comment at: clang-tools-extra/clangd/FindTarget.cpp:668
+  /*IsDecl=*/false,
+  {OCD->getClassInterface()}});
+  Refs.push_back(ReferenceLoc{NestedNameSpecifierLoc(),

IIRC I think it's possible that these could be NULL if the code was invalid, is 
this NULL safe?



Comment at: clang-tools-extra/clangd/FindTarget.cpp:687-689
+  if (OPD->hasDefinition())
+visitProtocolList(OPD->protocols(), OPD->protocol_locs());
+  Base::VisitObjCProtocolDecl(OPD); // Visit the protocol itself.

Same comments here as the interface code above



Comment at: clang-tools-extra/clangd/FindTarget.cpp:774
+  Refs.push_back(ReferenceLoc{NestedNameSpecifierLoc(),
+  E->getSelectorStartLoc(),
+  /*IsDecl=*/false, Targets});

What is this location used for? I guess it's not possible to have multiple Locs 
here like we have for a selector and you specifically handle for semantic 
highlighting below?



Comment at: clang-tools-extra/clangd/XRefs.cpp:927-930
+  // Possible it was something else referencing an ObjCMethodDecl.
+  // If the first token doesn't match, assume our guess was wrong.
+  if (!Locs.empty() && Locs.front() != Loc)
+Locs.clear();

Hmm, is this intentional? Not sure what else could reference it besides maybe a 
property?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97617

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


[clang-tools-extra] 8adfb38 - [clang-tidy] Simplify diagnostics for UniqueptrResetRelease check

2021-03-01 Thread Nathan James via cfe-commits

Author: Nathan James
Date: 2021-03-01T18:40:37Z
New Revision: 8adfb38224697afca205343c0e1a49bd03ecfc09

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

LOG: [clang-tidy] Simplify diagnostics for UniqueptrResetRelease check

Tweak the diagnostics to create small replacements rather than grabbing source 
text from the lexer.
Also simplified the diagnostic message.

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/misc/UniqueptrResetReleaseCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/misc-uniqueptr-reset-release.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/misc/UniqueptrResetReleaseCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/UniqueptrResetReleaseCheck.cpp
index f1e2cbe1fed08..dffb03f76a3d9 100644
--- a/clang-tools-extra/clang-tidy/misc/UniqueptrResetReleaseCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UniqueptrResetReleaseCheck.cpp
@@ -19,18 +19,21 @@ namespace misc {
 void UniqueptrResetReleaseCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
   cxxMemberCallExpr(
-  on(expr().bind("left")), callee(memberExpr().bind("reset_member")),
-  callee(
-  cxxMethodDecl(hasName("reset"),
-ofClass(cxxRecordDecl(hasName("::std::unique_ptr"),
-  
decl().bind("left_class"),
-  has(ignoringParenImpCasts(cxxMemberCallExpr(
-  on(expr().bind("right")),
-  callee(memberExpr().bind("release_member")),
-  callee(cxxMethodDecl(
-  hasName("release"),
-  ofClass(cxxRecordDecl(hasName("::std::unique_ptr"),
-decl().bind("right_class")
+  callee(memberExpr(
+ member(cxxMethodDecl(
+ hasName("reset"),
+ ofClass(cxxRecordDecl(hasName("::std::unique_ptr"),
+   decl().bind("left_class"))
+ .bind("reset_member")),
+  hasArgument(
+  0, ignoringParenImpCasts(cxxMemberCallExpr(
+ on(expr().bind("right")),
+ callee(memberExpr(member(cxxMethodDecl(
+   hasName("release"),
+   ofClass(cxxRecordDecl(
+   hasName("::std::unique_ptr"),
+   decl().bind("right_class"))
+.bind("release_member"))
   .bind("reset_call"),
   this);
 }
@@ -95,37 +98,31 @@ void UniqueptrResetReleaseCheck::check(const 
MatchFinder::MatchResult &Result) {
   const auto *ReleaseMember =
   Result.Nodes.getNodeAs("release_member");
   const auto *Right = Result.Nodes.getNodeAs("right");
-  const auto *Left = Result.Nodes.getNodeAs("left");
   const auto *ResetCall =
   Result.Nodes.getNodeAs("reset_call");
 
-  std::string LeftText = std::string(clang::Lexer::getSourceText(
-  CharSourceRange::getTokenRange(Left->getSourceRange()),
-  *Result.SourceManager, getLangOpts()));
-  std::string RightText = std::string(clang::Lexer::getSourceText(
-  CharSourceRange::getTokenRange(Right->getSourceRange()),
-  *Result.SourceManager, getLangOpts()));
-
-  if (ResetMember->isArrow())
-LeftText = "*" + LeftText;
-  if (ReleaseMember->isArrow())
-RightText = "*" + RightText;
-  bool IsMove = false;
-  // Even if x was rvalue, *x is not rvalue anymore.
-  if (!Right->isRValue() || ReleaseMember->isArrow()) {
-RightText = "std::move(" + RightText + ")";
-IsMove = true;
+  StringRef AssignmentText = " = ";
+  StringRef TrailingText = "";
+  if (ReleaseMember->isArrow()) {
+AssignmentText = " = std::move(*";
+TrailingText = ")";
+  } else if (!Right->isRValue()) {
+AssignmentText = " = std::move(";
+TrailingText = ")";
   }
 
-  std::string NewText = LeftText + " = " + RightText;
-
-  diag(ResetMember->getExprLoc(),
-   "prefer ptr = %select{std::move(ptr2)|ReturnUnique()}0 over "
-   "ptr.reset(%select{ptr2|ReturnUnique()}0.release())")
-  << !IsMove
-  << FixItHint::CreateReplacement(
- CharSourceRange::getTokenRange(ResetCall->getSourceRange()),
- NewText);
+  auto D = diag(ResetMember->getExprLoc(),
+"prefer 'unique_ptr<>' assignment over 'release' and 'reset'");
+  if (ResetMember->isArrow())
+D << FixItHint::CreateInsertion(ResetMember->getBeginLoc(), "*");
+  D << FixItHint::CreateReplacement(
+   CharSourceRange::getCharRange(ResetMember->getOp

  1   2   3   >