r310817 - Fix memory leak in ToolChain::TranslateOpenMPTargetArgs

2017-08-14 Thread Jonas Hahnfeld via cfe-commits
Author: hahnfeld
Date: Mon Aug 14 00:44:05 2017
New Revision: 310817

URL: http://llvm.org/viewvc/llvm-project?rev=310817&view=rev
Log:
Fix memory leak in ToolChain::TranslateOpenMPTargetArgs

rL310433 introduced a code path where DAL is not returned and must be freed.
This change allows to run openmp-offload.c when Clang is built with ASan.

Modified:
cfe/trunk/lib/Driver/ToolChain.cpp
cfe/trunk/test/Driver/openmp-offload.c

Modified: cfe/trunk/lib/Driver/ToolChain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChain.cpp?rev=310817&r1=310816&r2=310817&view=diff
==
--- cfe/trunk/lib/Driver/ToolChain.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChain.cpp Mon Aug 14 00:44:05 2017
@@ -859,7 +859,11 @@ ToolChain::TranslateOpenMPTargetArgs(con
   NewArgAdded = true;
 }
 
-return NewArgAdded ? DAL : nullptr;
+if (NewArgAdded) {
+  return DAL;
+} else {
+  delete DAL;
+}
   }
 
   return nullptr;

Modified: cfe/trunk/test/Driver/openmp-offload.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/openmp-offload.c?rev=310817&r1=310816&r2=310817&view=diff
==
--- cfe/trunk/test/Driver/openmp-offload.c (original)
+++ cfe/trunk/test/Driver/openmp-offload.c Mon Aug 14 00:44:05 2017
@@ -2,9 +2,6 @@
 /// Perform several driver tests for OpenMP offloading
 ///
 
-// Until this test is stabilized on all local configurations.
-// UNSUPPORTED: linux
-
 // REQUIRES: clang-driver
 // REQUIRES: x86-registered-target
 // REQUIRES: powerpc-registered-target


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


[PATCH] D29660: [OpenMP] Add flag for overwriting default PTX version for OpenMP targets

2017-08-14 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

In https://reviews.llvm.org/D29660#839736, @alekseyshl wrote:

> In https://reviews.llvm.org/D29660#839728, @alekseyshl wrote:
>
> > Bad news, the bot is still red: 
> > http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/7114
>
>
> Disabled openmp-offload.c on Linux again: https://reviews.llvm.org/rL310772


I think I've found the memory leak with `cmake -DCMAKE_BUILD_TYPE=Release 
-DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_USE_SANITIZER=Address 
-DLLVM_ENABLE_LIBCXX=ON`.
I committed a fix, let's see if the bot likes `openmp-offload.c` in 
https://reviews.llvm.org/rL310817. There is another leak for 
`openmp-offload-gpu.c` which I will write about in 
https://reviews.llvm.org/D34784.

Side note: We might want to get rid of `2>&1` in all the tests so that 
sanitizer errors get through! That would have sped up the search...


Repository:
  rL LLVM

https://reviews.llvm.org/D29660



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


[PATCH] D34784: [OpenMP] Add flag for specifying the target device architecture for OpenMP device offloading

2017-08-14 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added inline comments.



Comment at: lib/Driver/ToolChain.cpp:851
+  XOpenMPTargetArg->setBaseArg(A);
+  A = XOpenMPTargetArg.release();
+  DAL->append(A);

This is a memory leak that is currently triggered in 
`tests/Driver/openmp-offload-gpu.c` and found by ASan. How to fix this? I'm not 
really familiar with OptTable...


https://reviews.llvm.org/D34784



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


[PATCH] D36397: [clangd] Fixed a data race.

2017-08-14 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer accepted this revision.
bkramer added a comment.
This revision is now accepted and ready to land.

I think this can be committed now. It's still a bit awkward but we can address 
that later.


https://reviews.llvm.org/D36397



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


[clang-tools-extra] r310818 - [clangd] Fixed a data race.

2017-08-14 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Mon Aug 14 01:17:24 2017
New Revision: 310818

URL: http://llvm.org/viewvc/llvm-project?rev=310818&view=rev
Log:
[clangd] Fixed a data race.

Summary:
Calling addDocument after removeDocument could have resulted in an
invalid program state (AST and Preamble for the valid document could
have been incorrectly removed).
This commit also includes an improved CppFile::cancelRebuild
implementation that allows to cancel reparse without waiting for
ongoing rebuild to finish.

Reviewers: krasimir, bkramer, klimek

Reviewed By: bkramer

Subscribers: cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.h
clang-tools-extra/trunk/clangd/ClangdUnit.cpp
clang-tools-extra/trunk/clangd/ClangdUnit.h

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=310818&r1=310817&r2=310818&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Mon Aug 14 01:17:24 2017
@@ -143,61 +143,14 @@ std::future ClangdServer::addDocum
   auto TaggedFS = FSProvider.getTaggedFileSystem(File);
   std::shared_ptr Resources =
   Units.getOrCreateFile(File, ResourceDir, CDB, PCHs, TaggedFS.Value);
-
-  std::future>> DeferredRebuild =
-  Resources->deferRebuild(Contents, TaggedFS.Value);
-  std::promise DonePromise;
-  std::future DoneFuture = DonePromise.get_future();
-
-  Path FileStr = File;
-  VFSTag Tag = TaggedFS.Tag;
-  auto ReparseAndPublishDiags =
-  [this, FileStr, Version,
-   Tag](std::future>>
-DeferredRebuild,
-std::promise DonePromise) -> void {
-FulfillPromiseGuard Guard(DonePromise);
-
-auto CurrentVersion = DraftMgr.getVersion(FileStr);
-if (CurrentVersion != Version)
-  return; // This request is outdated
-
-auto Diags = DeferredRebuild.get();
-if (!Diags)
-  return; // A new reparse was requested before this one completed.
-DiagConsumer.onDiagnosticsReady(FileStr,
-make_tagged(std::move(*Diags), Tag));
-  };
-
-  WorkScheduler.addToFront(std::move(ReparseAndPublishDiags),
-   std::move(DeferredRebuild), std::move(DonePromise));
-  return DoneFuture;
+  return scheduleReparseAndDiags(File, VersionedDraft{Version, Contents.str()},
+ std::move(Resources), std::move(TaggedFS));
 }
 
 std::future ClangdServer::removeDocument(PathRef File) {
-  auto Version = DraftMgr.removeDraft(File);
-  Path FileStr = File;
-
-  std::promise DonePromise;
-  std::future DoneFuture = DonePromise.get_future();
-
-  auto RemoveDocFromCollection = [this, FileStr,
-  Version](std::promise DonePromise) {
-FulfillPromiseGuard Guard(DonePromise);
-
-if (Version != DraftMgr.getVersion(FileStr))
-  return; // This request is outdated, do nothing
-
-std::shared_ptr File = Units.removeIfPresent(FileStr);
-if (!File)
-  return;
-// Cancel all ongoing rebuilds, so that we don't do extra work before
-// deleting this file.
-File->cancelRebuilds();
-  };
-  WorkScheduler.addToFront(std::move(RemoveDocFromCollection),
-   std::move(DonePromise));
-  return DoneFuture;
+  DraftMgr.removeDraft(File);
+  std::shared_ptr Resources = Units.removeIfPresent(File);
+  return scheduleCancelRebuild(std::move(Resources));
 }
 
 std::future ClangdServer::forceReparse(PathRef File) {
@@ -306,3 +259,60 @@ Tagged> ClangdServ
   });
   return make_tagged(std::move(Result), TaggedFS.Tag);
 }
+
+std::future ClangdServer::scheduleReparseAndDiags(
+PathRef File, VersionedDraft Contents, std::shared_ptr Resources,
+Tagged> TaggedFS) {
+
+  assert(Contents.Draft && "Draft must have contents");
+  std::future>> DeferredRebuild =
+  Resources->deferRebuild(*Contents.Draft, TaggedFS.Value);
+  std::promise DonePromise;
+  std::future DoneFuture = DonePromise.get_future();
+
+  DocVersion Version = Contents.Version;
+  Path FileStr = File;
+  VFSTag Tag = TaggedFS.Tag;
+  auto ReparseAndPublishDiags =
+  [this, FileStr, Version,
+   Tag](std::future>>
+DeferredRebuild,
+std::promise DonePromise) -> void {
+FulfillPromiseGuard Guard(DonePromise);
+
+auto CurrentVersion = DraftMgr.getVersion(FileStr);
+if (CurrentVersion != Version)
+  return; // This request is outdated
+
+auto Diags = DeferredRebuild.get();
+if (!Diags)
+  return; // A new reparse was requested before this one completed.
+DiagConsumer.onDiagnosticsReady(FileStr,
+make_tagged(std::move(*Diags), Tag));
+  };
+
+  WorkScheduler.addToFront(std::move(ReparseAndPublis

[PATCH] D36397: [clangd] Fixed a data race.

2017-08-14 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL310818: [clangd] Fixed a data race. (authored by ibiryukov).

Repository:
  rL LLVM

https://reviews.llvm.org/D36397

Files:
  clang-tools-extra/trunk/clangd/ClangdServer.cpp
  clang-tools-extra/trunk/clangd/ClangdServer.h
  clang-tools-extra/trunk/clangd/ClangdUnit.cpp
  clang-tools-extra/trunk/clangd/ClangdUnit.h

Index: clang-tools-extra/trunk/clangd/ClangdUnit.h
===
--- clang-tools-extra/trunk/clangd/ClangdUnit.h
+++ clang-tools-extra/trunk/clangd/ClangdUnit.h
@@ -151,9 +151,17 @@
   CppFile(CppFile const &) = delete;
   CppFile(CppFile &&) = delete;
 
-  /// Cancels all scheduled rebuilds and sets AST and Preamble to nulls.
+  /// Cancels a scheduled rebuild, if any, and sets AST and Preamble to nulls.
   /// If a rebuild is in progress, will wait for it to finish.
-  void cancelRebuilds();
+  void cancelRebuild();
+
+  /// Similar to deferRebuild, but sets both Preamble and AST to nulls instead
+  /// of doing an actual parsing. Returned future is a deferred computation that
+  /// will wait for any ongoing rebuilds to finish and actually set the AST and
+  /// Preamble to nulls. It can be run on a different thread.
+  /// This function is useful to cancel ongoing rebuilds, if any, before
+  /// removing CppFile.
+  std::future deferCancelRebuild();
 
   /// Rebuild AST and Preamble synchronously on the calling thread.
   /// Returns a list of diagnostics or a llvm::None, if another rebuild was
Index: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
===
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp
@@ -711,10 +711,12 @@
   ASTFuture = ASTPromise.get_future();
 }
 
-void CppFile::cancelRebuilds() {
+void CppFile::cancelRebuild() { deferCancelRebuild().get(); }
+
+std::future CppFile::deferCancelRebuild() {
   std::unique_lock Lock(Mutex);
   // Cancel an ongoing rebuild, if any, and wait for it to finish.
-  ++this->RebuildCounter;
+  unsigned RequestRebuildCounter = ++this->RebuildCounter;
   // Rebuild asserts that futures aren't ready if rebuild is cancelled.
   // We want to keep this invariant.
   if (futureIsReady(PreambleFuture)) {
@@ -725,12 +727,28 @@
 ASTPromise = std::promise>();
 ASTFuture = ASTPromise.get_future();
   }
-  // Now wait for rebuild to finish.
-  RebuildCond.wait(Lock, [this]() { return !this->RebuildInProgress; });
 
-  // Return empty results for futures.
-  PreamblePromise.set_value(nullptr);
-  ASTPromise.set_value(std::make_shared(llvm::None));
+  Lock.unlock();
+  // Notify about changes to RebuildCounter.
+  RebuildCond.notify_all();
+
+  std::shared_ptr That = shared_from_this();
+  return std::async(std::launch::deferred, [That, RequestRebuildCounter]() {
+std::unique_lock Lock(That->Mutex);
+CppFile *This = &*That;
+This->RebuildCond.wait(Lock, [This, RequestRebuildCounter]() {
+  return !This->RebuildInProgress ||
+ This->RebuildCounter != RequestRebuildCounter;
+});
+
+// This computation got cancelled itself, do nothing.
+if (This->RebuildCounter != RequestRebuildCounter)
+  return;
+
+// Set empty results for Promises.
+That->PreamblePromise.set_value(nullptr);
+That->ASTPromise.set_value(std::make_shared(llvm::None));
+  });
 }
 
 llvm::Optional>
@@ -767,6 +785,8 @@
   this->ASTFuture = this->ASTPromise.get_future();
 }
   } // unlock Mutex.
+  // Notify about changes to RebuildCounter.
+  RebuildCond.notify_all();
 
   // A helper to function to finish the rebuild. May be run on a different
   // thread.
@@ -916,7 +936,10 @@
   if (WasCancelledBeforeConstruction)
 return;
 
-  File.RebuildCond.wait(Lock, [&File]() { return !File.RebuildInProgress; });
+  File.RebuildCond.wait(Lock, [&File, RequestRebuildCounter]() {
+return !File.RebuildInProgress ||
+   File.RebuildCounter != RequestRebuildCounter;
+  });
 
   WasCancelledBeforeConstruction = File.RebuildCounter != RequestRebuildCounter;
   if (WasCancelledBeforeConstruction)
Index: clang-tools-extra/trunk/clangd/ClangdServer.h
===
--- clang-tools-extra/trunk/clangd/ClangdServer.h
+++ clang-tools-extra/trunk/clangd/ClangdServer.h
@@ -233,6 +233,13 @@
   std::string dumpAST(PathRef File);
 
 private:
+  std::future
+  scheduleReparseAndDiags(PathRef File, VersionedDraft Contents,
+  std::shared_ptr Resources,
+  Tagged> TaggedFS);
+
+  std::future scheduleCancelRebuild(std::shared_ptr Resources);
+
   GlobalCompilationDatabase &CDB;
   DiagnosticsConsumer &DiagConsumer;
   FileSystemProvider &FSProvider;
Index: clang-tools-extra/trunk/clangd/ClangdServer.cpp
===
--- clang-tools-extra

[PATCH] D36397: [clangd] Fixed a data race.

2017-08-14 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

Thanks. I'll make sure to address the awkwardness in further commits.


https://reviews.llvm.org/D36397



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


[PATCH] D35370: [clang-tidy] Add a close-on-exec check on inotify_init() in Android module.

2017-08-14 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.

LGTM


https://reviews.llvm.org/D35370



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


[PATCH] D35368: [clang-tidy] Add a close-on-exec check on inotify_init1() in Android module.

2017-08-14 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.

LGTM


https://reviews.llvm.org/D35368



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


[PATCH] D35364: [clang-tidy] Add a close-on-exec check on dup() in Android module.

2017-08-14 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.

LGTM




Comment at: clang-tidy/android/CloexecCheck.h:91
+  /// Helper function to get the spelling of a particular argument.
+  StringRef getSpellingArg(const ast_matchers::MatchFinder::MatchResult 
&Result,
+   int N) const;

yawanng wrote:
> hokein wrote:
> > This method seems only be used in one check. Maybe move it to the 
> > implementation of that specific check? And you can make the  private 
> > members `FuncBindingStr` and `FuncDeclBindingStr` to protected member.
> Actually, this  method will be used in three checks. 
Ah, ok. Sorry for missing it.


https://reviews.llvm.org/D35364



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


[clang-tools-extra] r310819 - [clangd] Check if CompileCommand has changed on forceReparse.

2017-08-14 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Mon Aug 14 01:37:32 2017
New Revision: 310819

URL: http://llvm.org/viewvc/llvm-project?rev=310819&view=rev
Log:
[clangd] Check if CompileCommand has changed on forceReparse.

Reviewers: krasimir, bkramer, klimek

Reviewed By: klimek

Subscribers: cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.h
clang-tools-extra/trunk/clangd/ClangdUnitStore.cpp
clang-tools-extra/trunk/clangd/ClangdUnitStore.h
clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=310819&r1=310818&r2=310819&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Mon Aug 14 01:37:32 2017
@@ -154,9 +154,20 @@ std::future ClangdServer::removeDo
 }
 
 std::future ClangdServer::forceReparse(PathRef File) {
-  // The addDocument schedules the reparse even if the contents of the file
-  // never changed, so we just call it here.
-  return addDocument(File, getDocument(File));
+  auto FileContents = DraftMgr.getDraft(File);
+  assert(FileContents.Draft &&
+ "forceReparse() was called for non-added document");
+
+  auto TaggedFS = FSProvider.getTaggedFileSystem(File);
+  auto Recreated = Units.recreateFileIfCompileCommandChanged(
+  File, ResourceDir, CDB, PCHs, TaggedFS.Value);
+
+  // Note that std::future from this cleanup action is ignored.
+  scheduleCancelRebuild(std::move(Recreated.RemovedFile));
+  // Schedule a reparse.
+  return scheduleReparseAndDiags(File, std::move(FileContents),
+ std::move(Recreated.FileInCollection),
+ std::move(TaggedFS));
 }
 
 Tagged>

Modified: clang-tools-extra/trunk/clangd/ClangdServer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.h?rev=310819&r1=310818&r2=310819&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.h Mon Aug 14 01:37:32 2017
@@ -192,10 +192,13 @@ public:
   std::future addDocument(PathRef File, StringRef Contents);
   /// Remove \p File from list of tracked files, schedule a request to free
   /// resources associated with it.
-  /// \return A future that will become ready the file is removed and all
-  /// associated reosources are freed.
+  /// \return A future that will become ready when the file is removed and all
+  /// associated resources are freed.
   std::future removeDocument(PathRef File);
   /// Force \p File to be reparsed using the latest contents.
+  /// Will also check if CompileCommand, provided by GlobalCompilationDatabase
+  /// for \p File has changed. If it has, will remove currently stored Preamble
+  /// and AST and rebuild them from scratch.
   std::future forceReparse(PathRef File);
 
   /// Run code completion for \p File at \p Pos. If \p OverridenContents is not

Modified: clang-tools-extra/trunk/clangd/ClangdUnitStore.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnitStore.cpp?rev=310819&r1=310818&r2=310819&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdUnitStore.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnitStore.cpp Mon Aug 14 01:37:32 2017
@@ -9,6 +9,7 @@
 
 #include "ClangdUnitStore.h"
 #include "llvm/Support/Path.h"
+#include 
 
 using namespace clang::clangd;
 using namespace clang;
@@ -25,6 +26,32 @@ std::shared_ptr CppFileCollecti
   return Result;
 }
 
+CppFileCollection::RecreateResult
+CppFileCollection::recreateFileIfCompileCommandChanged(
+PathRef File, PathRef ResourceDir, GlobalCompilationDatabase &CDB,
+std::shared_ptr PCHs,
+IntrusiveRefCntPtr VFS) {
+  auto NewCommand = getCompileCommand(CDB, File, ResourceDir);
+
+  std::lock_guard Lock(Mutex);
+
+  RecreateResult Result;
+
+  auto It = OpenedFiles.find(File);
+  if (It == OpenedFiles.end()) {
+It = OpenedFiles
+ .try_emplace(File, CppFile::Create(File, std::move(NewCommand),
+std::move(PCHs)))
+ .first;
+  } else if (!compileCommandsAreEqual(It->second->getCompileCommand(),
+  NewCommand)) {
+Result.RemovedFile = std::move(It->second);
+It->second = CppFile::Create(File, std::move(NewCommand), std::move(PCHs));
+  }
+  Result.FileInCollection = It->second;
+  return Result;
+}
+
 tooling::CompileCommand
 CppFileCollection::getCompileCommand(GlobalCompilationDatabase &CDB,
  PathRe

[PATCH] D36398: [clangd] Check if CompileCommand has changed on forceReparse.

2017-08-14 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL310819: [clangd] Check if CompileCommand has changed on 
forceReparse. (authored by ibiryukov).

Repository:
  rL LLVM

https://reviews.llvm.org/D36398

Files:
  clang-tools-extra/trunk/clangd/ClangdServer.cpp
  clang-tools-extra/trunk/clangd/ClangdServer.h
  clang-tools-extra/trunk/clangd/ClangdUnitStore.cpp
  clang-tools-extra/trunk/clangd/ClangdUnitStore.h
  clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp

Index: clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp
===
--- clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp
+++ clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp
@@ -501,6 +501,53 @@
 }
 #endif // LLVM_ON_UNIX
 
+TEST_F(ClangdVFSTest, ForceReparseCompileCommand) {
+  MockFSProvider FS;
+  ErrorCheckingDiagConsumer DiagConsumer;
+  MockCompilationDatabase CDB(/*AddFreestandingFlag=*/true);
+  ClangdServer Server(CDB, DiagConsumer, FS,
+  /*RunSynchronously=*/true);
+  // No need to sync reparses, because RunSynchronously is set
+  // to true.
+
+  auto FooCpp = getVirtualTestFilePath("foo.cpp");
+  const auto SourceContents1 = R"cpp(
+template 
+struct foo { T x; };
+)cpp";
+  const auto SourceContents2 = R"cpp(
+template 
+struct bar { T x; };
+)cpp";
+
+  FS.Files[FooCpp] = "";
+  FS.ExpectedFile = FooCpp;
+
+  // First parse files in C mode and check they produce errors.
+  CDB.ExtraClangFlags = {"-xc"};
+  Server.addDocument(FooCpp, SourceContents1);
+  EXPECT_TRUE(DiagConsumer.hadErrorInLastDiags());
+  Server.addDocument(FooCpp, SourceContents2);
+  EXPECT_TRUE(DiagConsumer.hadErrorInLastDiags());
+
+  // Now switch to C++ mode.
+  CDB.ExtraClangFlags = {"-xc++"};
+  // Currently, addDocument never checks if CompileCommand has changed, so we
+  // expect to see the errors.
+  Server.addDocument(FooCpp, SourceContents1);
+  EXPECT_TRUE(DiagConsumer.hadErrorInLastDiags());
+  Server.addDocument(FooCpp, SourceContents2);
+  EXPECT_TRUE(DiagConsumer.hadErrorInLastDiags());
+  // But forceReparse should reparse the file with proper flags.
+  Server.forceReparse(FooCpp);
+  EXPECT_FALSE(DiagConsumer.hadErrorInLastDiags());
+  // Subsequent addDocument calls should finish without errors too.
+  Server.addDocument(FooCpp, SourceContents1);
+  EXPECT_FALSE(DiagConsumer.hadErrorInLastDiags());
+  Server.addDocument(FooCpp, SourceContents2);
+  EXPECT_FALSE(DiagConsumer.hadErrorInLastDiags());
+}
+
 class ClangdCompletionTest : public ClangdVFSTest {
 protected:
   bool ContainsItem(std::vector const &Items, StringRef Name) {
Index: clang-tools-extra/trunk/clangd/ClangdServer.h
===
--- clang-tools-extra/trunk/clangd/ClangdServer.h
+++ clang-tools-extra/trunk/clangd/ClangdServer.h
@@ -192,10 +192,13 @@
   std::future addDocument(PathRef File, StringRef Contents);
   /// Remove \p File from list of tracked files, schedule a request to free
   /// resources associated with it.
-  /// \return A future that will become ready the file is removed and all
-  /// associated reosources are freed.
+  /// \return A future that will become ready when the file is removed and all
+  /// associated resources are freed.
   std::future removeDocument(PathRef File);
   /// Force \p File to be reparsed using the latest contents.
+  /// Will also check if CompileCommand, provided by GlobalCompilationDatabase
+  /// for \p File has changed. If it has, will remove currently stored Preamble
+  /// and AST and rebuild them from scratch.
   std::future forceReparse(PathRef File);
 
   /// Run code completion for \p File at \p Pos. If \p OverridenContents is not
Index: clang-tools-extra/trunk/clangd/ClangdServer.cpp
===
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp
@@ -154,9 +154,20 @@
 }
 
 std::future ClangdServer::forceReparse(PathRef File) {
-  // The addDocument schedules the reparse even if the contents of the file
-  // never changed, so we just call it here.
-  return addDocument(File, getDocument(File));
+  auto FileContents = DraftMgr.getDraft(File);
+  assert(FileContents.Draft &&
+ "forceReparse() was called for non-added document");
+
+  auto TaggedFS = FSProvider.getTaggedFileSystem(File);
+  auto Recreated = Units.recreateFileIfCompileCommandChanged(
+  File, ResourceDir, CDB, PCHs, TaggedFS.Value);
+
+  // Note that std::future from this cleanup action is ignored.
+  scheduleCancelRebuild(std::move(Recreated.RemovedFile));
+  // Schedule a reparse.
+  return scheduleReparseAndDiags(File, std::move(FileContents),
+ std::move(Recreated.FileInCollection),
+ std::move(TaggedFS));
 }
 
 Tagged>
Index: clang-tools-extra/trunk/clangd/ClangdUnitStore.h
==

r310820 - [analyzer] Rename functions responsible for CFG-based suppress-on-sink.

2017-08-14 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Mon Aug 14 01:38:47 2017
New Revision: 310820

URL: http://llvm.org/viewvc/llvm-project?rev=310820&view=rev
Log:
[analyzer] Rename functions responsible for CFG-based suppress-on-sink.

Update comments. No functional change intended.

Addresses Devin's post-commit review comments in https://reviews.llvm.org/D35673
and https://reviews.llvm.org/D35674.

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp?rev=310820&r1=310819&r2=310820&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp Mon Aug 14 01:38:47 2017
@@ -3310,7 +3310,13 @@ static const CFGBlock *findBlockForNode(
   return nullptr;
 }
 
-static bool isNoReturnBlock(const CFGBlock *Blk) {
+// Returns true if by simply looking at the block, we can be sure that it
+// results in a sink during analysis. This is useful to know when the analysis
+// was interrupted, and we try to figure out if it would sink eventually.
+// There may be many more reasons why a sink would appear during analysis
+// (eg. checkers may generate sinks arbitrarily), but here we only consider
+// sinks that would be obvious by looking at the CFG.
+static bool isImmediateSinkBlock(const CFGBlock *Blk) {
   if (Blk->hasNoReturnElement())
 return true;
 
@@ -3331,13 +3337,17 @@ static bool isNoReturnBlock(const CFGBlo
   return false;
 }
 
-static bool isDominatedByNoReturnBlocks(const ExplodedNode *N) {
+// Returns true if by looking at the CFG surrounding the node's program
+// point, we can be sure that any analysis starting from this point would
+// eventually end with a sink. We scan the child CFG blocks in a depth-first
+// manner and see if all paths eventually end up in an immediate sink block.
+static bool isInevitablySinking(const ExplodedNode *N) {
   const CFG &Cfg = N->getCFG();
 
   const CFGBlock *StartBlk = findBlockForNode(N);
   if (!StartBlk)
 return false;
-  if (isNoReturnBlock(StartBlk))
+  if (isImmediateSinkBlock(StartBlk))
 return true;
 
   llvm::SmallVector DFSWorkList;
@@ -3352,12 +3362,14 @@ static bool isDominatedByNoReturnBlocks(
 for (const auto &Succ : Blk->succs()) {
   if (const CFGBlock *SuccBlk = Succ.getReachableBlock()) {
 if (SuccBlk == &Cfg.getExit()) {
-  // We seem to be leaving the current CFG.
-  // We're no longer sure what happens next.
+  // If at least one path reaches the CFG exit, it means that control 
is
+  // returned to the caller. For now, say that we are not sure what
+  // happens next. If necessary, this can be improved to analyze
+  // the parent StackFrameContext's call site in a similar manner.
   return false;
 }
 
-if (!isNoReturnBlock(SuccBlk) && !Visited.count(SuccBlk)) {
+if (!isImmediateSinkBlock(SuccBlk) && !Visited.count(SuccBlk)) {
   // If the block has reachable child blocks that aren't no-return,
   // add them to the worklist.
   DFSWorkList.push_back(SuccBlk);
@@ -3420,13 +3432,9 @@ FindReportInEquivalenceClass(BugReportEq
 
 // See if we are in a no-return CFG block. If so, treat this similarly
 // to being post-dominated by a sink. This works better when the analysis
-// is incomplete and we have never reached a no-return function
-// we're post-dominated by.
-// This is not quite enough to handle the incomplete analysis case.
-// We may be post-dominated in subsequent blocks, or even
-// inter-procedurally. However, it is not clear if more complicated
-// cases are generally worth suppressing.
-if (isDominatedByNoReturnBlocks(errorNode))
+// is incomplete and we have never reached the no-return function call(s)
+// that we'd inevitably bump into on this path.
+if (isInevitablySinking(errorNode))
   continue;
 
 // At this point we know that 'N' is not a sink and it has at least one


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


[PATCH] D36664: [analyzer] Make StmtDataCollector customizable

2017-08-14 Thread Johannes Altmanninger via Phabricator via cfe-commits
johannes created this revision.
Herald added subscribers: xazax.hun, mgorny.
Herald added 1 blocking reviewer(s): teemperor.

This moves the data collection macro calls for Stmt nodes
to lib/AST/StmtDataCollectors.inc

Users can subclass ConstStmtVisitor and include StmtDataCollectors.inc
to define visitor methods for each Stmt subclass. This makes it also
possible to customize the visit methods as exemplified in
CloneDetection.cpp.

Move helper methods for data collection to a new module,

  AST/DataCollection.

Add data collection for DeclRefExpr, MemberExpr and some literals


https://reviews.llvm.org/D36664

Files:
  include/clang/AST/DataCollection.h
  include/clang/Analysis/CloneDetection.h
  lib/AST/CMakeLists.txt
  lib/AST/DataCollection.cpp
  lib/AST/StmtDataCollectors.inc
  lib/Analysis/CloneDetection.cpp

Index: lib/Analysis/CloneDetection.cpp
===
--- lib/Analysis/CloneDetection.cpp
+++ lib/Analysis/CloneDetection.cpp
@@ -13,16 +13,12 @@
 
 #include "clang/Analysis/CloneDetection.h"
 
-#include "clang/AST/ASTContext.h"
-#include "clang/AST/RecursiveASTVisitor.h"
-#include "clang/AST/Stmt.h"
-#include "clang/Lex/Lexer.h"
+#include "clang/AST/DataCollection.h"
+#include "clang/AST/DeclTemplate.h"
 #include "llvm/Support/MD5.h"
-#include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/Path.h"
 
 using namespace clang;
-using namespace clang::clone_detection;
 
 StmtSequence::StmtSequence(const CompoundStmt *Stmt, const Decl *D,
unsigned StartIndex, unsigned EndIndex)
@@ -91,34 +87,6 @@
   return SourceRange(getStartLoc(), getEndLoc());
 }
 
-/// Prints the macro name that contains the given SourceLocation into the given
-/// raw_string_ostream.
-static void printMacroName(llvm::raw_string_ostream &MacroStack,
-   ASTContext &Context, SourceLocation Loc) {
-  MacroStack << Lexer::getImmediateMacroName(Loc, Context.getSourceManager(),
- Context.getLangOpts());
-
-  // Add an empty space at the end as a padding to prevent
-  // that macro names concatenate to the names of other macros.
-  MacroStack << " ";
-}
-
-std::string clone_detection::getMacroStack(SourceLocation Loc,
-   ASTContext &Context) {
-  std::string MacroStack;
-  llvm::raw_string_ostream MacroStackStream(MacroStack);
-  SourceManager &SM = Context.getSourceManager();
-
-  // Iterate over all macros that expanded into the given SourceLocation.
-  while (Loc.isMacroID()) {
-// Add the macro name to the stream.
-printMacroName(MacroStackStream, Context, Loc);
-Loc = SM.getImmediateMacroCallerLoc(Loc);
-  }
-  MacroStackStream.flush();
-  return MacroStack;
-}
-
 void CloneDetector::analyzeCodeBody(const Decl *D) {
   assert(D);
   assert(D->hasBody());
@@ -201,6 +169,59 @@
   return false;
 }
 
+/// Collects the data of a single Stmt.
+///
+/// This class defines what a code clone is: If it collects for two statements
+/// the same data, then those two statements are considered to be clones of each
+/// other.
+///
+/// All collected data is forwarded to the given data consumer of the type T.
+/// The data consumer class needs to provide a member method with the signature:
+///   update(StringRef Str)
+template 
+class CloneTypeIIStmtDataCollector
+: public ConstStmtVisitor> {
+  ASTContext &Context;
+  /// The data sink to which all data is forwarded.
+  T &DataConsumer;
+
+  template  void addData(Ty Data) {
+addDataToConsumer(DataConsumer, Data);
+  }
+
+public:
+  CloneTypeIIStmtDataCollector(const Stmt *S, ASTContext &Context,
+   T &DataConsumer)
+  : Context(Context), DataConsumer(DataConsumer) {
+this->Visit(S);
+  }
+
+// Define a visit method for each class to collect data and subsequently visit
+// all parent classes. This uses a template so that custom visit methods by us
+// take precedence.
+#define DEF_ADD_DATA(CLASS, CODE)  \
+  template  Dummy Visit##CLASS(const CLASS *S) {   \
+CODE;  \
+ConstStmtVisitor>::Visit##CLASS(S);\
+  }
+
+#include "../AST/StmtDataCollectors.inc"
+
+// Override the definition for some visitors.
+#define SKIP(CLASS)\
+  void Visit##CLASS(const CLASS *S) {  \
+ConstStmtVisitor>::Visit##CLASS(S);\
+  }
+  SKIP(DeclRefExpr)
+  SKIP(MemberExpr)
+  SKIP(IntegerLiteral)
+  SKIP(FloatingLiteral)
+  SKIP(StringLiteral)
+  SKIP(CXXBoolLiteralExpr)
+  SKIP(CharacterLiteral)
+#undef SKIP
+};
+
 static size_t createHash(llvm::MD5 &Hash) {
   size_t HashCode;
 
@@ -222,7 +243,7 @@
   llvm::MD5 Hash;
   ASTContext &Context = D->getASTContext();
 
-  StmtDataCollector(S, Context, Hash);
+  CloneTypeIIStmtDataC

[clang-tools-extra] r310821 - [clangd] Use multiple working threads in clangd.

2017-08-14 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Mon Aug 14 01:45:47 2017
New Revision: 310821

URL: http://llvm.org/viewvc/llvm-project?rev=310821&view=rev
Log:
[clangd] Use multiple working threads in clangd.

Reviewers: bkramer, krasimir, klimek

Reviewed By: klimek

Subscribers: arphaman, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/ClangdLSPServer.h
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.h
clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=310821&r1=310820&r2=310821&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Mon Aug 14 01:45:47 2017
@@ -220,10 +220,10 @@ void ClangdLSPServer::LSPProtocolCallbac
   R"(,"result":[)" + Locations + R"(]})");
 }
 
-ClangdLSPServer::ClangdLSPServer(JSONOutput &Out, bool RunSynchronously,
+ClangdLSPServer::ClangdLSPServer(JSONOutput &Out, unsigned AsyncThreadsCount,
  llvm::Optional ResourceDir)
 : Out(Out), DiagConsumer(*this),
-  Server(CDB, DiagConsumer, FSProvider, RunSynchronously, ResourceDir) {}
+  Server(CDB, DiagConsumer, FSProvider, AsyncThreadsCount, ResourceDir) {}
 
 void ClangdLSPServer::run(std::istream &In) {
   assert(!IsDone && "Run was called before");

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.h?rev=310821&r1=310820&r2=310821&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.h Mon Aug 14 01:45:47 2017
@@ -26,7 +26,7 @@ class JSONOutput;
 /// dispatch and ClangdServer together.
 class ClangdLSPServer {
 public:
-  ClangdLSPServer(JSONOutput &Out, bool RunSynchronously,
+  ClangdLSPServer(JSONOutput &Out, unsigned AsyncThreadsCount,
   llvm::Optional ResourceDir);
 
   /// Run LSP server loop, receiving input for it from \p In. \p In must be

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=310821&r1=310820&r2=310821&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Mon Aug 14 01:45:47 2017
@@ -78,40 +78,52 @@ RealFileSystemProvider::getTaggedFileSys
   return make_tagged(vfs::getRealFileSystem(), VFSTag());
 }
 
-ClangdScheduler::ClangdScheduler(bool RunSynchronously)
-: RunSynchronously(RunSynchronously) {
+unsigned clangd::getDefaultAsyncThreadsCount() {
+  unsigned HardwareConcurrency = std::thread::hardware_concurrency();
+  // C++ standard says that hardware_concurrency()
+  // may return 0, fallback to 1 worker thread in
+  // that case.
+  if (HardwareConcurrency == 0)
+return 1;
+  return HardwareConcurrency;
+}
+
+ClangdScheduler::ClangdScheduler(unsigned AsyncThreadsCount)
+: RunSynchronously(AsyncThreadsCount == 0) {
   if (RunSynchronously) {
 // Don't start the worker thread if we're running synchronously
 return;
   }
 
-  // Initialize Worker in ctor body, rather than init list to avoid potentially
-  // using not-yet-initialized members
-  Worker = std::thread([this]() {
-while (true) {
-  std::future Request;
-
-  // Pick request from the queue
-  {
-std::unique_lock Lock(Mutex);
-// Wait for more requests.
-RequestCV.wait(Lock, [this] { return !RequestQueue.empty() || Done; });
-if (Done)
-  return;
-
-assert(!RequestQueue.empty() && "RequestQueue was empty");
-
-// We process requests starting from the front of the queue. Users of
-// ClangdScheduler have a way to prioritise their requests by putting
-// them to the either side of the queue (using either addToEnd or
-// addToFront).
-Request = std::move(RequestQueue.front());
-RequestQueue.pop_front();
-  } // unlock Mutex
-
-  Request.get();
-}
-  });
+  Workers.reserve(AsyncThreadsCount);
+  for (unsigned I = 0; I < AsyncThreadsCount; ++I) {
+Workers.push_back(std::thread([this]() {
+  while (true) {
+std::future Request;
+
+// Pick request from the queue
+{
+  std::unique_lock Lock(Mutex);
+  // Wait for more requests.
+  RequestCV.wait(Lock,
+ [this] { r

[PATCH] D36261: [clangd] Use multiple working threads in clangd.

2017-08-14 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL310821: [clangd] Use multiple working threads in clangd. 
(authored by ibiryukov).

Changed prior to commit:
  https://reviews.llvm.org/D36261?vs=110381&id=110922#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D36261

Files:
  clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
  clang-tools-extra/trunk/clangd/ClangdLSPServer.h
  clang-tools-extra/trunk/clangd/ClangdServer.cpp
  clang-tools-extra/trunk/clangd/ClangdServer.h
  clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
  clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp

Index: clang-tools-extra/trunk/clangd/ClangdLSPServer.h
===
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.h
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.h
@@ -26,7 +26,7 @@
 /// dispatch and ClangdServer together.
 class ClangdLSPServer {
 public:
-  ClangdLSPServer(JSONOutput &Out, bool RunSynchronously,
+  ClangdLSPServer(JSONOutput &Out, unsigned AsyncThreadsCount,
   llvm::Optional ResourceDir);
 
   /// Run LSP server loop, receiving input for it from \p In. \p In must be
Index: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
===
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
@@ -220,10 +220,10 @@
   R"(,"result":[)" + Locations + R"(]})");
 }
 
-ClangdLSPServer::ClangdLSPServer(JSONOutput &Out, bool RunSynchronously,
+ClangdLSPServer::ClangdLSPServer(JSONOutput &Out, unsigned AsyncThreadsCount,
  llvm::Optional ResourceDir)
 : Out(Out), DiagConsumer(*this),
-  Server(CDB, DiagConsumer, FSProvider, RunSynchronously, ResourceDir) {}
+  Server(CDB, DiagConsumer, FSProvider, AsyncThreadsCount, ResourceDir) {}
 
 void ClangdLSPServer::run(std::istream &In) {
   assert(!IsDone && "Run was called before");
Index: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
@@ -16,14 +16,20 @@
 #include 
 #include 
 #include 
+#include 
 
 using namespace clang;
 using namespace clang::clangd;
 
-static llvm::cl::opt
-RunSynchronously("run-synchronously",
- llvm::cl::desc("Parse on main thread"),
- llvm::cl::init(false), llvm::cl::Hidden);
+static llvm::cl::opt
+WorkerThreadsCount("j",
+   llvm::cl::desc("Number of async workers used by clangd"),
+   llvm::cl::init(getDefaultAsyncThreadsCount()));
+
+static llvm::cl::opt RunSynchronously(
+"run-synchronously",
+llvm::cl::desc("Parse on main thread. If set, -j is ignored"),
+llvm::cl::init(false), llvm::cl::Hidden);
 
 static llvm::cl::opt
 ResourceDir("resource-dir",
@@ -33,6 +39,17 @@
 int main(int argc, char *argv[]) {
   llvm::cl::ParseCommandLineOptions(argc, argv, "clangd");
 
+  if (!RunSynchronously && WorkerThreadsCount == 0) {
+llvm::errs() << "A number of worker threads cannot be 0. Did you mean to "
+"specify -run-synchronously?";
+return 1;
+  }
+
+  // Ignore -j option if -run-synchonously is used.
+  // FIXME: a warning should be shown here.
+  if (RunSynchronously)
+WorkerThreadsCount = 0;
+
   llvm::raw_ostream &Outs = llvm::outs();
   llvm::raw_ostream &Logs = llvm::errs();
   JSONOutput Out(Outs, Logs);
@@ -43,6 +60,7 @@
   llvm::Optional ResourceDirRef = None;
   if (!ResourceDir.empty())
 ResourceDirRef = ResourceDir;
-  ClangdLSPServer LSPServer(Out, RunSynchronously, ResourceDirRef);
+
+  ClangdLSPServer LSPServer(Out, WorkerThreadsCount, ResourceDirRef);
   LSPServer.run(std::cin);
 }
Index: clang-tools-extra/trunk/clangd/ClangdServer.h
===
--- clang-tools-extra/trunk/clangd/ClangdServer.h
+++ clang-tools-extra/trunk/clangd/ClangdServer.h
@@ -101,11 +101,20 @@
 
 class ClangdServer;
 
-/// Handles running WorkerRequests of ClangdServer on a separate threads.
-/// Currently runs only one worker thread.
+/// Returns a number of a default async threads to use for ClangdScheduler.
+/// Returned value is always >= 1 (i.e. will not cause requests to be processed
+/// synchronously).
+unsigned getDefaultAsyncThreadsCount();
+
+/// Handles running WorkerRequests of ClangdServer on a number of worker
+/// threads.
 class ClangdScheduler {
 public:
-  ClangdScheduler(bool RunSynchronously);
+  /// If \p AsyncThreadsCount is 0, requests added using addToFront and addToEnd
+  /// will be processed synchronously on the calling thread.
+  // Otherwise, \p AsyncThreadsCount threads will be created to schedule the
+  // requests.
+  ClangdScheduler(unsigned AsyncThreadsCount);
   ~ClangdScheduler

[PATCH] D36666: [ObjC] Use consistent comment style in inline asm

2017-08-14 Thread Oliver Stannard via Phabricator via cfe-commits
olista01 created this revision.
Herald added a subscriber: javed.absar.

The comment markers accepted by the assembler vary between different targets, 
but '//' is always accepted, so we should use that for consistency.


Repository:
  rL LLVM

https://reviews.llvm.org/D3

Files:
  lib/CodeGen/TargetInfo.cpp
  test/CodeGenObjC/arc-arm.m


Index: test/CodeGenObjC/arc-arm.m
===
--- test/CodeGenObjC/arc-arm.m
+++ test/CodeGenObjC/arc-arm.m
@@ -13,7 +13,7 @@
 void test1(void) {
   extern id test1_helper(void);
   // CHECK:  [[T0:%.*]] = call [[CC]]i8* @test1_helper()
-  // CHECK-NEXT: call void asm sideeffect "mov
+  // CHECK-NEXT: call void asm sideeffect "mov\09{{fp, fp|r7, r7}}\09\09// 
marker for objc_retainAutoreleaseReturnValue"
   // CHECK-NEXT: [[T1:%.*]] = call [[CC]]i8* 
@objc_retainAutoreleasedReturnValue(i8* [[T0]])
   // CHECK-NEXT: store i8* [[T1]],
   // CHECK-NEXT: call [[CC]]void @objc_storeStrong(
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -1085,7 +1085,7 @@
 
   StringRef getARCRetainAutoreleasedReturnValueMarker() const override {
 return "movl\t%ebp, %ebp"
-   "\t\t## marker for objc_retainAutoreleaseReturnValue";
+   "\t\t// marker for objc_retainAutoreleaseReturnValue";
   }
 };
 
@@ -4880,7 +4880,7 @@
   : TargetCodeGenInfo(new AArch64ABIInfo(CGT, Kind)) {}
 
   StringRef getARCRetainAutoreleasedReturnValueMarker() const override {
-return "mov\tfp, fp\t\t# marker for objc_retainAutoreleaseReturnValue";
+return "mov\tfp, fp\t\t// marker for objc_retainAutoreleaseReturnValue";
   }
 
   int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const override {
@@ -5486,7 +5486,7 @@
   }
 
   StringRef getARCRetainAutoreleasedReturnValueMarker() const override {
-return "mov\tr7, r7\t\t@ marker for objc_retainAutoreleaseReturnValue";
+return "mov\tr7, r7\t\t// marker for objc_retainAutoreleaseReturnValue";
   }
 
   bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,


Index: test/CodeGenObjC/arc-arm.m
===
--- test/CodeGenObjC/arc-arm.m
+++ test/CodeGenObjC/arc-arm.m
@@ -13,7 +13,7 @@
 void test1(void) {
   extern id test1_helper(void);
   // CHECK:  [[T0:%.*]] = call [[CC]]i8* @test1_helper()
-  // CHECK-NEXT: call void asm sideeffect "mov
+  // CHECK-NEXT: call void asm sideeffect "mov\09{{fp, fp|r7, r7}}\09\09// marker for objc_retainAutoreleaseReturnValue"
   // CHECK-NEXT: [[T1:%.*]] = call [[CC]]i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]])
   // CHECK-NEXT: store i8* [[T1]],
   // CHECK-NEXT: call [[CC]]void @objc_storeStrong(
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -1085,7 +1085,7 @@
 
   StringRef getARCRetainAutoreleasedReturnValueMarker() const override {
 return "movl\t%ebp, %ebp"
-   "\t\t## marker for objc_retainAutoreleaseReturnValue";
+   "\t\t// marker for objc_retainAutoreleaseReturnValue";
   }
 };
 
@@ -4880,7 +4880,7 @@
   : TargetCodeGenInfo(new AArch64ABIInfo(CGT, Kind)) {}
 
   StringRef getARCRetainAutoreleasedReturnValueMarker() const override {
-return "mov\tfp, fp\t\t# marker for objc_retainAutoreleaseReturnValue";
+return "mov\tfp, fp\t\t// marker for objc_retainAutoreleaseReturnValue";
   }
 
   int getDwarfEHStackPointer(CodeGen::CodeGenModule &M) const override {
@@ -5486,7 +5486,7 @@
   }
 
   StringRef getARCRetainAutoreleasedReturnValueMarker() const override {
-return "mov\tr7, r7\t\t@ marker for objc_retainAutoreleaseReturnValue";
+return "mov\tr7, r7\t\t// marker for objc_retainAutoreleaseReturnValue";
   }
 
   bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35355: Fix templated type alias completion when using global completion cache

2017-08-14 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

Can someone help me to commit it to the proper branch?
(I don't have permissions)


https://reviews.llvm.org/D35355



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


Re: r310401 - PR19668, PR23034: Fix handling of move constructors and deleted copy

2017-08-14 Thread Diana Picus via cfe-commits
Hi,

Strangely enough, it turns out that if I run
Asan-armhf-with-calls-Noinst-Test on the command line it fails,
although it doesn't fail when run with lit. I've attached the stack
trace from gdb. It looks like some trouble passing down va_arg
parameters, but I haven't looked into too much details. The segfault
happens when we try to do a   ldrb   r3, [r0, r1], with r1 set to 0 by
the current function and r0 passed down from the caller. I'm not sure
if this is the exact same problem as the other tests, but feel free to
have a look at that code.

Meanwhile, I've removed some clutter from Asan-armhf-with-calls-Test
(which is the original failure that we were seeing) and left only one
failing test that seemed small enough. I'll try to look at the
disassembly before/after the patch and maybe even run valgrind on it
(running it on the original binary naturally takes forever).

Let me know if there's anything else I could try. I can also send you
disassembly or even LLVM IR for the Asan-armhf-with-calls-Noinst-Test
if you think it helps.

Cheers,
Diana

On 11 August 2017 at 15:34, Diana Picus  wrote:
> Well, these are ASAN tests, I'm not sure how that would interact with 
> Valgrind.
> Anyway, I'll try to reproduce the environment, I'm guessing it would
> be best to catch this in gdb so I can actually see what's going on.
>
> On 11 August 2017 at 15:21, Vassil Vassilev  wrote:
>> That's really strange. It looks like some random behavior. Did you run some 
>> memory checker like valgrind?
>>
>> Do the environment provided by the test runner and yours match?
>>
>> Sent from my phone. Please excuse my brevity.
>>
>>> On 11 Aug 2017, at 15:58, Diana Picus  wrote:
>>>
>>> Hi again,
>>>
>>> I finally got the debug build, but unfortunately the stack traces that
>>> the tests print look the same. My suspicion is that this is because
>>> the addresses printed by the tests are funny (i.e. odd numbers instead
>>> of divisible by 4). I tried to follow those addresses in an objdump of
>>> the executable, but I didn't have much success since most of them
>>> weren't really pointing to call instructions.
>>>
>>> When I try to run the tests manually in the shell or in gdb, they pass.
>>>
>>> I'm not sure what else to try. Thoughts?
>>>
>>> Thanks,
>>> Diana
>>>
 On 11 August 2017 at 11:14, Diana Picus  wrote:
 Hi guys,

 I'm SO sorry about the delays. I've been having all sorts of trouble
 getting that debug build on the board (from ld running out of memory
 to the board just crashing on me, in which case I need to ask someone
 else to reboot it because I can't power cycle it remotely). I can
 assure you this is one of my top priorities, I'll get those stack
 traces as soon as I can.

 Thanks for your patience and sorry again,
 Diana

> On 10 August 2017 at 22:55, Richard Smith  wrote:
> Any news on this? We want this change in Clang 5, so the sooner we can
> understand and fix this regression the better...
>
> On 10 August 2017 at 01:28, Diana Picus via cfe-commits
>  wrote:
>>
>> Hi Vassil,
>>
>> My build is in progress, but since it's a full build it's probably
>> going to take another couple of hours to complete. I'll let you know
>> when it's done.
>>
>> Thanks,
>> Diana
>>
>> On 10 August 2017 at 10:09, Vassil Vassilev 
>> wrote:
>>> It looks like I can not reproduce it on osx (non-arm)... :(
 On 09/08/17 22:54, Diana Picus wrote:

 Reverting this also fixed the selfhost bots:


 http://lab.llvm.org:8011/builders/clang-cmake-thumbv7-a15-full-sh/builds/2142


 http://lab.llvm.org:8011/builders/clang-cmake-armv7-a15-selfhost/builds/2309


 http://lab.llvm.org:8011/builders/clang-cmake-armv7-a15-selfhost-neon/builds/1819

 I'm afraid the logs for those look even less helpful.

> On 9 August 2017 at 16:17, Diana Picus  wrote:
>
> Hi,
>
> See attached. FWIW, when I ran this on a very similar machine, I got
> 194 failures, all of which went away after reverting. So there might
> be something fishy going on.
>
> Regards,
> Diana
>
> On 9 August 2017 at 15:02, Vassil Vassilev 
> wrote:
>>
>> Hi Diana,
>>
>>   It seems the service is down. Could you send us the details of the
>> failures (incl stack traces if any)
>>
>> Many thanks,
>> Vassil
>>
>>> On 09/08/17 15:27, Diana Picus via cfe-commits wrote:
>>>
>>> Hi Richard,
>>>
>>> I'm sorry but I've reverted this in r310464 because it was breaking
>>> some ASAN tests on this bot:
>>>
>>>
>>> http://lab.llvm.org:8011/builders/clang-cmake-armv7-a15-full/builds/9452
>>>
>>> Please 

r310829 - Set the lexical context for dummy tag decl inside createTagFromNewDecl

2017-08-14 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Mon Aug 14 03:59:44 2017
New Revision: 310829

URL: http://llvm.org/viewvc/llvm-project?rev=310829&view=rev
Log:
Set the lexical context for dummy tag decl inside createTagFromNewDecl

This is a follow-up to r310706. This change has been recommended by
Bruno Cardoso Lopes and Richard Smith.

Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=310829&r1=310828&r2=310829&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Aug 14 03:59:44 2017
@@ -13298,6 +13298,7 @@ Decl *Sema::ActOnTag(Scope *S, unsigned
 AddMsStructLayoutForRecord(RD);
   }
 }
+New->setLexicalDeclContext(CurContext);
 return New;
   };
 
@@ -13723,7 +13724,6 @@ Decl *Sema::ActOnTag(Scope *S, unsigned
   // comparison.
   SkipBody->CheckSameAsPrevious = true;
   SkipBody->New = createTagFromNewDecl();
-  SkipBody->New->setLexicalDeclContext(CurContext);
   SkipBody->Previous = Hidden;
 } else {
   SkipBody->ShouldSkip = true;


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


Re: r310706 - [modules] Set the lexical DC for dummy tag decls that refer to hidden

2017-08-14 Thread Alex L via cfe-commits
Sure, I committed r310829 which moves the lexical decl adjustment.

Hans, can you please merge r310706 with r310829.

Cheers,
Alex

On 12 August 2017 at 01:29, Richard Smith  wrote:

> On 11 August 2017 at 17:20, Bruno Cardoso Lopes via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Hi Alex,
>>
>> On Fri, Aug 11, 2017 at 9:06 AM, Alex Lorenz via cfe-commits
>>  wrote:
>> > Author: arphaman
>> > Date: Fri Aug 11 05:06:52 2017
>> > New Revision: 310706
>> >
>> > URL: http://llvm.org/viewvc/llvm-project?rev=310706&view=rev
>> > Log:
>> > [modules] Set the lexical DC for dummy tag decls that refer to hidden
>> > declarations that are made visible after the dummy is parsed and ODR
>> verified
>> >
>> > Prior to this commit the
>> > "(getContainingDC(DC) == CurContext && "The next DeclContext should be
>> lexically contained in the current one."),"
>> > assertion failure was triggered during semantic analysis of the dummy
>> > tag declaration that was declared in another tag declaration because its
>> > lexical context did not point to the outer tag decl.
>> >
>> > rdar://32292196
>> >
>> > Added:
>> > cfe/trunk/test/Modules/Inputs/innerstructredef.h
>> > cfe/trunk/test/Modules/inner-struct-redefines-invisible.m
>> > Modified:
>> > cfe/trunk/lib/Sema/SemaDecl.cpp
>> > cfe/trunk/test/Modules/Inputs/module.map
>> >
>> > Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
>> > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaD
>> ecl.cpp?rev=310706&r1=310705&r2=310706&view=diff
>> > 
>> ==
>> > --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
>> > +++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Aug 11 05:06:52 2017
>> > @@ -13722,6 +13722,7 @@ Decl *Sema::ActOnTag(Scope *S, unsigned
>> >// comparison.
>> >SkipBody->CheckSameAsPrevious = true;
>> >SkipBody->New = createTagFromNewDecl();
>> > +  SkipBody->New->setLexicalDeclContext(CurContext);
>>
>> I think it would be cleaner to do this inside "createTagFromNewDecl" than
>> here.
>
>
> I agree. Either before or after that change, this seems sufficiently
> isolated and low-risk that it makes sense to take it for Clang 5.
>
>
>> >SkipBody->Previous = Hidden;
>> >  } else {
>> >SkipBody->ShouldSkip = true;
>> >
>> > Added: cfe/trunk/test/Modules/Inputs/innerstructredef.h
>> > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/
>> Inputs/innerstructredef.h?rev=310706&view=auto
>> > 
>> ==
>> > --- cfe/trunk/test/Modules/Inputs/innerstructredef.h (added)
>> > +++ cfe/trunk/test/Modules/Inputs/innerstructredef.h Fri Aug 11
>> 05:06:52 2017
>> > @@ -0,0 +1,6 @@
>> > +struct Outer {
>> > +// This definition is actually hidden since only submodule 'one' is
>> imported.
>> > +struct Inner {
>> > +  int x;
>> > +} field;
>> > +};
>> >
>> > Modified: cfe/trunk/test/Modules/Inputs/module.map
>> > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/
>> Inputs/module.map?rev=310706&r1=310705&r2=310706&view=diff
>> > 
>> ==
>> > --- cfe/trunk/test/Modules/Inputs/module.map (original)
>> > +++ cfe/trunk/test/Modules/Inputs/module.map Fri Aug 11 05:06:52 2017
>> > @@ -451,3 +451,12 @@ module DebugNestedB {
>> >  module objcAtKeywordMissingEnd {
>> >header "objcAtKeywordMissingEnd.h"
>> >  }
>> > +
>> > +module innerstructredef {
>> > +  module one {
>> > +header "empty.h"
>> > +  }
>> > +  module two {
>> > +   header "innerstructredef.h"
>> > +  }
>> > +}
>> >
>> > Added: cfe/trunk/test/Modules/inner-struct-redefines-invisible.m
>> > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/
>> inner-struct-redefines-invisible.m?rev=310706&view=auto
>> > 
>> ==
>> > --- cfe/trunk/test/Modules/inner-struct-redefines-invisible.m (added)
>> > +++ cfe/trunk/test/Modules/inner-struct-redefines-invisible.m Fri Aug
>> 11 05:06:52 2017
>> > @@ -0,0 +1,12 @@
>> > +// RUN: rm -rf %t
>> > +// RUN: %clang_cc1 -fsyntax-only -I%S/Inputs -fmodules
>> -fimplicit-module-maps -fmodules-cache-path=%t -verify %s
>> > +// expected-no-diagnostics
>> > +
>> > +@import innerstructredef.one;
>> > +
>> > +struct Outer {
>> > +// Should set lexical context when parsing 'Inner' here, otherwise
>> there's a crash:
>> > +struct Inner {
>> > +  int x;
>> > +} field;
>> > +};
>> >
>> >
>> > ___
>> > cfe-commits mailing list
>> > cfe-commits@lists.llvm.org
>> > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>>
>>
>> --
>> Bruno Cardoso Lopes
>> http://www.brunocardoso.cc
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.l

[clang-tools-extra] r310830 - Add braces to silence gcc dangling-else warnings. NFCI.

2017-08-14 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Mon Aug 14 04:05:56 2017
New Revision: 310830

URL: http://llvm.org/viewvc/llvm-project?rev=310830&view=rev
Log:
Add braces to silence gcc dangling-else warnings. NFCI.

Modified:
clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp

Modified: clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp?rev=310830&r1=310829&r2=310830&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp Mon Aug 14 
04:05:56 2017
@@ -237,8 +237,9 @@ class MockFSProvider : public FileSystem
 public:
   Tagged>
   getTaggedFileSystem(PathRef File) override {
-if (ExpectedFile)
+if (ExpectedFile) {
   EXPECT_EQ(*ExpectedFile, File);
+}
 
 auto FS = buildTestFS(Files);
 return make_tagged(FS, Tag);
@@ -876,9 +877,10 @@ int d;
   // Check some invariants about the state of the program.
   std::vector Stats = DiagConsumer.takeFileStats();
   for (unsigned I = 0; I < FilesCount; ++I) {
-if (!ReqStats[I].FileIsRemoved)
+if (!ReqStats[I].FileIsRemoved) {
   ASSERT_EQ(Stats[I].HadErrorsInLastDiags,
 ReqStats[I].LastContentsHadErrors);
+}
 
 ASSERT_LE(Stats[I].HitsWithErrors, ReqStats[I].RequestsWithErrors);
 ASSERT_LE(Stats[I].HitsWithoutErrors, ReqStats[I].RequestsWithoutErrors);


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


r310831 - clang-format: Fix left pointer alignment after delctype/typeof

2017-08-14 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Mon Aug 14 04:06:07 2017
New Revision: 310831

URL: http://llvm.org/viewvc/llvm-project?rev=310831&view=rev
Log:
clang-format: Fix left pointer alignment after delctype/typeof

Change 272124* introduced a regression in spaceRequiredBetween for left aligned 
pointers to decltype and typeof expressions. This fix adds logic to fix this. 
The test added is based on a related test in determineStarAmpUsage. Also add 
test cases for the regression.

http://llvm.org/viewvc/llvm-project?view=revision&revision=272124
LLVM bug tracker: https://bugs.llvm.org/show_bug.cgi?id=30407

Differential revision: https://reviews.llvm.org/D35847

Fix contributed by euhlmann!

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=310831&r1=310830&r2=310831&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Aug 14 04:06:07 2017
@@ -1406,11 +1406,13 @@ private:
 if (NextToken->isOneOf(tok::comma, tok::semi))
   return TT_PointerOrReference;
 
-if (PrevToken->is(tok::r_paren) && PrevToken->MatchingParen &&
-PrevToken->MatchingParen->Previous &&
-PrevToken->MatchingParen->Previous->isOneOf(tok::kw_typeof,
-tok::kw_decltype))
-  return TT_PointerOrReference;
+if (PrevToken->is(tok::r_paren) && PrevToken->MatchingParen) {
+  FormatToken *TokenBeforeMatchingParen =
+  PrevToken->MatchingParen->getPreviousNonComment();
+  if (TokenBeforeMatchingParen &&
+  TokenBeforeMatchingParen->isOneOf(tok::kw_typeof, tok::kw_decltype))
+return TT_PointerOrReference;
+}
 
 if (PrevToken->Tok.isLiteral() ||
 PrevToken->isOneOf(tok::r_paren, tok::r_square, tok::kw_true,
@@ -2214,14 +2216,23 @@ bool TokenAnnotator::spaceRequiredBetwee
 Left.Previous->is(tok::kw_case));
   if (Left.is(tok::l_square) && Right.is(tok::amp))
 return false;
-  if (Right.is(TT_PointerOrReference))
-return (Left.is(tok::r_paren) && Line.MightBeFunctionDecl) ||
-   (Left.Tok.isLiteral() ||
+  if (Right.is(TT_PointerOrReference)) {
+if (Left.is(tok::r_paren) && Line.MightBeFunctionDecl) {
+  if (!Left.MatchingParen)
+return true;
+  FormatToken *TokenBeforeMatchingParen =
+  Left.MatchingParen->getPreviousNonComment();
+  if (!TokenBeforeMatchingParen ||
+  !TokenBeforeMatchingParen->isOneOf(tok::kw_typeof, tok::kw_decltype))
+return true;
+}
+return (Left.Tok.isLiteral() ||
 (!Left.isOneOf(TT_PointerOrReference, tok::l_paren) &&
  (Style.PointerAlignment != FormatStyle::PAS_Left ||
   (Line.IsMultiVariableDeclStmt &&
(Left.NestingLevel == 0 ||
 (Left.NestingLevel == 1 && Line.First->is(tok::kw_for)));
+  }
   if (Right.is(TT_FunctionTypeLParen) && Left.isNot(tok::l_paren) &&
   (!Left.is(TT_PointerOrReference) ||
(Style.PointerAlignment != FormatStyle::PAS_Right &&

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=310831&r1=310830&r2=310831&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Aug 14 04:06:07 2017
@@ -5448,6 +5448,10 @@ TEST_F(FormatTest, UnderstandsUsesOfStar
   verifyFormat("for (;; *a = b) {\n}", Left);
   verifyFormat("return *this += 1;", Left);
   verifyFormat("throw *x;", Left);
+  verifyFormat("delete *x;", Left);
+  verifyFormat("typedef typeof(int(int, int))* MyFuncPtr;", Left);
+  verifyFormat("[](const decltype(*a)* ptr) {}", Left);
+  verifyFormat("typedef typeof /*comment*/ (int(int, int))* MyFuncPtr;", Left);
 
   verifyIndependentOfContext("a = *(x + y);");
   verifyIndependentOfContext("a = &(x + y);");
@@ -5494,9 +5498,6 @@ TEST_F(FormatTest, UnderstandsUsesOfStar
   verifyGoogleFormat("T** t = new T*;");
   verifyGoogleFormat("T** t = new T*();");
 
-  FormatStyle PointerLeft = getLLVMStyle();
-  PointerLeft.PointerAlignment = FormatStyle::PAS_Left;
-  verifyFormat("delete *x;", PointerLeft);
   verifyFormat("STATIC_ASSERT((a & b) == 0);");
   verifyFormat("STATIC_ASSERT(0 == (a & b));");
   verifyFormat("template  "


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


[PATCH] D35847: clang-format: Fix left pointer alignment after delctype/typeof

2017-08-14 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL310831: clang-format: Fix left pointer alignment after 
delctype/typeof (authored by krasimir).

Changed prior to commit:
  https://reviews.llvm.org/D35847?vs=110032&id=110938#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35847

Files:
  cfe/trunk/lib/Format/TokenAnnotator.cpp
  cfe/trunk/unittests/Format/FormatTest.cpp


Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -1406,11 +1406,13 @@
 if (NextToken->isOneOf(tok::comma, tok::semi))
   return TT_PointerOrReference;
 
-if (PrevToken->is(tok::r_paren) && PrevToken->MatchingParen &&
-PrevToken->MatchingParen->Previous &&
-PrevToken->MatchingParen->Previous->isOneOf(tok::kw_typeof,
-tok::kw_decltype))
-  return TT_PointerOrReference;
+if (PrevToken->is(tok::r_paren) && PrevToken->MatchingParen) {
+  FormatToken *TokenBeforeMatchingParen =
+  PrevToken->MatchingParen->getPreviousNonComment();
+  if (TokenBeforeMatchingParen &&
+  TokenBeforeMatchingParen->isOneOf(tok::kw_typeof, tok::kw_decltype))
+return TT_PointerOrReference;
+}
 
 if (PrevToken->Tok.isLiteral() ||
 PrevToken->isOneOf(tok::r_paren, tok::r_square, tok::kw_true,
@@ -2214,14 +2216,23 @@
 Left.Previous->is(tok::kw_case));
   if (Left.is(tok::l_square) && Right.is(tok::amp))
 return false;
-  if (Right.is(TT_PointerOrReference))
-return (Left.is(tok::r_paren) && Line.MightBeFunctionDecl) ||
-   (Left.Tok.isLiteral() ||
+  if (Right.is(TT_PointerOrReference)) {
+if (Left.is(tok::r_paren) && Line.MightBeFunctionDecl) {
+  if (!Left.MatchingParen)
+return true;
+  FormatToken *TokenBeforeMatchingParen =
+  Left.MatchingParen->getPreviousNonComment();
+  if (!TokenBeforeMatchingParen ||
+  !TokenBeforeMatchingParen->isOneOf(tok::kw_typeof, tok::kw_decltype))
+return true;
+}
+return (Left.Tok.isLiteral() ||
 (!Left.isOneOf(TT_PointerOrReference, tok::l_paren) &&
  (Style.PointerAlignment != FormatStyle::PAS_Left ||
   (Line.IsMultiVariableDeclStmt &&
(Left.NestingLevel == 0 ||
 (Left.NestingLevel == 1 && Line.First->is(tok::kw_for)));
+  }
   if (Right.is(TT_FunctionTypeLParen) && Left.isNot(tok::l_paren) &&
   (!Left.is(TT_PointerOrReference) ||
(Style.PointerAlignment != FormatStyle::PAS_Right &&
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -5448,6 +5448,10 @@
   verifyFormat("for (;; *a = b) {\n}", Left);
   verifyFormat("return *this += 1;", Left);
   verifyFormat("throw *x;", Left);
+  verifyFormat("delete *x;", Left);
+  verifyFormat("typedef typeof(int(int, int))* MyFuncPtr;", Left);
+  verifyFormat("[](const decltype(*a)* ptr) {}", Left);
+  verifyFormat("typedef typeof /*comment*/ (int(int, int))* MyFuncPtr;", Left);
 
   verifyIndependentOfContext("a = *(x + y);");
   verifyIndependentOfContext("a = &(x + y);");
@@ -5494,9 +5498,6 @@
   verifyGoogleFormat("T** t = new T*;");
   verifyGoogleFormat("T** t = new T*();");
 
-  FormatStyle PointerLeft = getLLVMStyle();
-  PointerLeft.PointerAlignment = FormatStyle::PAS_Left;
-  verifyFormat("delete *x;", PointerLeft);
   verifyFormat("STATIC_ASSERT((a & b) == 0);");
   verifyFormat("STATIC_ASSERT(0 == (a & b));");
   verifyFormat("template  "


Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -1406,11 +1406,13 @@
 if (NextToken->isOneOf(tok::comma, tok::semi))
   return TT_PointerOrReference;
 
-if (PrevToken->is(tok::r_paren) && PrevToken->MatchingParen &&
-PrevToken->MatchingParen->Previous &&
-PrevToken->MatchingParen->Previous->isOneOf(tok::kw_typeof,
-tok::kw_decltype))
-  return TT_PointerOrReference;
+if (PrevToken->is(tok::r_paren) && PrevToken->MatchingParen) {
+  FormatToken *TokenBeforeMatchingParen =
+  PrevToken->MatchingParen->getPreviousNonComment();
+  if (TokenBeforeMatchingParen &&
+  TokenBeforeMatchingParen->isOneOf(tok::kw_typeof, tok::kw_decltype))
+return TT_PointerOrReference;
+}
 
 if (PrevToken->Tok.isLiteral() ||
 PrevToken->isOneOf(tok::r_paren, tok::r_square, tok::kw_true,
@@ -2214,14 +2216,23 @@
 Left.Previous->is(tok::kw_case));
   if (Left.is(tok::l

[PATCH] D36670: misc-misplaced-widening-cast: fix assertion

2017-08-14 Thread Anders Rönnholm via Phabricator via cfe-commits
AndersRonnholm created this revision.
AndersRonnholm added a project: clang-tools-extra.

Fixes assert reported in https://bugs.llvm.org/show_bug.cgi?id=33660


Repository:
  rL LLVM

https://reviews.llvm.org/D36670

Files:
  clang-tidy/misc/MisplacedWideningCastCheck.cpp
  test/clang-tidy/misc-misplaced-widening-cast-explicit-only.cpp


Index: test/clang-tidy/misc-misplaced-widening-cast-explicit-only.cpp
===
--- test/clang-tidy/misc-misplaced-widening-cast-explicit-only.cpp
+++ test/clang-tidy/misc-misplaced-widening-cast-explicit-only.cpp
@@ -56,3 +56,9 @@
 return (long)a * 1000;
   }
 }
+
+// Shall not generate an assert. https://bugs.llvm.org/show_bug.cgi?id=33660
+template  class A {
+  enum Type {};
+  static char *m_fn1() { char p = (Type)(&p - m_fn1()); }
+};
Index: clang-tidy/misc/MisplacedWideningCastCheck.cpp
===
--- clang-tidy/misc/MisplacedWideningCastCheck.cpp
+++ clang-tidy/misc/MisplacedWideningCastCheck.cpp
@@ -192,6 +192,10 @@
   if (Calc->getLocStart().isMacroID())
 return;
 
+  if (Cast->isTypeDependent() || Cast->isValueDependent() ||
+  Calc->isTypeDependent() || Calc->isValueDependent())
+return;
+
   ASTContext &Context = *Result.Context;
 
   QualType CastType = Cast->getType();


Index: test/clang-tidy/misc-misplaced-widening-cast-explicit-only.cpp
===
--- test/clang-tidy/misc-misplaced-widening-cast-explicit-only.cpp
+++ test/clang-tidy/misc-misplaced-widening-cast-explicit-only.cpp
@@ -56,3 +56,9 @@
 return (long)a * 1000;
   }
 }
+
+// Shall not generate an assert. https://bugs.llvm.org/show_bug.cgi?id=33660
+template  class A {
+  enum Type {};
+  static char *m_fn1() { char p = (Type)(&p - m_fn1()); }
+};
Index: clang-tidy/misc/MisplacedWideningCastCheck.cpp
===
--- clang-tidy/misc/MisplacedWideningCastCheck.cpp
+++ clang-tidy/misc/MisplacedWideningCastCheck.cpp
@@ -192,6 +192,10 @@
   if (Calc->getLocStart().isMacroID())
 return;
 
+  if (Cast->isTypeDependent() || Cast->isValueDependent() ||
+  Calc->isTypeDependent() || Calc->isValueDependent())
+return;
+
   ASTContext &Context = *Result.Context;
 
   QualType CastType = Cast->getType();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r310401 - PR19668, PR23034: Fix handling of move constructors and deleted copy

2017-08-14 Thread Vassil Vassilev via cfe-commits

Hi Diana,

On 14/08/17 11:27, Diana Picus wrote:

Hi,

Strangely enough, it turns out that if I run
Asan-armhf-with-calls-Noinst-Test on the command line it fails,
although it doesn't fail when run with lit. I've attached the stack
trace from gdb. It looks like some trouble passing down va_arg
parameters, but I haven't looked into too much details. The segfault
happens when we try to do a   ldrb   r3, [r0, r1], with r1 set to 0 by
the current function and r0 passed down from the caller. I'm not sure
if this is the exact same problem as the other tests, but feel free to
have a look at that code.

  That smells like our patch is interfering in some way...


Meanwhile, I've removed some clutter from Asan-armhf-with-calls-Test
(which is the original failure that we were seeing) and left only one
failing test that seemed small enough. I'll try to look at the
disassembly before/after the patch and maybe even run valgrind on it
(running it on the original binary naturally takes forever).

Let me know if there's anything else I could try. I can also send you
disassembly or even LLVM IR for the Asan-armhf-with-calls-Noinst-Test
if you think it helps.
  Would you be able to run clang -E on the translation unit that 
crashes and send it over? If you could give us a minimal reproducer it 
would be even better.


Cheers, Vassil


Cheers,
Diana

On 11 August 2017 at 15:34, Diana Picus  wrote:

Well, these are ASAN tests, I'm not sure how that would interact with Valgrind.
Anyway, I'll try to reproduce the environment, I'm guessing it would
be best to catch this in gdb so I can actually see what's going on.

On 11 August 2017 at 15:21, Vassil Vassilev  wrote:

That's really strange. It looks like some random behavior. Did you run some 
memory checker like valgrind?

Do the environment provided by the test runner and yours match?

Sent from my phone. Please excuse my brevity.


On 11 Aug 2017, at 15:58, Diana Picus  wrote:

Hi again,

I finally got the debug build, but unfortunately the stack traces that
the tests print look the same. My suspicion is that this is because
the addresses printed by the tests are funny (i.e. odd numbers instead
of divisible by 4). I tried to follow those addresses in an objdump of
the executable, but I didn't have much success since most of them
weren't really pointing to call instructions.

When I try to run the tests manually in the shell or in gdb, they pass.

I'm not sure what else to try. Thoughts?

Thanks,
Diana


On 11 August 2017 at 11:14, Diana Picus  wrote:
Hi guys,

I'm SO sorry about the delays. I've been having all sorts of trouble
getting that debug build on the board (from ld running out of memory
to the board just crashing on me, in which case I need to ask someone
else to reboot it because I can't power cycle it remotely). I can
assure you this is one of my top priorities, I'll get those stack
traces as soon as I can.

Thanks for your patience and sorry again,
Diana


On 10 August 2017 at 22:55, Richard Smith  wrote:
Any news on this? We want this change in Clang 5, so the sooner we can
understand and fix this regression the better...

On 10 August 2017 at 01:28, Diana Picus via cfe-commits
 wrote:

Hi Vassil,

My build is in progress, but since it's a full build it's probably
going to take another couple of hours to complete. I'll let you know
when it's done.

Thanks,
Diana

On 10 August 2017 at 10:09, Vassil Vassilev 
wrote:

It looks like I can not reproduce it on osx (non-arm)... :(

On 09/08/17 22:54, Diana Picus wrote:

Reverting this also fixed the selfhost bots:


http://lab.llvm.org:8011/builders/clang-cmake-thumbv7-a15-full-sh/builds/2142


http://lab.llvm.org:8011/builders/clang-cmake-armv7-a15-selfhost/builds/2309


http://lab.llvm.org:8011/builders/clang-cmake-armv7-a15-selfhost-neon/builds/1819

I'm afraid the logs for those look even less helpful.


On 9 August 2017 at 16:17, Diana Picus  wrote:

Hi,

See attached. FWIW, when I ran this on a very similar machine, I got
194 failures, all of which went away after reverting. So there might
be something fishy going on.

Regards,
Diana

On 9 August 2017 at 15:02, Vassil Vassilev 
wrote:

Hi Diana,

   It seems the service is down. Could you send us the details of the
failures (incl stack traces if any)

Many thanks,
Vassil


On 09/08/17 15:27, Diana Picus via cfe-commits wrote:

Hi Richard,

I'm sorry but I've reverted this in r310464 because it was breaking
some ASAN tests on this bot:


http://lab.llvm.org:8011/builders/clang-cmake-armv7-a15-full/builds/9452

Please let me know if I can help debug this.

Cheers,
Diana

On 8 August 2017 at 21:14, Richard Smith via cfe-commits
 wrote:

I forgot to say:

Based on a patch by Vassil Vassilev, which was based on a patch by
Bernd
Schmidt, which was based on a patch by Reid Kleckner.

On 8 August 2017 at 12:12, Richard Smith via cfe-commits
 wrote:

Author: rsmith
Date: Tue Aug  8 12:12:28 2017
New Revision: 310401

URL: http://llvm.org/viewvc/llvm-project?rev=310401&vie

Re: r310401 - PR19668, PR23034: Fix handling of move constructors and deleted copy

2017-08-14 Thread Vassil Vassilev via cfe-commits

On 14/08/17 11:27, Diana Picus wrote:

Hi,

Strangely enough, it turns out that if I run
Asan-armhf-with-calls-Noinst-Test on the command line it fails,
although it doesn't fail when run with lit. I've attached the stack
trace from gdb. It looks like some trouble passing down va_arg
parameters, but I haven't looked into too much details. The segfault
happens when we try to do a   ldrb   r3, [r0, r1], with r1 set to 0 by
the current function and r0 passed down from the caller. I'm not sure
if this is the exact same problem as the other tests, but feel free to
have a look at that code.

Meanwhile, I've removed some clutter from Asan-armhf-with-calls-Test
(which is the original failure that we were seeing) and left only one
failing test that seemed small enough. I'll try to look at the
disassembly before/after the patch and maybe even run valgrind on it
(running it on the original binary naturally takes forever).

Let me know if there's anything else I could try. I can also send you
disassembly or even LLVM IR for the Asan-armhf-with-calls-Noinst-Test
if you think it helps.

  disassembly and LLVM will greatly help as well.


Cheers,
Diana

On 11 August 2017 at 15:34, Diana Picus  wrote:

Well, these are ASAN tests, I'm not sure how that would interact with Valgrind.
Anyway, I'll try to reproduce the environment, I'm guessing it would
be best to catch this in gdb so I can actually see what's going on.

On 11 August 2017 at 15:21, Vassil Vassilev  wrote:

That's really strange. It looks like some random behavior. Did you run some 
memory checker like valgrind?

Do the environment provided by the test runner and yours match?

Sent from my phone. Please excuse my brevity.


On 11 Aug 2017, at 15:58, Diana Picus  wrote:

Hi again,

I finally got the debug build, but unfortunately the stack traces that
the tests print look the same. My suspicion is that this is because
the addresses printed by the tests are funny (i.e. odd numbers instead
of divisible by 4). I tried to follow those addresses in an objdump of
the executable, but I didn't have much success since most of them
weren't really pointing to call instructions.

When I try to run the tests manually in the shell or in gdb, they pass.

I'm not sure what else to try. Thoughts?

Thanks,
Diana


On 11 August 2017 at 11:14, Diana Picus  wrote:
Hi guys,

I'm SO sorry about the delays. I've been having all sorts of trouble
getting that debug build on the board (from ld running out of memory
to the board just crashing on me, in which case I need to ask someone
else to reboot it because I can't power cycle it remotely). I can
assure you this is one of my top priorities, I'll get those stack
traces as soon as I can.

Thanks for your patience and sorry again,
Diana


On 10 August 2017 at 22:55, Richard Smith  wrote:
Any news on this? We want this change in Clang 5, so the sooner we can
understand and fix this regression the better...

On 10 August 2017 at 01:28, Diana Picus via cfe-commits
 wrote:

Hi Vassil,

My build is in progress, but since it's a full build it's probably
going to take another couple of hours to complete. I'll let you know
when it's done.

Thanks,
Diana

On 10 August 2017 at 10:09, Vassil Vassilev 
wrote:

It looks like I can not reproduce it on osx (non-arm)... :(

On 09/08/17 22:54, Diana Picus wrote:

Reverting this also fixed the selfhost bots:


http://lab.llvm.org:8011/builders/clang-cmake-thumbv7-a15-full-sh/builds/2142


http://lab.llvm.org:8011/builders/clang-cmake-armv7-a15-selfhost/builds/2309


http://lab.llvm.org:8011/builders/clang-cmake-armv7-a15-selfhost-neon/builds/1819

I'm afraid the logs for those look even less helpful.


On 9 August 2017 at 16:17, Diana Picus  wrote:

Hi,

See attached. FWIW, when I ran this on a very similar machine, I got
194 failures, all of which went away after reverting. So there might
be something fishy going on.

Regards,
Diana

On 9 August 2017 at 15:02, Vassil Vassilev 
wrote:

Hi Diana,

   It seems the service is down. Could you send us the details of the
failures (incl stack traces if any)

Many thanks,
Vassil


On 09/08/17 15:27, Diana Picus via cfe-commits wrote:

Hi Richard,

I'm sorry but I've reverted this in r310464 because it was breaking
some ASAN tests on this bot:


http://lab.llvm.org:8011/builders/clang-cmake-armv7-a15-full/builds/9452

Please let me know if I can help debug this.

Cheers,
Diana

On 8 August 2017 at 21:14, Richard Smith via cfe-commits
 wrote:

I forgot to say:

Based on a patch by Vassil Vassilev, which was based on a patch by
Bernd
Schmidt, which was based on a patch by Reid Kleckner.

On 8 August 2017 at 12:12, Richard Smith via cfe-commits
 wrote:

Author: rsmith
Date: Tue Aug  8 12:12:28 2017
New Revision: 310401

URL: http://llvm.org/viewvc/llvm-project?rev=310401&view=rev
Log:
PR19668, PR23034: Fix handling of move constructors and deleted
copy
constructors when deciding whether classes should be passed
indirectly.

This fixes ABI differences between Clang and 

[PATCH] D36156: [rename] Introduce symbol occurrences

2017-08-14 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

Ping.


Repository:
  rL LLVM

https://reviews.llvm.org/D36156



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


Re: r310401 - PR19668, PR23034: Fix handling of move constructors and deleted copy

2017-08-14 Thread Diana Picus via cfe-commits
Also if you want the disassembly for the whole test executable (with
just that test in it):
https://goo.gl/pjULbN

It's 177MB though.

On 14 August 2017 at 14:04, Diana Picus  wrote:
> See attached.
>
> On 14 August 2017 at 13:30, Vassil Vassilev  wrote:
>> On 14/08/17 11:27, Diana Picus wrote:
>>>
>>> Hi,
>>>
>>> Strangely enough, it turns out that if I run
>>> Asan-armhf-with-calls-Noinst-Test on the command line it fails,
>>> although it doesn't fail when run with lit. I've attached the stack
>>> trace from gdb. It looks like some trouble passing down va_arg
>>> parameters, but I haven't looked into too much details. The segfault
>>> happens when we try to do a   ldrb   r3, [r0, r1], with r1 set to 0 by
>>> the current function and r0 passed down from the caller. I'm not sure
>>> if this is the exact same problem as the other tests, but feel free to
>>> have a look at that code.
>>>
>>> Meanwhile, I've removed some clutter from Asan-armhf-with-calls-Test
>>> (which is the original failure that we were seeing) and left only one
>>> failing test that seemed small enough. I'll try to look at the
>>> disassembly before/after the patch and maybe even run valgrind on it
>>> (running it on the original binary naturally takes forever).
>>>
>>> Let me know if there's anything else I could try. I can also send you
>>> disassembly or even LLVM IR for the Asan-armhf-with-calls-Noinst-Test
>>> if you think it helps.
>>
>>   disassembly and LLVM will greatly help as well.
>>
>>>
>>> Cheers,
>>> Diana
>>>
>>> On 11 August 2017 at 15:34, Diana Picus  wrote:

 Well, these are ASAN tests, I'm not sure how that would interact with
 Valgrind.
 Anyway, I'll try to reproduce the environment, I'm guessing it would
 be best to catch this in gdb so I can actually see what's going on.

 On 11 August 2017 at 15:21, Vassil Vassilev 
 wrote:
>
> That's really strange. It looks like some random behavior. Did you run
> some memory checker like valgrind?
>
> Do the environment provided by the test runner and yours match?
>
> Sent from my phone. Please excuse my brevity.
>
>> On 11 Aug 2017, at 15:58, Diana Picus  wrote:
>>
>> Hi again,
>>
>> I finally got the debug build, but unfortunately the stack traces that
>> the tests print look the same. My suspicion is that this is because
>> the addresses printed by the tests are funny (i.e. odd numbers instead
>> of divisible by 4). I tried to follow those addresses in an objdump of
>> the executable, but I didn't have much success since most of them
>> weren't really pointing to call instructions.
>>
>> When I try to run the tests manually in the shell or in gdb, they pass.
>>
>> I'm not sure what else to try. Thoughts?
>>
>> Thanks,
>> Diana
>>
>>> On 11 August 2017 at 11:14, Diana Picus 
>>> wrote:
>>> Hi guys,
>>>
>>> I'm SO sorry about the delays. I've been having all sorts of trouble
>>> getting that debug build on the board (from ld running out of memory
>>> to the board just crashing on me, in which case I need to ask someone
>>> else to reboot it because I can't power cycle it remotely). I can
>>> assure you this is one of my top priorities, I'll get those stack
>>> traces as soon as I can.
>>>
>>> Thanks for your patience and sorry again,
>>> Diana
>>>
 On 10 August 2017 at 22:55, Richard Smith 
 wrote:
 Any news on this? We want this change in Clang 5, so the sooner we
 can
 understand and fix this regression the better...

 On 10 August 2017 at 01:28, Diana Picus via cfe-commits
  wrote:
>
> Hi Vassil,
>
> My build is in progress, but since it's a full build it's probably
> going to take another couple of hours to complete. I'll let you know
> when it's done.
>
> Thanks,
> Diana
>
> On 10 August 2017 at 10:09, Vassil Vassilev 
> wrote:
>>
>> It looks like I can not reproduce it on osx (non-arm)... :(
>>>
>>> On 09/08/17 22:54, Diana Picus wrote:
>>>
>>> Reverting this also fixed the selfhost bots:
>>>
>>>
>>>
>>> http://lab.llvm.org:8011/builders/clang-cmake-thumbv7-a15-full-sh/builds/2142
>>>
>>>
>>>
>>> http://lab.llvm.org:8011/builders/clang-cmake-armv7-a15-selfhost/builds/2309
>>>
>>>
>>>
>>> http://lab.llvm.org:8011/builders/clang-cmake-armv7-a15-selfhost-neon/builds/1819
>>>
>>> I'm afraid the logs for those look even less helpful.
>>>
 On 9 August 2017 at 16:17, Diana Picus 
 wrote:

 Hi,

 See attached. FWIW, when I ran this on a very similar machine, I
 got
 194 fail

[PATCH] D36670: misc-misplaced-widening-cast: fix assertion

2017-08-14 Thread Daniel Marjamäki via Phabricator via cfe-commits
danielmarjamaki added a comment.

LGTM. I let others approve this.


Repository:
  rL LLVM

https://reviews.llvm.org/D36670



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


[PATCH] D36179: [clang-diff] Move printing of matches and changes to clang-diff

2017-08-14 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman accepted this revision.
arphaman added a comment.
This revision is now accepted and ready to land.

LGTM, with one request below:




Comment at: lib/Tooling/ASTDiff/ASTDiff.cpp:96
 
-  /// Finds an edit script that converts T1 to T2.
-  std::vector computeChanges(Mapping &M);
-
-  void printChangeImpl(raw_ostream &OS, const Change &Chg) const;
-  void printMatchImpl(raw_ostream &OS, const Match &M) const;
-
-  // Returns a mapping of identical subtrees.
-  Mapping matchTopDown() const;
+  NodeId getMapped(const std::unique_ptr &Tree, NodeId Id) 
const {
+if (&*Tree == &T1)

80 column violation, please re-format.


https://reviews.llvm.org/D36179



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


[PATCH] D36672: readability-non-const-parameter: fixit on all function declarations

2017-08-14 Thread Anders Rönnholm via Phabricator via cfe-commits
AndersRonnholm created this revision.

Fixes issue reported in https://bugs.llvm.org/show_bug.cgi?id=33219


Repository:
  rL LLVM

https://reviews.llvm.org/D36672

Files:
  clang-tidy/readability/NonConstParameterCheck.cpp
  test/clang-tidy/readability-non-const-parameter.cpp


Index: test/clang-tidy/readability-non-const-parameter.cpp
===
--- test/clang-tidy/readability-non-const-parameter.cpp
+++ test/clang-tidy/readability-non-const-parameter.cpp
@@ -277,3 +277,11 @@
 int x = *p;
   }
 };
+
+int declarationFixit(int *i);
+// CHECK-FIXES: {{^}}int declarationFixit(const int *i);{{$}}
+// CHECK-MESSAGES: :[[@LINE+1]]:27: warning: pointer parameter 'i' can be
+int declarationFixit(int *i) {
+  // CHECK-FIXES: {{^}}int declarationFixit(const int *i) {{{$}}
+  return *i;
+}
Index: clang-tidy/readability/NonConstParameterCheck.cpp
===
--- clang-tidy/readability/NonConstParameterCheck.cpp
+++ clang-tidy/readability/NonConstParameterCheck.cpp
@@ -138,9 +138,20 @@
 if (!ParamInfo.CanBeConst)
   continue;
 
-diag(Par->getLocation(), "pointer parameter '%0' can be pointer to const")
-<< Par->getName()
-<< FixItHint::CreateInsertion(Par->getLocStart(), "const ");
+auto D = diag(Par->getLocation(),
+  "pointer parameter '%0' can be pointer to const")
+ << Par->getName()
+ << FixItHint::CreateInsertion(Par->getLocStart(), "const ");
+
+if (const auto *Parent = Par->getParentFunctionOrMethod()) {
+  if (const auto *F = dyn_cast(Parent)) {
+const auto ParDecl =
+F->getFirstDecl()->getParamDecl(Par->getFunctionScopeIndex());
+if (Par != ParDecl)
+  D << ParDecl->getName()
+<< FixItHint::CreateInsertion(ParDecl->getLocStart(), "const ");
+  }
+}
   }
 }
 


Index: test/clang-tidy/readability-non-const-parameter.cpp
===
--- test/clang-tidy/readability-non-const-parameter.cpp
+++ test/clang-tidy/readability-non-const-parameter.cpp
@@ -277,3 +277,11 @@
 int x = *p;
   }
 };
+
+int declarationFixit(int *i);
+// CHECK-FIXES: {{^}}int declarationFixit(const int *i);{{$}}
+// CHECK-MESSAGES: :[[@LINE+1]]:27: warning: pointer parameter 'i' can be
+int declarationFixit(int *i) {
+  // CHECK-FIXES: {{^}}int declarationFixit(const int *i) {{{$}}
+  return *i;
+}
Index: clang-tidy/readability/NonConstParameterCheck.cpp
===
--- clang-tidy/readability/NonConstParameterCheck.cpp
+++ clang-tidy/readability/NonConstParameterCheck.cpp
@@ -138,9 +138,20 @@
 if (!ParamInfo.CanBeConst)
   continue;
 
-diag(Par->getLocation(), "pointer parameter '%0' can be pointer to const")
-<< Par->getName()
-<< FixItHint::CreateInsertion(Par->getLocStart(), "const ");
+auto D = diag(Par->getLocation(),
+  "pointer parameter '%0' can be pointer to const")
+ << Par->getName()
+ << FixItHint::CreateInsertion(Par->getLocStart(), "const ");
+
+if (const auto *Parent = Par->getParentFunctionOrMethod()) {
+  if (const auto *F = dyn_cast(Parent)) {
+const auto ParDecl =
+F->getFirstDecl()->getParamDecl(Par->getFunctionScopeIndex());
+if (Par != ParDecl)
+  D << ParDecl->getName()
+<< FixItHint::CreateInsertion(ParDecl->getLocStart(), "const ");
+  }
+}
   }
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36182: [clang-diff] Add HTML side-by-side diff output

2017-08-14 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

Awesome, thanks! LGTM.


https://reviews.llvm.org/D36182



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


[PATCH] D36179: [clang-diff] Move printing of matches and changes to clang-diff

2017-08-14 Thread Johannes Altmanninger via Phabricator via cfe-commits
johannes updated this revision to Diff 110945.
johannes added a comment.

format


https://reviews.llvm.org/D36179

Files:
  include/clang/Tooling/ASTDiff/ASTDiff.h
  include/clang/Tooling/ASTDiff/ASTDiffInternal.h
  lib/Tooling/ASTDiff/ASTDiff.cpp
  test/Tooling/clang-diff-basic.cpp
  tools/clang-diff/ClangDiff.cpp

Index: tools/clang-diff/ClangDiff.cpp
===
--- tools/clang-diff/ClangDiff.cpp
+++ tools/clang-diff/ClangDiff.cpp
@@ -129,7 +129,7 @@
   auto Offsets = Tree.getSourceRangeOffsets(N);
   OS << R"(,"begin":)" << Offsets.first;
   OS << R"(,"end":)" << Offsets.second;
-  std::string Value = Tree.getNodeValue(N.ASTNode);
+  std::string Value = Tree.getNodeValue(N);
   if (!Value.empty()) {
 OS << R"(,"value":")";
 printJsonString(OS, Value);
@@ -153,6 +153,52 @@
   OS << "]}";
 }
 
+static void printNode(raw_ostream &OS, diff::SyntaxTree &Tree,
+  diff::NodeId Id) {
+  if (Id.isInvalid()) {
+OS << "None";
+return;
+  }
+  OS << Tree.getNode(Id).getTypeLabel();
+  std::string Value = Tree.getNodeValue(Id);
+  if (!Value.empty())
+OS << ": " << Value;
+  OS << "(" << Id << ")";
+}
+
+static void printDstChange(raw_ostream &OS, diff::ASTDiff &Diff,
+   diff::SyntaxTree &SrcTree, diff::SyntaxTree &DstTree,
+   diff::NodeId Dst) {
+  const diff::Node &DstNode = DstTree.getNode(Dst);
+  diff::NodeId Src = Diff.getMapped(DstTree, Dst);
+  switch (DstNode.ChangeKind) {
+  case diff::None:
+break;
+  case diff::Delete:
+llvm_unreachable("The destination tree can't have deletions.");
+  case diff::Update:
+OS << "Update ";
+printNode(OS, SrcTree, Src);
+OS << " to " << DstTree.getNodeValue(Dst) << "\n";
+break;
+  case diff::Insert:
+  case diff::Move:
+  case diff::UpdateMove:
+if (DstNode.ChangeKind == diff::Insert)
+  OS << "Insert";
+else if (DstNode.ChangeKind == diff::Move)
+  OS << "Move";
+else if (DstNode.ChangeKind == diff::UpdateMove)
+  OS << "Update and Move";
+OS << " ";
+printNode(OS, DstTree, Dst);
+OS << " into ";
+printNode(OS, DstTree, DstNode.Parent);
+OS << " at " << DstTree.findPositionInParent(Dst) << "\n";
+break;
+  }
+}
+
 int main(int argc, const char **argv) {
   std::string ErrorMessage;
   std::unique_ptr CommonCompilations =
@@ -199,11 +245,26 @@
 Options.MaxSize = MaxSize;
   diff::SyntaxTree SrcTree(Src->getASTContext());
   diff::SyntaxTree DstTree(Dst->getASTContext());
-  diff::ASTDiff DiffTool(SrcTree, DstTree, Options);
-  for (const auto &Match : DiffTool.getMatches())
-DiffTool.printMatch(llvm::outs(), Match);
-  for (const auto &Change : DiffTool.getChanges())
-DiffTool.printChange(llvm::outs(), Change);
+  diff::ASTDiff Diff(SrcTree, DstTree, Options);
+
+  for (diff::NodeId Dst : DstTree) {
+diff::NodeId Src = Diff.getMapped(DstTree, Dst);
+if (Src.isValid()) {
+  llvm::outs() << "Match ";
+  printNode(llvm::outs(), SrcTree, Src);
+  llvm::outs() << " to ";
+  printNode(llvm::outs(), DstTree, Dst);
+  llvm::outs() << "\n";
+}
+printDstChange(llvm::outs(), Diff, SrcTree, DstTree, Dst);
+  }
+  for (diff::NodeId Src : SrcTree) {
+if (Diff.getMapped(SrcTree, Src).isInvalid()) {
+  llvm::outs() << "Delete ";
+  printNode(llvm::outs(), SrcTree, Src);
+  llvm::outs() << "\n";
+}
+  }
 
   return 0;
 }
Index: test/Tooling/clang-diff-basic.cpp
===
--- test/Tooling/clang-diff-basic.cpp
+++ test/Tooling/clang-diff-basic.cpp
@@ -31,6 +31,10 @@
   int id(int i) { return i; }
 };
 }
+
+void m() { int x = 0 + 0 + 0; }
+int um = 1 + 2 + 3;
+
 #else
 // CHECK: Match TranslationUnitDecl{{.*}} to TranslationUnitDecl
 // CHECK: Match NamespaceDecl: src{{.*}} to NamespaceDecl: dst
@@ -54,8 +58,8 @@
 typedef unsigned nat;
 
 // CHECK: Match VarDecl: p(int){{.*}} to VarDecl: prod(double)
-// CHECK: Match BinaryOperator: *{{.*}} to BinaryOperator: *
 // CHECK: Update VarDecl: p(int){{.*}} to prod(double)
+// CHECK: Match BinaryOperator: *{{.*}} to BinaryOperator: *
 double prod = 1 * 2 * 10;
 // CHECK: Update DeclRefExpr
 int squared = prod * prod;
@@ -70,9 +74,15 @@
   return "foo";
 return 0;
   }
-  // CHECK: Delete AccessSpecDecl: public
-  X(){};
-  // CHECK: Delete CXXMethodDecl
+  X(){}
 };
 }
+
+// CHECK: Move DeclStmt{{.*}} into CompoundStmt
+void m() { { int x = 0 + 0 + 0; } }
+// CHECK: Update and Move IntegerLiteral: 7{{.*}} into BinaryOperator: +({{.*}}) at 1
+int um = 1 + 7;
 #endif
+
+// CHECK: Delete AccessSpecDecl: public
+// CHECK: Delete CXXMethodDecl
Index: lib/Tooling/ASTDiff/ASTDiff.cpp
===
--- lib/Tooling/ASTDiff/ASTDiff.cpp
+++ lib/Tooling/ASTDiff/ASTDiff.cpp
@@ -82,26 +82,24 @@
 class ASTDiff::Impl {
 public:
   SyntaxTree::Impl &T1, &T2;
-  boo

[PATCH] D36156: [rename] Introduce symbol occurrences

2017-08-14 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

Sorry for the delay. The code looks good roughly, a few nits below.




Comment at: include/clang/Tooling/Refactoring/Rename/SymbolName.h:19
+namespace clang {
+namespace tooling {
+

An off-topic thought: currently we put everything into `clang::tooling`, I 
think we might need a separate namespace e.g. `clang::tooling::refactoring` in 
the future? 



Comment at: include/clang/Tooling/Refactoring/Rename/SymbolName.h:21
+
+class SymbolName;
+

I think this can be removed?



Comment at: lib/Tooling/Refactoring/Rename/RenamingAction.cpp:60
+static void
+applyChanges(ArrayRef AtomicChanges,
+ std::map &FileToReplaces) {

Maybe add a comment for this utility function.

The name is a bit confusing, IIUC, the function actually fills the 
`FileToReplaces`, not apply the changes? maybe a better name for it?



Comment at: lib/Tooling/Refactoring/Rename/RenamingAction.cpp:61
+applyChanges(ArrayRef AtomicChanges,
+ std::map &FileToReplaces) {
+  for (const auto AtomicChange : AtomicChanges) {

nit: For out parameter, I'd use pointer.



Comment at: lib/Tooling/Refactoring/Rename/RenamingAction.cpp:62
+ std::map &FileToReplaces) {
+  for (const auto AtomicChange : AtomicChanges) {
+for (const auto &Replace : AtomicChange.getReplacements()) {

nit: `const auto &`



Comment at: lib/Tooling/Refactoring/Rename/SymbolOccurrences.cpp:17
+
+SymbolOccurrence::SymbolOccurrence(const SymbolName &Name, OccurrenceKind Kind,
+   ArrayRef Locations)

Shouldn't the definition be in clang::tooling namespace?



Comment at: lib/Tooling/Refactoring/Rename/USRLocFinder.cpp:398
   Visitor.TraverseDecl(Decl);
-  return Visitor.getLocationsFound();
+  return std::move(Visitor.getOccurrences());
 }

I think just returning `Visitor.getOccurrences()` is sufficient -- compiler can 
handle it well, also using std::move would prevent copy elision.


Repository:
  rL LLVM

https://reviews.llvm.org/D36156



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


[PATCH] D33989: [OpenCL] Allow targets to select address space per type

2017-08-14 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh updated this revision to Diff 110947.
svenvh edited the summary of this revision.
svenvh added a comment.
Herald added a subscriber: nhaehnle.

Apologies for the late followup!  Rebased the patch and addressed your comments.


https://reviews.llvm.org/D33989

Files:
  include/clang/Basic/TargetInfo.h
  lib/AST/ASTContext.cpp
  lib/Basic/TargetInfo.cpp
  lib/Basic/Targets/AMDGPU.h
  lib/CodeGen/CGOpenCLRuntime.cpp
  lib/CodeGen/CGOpenCLRuntime.h
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenTypes.cpp
  test/CodeGenOpenCL/opencl_types.cl

Index: test/CodeGenOpenCL/opencl_types.cl
===
--- test/CodeGenOpenCL/opencl_types.cl
+++ test/CodeGenOpenCL/opencl_types.cl
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 %s -triple "spir-unknown-unknown" -emit-llvm -o - -O0 | FileCheck %s --check-prefix=CHECK-SPIR
-// RUN: %clang_cc1 %s -triple "amdgcn--amdhsa" -emit-llvm -o - -O0 | FileCheck %s --check-prefix=CHECK-AMDGCN
+// RUN: %clang_cc1 -cl-std=CL2.0 %s -triple "spir-unknown-unknown" -emit-llvm -o - -O0 | FileCheck %s --check-prefix=CHECK-SPIR
+// RUN: %clang_cc1 -cl-std=CL2.0 %s -triple "amdgcn--amdhsa" -emit-llvm -o - -O0 | FileCheck %s --check-prefix=CHECK-AMDGCN
 
 #define CLK_ADDRESS_CLAMP_TO_EDGE   2
 #define CLK_NORMALIZED_COORDS_TRUE  1
@@ -42,13 +42,23 @@
   // CHECK-SPIR: alloca %opencl.sampler_t addrspace(2)*
   event_t evt;
   // CHECK-SPIR: alloca %opencl.event_t*
+  clk_event_t clk_evt;
+  // CHECK-SPIR: alloca %opencl.clk_event_t*
+  queue_t queue;
+  // CHECK-SPIR: alloca %opencl.queue_t*
+  reserve_id_t rid;
+  // CHECK-SPIR: alloca %opencl.reserve_id_t*
   // CHECK-SPIR: store %opencl.sampler_t addrspace(2)*
   fnc4smp(smp);
   // CHECK-SPIR: call {{.*}}void @fnc4smp(%opencl.sampler_t addrspace(2)*
   fnc4smp(glb_smp);
   // CHECK-SPIR: call {{.*}}void @fnc4smp(%opencl.sampler_t addrspace(2)*
 }
 
+kernel void foo_pipe(read_only pipe int p) {}
+// CHECK-SPIR: @foo_pipe(%opencl.pipe_t addrspace(1)* %p)
+// CHECK_AMDGCN: @foo_pipe(%opencl.pipe_t addrspace(1)* %p)
+
 void __attribute__((overloadable)) bad1(image1d_t b, image2d_t c, image2d_t d) {}
 // CHECK-SPIR-LABEL: @{{_Z4bad114ocl_image1d_ro14ocl_image2d_roS0_|"\\01\?bad1@@\$\$J0YAXPAUocl_image1d_ro@@PAUocl_image2d_ro@@1@Z"}}
 // CHECK-AMDGCN-LABEL: @{{_Z4bad114ocl_image1d_ro14ocl_image2d_roS0_|"\\01\?bad1@@\$\$J0YAXPAUocl_image1d_ro@@PAUocl_image2d_ro@@1@Z"}}(%opencl.image1d_ro_t addrspace(2)*{{.*}}%opencl.image2d_ro_t addrspace(2)*{{.*}}%opencl.image2d_ro_t addrspace(2)*{{.*}})
Index: lib/CodeGen/CodeGenTypes.cpp
===
--- lib/CodeGen/CodeGenTypes.cpp
+++ lib/CodeGen/CodeGenTypes.cpp
@@ -635,7 +635,7 @@
 break;
   }
   case Type::Pipe: {
-ResultType = CGM.getOpenCLRuntime().getPipeType();
+ResultType = CGM.getOpenCLRuntime().getPipeType(cast(Ty));
 break;
   }
   }
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -4536,7 +4536,7 @@
 CodeGenModule::createOpenCLIntToSamplerConversion(const Expr *E,
   CodeGenFunction &CGF) {
   llvm::Constant *C = EmitConstantExpr(E, E->getType(), &CGF);
-  auto SamplerT = getOpenCLRuntime().getSamplerType();
+  auto SamplerT = getOpenCLRuntime().getSamplerType(E->getType().getTypePtr());
   auto FTy = llvm::FunctionType::get(SamplerT, {C->getType()}, false);
   return CGF.Builder.CreateCall(CreateRuntimeFunction(FTy,
 "__translate_sampler_initializer"),
Index: lib/CodeGen/CGOpenCLRuntime.h
===
--- lib/CodeGen/CGOpenCLRuntime.h
+++ lib/CodeGen/CGOpenCLRuntime.h
@@ -48,9 +48,9 @@
 
   virtual llvm::Type *convertOpenCLSpecificType(const Type *T);
 
-  virtual llvm::Type *getPipeType();
+  virtual llvm::Type *getPipeType(const PipeType *T);
 
-  llvm::PointerType *getSamplerType();
+  llvm::PointerType *getSamplerType(const Type *T);
 
   // \brief Returnes a value which indicates the size in bytes of the pipe
   // element.
Index: lib/CodeGen/CGOpenCLRuntime.cpp
===
--- lib/CodeGen/CGOpenCLRuntime.cpp
+++ lib/CodeGen/CGOpenCLRuntime.cpp
@@ -35,52 +35,52 @@
  "Not an OpenCL specific type!");
 
   llvm::LLVMContext& Ctx = CGM.getLLVMContext();
-  uint32_t ImgAddrSpc = CGM.getContext().getTargetAddressSpace(
-CGM.getTarget().getOpenCLImageAddrSpace());
+  uint32_t AddrSpc = CGM.getContext().getTargetAddressSpace(
+  CGM.getTarget().getOpenCLTypeAddrSpace(T));
   switch (cast(T)->getKind()) {
   default:
 llvm_unreachable("Unexpected opencl builtin type!");
 return nullptr;
 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
   case BuiltinType::Id: \
 return llvm::PointerType::get( \
 llvm::Str

[PATCH] D33989: [OpenCL] Allow targets to select address space per type

2017-08-14 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh marked 2 inline comments as done.
svenvh added inline comments.



Comment at: include/clang/Basic/TargetInfo.h:1041
+default:
+  return LangAS::Default;
+}

yaxunl wrote:
> Anastasia wrote:
> > bader wrote:
> > > yaxunl wrote:
> > > > bader wrote:
> > > > > yaxunl wrote:
> > > > > > I think the default (including even_t, clk_event_t, queue_t, 
> > > > > > reserved_id_t) should be global since these opaque OpenCL objects 
> > > > > > are pointers to some shared resources. These pointers may be an 
> > > > > > automatic variable themselves but the memory they point to should 
> > > > > > be global. Since these objects are dynamically allocated, assuming 
> > > > > > them in private address space implies runtime needs to maintain a 
> > > > > > private memory pool for each work item and allocate objects from 
> > > > > > there. Considering the huge number of work items in typical OpenCL 
> > > > > > applications, it would be very inefficient to implement these 
> > > > > > objects in private memory pool. On the other hand, a global memory 
> > > > > > pool seems much reasonable.
> > > > > > 
> > > > > > Anastasia/Alexey, any comments on this? Thanks.
> > > > > I remember we discussed this a couple of time in the past. 
> > > > > The address space for variables of these types is not clearly stated 
> > > > > in the spec, so I think the right way to treat it - it's 
> > > > > implementation defined.
> > > > > On the other hand your reasoning on using global address space as 
> > > > > default AS makes sense in general - so can we put additional 
> > > > > clarification to the spec to align it with the proposed 
> > > > > implementation?
> > > > I think it is unnecessary to specify the implementation details in the 
> > > > OpenCL spec.
> > > > 
> > > > It is also unnecessary for SPIR-V spec since the pointee address space 
> > > > of OpenCL opaque struct is not encoded in SPIR-V.
> > > > 
> > > > We can use the commonly accepted address space definition in the 
> > > > TargetInfo base class. If a target chooses to use different address 
> > > > space for specific opaque objects, it can override it in its own 
> > > > virtual function.
> > > > I think it is unnecessary to specify the implementation details in the 
> > > > OpenCL spec.
> > > 
> > > Agree, but my point was about specifying the intention in the 
> > > specification.
> > > For instance, OpenCL spec says that image objects are located in global 
> > > memory.
> > > It says nothing about objects like events, queues, etc., so I assumed 
> > > that if it says nothing an implementation is allowed to choose the memory 
> > > region, but it might be false assumption.
> > We could create a bug to Khronos OpenCL C spec and discuss it on the next 
> > call just to make sure... but otherwise this change seems reasonable enough!
> Can you or Alexey bring this issue to the WG? Thanks.

It's probably better to change the default to global in a separate commit, once 
we agree that that is the best solution.  So I have preserved the address 
spaces of the old code in this updated patch.


https://reviews.llvm.org/D33989



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


[PATCH] D36185: [clang-diff] Fix similarity computation

2017-08-14 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman accepted this revision.
arphaman added a comment.
This revision is now accepted and ready to land.

LGTM.




Comment at: lib/Tooling/ASTDiff/ASTDiff.cpp:738
+  }
+  double Denominator = T1.getNumberOfDescendants(Id1) - 1 +
+   T2.getNumberOfDescendants(Id2) - 1 - CommonDescendants;

Can denominator even be negative here? If no, please assert correspondingly. 


https://reviews.llvm.org/D36185



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


[PATCH] D33989: [OpenCL] Allow targets to select address space per type

2017-08-14 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl accepted this revision.
yaxunl added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks.


https://reviews.llvm.org/D33989



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


[PATCH] D36185: [clang-diff] Fix similarity computation

2017-08-14 Thread Johannes Altmanninger via Phabricator via cfe-commits
johannes updated this revision to Diff 110951.
johannes added a comment.

comment getJaccardSimilarity


https://reviews.llvm.org/D36185

Files:
  include/clang/Tooling/ASTDiff/ASTDiff.h
  lib/Tooling/ASTDiff/ASTDiff.cpp
  test/Tooling/clang-diff-bottomup.cpp
  test/Tooling/clang-diff-opt.cpp
  test/Tooling/clang-diff-topdown.cpp
  tools/clang-diff/ClangDiff.cpp

Index: tools/clang-diff/ClangDiff.cpp
===
--- tools/clang-diff/ClangDiff.cpp
+++ tools/clang-diff/ClangDiff.cpp
@@ -50,6 +50,11 @@
 cl::Optional,
 cl::cat(ClangDiffCategory));
 
+static cl::opt StopAfter("stop-after",
+  cl::desc(""),
+  cl::Optional, cl::init(""),
+  cl::cat(ClangDiffCategory));
+
 static cl::opt MaxSize("s", cl::desc(""), cl::Optional,
 cl::init(-1), cl::cat(ClangDiffCategory));
 
@@ -424,6 +429,14 @@
   diff::ComparisonOptions Options;
   if (MaxSize != -1)
 Options.MaxSize = MaxSize;
+  if (!StopAfter.empty()) {
+if (StopAfter == "topdown")
+  Options.StopAfterTopDown = true;
+else if (StopAfter != "bottomup") {
+  llvm::errs() << "Error: Invalid argument for -stop-after\n";
+  return 1;
+}
+  }
   diff::SyntaxTree SrcTree(Src->getASTContext());
   diff::SyntaxTree DstTree(Dst->getASTContext());
   diff::ASTDiff Diff(SrcTree, DstTree, Options);
Index: test/Tooling/clang-diff-topdown.cpp
===
--- /dev/null
+++ test/Tooling/clang-diff-topdown.cpp
@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -E %s > %t.src.cpp
+// RUN: %clang_cc1 -E %s > %t.dst.cpp -DDEST
+// RUN: clang-diff -dump-matches -stop-after=topdown %t.src.cpp %t.dst.cpp -- | FileCheck %s
+//
+// Test the top-down matching of identical subtrees only.
+
+#ifndef DEST
+
+void f1()
+{
+  // Match some subtree of height greater than 2.
+  // CHECK: Match CompoundStmt(3) to CompoundStmt(3)
+  // CHECK: Match CompoundStmt(4) to CompoundStmt(4)
+  // CHECK: Match NullStmt(5) to NullStmt(5)
+  {{;}}
+
+  // Don't match subtrees that are smaller.
+  // CHECK-NOT: Match CompoundStmt(6)
+  // CHECK-NOT: Match NullStmt(7)
+  {;}
+
+  // Greedy approach - use the first matching subtree when there are multiple
+  // identical subtrees.
+  // CHECK: Match CompoundStmt(8) to CompoundStmt(8)
+  // CHECK: Match CompoundStmt(9) to CompoundStmt(9)
+  // CHECK: Match NullStmt(10) to NullStmt(10)
+  {{;;}}
+}
+
+#else
+
+void f1() {
+
+  {{;}}
+
+  {;}
+
+  {{;;}}
+  // CHECK-NOT: Match {{.*}} to CompoundStmt(11)
+  // CHECK-NOT: Match {{.*}} to CompoundStmt(12)
+  // CHECK-NOT: Match {{.*}} to NullStmt(13)
+  {{;;}}
+
+  // CHECK-NOT: Match {{.*}} to NullStmt(14)
+  ;
+}
+
+#endif
Index: test/Tooling/clang-diff-opt.cpp
===
--- /dev/null
+++ test/Tooling/clang-diff-opt.cpp
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 -E %s > %t.src.cpp
+// RUN: %clang_cc1 -E %s > %t.dst.cpp -DDEST
+// RUN: clang-diff -dump-matches -s=10 %t.src.cpp %t.dst.cpp -- | FileCheck %s
+//
+// Test the behaviour of the matching according to the optimal tree edit
+// distance, implemented with Zhang and Shasha's algorithm.
+// Just for testing we use a tiny value of 10 for maxsize. Subtrees bigger than
+// this size will not be processed by the optimal algorithm.
+
+#ifndef DEST
+
+void f1() { {;} {{;}} }
+
+void f2() { {;} {{;}} }
+
+void f3() { {;} {{;;}} }
+
+#else
+
+void f1() {
+// Jaccard similarity = 3 / (5 + 4 - 3) = 3 / 6 >= 0.5
+// The optimal matching algorithm should move the ; into the outer block
+// CHECK: Match CompoundStmt(2) to CompoundStmt(2)
+// CHECK-NOT: Match CompoundStmt(3)
+// CHECK-NEXT: Match NullStmt(4) to NullStmt(3)
+  ; {{;}}
+}
+ 
+void f2() {
+  // Jaccard similarity = 7 / (10 + 10 - 7) >= 0.5
+  // As none of the subtrees is bigger than 10 nodes, the optimal algorithm
+  // will be run.
+  // CHECK: Match NullStmt(11) to NullStmt(9)
+  ;; {{;}}
+}
+
+void f3() {
+  // Jaccard similarity = 8 / (11 + 11 - 8) >= 0.5
+  // As the subtrees are bigger than 10 nodes, the optimal algorithm will not
+  // be run.
+  // CHECK: Delete NullStmt(22)
+  ;; {{;;}}
+}
+#endif
Index: test/Tooling/clang-diff-bottomup.cpp
===
--- /dev/null
+++ test/Tooling/clang-diff-bottomup.cpp
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 -E %s > %t.src.cpp
+// RUN: %clang_cc1 -E %s > %t.dst.cpp -DDEST
+// RUN: clang-diff -dump-matches -s=0 %t.src.cpp %t.dst.cpp -- | FileCheck %s
+//
+// Test the bottom-up matching, with maxsize set to 0, so that the optimal matching will never be applied.
+
+#ifndef DEST
+
+void f1() { ; {{;}} }
+void f2() { ;; {{;}} }
+
+#else
+
+// Jaccard similarity threshold is 0.5.
+
+void f1() {
+// Compoun

[PATCH] D36186: [clang-diff] Improve and test getNodeValue

2017-08-14 Thread Johannes Altmanninger via Phabricator via cfe-commits
johannes updated this revision to Diff 110952.
johannes added a comment.

add test for delegating initializer and unwritten initializer


https://reviews.llvm.org/D36186

Files:
  include/clang/Tooling/ASTDiff/ASTDiff.h
  lib/Tooling/ASTDiff/ASTDiff.cpp
  test/Tooling/clang-diff-ast.cpp
  test/Tooling/clang-diff-basic.cpp
  test/Tooling/clang-diff-bottomup.cpp
  test/Tooling/clang-diff-html.test
  test/Tooling/clang-diff-opt.cpp
  test/Tooling/clang-diff-topdown.cpp
  tools/clang-diff/ClangDiff.cpp

Index: tools/clang-diff/ClangDiff.cpp
===
--- tools/clang-diff/ClangDiff.cpp
+++ tools/clang-diff/ClangDiff.cpp
@@ -315,6 +315,18 @@
   const diff::Node &N = Tree.getNode(Id);
   OS << "{";
   printNodeAttributes(OS, Tree, Id);
+  auto Identifier = N.getIdentifier();
+  auto QualifiedIdentifier = N.getQualifiedIdentifier();
+  if (Identifier) {
+OS << R"(,"identifier":")";
+printJsonString(OS, *Identifier);
+OS << R"(")";
+if (QualifiedIdentifier && *Identifier != *QualifiedIdentifier) {
+  OS << R"(,"qualified_identifier":")";
+  printJsonString(OS, *QualifiedIdentifier);
+  OS << R"(")";
+}
+  }
   OS << R"(,"children":[)";
   if (N.Children.size() > 0) {
 printNodeAsJson(OS, Tree, N.Children[0]);
Index: test/Tooling/clang-diff-topdown.cpp
===
--- test/Tooling/clang-diff-topdown.cpp
+++ test/Tooling/clang-diff-topdown.cpp
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -E %s > %t.src.cpp
 // RUN: %clang_cc1 -E %s > %t.dst.cpp -DDEST
-// RUN: clang-diff -dump-matches -stop-after=topdown %t.src.cpp %t.dst.cpp -- | FileCheck %s
+// RUN: clang-diff -dump-matches -stop-after=topdown %t.src.cpp %t.dst.cpp -- -std=c++11 | FileCheck %s
 //
 // Test the top-down matching of identical subtrees only.
 
Index: test/Tooling/clang-diff-opt.cpp
===
--- test/Tooling/clang-diff-opt.cpp
+++ test/Tooling/clang-diff-opt.cpp
@@ -25,7 +25,7 @@
 // CHECK-NEXT: Match NullStmt(4) to NullStmt(3)
   ; {{;}}
 }
- 
+
 void f2() {
   // Jaccard similarity = 7 / (10 + 10 - 7) >= 0.5
   // As none of the subtrees is bigger than 10 nodes, the optimal algorithm
@@ -41,4 +41,5 @@
   // CHECK: Delete NullStmt(22)
   ;; {{;;}}
 }
+ 
 #endif
Index: test/Tooling/clang-diff-html.test
===
--- test/Tooling/clang-diff-html.test
+++ test/Tooling/clang-diff-html.test
@@ -11,12 +11,12 @@
 // match, move
 // CHECK: void foo()
+// CHECK-NEXT: src::foo(void ())' class='u m'>void foo()
 
 // match
 // CHECK: void main()
+// CHECK-NEXT: src::main(void ())' class='u'>void main()
 
 // deletion
 // CHECK: 

[PATCH] D36156: [rename] Introduce symbol occurrences

2017-08-14 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman marked 5 inline comments as done.
arphaman added inline comments.



Comment at: include/clang/Tooling/Refactoring/Rename/SymbolName.h:19
+namespace clang {
+namespace tooling {
+

hokein wrote:
> An off-topic thought: currently we put everything into `clang::tooling`, I 
> think we might need a separate namespace e.g. `clang::tooling::refactoring` 
> in the future? 
That would be nice, I agree. Don't think it's in scope for this patch though, 
maybe for https://reviews.llvm.org/D36075?



Comment at: lib/Tooling/Refactoring/Rename/SymbolOccurrences.cpp:17
+
+SymbolOccurrence::SymbolOccurrence(const SymbolName &Name, OccurrenceKind Kind,
+   ArrayRef Locations)

hokein wrote:
> Shouldn't the definition be in clang::tooling namespace?
That's not necessary because of the `using namespace` directives above. Only 
standalone functions have to be defined in namespaces, out-of-line member 
function definitions don't have to follow that rule because they already have 
the class qualifier.



Comment at: lib/Tooling/Refactoring/Rename/USRLocFinder.cpp:398
   Visitor.TraverseDecl(Decl);
-  return Visitor.getLocationsFound();
+  return std::move(Visitor.getOccurrences());
 }

hokein wrote:
> I think just returning `Visitor.getOccurrences()` is sufficient -- compiler 
> can handle it well, also using std::move would prevent copy elision.
I'm returning by non-const reference from `getOccurrences`, so the compiler 
copies by default. I have to move either here or return by value from 
`getOccurrences` and move there. We also have warnings for redundant 
`std::move`, and they don't fire here.


Repository:
  rL LLVM

https://reviews.llvm.org/D36156



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


[PATCH] D36156: [rename] Introduce symbol occurrences

2017-08-14 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman updated this revision to Diff 110954.
arphaman marked an inline comment as done.
arphaman added a comment.

Address review comments.


Repository:
  rL LLVM

https://reviews.llvm.org/D36156

Files:
  include/clang/Tooling/Refactoring/Rename/RenamingAction.h
  include/clang/Tooling/Refactoring/Rename/SymbolName.h
  include/clang/Tooling/Refactoring/Rename/SymbolOccurrences.h
  include/clang/Tooling/Refactoring/Rename/USRLocFinder.h
  lib/Tooling/Refactoring/CMakeLists.txt
  lib/Tooling/Refactoring/Rename/RenamingAction.cpp
  lib/Tooling/Refactoring/Rename/SymbolOccurrences.cpp
  lib/Tooling/Refactoring/Rename/USRLocFinder.cpp

Index: lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
===
--- lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
+++ lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
@@ -23,6 +23,7 @@
 #include "clang/Lex/Lexer.h"
 #include "clang/Tooling/Core/Lookup.h"
 #include "clang/Tooling/Refactoring/RecursiveSymbolVisitor.h"
+#include "clang/Tooling/Refactoring/Rename/SymbolName.h"
 #include "clang/Tooling/Refactoring/Rename/USRFinder.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Casting.h"
@@ -68,11 +69,9 @@
 
   // Non-visitors:
 
-  // \brief Returns a list of unique locations. Duplicate or overlapping
-  // locations are erroneous and should be reported!
-  const std::vector &getLocationsFound() const {
-return LocationsFound;
-  }
+  /// \brief Returns a set of unique symbol occurrences. Duplicate or
+  /// overlapping occurrences are erroneous and should be reported!
+  SymbolOccurrences &getOccurrences() { return Occurrences; }
 
 private:
   void checkAndAddLocation(SourceLocation Loc) {
@@ -82,17 +81,18 @@
 StringRef TokenName =
 Lexer::getSourceText(CharSourceRange::getTokenRange(BeginLoc, EndLoc),
  Context.getSourceManager(), Context.getLangOpts());
-size_t Offset = TokenName.find(PrevName);
+size_t Offset = TokenName.find(PrevName.getNamePieces()[0]);
 
 // The token of the source location we find actually has the old
 // name.
 if (Offset != StringRef::npos)
-  LocationsFound.push_back(BeginLoc.getLocWithOffset(Offset));
+  Occurrences.emplace_back(PrevName, SymbolOccurrence::MatchingSymbol,
+   BeginLoc.getLocWithOffset(Offset));
   }
 
   const std::set USRSet;
-  const std::string PrevName;
-  std::vector LocationsFound;
+  const SymbolName PrevName;
+  SymbolOccurrences Occurrences;
   const ASTContext &Context;
 };
 
@@ -391,12 +391,11 @@
 
 } // namespace
 
-std::vector
-getLocationsOfUSRs(const std::vector &USRs, StringRef PrevName,
-   Decl *Decl) {
+SymbolOccurrences getOccurrencesOfUSRs(ArrayRef USRs,
+   StringRef PrevName, Decl *Decl) {
   USRLocFindingASTVisitor Visitor(USRs, PrevName, Decl->getASTContext());
   Visitor.TraverseDecl(Decl);
-  return Visitor.getLocationsFound();
+  return std::move(Visitor.getOccurrences());
 }
 
 std::vector
Index: lib/Tooling/Refactoring/Rename/SymbolOccurrences.cpp
===
--- /dev/null
+++ lib/Tooling/Refactoring/Rename/SymbolOccurrences.cpp
@@ -0,0 +1,37 @@
+//===--- SymbolOccurrences.cpp - Clang refactoring library ===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "clang/Tooling/Refactoring/Rename/SymbolOccurrences.h"
+#include "clang/Tooling/Refactoring/Rename/SymbolName.h"
+#include "llvm/ADT/STLExtras.h"
+
+using namespace clang;
+using namespace tooling;
+
+SymbolOccurrence::SymbolOccurrence(const SymbolName &Name, OccurrenceKind Kind,
+   ArrayRef Locations)
+: Kind(Kind) {
+  ArrayRef NamePieces = Name.getNamePieces();
+  assert(Locations.size() == NamePieces.size() &&
+ "mismatching number of locations and lengths");
+  assert(!Locations.empty() && "no locations");
+  if (Locations.size() == 1) {
+RangeOrNumRanges = SourceRange(
+Locations[0], Locations[0].getLocWithOffset(NamePieces[0].size()));
+return;
+  }
+  MultipleRanges = llvm::make_unique(Locations.size());
+  RangeOrNumRanges.setBegin(
+  SourceLocation::getFromRawEncoding(Locations.size()));
+  for (const auto &Loc : llvm::enumerate(Locations)) {
+MultipleRanges[Loc.index()] = SourceRange(
+Loc.value(),
+Loc.value().getLocWithOffset(NamePieces[Loc.index()].size()));
+  }
+}
Index: lib/Tooling/Refactoring/Rename/RenamingAction.cpp
===
--- lib/Tooling/Refactoring/Rename/RenamingAction.cpp
+++ lib/Tooling/Refactoring/Rename/RenamingAction.cpp
@@ -24,14 +24,54 @@
 #include "clang/Tool

[PATCH] D36676: Remove -finclude-default-header in OpenCL atomic tests

2017-08-14 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
Herald added a subscriber: Anastasia.

Only define enums necessary for the tests to speed up the tests.


https://reviews.llvm.org/D36676

Files:
  test/CodeGenOpenCL/atomic-ops-libcall.cl
  test/CodeGenOpenCL/atomic-ops.cl
  test/SemaOpenCL/atomic-ops.cl

Index: test/SemaOpenCL/atomic-ops.cl
===
--- test/SemaOpenCL/atomic-ops.cl
+++ test/SemaOpenCL/atomic-ops.cl
@@ -1,11 +1,32 @@
-// RUN: %clang_cc1 %s -cl-std=CL2.0 -finclude-default-header -verify -fsyntax-only -triple=spir64
-// RUN: %clang_cc1 %s -cl-std=CL2.0 -finclude-default-header -verify -fsyntax-only -triple=amdgcn-amdhsa-amd-opencl
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -fsyntax-only -triple=spir64
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -fsyntax-only -triple=amdgcn-amdhsa-amd-opencl
 
 // Basic parsing/Sema tests for __opencl_atomic_*
 
 #pragma OPENCL EXTENSION cl_khr_int64_base_atomics : enable
 #pragma OPENCL EXTENSION cl_khr_int64_extended_atomics : enable
 
+typedef __INTPTR_TYPE__ intptr_t;
+typedef int int8 __attribute__((ext_vector_type(8)));
+
+typedef enum memory_order {
+  memory_order_relaxed = __ATOMIC_RELAXED,
+  memory_order_acquire = __ATOMIC_ACQUIRE,
+  memory_order_release = __ATOMIC_RELEASE,
+  memory_order_acq_rel = __ATOMIC_ACQ_REL,
+  memory_order_seq_cst = __ATOMIC_SEQ_CST
+} memory_order;
+
+typedef enum memory_scope {
+  memory_scope_work_item = __OPENCL_MEMORY_SCOPE_WORK_ITEM,
+  memory_scope_work_group = __OPENCL_MEMORY_SCOPE_WORK_GROUP,
+  memory_scope_device = __OPENCL_MEMORY_SCOPE_DEVICE,
+  memory_scope_all_svm_devices = __OPENCL_MEMORY_SCOPE_ALL_SVM_DEVICES,
+#if defined(cl_intel_subgroups) || defined(cl_khr_subgroups)
+  memory_scope_sub_group = __OPENCL_MEMORY_SCOPE_SUB_GROUP
+#endif
+} memory_scope;
+
 struct S { char c[3]; };
 
 char i8;
@@ -170,5 +191,5 @@
 
 void nullPointerWarning(atomic_int *Ap, int *p, int val) {
   // The 'expected' pointer shouldn't be NULL.
-  (void)__opencl_atomic_compare_exchange_strong(Ap, NULL, val, memory_order_relaxed, memory_order_relaxed, memory_scope_work_group); // expected-warning {{null passed to a callee that requires a non-null argument}}
+  (void)__opencl_atomic_compare_exchange_strong(Ap, (void *)0, val, memory_order_relaxed, memory_order_relaxed, memory_scope_work_group); // expected-warning {{null passed to a callee that requires a non-null argument}}
 }
Index: test/CodeGenOpenCL/atomic-ops.cl
===
--- test/CodeGenOpenCL/atomic-ops.cl
+++ test/CodeGenOpenCL/atomic-ops.cl
@@ -1,12 +1,33 @@
-// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -finclude-default-header -O0 -o - -triple=amdgcn-amd-amdhsa-opencl | FileCheck %s
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -O0 -o - -triple=amdgcn-amd-amdhsa-opencl | FileCheck %s
 
 // Also test serialization of atomic operations here, to avoid duplicating the test.
-// RUN: %clang_cc1 %s -cl-std=CL2.0 -finclude-default-header -emit-pch -O0 -o %t -triple=amdgcn-amd-amdhsa-opencl
-// RUN: %clang_cc1 %s -cl-std=CL2.0 -finclude-default-header -include-pch %t -O0 -triple=amdgcn-amd-amdhsa-opencl -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-pch -O0 -o %t -triple=amdgcn-amd-amdhsa-opencl
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -include-pch %t -O0 -triple=amdgcn-amd-amdhsa-opencl -emit-llvm -o - | FileCheck %s
 
 #ifndef ALREADY_INCLUDED
 #define ALREADY_INCLUDED
 
+typedef __INTPTR_TYPE__ intptr_t;
+typedef int int8 __attribute__((ext_vector_type(8)));
+
+typedef enum memory_order {
+  memory_order_relaxed = __ATOMIC_RELAXED,
+  memory_order_acquire = __ATOMIC_ACQUIRE,
+  memory_order_release = __ATOMIC_RELEASE,
+  memory_order_acq_rel = __ATOMIC_ACQ_REL,
+  memory_order_seq_cst = __ATOMIC_SEQ_CST
+} memory_order;
+
+typedef enum memory_scope {
+  memory_scope_work_item = __OPENCL_MEMORY_SCOPE_WORK_ITEM,
+  memory_scope_work_group = __OPENCL_MEMORY_SCOPE_WORK_GROUP,
+  memory_scope_device = __OPENCL_MEMORY_SCOPE_DEVICE,
+  memory_scope_all_svm_devices = __OPENCL_MEMORY_SCOPE_ALL_SVM_DEVICES,
+#if defined(cl_intel_subgroups) || defined(cl_khr_subgroups)
+  memory_scope_sub_group = __OPENCL_MEMORY_SCOPE_SUB_GROUP
+#endif
+} memory_scope;
+
 atomic_int j;
 
 void fi1(atomic_int *i) {
Index: test/CodeGenOpenCL/atomic-ops-libcall.cl
===
--- test/CodeGenOpenCL/atomic-ops-libcall.cl
+++ test/CodeGenOpenCL/atomic-ops-libcall.cl
@@ -1,5 +1,22 @@
-// RUN: %clang_cc1 < %s -cl-std=CL2.0 -finclude-default-header -triple spir64 -emit-llvm | FileCheck -check-prefix=SPIR %s
-// RUN: %clang_cc1 < %s -cl-std=CL2.0 -finclude-default-header -triple armv5e-none-linux-gnueabi -emit-llvm | FileCheck -check-prefix=ARM %s
+// RUN: %clang_cc1 < %s -cl-std=CL2.0 -triple spir64 -emit-llvm | FileCheck -check-prefix=SPIR %s
+// RUN: %clang_cc1 < %s -cl-std=CL2.0 -triple armv5e-none-linux-gnueabi -emit-llvm | F

[PATCH] D36678: [OpenCL] Do not use vararg in emitted functions for enqueue_kernel

2017-08-14 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
Herald added a subscriber: tpr.

Not all targets support vararg (e.g. amdgpu). Instead of using vararg in the 
emitted functions for enqueue_kernel,
this patch creates a temporary array of size_t, stores the size arguments in 
the temporary array
and passes it to the emitted functions for enqueue_kernel.


https://reviews.llvm.org/D36678

Files:
  lib/CodeGen/CGBuiltin.cpp
  test/CodeGenOpenCL/cl20-device-side-enqueue.cl

Index: test/CodeGenOpenCL/cl20-device-side-enqueue.cl
===
--- test/CodeGenOpenCL/cl20-device-side-enqueue.cl
+++ test/CodeGenOpenCL/cl20-device-side-enqueue.cl
@@ -49,8 +49,8 @@
 
   // COMMON: [[DEF_Q:%[0-9]+]] = load %opencl.queue_t{{.*}}*, %opencl.queue_t{{.*}}** %default_queue
   // COMMON: [[FLAGS:%[0-9]+]] = load i32, i32* %flags
-  // B32: call i32 (%opencl.queue_t{{.*}}*, i32, %struct.ndrange_t*, i8 addrspace(4)*, i32, ...) @__enqueue_kernel_vaargs(%opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]], %struct.ndrange_t* [[NDR]]{{(.[0-9]+)?}}, i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i8**, i32, i32, i8*, %struct.__block_descriptor addrspace(2)* } addrspace(1)* @__block_literal_global{{(.[0-9]+)?}} to i8 addrspace(1)*) to i8 addrspace(4)*), i32 1, i32 256)
-  // B64: call i32 (%opencl.queue_t{{.*}}*, i32, %struct.ndrange_t*, i8 addrspace(4)*, i32, ...) @__enqueue_kernel_vaargs(%opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]], %struct.ndrange_t* [[NDR]]{{(.[0-9]+)?}}, i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i8**, i32, i32, i8*, %struct.__block_descriptor addrspace(2)* } addrspace(1)* @__block_literal_global{{(.[0-9]+)?}} to i8 addrspace(1)*) to i8 addrspace(4)*), i32 1, i64 256)
+  // B32: call i32 @__enqueue_kernel_vaargs(%opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]], %struct.ndrange_t* [[NDR]]{{(.[0-9]+)?}}, i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i8**, i32, i32, i8*, %struct.__block_descriptor addrspace(2)* } addrspace(1)* @__block_literal_global{{(.[0-9]+)?}} to i8 addrspace(1)*) to i8 addrspace(4)*), i32 1, i32* {{.*}})
+  // B64: call i32 @__enqueue_kernel_vaargs(%opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]], %struct.ndrange_t* [[NDR]]{{(.[0-9]+)?}}, i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i8**, i32, i32, i8*, %struct.__block_descriptor addrspace(2)* } addrspace(1)* @__block_literal_global{{(.[0-9]+)?}} to i8 addrspace(1)*) to i8 addrspace(4)*), i32 1, i64* {{.*}})
   enqueue_kernel(default_queue, flags, ndrange,
  ^(local void *p) {
return;
@@ -60,9 +60,9 @@
   // COMMON: [[DEF_Q:%[0-9]+]] = load %opencl.queue_t{{.*}}*, %opencl.queue_t{{.*}}** %default_queue
   // COMMON: [[FLAGS:%[0-9]+]] = load i32, i32* %flags
   // B32: [[SIZE:%[0-9]+]] = zext i8 {{%[0-9]+}} to i32
-  // B32: call i32 (%opencl.queue_t{{.*}}*, i32, %struct.ndrange_t*, i8 addrspace(4)*, i32, ...) @__enqueue_kernel_vaargs(%opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]], %struct.ndrange_t* [[NDR]]{{(.[0-9]+)?}}, i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i8**, i32, i32, i8*, %struct.__block_descriptor addrspace(2)* } addrspace(1)* @__block_literal_global{{(.[0-9]+)?}} to i8 addrspace(1)*) to i8 addrspace(4)*), i32 1, i32 [[SIZE]])
+  // B32: call i32 @__enqueue_kernel_vaargs(%opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]], %struct.ndrange_t* [[NDR]]{{(.[0-9]+)?}}, i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i8**, i32, i32, i8*, %struct.__block_descriptor addrspace(2)* } addrspace(1)* @__block_literal_global{{(.[0-9]+)?}} to i8 addrspace(1)*) to i8 addrspace(4)*), i32 1, i32* {{.*}})
   // B64: [[SIZE:%[0-9]+]] = zext i8 {{%[0-9]+}} to i64
-  // B64: call i32 (%opencl.queue_t{{.*}}*, i32, %struct.ndrange_t*, i8 addrspace(4)*, i32, ...) @__enqueue_kernel_vaargs(%opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]], %struct.ndrange_t* [[NDR]]{{(.[0-9]+)?}}, i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i8**, i32, i32, i8*, %struct.__block_descriptor addrspace(2)* } addrspace(1)* @__block_literal_global{{(.[0-9]+)?}} to i8 addrspace(1)*) to i8 addrspace(4)*), i32 1, i64 [[SIZE]])
+  // B64: call i32 @__enqueue_kernel_vaargs(%opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]], %struct.ndrange_t* [[NDR]]{{(.[0-9]+)?}}, i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i8**, i32, i32, i8*, %struct.__block_descriptor addrspace(2)* } addrspace(1)* @__block_literal_global{{(.[0-9]+)?}} to i8 addrspace(1)*) to i8 addrspace(4)*), i32 1, i64* {{.*}})
   enqueue_kernel(default_queue, flags, ndrange,
  ^(local void *p) {
return;
@@ -74,8 +74,8 @@
   // COMMON: [[AD:%arraydecay[0-9]*]] = getelementptr inbounds [1 x %opencl.clk_event_t*], [1 x %opencl.clk_event_t*]* %event_wait_list2, i32 0, i32 0
   // COMMON: [[WAIT_EVNT:%[0-9]+]] = addrspacecast %opencl.clk_event_t{{.*}}** [[AD]] to %opencl.clk_event_t{{.*}}* addrspace(4)*
   // COMMON: [[

[PATCH] D36142: clang-format: [JS] do not insert whitespace in call positions.

2017-08-14 Thread Martin Probst via Phabricator via cfe-commits
mprobst updated this revision to Diff 110959.
mprobst marked 2 inline comments as done.
mprobst added a comment.

- clean up implementation, just use getIdentifierInfo
- clean up tests, remove illegal syntax, add more tests


https://reviews.llvm.org/D36142

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTestJS.cpp


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -271,14 +271,21 @@
   verifyFormat("x.case = 1;");
   verifyFormat("x.interface = 1;");
   verifyFormat("x.for = 1;");
-  verifyFormat("x.of() = 1;");
+  verifyFormat("x.of();");
   verifyFormat("of(null);");
   verifyFormat("import {of} from 'x';");
-  verifyFormat("x.in() = 1;");
-  verifyFormat("x.let() = 1;");
-  verifyFormat("x.var() = 1;");
-  verifyFormat("x.for() = 1;");
-  verifyFormat("x.as() = 1;");
+  verifyFormat("x.in();");
+  verifyFormat("x.let();");
+  verifyFormat("x.var();");
+  verifyFormat("x.for();");
+  verifyFormat("x.as();");
+  verifyFormat("x.instanceof();");
+  verifyFormat("x.switch();");
+  verifyFormat("x.case();");
+  verifyFormat("x.delete();");
+  verifyFormat("x.throw();");
+  verifyFormat("x.throws();");
+  verifyFormat("x.if();");
   verifyFormat("x = {\n"
"  a: 12,\n"
"  interface: 1,\n"
@@ -1228,7 +1235,6 @@
   // But, of course, "catch" is a perfectly fine function name in JavaScript.
   verifyFormat("someObject.catch();");
   verifyFormat("someObject.new();");
-  verifyFormat("someObject.delete();");
 }
 
 TEST_F(FormatTestJS, StringLiteralConcatenation) {
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2367,13 +2367,20 @@
 Left.isOneOf(Keywords.kw_function, Keywords.kw_yield,
  Keywords.kw_extends, Keywords.kw_implements))
   return true;
-// JS methods can use some keywords as names (e.g. `delete()`).
-if (Right.is(tok::l_paren) && Line.MustBeDeclaration &&
-Left.Tok.getIdentifierInfo())
-  return false;
-if (Right.is(tok::l_paren) &&
-Left.isOneOf(tok::kw_throw, Keywords.kw_await, Keywords.kw_typeof, 
tok::kw_void))
-  return true;
+if (Right.is(tok::l_paren)) {
+  // JS methods can use some keywords as names (e.g. `delete()`).
+  if (Line.MustBeDeclaration && Left.Tok.getIdentifierInfo())
+return false;
+  // Valid JS method names can include keywords, e.g. `foo.delete()` or
+  // `bar.instanceof()`. Recognize call positions by preceding period.
+  if (Left.Previous && Left.Previous->is(tok::period) &&
+  Left.Tok.getIdentifierInfo())
+return false;
+  // Additional unary JavaScript operators that need a space after.
+  if (Left.isOneOf(tok::kw_throw, Keywords.kw_await, Keywords.kw_typeof,
+   tok::kw_void))
+return true;
+}
 if ((Left.isOneOf(Keywords.kw_let, Keywords.kw_var, Keywords.kw_in,
   tok::kw_const) ||
  // "of" is only a keyword if it appears after another identifier


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -271,14 +271,21 @@
   verifyFormat("x.case = 1;");
   verifyFormat("x.interface = 1;");
   verifyFormat("x.for = 1;");
-  verifyFormat("x.of() = 1;");
+  verifyFormat("x.of();");
   verifyFormat("of(null);");
   verifyFormat("import {of} from 'x';");
-  verifyFormat("x.in() = 1;");
-  verifyFormat("x.let() = 1;");
-  verifyFormat("x.var() = 1;");
-  verifyFormat("x.for() = 1;");
-  verifyFormat("x.as() = 1;");
+  verifyFormat("x.in();");
+  verifyFormat("x.let();");
+  verifyFormat("x.var();");
+  verifyFormat("x.for();");
+  verifyFormat("x.as();");
+  verifyFormat("x.instanceof();");
+  verifyFormat("x.switch();");
+  verifyFormat("x.case();");
+  verifyFormat("x.delete();");
+  verifyFormat("x.throw();");
+  verifyFormat("x.throws();");
+  verifyFormat("x.if();");
   verifyFormat("x = {\n"
"  a: 12,\n"
"  interface: 1,\n"
@@ -1228,7 +1235,6 @@
   // But, of course, "catch" is a perfectly fine function name in JavaScript.
   verifyFormat("someObject.catch();");
   verifyFormat("someObject.new();");
-  verifyFormat("someObject.delete();");
 }
 
 TEST_F(FormatTestJS, StringLiteralConcatenation) {
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2367,13 +2367,20 @@
 Left.isOneOf(Keywords.kw_function, Keywords.kw_yield,
  Keywords.kw_extends, Keywords.kw_implements))
   return true;
-// JS methods can use some keywords as names (e.g. `delete()`).
-if 

[PATCH] D36142: clang-format: [JS] do not insert whitespace in call positions.

2017-08-14 Thread Martin Probst via Phabricator via cfe-commits
mprobst added inline comments.



Comment at: lib/Format/TokenAnnotator.cpp:2355
+(Left.Tok.getIdentifierInfo() ||
+ Left.isOneOf(tok::kw_switch, tok::kw_case, tok::kw_delete)))
+  return false;

djasper wrote:
> Why is instanceof not required in this list?
`instanceof` is not a keyword in the C++ sense, so it is covered by the 
`getIdentifierInfo` part. But this was actually a misunderstanding - 
`getIdentifierInfo` actually covers all keyword-ish tokens, so we don't need 
the list of tokens here at all.


https://reviews.llvm.org/D36142



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


[PATCH] D36327: [OpenCL] Allow targets emit optimized pipe functions for power of 2 type sizes

2017-08-14 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In https://reviews.llvm.org/D36327#839809, @rjmccall wrote:

> Could you just implement this in SimplifyLibCalls?  I assume there's some way 
> to fill in TargetLibraryInfo appropriately for a platform.  Is that too late 
> for your linking requirements?


Both the optimized and generic versions of __read_pipe function contains call 
of other library functions and are complicate enough not to be generated 
programmatically. amdgpu target does not have the capability to link in library 
code after LLVM codegen. The linking has to be done before SimplifyLibCalls.


https://reviews.llvm.org/D36327



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


[PATCH] D36676: Remove -finclude-default-header in OpenCL atomic tests

2017-08-14 Thread Alexey Bader via Phabricator via cfe-commits
bader accepted this revision.
bader added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks.


https://reviews.llvm.org/D36676



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


[PATCH] D36564: [analyzer] Fix SimpleSValBuilder::simplifySVal

2017-08-14 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Hmm, looks correct. Thanks! I guess this problem appeared when we enabled 
`SymSymExpr`s, otherwise `(End - Begin)` would have been `UnknownVal`.


Repository:
  rL LLVM

https://reviews.llvm.org/D36564



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


Re: r310401 - PR19668, PR23034: Fix handling of move constructors and deleted copy

2017-08-14 Thread Vassil Vassilev via cfe-commits

On 14/08/17 13:04, Diana Picus wrote:

See attached.
Thanks! It looks like asan_test.i doesn't have gtest.cc which appears in 
the stack trace. Am I missing something?


On 14 August 2017 at 13:30, Vassil Vassilev  wrote:

On 14/08/17 11:27, Diana Picus wrote:

Hi,

Strangely enough, it turns out that if I run
Asan-armhf-with-calls-Noinst-Test on the command line it fails,
although it doesn't fail when run with lit. I've attached the stack
trace from gdb. It looks like some trouble passing down va_arg
parameters, but I haven't looked into too much details. The segfault
happens when we try to do a   ldrb   r3, [r0, r1], with r1 set to 0 by
the current function and r0 passed down from the caller. I'm not sure
if this is the exact same problem as the other tests, but feel free to
have a look at that code.

Meanwhile, I've removed some clutter from Asan-armhf-with-calls-Test
(which is the original failure that we were seeing) and left only one
failing test that seemed small enough. I'll try to look at the
disassembly before/after the patch and maybe even run valgrind on it
(running it on the original binary naturally takes forever).

Let me know if there's anything else I could try. I can also send you
disassembly or even LLVM IR for the Asan-armhf-with-calls-Noinst-Test
if you think it helps.

   disassembly and LLVM will greatly help as well.


Cheers,
Diana

On 11 August 2017 at 15:34, Diana Picus  wrote:

Well, these are ASAN tests, I'm not sure how that would interact with
Valgrind.
Anyway, I'll try to reproduce the environment, I'm guessing it would
be best to catch this in gdb so I can actually see what's going on.

On 11 August 2017 at 15:21, Vassil Vassilev 
wrote:

That's really strange. It looks like some random behavior. Did you run
some memory checker like valgrind?

Do the environment provided by the test runner and yours match?

Sent from my phone. Please excuse my brevity.


On 11 Aug 2017, at 15:58, Diana Picus  wrote:

Hi again,

I finally got the debug build, but unfortunately the stack traces that
the tests print look the same. My suspicion is that this is because
the addresses printed by the tests are funny (i.e. odd numbers instead
of divisible by 4). I tried to follow those addresses in an objdump of
the executable, but I didn't have much success since most of them
weren't really pointing to call instructions.

When I try to run the tests manually in the shell or in gdb, they pass.

I'm not sure what else to try. Thoughts?

Thanks,
Diana


On 11 August 2017 at 11:14, Diana Picus 
wrote:
Hi guys,

I'm SO sorry about the delays. I've been having all sorts of trouble
getting that debug build on the board (from ld running out of memory
to the board just crashing on me, in which case I need to ask someone
else to reboot it because I can't power cycle it remotely). I can
assure you this is one of my top priorities, I'll get those stack
traces as soon as I can.

Thanks for your patience and sorry again,
Diana


On 10 August 2017 at 22:55, Richard Smith 
wrote:
Any news on this? We want this change in Clang 5, so the sooner we
can
understand and fix this regression the better...

On 10 August 2017 at 01:28, Diana Picus via cfe-commits
 wrote:

Hi Vassil,

My build is in progress, but since it's a full build it's probably
going to take another couple of hours to complete. I'll let you know
when it's done.

Thanks,
Diana

On 10 August 2017 at 10:09, Vassil Vassilev 
wrote:

It looks like I can not reproduce it on osx (non-arm)... :(

On 09/08/17 22:54, Diana Picus wrote:

Reverting this also fixed the selfhost bots:



http://lab.llvm.org:8011/builders/clang-cmake-thumbv7-a15-full-sh/builds/2142



http://lab.llvm.org:8011/builders/clang-cmake-armv7-a15-selfhost/builds/2309



http://lab.llvm.org:8011/builders/clang-cmake-armv7-a15-selfhost-neon/builds/1819

I'm afraid the logs for those look even less helpful.


On 9 August 2017 at 16:17, Diana Picus 
wrote:

Hi,

See attached. FWIW, when I ran this on a very similar machine, I
got
194 failures, all of which went away after reverting. So there
might
be something fishy going on.

Regards,
Diana

On 9 August 2017 at 15:02, Vassil Vassilev

wrote:

Hi Diana,

It seems the service is down. Could you send us the details
of the
failures (incl stack traces if any)

Many thanks,
Vassil


On 09/08/17 15:27, Diana Picus via cfe-commits wrote:

Hi Richard,

I'm sorry but I've reverted this in r310464 because it was
breaking
some ASAN tests on this bot:



http://lab.llvm.org:8011/builders/clang-cmake-armv7-a15-full/builds/9452

Please let me know if I can help debug this.

Cheers,
Diana

On 8 August 2017 at 21:14, Richard Smith via cfe-commits
 wrote:

I forgot to say:

Based on a patch by Vassil Vassilev, which was based on a
patch by
Bernd
Schmidt, which was based on a patch by Reid Kleckner.

On 8 August 2017 at 12:12, Richard Smith via cfe-commits
 wrote:

Author: rsmith
Date: Tue Aug  8 12:12:28 2017
New Revision: 310401

URL: http://llvm.org/view

r310837 - Fixes a typo in a comment; NFC.

2017-08-14 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Mon Aug 14 07:16:00 2017
New Revision: 310837

URL: http://llvm.org/viewvc/llvm-project?rev=310837&view=rev
Log:
Fixes a typo in a comment; NFC.

Modified:
cfe/trunk/include/clang/AST/ASTContext.h

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=310837&r1=310836&r2=310837&view=diff
==
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Mon Aug 14 07:16:00 2017
@@ -465,7 +465,7 @@ private:
   mutable BuiltinTemplateDecl *MakeIntegerSeqDecl;
   mutable BuiltinTemplateDecl *TypePackElementDecl;
 
-  /// \brief The associated SourceManager object.a
+  /// \brief The associated SourceManager object.
   SourceManager &SourceMgr;
 
   /// \brief The language options used to create the AST associated with


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


[PATCH] D36156: [rename] Introduce symbol occurrences

2017-08-14 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: lib/Tooling/Refactoring/Rename/SymbolOccurrences.cpp:17
+
+SymbolOccurrence::SymbolOccurrence(const SymbolName &Name, OccurrenceKind Kind,
+   ArrayRef Locations)

arphaman wrote:
> hokein wrote:
> > Shouldn't the definition be in clang::tooling namespace?
> That's not necessary because of the `using namespace` directives above. Only 
> standalone functions have to be defined in namespaces, out-of-line member 
> function definitions don't have to follow that rule because they already have 
> the class qualifier.
Ah, I see, thanks for the explanation. The constructor actually lives in 
"SymbolOccurrence". T

I'd like to use a more familiar way: `namespace clang { namespace tooling { ... 
} }` 



Comment at: lib/Tooling/Refactoring/Rename/USRLocFinder.cpp:398
   Visitor.TraverseDecl(Decl);
-  return Visitor.getLocationsFound();
+  return std::move(Visitor.getOccurrences());
 }

arphaman wrote:
> hokein wrote:
> > I think just returning `Visitor.getOccurrences()` is sufficient -- compiler 
> > can handle it well, also using std::move would prevent copy elision.
> I'm returning by non-const reference from `getOccurrences`, so the compiler 
> copies by default. I have to move either here or return by value from 
> `getOccurrences` and move there. We also have warnings for redundant 
> `std::move`, and they don't fire here.
Ok, didn't notice that `getOccurance()` returns non-const reference.

I think the method `getOccurances` may have potential effect -- the clients 
could change the Occurences member variable of USRLocFindingASTVisitor, after 
getting the non-const reference.

Another option is to rename `getOccurances` to `takeOccurrences` and return by 
value:

```
SymbolOccurrences takeOccurrences() { return std::move(Occurrences); }
```

What do you think?


Repository:
  rL LLVM

https://reviews.llvm.org/D36156



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


r310838 - [Parse] Fix typo in header docs (NFC)

2017-08-14 Thread Brian Gesiak via cfe-commits
Author: modocache
Date: Mon Aug 14 07:29:11 2017
New Revision: 310838

URL: http://llvm.org/viewvc/llvm-project?rev=310838&view=rev
Log:
[Parse] Fix typo in header docs (NFC)

Summary:
Fix typo "delcarations", added in rL310609 and rL310627.


Modified:
cfe/trunk/include/clang/Parse/ParseAST.h
cfe/trunk/include/clang/Parse/Parser.h

Modified: cfe/trunk/include/clang/Parse/ParseAST.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/ParseAST.h?rev=310838&r1=310837&r2=310838&view=diff
==
--- cfe/trunk/include/clang/Parse/ParseAST.h (original)
+++ cfe/trunk/include/clang/Parse/ParseAST.h Mon Aug 14 07:29:11 2017
@@ -35,7 +35,7 @@ namespace clang {
   /// results.
   /// \param SkipFunctionBodies Whether to skip parsing of function bodies.
   /// This option can be used, for example, to speed up searches for
-  /// delcarations/definitions when indexing.
+  /// declarations/definitions when indexing.
   void ParseAST(Preprocessor &pp, ASTConsumer *C,
 ASTContext &Ctx, bool PrintStats = false,
 TranslationUnitKind TUKind = TU_Complete,

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=310838&r1=310837&r2=310838&view=diff
==
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Mon Aug 14 07:29:11 2017
@@ -256,7 +256,7 @@ class Parser : public CodeCompletionHand
   /// Whether to skip parsing of function bodies.
   ///
   /// This option can be used, for example, to speed up searches for
-  /// delcarations/definitions when indexing.
+  /// declarations/definitions when indexing.
   bool SkipFunctionBodies;
 
   /// The location of the expression statement that is being parsed right now.


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


[PATCH] D36186: [clang-diff] Improve and test getNodeValue

2017-08-14 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman accepted this revision.
arphaman added a comment.
This revision is now accepted and ready to land.

Perfect, thanks!


https://reviews.llvm.org/D36186



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


[PATCH] D36327: [OpenCL] Allow targets emit optimized pipe functions for power of 2 type sizes

2017-08-14 Thread Alexey Bader via Phabricator via cfe-commits
bader added a comment.

In https://reviews.llvm.org/D36327#840616, @yaxunl wrote:

> In https://reviews.llvm.org/D36327#839809, @rjmccall wrote:
>
> > Could you just implement this in SimplifyLibCalls?  I assume there's some 
> > way to fill in TargetLibraryInfo appropriately for a platform.  Is that too 
> > late for your linking requirements?
>
>
> Both the optimized and generic versions of __read_pipe function contains call 
> of other library functions and are complicate enough not to be generated 
> programmatically. amdgpu target does not have the capability to link in 
> library code after LLVM codegen. The linking has to be done before 
> SimplifyLibCalls.


If I understand correctly, SimplifyLibCalls is LLVM IR transformation, so it 
works before linking and LLVM codegen (e.g. InstCombine passes run this 
transformation). This pass is doing something similar to what you are trying to 
achieve for __read_pipe builti-ins: pow(2.0, x) -> llvm.exp2(x).


https://reviews.llvm.org/D36327



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


Buildmaster reconfig

2017-08-14 Thread Victor Leschuk via cfe-commits
Hello everyone,
LLVM buildmaster was updated and restarted, downtime was about 2 minutes.

-- 
Best Regards,

Victor Leschuk | Software Engineer |Access Softek

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


[PATCH] D36187: [clang-diff] Use the relative name for NamedDecls

2017-08-14 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

Please rebase, it doesn't apply cleanly anymore.


https://reviews.llvm.org/D36187



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


[PATCH] D36187: [clang-diff] Use the relative name for NamedDecls

2017-08-14 Thread Johannes Altmanninger via Phabricator via cfe-commits
johannes updated this revision to Diff 110962.
johannes added a comment.

rebase


https://reviews.llvm.org/D36187

Files:
  include/clang/Tooling/ASTDiff/ASTDiff.h
  lib/Tooling/ASTDiff/ASTDiff.cpp
  test/Tooling/clang-diff-ast.cpp
  test/Tooling/clang-diff-basic.cpp
  test/Tooling/clang-diff-html.test
  test/Tooling/clang-diff-topdown.cpp

Index: test/Tooling/clang-diff-topdown.cpp
===
--- test/Tooling/clang-diff-topdown.cpp
+++ test/Tooling/clang-diff-topdown.cpp
@@ -27,8 +27,19 @@
   {{;;}}
 }
 
+int x;
+
+namespace src {
+  int x;
+  int x1 = x + 1;
+  int x2 = ::x + 1;
+}
+
+class A { int x = 1 + 1; void f() { int x1 = x; } };
+
 #else
 
+
 void f1() {
 
   {{;}}
@@ -45,4 +56,28 @@
   ;
 }
 
+int x;
+
+namespace dst {
+  int x;
+  // CHECK: Match DeclRefExpr: :x(17) to DeclRefExpr: :x(22)
+  int x1 = x + 1;
+  // CHECK: Match DeclRefExpr: x(21) to DeclRefExpr: x(26)
+  int x2 = ::x + 1;
+}
+
+class B {
+  // Only the class name changed; it is not included in the field value,
+  // therefore there is no update.
+  // CHECK: Match FieldDecl: :x(int)(24) to FieldDecl: :x(int)(29)
+  // CHECK-NOT: Update FieldDecl: :x(int)(24)
+  int x = 1+1;
+  void f() {
+// CHECK: Match MemberExpr: :x(32) to MemberExpr: :x(37)
+// CHECK-NOT: Update MemberExpr: :x(32)
+int x1 = B::x;
+  }
+
+};
+
 #endif
Index: test/Tooling/clang-diff-html.test
===
--- test/Tooling/clang-diff-html.test
+++ test/Tooling/clang-diff-html.test
@@ -11,12 +11,12 @@
 // match, move
 // CHECK: void foo()
+// CHECK-NEXT: :foo(void ())' class='m'>void foo()
 
 // match
 // CHECK: void main()
+// CHECK-NEXT: :main(void ())'>void main()
 
 // deletion
 // CHECK: (Context))
+ContextPrefix = Namespace->getQualifiedNameAsString();
+  else if (auto *Tag = dyn_cast(Context))
+ContextPrefix = Tag->getQualifiedNameAsString();
+  std::string Val = ND->getQualifiedNameAsString();
+  // Strip the qualifier, if Val refers to somthing in the current scope.
+  // But leave one leading ':' in place, so that we know that this is a
+  // relative path.
+  if (!ContextPrefix.empty() &&
+  StringRef(Val).startswith(ContextPrefix))
+Val = Val.substr(ContextPrefix.size() + 1);
+  return Val;
+}
+
+static std::string getRelativeName(const NamedDecl *ND) {
+  return getRelativeName(ND, ND->getDeclContext());
+}
+
+static const DeclContext *getEnclosingDeclContext(ASTContext &AST,
+  const Stmt *S) {
+  while (S) {
+const auto &Parents = AST.getParents(*S);
+if (Parents.empty())
+  return nullptr;
+const auto &P = Parents[0];
+if (const auto *D = P.get())
+  return D->getDeclContext();
+S = P.get();
+  }
+  llvm_unreachable("Could not find Decl ancestor.");
+}
+
 std::string SyntaxTree::Impl::getNodeValue(NodeId Id) const {
   return getNodeValue(getNode(Id));
 }
@@ -384,8 +419,7 @@
   TypePP.AnonymousTagLocations = false;
 
   if (auto *V = dyn_cast(D)) {
-Value += V->getQualifiedNameAsString() + "(" +
- V->getType().getAsString(TypePP) + ")";
+Value += getRelativeName(V) + "(" + V->getType().getAsString(TypePP) + ")";
 if (auto *C = dyn_cast(D)) {
   for (auto *Init : C->inits()) {
 if (!Init->isWritten())
@@ -397,15 +431,15 @@
   Value += C->getNameAsString();
 } else {
   assert(Init->isAnyMemberInitializer());
-  Value += Init->getMember()->getQualifiedNameAsString();
+  Value += getRelativeName(Init->getMember());
 }
 Value += ",";
   }
 }
 return Value;
   }
   if (auto *N = dyn_cast(D))
-Value += N->getQualifiedNameAsString() + ";";
+Value += getRelativeName(N) + ";";
   if (auto *T = dyn_cast(D))
 return Value + T->getUnderlyingType().getAsString(TypePP) + ";";
   if (auto *T = dyn_cast(D))
@@ -429,7 +463,7 @@
   if (auto *B = dyn_cast(S))
 return B->getOpcodeStr();
   if (auto *M = dyn_cast(S))
-return M->getMemberDecl()->getQualifiedNameAsString();
+return getRelativeName(M->getMemberDecl());
   if (auto *I = dyn_cast(S)) {
 SmallString<256> Str;
 I->getValue().toString(Str, /*Radix=*/10, /*Signed=*/false);
@@ -441,7 +475,7 @@
 return Str.str();
   }
   if (auto *D = dyn_cast(S))
-return D->getDecl()->getQualifiedNameAsString();
+return getRelativeName(D->getDecl(), getEnclosingDeclContext(AST, S));
   if (auto *String = dyn_cast(S))
 return String->getString();
   if (auto *B = dyn_cast(S))
@@ -950,7 +984,7 @@
   return DiffImpl->getMapped(SourceTree.TreeImpl, Id);
 }
 
-SyntaxTree::SyntaxTree(const ASTContext &AST)
+SyntaxTree::SyntaxTree(ASTContext &AST)
 : TreeImpl(llvm::make_unique(
   this, AST.getTranslationUnitDecl(), AST)) {}
 
Index: include/clang/Tooling/ASTDiff/ASTDiff.h
===
--- include/clang/Too

Re: r310401 - PR19668, PR23034: Fix handling of move constructors and deleted copy

2017-08-14 Thread Vassil Vassilev via cfe-commits

On 14/08/17 15:08, Vassil Vassilev wrote:

On 14/08/17 13:04, Diana Picus wrote:

See attached.
Thanks! It looks like asan_test.i doesn't have gtest.cc which appears 
in the stack trace. Am I missing something?
  Could you paste the compiler invocation. Are we building with -O0 (I 
see quite a lot of things inline). Could it be an optimizer problem?


On 14 August 2017 at 13:30, Vassil Vassilev  
wrote:

On 14/08/17 11:27, Diana Picus wrote:

Hi,

Strangely enough, it turns out that if I run
Asan-armhf-with-calls-Noinst-Test on the command line it fails,
although it doesn't fail when run with lit. I've attached the stack
trace from gdb. It looks like some trouble passing down va_arg
parameters, but I haven't looked into too much details. The segfault
happens when we try to do a   ldrb   r3, [r0, r1], with r1 set to 0 by
the current function and r0 passed down from the caller. I'm not sure
if this is the exact same problem as the other tests, but feel free to
have a look at that code.

Meanwhile, I've removed some clutter from Asan-armhf-with-calls-Test
(which is the original failure that we were seeing) and left only one
failing test that seemed small enough. I'll try to look at the
disassembly before/after the patch and maybe even run valgrind on it
(running it on the original binary naturally takes forever).

Let me know if there's anything else I could try. I can also send you
disassembly or even LLVM IR for the Asan-armhf-with-calls-Noinst-Test
if you think it helps.

   disassembly and LLVM will greatly help as well.


Cheers,
Diana

On 11 August 2017 at 15:34, Diana Picus  
wrote:

Well, these are ASAN tests, I'm not sure how that would interact with
Valgrind.
Anyway, I'll try to reproduce the environment, I'm guessing it would
be best to catch this in gdb so I can actually see what's going on.

On 11 August 2017 at 15:21, Vassil Vassilev 
wrote:
That's really strange. It looks like some random behavior. Did 
you run

some memory checker like valgrind?

Do the environment provided by the test runner and yours match?

Sent from my phone. Please excuse my brevity.

On 11 Aug 2017, at 15:58, Diana Picus  
wrote:


Hi again,

I finally got the debug build, but unfortunately the stack 
traces that

the tests print look the same. My suspicion is that this is because
the addresses printed by the tests are funny (i.e. odd numbers 
instead
of divisible by 4). I tried to follow those addresses in an 
objdump of

the executable, but I didn't have much success since most of them
weren't really pointing to call instructions.

When I try to run the tests manually in the shell or in gdb, 
they pass.


I'm not sure what else to try. Thoughts?

Thanks,
Diana


On 11 August 2017 at 11:14, Diana Picus 
wrote:
Hi guys,

I'm SO sorry about the delays. I've been having all sorts of 
trouble
getting that debug build on the board (from ld running out of 
memory
to the board just crashing on me, in which case I need to ask 
someone

else to reboot it because I can't power cycle it remotely). I can
assure you this is one of my top priorities, I'll get those stack
traces as soon as I can.

Thanks for your patience and sorry again,
Diana


On 10 August 2017 at 22:55, Richard Smith 
wrote:
Any news on this? We want this change in Clang 5, so the 
sooner we

can
understand and fix this regression the better...

On 10 August 2017 at 01:28, Diana Picus via cfe-commits
 wrote:

Hi Vassil,

My build is in progress, but since it's a full build it's 
probably
going to take another couple of hours to complete. I'll let 
you know

when it's done.

Thanks,
Diana

On 10 August 2017 at 10:09, Vassil Vassilev 


wrote:

It looks like I can not reproduce it on osx (non-arm)... :(

On 09/08/17 22:54, Diana Picus wrote:

Reverting this also fixed the selfhost bots:



http://lab.llvm.org:8011/builders/clang-cmake-thumbv7-a15-full-sh/builds/2142 





http://lab.llvm.org:8011/builders/clang-cmake-armv7-a15-selfhost/builds/2309 





http://lab.llvm.org:8011/builders/clang-cmake-armv7-a15-selfhost-neon/builds/1819 



I'm afraid the logs for those look even less helpful.

On 9 August 2017 at 16:17, Diana Picus 


wrote:

Hi,

See attached. FWIW, when I ran this on a very similar 
machine, I

got
194 failures, all of which went away after reverting. So 
there

might
be something fishy going on.

Regards,
Diana

On 9 August 2017 at 15:02, Vassil Vassilev

wrote:

Hi Diana,

It seems the service is down. Could you send us the 
details

of the
failures (incl stack traces if any)

Many thanks,
Vassil


On 09/08/17 15:27, Diana Picus via cfe-commits wrote:

Hi Richard,

I'm sorry but I've reverted this in r310464 because it was
breaking
some ASAN tests on this bot:



http://lab.llvm.org:8011/builders/clang-cmake-armv7-a15-full/builds/9452 



Please let me know if I can help debug this.

Cheers,
Diana

On 8 August 2017 at 21:14, Richard Smith via cfe-commits
 wrote:

I forgot to say:

Based on a patch by Vassil Vassilev, which was based on a
patc

Re: r310401 - PR19668, PR23034: Fix handling of move constructors and deleted copy

2017-08-14 Thread Diana Picus via cfe-commits
No, the buildbots don't build with -O0 (at least not the ones that broke).

The command line for that particular object is:
build/./bin/clang -fPIC -fvisibility-inlines-hidden -Werror=date-time
-std=c++11 -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual
-Wmissing-field-initializers -pedantic -Wno-long-long
-Wcovered-switch-default -Wnon-virtual-dtor -Wdelete-non-virtual-dtor
-Wstring-conversion -fcolor-diagnostics -ffunction-sections
-fdata-sections -Wall -std=c++11 -Wno-unused-parameter
-Wno-unknown-warning-option -Wno-covered-switch-default
-DGTEST_NO_LLVM_RAW_OSTREAM=1 -DGTEST_HAS_RTTI=0
-I$LLVM_SRC/llvm/utils/unittest/googletest/include
-I/home/diana.picus/linaro-scripts/bisect/llvm/utils/unittest/googletest
-I$LLVM_SRC/llvm/projects/compiler-rt/include
-I$LLVM_SRC/llvm/projects/compiler-rt/lib
-I$LLVM_SRC/llvm/projects/compiler-rt/lib/asan
-I$LLVM_SRC/llvm/projects/compiler-rt/lib/sanitizer_common/tests
-fno-rtti -O2 -Wno-format -Werror=sign-compare -Wno-non-virtual-dtor
-Wno-variadic-macros -gline-tables-only -DASAN_HAS_BLACKLIST=1
-DASAN_HAS_EXCEPTIONS=1 -DASAN_UAR=0 -fsanitize=address
-fsanitize-blacklist=$LLVM_SRC/llvm/projects/compiler-rt/lib/asan/tests/asan_test.ignore
-mllvm -asan-instrumentation-with-call-threshold=0 -march=armv7-a
-mfloat-abi=hard -c -o
ASAN_INST_TEST_OBJECTS.asan_test.cc.armhf-with-calls.o
$LLVM_SRC/compiler-rt/lib/asan/tests/asan_test.cc

Why would it contain gtest.cc? It seems to contain gtest.h and a bunch
of other internal gtest headers...


On 14 August 2017 at 16:51, Vassil Vassilev  wrote:
> On 14/08/17 15:08, Vassil Vassilev wrote:
>>
>> On 14/08/17 13:04, Diana Picus wrote:
>>>
>>> See attached.
>>
>> Thanks! It looks like asan_test.i doesn't have gtest.cc which appears in
>> the stack trace. Am I missing something?
>
>   Could you paste the compiler invocation. Are we building with -O0 (I see
> quite a lot of things inline). Could it be an optimizer problem?
>
>>>
>>> On 14 August 2017 at 13:30, Vassil Vassilev 
>>> wrote:

 On 14/08/17 11:27, Diana Picus wrote:
>
> Hi,
>
> Strangely enough, it turns out that if I run
> Asan-armhf-with-calls-Noinst-Test on the command line it fails,
> although it doesn't fail when run with lit. I've attached the stack
> trace from gdb. It looks like some trouble passing down va_arg
> parameters, but I haven't looked into too much details. The segfault
> happens when we try to do a   ldrb   r3, [r0, r1], with r1 set to 0 by
> the current function and r0 passed down from the caller. I'm not sure
> if this is the exact same problem as the other tests, but feel free to
> have a look at that code.
>
> Meanwhile, I've removed some clutter from Asan-armhf-with-calls-Test
> (which is the original failure that we were seeing) and left only one
> failing test that seemed small enough. I'll try to look at the
> disassembly before/after the patch and maybe even run valgrind on it
> (running it on the original binary naturally takes forever).
>
> Let me know if there's anything else I could try. I can also send you
> disassembly or even LLVM IR for the Asan-armhf-with-calls-Noinst-Test
> if you think it helps.

disassembly and LLVM will greatly help as well.

> Cheers,
> Diana
>
> On 11 August 2017 at 15:34, Diana Picus  wrote:
>>
>> Well, these are ASAN tests, I'm not sure how that would interact with
>> Valgrind.
>> Anyway, I'll try to reproduce the environment, I'm guessing it would
>> be best to catch this in gdb so I can actually see what's going on.
>>
>> On 11 August 2017 at 15:21, Vassil Vassilev 
>> wrote:
>>>
>>> That's really strange. It looks like some random behavior. Did you
>>> run
>>> some memory checker like valgrind?
>>>
>>> Do the environment provided by the test runner and yours match?
>>>
>>> Sent from my phone. Please excuse my brevity.
>>>
 On 11 Aug 2017, at 15:58, Diana Picus 
 wrote:

 Hi again,

 I finally got the debug build, but unfortunately the stack traces
 that
 the tests print look the same. My suspicion is that this is because
 the addresses printed by the tests are funny (i.e. odd numbers
 instead
 of divisible by 4). I tried to follow those addresses in an objdump
 of
 the executable, but I didn't have much success since most of them
 weren't really pointing to call instructions.

 When I try to run the tests manually in the shell or in gdb, they
 pass.

 I'm not sure what else to try. Thoughts?

 Thanks,
 Diana

> On 11 August 2017 at 11:14, Diana Picus 
> wrote:
> Hi guys,
>
> I'm SO sorry about the delays. I've been having all sorts of
> trouble
> getting that debug b

r310840 - [OPENMP] Generalization of calls of the outlined functions.

2017-08-14 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Mon Aug 14 08:01:03 2017
New Revision: 310840

URL: http://llvm.org/viewvc/llvm-project?rev=310840&view=rev
Log:
[OPENMP] Generalization of calls of the outlined functions.

General improvement of the outlined functions calls.

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/test/OpenMP/parallel_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=310840&r1=310839&r2=310840&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Mon Aug 14 08:01:03 2017
@@ -2447,7 +2447,7 @@ void CGOpenMPRuntime::emitParallelCall(C
 OutlinedFnArgs.push_back(ThreadIDAddr.getPointer());
 OutlinedFnArgs.push_back(ZeroAddr.getPointer());
 OutlinedFnArgs.append(CapturedVars.begin(), CapturedVars.end());
-RT.emitOutlinedFunctionCall(CGF, OutlinedFn, OutlinedFnArgs);
+RT.emitOutlinedFunctionCall(CGF, Loc, OutlinedFn, OutlinedFnArgs);
 
 // __kmpc_end_serialized_parallel(&Loc, GTid);
 llvm::Value *EndArgs[] = {RT.emitUpdateLocation(CGF, Loc), ThreadID};
@@ -3348,14 +3348,14 @@ CGOpenMPRuntime::createOffloadingBinaryD
   auto *UnRegFn = createOffloadingBinaryDescriptorFunction(
   CGM, ".omp_offloading.descriptor_unreg",
   [&](CodeGenFunction &CGF, PrePostActionTy &) {
-CGF.EmitCallOrInvoke(createRuntimeFunction(OMPRTL__tgt_unregister_lib),
- Desc);
+CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__tgt_unregister_lib),
+Desc);
   });
   auto *RegFn = createOffloadingBinaryDescriptorFunction(
   CGM, ".omp_offloading.descriptor_reg",
   [&](CodeGenFunction &CGF, PrePostActionTy &) {
-CGF.EmitCallOrInvoke(createRuntimeFunction(OMPRTL__tgt_register_lib),
- Desc);
+CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__tgt_register_lib),
+Desc);
 CGM.getCXXABI().registerGlobalDtor(CGF, RegUnregVar, UnRegFn, Desc);
   });
   if (CGM.supportsCOMDAT()) {
@@ -3859,7 +3859,8 @@ emitProxyTaskFunction(CodeGenModule &CGM
   }
   CallArgs.push_back(SharedsParam);
 
-  CGM.getOpenMPRuntime().emitOutlinedFunctionCall(CGF, TaskFunction, CallArgs);
+  CGM.getOpenMPRuntime().emitOutlinedFunctionCall(CGF, Loc, TaskFunction,
+  CallArgs);
   CGF.EmitStoreThroughLValue(
   RValue::get(CGF.Builder.getInt32(/*C=*/0)),
   CGF.MakeAddrLValue(CGF.ReturnValue, KmpInt32Ty));
@@ -4534,8 +4535,8 @@ void CGOpenMPRuntime::emitTaskCall(CodeG
 DepWaitTaskArgs[5] = llvm::ConstantPointerNull::get(CGF.VoidPtrTy);
   }
   auto &&ElseCodeGen = [&TaskArgs, ThreadID, NewTaskNewTaskTTy, TaskEntry,
-NumDependencies, &DepWaitTaskArgs](CodeGenFunction 
&CGF,
-   PrePostActionTy &) {
+NumDependencies, &DepWaitTaskArgs,
+Loc](CodeGenFunction &CGF, PrePostActionTy &) {
 auto &RT = CGF.CGM.getOpenMPRuntime();
 CodeGenFunction::RunCleanupsScope LocalScope(CGF);
 // Build void __kmpc_omp_wait_deps(ident_t *, kmp_int32 gtid,
@@ -4546,11 +4547,11 @@ void CGOpenMPRuntime::emitTaskCall(CodeG
   CGF.EmitRuntimeCall(RT.createRuntimeFunction(OMPRTL__kmpc_omp_wait_deps),
   DepWaitTaskArgs);
 // Call proxy_task_entry(gtid, new_task);
-auto &&CodeGen = [TaskEntry, ThreadID, NewTaskNewTaskTTy](
-CodeGenFunction &CGF, PrePostActionTy &Action) {
+auto &&CodeGen = [TaskEntry, ThreadID, NewTaskNewTaskTTy,
+  Loc](CodeGenFunction &CGF, PrePostActionTy &Action) {
   Action.Enter(CGF);
   llvm::Value *OutlinedFnArgs[] = {ThreadID, NewTaskNewTaskTTy};
-  CGF.CGM.getOpenMPRuntime().emitOutlinedFunctionCall(CGF, TaskEntry,
+  CGF.CGM.getOpenMPRuntime().emitOutlinedFunctionCall(CGF, Loc, TaskEntry,
   OutlinedFnArgs);
 };
 
@@ -7035,7 +7036,7 @@ void CGOpenMPRuntime::emitTargetCall(Cod
   CGF.Builder.CreateCondBr(Failed, OffloadFailedBlock, OffloadContBlock);
 
   CGF.EmitBlock(OffloadFailedBlock);
-  emitOutlinedFunctionCall(CGF, OutlinedFn, KernelArgs);
+  emitOutlinedFunctionCall(CGF, D.getLocStart(), OutlinedFn, KernelArgs);
   CGF.EmitBranch(OffloadContBlock);
 
   CGF.EmitBlock(OffloadContBlock, /*IsFinished=*/true);
@@ -7755,16 +7756,25 @@ void CGOpenMPRuntime::emitDoacrossOrdere
   CGF.EmitRuntimeCall(RTLFn, Args);
 }
 
-void CGOpenMPRuntime::emitOutlinedFunctionCall(
-CodeGenFunction &CGF, llvm::V

Re: r310401 - PR19668, PR23034: Fix handling of move constructors and deleted copy

2017-08-14 Thread Diana Picus via cfe-commits
On 14 August 2017 at 16:59, Diana Picus  wrote:
> No, the buildbots don't build with -O0 (at least not the ones that broke).
>
> The command line for that particular object is:
> build/./bin/clang -fPIC -fvisibility-inlines-hidden -Werror=date-time
> -std=c++11 -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual
> -Wmissing-field-initializers -pedantic -Wno-long-long
> -Wcovered-switch-default -Wnon-virtual-dtor -Wdelete-non-virtual-dtor
> -Wstring-conversion -fcolor-diagnostics -ffunction-sections
> -fdata-sections -Wall -std=c++11 -Wno-unused-parameter
> -Wno-unknown-warning-option -Wno-covered-switch-default
> -DGTEST_NO_LLVM_RAW_OSTREAM=1 -DGTEST_HAS_RTTI=0
> -I$LLVM_SRC/llvm/utils/unittest/googletest/include
> -I/home/diana.picus/linaro-scripts/bisect/llvm/utils/unittest/googletest
> -I$LLVM_SRC/llvm/projects/compiler-rt/include
> -I$LLVM_SRC/llvm/projects/compiler-rt/lib
> -I$LLVM_SRC/llvm/projects/compiler-rt/lib/asan
> -I$LLVM_SRC/llvm/projects/compiler-rt/lib/sanitizer_common/tests
> -fno-rtti -O2 -Wno-format -Werror=sign-compare -Wno-non-virtual-dtor
> -Wno-variadic-macros -gline-tables-only -DASAN_HAS_BLACKLIST=1
> -DASAN_HAS_EXCEPTIONS=1 -DASAN_UAR=0 -fsanitize=address
> -fsanitize-blacklist=$LLVM_SRC/llvm/projects/compiler-rt/lib/asan/tests/asan_test.ignore
> -mllvm -asan-instrumentation-with-call-threshold=0 -march=armv7-a
> -mfloat-abi=hard -c -o
> ASAN_INST_TEST_OBJECTS.asan_test.cc.armhf-with-calls.o
> $LLVM_SRC/compiler-rt/lib/asan/tests/asan_test.cc
>
> Why would it contain gtest.cc? It seems to contain gtest.h and a bunch
> of other internal gtest headers...
>

In particular, gtest.cc is included into gtest_all.cc, which compiled
to ASAN_INST_TEST_OBJECTS.gtest_all.cc.armhf-with-calls.o and then
added to the link line, which looks like this:
build/./bin/clang
ASAN_INST_TEST_OBJECTS.gtest-all.cc.armhf-with-calls.o
ASAN_INST_TEST_OBJECTS.asan_asm_test.cc.armhf-with-calls.o
ASAN_INST_TEST_OBJECTS.asan_globals_test.cc.armhf-with-calls.o
ASAN_INST_TEST_OBJECTS.asan_interface_test.cc.armhf-with-calls.o
ASAN_INST_TEST_OBJECTS.asan_internal_interface_test.cc.armhf-with-calls.o
ASAN_INST_TEST_OBJECTS.asan_test.cc.armhf-with-calls.o
ASAN_INST_TEST_OBJECTS.asan_oob_test.cc.armhf-with-calls.o
ASAN_INST_TEST_OBJECTS.asan_mem_test.cc.armhf-with-calls.o
ASAN_INST_TEST_OBJECTS.asan_str_test.cc.armhf-with-calls.o
ASAN_INST_TEST_OBJECTS.asan_test_main.cc.armhf-with-calls.o -o
build/projects/compiler-rt/lib/asan/tests/default/Asan-armhf-with-calls-Test
-Wl,-allow-shlib-undefined -g --driver-mode=g++ -fsanitize=address
-march=armv7-a -mfloat-abi=hard

>
> On 14 August 2017 at 16:51, Vassil Vassilev  wrote:
>> On 14/08/17 15:08, Vassil Vassilev wrote:
>>>
>>> On 14/08/17 13:04, Diana Picus wrote:

 See attached.
>>>
>>> Thanks! It looks like asan_test.i doesn't have gtest.cc which appears in
>>> the stack trace. Am I missing something?
>>
>>   Could you paste the compiler invocation. Are we building with -O0 (I see
>> quite a lot of things inline). Could it be an optimizer problem?
>>

 On 14 August 2017 at 13:30, Vassil Vassilev 
 wrote:
>
> On 14/08/17 11:27, Diana Picus wrote:
>>
>> Hi,
>>
>> Strangely enough, it turns out that if I run
>> Asan-armhf-with-calls-Noinst-Test on the command line it fails,
>> although it doesn't fail when run with lit. I've attached the stack
>> trace from gdb. It looks like some trouble passing down va_arg
>> parameters, but I haven't looked into too much details. The segfault
>> happens when we try to do a   ldrb   r3, [r0, r1], with r1 set to 0 by
>> the current function and r0 passed down from the caller. I'm not sure
>> if this is the exact same problem as the other tests, but feel free to
>> have a look at that code.
>>
>> Meanwhile, I've removed some clutter from Asan-armhf-with-calls-Test
>> (which is the original failure that we were seeing) and left only one
>> failing test that seemed small enough. I'll try to look at the
>> disassembly before/after the patch and maybe even run valgrind on it
>> (running it on the original binary naturally takes forever).
>>
>> Let me know if there's anything else I could try. I can also send you
>> disassembly or even LLVM IR for the Asan-armhf-with-calls-Noinst-Test
>> if you think it helps.
>
>disassembly and LLVM will greatly help as well.
>
>> Cheers,
>> Diana
>>
>> On 11 August 2017 at 15:34, Diana Picus  wrote:
>>>
>>> Well, these are ASAN tests, I'm not sure how that would interact with
>>> Valgrind.
>>> Anyway, I'll try to reproduce the environment, I'm guessing it would
>>> be best to catch this in gdb so I can actually see what's going on.
>>>
>>> On 11 August 2017 at 15:21, Vassil Vassilev 
>>> wrote:

 That's really strange. It looks like some random behavior. Did you
 run
 some memory checker like valg

Re: r310401 - PR19668, PR23034: Fix handling of move constructors and deleted copy

2017-08-14 Thread Vassil Vassilev via cfe-commits

On 14/08/17 15:59, Diana Picus wrote:

No, the buildbots don't build with -O0 (at least not the ones that broke).

The command line for that particular object is:
build/./bin/clang -fPIC -fvisibility-inlines-hidden -Werror=date-time
-std=c++11 -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual
-Wmissing-field-initializers -pedantic -Wno-long-long
-Wcovered-switch-default -Wnon-virtual-dtor -Wdelete-non-virtual-dtor
-Wstring-conversion -fcolor-diagnostics -ffunction-sections
-fdata-sections -Wall -std=c++11 -Wno-unused-parameter
-Wno-unknown-warning-option -Wno-covered-switch-default
-DGTEST_NO_LLVM_RAW_OSTREAM=1 -DGTEST_HAS_RTTI=0
-I$LLVM_SRC/llvm/utils/unittest/googletest/include
-I/home/diana.picus/linaro-scripts/bisect/llvm/utils/unittest/googletest
-I$LLVM_SRC/llvm/projects/compiler-rt/include
-I$LLVM_SRC/llvm/projects/compiler-rt/lib
-I$LLVM_SRC/llvm/projects/compiler-rt/lib/asan
-I$LLVM_SRC/llvm/projects/compiler-rt/lib/sanitizer_common/tests
-fno-rtti -O2 -Wno-format -Werror=sign-compare -Wno-non-virtual-dtor
-Wno-variadic-macros -gline-tables-only -DASAN_HAS_BLACKLIST=1
-DASAN_HAS_EXCEPTIONS=1 -DASAN_UAR=0 -fsanitize=address
-fsanitize-blacklist=$LLVM_SRC/llvm/projects/compiler-rt/lib/asan/tests/asan_test.ignore
-mllvm -asan-instrumentation-with-call-threshold=0 -march=armv7-a
-mfloat-abi=hard -c -o
ASAN_INST_TEST_OBJECTS.asan_test.cc.armhf-with-calls.o
$LLVM_SRC/compiler-rt/lib/asan/tests/asan_test.cc
  Could you try to reproduce the issue with O0? This would rule out the 
optimizer. Could you resend the O0 ll file, maybe I could find something 
out. IIUC, the gtest version is 1.8.0?


Why would it contain gtest.cc? It seems to contain gtest.h and a bunch
of other internal gtest headers...


On 14 August 2017 at 16:51, Vassil Vassilev  wrote:

On 14/08/17 15:08, Vassil Vassilev wrote:

On 14/08/17 13:04, Diana Picus wrote:

See attached.

Thanks! It looks like asan_test.i doesn't have gtest.cc which appears in
the stack trace. Am I missing something?

   Could you paste the compiler invocation. Are we building with -O0 (I see
quite a lot of things inline). Could it be an optimizer problem?


On 14 August 2017 at 13:30, Vassil Vassilev 
wrote:

On 14/08/17 11:27, Diana Picus wrote:

Hi,

Strangely enough, it turns out that if I run
Asan-armhf-with-calls-Noinst-Test on the command line it fails,
although it doesn't fail when run with lit. I've attached the stack
trace from gdb. It looks like some trouble passing down va_arg
parameters, but I haven't looked into too much details. The segfault
happens when we try to do a   ldrb   r3, [r0, r1], with r1 set to 0 by
the current function and r0 passed down from the caller. I'm not sure
if this is the exact same problem as the other tests, but feel free to
have a look at that code.

Meanwhile, I've removed some clutter from Asan-armhf-with-calls-Test
(which is the original failure that we were seeing) and left only one
failing test that seemed small enough. I'll try to look at the
disassembly before/after the patch and maybe even run valgrind on it
(running it on the original binary naturally takes forever).

Let me know if there's anything else I could try. I can also send you
disassembly or even LLVM IR for the Asan-armhf-with-calls-Noinst-Test
if you think it helps.

disassembly and LLVM will greatly help as well.


Cheers,
Diana

On 11 August 2017 at 15:34, Diana Picus  wrote:

Well, these are ASAN tests, I'm not sure how that would interact with
Valgrind.
Anyway, I'll try to reproduce the environment, I'm guessing it would
be best to catch this in gdb so I can actually see what's going on.

On 11 August 2017 at 15:21, Vassil Vassilev 
wrote:

That's really strange. It looks like some random behavior. Did you
run
some memory checker like valgrind?

Do the environment provided by the test runner and yours match?

Sent from my phone. Please excuse my brevity.


On 11 Aug 2017, at 15:58, Diana Picus 
wrote:

Hi again,

I finally got the debug build, but unfortunately the stack traces
that
the tests print look the same. My suspicion is that this is because
the addresses printed by the tests are funny (i.e. odd numbers
instead
of divisible by 4). I tried to follow those addresses in an objdump
of
the executable, but I didn't have much success since most of them
weren't really pointing to call instructions.

When I try to run the tests manually in the shell or in gdb, they
pass.

I'm not sure what else to try. Thoughts?

Thanks,
Diana


On 11 August 2017 at 11:14, Diana Picus 
wrote:
Hi guys,

I'm SO sorry about the delays. I've been having all sorts of
trouble
getting that debug build on the board (from ld running out of
memory
to the board just crashing on me, in which case I need to ask
someone
else to reboot it because I can't power cycle it remotely). I can
assure you this is one of my top priorities, I'll get those stack
traces as soon as I can.

Thanks for your patience and sorry again,
Diana


On 10 August 2017 at 22:55, Richard Smith 
w

[PATCH] D36156: [rename] Introduce symbol occurrences

2017-08-14 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman marked an inline comment as done.
arphaman added inline comments.



Comment at: lib/Tooling/Refactoring/Rename/USRLocFinder.cpp:398
   Visitor.TraverseDecl(Decl);
-  return Visitor.getLocationsFound();
+  return std::move(Visitor.getOccurrences());
 }

hokein wrote:
> arphaman wrote:
> > hokein wrote:
> > > I think just returning `Visitor.getOccurrences()` is sufficient -- 
> > > compiler can handle it well, also using std::move would prevent copy 
> > > elision.
> > I'm returning by non-const reference from `getOccurrences`, so the compiler 
> > copies by default. I have to move either here or return by value from 
> > `getOccurrences` and move there. We also have warnings for redundant 
> > `std::move`, and they don't fire here.
> Ok, didn't notice that `getOccurance()` returns non-const reference.
> 
> I think the method `getOccurances` may have potential effect -- the clients 
> could change the Occurences member variable of USRLocFindingASTVisitor, after 
> getting the non-const reference.
> 
> Another option is to rename `getOccurances` to `takeOccurrences` and return 
> by value:
> 
> ```
> SymbolOccurrences takeOccurrences() { return std::move(Occurrences); }
> ```
> 
> What do you think?
Yeah, `takeOccurrences` would be better I think. I'll update.


Repository:
  rL LLVM

https://reviews.llvm.org/D36156



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


[PATCH] D36156: [rename] Introduce symbol occurrences

2017-08-14 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman updated this revision to Diff 110964.
arphaman marked an inline comment as done.
arphaman added a comment.

Use `takeOccurrences`


Repository:
  rL LLVM

https://reviews.llvm.org/D36156

Files:
  include/clang/Tooling/Refactoring/Rename/RenamingAction.h
  include/clang/Tooling/Refactoring/Rename/SymbolName.h
  include/clang/Tooling/Refactoring/Rename/SymbolOccurrences.h
  include/clang/Tooling/Refactoring/Rename/USRLocFinder.h
  lib/Tooling/Refactoring/CMakeLists.txt
  lib/Tooling/Refactoring/Rename/RenamingAction.cpp
  lib/Tooling/Refactoring/Rename/SymbolOccurrences.cpp
  lib/Tooling/Refactoring/Rename/USRLocFinder.cpp

Index: lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
===
--- lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
+++ lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
@@ -23,6 +23,7 @@
 #include "clang/Lex/Lexer.h"
 #include "clang/Tooling/Core/Lookup.h"
 #include "clang/Tooling/Refactoring/RecursiveSymbolVisitor.h"
+#include "clang/Tooling/Refactoring/Rename/SymbolName.h"
 #include "clang/Tooling/Refactoring/Rename/USRFinder.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Casting.h"
@@ -68,11 +69,9 @@
 
   // Non-visitors:
 
-  // \brief Returns a list of unique locations. Duplicate or overlapping
-  // locations are erroneous and should be reported!
-  const std::vector &getLocationsFound() const {
-return LocationsFound;
-  }
+  /// \brief Returns a set of unique symbol occurrences. Duplicate or
+  /// overlapping occurrences are erroneous and should be reported!
+  SymbolOccurrences takeOccurrences() { return std::move(Occurrences); }
 
 private:
   void checkAndAddLocation(SourceLocation Loc) {
@@ -82,17 +81,18 @@
 StringRef TokenName =
 Lexer::getSourceText(CharSourceRange::getTokenRange(BeginLoc, EndLoc),
  Context.getSourceManager(), Context.getLangOpts());
-size_t Offset = TokenName.find(PrevName);
+size_t Offset = TokenName.find(PrevName.getNamePieces()[0]);
 
 // The token of the source location we find actually has the old
 // name.
 if (Offset != StringRef::npos)
-  LocationsFound.push_back(BeginLoc.getLocWithOffset(Offset));
+  Occurrences.emplace_back(PrevName, SymbolOccurrence::MatchingSymbol,
+   BeginLoc.getLocWithOffset(Offset));
   }
 
   const std::set USRSet;
-  const std::string PrevName;
-  std::vector LocationsFound;
+  const SymbolName PrevName;
+  SymbolOccurrences Occurrences;
   const ASTContext &Context;
 };
 
@@ -391,12 +391,11 @@
 
 } // namespace
 
-std::vector
-getLocationsOfUSRs(const std::vector &USRs, StringRef PrevName,
-   Decl *Decl) {
+SymbolOccurrences getOccurrencesOfUSRs(ArrayRef USRs,
+   StringRef PrevName, Decl *Decl) {
   USRLocFindingASTVisitor Visitor(USRs, PrevName, Decl->getASTContext());
   Visitor.TraverseDecl(Decl);
-  return Visitor.getLocationsFound();
+  return Visitor.takeOccurrences();
 }
 
 std::vector
Index: lib/Tooling/Refactoring/Rename/SymbolOccurrences.cpp
===
--- /dev/null
+++ lib/Tooling/Refactoring/Rename/SymbolOccurrences.cpp
@@ -0,0 +1,37 @@
+//===--- SymbolOccurrences.cpp - Clang refactoring library ===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "clang/Tooling/Refactoring/Rename/SymbolOccurrences.h"
+#include "clang/Tooling/Refactoring/Rename/SymbolName.h"
+#include "llvm/ADT/STLExtras.h"
+
+using namespace clang;
+using namespace tooling;
+
+SymbolOccurrence::SymbolOccurrence(const SymbolName &Name, OccurrenceKind Kind,
+   ArrayRef Locations)
+: Kind(Kind) {
+  ArrayRef NamePieces = Name.getNamePieces();
+  assert(Locations.size() == NamePieces.size() &&
+ "mismatching number of locations and lengths");
+  assert(!Locations.empty() && "no locations");
+  if (Locations.size() == 1) {
+RangeOrNumRanges = SourceRange(
+Locations[0], Locations[0].getLocWithOffset(NamePieces[0].size()));
+return;
+  }
+  MultipleRanges = llvm::make_unique(Locations.size());
+  RangeOrNumRanges.setBegin(
+  SourceLocation::getFromRawEncoding(Locations.size()));
+  for (const auto &Loc : llvm::enumerate(Locations)) {
+MultipleRanges[Loc.index()] = SourceRange(
+Loc.value(),
+Loc.value().getLocWithOffset(NamePieces[Loc.index()].size()));
+  }
+}
Index: lib/Tooling/Refactoring/Rename/RenamingAction.cpp
===
--- lib/Tooling/Refactoring/Rename/RenamingAction.cpp
+++ lib/Tooling/Refactoring/Rename/RenamingAction.cpp
@@ -24,14 +24,54 @@
 #include "clang/Toolin

[PATCH] D36458: Fix crash when current lexer is nullptr

2017-08-14 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan updated this revision to Diff 110978.
yvvan added a comment.

I have minimized the crash case and added simple test for it.


https://reviews.llvm.org/D36458

Files:
  lib/Parse/Parser.cpp
  test/Index/std-begin-error.cpp


Index: test/Index/std-begin-error.cpp
===
--- test/Index/std-begin-error.cpp
+++ test/Index/std-begin-error.cpp
@@ -0,0 +1,9 @@
+#ifndef RC_INVOKED
+#include 
+_STD_BEGIN
+}
+#endif /* RC_INVOKED */
+
+// RUN: env CINDEXTEST_EDITING=1 c-index-test -test-load-source-reparse 5 
local -std=c++14 %S\std-begin-error.cpp 2> %t.err
+// RUN: not FileCheck < %t.err %s
+// CHECK: Failure: libclang crashed
Index: lib/Parse/Parser.cpp
===
--- lib/Parse/Parser.cpp
+++ lib/Parse/Parser.cpp
@@ -516,8 +516,8 @@
 
   // Prime the lexer look-ahead.
   ConsumeToken();
-
-  PP.replayPreambleConditionalStack();
+  if (!PP.isCurrentLexer(nullptr))
+PP.replayPreambleConditionalStack();
 }
 
 void Parser::LateTemplateParserCleanupCallback(void *P) {


Index: test/Index/std-begin-error.cpp
===
--- test/Index/std-begin-error.cpp
+++ test/Index/std-begin-error.cpp
@@ -0,0 +1,9 @@
+#ifndef RC_INVOKED
+#include 
+_STD_BEGIN
+}
+#endif /* RC_INVOKED */
+
+// RUN: env CINDEXTEST_EDITING=1 c-index-test -test-load-source-reparse 5 local -std=c++14 %S\std-begin-error.cpp 2> %t.err
+// RUN: not FileCheck < %t.err %s
+// CHECK: Failure: libclang crashed
Index: lib/Parse/Parser.cpp
===
--- lib/Parse/Parser.cpp
+++ lib/Parse/Parser.cpp
@@ -516,8 +516,8 @@
 
   // Prime the lexer look-ahead.
   ConsumeToken();
-
-  PP.replayPreambleConditionalStack();
+  if (!PP.isCurrentLexer(nullptr))
+PP.replayPreambleConditionalStack();
 }
 
 void Parser::LateTemplateParserCleanupCallback(void *P) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36156: [rename] Introduce symbol occurrences

2017-08-14 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

LGTM.




Comment at: include/clang/Tooling/Refactoring/Rename/SymbolName.h:19
+namespace clang {
+namespace tooling {
+

arphaman wrote:
> hokein wrote:
> > An off-topic thought: currently we put everything into `clang::tooling`, I 
> > think we might need a separate namespace e.g. `clang::tooling::refactoring` 
> > in the future? 
> That would be nice, I agree. Don't think it's in scope for this patch though, 
> maybe for https://reviews.llvm.org/D36075?
Sounds good. No need to do it in this patch.


Repository:
  rL LLVM

https://reviews.llvm.org/D36156



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


[PATCH] D35670: [StaticAnalyzer] Handle LoopExit CFGElement in the analyzer

2017-08-14 Thread Peter Szecsi via Phabricator via cfe-commits
szepet updated this revision to Diff 110981.
szepet marked an inline comment as done.
szepet added a comment.

Updates based on comments.


https://reviews.llvm.org/D35670

Files:
  include/clang/Analysis/ProgramPoint.h
  include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
  lib/StaticAnalyzer/Core/CoreEngine.cpp
  lib/StaticAnalyzer/Core/ExprEngine.cpp

Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -364,8 +364,10 @@
 case CFGElement::TemporaryDtor:
   ProcessImplicitDtor(E.castAs(), Pred);
   return;
-case CFGElement::LifetimeEnds:
 case CFGElement::LoopExit:
+  ProcessLoopExit(E.castAs().getLoopStmt(), Pred);
+  return;
+case CFGElement::LifetimeEnds:
   return;
   }
 }
@@ -510,6 +512,21 @@
   Engine.enqueue(Dst, currBldrCtx->getBlock(), currStmtIdx);
 }
 
+void ExprEngine::ProcessLoopExit(const Stmt* S, ExplodedNode *Pred) {
+  PrettyStackTraceLoc CrashInfo(getContext().getSourceManager(),
+S->getLocStart(),
+"Error evaluating end of the loop");
+  ExplodedNodeSet Dst;
+  Dst.Add(Pred);
+  NodeBuilder Bldr(Pred, Dst, *currBldrCtx);
+
+  LoopExit PP(S, Pred->getLocationContext());
+  Bldr.generateNode(PP, Pred->getState(), Pred);
+
+  // Enqueue the new nodes onto the work list.
+  Engine.enqueue(Dst, currBldrCtx->getBlock(), currStmtIdx);
+}
+
 void ExprEngine::ProcessInitializer(const CFGInitializer Init,
 ExplodedNode *Pred) {
   const CXXCtorInitializer *BMI = Init.getInitializer();
@@ -2689,6 +2706,12 @@
 Out << "Epsilon Point";
 break;
 
+  case ProgramPoint::LoopExitKind: {
+LoopExit LE = Loc.castAs();
+Out << "LoopExit: " << LE.getLoopStmt()->getStmtClassName();
+break;
+  }
+
   case ProgramPoint::PreImplicitCallKind: {
 ImplicitCallPoint PC = Loc.castAs();
 Out << "PreCall: ";
Index: lib/StaticAnalyzer/Core/CoreEngine.cpp
===
--- lib/StaticAnalyzer/Core/CoreEngine.cpp
+++ lib/StaticAnalyzer/Core/CoreEngine.cpp
@@ -274,7 +274,8 @@
   assert(Loc.getAs() ||
  Loc.getAs() ||
  Loc.getAs() ||
- Loc.getAs());
+ Loc.getAs() ||
+ Loc.getAs());
   HandlePostStmt(WU.getBlock(), WU.getIndex(), Pred);
   break;
   }
@@ -566,7 +567,8 @@
 
   // Do not create extra nodes. Move to the next CFG element.
   if (N->getLocation().getAs() ||
-  N->getLocation().getAs()) {
+  N->getLocation().getAs()||
+  N->getLocation().getAs()) {
 WList->enqueue(N, Block, Idx+1);
 return;
   }
Index: include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
@@ -196,6 +196,8 @@
 
   void ProcessStmt(const CFGStmt S, ExplodedNode *Pred);
 
+  void ProcessLoopExit(const Stmt* S, ExplodedNode *Pred);
+
   void ProcessInitializer(const CFGInitializer I, ExplodedNode *Pred);
 
   void ProcessImplicitDtor(const CFGImplicitDtor D, ExplodedNode *Pred);
Index: include/clang/Analysis/ProgramPoint.h
===
--- include/clang/Analysis/ProgramPoint.h
+++ include/clang/Analysis/ProgramPoint.h
@@ -83,6 +83,7 @@
   PostImplicitCallKind,
   MinImplicitCallKind = PreImplicitCallKind,
   MaxImplicitCallKind = PostImplicitCallKind,
+  LoopExitKind,
   EpsilonKind};
 
 private:
@@ -654,6 +655,24 @@
   }
 };
 
+/// Represents a point when we exit a loop.
+class LoopExit : public ProgramPoint {
+public:
+LoopExit(const Stmt *LoopStmt, const LocationContext *LC)
+: ProgramPoint(LoopStmt, nullptr, LoopExitKind, LC) {}
+
+const Stmt *getLoopStmt() const {
+  return static_cast(getData1());
+}
+
+private:
+friend class ProgramPoint;
+LoopExit() {}
+static bool isKind(const ProgramPoint &Location) {
+  return Location.getKind() == LoopExitKind;
+}
+};
+
 /// This is a meta program point, which should be skipped by all the diagnostic
 /// reasoning etc.
 class EpsilonPoint : public ProgramPoint {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35670: [StaticAnalyzer] Handle LoopExit CFGElement in the analyzer

2017-08-14 Thread Peter Szecsi via Phabricator via cfe-commits
szepet added inline comments.



Comment at: include/clang/Analysis/ProgramPoint.h:658
 
+class LoopExit : public ProgramPoint {
+public:

dcoughlin wrote:
> Can you add a comment explaining what meaning of this program point is.
Can you help me with that? I am not sure what is important to say about this 
point to understand it better than from its name.



Comment at: lib/StaticAnalyzer/Core/CoreEngine.cpp:586
 
+  if ((*Block)[Idx].getKind() == CFGElement::LoopExit) {
+WList->enqueue(N, Block, Idx+1);

dcoughlin wrote:
> I'm surprised both this and the checks for N's location above are needed. How 
> does this arise?
We don't need both of the checks, I just left it by mistake.


https://reviews.llvm.org/D35670



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


[PATCH] D36327: [OpenCL] Allow targets emit optimized pipe functions for power of 2 type sizes

2017-08-14 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In https://reviews.llvm.org/D36327#840658, @bader wrote:

> In https://reviews.llvm.org/D36327#840616, @yaxunl wrote:
>
> > In https://reviews.llvm.org/D36327#839809, @rjmccall wrote:
> >
> > > Could you just implement this in SimplifyLibCalls?  I assume there's some 
> > > way to fill in TargetLibraryInfo appropriately for a platform.  Is that 
> > > too late for your linking requirements?
> >
> >
> > Both the optimized and generic versions of __read_pipe function contains 
> > call of other library functions and are complicate enough not to be 
> > generated programmatically. amdgpu target does not have the capability to 
> > link in library code after LLVM codegen. The linking has to be done before 
> > SimplifyLibCalls.
>
>
> If I understand correctly, SimplifyLibCalls is LLVM IR transformation, so it 
> works before linking and LLVM codegen (e.g. InstCombine passes run this 
> transformation). This pass is doing something similar to what you are trying 
> to achieve for __read_pipe builti-ins: pow(2.0, x) -> llvm.exp2(x).


Thanks. I will take a look.


https://reviews.llvm.org/D36327



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


[PATCH] D36684: clang-format: [JS] wrap optional properties in type aliases.

2017-08-14 Thread Martin Probst via Phabricator via cfe-commits
mprobst created this revision.
Herald added a subscriber: klimek.

clang-format wraps object literal keys in an object literal if they are
marked as `TT_SelectorName`s and/or the colon is marked as
`TT_DictLiteral`. Previously, clang-format would accidentally work
because colons in type aliases were marked as `TT_DictLiteral`. r310367
fixed this to assing `TT_JsTypeColon`, which broke wrapping in certain
situations. However the root cause was that clang-format incorrectly
didn't skip questionmarks when detecting selector name.

This change fixes both locations to (1) assign `TT_SelectorName` and (2)
treat `TT_JsTypeColon` like `TT_DictLiteral`.

Previously:

  type X = {
a: string, b?: string,
  };

Now:

  type X = {
a: string,
b?: string,
  };


https://reviews.llvm.org/D36684

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTestJS.cpp


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -1555,6 +1555,10 @@
"  y: number\n"
"};\n"
"class C {}");
+  verifyFormat("export type X = {\n"
+   "  a: string,\n"
+   "  b?: string,\n"
+   "};\n");
 }
 
 TEST_F(FormatTestJS, TypeInterfaceLineWrapping) {
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -459,6 +459,8 @@
 updateParameterCount(Left, CurrentToken);
 if (CurrentToken->isOneOf(tok::colon, tok::l_brace, tok::less)) {
   FormatToken *Previous = CurrentToken->getPreviousNonComment();
+  if (Previous->is(TT_JsTypeOptionalQuestion))
+Previous = Previous->getPreviousNonComment();
   if (((CurrentToken->is(tok::colon) &&
 (!Contexts.back().ColonIsDictLiteral || !Style.isCpp())) ||
Style.Language == FormatStyle::LK_Proto ||
@@ -1601,7 +1603,7 @@
   if (Current->is(TT_ConditionalExpr))
 return prec::Conditional;
   if (NextNonComment && Current->is(TT_SelectorName) &&
-  (NextNonComment->is(TT_DictLiteral) ||
+  (NextNonComment->isOneOf(TT_DictLiteral, TT_JsTypeColon) ||
((Style.Language == FormatStyle::LK_Proto ||
  Style.Language == FormatStyle::LK_TextProto) &&
 NextNonComment->is(tok::less


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -1555,6 +1555,10 @@
"  y: number\n"
"};\n"
"class C {}");
+  verifyFormat("export type X = {\n"
+   "  a: string,\n"
+   "  b?: string,\n"
+   "};\n");
 }
 
 TEST_F(FormatTestJS, TypeInterfaceLineWrapping) {
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -459,6 +459,8 @@
 updateParameterCount(Left, CurrentToken);
 if (CurrentToken->isOneOf(tok::colon, tok::l_brace, tok::less)) {
   FormatToken *Previous = CurrentToken->getPreviousNonComment();
+  if (Previous->is(TT_JsTypeOptionalQuestion))
+Previous = Previous->getPreviousNonComment();
   if (((CurrentToken->is(tok::colon) &&
 (!Contexts.back().ColonIsDictLiteral || !Style.isCpp())) ||
Style.Language == FormatStyle::LK_Proto ||
@@ -1601,7 +1603,7 @@
   if (Current->is(TT_ConditionalExpr))
 return prec::Conditional;
   if (NextNonComment && Current->is(TT_SelectorName) &&
-  (NextNonComment->is(TT_DictLiteral) ||
+  (NextNonComment->isOneOf(TT_DictLiteral, TT_JsTypeColon) ||
((Style.Language == FormatStyle::LK_Proto ||
  Style.Language == FormatStyle::LK_TextProto) &&
 NextNonComment->is(tok::less
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r310516 - Make -std=c++17 an alias of -std=c++1z

2017-08-14 Thread Hans Wennborg via cfe-commits
Merged in r310848.

On Wed, Aug 9, 2017 at 1:12 PM, Hans Wennborg via cfe-commits
 wrote:
> Author: hans
> Date: Wed Aug  9 13:12:53 2017
> New Revision: 310516
>
> URL: http://llvm.org/viewvc/llvm-project?rev=310516&view=rev
> Log:
> Make -std=c++17 an alias of -std=c++1z
>
> As suggested on PR33912.
>
> Trying to keep this small to make it easy to merge to the 5.0 branch. We
> can do a follow-up with more thorough renaming (diagnostic text,
> options, ids, etc.) later.
>
> (For C++14 this was done in r215982, and I think a smaller patch for the
> 3.5 branch:
> http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20140818/113013.html)
>
> Differential Revision: https://reviews.llvm.org/D36532
>
> Modified:
> cfe/trunk/include/clang/Frontend/LangStandards.def
> cfe/trunk/test/Driver/unknown-std.cpp
> cfe/trunk/test/SemaCXX/cxx1z-init-statement.cpp
>
> Modified: cfe/trunk/include/clang/Frontend/LangStandards.def
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/LangStandards.def?rev=310516&r1=310515&r2=310516&view=diff
> ==
> --- cfe/trunk/include/clang/Frontend/LangStandards.def (original)
> +++ cfe/trunk/include/clang/Frontend/LangStandards.def Wed Aug  9 13:12:53 
> 2017
> @@ -109,15 +109,17 @@ LANGSTANDARD(gnucxx14, "gnu++14",
>   GNUMode)
>  LANGSTANDARD_ALIAS_DEPR(gnucxx14, "gnu++1y")
>
> -LANGSTANDARD(cxx1z, "c++1z",
> - CXX, "Working draft for ISO C++ 2017",
> +LANGSTANDARD(cxx17, "c++17",
> + CXX, "ISO C++ 2017 with amendments",
>   LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | 
> CPlusPlus1z |
>   Digraphs | HexFloat)
> +LANGSTANDARD_ALIAS_DEPR(cxx17, "c++1z")
>
> -LANGSTANDARD(gnucxx1z, "gnu++1z",
> - CXX, "Working draft for ISO C++ 2017 with GNU extensions",
> +LANGSTANDARD(gnucxx17, "gnu++17",
> + CXX, "ISO C++ 2017 with amendments and GNU extensions",
>   LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | 
> CPlusPlus1z |
>   Digraphs | HexFloat | GNUMode)
> +LANGSTANDARD_ALIAS_DEPR(gnucxx17, "gnu++1z")
>
>  LANGSTANDARD(cxx2a, "c++2a",
>   CXX, "Working draft for ISO C++ 2020",
>
> Modified: cfe/trunk/test/Driver/unknown-std.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/unknown-std.cpp?rev=310516&r1=310515&r2=310516&view=diff
> ==
> --- cfe/trunk/test/Driver/unknown-std.cpp (original)
> +++ cfe/trunk/test/Driver/unknown-std.cpp Wed Aug  9 13:12:53 2017
> @@ -13,8 +13,8 @@
>  // CHECK-NEXT: note: use 'gnu++11' for 'ISO C++ 2011 with amendments and GNU 
> extensions' standard
>  // CHECK-NEXT: note: use 'c++14' for 'ISO C++ 2014 with amendments' standard
>  // CHECK-NEXT: note: use 'gnu++14' for 'ISO C++ 2014 with amendments and GNU 
> extensions' standard
> -// CHECK-NEXT: note: use 'c++1z' for 'Working draft for ISO C++ 2017' 
> standard
> -// CHECK-NEXT: note: use 'gnu++1z' for 'Working draft for ISO C++ 2017 with 
> GNU extensions' standard
> +// CHECK-NEXT: note: use 'c++17' for 'ISO C++ 2017 with amendments' standard
> +// CHECK-NEXT: note: use 'gnu++17' for 'ISO C++ 2017 with amendments and GNU 
> extensions' standard
>  // CHECK-NEXT: note: use 'c++2a' for 'Working draft for ISO C++ 2020' 
> standard
>  // CHECK-NEXT: note: use 'gnu++2a' for 'Working draft for ISO C++ 2020 with 
> GNU extensions' standard
>  // CUDA-NEXT: note: use 'cuda' for 'NVIDIA CUDA(tm)' standard
>
> Modified: cfe/trunk/test/SemaCXX/cxx1z-init-statement.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx1z-init-statement.cpp?rev=310516&r1=310515&r2=310516&view=diff
> ==
> --- cfe/trunk/test/SemaCXX/cxx1z-init-statement.cpp (original)
> +++ cfe/trunk/test/SemaCXX/cxx1z-init-statement.cpp Wed Aug  9 13:12:53 2017
> @@ -1,4 +1,5 @@
>  // RUN: %clang_cc1 -std=c++1z -verify %s
> +// RUN: %clang_cc1 -std=c++17 -verify %s
>
>  void testIf() {
>int x = 0;
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36685: [clang-diff] HTML diff navigation

2017-08-14 Thread Johannes Altmanninger via Phabricator via cfe-commits
johannes created this revision.

This adds shortcuts j and k to jump between changes.
It is especially useful in diffs with few changes.


https://reviews.llvm.org/D36685

Files:
  tools/clang-diff/ClangDiff.cpp


Index: tools/clang-diff/ClangDiff.cpp
===
--- tools/clang-diff/ClangDiff.cpp
+++ tools/clang-diff/ClangDiff.cpp
@@ -145,34 +145,79 @@
 highlightStack = []
 function clearHighlight() {
   while (highlightStack.length) {
-let [l, r] = highlightStack.pop()
+var [l, r] = highlightStack.pop()
 document.getElementById(l).style.backgroundColor = 'white'
-document.getElementById(r).style.backgroundColor = 'white'
+if (r[1] != '-')
+  document.getElementById(r).style.backgroundColor = 'white'
   }
 }
 function highlight(event) {
-  id = event.target['id']
+  var id = event.target['id']
   doHighlight(id)
 }
 function doHighlight(id) {
   clearHighlight()
   source = document.getElementById(id)
   if (!source.attributes['tid'])
 return
-  tid = source.attributes['tid'].value
-  target = document.getElementById(tid)
-  if (!target || source.parentElement && 
source.parentElement.classList.contains('code'))
+  var mapped = source
+  while (mapped && mapped.parentElement && 
mapped.attributes['tid'].value.substr(1) === '-1')
+mapped = mapped.parentElement
+  var tid = null, target = null
+  if (mapped) {
+tid = mapped.attributes['tid'].value
+target = document.getElementById(tid)
+  }
+  if (source.parentElement && source.parentElement.classList.contains('code'))
 return
-  source.style.backgroundColor = target.style.backgroundColor = 'lightgrey'
-  highlightStack.push([id, tid])
+  source.style.backgroundColor = 'lightgrey'
   source.scrollIntoView()
-  target.scrollIntoView()
+  if (target) {
+if (mapped === source)
+  target.style.backgroundColor = 'lightgrey'
+target.scrollIntoView()
+  }
+  highlightStack.push([id, tid])
   location.hash = '#' + id
 }
 function scrollToBoth() {
   doHighlight(location.hash.substr(1))
 }
+function nextWithoutClass(prefix, increment, number) {
+  do {
+number += increment
+var elem = document.getElementById(prefix + number)
+  } while(elem && elem.classList.length == 0)
+  return elem ? number : null
+}
+function handleKey(e) {
+  var down = e.code === "KeyJ"
+  var up = e.code === "KeyK"
+  if (!down && !up)
+return
+  var id = highlightStack[0] ? highlightStack[0][0] : 'R0'
+  var oldelem = document.getElementById(id)
+  var number = parseInt(id.substr(1))
+  var increment = down ? 1 : -1
+  var lastnumber = number
+  var prefix = id[0]
+  do {
+number = nextWithoutClass(prefix, increment, number)
+var elem = document.getElementById(prefix + number)
+if (up && elem) {
+  while (elem.parentElement && elem.parentElement.classList.length != 0) {
+elem = elem.parentElement
+number = elem.id.substr(1)
+  }
+}
+  } while ((down && id !== 'R0' && oldelem.contains(elem)))
+  if (!number)
+number = lastnumber
+  elem = document.getElementById(prefix + number)
+  doHighlight(prefix + number)
+}
 window.onload = scrollToBoth
+window.onkeydown = handleKey
 
 
 


Index: tools/clang-diff/ClangDiff.cpp
===
--- tools/clang-diff/ClangDiff.cpp
+++ tools/clang-diff/ClangDiff.cpp
@@ -145,34 +145,79 @@
 highlightStack = []
 function clearHighlight() {
   while (highlightStack.length) {
-let [l, r] = highlightStack.pop()
+var [l, r] = highlightStack.pop()
 document.getElementById(l).style.backgroundColor = 'white'
-document.getElementById(r).style.backgroundColor = 'white'
+if (r[1] != '-')
+  document.getElementById(r).style.backgroundColor = 'white'
   }
 }
 function highlight(event) {
-  id = event.target['id']
+  var id = event.target['id']
   doHighlight(id)
 }
 function doHighlight(id) {
   clearHighlight()
   source = document.getElementById(id)
   if (!source.attributes['tid'])
 return
-  tid = source.attributes['tid'].value
-  target = document.getElementById(tid)
-  if (!target || source.parentElement && source.parentElement.classList.contains('code'))
+  var mapped = source
+  while (mapped && mapped.parentElement && mapped.attributes['tid'].value.substr(1) === '-1')
+mapped = mapped.parentElement
+  var tid = null, target = null
+  if (mapped) {
+tid = mapped.attributes['tid'].value
+target = document.getElementById(tid)
+  }
+  if (source.parentElement && source.parentElement.classList.contains('code'))
 return
-  source.style.backgroundColor = target.style.backgroundColor = 'lightgrey'
-  highlightStack.push([id, tid])
+  source.style.backgroundColor = 'lightgrey'
   source.scrollIntoView()
-  target.scrollIntoView()
+  if (target) {
+if (mapped === source)
+  target.style.backgroundColor = 'lightgrey'
+target.scrollIntoView()
+  }
+  highlightStack.push([id, tid])
   location.hash = '#'

r310850 - [OPENMP][DEBUG] Fix for PR33676: Debug info for OpenMP region is broken.

2017-08-14 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Mon Aug 14 09:03:47 2017
New Revision: 310850

URL: http://llvm.org/viewvc/llvm-project?rev=310850&view=rev
Log:
[OPENMP][DEBUG] Fix for PR33676: Debug info for OpenMP region is broken.

After some changes in clang/LLVM debug info for task-based regions was
not generated at all. Patch fixes this problem.

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/test/OpenMP/taskloop_reduction_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=310850&r1=310849&r2=310850&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Mon Aug 14 09:03:47 2017
@@ -3790,7 +3790,6 @@ emitProxyTaskFunction(CodeGenModule &CGM
  ".omp_task_entry.", &CGM.getModule());
   CGM.SetInternalFunctionAttributes(/*D=*/nullptr, TaskEntry, TaskEntryFnInfo);
   CodeGenFunction CGF(CGM);
-  CGF.disableDebugInfo();
   CGF.StartFunction(GlobalDecl(), KmpInt32Ty, TaskEntry, TaskEntryFnInfo, 
Args);
 
   // TaskFunction(gtid, tt->task_data.part_id, &tt->privates, 
task_privates_map,

Modified: cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp?rev=310850&r1=310849&r2=310850&view=diff
==
--- cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp Mon Aug 14 09:03:47 2017
@@ -342,8 +342,8 @@ static llvm::Function *emitOutlinedFunct
 F->setDoesNotThrow();
 
   // Generate the function.
-  CGF.StartFunction(CD, Ctx.VoidTy, F, FuncInfo, TargetArgs, CD->getLocation(),
-CD->getBody()->getLocStart());
+  CGF.StartFunction(CD, Ctx.VoidTy, F, FuncInfo, TargetArgs,
+FO.S->getLocStart(), CD->getBody()->getLocStart());
   unsigned Cnt = CD->getContextParamPosition();
   I = FO.S->captures().begin();
   for (auto *FD : RD->fields()) {

Modified: cfe/trunk/test/OpenMP/taskloop_reduction_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/taskloop_reduction_codegen.cpp?rev=310850&r1=310849&r2=310850&view=diff
==
--- cfe/trunk/test/OpenMP/taskloop_reduction_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/taskloop_reduction_codegen.cpp Mon Aug 14 09:03:47 
2017
@@ -143,7 +143,7 @@ sum = 0.0;
 // CHECK:[[DIV:%.*]] = sdiv i32 [[ADD11]], 1
 // CHECK:[[SUB12:%.*]] = sub nsw i32 [[DIV]], 1
 // CHECK:store i32 [[SUB12]], i32* [[DOTCAPTURE_EXPR_9]],
-// CHECK:[[TMP65:%.*]] = call i8* @__kmpc_omp_task_alloc(%ident_t* 
%{{.+}}, i32 [[TMP0]], i32 1, i64 888, i64 72, i32 (i32, i8*)* bitcast (i32 
(i32, %struct.kmp_task_t_with_privates*)* @{{.+}} to i32 (i32, i8*)*))
+// CHECK:[[TMP65:%.*]] = call i8* @__kmpc_omp_task_alloc(%ident_t* 
%{{.+}}, i32 [[TMP0]], i32 1, i64 888, i64 72, i32 (i32, i8*)* bitcast (i32 
(i32, %struct.kmp_task_t_with_privates*)* @[[TASK:.+]] to i32 (i32, i8*)*))
 // CHECK:call void @__kmpc_taskloop(%ident_t* %{{.+}}, i32 [[TMP0]], i8* 
[[TMP65]], i32 1, i64* %{{.+}}, i64* %{{.+}}, i64 %{{.+}}, i32 0, i32 0, i64 0, 
i8* null)
 // CHECK:call void @__kmpc_end_taskgroup(%ident_t*
 
@@ -195,3 +195,4 @@ sum = 0.0;
 // CHECK: store float %{{.+}}, float* %
 // CHECK: ret void
 
+// CHECK: distinct !DISubprogram(linkageName: "[[TASK]]", scope: !


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


[PATCH] D36684: clang-format: [JS] wrap optional properties in type aliases.

2017-08-14 Thread Daniel Jasper via Phabricator via cfe-commits
djasper accepted this revision.
djasper added a comment.
This revision is now accepted and ready to land.

Looks good.


https://reviews.llvm.org/D36684



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


[PATCH] D36142: clang-format: [JS] do not insert whitespace in call positions.

2017-08-14 Thread Daniel Jasper via Phabricator via cfe-commits
djasper accepted this revision.
djasper added a comment.
This revision is now accepted and ready to land.

Looks good.


https://reviews.llvm.org/D36142



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


[PATCH] D36686: [clang-diff] Add option to compare files across git revisions

2017-08-14 Thread Johannes Altmanninger via Phabricator via cfe-commits
johannes created this revision.

This adds a command line option "-git-rev=".
When it is used, only one filename is accepted.  The file in its version
in the specified revision is compared against the current version. Note
that this calls `git checkout` in the current directory.


https://reviews.llvm.org/D36686

Files:
  tools/clang-diff/ClangDiff.cpp

Index: tools/clang-diff/ClangDiff.cpp
===
--- tools/clang-diff/ClangDiff.cpp
+++ tools/clang-diff/ClangDiff.cpp
@@ -16,6 +16,7 @@
 #include "clang/Tooling/CommonOptionsParser.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Program.h"
 
 using namespace llvm;
 using namespace clang;
@@ -33,9 +34,9 @@
 cl::desc("Print the internal representation of the AST as JSON."),
 cl::init(false), cl::cat(ClangDiffCategory));
 
-static cl::opt
-PrintMatches("dump-matches", cl::desc("Print the matched nodes."),
- cl::init(false), cl::cat(ClangDiffCategory));
+static cl::opt PrintMatches("dump-matches",
+  cl::desc("Print the matched nodes."),
+  cl::init(false), cl::cat(ClangDiffCategory));
 
 static cl::opt HtmlDiff("html",
   cl::desc("Output a side-by-side diff in HTML."),
@@ -55,6 +56,11 @@
   cl::Optional, cl::init(""),
   cl::cat(ClangDiffCategory));
 
+static cl::opt
+GitRevision("git-rev", cl::desc("Compare the file from a checkout of this "
+"revision with the current version."),
+cl::Optional, cl::init(""), cl::cat(ClangDiffCategory));
+
 static cl::opt MaxSize("s", cl::desc(""), cl::Optional,
 cl::init(-1), cl::cat(ClangDiffCategory));
 
@@ -438,6 +444,19 @@
   }
 }
 
+std::string Exec(const char *Command) {
+  char Buffer[128];
+  std::string Result;
+  std::shared_ptr Pipe(popen(Command, "r"), pclose);
+  if (!Pipe)
+return Result;
+  while (!feof(Pipe.get())) {
+if (fgets(Buffer, 128, Pipe.get()) != nullptr)
+  Result += Buffer;
+  }
+  return Result;
+}
+
 int main(int argc, const char **argv) {
   std::string ErrorMessage;
   std::unique_ptr CommonCompilations =
@@ -473,13 +492,40 @@
 return 0;
   }
 
-  if (DestinationPath.empty()) {
+  if (DestinationPath.empty() && GitRevision.empty()) {
 llvm::errs() << "Error: Exactly two paths are required.\n";
 return 1;
   }
 
-  std::unique_ptr Src = getAST(CommonCompilations, SourcePath);
-  std::unique_ptr Dst = getAST(CommonCompilations, DestinationPath);
+  std::unique_ptr Src, Dst;
+
+  if (!GitRevision.empty()) {
+std::string CurrentRevision, Git;
+auto ErrorOrGit = llvm::sys::findProgramByName("git");
+if (!ErrorOrGit) {
+  llvm::errs() << "Error: Could not find git executable.\n";
+  return 1;
+}
+Git = ErrorOrGit.get();
+CurrentRevision = Exec("git rev-parse HEAD");
+*std::find(CurrentRevision.begin(), CurrentRevision.end(), '\n') = '\0';
+const char *Checkout[] = {"git", "checkout", GitRevision.data(), nullptr};
+if (llvm::sys::ExecuteAndWait(Git, Checkout)) {
+  llvm::errs() << "Error: Failed to checkout " << GitRevision << "\n";
+  return 1;
+}
+Src = getAST(CommonCompilations, SourcePath);
+Checkout[2] = CurrentRevision.data();
+if (llvm::sys::ExecuteAndWait(Git, Checkout)) {
+  llvm::errs() << "Error: Failed to checkout " << CurrentRevision << "\n";
+  return 1;
+}
+Dst = getAST(CommonCompilations, SourcePath);
+  } else {
+Src = getAST(CommonCompilations, SourcePath);
+Dst = getAST(CommonCompilations, DestinationPath);
+  }
+
   if (!Src || !Dst)
 return 1;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36687: [clang-diff] Match nodes with the same parent and same value

2017-08-14 Thread Johannes Altmanninger via Phabricator via cfe-commits
johannes created this revision.

This adds another pass to the matching algorithm that tries to match nodes with
common parents, if they have similar values.


https://reviews.llvm.org/D36687

Files:
  include/clang/Tooling/ASTDiff/ASTDiff.h
  lib/Tooling/ASTDiff/ASTDiff.cpp
  test/Tooling/clang-diff-bottomup.cpp
  test/Tooling/clang-diff-heuristics.cpp
  test/Tooling/clang-diff-opt.cpp
  tools/clang-diff/ClangDiff.cpp

Index: tools/clang-diff/ClangDiff.cpp
===
--- tools/clang-diff/ClangDiff.cpp
+++ tools/clang-diff/ClangDiff.cpp
@@ -535,7 +535,9 @@
   if (!StopAfter.empty()) {
 if (StopAfter == "topdown")
   Options.StopAfterTopDown = true;
-else if (StopAfter != "bottomup") {
+else if (StopAfter == "bottomup")
+  Options.StopAfterBottomUp = true;
+else {
   llvm::errs() << "Error: Invalid argument for -stop-after\n";
   return 1;
 }
Index: test/Tooling/clang-diff-opt.cpp
===
--- test/Tooling/clang-diff-opt.cpp
+++ test/Tooling/clang-diff-opt.cpp
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -E %s > %t.src.cpp
 // RUN: %clang_cc1 -E %s > %t.dst.cpp -DDEST
-// RUN: clang-diff -dump-matches -s=10 %t.src.cpp %t.dst.cpp -- | FileCheck %s
+// RUN: clang-diff -dump-matches -s=10 -stop-after=bottomup %t.src.cpp %t.dst.cpp -- | FileCheck %s
 //
 // Test the behaviour of the matching according to the optimal tree edit
 // distance, implemented with Zhang and Shasha's algorithm.
@@ -41,5 +41,5 @@
   // CHECK: Delete NullStmt(22)
   ;; {{;;}}
 }
- 
+
 #endif
Index: test/Tooling/clang-diff-heuristics.cpp
===
--- /dev/null
+++ test/Tooling/clang-diff-heuristics.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -E %s > %t.src.cpp
+// RUN: %clang_cc1 -E %s > %t.dst.cpp -DDEST
+// RUN: clang-diff -dump-matches -s=0 %t.src.cpp %t.dst.cpp -- | FileCheck %s
+//
+// Test the heuristics, with maxsize set to 0, so that the optimal matching will never be applied.
+
+#ifndef DEST
+
+void f1() {;}
+
+void f2(int) {;}
+
+#else
+
+// same parents, same value
+// CHECK: Match FunctionDecl: f1(void ())(1) to FunctionDecl: f1(void ())(1)
+// CHECK: Match CompoundStmt
+void f1() {}
+
+// same parents, same identifier
+// CHECK: Match FunctionDecl: f2(void (int))(4) to FunctionDecl: f2(void ())(3)
+// CHECK: Match CompoundStmt
+void f2() {}
+
+#endif
Index: test/Tooling/clang-diff-bottomup.cpp
===
--- test/Tooling/clang-diff-bottomup.cpp
+++ test/Tooling/clang-diff-bottomup.cpp
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -E %s > %t.src.cpp
 // RUN: %clang_cc1 -E %s > %t.dst.cpp -DDEST
-// RUN: clang-diff -dump-matches -s=0 %t.src.cpp %t.dst.cpp -- | FileCheck %s
+// RUN: clang-diff -dump-matches -s=0 -stop-after=bottomup %t.src.cpp %t.dst.cpp -- | FileCheck %s
 //
 // Test the bottom-up matching, with maxsize set to 0, so that the optimal matching will never be applied.
 
Index: lib/Tooling/ASTDiff/ASTDiff.cpp
===
--- lib/Tooling/ASTDiff/ASTDiff.cpp
+++ lib/Tooling/ASTDiff/ASTDiff.cpp
@@ -94,15 +94,23 @@
   // Descendants are only considered to be equal when they are mapped in M.
   double getJaccardSimilarity(const Mapping &M, NodeId Id1, NodeId Id2) const;
 
+  double getNodeSimilarity(const Mapping &M, NodeId Id1, NodeId Id2) const;
+
   // Returns the node that has the highest degree of similarity.
   NodeId findCandidate(const Mapping &M, NodeId Id1) const;
 
+  NodeId findCandidateFromChildren(const Mapping &M, NodeId Id1,
+   NodeId P2) const;
+
   // Returns a mapping of identical subtrees.
   Mapping matchTopDown() const;
 
   // Tries to match any yet unmapped nodes, in a bottom-up fashion.
   void matchBottomUp(Mapping &M) const;
 
+  // Matches nodes, whose parents are matched.
+  void matchChildren(Mapping &M);
+
   const ComparisonOptions &Options;
 
   friend class ZhangShashaMatcher;
@@ -828,6 +836,23 @@
   return CommonDescendants / Denominator;
 }
 
+double ASTDiff::Impl::getNodeSimilarity(const Mapping &M, NodeId Id1,
+NodeId Id2) const {
+  const Node &N1 = T1.getNode(Id1);
+  const Node &N2 = T2.getNode(Id2);
+  auto Ident1 = N1.getIdentifier(), Ident2 = N2.getIdentifier();
+
+  bool SameValue = T1.getNodeValue(Id1) == T2.getNodeValue(Id2);
+  auto SameIdent = Ident1 && Ident2 && *Ident1 == *Ident2;
+
+  double NodeSimilarity = 0;
+  NodeSimilarity += SameValue;
+  NodeSimilarity += SameIdent;
+
+  assert(haveSameParents(M, Id1, Id2));
+  return NodeSimilarity * Options.MinSimilarity;
+}
+
 NodeId ASTDiff::Impl::findCandidate(const Mapping &M, NodeId Id1) const {
   NodeId Candidate;
   double HighestSimilarity = 0.0;
@@ -845,6 +870,25 @@
   return Candidate;
 }
 
+NodeId ASTDiff::Impl::findCandidateFromChildren(const 

[PATCH] D36688: [clang-diff] Fix matching for unnamed NamedDecs

2017-08-14 Thread Johannes Altmanninger via Phabricator via cfe-commits
johannes created this revision.
Herald added a subscriber: klimek.

This makes Node::getIdentifier return a valid value for special
NamedDecl nodes that do not have a name, such as ctors, dtors
and unnamed classes / namespaces.


https://reviews.llvm.org/D36688

Files:
  lib/Tooling/ASTDiff/ASTDiff.cpp
  test/Tooling/clang-diff-heuristics.cpp


Index: test/Tooling/clang-diff-heuristics.cpp
===
--- test/Tooling/clang-diff-heuristics.cpp
+++ test/Tooling/clang-diff-heuristics.cpp
@@ -10,6 +10,8 @@
 
 void f2(int) {;}
 
+class C3 { C3(); };
+
 #else
 
 // same parents, same value
@@ -22,4 +24,8 @@
 // CHECK: Match CompoundStmt
 void f2() {}
 
+// same parents, same identifier
+// CHECK: Match CXXConstructorDecl: :C3(void ())(9) to CXXConstructorDecl: 
:C3(void (int))(6)
+class C3 { C3(int); };
+
 #endif
Index: lib/Tooling/ASTDiff/ASTDiff.cpp
===
--- lib/Tooling/ASTDiff/ASTDiff.cpp
+++ lib/Tooling/ASTDiff/ASTDiff.cpp
@@ -384,8 +384,7 @@
   // Strip the qualifier, if Val refers to somthing in the current scope.
   // But leave one leading ':' in place, so that we know that this is a
   // relative path.
-  if (!ContextPrefix.empty() &&
-  StringRef(Val).startswith(ContextPrefix))
+  if (!ContextPrefix.empty() && StringRef(Val).startswith(ContextPrefix))
 Val = Val.substr(ContextPrefix.size() + 1);
   return Val;
 }
@@ -715,14 +714,18 @@
   if (auto *ND = ASTNode.get()) {
 if (ND->getDeclName().isIdentifier())
   return ND->getQualifiedNameAsString();
+else
+  return std::string();
   }
   return llvm::None;
 }
 
 llvm::Optional Node::getIdentifier() const {
   if (auto *ND = ASTNode.get()) {
 if (ND->getDeclName().isIdentifier())
   return ND->getName();
+else
+  return StringRef();
   }
   return llvm::None;
 }


Index: test/Tooling/clang-diff-heuristics.cpp
===
--- test/Tooling/clang-diff-heuristics.cpp
+++ test/Tooling/clang-diff-heuristics.cpp
@@ -10,6 +10,8 @@
 
 void f2(int) {;}
 
+class C3 { C3(); };
+
 #else
 
 // same parents, same value
@@ -22,4 +24,8 @@
 // CHECK: Match CompoundStmt
 void f2() {}
 
+// same parents, same identifier
+// CHECK: Match CXXConstructorDecl: :C3(void ())(9) to CXXConstructorDecl: :C3(void (int))(6)
+class C3 { C3(int); };
+
 #endif
Index: lib/Tooling/ASTDiff/ASTDiff.cpp
===
--- lib/Tooling/ASTDiff/ASTDiff.cpp
+++ lib/Tooling/ASTDiff/ASTDiff.cpp
@@ -384,8 +384,7 @@
   // Strip the qualifier, if Val refers to somthing in the current scope.
   // But leave one leading ':' in place, so that we know that this is a
   // relative path.
-  if (!ContextPrefix.empty() &&
-  StringRef(Val).startswith(ContextPrefix))
+  if (!ContextPrefix.empty() && StringRef(Val).startswith(ContextPrefix))
 Val = Val.substr(ContextPrefix.size() + 1);
   return Val;
 }
@@ -715,14 +714,18 @@
   if (auto *ND = ASTNode.get()) {
 if (ND->getDeclName().isIdentifier())
   return ND->getQualifiedNameAsString();
+else
+  return std::string();
   }
   return llvm::None;
 }
 
 llvm::Optional Node::getIdentifier() const {
   if (auto *ND = ASTNode.get()) {
 if (ND->getDeclName().isIdentifier())
   return ND->getName();
+else
+  return StringRef();
   }
   return llvm::None;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r310851 - clang-format: [JS] do not insert whitespace in call positions.

2017-08-14 Thread Martin Probst via cfe-commits
Author: mprobst
Date: Mon Aug 14 09:08:16 2017
New Revision: 310851

URL: http://llvm.org/viewvc/llvm-project?rev=310851&view=rev
Log:
clang-format: [JS] do not insert whitespace in call positions.

Summary:
In JavaScript, may keywords can be used in method names and thus call sites:

foo.delete();
foo.instanceof();

clang-format would previously insert whitespace after the `instanceof`. This
change generically skips inserting whitespace between a keyword and a
parenthesis if preceded by a dot, i.e. in a callsite.

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=310851&r1=310850&r2=310851&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Aug 14 09:08:16 2017
@@ -2367,13 +2367,20 @@ bool TokenAnnotator::spaceRequiredBefore
 Left.isOneOf(Keywords.kw_function, Keywords.kw_yield,
  Keywords.kw_extends, Keywords.kw_implements))
   return true;
-// JS methods can use some keywords as names (e.g. `delete()`).
-if (Right.is(tok::l_paren) && Line.MustBeDeclaration &&
-Left.Tok.getIdentifierInfo())
-  return false;
-if (Right.is(tok::l_paren) &&
-Left.isOneOf(tok::kw_throw, Keywords.kw_await, Keywords.kw_typeof, 
tok::kw_void))
-  return true;
+if (Right.is(tok::l_paren)) {
+  // JS methods can use some keywords as names (e.g. `delete()`).
+  if (Line.MustBeDeclaration && Left.Tok.getIdentifierInfo())
+return false;
+  // Valid JS method names can include keywords, e.g. `foo.delete()` or
+  // `bar.instanceof()`. Recognize call positions by preceding period.
+  if (Left.Previous && Left.Previous->is(tok::period) &&
+  Left.Tok.getIdentifierInfo())
+return false;
+  // Additional unary JavaScript operators that need a space after.
+  if (Left.isOneOf(tok::kw_throw, Keywords.kw_await, Keywords.kw_typeof,
+   tok::kw_void))
+return true;
+}
 if ((Left.isOneOf(Keywords.kw_let, Keywords.kw_var, Keywords.kw_in,
   tok::kw_const) ||
  // "of" is only a keyword if it appears after another identifier

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=310851&r1=310850&r2=310851&view=diff
==
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Mon Aug 14 09:08:16 2017
@@ -271,14 +271,21 @@ TEST_F(FormatTestJS, ReservedWords) {
   verifyFormat("x.case = 1;");
   verifyFormat("x.interface = 1;");
   verifyFormat("x.for = 1;");
-  verifyFormat("x.of() = 1;");
+  verifyFormat("x.of();");
   verifyFormat("of(null);");
   verifyFormat("import {of} from 'x';");
-  verifyFormat("x.in() = 1;");
-  verifyFormat("x.let() = 1;");
-  verifyFormat("x.var() = 1;");
-  verifyFormat("x.for() = 1;");
-  verifyFormat("x.as() = 1;");
+  verifyFormat("x.in();");
+  verifyFormat("x.let();");
+  verifyFormat("x.var();");
+  verifyFormat("x.for();");
+  verifyFormat("x.as();");
+  verifyFormat("x.instanceof();");
+  verifyFormat("x.switch();");
+  verifyFormat("x.case();");
+  verifyFormat("x.delete();");
+  verifyFormat("x.throw();");
+  verifyFormat("x.throws();");
+  verifyFormat("x.if();");
   verifyFormat("x = {\n"
"  a: 12,\n"
"  interface: 1,\n"
@@ -1228,7 +1235,6 @@ TEST_F(FormatTestJS, TryCatch) {
   // But, of course, "catch" is a perfectly fine function name in JavaScript.
   verifyFormat("someObject.catch();");
   verifyFormat("someObject.new();");
-  verifyFormat("someObject.delete();");
 }
 
 TEST_F(FormatTestJS, StringLiteralConcatenation) {


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


[PATCH] D36142: clang-format: [JS] do not insert whitespace in call positions.

2017-08-14 Thread Martin Probst via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL310851: clang-format: [JS] do not insert whitespace in call 
positions. (authored by mprobst).

Repository:
  rL LLVM

https://reviews.llvm.org/D36142

Files:
  cfe/trunk/lib/Format/TokenAnnotator.cpp
  cfe/trunk/unittests/Format/FormatTestJS.cpp


Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -2367,13 +2367,20 @@
 Left.isOneOf(Keywords.kw_function, Keywords.kw_yield,
  Keywords.kw_extends, Keywords.kw_implements))
   return true;
-// JS methods can use some keywords as names (e.g. `delete()`).
-if (Right.is(tok::l_paren) && Line.MustBeDeclaration &&
-Left.Tok.getIdentifierInfo())
-  return false;
-if (Right.is(tok::l_paren) &&
-Left.isOneOf(tok::kw_throw, Keywords.kw_await, Keywords.kw_typeof, 
tok::kw_void))
-  return true;
+if (Right.is(tok::l_paren)) {
+  // JS methods can use some keywords as names (e.g. `delete()`).
+  if (Line.MustBeDeclaration && Left.Tok.getIdentifierInfo())
+return false;
+  // Valid JS method names can include keywords, e.g. `foo.delete()` or
+  // `bar.instanceof()`. Recognize call positions by preceding period.
+  if (Left.Previous && Left.Previous->is(tok::period) &&
+  Left.Tok.getIdentifierInfo())
+return false;
+  // Additional unary JavaScript operators that need a space after.
+  if (Left.isOneOf(tok::kw_throw, Keywords.kw_await, Keywords.kw_typeof,
+   tok::kw_void))
+return true;
+}
 if ((Left.isOneOf(Keywords.kw_let, Keywords.kw_var, Keywords.kw_in,
   tok::kw_const) ||
  // "of" is only a keyword if it appears after another identifier
Index: cfe/trunk/unittests/Format/FormatTestJS.cpp
===
--- cfe/trunk/unittests/Format/FormatTestJS.cpp
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp
@@ -271,14 +271,21 @@
   verifyFormat("x.case = 1;");
   verifyFormat("x.interface = 1;");
   verifyFormat("x.for = 1;");
-  verifyFormat("x.of() = 1;");
+  verifyFormat("x.of();");
   verifyFormat("of(null);");
   verifyFormat("import {of} from 'x';");
-  verifyFormat("x.in() = 1;");
-  verifyFormat("x.let() = 1;");
-  verifyFormat("x.var() = 1;");
-  verifyFormat("x.for() = 1;");
-  verifyFormat("x.as() = 1;");
+  verifyFormat("x.in();");
+  verifyFormat("x.let();");
+  verifyFormat("x.var();");
+  verifyFormat("x.for();");
+  verifyFormat("x.as();");
+  verifyFormat("x.instanceof();");
+  verifyFormat("x.switch();");
+  verifyFormat("x.case();");
+  verifyFormat("x.delete();");
+  verifyFormat("x.throw();");
+  verifyFormat("x.throws();");
+  verifyFormat("x.if();");
   verifyFormat("x = {\n"
"  a: 12,\n"
"  interface: 1,\n"
@@ -1228,7 +1235,6 @@
   // But, of course, "catch" is a perfectly fine function name in JavaScript.
   verifyFormat("someObject.catch();");
   verifyFormat("someObject.new();");
-  verifyFormat("someObject.delete();");
 }
 
 TEST_F(FormatTestJS, StringLiteralConcatenation) {


Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -2367,13 +2367,20 @@
 Left.isOneOf(Keywords.kw_function, Keywords.kw_yield,
  Keywords.kw_extends, Keywords.kw_implements))
   return true;
-// JS methods can use some keywords as names (e.g. `delete()`).
-if (Right.is(tok::l_paren) && Line.MustBeDeclaration &&
-Left.Tok.getIdentifierInfo())
-  return false;
-if (Right.is(tok::l_paren) &&
-Left.isOneOf(tok::kw_throw, Keywords.kw_await, Keywords.kw_typeof, tok::kw_void))
-  return true;
+if (Right.is(tok::l_paren)) {
+  // JS methods can use some keywords as names (e.g. `delete()`).
+  if (Line.MustBeDeclaration && Left.Tok.getIdentifierInfo())
+return false;
+  // Valid JS method names can include keywords, e.g. `foo.delete()` or
+  // `bar.instanceof()`. Recognize call positions by preceding period.
+  if (Left.Previous && Left.Previous->is(tok::period) &&
+  Left.Tok.getIdentifierInfo())
+return false;
+  // Additional unary JavaScript operators that need a space after.
+  if (Left.isOneOf(tok::kw_throw, Keywords.kw_await, Keywords.kw_typeof,
+   tok::kw_void))
+return true;
+}
 if ((Left.isOneOf(Keywords.kw_let, Keywords.kw_var, Keywords.kw_in,
   tok::kw_const) ||
  // "of" is only a keyword if it appears after another identifier
Index: cfe/trunk/unittests/Format/FormatTestJS.cpp
=

r310852 - clang-format: [JS] wrap optional properties in type aliases.

2017-08-14 Thread Martin Probst via cfe-commits
Author: mprobst
Date: Mon Aug 14 09:09:08 2017
New Revision: 310852

URL: http://llvm.org/viewvc/llvm-project?rev=310852&view=rev
Log:
clang-format: [JS] wrap optional properties in type aliases.

Summary:
clang-format wraps object literal keys in an object literal if they are
marked as `TT_SelectorName`s and/or the colon is marked as
`TT_DictLiteral`. Previously, clang-format would accidentally work
because colons in type aliases were marked as `TT_DictLiteral`. r310367
fixed this to assing `TT_JsTypeColon`, which broke wrapping in certain
situations. However the root cause was that clang-format incorrectly
didn't skip questionmarks when detecting selector name.

This change fixes both locations to (1) assign `TT_SelectorName` and (2)
treat `TT_JsTypeColon` like `TT_DictLiteral`.

Previously:

type X = {
  a: string, b?: string,
};

Now:

type X = {
  a: string,
  b?: string,
};

Reviewers: djasper, sammccall

Subscribers: cfe-commits, klimek

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

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=310852&r1=310851&r2=310852&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Aug 14 09:09:08 2017
@@ -459,6 +459,8 @@ private:
 updateParameterCount(Left, CurrentToken);
 if (CurrentToken->isOneOf(tok::colon, tok::l_brace, tok::less)) {
   FormatToken *Previous = CurrentToken->getPreviousNonComment();
+  if (Previous->is(TT_JsTypeOptionalQuestion))
+Previous = Previous->getPreviousNonComment();
   if (((CurrentToken->is(tok::colon) &&
 (!Contexts.back().ColonIsDictLiteral || !Style.isCpp())) ||
Style.Language == FormatStyle::LK_Proto ||
@@ -1601,7 +1603,7 @@ private:
   if (Current->is(TT_ConditionalExpr))
 return prec::Conditional;
   if (NextNonComment && Current->is(TT_SelectorName) &&
-  (NextNonComment->is(TT_DictLiteral) ||
+  (NextNonComment->isOneOf(TT_DictLiteral, TT_JsTypeColon) ||
((Style.Language == FormatStyle::LK_Proto ||
  Style.Language == FormatStyle::LK_TextProto) &&
 NextNonComment->is(tok::less

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=310852&r1=310851&r2=310852&view=diff
==
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Mon Aug 14 09:09:08 2017
@@ -1561,6 +1561,10 @@ TEST_F(FormatTestJS, TypeAliases) {
"  y: number\n"
"};\n"
"class C {}");
+  verifyFormat("export type X = {\n"
+   "  a: string,\n"
+   "  b?: string,\n"
+   "};\n");
 }
 
 TEST_F(FormatTestJS, TypeInterfaceLineWrapping) {


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


[PATCH] D36684: clang-format: [JS] wrap optional properties in type aliases.

2017-08-14 Thread Martin Probst via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL310852: clang-format: [JS] wrap optional properties in type 
aliases. (authored by mprobst).

Repository:
  rL LLVM

https://reviews.llvm.org/D36684

Files:
  cfe/trunk/lib/Format/TokenAnnotator.cpp
  cfe/trunk/unittests/Format/FormatTestJS.cpp


Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -459,6 +459,8 @@
 updateParameterCount(Left, CurrentToken);
 if (CurrentToken->isOneOf(tok::colon, tok::l_brace, tok::less)) {
   FormatToken *Previous = CurrentToken->getPreviousNonComment();
+  if (Previous->is(TT_JsTypeOptionalQuestion))
+Previous = Previous->getPreviousNonComment();
   if (((CurrentToken->is(tok::colon) &&
 (!Contexts.back().ColonIsDictLiteral || !Style.isCpp())) ||
Style.Language == FormatStyle::LK_Proto ||
@@ -1601,7 +1603,7 @@
   if (Current->is(TT_ConditionalExpr))
 return prec::Conditional;
   if (NextNonComment && Current->is(TT_SelectorName) &&
-  (NextNonComment->is(TT_DictLiteral) ||
+  (NextNonComment->isOneOf(TT_DictLiteral, TT_JsTypeColon) ||
((Style.Language == FormatStyle::LK_Proto ||
  Style.Language == FormatStyle::LK_TextProto) &&
 NextNonComment->is(tok::less
Index: cfe/trunk/unittests/Format/FormatTestJS.cpp
===
--- cfe/trunk/unittests/Format/FormatTestJS.cpp
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp
@@ -1561,6 +1561,10 @@
"  y: number\n"
"};\n"
"class C {}");
+  verifyFormat("export type X = {\n"
+   "  a: string,\n"
+   "  b?: string,\n"
+   "};\n");
 }
 
 TEST_F(FormatTestJS, TypeInterfaceLineWrapping) {


Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -459,6 +459,8 @@
 updateParameterCount(Left, CurrentToken);
 if (CurrentToken->isOneOf(tok::colon, tok::l_brace, tok::less)) {
   FormatToken *Previous = CurrentToken->getPreviousNonComment();
+  if (Previous->is(TT_JsTypeOptionalQuestion))
+Previous = Previous->getPreviousNonComment();
   if (((CurrentToken->is(tok::colon) &&
 (!Contexts.back().ColonIsDictLiteral || !Style.isCpp())) ||
Style.Language == FormatStyle::LK_Proto ||
@@ -1601,7 +1603,7 @@
   if (Current->is(TT_ConditionalExpr))
 return prec::Conditional;
   if (NextNonComment && Current->is(TT_SelectorName) &&
-  (NextNonComment->is(TT_DictLiteral) ||
+  (NextNonComment->isOneOf(TT_DictLiteral, TT_JsTypeColon) ||
((Style.Language == FormatStyle::LK_Proto ||
  Style.Language == FormatStyle::LK_TextProto) &&
 NextNonComment->is(tok::less
Index: cfe/trunk/unittests/Format/FormatTestJS.cpp
===
--- cfe/trunk/unittests/Format/FormatTestJS.cpp
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp
@@ -1561,6 +1561,10 @@
"  y: number\n"
"};\n"
"class C {}");
+  verifyFormat("export type X = {\n"
+   "  a: string,\n"
+   "  b?: string,\n"
+   "};\n");
 }
 
 TEST_F(FormatTestJS, TypeInterfaceLineWrapping) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36686: [clang-diff] Add option to compare files across git revisions

2017-08-14 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

It might be useful to have both source and destination in a different revision. 
Maybe something like `-src-git-rev` and `-dst-git-rev`?


https://reviews.llvm.org/D36686



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


[PATCH] D36672: [clang-tidy] readability-non-const-parameter: fixit on all function declarations

2017-08-14 Thread Daniel Marjamäki via Phabricator via cfe-commits
danielmarjamaki added a comment.

LGTM. But others should approve.


Repository:
  rL LLVM

https://reviews.llvm.org/D36672



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


r310853 - [rename] Introduce symbol occurrences

2017-08-14 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Mon Aug 14 09:19:24 2017
New Revision: 310853

URL: http://llvm.org/viewvc/llvm-project?rev=310853&view=rev
Log:
[rename] Introduce symbol occurrences

Symbol occurrences store the results of local rename and will also be used for
the global, indexed rename results. Their kind is used to determine whether they
should be renamed automatically or not. They can be converted to a set of
AtomicChanges as well.

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

Added:
cfe/trunk/include/clang/Tooling/Refactoring/Rename/SymbolName.h
cfe/trunk/include/clang/Tooling/Refactoring/Rename/SymbolOccurrences.h
cfe/trunk/lib/Tooling/Refactoring/Rename/SymbolOccurrences.cpp
Modified:
cfe/trunk/include/clang/Tooling/Refactoring/Rename/RenamingAction.h
cfe/trunk/include/clang/Tooling/Refactoring/Rename/USRLocFinder.h
cfe/trunk/lib/Tooling/Refactoring/CMakeLists.txt
cfe/trunk/lib/Tooling/Refactoring/Rename/RenamingAction.cpp
cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp

Modified: cfe/trunk/include/clang/Tooling/Refactoring/Rename/RenamingAction.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Refactoring/Rename/RenamingAction.h?rev=310853&r1=310852&r2=310853&view=diff
==
--- cfe/trunk/include/clang/Tooling/Refactoring/Rename/RenamingAction.h 
(original)
+++ cfe/trunk/include/clang/Tooling/Refactoring/Rename/RenamingAction.h Mon Aug 
14 09:19:24 2017
@@ -16,6 +16,9 @@
 #define LLVM_CLANG_TOOLING_REFACTOR_RENAME_RENAMING_ACTION_H
 
 #include "clang/Tooling/Refactoring.h"
+#include "clang/Tooling/Refactoring/AtomicChange.h"
+#include "clang/Tooling/Refactoring/Rename/SymbolOccurrences.h"
+#include "llvm/Support/Error.h"
 
 namespace clang {
 class ASTConsumer;
@@ -42,6 +45,13 @@ private:
   bool PrintLocations;
 };
 
+/// Returns source replacements that correspond to the rename of the given
+/// symbol occurrences.
+llvm::Expected>
+createRenameReplacements(const SymbolOccurrences &Occurrences,
+ const SourceManager &SM,
+ ArrayRef NewNameStrings);
+
 /// Rename all symbols identified by the given USRs.
 class QualifiedRenamingAction {
 public:

Added: cfe/trunk/include/clang/Tooling/Refactoring/Rename/SymbolName.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Refactoring/Rename/SymbolName.h?rev=310853&view=auto
==
--- cfe/trunk/include/clang/Tooling/Refactoring/Rename/SymbolName.h (added)
+++ cfe/trunk/include/clang/Tooling/Refactoring/Rename/SymbolName.h Mon Aug 14 
09:19:24 2017
@@ -0,0 +1,49 @@
+//===--- SymbolName.h - Clang refactoring library 
-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLING_REFACTOR_RENAME_SYMBOL_NAME_H
+#define LLVM_CLANG_TOOLING_REFACTOR_RENAME_SYMBOL_NAME_H
+
+#include "clang/Basic/LLVM.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+
+namespace clang {
+namespace tooling {
+
+/// A name of a symbol.
+///
+/// Symbol's name can be composed of multiple strings. For example, Objective-C
+/// methods can contain multiple argument lables:
+///
+/// \code
+/// - (void) myMethodNamePiece: (int)x anotherNamePieces:(int)y;
+/// //   ^~ string 0 ~ ^~ string 1 ~
+/// \endcode
+class SymbolName {
+public:
+  SymbolName(StringRef Name) {
+// While empty symbol names are valid (Objective-C selectors can have empty
+// name pieces), occurrences Objective-C selectors are created using an
+// array of strings instead of just one string.
+assert(!Name.empty() && "Invalid symbol name!");
+this->Name.push_back(Name.str());
+  }
+
+  ArrayRef getNamePieces() const { return Name; }
+
+private:
+  llvm::SmallVector Name;
+};
+
+} // end namespace tooling
+} // end namespace clang
+
+#endif // LLVM_CLANG_TOOLING_REFACTOR_RENAME_SYMBOL_NAME_H

Added: cfe/trunk/include/clang/Tooling/Refactoring/Rename/SymbolOccurrences.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Refactoring/Rename/SymbolOccurrences.h?rev=310853&view=auto
==
--- cfe/trunk/include/clang/Tooling/Refactoring/Rename/SymbolOccurrences.h 
(added)
+++ cfe/trunk/include/clang/Tooling/Refactoring/Rename/SymbolOccurrences.h Mon 
Aug 14 09:19:24 2017
@@ -0,0 +1,91 @@
+//===--- SymbolOccurrences.h - Clang refactoring library 
--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Op

[PATCH] D36156: [rename] Introduce symbol occurrences

2017-08-14 Thread Alex Lorenz via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL310853: [rename] Introduce symbol occurrences (authored by 
arphaman).

Changed prior to commit:
  https://reviews.llvm.org/D36156?vs=110964&id=110999#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D36156

Files:
  cfe/trunk/include/clang/Tooling/Refactoring/Rename/RenamingAction.h
  cfe/trunk/include/clang/Tooling/Refactoring/Rename/SymbolName.h
  cfe/trunk/include/clang/Tooling/Refactoring/Rename/SymbolOccurrences.h
  cfe/trunk/include/clang/Tooling/Refactoring/Rename/USRLocFinder.h
  cfe/trunk/lib/Tooling/Refactoring/CMakeLists.txt
  cfe/trunk/lib/Tooling/Refactoring/Rename/RenamingAction.cpp
  cfe/trunk/lib/Tooling/Refactoring/Rename/SymbolOccurrences.cpp
  cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp

Index: cfe/trunk/lib/Tooling/Refactoring/CMakeLists.txt
===
--- cfe/trunk/lib/Tooling/Refactoring/CMakeLists.txt
+++ cfe/trunk/lib/Tooling/Refactoring/CMakeLists.txt
@@ -3,6 +3,7 @@
 add_clang_library(clangToolingRefactor
   AtomicChange.cpp
   Rename/RenamingAction.cpp
+  Rename/SymbolOccurrences.cpp
   Rename/USRFinder.cpp
   Rename/USRFindingAction.cpp
   Rename/USRLocFinder.cpp
Index: cfe/trunk/lib/Tooling/Refactoring/Rename/SymbolOccurrences.cpp
===
--- cfe/trunk/lib/Tooling/Refactoring/Rename/SymbolOccurrences.cpp
+++ cfe/trunk/lib/Tooling/Refactoring/Rename/SymbolOccurrences.cpp
@@ -0,0 +1,37 @@
+//===--- SymbolOccurrences.cpp - Clang refactoring library ===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "clang/Tooling/Refactoring/Rename/SymbolOccurrences.h"
+#include "clang/Tooling/Refactoring/Rename/SymbolName.h"
+#include "llvm/ADT/STLExtras.h"
+
+using namespace clang;
+using namespace tooling;
+
+SymbolOccurrence::SymbolOccurrence(const SymbolName &Name, OccurrenceKind Kind,
+   ArrayRef Locations)
+: Kind(Kind) {
+  ArrayRef NamePieces = Name.getNamePieces();
+  assert(Locations.size() == NamePieces.size() &&
+ "mismatching number of locations and lengths");
+  assert(!Locations.empty() && "no locations");
+  if (Locations.size() == 1) {
+RangeOrNumRanges = SourceRange(
+Locations[0], Locations[0].getLocWithOffset(NamePieces[0].size()));
+return;
+  }
+  MultipleRanges = llvm::make_unique(Locations.size());
+  RangeOrNumRanges.setBegin(
+  SourceLocation::getFromRawEncoding(Locations.size()));
+  for (const auto &Loc : llvm::enumerate(Locations)) {
+MultipleRanges[Loc.index()] = SourceRange(
+Loc.value(),
+Loc.value().getLocWithOffset(NamePieces[Loc.index()].size()));
+  }
+}
Index: cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
===
--- cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
+++ cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
@@ -23,6 +23,7 @@
 #include "clang/Lex/Lexer.h"
 #include "clang/Tooling/Core/Lookup.h"
 #include "clang/Tooling/Refactoring/RecursiveSymbolVisitor.h"
+#include "clang/Tooling/Refactoring/Rename/SymbolName.h"
 #include "clang/Tooling/Refactoring/Rename/USRFinder.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Casting.h"
@@ -68,11 +69,9 @@
 
   // Non-visitors:
 
-  // \brief Returns a list of unique locations. Duplicate or overlapping
-  // locations are erroneous and should be reported!
-  const std::vector &getLocationsFound() const {
-return LocationsFound;
-  }
+  /// \brief Returns a set of unique symbol occurrences. Duplicate or
+  /// overlapping occurrences are erroneous and should be reported!
+  SymbolOccurrences takeOccurrences() { return std::move(Occurrences); }
 
 private:
   void checkAndAddLocation(SourceLocation Loc) {
@@ -82,17 +81,18 @@
 StringRef TokenName =
 Lexer::getSourceText(CharSourceRange::getTokenRange(BeginLoc, EndLoc),
  Context.getSourceManager(), Context.getLangOpts());
-size_t Offset = TokenName.find(PrevName);
+size_t Offset = TokenName.find(PrevName.getNamePieces()[0]);
 
 // The token of the source location we find actually has the old
 // name.
 if (Offset != StringRef::npos)
-  LocationsFound.push_back(BeginLoc.getLocWithOffset(Offset));
+  Occurrences.emplace_back(PrevName, SymbolOccurrence::MatchingSymbol,
+   BeginLoc.getLocWithOffset(Offset));
   }
 
   const std::set USRSet;
-  const std::string PrevName;
-  std::vector LocationsFound;
+  const SymbolName PrevName;
+  SymbolOccurrences Occurrences;
   const ASTContext &Context;
 };
 
@@ -391,12 +391,11 

Re: r310853 - [rename] Introduce symbol occurrences

2017-08-14 Thread Alex L via cfe-commits
It's an NFC, thus untested.

On 14 August 2017 at 17:19, Alex Lorenz via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: arphaman
> Date: Mon Aug 14 09:19:24 2017
> New Revision: 310853
>
> URL: http://llvm.org/viewvc/llvm-project?rev=310853&view=rev
> Log:
> [rename] Introduce symbol occurrences
>
> Symbol occurrences store the results of local rename and will also be used
> for
> the global, indexed rename results. Their kind is used to determine
> whether they
> should be renamed automatically or not. They can be converted to a set of
> AtomicChanges as well.
>
> Differential Revision: https://reviews.llvm.org/D36156
>
> Added:
> cfe/trunk/include/clang/Tooling/Refactoring/Rename/SymbolName.h
> cfe/trunk/include/clang/Tooling/Refactoring/Rename/SymbolOccurrences.h
> cfe/trunk/lib/Tooling/Refactoring/Rename/SymbolOccurrences.cpp
> Modified:
> cfe/trunk/include/clang/Tooling/Refactoring/Rename/RenamingAction.h
> cfe/trunk/include/clang/Tooling/Refactoring/Rename/USRLocFinder.h
> cfe/trunk/lib/Tooling/Refactoring/CMakeLists.txt
> cfe/trunk/lib/Tooling/Refactoring/Rename/RenamingAction.cpp
> cfe/trunk/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp
>
> Modified: cfe/trunk/include/clang/Tooling/Refactoring/Rename/
> RenamingAction.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/Tooling/Refactoring/Rename/RenamingAction.h?rev=
> 310853&r1=310852&r2=310853&view=diff
> 
> ==
> --- cfe/trunk/include/clang/Tooling/Refactoring/Rename/RenamingAction.h
> (original)
> +++ cfe/trunk/include/clang/Tooling/Refactoring/Rename/RenamingAction.h
> Mon Aug 14 09:19:24 2017
> @@ -16,6 +16,9 @@
>  #define LLVM_CLANG_TOOLING_REFACTOR_RENAME_RENAMING_ACTION_H
>
>  #include "clang/Tooling/Refactoring.h"
> +#include "clang/Tooling/Refactoring/AtomicChange.h"
> +#include "clang/Tooling/Refactoring/Rename/SymbolOccurrences.h"
> +#include "llvm/Support/Error.h"
>
>  namespace clang {
>  class ASTConsumer;
> @@ -42,6 +45,13 @@ private:
>bool PrintLocations;
>  };
>
> +/// Returns source replacements that correspond to the rename of the given
> +/// symbol occurrences.
> +llvm::Expected>
> +createRenameReplacements(const SymbolOccurrences &Occurrences,
> + const SourceManager &SM,
> + ArrayRef NewNameStrings);
> +
>  /// Rename all symbols identified by the given USRs.
>  class QualifiedRenamingAction {
>  public:
>
> Added: cfe/trunk/include/clang/Tooling/Refactoring/Rename/SymbolName.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/Tooling/Refactoring/Rename/SymbolName.h?rev=310853&view=auto
> 
> ==
> --- cfe/trunk/include/clang/Tooling/Refactoring/Rename/SymbolName.h
> (added)
> +++ cfe/trunk/include/clang/Tooling/Refactoring/Rename/SymbolName.h Mon
> Aug 14 09:19:24 2017
> @@ -0,0 +1,49 @@
> +//===--- SymbolName.h - Clang refactoring library
> -===//
> +//
> +// The LLVM Compiler Infrastructure
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
> +//===--
> ===//
> +
> +#ifndef LLVM_CLANG_TOOLING_REFACTOR_RENAME_SYMBOL_NAME_H
> +#define LLVM_CLANG_TOOLING_REFACTOR_RENAME_SYMBOL_NAME_H
> +
> +#include "clang/Basic/LLVM.h"
> +#include "llvm/ADT/ArrayRef.h"
> +#include "llvm/ADT/SmallVector.h"
> +#include "llvm/ADT/StringRef.h"
> +
> +namespace clang {
> +namespace tooling {
> +
> +/// A name of a symbol.
> +///
> +/// Symbol's name can be composed of multiple strings. For example,
> Objective-C
> +/// methods can contain multiple argument lables:
> +///
> +/// \code
> +/// - (void) myMethodNamePiece: (int)x anotherNamePieces:(int)y;
> +/// //   ^~ string 0 ~ ^~ string 1 ~
> +/// \endcode
> +class SymbolName {
> +public:
> +  SymbolName(StringRef Name) {
> +// While empty symbol names are valid (Objective-C selectors can have
> empty
> +// name pieces), occurrences Objective-C selectors are created using
> an
> +// array of strings instead of just one string.
> +assert(!Name.empty() && "Invalid symbol name!");
> +this->Name.push_back(Name.str());
> +  }
> +
> +  ArrayRef getNamePieces() const { return Name; }
> +
> +private:
> +  llvm::SmallVector Name;
> +};
> +
> +} // end namespace tooling
> +} // end namespace clang
> +
> +#endif // LLVM_CLANG_TOOLING_REFACTOR_RENAME_SYMBOL_NAME_H
>
> Added: cfe/trunk/include/clang/Tooling/Refactoring/Rename/
> SymbolOccurrences.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/Tooling/Refactoring/Rename/SymbolOccurrences.h?rev=310853&view=auto
> 
> ==
> --- cfe/trunk/include/clang/T

Re: r310401 - PR19668, PR23034: Fix handling of move constructors and deleted copy

2017-08-14 Thread Diana Picus via cfe-commits
Hi,

I didn't manage to reproduce this at -O0. Yes, I think the version in
1.8.0, slightly modified (see
llvm/utils/unittest/googletest/README.LLVM)

On 14 August 2017 at 17:06, Vassil Vassilev  wrote:
> On 14/08/17 15:59, Diana Picus wrote:
>>
>> No, the buildbots don't build with -O0 (at least not the ones that broke).
>>
>> The command line for that particular object is:
>> build/./bin/clang -fPIC -fvisibility-inlines-hidden -Werror=date-time
>> -std=c++11 -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual
>> -Wmissing-field-initializers -pedantic -Wno-long-long
>> -Wcovered-switch-default -Wnon-virtual-dtor -Wdelete-non-virtual-dtor
>> -Wstring-conversion -fcolor-diagnostics -ffunction-sections
>> -fdata-sections -Wall -std=c++11 -Wno-unused-parameter
>> -Wno-unknown-warning-option -Wno-covered-switch-default
>> -DGTEST_NO_LLVM_RAW_OSTREAM=1 -DGTEST_HAS_RTTI=0
>> -I$LLVM_SRC/llvm/utils/unittest/googletest/include
>> -I/home/diana.picus/linaro-scripts/bisect/llvm/utils/unittest/googletest
>> -I$LLVM_SRC/llvm/projects/compiler-rt/include
>> -I$LLVM_SRC/llvm/projects/compiler-rt/lib
>> -I$LLVM_SRC/llvm/projects/compiler-rt/lib/asan
>> -I$LLVM_SRC/llvm/projects/compiler-rt/lib/sanitizer_common/tests
>> -fno-rtti -O2 -Wno-format -Werror=sign-compare -Wno-non-virtual-dtor
>> -Wno-variadic-macros -gline-tables-only -DASAN_HAS_BLACKLIST=1
>> -DASAN_HAS_EXCEPTIONS=1 -DASAN_UAR=0 -fsanitize=address
>>
>> -fsanitize-blacklist=$LLVM_SRC/llvm/projects/compiler-rt/lib/asan/tests/asan_test.ignore
>> -mllvm -asan-instrumentation-with-call-threshold=0 -march=armv7-a
>> -mfloat-abi=hard -c -o
>> ASAN_INST_TEST_OBJECTS.asan_test.cc.armhf-with-calls.o
>> $LLVM_SRC/compiler-rt/lib/asan/tests/asan_test.cc
>
>   Could you try to reproduce the issue with O0? This would rule out the
> optimizer. Could you resend the O0 ll file, maybe I could find something
> out. IIUC, the gtest version is 1.8.0?
>
>>
>> Why would it contain gtest.cc? It seems to contain gtest.h and a bunch
>> of other internal gtest headers...
>>
>>
>> On 14 August 2017 at 16:51, Vassil Vassilev 
>> wrote:
>>>
>>> On 14/08/17 15:08, Vassil Vassilev wrote:

 On 14/08/17 13:04, Diana Picus wrote:
>
> See attached.

 Thanks! It looks like asan_test.i doesn't have gtest.cc which appears in
 the stack trace. Am I missing something?
>>>
>>>Could you paste the compiler invocation. Are we building with -O0 (I
>>> see
>>> quite a lot of things inline). Could it be an optimizer problem?
>>>
> On 14 August 2017 at 13:30, Vassil Vassilev 
> wrote:
>>
>> On 14/08/17 11:27, Diana Picus wrote:
>>>
>>> Hi,
>>>
>>> Strangely enough, it turns out that if I run
>>> Asan-armhf-with-calls-Noinst-Test on the command line it fails,
>>> although it doesn't fail when run with lit. I've attached the stack
>>> trace from gdb. It looks like some trouble passing down va_arg
>>> parameters, but I haven't looked into too much details. The segfault
>>> happens when we try to do a   ldrb   r3, [r0, r1], with r1 set to 0
>>> by
>>> the current function and r0 passed down from the caller. I'm not sure
>>> if this is the exact same problem as the other tests, but feel free
>>> to
>>> have a look at that code.
>>>
>>> Meanwhile, I've removed some clutter from Asan-armhf-with-calls-Test
>>> (which is the original failure that we were seeing) and left only one
>>> failing test that seemed small enough. I'll try to look at the
>>> disassembly before/after the patch and maybe even run valgrind on it
>>> (running it on the original binary naturally takes forever).
>>>
>>> Let me know if there's anything else I could try. I can also send you
>>> disassembly or even LLVM IR for the Asan-armhf-with-calls-Noinst-Test
>>> if you think it helps.
>>
>> disassembly and LLVM will greatly help as well.
>>
>>> Cheers,
>>> Diana
>>>
>>> On 11 August 2017 at 15:34, Diana Picus 
>>> wrote:

 Well, these are ASAN tests, I'm not sure how that would interact
 with
 Valgrind.
 Anyway, I'll try to reproduce the environment, I'm guessing it would
 be best to catch this in gdb so I can actually see what's going on.

 On 11 August 2017 at 15:21, Vassil Vassilev 
 wrote:
>
> That's really strange. It looks like some random behavior. Did you
> run
> some memory checker like valgrind?
>
> Do the environment provided by the test runner and yours match?
>
> Sent from my phone. Please excuse my brevity.
>
>> On 11 Aug 2017, at 15:58, Diana Picus 
>> wrote:
>>
>> Hi again,
>>
>> I finally got the debug build, but unfortunately the stack traces
>> that
>> the tests print look the same. My suspicion is that this is
>> because

[PATCH] D36200: [Sema] Improve some -Wunguarded-availability diagnostic messages

2017-08-14 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington added a comment.

Ping!


https://reviews.llvm.org/D36200



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


[PATCH] D36200: [Sema] Improve some -Wunguarded-availability diagnostic messages

2017-08-14 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman accepted this revision.
arphaman added a comment.
This revision is now accepted and ready to land.

Sorry for the delay, LGTM


https://reviews.llvm.org/D36200



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


[clang-tools-extra] r310858 - [clang-tidy] Add a close-on-exec check on dup() in Android module.

2017-08-14 Thread Chih-Hung Hsieh via cfe-commits
Author: chh
Date: Mon Aug 14 10:04:16 2017
New Revision: 310858

URL: http://llvm.org/viewvc/llvm-project?rev=310858&view=rev
Log:
[clang-tidy] Add a close-on-exec check on dup() in Android module.

Summary:
dup() is better to be replaced by fcntl() to avoid file descriptor leakage.

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


Added:
clang-tools-extra/trunk/clang-tidy/android/CloexecDupCheck.cpp
clang-tools-extra/trunk/clang-tidy/android/CloexecDupCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/android-cloexec-dup.rst
clang-tools-extra/trunk/test/clang-tidy/android-cloexec-dup.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.cpp
clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.h
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp?rev=310858&r1=310857&r2=310858&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp Mon Aug 14 
10:04:16 2017
@@ -11,6 +11,7 @@
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
 #include "CloexecCreatCheck.h"
+#include "CloexecDupCheck.h"
 #include "CloexecFopenCheck.h"
 #include "CloexecMemfdCreateCheck.h"
 #include "CloexecOpenCheck.h"
@@ -27,6 +28,7 @@ class AndroidModule : public ClangTidyMo
 public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
 CheckFactories.registerCheck("android-cloexec-creat");
+CheckFactories.registerCheck("android-cloexec-dup");
 CheckFactories.registerCheck("android-cloexec-fopen");
 CheckFactories.registerCheck(
 "android-cloexec-memfd-create");

Modified: clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt?rev=310858&r1=310857&r2=310858&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt Mon Aug 14 
10:04:16 2017
@@ -4,6 +4,7 @@ add_clang_library(clangTidyAndroidModule
   AndroidTidyModule.cpp
   CloexecCheck.cpp
   CloexecCreatCheck.cpp
+  CloexecDupCheck.cpp
   CloexecFopenCheck.cpp
   CloexecMemfdCreateCheck.cpp
   CloexecOpenCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.cpp?rev=310858&r1=310857&r2=310858&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.cpp Mon Aug 14 
10:04:16 2017
@@ -100,6 +100,15 @@ void CloexecCheck::insertStringFlag(
   ReplacementText);
 }
 
+StringRef CloexecCheck::getSpellingArg(const MatchFinder::MatchResult &Result,
+   int N) const {
+  const auto *MatchedCall = Result.Nodes.getNodeAs(FuncBindingStr);
+  const SourceManager &SM = *Result.SourceManager;
+  return Lexer::getSourceText(
+  CharSourceRange::getTokenRange(MatchedCall->getArg(N)->getSourceRange()),
+  SM, Result.Context->getLangOpts());
+}
+
 } // namespace android
 } // namespace tidy
 } // namespace clang

Modified: clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.h?rev=310858&r1=310857&r2=310858&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.h (original)
+++ clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.h Mon Aug 14 
10:04:16 2017
@@ -86,6 +86,10 @@ protected:
   /// \param ArgPos The 0-based position of the flag argument.
   void insertStringFlag(const ast_matchers::MatchFinder::MatchResult &Result,
 const char Mode, const int ArgPos);
+
+  /// Helper function to get the spelling of a particular argument.
+  StringRef getSpellingArg(const ast_matchers::MatchFinder::MatchResult 
&Result,
+   int N) const;
 };
 
 } // namespace android

Added: clang-tools-extra/trunk/clang-tidy/android/CloexecDupCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/CloexecDupCheck.cpp?rev=310858&view=auto
===

[PATCH] D35364: [clang-tidy] Add a close-on-exec check on dup() in Android module.

2017-08-14 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL310858: [clang-tidy] Add a close-on-exec check on dup() in 
Android module. (authored by chh).

Changed prior to commit:
  https://reviews.llvm.org/D35364?vs=110753&id=111021#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35364

Files:
  clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
  clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.cpp
  clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.h
  clang-tools-extra/trunk/clang-tidy/android/CloexecDupCheck.cpp
  clang-tools-extra/trunk/clang-tidy/android/CloexecDupCheck.h
  clang-tools-extra/trunk/docs/ReleaseNotes.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/android-cloexec-dup.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
  clang-tools-extra/trunk/test/clang-tidy/android-cloexec-dup.cpp

Index: clang-tools-extra/trunk/docs/ReleaseNotes.rst
===
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst
@@ -70,6 +70,11 @@
   ``AllowConditionalIntegerCasts`` -> ``AllowIntegerConditions``,
   ``AllowConditionalPointerCasts`` -> ``AllowPointerConditions``.
 
+- New `android-cloexec-dup
+  `_ check
+
+  Detects usage of ``dup()``.
+
 - New `android-cloexec-memfd_create
   `_ check
 
Index: clang-tools-extra/trunk/docs/clang-tidy/checks/android-cloexec-dup.rst
===
--- clang-tools-extra/trunk/docs/clang-tidy/checks/android-cloexec-dup.rst
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/android-cloexec-dup.rst
@@ -0,0 +1,18 @@
+.. title:: clang-tidy - android-cloexec-dup
+
+android-cloexec-dup
+===
+
+The usage of ``dup()`` is not recommended, it's better to use ``fcntl()``,
+which can set the close-on-exec flag. Otherwise, an opened sensitive file would
+remain open across a fork+exec to a lower-privileged SELinux domain.
+
+Examples:
+
+.. code-block:: c++
+
+  int fd = dup(oldfd);
+
+  // becomes
+
+  int fd = fcntl(oldfd, F_DUPFD_CLOEXEC);
Index: clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
@@ -5,6 +5,7 @@
 
 .. toctree::
android-cloexec-creat
+   android-cloexec-dup
android-cloexec-fopen
android-cloexec-memfd-create
android-cloexec-open
Index: clang-tools-extra/trunk/test/clang-tidy/android-cloexec-dup.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/android-cloexec-dup.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/android-cloexec-dup.cpp
@@ -0,0 +1,31 @@
+// RUN: %check_clang_tidy %s android-cloexec-dup %t
+
+extern "C" int dup(int oldfd);
+void f() {
+  dup(1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer fcntl() to dup() because fcntl() allows F_DUPFD_CLOEXEC [android-cloexec-dup]
+  // CHECK-FIXES: fcntl(1, F_DUPFD_CLOEXEC);
+  int oldfd = 0;
+  dup(oldfd);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: prefer
+  // CHECK-FIXES: fcntl(oldfd, F_DUPFD_CLOEXEC);
+}
+
+namespace i {
+int dup(int oldfd);
+void g() {
+  dup(0);
+  int oldfd = 1;
+  dup(oldfd);
+}
+} // namespace i
+
+class C {
+public:
+  int dup(int oldfd);
+  void h() {
+dup(0);
+int oldfd = 1;
+dup(oldfd);
+  }
+};
Index: clang-tools-extra/trunk/clang-tidy/android/CloexecDupCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/android/CloexecDupCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/android/CloexecDupCheck.cpp
@@ -0,0 +1,38 @@
+//===--- CloexecDupCheck.cpp - clang-tidy--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "CloexecDupCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+void CloexecDupCheck::registerMatchers(MatchFinder *Finder) {
+  registerMatchersImpl(Finder,
+   functionDecl(returns(isInteger()), hasName("dup"),
+hasParameter(0, hasType(isInteger();
+}
+
+void CloexecDupCheck::check(const MatchFinder::MatchResult &Result) {
+  const std::string &ReplacementText =
+  (Twine("fcntl(") + getSpelli

[PATCH] D34158: For Linux/gnu compatibility, preinclude if the file is available

2017-08-14 Thread Melanie Blower via Phabricator via cfe-commits
mibintc updated this revision to Diff 111019.
mibintc added a comment.

@jyknight recommended adding the new option to skipArgs in Job.cpp.  This 
revision makes that change and tests that in crash-report.c; look OK?


https://reviews.llvm.org/D34158

Files:
  include/clang/Driver/CC1Options.td
  include/clang/Lex/PreprocessorOptions.h
  lib/Driver/Job.cpp
  lib/Driver/ToolChains/Linux.cpp
  lib/Driver/ToolChains/Linux.h
  lib/Frontend/CompilerInvocation.cpp
  lib/Frontend/InitPreprocessor.cpp
  test/Driver/Inputs/stdc-predef/usr/include/stdc-predef.h
  test/Driver/clang_cpp.c
  test/Driver/crash-report-header.h
  test/Driver/crash-report-spaces.c
  test/Driver/crash-report.c
  test/Driver/rewrite-legacy-objc.m
  test/Driver/rewrite-map-in-diagnostics.c
  test/Driver/rewrite-objc.m
  test/Driver/stdc-predef.c
  test/Driver/stdc-predef.i
  test/Index/IBOutletCollection.m
  test/Index/annotate-macro-args.m
  test/Index/annotate-tokens-pp.c
  test/Index/annotate-tokens.c
  test/Index/c-index-getCursor-test.m
  test/Index/get-cursor-macro-args.m
  test/Index/get-cursor.cpp
  test/Preprocessor/ignore-pragmas.c
  unittests/Tooling/TestVisitor.h

Index: lib/Driver/ToolChains/Linux.h
===
--- lib/Driver/ToolChains/Linux.h
+++ lib/Driver/ToolChains/Linux.h
@@ -31,6 +31,8 @@
   void addLibStdCxxIncludePaths(
   const llvm::opt::ArgList &DriverArgs,
   llvm::opt::ArgStringList &CC1Args) const override;
+  void AddGnuIncludeArgs(const llvm::opt::ArgList &DriverArgs,
+  llvm::opt::ArgStringList &CC1Args) const;
   void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs,
   llvm::opt::ArgStringList &CC1Args) const override;
   void AddIAMCUIncludeArgs(const llvm::opt::ArgList &DriverArgs,
Index: lib/Driver/ToolChains/Linux.cpp
===
--- lib/Driver/ToolChains/Linux.cpp
+++ lib/Driver/ToolChains/Linux.cpp
@@ -705,6 +705,8 @@
   addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/include");
 
   addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include");
+
+  AddGnuIncludeArgs(DriverArgs, CC1Args);
 }
 
 static std::string DetectLibcxxIncludePath(StringRef base) {
@@ -743,6 +745,17 @@
   return "";
 }
 
+void Linux::AddGnuIncludeArgs(const llvm::opt::ArgList &DriverArgs,
+  llvm::opt::ArgStringList &CC1Args) const {
+  if (!DriverArgs.hasArg(options::OPT_ffreestanding)) {
+// For gcc compatibility, clang will preinclude 
+// -ffreestanding suppresses this behavior.
+CC1Args.push_back("-fsystem-include-if-exists");
+CC1Args.push_back("stdc-predef.h");
+  }
+}
+
+
 void Linux::addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
  llvm::opt::ArgStringList &CC1Args) const {
   // We need a detected GCC installation on Linux to provide libstdc++'s
Index: lib/Driver/Job.cpp
===
--- lib/Driver/Job.cpp
+++ lib/Driver/Job.cpp
@@ -63,7 +63,7 @@
 .Cases("-internal-externc-isystem", "-iprefix", true)
 .Cases("-iwithprefixbefore", "-isystem", "-iquote", true)
 .Cases("-isysroot", "-I", "-F", "-resource-dir", true)
-.Cases("-iframework", "-include-pch", true)
+.Cases("-iframework", "-include-pch", "-fsystem-include-if-exists", true)
 .Default(false);
   if (IsInclude)
 return HaveCrashVFS ? false : true;
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2517,6 +2517,10 @@
   for (const Arg *A : Args.filtered(OPT_chain_include))
 Opts.ChainedIncludes.emplace_back(A->getValue());
 
+  // Add the ordered list of -fsystem-include-if-exists.
+  for (const Arg *A : Args.filtered(OPT_fsystem_include_if_exists))
+Opts.FSystemIncludeIfExists.emplace_back(A->getValue());
+
   for (const Arg *A : Args.filtered(OPT_remap_file)) {
 std::pair Split = StringRef(A->getValue()).split(';');
 
Index: lib/Frontend/InitPreprocessor.cpp
===
--- lib/Frontend/InitPreprocessor.cpp
+++ lib/Frontend/InitPreprocessor.cpp
@@ -70,6 +70,15 @@
   Builder.append(Twine("#include \"") + File + "\"");
 }
 
+/// AddImplicitSystemIncludeIfExists - Add an implicit system \#include of the 
+/// specified file to the predefines buffer: precheck with __has_include.
+static void AddImplicitSystemIncludeIfExists(MacroBuilder &Builder, 
+ StringRef File) {
+  Builder.append(Twine("#if __has_include( <") + File + ">)");
+  Builder.append(Twine("#include <") + File + ">");
+  Builder.append(Twine("#endif"));
+}
+
 static void AddImplicitIncludeMacros(MacroBuilder &Builder, StringRef File) {
   Builder.append(Twine("#__include_macros \"") + File

Re: r310776 - PR34163: Don't cache an incorrect key function for a class if queried between

2017-08-14 Thread Hans Wennborg via cfe-commits
Sounds good to me. Let's give it another day and see how it goes.

On Fri, Aug 11, 2017 at 6:48 PM, Richard Smith  wrote:
> Hi Hans,
>
> I'd like to get this into Clang 5, but it's not entirely risk-free. Perhaps
> we could leave it in the tree for a little while and then merge if it seems
> OK?
>
> On 11 August 2017 at 18:46, Richard Smith via cfe-commits
>  wrote:
>>
>> Author: rsmith
>> Date: Fri Aug 11 18:46:03 2017
>> New Revision: 310776
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=310776&view=rev
>> Log:
>> PR34163: Don't cache an incorrect key function for a class if queried
>> between
>> the class becoming complete and its inline methods being parsed.
>>
>> This replaces the hack of using the "late parsed template" flag to track
>> member
>> functions with bodies we've not parsed yet; instead we now use the "will
>> have
>> body" flag, which carries the desired implication that the function
>> declaration
>> *is* a definition, and that we've just not parsed its body yet.
>>
>> Added:
>> cfe/trunk/test/CodeGenCXX/pr34163.cpp
>> Modified:
>> cfe/trunk/include/clang/AST/Decl.h
>> cfe/trunk/lib/AST/DeclCXX.cpp
>> cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp
>> cfe/trunk/lib/Sema/SemaDecl.cpp
>> cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
>> cfe/trunk/test/SemaCUDA/function-overload.cu
>> cfe/trunk/test/SemaCUDA/no-destructor-overload.cu
>>
>> Modified: cfe/trunk/include/clang/AST/Decl.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=310776&r1=310775&r2=310776&view=diff
>>
>> ==
>> --- cfe/trunk/include/clang/AST/Decl.h (original)
>> +++ cfe/trunk/include/clang/AST/Decl.h Fri Aug 11 18:46:03 2017
>> @@ -1666,8 +1666,7 @@ private:
>>unsigned HasSkippedBody : 1;
>>
>>/// Indicates if the function declaration will have a body, once we're
>> done
>> -  /// parsing it.  (We don't set it to false when we're done parsing, in
>> the
>> -  /// hopes this is simpler.)
>> +  /// parsing it.
>>unsigned WillHaveBody : 1;
>>
>>/// \brief End part of this FunctionDecl's source range.
>>
>> Modified: cfe/trunk/lib/AST/DeclCXX.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=310776&r1=310775&r2=310776&view=diff
>>
>> ==
>> --- cfe/trunk/lib/AST/DeclCXX.cpp (original)
>> +++ cfe/trunk/lib/AST/DeclCXX.cpp Fri Aug 11 18:46:03 2017
>> @@ -1837,9 +1837,10 @@ bool CXXMethodDecl::hasInlineBody() cons
>>const FunctionDecl *CheckFn = getTemplateInstantiationPattern();
>>if (!CheckFn)
>>  CheckFn = this;
>> -
>> +
>>const FunctionDecl *fn;
>> -  return CheckFn->hasBody(fn) && !fn->isOutOfLine();
>> +  return CheckFn->isDefined(fn) && !fn->isOutOfLine() &&
>> + (fn->doesThisDeclarationHaveABody() || fn->willHaveBody());
>>  }
>>
>>  bool CXXMethodDecl::isLambdaStaticInvoker() const {
>>
>> Modified: cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp?rev=310776&r1=310775&r2=310776&view=diff
>>
>> ==
>> --- cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp (original)
>> +++ cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp Fri Aug 11 18:46:03 2017
>> @@ -166,20 +166,11 @@ NamedDecl *Parser::ParseCXXInlineMethodD
>>}
>>
>>if (FnD) {
>> -// If this is a friend function, mark that it's late-parsed so that
>> -// it's still known to be a definition even before we attach the
>> -// parsed body.  Sema needs to treat friend function definitions
>> -// differently during template instantiation, and it's possible for
>> -// the containing class to be instantiated before all its member
>> -// function definitions are parsed.
>> -//
>> -// If you remove this, you can remove the code that clears the flag
>> -// after parsing the member.
>> -if (D.getDeclSpec().isFriendSpecified()) {
>> -  FunctionDecl *FD = FnD->getAsFunction();
>> -  Actions.CheckForFunctionRedefinition(FD);
>> -  FD->setLateTemplateParsed(true);
>> -}
>> +FunctionDecl *FD = FnD->getAsFunction();
>> +// Track that this function will eventually have a body; Sema needs
>> +// to know this.
>> +Actions.CheckForFunctionRedefinition(FD);
>> +FD->setWillHaveBody(true);
>>} else {
>>  // If semantic analysis could not build a function declaration,
>>  // just throw away the late-parsed declaration.
>> @@ -559,10 +550,6 @@ void Parser::ParseLexedMethodDef(LexedMe
>>
>>ParseFunctionStatementBody(LM.D, FnScope);
>>
>> -  // Clear the late-template-parsed bit if we set it before.
>> -  if (LM.D)
>> -LM.D->getAsFunction()->setLateTemplateParsed(false);
>> -
>>while (Tok.isNot(tok::eof))
>>  ConsumeAnyToken();
>>
>>
>>

[PATCH] D36423: [libc++] Introsort based sorting function

2017-08-14 Thread DIVYA SHANMUGHAN via Phabricator via cfe-commits
DIVYA updated this revision to Diff 111027.

https://reviews.llvm.org/D36423

Files:
  benchmarks/algorithms.bench.cpp
  include/algorithm
  include/rng_utils.h
  include/test_configs.h
  include/test_utils.h

Index: include/test_utils.h
===
--- /dev/null
+++ include/test_utils.h
@@ -0,0 +1,270 @@
+#ifndef TEST_UTILS_H
+#define TEST_UTILS_H
+
+#include "rng_utils.h"
+#include
+#include
+
+// TODO: Add more aggregates.
+struct aggregate {
+  int first;
+  int second;
+  int third;
+  int fourth;
+  aggregate() : first(0), second(0), third(0), fourth(0)
+  {}
+  // This is a hacky constructor for ::find on associative containers to work.
+  aggregate(int i)
+: first(i), second(i), third(i), fourth(i)
+  {}
+  aggregate(int i, int j, int k, int l)
+: first(i), second(j), third(k), fourth(l)
+  {}
+
+  aggregate& operator++() {
+++first;
+++second;
+++third;
+++fourth;
+return *this;
+  }
+  aggregate operator++(int) {
+aggregate N(*this);
+++(*this);
+return N;
+  }
+
+  bool operator<(const aggregate& i) const {
+return first < i.first;
+  }
+
+  bool operator>(const aggregate& i) const {
+return i < *this;
+  }
+
+  bool operator==(const aggregate& i) const {
+return first == i.first;
+  }
+
+  bool operator!=(const aggregate& i) const {
+return !(*this == i);
+  }
+};
+
+// Hasher for aggregate data type.
+namespace std {
+  template <>
+  struct hash
+  {
+std::size_t operator()(const aggregate& k) const
+{
+  using std::hash;
+  // Hash and combine using bit-shift.
+  return ((hash()(k.first)
+   ^ (hash()(k.second) << 1)) >> 1)
+   ^ (hash()(k.third) << 1)
+   ^ (hash()(k.fourth) << 1);
+}
+  };
+}
+
+template
+struct remove_const { typedef T type; };
+
+// value_type of a std::map is std::pair
+template
+struct remove_const> { typedef std::pair type; };
+
+template
+T get_rand(random_device &r, int max) {
+  return r.get_rand(T(0), T(max));
+}
+
+template<>
+std::pair get_rand>(random_device &r, int max) {
+  return std::make_pair(r.get_rand(0, max), r.get_rand(0, max));
+}
+
+template<>
+aggregate get_rand(random_device &r, int max) {
+  return aggregate(r.get_rand(0, max));
+}
+
+template<>
+std::pair
+get_rand>(random_device &r, int max) {
+  return std::make_pair(r.get_rand(0, max), r.get_rand(0, max));
+}
+
+template
+T increment(T &i) {
+  return ++i;
+}
+
+// value_type of a std::map is std::pair
+template<>
+std::pair increment>(std::pair &i) {
+  return std::make_pair(++i.first, i.second);
+}
+
+template<>
+std::pair
+increment>(std::pair &i) {
+  return std::make_pair(++i.first, i.second);
+}
+
+template
+T init() {
+  return T(0);
+}
+
+template<>
+std::pair init>() {
+  return std::make_pair(0, 0);
+}
+
+template<>
+std::pair init>() {
+  return std::make_pair(0, 0);
+}
+
+template  class Container, class value_type>
+void fill_random(Container> &v,
+int max = RAND_MAX) {
+  random_device r;
+  for (auto &e : v)
+e = get_rand(r, max);
+}
+
+template 
+void fill_random(T begin, T end, int max = RAND_MAX) {
+  typedef typename std::iterator_traits::value_type value_type;
+  random_device r;
+  for (auto it = begin; it != end; ++it)
+*it = get_rand(r, max);
+}
+
+// It can work with char* or std::string.
+template
+void fill_random_chars(T begin, T end, bool upper) {
+  char max = upper ? 'Z' : 'z';
+  char min = upper ? 'A' : 'a';
+  auto it = begin;
+  typedef typename std::iterator_traits::value_type value_type;
+  random_device r;
+  for (; it != end -1; ++it) {
+*it = get_rand(r, max) * (max - min) + min;
+assert(*it >= min);
+assert(*it <= max);
+  }
+  *it = '\0';
+}
+
+// TODO: Create a template class such that all the
+// APIs of STL containers can be exercised in a concise way.
+// for example insert, push_back, pop_back, push_front, pop_front, advance
+
+// TODO: Benchmark memory allocated on heap vs. stack.
+template 
+void fill_seq(T begin, T end) {
+  typedef typename std::iterator_traits::value_type value_type;
+  //random_device r;
+  value_type j = init();// = get_rand(r, RAND_MAX);
+  for (auto it = begin; it != end; ++it, increment(j))
+*it = j;
+}
+
+template  class Container, class value_type>
+void fill_seq(Container> &v) {
+  fill_seq(std::begin(v), std::end(v));
+}
+
+// Size of vector \p v to be constructed is \p size
+template 
+void make_killer(int size, std::vector& v) {
+  int candidate = 0;
+  int num_solid = 0;
+  int gas = size - 1;
+
+  std::vector tmp(size);
+  v.resize(size);
+
+  for (T i = 0; i < size; ++i) {
+tmp[i] = i;
+v[i] = gas;
+  }
+
+  std::sort(tmp.begin(), tmp.end(), [&](T x, T y) {
+  if (v[x] == gas && v[y] == gas) {
+if (x == candidate) v[x] = num_solid++;
+else v[y] = num_solid++;
+  }
+
+  if (v[x] == gas) candidate = x;
+  else if (v[y] == gas) candidate = y;
+
+  return v[x] < v[y

[PATCH] D36423: [libc++] Introsort based sorting function

2017-08-14 Thread DIVYA SHANMUGHAN via Phabricator via cfe-commits
DIVYA added a comment.

Added benchmark from Aditya's repo into the libcxx benchmark code base


https://reviews.llvm.org/D36423



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


[PATCH] D35370: [clang-tidy] Add a close-on-exec check on inotify_init() in Android module.

2017-08-14 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL310861: [clang-tidy] Add a close-on-exec check on 
inotify_init() in Android module. (authored by chh).

Changed prior to commit:
  https://reviews.llvm.org/D35370?vs=110749&id=111028#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35370

Files:
  clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
  clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/android/CloexecInotifyInitCheck.cpp
  clang-tools-extra/trunk/clang-tidy/android/CloexecInotifyInitCheck.h
  clang-tools-extra/trunk/docs/ReleaseNotes.rst
  
clang-tools-extra/trunk/docs/clang-tidy/checks/android-cloexec-inotify-init.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
  clang-tools-extra/trunk/test/clang-tidy/android-cloexec-inotify-init.cpp

Index: clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
===
--- clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
+++ clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
@@ -13,6 +13,7 @@
 #include "CloexecCreatCheck.h"
 #include "CloexecDupCheck.h"
 #include "CloexecFopenCheck.h"
+#include "CloexecInotifyInitCheck.h"
 #include "CloexecMemfdCreateCheck.h"
 #include "CloexecOpenCheck.h"
 #include "CloexecSocketCheck.h"
@@ -30,6 +31,8 @@
 CheckFactories.registerCheck("android-cloexec-creat");
 CheckFactories.registerCheck("android-cloexec-dup");
 CheckFactories.registerCheck("android-cloexec-fopen");
+CheckFactories.registerCheck(
+"android-cloexec-inotify-init");
 CheckFactories.registerCheck(
 "android-cloexec-memfd-create");
 CheckFactories.registerCheck("android-cloexec-open");
Index: clang-tools-extra/trunk/clang-tidy/android/CloexecInotifyInitCheck.h
===
--- clang-tools-extra/trunk/clang-tidy/android/CloexecInotifyInitCheck.h
+++ clang-tools-extra/trunk/clang-tidy/android/CloexecInotifyInitCheck.h
@@ -0,0 +1,35 @@
+//===--- CloexecInotifyInitCheck.h - clang-tidy--*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_INOTIFY_INIT_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_INOTIFY_INIT_H
+
+#include "CloexecCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+/// inotify_init() is better to be replaced by inotify_init1().
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-inotify-init.html
+class CloexecInotifyInitCheck : public CloexecCheck {
+public:
+  CloexecInotifyInitCheck(StringRef Name, ClangTidyContext *Context)
+  : CloexecCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_INOTIFY_INIT_H
Index: clang-tools-extra/trunk/clang-tidy/android/CloexecInotifyInitCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/android/CloexecInotifyInitCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/android/CloexecInotifyInitCheck.cpp
@@ -0,0 +1,34 @@
+//===--- CloexecInotifyInitCheck.cpp - clang-tidy--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "CloexecInotifyInitCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+void CloexecInotifyInitCheck::registerMatchers(MatchFinder *Finder) {
+  registerMatchersImpl(
+  Finder, functionDecl(returns(isInteger()), hasName("inotify_init")));
+}
+
+void CloexecInotifyInitCheck::check(const MatchFinder::MatchResult &Result) {
+  replaceFunc(Result, /*WarningMsg=*/
+  "prefer inotify_init() to inotify_init1() "
+  "because inotify_init1() allows IN_CLOEXEC",
+  /*FixMsg=*/"inotify_init1(IN_CLOEXEC)");
+}
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
Index: clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
===
--- clang-tools-extra/trunk/clang-tidy/android/C

[clang-tools-extra] r310861 - [clang-tidy] Add a close-on-exec check on inotify_init() in Android module.

2017-08-14 Thread Chih-Hung Hsieh via cfe-commits
Author: chh
Date: Mon Aug 14 10:25:41 2017
New Revision: 310861

URL: http://llvm.org/viewvc/llvm-project?rev=310861&view=rev
Log:
[clang-tidy] Add a close-on-exec check on inotify_init() in Android module.

Summary:
inotify_init() is better to be replaced by inotify_init1() with IN_CLOEXEC flag 
to avoid file descriptor leakage.

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


Added:
clang-tools-extra/trunk/clang-tidy/android/CloexecInotifyInitCheck.cpp
clang-tools-extra/trunk/clang-tidy/android/CloexecInotifyInitCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/android-cloexec-inotify-init.rst
clang-tools-extra/trunk/test/clang-tidy/android-cloexec-inotify-init.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp?rev=310861&r1=310860&r2=310861&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp Mon Aug 14 
10:25:41 2017
@@ -13,6 +13,7 @@
 #include "CloexecCreatCheck.h"
 #include "CloexecDupCheck.h"
 #include "CloexecFopenCheck.h"
+#include "CloexecInotifyInitCheck.h"
 #include "CloexecMemfdCreateCheck.h"
 #include "CloexecOpenCheck.h"
 #include "CloexecSocketCheck.h"
@@ -30,6 +31,8 @@ public:
 CheckFactories.registerCheck("android-cloexec-creat");
 CheckFactories.registerCheck("android-cloexec-dup");
 CheckFactories.registerCheck("android-cloexec-fopen");
+CheckFactories.registerCheck(
+"android-cloexec-inotify-init");
 CheckFactories.registerCheck(
 "android-cloexec-memfd-create");
 CheckFactories.registerCheck("android-cloexec-open");

Modified: clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt?rev=310861&r1=310860&r2=310861&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt Mon Aug 14 
10:25:41 2017
@@ -6,6 +6,7 @@ add_clang_library(clangTidyAndroidModule
   CloexecCreatCheck.cpp
   CloexecDupCheck.cpp
   CloexecFopenCheck.cpp
+  CloexecInotifyInitCheck.cpp
   CloexecMemfdCreateCheck.cpp
   CloexecOpenCheck.cpp
   CloexecSocketCheck.cpp

Added: clang-tools-extra/trunk/clang-tidy/android/CloexecInotifyInitCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/CloexecInotifyInitCheck.cpp?rev=310861&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/android/CloexecInotifyInitCheck.cpp 
(added)
+++ clang-tools-extra/trunk/clang-tidy/android/CloexecInotifyInitCheck.cpp Mon 
Aug 14 10:25:41 2017
@@ -0,0 +1,34 @@
+//===--- CloexecInotifyInitCheck.cpp - 
clang-tidy--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "CloexecInotifyInitCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+void CloexecInotifyInitCheck::registerMatchers(MatchFinder *Finder) {
+  registerMatchersImpl(
+  Finder, functionDecl(returns(isInteger()), hasName("inotify_init")));
+}
+
+void CloexecInotifyInitCheck::check(const MatchFinder::MatchResult &Result) {
+  replaceFunc(Result, /*WarningMsg=*/
+  "prefer inotify_init() to inotify_init1() "
+  "because inotify_init1() allows IN_CLOEXEC",
+  /*FixMsg=*/"inotify_init1(IN_CLOEXEC)");
+}
+
+} // namespace android
+} // namespace tidy
+} // namespace clang

Added: clang-tools-extra/trunk/clang-tidy/android/CloexecInotifyInitCheck.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/CloexecInotifyInitCheck.h?rev=310861&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/android/CloexecInotifyInitCheck.h (added)
+++ clang-tools-extra/trunk/clang-tidy/android/CloexecInotifyInitCheck.h Mon 
Aug 14 10:25:41 2017
@@ -0,0 +1,35 @@
+//===--- CloexecInotifyInitCheck.h - clang-tidy--*- C++ 
-*-===//
+//
+//

  1   2   >